Module: sip-router
Branch: master
Commit: 29e00cb942e122a8d0dc2b4e3adf4ef8e431c4b5
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=29e00cb…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sat Mar 7 01:51:19 2009 +0100
Update tm module to use and set the global route_type variable.
This patch removes the rmode variable from tm module and replaces it
with the global variable route_type defined in route.h. In addition to
that we replaced MODE_* constants with *_ROUTE (also defined in
route.h).
A variable that was once defined in the tm module is now better moved
to the core, because just the core itself without the tm module loaded
can execute two types of routes, the request route and the global
onreply route (if used).
---
modules/tm/t_fwd.c | 16 +++++++++-------
modules/tm/t_lookup.c | 26 +++++++++++++-------------
modules/tm/t_reply.c | 24 +++++++++++-------------
modules/tm/t_reply.h | 3 ---
modules/tm/tm.c | 28 ++++++++++++++--------------
modules/tm/tm_load.c | 1 -
onsend.h | 1 +
receive.c | 3 +++
route.c | 1 +
9 files changed, 52 insertions(+), 51 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=29e…
Module: sip-router
Branch: master
Commit: 1dfe92cbe2f80f662087230e716e473367708f24
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1dfe92c…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sat Mar 7 01:42:04 2009 +0100
New global variable route_type with the type of route being executed
This patch adds a new global variable called route_type. This value of
the variable is one of the *_ROUTE values defined in route.h. Those
defines have been moved from sr_module.h, originally they were used
as the flags for functions in module exports but we can use them here
for the global route_type variable as well.
The variable route_type is meant to be used by module functions, in
some cases they need to test for the type of the route being executed
to know what functions are available and whether the sip message being
process is stored in shared memory or private memory.
The tm module contained similar variable (which was exported through
the tm module API), but it makes more sense to keep it in sip-router
core, because the core can execute two route types, the request route
and the onreply route, even if the tm module is not used.
---
route.h | 23 +++++++++++++++++++++++
sr_module.h | 10 +---------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/route.h b/route.h
index 732d4a9..221fb4c 100644
--- a/route.h
+++ b/route.h
@@ -42,6 +42,29 @@
/*#include "cfg_parser.h" */
+/* Various types of route sections, make sure that the values defined in the
+ * macros below occupy disjunct bits so that they can also be used as flags
+ */
+#define REQUEST_ROUTE (1 << 0)
+#define FAILURE_ROUTE (1 << 1)
+#define ONREPLY_ROUTE (1 << 2)
+#define BRANCH_ROUTE (1 << 3)
+#define ONSEND_ROUTE (1 << 4)
+#define ERROR_ROUTE (1 << 5)
+#define LOCAL_ROUTE (1 << 6)
+
+/* The value of this variable is one of the route types defined above and it
+ * determines the type of the route being executed, module functions can use
+ * this value to determine the type of the route they are being executed in
+ */
+extern int route_type;
+
+#define set_route_type(type) \
+ do { \
+ route_type = (type); \
+ } while(0)
+
+#define is_route_type(type) (route_type == (type))
struct route_list{
struct action** rlist;
diff --git a/sr_module.h b/sr_module.h
index 149ca6e..0078f25 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -62,6 +62,7 @@
#include "version.h"
#include "rpc.h"
#include "route_struct.h"
+#include "route.h"
#include "str.h"
/* kamailio compat */
@@ -146,15 +147,6 @@ typedef int (*param_func_t)( modparam_t type, void* val);
#define VAR_PARAM_NO -128 /* function has variable number of parameters
(see cmd_function_var for the prototype) */
-/* functions flags */
-#define REQUEST_ROUTE 1 /* Function can be used in request route blocks */
-#define FAILURE_ROUTE 2 /* Function can be used in reply route blocks */
-#define ONREPLY_ROUTE 4 /* Function can be used in on_reply */
-#define BRANCH_ROUTE 8 /* Function can be used in branch_route blocks */
-#define ONSEND_ROUTE 16 /* Function can be used in onsend_route blocks */
-#define ERROR_ROUTE 32 /* Function can be used in an error route */
-#define LOCAL_ROUTE 64 /* Function can be used in a local route */
-
/* Macros - used as rank in child_init function */
#define PROC_MAIN 0 /* Main ser process */
#define PROC_TIMER -1 /* Timer attendant process */
Module: sip-router
Branch: janakj/kcore
Commit: 66b8eec6fd1123e10b805d11d8d78cfb50c7a33e
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=66b8eec…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Thu Mar 5 23:57:38 2009 +0100
Parser helper functions not present in sip-router.
That include parse_to_uri and parse_from_uri. Also adding errinfo.[ch]
which is required by the parser helpers.
---
lib/kcore/errinfo.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
lib/kcore/errinfo.h | 59 ++++++++++++++++++++++++++++++++++
lib/kcore/parser_helpers.c | 65 ++++++++++++++++++++++++++++++++++++++
lib/kcore/parser_helpers.h | 11 ++++++
4 files changed, 210 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/errinfo.c b/lib/kcore/errinfo.c
new file mode 100644
index 0000000..799549f
--- /dev/null
+++ b/lib/kcore/errinfo.c
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Voice Sistem SRL
+ *
+ * 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 errinfo.c
+ * \brief Kamailio Error info functions
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../dprint.h"
+#include "errinfo.h"
+
+/*! global error info */
+err_info_t _oser_err_info;
+
+/*! \brief Get global error state
+ */
+err_info_t* get_err_info(void) { return &_oser_err_info; }
+
+/*! \brief Initialize global error state
+ */
+void init_err_info(void)
+{
+ memset(&_oser_err_info, 0, sizeof(err_info_t));
+}
+
+/*! \brief Set suggested error info message
+ */
+void set_err_info(int ec, int el, char *info)
+{
+ LM_DBG("ec: %d, el: %d, ei: '%s'\n", ec, el,
+ (info)?info:"");
+ _oser_err_info.eclass = ec;
+ _oser_err_info.level = el;
+ if(info)
+ {
+ _oser_err_info.info.s = info;
+ _oser_err_info.info.len = strlen(info);
+ }
+}
+
+/*! \brief Set suggested error reply
+ */
+void set_err_reply(int rc, char *rr)
+{
+ _oser_err_info.rcode = rc;
+ if(rr)
+ {
+ _oser_err_info.rreason.s = rr;
+ _oser_err_info.rreason.len = strlen(rr);
+ }
+}
+
diff --git a/lib/kcore/errinfo.h b/lib/kcore/errinfo.h
new file mode 100644
index 0000000..fb4bf6b
--- /dev/null
+++ b/lib/kcore/errinfo.h
@@ -0,0 +1,59 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Voice Sistem SRL
+ *
+ * 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 errinfo.h
+ * \brief Error handling
+ */
+
+
+#ifndef _errinfo_h_
+#define _errinfo_h_
+
+#include "../../str.h"
+
+/*! \name ErrorClasses error clases */
+#define OSER_EC_PARSER 1 /*!< parse error */
+#define OSER_EC_PMEMORY 2 /*!< private memory error */
+#define OSER_EC_SMEMORY 3 /*!< share memory error */
+
+#define OSER_EL_CRITIC 1
+#define OSER_EL_HIGH 2
+#define OSER_EL_MEDIUM 3 /*!< severity level normal - used by parsing errors */
+#define OSER_EL_NORMAL 4
+#define OSER_EL_LOW 5
+
+typedef struct err_info_
+{
+ int eclass; /*!< error class */
+ int level; /*!< severity level (lower is higher) */
+ str info; /*!< error details */
+ int rcode; /*!< recommended reply code */
+ str rreason; /*!< recommended reply reason phrase */
+} err_info_t;
+
+void init_err_info(void);
+void set_err_info(int ec, int el, char *info);
+void set_err_reply(int rc, char *rr);
+err_info_t* get_err_info(void);
+
+#endif
diff --git a/lib/kcore/parser_helpers.c b/lib/kcore/parser_helpers.c
new file mode 100644
index 0000000..15c48c6
--- /dev/null
+++ b/lib/kcore/parser_helpers.c
@@ -0,0 +1,65 @@
+#include "parser_helpers.h"
+#include "errinfo.h"
+#include "../../parser/parse_to.h"
+#include "../../parser/parse_from.h"
+#include "../../dprint.h"
+
+#include <string.h>
+
+struct sip_uri *parse_to_uri(struct sip_msg *msg)
+{
+ struct to_body *tb = NULL;
+
+ if(msg==NULL || msg->to==NULL || msg->to->parsed==NULL)
+ return NULL;
+
+ tb = get_to(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 To uri\n");
+ memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
+ set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, "error parsing To uri");
+ set_err_reply(400, "bad To uri");
+ return NULL;
+ }
+
+ return &tb->parsed_uri;
+}
+
+
+struct sip_uri *parse_from_uri(struct sip_msg *msg)
+{
+ struct to_body *tb = NULL;
+
+ if(msg==NULL)
+ return NULL;
+
+ if(parse_from_header(msg)<0)
+ {
+ LM_ERR("cannot parse FROM header\n");
+ return NULL;
+ }
+
+ if(msg->from==NULL || get_from(msg)==NULL)
+ return NULL;
+
+ tb = get_from(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 From uri\n");
+ memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
+ set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, "error parsing From uri");
+ set_err_reply(400, "bad From uri");
+ return NULL;
+ }
+ return &tb->parsed_uri;
+}
+
diff --git a/lib/kcore/parser_helpers.h b/lib/kcore/parser_helpers.h
new file mode 100644
index 0000000..58e8764
--- /dev/null
+++ b/lib/kcore/parser_helpers.h
@@ -0,0 +1,11 @@
+#ifndef _PARSER_HELPERS_H
+#define _PARSER_HELPERS_H
+
+#include "../../parser/msg_parser.h"
+#include "../../parser/parse_uri.h"
+
+struct sip_uri* parse_to_uri(struct sip_msg* msg);
+
+struct sip_uri* parse_from_uri(struct sip_msg* msg);
+
+#endif /* _PARSER_HELPERS_H */
Module: sip-router
Branch: janakj/kcore
Commit: 8f3676cf2f6d3b20ae67294817bd49514a061d3a
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8f3676c…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Thu Mar 5 23:56:19 2009 +0100
Merge branch 'sr' into kcore
* sr:
Include parse_to.h explicitly where needed.
Add parsed_uri structure to the to_body structure.
Kamailo compatiblity macros was_canceled and no_new_branches
fix compiler warning about uninitialized variable
integrate sip-router compatiblity patches from Jan Janak
Define fixup_spve_null
Alias LM_NOTICE to NOTICE
Function load_tm_api added
A comment warning about flag FL_REQ_UPSTREAM.
Replace explicit flag values with bit shifts for better readability
---