X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fhelper-api.c;h=303fd57d1fd48960ed183f3439b10753f9d33c1e;hb=cc4b56b6710624c069642d1a510d0060949fe5b9;hp=7684469b0c198880c72d400a41bef783d758ad4d;hpb=1dce3309d91cb73df9234222227585917c8ee9f4;p=src%2Fapp-framework-binder.git diff --git a/src/helper-api.c b/src/helper-api.c index 7684469b..303fd57d 100644 --- a/src/helper-api.c +++ b/src/helper-api.c @@ -21,6 +21,7 @@ #include #include #include +#include // handle to hold queryAll values @@ -30,50 +31,20 @@ typedef struct { size_t len; } queryHandleT; -static AFB_errorT AFBerr [AFB_SUCCESS+1]; -static json_object *jTypeStatic; -PUBLIC int verbose; - -/* ------------------------------------------------------------------------------ - * Get localtime and return in a string - * ------------------------------------------------------------------------------ */ - -PUBLIC char * configTime (void) { - static char reqTime [26]; - time_t tt; - struct tm *rt; - - /* Get actual Date and Time */ - time (&tt); - rt = localtime (&tt); +// Error code are requested through function to manage json usage count +typedef struct { + int level; + const char* label; + json_object *json; +} AFB_errorT; - strftime (reqTime, sizeof (reqTime), "(%d-%b %H:%M)",rt); +static AFB_errorT AFBerr [AFB_UNAUTH+1]; +static json_object *jTypeStatic; - // return pointer on static data - return (reqTime); -} +PUBLIC int verbose; +static const char *ERROR_LABEL[] = {"false", "true", "fatal", "fail", "warning", "empty", "success", "done", "unauth"}; -// Sample Generic Ping Debug API -json_object* getPingTest(AFB_request *request) { - static int pingcount = 0; - json_object *response; - char query [256]; - char session[256]; - int len; - - // request all query key/value - len = getQueryAll (request, query, sizeof(query)); - if (len == 0) strncpy (query, "NoSearchQueryList", sizeof(query)); - - // check if we have some post data - if (request->post == NULL) request->post->data="NoData"; - - // return response to caller - response = jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon count=%d uuid=%s query={%s} session={0x%x} PostData: [%s] " - , pingcount++, request->uuid, query, session, request->post->data); - return (response); -} // Helper to retrieve argument from connection @@ -254,7 +225,7 @@ static void jsoninit() verbosesav = verbose; verbose = 0; // run initialisation in silent mode jTypeStatic = json_object_new_string ("AFB_message"); - for (idx = 0; idx <= AFB_SUCCESS; idx++) { + for (idx = 0; idx <= AFB_UNAUTH; idx++) { AFBerr[idx].level = idx; AFBerr[idx].label = ERROR_LABEL [idx]; AFBerr[idx].json = jsonNewMessage (idx, NULL); @@ -263,25 +234,6 @@ static void jsoninit() } - -// get JSON object from error level and increase its reference count -struct json_object *jsonNewStatus (AFB_error level) -{ - jsoninit(); - json_object *target = AFBerr[level].json; - json_object_get (target); - - return (target); -} - -// get AFB object type with adequate usage count -struct json_object *jsonNewjtype (void) -{ - jsoninit(); - json_object_get (jTypeStatic); // increase reference count - return (jTypeStatic); -} - // build an ERROR message and return it as a valid json object struct json_object *jsonNewMessage (AFB_error level, char* format, ...) { static int count = 0; @@ -299,7 +251,7 @@ struct json_object *jsonNewMessage (AFB_error level, char* format, ...) { } AFBResponse = json_object_new_object(); - json_object_object_add (AFBResponse, "jtype", jsonNewjtype ()); + json_object_object_add (AFBResponse, "jtype", json_object_get (jTypeStatic)); json_object_object_add (AFBResponse, "status" , json_object_new_string (ERROR_LABEL[level])); if (format != NULL) { json_object_object_add (AFBResponse, "info" , json_object_new_string (message)); @@ -317,11 +269,3 @@ struct json_object *jsonNewMessage (AFB_error level, char* format, ...) { return (AFBResponse); } -// Dump a message on stderr -void jsonDumpObject (struct json_object * jObject) { - - if (verbose) { - fprintf (stderr, "AFB:dump [%s]\n", json_object_to_json_string(jObject)); - } -} -