static bool clientCancel(LSHandle *sh, LSMessage *message, void *ctx) { LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"clientCancelByName", LSMessageGetPayload(message), NULL,(void *)message, NULL, NULL); return true; }
bool AmbientLightSensor::cancelSubscription(LSHandle *sh, LSMessage *message, void *ctx) { bool result = false; g_debug ("%s: category %s, method %s", __FUNCTION__, LSMessageGetCategory(message), LSMessageGetMethod(message)); AmbientLightSensor *als = (AmbientLightSensor *)ctx; if (0 == strcmp (LSMessageGetMethod(message), "status") && 0 == strcmp (LSMessageGetCategory(message), "/control")) { als->m_alsSubscriptions--; if (als->m_alsSubscriptions == 0) { bool disable = false; const char* str = LSMessageGetPayload(message); if (str) { json_object* root = json_tokener_parse(str); if (root && !is_error(root)) { result = true; disable = json_object_get_boolean(json_object_object_get(root, "disableALS")); json_object_put(root); } } if (result && disable) als->m_alsDisabled--; als->off (); } } return true; }
static bool shutdownServicesAck(LSHandle *sh, LSMessage *message, void *user_data) { struct json_object *object = json_tokener_parse( LSMessageGetPayload(message)); if (is_error(object)) { LSMessageReplyErrorBadJSON(sh, message); goto cleanup; } const char *clientId = json_object_get_string( json_object_object_get(object, "clientId")); if (!clientId) { LSMessageReplyErrorInvalidParams(sh, message); goto cleanup; } ShutdownEvent event; event.id = kShutdownEventAck; event.client = client_lookup_service(clientId); shutdown_state_dispatch(&event); cleanup: if (!is_error(object)) json_object_put(object); return true; }
/** * @brief Shutdown the machine forcefully by calling "tellbootie" * * @param sh * @param message with "reason" field for shutdown reason. * @param user_data */ static bool machineOff(LSHandle *sh, LSMessage *message, void *user_data) { struct json_object *object = json_tokener_parse( LSMessageGetPayload(message)); if (is_error(object)) { LSMessageReplyErrorBadJSON(sh, message); goto cleanup; } const char *reason = json_object_get_string( json_object_object_get(object, "reason")); if (!reason) { LSMessageReplyErrorInvalidParams(sh, message); goto cleanup; } MachineForceShutdown(reason); LSMessageReplySuccess(sh, message); cleanup: if (!is_error(object)) json_object_put(object); return true; }
bool InputManager::activityStartCallback(LSHandle* handle, LSMessage* msg, void* userData) { struct json_object* retValObj = NULL; bool retVal = false; const char* msgStr = LSMessageGetPayload(msg); struct json_object* respObj = json_tokener_parse(msgStr); if (is_error(respObj)) { g_message("%s: Unable to parse JSON response: %s\n", __PRETTY_FUNCTION__, msgStr); goto Exit; } retValObj = json_object_object_get(respObj, "returnValue"); if (NULL == retValObj) { g_message("%s: Unable to get returnValue from: %s", __PRETTY_FUNCTION__, msgStr); goto Exit; } retVal = json_object_get_boolean(retValObj); if (!retVal) { g_message("%s: error response: %s", __PRETTY_FUNCTION__, msgStr); } Exit: if (!is_error(respObj)) json_object_put(respObj); return true; }
bool EASPolicyManager::cbSecurityPolicy (LSHandle *sh, LSMessage *message, void *data) { const char* str = LSMessageGetPayload(message); json_object *root = 0, *results = 0, *policy = 0; if (!str) goto done; root = json_tokener_parse(str); if (!root || is_error(root)) goto done; results = json_object_object_get (root, "results"); if (!results) { g_debug ("No security policies set, no processing needed"); goto done; } EASPolicyManager::instance()->updateDevicePolicy (results); done: if (root && !is_error(root)) json_object_put (root); return true; }
bool getFilecacheType_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); if (access_denied(message)) return true; char filename[MAXLINLEN]; // Extract the id argument from the message json_t *object = json_parse_document(LSMessageGetPayload(message)); json_t *type = json_find_first_label(object, "type"); if (!type || (type->child->type != JSON_STRING) || (strspn(type->child->text, ALLOWED_CHARS) != strlen(type->child->text))) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing type\"}", &lserror)) goto error; return true; } sprintf(filename, "/etc/palm/filecache_types/%s", type->child->text); return read_file(message, filename, true); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
bool WindowServerLuna::cbFullEraseCallback(LSHandle* handle, LSMessage* msg, void* data) { bool success = false; const char* str = LSMessageGetPayload(msg); if (str) { json_object* root = json_tokener_parse(str); if (root && !is_error(root)) { json_object* prop = json_object_object_get(root, "returnValue"); if (prop && !is_error(prop)) { success = json_object_get_boolean(prop); } json_object_put(root); } } g_warning("%s: full erase successful? %d", __PRETTY_FUNCTION__, success); if (success) { exit(-2); } // in the outside case that the full erase fails, remove the full erase window // so the user can attempt it again WindowServerLuna* ws = reinterpret_cast<WindowServerLuna*>(data); ws->m_fullErasePending = false; ws->m_powerVolumeKeyComboState.reset(); ws->cancelFullEraseCountdown(); return true; }
/** * @brief Called to re-register with powerd if powerd crashes. * * @param sh * @param msg * @param ctx * * @retval */ static bool _powerd_server_up(LSHandle *sh, LSMessage *msg, void *ctx) { bool connected; struct json_object *object = json_tokener_parse(LSMessageGetPayload(msg)); if (is_error(object)) goto error; connected = json_object_get_boolean( json_object_object_get(object, "connected")); if (connected) { g_debug("%s connected was true (powerd is already running)", __FUNCTION__); PowerdHandle *handle = PowerdGetHandle(); /* Send our name to powerd. */ SendMessage(_identify_callback, "luna://com.palm.power/com/palm/power/identify", "{\"subscribe\":true,\"clientName\":\"%s\"}", handle->clientName); } end: if (!is_error(object)) json_object_put(object); return true; error: g_critical("%s: Error registering with com.palm.power", __FUNCTION__); goto end; }
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 bool shutdownServicesRegister(LSHandle *sh, LSMessage *message, void *user_data) { struct json_object *object = json_tokener_parse(LSMessageGetPayload(message)); if (is_error(object)) goto end; const char *clientId = LSMessageGetUniqueToken(message); const char *clientName = json_object_get_string(json_object_object_get( object, "clientName")); client_new_service(clientId, clientName); bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSSubscriptionAdd(sh, "shutdownClient", message, &lserror); if (!retVal) { g_critical("LSSubscriptionAdd failed."); LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } send_reply(sh, message, "{\"clientId\":\"%s\"}", clientId); json_object_put(object); end: return true; }
bool InputManager::processKeyState(LSHandle* handle, LSMessage* msg, void* userData) { // {"get": string} VALIDATE_SCHEMA_AND_RETURN(handle, msg, SCHEMA_1(REQUIRED(get, string))); bool success = false; const char* keyString = NULL; QEvent::Type state = QEvent::None; LSError err; json_object* root = 0; LSErrorInit(&err); // get the text name of the key const char* str = LSMessageGetPayload(msg); if (!str) { g_debug("%s: Unable to get JSON payload from message", __PRETTY_FUNCTION__); return false; } root = json_tokener_parse(str); if (root && !is_error(root)) { // Get the key name from the msg -- the format will be {"get":"NAME"}, // where NAME is something like ringer, slider, etc keyString = json_object_get_string(json_object_object_get(root, "get")); if (keyString) { // lookup the state of the key Qt::Key key = stringToKey(keyString); state = getKeyState(key); success = true; } } json_object* response = 0; if (success) { response = createKeyJson(keyString, state); } else { response = json_object_new_object(); } json_object_object_add(response, "returnValue", json_object_new_boolean(success)); if (!LSMessageReply(handle, msg, json_object_to_json_string(response), &err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } if (root && !is_error(root)) json_object_put(root); json_object_put(response); return true; }
/** * @brief Turn on/off visual leds suspend via luna-service. * * @retval */ bool visualLedSuspendCallback(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"visualLedSuspend", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
/** * @brief Start an activity. */ bool activityStartCallback(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"activityStart", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
/** * @brief Called by test code to reset state machine to square 1. * * @retval */ static bool TESTresetShutdownState(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"TESTresetShutdownState", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); return true; }
bool prepareSuspendRegister(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"prepareSuspendRegister", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
static bool listContactsHandler(LSHandle *sh, LSMessage *reply, void *ctx) { printf("Got reply: %s\n", LSMessageGetPayload(reply)); if (!LSMessageIsHubErrorMessage(reply)) hit_reply = TRUE; g_main_loop_quit((GMainLoop *) ctx); return TRUE; }
/** * @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 Ack the "shutdownApplications" signal. */ static bool shutdownApplicationsAck(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownApplicationsAck", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); return true; }
static bool alarmRemove(LSHandle *sh, LSMessage *message, void *ctx) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmRemove", LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL); return true; }
static bool _identify_callback(LSHandle *sh, LSMessage *msg, void *ctx) { struct json_object * object = json_tokener_parse(LSMessageGetPayload(msg)); if (is_error(object)) goto error; bool subscribed = json_object_get_boolean( json_object_object_get(object, "subscribed")); const char *clientId = json_object_get_string( json_object_object_get(object, "clientId")); if (!subscribed || !clientId) { g_critical("%s: Could not subscribe to powerd %s.", __FUNCTION__, LSMessageGetPayload(msg)); goto end; } PowerdHandle *handle = PowerdGetHandle(); PowerdSetClientId(handle, clientId); char *message = g_strdup_printf( "{\"register\":true,\"clientId\":\"%s\"}", clientId); if (handle->suspendRequestRegistered) { SendMessage(NULL, "luna://" POWERD_IPC_NAME POWERD_DEFAULT_CATEGORY "suspendRequestRegister", message); } if (handle->prepareSuspendRegistered) { SendMessage(NULL, "luna://" POWERD_IPC_NAME POWERD_DEFAULT_CATEGORY "prepareSuspendRegister", message); } g_free(message); error: end: if (!is_error(object)) json_object_put(object); return true; }
/** * @brief Add a new alarm based on calender time. Sets the callback function based on the "subscribe" option value. */ static bool alarmAddCalendar(LSHandle *sh, LSMessage *message, void *ctx) { struct json_object *object=NULL; object = json_tokener_parse(LSMessageGetPayload(message)); if ( is_error(object) ) { goto malformed_json; } struct json_object *subscribe_json = json_object_object_get(object, "subscribe"); bool subscribe = json_object_get_boolean(subscribe_json); LSMessageRef(message); if(subscribe) { struct context *alrm_ctx=NULL; alrm_ctx = malloc(sizeof(struct context)); if(!alrm_ctx) goto error; memset(alrm_ctx,0,sizeof(struct context)); alrm_ctx->replyMessage = message; LSCall(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender", LSMessageGetPayload(message), alarms_timeout_subscribe_cb, (void *)alrm_ctx, &alrm_ctx->call_token, NULL); } else LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender", LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL); goto cleanup; malformed_json: LSMessageReplyErrorBadJSON(sh, message); goto cleanup; error: POWERDLOG(LOG_ERR,"Failed to allocate memory"); LSMessageReplyErrorUnknown(sh, message); cleanup: if (!is_error(object)) json_object_put(object); 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 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; }
static bool alarms_timeout_subscribe_cb(LSHandle *sh, LSMessage *message, void *ctx) { bool retVal; bool fired = false; struct context *alrm_ctx = (struct context *)ctx; const char *payload = LSMessageGetPayload(message); struct json_object *object = json_tokener_parse(payload); if (is_error(object)) { POWERDLOG(LOG_CRIT,"%s: invalid json from sleep daemon",__func__); } else { fired = json_object_get_boolean(json_object_object_get(object, "fired")); } POWERDLOG(LOG_INFO,"%s: response with payload %s, count : %d", __FUNCTION__, payload, alrm_ctx->count); if(alrm_ctx->replyMessage) { if(fired) { retVal = LSMessageReply(GetLunaServiceHandle(), alrm_ctx->replyMessage, payload, NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } } else if(LSMessageGetConnection(alrm_ctx->replyMessage)) { retVal = LSMessageReply(LSMessageGetConnection(alrm_ctx->replyMessage), alrm_ctx->replyMessage, payload, NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } } alrm_ctx->count++; } else POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__); if(alrm_ctx->count == 2) { if(!LSCallCancel(sh, alrm_ctx->call_token, NULL)) { POWERDLOG(LOG_WARNING, "%s could not cancel luna-service alarm call.", __FUNCTION__); } LSMessageUnref(alrm_ctx->replyMessage); free(alrm_ctx); } if (!is_error(object)) json_object_put(object); return true; }
// // Return a polite response. // Called directly from webOS, and returns directly to webOS. // bool set_debug_log_method(LSHandle* lshandle, LSMessage *message, void *ctx) { log("set_debug_log_method"); LSError lserror; LSErrorInit(&lserror); // Extract the id argument from the message json_t *object = json_parse_document(LSMessageGetPayload(message)); json_t *enableDebugLogging = json_find_first_label(object, "enableDebugLogging"); if(enableDebugLogging) { if(enableDebugLogging->child->type == JSON_TRUE) { log("enableDebugLogging: JSON_TRUE"); g_debugLoggingEnabled = true; } else if(enableDebugLogging->child->type == JSON_FALSE) { log("enableDebugLogging: JSON_FALSE"); g_debugLoggingEnabled = false; remove(LOG_FILE); } else { log("enableDebugLogging: %d", enableDebugLogging->child->type); } } else { if (!LSMessageReply(lshandle, message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing parameters\"}", &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return false; } } // Local buffer to store the reply char reply[MAXLINLEN]; sprintf(reply, "{\"returnValue\": true, \"debugLoggingEnabled\": %s}", g_debugLoggingEnabled ? "true" : "false"); log(reply); if (!LSMessageReply(lshandle, message, reply, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return false; } return true; }
static bool FilecacheServiceCb(LSHandle *sh, LSMessage *message, void *ctx) { printf("got callback\n"); LSMessagePrint(message, stdout); jsonResponseStr = LSMessageGetPayload(message); handledResponse = true; //waiter_signal(&response_waiter); return true; }
static bool suspend_ipc_method_cb(LSHandle *sh, LSMessage *message, void *ctx) { bool retVal; LSMessage *replyMessage = (LSMessage *)ctx; POWERDLOG(LOG_INFO,"%s: response with payload %s", __FUNCTION__, LSMessageGetPayload(message)); if(replyMessage && LSMessageGetConnection(replyMessage)) { retVal = LSMessageReply(LSMessageGetConnection(replyMessage), replyMessage, LSMessageGetPayload(message), NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } LSMessageUnref(replyMessage); } else POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__); return true; }
/** * @brief Convenience function to pretty print a message. * * @param lmsg * @param out * * @retval */ bool LSMessagePrint(LSMessage *message, FILE *out) { _LSErrorIfFail(NULL != message, NULL); fprintf(out, "%s/%s <%s>\n", LSMessageGetCategory(message), LSMessageGetMethod(message), LSMessageGetPayload(message)); return true; }
/** * @brief Register a new client. */ bool identifyCallback(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"identify", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); struct json_object *object = json_tokener_parse(LSMessageGetPayload(message)); if ( is_error(object) ) { goto out; } bool subscribe = json_object_get_boolean(json_object_object_get(object, "subscribe")); if (subscribe) { LSSubscriptionAdd(sh, "PowerdClients", message, NULL); } out: return true; }