Module: sip-router
Branch: master
Commit: 578b3a95ec13d1ca934c02fed8291aa5419f2160
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=578b3a9…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 8 04:42:10 2009 +0100
Remove function replace_len which is no longer needed.
This function was originally used to calculate the size of the memory
buffer in replace_build for the resulting string. Since we now print
the result into a static buffer, this function is no longer needed.
---
re.c | 46 ----------------------------------------------
1 files changed, 0 insertions(+), 46 deletions(-)
diff --git a/re.c b/re.c
index 6b19786..2b2f6b0 100644
--- a/re.c
+++ b/re.c
@@ -328,52 +328,6 @@ error:
return 0;
}
-
-
-static int replace_len(const char* match, int nmatch, regmatch_t* pmatch,
- struct subst_expr* se, struct sip_msg* msg)
-{
- int r;
- int len;
- str* uri;
-
- len=se->replacement.len;
- for (r=0; r<se->n_escapes; r++){
- switch(se->replace[r].type){
- case REPLACE_NMATCH:
- len-=se->replace[r].size;
- if ((se->replace[r].u.nmatch<nmatch)&&(
- pmatch[se->replace[r].u.nmatch].rm_so!=-1)){
- /* do the replace */
- len+=pmatch[se->replace[r].u.nmatch].rm_eo-
- pmatch[se->replace[r].u.nmatch].rm_so;
- };
- break;
- case REPLACE_CHAR:
- len-=(se->replace[r].size-1);
- break;
- case REPLACE_URI:
- len-=se->replace[r].size;
- if (msg->first_line.type!=SIP_REQUEST){
- LOG(L_CRIT, "BUG: replace_len: uri substitution on"
- " a reply\n");
- break; /* ignore, we can continue */
- }
- uri= (msg->new_uri.s)?(&msg->new_uri):
- (&msg->first_line.u.request.uri);
- len+=uri->len;
- break;
- default:
- LOG(L_CRIT, "BUG: replace_len: unknown type %d\n",
- se->replace[r].type);
- /* ignore it */
- }
- }
- return len;
-}
-
-
-
/* rpl.s will be alloc'ed with the proper size & rpl.len set
* returns 0 on success, <0 on error*/
static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
Module: sip-router
Branch: master
Commit: e12b2f1d22db9b2ac08c07cdfa4c9923e7c0de42
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e12b2f1…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 8 04:40:13 2009 +0100
Kamailio compatibility changes: replace_build
List of changes:
* Add support for pseudo variables
* Create a static buffer allocated on the stack that will be used to
print the resulting string, we no longer can determine the final
size of the result in advance because of pseudo-variable support and
thus we print to a fixed-size buffer and copy the result into a
dynamically allocated buffer when done.
* Define macro RBUF_APPEND which is used to add text to the static
buffer, the macro checks if there is enough space in the buffer
before each write
* Remove the call to replace_len at the beginning of the function
* Replace all occurrences of memcpy(...) and dest+=... with
RBUF_APPEND
* At the end create a dynamically allocated buffer for the result and
copy the string from the static buffer into the dynamic buffer.
---
re.c | 56 +++++++++++++++++++++++++++++++++-----------------------
1 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/re.c b/re.c
index 7f1dc23..6b19786 100644
--- a/re.c
+++ b/re.c
@@ -381,30 +381,30 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
{
int r;
str* uri;
+ pv_value_t sv;
char* p;
char* dest;
char* end;
int size;
-
- rpl->len=replace_len(match, nmatch, pmatch, se, msg);
- if (rpl->len==0){
- rpl->s=0; /* empty string */
- return 0;
- }
- rpl->s=pkg_malloc(rpl->len);
- if (rpl->s==0){
- LOG(L_ERR, "ERROR: replace_build: out of mem (rpl)\n");
- goto error;
- }
+ static char rbuf[REPLACE_BUFFER_SIZE];
+
+#define RBUF_APPEND(dst, src, size) \
+ if ((dst) - rbuf + (size) >= REPLACE_BUFFER_SIZE - 1) { \
+ ERR("replace_build: Buffer too small\n"); \
+ goto error; \
+ } \
+ memcpy((dst), (src), (size)); \
+ (dst) += (size);
+
p=se->replacement.s;
end=p+se->replacement.len;
- dest=rpl->s;
+ dest=rbuf;
+
for (r=0; r<se->n_escapes; r++){
/* copy the unescaped parts */
size=se->replacement.s+se->replace[r].offset-p;
- memcpy(dest, p, size);
+ RBUF_APPEND(dest, p, size);
p+=size+se->replace[r].size;
- dest+=size;
switch(se->replace[r].type){
case REPLACE_NMATCH:
if ((se->replace[r].u.nmatch<nmatch)&&(
@@ -412,15 +412,13 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
/* do the replace */
size=pmatch[se->replace[r].u.nmatch].rm_eo-
pmatch[se->replace[r].u.nmatch].rm_so;
- memcpy(dest,
- match+pmatch[se->replace[r].u.nmatch].rm_so,
- size);
- dest+=size;
+ RBUF_APPEND(dest,
+ match+pmatch[se->replace[r].u.nmatch].rm_so,
+ size);
};
break;
case REPLACE_CHAR:
- *dest=se->replace[r].u.c;
- dest++;
+ RBUF_APPEND(dest, &se->replace[r].u.c, 1);
break;
case REPLACE_URI:
if (msg->first_line.type!=SIP_REQUEST){
@@ -430,8 +428,14 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
}
uri= (msg->new_uri.s)?(&msg->new_uri):
(&msg->first_line.u.request.uri);
- memcpy(dest, uri->s, uri->len);
- dest+=uri->len;
+ RBUF_APPEND(dest, uri->s, uri->len);
+ break;
+ case REPLACE_SPEC:
+ if(pv_get_spec_value(msg, &se->replace[r].u.spec, &sv)!=0) {
+ ERR("replace_build: item substitution returned error\n");
+ break; /* ignore, we can continue */
+ }
+ RBUF_APPEND(dest, sv.rs.s, sv.rs.len);
break;
default:
LOG(L_CRIT, "BUG: replace_build: unknown type %d\n",
@@ -439,7 +443,13 @@ static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
/* ignore it */
}
}
- memcpy(dest, p, end-p);
+ RBUF_APPEND(dest, p, end-p);
+ rpl->len = dest - rbuf;
+ if ((rpl->s = pkg_malloc(rpl->len)) == NULL) {
+ ERR("replace_build: Out of pkg memory\n");
+ goto error;
+ }
+ memcpy(rpl->s, rbuf, rpl->len);
return 0;
error:
return -1;
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: 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: 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
---
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 */