bool getMessages_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); char filename[MAXLINLEN]; strcpy(filename, "/var/log/messages"); return read_file(lshandle, message, filename, true); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static void SignalCancel(CBH *helper) { bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSCallCancel(gServiceHandle, helper->token, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } helper->token = 0; }
bool luna_service_check_for_subscription_and_process(LSHandle *handle, LSMessage *message) { LSError lserror; bool subscribed = false; LSErrorInit(&lserror); if (LSMessageIsSubscription(message)) { if (!LSSubscriptionProcess(handle, message, &subscribed, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } return subscribed; }
// callback static bool listContacts(LSHandle *sh, LSMessage *message, void *categoryContext) { bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSMessageReply(sh, message, "{ JSON REPLY PAYLOAD }", &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return retVal; }
bool clearMessages_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); char command[MAXLINLEN]; sprintf(command, "rm -rf /var/log/messages 2>&1"); return simple_command(lshandle, message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static void send_shutdown_services() { bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSSignalSend(GetLunaServiceHandle(), "luna://com.palm.sleep/shutdown/shutdownServices", "{}", &lserror); if (!retVal) { g_critical("%s Could not send shutdown applications", __FUNCTION__); LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } }
// // A dummy method, useful for unimplemented functions or as a status function. // Called directly from webOS, and returns directly to webOS. // bool dummy_method(LSHandle* lshandle, LSMessage *message, void *ctx) { log("dummy_method"); LSError lserror; LSErrorInit(&lserror); if (!LSMessageReply(lshandle, message, "{\"returnValue\": true}", &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return false; } return true; }
/** * @brief Add a new alarm to the queue. * * @param id * @param calendar_time * @param expiry * @param serviceName * @param applicationName * * @retval */ static bool alarm_queue_add(uint32_t id, const char *key, bool calendar_time, time_t expiry, const char *serviceName, const char *applicationName, bool subscribe, LSMessage *message) { _Alarm *alarm = g_new0(_Alarm, 1); alarm->key = g_strdup(key); alarm->id = id; alarm->calendar = calendar_time; alarm->expiry = expiry; alarm->serviceName = g_strdup(serviceName); alarm->applicationName = g_strdup(applicationName); if (subscribe) { LSError lserror; LSErrorInit(&lserror); bool retVal = LSSubscriptionAdd( GetLunaServiceHandle(), "alarm", message, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); goto error; } LSMessageRef(message); alarm->message = message; } alarm_print(alarm); if (alarm->id >= gAlarmQueue->seq_id) { gAlarmQueue->seq_id = alarm->id+1; } g_sequence_insert_sorted(gAlarmQueue->alarms, alarm, (GCompareDataFunc)alarm_cmp_func, NULL); update_alarms(); return true; error: return false; }
void WindowServerLuna::slotFullEraseDevice() { LSHandle* handle = SystemService::instance()->serviceHandle(); LSError err; LSErrorInit(&err); luna_assert(handle != 0); LSCall(handle, "palm://com.palm.storage/erase/EraseAll", "{}", &WindowServerLuna::cbFullEraseCallback, this, NULL, &err); if (LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } else { m_fullErasePending = true; } }
void luna_service_message_reply_custom_error(LSHandle *handle, LSMessage *message, const char *error_text) { bool ret; LSError lserror; char *payload; LSErrorInit(&lserror); payload = g_strdup_printf("{\"returnValue\":false, \"errorText\":\"%s\"}", error_text); ret = LSMessageReply(handle, message, payload, &lserror); if (!ret) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_free(payload); }
void HostArmPixie::getInitialSwitchStates() { LSError err; LSErrorInit(&err); if (!LSCall(m_service, HIDD_RINGER_URI, HIDD_GET_STATE, HostArm::switchStateCallback, (void*)SW_RINGER, NULL, &err)) goto Error; if (!LSCall(m_service, HIDD_HEADSET_URI, HIDD_GET_STATE, HostArm::switchStateCallback, (void*)SW_HEADPHONE_INSERT, NULL, &err)) goto Error; Error: if (LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } }
// // Run command to get Logging context level. // bool getLogging_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); // Local buffer to store the update command char command[MAXLINLEN]; // Store the command, so it can be used in the error report if necessary sprintf(command, "PmLogCtl show 2>&1"); return simple_command(lshandle, message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static int shutdown_init(void) { LSError lserror; LSErrorInit(&lserror); if (!LSRegisterCategory(GetLunaServiceHandle(), "/shutdown", shutdown_methods, NULL, NULL, &lserror)) { goto error; } return 0; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return -1; }
bool listConnections_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); if (access_denied(message)) return true; // Local buffer to store the command char command[MAXLINLEN]; sprintf(command, "cat /proc/net/nf_conntrack 2>&1"); return simple_command(message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
bool listFilecacheTypes_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); if (access_denied(message)) return true; // Local buffer to store the command char command[MAXLINLEN]; sprintf(command, "/bin/ls -1 /etc/palm/filecache_types/ 2>&1"); return simple_command(message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
bool listKeys_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); if (access_denied(message)) return true; // Local buffer to store the command char command[MAXLINLEN]; sprintf(command, "sqlite3 /var/palm/data/keys.db 'SELECT id,ownerId,keyId FROM keytable ;' 2>&1"); return simple_command(message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static int com_palm_power_lunabus_init(void) { LSError lserror; LSErrorInit(&lserror); if (!LSPalmServiceRegisterCategory(GetPalmService(), "/com/palm/power", com_palm_power_public_methods, com_palm_power_methods, com_palm_power_signals, NULL, &lserror)) { goto error; } return 0; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return -1; }
void machineShutdown(void) { char *payload = g_strdup_printf("{\"reason\":\"Battery level is critical\"}"); LSError lserror; LSErrorInit(&lserror); POWERDLOG(LOG_DEBUG,"%s: Sending payload : %s",__func__,payload); bool retVal = LSSignalSend(GetLunaServiceHandle(), "luna://com.palm.power/shutdown/machineOff", payload, &lserror); g_free(payload); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } }
void DisplayBlocker::acquire(const char *clientName) { if (!m_service) return; char *parameters = g_strdup_printf("{\"requestBlock\":true,\"client\":\"%s\"}", clientName); LSError lserror; LSErrorInit(&lserror); if (!LSCall(m_service, "palm://com.palm.display/control/setProperty", parameters, cbRegistrationResponse, this, &m_token, &lserror)) { m_token = 0; LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } }
static void _ListServiceSubscriptions(LSHandle *sh, LSFilterFunc callback, GSList *monitor_list, int total_services, GSList **reply_list) { LSError lserror; LSErrorInit(&lserror); _LSMonitorListInfo *cur = NULL; bool retVal = false; _SubscriptionReplyData *data = g_malloc(sizeof(_SubscriptionReplyData)); if (!data) { g_critical("Out of memory when allocating reply data"); exit(EXIT_FAILURE); } /* NOTE: we only allocate one of these items and pass it as the data to all the callbacks */ data->reply_list = reply_list; data->total_replies = total_services; for (; monitor_list != NULL; monitor_list = g_slist_next(monitor_list)) { cur = monitor_list->data; /* skip any non-services and the monitor itself */ if (!_CanGetSubscriptionInfo(cur)) { continue; } char *uri = g_strconcat("palm://", cur->service_name, list_subscriptions ? SUBSCRIPTION_DEBUG_METHOD : MALLOC_DEBUG_METHOD, NULL); retVal = LSCall(sh, uri, "{}", callback, data, NULL, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_free(uri); } }
// // Send a standard format command failure message back to webOS. // The command will be escaped. The output argument should be a JSON array and is not escaped. // The additional text will not be escaped. // The return value is from the LSMessageReply call, not related to the command execution. // static bool report_command_failure(LSHandle* lshandle, LSMessage *message, char *command, char *stdErrText, char *additional) { LSError lserror; LSErrorInit(&lserror); char buffer[MAXBUFLEN]; char esc_buffer[MAXBUFLEN]; // Include the command that was executed, in escaped form. snprintf(buffer, MAXBUFLEN, "{\"errorText\": \"Unable to run command: %s\"", json_escape_str(command, esc_buffer)); // Include any stderr fields from the command. if (stdErrText) { strcat(buffer, ", \"stdErr\": "); strcat(buffer, stdErrText); } // Report that an error occurred. strcat(buffer, ", \"returnValue\": false, \"errorCode\": -1"); // Add any additional JSON fields. if (additional) { strcat(buffer, ", "); strcat(buffer, additional); } // Terminate the JSON reply message ... strcat(buffer, "}"); // fprintf(stderr, "Message is %s\n", buffer); // and send it. if (!LSMessageReply(lshandle, message, buffer, &lserror)) goto error; return true; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static bool shutdownServicesRegister(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownServicesRegister", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSSubscriptionAdd(sh, "shutdownClient", message, &lserror); if (!retVal) { g_critical("LSSubscriptionAdd failed."); LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return true; }
/** * Client side cancel point. Also used internally. */ void SoundPlayer::stop() { PRINTF_BLUE("SoundPlayer::stop(%s)", getStateName()); if (m_state == eState_PlayPending || m_state == eState_Playing) { if (VERIFY(m_player)) { m_player->pause(); m_player->unload(); } setState(eState_Closing); } else { // not sure why we were not playing: don't take chance... WARNING("SoundPlayer::stop(%s): unexpected stop request. Declaring SoundPlayer object dead.", getStateName()); setState(eState_Dead); } m_filePath.clear(); m_streamClass.clear(); m_lastPlayingTime = currentTime(); m_fakeBackupRingtoneCount = 0; if (m_activityID) { gchar * request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\"}", m_activityID); LSError lserror; LSErrorInit(&lserror); bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityEnd", request, NULL, NULL, NULL, &lserror); if (!activityStartRequestSuccess) { CRITICAL("SoundPlayer::stop: activity '%s' End failed", request); LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } else DEBUG("SoundPlayer::stop: ended activity '%s'...", request); g_free(request); m_activityID = 0; } }
void luna_service_post_subscription(LSHandle *handle, const char *path, const char *method, jvalue_ref reply_obj) { jschema_ref response_schema = NULL; LSError lserror; LSErrorInit(&lserror); response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!response_schema) goto cleanup; if (!LSSubscriptionPost(handle, path, method, jvalue_tostring(reply_obj, response_schema), &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } cleanup: if (response_schema) jschema_release(&response_schema); }
static void SignalRegister(const char *signalName, LSFilterFunc callback, CBH *helper) { bool retVal; LSError lserror; LSErrorInit(&lserror); char *payload = g_strdup_printf( "{\"category\":\"/com/palm/power\",\"method\":\"%s\"}", signalName); retVal = LSCall(gServiceHandle, "luna://com.palm.lunabus/signal/addmatch", payload, callback, helper, &helper->token, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_free(payload); }
// // Return the current API version of the service. // Called directly from webOS, and returns directly to webOS. // bool version_method(LSHandle* lshandle, LSMessage *message, void *ctx) { log("version_method"); LSError lserror; LSErrorInit(&lserror); // Local buffer to store the reply char reply[MAXLINLEN]; sprintf(reply, "{\"returnValue\": true, \"version\": \"%s\", \"apiVersion\": \"%s\"}", VERSION, API_VERSION); log(reply); if (!LSMessageReply(lshandle, message, reply, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return false; } return true; }
static gpointer ClientProc(gpointer data) { GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); gpointer userData = mainLoop; g_timeout_add(10000, &OnTimeout, mainLoop); /*! [client call] */ bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessageToken token = LSMESSAGE_TOKEN_INVALID; LSHandle *serviceHandle; retVal = LSRegister(NULL, &serviceHandle, &lserror); if (!retVal) goto error; retVal = LSCallOneReply(serviceHandle, "luna://com.palm.contacts/category/listContacts", "{ \"json payload\" }", listContactsHandler, userData, &token, &lserror); if (!retVal) goto error; LSGmainAttach(serviceHandle, mainLoop, &lserror); g_main_loop_run(mainLoop); /*! [client call] */ LSUnregister(serviceHandle, &lserror); g_main_loop_unref(mainLoop); g_main_loop_quit((GMainLoop *) data); // Finish the service with the client return GINT_TO_POINTER(0); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); if (serviceHandle) LSUnregister(serviceHandle, &lserror); g_main_loop_unref(mainLoop); g_main_loop_quit((GMainLoop *) data); return GINT_TO_POINTER(1); }
void Activity::unfocus() { if (!mFocus || mId == LSMESSAGE_TOKEN_INVALID) return; LSError lserror; LSErrorInit(&lserror); QJsonObject request; request.insert("activityId", mId); QJsonDocument payload(request); if (!LSCallFromApplication(mHandle, "palm://com.palm.activitymanager/unfocus", payload.toJson().constData(), mIdentifier.toUtf8().constData(), 0, 0, 0, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return; } mFocus = false; }
// // Encrypt text // bool encrypt_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); // Local buffer to store the update command char command[MAXLINLEN]; char *document; // Extract the userdata argument from the message json_t *object = json_parse_document(LSMessageGetPayload(message)); json_t *userdata = json_find_first_label(object, "userdata"); if (!userdata || (userdata->child->type != JSON_OBJECT)) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing userdata\"}", &lserror)) goto error; return true; } if (json_tree_to_string(userdata->child, &document) != JSON_OK) { if (!LSMessageRespond(message, "{\"errorText\": \"Unable to parse userdata\", \"returnValue\": false, \"errorCode\": -1 }", &lserror)) goto error; return true; } // Store the command, so it can be used in the error report if necessary sprintf(command, "echo '%s' | openssl rsautl -encrypt -certin -inkey /media/cryptofs/apps/usr/palm/applications/com.apptuckerbox.register/certs/com.apptuckerbox.crt | openssl enc -e -a 2>&1", document); return simple_command(message, command); error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
void connectionmanager_send_status(void) { jvalue_ref reply = jobject_create(); jobject_put(reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true)); send_connection_status(&reply); jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(response_schema) { const char *payload = jvalue_tostring(reply, response_schema); LSError lserror; LSErrorInit(&lserror); WCA_LOG_INFO("Sending payload %s",payload); if (!LSSubscriptionPost(pLsHandle, "/", "getstatus", payload, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } jschema_release(&response_schema); } j_release(&reply); }