Convert uri_redirects list to read/write locks.
authorJoshua Colp <jcolp@digium.com>
Thu, 28 Dec 2006 20:05:00 +0000 (20:05 +0000)
committerJoshua Colp <jcolp@digium.com>
Thu, 28 Dec 2006 20:05:00 +0000 (20:05 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49027 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/http.c

index 8def001..093ddf4 100644 (file)
@@ -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;
        ast_uri_decode(uri);
 
        *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);
                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;
                }
        }
                        break;
                }
        }
-       AST_LIST_UNLOCK(&uri_redirects);
+       AST_RWLIST_UNLOCK(&uri_redirects);
        if (redirect)
                goto cleanup;
 
        if (redirect)
                goto cleanup;
 
@@ -837,28 +837,28 @@ static void add_redirect(const char *value)
        strcpy(redirect->target, target);
        strcpy(redirect->dest, dest);
 
        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() */
 
        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;
        }
 
                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;
                }
        }
 
                        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);
        http_tls_cfg.cipher = ast_strdup("");
 
                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);
                free(redirect);
-       AST_LIST_UNLOCK(&uri_redirects);
+       AST_RWLIST_UNLOCK(&uri_redirects);
 
        cfg = ast_config_load("http.conf");
        if (cfg) {
 
        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_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);
                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;
 }