Beispiel #1
0
static int sr_mono_hdr_append_to_reply (MonoString *hv)
{
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("append to reply: %s\n", txt.s);

	if(add_lump_rpl(env_M->msg, txt.s, txt.len, LUMP_RPL_HDR)==0)
	{
		LM_ERR("unable to add reply lump\n");
		goto error;
	}

	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Beispiel #2
0
static int sr_mono_pv_sets (MonoString *pv, MonoString *sv)
{
	str pvn = {0};
	pv_spec_t *pvs;
    pv_value_t val;
	int pl;
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	pvn.s = mono_string_to_utf8(pv);

	if(pvn.s==NULL || env_M->msg==NULL)
		goto error;

	memset(&val, 0, sizeof(pv_value_t));
	val.rs.s = mono_string_to_utf8(sv);
	if(val.rs.s == NULL)
		goto error;

	val.rs.len = strlen(val.rs.s);
	val.flags |= PV_VAL_STR;
	
	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		goto error;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		goto error;
	}
	if(pv_set_spec_value(env_M->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return -1;
	}

	mono_free(pvn.s);
	return 0;
error:
	if(pvn.s!=NULL)
		mono_free(pvn.s);
	return -1;
}
Beispiel #3
0
static int sr_mono_hdr_append (MonoString *hv)
{
	struct lump* anchor;
	struct hdr_field *hf;
	char *hdr;
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("append hf: %s\n", txt.s);
	if (parse_headers(env_M->msg, HDR_EOH_F, 0) == -1)
	{
		LM_ERR("error while parsing message\n");
		goto error;
	}

	hf = env_M->msg->last_header;
	hdr = (char*)pkg_malloc(txt.len+1);
	if(hdr==NULL)
	{
		PKG_MEM_ERROR;
		goto error;
	}
	memcpy(hdr, txt.s, txt.len);
	hdr[txt.len] = '\0';
	anchor = anchor_lump(env_M->msg,
				hf->name.s + hf->len - env_M->msg->buf, 0, 0);
	if(insert_new_lump_before(anchor, hdr, txt.len, 0) == 0)
	{
		LM_ERR("can't insert lump\n");
		pkg_free(hdr);
		goto error;
	}
	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Beispiel #4
0
CFArrayRef CMCreateArrayWithMonoStringArray(CFAllocatorRef allocator, MonoArray *monoArray) {
    CFArrayRef array = NULL;
    if (monoArray) {
        uintptr_t n = mono_array_length(monoArray);
        CFTypeRef *values = CFAllocatorAllocate(allocator, n * sizeof(CFTypeRef), 0);
        if (values) {

            for (uintptr_t i = 0; i < n; i++) {
                values[i] = kCFNull;
                MonoString *monoString = mono_array_get(monoArray, MonoString*, i);
                if (monoString) {
                    char *utf8MonoString = mono_string_to_utf8(monoString);
                    if (utf8MonoString) {
                        CFStringRef string = CFStringCreateWithCString(allocator, utf8MonoString, kCFStringEncodingUTF8);
                        if (string) {
                            values[i] = string;
                        }
                        mono_free(utf8MonoString);
                    }
                }
            }

            array = CFArrayCreate(allocator, values, n, &kCFTypeArrayCallBacks);

            for (uintptr_t i = 0; i < n; i++) {
                if (values[i] != kCFNull) {
                    CFRelease(values[i]);
                }
            }

            CFAllocatorDeallocate(allocator, values);
        }
    }
    return array;
}
Beispiel #5
0
String GDMonoMethod::get_signature_desc(bool p_namespaces) const {
	MonoMethodSignature *method_sig = mono_method_signature(mono_method);
	char *sig_desc = mono_signature_get_desc(method_sig, p_namespaces);
	String res = sig_desc;
	mono_free(sig_desc);
	return res;
}
Beispiel #6
0
String GDMonoMethod::get_ret_type_full_name() const {
	MonoMethodSignature *method_sig = mono_method_signature(mono_method);
	char *ret_str = mono_type_full_name(mono_signature_get_return_type(method_sig));
	String res = ret_str;
	mono_free(ret_str);
	return res;
}
Beispiel #7
0
static int sr_mono_pv_geti (MonoString *pv)
{
	str pvn = {0};
	pv_spec_t *pvs;
    pv_value_t val;
	int pl;
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	pvn.s = mono_string_to_utf8(pv);

	if(pvn.s==NULL || env_M->msg==NULL)
		goto error;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv get: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		goto error;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		goto error;
	}
	memset(&val, 0, sizeof(pv_value_t));
	if(pv_get_spec_value(env_M->msg, pvs, &val) != 0)
	{
		LM_ERR("unable to get pv value for [%s]\n", pvn.s);
		goto error;
	}
	if((val.flags&PV_VAL_NULL) || !(val.flags&PV_TYPE_INT))
	{
		mono_free(pvn.s);
		return 0;
	}
	mono_free(pvn.s);
	return val.ri;

error:
	if(pvn.s!=NULL)
		mono_free(pvn.s);
	return 0;
}
Beispiel #8
0
static int sr_mono_hdr_remove (MonoString *hv)
{
	struct lump* anchor;
	struct hdr_field *hf;
	str hname;
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("remove hf: %s\n", txt.s);
	if (parse_headers(env_M->msg, HDR_EOH_F, 0) == -1) {
		LM_ERR("error while parsing message\n");
		goto error;
	}

	hname.s = txt.s;
	hname.len = txt.len;
	for (hf=env_M->msg->headers; hf; hf=hf->next)
	{
		if (cmp_hdrname_str(&hf->name, &hname)==0)
		{
			anchor=del_lump(env_M->msg,
					hf->name.s - env_M->msg->buf, hf->len, 0);
			if (anchor==0)
			{
				LM_ERR("cannot remove hdr %s\n", txt.s);
				goto error;
			}
		}
	}
	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Beispiel #9
0
bool GDMono::load_assembly(const String &p_name, GDMonoAssembly **r_assembly, bool p_refonly) {

	CRASH_COND(!r_assembly);

	MonoAssemblyName *aname = mono_assembly_name_new(p_name.utf8());
	bool result = load_assembly(p_name, aname, r_assembly, p_refonly);
	mono_assembly_name_free(aname);
	mono_free(aname);

	return result;
}
Beispiel #10
0
String GDMonoMethod::get_full_name_no_class() const {
	String res;

	MonoMethodSignature *method_sig = mono_method_signature(mono_method);

	char *ret_str = mono_type_full_name(mono_signature_get_return_type(method_sig));
	res += ret_str;
	mono_free(ret_str);

	res += " ";
	res += name;
	res += "(";

	char *sig_desc = mono_signature_get_desc(method_sig, true);
	res += sig_desc;
	mono_free(sig_desc);

	res += ")";

	return res;
}
Beispiel #11
0
String get_exception_name_and_message(MonoException *p_exc) {
	String res;

	MonoClass *klass = mono_object_get_class((MonoObject *)p_exc);
	MonoType *type = mono_class_get_type(klass);

	char *full_name = mono_type_full_name(type);
	res += full_name;
	mono_free(full_name);

	res += ": ";

	MonoProperty *prop = mono_class_get_property_from_name(klass, "Message");
	MonoString *msg = (MonoString *)property_get_value(prop, (MonoObject *)p_exc, NULL, NULL);
	res += GDMonoMarshal::mono_string_to_godot(msg);

	return res;
}
Beispiel #12
0
String GDMonoMethod::get_full_name(bool p_signature) const {
	char *res = mono_method_full_name(mono_method, p_signature);
	String full_name(res);
	mono_free(res);
	return full_name;
}
Beispiel #13
0
GodotSharpExport::~GodotSharpExport() {
	if (aname_prealloc)
		mono_free(aname_prealloc);
}
Beispiel #14
0
mono_string_utf8::~mono_string_utf8()
{
	if(m_str!=0)
		mono_free(m_str);
}
Beispiel #15
0
static void sr_mono_log(int level, MonoString *text) {
	char *logmsg;
	logmsg = mono_string_to_utf8(text);
	LOG(level, "%s", logmsg);
	mono_free(logmsg);
}
Beispiel #16
0
static void sr_mono_dbg(MonoString *text) {
	char *logmsg;
	logmsg = mono_string_to_utf8(text);
	LOG(L_DBG, "%s", logmsg);
	mono_free(logmsg);
}
Beispiel #17
0
static int sr_mono_modf(MonoString *nfunc)
{
	int ret;
	int mod_type;
	struct run_act_ctx ra_ctx;
	struct action *act = NULL;
	ksr_cmd_export_t* expf;
	sr_mono_env_t *env_M;
	char *func = NULL;

	env_M = sr_mono_env_get();
	if(env_M->msg==NULL)
		goto error;

	func = mono_string_to_utf8(nfunc);

	expf = find_export_record(func, 0, 0);
	if (expf==NULL) {
		LM_ERR("function '%s' is not available\n", func);
		goto error;
	}
	/* check fixups */
	if (expf->fixup!=NULL && expf->free_fixup==NULL) {
		LM_ERR("function '%s' has fixup - cannot be used\n", func);
		goto error;
	}
	mod_type = MODULE0_T;

	act = mk_action(mod_type,  1        /* number of (type, value) pairs */,
					MODEXP_ST, expf,    /* function */
					NUMBER_ST, 0,       /* parameter number */
					STRING_ST, NULL,    /* param. 1 */
					STRING_ST, NULL,    /* param. 2 */
					STRING_ST, NULL,    /* param. 3 */
					STRING_ST, NULL,    /* param. 4 */
					STRING_ST, NULL,    /* param. 5 */
					STRING_ST, NULL     /* param. 6 */
			);

	if (act==NULL) {
		LM_ERR("action structure could not be created for '%s'\n", func);
		goto error;
	}

	/* handle fixups */
	if (expf->fixup) {
		/* no parameters */
		if(expf->fixup(0, 0)<0)
		{
			LM_ERR("Error in fixup (0) for '%s'\n", func);
			goto error;
		}
	}
	init_run_actions_ctx(&ra_ctx);
	ret = do_action(&ra_ctx, act, env_M->msg);
	pkg_free(act);
	mono_free(func);
	return ret;

error:
	if(func!=NULL)
		mono_free(func);
	if(act!=NULL)
		pkg_free(act);
	return -127;
}