dect
/
asterisk
Archived
13
0
Fork 0

comment some functions, and more small code simplifications

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@45169 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
rizzo 2006-10-16 08:38:35 +00:00
parent 8ec107ece6
commit 031898f74c
1 changed files with 40 additions and 30 deletions

View File

@ -68,8 +68,9 @@ static struct ast_http_uri *uris;
static int httpfd = -1; static int httpfd = -1;
static pthread_t master = AST_PTHREADT_NULL; static pthread_t master = AST_PTHREADT_NULL;
/* all valid URIs must be prepended by the string in prefix. */
static char prefix[MAX_PREFIX]; static char prefix[MAX_PREFIX];
static int prefix_len = 0;
static struct sockaddr_in oldsin; static struct sockaddr_in oldsin;
static int enablestatic=0; static int enablestatic=0;
@ -239,14 +240,23 @@ char *ast_http_error(int status, const char *title, const char *extra_header, co
return c; return c;
} }
/*! \brief
* Link the new uri into the list. They are sorted by length of
* the string, not alphabetically. Duplicate entries are not replaced,
* but the insertion order (using <= and not just <) makes sure that
* more recent insertions hide older ones.
* On a lookup, we just scan the list and stop at the first matching entry.
*/
int ast_http_uri_link(struct ast_http_uri *urih) int ast_http_uri_link(struct ast_http_uri *urih)
{ {
struct ast_http_uri *prev=uris; struct ast_http_uri *prev=uris;
if (!uris || strlen(uris->uri) <= strlen(urih->uri)) { int len = strlen(urih->uri);
if (!uris || strlen(uris->uri) <= len ) {
urih->next = uris; urih->next = uris;
uris = urih; uris = urih;
} else { } else {
while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri))) while (prev->next && strlen(prev->next->uri) > len)
prev = prev->next; prev = prev->next;
/* Insert it here */ /* Insert it here */
urih->next = prev->next; urih->next = prev->next;
@ -275,17 +285,16 @@ void ast_http_uri_unlink(struct ast_http_uri *urih)
static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies) static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies)
{ {
char *c; char *c;
char *turi;
char *params; char *params;
char *var;
char *val;
struct ast_http_uri *urih=NULL; struct ast_http_uri *urih=NULL;
int len; int prefix_len;
struct ast_variable *vars=NULL, *v, *prev = NULL; struct ast_variable *vars=NULL, *v, *prev = NULL;
/* Extract arguments from the request and store them in variables. */
params = strchr(uri, '?'); params = strchr(uri, '?');
if (params) { if (params) {
char *var, *val;
*params++ = '\0'; *params++ = '\0';
while ((var = strsep(&params, "&"))) { while ((var = strsep(&params, "&"))) {
val = strchr(var, '='); val = strchr(var, '=');
@ -304,32 +313,35 @@ static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **
} }
} }
} }
/*
* Append the cookies to the variables (the only reason to have them
* at the end is to avoid another pass of the cookies list to find
* the tail.
*/
if (prev) if (prev)
prev->next = *cookies; prev->next = *cookies;
else else
vars = *cookies; vars = *cookies;
*cookies = NULL; *cookies = NULL;
ast_uri_decode(uri); ast_uri_decode(uri);
if (!strncasecmp(uri, prefix, prefix_len)) {
uri += prefix_len; /* We want requests to start with the prefix and '/' */
if (!*uri || (*uri == '/')) { prefix_len = strlen(prefix);
if (*uri == '/') if (prefix_len && !strncasecmp(uri, prefix, prefix_len) && uri[prefix_len] == '/') {
uri++; uri += prefix_len + 1;
urih = uris; /* scan registered uris to see if we match one. */
while(urih) { for (urih = uris; urih; urih = urih->next) {
len = strlen(urih->uri); int len = strlen(urih->uri);
if (!strncasecmp(urih->uri, uri, len)) { if (!strncasecmp(urih->uri, uri, len)) {
if (!uri[len] || uri[len] == '/') { if (!uri[len] || uri[len] == '/') {
turi = uri + len; char *turi = uri + len; /* possible candidate */
if (*turi == '/') if (*turi == '/')
turi++; turi++;
if (!*turi || urih->has_subtree) { if (!*turi || urih->has_subtree) {
uri = turi; uri = turi;
break; break;
}
} }
} }
urih = urih->next;
} }
} }
} }
@ -639,10 +651,8 @@ static int __ast_http_load(int reload)
} }
if (enabled) if (enabled)
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (strcmp(prefix, newprefix)) { if (strcmp(prefix, newprefix))
ast_copy_string(prefix, newprefix, sizeof(prefix)); ast_copy_string(prefix, newprefix, sizeof(prefix));
prefix_len = strlen(prefix);
}
enablestatic = newenablestatic; enablestatic = newenablestatic;
http_server_start(&sin); http_server_start(&sin);
return 0; return 0;