Module: sip-router
Branch: master
Commit: ae232eca582e48f93b5a7145b52b12ce484b47ad
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ae232ec…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 21:17:30 2009 +0100
Kamailio compatibility: Parse and store integer message id in cseq.
This patch modifies the CSeq header field parser. The new version of
the parser will also parse the method string and store an integer id
of the method string in the data structure representing cseq header
fields.
---
parser/parse_cseq.c | 7 +++++++
parser/parse_cseq.h | 1 +
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/parser/parse_cseq.c b/parser/parse_cseq.c
index e3c1656..23dbf42 100644
--- a/parser/parse_cseq.c
+++ b/parser/parse_cseq.c
@@ -36,6 +36,7 @@
#include "parser_f.h" /* eat_space_end and so on */
#include "../dprint.h"
#include "parse_def.h"
+#include "parse_methods.h"
#include "../mem/mem.h"
/*
@@ -72,6 +73,12 @@ char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
t=m_end;
cb->method.len=t-cb->method.s;
+ /* Cache method id */
+ if (parse_method(&cb->method, &cb->method_id) == 0) {
+ LOG(L_ERR, "ERROR: parse_cseq: Cannot parse method string\n");
+ goto error;
+ }
+
/* there may be trailing LWS
* (it was not my idea to put it in SIP; -jiri )
*/
diff --git a/parser/parse_cseq.h b/parser/parse_cseq.h
index 2b1794e..4779e11 100644
--- a/parser/parse_cseq.h
+++ b/parser/parse_cseq.h
@@ -36,6 +36,7 @@ struct cseq_body{
int error; /* Error code */
str number; /* CSeq number */
str method; /* Associated method */
+ unsigned int method_id; /* Associated method ID */
};
Module: sip-router
Branch: master
Commit: d8cd450f97721dd61f0803d7d1ef7a6efd550f45
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d8cd450…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 20:52:41 2009 +0100
Kamailio compatiblity: export parse_method function to modules.
The parser function was originally static and we are now exporting
it to other object files so that they can reuse the method parser.
---
parser/parse_methods.c | 2 +-
parser/parse_methods.h | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/parser/parse_methods.c b/parser/parse_methods.c
index 7ecac7c..8e6aabd 100644
--- a/parser/parse_methods.c
+++ b/parser/parse_methods.c
@@ -49,7 +49,7 @@ static int token_char(char _c)
* Parse a method pointed by _next, assign its enum bit to _method, and update
* _next past the method. Returns 1 if parse succeeded and 0 otherwise.
*/
-static int parse_method(str* _next, unsigned int* _method)
+int parse_method(str* _next, unsigned int* _method)
{
if (!_next || !_method) {
LOG(L_ERR, "parse_method: Invalid parameter value\n");
diff --git a/parser/parse_methods.h b/parser/parse_methods.h
index c97aea3..a4d70aa 100644
--- a/parser/parse_methods.h
+++ b/parser/parse_methods.h
@@ -57,5 +57,7 @@ enum method {
*/
int parse_methods(str* _body, unsigned int* _methods);
+int parse_method(str* _next, unsigned int* _method);
+
#endif /* PARSE_METHODS_H */
Module: sip-router
Branch: master
Commit: 7c7704130af7a25d3301376cc08b1eaa670d0e77
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7c77041…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 20:45:53 2009 +0100
Kamailio compatibility: script flags
This patch adds support for script flags identical to those present in
the kamailio core. Script flags is a global set of flags which preserve
their value for the duration of script processing. Script flags are kept
in a global variable in the sip-router core.
There are several functions that can be used to manipulate the value
of script flags:
* setflagsval - This function sets the value of _all_ script flags
at once. The new value of all the flags must be combined in the
single function parameter.
* setsflag - This function sets one particular script flag to 1. The
function gets the index of the flag (counting from 0) as a
parameter.
* resetsflag - This function sets one particular script flag to 0. The
function gets the index of the flag (counting from 0) as a parameter.
* issflagset - Test the value of a script flag. Returns 1 if the flag
is set and -1 otherwise.
* getsflags - Returns the value of all script flags combined into a
single variable of type flag_t. This function can be used to make a
backup copy of script flags.
---
flags.c | 37 +++++++++++++++++++++++++++++++++++++
flags.h | 20 ++++++++++++++++++++
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/flags.c b/flags.c
index e9f559e..70c3333 100644
--- a/flags.c
+++ b/flags.c
@@ -43,6 +43,10 @@
#include "clist.h"
#include "mem/mem.h"
+/* Script flags */
+static flag_t sflags = 0;
+
+
int setflag( struct sip_msg* msg, flag_t flag ) {
msg->flags |= 1 << flag;
return 1;
@@ -72,6 +76,39 @@ int flag_in_range( flag_t flag ) {
}
+int setsflagsval(flag_t val)
+{
+ sflags = val;
+ return 1;
+}
+
+
+int setsflag(flag_t flag)
+{
+ sflags |= 1 << flag;
+ return 1;
+}
+
+
+int resetsflag(flag_t flag)
+{
+ sflags &= ~ (1 << flag);
+ return 1;
+}
+
+
+int issflagset(flag_t flag)
+{
+ return (sflags & (1<<flag)) ? 1 : -1;
+}
+
+
+flag_t getsflags(void)
+{
+ return sflags;
+}
+
+
/* use 2^k */
#define FLAGS_NAME_HASH_ENTRIES 32
diff --git a/flags.h b/flags.h
index 62b3235..30809fe 100644
--- a/flags.h
+++ b/flags.h
@@ -43,6 +43,26 @@ int setflag( struct sip_msg* msg, flag_t flag );
int resetflag( struct sip_msg* msg, flag_t flag );
int isflagset( struct sip_msg* msg, flag_t flag );
+
+/* Script flag functions. Script flags are global flags that keep their
+ * value regardless of the SIP message being processed.
+ */
+
+/* Set the value of all the global flags */
+int setsflagsval(flag_t val);
+
+/* Set the given flag to 1. Parameter flag contains the index of the flag */
+int setsflag(flag_t flag);
+
+/* Reset the given flag to 0. Parameter flag contains the index of the flag */
+int resetsflag(flag_t flag);
+
+/* Returns 1 if the given flag is set and -1 otherwise */
+int issflagset(flag_t flag);
+
+/* Get the value of all the script flags combined */
+flag_t getsflags(void);
+
int flag_in_range( flag_t flag );
int register_flag(char* name, int pos);
Module: sip-router
Branch: master
Commit: 0202608d607019077e69f432343c767f96db9372
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0202608…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sat Mar 14 19:23:07 2009 +0100
Functions to set/reset/test per-branch flags.
This patch adds support for setbflag,resetbflag, and isbflagset
functions, these functions can be used to manipulate branch flags and
they are inspired by similar functions in kamailio.
There is a small difference compared to their counterparts in kamailio
though. The second parameter of all these functions is of type flag_t
and it is the index (counting from 0) of the flag to be manipulated.
This is better aligned with how normal flags (flags.[ch]) in sip-router
work. Similar functions in kamailio took the mask as the second
parameter with values of flags to be manipulated.
This also prevents users from modifying multiple flags at the same time
accidental (note that it is not obvious from the function name that
the function could do it).
---
dset.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
dset.h | 30 ++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/dset.c b/dset.c
index e4e995a..a3a6fff 100644
--- a/dset.c
+++ b/dset.c
@@ -66,7 +66,7 @@ struct branch
struct socket_info* force_send_socket;
/* Branch flags */
- unsigned int flags;
+ flag_t flags;
};
@@ -83,7 +83,47 @@ unsigned int nr_branches = 0;
static int branch_iterator = 0;
/* The q parameter of the Request-URI */
-static qvalue_t ruri_q = Q_UNSPECIFIED;
+static qvalue_t ruri_q = Q_UNSPECIFIED;
+
+/* Branch flags of the Request-URI */
+static flag_t ruri_bflags;
+
+
+static inline flag_t* get_bflags_ptr(unsigned int branch)
+{
+ if (branch == 0) return &ruri_bflags;
+ if (branch - 1 < nr_branches) return &branches[branch - 1].flags;
+ return NULL;
+}
+
+
+int setbflag(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ (*flags) |= 1 << flag;
+ return 1;
+}
+
+
+int isbflagset(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ return ((*flags) & (1 << flag)) ? 1 : -1;
+}
+
+
+int resetbflag(unsigned int branch, flag_t flag)
+{
+ flag_t* flags;
+
+ if ((flags = get_bflags_ptr(branch)) == NULL) return -1;
+ (*flags) &= ~ (1 << flag);
+ return 1;
+}
/*
diff --git a/dset.h b/dset.h
index c23d4ce..a4b4f7c 100644
--- a/dset.h
+++ b/dset.h
@@ -30,6 +30,7 @@
#include "ip_addr.h"
#include "qvalue.h"
+#include "flags.h"
struct sip_msg;
@@ -82,5 +83,34 @@ qvalue_t get_ruri_q(void);
int get_request_uri(struct sip_msg* _m, str* _u);
int rewrite_uri(struct sip_msg* _m, str* _s);
+/**
+ * Set a per-branch flag to 1.
+ *
+ * This function sets the value of one particular branch flag to 1.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be set (starting with 0)
+ * @return 1 on success, -1 on failure.
+ */
+int setbflag(unsigned int branch, flag_t flag);
+
+/**
+ * Reset a per-branch flag value to 0.
+ *
+ * This function resets the value of one particular branch flag to 0.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be reset (starting with 0)
+ * @return 1 on success, -1 on failure.
+ */
+int resetbflag(unsigned int branch, flag_t flag);
+
+/**
+ * Determine if a branch flag is set.
+ *
+ * This function tests the value of one particular per-branch flag.
+ * @param branch Number of the branch (0 for the main Request-URI branch)
+ * @param flag Number of the flag to be tested (starting with 0)
+ * @return 1 if the branch flag is set, -1 if not or on failure.
+ */
+int isbflagset(unsigned int branch, flag_t flag);
#endif /* _DSET_H */
Module: sip-router
Branch: master
Commit: 537ce843fd6cc59e022511f3c16c15a92a26aca1
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=537ce84…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 17:00:06 2009 +0100
Export parse_phostport function to modules.
Function parse_phostport was originally defined static in file.c, some
of kamailio modules use the function and so we re-define it as public
and add a declaration to header file socket_info.h
---
main.c | 4 ++--
socket_info.h | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
index aabaa7b..868572f 100644
--- a/main.c
+++ b/main.c
@@ -958,8 +958,8 @@ error:
* returns fills proto, port, host and returns list of addresses on success
* (pkg malloc'ed) and 0 on failure
*/
-static struct name_lst* parse_phostport(char* s, char** host, int* hlen,
- int* port, int* proto)
+struct name_lst* parse_phostport(char* s, char** host, int* hlen,
+ int* port, int* proto)
{
char* first; /* first ':' occurrence */
char* second; /* second ':' occurrence */
diff --git a/socket_info.h b/socket_info.h
index 627e3db..ebe051a 100644
--- a/socket_info.h
+++ b/socket_info.h
@@ -90,6 +90,9 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
struct socket_info** get_sock_info_list(unsigned short proto);
+struct name_lst* parse_phostport(char* s, char** host, int* hlen,
+ int* port, int* proto);
+
/* helper function:
* returns next protocol, if the last one is reached return 0
* useful for cycling on the supported protocols
In sr core, sip_resolvehost is pointing to dns_sip_resolvehost:
resolve.h:#define sip_resolvehost dns_sip_resolvehost
but in k core, sip_resolvehost is a standalone method.
This is creating issues due to different signatures for the two methods:
k core:
struct hostent* sip_resolvehost(str* name, unsigned short* port,
unsigned short *proto, int is_sips, struct dns_node **dn);
sr core:
struct hostent* dns_sip_resolvehost(str* name, unsigned short* port,
char* proto);
Modules affected by this:
- enum
- nat_traversal
- nathelper
Regards,
Ovidiu Sas