- * Connections to D-Bus
- * This is an array for using the function
- * jbus_read_write_dispatch_multiple
- * directly without transformations.
- */
-static struct jbus *jbuses[2];
-#define system_bus jbuses[0]
-#define user_bus jbuses[1]
-
-/*
- * Handle to the database of applications
- */
-#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
-static struct afm_db *afdb;
-#else
-static struct afm_udb *afudb;
-#endif
-
-/*
- * Returned error strings
- */
-const char error_nothing[] = "[]";
-const char error_bad_request[] = "\"bad request\"";
-const char error_not_found[] = "\"not found\"";
-const char error_cant_start[] = "\"can't start\"";
-const char error_system[] = "\"system error\"";
-
-
-/*
- * retrieves the 'runid' in 'obj' parameters received with the
- * request 'smsg' for the 'method'.
- *
- * Returns 1 in case of success.
- * Otherwise, if the 'runid' can't be retrived, an error stating
- * the bad request is replied for 'smsg' and 0 is returned.
- */
-static int onrunid(struct sd_bus_message *smsg, struct json_object *obj,
- const char *method, int *runid)
-{
- if (!j_read_integer(obj, runid)
- && !j_read_integer_at(obj, "runid", runid)) {
- INFO("bad request method %s: %s", method,
- json_object_to_json_string(obj));
- jbus_reply_error_s(smsg, error_bad_request);
- return 0;
- }
-
- INFO("method %s called for %d", method, *runid);
- return 1;
-}
-
-/*
- * Sends the reply 'resp' to the request 'smsg' if 'resp' is not NULL.
- * Otherwise, when 'resp' is NULL replies the error string 'errstr'.
- */
-static void reply(struct sd_bus_message *smsg, struct json_object *resp,
- const char *errstr)
-{
- if (resp)
- jbus_reply_j(smsg, resp);
- else
- jbus_reply_error_s(smsg, errstr);
-}
-
-/*
- * Sends the reply "true" to the request 'smsg' if 'status' is zero.
- * Otherwise, when 'status' is not zero replies the error string 'errstr'.
- */
-static void reply_status(struct sd_bus_message *smsg, int status, const char *errstr)
-{
- if (status)
- jbus_reply_error_s(smsg, errstr);
- else
- jbus_reply_s(smsg, "true");
-}
-
-/*
- * On query "runnables" from 'smsg' with parameters of 'obj'.
- *
- * Nothing is expected in 'obj' that can be anything.