Module: sip-router
Branch: janakj/kcore
Commit: 822a61e21b628272861a1dad6ba571acdf819c8b
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=822a61e…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 17:55:11 2009 +0100
Adding P-Preferred-Identity header parser from kamailio core
---
lib/kcore/parse_ppi.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/kcore/parse_ppi.h | 52 +++++++++++++++++++++
2 files changed, 174 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/parse_ppi.c b/lib/kcore/parse_ppi.c
new file mode 100644
index 0000000..791c3aa
--- /dev/null
+++ b/lib/kcore/parse_ppi.c
@@ -0,0 +1,122 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Juha Heinanen
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*!
+ * \file
+ * \brief P-Preferred-Identity header parser
+ * \ingroup parser
+ */
+
+#include "parse_ppi.h"
+#include "parse_to.h"
+#include "parse_uri.h"
+#include <stdlib.h>
+#include <string.h>
+#include "../dprint.h"
+#include "msg_parser.h"
+#include "../ut.h"
+#include "../errinfo.h"
+#include "../mem/mem.h"
+
+
+/*!
+ * \brief This method is used to parse P-Preferred-Identity header (RFC 3325).
+ *
+ * Currently only one name-addr / addr-spec is supported in the header
+ * and it must contain a sip or sips URI.
+ * \param msg sip msg
+ * \return 0 on success, -1 on failure.
+ */
+int parse_ppi_header( struct sip_msg *msg )
+{
+ struct to_body* ppi_b;
+
+ if ( !msg->ppi &&
+ (parse_headers(msg, HDR_PPI_F,0)==-1 || !msg->ppi)) {
+ goto error;
+ }
+
+ /* maybe the header is already parsed! */
+ if (msg->ppi->parsed)
+ return 0;
+
+ /* bad luck! :-( - we have to parse it */
+ /* first, get some memory */
+ ppi_b = pkg_malloc(sizeof(struct to_body));
+ if (ppi_b == 0) {
+ LM_ERR("out of pkg_memory\n");
+ goto error;
+ }
+
+ /* now parse it!! */
+ memset(ppi_b, 0, sizeof(struct to_body));
+ parse_to(msg->ppi->body.s,
+ msg->ppi->body.s + msg->ppi->body.len+1,
+ ppi_b);
+ if (ppi_b->error == PARSE_ERROR) {
+ LM_ERR("bad P-Preferred-Identity header\n");
+ pkg_free(ppi_b);
+ goto error;
+ }
+ msg->ppi->parsed = ppi_b;
+
+ return 0;
+ error:
+ return -1;
+}
+
+
+/*!
+ * \brief Parse P-Preferred-Identity header URI
+ */
+struct sip_uri *parse_ppi_uri(struct sip_msg *msg)
+{
+ struct to_body *tb = NULL;
+
+ if(msg==NULL)
+ return NULL;
+
+ if(parse_ppi_header(msg)<0)
+ {
+ LM_ERR("cannot parse P-P-I header\n");
+ return NULL;
+ }
+
+ if(msg->ppi==NULL || get_ppi(msg)==NULL)
+ return NULL;
+
+ tb = get_ppi(msg);
+
+ if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
+ return &tb->parsed_uri;
+
+ if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
+ {
+ LM_ERR("failed to parse P-P-I URI\n");
+ memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
+ set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, "error parsing P-P-I URI");
+ set_err_reply(400, "bad P-Preferred-Identity uri");
+ return NULL;
+ }
+
+ return &tb->parsed_uri;
+}
diff --git a/lib/kcore/parse_ppi.h b/lib/kcore/parse_ppi.h
new file mode 100644
index 0000000..ff0d26c
--- /dev/null
+++ b/lib/kcore/parse_ppi.h
@@ -0,0 +1,52 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Juha Heinanen
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*!
+ * \file
+ * \brief P-Preferred-Identity header parser
+ * \ingroup parser
+ */
+
+#ifndef PARSE_PPI_H
+#define PARSE_PPI_H
+
+#include "msg_parser.h"
+
+
+/*! casting macro for accessing P-Preferred-Identity body */
+#define get_ppi(p_msg) ((struct to_body*)(p_msg)->ppi->parsed)
+
+
+/*!
+ * \brief This method is used to parse P-Preferred-Identity header (RFC 3325).
+ *
+ * Currently only one name-addr / addr-spec is supported in the header
+ * and it must contain a sip or sips URI.
+ * \param msg sip msg
+ * \return 0 on success, -1 on failure.
+ */
+int parse_ppi_header( struct sip_msg *msg);
+
+struct sip_uri *parse_ppi_uri(struct sip_msg *msg);
+
+#endif /* PARSE_PPI_H */
Module: sip-router
Branch: janakj/kcore
Commit: bbbc6625cef466839d25fd7f95e99d6a6045d645
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bbbc662…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 17:42:45 2009 +0100
P-Asserted-Identity parser from kamailio core
This patch adds the P-Asserted-Identity parser from the kamailio
core to the libkcore library.
---
lib/kcore/parse_pai.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/kcore/parse_pai.h | 44 ++++++++++++++++++++++++++++
2 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/parse_pai.c b/lib/kcore/parse_pai.c
new file mode 100644
index 0000000..b047eb6
--- /dev/null
+++ b/lib/kcore/parse_pai.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2006 Juha Heinanen
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*!
+ * \file
+ * \brief P-Asserted-Identity header parser
+ * \ingroup parser
+ */
+
+#include "parse_from.h"
+#include "parse_to.h"
+#include <stdlib.h>
+#include <string.h>
+#include "../dprint.h"
+#include "msg_parser.h"
+#include "../ut.h"
+#include "../mem/mem.h"
+
+/*!
+ * This method is used to parse P-Asserted-Identity header (RFC 3325).
+ *
+ * Currently only one name-addr / addr-spec is supported in the header
+ * and it must contain a sip or sips URI.
+ * \param msg sip msg
+ * \return 0 on success, -1 on failure.
+ */
+int parse_pai_header( struct sip_msg *msg )
+{
+ struct to_body* pai_b;
+
+ if ( !msg->pai && (parse_headers(msg, HDR_PAI_F,0)==-1 || !msg->pai)) {
+ goto error;
+ }
+
+ /* maybe the header is already parsed! */
+ if (msg->pai->parsed)
+ return 0;
+
+ /* bad luck! :-( - we have to parse it */
+ /* first, get some memory */
+ pai_b = pkg_malloc(sizeof(struct to_body));
+ if (pai_b == 0) {
+ LM_ERR("out of pkg_memory\n");
+ goto error;
+ }
+
+ /* now parse it!! */
+ memset(pai_b, 0, sizeof(struct to_body));
+ parse_to(msg->pai->body.s, msg->pai->body.s + msg->pai->body.len+1, pai_b);
+ if (pai_b->error == PARSE_ERROR) {
+ LM_ERR("bad P-Asserted-Identity header\n");
+ pkg_free(pai_b);
+ goto error;
+ }
+ msg->pai->parsed = pai_b;
+
+ return 0;
+error:
+ return -1;
+}
diff --git a/lib/kcore/parse_pai.h b/lib/kcore/parse_pai.h
new file mode 100644
index 0000000..f9af2fc
--- /dev/null
+++ b/lib/kcore/parse_pai.h
@@ -0,0 +1,44 @@
+/*
+ *
+ * Copyright (C) 2006 Juha Heinanen
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*!
+ * \file
+ * \brief P-Asserted-Identity header parser
+ * \ingroup parser
+ */
+
+#ifndef PARSE_PAI_H
+#define PARSE_PAI_H
+
+#include "msg_parser.h"
+
+
+/*! casting macro for accessing P-Asserted-Identity body */
+#define get_pai(p_msg) ((struct to_body*)(p_msg)->pai->parsed)
+
+
+/*!
+ * P-Asserted-Identity header field parser
+ */
+int parse_pai_header( struct sip_msg *msg);
+
+#endif /* PARSE_PAI_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
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: 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: 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 */