Module: sip-router
Branch: alexh/master
Commit: 11da29e549ff2dd04f3d94b5aa2667df8b6cb9e6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=11da29e…
Author: Alex Hermann <alex(a)speakup.nl>
Committer: Alex Hermann <alex(a)speakup.nl>
Date: Mon Mar 7 14:36:27 2011 +0100
modules_k/permissions: allow_trusted(): Return number of matched entries.
---
modules_k/permissions/hash.c | 12 +++++++-----
modules_k/permissions/trusted.c | 15 ++++++++-------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/modules_k/permissions/hash.c b/modules_k/permissions/hash.c
index c24b94b..1261227 100644
--- a/modules_k/permissions/hash.c
+++ b/modules_k/permissions/hash.c
@@ -199,6 +199,7 @@ int hash_table_insert(struct trusted_list** table, char* src_ip,
* Check if an entry exists in hash table that has given src_ip and protocol
* value and pattern that matches to From URI. If an entry exists and tag_avp
* has been defined, tag of the entry is added as a value to tag_avp.
+ * Returns number of matches or -1 if none matched.
*/
int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
char *src_ip_c_str, int proto)
@@ -209,7 +210,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;
+ int count = 0;
src_ip.s = src_ip_c_str;
src_ip.len = strlen(src_ip.s);
@@ -245,13 +246,14 @@ int match_hash_table(struct trusted_list** table, struct sip_msg*
msg,
LM_ERR("setting of tag_avp failed\n");
return -1;
}
- rc = 1;
- } else {
- return 1;
}
+ count++;
}
}
- return rc;
+ if (!count)
+ return -1;
+ else
+ return count;
}
diff --git a/modules_k/permissions/trusted.c b/modules_k/permissions/trusted.c
index 62fba29..32e1313 100644
--- a/modules_k/permissions/trusted.c
+++ b/modules_k/permissions/trusted.c
@@ -328,8 +328,8 @@ 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 -1 if none of the patterns match.
+ * Matches from uri against patterns returned from database. Returns number
+ * of matches or -1 if none of the patterns match.
*/
static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
{
@@ -340,7 +340,7 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
db_val_t* val;
regex_t preg;
int_str tag_avp, avp_val;
- int rc = -1;
+ int count = 0;
if (parse_from_header(msg) < 0) return -1;
uri = get_from(msg)->uri;
@@ -383,13 +383,14 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
LM_ERR("failed to set of tag_avp failed\n");
return -1;
}
- rc = 1;
- } else {
- return 1;
}
+ count++;
}
}
- return rc;
+ if (!count)
+ return -1;
+ else
+ return count;
}