Module: sip-router Branch: master Commit: b6525fad3de205ab4504d669002acb8f6309f9a1 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b6525fad...
Author: Alex Hermann alex@speakup.nl Committer: Alex Hermann alex@speakup.nl Date: Fri Mar 4 17:22:20 2011 +0100
modules_k/permisisons: allow_trusted(): Add tags from all matching entries to the peer_tag_avp instead of just the first match.
---
modules_k/permissions/hash.c | 51 ++++++++++++++------------ modules_k/permissions/trusted.c | 75 ++++++++++++++++++++------------------- 2 files changed, 65 insertions(+), 61 deletions(-)
diff --git a/modules_k/permissions/hash.c b/modules_k/permissions/hash.c index b9bfa68..c24b94b 100644 --- a/modules_k/permissions/hash.c +++ b/modules_k/permissions/hash.c @@ -209,6 +209,7 @@ int match_hash_table(struct trusted_list** table, struct sip_msg* msg, struct trusted_list *np; str src_ip; int_str val; + int rc = -1;
src_ip.s = src_ip_c_str; src_ip.len = strlen(src_ip.s); @@ -223,32 +224,34 @@ int match_hash_table(struct trusted_list** table, struct sip_msg* msg, uri_string[uri.len] = (char)0;
for (np = table[perm_hash(src_ip)]; np != NULL; np = np->next) { - if ((np->src_ip.len == src_ip.len) && - (strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) && - ((np->proto == PROTO_NONE) || (np->proto == proto))) { - if (!(np->pattern)) goto found; - if (regcomp(&preg, np->pattern, REG_NOSUB)) { - LM_ERR("invalid regular expression\n"); - return -1; - } - if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) { - regfree(&preg); - } else { - regfree(&preg); - goto found; + if ((np->src_ip.len == src_ip.len) && + (strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) && + ((np->proto == PROTO_NONE) || (np->proto == proto))) { + if (np->pattern) { + if (regcomp(&preg, np->pattern, REG_NOSUB)) { + LM_ERR("invalid regular expression\n"); + continue; + } + if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) { + regfree(&preg); + continue; + } + regfree(&preg); + } + /* Found a match */ + if (tag_avp.n && np->tag.s) { + val.s = np->tag; + if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) { + LM_ERR("setting of tag_avp failed\n"); + return -1; + } + rc = 1; + } else { + return 1; + } } - } - } - return -1; -found: - if (tag_avp.n && np->tag.s) { - val.s = np->tag; - if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) { - LM_ERR("setting of tag_avp failed\n"); - return -1; - } } - return 1; + return rc; }
diff --git a/modules_k/permissions/trusted.c b/modules_k/permissions/trusted.c index 1f8a106..62fba29 100644 --- a/modules_k/permissions/trusted.c +++ b/modules_k/permissions/trusted.c @@ -329,17 +329,18 @@ static inline int match_proto(const char *proto_string, int proto_int)
/* * Matches from uri against patterns returned from database. Returns 1 when - * first pattern matches and 0 if none of the patterns match. + * first pattern matches and -1 if none of the patterns match. */ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r) { - int i, tag_avp_type; + int i, tag_avp_type; str uri; char uri_string[MAX_URI_SIZE+1]; db_row_t* row; db_val_t* val; regex_t preg; int_str tag_avp, avp_val; + int rc = -1;
if (parse_from_header(msg) < 0) return -1; uri = get_from(msg)->uri; @@ -349,46 +350,46 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r) } memcpy(uri_string, uri.s, uri.len); uri_string[uri.len] = (char)0; + get_tag_avp(&tag_avp, &tag_avp_type);
row = RES_ROWS(_r); - + for(i = 0; i < RES_ROW_N(_r); i++) { - val = ROW_VALUES(row + i); - if ((ROW_N(row + i) == 3) && - (VAL_TYPE(val) == DB1_STRING) && !VAL_NULL(val) && - match_proto(VAL_STRING(val), proto) && - (VAL_NULL(val + 1) || - ((VAL_TYPE(val + 1) == DB1_STRING) && !VAL_NULL(val + 1))) && - (VAL_NULL(val + 2) || - ((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 2)))) - { - if (VAL_NULL(val + 1)) goto found; - if (regcomp(&preg, (char *)VAL_STRING(val + 1), REG_NOSUB)) { - LM_ERR("invalid regular expression\n"); - continue; - } - if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) { - regfree(&preg); - continue; - } else { - regfree(&preg); - goto found; + val = ROW_VALUES(row + i); + if ((ROW_N(row + i) == 3) && + (VAL_TYPE(val) == DB1_STRING) && !VAL_NULL(val) && + match_proto(VAL_STRING(val), proto) && + (VAL_NULL(val + 1) || + ((VAL_TYPE(val + 1) == DB1_STRING) && !VAL_NULL(val + 1))) && + (VAL_NULL(val + 2) || + ((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 2)))) + { + if (!VAL_NULL(val + 1)) { + if (regcomp(&preg, (char *)VAL_STRING(val + 1), REG_NOSUB)) { + LM_ERR("invalid regular expression\n"); + continue; + } + if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) { + regfree(&preg); + continue; + } + regfree(&preg); + } + /* Found a match */ + if (tag_avp.n && !VAL_NULL(val + 2)) { + avp_val.s.s = (char *)VAL_STRING(val + 2); + avp_val.s.len = strlen(avp_val.s.s); + if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, avp_val) != 0) { + LM_ERR("failed to set of tag_avp failed\n"); + return -1; + } + rc = 1; + } else { + return 1; + } } - } - } - return -1; - -found: - get_tag_avp(&tag_avp, &tag_avp_type); - if (tag_avp.n && !VAL_NULL(val + 2)) { - avp_val.s.s = (char *)VAL_STRING(val + 2); - avp_val.s.len = strlen(avp_val.s.s); - if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, avp_val) != 0) { - LM_ERR("failed to set of tag_avp failed\n"); - return -1; - } } - return 1; + return rc; }