From: Jaroslav Kysela Date: Wed, 3 Sep 2014 08:03:53 +0000 (+0200) Subject: http: optimize the access verification X-Git-Tag: v4.1~1456 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d75fb09368d88b94e14514cb35c1411b623eb15;p=thirdparty%2Ftvheadend.git http: optimize the access verification --- diff --git a/src/http.c b/src/http.c index 14f94b030..ef340c5c0 100644 --- a/src/http.c +++ b/src/http.c @@ -422,8 +422,15 @@ http_access_verify(http_connection_t *hc, int mask) if (!http_access_verify_ticket(hc)) return 0; - return access_verify(hc->hc_username, hc->hc_password, - (struct sockaddr *)hc->hc_peer, mask); + if (hc->hc_access) + return access_verify2(hc->hc_access, mask); + + hc->hc_access = access_get(hc->hc_username, hc->hc_password, + (struct sockaddr *)hc->hc_peer); + if (hc->hc_access == NULL) + return -1; + + return access_verify2(hc->hc_access, mask); } /** @@ -433,7 +440,6 @@ int http_access_verify_channel(http_connection_t *hc, int mask, struct channel *ch) { - access_t *a; int res = -1; assert(ch); @@ -441,11 +447,8 @@ http_access_verify_channel(http_connection_t *hc, int mask, if (!http_access_verify_ticket(hc)) return 0; - a = access_get(hc->hc_username, hc->hc_password, - (struct sockaddr *)hc->hc_peer); - if (channel_access(ch, a, hc->hc_username)) + if (channel_access(ch, hc->hc_access, hc->hc_username)) res = 0; - access_destroy(a); return res; } @@ -464,12 +467,10 @@ http_exec(http_connection_t *hc, http_path_t *hp, char *remain) err = HTTP_STATUS_UNAUTHORIZED; else { /* FIXME: Recode to obtain access only once */ - hc->hc_access = access_get(hc->hc_username, hc->hc_password, - (struct sockaddr *)hc->hc_peer); err = hp->hp_callback(hc, remain, hp->hp_opaque); - access_destroy(hc->hc_access); - hc->hc_access = NULL; } + access_destroy(hc->hc_access); + hc->hc_access = NULL; if(err == -1) return 1;