From 933aa51def66a577894bf210cff21378f9d2a43a Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Sat, 16 Mar 2013 04:08:05 +0000 Subject: [PATCH] Fix the bug of trigger_update & set_period API. It requires URI based Id. But the inhouse livebox only knows filename (without File schema). So the API will check the schema of each Id. and if it has no schema, prepend "file://" schema. Change-Id: Id374a66f236e365837aa1068f20f5dd3f52ceb86 --- include/util.h | 1 + packaging/liblivebox-service.spec | 2 +- src/livebox-service.c | 18 ++++++++++++------ src/util.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/include/util.h b/include/util.h index 3dd8a74..0bf4596 100644 --- a/include/util.h +++ b/include/util.h @@ -21,6 +21,7 @@ extern char *util_replace_string(const char *src, const char *pattern, const cha extern const char *util_uri_to_path(const char *uri); extern int util_validate_livebox_package(const char *pkgname); extern char *util_conf_get_libexec(const char *pkgname); +extern char *util_id_to_uri(const char *id); /* For FILENAME id */ #define SCHEMA_FILE "file://" #define SCHEMA_PIXMAP "pixmap://" diff --git a/packaging/liblivebox-service.spec b/packaging/liblivebox-service.spec index e1d59f6..34ff7da 100644 --- a/packaging/liblivebox-service.spec +++ b/packaging/liblivebox-service.spec @@ -1,6 +1,6 @@ Name: liblivebox-service Summary: Service API for gathering installed livebox information. -Version: 0.3.9 +Version: 0.3.10 Release: 1 Group: framework/livebox License: Flora License diff --git a/src/livebox-service.c b/src/livebox-service.c index 1d52caf..9bb81e3 100644 --- a/src/livebox-service.c +++ b/src/livebox-service.c @@ -363,6 +363,7 @@ EAPI int livebox_service_change_period(const char *pkgname, const char *id, doub { struct packet *packet; struct packet *result; + char *uri; int ret; if (!pkgname || !id || period < 0.0f) { @@ -370,10 +371,12 @@ EAPI int livebox_service_change_period(const char *pkgname, const char *id, doub return -EINVAL; } - if (!id) - id = ""; + uri = util_id_to_uri(id); + if (!uri) + return -ENOMEM; - packet = packet_create("service_change_period", "ssd", pkgname, id, period); + packet = packet_create("service_change_period", "ssd", pkgname, uri, period); + free(uri); if (!packet) { ErrPrint("Failed to create a packet for period changing\n"); return -EFAULT; @@ -400,6 +403,7 @@ EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, con { struct packet *packet; struct packet *result; + char *uri; int ret; if (!pkgname) { @@ -412,8 +416,9 @@ EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, con return -ECANCELED; } - if (!id) - id = ""; + uri = util_id_to_uri(id); + if (!uri) + return -ENOMEM; if (!cluster) cluster = "user,created"; @@ -421,7 +426,8 @@ EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, con if (!category) category = "default"; - packet = packet_create("service_update", "ssss", pkgname, id, cluster, category); + packet = packet_create("service_update", "ssss", pkgname, uri, cluster, category); + free(uri); if (!packet) { ErrPrint("Failed to create a packet for service_update\n"); return -EFAULT; diff --git a/src/util.c b/src/util.c index e5a545e..678f50a 100644 --- a/src/util.c +++ b/src/util.c @@ -296,4 +296,36 @@ char *util_conf_get_libexec(const char *pkgname) return path; } + +char *util_id_to_uri(const char *id) +{ + char *uri; + + if (!id) { + uri = strdup(""); + if (!uri) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + } else if (strncmp(id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + int len; + len = strlen(SCHEMA_FILE) + strlen(id) + 2; + uri = malloc(len); + if (!uri) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + snprintf(uri, len, SCHEMA_FILE"%s", id); + } else { + uri = strdup(id); + if (!uri) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + } + + return uri; +} + /* End of a file */ -- 2.7.4