Module: sip-router
Branch: master
Commit: 45df9f7e49450e27507977fa71a67dd98d381d9e
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=45df9f7…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue Mar 10 22:35:33 2009 +0100
timers: helpers for forking separate timer procs
Helper functions for forking simple separate timer processes:
fork_dummy_timer(...) - forks a process that will just sleep()
for the required interval and then will call the provided
timer function, all that in a loop.
Care must be taken to use it only when fork_process() is
allowed (e.g.: module child_init function, when
rank==PROC_MAIN; see doc/modules_init.txt for more details)
It can be used to replace kamailio register_timer_process()
(but note that it's not a "drop-in" replacement).
fork_local_timer_process() - forks a process, initializes a
local_timer for it, and returns the local_timer handler both
to the parent and to the child process, so both of them can
add/del timers (if appropriate locking is used).
Example usage:
struct local_timer* lt_h;
pid=fork_local_timer_process(...., <_h);
if (pid==0){
timer_init(&my_timer1, my_timer_f1, 0, 0);
...
local_timer_add(<_h, &my_timer, S_TO_TICKS(10), get_ticks_raw());
...
while(1) { sleep(1); local_timer_run(lt, get_ticks_raw()); }
}
(note that instead of sleep()-ing the process can do some useful work,
like polling some fds a.s.o.)
---
timer_proc.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
timer_proc.h | 43 +++++++++++++++++++++
2 files changed, 159 insertions(+), 0 deletions(-)
diff --git a/timer_proc.c b/timer_proc.c
new file mode 100644
index 0000000..7d0abb7
--- /dev/null
+++ b/timer_proc.c
@@ -0,0 +1,116 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * timer_proc.c - separate process timers
+ * (unrelated to the main fast and slow timers)
+ */
+/*
+ * History:
+ * --------
+ * 2009-03-10 initial version (andrei)
+*/
+
+#include "timer_proc.h"
+#include "pt.h"
+#include "mem/shm_mem.h"
+
+#include <unistd.h>
+
+
+/** forks a separate simple sleep() periodic timer.
+ * Forks a very basic periodic timer process, that just sleep()s for
+ * the specified interval and then calls the timer function.
+ * The new "dummy timer" process execution start immediately, the sleep()
+ * is called first (so the first call to the timer function will happen
+ * <interval> seconds after the call to fork_dummy_timer)
+ * @param child_id - @see fork_process()
+ * @param desc - @see fork_process()
+ * @param make_sock - @see fork_process()
+ * @param f - timer function/callback
+ * @param param - parameter passed to the timer function
+ * @param interval - interval in seconds.
+ * @return - pid of the new process on success, -1 on error
+ * (doesn't return anything in the child process)
+ */
+int fork_dummy_timer(int child_id, char* desc, int make_sock,
+ timer_function* f, void* param, int interval)
+{
+ int pid;
+
+ pid=fork_process(child_id, desc, make_sock);
+ if (pid<0) return -1;
+ if (pid==0){
+ /* child */
+ for(;;){
+ sleep(interval);
+ f(get_ticks(), param); /* ticks in s for compatibility with old
+ timers */
+ }
+ }
+ /* parent */
+ return pid;
+}
+
+
+
+/** forks a timer process based on the local timer.
+ * Forks a separate timer process running a local_timer.h type of timer
+ * A pointer to the local_timer handle (allocated in shared memory) is
+ * returned in lt_h. It can be used to add/delete more timers at runtime
+ * (via local_timer_add()/local_timer_del() a.s.o).
+ * If timers are added from separate processes, some form of locking must be
+ * used (all the calls to local_timer* must be enclosed by locks if it
+ * cannot be guaranteed that they cannot execute in the same time)
+ * The timer "engine" must be run manually from the child process. For
+ * example a very simple local timer process that just runs a single
+ * periodic timer can be started in the following way:
+ * struct local_timer* lt_h;
+ *
+ * pid=fork_local_timer_process(...., <_h);
+ * if (pid==0){
+ * timer_init(&my_timer, my_timer_f, 0, 0);
+ * local_timer_add(<_h, &my_timer, S_TO_TICKS(10), get_ticks_raw());
+ * while(1) { sleep(1); local_timer_run(lt, get_ticks_raw()); }
+ * }
+ *
+ * @param child_id - @see fork_process()
+ * @param desc - @see fork_process()
+ * @param make_sock - @see fork_process()
+ * @param lt_h - local_timer handler
+ * @return - pid to the parent, 0 to the child, -1 if error.
+ */
+int fork_local_timer_process(int child_id, char* desc, int make_sock,
+ struct local_timer** lt_h)
+{
+ int pid;
+ struct local_timer* lt;
+
+ lt=shm_malloc(sizeof(*lt));
+ if (lt==0) goto error;
+ if (init_local_timer(lt, get_ticks_raw())<0) goto error;
+ pid=fork_process(child_id, desc, make_sock);
+ if (pid<0) goto error;
+ *lt_h=lt;
+ return pid;
+error:
+ if (lt) shm_free(lt);
+ return -1;
+}
+
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/timer_proc.h b/timer_proc.h
new file mode 100644
index 0000000..e68e146
--- /dev/null
+++ b/timer_proc.h
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * timer_proc.h - separate process timers
+ * (unrelated to the main fast and slow timers)
+ */
+/*
+ * History:
+ * --------
+ * 2009-03-10 initial version (andrei)
+*/
+
+#ifndef __timer_proc_h
+#define __timer_proc_h
+
+#include "local_timer.h"
+
+/* forks a separate simple sleep() periodic timer */
+int fork_dummy_timer(int child_id, char* desc, int make_sock,
+ timer_function* f, void* param, int interval);
+
+/* forks a timer process based on the local timer */
+int fork_local_timer_process(int child_id, char* desc, int make_sock,
+ struct local_timer** lt_h);
+
+#endif /*__timer_proc_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
Daniel-Constantin Mierla writes:
> what I was saying is that many errors can happen before actually
> creating the transaction. And if there is a bad formatted sip message
> then the transaction is not created. Without a transaction, failure
> route cannot be called.
but in case of tcp forwarding failure, failure route is not called even
when transaction is created. i consider that a bug.
what comes to not creating transaction is sip request is badly
formatted, are you saying that if i call t_newtran() in script when sip
request has syntax error, the call fails? if not, what you say is not
true.
> There will be lot to debate on sip transaction specs and handling.
> sr-dev is the right to discuss the future of this one.
yes, i cc'ed sr-dev.
-- juha
Module: sip-router
Branch: janakj/kcore
Commit: d13c2c41f9dc331cf22008c6d7ebd470a0df5525
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d13c2c4…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 8 23:42:13 2009 +0100
Adding faked_msg.[ch] from kamailio core
These files are missing in the sip-router core
---
lib/kcore/faked_msg.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/kcore/faked_msg.h | 31 +++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/faked_msg.c b/lib/kcore/faked_msg.c
new file mode 100644
index 0000000..9a51723
--- /dev/null
+++ b/lib/kcore/faked_msg.c
@@ -0,0 +1,64 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of kamailio, a free SIP server.
+ *
+ * openser 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
+ *
+ * openser 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
+ */
+
+#include "../../dprint.h"
+#include "../../globals.h"
+#include "../../dset.h"
+
+#include "faked_msg.h"
+
+#define FAKED_SIP_MSG "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <you(a)kamailio.org>;tag=123\r\nTo: <you(a)kamailio.org>\r\nCall-ID: 123\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
+#define FAKED_SIP_MSG_LEN (sizeof(FAKED_SIP_MSG)-1)
+static char _faked_sip_buf[FAKED_SIP_MSG_LEN+1];
+static struct sip_msg _faked_msg;
+static unsigned int _faked_msg_no = 0;
+
+int faked_msg_init(void)
+{
+ if(_faked_msg_no>0)
+ return 0;
+ /* init faked sip msg */
+ memcpy(_faked_sip_buf, FAKED_SIP_MSG, FAKED_SIP_MSG_LEN);
+ _faked_sip_buf[FAKED_SIP_MSG_LEN] = '\0';
+
+ memset(&_faked_msg, 0, sizeof(struct sip_msg));
+
+ _faked_msg.buf=_faked_sip_buf;
+ _faked_msg.len=FAKED_SIP_MSG_LEN;
+
+ _faked_msg.set_global_address=default_global_address;
+ _faked_msg.set_global_port=default_global_port;
+
+ if (parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg)!=0)
+ {
+ LM_ERR("parse_msg failed\n");
+ return -1;
+ }
+ return 0;
+}
+
+struct sip_msg* faked_msg_next(void)
+{
+ _faked_msg.id=_faked_msg_no++;
+ clear_branches();
+ return &_faked_msg;
+}
diff --git a/lib/kcore/faked_msg.h b/lib/kcore/faked_msg.h
new file mode 100644
index 0000000..55a4daa
--- /dev/null
+++ b/lib/kcore/faked_msg.h
@@ -0,0 +1,31 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
+ *
+ * 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
+ */
+
+#ifndef _FAKED_SIP_MSG_H_
+#define _FAKED_SIP_MSG_H_
+
+#include "../../parser/msg_parser.h"
+
+int faked_msg_init(void);
+struct sip_msg* faked_msg_next(void);
+
+#endif
Module: sip-router
Branch: master
Commit: 00c747a1b113b8af4f9e96f99dcde6b14e36eebd
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=00c747a…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Tue Mar 10 17:44:42 2009 +0100
Export get_sock_info_list function to modules
---
socket_info.c | 2 +-
socket_info.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/socket_info.c b/socket_info.c
index 1b260dd..abd3064 100644
--- a/socket_info.c
+++ b/socket_info.c
@@ -301,7 +301,7 @@ static char* get_proto_name(unsigned short proto)
/* returns 0 if support for the protocol is not compiled or if proto is
invalid */
-static struct socket_info** get_sock_info_list(unsigned short proto)
+struct socket_info** get_sock_info_list(unsigned short proto)
{
switch(proto){
diff --git a/socket_info.h b/socket_info.h
index bf36ddb..627e3db 100644
--- a/socket_info.h
+++ b/socket_info.h
@@ -88,7 +88,7 @@ struct socket_info* grep_sock_info_by_port(unsigned short port,
struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
unsigned short proto);
-
+struct socket_info** get_sock_info_list(unsigned short proto);
/* helper function:
* returns next protocol, if the last one is reached return 0
Module: sip-router
Branch: master
Commit: c5c2bcd6fe8cbcdd825a916aefe232c0a3fe0574
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c5c2bcd…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Mar 9 00:15:31 2009 +0100
K. compatibility members of the branch structure in dset.c
The structure now also contains the buffer and length variable
to store the path header and an unsigned int variable to store
branch flags.
---
config.h | 2 ++
dset.c | 7 +++++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/config.h b/config.h
index a18def8..317ff1c 100644
--- a/config.h
+++ b/config.h
@@ -70,6 +70,8 @@
#define MAX_URI_SIZE 1024 /* used when rewriting URIs */
+#define MAX_PATH_SIZE 256 /* Maximum length of path header buffer */
+
#define MY_VIA "Via: SIP/2.0/UDP "
#define MY_VIA_LEN (sizeof(MY_VIA) - 1)
diff --git a/dset.c b/dset.c
index ab58dca..e4e995a 100644
--- a/dset.c
+++ b/dset.c
@@ -57,9 +57,16 @@ struct branch
char dst_uri[MAX_URI_SIZE];
unsigned int dst_uri_len;
+ /* Path set */
+ char path[MAX_PATH_SIZE];
+ unsigned int path_len;
+
int q; /* Preference of the contact among
* contact within the array */
struct socket_info* force_send_socket;
+
+ /* Branch flags */
+ unsigned int flags;
};
Folks,
As some of you know I have been trying to make kamailio modules
compile with the sip-router core. I wrote several scripts to perform
bulk updates of the source code and commit the changes. That includes
database related changes for libsrdb1, changes of headers that are not
present in the core anymore, and so on.
I keep my changes in a git repository which I just published on
git.sip-router.org. You can browse the repository here:
http://git.sip-router.org/cgi-bin/gitweb.cgi?p=kamailio-3.0/.git;a=summary
And you can clone it using:
git clone git://git.sip-router.org/kamailio-3.0
I'd like to point out that this is a temporary repository only, it
helps me with my merging work, it allows me to keep my patches up to
date on top of moving sip-router core and kamailio modules (using a
set of scripts that I didn't publish), but it is not how it should be
organized in the future.
The repository is fairly big, it contains 91 branches, and is
organized as follows:
* Branch 'sr' contains the contents of the sip-router/master branch
from the main sip-router repository, possibly with some local
changes not yet published on the sip-router/master branch. I pull
into this branch from the main branch. I also use this branch to do
compatibility changes in the sip-router core and those changes are
then pushed into sip-router/master when done.
* Branch 'kcore' contains the contents of sip-router/janakj/kcore
branch, I use this branch to do changes in the libkcore stuff. Local
changes from this branch are then pushed into
sip-router/janakj/kcore
* Branch 'km_module' contains kamailio modules from kamailio svn
trunk, but with the core, tm module and some database drivers
removed. I keep this branch synchronized with the git import of
kamailio trunk and on top of that there are a few commits that
remove everything which would conflict with the sip-router
core. This branch must have no local changes except for the commits
that remove conflicting files.
* Branch 'km_sr' contains all three previous branches merged, that is
sip-router core + libkcore + kamailio modules. This brach serves as
the basis for other per-module branches, module branches base their
changes on top of km_sr.
* A bunch of module branches, there is one branch per kamailio module
that needs to be update, the name of the branch is always the name of
the module. You can get full list here:
http://git.sip-router.org/cgi-bin/gitweb.cgi?p=kamailio-3.0/.git;a=heads
One thing that is special about module branches is that they use
git-rebase to keep local changes on top of all other changes coming
from the branch km_sr. In other words, what happens when you merge
km_sr into a module branch is this:
- All local changes are undone and saved into a temporary area
- Changes from km_sr are applied to the branch
- Changes from the temporary area are applied back on top of the
updated branch
This keeps local changes in module branches on top of all other
changes that might have propagated from the sip-router repository
or kamailio svn repository. In the end we will be using the
repository to generate a set of patches that will be applied either
to the code in the svn repository or in another git repository so I
think this is the way to go.
Here is a diagram showing how changes propagate into individual branches:
svn ---> git:km/trunk --(D)----> km_modules -+
cvs ---> git:sr/master --(L)---> sr ---------+-(O)-> km_sr ---+--(R)-> acc
sr/janakj/kcore -(L)--> kcore ------+ +--(R)-> auth
+--(R)--> ...
(D) is where the kamailio core and conflicting modules get removed,
(L) indicates possible local changes to the sip-router core or
likcore, (O) denotes the place where git octopus merge happends, and
finally (R) marks places where git-rebase is used instead of the
default git merge.
Because the process of updating the repository is quite complex, and,
frankly, brittle, I'd like to ask you that you do not push into this
repository although it is allowed for anyone who has write access on
git.sip-router.org. Instead do all the changes that you would like to
have applied in your local clone and then send patches to the mailing
list, I will apply them to my master copy and then republish.
This is how my typical workflow looks like:
Today I want to work on the presence module, so I checkout the
presence branch:
$ git co presence
I investigate why the module does not compile, do some changes and
commit them into the branch. In this step I try hard to make sure
that the commits are logically split, because it makes reviewing the
changes much easier. A reviewer can typically just decide whether
the patch should be applied or thrown away as a whole.
In the previous step I realized that I might need to do some changes
in the sip-router core to make the module work, so I check out the
'sr' branch:
$ git co sr
and do the changes there. After that I need to propagate the changes
I did to the sr core into the presence branch, I do this in two
steps, first I pull the changes into the km_sr branch:
$ git co km_sr
$ git pull
And secondly I pull the sip-router core change into 'presence' branch:
$ git co presence
$ got pull
After the last step you will see the rebase taking place. There
should be no conflicts because I never modify anything that belongs
to the sip-router core or libkcore on the per-module branch. I
always use 'sr' and 'kcore' branches for that.
That's it, I should also note that I have a bunch of scripts that help
me to keep the whole repository up-to-date, so I'd typically just run
something like km_pull.sh and that updates all branches, also pulling
changes from svn and cvs in the process. The scripts are currently not
ready to be published, they are brittle and would most likely work in
my environment only. But I do offer the service of keeping the
kamailo-3.0 repository up-to-date, so you can just mirror that one and
you wouldn't need the scripts.
I'll send a separate email describing the current state of kamailio
modules.
Jan.
Here's a small patch to fix some compilation error on the sip-router.
There are still issue with respect to the timer registration, but that
is discussed on a separate thread.
$ git diff
diff --git a/modules/ratelimit/ratelimit.c b/modules/ratelimit/ratelimit.c
index a3099cf..8d57243 100644
--- a/modules/ratelimit/ratelimit.c
+++ b/modules/ratelimit/ratelimit.c
@@ -46,6 +46,7 @@
#include "../../data_lump.h"
#include "../../data_lump_rpl.h"
#include "../sl/sl_api.h"
+#include "../../lib/kcore/km_ut.h"
MODULE_VERSION
Regards,
Ovidiu Sas
Hello all,
The SDP parser from the kamailio core needs to be imported into the
sip-router core.
It is located under parser/sdp directory.
Th qos module has a dependency on the SDP parser.
Regards,
Ovidiu Sas