aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-06-14 13:14:02 +0000
committerGerrit Code Review <gerrit@automotivelinux.org>2018-06-14 13:14:02 +0000
commitc92d55d47367d1d97aa0782f3456033f0f5f73db (patch)
treeb379ba6299374b0de9829e236add013452c408f0
parente9758a911e9623cacd926abc49d480a976fd3a81 (diff)
parentc86a4c102d18f8d94993a632e42a51c4d4b82966 (diff)
Merge changes from topic 'binding-v3'
* changes: afm-binding: Review of the permissions afm-binding: Improve comment and strings
-rw-r--r--src/afm-binding.c105
1 files changed, 79 insertions, 26 deletions
diff --git a/src/afm-binding.c b/src/afm-binding.c
index 5aad281..ae7c9db 100644
--- a/src/afm-binding.c
+++ b/src/afm-binding.c
@@ -34,8 +34,13 @@
#include "wgtpkg-uninstall.h"
#include "wrap-json.h"
+/*
+ * constant strings
+ */
static const char _added_[] = "added";
static const char _a_l_c_[] = "application-list-changed";
+static const char _bad_request_[] = "bad-request";
+static const char _cannot_start_[] = "cannot-start";
static const char _detail_[] = "detail";
static const char _id_[] = "id";
static const char _install_[] = "install";
@@ -52,31 +57,87 @@ static const char _state_[] = "state";
static const char _terminate_[] = "terminate";
static const char _uninstall_[] = "uninstall";
+/*
+ * the permissions
+ */
+static const struct afb_auth
+ auth_install = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:install"
+ },
+ auth_uninstall = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:uninstall"
+ },
+ auth_preinstall = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:preinstall"
+ },
+ auth_detail = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:detail"
+ },
+ auth_start = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:start"
+ },
+ auth_view_all = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:widget:view-all"
+ },
+ auth_state = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:runner:state"
+ },
+ auth_kill = {
+ .type = afb_auth_Permission,
+ .text = "urn:AGL:permission:afm:system:runner:kill"
+ }
+;
+
+/*
+ * default root
+ */
static const char *rootdir = FWK_APP_DIR;
-static struct afb_event applist_changed_event;
+
+/*
+ * the internal application database
+ */
static struct afm_udb *afudb;
+
+/*
+ * the event signalling that application list changed
+ */
+static struct afb_event applist_changed_event;
+
+/*
+ * the preallocated true json_object
+ */
static struct json_object *json_true;
+/* enforce daemon reload */
static void do_reloads()
{
- /* enforce daemon reload */
systemd_daemon_reload(0);
systemd_unit_restart_name(0, "sockets.target");
}
+/* common bad request reply */
static void bad_request(struct afb_req req)
{
- afb_req_fail(req, "bad-request", NULL);
+ afb_req_fail(req, _bad_request_, NULL);
}
+/* common not found reply */
static void not_found(struct afb_req req)
{
afb_req_fail(req, _not_found_, NULL);
}
+/* common can't start reply */
static void cant_start(struct afb_req req)
{
- afb_req_fail(req, "cannot-start", NULL);
+ afb_req_fail(req, _cannot_start_, NULL);
}
/*
@@ -416,6 +477,9 @@ static void install(struct afb_req req)
}
}
+/*
+ * On querying uninstallation of widget(s)
+ */
static void uninstall(struct afb_req req)
{
const char *idaver;
@@ -463,30 +527,19 @@ static int init()
return -!afb_event_is_valid(applist_changed_event);
}
-static const struct afb_auth
- auth_install = {
- .type = afb_auth_Permission,
- .text = "urn:AGL:permission:afm:system:widget:install"
- },
- auth_uninstall = {
- .type = afb_auth_Permission,
- .text = "urn:AGL:permission:afm:system:widget:uninstall"
- }
-;
-
static const struct afb_verb_v2 verbs[] =
{
- {_runnables_, runnables, NULL, "Get list of runnable applications", AFB_SESSION_CHECK_V2 },
- {_detail_ , detail, NULL, "Get the details for one application", AFB_SESSION_CHECK_V2 },
- {_start_ , start, NULL, "Start an application", AFB_SESSION_CHECK_V2 },
- {_once_ , once, NULL, "Start once an application", AFB_SESSION_CHECK_V2 },
- {_terminate_, terminate, NULL, "Terminate a running application", AFB_SESSION_CHECK_V2 },
- {_pause_ , pause, NULL, "Pause a running application", AFB_SESSION_CHECK_V2 },
- {_resume_ , resume, NULL, "Resume a paused application", AFB_SESSION_CHECK_V2 },
- {_runners_ , runners, NULL, "Get the list of running applications", AFB_SESSION_CHECK_V2 },
- {_state_ , state, NULL, "Get the state of a running application", AFB_SESSION_CHECK_V2 },
- {_install_ , install, NULL, "Install an application using a widget file", AFB_SESSION_CHECK_V2 },
- {_uninstall_, uninstall, NULL, "Uninstall an application", AFB_SESSION_CHECK_V2 },
+ {_runnables_, runnables, &auth_detail, "Get list of runnable applications", AFB_SESSION_CHECK_V2 },
+ {_detail_ , detail, &auth_detail, "Get the details for one application", AFB_SESSION_CHECK_V2 },
+ {_start_ , start, &auth_start, "Start an application", AFB_SESSION_CHECK_V2 },
+ {_once_ , once, &auth_start, "Start once an application", AFB_SESSION_CHECK_V2 },
+ {_terminate_, terminate, &auth_kill, "Terminate a running application", AFB_SESSION_CHECK_V2 },
+ {_pause_ , pause, &auth_kill, "Pause a running application", AFB_SESSION_CHECK_V2 },
+ {_resume_ , resume, &auth_kill, "Resume a paused application", AFB_SESSION_CHECK_V2 },
+ {_runners_ , runners, &auth_state, "Get the list of running applications", AFB_SESSION_CHECK_V2 },
+ {_state_ , state, &auth_state, "Get the state of a running application", AFB_SESSION_CHECK_V2 },
+ {_install_ , install, &auth_install, "Install an application using a widget file", AFB_SESSION_CHECK_V2 },
+ {_uninstall_, uninstall, &auth_uninstall, "Uninstall an application", AFB_SESSION_CHECK_V2 },
{ NULL, NULL, NULL, NULL, 0 }
};