http_send: Make add_perm_list_entry() and del_perm_list_entry() generic.
authorAndre Noll <maan@systemlinux.org>
Sun, 13 Jan 2008 15:26:17 +0000 (16:26 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 13 Jan 2008 15:26:17 +0000 (16:26 +0100)
http_send.c

index 446cde4f72488c684696c13b41e91840df20fe0c..037d4f248d99a296a9c94da06ec27a34fd1aff39 100644 (file)
@@ -391,14 +391,15 @@ static int http_com_off(__a_unused struct sender_command_data *scd)
        return 1;
 }
 
        return 1;
 }
 
-static void del_perm_list_entry(struct sender_command_data *scd)
+static void del_acl_entry(struct list_head *acl, struct in_addr addr,
+               int netmask)
 {
        struct access_info *ai, *tmp;
 
 {
        struct access_info *ai, *tmp;
 
-       list_for_each_entry_safe(ai, tmp, &http_acl, node) {
+       list_for_each_entry_safe(ai, tmp, acl, node) {
                char *nad = para_strdup(inet_ntoa(ai->addr));
                char *nad = para_strdup(inet_ntoa(ai->addr));
-               if (!strcmp(nad, inet_ntoa(scd->addr)) &&
-                               ai->netmask == scd->netmask) {
+               if (!strcmp(nad, inet_ntoa(addr)) &&
+                               ai->netmask == netmask) {
                        PARA_NOTICE_LOG("removing %s/%i from access list\n",
                                nad, ai->netmask);
                        list_del(&ai->node);
                        PARA_NOTICE_LOG("removing %s/%i from access list\n",
                                nad, ai->netmask);
                        list_del(&ai->node);
@@ -408,31 +409,32 @@ static void del_perm_list_entry(struct sender_command_data *scd)
        }
 }
 
        }
 }
 
-static void add_perm_list_entry(struct sender_command_data *scd)
+static void add_acl_entry(struct list_head *acl, struct in_addr addr,
+               int netmask)
 {
        struct access_info *ai = para_malloc(sizeof(struct access_info));
 {
        struct access_info *ai = para_malloc(sizeof(struct access_info));
-       ai->addr = scd->addr;
-       ai->netmask = scd->netmask;
+       ai->addr = addr;
+       ai->netmask = netmask;
        PARA_INFO_LOG("adding %s/%i to access list\n", inet_ntoa(ai->addr),
                ai->netmask);
        PARA_INFO_LOG("adding %s/%i to access list\n", inet_ntoa(ai->addr),
                ai->netmask);
-       para_list_add(&ai->node, &http_acl);
+       para_list_add(&ai->node, acl);
 }
 
 static int http_com_deny(struct sender_command_data *scd)
 {
        if (conf.http_default_deny_given)
 }
 
 static int http_com_deny(struct sender_command_data *scd)
 {
        if (conf.http_default_deny_given)
-               del_perm_list_entry(scd);
+               del_acl_entry(&http_acl, scd->addr, scd->netmask);
        else
        else
-               add_perm_list_entry(scd);
+               add_acl_entry(&http_acl, scd->addr, scd->netmask);
        return 1;
 }
 
 static int http_com_allow(struct sender_command_data *scd)
 {
        if (conf.http_default_deny_given)
        return 1;
 }
 
 static int http_com_allow(struct sender_command_data *scd)
 {
        if (conf.http_default_deny_given)
-               add_perm_list_entry(scd);
+               add_acl_entry(&http_acl, scd->addr, scd->netmask);
        else
        else
-               del_perm_list_entry(scd);
+               del_acl_entry(&http_acl, scd->addr, scd->netmask);
        return 1;
 }
 
        return 1;
 }
 
@@ -485,25 +487,26 @@ static char *http_info(void)
 static void init_acl(struct list_head *acl, char * const *acl_info, int num)
 {
        int i;
 static void init_acl(struct list_head *acl, char * const *acl_info, int num)
 {
        int i;
-       struct sender_command_data scd;
 
        INIT_LIST_HEAD(acl);
        for (i = 0; i < num; i++) {
                char *arg = para_strdup(acl_info[i]);
                char *p = strchr(arg, '/');
 
        INIT_LIST_HEAD(acl);
        for (i = 0; i < num; i++) {
                char *arg = para_strdup(acl_info[i]);
                char *p = strchr(arg, '/');
+               struct in_addr addr;
+               int netmask;
+
                if (!p)
                        goto err;
                *p = '\0';
                if (!p)
                        goto err;
                *p = '\0';
-               if (!inet_pton(AF_INET, arg, &scd.addr))
+               if (!inet_pton(AF_INET, arg, &addr))
                        goto err;
                        goto err;
-               scd.netmask = atoi(++p);
-               if (scd.netmask < 0 || scd.netmask > 32)
+               netmask = atoi(++p);
+               if (netmask < 0 || netmask > 32)
                        goto err;
                        goto err;
-               add_perm_list_entry(&scd);
+               add_acl_entry(acl, addr, netmask);
                goto success;
 err:
                goto success;
 err:
-               PARA_CRIT_LOG("syntax error for http_access option "
-                       "#%d, ignoring\n", i);
+               PARA_CRIT_LOG("syntax error: %s\n", acl_info[i]);
 success:
                free(arg);
                continue;
 success:
                free(arg);
                continue;