Module: sip-router
Branch: andrei/mod_register
Commit: ea31876f3efd0d33fd86352299981dd16e3f7908
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ea31876…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Nov 20 17:33:44 2008 +0100
modules: support for mod_register
- new mod_register function added to the module interface
(separate from exports structure):
If a module exports a mod_register function it will be called
immediately after loading the module and checking the module
version and module interface (this means way before calling
mod_init).
The mod_register function prototype is:
int mod_register(char* path, int* dlflags, void* r1, void* r2)
where path is the module path including the filename, dlflags
is a pointer to the dlflags used when loading the module (If
the value is changed to a different and non-zero value, the
module will be reloaded with the new flags), and r1 and r2 are
parameters reserved for future use.
A 0 return means success and -1 means error (the module will not
be loaded).
This new function can be used to register new parsing functions,
alter dynamically the mod_exports structure contents a.s.o.
- kamailio compatible mod exports dlflags handling (but a warning
will be printed saying this is deprecated and the preferred way
is using mod_register().
---
sr_module.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
sr_module.h | 14 ++++++++++++++
2 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/sr_module.c b/sr_module.c
index 21d89ac..491e971 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -216,17 +216,29 @@ static inline int version_control(void *handle, char *path)
return 0;
}
-/* returns 0 on success , <0 on error */
+/** load a sr module.
+ * tries to load the module specified by path.
+ * If modname does contain a '/' or a '.' it would be assumed to contain a
+ * path to the module and it will be used as give.
+ * else <MODS_DIR>/<modname>.so will be tried and if this fails
+ * <MODS_DIR>/<modname>/<modname>.so
+ * @param modname - path or module name
+ * @return 0 on success , <0 on error
+ */
int load_module(char* path)
{
void* handle;
char* error;
+ mod_register_function mr;
union module_exports_u* exp;
unsigned* mod_if_ver;
struct sr_module* t;
struct stat stat_buf;
char* modname;
int len;
+ int dlflags;
+ int new_dlflags;
+ int retries;
#ifndef RTLD_NOW
/* for openbsd */
@@ -287,7 +299,9 @@ int load_module(char* path)
}
#endif /* !EXTRA_DEBUG */
}
-
+ retries=2;
+ dlflags=RTLD_NOW;
+reload:
handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
if (handle==0){
LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",
@@ -314,11 +328,47 @@ int load_module(char* path)
goto error1;
}
/* launch register */
+ mr = (mod_register_function)dlsym(handle, DLSYM_PREFIX "mod_register");
+ if (((error =(char*)dlerror())==0) && mr) {
+ /* no error call it */
+ new_dlflags=dlflags;
+ if (mr(path, &dlflags, 0, 0)!=0) {
+ LOG(L_ERR, "ERROR: load_module: %s: mod_register failed\n", path);
+ goto error1;
+ }
+ if (new_dlflags!=dlflags && new_dlflags!=0) {
+ /* we have to reload the module */
+ dlclose(handle);
+ dlflags=new_dlflags;
+ retries--;
+ if (retries>0) goto reload;
+ LOG(L_ERR, "ERROR: load_module: %s: cannot agree"
+ " on the dlflags\n", path);
+ goto error;
+ }
+ }
exp = (union module_exports_u*)dlsym(handle, DLSYM_PREFIX "exports");
if ( (error =(char*)dlerror())!=0 ){
LOG(L_ERR, "ERROR: load_module: %s\n", error);
goto error1;
}
+ /* hack to allow for kamailio style dlflags inside exports */
+ if (*mod_if_ver == 1) {
+ new_dlflags = exp->v1.dlflags;
+ if (new_dlflags!=dlflags && new_dlflags!=DEFAULT_DLFLAGS) {
+ /* we have to reload the module */
+ dlclose(handle);
+ WARN("%s: exports dlflags interface is deprecated and it will not"
+ "be supported in newer versions; consider using"
+ " mod_register() instead", path);
+ dlflags=new_dlflags;
+ retries--;
+ if (retries>0) goto reload;
+ LOG(L_ERR, "ERROR: load_module: %s: cannot agree"
+ " on the dlflags\n", path);
+ goto error;
+ }
+ }
if (register_module(*mod_if_ver, exp, path, handle)<0) goto error1;
return 0;
diff --git a/sr_module.h b/sr_module.h
index f2aea0e..13474cd 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -89,6 +89,20 @@
#endif
+/** type used for the mod_register function export.
+ * mod_register is a function called when loading a module
+ * (if present), prior to registering the module exports.
+ * @param path - path to the module, including file name
+ * @param dlflags - pointer to the dlflags used when loading the module.
+ * If the value is changed to a different and non-zero
+ * value, the module will be reloaded with the new flags.
+ * @param reserved1 - reserved for future use.
+ * @param reserved2 - reserver for future use
+ * @return 0 on success, -1 on error, all the other values are reserved
+ * for future use (<0 meaning error and >0 success)
+ */
+typedef int (*mod_register_function)(char*, int*, void*, void*);
+
typedef struct module_exports* (*module_register)(void);
typedef int (*cmd_function)(struct sip_msg*, char*, char*);
typedef int (*cmd_function3)(struct sip_msg*, char*, char*, char*);
The commit email script has some quirks that you should be aware of.
Some unexpected feature is that if you create a new branch
(git push origin my_branch:new_branch_that_does_not_exist_yet)
an email will be sent only for the last commit message in the branch.
If you update an existing branch or you don't care that only the last
commit will be emailed (the others will be emailed only if/when somebody
merges your branch in an existing branch), you can skip this.
Example:
git checkout -b my_branch master
vim file1
git add file1
git commit file1
vim file2
git add file2
git commit file2
git push origin my_branch:tmp/my_new_branch
=> only the 2nd commit will be emailed to the list.
This happens because of the email comit script that tries to send
mail only for changes on the branch: it looks at the original branch
and at the new branch head and sends an email for all the commits
between them . However when creating a new branch, there is not enough
information to get the original branch and you either send emails for
all the commits since project start (:-)) or only for the last one.
Even if that happen to you, all the commits messages will be sent the
first time you merge your new branch into some existing branch.
A way to avoid it in the first place is to first create a new branch,
e.g:
git checkout -b my_new_branch master
git push origin my_new_branch:tmp/my_new_branch
and then push your branch on it:
git checkout my_branch
git push origin my_branch:tmp/my_new_branch
Andrei
Module: sip-router
Branch: daniel/pv
Commit: 3247010ccea606a386cf24e00083dc38ae8b43c2
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=3247010…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Nov 20 14:45:47 2008 +0200
PV get null helper added
- PV get null helper function required to stay in the API
- removed unused PV types - now AVP type is used to detect the type of
parameters, some related to R-URI are used by avpops, to be added if a
different solution is not found. Would be hard to manage the types in
core and do the implementation in module.
---
pvapi.c | 23 ++++++++++++++++++-----
pvar.h | 35 ++++-------------------------------
2 files changed, 22 insertions(+), 36 deletions(-)
diff --git a/pvapi.c b/pvapi.c
index f6c6399..eb4ea7a 100644
--- a/pvapi.c
+++ b/pvapi.c
@@ -1,16 +1,16 @@
/*
- * $Id: items.h 2111 2007-05-01 11:18:08Z juhe $
+ * $Id$
*
* Copyright (C) 2001-2003 FhG Fokus
*
- * This file is part of Kamailio, a free SIP server.
+ * This file is part of SIP-Router, a free SIP server.
*
- * Kamailio is free software; you can redistribute it and/or modify
+ * SIP-Router 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,
+ * SIP-Router 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.
@@ -296,7 +296,20 @@ static str pv_str_marker = { PV_MARKER_STR, 1 };
static int pv_get_marker(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
- return pv_get_strintval(msg, param, res, &pv_str_marker, (int)pv_str_marker.s[0]);
+ return pv_get_strintval(msg, param, res, &pv_str_marker,
+ (int)pv_str_marker.s[0]);
+}
+
+static str pv_str_empty = { "", 0 };
+int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+ if(res==NULL)
+ return -1;
+
+ res->rs = pv_str_empty;
+ res->ri = 0;
+ res->flags = PV_VAL_NULL;
+ return 0;
}
pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
diff --git a/pvar.h b/pvar.h
index fcf3982..be7b3bc 100644
--- a/pvar.h
+++ b/pvar.h
@@ -3,14 +3,14 @@
*
* Copyright (C) 2001-2003 FhG Fokus
*
- * This file is part of Kamailio, a free SIP server.
+ * This file is part of SIP-Router, a free SIP server.
*
- * Kamailio is free software; you can redistribute it and/or modify
+ * SIP-Router 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,
+ * SIP-Router 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.
@@ -72,34 +72,7 @@
enum _pv_type {
PVT_NONE=0, PVT_EMPTY, PVT_NULL,
- PVT_MARKER, PVT_AVP, PVT_HDR,
- PVT_PID, PVT_RETURN_CODE, PVT_TIMES,
- PVT_TIMEF, PVT_MSGID, PVT_METHOD,
- PVT_STATUS, PVT_REASON, PVT_RURI,
- PVT_RURI_USERNAME, PVT_RURI_DOMAIN, PVT_RURI_PORT,
- PVT_FROM, PVT_FROM_USERNAME, PVT_FROM_DOMAIN,
- PVT_FROM_TAG, PVT_TO, PVT_TO_USERNAME,
- PVT_TO_DOMAIN, PVT_TO_TAG, PVT_CSEQ,
- PVT_CONTACT, PVT_CALLID, PVT_USERAGENT,
- PVT_MSG_BUF, PVT_MSG_LEN, PVT_FLAGS,
- PVT_HEXFLAGS, PVT_SRCIP, PVT_SRCPORT,
- PVT_RCVIP, PVT_RCVPORT, PVT_REFER_TO,
- PVT_DSET, PVT_DSTURI, PVT_COLOR,
- PVT_BRANCH, PVT_BRANCHES, PVT_CONTENT_TYPE,
- PVT_CONTENT_LENGTH, PVT_MSG_BODY, PVT_AUTH_USERNAME,
- PVT_AUTH_REALM, PVT_RURI_PROTOCOL, PVT_DSTURI_DOMAIN,
- PVT_DSTURI_PORT, PVT_DSTURI_PROTOCOL, PVT_FROM_DISPLAYNAME,
- PVT_TO_DISPLAYNAME, PVT_OURI, PVT_OURI_USERNAME,
- PVT_OURI_DOMAIN, PVT_OURI_PORT, PVT_OURI_PROTOCOL,
- PVT_FORCE_SOCK, PVT_RPID_URI, PVT_DIVERSION_URI,
- PVT_ACC_USERNAME, PVT_PPI, PVT_PPI_DISPLAYNAME,
- PVT_PPI_DOMAIN, PVT_PPI_USERNAME, PVT_PAI_URI,
- PVT_BFLAGS, PVT_HEXBFLAGS, PVT_SFLAGS,
- PVT_HEXSFLAGS, PVT_ERR_CLASS, PVT_ERR_LEVEL,
- PVT_ERR_INFO, PVT_ERR_RCODE, PVT_ERR_RREASON,
- PVT_SCRIPTVAR, PVT_PROTO, PVT_AUTH_USERNAME_WHOLE,
- PVT_AUTH_DURI, PVT_DIV_REASON, PVT_DIV_PRIVACY,
- PVT_AUTH_DOMAIN, PVT_OTHER,
+ PVT_MARKER, PVT_AVP, PVT_OTHER,
PVT_EXTRA /* keep it last */
};
Module: sip-router
Branch: daniel/pv
Commit: d74b7829c6f0c23d786e6e3c3f0cba8b61b438b1
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d74b782…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Nov 20 13:39:29 2008 +0200
pseudo-variable engine api
- imported pvar.h and unified PV and transformations interface in
pvapi.c
- PV engine does not use anymore static array plus a linked list for PV
implementations, PVs will be in module and indexed in a hash table
(small performance enhancement)
- transformations are registered via same model as PV, they will be
implemented in modules, the core will held a hash table to index them
- the core gets a smaller footprint now and better flexibility in
hadling PVs and transformations. pv and transformations will be moved
in pv module
- compiles but no testing so far
---
pvapi.c | 952 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 952 insertions(+), 0 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=d74…
Hello,
working to port PV engine to srouter, but also needed for kamailio's
migration of pseudo-variables (PVs) from core to modules, I need to
extend the module interface. The srouter has already support to work in
dual mode committed by Andrei few days ago, so it should affect only
kamailio's module interface if ser side does not need.
Here is the issue. In kamailio/openser we have so called transformations
that are bound to PV. They are now implemented directly in core. To move
them in a module, the interface needs to be extended, like we did in the
past to export PVs from modules. The important aspect is that they must
become visible immediately after the module is loaded -- this happens
also with PVs (so cannot use mod_init, etc...). This is required because
they may occur during script parsing, therefore the core/parser should
get knowledge of them in very early stage.
PVs are exported via a specific structure in module interface. We can do
same for transformations. There is another option, which can be used for
other purposes in the future - introducing in module interface a
callback to be run immediately after a module is loaded. The
transformations can be exported inside the callback.
Extending this way, in the future, the modules can make other attributes
visible to core/other modules immediately after loading without changing
the module interface.
Therefore I would go for second option. Other opinions?
Cheers,
Daniel
--
Daniel-Constantin Mierla
http://www.asipto.com
Include one line summaries of the merged commits in commit merge messages
(a MUST):
git config --global merge.log true
Use auto-tracking (behave as if -track is added to every git-pull):
git config --global branch.autosetupmerge always
Note: --global changes the global configuration ( ~/.gitconfig). Without
--global the local per repository configuration will be changed
(.git/config). You can either use the commands above or edit by hand
the config files.
Example ~/.gitconfig:
[user]
name = Andrei Pelinescu-Onciul
email = andrei(a)iptel.org
signinkey = 2CF56A2D
[color]
branch = auto
status = auto
[merge]
log = true
[branch]
autosetupmerge = always
[remote "ser"]
url= ssh://git.sip-router.org/ser
push=cvshead:andrei/cvshead
push=sctp:andrei/sctp
[url "ssh://git.sip-router.org/"]
insteadOf = sip-router:
insteadOf = sip_router:
[alias]
intercommit = !sh -c 'git show "$0" > /tmp/commit1 && git show "$1" > /tmp/commit2 && interdiff /tmp/commit[12] | less -FRS'
funcdiff = !sh -c \"git show \\\"\\$0:\\$2\\\" | sed -n \\\"/^[^ \\t].*\\$3(/,/^}/p\\\" > /tmp/.tmp1 &&\n git show \\\"\\$1:\\$2\\\" | sed -n \\\"/^[^ \\t].*\\$3(/,/^}/p\\\" > /tmp/.tmp2 &&\ngit diff /tmp/.tmp1 /tmp/.tmp2\"
The insteadOf lines create aliases for the url (so that I can use
git pull sip-router:ser_core cvs-head instead of
git pull ssh://git.sip-router.org/ser_core cvs-head
The aliases create a new git "commands", for more details see
http://git.or.cz/gitwiki/Aliases.
The funcdiff alias tries to display the differences in _one_ function
between 2 different commits, e.g.:
git funcdiff <oldrev> <newrev> <path> <function>
The intecommit alias is for seeing differences between a submited patch
(local commit into your repository) and the possibly modified version
applied: git intercommit <orig_commit> <applied_commit>.
Andrei
Hi,
I've attached a very brief version of the Karlsruhe meeting minutes.
It contains input mostly from me and Daniel (so that you know who to
blame :-)).
Sorry for the long delay.
Hope we haven't missed anything and if we did feel free to reply to this
thread.
Thanks a lot to 1&1 for hosting the meeting and to everyone who was
able to come on such a short notice.
Andrei
>
> Here is some more information on the git repository:
>
>
> Synchronization with SER CVS
> ============================
> The repository git.sip-router.org/ser is pulls commits from the SER CVS
> repository automatically. The synchronization works one-way only, changes
> commited to the SER CVS are automatically imported into the Git repository,
> but not vice versa. In other words if you want to commit something in the
> SER CVS repository then you have to do it manually, git won't help you here.
To push changes I've done in the git ser repo to ser cvs I use:
git log --pretty=oneline # to get the commit id I want to "export"
git cvsexportcommit -c -p -w ~/ser.cvs/ -v <commitid>
e.g.: git cvsexportcommit -c -p -w ~/ser.cvs/ -v <commitid> a9d929f558a6a620034fac8aa06c503b72c30fd8
in ~/ser.cvs I have an up-to-date checkout of ser from berlios cvs with
the following small change:
cd ~/ser.cvs; rm ser;
ln -s . ser
I need this because in the git repo ser is under the ser subdir, while
in cvs it's in the "root" dir (or at least this is the way I checkout
it).
Another way to do it is to generate patches in git (e.g.
git format-patch <comitid>) and the apply it manually on cvs, but this
requires also a copy-paste for the commit message.
>
> Clone the repository:
> $ git clone git://git.sip-router.org/ser
>
> and display the list of branches in the cloned repository:
> $ git branch -a
>
> origin/HEAD
> origin/MAIN
> origin/Maintainer
> origin/andrei_cvs-head
> origin/cancel_fix
> origin/cvs-head
> origin/janakj
> origin/jj/cvshead
> origin/jj/doxygen
> origin/master
> origin/rel_0_8_11
> origin/rel_0_8_12
> origin/rel_0_8_14
> origin/rel_0_9_0
> origin/rel_2_0_0
> origin/rel_janakj
> origin/start
> origin/testing_0_8_12
> origin/vendor
>
> Several of the branches above are automatically updated from CVS, namely
> origin/cvs-head receives cvs commits to HEAD and origin/rel_2_0_0
> receives commits to the branch rel_2_0_0 in CVS, and so on.
>
> These branches will be updated with latest commits from the CVS repository
> every time you do:
>
> $ git pull
>
> Note that after the steps described above you have the whole CVS commit history
> of SER on your local machine, starting with day 1 until today, and including
> all branches from the CVS repository. This is convenient because you can
> work with the history offline and pretty much all common operations are
> blazingly fast because they only work with local files.
>
Note also that you can push changes only to branches starting with tmp/
, with your <your_username>/ or master (which is unused).
The cvs sync branches are read-only,
Andrei
[...]