mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 23:08:32 +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];
|
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)
|
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;
|
*cookies = NULL;
|
||||||
ast_uri_decode(uri);
|
ast_uri_decode(uri);
|
||||||
|
|
||||||
AST_LIST_LOCK(&uri_redirects);
|
AST_RWLIST_RDLOCK(&uri_redirects);
|
||||||
AST_LIST_TRAVERSE(&uri_redirects, redirect, entry) {
|
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry) {
|
||||||
if (!strcasecmp(uri, redirect->target)) {
|
if (!strcasecmp(uri, redirect->target)) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
snprintf(buf, sizeof(buf), "Location: %s\r\n", redirect->dest);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AST_LIST_UNLOCK(&uri_redirects);
|
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||||
if (redirect)
|
if (redirect)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@@ -837,28 +837,28 @@ static void add_redirect(const char *value)
|
|||||||
strcpy(redirect->target, target);
|
strcpy(redirect->target, target);
|
||||||
strcpy(redirect->dest, dest);
|
strcpy(redirect->dest, dest);
|
||||||
|
|
||||||
AST_LIST_LOCK(&uri_redirects);
|
AST_RWLIST_WRLOCK(&uri_redirects);
|
||||||
|
|
||||||
target_len--; /* So we can compare directly with strlen() */
|
target_len--; /* So we can compare directly with strlen() */
|
||||||
if ( AST_LIST_EMPTY(&uri_redirects)
|
if ( AST_RWLIST_EMPTY(&uri_redirects)
|
||||||
|| strlen(AST_LIST_FIRST(&uri_redirects)->target) <= target_len ) {
|
|| strlen(AST_RWLIST_FIRST(&uri_redirects)->target) <= target_len ) {
|
||||||
AST_LIST_INSERT_HEAD(&uri_redirects, redirect, entry);
|
AST_RWLIST_INSERT_HEAD(&uri_redirects, redirect, entry);
|
||||||
AST_LIST_UNLOCK(&uri_redirects);
|
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_LIST_TRAVERSE(&uri_redirects, cur, entry) {
|
AST_RWLIST_TRAVERSE(&uri_redirects, cur, entry) {
|
||||||
if ( AST_LIST_NEXT(cur, entry)
|
if ( AST_RWLIST_NEXT(cur, entry)
|
||||||
&& strlen(AST_LIST_NEXT(cur, entry)->target) <= target_len ) {
|
&& strlen(AST_RWLIST_NEXT(cur, entry)->target) <= target_len ) {
|
||||||
AST_LIST_INSERT_AFTER(&uri_redirects, cur, redirect, entry);
|
AST_RWLIST_INSERT_AFTER(&uri_redirects, cur, redirect, entry);
|
||||||
AST_LIST_UNLOCK(&uri_redirects);
|
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||||
return;
|
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)
|
static int __ast_http_load(int reload)
|
||||||
@@ -889,10 +889,10 @@ static int __ast_http_load(int reload)
|
|||||||
free(http_tls_cfg.cipher);
|
free(http_tls_cfg.cipher);
|
||||||
http_tls_cfg.cipher = ast_strdup("");
|
http_tls_cfg.cipher = ast_strdup("");
|
||||||
|
|
||||||
AST_LIST_LOCK(&uri_redirects);
|
AST_RWLIST_WRLOCK(&uri_redirects);
|
||||||
while ((redirect = AST_LIST_REMOVE_HEAD(&uri_redirects, entry)))
|
while ((redirect = AST_RWLIST_REMOVE_HEAD(&uri_redirects, entry)))
|
||||||
free(redirect);
|
free(redirect);
|
||||||
AST_LIST_UNLOCK(&uri_redirects);
|
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||||
|
|
||||||
cfg = ast_config_load("http.conf");
|
cfg = ast_config_load("http.conf");
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
@@ -989,12 +989,12 @@ static int handle_show_http(int fd, int argc, char *argv[])
|
|||||||
AST_RWLIST_UNLOCK(&uris);
|
AST_RWLIST_UNLOCK(&uris);
|
||||||
|
|
||||||
ast_cli(fd, "\nEnabled Redirects:\n");
|
ast_cli(fd, "\nEnabled Redirects:\n");
|
||||||
AST_LIST_LOCK(&uri_redirects);
|
AST_RWLIST_RDLOCK(&uri_redirects);
|
||||||
AST_LIST_TRAVERSE(&uri_redirects, redirect, entry)
|
AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry)
|
||||||
ast_cli(fd, " %s => %s\n", redirect->target, redirect->dest);
|
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_cli(fd, " None.\n");
|
||||||
AST_LIST_UNLOCK(&uri_redirects);
|
AST_RWLIST_UNLOCK(&uri_redirects);
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user