[Serusers] Re: append_rpid_hf() and search()
Alexander Mayrhofer
axelm at nic.at
Tue Oct 28 14:01:48 CET 2003
On (27.10.03 16:03), Nils Ohlmeier wrote:
> > If yes, is there another way to search SER's rpid information
> > for a specific string?
>
> I fear there is currently no way to search this information in a modified
> request.
>
not anymore ;)
I've made a small change to the auth module which adds the function
search_rpid() to the module. Seems to work for me, here's a diff
(the original sources are a bit outdated, sorry, so ymmv when patching):
As usual, feel free to add the change to the upstream sources if
it qualifies.
cheers
axelm
Index: at43-authmod/README
diff -c at43-authmod/README:1.1 at43-authmod/README:1.2
*** at43-authmod/README:1.1 Tue Oct 28 13:44:18 2003
--- at43-authmod/README Tue Oct 28 13:51:09 2003
***************
*** 34,39 ****
--- 34,40 ----
1.4.3. consume_credentials()
1.4.4. is_rpid_user_e164()
1.4.5. append_rpid_hf
+ 1.4.6. search_rpid()
2. Developer's Guide
3. Frequently Asked Questions
***************
*** 47,52 ****
--- 48,54 ----
1-6. consume_credentials example
1-7. is_rpid_user_e164 usage
1-8. append_rpid_hf
+ 1-9. search_rpid
_________________________________________________________
Chapter 1. User's Guide
***************
*** 238,243 ****
--- 240,259 ----
Example 1-8. append_rpid_hf
...
append_rpid_hf(); # Append Remote-Party-ID header field
+ ...
+ _________________________________________________________
+
+ 1.4.5. search_rpid
+
+ Searches stored Remote-Party-ID value for given text. Returns true
+ if text is found, false otherwise. This function does plain text
+ comparison, no regular expressions. Searches are case sensitive.
+
+ Example 1-9. search_rpid()
+ ...
+ if (search_rpid("1234")); # Check if RPID contains string 1234
+ # do something here
+ };
...
_________________________________________________________
Index: at43-authmod/auth_mod.c
diff -c at43-authmod/auth_mod.c:1.1 at43-authmod/auth_mod.c:1.2
*** at43-authmod/auth_mod.c:1.1 Tue Oct 28 13:44:18 2003
--- at43-authmod/auth_mod.c Tue Oct 28 13:51:09 2003
***************
*** 1,5 ****
/*
! * $Id: auth_mod.c,v 1.1 2003/10/28 12:44:18 axelm Exp $
*
* Digest Authentication Module
*
--- 1,5 ----
/*
! * $Id: auth_mod.c,v 1.2 2003/10/28 12:51:09 axelm Exp $
*
* Digest Authentication Module
*
***************
*** 112,117 ****
--- 112,118 ----
{"consume_credentials", consume_credentials, 0, 0, REQUEST_ROUTE},
{"is_rpid_user_e164", is_rpid_user_e164, 0, 0, REQUEST_ROUTE},
{"append_rpid_hf", append_rpid_hf, 0, 0, REQUEST_ROUTE},
+ {"search_rpid", search_rpid, 1, 0, REQUEST_ROUTE},
{"pre_auth", (cmd_function)pre_auth, 0, 0, 0 },
{"post_auth", (cmd_function)post_auth, 0, 0, 0 },
{0, 0, 0, 0, 0}
Index: at43-authmod/rpid.c
diff -c at43-authmod/rpid.c:1.1 at43-authmod/rpid.c:1.2
*** at43-authmod/rpid.c:1.1 Tue Oct 28 13:44:18 2003
--- at43-authmod/rpid.c Tue Oct 28 13:51:09 2003
***************
*** 1,5 ****
/*
! * $Id: rpid.c,v 1.1 2003/10/28 12:44:18 axelm Exp $
*
* Remote-Party-ID related functions
*
--- 1,5 ----
/*
! * $Id: rpid.c,v 1.2 2003/10/28 12:51:09 axelm Exp $
*
* Remote-Party-ID related functions
*
***************
*** 200,203 ****
--- 200,241 ----
rpid.s = _rpid->s;
rpid.len = _rpid->len;
DBG("save_rpid(): rpid value is '%.*s'\n", _rpid->len, ZSW(_rpid->s));
+ }
+
+ /*
+ * Search RPID for text. does not do regex
+ * Alexander Mayrhofer <axelm at nic.at>
+ */
+ int search_rpid(struct sip_msg* _m, char* _s1) {
+
+ char* s;
+ int search_rpid_result;
+
+ search_rpid_result = -1;
+
+ if (!rpid.len) {
+ LOG(L_ERR, "search_rpid(): RPID is empty");
+ return -1;
+ }
+
+ s = pkg_malloc(rpid.len+1);
+ if (!s) {
+ LOG(L_ERR, "search_rpid(): out of memory");
+ return -1;
+ }
+
+ memset(s, 0, rpid.len+1);
+ strncpy(s, rpid.s, rpid.len);
+
+ if (strstr(s, _s1)) {
+ search_rpid_result = 1;
+ DBG("search_rpid(): search succeeded\n");
+ } else {
+ DBG("search_rpid(): search failed\n");
+ }
+
+ if (s) {
+ pkg_free(s);
+ }
+ return search_rpid_result;
}
Index: at43-authmod/rpid.h
diff -c at43-authmod/rpid.h:1.1 at43-authmod/rpid.h:1.2
*** at43-authmod/rpid.h:1.1 Tue Oct 28 13:44:18 2003
--- at43-authmod/rpid.h Tue Oct 28 13:51:09 2003
***************
*** 1,5 ****
/*
! * $Id: rpid.h,v 1.1 2003/10/28 12:44:18 axelm Exp $
*
* Remote-Party-ID related functions
*
--- 1,5 ----
/*
! * $Id: rpid.h,v 1.2 2003/10/28 12:51:09 axelm Exp $
*
* Remote-Party-ID related functions
*
***************
*** 54,59 ****
--- 54,64 ----
* Store rpid
*/
void save_rpid(str* _rpid);
+
+ /*
+ * Search rpid
+ */
+ int search_rpid(struct sip_msg* _m, char* _s1);
#endif /* RPID_H */
More information about the sr-users
mailing list