Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
http: optimize the access verification
  • Loading branch information
perexg committed Sep 8, 2014
1 parent 0fa4c91 commit 8d75fb0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/http.c
Expand Up @@ -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);
}

/**
Expand All @@ -433,19 +440,15 @@ int
http_access_verify_channel(http_connection_t *hc, int mask,
struct channel *ch)
{
access_t *a;
int res = -1;

assert(ch);

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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 8d75fb0

Please sign in to comment.