X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=b1f300db6c1ccd527e7556d1609d369befb78b43;hb=ceb2e567b5f26ff148fbc0e9526f7e7e99464000;hp=518bc5cb50eb59ed1723f44c2429b3f979314d53;hpb=f1b901ed676b2d45ec8e6ae3d6ef2f94d79f9ee6;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 518bc5cb..b1f300db 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 IoT.bzh + * Copyright (C) 2016 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,14 +26,14 @@ #include #include -#include +#include #if defined(USE_MAGIC_MIME_TYPE) #include #endif #include "afb-method.h" -#include "afb-req-itf.h" +#include #include "afb-msg-json.h" #include "afb-context.h" #include "afb-hreq.h" @@ -44,13 +44,11 @@ static char empty_string[] = ""; -static const char uuid_header[] = "x-afb-uuid"; -static const char uuid_arg[] = "uuid"; -static const char uuid_cookie[] = "uuid"; +static const char key_for_uuid[] = "x-afb-uuid"; +static const char old_key_for_uuid[] = "uuid"; -static const char token_header[] = "x-afb-token"; -static const char token_arg[] = "token"; -static const char token_cookie[] = "token"; +static const char key_for_token[] = "x-afb-token"; +static const char old_key_for_token[] = "token"; static char *cookie_name = NULL; static char *cookie_setter = NULL; @@ -234,18 +232,15 @@ static magic_t lazy_libmagic() done = 1; /* MAGIC_MIME tells magic to return a mime of the file, but you can specify different things */ - if (verbosity) - fprintf(stderr, "Loading mimetype default magic database\n"); - + INFO("Loading mimetype default magic database"); result = magic_open(MAGIC_MIME_TYPE); if (result == NULL) { - fprintf(stderr,"ERROR: unable to initialize magic library\n"); + ERROR("unable to initialize magic library"); } /* Warning: should not use NULL for DB [libmagic bug wont pass efence check] */ else if (magic_load(result, MAGIC_DB) != 0) { - fprintf(stderr,"cannot load magic database - %s\n", - magic_error(result)); + ERROR("cannot load magic database: %s", magic_error(result)); magic_close(result); result = NULL; } @@ -435,8 +430,7 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f if (inm && 0 == strcmp(inm, etag)) { /* etag ok, return NOT MODIFIED */ close(fd); - if (verbosity) - fprintf(stderr, "Not Modified: [%s]\n", filename); + DEBUG("Not Modified: [%s]", filename); response = MHD_create_response_from_buffer(0, empty_string, MHD_RESPMEM_PERSISTENT); status = MHD_HTTP_NOT_MODIFIED; } else { @@ -475,10 +469,10 @@ int afb_hreq_reply_file(struct afb_hreq *hreq, int dirfd, const char *filename) int afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url) { + /* TODO: append the query part! */ afb_hreq_reply_static(hreq, MHD_HTTP_MOVED_PERMANENTLY, 0, NULL, MHD_HTTP_HEADER_LOCATION, url, NULL); - if (verbosity) - fprintf(stderr, "redirect from [%s] to [%s]\n", hreq->url, url); + DEBUG("redirect from [%s] to [%s]", hreq->url, url); return 1; } @@ -712,17 +706,19 @@ int afb_hreq_init_context(struct afb_hreq *hreq) if (hreq->context.session != NULL) return 0; - uuid = afb_hreq_get_header(hreq, uuid_header); + uuid = afb_hreq_get_header(hreq, key_for_uuid); if (uuid == NULL) - uuid = afb_hreq_get_argument(hreq, uuid_arg); + uuid = afb_hreq_get_argument(hreq, key_for_uuid); if (uuid == NULL) uuid = afb_hreq_get_cookie(hreq, cookie_name); + if (uuid == NULL) + uuid = afb_hreq_get_argument(hreq, old_key_for_uuid); - token = afb_hreq_get_header(hreq, token_header); + token = afb_hreq_get_header(hreq, key_for_token); if (token == NULL) - token = afb_hreq_get_argument(hreq, token_arg); + token = afb_hreq_get_argument(hreq, key_for_token); if (token == NULL) - token = afb_hreq_get_cookie(hreq, token_cookie); + token = afb_hreq_get_argument(hreq, old_key_for_token); return afb_context_connect(&hreq->context, uuid, token); } @@ -737,7 +733,7 @@ int afb_hreq_init_cookie(int port, const char *path, int maxage) cookie_setter = NULL; path = path ? : "/"; - rc = asprintf(&cookie_name, "x-afb-uuid-%d", port); + rc = asprintf(&cookie_name, "%s-%d", key_for_uuid, port); if (rc < 0) return 0; rc = asprintf(&cookie_setter, "%s=%%s; Path=%s; Max-Age=%d; HttpOnly",