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; }
static int _service_signal_strength_query_finish(const struct telephony_error *error, unsigned int bars, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); extended_obj = jobject_create(); 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("")); /* handle possible subscriptions */ if (req_data->subscribed) jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed)); if (success) { jobject_put(extended_obj, J_CSTR_TO_JVAL("bars"), jnumber_create_i32(bars)); 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
static int _service_network_list_query_cancel_finish(const struct telephony_error *error, void *data) { struct luna_service_req_data *req_data = data; struct telephony_service *service = req_data->user_data; jvalue_ref reply_obj = NULL; bool success = (error == NULL); if (!success) { luna_service_message_reply_error_unknown(req_data->handle, req_data->message); goto cleanup; } reply_obj = jobject_create(); 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("success")); 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; } service->network_status_query_pending = false; cleanup: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
static int _service_network_selection_mode_query_finish(const struct telephony_error *error, bool automatic, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); 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) { jobject_put(reply_obj, J_CSTR_TO_JVAL("automatic"), jboolean_create(automatic)); } 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
bool _service_device_lock_query_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct telephony_service *service = user_data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool subscribed = false; reply_obj = jobject_create(); extended_obj = jobject_create(); subscribed = luna_service_check_for_subscription_and_process(handle, message); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); if (!service->powered) { jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(1)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("Phone Radio is off")); } else { jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success")); } /* FIXME we don't really now which properties are part of the extended object */ jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj); jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed)); if(!luna_service_message_validate_and_send(handle, message, reply_obj)) luna_service_message_reply_error_internal(handle, message); j_release(&reply_obj); return true; }
static int _service_rat_query_finish(const struct telephony_error *error, enum telephony_radio_access_mode mode, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); 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(success ? "success" : "")); if (success) { extended_obj = jobject_create(); jobject_put(extended_obj, J_CSTR_TO_JVAL("mode"), jstring_create(telephony_radio_access_mode_to_string(mode))); 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
static bool get_status_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct audio_service *service = user_data; jvalue_ref reply_obj = NULL; bool subscribed = false; if (!service->context_initialized) { luna_service_message_reply_custom_error(handle, message, "Not yet initialized"); return true; } subscribed = luna_service_check_for_subscription_and_process(handle, message); reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("volume"), jnumber_create_f64(service->volume)); jobject_put(reply_obj, J_CSTR_TO_JVAL("mute"), jboolean_create(service->mute)); jobject_put(reply_obj, J_CSTR_TO_JVAL("inCall"), jboolean_create(service->in_call)); jobject_put(reply_obj, J_CSTR_TO_JVAL("speakerMode"), jboolean_create(service->speaker_mode)); jobject_put(reply_obj, J_CSTR_TO_JVAL("micMute"), jboolean_create(service->mic_mute)); if (subscribed) jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(true)); 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); return true; }
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; }
static int _service_platform_query_finish(const struct telephony_error *error, struct telephony_platform_info *platform_info, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); extended_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success)); if (success) { jobject_put(extended_obj, J_CSTR_TO_JVAL("platformType"), jstring_create(telephony_platform_type_to_string(platform_info->platform_type))); if (platform_info->imei != NULL) jobject_put(extended_obj, J_CSTR_TO_JVAL("imei"), jstring_create(platform_info->imei)); if (platform_info->carrier != NULL) jobject_put(extended_obj, J_CSTR_TO_JVAL("carrier"), jstring_create(platform_info->carrier)); if (platform_info->mcc > 0 && platform_info->mnc > 0) { jobject_put(extended_obj, J_CSTR_TO_JVAL("mcc"), jnumber_create_i32(platform_info->mcc)); jobject_put(extended_obj, J_CSTR_TO_JVAL("mnc"), jnumber_create_i32(platform_info->mnc)); } if (platform_info->version != NULL) jobject_put(extended_obj, J_CSTR_TO_JVAL("version"), jstring_create(platform_info->version)); jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj); } else { /* FIXME better error message */ luna_service_message_reply_error_unknown(req_data->handle, req_data->message); goto cleanup; } 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
static int _service_subscriber_id_query_finish(const struct telephony_error *error, struct telephony_subscriber_info *info, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); extended_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success)); if (success) { jobject_put(extended_obj, J_CSTR_TO_JVAL("platformType"), jstring_create(telephony_platform_type_to_string(info->platform_type))); switch (info->platform_type) { case TELEPHONY_PLATFORM_TYPE_GSM: jobject_put(extended_obj, J_CSTR_TO_JVAL("imsi"), jstring_create(info->imsi)); jobject_put(extended_obj, J_CSTR_TO_JVAL("msisdn"), jstring_create(info->msisdn)); break; case TELEPHONY_PLATFORM_TYPE_CDMA: jobject_put(extended_obj, J_CSTR_TO_JVAL("min"), jstring_create(info->min)); jobject_put(extended_obj, J_CSTR_TO_JVAL("mdn"), jstring_create(info->mdn)); break; } jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj); } else { /* FIXME better error message */ luna_service_message_reply_error_unknown(req_data->handle, req_data->message); goto cleanup; } 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
void system_upgrade_progress_cb(const opkg_progress_data_t *progress, void *user_data) { struct luna_service_req_data *req_data = user_data; jvalue_ref reply_obj = NULL; if (progress && progress->pkg) { g_message("[%i%] %s %s", progress->percentage, opkg_action_to_string(progress->action), progress->pkg->name); reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); jobject_put(reply_obj, J_CSTR_TO_JVAL("state"), jstring_create("inprogress")); jobject_put(reply_obj, J_CSTR_TO_JVAL("action"), jstring_create(opkg_action_to_string(progress->action))); jobject_put(reply_obj, J_CSTR_TO_JVAL("package"), jstring_create(progress->pkg->name)); luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj); } }
bool _service_charge_source_query_cb(LSHandle *handle, LSMessage *message, void *user_data) { jvalue_ref reply_obj = NULL; reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); /* FIXME tested implementation in legacy webOS always returns the following error message */ jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(103)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("Not supported by this network type")); if(!luna_service_message_validate_and_send(handle, message, reply_obj)) luna_service_message_reply_error_internal(handle, message); j_release(&reply_obj); return true; }
int _service_power_set_finish(const struct telephony_error *error, void *data) { struct luna_service_req_data *req_data = data; struct telephony_service *service = req_data->user_data; jvalue_ref reply_obj = NULL; reply_obj = jobject_create(); service->power_off_pending = false; jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create((error == NULL))); 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); j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
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; }
bool service_run_upgrade_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct luna_service_req_data *req_data; jvalue_ref reply_obj; bool upgrade_succeeded = true; g_message("User requested starting a complete system upgrade ..."); if (opkg_new()) { luna_service_message_reply_error_internal(handle, message); return true; } req_data = luna_service_req_data_new(handle, message); if (opkg_upgrade_all(system_upgrade_progress_cb, req_data) != 0) { g_warning("Failed to upgrade the system"); upgrade_succeeded = false; } reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(upgrade_succeeded)); jobject_put(reply_obj, J_CSTR_TO_JVAL("state"), jstring_create(upgrade_succeeded ? "finished" : "failed")); 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; } if (upgrade_succeeded) g_message("Successfully finished system upgrade!"); cleanup: if (req_data) luna_service_req_data_free(req_data); opkg_free(); return true; }
static int _service_network_status_query_finish(const struct telephony_error *error, struct telephony_network_status *net_status, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); extended_obj = jobject_create(); 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("")); /* handle possible subscriptions */ if (req_data->subscribed) jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed)); if (success) { jobject_put(extended_obj, J_CSTR_TO_JVAL("state"), jstring_create(telephony_network_state_to_string(net_status->state))); jobject_put(extended_obj, J_CSTR_TO_JVAL("registration"), jstring_create(telephony_network_registration_to_string(net_status->registration))); jobject_put(extended_obj, J_CSTR_TO_JVAL("networkName"), jstring_create(net_status->name != NULL ? net_status->name : "")); jobject_put(extended_obj, J_CSTR_TO_JVAL("causeCode"), jstring_create("")); 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
int telephonyservice_common_finish(const struct telephony_error *error, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success)); if (!success) jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(error->code)); 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
bool _service_is_telephony_ready_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct telephony_service *service = user_data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool subscribed = false; reply_obj = jobject_create(); extended_obj = jobject_create(); subscribed = luna_service_check_for_subscription_and_process(handle, message); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success")); jobject_put(extended_obj, J_CSTR_TO_JVAL("radioConnected"), jboolean_create(service->initialized)); jobject_put(extended_obj, J_CSTR_TO_JVAL("power"), jboolean_create(service->powered)); jobject_put(extended_obj, J_CSTR_TO_JVAL("ready"), jboolean_create(service->initialized)); jobject_put(extended_obj, J_CSTR_TO_JVAL("networkRegistered"), jboolean_create(service->network_registered)); jobject_put(extended_obj, J_CSTR_TO_JVAL("dataRegistered"), jboolean_create(service->data_registered)); /* FIXME check in which situations the three fields below are set and updated */ jobject_put(extended_obj, J_CSTR_TO_JVAL("emergency"), jboolean_create(false)); jobject_put(extended_obj, J_CSTR_TO_JVAL("security"), jboolean_create(false)); jobject_put(extended_obj, J_CSTR_TO_JVAL("securityLocked"), jboolean_create(false)); jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj); jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed)); if(!luna_service_message_validate_and_send(handle, message, reply_obj)) luna_service_message_reply_error_internal(handle, message); j_release(&reply_obj); return true; }
bool service_check_for_update_cb(LSHandle *handle, LSMessage *message, void *user_data) { int err = 0; struct package_list_info plistinfo; GSList *iter; jvalue_ref reply_obj = NULL; if (opkg_new()) { luna_service_message_reply_error_internal(handle, message); return true; } err = opkg_update_package_lists(NULL, NULL); if (err != 0) { luna_service_message_reply_custom_error(handle, message, "Failed to update package list from configured feeds"); 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)); jobject_put(reply_obj, J_CSTR_TO_JVAL("updatesAvailable"), jboolean_create(g_slist_length(plistinfo.pkgs) > 0)); 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; }
int _service_power_query_finish(const struct telephony_error *error, bool power, void *data) { struct luna_service_req_data *req_data = data; jvalue_ref reply_obj = NULL; jvalue_ref extended_obj = NULL; bool success = (error == NULL); reply_obj = jobject_create(); extended_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success)); /* handle possible subscriptions */ if (req_data->subscribed) jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed)); if (success) { jobject_put(extended_obj, J_CSTR_TO_JVAL("powerState"), jstring_create(power ? "on" : "off")); jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj); } else { /* FIXME better error message */ luna_service_message_reply_error_unknown(req_data->handle, req_data->message); goto cleanup; } 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: j_release(&reply_obj); luna_service_req_data_free(req_data); return 0; }
/** * @brief Subscribe for a specific group of events * * JSON format: * {"events":"<type>"} **/ bool _service_subscribe_cb(LSHandle *handle, LSMessage *message, void *user_data) { jvalue_ref parsed_obj = NULL; jvalue_ref events_obj = NULL; jvalue_ref reply_obj = NULL; bool result = false; LSError lserror; const char *payload; bool subscribed = false; 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("events"), &events_obj)) { luna_service_message_reply_error_invalid_params(handle, message); goto cleanup; } if (jstring_equal2(events_obj, J_CSTR_TO_BUF("network"))) { result = LSSubscriptionAdd(handle, "/networkStatusQuery", message, &lserror); if (!result) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); luna_service_message_reply_error_internal(handle, message); goto cleanup; } subscribed = true; } else if (jstring_equal2(events_obj, J_CSTR_TO_BUF("signal"))) { result = LSSubscriptionAdd(handle, "/signalStrengthQuery", message, &lserror); if (!result) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); luna_service_message_reply_error_internal(handle, message); goto cleanup; } subscribed = true; } reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0)); jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success")); jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed)); if (!luna_service_message_validate_and_send(handle, message, reply_obj)) { luna_service_message_reply_error_internal(handle, message); goto cleanup; } cleanup: j_release(&parsed_obj); return true; }
bool service_retrieve_package_info_cb(LSHandle *handle, LSMessage *message, void *user_data) { jvalue_ref reply_obj; jvalue_ref parsed_obj; jvalue_ref name_obj; jvalue_ref depends_obj; jvalue_ref recommends_obj; jvalue_ref conflicts_obj; pkg_t *package = NULL; const char *payload = NULL; const char *pkgname = NULL; raw_buffer name_buf; int n; 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); return true; } if (!jobject_get_exists(parsed_obj, J_CSTR_TO_BUF("name"), &name_obj)) { luna_service_message_reply_error_bad_json(handle, message); return true; } if (opkg_new()) { luna_service_message_reply_error_internal(handle, message); return true; } name_buf = jstring_get(name_obj); package = opkg_find_package(name_buf.m_str, NULL, NULL, NULL); if (!package) { luna_service_message_reply_custom_error(handle, message, "Package does not exist"); goto cleanup; } set_flags_from_control(package); reply_obj = jobject_create(); jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); jobject_put(reply_obj, J_CSTR_TO_JVAL("version"), jstring_create(package->version ? package->version : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("revision"), jstring_create(package->revision ? package->revision : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("architecture"), jstring_create(package->architecture ? package->architecture : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("section"), jstring_create(package->section ? package->section : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("maintainer"), jstring_create(package->maintainer ? package->maintainer : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("description"), jstring_create(package->description ? package->description : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("tags"), jstring_create(package->tags ? package->tags : "")); jobject_put(reply_obj, J_CSTR_TO_JVAL("size"), jnumber_create_i32(package->size)); jobject_put(reply_obj, J_CSTR_TO_JVAL("installed_size"), jnumber_create_i32(package->installed_size)); jobject_put(reply_obj, J_CSTR_TO_JVAL("auto_installed"), jboolean_create(package->auto_installed > 0 ? true : false)); if (!luna_service_message_validate_and_send(handle, message, reply_obj)) { luna_service_message_reply_error_internal(handle, message); goto cleanup; } cleanup: opkg_free(); return true; }
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; }