From: Andre Noll Date: Sun, 13 Jan 2008 15:26:17 +0000 (+0100) Subject: http_send: Make add_perm_list_entry() and del_perm_list_entry() generic. X-Git-Tag: v0.3.1~95^2~5 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=11c9ad31156c3bac5627b0539010c87eccc9bba2;p=paraslash.git http_send: Make add_perm_list_entry() and del_perm_list_entry() generic. --- 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;