bool luna_service_initialize(const char *dbusAddress) { bool returnVal = FALSE; LSError lserror; LSErrorInit(&lserror); loop = g_main_loop_new(NULL, FALSE); if (loop==NULL) goto end; returnVal = LSRegisterPalmService(dbusAddress, &serviceHandle, &lserror); if (returnVal) { pub_serviceHandle = LSPalmServiceGetPublicConnection(serviceHandle); priv_serviceHandle = LSPalmServiceGetPrivateConnection(serviceHandle); } else goto end; returnVal = register_methods(serviceHandle, lserror); if (returnVal) { LSGmainAttachPalmService(serviceHandle, loop, &lserror); } end: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return returnVal; }
bool service_register(const char *name) { bool rc; LSError err; LSErrorInit(&err); loop = g_main_loop_new(NULL, FALSE); if(loop == NULL) goto end; rc = LSRegisterPalmService(name, &handle, &err); if(rc) { pub = LSPalmServiceGetPublicConnection(handle); prv = LSPalmServiceGetPrivateConnection(handle); } else goto end; rc = LSPalmServiceRegisterCategory(handle, "/", methods, NULL, NULL, NULL, &err); LSGmainAttachPalmService(handle, loop, &err); if(!rc) goto end; end: if(LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); puts("servece startup error..."); } return rc; }
static void test_LSErrorInit(TestData *fixture, gconstpointer user_data) { LSError error; LSErrorInit(&error); g_assert(!LSErrorIsSet(&error)); }
void InputManager::startService() { LSError lserror; LSErrorInit(&lserror); bool result; GMainLoop* mainLoop = HostBase::instance()->mainLoop(); g_debug ("%s starting", __PRETTY_FUNCTION__); result = LSRegisterPalmService(LUNA_KEYS, &m_palmService, &lserror); if (!result) goto Error; // Save off public and private bus handles m_publicService = LSPalmServiceGetPublicConnection(m_palmService); if (NULL == m_publicService) { g_message("unable to get public handle"); } m_service = LSPalmServiceGetPrivateConnection(m_palmService); if (NULL == m_service) { g_message("unable to get private handle"); } // We're providing the notion of "key categories" that you can // subscribe to in order to get notifications when a key is pressed result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_AUDIO, s_audioMethods, NULL, NULL, this, &lserror); if (!result) goto Error; // For now the media keys are the only ones that have been requested // to be put on the public bus -- the calling syntax is a little // strange, but when using this call everything on the public bus // is also put on the private bus result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_MEDIA, s_mediaMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_SWITCHES, s_switchesMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_HEADSET, s_headsetMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSGmainAttachPalmService(m_palmService, mainLoop, &lserror); if (!result) goto Error; g_debug ("%s service started", LUNA_KEYS); return; Error: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_debug(":%s: Unable to start service", __PRETTY_FUNCTION__); }
static void test_LSErrorFree(TestData *fixture, gconstpointer user_data) { LSError error; LSErrorInit(&error); _LSErrorSetNoPrint(&error, LS_ERROR_CODE_UNKNOWN_ERROR, LS_ERROR_TEXT_UNKNOWN_ERROR); LSErrorFree(&error); g_assert(!LSErrorIsSet(&error)); }
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; }
// If service handle exists, return it, otherwise create it then return it // In an error situation, this could return NULL LSHandle *SysmgrIMEModel::getLunaServiceHandle() { if (!m_serviceHandle) { LSError lserror; LSErrorInit(&lserror); if (LSRegister(NULL, &m_serviceHandle, &lserror)) LSGmainAttach(m_serviceHandle, HostBase::instance()->mainLoop(), &lserror); if (LSErrorIsSet(&lserror)) { qCritical() << lserror.message << lserror.file << lserror.line << lserror.func; LSErrorFree(&lserror); } } return m_serviceHandle; }
static void test_LSErrorSet(TestData *fixture, gconstpointer user_data) { LSError error; LSErrorInit(&error); _LSErrorSetNoPrint(&error, LS_ERROR_CODE_UNKNOWN_ERROR, LS_ERROR_TEXT_UNKNOWN_ERROR); g_assert(LSErrorIsSet(&error)); g_assert_cmpint(error.error_code, ==, LS_ERROR_CODE_UNKNOWN_ERROR); g_assert_cmpstr(error.message, ==, LS_ERROR_TEXT_UNKNOWN_ERROR); LSErrorFree(&error); }
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 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); } }
bool LunaServiceCall::execute(const QString& uri, const QString& arguments) { LSError error; LSErrorInit(&error); QString errorMessage; if (mResponseLimit == 1) { if (!LSCallOneReply(mServiceHandle, uri.toUtf8().constData(), arguments.toUtf8().constData(), &LunaServiceCall::responseCallback, this, &mToken, &error)) { qWarning("Failed to call remote service %s", uri.toUtf8().constData()); errorMessage = QString("Failed to call remote service: %0").arg(error.message); goto error; } } else { if (!LSCall(mServiceHandle, uri.toUtf8().constData(), arguments.toUtf8().constData(), &LunaServiceCall::responseCallback, this, &mToken, &error)) { qWarning("Failed to call remote service %s", uri.toUtf8().constData()); errorMessage = QString("Failed to call remote service: %0").arg(error.message); goto error; } } return true; error: if (LSErrorIsSet(&error)) { LSErrorPrint(&error, stderr); LSErrorFree(&error); } if (mErrorCallback.isCallable()) mErrorCallback.call(QJSValueList() << errorMessage); return false; }
/** * @brief Set a calendar event. * * luna://com.palm.sleep/time/alarmAddCalendar * * Message: * Set alarm to expire at a fixed calendar time in UTC. Response will be sent * as a call to "luna://com.palm.X/alarm". * * {"key":"calendarAlarm", "serviceName":"com.palm.X", * "date":"01-02-2009", "time":"13:40:03"} * * Subscribing indicates that you want the alarm message as a response to * the current call. * * {"subscribe":true, "key":"calendarAlarm", "serviceName":"com.palm.X", * "date":"01-02-2009", "time":"13:40:03"} * * Response: * * Alarm is sucessfully registered for calendar date * {"alarmId":1} * * Subscribe case: * {"alarmId":1,"subscribed":true} * {"alarmId":1,"fired":true} * * Alarm failed to be registered: * * {"returnValue":false, ...} * {"returnValue":false,"serivceName":"com.palm.sleep", * "errorText":"com.palm.sleep is not running"} * * @param sh * @param message * @param ctx * * @retval */ static bool alarmAddCalendar(LSHandle *sh, LSMessage *message, void *ctx) { int alarm_id; struct json_object *object; const char *key, *serviceName, *applicationName, *cal_date, *cal_time; struct tm gm_time; bool subscribe; bool retVal = false; gchar **cal_date_str; time_t alarm_time = 0; LSError lserror; LSErrorInit(&lserror); object = json_tokener_parse(LSMessageGetPayload(message)); if (is_error(object)) { goto malformed_json; } SLEEPDLOG_DEBUG("alarmAddCalendar() : %s", LSMessageGetPayload(message)); serviceName = json_object_get_string( json_object_object_get(object, "serviceName")); applicationName = LSMessageGetApplicationID(message); key = json_object_get_string(json_object_object_get(object, "key")); cal_date = json_object_get_string( json_object_object_get(object, "date")); cal_time = json_object_get_string( json_object_object_get(object, "time")); if (!cal_date || !cal_time) { goto invalid_format; } int hour, min, sec; int month, day, year; if (!ConvertJsonTime(cal_time, &hour, &min, &sec)) { goto invalid_format; } cal_date_str = g_strsplit(cal_date, "-", 3); if ((NULL == cal_date_str[0]) || (NULL == cal_date_str[1]) || (NULL == cal_date_str[2])) { goto invalid_format; } month = atoi(cal_date_str[0]); day = atoi(cal_date_str[1]); year = atoi(cal_date_str[2]); g_strfreev(cal_date_str); if (hour < 0 || hour > 24 || min < 0 || min > 59 || sec < 0 || sec > 59 || month < 1 || month > 12 || day < 1 || day > 31 || year < 0) { goto invalid_format; } SLEEPDLOG_DEBUG("alarmAddCalendar() : (%s %s %s) at %s %s", serviceName, applicationName, key, cal_date, cal_time); struct json_object *subscribe_json = json_object_object_get(object, "subscribe"); subscribe = json_object_get_boolean(subscribe_json); memset(&gm_time, 0, sizeof(struct tm)); gm_time.tm_hour = hour; gm_time.tm_min = min; gm_time.tm_sec = sec; gm_time.tm_mon = month - 1; // month-of-year [0-11] gm_time.tm_mday = day; // day-of-month [1-31] gm_time.tm_year = year - 1900; /* timegm converts time(GMT) -> seconds since epoch */ alarm_time = timegm(&gm_time); if (alarm_time < 0) { goto invalid_format; } retVal = alarm_queue_new(key, true, alarm_time, serviceName, applicationName, subscribe, message, &alarm_id); if (!retVal) { goto error; } /***************** * Use new timeout API */ { char *timeout_key = g_strdup_printf("%s-%d", key, alarm_id); _AlarmTimeout timeout; _timeout_create(&timeout, "com.palm.sleep", timeout_key, "luna://com.palm.sleep/time/internalAlarmFired", "{}", false /*public bus*/, true /*wakeup*/, "" /*activity_id*/, 0 /*activity_duration_ms*/, true /*calendar*/, alarm_time); retVal = _timeout_set(&timeout); g_free(timeout_key); if (!retVal) { goto error; } } /*****************/ /* Send alarm id of sucessful alarm add. */ GString *reply = g_string_sized_new(512); g_string_append_printf(reply, "{\"alarmId\":%d", alarm_id); if (subscribe_json) { g_string_append_printf(reply, ",\"subscribed\":%s", subscribe ? "true" : "false"); } g_string_append_printf(reply, "}"); retVal = LSMessageReply(sh, message, reply->str, &lserror); g_string_free(reply, TRUE); goto cleanup; error: retVal = LSMessageReply(sh, message, "{\"returnValue\":false," "\"errorText\":\"Unknown error\"}", &lserror); goto cleanup; invalid_format: retVal = LSMessageReply(sh, message, "{\"returnValue\":false," "\"errorText\":\"Invalid format for alarm time.\"}", &lserror); goto cleanup; malformed_json: LSMessageReplyErrorBadJSON(sh, message); goto cleanup; cleanup: if (!is_error(object)) { json_object_put(object); } if (!retVal && LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return true; }
/** * @brief Set alarm to fire in a fixed time in the future. * * luna://com.palm.sleep/time/alarmAdd * * Set alarm to expire in T+5hrs. Response will be sent * as a call to "luna://com.palm.X/alarm". * * {"key":"calendarAlarm", "serviceName":"com.palm.X", * "relative_time":"05:00:00"} * * Subscribing indicates that you want the alarm message as a response to * the current call. * * {"subscribe":true, "key":"calendarAlarm", "serviceName":"com.palm.X", * "relative_time":"05:00:00"} * * Alarm is sucessfully registered. * {"alarmId":1} * * Alarm failed to be registered: * * {"returnValue":false, ...} * {"returnValue":false,"serivceName":"com.palm.sleep", * "errorText":"com.palm.sleep is not running"} * * @param sh * @param message * @param ctx * * @retval */ static bool alarmAdd(LSHandle *sh, LSMessage *message, void *ctx) { time_t alarm_time = 0; int rel_hour, rel_min, rel_sec; const char *key, *serviceName, *applicationName, *rel_time; bool subscribe; struct json_object *object; int alarm_id; bool retVal = false; LSError lserror; LSErrorInit(&lserror); time_t rtctime = 0; object = json_tokener_parse(LSMessageGetPayload(message)); if (is_error(object)) { goto malformed_json; } SLEEPDLOG_DEBUG("%s", LSMessageGetPayload(message)); serviceName = json_object_get_string( json_object_object_get(object, "serviceName")); applicationName = LSMessageGetApplicationID(message); key = json_object_get_string(json_object_object_get(object, "key")); rel_time = json_object_get_string( json_object_object_get(object, "relative_time")); if (!rel_time) { goto invalid_format; } if (!ConvertJsonTime(rel_time, &rel_hour, &rel_min, &rel_sec) || (rel_hour < 0 || rel_hour > 24 || rel_min < 0 || rel_min > 59 || rel_sec < 0 || rel_sec > 59)) { goto invalid_format; } nyx_system_query_rtc_time(GetNyxSystemDevice(), &rtctime); SLEEPDLOG_DEBUG("alarmAdd(): (%s %s %s) in %s (rtc %ld)", serviceName, applicationName, key, rel_time, rtctime); struct json_object *subscribe_json = json_object_object_get(object, "subscribe"); subscribe = json_object_get_boolean(subscribe_json); alarm_time = reference_time(); alarm_time += rel_sec; alarm_time += rel_min * 60; alarm_time += rel_hour * 60 * 60; retVal = alarm_queue_new(key, false, alarm_time, serviceName, applicationName, subscribe, message, &alarm_id); if (!retVal) { goto error; } /***************** * Use new timeout API */ { char *timeout_key = g_strdup_printf("%s-%d", key, alarm_id); _AlarmTimeout timeout; _timeout_create(&timeout, "com.palm.sleep", timeout_key, "luna://com.palm.sleep/time/internalAlarmFired", "{}", false /*public bus*/, true /*wakeup*/, "" /*activity_id*/, 0 /*activity_duration_ms*/, false /*calendar*/, alarm_time); retVal = _timeout_set(&timeout); g_free(timeout_key); if (!retVal) { goto error; } } /*****************/ /* Send alarm id of sucessful alarm add. */ GString *reply = g_string_sized_new(512); g_string_append_printf(reply, "{\"alarmId\":%d", alarm_id); if (subscribe_json) { g_string_append_printf(reply, ",\"subscribed\":%s", subscribe ? "true" : "false"); } g_string_append_printf(reply, "}"); retVal = LSMessageReply(sh, message, reply->str, &lserror); g_string_free(reply, TRUE); goto cleanup; error: retVal = LSMessageReply(sh, message, "{\"returnValue\":false," "\"errorText\":\"Unknown error\"}", &lserror); goto cleanup; invalid_format: retVal = LSMessageReply(sh, message, "{\"returnValue\":false," "\"errorText\":\"Invalid format for alarm time.\"}", &lserror); goto cleanup; malformed_json: LSMessageReplyErrorBadJSON(sh, message); goto cleanup; cleanup: if (!is_error(object)) { json_object_put(object); } if (!retVal && LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return true; }
int main(int argc, char **argv) { bool interactive = false; bool timing = false; bool signal = false; bool use_public_bus = false; char *serviceName = NULL; int optionCount = 0; int opt; while ((opt = getopt(argc, argv, "hdisPrlfn:t:m:a:q:")) != -1) { switch (opt) { case 'i': interactive = true; optionCount++; break; case 's': signal = true; optionCount++; break; case 'P': use_public_bus = true; optionCount++; break; case 'd': sLogLevel = G_LOG_LEVEL_DEBUG; optionCount++; break; case 'n': interactive = true; count = atoi(optarg); optionCount+=2; break; case 't': timing = true; count = atoi(optarg); optionCount+=2; break; case 'm': serviceName = g_strdup(optarg); optionCount+=2; break; case 'a': appId = g_strdup(optarg); optionCount+=2; break; case 'l': line_number = true; optionCount++; break; case 'f': format_response = true; optionCount++; break; case 'q': query_list = g_list_append(query_list, g_strdup(optarg)); optionCount+=2; break; case 'h': default: PrintUsage(argv[0]); return 0; } } if (argc < 3 + optionCount) { PrintUsage(argv[0]); return 0; } g_log_set_default_handler(g_log_filter, NULL); GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); if (mainLoop == NULL) { g_critical("Unable to create mainloop"); exit(EXIT_FAILURE); } LSError lserror; LSErrorInit(&lserror); LSHandle *sh = NULL; bool serviceInit = LSRegisterPubPriv(serviceName, &sh, use_public_bus, &lserror); if (!serviceInit) goto exit; bool gmainAttach = LSGmainAttach(sh, mainLoop, &lserror); if (!gmainAttach) goto exit; url = g_strdup(argv[optionCount + 1]); message = g_strdup(argv[optionCount + 2]); LSMessageToken sessionToken; bool retVal; if (timing) { /* Timing loop */ clock_gettime(CLOCK_MONOTONIC, &startTime); retVal = LSCallFromApplication(sh, url, message, appId, timingServiceResponse, mainLoop, &sessionToken, &lserror); if (!retVal) goto exit; g_main_loop_run(mainLoop); printf("Total time %.02f ms, %d iterations, %.02f ms per iteration\n", roundtripTime * 1000.0, roundtripCount, (roundtripTime / roundtripCount) * 1000.0); printf("%d bytes sent, %d bytes received\n", sentBytes, rcvdBytes); } else { if (signal) { retVal = LSSignalSend(sh, url, message, &lserror); } else { /* Basic sending */ retVal = LSCallFromApplication(sh, url, message, appId, serviceResponse, mainLoop, &sessionToken, &lserror); } if (!retVal) goto exit; if (interactive && !signal) { g_io_add_watch(g_io_channel_unix_new(0), G_IO_ERR|G_IO_HUP, input_closed, mainLoop); g_main_loop_run(mainLoop); } else if (!signal) { /* * NOV-93580: In the non-interactive case, we can't guarantee that * an LSCall() will necessarily get the QueryNameReply before * shutting down if it does not wait for (or have) a reply from the * far side. */ g_critical("WARNING: you must always call luna-send with \"-i\" or \"-n\". Exiting with failure return code."); exit(EXIT_FAILURE); } } exit: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } if (sh != NULL) { if (!LSUnregister(sh, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } g_main_loop_unref(mainLoop); if (url) g_free (url); if (message) g_free (message); return 0; }
int initialize_connectionmanager_ls2_calls( GMainLoop *mainloop ) { LSError lserror; LSErrorInit (&lserror); pLsHandle = NULL; pLsPublicHandle = NULL; if(NULL == mainloop) goto Exit; if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsHandle, false, &lserror) == false) { WCA_LOG_FATAL("LSRegister() private returned error"); goto Exit; } if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsPublicHandle, true, &lserror) == false) { WCA_LOG_FATAL("LSRegister() public returned error"); goto Exit; } if (LSRegisterCategory(pLsHandle, NULL, connectionmanager_methods, NULL, NULL, &lserror) == false) { WCA_LOG_FATAL("LSRegisterCategory() returned error"); goto Exit; } if (LSGmainAttach(pLsHandle, mainloop, &lserror) == false) { WCA_LOG_FATAL("LSGmainAttach() private returned error"); goto Exit; } if (LSGmainAttach(pLsPublicHandle, mainloop, &lserror) == false) { WCA_LOG_FATAL("LSGmainAttach() public returned error"); goto Exit; } /* Register for Wired technology's "PropertyChanged" signal (For wifi its being done in wifi_service.c*/ connman_technology_t *technology = connman_manager_find_ethernet_technology(manager); if(technology) { connman_technology_register_property_changed_cb(technology, technology_property_changed_callback); } return 0; Exit: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } if (pLsHandle) { LSErrorInit (&lserror); if(LSUnregister(pLsHandle, &lserror) == false) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } if (pLsPublicHandle) { LSErrorInit (&lserror); if(LSUnregister(pLsPublicHandle, &lserror) == false) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } return -1; }
{ setenv("LS_DEBUG", "2", 1); setenv("LS_ENABLE_UTF8", "2", 1); LSRegister("com.name.service", &sh, &error); g_assert_cmpint(_ls_debug_tracing, ==, 2); g_assert(_ls_enable_utf8_validation == true); LSUnregister(sh, &error); exit(0); } g_test_trap_assert_stderr("Log mode enabled to level 2\nEnable UTF8 validation on payloads\n"); g_test_trap_assert_passed(); g_assert(LSRegister("com.name.service", &sh, &error)); g_assert(NULL != sh); g_assert(!LSErrorIsSet(&error)); g_assert_cmpstr(LSHandleGetName(sh), ==, "com.name.service"); g_assert(LSUnregister(sh, &error)); g_assert(!LSErrorIsSet(&error)); g_assert(LSRegisterPubPriv("com.name.service", &sh, true, &error)); g_assert(NULL != sh); g_assert(!LSErrorIsSet(&error)); g_assert(LSUnregister(sh, &error)); g_assert(!LSErrorIsSet(&error)); g_assert(LSRegisterPubPriv("com.name.service", &sh, false, &error)); g_assert(NULL != sh); g_assert(!LSErrorIsSet(&error)); if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR))
static void test_LSHubPermissionMapLookup(void *fixture, gconstpointer user_data) { ConfigSetDefaults(); char const *dirs[] = { TEST_STEADY_ROLES_DIRECTORY, NULL }; LSError error; LSErrorInit(&error); g_assert(ProcessRoleDirectories(dirs, NULL, &error)); g_assert(!LSErrorIsSet(&error)); _LSTransportCred *cred = _LSTransportCredNew(); g_assert(cred); pid_t pid = getpid(); _LSTransportCredSetPid(cred, pid); struct LSTransportHandlers test_handlers = {}; _LSTransport *transport = NULL; g_assert(_LSTransportInit(&transport, "com.webos.foo", &test_handlers, NULL)); _LSTransportSetTransportType(transport, _LSTransportTypeLocal); g_assert(transport); _LSTransportClient test_client = { .service_name = "com.webos.foo", .cred = cred, .transport = transport, }; _LSTransportCredSetExePath(cred, "/bin/foo"); test_client.service_name = "com.webos.foo"; g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.foo")); LSHubActiveRoleMapUnref(pid); g_assert(!LSHubIsClientAllowedToRequestName(&test_client, "com.webos.foo2")); LSHubActiveRoleMapUnref(pid); _LSTransportCredSetExePath(cred, "/bin/bar"); test_client.service_name = "com.webos.bar"; g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.bar")); LSHubActiveRoleMapUnref(pid); g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.bar2")); LSHubActiveRoleMapUnref(pid); _LSTransportCredSetExePath(cred, "/bin/foo"); test_client.service_name = "com.webos.foo"; g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.bar", "asdf")); _LSTransportCredSetExePath(cred, "/bin/bar"); test_client.service_name = "com.webos.bar"; g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.foo", "asdf")); _LSTransportCredSetExePath(cred, "/bin/bar"); test_client.service_name = "com.webos.bar2"; g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.foo", "asdf")); _LSTransportDeinit(transport); _LSTransportCredFree(cred); _ConfigFreeSettings(); } int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); g_log_set_always_fatal (G_LOG_LEVEL_ERROR); g_log_set_fatal_mask ("LunaServiceHub", G_LOG_LEVEL_ERROR); g_test_add("/hub/LSHubPermissionMapLookup", void, NULL, NULL, test_LSHubPermissionMapLookup, NULL); return g_test_run(); }
bool isSet() const { return LSErrorIsSet(const_cast<LSError*>(&_error)); }