X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=0fe908cb6818d5d6ef11c0a8f7677c1a94675dae;hb=44f21bd2a3b50f92669223cdafe79993654c1e19;hp=885a45614f81687e5c1e1a50eb2a980fa0570dc1;hpb=9c4961a0e68458061171aef5f3b30a9b1fa8e333;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 885a4561..0fe908cb 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,7 +38,7 @@ #include "afb-context.h" #include "afb-hreq.h" #include "afb-subcall.h" -#include "session.h" +#include "afb-session.h" #include "verbose.h" #include "locale-root.h" @@ -274,12 +274,22 @@ 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] = { { ".js", "text/javascript" }, { ".html", "text/html" }, { ".css", "text/css" }, + { ".ico", "image/x-icon"}, + { ".png", "image/png" }, + { ".svg", "image/svg+xml" }, + { ".ttf", "application/x-font-ttf"}, { NULL, NULL } }; int i = 0; @@ -325,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); } @@ -930,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;