From 11c9ad31156c3bac5627b0539010c87eccc9bba2 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 13 Jan 2008 16:26:17 +0100 Subject: [PATCH] http_send: Make add_perm_list_entry() and del_perm_list_entry() generic. --- http_send.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/http_send.c b/http_send.c index 446cde4f..037d4f24 100644 --- a/http_send.c +++ b/http_send.c @@ -391,14 +391,15 @@ static int http_com_off(__a_unused struct sender_command_data *scd) 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; - 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)); - 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); @@ -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)); - 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_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) - del_perm_list_entry(scd); + del_acl_entry(&http_acl, scd->addr, scd->netmask); 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) - add_perm_list_entry(scd); + add_acl_entry(&http_acl, scd->addr, scd->netmask); else - del_perm_list_entry(scd); + del_acl_entry(&http_acl, scd->addr, scd->netmask); 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; - 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, '/'); + struct in_addr addr; + int netmask; + if (!p) goto err; *p = '\0'; - if (!inet_pton(AF_INET, arg, &scd.addr)) + if (!inet_pton(AF_INET, arg, &addr)) goto err; - scd.netmask = atoi(++p); - if (scd.netmask < 0 || scd.netmask > 32) + netmask = atoi(++p); + if (netmask < 0 || netmask > 32) goto err; - add_perm_list_entry(&scd); + add_acl_entry(acl, addr, netmask); 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; -- 2.39.2