#include "verbose.h"
#include "utils-systemd.h"
-#include "afm.h"
#include "afm-udb.h"
#include "afm-urun.h"
#include "wgt-info.h"
afb_event_broadcast(applist_changed_event, e);
}
+/*
+ * retrieves the 'appid' in parameters received with the
+ * request 'req' for the 'method'.
+ *
+ * Returns 1 in case of success.
+ * Otherwise, if the 'appid' can't be retrieved, an error stating
+ * the bad request is replied for 'req' and 0 is returned.
+ */
+static int onappid(struct afb_req req, const char *method, const char **appid)
+{
+ struct json_object *json;
+
+ /* get the paramaters of the request */
+ json = afb_req_json(req);
+
+ /* get the appid if any */
+ if (!wrap_json_unpack(json, "s", appid)
+ || !wrap_json_unpack(json, "{si}", _id_, appid)) {
+ /* found */
+ INFO("method %s called for %s", method, *appid);
+ return 1;
+ }
+
+ /* nothing appropriate */
+ INFO("bad request method %s: %s", method,
+ json_object_to_json_string(json));
+ bad_request(req);
+ return 0;
+}
+
/*
* retrieves the 'runid' in parameters received with the
* request 'req' for the 'method'.
*
* Returns 1 in case of success.
- * Otherwise, if the 'runid' can't be retrived, an error stating
+ * Otherwise, if the 'runid' can't be retrieved, an error stating
* the bad request is replied for 'req' and 0 is returned.
*/
static int onrunid(struct afb_req req, const char *method, int *runid)
{
struct json_object *json;
+ const char *appid;
+ /* get the paramaters of the request */
json = afb_req_json(req);
- if (wrap_json_unpack(json, "s", runid)
- || wrap_json_unpack(json, "{ss}", "runid", runid)) {
- INFO("bad request method %s: %s", method,
- json_object_to_json_string(json));
- bad_request(req);
+
+ /* get the runid if any */
+ if (!wrap_json_unpack(json, "i", runid)
+ || !wrap_json_unpack(json, "{si}", _runid_, runid)) {
+ INFO("method %s called for %d", method, *runid);
+ return 1;
+ }
+
+ /* get the appid if any */
+ if (!onappid(req, method, &appid))
+ return 0;
+
+ /* search the runid of the appid */
+ *runid = afm_urun_search_runid(afudb, appid, afb_req_get_uid(req));
+ if (*runid < 0) {
+ /* nothing appropriate */
+ INFO("method %s can't get runid for %s: %m", method,
+ appid);
+ not_found(req);
return 0;
}
- INFO("method %s called for %d", method, *runid);
+ /* found */
+ INFO("method %s called for %s -> %d", method, appid, *runid);
return 1;
}
static void detail(struct afb_req req)
{
const char *appid;
- struct json_object *resp, *json;
+ struct json_object *resp;
/* scan the request */
- json = afb_req_json(req);
- if (wrap_json_unpack(json, "s", &appid)
- || wrap_json_unpack(json, "{ss}", _id_, &appid)) {
- bad_request(req);
+ if (!onappid(req, _detail_, &appid))
return;
- }
/* wants details for appid */
- INFO("method detail called for %s", appid);
resp = afm_udb_get_application_public(afudb, appid, afb_req_get_uid(req));
if (resp)
afb_req_success(req, resp, NULL);
static void start(struct afb_req req)
{
const char *appid;
- struct json_object *appli, *resp, *json;
+ struct json_object *appli, *resp;
int runid;
/* scan the request */
- json = afb_req_json(req);
- if (wrap_json_unpack(json, "s", &appid)
- || wrap_json_unpack(json, "{ss}", _id_, &appid)) {
- bad_request(req);
+ if (!onappid(req, _start_, &appid))
return;
- }
/* get the application */
- INFO("method start called for %s", appid);
appli = afm_udb_get_application_private(afudb, appid, afb_req_get_uid(req));
if (appli == NULL) {
not_found(req);
/* returns */
resp = NULL;
+#if 0
wrap_json_pack(&resp, "{si}", _runid_, runid);
+#else
+ wrap_json_pack(&resp, "i", runid);
+#endif
afb_req_success(req, resp, NULL);
}
static void once(struct afb_req req)
{
const char *appid;
- struct json_object *appli, *resp, *json;
+ struct json_object *appli, *resp;
int runid;
/* scan the request */
- json = afb_req_json(req);
- if (wrap_json_unpack(json, "s", &appid)
- || wrap_json_unpack(json, "{ss}", _id_, &appid)) {
- bad_request(req);
+ if (!onappid(req, _once_, &appid))
return;
- }
/* get the application */
- INFO("method once called for %s", appid);
appli = afm_udb_get_application_private(afudb, appid, afb_req_get_uid(req));
if (appli == NULL) {
not_found(req);
/* scan the request */
json = afb_req_json(req);
if (wrap_json_unpack(json, "s", &wgtfile)
- || wrap_json_unpack(json, "{ss s?s s?b s?b}",
+ && wrap_json_unpack(json, "{ss s?s s?b s?b}",
"wgt", &wgtfile,
"root", &root,
"force", &force,
if (ifo == NULL)
afb_req_fail_f(req, "failed", "installation failed: %m");
else {
+ afm_udb_update(afudb);
/* reload if needed */
if (reload)
do_reloads();
/* scan the request */
json = afb_req_json(req);
if (wrap_json_unpack(json, "s", &idaver)
- || wrap_json_unpack(json, "{ss s?s}",
+ && wrap_json_unpack(json, "{ss s?s}",
_id_, &idaver,
"root", &root)) {
return bad_request(req);
if (rc)
afb_req_fail_f(req, "failed", "uninstallation failed: %m");
else {
+ afm_udb_update(afudb);
afb_req_success(req, NULL, NULL);
application_list_changed(_uninstall_, idaver);
}
return -1;
}
- /* set the systemd's buses */
- systemd_set_bus(0, afb_daemon_get_system_bus());
- systemd_set_bus(1, afb_daemon_get_user_bus());
-
/* create TRUE */
json_true = json_object_new_boolean(1);