bool get_all_properties_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	jvalue_ref reply_obj = NULL;
	jvalue_ref props_obj = NULL;
	struct property_list list;

	reply_obj = jobject_create();
	props_obj = jarray_create(NULL);

	memset(&list, 0, sizeof(struct property_list));
	if (property_list(record_prop, props_obj) < 0) {
		luna_service_message_reply_error_internal(handle, message);
		goto cleanup;
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("properties"), props_obj);
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if (!luna_service_message_validate_and_send(handle, message, reply_obj))
		goto cleanup;

cleanup:
	if (!jis_null(reply_obj))
		j_release(&reply_obj);

	if (!jis_null(props_obj))
		j_release(&props_obj);

	return true;
}
Esempio n. 2
0
	int jass_get(lua_State* L)
	{
		const char* name = lua_tostring(L, 2);

		jass::func_value const* nf = jass::jass_func(name);
		if (nf && nf->is_valid())
		{
			if (!lua::allow_yield(L))
			{
				if ((0 == strcmp(name, "TriggerSleepAction"))
					|| (0 == strcmp(name, "TriggerWaitForSound"))
					|| (0 == strcmp(name, "TriggerSyncReady"))
					|| (0 == strcmp(name, "SyncSelections")))
				{
					lua_pushstring(L, name);
					lua_pushcclosure(L, jass_call_null_function, 1);
					return 1;
				}
			}

			lua_pushinteger(L, (uint32_t)(uintptr_t)nf);
			lua_pushcclosure(L, jass_call_closure, 1);
			return 1;
		}

		if (!is_gaming())
		{
			lua_pushnil(L);
			return 1;
		}

		jass::global_variable gv(name);
		if (gv.is_vaild())
		{
			if (!gv.is_array())
			{
				globals::jass_get_global_variable(L, gv.type(), gv);
				return 1;
			}
			else
			{
				switch (gv.type())
				{
				case jass::OPCODE_VARIABLE_INTEGER_ARRAY:
				case jass::OPCODE_VARIABLE_REAL_ARRAY:
				case jass::OPCODE_VARIABLE_STRING_ARRAY:
				case jass::OPCODE_VARIABLE_HANDLE_ARRAY:
				case jass::OPCODE_VARIABLE_BOOLEAN_ARRAY:
					return jarray_create(L, (uintptr_t)gv.ptr());
				default:
					lua_pushnil(L);
					return 1;
				}
			}
		}

		lua_pushnil(L);
		return 1;
	}
static int _service_network_list_query_finish(const struct telephony_error *error, GList *networks, void *data)
{
	struct luna_service_req_data *req_data = data;
	struct telephony_service *service = req_data->user_data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	jvalue_ref networks_obj = NULL;
	jvalue_ref network_obj = NULL;
	bool success = (error == NULL);
	struct telephony_network *current_network = NULL;
	int n;

	reply_obj = jobject_create();
	extended_obj = jobject_create();
	networks_obj = jarray_create(NULL);

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	if (success) {
		for (n = 0; n < g_list_length(networks); n++) {
			current_network = g_list_nth_data(networks, n);

			network_obj = jobject_create();
			jobject_put(network_obj, J_CSTR_TO_JVAL("id"), jnumber_create_i32(current_network->id));
			jobject_put(network_obj, J_CSTR_TO_JVAL("name"),
						jstring_create(current_network->name ? current_network->name : ""));
			const char *rat_str = telephony_radio_access_mode_to_string(current_network->radio_access_mode);
			jobject_put(network_obj, J_CSTR_TO_JVAL("rat"), jstring_create(rat_str));
			jarray_append(networks_obj, network_obj);
		}

		jobject_put(extended_obj, J_CSTR_TO_JVAL("networks"), networks_obj);
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	service->network_status_query_pending = false;

	j_release(&reply_obj);
	luna_service_req_data_free(req_data);

	return 0;
}
Esempio n. 4
0
	int jass_get(lua_State* L)
	{
		const char* name = lua_tostring(L, 2);

		jass::func_value const* nf = jass::jass_func(name);
		if (nf && nf->is_valid())
		{
			lua_pushinteger(L, (uint32_t)(uintptr_t)nf);
			lua_pushcclosure(L, jass_call_closure, 1);
			return 1;
		}

		if (!is_gaming())
		{
			lua_pushnil(L);
			return 1;
		}

		jass::global_variable gv(name);
		if (gv.is_vaild())
		{
			if (!gv.is_array())
			{
				globals::jass_get_global_variable(L, gv.type(), gv);
				return 1;
			}
			else
			{
				switch (gv.type())
				{
				case jass::OPCODE_VARIABLE_INTEGER_ARRAY:
				case jass::OPCODE_VARIABLE_REAL_ARRAY:
				case jass::OPCODE_VARIABLE_STRING_ARRAY:
				case jass::OPCODE_VARIABLE_HANDLE_ARRAY:
				case jass::OPCODE_VARIABLE_BOOLEAN_ARRAY:
					return jarray_create(L, (uintptr_t)gv.ptr());
				default:
					lua_pushnil(L);
					return 1;
				}
			}
		}

		lua_pushnil(L);
		return 1;
	}
bool service_list_upgradable_packages_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct package_list_info plistinfo;
	GSList *iter;
	jvalue_ref reply_obj = NULL;
	jvalue_ref pkglist_obj = NULL;
	jvalue_ref pkgname_obj = NULL;

	if (opkg_new()) {
		luna_service_message_reply_error_internal(handle, message);
		return true;
	}

	plistinfo.pkgs = g_slist_alloc();
	opkg_list_upgradable_packages(upgradable_package_list_cb, &plistinfo);

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	pkglist_obj = jarray_create(NULL);

	for (iter = plistinfo.pkgs; iter != NULL; iter = g_slist_next(iter)) {
		if (iter->data != NULL) {
			gchar *pkgname = iter->data;
			pkgname_obj = jstring_create(pkgname);
			jarray_append(pkglist_obj, pkgname_obj);
		}
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("upgradablePackages"), pkglist_obj);

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);
	g_slist_free_full(plistinfo.pkgs, g_free);

	opkg_free();

	return true;
}
Esempio n. 6
0
static int dom_array_start(JSAXContextRef ctxt)
{
	DomInfo *data = getDOMContext(ctxt);
	jvalue_ref newParent;
	DomInfo *newChild;
	CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "object encountered without any context");

	newParent = jarray_create(NULL);
	newChild = calloc(1, sizeof(DomInfo));
	if (UNLIKELY(newChild == NULL || jis_null(newParent))) {
		PJ_LOG_ERR("Failed to allocate space for new array node");
		j_release(&newParent);
		free(newChild);
		return 0;
	}
	newChild->m_prev = data;
	newChild->m_optInformation = data->m_optInformation;
	changeDOMContext(ctxt, newChild);

	if (data->m_prev != NULL) {
		if (jis_array(data->m_prev->m_value)) {
			assert(data->m_value == NULL);
			jarray_append(data->m_prev->m_value, newParent);
		} else {
			assert(jis_object(data->m_prev->m_value));
			if (UNLIKELY(!jis_string(data->m_value))) {
				PJ_LOG_ERR("improper place for a child object");
				j_release(&newParent);
				return 0;
			}
			jobject_put(data->m_prev->m_value, data->m_value, newParent);
		}
	}

	// not using reference counting here on purpose
	data->m_value = newParent;

	return 1;
}
Esempio n. 7
0
JValue Array()
{
	return jarray_create(NULL);
}
bool get_property_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	jvalue_ref parsed_obj = NULL;
	jvalue_ref keys_obj = NULL;
	jvalue_ref reply_obj = NULL;
	jvalue_ref props_obj = NULL;
	jvalue_ref prop_obj = NULL;
	char *payload, value[PROP_VALUE_MAX];
	int n;
	raw_buffer key_buf;

	payload = LSMessageGetPayload(message);
	parsed_obj = luna_service_message_parse_and_validate(payload);
	if (jis_null(parsed_obj)) {
		luna_service_message_reply_error_bad_json(handle, message);
		goto cleanup;
	}

	if (!jobject_get_exists(parsed_obj, J_CSTR_TO_BUF("keys"), &keys_obj) ||
		!jis_array(keys_obj)) {
		luna_service_message_reply_error_bad_json(handle, message);
		goto cleanup;
	}

	reply_obj = jobject_create();
	props_obj = jarray_create(NULL);

	for (n = 0; n < jarray_size(keys_obj); n++) {
		jvalue_ref key_obj = jarray_get(keys_obj, n);

		if (!jis_string(key_obj))
			continue;

		key_buf = jstring_get(key_obj);

		if (strlen(key_buf.m_str) == 0)
			continue;

		property_get(key_buf.m_str, value, "");

		prop_obj = jobject_create();
		jobject_put(prop_obj, jstring_create(key_buf.m_str), jstring_create(value));

		jarray_append(props_obj, prop_obj);
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("properties"), props_obj);
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if (!luna_service_message_validate_and_send(handle, message, reply_obj))
		goto cleanup;

cleanup:
	if (!jis_null(parsed_obj))
		j_release(&parsed_obj);

	if (!jis_null(reply_obj))
		j_release(&reply_obj);

	return true;
}
Esempio n. 9
0
bool
_LSSubscriptionGetJson(LSHandle *sh, jvalue_ref *ret_obj, LSError *lserror)
{
    _Catalog *catalog = sh->catalog;
    const char *key = NULL;
    _SubList *sub_list = NULL;
    GHashTableIter iter;

    jvalue_ref true_obj = NULL;
    jvalue_ref array = NULL;
    jvalue_ref cur_obj = NULL;
    jvalue_ref sub_array = NULL;
    jvalue_ref key_name = NULL;
    jvalue_ref message_obj = NULL;
    jvalue_ref sub_array_item = NULL;
    jvalue_ref unique_name_obj = NULL;
    jvalue_ref service_name_obj = NULL;

    *ret_obj = jobject_create();
    if (*ret_obj == NULL) goto error;

    true_obj = jboolean_create(true);
    if (true_obj == NULL) goto error;

    array = jarray_create(NULL);
    if (array == NULL) goto error;

    /* returnValue: true,
     * subscriptions: [
     *  { key: key_name, subscribers: [{unique_name: , service_name: }, ...] },
     *  ...
     * ]
     */
    _CatalogLock(catalog);

    g_hash_table_iter_init(&iter, catalog->subscription_lists);

    while (g_hash_table_iter_next(&iter, (gpointer)&key, (gpointer)&sub_list))
    {
        cur_obj = jobject_create();
        if (cur_obj == NULL) goto error;

        sub_array = jarray_create(NULL);
        if (sub_array == NULL) goto error;

        key_name = jstring_create_copy(j_cstr_to_buffer(key));
        if (key_name == NULL) goto error;

        /* iterate over SubList */
        int i = 0;
        const char *token = NULL;
        const int len = _SubListLen(sub_list);
        for (i = 0; i < len; i++)
        {
            token = _SubListGet(sub_list, i);

            if (token)
            {
                _Subscription *sub = g_hash_table_lookup(catalog->token_map, token);

                if (!sub) continue;

                LSMessage *msg = sub->message;
                const char *unique_name = LSMessageGetSender(msg);
                const char *service_name = LSMessageGetSenderServiceName(msg);
                const char *message_body = LSMessageGetPayload(msg);

                /* create subscribers item and add to sub_array */
                sub_array_item = jobject_create();
                if (sub_array_item == NULL) goto error;

                unique_name_obj = unique_name ? jstring_create_copy(j_cstr_to_buffer(unique_name))
                                  : jstring_empty();
                if (unique_name_obj == NULL) goto error;

                service_name_obj = service_name ? jstring_create_copy(j_cstr_to_buffer(service_name))
                                   : jstring_empty();
                if (service_name_obj == NULL) goto error;

                message_obj = message_body ? jstring_create_copy(j_cstr_to_buffer(message_body))
                              : jstring_empty();
                if (message_obj == NULL) goto error;

                jobject_put(sub_array_item,
                            J_CSTR_TO_JVAL("unique_name"),
                            unique_name_obj);
                jobject_put(sub_array_item,
                            J_CSTR_TO_JVAL("service_name"),
                            service_name_obj);
                jobject_put(sub_array_item,
                            J_CSTR_TO_JVAL("subscription_message"),
                            message_obj);
                jarray_append(sub_array, sub_array_item);

                sub_array_item = NULL;
                unique_name_obj = NULL;
                service_name_obj = NULL;
                message_obj = NULL;
            }
        }
        jobject_put(cur_obj, J_CSTR_TO_JVAL("key"),
                    key_name);
        jobject_put(cur_obj,
                    J_CSTR_TO_JVAL("subscribers"),
                    sub_array);
        jarray_append(array, cur_obj);
        key_name = NULL;
        cur_obj = NULL;
        sub_array = NULL;
    }

    jobject_put(*ret_obj,
                J_CSTR_TO_JVAL("returnValue"),
                true_obj);
    jobject_put(*ret_obj,
                J_CSTR_TO_JVAL("subscriptions"), array);

    _CatalogUnlock(catalog);

    return true;

error:
    _CatalogUnlock(catalog);

    j_release(ret_obj);
    j_release(&true_obj);
    j_release(&array);

    j_release(&cur_obj);
    j_release(&sub_array);
    j_release(&key_name);

    j_release(&sub_array_item);
    j_release(&unique_name_obj);
    j_release(&service_name_obj);

    return false;
}