Merged revisions 49024 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r49024 | qwell | 2006-12-28 14:52:46 -0500 (Thu, 28 Dec 2006) | 2 lines make the uris_lock a rwlock instead of a mutex lock - needs to be forward ported to trunk ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@49026 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
553307308a
commit
7aff08fedb
1 changed files with 26 additions and 24 deletions
50
main/http.c
50
main/http.c
|
@ -107,7 +107,7 @@ static struct server_args https_desc = {
|
|||
.worker_fn = httpd_helper_thread,
|
||||
};
|
||||
|
||||
static AST_LIST_HEAD_STATIC(uris, ast_http_uri); /*!< list of supported handlers */
|
||||
static AST_RWLIST_HEAD_STATIC(uris, ast_http_uri); /*!< list of supported handlers */
|
||||
|
||||
/* all valid URIs must be prepended by the string in prefix. */
|
||||
static char prefix[MAX_PREFIX];
|
||||
|
@ -309,35 +309,35 @@ int ast_http_uri_link(struct ast_http_uri *urih)
|
|||
struct ast_http_uri *uri;
|
||||
int len = strlen(urih->uri);
|
||||
|
||||
AST_LIST_LOCK(&uris);
|
||||
AST_RWLIST_WRLOCK(&uris);
|
||||
|
||||
if ( AST_LIST_EMPTY(&uris) || strlen(AST_LIST_FIRST(&uris)->uri) <= len ) {
|
||||
AST_LIST_INSERT_HEAD(&uris, urih, entry);
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
|
||||
AST_RWLIST_INSERT_HEAD(&uris, urih, entry);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AST_LIST_TRAVERSE(&uris, uri, entry) {
|
||||
if ( AST_LIST_NEXT(uri, entry)
|
||||
&& strlen(AST_LIST_NEXT(uri, entry)->uri) <= len ) {
|
||||
AST_LIST_INSERT_AFTER(&uris, uri, urih, entry);
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
AST_RWLIST_TRAVERSE(&uris, uri, entry) {
|
||||
if ( AST_RWLIST_NEXT(uri, entry)
|
||||
&& strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len ) {
|
||||
AST_RWLIST_INSERT_AFTER(&uris, uri, urih, entry);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
AST_LIST_INSERT_TAIL(&uris, urih, entry);
|
||||
AST_RWLIST_INSERT_TAIL(&uris, urih, entry);
|
||||
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ast_http_uri_unlink(struct ast_http_uri *urih)
|
||||
{
|
||||
AST_LIST_LOCK(&uris);
|
||||
AST_LIST_REMOVE(&uris, urih, entry);
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
AST_RWLIST_WRLOCK(&uris);
|
||||
AST_RWLIST_REMOVE(&uris, urih, entry);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
}
|
||||
|
||||
static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength, struct ast_variable **cookies)
|
||||
|
@ -404,8 +404,8 @@ static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *statu
|
|||
if (l && !strncasecmp(uri, prefix, l) && uri[l] == '/') {
|
||||
uri += l + 1;
|
||||
/* scan registered uris to see if we match one. */
|
||||
AST_LIST_LOCK(&uris);
|
||||
AST_LIST_TRAVERSE(&uris, urih, entry) {
|
||||
AST_RWLIST_RDLOCK(&uris);
|
||||
AST_RWLIST_TRAVERSE(&uris, urih, entry) {
|
||||
l = strlen(urih->uri);
|
||||
c = uri + l; /* candidate */
|
||||
if (strncasecmp(urih->uri, uri, l) /* no match */
|
||||
|
@ -419,11 +419,11 @@ static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *statu
|
|||
}
|
||||
}
|
||||
if (!urih)
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
}
|
||||
if (urih) {
|
||||
out = urih->callback(sin, uri, vars, status, title, contentlength);
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
} else {
|
||||
out = ast_http_error(404, "Not Found", NULL,
|
||||
"The requested URL was not found on this server.");
|
||||
|
@ -979,12 +979,14 @@ static int handle_show_http(int fd, int argc, char *argv[])
|
|||
}
|
||||
|
||||
ast_cli(fd, "Enabled URI's:\n");
|
||||
AST_LIST_LOCK(&uris);
|
||||
AST_LIST_TRAVERSE(&uris, urih, entry)
|
||||
ast_cli(fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
|
||||
if (AST_LIST_EMPTY(&uris))
|
||||
AST_RWLIST_RDLOCK(&uris);
|
||||
if (AST_RWLIST_EMPTY(&uris)) {
|
||||
ast_cli(fd, "None.\n");
|
||||
AST_LIST_UNLOCK(&uris);
|
||||
} else {
|
||||
AST_RWLIST_TRAVERSE(&uris, urih, entry)
|
||||
ast_cli(fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
|
||||
ast_cli(fd, "\nEnabled Redirects:\n");
|
||||
AST_LIST_LOCK(&uri_redirects);
|
||||
|
|
Reference in a new issue