Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
afm-binding: Simplify helpers
[src/app-framework-main.git]
/
src
/
afm-binding.c
diff --git
a/src/afm-binding.c
b/src/afm-binding.c
index
55010a2
..
7e99b20
100644
(file)
--- a/
src/afm-binding.c
+++ b/
src/afm-binding.c
@@
-180,6
+180,9
@@
static void do_reloads()
/* common bad request reply */
static void bad_request(afb_req_t req)
{
/* common bad request reply */
static void bad_request(afb_req_t req)
{
+ INFO("bad request verb %s: %s",
+ afb_req_get_called_verb(req),
+ json_object_to_json_string(afb_req_json(req)));
afb_req_fail(req, _bad_request_, NULL);
}
afb_req_fail(req, _bad_request_, NULL);
}
@@
-239,16
+242,15
@@
static int get_all(afb_req_t req)
&& json_object_get_boolean(val);
}
&& json_object_get_boolean(val);
}
-
/*
* retrieves the 'appid' in parameters received with the
/*
* retrieves the 'appid' in parameters received with the
- * request 'req'
for the 'method'
.
+ * request 'req'.
*
* 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.
*/
*
* 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(afb_req_t req, const char *
method, const char *
*appid)
+static int onappid(afb_req_t req, const char **appid)
{
struct json_object *json;
{
struct json_object *json;
@@
-259,26
+261,24
@@
static int onappid(afb_req_t req, const char *method, const char **appid)
if (!wrap_json_unpack(json, "s", appid)
|| !wrap_json_unpack(json, "{ss}", _id_, appid)) {
/* found */
if (!wrap_json_unpack(json, "s", appid)
|| !wrap_json_unpack(json, "{ss}", _id_, appid)) {
/* found */
- INFO("method %s called for %s",
method
, *appid);
+ INFO("method %s called for %s",
afb_req_get_called_verb(req)
, *appid);
return 1;
}
/* nothing appropriate */
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
bad_request(req);
return 0;
}
/*
* retrieves the 'runid' in parameters received with the
- * request 'req'
for the 'method'
.
+ * request 'req'.
*
* Returns 1 in case of success.
* Otherwise, if the 'runid' can't be retrieved, an error stating
* the bad request is replied for 'req' and 0 is returned.
*/
*
* Returns 1 in case of success.
* 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(afb_req_t req,
const char *method,
int *runid)
+static int onrunid(afb_req_t req, int *runid)
{
struct json_object *json;
const char *appid;
{
struct json_object *json;
const char *appid;
@@
-289,19
+289,19
@@
static int onrunid(afb_req_t req, const char *method, int *runid)
/* get the runid if any */
if (!wrap_json_unpack(json, "i", runid)
|| !wrap_json_unpack(json, "{si}", _runid_, runid)) {
/* 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);
+ INFO("method %s called for %d",
afb_req_get_called_verb(req)
, *runid);
return 1;
}
/* get the appid if any */
return 1;
}
/* get the appid if any */
- if (!onappid(req,
method,
&appid))
+ if (!onappid(req, &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 */
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
,
+ INFO("method %s can't get runid for %s: %m",
afb_req_get_called_verb(req)
,
appid);
if (errno == ESRCH)
not_running(req);
appid);
if (errno == ESRCH)
not_running(req);
@@
-311,7
+311,7
@@
static int onrunid(afb_req_t req, const char *method, int *runid)
}
/* found */
}
/* found */
- INFO("method %s called for %s -> %d",
method
, appid, *runid);
+ INFO("method %s called for %s -> %d",
afb_req_get_called_verb(req)
, appid, *runid);
return 1;
}
return 1;
}
@@
-366,7
+366,7
@@
static void detail(afb_req_t req)
struct json_object *resp;
/* scan the request */
struct json_object *resp;
/* scan the request */
- if (!onappid(req,
_detail_,
&appid))
+ if (!onappid(req, &appid))
return;
/* get the language */
return;
/* get the language */
@@
-390,7
+390,7
@@
static void start(afb_req_t req)
int runid;
/* scan the request */
int runid;
/* scan the request */
- if (!onappid(req,
_start_,
&appid))
+ if (!onappid(req, &appid))
return;
/* get the application */
return;
/* get the application */
@@
-427,7
+427,7
@@
static void once(afb_req_t req)
int runid;
/* scan the request */
int runid;
/* scan the request */
- if (!onappid(req,
_once_,
&appid))
+ if (!onappid(req, &appid))
return;
/* get the application */
return;
/* get the application */
@@
-455,7
+455,7
@@
static void once(afb_req_t req)
static void pause(afb_req_t req)
{
int runid, status;
static void pause(afb_req_t req)
{
int runid, status;
- if (onrunid(req,
"pause",
&runid)) {
+ if (onrunid(req, &runid)) {
status = afm_urun_pause(runid, afb_req_get_uid(req));
reply_status(req, status);
}
status = afm_urun_pause(runid, afb_req_get_uid(req));
reply_status(req, status);
}
@@
-467,7
+467,7
@@
static void pause(afb_req_t req)
static void resume(afb_req_t req)
{
int runid, status;
static void resume(afb_req_t req)
{
int runid, status;
- if (onrunid(req,
"resume",
&runid)) {
+ if (onrunid(req, &runid)) {
status = afm_urun_resume(runid, afb_req_get_uid(req));
reply_status(req, status);
}
status = afm_urun_resume(runid, afb_req_get_uid(req));
reply_status(req, status);
}
@@
-479,7
+479,7
@@
static void resume(afb_req_t req)
static void terminate(afb_req_t req)
{
int runid, status;
static void terminate(afb_req_t req)
{
int runid, status;
- if (onrunid(req,
"terminate",
&runid)) {
+ if (onrunid(req, &runid)) {
status = afm_urun_terminate(runid, afb_req_get_uid(req));
reply_status(req, status);
}
status = afm_urun_terminate(runid, afb_req_get_uid(req));
reply_status(req, status);
}
@@
-504,7
+504,7
@@
static void state(afb_req_t req)
{
int runid;
struct json_object *resp;
{
int runid;
struct json_object *resp;
- if (onrunid(req,
"state",
&runid)) {
+ if (onrunid(req, &runid)) {
resp = afm_urun_state(afudb, runid, afb_req_get_uid(req));
reply(req, resp);
}
resp = afm_urun_state(afudb, runid, afb_req_get_uid(req));
reply(req, resp);
}