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…