Simplify functions for calls
[src/app-framework-binder.git] / src / afb-hreq.c
index 5052cca..0fe908c 100644 (file)
@@ -274,6 +274,12 @@ static const char *mimetype_fd_name(int fd, const char *filename)
        const char *result = NULL;
 
 #if defined(INFER_EXTENSION)
+       /*
+        * Set some well-known extensions
+        * Note that it is mandatory for example for css files in order to provide
+        * right mimetype that must be text/css (otherwise chrome browser will not
+        * load correctly css file) while libmagic returns text/plain.
+        */
        const char *extension = strrchr(filename, '.');
        if (extension) {
                static const char *const known[][2] = {
@@ -329,6 +335,8 @@ void afb_hreq_unref(struct afb_hreq *hreq)
        }
        afb_context_disconnect(&hreq->context);
        json_object_put(hreq->json);
+       free(hreq->api);
+       free(hreq->verb);
        free(hreq);
 }
 
@@ -934,6 +942,20 @@ static void req_subcall(struct afb_hreq *hreq, const char *api, const char *verb
        afb_subcall(&hreq->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_hreq_req_itf, .closure = hreq });
 }
 
+int afb_hreq_init_req_call(struct afb_hreq *hreq, const char *api, size_t lenapi, const char *verb, size_t lenverb)
+{
+       free(hreq->api);
+       free(hreq->verb);
+       hreq->api = strndup(api, lenapi);
+       hreq->verb = strndup(verb, lenverb);
+       if (hreq->api == NULL || hreq->verb == NULL) {
+               ERROR("Out of memory");
+               errno = ENOMEM;
+               return -1;
+       }
+       return afb_hreq_init_context(hreq);
+}
+
 int afb_hreq_init_context(struct afb_hreq *hreq)
 {
        const char *uuid;