/** * @brief Set the network the modem should connect to. * * JSON format: * request: * { * "automatic": <boolean>, * "id": <string>, * } * response: * { * "returnValue": <boolean>, * "errorCode": <integer>, * "errorString": <string>, * } **/ bool _service_network_set_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct telephony_service *service = user_data; struct luna_service_req_data *req_data = NULL; jvalue_ref parsed_obj = NULL; jvalue_ref automatic_obj = NULL; jvalue_ref id_obj = NULL; const char *payload; raw_buffer id_buf; const char *id = NULL; bool automatic = false; if (!service->initialized) { luna_service_message_reply_custom_error(handle, message, "Backend not initialized"); return true; } if (!service->driver || !service->driver->network_set) { g_warning("No implementation available for service networkSet API method"); luna_service_message_reply_error_not_implemented(handle, message); goto cleanup; } 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("automatic"), &automatic_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } jboolean_get(automatic_obj, &automatic); if (!automatic) { if (!jobject_get_exists(parsed_obj, J_CSTR_TO_BUF("id"), &id_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } id_buf = jstring_get(id_obj); id = id_buf.m_str; } req_data = luna_service_req_data_new(handle, message); service->driver->network_set(service, automatic, id, telephonyservice_common_finish, req_data); cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
/** * @brief If message contains subscribe:true, add the message to subscription list using the default key '/category/method'. * * This is equivalent to LSSubscriptionAdd(sh, key, message, lserror) * where the key is LSMessageGetKind(message). * * @param sh * @param message * @param subscribed * @param lserror * * @retval */ bool LSSubscriptionProcess (LSHandle *sh, LSMessage *message, bool *subscribed, LSError *lserror) { JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); bool retVal = false; bool subscribePayload = false; jvalue_ref subObj = NULL; const char *payload = LSMessageGetPayload(message); jvalue_ref object = jdom_parse(j_cstr_to_buffer(payload), DOMOPT_NOOPT, &schemaInfo); if (jis_null(object)) { _LSErrorSet(lserror, MSGID_LS_INVALID_JSON, -1, "Unable to parse JSON: %s", payload); goto exit; } if (!jobject_get_exists(object, J_CSTR_TO_BUF("subscribe"), &subObj) || subObj == NULL || !jis_boolean(subObj)) { subscribePayload = false; /* FIXME: I think retVal should be false, but I don't know if anyone * is relying on this behavior. If set to false, make sure to set * LSError */ retVal = true; } else { (void)jboolean_get(subObj, &subscribePayload);/* TODO: handle appropriately */ retVal = true; } if (subscribePayload) { const char *key = LSMessageGetKind(message); retVal = LSSubscriptionAdd(sh, key, message, lserror); } if (retVal && subscribePayload) { *subscribed = true; } else { *subscribed = false; } exit: j_release(&object); return retVal; }
bool luna_service_message_get_boolean(jvalue_ref parsed_obj, const char *name, bool default_value) { jvalue_ref boolean_obj; bool value; if (!jobject_get_exists(parsed_obj, j_str_to_buffer(name, strlen(name)), &boolean_obj) || !jis_boolean(boolean_obj)) return default_value; jboolean_get(boolean_obj, &value); return value; }
int luna_service_message_get_int(jvalue_ref parsed_obj, const char *name, int default_value) { jvalue_ref int_obj = NULL; int value = 0; if (!jobject_get_exists(parsed_obj, j_str_to_buffer(name, strlen(name)), &int_obj) || !jis_number(int_obj)) return default_value; jnumber_get_i32(int_obj, &value); return value; }
char* luna_service_message_get_string(jvalue_ref parsed_obj, const char *name, const char *default_value) { jvalue_ref string_obj = NULL; raw_buffer string_buf; if (!jobject_get_exists(parsed_obj, j_str_to_buffer(name, strlen(name)), &string_obj) || !jis_string(string_obj)) return g_strdup(default_value); string_buf = jstring_get(string_obj); return g_strdup(string_buf.m_str); }
/** * @brief Set the radio access technology mode * * JSON format: * request: * { * "mode": <string>, * } * response: * { * "returnValue": <boolean>, * "errorCode": <integer>, * "errorString": <string>, * } **/ bool _service_rat_set_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct telephony_service *service = user_data; struct luna_service_req_data *req_data = NULL; jvalue_ref parsed_obj = NULL; jvalue_ref mode_obj = NULL; const char *payload; raw_buffer mode_buf; enum telephony_radio_access_mode mode; if (!service->initialized) { luna_service_message_reply_custom_error(handle, message, "Backend not initialized"); return true; } if (!service->driver || !service->driver->rat_set) { g_warning("No implementation available for service ratSet API method"); luna_service_message_reply_error_not_implemented(handle, message); goto cleanup; } 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("mode"), &mode_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } mode_buf = jstring_get(mode_obj); mode = telephony_radio_access_mode_from_string(mode_buf.m_str); if (mode < 0) { luna_service_message_reply_error_invalid_params(handle, message); goto cleanup; } req_data = luna_service_req_data_new(handle, message); service->driver->rat_set(service, mode, telephonyservice_common_finish, req_data); cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
static bool set_volume_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct audio_service *service = user_data; const char *payload; jvalue_ref parsed_obj = NULL; jvalue_ref volume_obj = NULL; struct luna_service_req_data *req; int new_volume = 0; if (!service->context_initialized) { luna_service_message_reply_custom_error(handle, message, "Not yet initialized"); return true; } 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("volume"), &volume_obj) || !jis_number(volume_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } jnumber_get_i32(volume_obj, &new_volume); if (new_volume < 0 || new_volume > 100) { luna_service_message_reply_custom_error(handle, message, "Volume out of range. Must be in [0;100]"); goto cleanup; } if (service->new_volume == service->volume) { luna_service_message_reply_custom_error(handle, message, "Provided volume doesn't differ from current one"); goto cleanup; } req = luna_service_req_data_new(handle, message); req->user_data = service; set_volume(service, service->new_volume, req); cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
bool _CatalogHandleCancel(_Catalog *catalog, LSMessage *cancelMsg, LSError *lserror) { JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); const char *sender; int token; jvalue_ref tokenObj = NULL; const char *payload = LSMessageGetPayload(cancelMsg); jvalue_ref object = jdom_parse(j_cstr_to_buffer(payload), DOMOPT_NOOPT, &schemaInfo); if (jis_null(object)) { _LSErrorSet(lserror, MSGID_LS_INVALID_JSON, -EINVAL, "Invalid json"); goto error; } sender = LSMessageGetSender(cancelMsg); if (!jobject_get_exists(object, J_CSTR_TO_BUF("token"), &tokenObj) || tokenObj == NULL || !jis_number(tokenObj)) { _LSErrorSet(lserror, MSGID_LS_INVALID_JSON, -EINVAL, "Invalid json"); goto error; } (void)jnumber_get_i32(tokenObj, &token);/* TODO: handle appropriately */ char *uniqueToken = g_strdup_printf("%s.%d", sender, token); _CatalogCallCancelNotifications(catalog, uniqueToken); _CatalogRemoveToken(catalog, uniqueToken, true); g_free(uniqueToken); j_release(&object); return true; error: j_release(&object); return false; }
/** ******************************************************************************* * @brief Get the service name from a "ServceStatus" message. The name is * allocated and should be freed. * * @param message IN message * * @retval name string on success * @retval NULL on error ******************************************************************************* */ char* LSTransportServiceStatusSignalGetServiceName(_LSTransportMessage *message) { JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); LS_ASSERT(_LSTransportMessageGetType(message) == _LSTransportMessageTypeServiceDownSignal || _LSTransportMessageGetType(message) == _LSTransportMessageTypeServiceUpSignal); char *service_name = NULL; jvalue_ref service_name_obj = NULL; const char *payload = _LSTransportMessageGetPayload(message); if (!payload) { LOG_LS_ERROR(MSGID_LS_INVALID_JSON, 0, "Unable to get payload from message"); return NULL; } /* get the serviceName part of the JSON object */ jvalue_ref payload_json = jdom_parse(j_cstr_to_buffer(payload), DOMOPT_NOOPT, &schemaInfo); bool ret = jobject_get_exists(payload_json, J_CSTR_TO_BUF(SERVICE_STATUS_SERVICE_NAME), &service_name_obj); if (ret) { raw_buffer service_name_buf = jstring_get_fast(service_name_obj); service_name = g_strndup(service_name_buf.m_str, service_name_buf.m_len); } else { LOG_LS_ERROR(MSGID_LS_INVALID_JSON, 0, "Unable to get service name string from payload: %s", payload); } j_release(&payload_json); return service_name; }
static bool handle_set_state_command(LSHandle *sh, LSMessage *message, void* context) { if(!connman_status_check(manager, sh, message)) return true; jvalue_ref parsedObj = {0}; jschema_ref input_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!input_schema) return false; JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, input_schema, NULL, NULL); // no external refs & no error handlers parsedObj = jdom_parse(j_cstr_to_buffer(LSMessageGetPayload(message)), DOMOPT_NOOPT, &schemaInfo); jschema_release(&input_schema); if (jis_null(parsedObj)) { LSMessageReplyErrorBadJSON(sh, message); return true; } jvalue_ref wifiObj = {0}, wiredObj = {0}; gboolean enable_wifi = FALSE, enable_wired = FALSE; gboolean invalidArg = TRUE; if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("wifi"), &wifiObj)) { if (jstring_equal2(wifiObj, J_CSTR_TO_BUF("enabled"))) { enable_wifi = TRUE; } else if (jstring_equal2(wifiObj, J_CSTR_TO_BUF("disabled"))) { enable_wifi = FALSE; } else { goto invalid_params; } /* * Check if we are enabling an already enabled service, * or disabling an already disabled service */ if((enable_wifi && is_wifi_powered()) || (!enable_wifi && !is_wifi_powered())) { WCA_LOG_DEBUG("Wifi technology already enabled/disabled"); } else { set_wifi_state(enable_wifi); } invalidArg = FALSE; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("wired"), &wiredObj)) { if (jstring_equal2(wiredObj, J_CSTR_TO_BUF("enabled"))) { enable_wired = TRUE; } else if (jstring_equal2(wiredObj, J_CSTR_TO_BUF("disabled"))) { enable_wired = FALSE; } else { goto invalid_params; } /* * Check if we are enabling an already enabled service, * or disabling an already disabled service */ if((enable_wired && is_ethernet_powered()) || (!enable_wired && !is_ethernet_powered())) { WCA_LOG_DEBUG("Wired technology already enabled/disabled"); } else { set_ethernet_state(enable_wired); } invalidArg = FALSE; } if(invalidArg == TRUE) { goto invalid_params; } LSMessageReplySuccess(sh,message); goto cleanup; invalid_params: LSMessageReplyErrorInvalidParams(sh, message); cleanup: j_release(&parsedObj); return true; }
static bool handle_set_ipv4_command(LSHandle *sh, LSMessage *message, void* context) { if(!connman_status_check(manager, sh, message)) return true; jvalue_ref parsedObj = {0}; jschema_ref input_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!input_schema) return false; JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, input_schema, NULL, NULL); // no external refs & no error handlers parsedObj = jdom_parse(j_cstr_to_buffer(LSMessageGetPayload(message)), DOMOPT_NOOPT, &schemaInfo); jschema_release(&input_schema); if (jis_null(parsedObj)) { LSMessageReplyErrorBadJSON(sh, message); return true; } jvalue_ref ssidObj = {0}, methodObj = {0}, addressObj = {0}, netmaskObj = {0}, gatewayObj = {0}; ipv4info_t ipv4 = {0}; gchar *ssid = NULL; gboolean invalidArg = TRUE; if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("method"), &methodObj)) { raw_buffer method_buf = jstring_get(methodObj); ipv4.method = g_strdup(method_buf.m_str); jstring_free_buffer(method_buf); invalidArg = FALSE; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("address"), &addressObj)) { raw_buffer address_buf = jstring_get(addressObj); ipv4.address = g_strdup(address_buf.m_str); jstring_free_buffer(address_buf); invalidArg = FALSE; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("netmask"), &netmaskObj)) { raw_buffer netmask_buf = jstring_get(netmaskObj); ipv4.netmask = g_strdup(netmask_buf.m_str); jstring_free_buffer(netmask_buf); invalidArg = FALSE; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("gateway"), &gatewayObj)) { raw_buffer gateway_buf = jstring_get(gatewayObj); ipv4.gateway = g_strdup(gateway_buf.m_str); jstring_free_buffer(gateway_buf); invalidArg = FALSE; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("ssid"), &ssidObj)) { raw_buffer ssid_buf = jstring_get(ssidObj); ssid = g_strdup(ssid_buf.m_str); jstring_free_buffer(ssid_buf); invalidArg = FALSE; } if(invalidArg == TRUE) { LSMessageReplyErrorInvalidParams(sh, message); goto Exit; } connman_service_t *service = get_connman_service(ssid); if(NULL != service) { if(connman_service_set_ipv4(service, &ipv4)) LSMessageReplySuccess(sh, message); else LSMessageReplyErrorUnknown(sh, message); goto Exit; } else { LSMessageReplyCustomError(sh, message, "Network not found"); } Exit: g_free(ipv4.method); g_free(ipv4.address); g_free(ipv4.netmask); g_free(ipv4.gateway); g_free(ssid); j_release(&parsedObj); 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; }
/** * @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_power_set_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct telephony_service *service = user_data; struct luna_service_req_data *req_data = NULL; bool power = false; jvalue_ref parsed_obj = NULL; jvalue_ref state_obj = NULL; jvalue_ref save_obj = NULL; const char *payload; bool should_save = false; if (!service->initialized) { luna_service_message_reply_custom_error(handle, message, "Backend not initialized"); return true; } if (!service->driver || !service->driver->power_set) { g_warning("No implementation available for service powerSet API method"); luna_service_message_reply_error_not_implemented(handle, message); goto cleanup; } 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("state"), &state_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } if (jstring_equal2(state_obj, J_CSTR_TO_BUF("on"))) power = true; else if (jstring_equal2(state_obj, J_CSTR_TO_BUF("off"))) power = false; else if (jstring_equal2(state_obj, J_CSTR_TO_BUF("default"))) { power = true; } else { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } if (jobject_get_exists(parsed_obj, J_CSTR_TO_BUF("save"), &save_obj)) { jboolean_get(save_obj, &should_save); if (should_save) telephony_settings_store(TELEPHONY_SETTINGS_TYPE_POWER_STATE, power ? "{\"state\":true}" : "{\"state\":false}"); } service->power_off_pending = !power; req_data = luna_service_req_data_new(handle, message); req_data->user_data = service; service->driver->power_set(service, power, _service_power_set_finish, req_data); cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
bool JValue::hasKey(const std::string& key) const { return jobject_get_exists(m_jval, strToRawBuffer(key), NULL); }
static bool handle_set_dns_command(LSHandle *sh, LSMessage *message, void* context) { if(!connman_status_check(manager, sh, message)) return true; jvalue_ref parsedObj = {0}; jschema_ref input_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!input_schema) return false; JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, input_schema, NULL, NULL); // no external refs & no error handlers parsedObj = jdom_parse(j_cstr_to_buffer(LSMessageGetPayload(message)), DOMOPT_NOOPT, &schemaInfo); jschema_release(&input_schema); if (jis_null(parsedObj)) { LSMessageReplyErrorBadJSON(sh, message); return true; } jvalue_ref ssidObj = {0}, dnsObj = {0}; GStrv dns = NULL; gchar *ssid = NULL; if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("dns"), &dnsObj)) { int i, dns_arrsize = jarray_size(dnsObj); dns = (GStrv) g_new0(GStrv, 1); for(i = 0; i < dns_arrsize; i++) { raw_buffer dns_buf = jstring_get(jarray_get(dnsObj, i)); dns[i] = g_strdup(dns_buf.m_str); jstring_free_buffer(dns_buf); } } else { LSMessageReplyErrorInvalidParams(sh, message); goto Exit; } if(jobject_get_exists(parsedObj, J_CSTR_TO_BUF("ssid"), &ssidObj)) { raw_buffer ssid_buf = jstring_get(ssidObj); ssid = g_strdup(ssid_buf.m_str); jstring_free_buffer(ssid_buf); } connman_service_t *service = get_connman_service(ssid); if(NULL != service) { if(connman_service_set_nameservers(service, dns)) LSMessageReplySuccess(sh, message); else LSMessageReplyErrorUnknown(sh, message); goto Exit; } else LSMessageReplyCustomError(sh, message, "No connected network"); Exit: g_strfreev(dns); g_free(ssid); j_release(&parsedObj); return true; }