summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afm-db.c11
-rw-r--r--src/afm-system-daemon.c88
-rw-r--r--src/utils-jbus.h1
-rw-r--r--src/wgt-info.c33
-rw-r--r--src/wgt-info.h1
-rw-r--r--src/wgtpkg-install.c9
-rw-r--r--src/wgtpkg-install.h20
-rw-r--r--src/wgtpkg.h5
8 files changed, 146 insertions, 22 deletions
diff --git a/src/afm-db.c b/src/afm-db.c
index 3f96821..8f52d1c 100644
--- a/src/afm-db.c
+++ b/src/afm-db.c
@@ -169,7 +169,6 @@ static int addapp(struct afapps *apps, const char *path)
const struct wgt_desc *desc;
const struct wgt_desc_feature *feat;
struct json_object *priv = NULL, *pub, *bya, *plugs, *str;
- char *appid, *end;
/* connect to the widget */
info = wgt_info_createat(AT_FDCWD, path, 0, 1, 0);
@@ -180,12 +179,6 @@ static int addapp(struct afapps *apps, const char *path)
}
desc = wgt_info_desc(info);
- /* create the application id */
- appid = alloca(2 + strlen(desc->id) + strlen(desc->version));
- end = stpcpy(appid, desc->id);
- *end++ = '@';
- strcpy(end, desc->version);
-
/* create the application structure */
priv = json_object_new_object();
if (!priv)
@@ -213,7 +206,7 @@ static int addapp(struct afapps *apps, const char *path)
|| json_add_str(priv, "path", path)
|| json_add_str(priv, "content", desc->content_src)
|| json_add_str(priv, "type", desc->content_type)
- || json_add_str(pub, "id", appid)
+ || json_add_str(pub, "id", desc->idaver)
|| json_add_str(pub, "version", desc->version)
|| json_add_int(pub, "width", desc->width)
|| json_add_int(pub, "height", desc->height)
@@ -249,7 +242,7 @@ static int addapp(struct afapps *apps, const char *path)
}
}
- if (json_add(apps->direct, appid, priv))
+ if (json_add(apps->direct, desc->idaver, priv))
goto error2;
json_object_get(priv);
diff --git a/src/afm-system-daemon.c b/src/afm-system-daemon.c
index f938372..84e8992 100644
--- a/src/afm-system-daemon.c
+++ b/src/afm-system-daemon.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <time.h>
#include <getopt.h>
+#include <errno.h>
#include <json.h>
@@ -27,6 +28,8 @@
#include "utils-jbus.h"
#include "afm.h"
#include "afm-db.h"
+#include "wgt-info.h"
+#include "wgtpkg-install.h"
static const char appname[] = "afm-system-daemon";
@@ -91,13 +94,90 @@ static void on_detail(struct jreq *jreq, struct json_object *obj)
json_object_put(resp);
}
-extern void install_widget(const char *wgtfile, const char *root, int force);
-static void on_install(struct jreq *jreq, struct json_object *obj)
+static const char *j_get_string(struct json_object *obj, const char *key, const char *defval)
{
- jbus_reply_error_s(jreq, "\"not yet implemented\"");
+ struct json_object *o;
+ return json_object_object_get_ex(obj, key, &o) && json_object_get_type(o) == json_type_string ? json_object_get_string(o) : defval;
+}
+
+static int j_get_boolean(struct json_object *obj, const char *key, int defval)
+{
+ struct json_object *o;
+ return json_object_object_get_ex(obj, key, &o) && json_object_get_type(o) == json_type_boolean ? json_object_get_boolean(o) : defval;
+}
+
+static int json_add(struct json_object *obj, const char *key, struct json_object *val)
+{
+ json_object_object_add(obj, key, val);
+ return 0;
+}
+
+static int json_add_str(struct json_object *obj, const char *key, const char *val)
+{
+ struct json_object *str = json_object_new_string (val ? val : "");
+ return str ? json_add(obj, key, str) : (errno = ENOMEM, -1);
+}
+/*
+static int json_add_int(struct json_object *obj, const char *key, int val)
+{
+ struct json_object *v = json_object_new_int (val);
+ return v ? json_add(obj, key, v) : (errno = ENOMEM, -1);
+}
+*/
+static void on_install(struct jreq *jreq, struct json_object *req)
+{
+ const char *wgtfile;
+ const char *root;
+ int force;
+ struct wgt_info *ifo;
+ struct json_object *resp;
+
+ /* scan the request */
+ switch (json_object_get_type(req)) {
+ case json_type_string:
+ wgtfile = json_object_get_string(req);
+ root = FWK_APP_DIR;
+ force = 0;
+ break;
+ case json_type_object:
+ wgtfile = j_get_string(req, "wgt", NULL);
+ if (wgtfile != NULL) {
+ root = j_get_string(req, "root", FWK_APP_DIR);
+ force = j_get_boolean(req, "force", 0);
+ break;
+ }
+ default:
+ jbus_reply_error_s(jreq, error_bad_request);
+ return;
+ }
+
+ /* install the widget */
+ ifo = install_widget(wgtfile, root, force);
+ if (ifo == NULL) {
+ jbus_reply_error_s(jreq, "\"installation failed\"");
+ return;
+ }
+
+ /* build the response */
+ resp = json_object_new_object();
+ if(!resp || json_add_str(resp, "added", wgt_info_desc(ifo)->idaver)) {
+ json_object_put(resp);
+ wgt_info_unref(ifo);
+ jbus_reply_error_s(jreq, "\"out of memory but installed!\"");
+ return;
+ }
+ wgt_info_unref(ifo);
+
+ /* update the current database */
+ afm_db_update_applications(afdb);
+
+ /* reply and propagate event */
+ jbus_reply_j(jreq, resp);
+ jbus_send_signal_j(jbus, "changed", resp);
+ json_object_put(resp);
}
-static void on_uninstall(struct jreq *jreq, struct json_object *obj)
+static void on_uninstall(struct jreq *jreq, struct json_object *req)
{
jbus_reply_error_s(jreq, "\"not yet implemented\"");
}
diff --git a/src/utils-jbus.h b/src/utils-jbus.h
index 68e9b68..218c21d 100644
--- a/src/utils-jbus.h
+++ b/src/utils-jbus.h
@@ -51,3 +51,4 @@ extern int jbus_add_service_j(struct jbus *jbus, const char *method, void (*onca
extern int jbus_start_serving(struct jbus *jbus);
extern int jbus_send_signal_s(struct jbus *jbus, const char *name, const char *content);
extern int jbus_send_signal_j(struct jbus *jbus, const char *name, struct json_object *content);
+
diff --git a/src/wgt-info.c b/src/wgt-info.c
index 1560feb..4d6b37d 100644
--- a/src/wgt-info.c
+++ b/src/wgt-info.c
@@ -75,6 +75,34 @@ static xmlChar *optcontent(xmlNodePtr node)
return node ? xmlNodeGetContent(node) : NULL;
}
+static char *mkidaver(char *id, char *version)
+{
+ int lid, lver;
+ char c, *r;
+ if (id && version) {
+ lid = strlen(id);
+ c = version[lver = 0];
+ while(c && c != ' ') {
+ if (c != '.')
+ c = version[++lver];
+ else {
+ do {
+ c = version[++lver];
+ } while (c && c != ' ' && c != '.');
+ break;
+ }
+ }
+ r = malloc(2 + lid + lver);
+ if (r) {
+ memcpy(r, id, lid);
+ r[lid] = '@';
+ memcpy(r + lid + 1, version, lver + 1);
+ return r;
+ }
+ }
+ return NULL;
+}
+
static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, int want_preferences)
{
xmlNodePtr node, pnode;
@@ -91,6 +119,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
}
desc->id = xmlGetProp(node, wgt_config_string_id);
desc->version = xmlGetProp(node, wgt_config_string_version);
+ desc->idaver = mkidaver(desc->id, desc->version);
desc->width = getpropnum(node, wgt_config_string_width, 0);
desc->height = getpropnum(node, wgt_config_string_height, 0);
desc->viewmodes = xmlGetProp(node, wgt_config_string_viewmodes);
@@ -237,6 +266,7 @@ static void free_desc(struct wgt_desc *desc)
xmlFree(desc->id);
xmlFree(desc->version);
+ free(desc->idaver);
xmlFree(desc->viewmodes);
xmlFree(desc->defaultlocale);
xmlFree(desc->name);
@@ -289,9 +319,10 @@ static void dump_desc(struct wgt_desc *desc, FILE *f, const char *prefix)
struct wgt_desc_param *param;
if (desc->id) fprintf(f, "%sid: %s\n", prefix, desc->id);
+ if (desc->version) fprintf(f, "%sversion: %s\n", prefix, desc->version);
+ if (desc->idaver) fprintf(f, "%sidaver: %s\n", prefix, desc->idaver);
if (desc->width) fprintf(f, "%swidth: %d\n", prefix, desc->width);
if (desc->height) fprintf(f, "%sheight: %d\n", prefix, desc->height);
- if (desc->version) fprintf(f, "%sversion: %s\n", prefix, desc->version);
if (desc->viewmodes) fprintf(f, "%sviewmodes: %s\n", prefix, desc->viewmodes);
if (desc->defaultlocale) fprintf(f, "%sdefaultlocale: %s\n", prefix, desc->defaultlocale);
if (desc->name) fprintf(f, "%sname: %s\n", prefix, desc->name);
diff --git a/src/wgt-info.h b/src/wgt-info.h
index ace9a2d..3d0a593 100644
--- a/src/wgt-info.h
+++ b/src/wgt-info.h
@@ -48,6 +48,7 @@ struct wgt_desc {
int refcount;
char *id;
char *version;
+ char *idaver;
int width;
int height;
char *viewmodes;
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index 933e612..70198e9 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -28,6 +28,7 @@
#include "wgtpkg.h"
#include "wgt.h"
#include "wgt-info.h"
+#include "wgtpkg-install.h"
#include "secmgr-wrap.h"
#include "utils-dir.h"
@@ -216,7 +217,7 @@ error:
}
/* install the widget of the file */
-int install_widget(const char *wgtfile, const char *root, int force)
+struct wgt_info *install_widget(const char *wgtfile, const char *root, int force)
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
@@ -253,7 +254,8 @@ int install_widget(const char *wgtfile, const char *root, int force)
if (install_security(desc))
goto error3;
- return 0;
+ file_reset();
+ return ifo;
error3:
wgt_info_unref(ifo);
@@ -262,6 +264,7 @@ error2:
remove_workdir();
error1:
- return -1;
+ file_reset();
+ return NULL;
}
diff --git a/src/wgtpkg-install.h b/src/wgtpkg-install.h
new file mode 100644
index 0000000..bf3c3a6
--- /dev/null
+++ b/src/wgtpkg-install.h
@@ -0,0 +1,20 @@
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+extern struct wgt_info *install_widget(const char *wgtfile, const char *root, int force);
+
diff --git a/src/wgtpkg.h b/src/wgtpkg.h
index 52a42e1..e700a9b 100644
--- a/src/wgtpkg.h
+++ b/src/wgtpkg.h
@@ -90,11 +90,6 @@ extern int file_set_prop(struct filedesc *file, const char *name, const char *va
extern const char *file_get_prop(struct filedesc *file, const char *name);
/**************************************************************/
-/* from wgtpkg-install */
-
-extern int install_widget(const char *wgtfile, const char *root, int force);
-
-/**************************************************************/
/* from wgtpkg-permission */
extern int is_standard_permission(const char *name);