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; }
int dom_number(JSAXContextRef ctxt, const char *number, size_t numberLen) { DomInfo *data = getDOMContext(ctxt); jvalue_ref jnum; CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "number encountered without any context"); CHECK_CONDITION_RETURN_VALUE(data->m_prev == NULL, 0, "unexpected state - how is this possible?"); CHECK_POINTER_RETURN_VALUE(number, 0); CHECK_CONDITION_RETURN_VALUE(numberLen == 0, 0, "unexpected - numeric string doesn't actually contain a number"); jnum = createOptimalNumber(data->m_optInformation, number, numberLen); if (data->m_value == NULL) { if (UNLIKELY(!jis_array(data->m_prev->m_value))) { PJ_LOG_ERR("PBNJSON_ARR_MISPLACED_NUM", 1, PMLOGKS("NUM", number), "Improper place for number"); j_release(&jnum); return 0; } jarray_append(data->m_prev->m_value, jnum); } else if (jis_string(data->m_value)) { if (UNLIKELY(!jis_object(data->m_prev->m_value))) { PJ_LOG_ERR("PBNJSON_OBJ_MISPLACED_NUM", 1, PMLOGKS("NUM", number), "Improper place for number"); j_release(&jnum); return 0; } jobject_put(data->m_prev->m_value, data->m_value, jnum); data->m_value = NULL; } else { PJ_LOG_ERR("PBNJSON_NUM_VALUE_WO_KEY", 1, PMLOGKS("NUM", number), "value portion of key-value pair without a key"); return 0; } return 1; }
static int __number(JSAXContextRef ctxt, const char *number, size_t len) { JParser *p = static_cast<JParser *>(jsax_getContext(ctxt)); switch (SaxBounce::conversionToUse(p)) { case JParser::JNUM_CONV_RAW: return SaxBounce::n(p, std::string(number, len)); case JParser::JNUM_CONV_NATIVE: { jvalue_ref toConv = jnumber_create_unsafe(j_str_to_buffer(number, len), NULL); int64_t asInteger; double asFloat; ConversionResultFlags toFloatErrors; if (CONV_OK == jnumber_get_i64(toConv, &asInteger)) { j_release(&toConv); return SaxBounce::n(p, (asInteger)); } toFloatErrors = jnumber_get_f64(toConv, &asFloat); j_release(&toConv); return SaxBounce::n(p, asFloat, toFloatErrors); } default: PJ_LOG_ERR("PBNJSON_NO_NUMS_TYPE", 0, "Actual parser hasn't told us a valid type for how it wants numbers presented to it"); return 0; } }
int dom_string(JSAXContextRef ctxt, const char *string, size_t stringLen) { DomInfo *data = getDOMContext(ctxt); CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "string encountered without any context"); CHECK_CONDITION_RETURN_VALUE(data->m_prev == NULL, 0, "unexpected state - how is this possible?"); jvalue_ref jstr = createOptimalString(data->m_optInformation, string, stringLen); if (data->m_value == NULL) { if (UNLIKELY(!jis_array(data->m_prev->m_value))) { PJ_LOG_ERR("PBNJSON_ARR_MISPLACED_STR", 1, PMLOGKS("STRING", string), "Improper place for string"); j_release(&jstr); return 0; } jarray_append(data->m_prev->m_value, jstr); } else if (jis_string(data->m_value)) { if (UNLIKELY(!jis_object(data->m_prev->m_value))) { PJ_LOG_ERR("PBNJSON_OBJ_MISPLACED_STR", 1, PMLOGKS("STRING", string), "Improper place for string"); j_release(&jstr); return 0; } jobject_put(data->m_prev->m_value, data->m_value, jstr); data->m_value = NULL; } else { PJ_LOG_ERR("PBNJSON_STR_VALUE_WO_KEY", 1, PMLOGKS("STRING", string), "value portion of key-value pair without a key"); return 0; } return 1; }
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_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; }
static Validator* set_default(Validator *v, jvalue_ref def_value) { ArrayValidator *a = (ArrayValidator *) v; j_release(&a->def_value); a->def_value = jvalue_copy(def_value); return v; }
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 int dom_object_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 = jobject_create(); newChild = calloc(1, sizeof(DomInfo)); if (UNLIKELY(newChild == NULL || jis_null(newParent))) { PJ_LOG_ERR("Failed to allocate space for new object"); 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)); CHECK_CONDITION_RETURN_VALUE(!jis_string(data->m_value), 0, "improper place for a child object"); jobject_put(data->m_prev->m_value, data->m_value, newParent); } } // not using reference counting here on purpose data->m_value = newParent; return 1; }
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; }
void telephony_service_network_status_changed_notify(struct telephony_service *service, struct telephony_network_status *net_status) { jvalue_ref reply_obj = NULL; jvalue_ref network_obj = NULL; if (service->power_off_pending) return; reply_obj = jobject_create(); network_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("")); service->network_registered = (net_status->state == TELEPHONY_NETWORK_STATE_SERVICE); jobject_put(network_obj, J_CSTR_TO_JVAL("state"), jstring_create(telephony_network_state_to_string(net_status->state))); jobject_put(network_obj, J_CSTR_TO_JVAL("registration"), jstring_create(telephony_network_registration_to_string(net_status->registration))); jobject_put(network_obj, J_CSTR_TO_JVAL("networkName"), jstring_create(net_status->name != NULL ? net_status->name : "")); jobject_put(network_obj, J_CSTR_TO_JVAL("causeCode"), jstring_create("")); jobject_put(reply_obj, J_CSTR_TO_JVAL("eventNetwork"), network_obj); luna_service_post_subscription(service->private_service, "/", "networkStatusQuery", reply_obj); j_release(&reply_obj); }
static bool set_mic_mute_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct audio_service *service = user_data; const char *payload; jvalue_ref parsed_obj = NULL; struct luna_service_req_data *req; pa_operation *op; 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; } service->mic_mute = luna_service_message_get_boolean(parsed_obj, "micMute", service->mic_mute); req = luna_service_req_data_new(handle, message); req->user_data = service; op = pa_context_get_source_info_list(service->context, mm_sourceinfo_cb, req); pa_operation_unref(op); cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
static Validator* set_default(Validator *validator, jvalue_ref def_value) { NumberValidator *v = (NumberValidator *) validator; j_release(&v->def_value); v->def_value = jvalue_copy(def_value); return validator; }
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; }
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 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; }
static bool play_feedback_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct audio_service *service = user_data; struct play_feedback_data *pfd; const char *payload; jvalue_ref parsed_obj; char *name, *sink; bool play; 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; } name = luna_service_message_get_string(parsed_obj, "name", NULL); if (!name) { luna_service_message_reply_custom_error(handle, message, "Invalid parameters: name parameter is required"); goto cleanup; } play = luna_service_message_get_boolean(parsed_obj, "play", true); sink = luna_service_message_get_string(parsed_obj, "sink", NULL); pfd = g_new0(struct play_feedback_data, 1); pfd->service = service; pfd->handle = handle; pfd->message = message; pfd->name = name; pfd->sink = sink; pfd->play = play; LSMessageRef(message); if (!preload_sample(service, pfd)) { luna_service_message_reply_custom_error(handle, message, "Could not preload sample"); LSMessageUnref(message); g_free(pfd); g_free(name); g_free(sink); goto cleanup; } 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; }
static void send_connection_status(jvalue_ref *reply) { if(NULL == reply) return; jobject_put(*reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); gboolean online = connman_manager_is_manager_online(manager); jobject_put(*reply, J_CSTR_TO_JVAL("isInternetConnectionAvailable"), jboolean_create(online)); jvalue_ref connected_wired_status = jobject_create(); jvalue_ref disconnected_wired_status = jobject_create(); jvalue_ref connected_wifi_status = jobject_create(); jvalue_ref disconnected_wifi_status = jobject_create(); jobject_put(disconnected_wired_status, J_CSTR_TO_JVAL("state"), jstring_create("disconnected")); jobject_put(disconnected_wifi_status, J_CSTR_TO_JVAL("state"), jstring_create("disconnected")); /* Get the service which is connecting or already in connected state */ connman_service_t *connected_wired_service = connman_manager_get_connected_service(manager->wired_services); if(NULL != connected_wired_service) { update_connection_status(connected_wired_service, &connected_wired_status); jobject_put(*reply, J_CSTR_TO_JVAL("wired"), connected_wired_status); j_release(&disconnected_wired_status); } else { jobject_put(*reply, J_CSTR_TO_JVAL("wired"), disconnected_wired_status); j_release(&connected_wired_status); } connman_service_t *connected_wifi_service = connman_manager_get_connected_service(manager->wifi_services); if(NULL != connected_wifi_service) { update_connection_status(connected_wifi_service, &connected_wifi_status); jobject_put(*reply, J_CSTR_TO_JVAL("wifi"), connected_wifi_status); j_release(&disconnected_wifi_status); } else { jobject_put(*reply, J_CSTR_TO_JVAL("wifi"), disconnected_wifi_status); j_release(&connected_wifi_status); } }
// Do not release original_ptr. It could be on a stack static void dom_cleanup(DomInfo *dom_info, DomInfo *original_ptr) { while (dom_info && dom_info != original_ptr) { DomInfo *cur_dom_info = dom_info; dom_info = dom_info->m_prev; j_release(&cur_dom_info->m_value); free(cur_dom_info); } }
void number_validator_release(NumberValidator *v) { if (v->expected_set) number_clear(&v->expected_value); if (v->min_set) number_clear(&v->min); if (v->max_set) number_clear(&v->max); j_release(&v->def_value); g_free(v); }
void array_validator_release(ArrayValidator *v) { if (v->items) array_items_unref(v->items); if (v->additional_items) validator_unref(v->additional_items); j_release(&v->def_value); g_free(v); }
int dom_object_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 = jobject_create(); newChild = calloc(1, sizeof(DomInfo)); if (UNLIKELY(newChild == NULL || !jis_valid(newParent))) { PJ_LOG_ERR("PBNJSON_OBJ_CALLOC_ERR", 0, "Failed to allocate space for new object"); 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, jvalue_copy(newParent)); } else { assert(jis_object(data->m_prev->m_value)); if (UNLIKELY(!jis_string(data->m_value))) { PJ_LOG_ERR("PBNJSON_OBJ_MISPLACED_CHILD", 0, "improper place for a child object"); j_release(&newParent); return 0; } jobject_put(data->m_prev->m_value, data->m_value, jvalue_copy(newParent)); } } data->m_value = newParent; return 1; }
static bool handle_get_info_command(LSHandle *sh, LSMessage *message, void* context) { jvalue_ref reply = jobject_create(); LSError lserror; LSErrorInit(&lserror); char wifi_mac_address[32]={0}, wired_mac_address[32]={0}; jobject_put(reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); if(get_wifi_mac_address(CONNMAN_WIFI_INTERFACE_NAME, wifi_mac_address) == 0) { jvalue_ref wifi_info = jobject_create(); jobject_put(wifi_info, J_CSTR_TO_JVAL("macAddress"),jstring_create(wifi_mac_address)); jobject_put(reply, J_CSTR_TO_JVAL("wifiInfo"), wifi_info); } else WCA_LOG_ERROR("Error in fetching mac address for wifi interface"); if(get_wifi_mac_address(CONNMAN_WIRED_INTERFACE_NAME, wired_mac_address) == 0) { jvalue_ref wired_info = jobject_create(); jobject_put(wired_info, J_CSTR_TO_JVAL("macAddress"),jstring_create(wired_mac_address)); jobject_put(reply, J_CSTR_TO_JVAL("wiredInfo"), wired_info); } else WCA_LOG_ERROR("Error in fetching mac address for wired interface"); jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!response_schema) { LSMessageReplyErrorUnknown(sh,message); goto cleanup; } if (!LSMessageReply(sh, message, jvalue_tostring(reply, response_schema), &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } jschema_release(&response_schema); cleanup: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } j_release(&reply); return true; }
JValue::ObjectIterator& JValue::ObjectIterator::operator=(const ObjectIterator &other) { if (this != &other) { _it = other._it; j_release(&_parent); _parent = jvalue_copy(other._parent); _key_value = other._key_value; _at_end = other._at_end; } return *this; }
JValue& JValue::operator=(const JValue& other) { if (m_jval != other.m_jval) { j_release(&m_jval); m_jval = jvalue_copy(other.m_jval); m_input = other.m_input; #if PBNJSON_ZERO_COPY_STL_STR m_children = other.m_children; #endif } return *this; }
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; }
/** * @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 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; }