mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
Convert uri_redirects list to read/write locks.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49027 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
46
main/http.c
46
main/http.c
@@ -131,7 +131,7 @@ struct http_uri_redirect {
|
||||
char target[0];
|
||||
};
|
||||
|
||||
static AST_LIST_HEAD_STATIC(uri_redirects, http_uri_redirect);
|
||||
static AST_RWLIST_HEAD_STATIC(uri_redirects, http_uri_redirect);
|
||||
|
||||
static char *ftype2mtype(const char *ftype, char *wkspace, int wkspacelen)
|
||||
{
|
||||
@@ -383,8 +383,8 @@ static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *statu
|
||||
*cookies = NULL;
|
||||
ast_uri_decode(uri);
|
||||
|
||||
AST_LIST_LOCK(&uri_redirects);
|
||||
AST_LIST_TRAVERSE(&uri_redirects, redirect, entry) {
|
||||
AST_RWLIST_RDLOCK(&uri_redirects);
|
||||
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry) {
|
||||
if (!strcasecmp(uri, redirect->target)) {
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof(buf), "Location: %s\r\n", redirect->dest);
|
||||
@@ -395,7 +395,7 @@ static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *statu
|
||||
break;
|
||||
}
|
||||
}
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
if (redirect)
|
||||
goto cleanup;
|
||||
|
||||
@@ -837,28 +837,28 @@ static void add_redirect(const char *value)
|
||||
strcpy(redirect->target, target);
|
||||
strcpy(redirect->dest, dest);
|
||||
|
||||
AST_LIST_LOCK(&uri_redirects);
|
||||
AST_RWLIST_WRLOCK(&uri_redirects);
|
||||
|
||||
target_len--; /* So we can compare directly with strlen() */
|
||||
if ( AST_LIST_EMPTY(&uri_redirects)
|
||||
|| strlen(AST_LIST_FIRST(&uri_redirects)->target) <= target_len ) {
|
||||
AST_LIST_INSERT_HEAD(&uri_redirects, redirect, entry);
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
if ( AST_RWLIST_EMPTY(&uri_redirects)
|
||||
|| strlen(AST_RWLIST_FIRST(&uri_redirects)->target) <= target_len ) {
|
||||
AST_RWLIST_INSERT_HEAD(&uri_redirects, redirect, entry);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
return;
|
||||
}
|
||||
|
||||
AST_LIST_TRAVERSE(&uri_redirects, cur, entry) {
|
||||
if ( AST_LIST_NEXT(cur, entry)
|
||||
&& strlen(AST_LIST_NEXT(cur, entry)->target) <= target_len ) {
|
||||
AST_LIST_INSERT_AFTER(&uri_redirects, cur, redirect, entry);
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
AST_RWLIST_TRAVERSE(&uri_redirects, cur, entry) {
|
||||
if ( AST_RWLIST_NEXT(cur, entry)
|
||||
&& strlen(AST_RWLIST_NEXT(cur, entry)->target) <= target_len ) {
|
||||
AST_RWLIST_INSERT_AFTER(&uri_redirects, cur, redirect, entry);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AST_LIST_INSERT_TAIL(&uri_redirects, redirect, entry);
|
||||
AST_RWLIST_INSERT_TAIL(&uri_redirects, redirect, entry);
|
||||
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
}
|
||||
|
||||
static int __ast_http_load(int reload)
|
||||
@@ -889,10 +889,10 @@ static int __ast_http_load(int reload)
|
||||
free(http_tls_cfg.cipher);
|
||||
http_tls_cfg.cipher = ast_strdup("");
|
||||
|
||||
AST_LIST_LOCK(&uri_redirects);
|
||||
while ((redirect = AST_LIST_REMOVE_HEAD(&uri_redirects, entry)))
|
||||
AST_RWLIST_WRLOCK(&uri_redirects);
|
||||
while ((redirect = AST_RWLIST_REMOVE_HEAD(&uri_redirects, entry)))
|
||||
free(redirect);
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
|
||||
cfg = ast_config_load("http.conf");
|
||||
if (cfg) {
|
||||
@@ -989,12 +989,12 @@ static int handle_show_http(int fd, int argc, char *argv[])
|
||||
AST_RWLIST_UNLOCK(&uris);
|
||||
|
||||
ast_cli(fd, "\nEnabled Redirects:\n");
|
||||
AST_LIST_LOCK(&uri_redirects);
|
||||
AST_LIST_TRAVERSE(&uri_redirects, redirect, entry)
|
||||
AST_RWLIST_RDLOCK(&uri_redirects);
|
||||
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry)
|
||||
ast_cli(fd, " %s => %s\n", redirect->target, redirect->dest);
|
||||
if (AST_LIST_EMPTY(&uri_redirects))
|
||||
if (AST_RWLIST_EMPTY(&uri_redirects))
|
||||
ast_cli(fd, " None.\n");
|
||||
AST_LIST_UNLOCK(&uri_redirects);
|
||||
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user