示例#1
0
static bool access_denied(LSMessage *message) {
  LSError lserror;
  LSErrorInit(&lserror);

  const char *appId = LSMessageGetApplicationID(message);
  if (!appId || strncmp(appId, "org.webosinternals.impostah", 27) || ((strlen(appId) > 27) && (*(appId+27) != ' '))) {
    if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorText\": \"Unauthorised access\"}", &lserror)) {
      LSErrorPrint(&lserror, stderr);
      LSErrorFree(&lserror);
    }
    return true;
  }

  return false;
}
示例#2
0
static bool access_denied(LSMessage *message) {
  LSError lserror;
  LSErrorInit(&lserror);

  const char *appId = LSMessageGetApplicationID(message);
  if (!appId || strncmp(appId, "com.apptuckerbox.register", 25) || ((strlen(appId) > 25) && (*(appId+25) != ' '))) {
    if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorText\": \"Unauthorised access\"}", &lserror)) {
      LSErrorPrint(&lserror, stderr);
      LSErrorFree(&lserror);
    }
    return true;
  }

  return false;
}
示例#3
0
文件: alarm.c 项目: Herrie82/sleepd
/**
* @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;
}
示例#4
0
文件: alarm.c 项目: Herrie82/sleepd
/**
* @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;
}
QString LunaServiceMessage::applicationId() const
{
    return QString(LSMessageGetApplicationID(mMessage));
}