Module: sip-router
Branch: master
Commit: f82c04eb21aa496b883c0e4ee486b247efeb04c9
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f82c04e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sat Feb 26 22:20:49 2011 +0100
siputils: added functions to detect type of SIP message
- is_request() returns true if the SIP message is a request
- is_reply() returns true if the SIP message is a reply
- useful to check in sub-routes that can be executed from both request
and reply routes
---
modules_k/siputils/checks.c | 27 +++++++++++++++++
modules_k/siputils/checks.h | 10 ++++++
modules_k/siputils/siputils.c | 64 +++++++++++++++++++++++++----------------
3 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/modules_k/siputils/checks.c b/modules_k/siputils/checks.c
index c0cee5f..f729739 100644
--- a/modules_k/siputils/checks.c
+++ b/modules_k/siputils/checks.c
@@ -54,6 +54,33 @@
#include "../../lvalue.h"
#include "checks.h"
+/**
+ * return 1 (true) if the SIP message type is request
+ */
+int w_is_request(struct sip_msg* msg, char *foo, char *bar)
+{
+ if(msg==NULL)
+ return -1;
+
+ if(msg->first_line.type == SIP_REQUEST)
+ return 1;
+
+ return -1;
+}
+
+/**
+ * return 1 (true) if the SIP message type is reply
+ */
+int w_is_reply(struct sip_msg* msg, char *foo, char *bar)
+{
+ if(msg==NULL)
+ return -1;
+
+ if(msg->first_line.type == SIP_REPLY)
+ return 1;
+
+ return -1;
+}
/*
* Checks if From includes a To-tag -- good to identify
diff --git a/modules_k/siputils/checks.h b/modules_k/siputils/checks.h
index cb49850..eeb2788 100644
--- a/modules_k/siputils/checks.h
+++ b/modules_k/siputils/checks.h
@@ -95,4 +95,14 @@ int is_e164(struct sip_msg* _m, char* _sp, char* _s2);
*/
int set_uri_user(struct sip_msg* _m, char* _uri, char* _value);
+/*
+ * Return true (1) if SIP message is request, otherwise false (-1)
+ */
+int w_is_request(struct sip_msg* msg, char *foo, char *bar);
+
+/*
+ * Return true (1) if SIP message is reply, otherwise false (-1)
+ */
+int w_is_reply(struct sip_msg* msg, char *foo, char *bar);
+
#endif /* CHECKS_H */
diff --git a/modules_k/siputils/siputils.c b/modules_k/siputils/siputils.c
index 3b31ad0..054dc9b 100644
--- a/modules_k/siputils/siputils.c
+++ b/modules_k/siputils/siputils.c
@@ -113,36 +113,50 @@ static int fixup_free_set_uri(void** param, int param_no);
char *contact_flds_separator = DEFAULT_SEPARATOR;
static cmd_export_t cmds[]={
- {"ring_insert_callid", (cmd_function)ring_insert_callid, 0, ring_fixup, 0,
REQUEST_ROUTE|FAILURE_ROUTE},
- {"options_reply", (cmd_function)opt_reply, 0, 0, 0, REQUEST_ROUTE},
- {"is_user", (cmd_function)is_user, 1, fixup_str_null, 0,
REQUEST_ROUTE|LOCAL_ROUTE},
- {"has_totag", (cmd_function)has_totag, 0, 0, 0, ANY_ROUTE},
- {"uri_param", (cmd_function)uri_param_1, 1, fixup_str_null, 0,
REQUEST_ROUTE|LOCAL_ROUTE},
- {"uri_param", (cmd_function)uri_param_2, 2, fixup_str_str, 0,
REQUEST_ROUTE|LOCAL_ROUTE},
- {"add_uri_param", (cmd_function)add_uri_param, 1, fixup_str_null, 0,
REQUEST_ROUTE},
- {"tel2sip", (cmd_function)tel2sip, 0, 0, 0,
REQUEST_ROUTE},
- {"is_e164", (cmd_function)is_e164, 1, fixup_pvar_null,
fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
- {"is_uri_user_e164", (cmd_function)is_uri_user_e164, 1, fixup_pvar_null,
fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
- {"encode_contact", (cmd_function)encode_contact,2,0, 0,
REQUEST_ROUTE|ONREPLY_ROUTE},
- {"decode_contact", (cmd_function)decode_contact,0,0, 0, REQUEST_ROUTE},
- {"decode_contact_header",
(cmd_function)decode_contact_header,0,0,0,REQUEST_ROUTE|ONREPLY_ROUTE},
- {"cmp_uri", (cmd_function)w_cmp_uri, 2,
- fixup_spve_spve, 0,
- ANY_ROUTE},
- {"cmp_aor", (cmd_function)w_cmp_aor, 2,
- fixup_spve_spve, 0,
- ANY_ROUTE},
- {"is_rpid_user_e164", (cmd_function)is_rpid_user_e164, 0, 0,
+ {"ring_insert_callid", (cmd_function)ring_insert_callid, 0, ring_fixup,
+ 0, REQUEST_ROUTE|FAILURE_ROUTE},
+ {"options_reply", (cmd_function)opt_reply, 0, 0,
+ 0, REQUEST_ROUTE},
+ {"is_user", (cmd_function)is_user, 1, fixup_str_null,
+ 0, REQUEST_ROUTE|LOCAL_ROUTE},
+ {"has_totag", (cmd_function)has_totag, 0, 0,
+ 0, ANY_ROUTE},
+ {"uri_param", (cmd_function)uri_param_1, 1, fixup_str_null,
+ 0, REQUEST_ROUTE|LOCAL_ROUTE},
+ {"uri_param", (cmd_function)uri_param_2, 2, fixup_str_str,
+ 0, REQUEST_ROUTE|LOCAL_ROUTE},
+ {"add_uri_param", (cmd_function)add_uri_param, 1, fixup_str_null,
+ 0, REQUEST_ROUTE},
+ {"tel2sip", (cmd_function)tel2sip, 0, 0,
+ 0, REQUEST_ROUTE},
+ {"is_e164", (cmd_function)is_e164, 1, fixup_pvar_null,
+ fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
+ {"is_uri_user_e164", (cmd_function)is_uri_user_e164, 1, fixup_pvar_null,
+ fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
+ {"encode_contact", (cmd_function)encode_contact, 2, 0,
+ 0, REQUEST_ROUTE|ONREPLY_ROUTE},
+ {"decode_contact", (cmd_function)decode_contact, 0, 0,
+ 0, REQUEST_ROUTE},
+ {"decode_contact_header", (cmd_function)decode_contact_header, 0, 0,
+ 0,REQUEST_ROUTE|ONREPLY_ROUTE},
+ {"cmp_uri", (cmd_function)w_cmp_uri, 2, fixup_spve_spve,
+ 0, ANY_ROUTE},
+ {"cmp_aor", (cmd_function)w_cmp_aor, 2, fixup_spve_spve,
+ 0, ANY_ROUTE},
+ {"is_rpid_user_e164", (cmd_function)is_rpid_user_e164, 0, 0,
0, REQUEST_ROUTE},
- {"append_rpid_hf", (cmd_function)append_rpid_hf, 0, 0,
+ {"append_rpid_hf", (cmd_function)append_rpid_hf, 0, 0,
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
- {"append_rpid_hf", (cmd_function)append_rpid_hf_p, 2,
fixup_str_str,
+ {"append_rpid_hf", (cmd_function)append_rpid_hf_p, 2, fixup_str_str,
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
- {"set_uri_user", (cmd_function)set_uri_user, 2, fixup_set_uri,
- fixup_free_set_uri,
- REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE},
+ {"set_uri_user", (cmd_function)set_uri_user, 2, fixup_set_uri,
+ fixup_free_set_uri, ANY_ROUTE},
{"bind_siputils", (cmd_function)bind_siputils, 0, 0,
0, 0},
+ {"is_request", (cmd_function)w_is_request, 0, 0,
+ 0, ANY_ROUTE},
+ {"is_reply", (cmd_function)w_is_reply, 0, 0,
+ 0, ANY_ROUTE},
{0,0,0,0,0,0}
};