X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=a4ccf6767de6528c91044ef1ca2effba5db767b3;hb=c44a48f295de04e4d0385b05d1afd93fac898d10;hp=d1a262f7d20a7de52d811dfd5a5c5c64b0cfe8d2;hpb=240329595f08192e7b88918cc8868b5af9504dc2;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index d1a262f7..a4ccf676 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -359,6 +359,22 @@ void afb_hreq_reply_error(struct afb_hreq *hreq, unsigned int status) afb_hreq_reply_empty(hreq, status, NULL); } +int afb_hreq_redirect_to_ending_slash_if_needed(struct afb_hreq *hreq) +{ + char *tourl; + + if (hreq->url[hreq->lenurl - 1] == '/') + return 0; + + /* the redirect is needed for reliability of relative path */ + tourl = alloca(hreq->lenurl + 2); + memcpy(tourl, hreq->url, hreq->lenurl); + tourl[hreq->lenurl] = '/'; + tourl[hreq->lenurl + 1] = 0; + afb_hreq_redirect_to(hreq, tourl, 1); + return 1; +} + int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *filename) { int rc; @@ -396,17 +412,10 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f /* serve directory */ if (S_ISDIR(st.st_mode)) { - if (hreq->url[hreq->lenurl - 1] != '/') { - /* the redirect is needed for reliability of relative path */ - char *tourl = alloca(hreq->lenurl + 2); - memcpy(tourl, hreq->url, hreq->lenurl); - tourl[hreq->lenurl] = '/'; - tourl[hreq->lenurl + 1] = 0; - rc = afb_hreq_redirect_to(hreq, tourl, 1); - } else { + rc = afb_hreq_redirect_to_ending_slash_if_needed(hreq); + if (rc == 0) { static const char *indexes[] = { "index.html", NULL }; int i = 0; - rc = 0; while (indexes[i] != NULL) { if (faccessat(fd, indexes[i], R_OK, 0) == 0) { rc = afb_hreq_reply_file_if_exist(hreq, fd, indexes[i]); @@ -564,7 +573,7 @@ static char *url_with_query(struct afb_hreq *hreq, const char *url) return mkq.text; } -int afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url, int add_query_part) +void afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url, int add_query_part) { const char *to; char *wqp; @@ -575,7 +584,6 @@ int afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url, int add_query_p MHD_HTTP_HEADER_LOCATION, to, NULL); DEBUG("redirect from [%s] to [%s]", hreq->url, url); free(wqp); - return 1; } const char *afb_hreq_get_cookie(struct afb_hreq *hreq, const char *name)