[Pkg-voip-commits] [kamailio] 01/03: New upstream version 5.0.4

Victor Seva vseva at moszumanska.debian.org
Thu Dec 14 17:33:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

vseva pushed a commit to branch master
in repository kamailio.

commit 767c033c5e08f4f05e4277219981f8af28b8e834
Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Date:   Thu Oct 26 09:18:12 2017 +0200

    New upstream version 5.0.4
---
 ChangeLog                                          |  711 +++++++++++++
 pkg/kamailio/centos/6/kamailio.spec                |    2 +-
 pkg/kamailio/centos/7/kamailio.spec                |    2 +-
 pkg/kamailio/deb/debian/changelog                  |    6 +
 pkg/kamailio/deb/debian/control                    |    2 +-
 pkg/kamailio/deb/jessie/changelog                  |    6 +
 pkg/kamailio/deb/jessie/control                    |    2 +-
 pkg/kamailio/deb/precise/changelog                 |    6 +
 pkg/kamailio/deb/precise/control                   |    2 +-
 pkg/kamailio/deb/sid/changelog                     |    6 +
 pkg/kamailio/deb/sid/control                       |    2 +-
 pkg/kamailio/deb/stretch/changelog                 |    6 +
 pkg/kamailio/deb/stretch/control                   |    2 +-
 pkg/kamailio/deb/trusty/changelog                  |    6 +
 pkg/kamailio/deb/trusty/control                    |    2 +-
 pkg/kamailio/deb/wheezy/changelog                  |    6 +
 pkg/kamailio/deb/wheezy/control                    |    2 +-
 pkg/kamailio/deb/xenial/changelog                  |    6 +
 pkg/kamailio/deb/xenial/control                    |    2 +-
 pkg/kamailio/fedora/17/kamailio.spec               |    2 +-
 pkg/kamailio/obs/README                            |   16 +
 pkg/kamailio/obs/kamailio.init                     |  141 +++
 pkg/kamailio/obs/kamailio.service                  |   17 +
 pkg/kamailio/{centos/7 => obs}/kamailio.spec       |  558 ++++++++--
 pkg/kamailio/obs/kamailio.sysconfig                |   18 +
 pkg/kamailio/obs/kamailio.tmpfiles                 |    1 +
 pkg/kamailio/obs/meta                              |   43 +
 pkg/kamailio/oracle/el6/kamailio.spec              |    2 +-
 pkg/kamailio/oracle/el7/kamailio.spec              |    2 +-
 pkg/kamailio/rpm/kamailio.spec-4.1                 |    2 +-
 pkg/kamailio/rpm/kamailio.spec.CenOS               |    2 +-
 pkg/kamailio/rpm/kamailio.spec.SuSE                |    2 +-
 src/Makefile.defs                                  |    2 +-
 src/core/core_cmd.c                                |    2 +-
 src/core/ip_addr.h                                 |    4 +-
 src/core/parser/parse_fline.h                      |   25 +-
 src/core/rvalue.c                                  |    4 +
 src/core/socket_info.c                             |    2 +-
 src/core/tcp_conn.h                                |    2 +-
 src/core/tcp_read.c                                |   47 +-
 src/modules/app_mono/doc/app_mono_admin.xml        |   22 +-
 src/modules/app_python/doc/app_python_admin.xml    |    8 +-
 src/modules/auth/README                            |   16 +-
 src/modules/auth/doc/auth_functions.xml            |   10 +-
 src/modules/auth_radius/doc/auth_radius_admin.xml  |  101 +-
 src/modules/carrierroute/cr_db.c                   |   34 +
 src/modules/carrierroute/cr_db.h                   |    5 +
 src/modules/carrierroute/cr_func.c                 |    2 +-
 src/modules/cfgutils/cfgutils.c                    |   32 +-
 src/modules/cnxcc/README                           |   12 +-
 src/modules/cnxcc/doc/cnxcc_admin.xml              |   73 +-
 src/modules/cplc/doc/cplc_admin.xml                |   38 +-
 src/modules/db_postgres/README                     |   16 +
 src/modules/db_postgres/doc/db_postgres_admin.xml  |   25 +-
 src/modules/dialog/README                          |   11 +-
 src/modules/dialog/dlg_cseq.c                      |   10 +-
 src/modules/dialog/dlg_handlers.c                  |    7 +-
 src/modules/dialog/doc/dialog_admin.xml            |   22 +-
 src/modules/domain/domain_mod.c                    |   28 +-
 src/modules/domainpolicy/README                    |   40 +-
 .../domainpolicy/doc/domainpolicy_admin.xml        |   78 +-
 src/modules/htable/htable.c                        |    2 +-
 src/modules/http_async_client/async_http.c         |    2 +
 src/modules/janssonrpcc/janssonrpc.h               |   10 +-
 src/modules/janssonrpcc/janssonrpc_io.c            |    4 +
 src/modules/janssonrpcc/janssonrpc_io.h            |    4 +-
 src/modules/janssonrpcc/janssonrpc_request.c       |    4 +-
 src/modules/janssonrpcc/janssonrpc_request.h       |    2 +-
 src/modules/janssonrpcc/janssonrpc_server.c        |    5 +
 src/modules/janssonrpcc/janssonrpc_server.h        |    6 +-
 src/modules/janssonrpcc/janssonrpc_srv.c           |    4 +
 src/modules/janssonrpcc/janssonrpc_srv.h           |    4 +-
 src/modules/janssonrpcc/janssonrpcc_mod.c          |   14 +-
 src/modules/json/json_mod.c                        |    4 +-
 src/modules/jsonrpcc/jsonrpcc_mod.c                |   44 +-
 src/modules/jsonrpcs/jsonrpcs_fifo.c               |  175 ++--
 src/modules/jsonrpcs/jsonrpcs_mod.c                |   28 +-
 src/modules/jsonrpcs/jsonrpcs_mod.h                |    1 +
 src/modules/jsonrpcs/jsonrpcs_sock.c               |   67 +-
 src/modules/maxfwd/doc/maxfwd_admin.xml            |   38 +-
 src/modules/mediaproxy/README                      |    6 +-
 src/modules/mediaproxy/doc/mediaproxy_admin.xml    |   58 +-
 src/modules/misc_radius/README                     |   10 +
 src/modules/misc_radius/doc/misc_radius_admin.xml  |   68 +-
 src/modules/msrp/msrp_netio.c                      |   14 +-
 src/modules/nat_traversal/README                   |    6 +-
 .../nat_traversal/doc/nat_traversal_admin.xml      |   46 +-
 src/modules/presence_conference/add_events.c       |   15 +-
 src/modules/presence_conference/add_events.h       |    7 +-
 src/modules/presence_conference/notify_body.c      |   21 +-
 src/modules/presence_conference/notify_body.h      |    8 +-
 src/modules/presence_conference/pidf.c             |   19 +-
 src/modules/presence_conference/pidf.h             |    5 -
 .../presence_conference/presence_conference.c      |    3 -
 .../presence_conference/presence_conference.h      |    7 +-
 src/modules/presence_xml/README                    |   22 +-
 .../presence_xml/doc/presence_xml_admin.xml        |   36 +-
 src/modules/pua_dialoginfo/dialog_publish.c        |  130 +--
 src/modules/pua_dialoginfo/pua_dialoginfo.c        |   13 +-
 src/modules/pua_dialoginfo/pua_dialoginfo.h        |   14 +-
 src/modules/rtpproxy/rtpproxy.c                    |    4 +-
 src/modules/seas/cluster.h                         |    7 +-
 src/modules/seas/encode_allow.h                    |   10 +-
 src/modules/seas/encode_content_disposition.h      |   10 +-
 src/modules/seas/encode_content_length.h           |   11 +-
 src/modules/seas/encode_content_type.h             |   11 +-
 src/modules/seas/encode_cseq.h                     |   11 +-
 src/modules/seas/encode_digest.h                   |   11 +-
 src/modules/seas/seas.c                            | 1101 ++++++++++----------
 src/modules/seas/seas.h                            |  107 +-
 src/modules/seas/seas_action.c                     |   20 +-
 src/modules/sipcapture/README                      |   26 +-
 src/modules/sipcapture/doc/sipcapture_admin.xml    |   22 +-
 src/modules/sipcapture/examples/kamailio.cfg       |   20 +-
 src/modules/sipcapture/hep.c                       |   52 +-
 src/modules/sipcapture/sipcapture.c                |   10 +-
 src/modules/snmpstats/utilities.c                  |   31 +-
 src/modules/sqlops/sql_api.c                       |    5 +-
 src/modules/timer/timer.c                          |    2 +-
 src/modules/tm/t_lookup.c                          |   16 +-
 src/modules/tm/t_suspend.c                         |   65 +-
 src/modules/tmx/tmx_mod.c                          |   66 +-
 src/modules/uid_auth_db/aaa_avps.h                 |   14 +-
 src/modules/uid_auth_db/authorize.c                |  301 +++---
 src/modules/uid_auth_db/authorize.h                |    6 +-
 src/modules/uid_auth_db/uid_auth_db_mod.c          |  156 ++-
 src/modules/uid_auth_db/uid_auth_db_mod.h          |   10 +-
 src/modules/uid_gflags/uid_gflags.c                |  131 ++-
 src/modules/uid_uri_db/checks.c                    |   21 +-
 src/modules/uid_uri_db/checks.h                    |   17 +-
 src/modules/uid_uri_db/uid_uri_db_mod.c            |  198 ++--
 src/modules/uid_uri_db/uid_uri_db_mod.h            |   17 +-
 src/modules/xmlrpc/xmlrpc.c                        |    8 +-
 utils/kamctl/kamctl                                |   26 +
 utils/kamctl/kamctl.sqlbase                        |    5 +-
 utils/kamctl/kamdbctl.pgsql                        |    4 +-
 136 files changed, 3664 insertions(+), 2057 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4fa1ff6..4c7f782 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,714 @@
+===================== 2017-10-25 Version 5.0.4 Released =====================
+
+===================== Changes Since Version 5.0.3 ===========================
+
+commit 6f6d0fb03ea80bfad049e13743c95adccdca2235
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 25 14:58:42 2017 +0200
+
+    Makefile.defs: version set to 5.0.4
+
+commit d191ff8712a775cf2f6c48b1134890fd636ae969
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 25 14:38:32 2017 +0200
+
+    pkg: rpm - version set to 5.0.4 in specs
+
+commit 10a6dec6a0278bfc4161651f28edf9402cc6b1d4
+Author: Kamailio Dev <kamailio.dev at kamailio.org>
+Date:   Wed Oct 25 12:16:21 2017 +0200
+
+    modules: readme files regenerated - modules ... [skip ci]
+
+commit 81c7a69b0be87c39365c405f0e3f945b9d99a199
+Merge: 49d4af496 055ad1cb6
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 25 12:06:34 2017 +0200
+
+    Merge pull request #1281 from oyvindkolbu/sipcapture-backport
+    
+    Sipcapture backport
+
+commit 055ad1cb61f61d9996f0018727adfcb92fa98912
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Thu Jul 27 19:03:42 2017 +0300
+
+    sipcapture: documentation typo
+    
+    (cherry picked from commit 6452e86bcc3e4b927a2e511f3c7a9f464a69ac66)
+
+commit a3d53389992f2ca7798a530d24677206b8be668b
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Aug 13 11:07:42 2017 +0200
+
+    sipcapture: safety checks for values inside w_float2int()
+    
+    (cherry picked from commit 97d8ebc966aba71efb3a964e71b00736db51401b)
+
+commit 5274a0f9e5a5b74bbc37a6d74504b517d9dbfebe
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Mon Jul 31 13:08:58 2017 +0300
+
+    sipcapture: keep hep buffer unmodified while getting PV $hep(NNN)
+    
+    - addition to GH PR #1191
+    
+    (cherry picked from commit 2140d0141b5a7551ebbd072d801ce2339020dac0)
+
+commit f909250081f06c5b9dfd96792cc7960ff00c9f32
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Fri Jul 28 10:51:38 2017 +0300
+
+    sipcapture: free allocated process memory before return
+    
+    (cherry picked from commit ecf1ad77a2b9f69d5ae4f68fdc71cb1b10ebe729)
+
+commit 1c944f3fb1d67dbeb97879d3177171af8d8aecd7
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Fri Jul 28 10:51:38 2017 +0300
+
+    sipcapture: fix custom field variable naming
+    
+    (cherry picked from commit c8a804f5e3c3b12b64871d3989a87d79d8627afe)
+
+commit 1ecac0c9eb4c328c9b69ae048817e1b13813b134
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Thu Jul 27 22:43:04 2017 +0300
+
+    sipcapture: add missing or invalid byte order conversion
+    
+    (cherry picked from commit dac238ac3fdf2d0f47d6915508160b8160e9ab11)
+
+commit 97b5af5d5ac874c848f698136645dd1b92d0030a
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Thu Jul 27 22:37:03 2017 +0300
+
+    sipcapture: remove excess byte order conversion
+    
+    - buffer pointer `tmp` in hepv3_get_chunk() was assigned to hg->time_(µ)sec
+    - therefore everytime route script calls pseudovariables, part of original
+      `buf` was byte converted
+    
+    (cherry picked from commit 6e43bf84a2afc4e83ce33b7a416d7b81f7dd5658)
+
+commit 1e5eb8bb8ae5fe4f2a8e8940462bdd67ea760d43
+Author: Mikko Lehto <mslehto at iki.fi>
+Date:   Tue Jul 25 15:53:52 2017 +0300
+
+    modules/sipcapture: improve nonsip_hook documentation
+    
+    (cherry picked from commit 2f872dcc684a345cff09a437ae4a3767613b5529)
+
+commit 49d4af49682ea189321875c7132b3987d55a5519
+Author: Victor Seva <linuxmaniac at torreviejawireless.org>
+Date:   Wed Oct 25 10:49:57 2017 +0200
+
+    pkg/kamailio/deb: set version to 5.0.4 [skip ci]
+
+commit 3ffbd3796cc8507480ccb666e724725c06b901ca
+Author: Bastian Triller <btriller at broadsoft.com>
+Date:   Sun Apr 16 13:36:44 2017 +0200
+
+    sipcapture: fix HEP3 capture-id >= 2^16
+    
+    (cherry picked from commit dbd57c3eac30e1de54d98eb2ba8f608a17f7adbf)
+
+commit 14560cbba998cbb5904ce279119afe4590d9660d
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 25 10:17:12 2017 +0200
+
+    dialog: safety check for handling http replies in cseq update code
+    
+    - reported by GH #1277
+    
+    (cherry picked from commit ba7f663a0f1da799fc7a8be9b86039af2862f287)
+
+commit 5cb020ac9ed53f8520b9070a1945329abad08029
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 25 10:16:43 2017 +0200
+
+    core: parser - typedef'ed msg_start struct to msg_start_t
+    
+    (cherry picked from commit a21ea97800c7d7d3b082a9b1d57887e125d83d68)
+
+commit bbe47d4a0c43008dfa1c009e2061d90ea5556d26
+Author: Kamailio Dev <kamailio.dev at kamailio.org>
+Date:   Tue Oct 24 12:16:35 2017 +0200
+
+    modules: readme files regenerated - modules ... [skip ci]
+
+commit 5d41da20a121370ec33155fe92ac94a31af8c27f
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Oct 23 10:33:28 2017 +0200
+
+    pua_dialoginfo: removed svn ids, history, done indentation
+    
+    (cherry picked from commit 904e7435cc4206a9058602b12ba23a1d733674db)
+
+commit e23e875be66d4f42d18f495b5fc86e3e6954612f
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Oct 13 12:19:30 2017 +0200
+
+    core: fix bitwise test for priting socket details
+    
+    (cherry picked from commit 18b996262fb1c7bde94b494ce837754dc82c9e7e)
+
+commit b0b77e07e10e8bbf65c991c7dae8f33627c7cbe4
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Oct 13 12:18:32 2017 +0200
+
+    core: fix for bitwise test in core rpc command
+    
+    (cherry picked from commit f662a62519f99e046caf03063147104af22ec3c3)
+
+commit 09a0a36e8ce21ed0422fe8649c9cfa4a1d6ff5bc
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Thu Oct 12 09:34:59 2017 +0200
+
+    nat_traversal: added section ids in docs
+    
+    (cherry picked from commit 642dcef14271bc1376a54f8afe3a159d4e831ba6)
+
+commit f39462818a109481281ad06303d9c7ee6888f6ea
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 11 18:27:50 2017 +0200
+
+    db_postgres: documentation for lockset parameter
+    
+    (cherry picked from commit 7d27b682cc6259b1f6bcd21584b9f1d5bbfc9a36)
+
+commit e9106f999c9a5ec0d82bbf061ccb8ee89dff3987
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Oct 10 11:33:22 2017 +0200
+
+    dialog: documented optional sdp body for rpc bridge command
+    
+    (cherry picked from commit 59b58035bfe8e722a696db889d5295254092ae90)
+
+commit bdfbaaebdd4b4abd1f48d52e7179706c069e4b49
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Oct 9 18:27:28 2017 +0200
+
+    tm: updated some structs to typedefs
+    
+    (cherry picked from commit 4267e1ef7c9ffaac606964fb1b2d64334754b5d9)
+
+commit 813f0d868a076dae51a6018917dfc668cdecb163
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Oct 8 22:54:00 2017 +0200
+
+    misc_radius: end separator for examples in docs
+    
+    - added section ids
+    
+    (cherry picked from commit e49512ce80693aa2638d9fca940ded5a889cd2f9)
+
+commit 7cdfc2083292e4ee75845aabc03379701501c90d
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Oct 7 23:11:01 2017 +0200
+
+    mediaproxy: added section ids in docs
+    
+    (cherry picked from commit 5535a612445ea71a938e427e0ed7e3f7ea5d88cf)
+
+commit d5580542873e2a71101e625a96e855b732d5adae
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Oct 6 01:16:10 2017 +0200
+
+    maxfwd: fixed location for section id of maxfwd_process
+    
+    (cherry picked from commit 1f54f3d21a81badb4ba43c6adb88195bdd2c42f1)
+
+commit 66cdd82fa174eb89cced4bb90c011dc0a61091fb
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Thu Oct 5 17:34:13 2017 +0200
+
+    presence_conference: removed history and svn ids
+    
+    (cherry picked from commit e4cb62486644cdca753fe6c7768bd738ee19c8a5)
+
+commit 010e0fcce60adbf15f91e8049e0257c631a1fd03
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 4 13:42:30 2017 +0200
+
+    domainpolicy: removed empty rpc section
+    
+    - added several section ids
+    
+    (cherry picked from commit d94a65cbd0a86e1869037bbcfa261bc4219be908)
+
+commit 81712b43b3f1863f1a4d0fefada7cf1e6f16c3d7
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Oct 3 15:38:29 2017 +0200
+
+    cplc: added section ids in docs
+    
+    (cherry picked from commit f460607b5b0903c0937e5272c18d1c4fed38d42d)
+
+commit 26fa101b3019d113ef4eea870921d22cee75a478
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Oct 2 19:11:26 2017 +0200
+
+    cnxcc: added section ids in the docs
+    
+    (cherry picked from commit f5430eb0ad6134539d5eb4369e4c60bdb5fa4a63)
+
+commit 078a253702e7ab320d346f2ed5cad584ce5d365b
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Oct 2 09:50:56 2017 +0200
+
+    app_python: added section ids in docs
+    
+    (cherry picked from commit b24c3093feeb49bd6e9e508a6947fb3926c4ea8f)
+
+commit 8c9d1d8cb198dc377029db76b16be13d681bbb93
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Oct 1 08:21:55 2017 +0200
+
+    app_mono: added section ids
+    
+    (cherry picked from commit 9229cb397e3afebd5e25e67713e4df9b6d622192)
+
+commit a91e787ebbe39e6f608e77da929c9f44385d5052
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 30 09:23:34 2017 +0200
+
+    auth_radius: added section ids in docs
+    
+    (cherry picked from commit 563004ca54cb31d19e3bd9e30633c9f860070883)
+
+commit 24048d5cc742f9421a1ea8962190e760269df798
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 29 13:11:50 2017 +0200
+
+    sqlops: keep string values zero-terminated inside db result structure
+    
+    (cherry picked from commit f90e785114c7dd738ca7ce7e70d72dd92cbd7136)
+
+commit f1921513187d432b67dd94df437f1ba07045e1bc
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 29 09:58:04 2017 +0200
+
+    kamctl: added db subcommand to mange records in version table
+    
+    (cherry picked from commit d3b7f0d390dd430d40a1d47112f076f4b21e3afe)
+
+commit 751aff9d26b910f0c9021d340831fe4a0101b476
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Sep 26 10:06:36 2017 +0200
+
+    auth: explicit listing of status codes for replies in docs of challenge functions
+    
+    (cherry picked from commit 4e2c3f2b41859767f13bef237b93ea7101f36d12)
+
+commit 1a096c81bf36f5de3f5f6632dd041a58f45069ff
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Sep 25 15:13:58 2017 +0200
+
+    dialog: adjusted debug messages when updating attributes
+    
+    (cherry picked from commit 47bfa060e6b182167c5d0b21cbaebf5b1c0bb8d2)
+
+commit ececbd9c1753b101e12e66ed86496b57d081fc54
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 23 09:30:08 2017 +0200
+
+    janssonrpcc: do not lock in mod destroy
+    
+    - all children are killed already and if lock was already set results in
+      a deadlock
+    
+    (cherry picked from commit 185db312ed91bba6c997a42a84c4da1e4ce2319f)
+
+commit 5ff6d3761a0722c5a8a18dfec3c856da5784b95f
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 23 09:29:10 2017 +0200
+
+    jsonrpcc: do not declare variables in header files
+    
+    - avoid declaration in each .c that includes the .h
+    
+    (cherry picked from commit 291649821f4d19790072ffaf9aefc41891a3551d)
+
+commit 2c509fdc77997c3a71add4d2b729e4211d99bf93
+Author: Alex Hermann <alex at hexla.nl>
+Date:   Fri Feb 24 14:23:57 2017 +0100
+
+    janssonrcp-c: Fix segfault in mod_destroy
+    
+    Check variable before dereferencing it.
+    
+    (cherry picked from commit 894e64ae69f485ee8b764092d255c65ab7740da7)
+
+commit 963594eaf13949a0c1e0c5e0221c8e0f27f5d566
+Author: Alex Hermann <alex at hexla.nl>
+Date:   Mon Feb 20 18:30:27 2017 +0100
+
+    json: Add fixup_free function for json_get_field
+    
+    (cherry picked from commit 305dbe7197f87d8e14bb75f14553852c8e3c9b8c)
+
+commit fe960c65c028bccd348140a4d02f23eec4ce0cad
+Author: Alex Hermann <alex at speakup.nl>
+Date:   Tue Oct 6 12:35:38 2015 +0200
+
+    cfgutils: Remove debug statements in sleep functions
+    
+    Too much noise when debug logging is on
+    
+    (cherry picked from commit efe9d554a912edb0ffc5ae8e7176adc5bcc44a5e)
+
+commit 635ff24db1e2f3439d15b9a0f3e3156f0d7026ee
+Author: Alex Hermann <alex at hexla.nl>
+Date:   Mon Feb 20 18:26:01 2017 +0100
+
+    cfgutils: Properly handle 'exit' when from route_if_exists()
+    
+    exit is supposed to exit the routing script. route_if_exists() wasn't
+    handling the exit, so script would continue to run after 'exit'.
+    
+    (cherry picked from commit d6a374d707f23afddfc007edfeae40b01836b3c0)
+
+commit 43efb087f618be3bba5fa4da15041fd6f9fc9d34
+Author: Alex Hermann <alex at hexla.nl>
+Date:   Mon Jan 2 19:22:03 2017 +0100
+
+    cfgutils: Allow pv in check_route_exists() and route_if_exists()
+    
+    These functions are somewhat useless if a dynamic parameter is not allowed.
+    
+    (cherry picked from commit 92e404b3676aa57bca531096cddc14d58e06c789)
+
+commit 85ad34b0f5afd7fd4c560efafb940fb7a341837b
+Author: Alex Hermann <alex at hexla.nl>
+Date:   Mon Jan 2 19:21:19 2017 +0100
+
+    cfgutils: Add fixup_free functions to (u)sleep functions
+    
+    (cherry picked from commit 194d1bd1d1b86a92ee51bb32d88c105eb6130910)
+
+commit 14bb444e8c106bf0d8ac6009ff6c47b373621775
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Sep 19 11:45:46 2017 +0200
+
+    core: tcp - increased the size for flags field in connection struct
+    
+    (cherry picked from commit 65ed9b065c497266a4ecd9760e7c168c69b4c6e8)
+
+commit 0edd5072b35809a7529d413c45372f338558479d
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 16 23:09:44 2017 +0200
+
+    msrp: updates to log macros
+    
+    (cherry picked from commit 0e38dabe44e475e8054d3905e553637977dd26e1)
+
+commit c7350a733d0c000f67192943be3d925e39905414
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 16 23:05:33 2017 +0200
+
+    rtpproxy: removed function name from log messages
+    
+    (cherry picked from commit 574f2d4d40fbdecf379292d65ad0218e8ecaab10)
+
+commit 5eda789b9885ca27afb29ab6145dcc53c4a137be
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Sep 13 11:43:04 2017 +0200
+
+    dialog: small updates to docs
+    
+    (cherry picked from commit e23c50aed89be717c0bc76e6fbfc902cf3deacb6)
+
+commit 0dd00c1aedc14e2b5509b84468c277e69056493b
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Sep 12 16:10:10 2017 +0200
+
+    seas: added guards to several include files
+    
+    - bits of formating and removal of inline history
+    
+    (cherry picked from commit e04716f4f9325fa5290555823132455ea599daac)
+
+commit 9800aba65146b72623bb512049300d1beb8c8ec4
+Author: Huseyin Dikme <hueseyin.dikme at 1und1.de>
+Date:   Tue Sep 12 15:37:17 2017 +0200
+
+    carrierroute: warning for the same carrier/domain having routes with only 0 probability
+    
+    - While starting kamailio or reloading the routes, if the same carrier/domain pairs do not have
+      any route with a probability other than 0 (zero) then an error log will be printed on the screen.
+      Besides, the log "invalid dice_max value" in the cr_func.c has been made more clear.
+    
+    (cherry picked from commit 9741bee7af8136b35af8e6279e530aa0ad54f574)
+
+commit 50579308d7830388e379ec039167f9e559b1dff1
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Sep 11 23:16:39 2017 +0200
+
+    uid_auth_db: removed history, updated log macros
+    
+    (cherry picked from commit 6eb9f46bc413b72f41423673f1ad1083775760c4)
+
+commit 83d4e1826e8f3f0876ccc6be0df4abf3edee4a23
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Sep 11 23:15:29 2017 +0200
+
+    uid_uri_db: fixed log message
+    
+    (cherry picked from commit 6fa1e72a8e8b74876432afe47830d2ee22b1caf6)
+
+commit dc37a5e439a23132db79a46d70ba17cfcbee6d3d
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Sep 10 11:34:13 2017 +0200
+
+    uid_uri_db: removed history, updated application name
+    
+    - adjustments to log messages and indentation
+    
+    (cherry picked from commit f5a329ff0ce0e433c5ff8a7bfdc815819dcf1022)
+
+commit 6c2630274461d33ac41217239a7436a89dfeffaa
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Sep 10 10:25:18 2017 +0200
+
+    jsonrpcc: more debug messages if init fails
+    
+    - coherent indentation and whitespacing
+    
+    (cherry picked from commit f60a3cfa3070a4782038dcf9f2169562220cc396)
+
+commit 270c8fce6414b8401a5d8181caa4fd50f73677f5
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Sep 9 23:12:43 2017 +0200
+
+    uid_gflags: fixed rpc commands doc strings
+    
+    - converted log macros
+    - coherent indentation and whitespacing
+    
+    (cherry picked from commit 0281dc351ca4cde8d3343164cc3091d02808f3cb)
+
+commit 42d7fa47bdb9447d3522b3d233bc93b7f65c4e8f
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Thu Sep 7 15:29:09 2017 +0200
+
+    snmpstats: removed wrong function name from log message
+    
+    (cherry picked from commit e27ba180ab9801e6b32bfb31aad1c02d28f7e559)
+
+commit 335eb8eed8009505fca8ee7859c1e452c137ce30
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Tue Sep 5 07:55:09 2017 +0200
+
+    presence_xml: small adjustments, added section ids
+    
+    (cherry picked from commit 6fbaac0d9383da5fe30ea9d2e9671ab3dffd9694)
+
+commit 92a0bccdc1ed5c1e00bced6a7cc996b21a9e3e60
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Oct 23 14:35:43 2017 +0200
+
+    jsonrpcs: use select on udp socket to work on non-blocking mode
+    
+    (cherry picked from commit b57c83c936bf729bda3174803cacbf006552f2dc)
+
+commit 114acb1d4c94846e1371e476237fc62e57f90bb0
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Jul 14 08:21:40 2017 +0200
+
+    pua_dialoginfo: fixed condition in mod init checking avp names
+    
+    (cherry picked from commit 666c9d1fcdde00dbdd2e87ff797e554af6d72b5c)
+
+commit 64a2bec28f1182b30bd3404f6bba9b2f4e868258
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sun Oct 22 09:49:22 2017 +0200
+
+    jsonrpcs: use same socket for dgram transport
+    
+    (cherry picked from commit 9c3883a7856d6fb12d103baf3f784107a7c3914c)
+
+commit 8a01ab81074313efa5daa4cc87d571f67f43178a
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Oct 21 12:19:41 2017 +0200
+
+    jsonrpcs: init fifo stream via mod init callback
+    
+    (cherry picked from commit 17697e4bcabcec62d4393c6ae60fabec7d1c8e98)
+
+commit 04c774d86a62387a6f297b29040220e7dcf597f1
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Oct 21 12:10:29 2017 +0200
+
+    jsonrpcs: init dgram sockets via mod init callback
+    
+    (cherry picked from commit 70fa5b79e413e162427f5a8ffad3357252c517e2)
+
+commit 6702903ee846590fd0759f71fa741af95150677d
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Sat Oct 21 11:47:35 2017 +0200
+
+    jsonrpcs: set rank PROC_RPC for fifo and dgram processes
+    
+    (cherry picked from commit a2b862a74c77bc71238d9b8c9ef19ddb629c75ce)
+
+commit 0b02a2f0cfecdb72e020d3d6bdab4ac6e97ecd27
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Oct 20 11:23:06 2017 +0200
+
+    jsonrpcs: updated the name of module in description of extra procs
+    
+    (cherry picked from commit d4f11b6ffc459faf5c6577cc3374420c1469baeb)
+
+commit 60dc10a3948bdc51d1c9298e8a174a0af066557a
+Author: Victor Seva <linuxmaniac at torreviejawireless.org>
+Date:   Thu Oct 19 10:36:27 2017 +0200
+
+    pkg/kamailio/deb: fix kamailio-berkeley-modules dependence
+
+commit 1b86bf2faa09d3a9ef3684f42582a83267635668
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Thu Oct 19 08:58:59 2017 +0200
+
+    jsonrpcs: proper propagation of rpc fault code and message
+    
+    (cherry picked from commit 9364b1691412ec1d3d59ca8a801613470e079c1d)
+
+commit 71876926dd7add9f7423bda1aa4489933d8174ac
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 18 18:41:01 2017 +0200
+
+    xmlrpc: fix handling the optional param spec on no more params
+    
+    (cherry picked from commit 9483efe6af26a2a8b08ee132e8ed2afe25e71cbc)
+
+commit dc9efda1bb416874fd3fe4320326d067fa9fb0c0
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Oct 18 18:36:26 2017 +0200
+
+    jsonrpcs: fix handling the optional param spec on no more params
+    
+    (cherry picked from commit 87d71619e7896d3d333bb6c15d4c00616add71a6)
+
+commit 9e3096e16ac233e1667110904e1d944753d53c7a
+Author: Victor Seva <linuxmaniac at torreviejawireless.org>
+Date:   Thu Oct 5 13:17:18 2017 +0200
+
+    core: add safety check to rval_get_tmp_str()
+    
+    See #1263
+    
+    (cherry picked from commit c6e921e45f1257913848110189eab82a34aa2f8b)
+
+commit eabe0f84b46840d1164c83791c998021f9c42bd1
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 29 18:58:49 2017 +0200
+
+    htable: do not fork clean timer if no auto-expire is defined
+    
+    - match the same condition used in mod init to declare the extra process
+    - reported by GH #1237
+    
+    (cherry picked from commit dc15a8cd44fa17bb5ad12bf418c78af9f6e071e1)
+
+commit 445adb0482a95f47dce518ecb403cbb1aa7cd1ac
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 29 18:21:53 2017 +0200
+
+    kamctl: do not set privileges on drouting tables without id for pgsql
+    
+    - reported by #1256
+    
+    (cherry picked from commit 711917153a4be290fd7e405c2c5578fe42ef9aff)
+
+commit a62698612bccaaa2defd640feb3552f6d916b279
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 29 09:28:08 2017 +0200
+
+    domain: proper output format for rpc dump command
+    
+    - arrays have to be used to list domains and attributes
+    
+    (cherry picked from commit 6d4367e4ab1e7e2d38b94b942f2383e3878a1e7a)
+
+commit 9312498fad89297bdd37f1a3bdd32df5b6970358
+Author: Federico Cabiddu <federico.cabiddu at gmail.com>
+Date:   Tue Sep 26 15:32:20 2017 +0200
+
+    http_async_client: null terminate the request id in the callback
+    
+    (cherry picked from commit b356c73494da7ef53447a5c7615bebeb8eb9a9e2)
+
+commit e37b0934ba3531e9d179fca360207a96b2b49bae
+Author: lazedo <luis.azedo at factorlusitano.com>
+Date:   Sat Sep 23 11:56:58 2017 +0100
+
+    timer: reset xavp using common function
+    (cherry picked from commit f083513f0139156e3b0f1ce68cb934b687d0a56d)
+
+commit 1ecc88431777f0013aa29cbcccc041168002dea5
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 15 09:27:07 2017 +0200
+
+    core: tcp_read_headers() safety checks for parsed pointer
+    
+    - reset if it is out of read buffer range and the state is H_SKIP_EMPTY
+    
+    (cherry picked from commit f47f42ac12ad111b3bad52aa2d495fbed5ef395d)
+
+commit fd96ab480515713e4a390376f38bc09aa28e93b4
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Fri Sep 15 09:00:18 2017 +0200
+
+    core: tcp_read_ws() - safety checks for very large advetised lenght
+    
+    - use unsigned for lenght to avoid going negative on large read values
+    
+    (cherry picked from commit 35ee3a4b0357820bf31b3aa68323dcb7df267e94)
+
+commit 6c749dea59d8f35b8a5303baba540edc2295cd92
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Sep 6 11:13:16 2017 +0200
+
+    tm: reset T_ASYNC_CONTINUE once t_continue() callback is executed
+    
+    - by having it still set, the reply field was not reset, causing to free
+      an invalid pointer when transaction was destroyed, reported by Vitaliy
+      Aleksandrov
+    - set reply of suspended request branch to FAKED_REPLY on continue,
+      the code was already set to 500 - make it coherent with the local
+      replied transactions
+    - reset cloned reply under lock for suspended reply branch and free it
+      later via backup pointer - safer if someone risks to access the
+      suspended reply branch (should happen now, just future proof)
+    
+    (cherry picked from commit b672d8ef63715cf816390a05ce7a441377c3e468)
+
+commit d5f89eb46c6d463d162dab0af1a7b56af513549c
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Wed Sep 6 09:09:13 2017 +0200
+
+    tm: more info in some log messages
+    
+    (cherry picked from commit 8599f6fca16367a3e2a0dd4a638c667459482cd5)
+
+commit 629d0dad29868926dc3ac8e60e15383ac681a7a2
+Author: Daniel-Constantin Mierla <miconda at gmail.com>
+Date:   Mon Sep 4 16:13:01 2017 +0200
+
+    pkg/obs: more details in the readme
+    
+    (cherry picked from commit 498e6a96fa101863170399e237cad66a8620a9e6)
+
+commit 0e201145cf9465c2752993867813ae8bff60336d
+Author: Sergey Safarov <s.safarov at gmail.com>
+Date:   Mon Sep 4 16:08:36 2017 +0200
+
+    pkg/kamailio/OBS: Added RPM packaging scripts for openSUSE  Build Service
+    
+    (cherry picked from commit 2406f79169aac6a94a4a8f26aa50dd6291d821ec)
+
+
 ===================== 2017-09-01 Version 5.0.3 Released =====================
 
 ===================== Changes Since Version 5.0.2 ===========================
diff --git a/pkg/kamailio/centos/6/kamailio.spec b/pkg/kamailio/centos/6/kamailio.spec
index b5f9f76..b345e4c 100644
--- a/pkg/kamailio/centos/6/kamailio.spec
+++ b/pkg/kamailio/centos/6/kamailio.spec
@@ -1,5 +1,5 @@
 %define name	kamailio
-%define ver	5.0.3
+%define ver	5.0.4
 %define rel	dev0.0%{dist}
 
 
diff --git a/pkg/kamailio/centos/7/kamailio.spec b/pkg/kamailio/centos/7/kamailio.spec
index b5aae37..a34446f 100644
--- a/pkg/kamailio/centos/7/kamailio.spec
+++ b/pkg/kamailio/centos/7/kamailio.spec
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver 5.0.3
+%define ver 5.0.4
 %define rel dev0.0%{dist}
 %bcond_with dnssec
 %bcond_with kazoo
diff --git a/pkg/kamailio/deb/debian/changelog b/pkg/kamailio/deb/debian/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/debian/changelog
+++ b/pkg/kamailio/deb/debian/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/debian/control b/pkg/kamailio/deb/debian/control
index 488c082..eb22c68 100644
--- a/pkg/kamailio/deb/debian/control
+++ b/pkg/kamailio/deb/debian/control
@@ -422,7 +422,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/jessie/changelog b/pkg/kamailio/deb/jessie/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/jessie/changelog
+++ b/pkg/kamailio/deb/jessie/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/jessie/control b/pkg/kamailio/deb/jessie/control
index eb2e603..5c71aa4 100644
--- a/pkg/kamailio/deb/jessie/control
+++ b/pkg/kamailio/deb/jessie/control
@@ -420,7 +420,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/precise/changelog b/pkg/kamailio/deb/precise/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/precise/changelog
+++ b/pkg/kamailio/deb/precise/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/precise/control b/pkg/kamailio/deb/precise/control
index 070856e..afb94c8 100644
--- a/pkg/kamailio/deb/precise/control
+++ b/pkg/kamailio/deb/precise/control
@@ -416,7 +416,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/sid/changelog b/pkg/kamailio/deb/sid/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/sid/changelog
+++ b/pkg/kamailio/deb/sid/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/sid/control b/pkg/kamailio/deb/sid/control
index e9e8231..2747c39 100644
--- a/pkg/kamailio/deb/sid/control
+++ b/pkg/kamailio/deb/sid/control
@@ -420,7 +420,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/stretch/changelog b/pkg/kamailio/deb/stretch/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/stretch/changelog
+++ b/pkg/kamailio/deb/stretch/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/stretch/control b/pkg/kamailio/deb/stretch/control
index e9e8231..2747c39 100644
--- a/pkg/kamailio/deb/stretch/control
+++ b/pkg/kamailio/deb/stretch/control
@@ -420,7 +420,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/trusty/changelog b/pkg/kamailio/deb/trusty/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/trusty/changelog
+++ b/pkg/kamailio/deb/trusty/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/trusty/control b/pkg/kamailio/deb/trusty/control
index d63ab59..4e375f6 100644
--- a/pkg/kamailio/deb/trusty/control
+++ b/pkg/kamailio/deb/trusty/control
@@ -418,7 +418,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/wheezy/changelog b/pkg/kamailio/deb/wheezy/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/wheezy/changelog
+++ b/pkg/kamailio/deb/wheezy/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/wheezy/control b/pkg/kamailio/deb/wheezy/control
index 070856e..afb94c8 100644
--- a/pkg/kamailio/deb/wheezy/control
+++ b/pkg/kamailio/deb/wheezy/control
@@ -416,7 +416,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/deb/xenial/changelog b/pkg/kamailio/deb/xenial/changelog
index 08f8f4a..3d61d4d 100644
--- a/pkg/kamailio/deb/xenial/changelog
+++ b/pkg/kamailio/deb/xenial/changelog
@@ -1,3 +1,9 @@
+kamailio (5.0.4) unstable; urgency=medium
+
+  * version set to 5.0.4
+
+ -- Victor Seva <vseva at debian.org>  Wed, 25 Oct 2017 10:49:00 +0200
+
 kamailio (5.0.3) unstable; urgency=medium
 
   * version set to 5.0.3
diff --git a/pkg/kamailio/deb/xenial/control b/pkg/kamailio/deb/xenial/control
index 0a03ef7..2e931f4 100644
--- a/pkg/kamailio/deb/xenial/control
+++ b/pkg/kamailio/deb/xenial/control
@@ -421,7 +421,7 @@ Package: kamailio-berkeley-modules
 Architecture: linux-any
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: db5.1-util,
+Depends: db-util (>= 4.6.19),
          kamailio (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff --git a/pkg/kamailio/fedora/17/kamailio.spec b/pkg/kamailio/fedora/17/kamailio.spec
index 1c29158..b8bcf62 100644
--- a/pkg/kamailio/fedora/17/kamailio.spec
+++ b/pkg/kamailio/fedora/17/kamailio.spec
@@ -1,5 +1,5 @@
 %define name	kamailio
-%define ver	5.0.3
+%define ver	5.0.4
 %define rel	dev7.2%{dist}
 
 
diff --git a/pkg/kamailio/obs/README b/pkg/kamailio/obs/README
new file mode 100644
index 0000000..113f593
--- /dev/null
+++ b/pkg/kamailio/obs/README
@@ -0,0 +1,16 @@
+# RPM Specs For OpenSuse Build Service (OBS) #
+
+Here are the RPM packaging specs for openSUSE Build Service:
+
+  * https://build.opensuse.org/
+
+It builds RPM packages for following distributions:
+
+  * CentOS 6 and 7
+  * RHEL 6 and 7
+  * Fedora 25 adn 26
+  * openSUSE 42.2 and 42.3
+
+Kamailio's RPMs bulding projects for various versions can be found at:
+
+  * https://build.opensuse.org/project/subprojects/home:kamailio
diff --git a/pkg/kamailio/obs/kamailio.init b/pkg/kamailio/obs/kamailio.init
new file mode 100644
index 0000000..2cdae7a
--- /dev/null
+++ b/pkg/kamailio/obs/kamailio.init
@@ -0,0 +1,141 @@
+#!/bin/bash
+#
+# Startup script for Kamailio
+#
+# chkconfig: 345 85 15
+# description: Kamailio (OpenSER) - the Open Source SIP Server
+#
+# processname: kamailio
+# pidfile: /var/run/kamailio.pid
+# config: /etc/kamailio/kamailio.cfg
+#
+### BEGIN INIT INFO
+# Provides: kamailio
+# Required-Start: $local_fs $network
+# Short-Description: Kamailio (OpenSER) - the Open Source SIP Server
+# Description: Kamailio (former OpenSER) is an Open Source SIP Server released
+# 	under GPL, able to handle thousands of call setups per second.
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+KAM=/usr/sbin/kamailio
+KAMCFG=/etc/kamailio/kamailio.cfg
+PROG=kamailio
+HOMEDIR=/var/run/$PROG
+PID_FILE=/var/run/$PROG/kamailio.pid
+LOCK_FILE=/var/lock/subsys/kamailio
+RETVAL=0
+DEFAULTS=/etc/sysconfig/kamailio
+RUN_KAMAILIO=no
+
+
+# Do not start kamailio if fork=no is set in the config file
+# otherwise the boot process will just stop
+check_fork ()
+{
+    if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $KAMCFG; then
+        echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/kamailio debug instead"
+        exit 1
+    fi
+}
+
+check_kamailio_config ()
+{
+        # Check if kamailio configuration is valid before starting the server
+        out=$($KAM -c 2>&1 > /dev/null)
+        retcode=$?
+        if [ "$retcode" != '0' ]; then
+            echo "Not starting $DESC: invalid configuration file!"
+            echo -e "\n$out\n"
+            exit 1
+        fi
+}
+
+
+start() {
+	check_kamailio_config
+        if [ "$1" != "debug" ]; then
+            check_fork
+        fi
+	echo -n $"Starting $PROG: "
+	daemon $KAM $OPTIONS >/dev/null 2>/dev/null
+	RETVAL=$?
+	[ $RETVAL = 0 ] && touch $LOCK_FILE && success
+	echo
+	return $RETVAL
+}
+
+stop() {
+	echo -n $"Stopping $PROG: "
+	killproc $KAM
+	RETVAL=$?
+	echo
+	[ $RETVAL = 0 ] && rm -f $LOCK_FILE $PID_FILE
+}
+
+# Load startup options if available
+if [ -f $DEFAULTS ]; then
+   . $DEFAULTS || true
+fi
+
+if [ "$RUN_KAMAILIO" != "yes" ]; then
+    echo "Kamailio not yet configured. Edit /etc/default/kamailio first."
+    exit 0
+fi
+
+
+SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`))
+PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`))
+[ -z "$USER" ]  && USER=kamailio
+[ -z "$GROUP" ] && GROUP=kamailio
+[ $SHM_MEMORY -le 0 ] && SHM_MEMORY=32
+[ $PKG_MEMORY -le 0 ] && PKG_MEMORY=4
+
+if test "$DUMP_CORE" = "yes" ; then
+    # set proper ulimit
+    ulimit -c unlimited
+
+    # directory for the core dump files
+    COREDIR=/tmp
+    echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern
+fi
+
+# /var/run can be a tmpfs
+if [ ! -d $HOMEDIR ]; then
+    mkdir -p $HOMEDIR
+	chown ${USER}:${GROUP} $HOMEDIR
+fi
+
+OPTIONS="-P $PID_FILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP $EXTRA_OPTIONS"
+
+
+# See how we were called.
+case "$1" in
+	start|debug)
+		start
+		;;
+	stop)
+		stop
+		;;
+	status)
+		status $KAM
+		RETVAL=$?
+		;;
+	restart)
+		stop
+		start
+		;;
+	condrestart)
+		if [ -f $PID_FILE ] ; then
+			stop
+			start
+		fi
+		;;
+	*)
+		echo $"Usage: $PROG {start|stop|restart|condrestart|status|debug|help}"
+		exit 1
+esac
+
+exit $RETVAL
diff --git a/pkg/kamailio/obs/kamailio.service b/pkg/kamailio/obs/kamailio.service
new file mode 100644
index 0000000..e33cc33
--- /dev/null
+++ b/pkg/kamailio/obs/kamailio.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Kamailio (OpenSER) - the Open Source SIP Server
+After=network.target
+
+[Service]
+Type=simple
+User=kamailio
+Group=daemon
+Environment='CFGFILE=/etc/kamailio/kamailio.cfg'
+Environment='SHM_MEMORY=64'
+Environment='PKG_MEMORY=4'
+EnvironmentFile=/etc/sysconfig/kamailio
+ExecStart=/usr/sbin/kamailio -DD -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/pkg/kamailio/centos/7/kamailio.spec b/pkg/kamailio/obs/kamailio.spec
similarity index 78%
copy from pkg/kamailio/centos/7/kamailio.spec
copy to pkg/kamailio/obs/kamailio.spec
index b5aae37..6e1995f 100644
--- a/pkg/kamailio/centos/7/kamailio.spec
+++ b/pkg/kamailio/obs/kamailio.spec
@@ -1,10 +1,142 @@
 %define name    kamailio
-%define ver 5.0.3
+%define ver 5.0.4
 %define rel dev0.0%{dist}
+
+%if 0%{?fedora} == 24
+%define dist_name fedora
+%define dist_version %{?fedora}
+%bcond_without cnxcc
+%bcond_with dnssec
+%bcond_without geoip
+%bcond_without http_async_client
+%bcond_without jansson
+%bcond_without json
+%bcond_without kazoo
+%bcond_without memcached
+%bcond_without redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
+
+%if 0%{?fedora} == 25
+%define dist_name fedora
+%define dist_version %{?fedora}
+%bcond_without cnxcc
 %bcond_with dnssec
+%bcond_without geoip
+%bcond_without http_async_client
+%bcond_without jansson
+%bcond_without json
+%bcond_without kazoo
+%bcond_without memcached
+%bcond_without redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
+
+%if 0%{?fedora} == 26
+%define dist_name fedora
+%define dist_version %{?fedora}
+%bcond_without cnxcc
+%bcond_with dnssec
+%bcond_without geoip
+%bcond_without http_async_client
+%bcond_without jansson
+%bcond_without json
+%bcond_without kazoo
+%bcond_without memcached
+%bcond_without redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
+
+%if 0%{?centos_version} == 600
+%define dist_name centos
+%define dist_version %{?centos}
+%bcond_with cnxcc
+%bcond_without dnssec
+%bcond_without geoip
+%bcond_with http_async_client
+%bcond_with jansson
+%bcond_with json
 %bcond_with kazoo
+%bcond_without memcached
+%bcond_with redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
 
+%if 0%{?centos_version} == 700
+%define dist_name centos
+%define dist_version %{?centos}
+%bcond_without cnxcc
+%bcond_with dnssec
+%bcond_without geoip
+%bcond_without http_async_client
+%bcond_without jansson
+%bcond_without json
+%bcond_without kazoo
+%bcond_without memcached
+%bcond_without redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
 
+%if 0%{?leap_version}
+%define dist_name suse
+%define dist_version %{?suse_version}
+%bcond_without cnxcc
+%bcond_with dnssec
+%bcond_without geoip
+%bcond_without http_async_client
+%bcond_without jansson
+%bcond_without json
+%bcond_with kazoo
+%bcond_without memcached
+%bcond_without redis
+%bcond_without sctp
+%bcond_without websocket
+%bcond_without xmlrpc
+%endif
+
+%if 0%{?rhel_version} == 600
+%define dist_name rhel
+%define dist_version %{?rhel}
+%bcond_with cnxcc
+%bcond_without dnssec
+%bcond_with geoip
+%bcond_with http_async_client
+%bcond_with jansson
+%bcond_with json
+%bcond_with kazoo
+%bcond_with memcached
+%bcond_with redis
+%bcond_with sctp
+%bcond_with websocket
+%bcond_without xmlrpc
+%endif
+
+%if 0%{?rhel_version} == 700
+%define dist_name rhel
+%define dist_version %{?rhel}
+%bcond_with cnxcc
+%bcond_with dnssec
+%bcond_with geoip
+%bcond_with http_async_client
+%bcond_with jansson
+%bcond_with json
+%bcond_with kazoo
+%bcond_with memcached
+%bcond_without redis
+%bcond_with sctp
+%bcond_with websocket
+%bcond_without xmlrpc
+%endif
 
 Summary:    Kamailio (former OpenSER) - the Open Source SIP Server
 Name:       %name
@@ -23,9 +155,7 @@ Conflicts:  kamailio-dialplan < %ver, kamailio-dnssec < %ver
 Conflicts:  kamailio-geoip < %ver, kamailio-gzcompress < %ver
 Conflicts:  kamailio-ims < %ver, kamailio-java < %ver, kamailio-json < %ver
 Conflicts:  kamailio-lcr < %ver, kamailio-ldap < %ver, kamailio-lua < %ver
-%if %{with kazoo}
 Conflicts:  kamailio-kazoo < %ver
-%endif
 Conflicts:  kamailio-memcached < %ver, kamailio-mysql < %ver
 Conflicts:  kamailio-outbound < %ver, kamailio-perl < %ver
 Conflicts:  kamailio-postgresql < %ver, kamailio-presence < %ver
@@ -38,7 +168,10 @@ Conflicts:  kamailio-utils < %ver, kamailio-websocket < %ver
 Conflicts:  kamailio-xhttp-pi < %ver, kamailio-xmlops < %ver
 Conflicts:  kamailio-xmlrpc < %ver, kamailio-xmpp < %ver
 Conflicts:  kamailio-uuid < %ver
-BuildRequires:  bison, flex, gcc, make, redhat-rpm-config
+BuildRequires:  bison, flex
+%if 0%{?leap_version}
+BuildRequires:  systemd-mini, shadow
+%endif
 
 %description
 Kamailio (former OpenSER) is an Open Source SIP Server released under GPL, able
@@ -54,7 +187,7 @@ like Asterisk™, FreeSWITCH™ or SEMS.
 
 
 %package    auth-ephemeral
-Summary:    Functions for authentication using ephemeral credentials.
+Summary:    Functions for authentication using ephemeral credentials
 Group:      System Environment/Daemons
 Requires:   openssl, kamailio = %ver
 BuildRequires:  openssl-devel
@@ -64,7 +197,7 @@ Functions for authentication using ephemeral credentials.
 
 
 %package    auth-xkeys
-Summary:    Functions for authentication using shared keys.
+Summary:    Functions for authentication using shared keys
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -73,17 +206,23 @@ Functions for authentication using shared keys.
 
 
 %package    bdb
-Summary:    Berkeley database connectivity for Kamailio.
+Summary:    Berkeley database connectivity for Kamailio
 Group:      System Environment/Daemons
-Requires:   db4, kamailio = %ver
+Requires:   kamailio = %ver
+%if 0%{?leap_version}
+Requires:   libdb-4_8
+BuildRequires:  libdb-4_8-devel
+%else
+Requires:   db4
 BuildRequires:  db4-devel
+%endif
 
 %description    bdb
 Berkeley database connectivity for Kamailio.
 
 
 %package    carrierroute
-Summary:    The carrierroute module for Kamailio.
+Summary:    The carrierroute module for Kamailio
 Group:      System Environment/Daemons
 Requires:   libconfuse, kamailio = %ver
 BuildRequires:  libconfuse-devel
@@ -93,7 +232,7 @@ The carrierroute module for Kamailio.
 
 
 %package    cfgt
-Summary:    Unit test config file execution tracing module for Kamailio.
+Summary:    Unit test config file execution tracing module for Kamailio
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -101,18 +240,20 @@ Requires:   kamailio = %ver
 The unit test config file execution tracing module for Kamailio. 
 
 
+%if %{with cnxcc}
 %package    cnxcc
-Summary:    Module which provides a mechanism to limit call duration based on credit information parameters for Kamailio.
+Summary:    Module provides a mechanism to limit call duration
 Group:      System Environment/Daemons
 Requires:   libevent, hiredis, kamailio = %ver
 BuildRequires:  libevent-devel, hiredis-devel
 
 %description    cnxcc
 Module which provides a mechanism to limit call duration based on credit information parameters for Kamailio.
+%endif
 
 
 %package    cpl
-Summary:    CPL (Call Processing Language) interpreter for Kamailio.
+Summary:    CPL (Call Processing Language) interpreter for Kamailio
 Group:      System Environment/Daemons
 Requires:   libxml2, kamailio = %ver
 BuildRequires:  libxml2-devel
@@ -122,7 +263,7 @@ CPL (Call Processing Language) interpreter for Kamailio.
 
 
 %package    crypto
-Summary:    Module to support cryptographic extensions for use in the Kamailio configuration.
+Summary:    Module to support cryptographic extensions for use in the Kamailio configuration
 Group:      System Environment/Daemons
 Requires:   libcrypto
 
@@ -131,7 +272,7 @@ This module provides various cryptography tools for use in Kamailio configuratio
 
 
 %package    dialplan
-Summary:    String translations based on rules for Kamailio.
+Summary:    String translations based on rules for Kamailio
 Group:      System Environment/Daemons
 Requires:   pcre, kamailio = %ver
 BuildRequires:  pcre-devel
@@ -141,17 +282,17 @@ String translations based on rules for Kamailio.
 
 
 %package    dmq_userloc
-Summary:    User location (usrloc) records replication between multiple servers via DMQ module for Kamailio.
+Summary:    User location records replication between multiple servers
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
 %description    dmq_userloc
-User location (usrloc) records replication between multiple servers via DMQ module.
+User location (usrloc) records replication between multiple servers via DMQ module for Kamailio.
 
 
 %if %{with dnssec}
 %package    dnssec
-Summary:    DNSSEC support for Kamailio.
+Summary:    DNSSEC support for Kamailio
 Group:      System Environment/Daemons
 Requires:   dnssec-tools-libs, kamailio = %ver
 BuildRequires:  dnssec-tools-libs-devel
@@ -161,18 +302,20 @@ DNSSEC support for Kamailio.
 %endif
 
 
+%if %{with geoip}
 %package    geoip
-Summary:    MaxMind GeoIP support for Kamailio.
+Summary:    MaxMind GeoIP support for Kamailio
 Group:      System Environment/Daemons
 Requires:   GeoIP, kamailio = %ver
 BuildRequires:  GeoIP-devel
 
 %description    geoip
 MaxMind GeoIP support for Kamailio.
+%endif
 
 
 %package    gzcompress
-Summary:    Compressed body (SIP and HTTP) handling for kamailio.
+Summary:    Compressed body (SIP and HTTP) handling for kamailio
 Group:      System Environment/Daemons
 Requires:   zlib, kamailio = %ver
 BuildRequires:  zlib-devel
@@ -180,17 +323,20 @@ BuildRequires:  zlib-devel
 %description    gzcompress
 Compressed body (SIP and HTTP) handling for kamailio.
 
+
+%if %{with http_async_client}
 %package    http_async_client
-Summary:    Async HTTP client module for Kamailio.
+Summary:    Async HTTP client module for Kamailio
 Group:      System Environment/Daemons
 Requires:   libcurl, libevent, kamailio = %ver
 BuildRequires: libcurl-devel, libevent-devel
 
 %description   http_async_client
 This module implements protocol functions that use the libcurl to communicate with HTTP servers in asyncronous way.
+%endif
 
 %package    http_client
-Summary:    HTTP client module for Kamailio.
+Summary:    HTTP client module for Kamailio
 Group:      System Environment/Daemons
 Requires:   libcrypto
 
@@ -199,7 +345,7 @@ This module implements protocol functions that use the libcurl to communicate wi
 
 
 %package    ims
-Summary:    IMS modules and extensions module for Kamailio.
+Summary:    IMS modules and extensions module for Kamailio
 Group:      System Environment/Daemons
 Requires:   libxml2, kamailio = %ver
 BuildRequires:  libxml2-devel
@@ -207,32 +353,50 @@ BuildRequires:  libxml2-devel
 %description    ims
 IMS modules and extensions module for Kamailio.
 
+
+%if %{with jansson}
 %package    jansson
-Summary:    json string handling and RPC modules for Kamailio using JANSSON library.
+Summary:    JSON string handling and RPC modules for Kamailio using JANSSON library
 Group:      System Environment/Daemons
-Requires:   json-c, libevent, kamailio = %ver
+Requires:   libevent, kamailio = %ver
+%if 0%{?leap_version}
+Requires:   libjson-c2
+BuildRequires:  libjansson-devel
+%else
+Requires:   json-c
 BuildRequires:  jansson-devel
+%endif
 
 %description    jansson
-json string handling and RPC modules for Kamailio using JANSSON library.
+JSON string handling and RPC modules for Kamailio using JANSSON library.
+%endif
 
 
+%if %{with json}
 %package    json
-Summary:    json string handling and RPC modules for Kamailio.
+Summary:    JSON string handling and RPC modules for Kamailio
 Group:      System Environment/Daemons
-Requires:   json-c, libevent, kamailio = %ver
-BuildRequires:  json-c-devel, libevent-devel
+Requires:   libevent, kamailio = %ver
+BuildRequires:  libevent-devel
+%if 0%{?leap_version}
+Requires:   libjson-c2
+BuildRequires:  libjson-c-devel
+%else
+Requires:   json-c
+BuildRequires:  json-c-devel
+%endif
 
 %description    json
-json string handling and RPC modules for Kamailio.
+JSON string handling and RPC modules for Kamailio.
+%endif
 
 
 %if %{with kazoo}
 %package    kazoo
 Summary:    Kazoo middle layer connector support for Kamailio
 Group:      System Environment/Daemons
-Requires:   libuuid, kamailio = %ver
-BuildRequires:	rabbitmq-c-devel, json-c-devel, libuuid-devel
+Requires:   libuuid, librabbitmq, json-c, libevent, kamailio = %ver
+BuildRequires:  libuuid-devel, librabbitmq-devel, json-c-devel, libevent-devel
 
 %description    kazoo
 Kazoo module for Kamailio.
@@ -240,7 +404,7 @@ Kazoo module for Kamailio.
 
 
 %package    lcr
-Summary:    Least cost routing for Kamailio.
+Summary:    Least cost routing for Kamailio
 Group:      System Environment/Daemons
 Requires:   pcre, kamailio = %ver
 BuildRequires:  pcre-devel
@@ -250,17 +414,23 @@ Least cost routing for Kamailio.
 
 
 %package    ldap
-Summary:    LDAP search interface for Kamailio.
+Summary:    LDAP search interface for Kamailio
 Group:      System Environment/Daemons
-Requires:   openldap, kamailio = %ver
+Requires:   kamailio = %ver
+%if 0%{?leap_version}
+Requires:   openldap2 libsasl2
+BuildRequires:  openldap2-devel cyrus-sasl-devel
+%else
+Requires:   openldap
 BuildRequires:  openldap-devel
+%endif
 
 %description    ldap
 LDAP search interface for Kamailio.
 
 
 %package    log_custom
-Summary:    Logging to custom backends from Kamailio.
+Summary:    Logging to custom backends from Kamailio
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -268,28 +438,32 @@ Requires:   kamailio = %ver
 This module provides logging to custom systems, replacing the default core logging to syslog.
 
 
+%if %{with lua}
 %package    lua
-Summary:    Lua extensions for Kamailio.
+Summary:    Lua extensions for Kamailio
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 BuildRequires:  lua-devel
 
 %description    lua
 Lua extensions for Kamailio.
+%endif
 
 
+%if %{with memcached}
 %package    memcached
-Summary:    memcached configuration file support for Kamailio.
+Summary:    Memcached configuration file support for Kamailio
 Group:      System Environment/Daemons
 Requires:   libmemcached, kamailio = %ver
 BuildRequires:  libmemcached-devel
 
 %description    memcached
-memcached configuration file support for Kamailio.
+Memcached configuration file support for Kamailio.
+%endif
 
 
 %package    mysql
-Summary:    MySQL database connectivity for Kamailio.
+Summary:    MySQL database connectivity for Kamailio
 Group:      System Environment/Daemons
 Requires:   mysql-libs, kamailio = %ver
 BuildRequires:  mysql-devel zlib-devel
@@ -299,7 +473,7 @@ MySQL database connectivity for Kamailio.
 
 
 %package    outbound
-Summary:    Outbound (RFC 5626) support for Kamailio.
+Summary:    Outbound (RFC 5626) support for Kamailio
 Group:      System Environment/Daemons
 Requires:   openssl, kamailio = %ver
 BuildRequires:  openssl-devel
@@ -309,18 +483,20 @@ RFC 5626, "Managing Client-Initiated Connections in the Session Initiation
 Protocol (SIP)" support for Kamailio.
 
 
+%if %{with perl}
 %package    perl
-Summary:    Perl extensions and database driver for Kamailio.
+Summary:    Perl extensions and database driver for Kamailio
 Group:      System Environment/Daemons 
 Requires:   mod_perl, kamailio = %ver
 BuildRequires:  mod_perl-devel
 
 %description    perl
 Perl extensions and database driver for Kamailio.
+%endif
 
 
 %package    postgresql
-Summary:    PostgreSQL database connectivity for Kamailio.
+Summary:    PostgreSQL database connectivity for Kamailio
 Group:      System Environment/Daemons
 Requires:   postgresql-libs, kamailio = %ver
 BuildRequires:  postgresql-devel
@@ -330,7 +506,7 @@ PostgreSQL database connectivity for Kamailio.
 
 
 %package    presence
-Summary:    SIP Presence (and RLS, XCAP, etc) support for Kamailio.
+Summary:    SIP Presence (and RLS, XCAP, etc) support for Kamailio
 Group:      System Environment/Daemons
 Requires:   libxml2, libcurl, kamailio = %ver, kamailio-xmpp = %ver
 BuildRequires:  libxml2-devel, libcurl-devel
@@ -340,7 +516,7 @@ SIP Presence (and RLS, XCAP, etc) support for Kamailio.
 
 
 %package    python
-Summary:    Python extensions for Kamailio.
+Summary:    Python extensions for Kamailio
 Group:      System Environment/Daemons
 Requires:   python, kamailio = %ver
 BuildRequires:  python-devel
@@ -350,27 +526,35 @@ Python extensions for Kamailio.
 
 
 %package    radius
-Summary:    RADIUS modules for Kamailio.
+Summary:    RADIUS modules for Kamailio
 Group:      System Environment/Daemons
-Requires:   radiusclient-ng, kamailio = %ver
+Requires:   kamailio = %ver
+%if 0%{?fedora} || 0%{?leap_version}
+Requires:   freeradius-client
+BuildRequires:  freeradius-client-devel
+%else
+Requires:   radiusclient-ng
 BuildRequires:  radiusclient-ng-devel
+%endif
 
 %description    radius
 RADIUS modules for Kamailio.
 
 
+%if %{with redis}
 %package    redis
-Summary:    Redis configuration file support for Kamailio.
+Summary:    Redis configuration file support for Kamailio
 Group:      System Environment/Daemons
 Requires:   hiredis, kamailio = %ver
 BuildRequires:  hiredis-devel
 
 %description    redis
 Redis configuration file support for Kamailio.
+%endif
 
 
 %package    regex
-Summary:    PCRE mtaching operations for Kamailio.
+Summary:    PCRE mtaching operations for Kamailio
 Group:      System Environment/Daemons
 Requires:   pcre, kamailio = %ver
 BuildRequires:  pcre-devel
@@ -380,7 +564,7 @@ PCRE mtaching operations for Kamailio.
 
 
 %package    rtjson
-Summary:    SIP routing based on JSON specifications.
+Summary:    SIP routing based on JSON specifications
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -388,14 +572,16 @@ Requires:   kamailio = %ver
 SIP routing based on JSON specifications.
 
 
+%if %{with sctp}
 %package    sctp
-Summary:    SCTP transport for Kamailio.
+Summary:    SCTP transport for Kamailio
 Group:      System Environment/Daemons
 Requires:   lksctp-tools, kamailio = %ver
 BuildRequires:  lksctp-tools-devel
 
 %description    sctp
 SCTP transport for Kamailio.
+%endif
 
 
 %package    smsops
@@ -408,7 +594,7 @@ This module collects the Transformations for 3GPP-SMS.
 
 
 %package    snmpstats
-Summary:    SNMP management interface (scalar statistics) for Kamailio.
+Summary:    SNMP management interface (scalar statistics) for Kamailio
 Group:      System Environment/Daemons
 Requires:   net-snmp-libs, kamailio = %ver
 BuildRequires:  net-snmp-devel
@@ -418,7 +604,7 @@ SNMP management interface (scalar statistics) for Kamailio.
 
 
 %package    statsc
-Summary:    Statistics collecting module providing reports for Kamailio.
+Summary:    Statistics collecting module providing reports for Kamailio
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -427,7 +613,7 @@ This module provides a statistics collector engine.
 
 
 %package    statsd
-Summary:    Send commands to statsd server.
+Summary:    Send commands to statsd server
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -436,7 +622,7 @@ Send commands to statsd server.
 
 
 %package    sqlite
-Summary:    SQLite database connectivity for Kamailio.
+Summary:    SQLite database connectivity for Kamailio
 Group:      System Environment/Daemons
 Requires:   sqlite, kamailio = %ver
 BuildRequires:  sqlite-devel
@@ -446,7 +632,7 @@ SQLite database connectivity for Kamailio.
 
 
 %package    tls
-Summary:    TLS transport for Kamailio.
+Summary:    TLS transport for Kamailio
 Group:      System Environment/Daemons
 Requires:   openssl, kamailio = %ver
 BuildRequires:  openssl-devel
@@ -456,7 +642,7 @@ TLS transport for Kamailio.
 
 
 %package    tcpops
-Summary:    On demand and per socket control to the TCP options.
+Summary:    On demand and per socket control to the TCP options
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -465,7 +651,7 @@ On demand and per socket control to the TCP options.
 
 
 %package    topos
-Summary:    Topology stripping module for Kamailio.
+Summary:    Topology stripping module for Kamailio
 Group:      System Environment/Daemons
 Requires:   kamailio = %ver
 
@@ -474,17 +660,17 @@ This module offers topology hiding by stripping the routing headers that could s
 
 
 %package    unixodbc
-Summary:    unixODBC database connectivity for Kamailio.
+Summary:    UnixODBC database connectivity for Kamailio
 Group:      System Environment/Daemons
 Requires:   unixODBC, kamailio = %ver
 BuildRequires:  unixODBC-devel
 
 %description    unixodbc
-unixODBC database connectivity for Kamailio.
+UnixODBC database connectivity for Kamailio.
 
 
 %package    utils
-Summary:    Non-SIP utitility functions for Kamailio.
+Summary:    Non-SIP utitility functions for Kamailio
 Group:      System Environment/Daemons
 Requires:   libcurl, libxml2, kamailio = %ver
 BuildRequires:  libcurl-devel, libxml2-devel
@@ -493,18 +679,20 @@ BuildRequires:  libcurl-devel, libxml2-devel
 Non-SIP utitility functions for Kamailio.
 
 
+%if %{with websocket}
 %package    websocket
-Summary:    WebSocket transport for Kamailio.
+Summary:    WebSocket transport for Kamailio
 Group:      System Environment/Daemons
 Requires:   libunistring, openssl, kamailio = %ver
 BuildRequires:  libunistring-devel, openssl-devel
 
 %description    websocket
 WebSocket transport for Kamailio.
+%endif
 
 
 %package    xhttp-pi
-Summary:    Web-provisioning interface for Kamailio.
+Summary:    Web-provisioning interface for Kamailio
 Group:      System Environment/Daemons
 Requires:   libxml2, kamailio = %ver
 BuildRequires:  libxml2-devel
@@ -514,7 +702,7 @@ Web-provisioning interface for Kamailio.
 
 
 %package    xmlops
-Summary:    XML operation functions for Kamailio.
+Summary:    XML operation functions for Kamailio
 Group:      System Environment/Daemons
 Requires:   libxml2, kamailio = %ver
 BuildRequires:  libxml2-devel
@@ -523,28 +711,37 @@ BuildRequires:  libxml2-devel
 XML operation functions for Kamailio.
 
 
+%if %{with xmlrpc}
 %package    xmlrpc
-Summary:    XMLRPC transport and encoding for Kamailio RPCs and MI commands.
+Summary:    XMLRPC transport and encoding for Kamailio RPCs and MI commands
 Group:      System Environment/Daemons
-Requires:   libxml2, xmlrpc-c, kamailio = %ver
-BuildRequires:  libxml2-devel, xmlrpc-c-devel
+#Requires:   libxml2, xmlrpc-c, kamailio = %ver
+#BuildRequires:  libxml2-devel, xmlrpc-c-devel
+Requires:   libxml2, kamailio = %ver
+BuildRequires:  libxml2-devel
 
 %description    xmlrpc
 XMLRPC transport and encoding for Kamailio RPCs and MI commands.
-
+%endif
 
 %package    xmpp
-Summary:    SIP/XMPP IM gateway for Kamailio.
+Summary:    SIP/XMPP IM gateway for Kamailio
 Group:      System Environment/Daemons
-Requires:   expat, kamailio = %ver
+Requires:   kamailio = %ver
+%if 0%{?leap_version}
+Requires:   libexpat
+BuildRequires:  libexpat-devel
+%else
+Requires:   expat
 BuildRequires:  expat-devel
+%endif
 
 %description    xmpp
 SIP/XMPP IM gateway for Kamailio.
 
 
 %package        uuid
-Summary:        uuid generator for Kamailio
+Summary:        UUID generator for Kamailio
 Group:          System Environment/Daemons
 Requires:       libuuid, kamailio = %version
 BuildRequires:  libuuid-devel
@@ -557,93 +754,202 @@ UUID module for Kamailio.
 %setup -n %{name}-%{ver}
 
 
-
 %build
-make cfg prefix=/usr cfg_prefix=$RPM_BUILD_ROOT basedir=$RPM_BUILD_ROOT \
-    cfg_target=/%{_sysconfdir}/kamailio/ modules_dirs="modules"
+%if 0%{?fedora} || 0%{?leap_version}
+export FREERADIUS=1
+%endif
+make cfg prefix=/usr basedir=%{buildroot} cfg_prefix=%{buildroot} doc_prefix=%{buildroot} \
+    doc_dir=%{_docdir}/kamailio/ \
+    cfg_target=%{_sysconfdir}/kamailio/ modules_dirs="modules"
 make
 make every-module skip_modules="app_mono db_cassandra db_oracle iptrtpproxy \
     jabber ndb_cassandra osp" \
-    group_include="kstandard kautheph kberkeley kcarrierroute kcnxcc kcpl \
+%if 0%{?fedora} || 0%{?leap_version}
+    FREERADIUS=1 \
+%endif
+    group_include="kstandard kautheph kberkeley kcarrierroute \
+%if %{with cnxcc}
+    kcnxcc \
+%endif
+    kcpl \
 %if %{with dnssec}
     kdnssec \
 %endif
-    kgeoip kgzcompress khttp_async kims kjansson kjson kjsonrpcs \
+%if %{with geoip}
+    kgeoip \
+%endif
+    kgzcompress \
+%if %{with http_async_client}
+    khttp_async \
+%endif
+    kims \
+%if %{with jansson}
+    kjansson \
+%endif
+%if %{with json}
+    kjson \
+%endif
+    kjsonrpcs \
 %if %{with kazoo}
     kkazoo \
 %endif
-    kldap klua kmemcached \
-    kmi_xmlrpc kmysql koutbound kperl kpostgres kpresence kpython \
-    kradius kredis ksctp ksnmpstats ksqlite ktls kunixodbc kutils \
-    kwebsocket kxml kxmpp kuuid"
+    kldap 
+%if %{with lua}
+    klua \
+%endif
+%if %{with memcached}
+    kmemcached \
+%endif
+%if %{with xmlrpc}
+    kmi_xmlrpc \
+%endif
+    kmysql koutbound \
+%if %{with perl}
+    kperl \
+%endif
+    kpostgres kpresence kpython kradius \
+%if %{with redis}
+    kredis \
+%endif
+%if %{with sctp}
+    ksctp \
+%endif
+    ksnmpstats ksqlite ktls kunixodbc kutils \
+%if %{with websocket}
+    kwebsocket \
+%endif
+    kxml kxmpp kuuid"
 
 make utils
 
 
 
 %install
-[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT"
+rm -rf %{buildroot}
 
 make install
 make install-modules-all skip_modules="app_mono db_cassandra db_oracle \
     iptrtpproxy jabber osp" \
-    group_include="kstandard kautheph kberkeley kcarrierroute kcnxcc kcpl \
+%if 0%{?fedora} || 0%{?leap_version}
+    FREERADIUS=1 \
+%endif
+    group_include="kstandard kautheph kberkeley kcarrierroute \
+%if %{with cnxcc}
+    kcnxcc \
+%endif
+    kcpl \
 %if %{with dnssec}
     kdnssec \
 %endif
-    kgeoip kgzcompress khttp_async kims kjansson kjson kjsonrpcs \
+%if %{with geoip}
+    kgeoip \
+%endif
+    kgzcompress \
+%if %{with http_async_client}
+    khttp_async \
+%endif
+    kims \
+%if %{with jansson}
+    kjansson \
+%endif
+%if %{with json}
+    kjson \
+%endif
+    kjsonrpcs \
 %if %{with kazoo}
     kkazoo \
 %endif
-    kldap klua kmemcached \
-    kmi_xmlrpc kmysql koutbound kperl kpostgres kpresence kpython \
-    kradius kredis ksctp ksnmpstats ksqlite ktls kunixodbc kutils \
-    kwebsocket kxml kxmpp kuuid"
+    kldap \
+%if %{with lua}
+    klua \
+%endif
+%if %{with memcached}
+    kmemcached \
+%endif
+%if %{with xmlrpc}
+    kmi_xmlrpc \
+%endif
+    kmysql koutbound \
+%if %{with perl}
+    kperl \
+%endif
+    kpostgres kpresence kpython kradius \
+%if %{with redis}
+    kredis \
+%endif
+%if %{with sctp}
+    ksctp \
+%endif
+    ksnmpstats ksqlite ktls kunixodbc kutils \
+%if %{with websocket}
+    kwebsocket \
+%endif
+    kxml kxmpp kuuid"
 
 %if "%{?_unitdir}" == ""
 # On RedHat 6 like
-mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d
-install -m755 pkg/kamailio/centos/%{?centos}/kamailio.init \
-        $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d/kamailio
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d
+install -m755 pkg/kamailio/%{dist_name}/%{dist_version}/kamailio.init \
+        %{buildroot}%{_sysconfdir}/rc.d/init.d/kamailio
 %else
 # systemd
 install -d %{buildroot}%{_unitdir}
-install -Dpm 0644 pkg/kamailio/centos/%{?centos}/kamailio.service %{buildroot}%{_unitdir}/kamailio.service
-install -Dpm 0644 pkg/kamailio/centos/%{?centos}/kamailio.tmpfiles %{buildroot}%{_tmpfilesdir}/kamailio.conf
+install -Dpm 0644 pkg/kamailio/%{dist_name}/%{dist_version}/kamailio.service %{buildroot}%{_unitdir}/kamailio.service
+install -Dpm 0644 pkg/kamailio/%{dist_name}/%{dist_version}/kamailio.tmpfiles %{buildroot}%{_tmpfilesdir}/kamailio.conf
 %endif
 
-mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig
-install -m644 pkg/kamailio/centos/%{?centos}/kamailio.sysconfig \
-        $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/kamailio
+%if 0%{?leap_version}
+mkdir -p %{buildroot}/var/adm/fillup-templates/
+install -m644 pkg/kamailio/%{dist_name}/%{dist_version}/kamailio.sysconfig \
+        %{buildroot}/var/adm/fillup-templates/sysconfig.kamailio
+%else
+mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
+install -m644 pkg/kamailio/%{dist_name}/%{dist_version}/kamailio.sysconfig \
+        %{buildroot}%{_sysconfdir}/sysconfig/kamailio
+%endif
 
+%if 0%{?leap_version}
+%py_compile -O %{buildroot}%{_libdir}/kamailio/kamctl/dbtextdb
+%endif
 
+# Removing devel files
+rm -f %{buildroot}%{_libdir}/kamailio/lib*.so
 
 %pre
-/usr/sbin/groupadd -r kamailio 2> /dev/null || :
-/usr/sbin/useradd -r -g kamailio -s /bin/false -c "Kamailio daemon" -d \
-        %{_libdir}/kamailio kamailio 2> /dev/null || :
-mkdir -p %{_var}/run/kamailio 2> /dev/null || :
-chown kamailio:kamailio %{_var}/run/kamailio 2> /dev/null || :
-
-
+if ! /usr/bin/id kamailio &>/dev/null; then
+       /usr/sbin/useradd -r -g daemon -s /bin/false -c "Kamailio daemon" -d %{_libdir}/kamailio kamailio || \
+                %logmsg "Unexpected error adding user \"kamailio\". Aborting installation."
+fi
 
 %clean
-rm -rf "$RPM_BUILD_ROOT"
-
+rm -rf %{buildroot}
 
 
 %post
+%if "%{?_unitdir}" == ""
+mkdir -p %{_var}/run/kamailio 2> /dev/null || :
+chown kamailio:kamailio %{_var}/run/kamailio 2> /dev/null
 /sbin/chkconfig --add kamailio
-
+%else
+%tmpfiles_create kamailio
+/usr/bin/systemctl -q enable kamailio.service
+%endif
 
 
 %preun
 if [ $1 = 0 ]; then
+%if "%{?_unitdir}" == ""
     /sbin/service kamailio stop > /dev/null 2>&1
     /sbin/chkconfig --del kamailio
+%else
+    %{?systemd_preun kamailio.service}
+%endif
 fi
 
-
+%if "%{?_unitdir}" == ""
+%postun
+%{?systemd_postun kamailio.service}
+%endif
 
 %files
 %defattr(-,root,root)
@@ -765,7 +1071,11 @@ fi
 
 %dir %attr(-,kamailio,kamailio) %{_sysconfdir}/kamailio
 %config(noreplace) %{_sysconfdir}/kamailio/*
+%if 0%{?leap_version}
+/var/adm/fillup-templates/sysconfig.kamailio
+%else
 %config %{_sysconfdir}/sysconfig/*
+%endif
 %if "%{?_unitdir}" == ""
 %config %{_sysconfdir}/rc.d/init.d/*
 %else
@@ -774,19 +1084,14 @@ fi
 %endif
 
 %dir %{_libdir}/kamailio
-%{_libdir}/kamailio/libprint.so
 %{_libdir}/kamailio/libprint.so.1
 %{_libdir}/kamailio/libprint.so.1.2
-%{_libdir}/kamailio/libsrdb1.so
 %{_libdir}/kamailio/libsrdb1.so.1
 %{_libdir}/kamailio/libsrdb1.so.1.0
-%{_libdir}/kamailio/libsrdb2.so
 %{_libdir}/kamailio/libsrdb2.so.1
 %{_libdir}/kamailio/libsrdb2.so.1.0
-%{_libdir}/kamailio/libsrutils.so
 %{_libdir}/kamailio/libsrutils.so.1
 %{_libdir}/kamailio/libsrutils.so.1.0
-%{_libdir}/kamailio/libtrie.so
 %{_libdir}/kamailio/libtrie.so.1
 %{_libdir}/kamailio/libtrie.so.1.0
 
@@ -960,10 +1265,13 @@ fi
 %{_libdir}/kamailio/modules/carrierroute.so
 
 
+%if %{with cnxcc}
 %files      cnxcc
 %defattr(-,root,root)
 %{_docdir}/kamailio/modules/README.cnxcc
 %{_libdir}/kamailio/modules/cnxcc.so
+%endif
+
 
 %files      cpl
 %defattr(-,root,root)
@@ -991,10 +1299,12 @@ fi
 %endif
 
 
+%if %{with geoip}
 %files      geoip
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.geoip
 %{_libdir}/kamailio/modules/geoip.so
+%endif
 
 
 %files      gzcompress
@@ -1002,10 +1312,13 @@ fi
 %doc %{_docdir}/kamailio/modules/README.gzcompress
 %{_libdir}/kamailio/modules/gzcompress.so
 
+
+%if %{with http_async_client}
 %files      http_async_client
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.http_async_client
 %{_libdir}/kamailio/modules/http_async_client.so
+%endif
 
 %files      http_client
 %defattr(-,root,root)
@@ -1014,7 +1327,6 @@ fi
 
 %files      ims
 %defattr(-,root,root)
-%{_libdir}/kamailio/libkamailio_ims.so
 %{_libdir}/kamailio/libkamailio_ims.so.0
 %{_libdir}/kamailio/libkamailio_ims.so.0.1
 
@@ -1035,7 +1347,6 @@ fi
 %doc %{_docdir}/kamailio/modules/README.smsops
 %doc %{_docdir}/kamailio/modules/README.statsc
 %doc %{_docdir}/kamailio/modules/README.topos
-#%doc %{_docdir}/kamailio/modules/README.ims_usrloc_scscf
 %{_libdir}/kamailio/modules/cdp.so
 %{_libdir}/kamailio/modules/cdp_avp.so
 %{_libdir}/kamailio/modules/cfgt.so
@@ -1055,20 +1366,24 @@ fi
 %{_libdir}/kamailio/modules/statsc.so
 %{_libdir}/kamailio/modules/topos.so
 
+%if %{with jansson}
 %files      jansson
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.jansson
 %doc %{_docdir}/kamailio/modules/README.janssonrpcc
 %{_libdir}/kamailio/modules/jansson.so
 %{_libdir}/kamailio/modules/janssonrpcc.so
+%endif
 
 
+%if %{with json}
 %files      json
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.json
 %doc %{_docdir}/kamailio/modules/README.jsonrpcc
 %{_libdir}/kamailio/modules/json.so
 %{_libdir}/kamailio/modules/jsonrpcc.so
+%endif
 
 
 %if %{with kazoo}
@@ -1078,7 +1393,6 @@ fi
 %{_libdir}/kamailio/modules/kazoo.so
 %endif
 
-
 %files      lcr
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.lcr
@@ -1095,16 +1409,20 @@ fi
 %{_libdir}/kamailio/modules/ldap.so
 
 
+%if %{with lua}
 %files      lua
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.app_lua
 %{_libdir}/kamailio/modules/app_lua.so
+%endif
 
 
+%if %{with memcached}
 %files      memcached
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.memcached
 %{_libdir}/kamailio/modules/memcached.so
+%endif
 
 
 %files      mysql
@@ -1123,6 +1441,7 @@ fi
 %{_libdir}/kamailio/modules/outbound.so
 
 
+%if %{with perl}
 %files      perl
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.app_perl
@@ -1155,6 +1474,7 @@ fi
 %{_libdir}/kamailio/perl/Kamailio/VDB/Adapter/Describe.pm
 %{_libdir}/kamailio/perl/Kamailio/VDB/Adapter/Speeddial.pm
 %{_libdir}/kamailio/perl/Kamailio/VDB/Adapter/TableVersions.pm
+%endif
 
 
 %files      postgresql
@@ -1221,10 +1541,12 @@ fi
 %{_libdir}/kamailio/modules/peering.so
 
 
+%if %{with redis}
 %files      redis
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.ndb_redis
 %{_libdir}/kamailio/modules/ndb_redis.so
+%endif
 
 
 %files      regex
@@ -1239,10 +1561,12 @@ fi
 %{_libdir}/kamailio/modules/rtjson.so
 
 
+%if %{with sctp}
 %files      sctp
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.sctp
 %{_libdir}/kamailio/modules/sctp.so
+%endif
 
 
 %files      snmpstats
@@ -1298,10 +1622,12 @@ fi
 %{_libdir}/kamailio/modules/utils.so
 
 
+%if %{with websocket}
 %files      websocket
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.websocket
 %{_libdir}/kamailio/modules/websocket.so
+%endif
 
 
 %files      xhttp-pi
@@ -1318,10 +1644,12 @@ fi
 %{_libdir}/kamailio/modules/xmlops.so
 
 
+%if %{with xmlrpc}
 %files      xmlrpc
 %defattr(-,root,root)
 %doc %{_docdir}/kamailio/modules/README.xmlrpc
 %{_libdir}/kamailio/modules/xmlrpc.so
+%endif
 
 
 %files      xmpp
@@ -1337,6 +1665,10 @@ fi
 
 
 %changelog
+* Thu Sep 02 2017 Sergey Safarov <s.safarov at gmail.com>
+  - added packaging for Fedora 26 and openSUSE Leap 42.3
+  - removed packaging for Fedora 24 and openSUSE Leap 42.1 as End Of Life
+  - rewrited SPEC file to support Fedora, RHEL, CentOS, openSUSE distrs
 * Thu Mar 09 2017 Federico Cabiddu <federico.cabiddu at gmail.com>
   - added jansson package
 * Sat Feb 04 2017 Federico Cabiddu <federico.cabiddu at gmail.com>
diff --git a/pkg/kamailio/obs/kamailio.sysconfig b/pkg/kamailio/obs/kamailio.sysconfig
new file mode 100644
index 0000000..c4332c7
--- /dev/null
+++ b/pkg/kamailio/obs/kamailio.sysconfig
@@ -0,0 +1,18 @@
+#
+# Kamailio startup options
+#
+
+# Amount of shared memory to allocate for the running Kamailio server (in Mb)
+#SHM_MEMORY=64
+
+# Amount of per-process (package) memory to allocate for Kamailio (in Mb)
+#PKG_MEMORY=4
+
+# Enable the server to leave a core file when it crashes.
+# Set this to 'yes' to enable kamailio to leave a core file when it crashes
+# or 'no' to disable this feature. This option is case sensitive and only
+# accepts 'yes' and 'no' and only in lowercase letters.
+# On some systems (e.g. Ubuntu 6.10, Debian 4.0) it is necessary to specify
+# a directory for the core files to get a dump. Look into the kamailio
+# init file for an example configuration.
+DUMP_CORE=no
diff --git a/pkg/kamailio/obs/kamailio.tmpfiles b/pkg/kamailio/obs/kamailio.tmpfiles
new file mode 100644
index 0000000..6c3cc0b
--- /dev/null
+++ b/pkg/kamailio/obs/kamailio.tmpfiles
@@ -0,0 +1 @@
+D /run/kamailio 0700 kamailio daemon -
diff --git a/pkg/kamailio/obs/meta b/pkg/kamailio/obs/meta
new file mode 100644
index 0000000..5607d66
--- /dev/null
+++ b/pkg/kamailio/obs/meta
@@ -0,0 +1,43 @@
+<project name="home:kamailio:v5.0.x-rpms">
+  <title>RPM Packages for Kamailio v5.0.x</title>
+  <description>RPM Packages for Kamailio v5.0.x</description>
+  <person userid="kamailio" role="maintainer"/>
+  <repository name="openSUSE_Leap_42.3_Update">
+    <path project="openSUSE:Leap:42.3:Update" repository="standard"/>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="openSUSE_Leap_42.2_Update">
+    <path project="openSUSE:Leap:42.2:Update" repository="standard"/>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="RHEL_7">
+    <path project="Fedora:EPEL:7" repository="RHEL"/>
+    <arch>x86_64</arch>
+    <arch>ppc64</arch>
+  </repository>
+  <repository name="RHEL_6">
+    <path project="Fedora:EPEL:6" repository="RHEL"/>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="Fedora_26">
+    <path project="Fedora:26" repository="update"/>
+    <path project="Fedora:26" repository="standard"/>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="Fedora_25">
+    <path project="Fedora:25" repository="update"/>
+    <path project="Fedora:25" repository="standard"/>
+    <arch>i586</arch>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="CentOS_7">
+    <path project="CentOS:CentOS-7" repository="update"/>
+    <path project="Fedora:EPEL:7" repository="CentOS"/>
+    <arch>x86_64</arch>
+  </repository>
+  <repository name="CentOS_6">
+    <path project="CentOS:CentOS-6" repository="update"/>
+    <path project="Fedora:EPEL:6" repository="CentOS"/>
+    <arch>x86_64</arch>
+  </repository>
+</project>
diff --git a/pkg/kamailio/oracle/el6/kamailio.spec b/pkg/kamailio/oracle/el6/kamailio.spec
index 2981d3b..342be9f 100644
--- a/pkg/kamailio/oracle/el6/kamailio.spec
+++ b/pkg/kamailio/oracle/el6/kamailio.spec
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver     5.0.3
+%define ver     5.0.4
 %define rel     0
 %define _sharedir %{_prefix}/share
 
diff --git a/pkg/kamailio/oracle/el7/kamailio.spec b/pkg/kamailio/oracle/el7/kamailio.spec
index 17cbf26..08a5de3 100644
--- a/pkg/kamailio/oracle/el7/kamailio.spec
+++ b/pkg/kamailio/oracle/el7/kamailio.spec
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver     5.0.3
+%define ver     5.0.4
 %define rel     0
 %define _sharedir %{_prefix}/share
 
diff --git a/pkg/kamailio/rpm/kamailio.spec-4.1 b/pkg/kamailio/rpm/kamailio.spec-4.1
index 7a5dc75..bcd08a2 100644
--- a/pkg/kamailio/rpm/kamailio.spec-4.1
+++ b/pkg/kamailio/rpm/kamailio.spec-4.1
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver     5.0.3
+%define ver     5.0.4
 %define rel     0
 
 %define EXCLUDED_MODULES	mysql jabber cpl-c avp_radius auth_radius group_radius uri_radius pa postgres osp tlsops unixodbc
diff --git a/pkg/kamailio/rpm/kamailio.spec.CenOS b/pkg/kamailio/rpm/kamailio.spec.CenOS
index 28160e1..7910759 100644
--- a/pkg/kamailio/rpm/kamailio.spec.CenOS
+++ b/pkg/kamailio/rpm/kamailio.spec.CenOS
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver     5.0.3
+%define ver     5.0.4
 %define rel     0
 %define _sharedir %{_prefix}/share
 
diff --git a/pkg/kamailio/rpm/kamailio.spec.SuSE b/pkg/kamailio/rpm/kamailio.spec.SuSE
index 8a253fe..5a504ee 100644
--- a/pkg/kamailio/rpm/kamailio.spec.SuSE
+++ b/pkg/kamailio/rpm/kamailio.spec.SuSE
@@ -1,5 +1,5 @@
 %define name    kamailio
-%define ver     5.0.3
+%define ver     5.0.4
 %define rel     0
 
 %define EXCLUDED_MODULES	mysql jabber cpl-c auth_radius misc_radius peering postgress pa unixodbc osp tlsops
diff --git a/src/Makefile.defs b/src/Makefile.defs
index 28c5158..0ae2c91 100644
--- a/src/Makefile.defs
+++ b/src/Makefile.defs
@@ -106,7 +106,7 @@ INSTALL_FLAVOUR=$(FLAVOUR)
 # version number
 VERSION = 5
 PATCHLEVEL = 0
-SUBLEVEL = 3
+SUBLEVEL = 4
 EXTRAVERSION = 
 
 # memory manager switcher
diff --git a/src/core/core_cmd.c b/src/core/core_cmd.c
index 096ac82..3eec746 100644
--- a/src/core/core_cmd.c
+++ b/src/core/core_cmd.c
@@ -943,7 +943,7 @@ static void core_sockets_list(rpc_t* rpc, void* c)
 				rpc->struct_add(ha, "ss",
 						"proto", get_proto_name(proto),
 						"address", si->name.s);
-				if (!si->flags & SI_IS_IP)
+				if (!(si->flags & SI_IS_IP))
 					rpc->struct_add(ha, "s",
 						"ipaddress", si->address_str.s);
 				rpc->struct_add(ha, "sss",
diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h
index d323239..ebf13ad 100644
--- a/src/core/ip_addr.h
+++ b/src/core/ip_addr.h
@@ -151,8 +151,8 @@ typedef struct sr_net_info {
 #define SND_F_FORCE_SOCKET		4 /* send socket in dst is forced */
 
 struct snd_flags {
-	unsigned char f;          /* snd flags */
-	unsigned char blst_imask; /* blacklist ignore mask */
+	unsigned short f;          /* snd flags */
+	unsigned short blst_imask; /* blacklist ignore mask */
 };
 
 
diff --git a/src/core/parser/parse_fline.h b/src/core/parser/parse_fline.h
index 04f96b6..b10c02b 100644
--- a/src/core/parser/parse_fline.h
+++ b/src/core/parser/parse_fline.h
@@ -18,8 +18,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -68,31 +68,28 @@
 #define REFER_LEN 5
 #define PUBLISH_LEN 7
 
-struct msg_start {
+typedef struct msg_start {
 	short type;					/*!< Type of the message - request/response */
 	short flags;				/*!< First line flags */
 	int len; 					/*!< length including delimiter */
 	union {
 		struct {
-			str method;       /*!< Method string */
-			str uri;          /*!< Request URI */
-			str version;      /*!< SIP version */
+			str method;			/*!< Method string */
+			str uri;			/*!< Request URI */
+			str version;		/*!< SIP version */
 			int method_value;
 		} request;
 		struct {
-			str version;      /*!< SIP version */
-			str status;       /*!< Reply status */
-			str reason;       /*!< Reply reason phrase */
-			unsigned int /*!< statusclass,*/ statuscode;
+			str version;		/*!< SIP version */
+			str status;			/*!< Reply status */
+			str reason;			/*!< Reply reason phrase */
+			unsigned int statuscode;	/*!< Reply status code */
 		} reply;
 	}u;
-};
-
-
+} msg_start_t;
 
 char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl);
 
 char* parse_fline(char* buffer, char* end, struct msg_start* fl);
 
-
 #endif /* PARSE_FLINE_H */
diff --git a/src/core/rvalue.c b/src/core/rvalue.c
index 540f266..fcb238d 100644
--- a/src/core/rvalue.c
+++ b/src/core/rvalue.c
@@ -1099,6 +1099,10 @@ int rval_get_tmp_str(struct run_act_ctx* h, struct sip_msg* msg,
 	avp_t* r_avp;
 	int i;
 
+	if(rv==NULL) {
+		return -1;
+	}
+
 	switch(rv->type){
 		case RV_INT:
 			tmpv->s=sint2strbuf(rv->v.l, tmp_cache->i2s,
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index d4bd76f..1047fc4 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -1912,7 +1912,7 @@ void print_all_socket_lists()
 				printf("             %s: %s",
 						get_valid_proto_name(proto),
 						si->name.s);
-				if (!si->flags & SI_IS_IP)
+				if (!(si->flags & SI_IS_IP))
 					printf(" [%s]", si->address_str.s);
 				printf( ":%s%s%s",
 						si->port_no_str.s, 
diff --git a/src/core/tcp_conn.h b/src/core/tcp_conn.h
index 771b744..c8ab563 100644
--- a/src/core/tcp_conn.h
+++ b/src/core/tcp_conn.h
@@ -199,7 +199,7 @@ struct tcp_connection{
 	struct tcp_req req; /* request data */
 	atomic_t refcnt;
 	enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
-	unsigned short flags; /* connection related flags */
+	unsigned int flags; /* connection related flags */
 	snd_flags_t send_flags; /* special send flags */
 	enum tcp_conn_states state; /* connection state */
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
diff --git a/src/core/tcp_read.c b/src/core/tcp_read.c
index b2a9e9f..818bc52 100644
--- a/src/core/tcp_read.c
+++ b/src/core/tcp_read.c
@@ -428,7 +428,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 							r->state=(newstate); break; \
 						crlf_default_skip_case; \
 					}
-	
+
 	#define change_state_case(state0, upper, lower, newstate)\
 					case state0: \
 							  change_state(upper, lower, newstate); \
@@ -437,6 +437,22 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
 
 
 	r=&c->req;
+	if(r->parsed<r->buf || r->parsed>r->buf+r->b_size) {
+		if(r->parsed<r->buf && (unsigned char)r->state==H_SKIP_EMPTY) {
+			/* give it a chance to parse from beginning */
+			LM_WARN("resetting parsed pointer (buf:%p parsed:%p bsize:%u)\n",
+				r->buf, r->parsed, r->b_size);
+			r->parsed = r->buf;
+		} else {
+			LM_ERR("out of bounds parsed pointer (buf:%p parsed:%p bsize:%u)\n",
+				r->buf, r->parsed, r->b_size);
+			r->parsed = r->buf;
+			r->content_len=0;
+			r->error=TCP_REQ_BAD_LEN;
+			r->state=H_SKIP; /* skip state now */
+			return -1;
+		}
+	}
 	/* if we still have some unparsed part, parse it first, don't do the read*/
 	if (unlikely(r->parsed<r->pos)){
 		bytes=0;
@@ -1079,8 +1095,8 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
 #ifdef READ_WS
 static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
 {
-	int bytes, size, pos, mask_present;
-	unsigned int len;
+	int bytes;
+	uint32_t size, pos, mask_present, len;
 	char *p;
 	struct tcp_req *r;
 
@@ -1137,22 +1153,27 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
 	/* Work out real length */
 	if (len == 126)
 	{
+		/* 2 bytes store the payload size */
 		if (size < pos + 2)
 			goto skip;
 
-		len =	  ((p[pos + 0] & 0xff) <<  8)
-			| ((p[pos + 1] & 0xff) <<  0);
+		len = ((p[pos + 0] & 0xff) <<  8) | ((p[pos + 1] & 0xff) <<  0);
 		pos += 2;
-	}
-	else if (len == 127)
-	{
-		if (size < pos + 8)
+	} else if (len == 127) {
+		/* 8 bytes store the payload size */
+		if (size < pos + 8) {
 			goto skip;
+		}
 
 		/* Only decoding the last four bytes of the length...
 		   This limits the size of WebSocket messages that can be
 		   handled to 2^32 - which should be plenty for SIP! */
-		len =	  ((p[pos + 4] & 0xff) << 24)
+		if((p[pos] & 0xff)!=0 || (p[pos + 1] & 0xff)!=0
+				|| (p[pos + 2] & 0xff)!=0 || (p[pos + 3] & 0xff)!=0) {
+			LM_WARN("advertised lenght is too large (more than 2^32)\n");
+			goto skip;
+		}
+		len = ((p[pos + 4] & 0xff) << 24)
 			| ((p[pos + 5] & 0xff) << 16)
 			| ((p[pos + 6] & 0xff) <<  8)
 			| ((p[pos + 7] & 0xff) <<  0);
@@ -1167,6 +1188,12 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
 		pos += 4;
 	}
 
+	/* check if advertised lenght fits in read buffer */
+	if(len>=r->b_size) {
+		LM_WARN("advertised lenght (%u) greater than buffer size (%u)\n",
+				len, r->b_size);
+		goto skip;
+	}
 	/* Now check the whole message has been received */
 	if (size < pos + len)
 		goto skip;
diff --git a/src/modules/app_mono/doc/app_mono_admin.xml b/src/modules/app_mono/doc/app_mono_admin.xml
index d5a06da..aae3589 100644
--- a/src/modules/app_mono/doc/app_mono_admin.xml
+++ b/src/modules/app_mono/doc/app_mono_admin.xml
@@ -11,20 +11,20 @@
 <!-- Module User's Guide -->
 
 <chapter>
-    
+
     <title>&adminguide;</title>
-    
+
     <section>
 	<title>Overview</title>
 	<para>
-		This module allows the execution of assemblies of managed code, among 
+		This module allows the execution of assemblies of managed code, among
 		the most popular of which is C# (.NET).
 		It uses the Mono project (http://www.mono-project.com/) to embed the managed
 		code interpreter inside the SIP server, providing fast execution.
 	</para>
 	<para>
 		Besides C#, other languages can be used to build managed assemblies,
-		such as: Java, Python, VisualBasic.NET, JavaScript. For more details on 
+		such as: Java, Python, VisualBasic.NET, JavaScript. For more details on
 		what kind of languages can be used to build managed
 		assemblies, see: http://www.mono-project.com/Languages
 	</para>
@@ -36,7 +36,7 @@
 	<para>
 		There are two ways to execute managed code assemblies: load the code at
 		startup and only execute at runtime, or load and execute at runtime. Only
-		one mode at a time may be used.  The mode is determined by the 'load' 
+		one mode at a time may be used.  The mode is determined by the 'load'
 		parameter and the function used to execute the code.
 	</para>
     </section>
@@ -72,7 +72,7 @@
     </section>
     <section>
 	<title>Parameters</title>
-	<section>
+	<section id="app_mono.p.load">
 	    <title><varname>load</varname> (string)</title>
 	    <para>
 			Set the path to the Mono assembly to be loaded at startup.  You
@@ -93,10 +93,10 @@ modparam("app_mono", "load", "/usr/local/etc/kamailio/mono/myscript.exe")
 	    </example>
 	</section>
 	</section>
-	
+
     <section>
 	<title>Functions</title>
- 	<section>
+	<section id="app_mono.f.mono_exec">
 	    <title>
 		<function moreinfo="none">mono_exec(path [, param])</function>
 	    </title>
@@ -119,8 +119,8 @@ mono_exec("/usr/local/etc/kamailio/mono/myscript.exe");
 </programlisting>
 	    </example>
 	</section>
-	
-	<section>
+
+	<section id="app_mono.mono_run">
 	    <title>
 		<function moreinfo="none">mono_run([param])</function>
 	    </title>
@@ -147,7 +147,7 @@ if(!mono_run("myparam"))
 	    </example>
 	</section>
 	</section>
-	
+
     <section>
 	<title>Usage</title>
 	<para>
diff --git a/src/modules/app_python/doc/app_python_admin.xml b/src/modules/app_python/doc/app_python_admin.xml
index 4d4d4db..52d1383 100644
--- a/src/modules/app_python/doc/app_python_admin.xml
+++ b/src/modules/app_python/doc/app_python_admin.xml
@@ -58,7 +58,7 @@
     </section>
     <section>
 	<title>Parameters</title>
-	<section>
+	<section id="app_python.p.script_name">
 	    <title><varname>script_name</varname> (string)</title>
 	    <para>
 			The path to the fiel with Python code to be executed
@@ -79,7 +79,7 @@ modparam("app_python", "script_name", "/usr/local/etc/kamailio/myscript.py")
 	    </example>
 	</section>
 
-	<section>
+	<section id="app_python.p.mod_init_function">
 	    <title><varname>mod_init_function</varname> (string)</title>
 	    <para>
 			The Python function to be executed by this module when
@@ -100,7 +100,7 @@ modparam("app_python", "mod_init_function", "my_mod_init")
 	    </example>
 	</section>
 
-	<section>
+	<section id="app_python.p.child_init_method">
 	    <title><varname>child_init_method</varname> (string)</title>
 	    <para>
 			The Python function to be executed by this module when
@@ -125,7 +125,7 @@ modparam("app_python", "child_init_method", "my_child_init")
 	
     <section>
 	<title>Functions</title>
- 	<section>
+ 	<section id="app_python.f.python_exec">
 	    <title>
 		<function moreinfo="none">python_exec(method [, args])</function>
 	    </title>
diff --git a/src/modules/auth/README b/src/modules/auth/README
index a89538a..fd9af10 100644
--- a/src/modules/auth/README
+++ b/src/modules/auth/README
@@ -721,8 +721,8 @@ if (has_credentials("myrealm")) {
    The function challenges a user agent. It will generate a WWW-Authorize
    header field containing a digest challenge, it will put the header
    field into a response generated from the request the server is
-   processing and send the reply. Upon reception of such a reply the user
-   agent should compute credentials and retry the request. For more
+   processing and send the 401 reply. Upon reception of such a reply the
+   user agent should compute credentials and retry the request. For more
    information regarding digest authentication see RFC2617. See module
    parameter force_stateless_reply regarding sending of the reply.
 
@@ -758,10 +758,10 @@ if (!www_authenticate("$td", "subscriber")) {
    The function challenges a user agent. It will generate a
    Proxy-Authorize header field containing a digest challenge, it will put
    the header field into a response generated from the request the server
-   is processing and send the reply. Upon reception of such a reply the
-   user agent should compute credentials and retry the request. For more
-   information regarding digest authentication see RFC2617. See module
-   parameter force_stateless_reply regarding sending of the reply.
+   is processing and send the 407 reply. Upon reception of such a reply
+   the user agent should compute credentials and retry the request. For
+   more information regarding digest authentication see RFC2617. See
+   module parameter force_stateless_reply regarding sending of the reply.
 
    Meaning of the parameters is the same as for function
    www_challenge(realm, flags)
@@ -780,7 +780,9 @@ if (!proxy_authenticate("$fd", "subscriber")) {
    The function challenges a user agent for authentication. It combines
    the functions www_challenge() and proxy_challenge(), by calling
    internally the first one for REGISTER requests and the second one for
-   the rest of other request types.
+   the rest of other request types. In other words, it challenges for
+   authentication by sending a 401 reply for REGISTER requests and 407
+   reply for the other types of SIP requests.
 
    Meaning of the parameters the same as for function www_challenge(realm,
    flags)
diff --git a/src/modules/auth/doc/auth_functions.xml b/src/modules/auth/doc/auth_functions.xml
index 225dbb3..b1384cd 100644
--- a/src/modules/auth/doc/auth_functions.xml
+++ b/src/modules/auth/doc/auth_functions.xml
@@ -57,10 +57,10 @@ if (has_credentials("myrealm")) {
 		The function challenges a user agent. It will generate a
 		WWW-Authorize header field containing a digest challenge, it will
 		put the header field into a response generated from the request the
-		server is processing and send the reply. Upon reception of such a
+		server is processing and send the 401 reply. Upon reception of such a
 		reply the user agent should compute credentials and retry the
 		request. For more information regarding digest authentication
-		see RFC2617.  See module parameter force_stateless_reply
+		see RFC2617. See module parameter force_stateless_reply
 		regarding sending of the reply.
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
@@ -130,7 +130,7 @@ if (!www_authenticate("$td", "subscriber")) {
 		The function challenges a user agent. It will generate a
 		Proxy-Authorize header field containing a digest challenge, it will
 		put the header field into a response generated from the request the
-		server is processing and send the reply. Upon reception of such a
+		server is processing and send the 407 reply. Upon reception of such a
 		reply the user agent should compute credentials and retry the request.
 		For more information regarding digest authentication see RFC2617.
 		See module parameter force_stateless_reply regarding sending of the reply.
@@ -160,7 +160,9 @@ if (!proxy_authenticate("$fd", "subscriber")) {
 		The function challenges a user agent for authentication. It combines
 		the functions www_challenge() and proxy_challenge(), by calling
 		internally the first one for REGISTER requests and the second one for
-		the rest of other request types.
+		the rest of other request types. In other words, it challenges for
+		authentication by sending a 401 reply for REGISTER requests and 407
+		reply for the other types of SIP requests.
 		</para>
 		<para>Meaning of the parameters the same as for function
 		www_challenge(realm, flags)</para>
diff --git a/src/modules/auth_radius/doc/auth_radius_admin.xml b/src/modules/auth_radius/doc/auth_radius_admin.xml
index fe47997..d7b4080 100644
--- a/src/modules/auth_radius/doc/auth_radius_admin.xml
+++ b/src/modules/auth_radius/doc/auth_radius_admin.xml
@@ -8,22 +8,22 @@
 ]>
 
 <chapter>
-	
+
 	<title>&adminguide;</title>
-	
+
 	<section>
 	<title>Overview</title>
 	<para>
-		This module contains functions that are used to perform authentication 
-		using a Radius server. Basically the proxy will pass along the 
-		credentials to the radius server which will in turn send a reply 
+		This module contains functions that are used to perform authentication
+		using a Radius server. Basically the proxy will pass along the
+		credentials to the radius server which will in turn send a reply
 		containing result of the authentication. So basically the whole
-		authentication is done in the Radius server. Before sending the request 
-		to the radius server we perform some sanity checks over the 
-		credentials to make sure that only well formed credentials will get to 
-		the server. We have implemented radius authentication according to 
+		authentication is done in the Radius server. Before sending the request
+		to the radius server we perform some sanity checks over the
+		credentials to make sure that only well formed credentials will get to
+		the server. We have implemented radius authentication according to
 		draft-sterman-aaa-sip-00. This module requires the radiusclient-ng
-		library version 0.5.0 or higheer or freeradius-client which is available from 
+		library version 0.5.0 or higheer or freeradius-client which is available from
 		<ulink url='https://github.com/FreeRADIUS/freeradius-client/'>
 		https://github.com/FreeRADIUS/freeradius-client/</ulink>.
 		You can also install this library from distribution repositories.
@@ -38,7 +38,7 @@
 		extra queries.
 	</para>
 	<para>
-		The additional credentials are embedded in the RADIUS reply as AVPs 
+		The additional credentials are embedded in the RADIUS reply as AVPs
 		<quote>SIP-AVP</quote>. The syntax of the value is:
 		<itemizedlist>
 			<listitem><para><emphasis>
@@ -81,7 +81,7 @@
 		<section>
 			<title>Modules</title>
 			<para>
-			The module depends on the following modules (in the other words 
+			The module depends on the following modules (in the other words
 			the listed modules must be loaded before this module):
 			<itemizedlist>
 				<listitem>
@@ -95,7 +95,7 @@
 		<section>
 			<title>External Libraries or Applications</title>
 			<para>
-			The following libraries or applications must be installed 
+			The following libraries or applications must be installed
 			before compilling &kamailio; with this module loaded:
 			</para>
 			<itemizedlist>
@@ -104,14 +104,14 @@
 				freeradius-client.</para>
 				<listitem>
 				<para>
-				<emphasis>freeradius-client</emphasis>  available from 
+				<emphasis>freeradius-client</emphasis>  available from
 				<ulink url='https://github.com/FreeRADIUS/freeradius-client/'>
 				https://github.com/FreeRADIUS/freeradius-client/</ulink>.
 				</para>
 				</listitem>
 				<listitem>
-				<para><emphasis>radiusclient-ng</emphasis> 0.5.0 or higher -- 
-				library and development files. See <ulink 
+				<para><emphasis>radiusclient-ng</emphasis> 0.5.0 or higher --
+				library and development files. See <ulink
 				url='http://developer.berlios.de/projects/radiusclient-ng/'>
 				http://developer.berlios.de/projects/radiusclient-ng/</ulink>.
 				</para>
@@ -122,14 +122,14 @@
 
 	<section>
 	<title>Parameters</title>
-	<section>
+	<section id="auth_radius.p.radius_config">
 		<title><varname>radius_config</varname> (string)</title>
 		<para>
-		This is the location of the configuration file of radius client 
+		This is the location of the configuration file of radius client
 		libraries.
 		</para>
 		<para>
-		Default value is 
+		Default value is
 			<quote>/usr/local/etc/radiusclient-ng/radiusclient.conf</quote>.
 		</para>
 		<example>
@@ -139,12 +139,12 @@ modparam("auth_radius", "radius_config", "/etc/radiusclient.conf")
 		</programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="auth_radius.p.service_type">
 		<title><varname>service_type</varname> (integer)</title>
 		<para>
-		This is the value of the Service-Type radius attribute to be used. 
-		The default should be fine for most people. See your radius client 
-		include files for numbers to be put in this parameter if you need 
+		This is the value of the Service-Type radius attribute to be used.
+		The default should be fine for most people. See your radius client
+		include files for numbers to be put in this parameter if you need
 		to change it.
 		</para>
 		<para>
@@ -157,13 +157,13 @@ modparam("auth_radius", "service_type", 15)
 		</programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="auth_radius.p.auth_extra">
 		<title><varname>auth_extra</varname> (string)</title>
 		<para>
 		Semi-colon separated list of extra RADIUS attribute
 		name=pseudo variable pairs. When radius_www_authorize() or
 		radius_proxy_authorize() function is called, listed extra
-		attributes are included in RADIUS request with 
+		attributes are included in RADIUS request with
 		current values of corresponding pseudo variables.
 		</para>
 		<para>
@@ -177,7 +177,7 @@ modparam("auth_radius", "auth_extra", "Acct-Session-Id=$ci")
 		</programlisting>
 		</example>
 	</section>
-        <section>
+        <section id="auth_radius.p.use_ruri_flag">
                 <title><varname>use_ruri_flag</varname> (integer)</title>
                 <para>
                 When this parameter is set to the value other than "-1" and the
@@ -237,17 +237,17 @@ modparam("auth_radius", "append_realm_to_username", 0)
 
 	<section>
 	<title>Functions</title>
-	<section>
+	<section id="auth_radius.f.radius_www_authorize">
 		<title><function moreinfo="none">radius_www_authorize(realm [, uri_user])</function></title>
 		<para>
-		The function verifies credentials according to 
-		<ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>. If 
-		the credentials are verified successfully then the function will 
-		succeed and mark the credentials as authorized (marked credentials can 
+		The function verifies credentials according to
+		<ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>. If
+		the credentials are verified successfully then the function will
+		succeed and mark the credentials as authorized (marked credentials can
 		be later used by some other functions).
 		</para>
 		<para>
-		If the function	was unable to  
+		If the function	was unable to
 		verify the credentials for some reason, it fails and
 		assigns a WWW-Authorize header containing a new
 	challenge to digest_challenge AVP (see modules/auth).
@@ -271,7 +271,8 @@ modparam("auth_radius", "append_realm_to_username", 0)
 			<emphasis>-4 (stale nonce)</emphasis> - stale nonce;
 			</para></listitem>
 			<listitem><para>
-			<emphasis>-2 (authorization failed)</emphasis> - RADIUS responded with Access Reject which may be, for example, due to user not found or wrong password;
+			<emphasis>-2 (authorization failed)</emphasis> - RADIUS responded
+			with Access Reject which may be, for example, due to user not found or wrong password;
 			</para></listitem>
 			<listitem><para>
 			<emphasis>-1 (error)</emphasis> - some error occurred during authorization (see syslog);
@@ -279,18 +280,18 @@ modparam("auth_radius", "append_realm_to_username", 0)
 		</itemizedlist>
 		<para>
 		This function will perform sanity checks over
-	the received  
+	the received
 		credentials and then pass them along to RADIUS
-	server which will  
+	server which will
 		verify the credentials and return whether they are valid or not.
 		</para>
 		<para>Meaning of the parameter is as follows:</para>
 		<itemizedlist>
 		<listitem>
 			<para><emphasis>realm</emphasis> - Realm is a
-	opaque string that  
+	opaque string that
 			the user agent should present to the user so he
-	can decide what  
+	can decide what
 			username and password to use.  In case of
 	REGISTER requests it is usually hostpart of To URI.
 			</para>
@@ -304,7 +305,7 @@ modparam("auth_radius", "append_realm_to_username", 0)
 			present, will be given to Radius server as value of
 			SIP-URI-User check item.
 			If uri_user pseudo variable parameter is not
-			present, the server will generate 
+			present, the server will generate
                         SIP-URI-User check item value from user part of
 			To/From URI.
 			</para>
@@ -339,17 +340,17 @@ modparam("auth_radius", "append_realm_to_username", 0)
 		</example>
 	</section>
 
-	<section>
+	<section id="auth_radius.f.radius_proxy_authorize">
 		<title><function
 		moreinfo="none">radius_proxy_authorize(realm [, uri_user])</function></title>
 		<para>
-		The function verifies credentials according to 
-		<ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>. If 
-		the credentials are verified successfully then the function will 
-		succeed and mark the credentials as authorized (marked credentials can 
-		be later used by some other functions).  
+		The function verifies credentials according to
+		<ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>. If
+		the credentials are verified successfully then the function will
+		succeed and mark the credentials as authorized (marked credentials can
+		be later used by some other functions).
 		</para>
-		<para>If the function was unable to  
+		<para>If the function was unable to
 		verify the credentials for some reason, it fails and
 		assigns a Proxy-Authorize header containing a new
 	challenge to digest_challenge AVP.  The script should
@@ -358,15 +359,15 @@ modparam("auth_radius", "append_realm_to_username", 0)
 		For negative result codes, see the above function.
 		</para>
 		<para>
-		This function will perform sanity checks over the received 
-		credentials and then pass them along to RADIUS server which will 
+		This function will perform sanity checks over the received
+		credentials and then pass them along to RADIUS server which will
 		verify the credentials and return whether they are valid or not.
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<listitem>
-			<para><emphasis>realm</emphasis> - Realm is a opaque string that 
-			the user agent should present to the user so he can decide what 
+			<para><emphasis>realm</emphasis> - Realm is a opaque string that
+			the user agent should present to the user so he can decide what
 			username and password to use.  In case of
 	non-REGISTER requests it is usually hostpart of From or
 		P-Preferred-Identity URI.
@@ -381,7 +382,7 @@ modparam("auth_radius", "append_realm_to_username", 0)
 			present, will be given to Radius server as value of
 			SIP-URI-User check item.
 			If uri_user pseudo variable parameter is not
-			present, the server will generate 
+			present, the server will generate
                         SIP-URI-User check item value from user part of
 			To/From URI.
 			</para>
diff --git a/src/modules/carrierroute/cr_db.c b/src/modules/carrierroute/cr_db.c
index 1668cdd..02cf94f 100644
--- a/src/modules/carrierroute/cr_db.c
+++ b/src/modules/carrierroute/cr_db.c
@@ -265,6 +265,7 @@ int load_user_carrier(str * user, str * domain) {
  */
 int load_route_data_db(struct route_data_t * rd) {
 	db1_res_t * res = NULL;
+	db1_res_t * prob_res = NULL;
 	db_row_t * row = NULL;
 	int i, ret;
 	struct carrier_data_t * tmp_carrier_data;
@@ -350,6 +351,7 @@ int load_route_data_db(struct route_data_t * rd) {
 		}
 	}
 	int n = 0;
+	boolean query_done = false;
 	do {
 		LM_DBG("loading, cycle %d", n++);
 		for (i = 0; i < RES_ROW_N(res); ++i) {
@@ -394,6 +396,35 @@ int load_route_data_db(struct route_data_t * rd) {
 					p_tmp_comment) == -1) {
 				goto errout;
 			}
+			if (row->values[COL_PROB].val.double_val == 0 && !query_done) {
+				int ret_tmp;
+				char query_tmp[QUERY_LEN];
+				str query_tmp_str;
+
+				memset(query_tmp, 0, QUERY_LEN);
+				ret_tmp = snprintf(query_tmp, QUERY_LEN, "SELECT * FROM %.*s WHERE %.*s=%d and %.*s=%d and %.*s>%d",
+						carrierroute_table.len, carrierroute_table.s, columns[COL_CARRIER]->len, columns[COL_CARRIER]->s, row->values[COL_CARRIER].val.int_val,
+						columns[COL_DOMAIN]->len, columns[COL_DOMAIN]->s, row->values[COL_DOMAIN].val.int_val, columns[COL_PROB]->len, columns[COL_PROB]->s, 0);
+
+				if (ret_tmp < 0) {
+					LM_ERR("error in snprintf while querying prob column");
+					goto errout;
+				}
+				query_tmp_str.s = query_tmp;
+				query_tmp_str.len = ret_tmp;
+
+				if (carrierroute_dbf.raw_query(carrierroute_dbh, &query_tmp_str, &prob_res) < 0) {
+					LM_ERR("Failed to query carrierroute db table based on prob column.\n");
+					goto errout;
+				}
+				if(RES_ROW_N(prob_res) == 0) {
+					LM_ERR("Carrierroute db table contains route(s) with only 0 probability.\n");
+					query_done = true;
+				}
+				carrierroute_dbf.free_result(carrierroute_dbh, prob_res);
+				prob_res = NULL;
+			}
+
 		}
 		if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) {
 			if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res,  cfg_get(carrierroute, carrierroute_cfg, fetch_rows)) < 0) {
@@ -460,5 +491,8 @@ errout:
 	if (res) {
 		carrierroute_dbf.free_result(carrierroute_dbh, res);
 	}
+	if (prob_res) {
+		carrierroute_dbf.free_result(carrierroute_dbh, prob_res);
+	}
 	return -1;
 }
diff --git a/src/modules/carrierroute/cr_db.h b/src/modules/carrierroute/cr_db.h
index 1f53c93..ffea731 100644
--- a/src/modules/carrierroute/cr_db.h
+++ b/src/modules/carrierroute/cr_db.h
@@ -88,4 +88,9 @@ int load_route_data_db (struct route_data_t * rd);
 
 int load_user_carrier(str * user, str * domain);
 
+typedef enum {
+	false = 0,
+	true = 1
+} boolean;
+
 #endif
diff --git a/src/modules/carrierroute/cr_func.c b/src/modules/carrierroute/cr_func.c
index cfa6146..3771978 100644
--- a/src/modules/carrierroute/cr_func.c
+++ b/src/modules/carrierroute/cr_func.c
@@ -471,7 +471,7 @@ static int rewrite_on_rule(struct route_flags *rf_head, flag_t flags, str * dest
 			avp_value_t cr_new_uri;
 
 			if(rf->dice_max == 0) {
-				LM_ERR("invalid dice_max value\n");
+				LM_ERR("invalid dice_max value (route has probability 0)\n");
 				return -1;
 			}
 			if ((prob = hash_func(msg, hash_source, rf->dice_max)) < 0) {
diff --git a/src/modules/cfgutils/cfgutils.c b/src/modules/cfgutils/cfgutils.c
index 86a0b11..bfde867 100644
--- a/src/modules/cfgutils/cfgutils.c
+++ b/src/modules/cfgutils/cfgutils.c
@@ -134,9 +134,9 @@ static cmd_export_t cmds[]={
 		ANY_ROUTE},
 	{"rand_event",      (cmd_function)rand_event, 0, 0, 0,
 		ANY_ROUTE},
-	{"sleep",  (cmd_function)m_sleep,  1, fixup_igp_null, 0,
+	{"sleep",  (cmd_function)m_sleep,  1, fixup_igp_null, fixup_free_igp_null,
 		ANY_ROUTE},
-	{"usleep", (cmd_function)m_usleep, 1, fixup_igp_null, 0,
+	{"usleep", (cmd_function)m_usleep, 1, fixup_igp_null, fixup_free_igp_null,
 		ANY_ROUTE},
 	{"abort",      (cmd_function)dbg_abort,        0, 0, 0,
 		ANY_ROUTE},
@@ -162,9 +162,9 @@ static cmd_export_t cmds[]={
 		ANY_ROUTE},
 	{"core_hash",    (cmd_function)w_core_hash, 3,   fixup_core_hash, 0,
 		ANY_ROUTE},
-	{"check_route_exists",    (cmd_function)w_check_route_exists, 1,   0, 0,
+	{"check_route_exists",    (cmd_function)w_check_route_exists, 1,   fixup_spve_null, fixup_free_spve_null,
 		ANY_ROUTE},
-	{"route_if_exists",    (cmd_function)w_route_exists, 1,   0, 0,
+	{"route_if_exists",    (cmd_function)w_route_exists, 1,   fixup_spve_null, fixup_free_spve_null,
 		ANY_ROUTE},
 	{"bind_cfgutils", (cmd_function)bind_cfgutils,  0,
 		0, 0, 0},
@@ -600,7 +600,6 @@ static int m_sleep(struct sip_msg *msg, char *time, char *str2)
 		LM_ERR("cannot get time interval value\n");
 		return -1;
 	}
-	LM_DBG("sleep %lu seconds\n", (unsigned long)s);
 	sleep((unsigned int)s);
 	return 1;
 }
@@ -613,7 +612,6 @@ static int m_usleep(struct sip_msg *msg, char *time, char *str2)
 		LM_ERR("cannot get time interval value\n");
 		return -1;
 	}
-	LM_DBG("sleep %lu microseconds\n", (unsigned long)time);
 	sleep_us((unsigned int)s);
 	return 1;
 }
@@ -731,7 +729,14 @@ static int w_cfg_trylock(struct sip_msg *msg, char *key, char *s2)
  */
 static int w_check_route_exists(struct sip_msg *msg, char *route)
 {
-	if (route_lookup(&main_rt, route)<0) {
+	str s;
+
+	if (fixup_get_svalue(msg, (gparam_p) route, &s) != 0)
+	{
+			LM_ERR("invalid route parameter\n");
+			return -1;
+	}
+	if (route_lookup(&main_rt, s.s)<0) {
 		/* not found */
 		return -1;
 	}
@@ -744,16 +749,27 @@ static int w_route_exists(struct sip_msg *msg, char *route)
 {
 	struct run_act_ctx ctx;
 	int newroute, backup_rt, ret;
+	str s;
 
-	newroute = route_lookup(&main_rt, route);
+	if (fixup_get_svalue(msg, (gparam_p) route, &s) != 0)
+	{
+			LM_ERR("invalid route parameter\n");
+			return -1;
+	}
+
+	newroute = route_lookup(&main_rt, s.s);
 	if (newroute<0) {
 		return -1;
 	}
 	backup_rt = get_route_type();
 	set_route_type(REQUEST_ROUTE);
+
 	init_run_actions_ctx(&ctx);
 	ret = run_top_route(main_rt.rlist[newroute], msg, &ctx);
 	set_route_type(backup_rt);
+	if (ctx.run_flags & EXIT_R_F) {
+		return 0;
+	}
 	return ret;
 }
 
diff --git a/src/modules/cnxcc/README b/src/modules/cnxcc/README
index 5ec0fa9..f2bd975 100644
--- a/src/modules/cnxcc/README
+++ b/src/modules/cnxcc/README
@@ -41,11 +41,11 @@ Carlos Ruiz Díaz
 
         6. Events
         7. Web Interface
-        8. Sample
+        8. Sample Config
 
    List of Examples
 
-   1.1. dlg_flag
+   1.1.
    1.2. credit_check_period
    1.3. cnxcc_set_max_credit()
    1.4. cnxcc_set_max_time()
@@ -86,7 +86,7 @@ Chapter 1. Admin Guide
 
    6. Events
    7. Web Interface
-   8. Sample
+   8. Sample Config
 
 1. Overview
 
@@ -138,11 +138,11 @@ Chapter 1. Admin Guide
    3.1. redis (integer)
    3.2. credit_check_period (integer)
 
-3.1.  redis (integer)
+3.1. redis (integer)
 
    Redis datasource connection information
 
-   Example 1.1. dlg_flag
+   Example 1.1.
 ...
 modparam("cnxcc", "redis", "addr=127.0.0.1;port=6379;db=1")
 ...
@@ -354,7 +354,7 @@ event_route[cnxcc:call-shutdown]
 
    Link: https://github.com/caruizdiaz/cnxcc-web
 
-8. Sample
+8. Sample Config
 
    Example 1.8. kamailio-cnxcc.cfg
 ...
diff --git a/src/modules/cnxcc/doc/cnxcc_admin.xml b/src/modules/cnxcc/doc/cnxcc_admin.xml
index 79a97c1..ae905e9 100644
--- a/src/modules/cnxcc/doc/cnxcc_admin.xml
+++ b/src/modules/cnxcc/doc/cnxcc_admin.xml
@@ -17,7 +17,7 @@
 	<para>
 		This module was designed to act as a mechanism to limit call duration based on credit information parameters.
 		After getting the credit information of the call being set up, you can instruct the module to start monitoring
-		the consumed credit to shutdown a single call or a group of calls in case of credit exhaustion.	
+		the consumed credit to shutdown a single call or a group of calls in case of credit exhaustion.
 	</para>
 	<para>
 		Every call is associated to an unique client/customer identifier. If a credit event occurs, all calls hooked
@@ -49,7 +49,7 @@
 	<section>
 	    <title>Modules</title>
 	    <para>
-		The following module must be loaded before this module: 
+		The following module must be loaded before this module:
 		<itemizedlist>
 		    <listitem>
 		    <para>
@@ -62,7 +62,7 @@
 	<section>
 	    <title>Libraries</title>
 	    <para>
-		The following module must be loaded before this module: 
+		The following module must be loaded before this module:
 		<itemizedlist>
 		    <listitem>
 		    <para>
@@ -83,23 +83,22 @@
 
     <section>
 	<title>Parameters</title>
-	<section>
-		<title><varname> redis </varname> (integer)</title>
+	<section id="cnxcc.p.redis">
+		<title><varname>redis</varname> (integer)</title>
 	    <para>
 		Redis datasource connection information
 	    </para>
 	    <example>
 
-		<title>dlg_flag</title>
 		<programlisting format="linespecific">
 ...
 modparam("cnxcc", "redis", "addr=127.0.0.1;port=6379;db=1")
-...		
+...
 		</programlisting>
 	    </example>
 	</section>
 
-	<section>
+	<section id="cnxcc.p.credit_check_period">
 	    <title><varname>credit_check_period</varname> (integer)</title>
 	    <para>
 		Indicates how often the credit checking function should be called. It is directly related to the precison of the
@@ -114,15 +113,15 @@ modparam("cnxcc", "redis", "addr=127.0.0.1;port=6379;db=1")
 		<programlisting format="linespecific">
 ...
 modparam("cnxcc", "credit_check_period", 1)
-...		
+...
 		</programlisting>
 	    </example>
-	</section> 
+	</section>
    </section>
 
     <section>
 	<title>Functions</title>
-	<section>
+	<section id="cnxcc.f.set_max_credit">
 	    <title>
 		<function moreinfo="none">cnxcc_set_max_credit()</function>
 	    </title>
@@ -164,12 +163,12 @@ $var(initial_p)   = "030";    # intial pulse
 $var(final_p)   = "006";      # final pulse
 
 cnxcc_set_max_credit("$var(customer)", "$var(credit)", "$var(cps)", "$var(initial_p)", "$var(final_p)");
-...		
+...
 		</programlisting>
 	    </example>
 	</section>
 
-        <section>
+        <section id="cnxcc.f.set_max_time">
             <title>
                 <function moreinfo="none">cnxcc_set_max_time()</function>
             </title>
@@ -184,7 +183,7 @@ cnxcc_set_max_credit("$var(customer)", "$var(credit)", "$var(cps)", "$var(initia
                         <emphasis>1 - successful</emphasis>
                     </para>
                     </listitem>
-                     
+
                     <listitem>
                     <para>
                         <emphasis>-1 - failed, error logged</emphasis>
@@ -205,7 +204,7 @@ cnxcc_set_max_time("$var(customer)", "$var(max_time)");
             </example>
         </section>
 
-        <section>
+        <section id="cnxcc.f.update_max_time">
             <title>
                 <function moreinfo="none">cnxcc_update_max_time()</function>
             </title>
@@ -220,7 +219,7 @@ cnxcc_set_max_time("$var(customer)", "$var(max_time)");
                         <emphasis>1 - successful</emphasis>
                     </para>
                     </listitem>
-                     
+
                     <listitem>
                     <para>
                         <emphasis>-1 - failed, error logged</emphasis>
@@ -248,7 +247,7 @@ cnxcc_set_max_time("$var(customer)", "$var(max_time)");
 
 
 
-    	<section>
+    	<section id="cnxcc.f.set_max_channel">
             <title>
                 <function moreinfo="none">cnxcc_set_max_channel()</function>
             </title>
@@ -263,7 +262,7 @@ cnxcc_set_max_time("$var(customer)", "$var(max_time)");
                         <emphasis>1 - successful</emphasis>
                     </para>
                     </listitem>
-                     
+
                     <listitem>
                     <para>
                         <emphasis>-1 - failed, error logged</emphasis>
@@ -275,7 +274,7 @@ cnxcc_set_max_time("$var(customer)", "$var(max_time)");
                         <emphasis>-2 - failed, calls established plus calls being established result in more than the limit you specified</emphasis>
                     </para>
                     </listitem>
-		    
+
 		    <listitem>
                     <para>
                         <emphasis>-3 - failed, number of calls established is more than the limit you specified</emphasis>
@@ -312,8 +311,8 @@ if ($var(retcode) < -1) {
 		</programlisting>
             </example>
     	</section>
-	
-    	<section>
+
+    	<section id="cnxcc.f.terminate_all">
             <title>
                 <function moreinfo="none">cnxcc_terminate_all()</function>
             </title>
@@ -328,7 +327,7 @@ if ($var(retcode) < -1) {
                         <emphasis>1 - successful</emphasis>
                     </para>
                     </listitem>
-                     
+
                     <listitem>
                     <para>
                         <emphasis>-1 - failed, error logged</emphasis>
@@ -350,12 +349,12 @@ if (!cnxcc_terminate_all("$var(customer)")) {
             </example>
         </section>
     </section>
-   
+
     <section>
 	<title>RPC Commands</title>
 
-	<section>
-	    <title><varname>cnxcc.active_clients</varname></title>
+	<section id="cnxcc.rpc.active_clients">
+	    <title>cnxcc.active_clients</title>
 	    <para>
 		Retrieves all calls grouped by their identifiers.
 	    </para>
@@ -370,8 +369,8 @@ if (!cnxcc_terminate_all("$var(customer)")) {
 	    </programlisting>
 	</section>
 
-	<section>
-            <title><varname>cnxcc.check_client</varname></title>
+	<section id="cnxcc.rpc.check_client">
+            <title>cnxcc.check_client</title>
             <para>
 		Retrives all calls from a particular identifier.
             </para>
@@ -386,8 +385,8 @@ if (!cnxcc_terminate_all("$var(customer)")) {
             </programlisting>
         </section>
 
-        <section>
-            <title><varname>cnxcc.kill_call</varname></title>
+        <section id="cnxcc.rpc.kill_call">
+            <title>cnxcc.kill_call</title>
             <para>
 		    Kills an active call using its call ID.
 	    </para>
@@ -401,8 +400,8 @@ if (!cnxcc_terminate_all("$var(customer)")) {
             &sercmd; cnxcc.kill_call qumojlaahitafih at carlosrdcnx-laptop.site
             </programlisting>
         </section>
-	<section>
-	    <title><varname>cnxcc.stats</varname></title>
+	<section id="cnxcc.rpc.stats">
+	    <title>cnxcc.stats</title>
 	    <para>
 		List credit control stats.
 	    </para>
@@ -419,9 +418,9 @@ if (!cnxcc_terminate_all("$var(customer)")) {
 
     </section>
 
-    <section>
+    <section id="cnxcc.evr.callshutdown">
 	    <title>Events</title>
-	    
+
 	    <para>
 		When a call is forced to end an event route is automatically invoked. This route is suited with a fake OPTIONS
 		message containing the call ID, ftag and ttag of the original call so it can be located somehow in the accounting
@@ -440,14 +439,14 @@ event_route[cnxcc:call-shutdown]
 }
 ...
 		</programlisting>
-	    
+
     </section>
     <section>
             <title>Web Interface</title>
 
             <para>
 		The module contains a web management interface completely optional. With it, you can review your calls in real time
-		and hang them up if necessary.    
+		and hang them up if necessary.
 	    </para>
             <para>
                 Link: https://github.com/caruizdiaz/cnxcc-web
@@ -455,7 +454,7 @@ event_route[cnxcc:call-shutdown]
     </section>
 
     <section>
-	<title>Sample</title>
+	<title>Sample Config</title>
 	<example>
 	    <title>kamailio-cnxcc.cfg</title>
 	    <programlisting format="linespecific">
@@ -482,7 +481,7 @@ event_route[cnxcc:call-shutdown]
 	xlog("L_INFO", "[$ci]: call killed");
 
 
-}	    
+}
 ...
 	    </programlisting>
 	</example>
diff --git a/src/modules/cplc/doc/cplc_admin.xml b/src/modules/cplc/doc/cplc_admin.xml
index 9d7ed77..fad0654 100644
--- a/src/modules/cplc/doc/cplc_admin.xml
+++ b/src/modules/cplc/doc/cplc_admin.xml
@@ -89,7 +89,7 @@
 
 	<section>
 		<title>Parameters</title>
-		<section>
+		<section id="cplc.p.db_url">
 			<title><varname>db_url</varname> (string)</title>
 			<para>
 				A SQL URL have to be given to the module for knowing where the
@@ -111,7 +111,7 @@ modparam("cpl-c","db_url","&exampledb;")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.db_table">
 			<title><varname>db_table</varname> (string)</title>
 			<para>
 				Indicates the name of the table that store the CPL scripts.
@@ -133,7 +133,7 @@ modparam("cpl-c","cpl_table","cpl")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.username_column">
 			<title><varname>username_column</varname> (string)</title>
 			<para>
 				Indicates the name of the column used for storing the username.
@@ -152,7 +152,7 @@ modparam("cpl-c","username_column","username")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.domain_column">
 			<title><varname>domain_column</varname> (string)</title>
 			<para>
 				Indicates the name of the column used for storing the domain.
@@ -171,7 +171,7 @@ modparam("cpl-c","domain_column","domain")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.xml_column">
 			<title><varname>cpl_xml_column</varname> (string)</title>
 			<para>
 				Indicates the name of the column used for storing the
@@ -191,7 +191,7 @@ modparam("cpl-c","cpl_xml_column","cpl_xml")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.bin_column">
 			<title><varname>cpl_bin_column</varname> (string)</title>
 			<para>
 				Indicates the name of the column used for storing the
@@ -211,7 +211,7 @@ modparam("cpl-c","cpl_bin_column","cpl_bin")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.dtd_file">
 			<title><varname>cpl_dtd_file</varname> (string)</title>
 			<para>
 				Points to the DTD file describing the CPL grammar. The file
@@ -233,7 +233,7 @@ modparam("cpl-c","cpl_dtd_file","/etc/kamailio/cpl-06.dtd")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.log_dir">
 			<title><varname>log_dir</varname> (string)</title>
 			<para>
 				Points to a directory where should be created all the log file
@@ -255,7 +255,7 @@ modparam("cpl-c","log_dir","/var/log/kamailio/cpl")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.proxy_recurse">
 			<title><varname>proxy_recurse</varname> (int)</title>
 			<para>
 				Tells for how many time is allow to have recurse for PROXY CPL
@@ -279,7 +279,7 @@ modparam("cpl-c","proxy_recurse",2)
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.proxy_route">
 			<title><varname>proxy_route</varname> (string)</title>
 			<para>
 				Before doing proxy (forward), a script route can be executed.
@@ -300,7 +300,7 @@ modparam("cpl-c","proxy_route","1")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.case_sensitive">
 			<title><varname>case_sensitive</varname> (int)</title>
 			<para>
 				Tells if the username matching should be perform case
@@ -321,7 +321,7 @@ modparam("cpl-c","case_sensitive",1)
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.realm_prefix">
 			<title><varname>realm_prefix</varname> (string)</title>
 			<para>
 				Defines a prefix for the domain part which should be ignored
@@ -341,7 +341,7 @@ modparam("cpl-c","realm_prefix","sip.")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.timer_avp">
 			<title><varname>timer_avp</varname> (string)</title>
 			<para>
 				Full specification (ID, NAME, ALIAS) of the AVP to be used to
@@ -366,7 +366,7 @@ modparam("cpl-c","timer_avp","$avp(i:14)")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.lookup_domain">
 			<title><varname>lookup_domain</varname> (string)</title>
 			<para>
 				Used by lookup tag to indicate where to perform user location.
@@ -391,7 +391,7 @@ modparam("cpl-c","lookup_domain","location")
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.lookup_append_branches">
 			<title><varname>lookup_append_branches</varname> (int)</title>
 			<para>
 				Tells if the lookup tag should append branches (to do parallel
@@ -414,7 +414,7 @@ modparam("cpl-c","lookup_append_branches",1)
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.use_domain">
 			<title><varname>use_domain</varname> (integer)</title>
 			<para>
 				Indicates if the domain part of the URI should be used in
@@ -441,7 +441,7 @@ modparam("cpl-c","use_domain",1)
 
 	<section>
 		<title>Functions</title>
-		<section>
+		<section id="cplc.f.cpl_run_script">
 			<title>
 				<function moreinfo="none">cpl_run_script(type,mode, [uri])</function>
 			</title>
@@ -539,7 +539,7 @@ cpl_run_script("incoming","force_stateful");
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.f.process_register">
 			<title>
 				<function moreinfo="none">cpl_process_register()</function>
 			</title>
@@ -578,7 +578,7 @@ if (method=="REGISTER") {
 </programlisting>
 			</example>
 		</section>
-		<section>
+		<section id="cplc.p.process_register_norpl">
 			<title>
 				<function moreinfo="none">cpl_process_register_norpl()
 					</function>
diff --git a/src/modules/db_postgres/README b/src/modules/db_postgres/README
index 7bfd597..7640f36 100644
--- a/src/modules/db_postgres/README
+++ b/src/modules/db_postgres/README
@@ -26,6 +26,7 @@ Greg Fausak
               3.1. retries (integer)
               3.2. timeout (integer)
               3.3. tcp_keepalive (integer)
+              3.4. lockset (integer)
 
         4. Functions
 
@@ -34,6 +35,7 @@ Greg Fausak
    1.1. Set retries parameter
    1.2. Set timeout parameter
    1.3. Set tcp_keepalive parameter
+   1.4. Set lockset parameter
 
 Chapter 1. Admin Guide
 
@@ -50,6 +52,7 @@ Chapter 1. Admin Guide
         3.1. retries (integer)
         3.2. timeout (integer)
         3.3. tcp_keepalive (integer)
+        3.4. lockset (integer)
 
    4. Functions
 
@@ -81,6 +84,7 @@ Chapter 1. Admin Guide
    3.1. retries (integer)
    3.2. timeout (integer)
    3.3. tcp_keepalive (integer)
+   3.4. lockset (integer)
 
 3.1. retries (integer)
 
@@ -127,6 +131,18 @@ modparam("db_postgres", "timeout", 10)
 modparam("db_postgres", "tcp_keepalive", 600)
 ...
 
+3.4. lockset (integer)
+
+   The value is used as power of two to compute the size of the lock set
+   needed to implement the equivalent of REPLACE SQL statement.
+
+   Default value is 4 (lock set size is 16).
+
+   Example 1.4. Set lockset parameter
+...
+modparam("db_postgres", "lockset", 6)
+...
+
 4. Functions
 
    NONE
diff --git a/src/modules/db_postgres/doc/db_postgres_admin.xml b/src/modules/db_postgres/doc/db_postgres_admin.xml
index 49bd882..e218294 100644
--- a/src/modules/db_postgres/doc/db_postgres_admin.xml
+++ b/src/modules/db_postgres/doc/db_postgres_admin.xml
@@ -11,9 +11,9 @@
 <!-- Module User's Guide -->
 
 <chapter>
-	
+
 	<title>&adminguide;</title>
-	
+
 	<section>
 	<title>Overview</title>
 	<para>The module is an implementation of the internal DB API v1 and v2
@@ -130,6 +130,27 @@ modparam("db_postgres", "tcp_keepalive", 600)
 </programlisting>
 		</example>
 	</section>
+
+	<section>
+		<title><varname>lockset</varname> (integer)</title>
+		<para>
+			The value is used as power of two to compute the size of the
+			lock set needed to implement the equivalent of REPLACE SQL
+			statement.
+		</para>
+		<para>
+			Default value is 4 (lock set size is 16).
+		</para>
+		<example>
+		<title>Set <varname>lockset</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("db_postgres", "lockset", 6)
+...
+</programlisting>
+		</example>
+	</section>
+
 	</section>
 
 	<section>
diff --git a/src/modules/dialog/README b/src/modules/dialog/README
index 18b10a1..6c326e4 100644
--- a/src/modules/dialog/README
+++ b/src/modules/dialog/README
@@ -1833,10 +1833,11 @@ kamcmd dlg.profile_list inbound_calls
      * from - SIP address to initiate the call
      * to - SIP address to refer 'from' to
      * op (optional) - outbound proxy SIP address
+     * body (optional) - SDP body for initial INVITE
 
    RPC Command Format:
 ...
-kamcmd dlg.list _from_ _to_ _op_
+kamcmd dlg.bridge_dlg _from_ _to_ _op_
 ...
 
 10. Exported Variables
@@ -1898,15 +1899,17 @@ kamcmd dlg.list _from_ _to_ _op_
 
 11.1. event_route[dialog:start]
 
-   Executed when 200OK for INVITE is processed.
+   Executed when 200OK reply for INVITE is processed.
 
 11.2. event_route[dialog:end]
 
-   Executed when BYE is processed or dialog timed out.
+   Executed when the BYE for the call is processed or the dialog timed
+   out.
 
 11.3. event_route[dialog:failed]
 
-   Executed when dialog is not completed (+300 reply to INVITE).
+   Executed when dialog is not completed (300 or greater reply code to
+   INVITE).
 
 Chapter 2. Developer Guide
 
diff --git a/src/modules/dialog/dlg_cseq.c b/src/modules/dialog/dlg_cseq.c
index 62e8ba3..716bde7 100644
--- a/src/modules/dialog/dlg_cseq.c
+++ b/src/modules/dialog/dlg_cseq.c
@@ -59,12 +59,16 @@ static int dlg_cseq_prepare_msg(sip_msg_t *msg)
 	LM_DBG("prepare msg for cseq update operations\n");
 
 	if(msg->first_line.type==SIP_REQUEST) {
-		if(!IS_SIP(msg))
-		{
+		if(!IS_SIP(msg)) {
 			LM_DBG("non sip request message\n");
 			return 1;
 		}
-	} else if(msg->first_line.type!=SIP_REPLY) {
+	} else if(msg->first_line.type==SIP_REPLY) {
+		if(!IS_SIP_REPLY(msg)) {
+			LM_DBG("non sip reply message\n");
+			return 1;
+		}
+	} else {
 		LM_DBG("non sip message\n");
 		return 1;
 	}
diff --git a/src/modules/dialog/dlg_handlers.c b/src/modules/dialog/dlg_handlers.c
index dbef1c2..642f9c1 100644
--- a/src/modules/dialog/dlg_handlers.c
+++ b/src/modules/dialog/dlg_handlers.c
@@ -245,14 +245,15 @@ int populate_leg_info( struct dlg_cell *dlg, struct sip_msg *msg,
 	if(leg==DLG_CALLER_LEG)
 		dlg->from_rr_nb = skip_recs;
 
-	LM_DBG("route_set %.*s, contact %.*s, cseq %.*s and bind_addr %.*s\n",
-		rr_set.len, rr_set.s, contact.len, contact.s,
+	LM_DBG("leg(%d) route_set [%.*s], contact [%.*s], cseq [%.*s]"
+			" and bind_addr [%.*s]\n",
+		leg, rr_set.len, rr_set.s, contact.len, contact.s,
 		cseq.len, cseq.s,
 		msg->rcv.bind_address->sock_str.len,
 		msg->rcv.bind_address->sock_str.s);
 
 	if (dlg_set_leg_info( dlg, tag, &rr_set, &contact, &cseq, leg)!=0) {
-		LM_ERR("dlg_set_leg_info failed\n");
+		LM_ERR("dlg_set_leg_info failed (leg %d)\n", leg);
 		if (rr_set.s) pkg_free(rr_set.s);
 		goto error0;
 	}
diff --git a/src/modules/dialog/doc/dialog_admin.xml b/src/modules/dialog/doc/dialog_admin.xml
index 68218a6..36cc98c 100644
--- a/src/modules/dialog/doc/dialog_admin.xml
+++ b/src/modules/dialog/doc/dialog_admin.xml
@@ -2244,7 +2244,7 @@ dlg_remote_profile("add", "caller", "test", "$sruid", "$var(exp)");
 		</programlisting>
 		</section>
 		<section>
-			<title><varname>dlg.end_dlg</varname></title>
+			<title>dlg.end_dlg</title>
 			<para>
 			Terminates an ongoing dialog by sending BYE in both directions.
 			</para>
@@ -2353,11 +2353,15 @@ dlg_remote_profile("add", "caller", "test", "$sruid", "$var(exp)");
 			<listitem><para>
 				<emphasis>op</emphasis> (optional) - outbound proxy SIP address
 			</para></listitem>
+			<listitem><para>
+				<emphasis>body</emphasis> (optional) - SDP body for initial
+				INVITE
+			</para></listitem>
 		</itemizedlist>
 		<para>RPC Command Format:</para>
 		<programlisting  format="linespecific">
 ...
-&kamcmd; dlg.list _from_ _to_ _op_
+&kamcmd; dlg.bridge_dlg _from_ _to_ _op_
 ...
 		</programlisting>
 		</section>
@@ -2444,21 +2448,23 @@ dlg_remote_profile("add", "caller", "test", "$sruid", "$var(exp)");
 	<section>
 	<title>Event Routes</title>
 		<section>
-			<title><varname>event_route[dialog:start]</varname></title>
+			<title>event_route[dialog:start]</title>
 			<para>
-			Executed when 200OK for INVITE is processed.
+			Executed when 200OK reply for INVITE is processed.
 			</para>
 		</section>
 		<section>
-			<title><varname>event_route[dialog:end]</varname></title>
+			<title>event_route[dialog:end]</title>
 			<para>
-			Executed when BYE is processed or dialog timed out.
+			Executed when the BYE for the call is processed
+			or the dialog timed out.
 			</para>
 		</section>
 		<section>
-			<title><varname>event_route[dialog:failed]</varname></title>
+			<title>event_route[dialog:failed]</title>
 			<para>
-			Executed when dialog is not completed (+300 reply to INVITE).
+			Executed when dialog is not completed (300 or greater reply code
+			to INVITE).
 			</para>
 		</section>
 	</section>
diff --git a/src/modules/domain/domain_mod.c b/src/modules/domain/domain_mod.c
index 179d847..3c16fe0 100644
--- a/src/modules/domain/domain_mod.c
+++ b/src/modules/domain/domain_mod.c
@@ -290,30 +290,46 @@ static void domain_rpc_dump(rpc_t *rpc, void *ctx)
 	struct domain_list *np;
 	struct attr_list *ap;
 	struct domain_list **ht;
+	void *rt;
+	void *at;
 	void *st;
 
 	if(hash_table == 0 || *hash_table == 0) {
 		rpc->fault(ctx, 404, "Server Domain Cache Empty");
 		return;
 	}
+	if(rpc->add(ctx, "{", &rt) < 0) {
+		rpc->fault(ctx, 500, "Failed to create root struct");
+		return;
+	}
+	if(rpc->struct_add(rt, "[", "domains", &at) < 0) {
+		rpc->fault(ctx, 500, "Failed to create domains struct");
+		return;
+	}
+
 	ht = *hash_table;
 	for(i = 0; i < DOM_HASH_SIZE; i++) {
 		np = ht[i];
 		while(np) {
-			if(rpc->add(ctx, "{", &st) < 0)
+			if(rpc->array_add(at, "{", &st) < 0)
 				return;
 			rpc->struct_add(st, "SS", "domain", &np->domain, "did", &np->did);
 			np = np->next;
 		}
 	}
+	if(rpc->struct_add(rt, "[", "attributes", &at) < 0) {
+		rpc->fault(ctx, 500, "Failed to create attributes struct");
+		return;
+	}
 	np = ht[DOM_HASH_SIZE];
 	while(np) {
-		if(rpc->add(ctx, "{", &st) < 0)
+		if(rpc->array_add(at, "{", &st) < 0)
 			return;
 		rpc->struct_add(st, "S", "did", &np->did);
+		rpc->struct_add(st, "[", "attrs", &st);
 		ap = np->attrs;
 		while(ap) {
-			rpc->struct_add(st, "S", "attr", &ap->name);
+			rpc->array_add(st, "S", &ap->name);
 			ap = ap->next;
 		}
 		np = np->next;
@@ -325,7 +341,9 @@ static void domain_rpc_dump(rpc_t *rpc, void *ctx)
 
 rpc_export_t domain_rpc_list[] = {
 		{"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0},
-		{"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0}, {0, 0, 0, 0}};
+		{"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0},
+		{0, 0, 0, 0}
+};
 
 static int domain_init_rpc(void)
 {
@@ -334,4 +352,4 @@ static int domain_init_rpc(void)
 		return -1;
 	}
 	return 0;
-}
\ No newline at end of file
+}
diff --git a/src/modules/domainpolicy/README b/src/modules/domainpolicy/README
index 4e0870e..29ad907 100644
--- a/src/modules/domainpolicy/README
+++ b/src/modules/domainpolicy/README
@@ -49,14 +49,13 @@ Klaus Darilion
               4.1. dp_can_connect()
               4.2. dp_apply_policy()
 
-        5. RPC Commands
-        6. Usage Scenarios
+        5. Usage Scenarios
 
-              6.1. TLS Based Federation
-              6.2. SIP Hub based Federation
-              6.3. Walled Garden Federation
+              5.1. TLS Based Federation
+              5.2. SIP Hub based Federation
+              5.3. Walled Garden Federation
 
-        7. Known Limitations
+        6. Known Limitations
 
    List of Examples
 
@@ -101,14 +100,13 @@ Chapter 1. Admin Guide
         4.1. dp_can_connect()
         4.2. dp_apply_policy()
 
-   5. RPC Commands
-   6. Usage Scenarios
+   5. Usage Scenarios
 
-        6.1. TLS Based Federation
-        6.2. SIP Hub based Federation
-        6.3. Walled Garden Federation
+        5.1. TLS Based Federation
+        5.2. SIP Hub based Federation
+        5.3. Walled Garden Federation
 
-   7. Known Limitations
+   6. Known Limitations
 
 1. Overview
 
@@ -407,18 +405,16 @@ if (dp_apply_policy()) {
 }
 ...
 
-5. RPC Commands
+5. Usage Scenarios
 
-6. Usage Scenarios
-
-   6.1. TLS Based Federation
-   6.2. SIP Hub based Federation
-   6.3. Walled Garden Federation
+   5.1. TLS Based Federation
+   5.2. SIP Hub based Federation
+   5.3. Walled Garden Federation
 
    This section describes how this module can be use to implement
    selective VoIP peerings.
 
-6.1. TLS Based Federation
+5.1. TLS Based Federation
 
    This example shows how a secure peering fabric can be configured based
    on TLS and Domain Policies.
@@ -460,7 +456,7 @@ tls_client_domain["tlsfed"] {
  tls_verify_server = 1
 }
 
-6.2. SIP Hub based Federation
+5.2. SIP Hub based Federation
 
    This example shows how a peering fabric based on a central SIP hub can
    be configured.
@@ -490,7 +486,7 @@ mysql> select * from domainpolicy;
 | 1  | http://HUBFED.org/ | fed  | domainreplacement | sip.HUBFED.org |
 +----+--------------------+------+-------------------+----------------+
 
-6.3. Walled Garden Federation
+5.3. Walled Garden Federation
 
    This example assumes that a set of SIP providers have established a
    secure Layer 3 network between their proxies. It does not matter
@@ -529,4 +525,4 @@ mysql> select * from domainpolicy;
 | 1  | http://l3fed.org/ | fed  | domainprefix | l3fed |
 +----+-------------------+------+--------------+-------+
 
-7. Known Limitations
+6. Known Limitations
diff --git a/src/modules/domainpolicy/doc/domainpolicy_admin.xml b/src/modules/domainpolicy/doc/domainpolicy_admin.xml
index 71bcc32..4a61375 100644
--- a/src/modules/domainpolicy/doc/domainpolicy_admin.xml
+++ b/src/modules/domainpolicy/doc/domainpolicy_admin.xml
@@ -50,13 +50,13 @@
 
 	<section>
 	<title>Parameters</title>
-	<section>
+	<section id="dompolicy.p.db_url">
 		<title><varname>db_url</varname> (string)</title>
 		<para>
 		This is <acronym>URL</acronym> of the database to be used.
 		</para>
 		<para>
-		Default value is 
+		Default value is
 			<quote>&defaultdb;</quote>
 		</para>
 		<example>
@@ -66,7 +66,7 @@ modparam("domainpolicy", "db_url", "&exampleotherdb;")
 		</programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.dp_table">
 		<title><varname>dp_table</varname> (string)</title>
 		<para>
 		Name of table containing the local support domain policy setup.
@@ -81,7 +81,7 @@ modparam("domainpolicy", "dp_table", "supportedpolicies")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.col_rule">
 		<title><varname>dp_col_rule</varname> (string)</title>
 		<para>
 		Name of column containing the domain policy rule name which is equal
@@ -97,7 +97,7 @@ modparam("domainpolicy", "dp_col_rule", "rules")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.col_type">
 		<title><varname>dp_col_type</varname> (string)</title>
 		<para>
 		Name of column containing the domain policy rule type.
@@ -117,7 +117,7 @@ modparam("domainpolicy", "dp_col_type", "type")
 	</section>
 
 
-	<section>
+	<section id="dompolicy.p.col_att">
 		<title><varname>dp_col_att</varname> (string)</title>
 		<para>
 		Name of column containing the AVP's name. If the rule stored in this
@@ -133,7 +133,7 @@ modparam("domainpolicy", "dp_col_att", "attribute")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.col_val">
 		<title><varname>dp_col_val</varname> (string)</title>
 		<para>
 		Name of column containing the value for AVPs created by dp_can_connect().
@@ -148,11 +148,11 @@ modparam("domainpolicy", "dp_col_val", "values")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.port_override_avp">
 		<title><varname>port_override_avp</varname> (string)</title>
 		<para>
 		This parameter defines the name of the AVP where dp_apply_policy() will look
-		for an override port number. 
+		for an override port number.
 		</para>
 		<para>
 		Default value is <quote>portoverride</quote>.
@@ -165,10 +165,10 @@ modparam("domainpolicy", "port_override_avp", "portoverride")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.p.transport_override_avp">
 		<title><varname>transport_override_avp</varname> (string)</title>
 		<para>
-		Name of the AVP which contains the override transport setting. 
+		Name of the AVP which contains the override transport setting.
 		</para>
 		<para>
 		Default value is <quote>transportoverride</quote>.
@@ -185,7 +185,7 @@ modparam("domainpolicy", "transport_override_avp", "transportoverride")
 	<section>
 		<title><varname>domain_replacement_avp</varname> (string)</title>
 		<para>
-		Name of the AVP which contains a domain replacement. 
+		Name of the AVP which contains a domain replacement.
 		</para>
 		<para>
 		Default value is <quote>domainreplacement</quote>.
@@ -202,7 +202,7 @@ modparam("domainpolicy", "domain_replacement_avp", "domainreplacement")
 	<section>
 		<title><varname>domain_prefix_avp</varname> (string)</title>
 		<para>
-		Name of the AVP which contains a domain prefix. 
+		Name of the AVP which contains a domain prefix.
 		</para>
 		<para>
 		Default value is <quote>domainprefix</quote>.
@@ -219,7 +219,7 @@ modparam("domainpolicy", "domain_prefix_avp", "domainprefix")
 	<section>
 		<title><varname>domain_suffix_avp</varname> (string)</title>
 		<para>
-		Name of the AVP which contains a domain suffix. 
+		Name of the AVP which contains a domain suffix.
 		</para>
 		<para>
 		Default value is <quote>domainsuffix</quote>.
@@ -237,7 +237,7 @@ modparam("domainpolicy", "domain_suffix_avp", "domainsuffix")
 		<para>
 		Name of the AVP which contains a send_socket. The format of the
 		send socket (the payload of this AVP) must be in the format
-		[proto:]ip_address[:port]. The function dp_apply_policy will 
+		[proto:]ip_address[:port]. The function dp_apply_policy will
 		look for this AVP and if defined, it will force the send socket
 		to its value (similar to the force_send_socket core function).
 		</para>
@@ -259,14 +259,14 @@ modparam("domainpolicy", "send_socket_avp", "sendsocket")
 
 	<section>
 	<title>Functions</title>
-	<section>
+	<section id="dompolicy.f.dp_can_connect">
 		<title><function moreinfo="none">dp_can_connect()</function></title>
 		<para>
-		Checks the interconnection policy of the caller. It uses the domain in the 
-		request URI to perform the DP-DDDS algorithm according to draft-lendl-domain-policy-ddds-02 
-		to retrieve the domain's policy announcements. 
+		Checks the interconnection policy of the caller. It uses the domain in the
+		request URI to perform the DP-DDDS algorithm according to draft-lendl-domain-policy-ddds-02
+		to retrieve the domain's policy announcements.
 		As of this version, only records conforming to draft-lendl-speermint-federations-02
-		and draft-lendl-speermint-technical-policy-00 are supported. 
+		and draft-lendl-speermint-technical-policy-00 are supported.
 		</para>
 		<para>
 		Non-terminal NAPTR records will cause recursion to the replacement domain. dp_can_connect()
@@ -276,14 +276,14 @@ modparam("domainpolicy", "send_socket_avp", "sendsocket")
 		</para>
 		<para>
 		In order to simplify direct domain-based peerings all destination domains are
-		treated as if they contain a top priority "D2P+SIP:dom" rule with the domain itself as the 
+		treated as if they contain a top priority "D2P+SIP:dom" rule with the domain itself as the
 		value of the rule. Thus any database row with type = 'dom' and rule = 'example.com'
 		will override any dynamic DNS-discovered rules.
 		</para>
 		<para>
-		For NAPTRs with service-type "D2P+SIP:fed", the federation IDs 
+		For NAPTRs with service-type "D2P+SIP:fed", the federation IDs
 		(as extracted from the regexp field) are used to retrieve
-		policy records from a local local database (basically: "SELECT dp_col_att, dp_col_val FROM 
+		policy records from a local local database (basically: "SELECT dp_col_att, dp_col_val FROM
 		dp_table WHERE dp_col_rule = '[federationID]' AND type = 'fed'). If records are found (and all other
 		records with the same order value are fulfillable) then AVPs will be created from
 		the dp_col_att and dp_col_val columns.
@@ -297,8 +297,8 @@ modparam("domainpolicy", "send_socket_avp", "sendsocket")
 		"order" match and try to set the same AVP, then the behaviour is undefined.
 		</para>
 		<para>
-		The dp_col_att column specifies the AVP's name. If the AVP start with "s:" or "i:", the 
-		corresponding AVP type (string named or integer named) will be generated. If the excat specifier 
+		The dp_col_att column specifies the AVP's name. If the AVP start with "s:" or "i:", the
+		corresponding AVP type (string named or integer named) will be generated. If the excat specifier
 		is omited, the AVP type will be guessed.
 		</para>
 		<para>
@@ -363,7 +363,7 @@ switch(retcode) {
 		</programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="dompolicy.f.dp_apply_policy">
 		<title><function moreinfo="none">dp_apply_policy()</function></title>
 		<para>
 		This function sets the destination URI according to the policy returned
@@ -373,7 +373,7 @@ switch(retcode) {
 		The AVPs can be configured in the module's parameter section.
 		</para>
 		<para>
-		Note: The name of the AVPs must correspond with the names in the 
+		Note: The name of the AVPs must correspond with the names in the
 		<emphasis>att</emphasis> column in the domainpolicy table.
 		</para>
 		<para>
@@ -384,7 +384,7 @@ switch(retcode) {
 		<listitem>
 		<para>
 			<emphasis>port_override_avp</emphasis>: If this AVP is set, the port
-			in the destination URI is set to this port. 
+			in the destination URI is set to this port.
 			Setting an override port disables NAPTR and
 			SRV lookups according to RFC 3263.
 		</para>
@@ -394,14 +394,14 @@ switch(retcode) {
 			<emphasis>transport_override_avp</emphasis>: If this AVP is set, the transport
 			parameter in the destination URI is set to the specified transport ("udp", "tcp",
 			"tls").
-			Setting an override transport also disables NAPTR lookups, but retains 
+			Setting an override transport also disables NAPTR lookups, but retains
 			an SRV lookup according to RFC 3263.
 		</para>
 		</listitem>
 		<listitem>
 		<para>
 			<emphasis>domain_replacement_avp</emphasis>: If this AVP is set, the domain
-			in the destination URI will be replaced by this domain. 
+			in the destination URI will be replaced by this domain.
 		</para>
 		<para>
 			A non-terminal NAPTR and thus a referral to a new domain implicitly
@@ -411,9 +411,9 @@ switch(retcode) {
 		<listitem>
 		<para>
 			<emphasis>domain_prefix_avp</emphasis>: If this AVP is set, the domain
-			in the destination URI will be prefixed with this "subdomain".  
-			E.g. if the domain in the request URI is 
-			"example.com" and the domain_prefix_avp contains "inbound", the domain 
+			in the destination URI will be prefixed with this "subdomain".
+			E.g. if the domain in the request URI is
+			"example.com" and the domain_prefix_avp contains "inbound", the domain
 			in the destinaton URI is set to "inbound.example.com".
 		</para>
 		</listitem>
@@ -421,15 +421,15 @@ switch(retcode) {
 		<para>
 			<emphasis>domain_suffix_avp</emphasis>: If this AVP is set, the domain
 			in the destination URI will have the content of the AVP appended to it.
-			E.g. if the domain in the request URI is 
-			"example.com" and the domain_suffix_avp contains "myroot.com", the domain 
+			E.g. if the domain in the request URI is
+			"example.com" and the domain_suffix_avp contains "myroot.com", the domain
 			in the destination URI is set to "example.com.myroot.com".
 		</para>
 		</listitem>
 		<listitem>
 		<para>
 			<emphasis>send_socket_avp</emphasis>: If this AVP is set, the sending socket
-			will be forced to the socket in the AVP. The payload format of this AVP must 
+			will be forced to the socket in the AVP. The payload format of this AVP must
 			be [proto:]ip_address[:port].
 		</para>
 		</listitem>
@@ -457,12 +457,6 @@ if (dp_apply_policy()) {
 	</section>
 
 	<section>
-	<title>RPC Commands</title>
-	<para>
-	</para>
-	</section>
-
-	<section>
 	<title>Usage Scenarios</title>
 	<para>
 	This section describes how this module can be use to implement
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 8f79c77..14973ee 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -226,7 +226,7 @@ static int child_init(int rank)
 	LM_DBG("rank is (%d)\n", rank);
 
 	if(rank==PROC_MAIN) {
-		if(ht_timer_procs>0) {
+		if(ht_has_autoexpire() && ht_timer_procs>0) {
 			for(i=0; i<ht_timer_procs; i++) {
 				if(fork_sync_timer(PROC_TIMER, "HTable Timer", 1 /*socks flag*/,
 						ht_timer, (void*)(long)i, ht_timer_interval)<0) {
diff --git a/src/modules/http_async_client/async_http.c b/src/modules/http_async_client/async_http.c
index 5057908..a2ef7cf 100644
--- a/src/modules/http_async_client/async_http.c
+++ b/src/modules/http_async_client/async_http.c
@@ -192,6 +192,8 @@ void async_http_cb(struct http_m_reply *reply, void *param)
 	aq = param;
 	strncpy(q_id, aq->id, strlen(aq->id));
 	
+	q_id[strlen(aq->id)] = '\0';
+
 	act = (cfg_action_t*)aq->param;
 	cfg_update();
 
diff --git a/src/modules/janssonrpcc/janssonrpc.h b/src/modules/janssonrpcc/janssonrpc.h
index 413fcee..20b38c3 100644
--- a/src/modules/janssonrpcc/janssonrpc.h
+++ b/src/modules/janssonrpcc/janssonrpc.h
@@ -31,8 +31,8 @@
 
 #include "../../core/sr_module.h"
 #include "../jansson/jansson_utils.h"
-jansson_to_val_f jsontoval;
-pv_spec_t jsonrpc_result_pv;
+extern jansson_to_val_f jsontoval;
+extern pv_spec_t jsonrpc_result_pv;
 
 #endif
 
@@ -86,10 +86,10 @@ typedef struct retry_range {
 } retry_range_t;
 
 /* globals */
-int cmd_pipe;
+extern int cmd_pipe;
+extern str result_pv_str;
+extern retry_range_t* global_retry_ranges;
 extern const str null_str;
-str result_pv_str;
-retry_range_t* global_retry_ranges;
 
 static inline str pkg_strdup(str src)
 {
diff --git a/src/modules/janssonrpcc/janssonrpc_io.c b/src/modules/janssonrpcc/janssonrpc_io.c
index 4708a75..898458b 100644
--- a/src/modules/janssonrpcc/janssonrpc_io.c
+++ b/src/modules/janssonrpcc/janssonrpc_io.c
@@ -53,6 +53,10 @@
 
 struct tm_binds tmb;
 
+/* event bases */
+struct event_base* global_ev_base = NULL;
+struct evdns_base* global_evdns_base = NULL;
+
 void cmd_pipe_cb(int fd, short event, void *arg);
 void io_shutdown(int sig);
 
diff --git a/src/modules/janssonrpcc/janssonrpc_io.h b/src/modules/janssonrpcc/janssonrpc_io.h
index 3011e3a..70f4990 100644
--- a/src/modules/janssonrpcc/janssonrpc_io.h
+++ b/src/modules/janssonrpcc/janssonrpc_io.h
@@ -33,8 +33,8 @@
 #include "janssonrpc.h"
 
 /* event bases */
-struct event_base* global_ev_base;
-struct evdns_base* global_evdns_base;
+extern struct event_base* global_ev_base;
+extern struct evdns_base* global_evdns_base;
 
 typedef enum
 { CMD_CONNECT = 1000
diff --git a/src/modules/janssonrpcc/janssonrpc_request.c b/src/modules/janssonrpcc/janssonrpc_request.c
index dd3b355..381138b 100644
--- a/src/modules/janssonrpcc/janssonrpc_request.c
+++ b/src/modules/janssonrpcc/janssonrpc_request.c
@@ -32,7 +32,9 @@
 #include "janssonrpc_request.h"
 #include "janssonrpc_io.h"
 
-int next_id = 1;
+jsonrpc_request_t* request_table[JSONRPC_DEFAULT_HTABLE_SIZE];
+
+static int next_id = 1;
 
 int store_request(jsonrpc_request_t* req);
 
diff --git a/src/modules/janssonrpcc/janssonrpc_request.h b/src/modules/janssonrpcc/janssonrpc_request.h
index e38c08e..2f6e758 100644
--- a/src/modules/janssonrpcc/janssonrpc_request.h
+++ b/src/modules/janssonrpcc/janssonrpc_request.h
@@ -50,7 +50,7 @@ struct jsonrpc_request {
 	unsigned int timeout;
 };
 
-jsonrpc_request_t* request_table[JSONRPC_DEFAULT_HTABLE_SIZE];
+extern jsonrpc_request_t* request_table[JSONRPC_DEFAULT_HTABLE_SIZE];
 
 jsonrpc_request_t* create_request(jsonrpc_req_cmd_t* cmd);
 void print_request(jsonrpc_request_t* req);
diff --git a/src/modules/janssonrpcc/janssonrpc_server.c b/src/modules/janssonrpcc/janssonrpc_server.c
index 6dafddc..86ba519 100644
--- a/src/modules/janssonrpcc/janssonrpc_server.c
+++ b/src/modules/janssonrpcc/janssonrpc_server.c
@@ -43,6 +43,11 @@
 #include "janssonrpc_server.h"
 #include "janssonrpc_connect.h"
 
+gen_lock_t* jsonrpc_server_group_lock = NULL;
+
+/* where all the servers are stored */
+jsonrpc_server_group_t** global_server_group = NULL;
+
 /* used for debugging only */
 void print_server(jsonrpc_server_t* server)
 {
diff --git a/src/modules/janssonrpcc/janssonrpc_server.h b/src/modules/janssonrpcc/janssonrpc_server.h
index da318d3..700695a 100644
--- a/src/modules/janssonrpcc/janssonrpc_server.h
+++ b/src/modules/janssonrpcc/janssonrpc_server.h
@@ -72,7 +72,7 @@ typedef struct jsonrpc_server_group {
 	struct jsonrpc_server_group* next;
 } jsonrpc_server_group_t;
 
-gen_lock_t* jsonrpc_server_group_lock;
+extern gen_lock_t* jsonrpc_server_group_lock;
 
 typedef struct server_list {
 	jsonrpc_server_t* server;
@@ -80,9 +80,9 @@ typedef struct server_list {
 } server_list_t;
 
 /* where all the servers are stored */
-jsonrpc_server_group_t** global_server_group;
+extern jsonrpc_server_group_t** global_server_group;
 
-int  jsonrpc_parse_server(char *_server, jsonrpc_server_group_t** group_ptr);
+int jsonrpc_parse_server(char *_server, jsonrpc_server_group_t** group_ptr);
 int jsonrpc_server_from_srv(str conn, str srv,
 		unsigned int hwm, jsonrpc_server_group_t** group_ptr);
 
diff --git a/src/modules/janssonrpcc/janssonrpc_srv.c b/src/modules/janssonrpcc/janssonrpc_srv.c
index 7cb5ab7..ea046d5 100644
--- a/src/modules/janssonrpcc/janssonrpc_srv.c
+++ b/src/modules/janssonrpcc/janssonrpc_srv.c
@@ -42,6 +42,10 @@
 #include "janssonrpc_io.h"
 #include "janssonrpc_server.h"
 
+jsonrpc_srv_t* global_srv_list = NULL;
+
+unsigned int jsonrpc_min_srv_ttl;
+
 int refresh_srv(jsonrpc_srv_t* srv_obj)
 {
 	DEBUG("Refreshing SRV for %.*s\n", STR(srv_obj->srv));
diff --git a/src/modules/janssonrpcc/janssonrpc_srv.h b/src/modules/janssonrpcc/janssonrpc_srv.h
index c902183..79c289f 100644
--- a/src/modules/janssonrpcc/janssonrpc_srv.h
+++ b/src/modules/janssonrpcc/janssonrpc_srv.h
@@ -38,9 +38,9 @@ typedef struct srv_cb_params {
 	unsigned int srv_ttl;
 } srv_cb_params_t;
 
-jsonrpc_srv_t* global_srv_list;
+extern jsonrpc_srv_t* global_srv_list;
 
-unsigned int jsonrpc_min_srv_ttl;
+extern unsigned int jsonrpc_min_srv_ttl;
 
 jsonrpc_srv_t* create_srv(str srv, str conn, unsigned int ttl);
 void addto_srv_list(jsonrpc_srv_t* srv, jsonrpc_srv_t** list);
diff --git a/src/modules/janssonrpcc/janssonrpcc_mod.c b/src/modules/janssonrpcc/janssonrpcc_mod.c
index a6e9c01..654ea82 100644
--- a/src/modules/janssonrpcc/janssonrpcc_mod.c
+++ b/src/modules/janssonrpcc/janssonrpcc_mod.c
@@ -61,6 +61,15 @@ int  pipe_fds[2] = {-1,-1};
 
 struct tm_binds tmb;
 
+/* globals */
+int cmd_pipe;
+str result_pv_str;
+retry_range_t* global_retry_ranges;
+#ifndef TEST
+jansson_to_val_f jsontoval;
+pv_spec_t jsonrpc_result_pv;
+#endif
+
 /*
  * Exported Functions
  */
@@ -205,8 +214,9 @@ static int child_init(int rank)
 
 void mod_destroy(void)
 {
-	lock_get(jsonrpc_server_group_lock); /* blocking */
-	if(jsonrpc_server_group_lock) lock_dealloc(jsonrpc_server_group_lock);
+	if(jsonrpc_server_group_lock) {
+		lock_dealloc(jsonrpc_server_group_lock);
+	}
 
 	free_server_group(global_server_group);
 	CHECK_AND_FREE(global_server_group);
diff --git a/src/modules/json/json_mod.c b/src/modules/json/json_mod.c
index b20299e..9b8c6bd 100644
--- a/src/modules/json/json_mod.c
+++ b/src/modules/json/json_mod.c
@@ -36,7 +36,7 @@ static int fixup_get_field_free(void** param, int param_no);
 
 /* Exported functions */
 static cmd_export_t cmds[]={
-	{"json_get_field", (cmd_function)json_get_field, 3, 
+	{"json_get_field", (cmd_function)json_get_field, 3,
 		fixup_get_field, fixup_get_field_free, ANY_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
@@ -82,7 +82,7 @@ static int fixup_get_field(void** param, int param_no)
 static int fixup_get_field_free(void** param, int param_no)
 {
 	if (param_no == 1 || param_no == 2) {
-		LM_WARN("free function has not been defined for spve\n");
+		fixup_free_spve_null(param, 1);
 		return 0;
 	}
 
diff --git a/src/modules/jsonrpcc/jsonrpcc_mod.c b/src/modules/jsonrpcc/jsonrpcc_mod.c
index 567fdaf..903b278 100644
--- a/src/modules/jsonrpcc/jsonrpcc_mod.c
+++ b/src/modules/jsonrpcc/jsonrpcc_mod.c
@@ -60,7 +60,7 @@ static cmd_export_t cmds[]={
 	{"jsonrpc_notification", (cmd_function)jsonrpc_notification, 2, fixup_notification, 0, ANY_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
- 
+
 
 /*
  * Script Parameters
@@ -71,23 +71,23 @@ static param_export_t mod_params[]={
 	{ 0,0,0 }
 };
 
- 
+
 /*
  * Exports
  */
 struct module_exports exports = {
-		"jsonrpcc",           /* module name */
-		DEFAULT_DLFLAGS,     /* dlopen flags */
-		cmds,                /* Exported functions */
-		mod_params,          /* Exported parameters */
-		0,                   /* exported statistics */
-		0,                   /* exported MI functions */
-		0,                   /* exported pseudo-variables */
-		0,                   /* extra processes */
-		mod_init,            /* module initialization function */
-		0,                   /* response function*/
-		0,                   /* destroy function */
-		child_init           /* per-child init function */
+	"jsonrpcc",           /* module name */
+	DEFAULT_DLFLAGS,     /* dlopen flags */
+	cmds,                /* Exported functions */
+	mod_params,          /* Exported parameters */
+	0,                   /* exported statistics */
+	0,                   /* exported MI functions */
+	0,                   /* exported pseudo-variables */
+	0,                   /* extra processes */
+	mod_init,            /* module initialization function */
+	0,                   /* response function*/
+	0,                   /* destroy function */
+	child_init           /* per-child init function */
 };
 
 
@@ -97,12 +97,14 @@ static int mod_init(void) {
 	/* load the tm functions  */
 	if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0)))
 	{
-		LOG(L_ERR, "ERROR:jsonrpc:mod_init: cannot import load_tm\n");
+		LM_ERR("failed find tm - cannot import load_tm\n");
 		return -1;
 	}
 	/* let the auto-loading function load all TM stuff */
-	if (load_tm( &tmb )==-1)
+	if (load_tm( &tmb )==-1) {
+		LM_ERR("failed to bind to tm api\n");
 		return -1;
+	}
 
 	if (servers_param == NULL) {
 		LM_ERR("servers parameter missing.\n");
@@ -130,8 +132,10 @@ static int child_init(int rank)
 		return 0;
 
 	pid=fork_process(PROC_NOCHLDINIT, "jsonrpc io handler", 1);
-	if (pid<0)
+	if (pid<0) {
+		LM_ERR("failed to fork jsonrpc io handler\n");
 		return -1; /* error */
+	}
 	if(pid==0){
 		/* child */
 		close(pipe_fds[1]);
@@ -144,7 +148,7 @@ static int child_init(int rank)
 
 static int fixup_request(void** param, int param_no)
 {
-  if (param_no <= 4) {
+	if (param_no <= 4) {
 		return fixup_spve_null(param, 1);
 	} else if (param_no == 5) {
 		return fixup_pvar_null(param, 1);
@@ -155,7 +159,7 @@ static int fixup_request(void** param, int param_no)
 
 static int fixup_notification(void** param, int param_no)
 {
-  if (param_no <= 2) {
+	if (param_no <= 2) {
 		return fixup_spve_null(param, 1);
 	}
 	LM_ERR("jsonrpc_notification takes exactly 2 parameters.\n");
@@ -164,7 +168,7 @@ static int fixup_notification(void** param, int param_no)
 
 static int fixup_request_free(void** param, int param_no)
 {
-  if (param_no <= 4) {
+	if (param_no <= 4) {
 		return 0;
 	} else if (param_no == 5) {
 		return fixup_free_pvar_null(param, 1);
diff --git a/src/modules/jsonrpcs/jsonrpcs_fifo.c b/src/modules/jsonrpcs/jsonrpcs_fifo.c
index c44a55c..c317712 100644
--- a/src/modules/jsonrpcs/jsonrpcs_fifo.c
+++ b/src/modules/jsonrpcs/jsonrpcs_fifo.c
@@ -47,83 +47,7 @@ char *jsonrpc_fifo_gid_s = 0;			/*!< Fifo default Group ID name */
 int  jsonrpc_fifo_mode = S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* Default file mode rw-rw---- */
 
 
-/* FIFO TRANSPORT */
-
-/*! \brief Initialize fifo transport */
-int jsonrpc_init_fifo_file(void)
-{
-	int n;
-	struct stat filestat;
-
-	/* checking the jsonrpc_fifo module param */
-	if (jsonrpc_fifo==NULL || *jsonrpc_fifo == 0) {
-		jsonrpc_fifo=NULL;
-		LM_DBG("No fifo configured\n");
-		return 0;
-	}
-
-	LM_DBG("testing if fifo file exists ...\n");
-	n=stat(jsonrpc_fifo, &filestat);
-	if (n==0) {
-		/* FIFO exist, delete it (safer) if no config check */
-		if(config_check==0) {
-			if (unlink(jsonrpc_fifo)<0){
-				LM_ERR("Cannot delete old fifo (%s): %s\n",
-					jsonrpc_fifo, strerror(errno));
-				return -1;
-			}
-		}
-	} else if (n<0 && errno!=ENOENT){
-		LM_ERR("MI FIFO stat failed: %s\n", strerror(errno));
-		return -1;
-	}
-
-	/* checking the fifo_reply_dir param */
-	if(!jsonrpc_fifo_reply_dir || *jsonrpc_fifo_reply_dir == 0) {
-		LM_ERR("fifo_reply_dir parameter is empty\n");
-		return -1;
-	}
-
-	/* Check if the directory for the reply fifo exists */
-	n = stat(jsonrpc_fifo_reply_dir, &filestat);
-	if(n < 0){
-		LM_ERR("Directory stat for MI Fifo reply failed: %s\n", strerror(errno));
-		return -1;
-	}
-
-	if(S_ISDIR(filestat.st_mode) == 0){
-		LM_ERR("fifo_reply_dir parameter is not a directory\n");
-		return -1;
-	}
-
-	/* check fifo_mode */
-	if(!jsonrpc_fifo_mode){
-		LM_WARN("cannot specify fifo_mode = 0, forcing it to rw-------\n");
-		jsonrpc_fifo_mode = S_IRUSR | S_IWUSR;
-	}
-
-	if (jsonrpc_fifo_uid_s){
-		if (user2uid(&jsonrpc_fifo_uid, &jsonrpc_fifo_gid, jsonrpc_fifo_uid_s)<0){
-			LM_ERR("Bad user name %s\n", jsonrpc_fifo_uid_s);
-			return -1;
-		}
-	}
-
-	if (jsonrpc_fifo_gid_s){
-		if (group2gid(&jsonrpc_fifo_gid, jsonrpc_fifo_gid_s)<0){
-			LM_ERR("Bad group name %s\n", jsonrpc_fifo_gid_s);
-			return -1;
-		}
-	}
-
-	/* add space for one extra process */
-	register_procs(1);
-
-	/* add child to update local config framework structures */
-	cfg_register_child(1);
-
-	return 0;
-}
+static FILE *_jsonrpcs_fifo_stream = NULL;
 
 
 static int  jsonrpc_fifo_read = 0;
@@ -211,6 +135,90 @@ FILE *jsonrpc_init_fifo_server(char *fifo_name, int fifo_mode,
 	return fifo_stream;
 }
 
+/*! \brief Initialize fifo transport */
+int jsonrpc_init_fifo_file(void)
+{
+	int n;
+	struct stat filestat;
+
+	/* checking the jsonrpc_fifo module param */
+	if (jsonrpc_fifo==NULL || *jsonrpc_fifo == 0) {
+		jsonrpc_fifo=NULL;
+		LM_DBG("No fifo configured\n");
+		return 0;
+	}
+
+	LM_DBG("testing if fifo file exists ...\n");
+	n=stat(jsonrpc_fifo, &filestat);
+	if (n==0) {
+		/* FIFO exist, delete it (safer) if no config check */
+		if(config_check==0) {
+			if (unlink(jsonrpc_fifo)<0){
+				LM_ERR("Cannot delete old fifo (%s): %s\n",
+					jsonrpc_fifo, strerror(errno));
+				return -1;
+			}
+		}
+	} else if (n<0 && errno!=ENOENT){
+		LM_ERR("MI FIFO stat failed: %s\n", strerror(errno));
+		return -1;
+	}
+
+	/* checking the fifo_reply_dir param */
+	if(!jsonrpc_fifo_reply_dir || *jsonrpc_fifo_reply_dir == 0) {
+		LM_ERR("fifo_reply_dir parameter is empty\n");
+		return -1;
+	}
+
+	/* Check if the directory for the reply fifo exists */
+	n = stat(jsonrpc_fifo_reply_dir, &filestat);
+	if(n < 0){
+		LM_ERR("Directory stat for MI Fifo reply failed: %s\n", strerror(errno));
+		return -1;
+	}
+
+	if(S_ISDIR(filestat.st_mode) == 0){
+		LM_ERR("fifo_reply_dir parameter is not a directory\n");
+		return -1;
+	}
+
+	/* check fifo_mode */
+	if(!jsonrpc_fifo_mode){
+		LM_WARN("cannot specify fifo_mode = 0, forcing it to rw-------\n");
+		jsonrpc_fifo_mode = S_IRUSR | S_IWUSR;
+	}
+
+	if (jsonrpc_fifo_uid_s){
+		if (user2uid(&jsonrpc_fifo_uid, &jsonrpc_fifo_gid, jsonrpc_fifo_uid_s)<0){
+			LM_ERR("Bad user name %s\n", jsonrpc_fifo_uid_s);
+			return -1;
+		}
+	}
+
+	if (jsonrpc_fifo_gid_s){
+		if (group2gid(&jsonrpc_fifo_gid, jsonrpc_fifo_gid_s)<0){
+			LM_ERR("Bad group name %s\n", jsonrpc_fifo_gid_s);
+			return -1;
+		}
+	}
+
+
+	_jsonrpcs_fifo_stream = jsonrpc_init_fifo_server( jsonrpc_fifo, jsonrpc_fifo_mode,
+		jsonrpc_fifo_uid, jsonrpc_fifo_gid, jsonrpc_fifo_reply_dir);
+	if ( _jsonrpcs_fifo_stream==NULL ) {
+		LM_CRIT("failed to init jsonrpc fifo server file stream\n");
+		return -1;
+	}
+
+	/* add space for one extra process */
+	register_procs(1);
+
+	/* add child to update local config framework structures */
+	cfg_register_child(1);
+
+	return 0;
+}
+
 /*! \brief Read input on fifo */
 int jsonrpc_read_stream(char *b, int max, FILE *stream, int *lread)
 {
@@ -479,18 +487,14 @@ static void jsonrpc_fifo_server(FILE *fifo_stream)
 
 static void jsonrpc_fifo_process(int rank)
 {
-	FILE *fifo_stream;
-
 	LM_DBG("new process with pid = %d created\n",getpid());
 
-	fifo_stream = jsonrpc_init_fifo_server( jsonrpc_fifo, jsonrpc_fifo_mode,
-		jsonrpc_fifo_uid, jsonrpc_fifo_gid, jsonrpc_fifo_reply_dir);
-	if ( fifo_stream==NULL ) {
-		LM_CRIT("failed to init jsonrpc fifo server\n");
+	if ( _jsonrpcs_fifo_stream==NULL ) {
+		LM_CRIT("fifo server stream not initialized\n");
 		exit(-1);
 	}
 
-	jsonrpc_fifo_server( fifo_stream );
+	jsonrpc_fifo_server( _jsonrpcs_fifo_stream );
 
 	LM_CRIT("failed to run jsonrpc fifo server\n");
 	exit(-1);
@@ -550,7 +554,7 @@ int jsonrpc_fifo_child_init(int rank)
 		LM_ERR("invalid fifo file path\n");
 	}
 
-	pid=fork_process(PROC_NOCHLDINIT, "JSONRPC-S FIFO", 1);
+	pid=fork_process(PROC_RPC, "JSONRPCS FIFO", 1);
 	if (pid<0) {
 		return -1; /* error */
 	}
@@ -601,4 +605,3 @@ int jsonrpc_fifo_destroy(void)
 error:
 	return -1;
 }
-
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.c b/src/modules/jsonrpcs/jsonrpcs_mod.c
index b30beaf..adf423d 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.c
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.c
@@ -298,13 +298,23 @@ static void jsonrpc_fault(jsonrpc_ctx_t* ctx, int code, char* fmt, ...)
 
 	jsonrpc_delayed_reply_ctx_init(ctx);
 
-	ctx->http_code = code;
+	if(code <= 100) {
+		ctx->http_code = 500;
+	} else {
+		ctx->http_code = code;
+	}
 	va_start(ap, fmt);
 	vsnprintf(jsonrpc_error_buf, JSONRPC_ERROR_REASON_BUF_LEN, fmt, ap);
 	va_end(ap);
-	ctx->http_text.len = strlen(jsonrpc_error_buf);
+	ctx->error_text.len = strlen(jsonrpc_error_buf);
+	ctx->error_text.s = jsonrpc_error_buf;
+	ctx->http_text.len = ctx->error_text.len;
 	ctx->http_text.s = jsonrpc_error_buf;
-	if(ctx->error_code == 0) ctx->error_code = -32000;
+	if(code == 0) {
+		ctx->error_code = -32000;
+	} else {
+		ctx->error_code = code;
+	}
 
 	return;
 }
@@ -347,8 +357,14 @@ static int jsonrpc_send(jsonrpc_ctx_t* ctx)
 					_jsonrpc_error_table[i].text.s,
 					_jsonrpc_error_table[i].text.len);
 			} else {
-				srjson_AddStrStrToObject(ctx->jrpl, nj,
-					"message", 7, "Unexpected Error", 16);
+				if(ctx->error_text.len>0) {
+					srjson_AddStrStrToObject(ctx->jrpl, nj,
+							"message", 7,
+							ctx->error_text.s, ctx->error_text.len);
+				} else {
+					srjson_AddStrStrToObject(ctx->jrpl, nj,
+							"message", 7, "Unexpected Error", 16);
+				}
 			}
 			srjson_AddItemToObject(ctx->jrpl, ctx->jrpl->root, "error", nj);
 		}
@@ -648,7 +664,7 @@ static int jsonrpc_scan(jsonrpc_ctx_t* ctx, char* fmt, ...)
 		ctx->req_node = ctx->req_node->next;
 	}
 	/* error if there is still a scan char type and it is not optional */
-	if(*fmt && mandatory_param==1)
+	if(*fmt && *fmt!='*' && mandatory_param==1)
 		goto error;
 
 	va_end(ap);
diff --git a/src/modules/jsonrpcs/jsonrpcs_mod.h b/src/modules/jsonrpcs/jsonrpcs_mod.h
index eec2a74..ef15c3e 100644
--- a/src/modules/jsonrpcs/jsonrpcs_mod.h
+++ b/src/modules/jsonrpcs/jsonrpcs_mod.h
@@ -50,6 +50,7 @@ typedef struct jsonrpc_ctx {
 	srjson_t *rpl_node;    /**< Pointer to crt node in json reply doc */
 	int reply_sent;        /**< Flag set if the json reply was sent */
 	int error_code;        /**< Json error code */
+	str error_text;        /**< Json error text */
 	int http_code;         /**< http reply code */
 	str http_text;         /**< http reply reason text */
 	int transport;         /**< RPC transport */
diff --git a/src/modules/jsonrpcs/jsonrpcs_sock.c b/src/modules/jsonrpcs/jsonrpcs_sock.c
index c61fa6d..3529941 100644
--- a/src/modules/jsonrpcs/jsonrpcs_sock.c
+++ b/src/modules/jsonrpcs/jsonrpcs_sock.c
@@ -30,6 +30,7 @@
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <sys/select.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
@@ -63,7 +64,7 @@ typedef struct{
 } jsonrpc_dgram_address_t;
 
 typedef struct jsonrpc_dgram_rx_tx {
-	int rx_sock, tx_sock;
+	int rx_sock;
 } jsonrpc_dgram_rx_tx_t;
 
 /* dgram variables */
@@ -71,7 +72,7 @@ static int jsonrpc_dgram_socket_domain =  AF_LOCAL;
 static jsonrpc_dgram_sockaddr_t jsonrpc_dgram_addr;
 
 /* dgram socket definition parameter */
-static jsonrpc_dgram_rx_tx_t jsonrpc_dgram_sockets;
+static jsonrpc_dgram_rx_tx_t jsonrpc_dgram_sockets = { -1 };
 
 /* dgram unixsock specific parameters */
 char *jsonrpc_dgram_socket = NAME "_rpc.sock";
@@ -89,8 +90,8 @@ int jsonrpc_dgram_child_init(int rank);
 int jsonrpc_dgram_destroy(void);
 
 
-void jsonrpc_dgram_server(int rx_sock, int tx_sock);
-static int jsonrpc_dgram_pre_process(void);
+void jsonrpc_dgram_server(int rx_sock);
+static int jsonrpc_dgram_init_socks(void);
 static int jsonrpc_dgram_post_process(void);
 
 int jsonrpc_dgram_mod_init(void)
@@ -241,6 +242,11 @@ int jsonrpc_dgram_mod_init(void)
 			jsonrpc_dgram_socket, strlen(jsonrpc_dgram_socket));
 
 done:
+	if(jsonrpc_dgram_init_socks()!=0) {
+		LM_ERR("init datagram sockets function failed\n");
+		return -1;
+	}
+
 	/* add space for extra processes */
 	register_procs(jsonrpc_dgram_workers);
 	/* add child to update local config framework structures */
@@ -358,7 +364,7 @@ int jsonrpc_dgram_init_server(jsonrpc_dgram_sockaddr_t *addr,
 
 	case AF_INET:
 			if (bind(socks->rx_sock, &addr->udp_addr.s,
-			sockaddru_len(addr->udp_addr))< 0) {
+						sockaddru_len(addr->udp_addr))< 0) {
 				LM_ERR("bind: %s\n", strerror(errno));
 				goto err_rx;
 			}
@@ -372,13 +378,12 @@ int jsonrpc_dgram_init_server(jsonrpc_dgram_sockaddr_t *addr,
 			break;
 	default:
 			LM_ERR("domain not supported\n");
-			goto err_both;
+			goto err_rx;
 
 	}
-	jsonrpc_dgram_create_reply_socket(socks->tx_sock, socket_domain, err_both);
 
 	optval = 64 * 1024;
-	if (setsockopt(socks->tx_sock, SOL_SOCKET, SO_SNDBUF,
+	if (setsockopt(socks->rx_sock, SOL_SOCKET, SO_SNDBUF,
 					(void*)&optval, sizeof(optval)) ==-1){
 		LM_ERR("failed to increse send buffer size via setsockopt "
 				" SO_SNDBUF (%d) - %d: %s\n", optval,
@@ -386,16 +391,25 @@ int jsonrpc_dgram_init_server(jsonrpc_dgram_sockaddr_t *addr,
 		/* continue, non-critical */
 	}
 
+	/* Turn non-blocking mode on for tx*/
+	flags = fcntl(socks->rx_sock, F_GETFL);
+	if (flags == -1){
+		LM_ERR("fcntl failed: %s\n", strerror(errno));
+		goto err_rx;
+	}
+	if (fcntl(socks->rx_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
+		LM_ERR("fcntl: set non-blocking failed: %s\n", strerror(errno));
+		goto err_rx;
+	}
 	return 0;
-err_both:
-	if(socks->tx_sock>=0) close(socks->tx_sock);
+
 err_rx:
 	if(socks->rx_sock>=0) close(socks->rx_sock);
 	return -1;
 }
 
 
-static int jsonrpc_dgram_pre_process(void)
+static int jsonrpc_dgram_init_socks(void)
 {
 	int res;
 
@@ -435,8 +449,7 @@ static void jsonrpc_dgram_process(int rank)
 
 	jsonrpc_dgram_write_buffer_len = JSONRPC_DGRAM_BUF_SIZE ;
 
-	jsonrpc_dgram_server(jsonrpc_dgram_sockets.rx_sock,
-			jsonrpc_dgram_sockets.tx_sock);
+	jsonrpc_dgram_server(jsonrpc_dgram_sockets.rx_sock);
 
 	exit(-1);
 }
@@ -448,12 +461,8 @@ int jsonrpc_dgram_child_init(int rank)
 	int pid;
 
 	if (rank==PROC_MAIN) {
-		if(jsonrpc_dgram_pre_process()!=0) {
-			LM_ERR("pre-fork function failed\n");
-			return -1;
-		}
 		for(i=0; i<jsonrpc_dgram_workers; i++) {
-			pid=fork_process(PROC_NOCHLDINIT, "JSONRPC-S DATAGRAM", 1);
+			pid=fork_process(PROC_RPC, "JSONRPCS DATAGRAM", 1);
 			if (pid<0)
 				return -1; /* error */
 			if(pid==0) {
@@ -479,8 +488,7 @@ int jsonrpc_dgram_child_init(int rank)
 static int jsonrpc_dgram_post_process(void)
 {
 	/* close the sockets */
-	close(jsonrpc_dgram_sockets.rx_sock);
-	close(jsonrpc_dgram_sockets.tx_sock);
+	if(jsonrpc_dgram_sockets.rx_sock>=0) close(jsonrpc_dgram_sockets.rx_sock);
 	return 0;
 }
 
@@ -548,21 +556,34 @@ static int jsonrpc_dgram_send_data(int fd, char* buf, unsigned int len,
 	return n;
 }
 
-void jsonrpc_dgram_server(int rx_sock, int tx_sock)
+void jsonrpc_dgram_server(int rx_sock)
 {
 	int ret;
 	str scmd;
 	jsonrpc_plain_reply_t* jr = NULL;
+	fd_set readfds;
+	int n;
 
 	ret = 0;
 
 	while(1) { /*read the datagram*/
 		/* update the local config framework structures */
 		cfg_update();
-
 		memset(jsonrpc_dgram_buf, 0, JSONRPC_DGRAM_BUF_SIZE);
 		jsonrpc_dgram_reply_addr_len = sizeof(jsonrpc_dgram_reply_addr);
 
+		FD_ZERO(&readfds);
+		FD_SET(rx_sock, &readfds);
+		n = select(rx_sock+1, &readfds, 0, 0, 0);
+		if(n < 0) {
+			LM_ERR("failure in select: (%d) %s\n", errno, strerror(errno));
+			continue;
+		}
+		if(!FD_ISSET(rx_sock, &readfds)) {
+			/* no data on udp socket */
+			continue;
+		}
+
 		/* get the client's address */
 		ret = recvfrom(rx_sock, jsonrpc_dgram_buf, JSONRPC_DGRAM_BUF_SIZE, 0,
 				(struct sockaddr*)&jsonrpc_dgram_reply_addr,
@@ -607,7 +628,7 @@ void jsonrpc_dgram_server(int rx_sock, int tx_sock)
 				jr->rcode, jr->rbody.s,
 				jr->rbody.len, jr->rbody.s);
 
-		jsonrpc_dgram_send_data(tx_sock, jr->rbody.s, jr->rbody.len,
+		jsonrpc_dgram_send_data(rx_sock, jr->rbody.s, jr->rbody.len,
 						  (struct sockaddr*)&jsonrpc_dgram_reply_addr,
 						  jsonrpc_dgram_reply_addr_len,
 						  jsonrpc_dgram_timeout);
diff --git a/src/modules/maxfwd/doc/maxfwd_admin.xml b/src/modules/maxfwd/doc/maxfwd_admin.xml
index 6634fc3..9a52ee6 100644
--- a/src/modules/maxfwd/doc/maxfwd_admin.xml
+++ b/src/modules/maxfwd/doc/maxfwd_admin.xml
@@ -10,9 +10,9 @@
 <!-- Module User's Guide -->
 
 <chapter>
-	
+
 	<title>&adminguide;</title>
-	
+
 	<section id="maxfwd.overview">
 	<title>Overview</title>
 	<para>
@@ -45,7 +45,7 @@
 	<section>
 		<title>External Libraries or Applications</title>
 		<para>
-		The following libraries or applications must be installed before 
+		The following libraries or applications must be installed before
 		running &kamailio; with this module loaded:
 			<itemizedlist>
 			<listitem>
@@ -64,15 +64,15 @@
 		<title><varname>max_limit</varname> (integer)</title>
 		<para>
 		Set an upper limit for the max-forward value in the outgoing requests.
-		If the header is present, the decremented value is not allowed to 
-		exceed this max_limits - if it does, the header value will by 
+		If the header is present, the decremented value is not allowed to
+		exceed this max_limits - if it does, the header value will by
 		decreased to <quote>max_limit</quote>.
 		</para>
-		<para>Note: This check is done when calling the 
+		<para>Note: This check is done when calling the
 		maxfwd_process() function.
 		</para>
 		<para>
-		The range of values stretches from 1 to 256, which is the maximum 
+		The range of values stretches from 1 to 256, which is the maximum
 		MAX-FORWARDS value allowed by RFC 3261. The value can be changed at
 		runtime.
 		</para>
@@ -93,15 +93,15 @@ modparam("maxfwd", "max_limit", 32)
 	</section>
 
 
-	<section id="maxfwd.f.maxfwd_process">
-	<title>Functions</title>
 	<section>
+	<title>Functions</title>
+	<section id="maxfwd.f.maxfwd_process">
 		<title>
 		<function moreinfo="none">maxfwd_process(max_value)</function>
 		</title>
 		<para>
-		If no Max-Forward header is present in the received request, a header 
-		will be added having the original value equal with 
+		If no Max-Forward header is present in the received request, a header
+		will be added having the original value equal with
 		<quote>max_value</quote>. If a Max-Forward header is already present,
 		its value will be decremented (if not 0). The parameter can be a
 		variable.
@@ -114,7 +114,7 @@ modparam("maxfwd", "max_limit", 32)
 			</para>
 		</listitem>
 		<listitem>
-			<para><emphasis>1 (true)</emphasis> - header was found and its 
+			<para><emphasis>1 (true)</emphasis> - header was found and its
 			value was successfully decremented (had a non-0 value).
 			</para>
 		</listitem>
@@ -129,13 +129,13 @@ modparam("maxfwd", "max_limit", 32)
 		</listitem>
 		</itemizedlist>
 		<para>
-		The return code may be extensivly tested via script variable 
+		The return code may be extensivly tested via script variable
 		<quote>retcode</quote> (or <quote>$?</quote>).
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<listitem>
-			<para><emphasis>max_value</emphasis> - Value to be added if 
+			<para><emphasis>max_value</emphasis> - Value to be added if
 			there is no Max-Forwards header field in the message.
 			</para>
 		</listitem>
@@ -181,7 +181,7 @@ if (!maxfwd_process("10") && $retcode==-1) {
 		<function moreinfo="none">is_maxfwd_lt(max_value)</function>
 		</title>
 		<para>
-		Checks if the Max-Forward header value is less then the 
+		Checks if the Max-Forward header value is less then the
 		<quote>max_value</quote> parameter value. It considers also the value
 		of the new inserted header (if locally added). The parameter can be
 		a variable.
@@ -189,12 +189,12 @@ if (!maxfwd_process("10") && $retcode==-1) {
 		<para>Retuning codes:</para>
 		<itemizedlist>
 		<listitem>
-			<para><emphasis>1 (true)</emphasis> - header was found or set and 
+			<para><emphasis>1 (true)</emphasis> - header was found or set and
 			its value is stricly less than <quote>max_value</quote>.
 			</para>
 		</listitem>
 		<listitem>
-			<para><emphasis>-1 (false)</emphasis> - the header was found or 
+			<para><emphasis>-1 (false)</emphasis> - the header was found or
 			set and its value is greater or equal to <quote>max_value</quote>.
 			</para>
 		</listitem>
@@ -209,13 +209,13 @@ if (!maxfwd_process("10") && $retcode==-1) {
 		</listitem>
 		</itemizedlist>
 		<para>
-		The return code may be extensivly tested via script variable 
+		The return code may be extensivly tested via script variable
 		<quote>retcode</quote> (or <quote>$?</quote>).
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<listitem>
-			<para><emphasis>max_value</emphasis> - value to check the 
+			<para><emphasis>max_value</emphasis> - value to check the
 			Max-Forward.value against (as less than).
 			</para>
 		</listitem>
diff --git a/src/modules/mediaproxy/README b/src/modules/mediaproxy/README
index 122de08..7be9930 100644
--- a/src/modules/mediaproxy/README
+++ b/src/modules/mediaproxy/README
@@ -25,7 +25,7 @@ Dan Pascu
               4.1. SIP Router Modules
               4.2. External Libraries or Applications
 
-        5. Exported parameters
+        5. Parameters
 
               5.1. disable (int)
               5.2. mediaproxy_socket (string)
@@ -66,7 +66,7 @@ Chapter 1. Admin Guide
         4.1. SIP Router Modules
         4.2. External Libraries or Applications
 
-   5. Exported parameters
+   5. Parameters
 
         5.1. disable (int)
         5.2. mediaproxy_socket (string)
@@ -160,7 +160,7 @@ Chapter 1. Admin Guide
      * Mediaproxy version 2.4.2 or higher (but not necessarily on the same
        host as SIP Router).
 
-5. Exported parameters
+5. Parameters
 
    5.1. disable (int)
    5.2. mediaproxy_socket (string)
diff --git a/src/modules/mediaproxy/doc/mediaproxy_admin.xml b/src/modules/mediaproxy/doc/mediaproxy_admin.xml
index aed612c..09567a7 100644
--- a/src/modules/mediaproxy/doc/mediaproxy_admin.xml
+++ b/src/modules/mediaproxy/doc/mediaproxy_admin.xml
@@ -11,20 +11,20 @@
 <!-- Module User's Guide -->
 
 <chapter>
-  
+
   <title>&adminguide;</title>
-  
+
   <section>
   <title>Overview</title>
     <para>
-      Mediaproxy is an &siprouter; module that is designed to allow automatic 
-      NAT traversal for the majority of existing SIP clients. This means 
-      that there will be no need to configure anything in particular on 
-      the NAT box to allow these clients to work behind NAT when using 
+      Mediaproxy is an &siprouter; module that is designed to allow automatic
+      NAT traversal for the majority of existing SIP clients. This means
+      that there will be no need to configure anything in particular on
+      the NAT box to allow these clients to work behind NAT when using
       the mediaproxy module.
     </para>
   </section>
-  
+
   <section>
   <title>Principle of operation</title>
     <para>
@@ -145,10 +145,10 @@
       </para>
     </section>
   </section>
-  
+
   <section>
-  <title>Exported parameters</title>
-    <section>
+  <title>Parameters</title>
+    <section id="mediaproxy.p.disable">
     <title><varname>disable</varname> (int)</title>
       <para>
         Boolean flag that specifies if mediaproxy should be disabled. This
@@ -174,7 +174,7 @@ modparam("mediaproxy", "disable", 1)
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.socket">
     <title><varname>mediaproxy_socket</varname> (string)</title>
       <para>
         It is the path to the filesystem socket where the mediaproxy dispatcher
@@ -183,7 +183,7 @@ modparam("mediaproxy", "disable", 1)
 
       <para>
         <emphasis>
-          Default value is 
+          Default value is
             <quote>/var/run/mediaproxy/dispatcher.sock</quote>.
         </emphasis>
       </para>
@@ -198,7 +198,7 @@ modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.timeout">
     <title><varname>mediaproxy_timeout</varname> (int)</title>
       <para>
         How much time (in milliseconds) to wait for an answer from the
@@ -221,7 +221,7 @@ modparam("mediaproxy", "mediaproxy_timeout", 500)
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.signaling_ip">
     <title><varname>signaling_ip_avp</varname> (string)</title>
       <para>
         Specification of the AVP which holds the IP address from where
@@ -255,7 +255,7 @@ modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.relay_avp">
     <title><varname>media_relay_avp</varname> (string)</title>
       <para>
         Specification of the AVP which holds an optional application
@@ -281,14 +281,14 @@ modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
         </programlisting>
       </example>
     </section>
-    
-    <section>
+
+    <section id="mediaproxy.p.ice_candidate">
     <title><varname>ice_candidate</varname> (string)</title>
       <para>
-        Indicates the type of ICE candidate that will be added to the SDP. 
-        It can take 3 values: 'none', 'low-priority' or 'high-priority'. 
-        If 'none' is selected no candidate will be adeed to the SDP. If 
-        'low-priority' is selected then a low priority candidate will be 
+        Indicates the type of ICE candidate that will be added to the SDP.
+        It can take 3 values: 'none', 'low-priority' or 'high-priority'.
+        If 'none' is selected no candidate will be adeed to the SDP. If
+        'low-priority' is selected then a low priority candidate will be
         added and if 'high-priority' is selected a high priority one.
       </para>
 
@@ -307,12 +307,12 @@ modparam("mediaproxy", "ice_candidate", "low-priority")
         </programlisting>
       </example>
     </section>
-    
-    <section>
+
+    <section id="mediaproxy.p.ice_candidate_avp">
     <title><varname>ice_candidate_avp</varname> (string)</title>
       <para>
-        Specification of the AVP which holds the ICE candidate that will be 
-        inserted in the SDP. The value specified in this AVP will override 
+        Specification of the AVP which holds the ICE candidate that will be
+        inserted in the SDP. The value specified in this AVP will override
         the value in ice_candidate module parameter.  If the AVP
         is not set, the default value will be used.
       </para>
@@ -336,7 +336,7 @@ modparam("mediaproxy", "ice_candidate_avp", "$avp(ice_candidate)")
 
   <section>
   <title>Functions</title>
-    <section>
+    <section id="mediaproxy.f.engage">
     <title><function moreinfo="none">engage_media_proxy()</function></title>
       <para>
         Trigger the use of MediaProxy for all the dialog requests and
@@ -385,7 +385,7 @@ if (method==INVITE && !has_totag()) {
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.use">
     <title><function moreinfo="none">use_media_proxy()</function></title>
       <para>
         Will make a call to the dispatcher and replace the IPs and ports
@@ -434,7 +434,7 @@ if (method==INVITE) {
       </example>
     </section>
 
-    <section>
+    <section id="mediaproxy.p.end">
     <title><function moreinfo="none">end_media_session()</function></title>
       <para>
         Will call on the dispatcher to inform the media relay to end the
@@ -450,7 +450,7 @@ if (method==INVITE) {
 
       <para>
         This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.
-      </para>    
+      </para>
 
       <example>
       <title>Using the <function>end_media_session</function> function</title>
diff --git a/src/modules/misc_radius/README b/src/modules/misc_radius/README
index 62685c5..c5d41f5 100644
--- a/src/modules/misc_radius/README
+++ b/src/modules/misc_radius/README
@@ -182,6 +182,7 @@ Chapter 1. Admin Guide
    Example 1.2. radius_config parameter usage
 ...
 modparam("misc_radius", "radius_config", "/etc/radiusclient.conf")
+...
 
 3.2. caller_service_type (integer)
 
@@ -193,6 +194,7 @@ modparam("misc_radius", "radius_config", "/etc/radiusclient.conf")
    Example 1.3. caller_service_type parameter usage
 ...
 modparam("misc_radius", "caller_service_type", 18)
+...
 
 3.3. callee_service_type (integer)
 
@@ -204,6 +206,7 @@ modparam("misc_radius", "caller_service_type", 18)
    Example 1.4. callee_service_type parameter usage
 ...
 modparam("misc_radius", "callee_service_type", 19)
+...
 
 3.4. group_service_type (integer)
 
@@ -215,6 +218,7 @@ modparam("misc_radius", "callee_service_type", 19)
    Example 1.5. group_service_type parameter usage
 ...
 modparam("misc_radius", "group_service_type", 20)
+...
 
 3.5. uri_service_type (integer)
 
@@ -226,6 +230,7 @@ modparam("misc_radius", "group_service_type", 20)
    Example 1.6. uri_service_type parameter usage
 ...
 modparam("misc_radius", "uri_service_type", 21)
+...
 
 3.6. caller_extra (string)
 
@@ -240,6 +245,7 @@ modparam("misc_radius", "uri_service_type", 21)
    Example 1.7. caller_extra parameter usage
 ...
 modparam("misc_radius", "caller_extra", "Calling-Station-Id=$fu")
+...
 
 3.7. callee_extra (string)
 
@@ -254,6 +260,7 @@ modparam("misc_radius", "caller_extra", "Calling-Station-Id=$fu")
    Example 1.8. callee_extra parameter usage
 ...
 modparam("misc_radius", "callee_extra", "SIP-URI-User=$rU;SIP-URI-Host=$rd")
+...
 
 3.8. group_extra (string)
 
@@ -268,6 +275,7 @@ modparam("misc_radius", "callee_extra", "SIP-URI-User=$rU;SIP-URI-Host=$rd")
    Example 1.9. group_extra parameter usage
 ...
 modparam("misc_radius", "group_extra", "My-Special=$avp(i:100)")
+...
 
 3.9. uri_extra (string)
 
@@ -282,6 +290,7 @@ modparam("misc_radius", "group_extra", "My-Special=$avp(i:100)")
    Example 1.10. uri_extra parameter usage
 ...
 modparam("misc_radius", "uri_extra", "Called-Station-Id=$tu")
+...
 
 3.10. use_sip_uri_host (integer)
 
@@ -295,6 +304,7 @@ modparam("misc_radius", "uri_extra", "Called-Station-Id=$tu")
    Example 1.11. use_sip_uri_host parameter usage
 ...
 modparam("misc_radius", "use_sip_uri_host", 1)
+...
 
 3.11. common_response (integer)
 
diff --git a/src/modules/misc_radius/doc/misc_radius_admin.xml b/src/modules/misc_radius/doc/misc_radius_admin.xml
index a1a4aa7..0790bb3 100644
--- a/src/modules/misc_radius/doc/misc_radius_admin.xml
+++ b/src/modules/misc_radius/doc/misc_radius_admin.xml
@@ -12,13 +12,13 @@
 <!-- misc_radius Module User's Guide -->
 
 <chapter>
-	
+
 	<title>&adminguide;</title>
-	
+
 	<section>
 	<title>Overview</title>
 	<para>
-	The <emphasis>misc_radius</emphasis> module implements various 
+	The <emphasis>misc_radius</emphasis> module implements various
 	RADIUS related functions.
 	Functions exist for loading caller's or callee's
 	attributes into AVPs, checking if user belongs to a group, and
@@ -59,7 +59,7 @@
 	<para>
 	Unlike in old avp_radius module, functions
 	radius_load_calle[re]_avps() do not prefix string names of AVPs
-	by string 
+	by string
 	<quote>caller_</quote> or <quote>callee_</quote> depending if
 	caller's or callee's attributes were loaded.  If you need these
 	prefixes, make your RADIUS server to prepend them into attribute
@@ -77,7 +77,7 @@
 		<section>
 		<title>&kamailio; Modules</title>
 			<para>
-			The module depends on the following modules (in the other words 
+			The module depends on the following modules (in the other words
 			the listed modules must be loaded before this module):
 			<itemizedlist>
 				<listitem>
@@ -123,14 +123,14 @@
 
 	<section>
 	<title>Parameters</title>
-	<section>
+	<section id="mrad.p.config">
 		<title><varname>radius_config</varname> (string)</title>
 		<para>
-		This is the location of the configuration file of radius client 
+		This is the location of the configuration file of radius client
 		libraries.
 		</para>
 		<para>
-		Default value is 
+		Default value is
 			<quote>/usr/local/etc/radiusclient-ng/radiusclient.conf</quote>.
 		</para>
 		<example>
@@ -138,10 +138,11 @@
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "radius_config", "/etc/radiusclient.conf")
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.caller_srv_type">
 		<title><varname>caller_service_type</varname> (integer)</title>
 		<para>
 		This is the value of the Service-Type radius attribute to be
@@ -156,10 +157,11 @@ modparam("misc_radius", "radius_config", "/etc/radiusclient.conf")
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "caller_service_type", 18)
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.callee_srv_type">
 		<title><varname>callee_service_type</varname> (integer)</title>
 		<para>
 		This is the value of the Service-Type radius attribute to be
@@ -174,10 +176,11 @@ modparam("misc_radius", "caller_service_type", 18)
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "callee_service_type", 19)
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.group_srv_type">
 		<title><varname>group_service_type</varname> (integer)</title>
 		<para>
 		This is the value of Service-Type RADIUS attribute to be
@@ -192,10 +195,11 @@ modparam("misc_radius", "callee_service_type", 19)
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "group_service_type", 20)
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.uri_srv_type">
 		<title><varname>uri_service_type</varname> (integer)</title>
 		<para>
 		This is the value of Service-Type RADIUS attribute to be
@@ -211,15 +215,16 @@ modparam("misc_radius", "group_service_type", 20)
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "uri_service_type", 21)
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.caller_extra">
 		<title><varname>caller_extra</varname> (string)</title>
 		<para>
 		Semi-colon separated list of extra RADIUS
 	        attribute name=pseudo variable pairs.  When
-		radius_load_caller_avps() is called, the listed extra 
+		radius_load_caller_avps() is called, the listed extra
 		attributes are included RADIUS request with
 		current values of corresponding pseudo variables.
 		</para>
@@ -232,15 +237,16 @@ modparam("misc_radius", "uri_service_type", 21)
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "caller_extra", "Calling-Station-Id=$fu")
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.callee_extra">
 		<title><varname>callee_extra</varname> (string)</title>
 		<para>
 		Semi-colon separated list of extra RADIUS
 	        attribute name=pseudo variable pairs.  When
-		radius_load_callee_avps() is called, the listed extra 
+		radius_load_callee_avps() is called, the listed extra
 		attributes are included RADIUS request with
 		current values of corresponding pseudo variables.
 		</para>
@@ -253,15 +259,16 @@ modparam("misc_radius", "caller_extra", "Calling-Station-Id=$fu")
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "callee_extra", "SIP-URI-User=$rU;SIP-URI-Host=$rd")
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.group_extra">
 		<title><varname>group_extra</varname> (string)</title>
 		<para>
 		Semi-colon separated list of extra RADIUS
 	        attribute name=pseudo variable pairs.  When
-		radius_is_user_in() is called, the listed extra 
+		radius_is_user_in() is called, the listed extra
 		attributes are included RADIUS request with
 		current values of corresponding pseudo variables.
 		</para>
@@ -274,16 +281,17 @@ modparam("misc_radius", "callee_extra", "SIP-URI-User=$rU;SIP-URI-Host=$rd")
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "group_extra", "My-Special=$avp(i:100)")
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.uri_extra">
 		<title><varname>uri_extra</varname> (string)</title>
 		<para>
 		Semi-colon separated list of extra RADIUS
 	        attribute name=pseudo variable pairs.  When
 		radius_does_uri[_user]_exist() function is called, the
-		listed extra  
+		listed extra
 		attributes are included in RADIUS request with
 		current values of corresponding pseudo variables.
 		</para>
@@ -296,11 +304,12 @@ modparam("misc_radius", "group_extra", "My-Special=$avp(i:100)")
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "uri_extra", "Called-Station-Id=$tu")
+...
 </programlisting>
 		</example>
 	</section>
 
-	<section>
+	<section id="mrad.p.use_sip_uri_host">
 		<title><varname>use_sip_uri_host</varname> (integer)</title>
 		<para>
 		If zero, radius_does_uri_exist() function sends to
@@ -317,10 +326,11 @@ modparam("misc_radius", "uri_extra", "Called-Station-Id=$tu")
 		<programlisting format="linespecific">
 ...
 modparam("misc_radius", "use_sip_uri_host", 1)
+...
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="mrad.p.common_response">
 		<title><varname>common_response</varname> (integer)</title>
 		<para>
 		Set it to 1 if you need common radius response attributes to
@@ -371,7 +381,7 @@ $avp(SIP-AVP) has string value  "email:sr-users at lists.sip-router.org session-tim
 	<section>
 	<title>Functions</title>
 
-	<section>
+	<section id="mrad.f.load_caller_avps">
 		<title><function
 	moreinfo="none">radius_load_caller_avps(caller)</function></title>
 		<para>
@@ -395,7 +405,7 @@ radius_load_caller_avps("$au@$ar");	# take caller from Authorization
 		</example>
 	</section>
 
-	<section>
+	<section id="mrad.f.load_callee_avps">
 		<title><function
 	moreinfo="none">radius_load_callee_avps(callee)</function></title>
 		<para>
@@ -417,7 +427,7 @@ radius_load_callee_avps("$rU@$rd");	# take callee from Request-URI
 		</example>
 	</section>
 
-	<section>
+	<section id="mrad.f.is_user_in">
 		<title><function
 	moreinfo="none">radius_is_user_in(user, group)</function></title>
 		<para>
@@ -443,13 +453,13 @@ radius_is_user_in("$au@$ar", "group_x");# take user from credentials
 		</example>
 	</section>
 
-	<section>
+	<section id="mrad.f.does_uri_exist">
 		<title><function
-		moreinfo="none">radius_does_uri_exist([uri])</function></title> 
+		moreinfo="none">radius_does_uri_exist([uri])</function></title>
 		<para>
 		Checks from RADIUS if userpart at hostpart of Request-URI
 		or of an URI stored in optional pseudo variable argument
-		belongs to a local 
+		belongs to a local
 		user.  In case of positive result, loads AVPs from
 		SIP-AVP reply items, if any.
 		</para>
@@ -469,7 +479,7 @@ if (radius_does_uri_exist("$avp(i:99)")) ...	# check URI in $avp(i:99)
 		</example>
 	</section>
 
-	<section>
+	<section id="mrad.f.does_uri_user_exist">
 		<title><function
 	moreinfo="none">radius_does_uri_user_exist([user])</function></title>
 		<para>
diff --git a/src/modules/msrp/msrp_netio.c b/src/modules/msrp/msrp_netio.c
index 5f0e120..76d3506 100644
--- a/src/modules/msrp/msrp_netio.c
+++ b/src/modules/msrp/msrp_netio.c
@@ -43,7 +43,7 @@ int msrp_forward_frame(msrp_frame_t *mf, int flags)
 	if ((msrp_uri_to_dstinfo(0, &dst, uac_r->dialog->send_sock, snd_flags,
 						uac_r->dialog->hooks.next_hop, PROTO_NONE)==0) ||
 				(dst.send_sock==0)){
-			LOG(L_ERR, "no send socket found\n");
+			LM_ERR("no send socket found\n");
 			return -1;
 		}
 #endif
@@ -157,7 +157,7 @@ done:
 			LM_WARN("TCP/TLS connection not found\n");
 			return -1;
 		}
-	
+
 		if (unlikely((con->rcv.proto == PROTO_WS || con->rcv.proto == PROTO_WSS)
 				&& sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
 			ws_event_info_t wsev;
@@ -329,13 +329,13 @@ struct dest_info *msrp_uri_to_dstinfo(struct dns_srv_handle* dns_h,
 		LM_ERR("bad msrp uri: %.*s\n", uri->len, uri->s );
 		return 0;
 	}
-	
+
 	if (parsed_uri.scheme_no==MSRP_SCHEME_MSRPS){
 		dst->proto = PROTO_TLS;
 	} else {
 		dst->proto = PROTO_TCP;
 	}
-	
+
 	dst->send_flags=sflags;
 	host=&parsed_uri.host;
 	port = parsed_uri.port_no;
@@ -367,20 +367,20 @@ struct dest_info *msrp_uri_to_dstinfo(struct dns_srv_handle* dns_h,
 				return dst; /* found a good one */
 			}
 		} while(dns_srv_handle_next(dns_h, err));
-		ERR("no corresponding socket for \"%.*s\" af %d\n", host->len, 
+		LM_ERR("no corresponding socket for \"%.*s\" af %d\n", host->len,
 				ZSW(host->s), dst->to.s.sa_family);
 		/* try to continue */
 		return dst;
 	}
 
 	if (sip_hostport2su(&dst->to, host, port, &dst->proto)!=0){
-		ERR("failed to resolve \"%.*s\"\n", host->len, ZSW(host->s));
+		LM_ERR("failed to resolve \"%.*s\"\n", host->len, ZSW(host->s));
 		return 0;
 	}
 	dst->send_sock = get_send_socket2(force_send_socket, &dst->to,
 			dst->proto, 0);
 	if (dst->send_sock==0) {
-		ERR("no corresponding socket for af %d\n", dst->to.s.sa_family);
+		LM_ERR("no corresponding socket for af %d\n", dst->to.s.sa_family);
 		/* try to continue */
 	}
 	return dst;
diff --git a/src/modules/nat_traversal/README b/src/modules/nat_traversal/README
index 9b37228..c305486 100644
--- a/src/modules/nat_traversal/README
+++ b/src/modules/nat_traversal/README
@@ -50,7 +50,7 @@ Dan Pascu
               6.3. subscribed_endpoints
               6.4. dialog_endpoints
 
-        7. Exported pseudo-variables
+        7. Pseudo Variables
 
               7.1. $keepalive.socket(nat_endpoint)
               7.2. $source_uri
@@ -113,7 +113,7 @@ Chapter 1. Admin Guide
         6.3. subscribed_endpoints
         6.4. dialog_endpoints
 
-   7. Exported pseudo-variables
+   7. Pseudo Variables
 
         7.1. $keepalive.socket(nat_endpoint)
         7.2. $source_uri
@@ -605,7 +605,7 @@ if ((method=="REGISTER" || method=="SUBSCRIBE" ||
    Indicates how many of the NAT endpoints are kept alive for taking part
    in an INVITE dialog.
 
-7. Exported pseudo-variables
+7. Pseudo Variables
 
    7.1. $keepalive.socket(nat_endpoint)
    7.2. $source_uri
diff --git a/src/modules/nat_traversal/doc/nat_traversal_admin.xml b/src/modules/nat_traversal/doc/nat_traversal_admin.xml
index 7067225..f031cc8 100644
--- a/src/modules/nat_traversal/doc/nat_traversal_admin.xml
+++ b/src/modules/nat_traversal/doc/nat_traversal_admin.xml
@@ -10,9 +10,9 @@
 <!-- Module's Admin Guide -->
 
 <chapter>
-  
+
   <title>&adminguide;</title>
-  
+
   <section>
   <title>Overview</title>
     <para>
@@ -33,7 +33,7 @@
       and hasn't been adapted to support IPv6 session keepalives.
     </para>
   </section>
-  
+
   <section>
   <title>Keepalive functionality</title>
     <section>
@@ -230,7 +230,7 @@
               <emphasis>REGISTER</emphasis> - called before save_location() or
               t_relay() (depending on whether the proxy that received the
               REGISTER is also handling registration for that subscriber or
-              not). It will determine from either the stateless reply 
+              not). It will determine from either the stateless reply
               generated by save_location() or the TM relayed reply if the
               registration was successful and what is its expiration time. If
               the registration was successful it will mark the given NAT
@@ -280,7 +280,7 @@
               if they are behind NAT. This is done by detecting if any of the
               destination endpoints already has a keepalive entry for the
               register condition. If so, a dialog condition will be added to
-              that entry thus preserving that endpoint visibility even if the 
+              that entry thus preserving that endpoint visibility even if the
               registration expires during the dialog or is moved to another
               proxy. During the call setup stage, multiple entries for the
               callee may be added with the dialog condition if parallel
@@ -354,8 +354,8 @@
       </para>
     </section>
   </section>
-  
-  <section>
+
+  <section id="nat_traversal.p.keepalive_interval">
   <title>Exported parameters</title>
     <section>
     <title><varname>keepalive_interval</varname> (integer)</title>
@@ -379,8 +379,8 @@ modparam("nat_traversal", "keepalive_interval", 90)
         </programlisting>
       </example>
     </section>
-  
-    <section>
+
+    <section id="nat_traversal.p.keepalive_method">
     <title><varname>keepalive_method</varname> (string)</title>
       <para>
         What SIP method to use to send keepalive messages. Typical methods
@@ -416,8 +416,8 @@ modparam("nat_traversal", "keepalive_method", "OPTIONS")
         </programlisting>
       </example>
     </section>
-  
-    <section>
+
+    <section id="nat_traversal.p.keepalive_from">
     <title><varname>keepalive_from</varname> (string)</title>
       <para>
         Indicates what SIP URI to use in the From header of the keepalive
@@ -441,8 +441,8 @@ modparam("nat_traversal", "keepalive_from", "sip:keepalive at my-domain.com")
         </programlisting>
       </example>
     </section>
-  
-    <section>
+
+    <section id="nat_traversal.p.keepalive_extra_headers">
     <title><varname>keepalive_extra_headers</varname> (string)</title>
       <para>
         Specifies extra headers that should be added to the keepalive messages
@@ -464,8 +464,8 @@ modparam("nat_traversal", "keepalive_extra_headers", "User-Agent: &kamailio;\r\n
         </programlisting>
       </example>
     </section>
-  
-    <section>
+
+    <section id="nat_traversal.p.keepalive_state_file">
     <title><varname>keepalive_state_file</varname> (string)</title>
       <para>
         Specifies a filename where information about the NAT endpoints and the
@@ -497,10 +497,10 @@ modparam("nat_traversal", "keepalive_state_file", "/var/run/kamailio/keepalive_s
         </programlisting>
       </example>
     </section>
-  
+
   </section>
 
-  <section>
+  <section id="nat_traversal.f.client_nat_test">
   <title>Exported functions</title>
     <section>
     <title>
@@ -517,7 +517,7 @@ modparam("nat_traversal", "keepalive_state_file", "/var/run/kamailio/keepalive_s
         <itemizedlist>
         <listitem><para>
           1 - tests if client has a private IP address (as defined by RFC1918)
-              or one from shared address space (RFC6598) in the Contact field 
+              or one from shared address space (RFC6598) in the Contact field
               of the SIP message.
         </para></listitem>
         <listitem><para>
@@ -527,7 +527,7 @@ modparam("nat_traversal", "keepalive_state_file", "/var/run/kamailio/keepalive_s
         </para></listitem>
         <listitem><para>
           4 - tests if client has a private IP address (as defined by RFC1918)
-              or one from shared address space (RFC6598) in the top Via field 
+              or one from shared address space (RFC6598) in the top Via field
               of the SIP message.
         </para></listitem>
         </itemizedlist>
@@ -554,7 +554,7 @@ if (client_nat_test("3")) {
       </example>
     </section>
 
-    <section>
+    <section id="nat_traversal.f.fix_contact">
     <title>
     <function moreinfo="none">fix_contact()</function>
     </title>
@@ -580,7 +580,7 @@ if (client_nat_test("3")) {
       </example>
     </section>
 
-    <section>
+    <section id="nat_traversal.f.nat_keepalive">
     <title>
     <function moreinfo="none">nat_keepalive()</function>
     </title>
@@ -651,7 +651,7 @@ if ((method=="REGISTER" || method=="SUBSCRIBE" ||
   </section>
 
   <section>
-  <title>Exported pseudo-variables</title>
+  <title>Pseudo Variables</title>
     <section>
     <title><varname>$keepalive.socket(nat_endpoint)</varname></title>
       <para>
@@ -747,7 +747,7 @@ if (method=="REGISTER") {
         force_rport();
         $avp(s:received_uri) = $source_uri;
         # or we could add some extra parameters to it if needed
-        # $avp(s:received_uri) = $source_uri + ";relayed=false" 
+        # $avp(s:received_uri) = $source_uri + ";relayed=false"
     }
     if (!www_authorize("", "subscriber")) {
         www_challenge("", "0");
diff --git a/src/modules/presence_conference/add_events.c b/src/modules/presence_conference/add_events.c
index 8db8ce9..576746e 100644
--- a/src/modules/presence_conference/add_events.c
+++ b/src/modules/presence_conference/add_events.c
@@ -1,6 +1,6 @@
 /*
  * add "conference" event to presence module - mariusbucur
- * 
+ *
  * Copyright (C) 2010 Marius Bucur
  * Copyright (C) 2007 Juha Heinanen
  * Copyright (C) 2008 Klaus Darilion, IPCom
@@ -17,13 +17,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 
 #include <stdio.h>
@@ -37,7 +34,7 @@
 int conference_add_events(void)
 {
     pres_ev_t event;
-	
+
     /* constructing "conference" event and add it to the list of events packages supported */
     memset(&event, 0, sizeof(pres_ev_t));
     event.name.s = "conference";
@@ -58,12 +55,10 @@ int conference_add_events(void)
     /* modify XML body for each watcher to set the correct "version" */
     event.aux_body_processing = conf_body_setversion;
 
-	
     if (pres_add_event(&event) < 0) {
 		LM_ERR("failed to add event \"conference\"\n");
 		return -1;
     }
-	
+
     return 0;
 }
-
diff --git a/src/modules/presence_conference/add_events.h b/src/modules/presence_conference/add_events.h
index eb997be..08554ba 100644
--- a/src/modules/presence_conference/add_events.h
+++ b/src/modules/presence_conference/add_events.h
@@ -16,13 +16,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 
 #ifndef _CONF_ADD_EV_H_
diff --git a/src/modules/presence_conference/notify_body.c b/src/modules/presence_conference/notify_body.c
index 78108dd..7118850 100644
--- a/src/modules/presence_conference/notify_body.c
+++ b/src/modules/presence_conference/notify_body.c
@@ -21,9 +21,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 /*! \file
  * \brief Kamailio Presence_Conference :: Notify body handling
@@ -78,12 +75,12 @@ str* conf_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, i
 	}
 
 	return n_body;
-}	
+}
 
 str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, int off_index)
 {
 	int i, j = 0;
-	
+
 	if(body_array == NULL || n == 0)
 		return 0;
 
@@ -115,7 +112,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, in
 			continue;
 
 		xml_array[j] = xmlParseMemory( body_array[i]->s, body_array[i]->len );
-		
+
 		/* LM_DBG("parsing XML body: [n]=%d, [i]=%d, [j]=%d xml_array[j]=%p\n", n, i, j, xml_array[j] ); */
 
 		if(unlikely(xml_array[j] == NULL))
@@ -124,7 +121,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, in
 			goto error;
 		}
 		j++;
-		
+
 	}
 
 	if(j == 0)  /* no body */
@@ -206,8 +203,8 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, in
 		ERR_MEM(PKG_MEM_STR);
 	}
 
-	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, 
-			&body->len, 1);	
+	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s,
+			&body->len, 1);
 
 	for(i=0; i<j; i++)
 	{
@@ -218,7 +215,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n, in
 		xmlFreeDoc(doc);
 	if(xml_array!=NULL)
 		pkg_free(xml_array);
-    
+
 	return body;
 
 error:
@@ -244,7 +241,7 @@ str *conf_body_setversion(subs_t *subs, str *body) {
 	if (!body) {
 		return NULL;
 	}
-	
+
 	xmlDocPtr doc = xmlParseMemory(body->s, body->len);
 	if(!doc) {
 		goto error;
@@ -256,7 +253,7 @@ str *conf_body_setversion(subs_t *subs, str *body) {
 	if(!xmlSetProp(conf_info, BAD_CAST "version", BAD_CAST version_str)) {
 		goto error;
 	}
-	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, 
+	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s,
 			&body->len, 1);
 	return NULL;
 error:
diff --git a/src/modules/presence_conference/notify_body.h b/src/modules/presence_conference/notify_body.h
index 39e8f1b..ca9d2ad 100644
--- a/src/modules/presence_conference/notify_body.h
+++ b/src/modules/presence_conference/notify_body.h
@@ -1,5 +1,4 @@
 /*
- *
  * presence_conference module - notify_body header file mariusbucur
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
@@ -17,13 +16,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 /*! \file
  * \brief Kamailio Presence_Conference :: Notify body handling
diff --git a/src/modules/presence_conference/pidf.c b/src/modules/presence_conference/pidf.c
index 7c8f1c1..ce4c39b 100644
--- a/src/modules/presence_conference/pidf.c
+++ b/src/modules/presence_conference/pidf.c
@@ -1,6 +1,4 @@
 /*
- * $Id: pidf.c 1953 2007-04-04 08:50:33Z anca_vamanu $
- *
  * presence module - presence server implementation
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
@@ -17,13 +15,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- *  2007-04-14  initial version (anca)
  */
 
 /*! \file
@@ -122,7 +117,7 @@ xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns)
 	return xmlNodeGetNodeByName(cur, name, ns);
 }
 
-char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name, 
+char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name,
 		const char *ns)
 {
 	xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns);
@@ -154,7 +149,7 @@ time_t xml_parse_dateTime(char* xml_time_str)
 		printf("error: failed to parse time\n");
 		return 0;
 	}
-	
+
 	if(*p== '\0')
 		goto done;
 
@@ -171,7 +166,7 @@ time_t xml_parse_dateTime(char* xml_time_str)
 	if(*p== '\0')
 		goto done;
 
-	
+
 	/* read time zone */
 
 	if(*p== 'Z')
@@ -188,14 +183,14 @@ time_t xml_parse_dateTime(char* xml_time_str)
 		printf("error: failed to parse time\n");
 		return 0;
 	}
-	
+
 	h= (h1- '0')*10+ h2- '0';
 	m= (m1- '0')*10+ m2- '0';
 
 	timezone_diff= sign* ((m+ h* 60)* 60);
 
 done:
-	return (mktime(&tm) + timezone_diff);	
+	return (mktime(&tm) + timezone_diff);
 }
 
 
diff --git a/src/modules/presence_conference/pidf.h b/src/modules/presence_conference/pidf.h
index e9f09b3..e555d90 100644
--- a/src/modules/presence_conference/pidf.h
+++ b/src/modules/presence_conference/pidf.h
@@ -1,6 +1,4 @@
 /*
- * $Id: pidf.h 1401 2006-12-14 11:12:42Z anca_vamanu $
- *
  * presence module - presence server implementation
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
@@ -21,9 +19,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- *  2006-08-15  initial version (anca)
  */
 
 /*! \file
diff --git a/src/modules/presence_conference/presence_conference.c b/src/modules/presence_conference/presence_conference.c
index b21d6b3..99c6aaf 100644
--- a/src/modules/presence_conference/presence_conference.c
+++ b/src/modules/presence_conference/presence_conference.c
@@ -21,9 +21,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 
 #include <stdio.h>
diff --git a/src/modules/presence_conference/presence_conference.h b/src/modules/presence_conference/presence_conference.h
index dd0ded3..f8e0efe 100644
--- a/src/modules/presence_conference/presence_conference.h
+++ b/src/modules/presence_conference/presence_conference.h
@@ -16,13 +16,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2010-07-12  initial version (mariusbucur)
  */
 
 #ifndef _PRES_CONFERENCE_H_
diff --git a/src/modules/presence_xml/README b/src/modules/presence_xml/README
index 4b26628..045edce 100644
--- a/src/modules/presence_xml/README
+++ b/src/modules/presence_xml/README
@@ -119,8 +119,8 @@ Chapter 1. Admin Guide
      * presence.
      * sl.
      * xcap_client.
-       Only compulsory if not using an integrated xcap server (if
-       'integrated_xcap_server' parameter is not set).
+       Needed only when not using the integrated xcap server (if
+       'integrated_xcap_server' parameter is set to 0).
 
 2.2. External Libraries or Applications
 
@@ -223,15 +223,15 @@ modparam("presence_xml", "force_active", 1)
    This parameter is a flag for the type of XCAP servers used. If the XCAP
    server is integrated with Kamailio presence_xml module and access the
    same database tables directly, like the embedded XCAP server
-   implemented in xcap_server module, the parameter should be set to a
-   positive value. Apart from updating in xcap table, if the integrated
-   server is not running on the same Kamailio instance, it must send an
-   RPC command presence.refreshWatchers [pres_uri] [event] when a user
-   modifies a rules document, to instruct the presence_xml module to
-   update states from the database and, if needed, send NOTIFY updates.
-
-   Otherwise, it uses xcap_client module to fetch documents from the XCAP
-   servers with HTTP requests.
+   implemented in xcap_server module, the parameter has to be set to 1.
+   Apart from updating in xcap table, if the integrated server is not
+   running on the same Kamailio instance, it must send an RPC command
+   presence.refreshWatchers [pres_uri] [event] when a user modifies a
+   rules document, to instruct the presence_xml module to update states
+   from the database and, if needed, send NOTIFY updates.
+
+   Otherwise (if set to 0) it uses xcap_client module to fetch documents
+   from the XCAP servers with HTTP requests.
 
    Default value is “0”.
 
diff --git a/src/modules/presence_xml/doc/presence_xml_admin.xml b/src/modules/presence_xml/doc/presence_xml_admin.xml
index 8c4213b..3189454 100644
--- a/src/modules/presence_xml/doc/presence_xml_admin.xml
+++ b/src/modules/presence_xml/doc/presence_xml_admin.xml
@@ -71,8 +71,8 @@
 				<emphasis>xcap_client</emphasis>.
 			</para>
 			<para>
-			Only compulsory if not using an integrated xcap server
-			(if 'integrated_xcap_server' parameter is not set).
+			Needed only when not using the integrated xcap server
+			(if 'integrated_xcap_server' parameter is set to 0).
 			</para>
 			</listitem>
 
@@ -98,13 +98,13 @@
 
 	<section>
 	<title>Parameters</title>
-	<section>
+	<section id="presence_xml.p.db_url">
 		<title><varname>db_url</varname>(str)</title>
 		<para>
 		The database URL.
 		</para>
 		<para>
-		<emphasis>	Default value is <quote>&defaultdb;</quote>.
+		<emphasis>Default value is <quote>&defaultdb;</quote>.
 		</emphasis>
 		</para>
 		<example>
@@ -116,13 +116,13 @@ modparam("presence_xml", "db_url", "&exampledb;")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.xcap_table">
 		<title><varname>xcap_table</varname>(str)</title>
 		<para>
 		The name of the database table where XCAP documents are stored.
 		</para>
 		<para>
-		<emphasis>	Default value is <quote>xcap</quote>.
+		<emphasis>Default value is <quote>xcap</quote>.
 		</emphasis>
 		</para>
 		<example>
@@ -135,7 +135,7 @@ modparam("presence_xml", "xcap_table", "xcaps")
 		</example>
 	</section>
 
-	<section>
+	<section id="presence_xml.p.disable_presence">
 		<title><varname>disable_presence</varname>(int)</title>
 		<para>
 		Set this parameter to disable the handling of the "presence" event.
@@ -153,7 +153,7 @@ modparam("presence_xml", "disable_presence", 1)
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.disable_winfo">
 		<title><varname>disable_winfo</varname>(int)</title>
 		<para>
 		Set this parameter to disable the handling of the "presence.winfo" event.
@@ -171,7 +171,7 @@ modparam("presence_xml", "disable_winfo", 1)
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.disable_bla">
 		<title><varname>disable_bla</varname>(int)</title>
 		<para>
 		Set this parameter to disable the handling of the "dialog;sla" event.
@@ -190,7 +190,7 @@ modparam("presence_xml", "disable_bla", 1)
 		</example>
 	</section>
 
-	<section>
+	<section id="presence_xml.p.force_active">
 		<title><varname>force_active</varname> (int)</title>
 		<para>
 		This parameter is used for permissions when handling Subscribe messages.
@@ -219,14 +219,14 @@ modparam("presence_xml", "force_active", 1)
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.integrated_xcap_server">
 		<title><varname>integrated_xcap_server</varname> (int)</title>
 		<para>
 		This parameter is a flag for the type of XCAP servers
 		used. If the XCAP server is integrated with &kamailio; presence_xml
 		module and access the same database tables directly, like the embedded
-		XCAP server implemented in xcap_server module, the parameter should be
-		set to a positive value. Apart from updating in xcap table,
+		XCAP server implemented in xcap_server module, the parameter has to be
+		set to 1. Apart from updating in xcap table,
 		if the integrated server is not running on the same &kamailio; instance,
 		it must send an RPC command presence.refreshWatchers
 		[pres_uri] [event] when a user modifies a rules document, to
@@ -234,7 +234,7 @@ modparam("presence_xml", "force_active", 1)
 		and, if needed, send NOTIFY updates.
 		</para>
 		<para>
-		Otherwise, it uses xcap_client module to fetch documents
+		Otherwise (if set to 0) it uses xcap_client module to fetch documents
 		from the XCAP servers with HTTP requests.</para>
 		<para>
 		<emphasis>Default value is <quote>0</quote>.
@@ -249,7 +249,7 @@ modparam("presence_xml", "integrated_xcap_server", 1)
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.xcap_server">
 		<title><varname>xcap_server</varname> (str)</title>
 		<para>
 		The address of the xcap servers used for storage.
@@ -266,7 +266,7 @@ modparam("presence_xml", "xcap_server", "xcap_server.ag.org")
 </programlisting>
 		</example>
 	</section>
-	<section>
+	<section id="presence_xml.p.passive_mode">
 		<title><varname>passive_mode</varname>(int)</title>
 		<para>
 		If set to 1, module acts in passive mode - no bind to presence module,
@@ -288,7 +288,7 @@ modparam("presence_xml", "passive_mode", 1)
 		</example>
 	</section>
 
-	<section>
+	<section id="presence_xml.p.xcapauth_userdel_reason">
 		<title><varname>xcapauth_userdel_reason</varname>(str)</title>
 		<para>
 		This parameter represents the reason that will be included in the
@@ -315,7 +315,7 @@ modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
 </programlisting>
 		</example>
 	</section>
-    <section>
+    <section id="presence_xml.p.force_dummy_presence">
         <title><varname>force_dummy_presence</varname>(int)</title>
         <para>
         Set this parameter to enable simple body notify with status 'open' when presentity info is not available.
diff --git a/src/modules/pua_dialoginfo/dialog_publish.c b/src/modules/pua_dialoginfo/dialog_publish.c
index ce9fe96..1abe8cb 100644
--- a/src/modules/pua_dialoginfo/dialog_publish.c
+++ b/src/modules/pua_dialoginfo/dialog_publish.c
@@ -1,6 +1,4 @@
 /*
- * $Id: ul_publish.c 4518 2008-07-28 15:39:28Z henningw $
- *
  * pua_usrloc module - usrloc pua module
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
@@ -17,8 +15,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -53,13 +51,13 @@ void print_publ(publ_info_t* p)
 	LM_DBG("uri= %.*s\n", p->pres_uri->len, p->pres_uri->s);
 	LM_DBG("id= %.*s\n", p->id.len, p->id.s);
 	LM_DBG("expires= %d\n", p->expires);
-}	
+}
 
-str* build_dialoginfo(char *state, str *entity, str *peer, str *callid, 
-	unsigned int initiator, str *localtag, str *remotetag,
-	str *localtarget, str *remotetarget)
+str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
+		unsigned int initiator, str *localtag, str *remotetag,
+		str *localtarget, str *remotetarget)
 {
-	xmlDocPtr  doc = NULL; 
+	xmlDocPtr  doc = NULL;
 	xmlNodePtr root_node = NULL;
 	xmlNodePtr dialog_node = NULL;
 	xmlNodePtr state_node = NULL;
@@ -70,7 +68,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	char buf[MAX_URI_SIZE+1];
 
 	if (entity->len > MAX_URI_SIZE) {
-		LM_ERR("entity URI '%.*s' too long, maximum=%d\n",entity->len, entity->s, MAX_URI_SIZE);
+		LM_ERR("entity URI '%.*s' too long, maximum=%d\n",entity->len,
+				entity->s, MAX_URI_SIZE);
 		return NULL;
 	}
 	memcpy(buf, entity->s, entity->len);
@@ -90,22 +89,22 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	xmlNewProp(root_node, BAD_CAST "xmlns",
 			BAD_CAST "urn:ietf:params:xml:ns:dialog-info");
 	/* we set the version to 0 but it should be set to the correct value
-	in the pua module */
+	 * in the pua module */
 	xmlNewProp(root_node, BAD_CAST "version",
 			BAD_CAST "0");
 	xmlNewProp(root_node, BAD_CAST  "state",
 			BAD_CAST "full" );
-	xmlNewProp(root_node, BAD_CAST "entity", 
+	xmlNewProp(root_node, BAD_CAST "entity",
 			BAD_CAST buf);
 
 	/* RFC 3245 differs between id and call-id. For example if a call
-	   is forked and 2 early dialogs are established, we should send 2
-	   PUBLISH requests, both have the same call-id but different id.
-	   Thus, id could be for example derived from the totag.
-
-	   Currently the dialog module does not support multiple dialogs.
-	   Thus, it does no make sense to differ here between multiple dialog.
-	   Thus, id and call-id will be populated identically */
+	 * is forked and 2 early dialogs are established, we should send 2
+	 * PUBLISH requests, both have the same call-id but different id.
+	 * Thus, id could be for example derived from the totag.
+	 *
+	 * Currently the dialog module does not support multiple dialogs.
+	 * Thus, it does no make sense to differ here between multiple dialog.
+	 * Thus, id and call-id will be populated identically */
 
 	/* dialog tag */
 	dialog_node =xmlNewChild(root_node, NULL, BAD_CAST "dialog", NULL) ;
@@ -116,7 +115,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	}
 
 	if (callid->len > MAX_URI_SIZE) {
-		LM_ERR("call-id '%.*s' too long, maximum=%d\n", callid->len, callid->s, MAX_URI_SIZE);
+		LM_ERR("call-id '%.*s' too long, maximum=%d\n", callid->len,
+				callid->s, MAX_URI_SIZE);
 		goto error;
 	}
 	memcpy(buf, callid->s, callid->len);
@@ -129,7 +129,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	if (include_tags) {
 		if (localtag && localtag->s) {
 			if (localtag->len > MAX_URI_SIZE) {
-				LM_ERR("localtag '%.*s' too long, maximum=%d\n", localtag->len, localtag->s, MAX_URI_SIZE);
+				LM_ERR("localtag '%.*s' too long, maximum=%d\n",
+						localtag->len, localtag->s, MAX_URI_SIZE);
 				goto error;
 			}
 			memcpy(buf, localtag->s, localtag->len);
@@ -138,7 +139,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 		}
 		if (remotetag && remotetag->s) {
 			if (remotetag->len > MAX_URI_SIZE) {
-				LM_ERR("remotetag '%.*s' too long, maximum=%d\n", remotetag->len, remotetag->s, MAX_URI_SIZE);
+				LM_ERR("remotetag '%.*s' too long, maximum=%d\n",
+						remotetag->len, remotetag->s, MAX_URI_SIZE);
 				goto error;
 			}
 			memcpy(buf, remotetag->s, remotetag->len);
@@ -154,7 +156,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	}
 
 	/* state tag */
-	state_node = xmlNewChild(dialog_node, NULL, BAD_CAST "state", BAD_CAST state) ;
+	state_node = xmlNewChild(dialog_node, NULL, BAD_CAST "state",
+			BAD_CAST state) ;
 	if( state_node ==NULL)
 	{
 		LM_ERR("while adding child\n");
@@ -162,7 +165,7 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 	}
 
 	if (include_localremote) {
-		/* remote tag*/	
+		/* remote tag*/
 		remote_node = xmlNewChild(dialog_node, NULL, BAD_CAST "remote", NULL) ;
 		if( remote_node ==NULL)
 		{
@@ -171,19 +174,21 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 		}
 
 		if (peer->len > MAX_URI_SIZE) {
-			LM_ERR("peer '%.*s' too long, maximum=%d\n", peer->len, peer->s, MAX_URI_SIZE);
+			LM_ERR("peer '%.*s' too long, maximum=%d\n", peer->len, peer->s,
+					MAX_URI_SIZE);
 			goto error;
 		}
 		memcpy(buf, peer->s, peer->len);
 		buf[peer->len]= '\0';
 
-		tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "identity", BAD_CAST buf) ;
+		tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "identity",
+				BAD_CAST buf) ;
 		if( tag_node ==NULL)
 		{
 			LM_ERR("while adding child\n");
 			goto error;
 		}
-		tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "target", NULL) ;
+		tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "target", NULL);
 		if( tag_node ==NULL)
 		{
 			LM_ERR("while adding child\n");
@@ -195,8 +200,8 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 		}
 		xmlNewProp(tag_node, BAD_CAST "uri", BAD_CAST buf);
 
-		/* local tag*/	
-		local_node = xmlNewChild(dialog_node, NULL, BAD_CAST "local", NULL) ;
+		/* local tag*/
+		local_node = xmlNewChild(dialog_node, NULL, BAD_CAST "local", NULL);
 		if( local_node ==NULL)
 		{
 			LM_ERR("while adding child\n");
@@ -204,19 +209,21 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
 		}
 
 		if (entity->len > MAX_URI_SIZE) {
-			LM_ERR("entity '%.*s' too long, maximum=%d\n", entity->len, entity->s, MAX_URI_SIZE);
+			LM_ERR("entity '%.*s' too long, maximum=%d\n",
+					entity->len, entity->s, MAX_URI_SIZE);
 			goto error;
 		}
 		memcpy(buf, entity->s, entity->len);
 		buf[entity->len]= '\0';
 
-		tag_node = xmlNewChild(local_node, NULL, BAD_CAST "identity", BAD_CAST buf) ;
+		tag_node = xmlNewChild(local_node, NULL, BAD_CAST "identity",
+				BAD_CAST buf) ;
 		if( tag_node ==NULL)
 		{
 			LM_ERR("while adding child\n");
 			goto error;
 		}
-		tag_node = xmlNewChild(local_node, NULL, BAD_CAST "target", NULL) ;
+		tag_node = xmlNewChild(local_node, NULL, BAD_CAST "target", NULL);
 		if( tag_node ==NULL)
 		{
 			LM_ERR("while adding child\n");
@@ -266,11 +273,12 @@ error:
 	}
 
 	return NULL;
-}	
+}
 
 void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid,
-	unsigned int initiator, unsigned int lifetime, str *localtag, str *remotetag,
-	str *localtarget, str *remotetarget, unsigned short do_pubruri_localcheck)
+		unsigned int initiator, unsigned int lifetime, str *localtag,
+		str *remotetag, str *localtarget, str *remotetarget,
+		unsigned short do_pubruri_localcheck)
 {
 	str* body= NULL;
 	str uri= {NULL, 0};
@@ -289,7 +297,8 @@ void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid,
 
 		/* send PUBLISH only if the receiver PUBLISH R-URI is local*/
 		if (!check_self(&(ruri_uri.host), 0, 0)) {
-			LM_DBG("do not send PUBLISH to external URI %.*s\n",ruri->len, ruri->s);
+			LM_DBG("do not send PUBLISH to external URI %.*s\n",
+					ruri->len, ruri->s);
 			return;
 		}
 
@@ -298,19 +307,20 @@ void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid,
 	content_type.s= "application/dialog-info+xml";
 	content_type.len= 27;
 
-	body= build_dialoginfo(state, entity, peer, callid, initiator, localtag, remotetag, localtarget, remotetarget);
+	body= build_dialoginfo(state, entity, peer, callid, initiator, localtag,
+			remotetag, localtarget, remotetarget);
 	if(body == NULL || body->s == NULL)
 		goto error;
-	
+
 	LM_DBG("publish uri= %.*s\n", ruri->len, ruri->s);
-	
-	size= sizeof(publ_info_t) 
-			+ sizeof(str) 			/* *pres_uri */
-			+ ( ruri->len 		/* pres_uri->s */
-			+ callid->len + 16	/* id.s */
-			+ content_type.len	/* content_type.s */
-			)*sizeof(char); 
-	
+
+	size= sizeof(publ_info_t)
+		+ sizeof(str) 			/* *pres_uri */
+		+ ( ruri->len 		/* pres_uri->s */
+				+ callid->len + 16	/* id.s */
+				+ content_type.len	/* content_type.s */
+			)*sizeof(char);
+
 	if(body)
 		size+= sizeof(str)+ body->len* sizeof(char);
 
@@ -352,9 +362,9 @@ void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid,
 	size+= content_type.len;
 
 	publ->expires= lifetime;
-	
-	/* make UPDATE_TYPE, as if this "publish dialog" is not found 
-	   by pua it will fallback to INSERT_TYPE anyway */
+
+	/* make UPDATE_TYPE, as if this "publish dialog" is not found
+	 * by pua it will fallback to INSERT_TYPE anyway */
 	publ->flag|= UPDATE_TYPE;
 
 	publ->source_flag|= DIALOG_PUBLISH;
@@ -364,7 +374,7 @@ void dialog_publish(char *state, str* ruri, str *entity, str *peer, str *callid,
 	if(pua_send_publish(publ)< 0)
 	{
 		LM_ERR("while sending publish\n");
-	}	
+	}
 
 error:
 
@@ -377,7 +387,7 @@ error:
 			xmlFree(body->s);
 		pkg_free(body);
 	}
-	
+
 	if(uri.s)
 		pkg_free(uri.s);
 
@@ -386,14 +396,18 @@ error:
 
 
 
-void dialog_publish_multi(char *state, struct str_list* ruris, str *entity, str *peer, str *callid,
-	unsigned int initiator, unsigned int lifetime, str *localtag, str *remotetag,
-	str *localtarget, str *remotetarget, unsigned short do_pubruri_localcheck) {
-
+void dialog_publish_multi(char *state, struct str_list* ruris, str *entity,
+		str *peer, str *callid, unsigned int initiator, unsigned int lifetime,
+		str *localtag, str *remotetag,
+		str *localtarget, str *remotetarget, unsigned short
+		do_pubruri_localcheck)
+{
 	while(ruris) {
-		LM_DBG("CALLING dialog_publish for URI %.*s\n",ruris->s.len, ruris->s.s);
-		dialog_publish(state,&(ruris->s),entity,peer,callid,initiator,lifetime,localtag,remotetag,localtarget,remotetarget,do_pubruri_localcheck);
+		LM_DBG("CALLING dialog_publish for URI %.*s\n",
+				ruris->s.len, ruris->s.s);
+		dialog_publish(state,&(ruris->s),entity,peer,callid,initiator,
+				lifetime,localtag,remotetag,localtarget,remotetarget,
+				do_pubruri_localcheck);
 		ruris=ruris->next;
 	}
-
 }
diff --git a/src/modules/pua_dialoginfo/pua_dialoginfo.c b/src/modules/pua_dialoginfo/pua_dialoginfo.c
index c625184..29dcfd5 100644
--- a/src/modules/pua_dialoginfo/pua_dialoginfo.c
+++ b/src/modules/pua_dialoginfo/pua_dialoginfo.c
@@ -17,13 +17,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- *  2008-08-25  initial version (kd)
  */
 
 #include <stdio.h>
@@ -584,7 +581,7 @@ __dialog_created(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
 	struct sip_msg *request = _params->req;
 	struct dlginfo_cell *dlginfo;
 
-	if (request->REQ_METHOD != METHOD_INVITE)
+	if (request==NULL || request->REQ_METHOD != METHOD_INVITE)
 		return;
 
 	if(send_publish_flag > -1 && !(request->flags & (1<<send_publish_flag)))
@@ -682,8 +679,8 @@ static int mod_init(void)
 
 	if(use_pubruri_avps) {
 
-		if(!(pubruri_caller_avp && *pubruri_caller_avp)
-				&& (pubruri_callee_avp && *pubruri_callee_avp)) {
+		if((pubruri_caller_avp==NULL || *pubruri_caller_avp==0)
+				|| (pubruri_callee_avp==NULL || *pubruri_callee_avp==0)) {
 			LM_ERR("pubruri_caller_avp and pubruri_callee_avp must be set,"
 					" if use_pubruri_avps is enabled\n");
 			return -1;
diff --git a/src/modules/pua_dialoginfo/pua_dialoginfo.h b/src/modules/pua_dialoginfo/pua_dialoginfo.h
index 69b3946..01fc876 100644
--- a/src/modules/pua_dialoginfo/pua_dialoginfo.h
+++ b/src/modules/pua_dialoginfo/pua_dialoginfo.h
@@ -1,6 +1,4 @@
 /*
- * $Id: pua_usrloc.h 4518 2008-07-28 15:39:28Z henningw $
- *
  * pua_dialoginfo module - publish dialog-info from dialo module
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
@@ -18,8 +16,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -33,15 +31,15 @@ void dialog_publish_multi(char *state, struct str_list* ruris, str *entity, str
 	unsigned int initiator, unsigned int lifetime, str *localtag, str *remotetag,
 	str *localtarget, str *remotetarget, unsigned short do_pubruri_localcheck);
 
-/* store the important data locally to avoid reading the data from the 
-   dlg_cell during the callback (as this could create a race condition 
-   if the dlg_cell gets meanwhile deleted) */
+/* store the important data locally to avoid reading the data from the
+ * dlg_cell during the callback (as this could create a race condition
+ * if the dlg_cell gets meanwhile deleted) */
 struct dlginfo_cell {
 	str from_uri;
 	str to_uri;
 	str callid;
 	str from_tag;
-/*	str *to_tag; */
+	/* str *to_tag; */
 	str req_uri;
 	str from_contact;
 	struct str_list* pubruris_caller;
diff --git a/src/modules/rtpproxy/rtpproxy.c b/src/modules/rtpproxy/rtpproxy.c
index e445ea3..054c2e3 100644
--- a/src/modules/rtpproxy/rtpproxy.c
+++ b/src/modules/rtpproxy/rtpproxy.c
@@ -1303,12 +1303,12 @@ insert_candidates(struct sip_msg *msg, char *where, str *ip, unsigned int port,
 
 	anchor = anchor_lump(msg, where - msg->buf, 0, 0);
 	if (anchor == 0) {
-		LOG(L_ERR, "insert_candidates: can't get anchor\n");
+		LM_ERR("can't get anchor\n");
 		pkg_free(buf);
 		return -1;
 	}
 	if (insert_new_lump_before(anchor, buf, at - buf, 0) == 0) {
-		LM_ERR("insert_candidates: insert_new_lump_before failed\n");
+		LM_ERR("insert_new_lump_before failed\n");
 		pkg_free(buf);
 		return -1;
 	}
diff --git a/src/modules/seas/cluster.h b/src/modules/seas/cluster.h
index 6c18116..b3e5967 100644
--- a/src/modules/seas/cluster.h
+++ b/src/modules/seas/cluster.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
diff --git a/src/modules/seas/encode_allow.h b/src/modules/seas/encode_allow.h
index e48ace7..b4663e1 100644
--- a/src/modules/seas/encode_allow.h
+++ b/src/modules/seas/encode_allow.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,11 +13,14 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 
+#ifndef __ENCODE_ALLOW_H__
+#define __ENCODE_ALLOW_H__
 int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where);
 int print_encoded_allow(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
+#endif
diff --git a/src/modules/seas/encode_content_disposition.h b/src/modules/seas/encode_content_disposition.h
index 63d81de..4804528 100644
--- a/src/modules/seas/encode_content_disposition.h
+++ b/src/modules/seas/encode_content_disposition.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,11 +13,14 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 
+#ifndef __ENCODE_CONTENT_DISPOSITION_H__
+#define __ENCODE_CONTENT_DISPOSITION_H__
 int encode_content_disposition(char *hdrstart,int hdrlen,struct disposition *body,unsigned char *where);
 int print_encoded_content_disposition(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
+#endif
diff --git a/src/modules/seas/encode_content_length.h b/src/modules/seas/encode_content_length.h
index fc58dbc..deb1cc4 100644
--- a/src/modules/seas/encode_content_length.h
+++ b/src/modules/seas/encode_content_length.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,11 +13,13 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
+#ifndef __ENCODE_CONTENT_LENGHT_H__
+#define __ENCODE_CONTENT_LENGHT_H__
 int encode_contentlength(char *hdr,int hdrlen,long int len,char *where);
 int print_encoded_contentlength(FILE* fd,char *hdr,int hdrlen,unsigned char *payload,int paylen,char *prefix);
+#endif
diff --git a/src/modules/seas/encode_content_type.h b/src/modules/seas/encode_content_type.h
index e52d81d..b3d359c 100644
--- a/src/modules/seas/encode_content_type.h
+++ b/src/modules/seas/encode_content_type.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,15 +13,17 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
+#ifndef __ENCODE_CONTENT_TYPE_H__
+#define __ENCODE_CONTENT_TYPE_H__
 int encode_content_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where);
 int encode_accept(char *hdrstart,int hdrlen,unsigned int *bodi,char *where);
 int encode_mime_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where);
 int print_encoded_mime_type(FILE* fd,char *hdr,int hdrlen,unsigned int* payload,int paylen,char *prefix);
 int print_encoded_content_type(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
 int print_encoded_accept(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
+#endif
diff --git a/src/modules/seas/encode_cseq.h b/src/modules/seas/encode_cseq.h
index 54aaed1..bcba4b8 100644
--- a/src/modules/seas/encode_cseq.h
+++ b/src/modules/seas/encode_cseq.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,13 +13,15 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
+#ifndef __ENCODE_CSEQ_H__
+#define __ENCODE_CSEQ_H__
 #include "../../core/str.h"
 #include "../../core/parser/msg_parser.h"
 int encode_cseq(char *hdrstart,int hdrlen,struct cseq_body *body,unsigned char *where);
 int print_encoded_cseq(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
+#endif
diff --git a/src/modules/seas/encode_digest.h b/src/modules/seas/encode_digest.h
index e91ff12..26952c2 100644
--- a/src/modules/seas/encode_digest.h
+++ b/src/modules/seas/encode_digest.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,12 +13,14 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
+#ifndef __ENCODE_DIGEST_H__
+#define __ENCODE_DIGEST_H__
 int encode_digest(char *hdrstart,int hdrlen,dig_cred_t *digest,unsigned char *where);
 int print_encoded_digest(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
 int dump_digest_test(char *hdr,int hdrlen,unsigned char* payload,int paylen,FILE* fd,char segregationLevel);
+#endif
diff --git a/src/modules/seas/seas.c b/src/modules/seas/seas.c
index 9c7b774..29ac065 100644
--- a/src/modules/seas/seas.c
+++ b/src/modules/seas/seas.c
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -89,20 +88,20 @@ struct seas_functions seas_f;
 static cmd_export_t cmds[]=
 {
 	{"as_relay_t",   (cmd_function)w_as_relay_t,  1,  fixup_as_relay,
-			0, REQUEST_ROUTE},
+		0, REQUEST_ROUTE},
 	{"as_relay_sl",  (cmd_function)w_as_relay_sl, 1,  fixup_as_relay,
-			0, REQUEST_ROUTE},
+		0, REQUEST_ROUTE},
 	{0,0,0,0,0,0}
 };
 
 static param_export_t params[]=
 {
-   {"listen_sockets",PARAM_STRING, &seas_listen_socket},
-   {"stats_socket",  PARAM_STRING, &seas_stats_socket},
-   {"jain_ping",     PARAM_STRING, &jain_ping_config},
-   {"servlet_ping",  PARAM_STRING, &servlet_ping_config},
-   {"clusters",      PARAM_STRING, &cluster_cfg},
-   {0,0,0}
+	{"listen_sockets",PARAM_STRING, &seas_listen_socket},
+	{"stats_socket",  PARAM_STRING, &seas_stats_socket},
+	{"jain_ping",     PARAM_STRING, &jain_ping_config},
+	{"servlet_ping",  PARAM_STRING, &servlet_ping_config},
+	{"clusters",      PARAM_STRING, &cluster_cfg},
+	{0,0,0}
 };
 
 static proc_export_t seas_procs[] = {
@@ -110,65 +109,65 @@ static proc_export_t seas_procs[] = {
 	{0,0,0,0,0}
 };
 
-struct module_exports exports= 
+struct module_exports exports=
 {
-   "seas",
-   DEFAULT_DLFLAGS,
-   cmds,        /* exported commands */
-   params,      /* exported parameters */
-   0,           /* exported statistics */
-   0,           /* exported mi commands */
-   0,           /* exported module-items (pseudo variables) */
-   seas_procs,  /* extra processes */
-   seas_init,   /* module initialization function */
-   0,           /* response function */
-   (destroy_function) seas_exit,   /* module exit function */
-   (child_init_function) seas_child_init  /* per-child init function */
+	"seas",
+	DEFAULT_DLFLAGS,
+	cmds,        /* exported commands */
+	params,      /* exported parameters */
+	0,           /* exported statistics */
+	0,           /* exported mi commands */
+	0,           /* exported module-items (pseudo variables) */
+	seas_procs,  /* extra processes */
+	seas_init,   /* module initialization function */
+	0,           /* response function */
+	(destroy_function) seas_exit,   /* module exit function */
+	(child_init_function) seas_child_init  /* per-child init function */
 };
 
 static int fixup_as_relay(void** param, int param_no)
 {
-   int len;
-   char *parameter;
-   struct as_entry **entry,*tmp;
-
-   parameter=(char *)(*param);
-
-   if (param_no!=1)
-      return 0;
-   len=strlen(parameter);
-   
-   for (entry=&as_list;*entry;entry=&((*entry)->next)) {
-      if (len== (*entry)->name.len && 
-	    !memcmp((*entry)->name.s,parameter,len)) {
-	 pkg_free(*param);
-	 *param=*entry;
-	 return 1;
-      }
-   }
-   if (!(*entry)) {
-      if (!(*entry=(struct as_entry *)shm_malloc(sizeof(struct as_entry)))) {
-	 LM_ERR("no more shm_mem\n");
-	 goto error;
-      }
-      memset(*entry,0,sizeof(struct as_entry));
-      if(!((*entry)->name.s=shm_malloc(len))){
-	 LM_ERR("no more share mem\n");
-	 goto error;
-      }
-      (*entry)->name.len=len;
-      memcpy((*entry)->name.s,parameter,len);
-      (*entry)->u.as.name=(*entry)->name;
-      (*entry)->u.as.event_fd=(*entry)->u.as.action_fd=-1;
-      (*entry)->type=AS_TYPE;
-      pkg_free(*param);
-      *param=*entry;
-   }
-   for (tmp=as_list;tmp;tmp=tmp->next)
-      LM_DBG("%.*s\n",tmp->name.len,tmp->name.s);
-   return 1;
+	int len;
+	char *parameter;
+	struct as_entry **entry,*tmp;
+
+	parameter=(char *)(*param);
+
+	if (param_no!=1)
+		return 0;
+	len=strlen(parameter);
+
+	for (entry=&as_list;*entry;entry=&((*entry)->next)) {
+		if (len== (*entry)->name.len &&
+				!memcmp((*entry)->name.s,parameter,len)) {
+			pkg_free(*param);
+			*param=*entry;
+			return 1;
+		}
+	}
+	if (!(*entry)) {
+		if (!(*entry=(struct as_entry *)shm_malloc(sizeof(struct as_entry)))) {
+			LM_ERR("no more shm_mem\n");
+			goto error;
+		}
+		memset(*entry,0,sizeof(struct as_entry));
+		if(!((*entry)->name.s=shm_malloc(len))){
+			LM_ERR("no more share mem\n");
+			goto error;
+		}
+		(*entry)->name.len=len;
+		memcpy((*entry)->name.s,parameter,len);
+		(*entry)->u.as.name=(*entry)->name;
+		(*entry)->u.as.event_fd=(*entry)->u.as.action_fd=-1;
+		(*entry)->type=AS_TYPE;
+		pkg_free(*param);
+		*param=*entry;
+	}
+	for (tmp=as_list;tmp;tmp=tmp->next)
+		LM_DBG("%.*s\n",tmp->name.len,tmp->name.s);
+	return 1;
 error:
-   return -1;
+	return -1;
 }
 
 /**
@@ -176,57 +175,57 @@ error:
  */
 void seas_sighandler(int signo)
 {
-   struct as_entry *as;
-   if(is_dispatcher)
-      sig_flag=signo;
-   switch(signo){
-      case SIGPIPE:
-	 if(is_dispatcher)
-	    return;
-	 LM_INFO("%s exiting\n",whoami);
-	 if(my_as->u.as.ac_buffer.s){
-	    pkg_free(my_as->u.as.ac_buffer.s);
-	    my_as->u.as.ac_buffer.s=0;
-	 }
-	 if(my_as->u.as.action_fd!=-1){
-	    close(my_as->u.as.action_fd);
-	    my_as->u.as.action_fd=-1;
-	 }
-	 exit(0);
-	 break;
-      case SIGCHLD:
-	 LM_INFO("Child stopped or terminated\n");
-	 break;
-      case SIGUSR1:
-      case SIGUSR2:
-	 LM_DBG("Memory status (pkg):\n");
+	struct as_entry *as;
+	if(is_dispatcher)
+		sig_flag=signo;
+	switch(signo){
+		case SIGPIPE:
+			if(is_dispatcher)
+				return;
+			LM_INFO("%s exiting\n",whoami);
+			if(my_as->u.as.ac_buffer.s){
+				pkg_free(my_as->u.as.ac_buffer.s);
+				my_as->u.as.ac_buffer.s=0;
+			}
+			if(my_as->u.as.action_fd!=-1){
+				close(my_as->u.as.action_fd);
+				my_as->u.as.action_fd=-1;
+			}
+			exit(0);
+			break;
+		case SIGCHLD:
+			LM_INFO("Child stopped or terminated\n");
+			break;
+		case SIGUSR1:
+		case SIGUSR2:
+			LM_DBG("Memory status (pkg):\n");
 #ifdef PKG_MALLOC
-	 pkg_status();
+			pkg_status();
 #endif
-	 break;
-      case SIGINT:
-      case SIGTERM:
-	 LM_INFO("INFO: signal %d received\n",signo);
+			break;
+		case SIGINT:
+		case SIGTERM:
+			LM_INFO("INFO: signal %d received\n",signo);
 #ifdef PKG_MALLOC
-	 pkg_status();
+			pkg_status();
 #endif
-	 if(is_dispatcher){
-	    for (as=as_list;as;as=as->next) {
-	       if(as->type==AS_TYPE && as->connected)
-		  kill(as->u.as.action_pid,signo);
-	    }
-	    while(wait(0) > 0);
-	    exit(0);
-	 }else{
-	    LM_INFO("%s exiting\n",whoami);
-	    if(my_as && my_as->u.as.ac_buffer.s)
-	       pkg_free(my_as->u.as.ac_buffer.s);
-	    if(my_as && my_as->u.as.action_fd!=-1)
-	       close(my_as->u.as.action_fd);
-	    exit(0);
-	 }
-	 break;
-   }
+			if(is_dispatcher){
+				for (as=as_list;as;as=as->next) {
+					if(as->type==AS_TYPE && as->connected)
+						kill(as->u.as.action_pid,signo);
+				}
+				while(wait(0) > 0);
+				exit(0);
+			}else{
+				LM_INFO("%s exiting\n",whoami);
+				if(my_as && my_as->u.as.ac_buffer.s)
+					pkg_free(my_as->u.as.ac_buffer.s);
+				if(my_as && my_as->u.as.action_fd!=-1)
+					close(my_as->u.as.action_fd);
+				exit(0);
+			}
+			break;
+	}
 }
 
 /**
@@ -235,112 +234,112 @@ void seas_sighandler(int signo)
  */
 static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
 {
-   as_msg_p my_as_ev;
-   int new_tran,ret=0,len;
-   char *buffer,processor_id;
-   struct cell *mycel;
-   struct as_entry *as;
-   char *msg100="Your call is important to us";
-   char *msg500="Server Internal Error!";
-
-   buffer=(char*)0;
-   my_as_ev=(as_msg_p)0;
-
-   /**
-    * returns <0 on error
-    * 1 if (new transaction was created) or if (ACK for locally replied 200 with totag) or if (ACK for code>=300)
-    * 0 if it was a retransmission 
-    */
-   new_tran = seas_f.tmb.t_newtran(msg);
-   if(new_tran<0) {
-      ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
-      goto done;
-   }
-   /*retransmission: script processing should be stopped*/
-   if (new_tran==0 && !(msg->REQ_METHOD==METHOD_ACK)){
-      ret = 0;
-      goto done;
-   }
-   /*new transaction created, let's pass it to an APP SERVER*/
-   if (msg->REQ_METHOD==METHOD_INVITE )
-   {
-      LM_DBG("new INVITE\n");
-      if(!seas_f.tmb.t_reply(msg,100,msg100)){
-	 LM_DBG("t_reply (100)\n");
-	 goto error;
-      }
-   }
-   as=(struct as_entry *)entry;
-   if(!as->connected){
-      LM_ERR("app server %.*s not connected\n",as->name.len,as->name.s);
-      goto error;
-   }
-   if(as->type==AS_TYPE){
-      if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
-	 LM_ERR("no processor found for packet dst %s:%d\n",ip_addr2a(&msg->rcv.dst_ip),msg->rcv.dst_port);
-	 goto error;
-      }
-   }else if(as->type==CLUSTER_TYPE){
-      LM_ERR("clustering not fully implemented\n");
-      return 0;
-   }else{
-      LM_ERR("unknown type of as (neither cluster nor as)\n");
-      return -1;
-   }
-   LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
-   if(new_tran==1 && msg->REQ_METHOD==METHOD_ACK){
-      LM_DBG("message handled in transaction callbacks. skipping\n");
-      ret = 0;
-      goto done;
-      /* core should forward statelessly (says t_newtran)
-      LM_DBG("forwarding statelessly !!!\n");
-      if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
-	 LM_ERR("create_as_event_sl() unable to create event code\n");
-	 goto error;
-      }
-      */
-   }else if(!(buffer=create_as_event_t(seas_f.tmb.t_gett(),msg,processor_id,&len,0))){
-      LM_ERR("unable to create event code\n");
-      goto error;
-   }
-   if(!(my_as_ev=shm_malloc(sizeof(as_msg_t)))){
-      LM_ERR("Out of shared mem!\n");
-      goto error;
-   }
-   my_as_ev->msg = buffer;
-   my_as_ev->as = as;
-   my_as_ev->type = T_REQ_IN;
-   my_as_ev->len = len;
-   my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
-   if(use_stats && new_tran>0)
-      as_relay_stat(seas_f.tmb.t_gett());
+	as_msg_p my_as_ev;
+	int new_tran,ret=0,len;
+	char *buffer,processor_id;
+	struct cell *mycel;
+	struct as_entry *as;
+	char *msg100="Your call is important to us";
+	char *msg500="Server Internal Error!";
+
+	buffer=(char*)0;
+	my_as_ev=(as_msg_p)0;
+
+	/**
+	 * returns <0 on error
+	 * 1 if (new transaction was created) or if (ACK for locally replied 200 with totag) or if (ACK for code>=300)
+	 * 0 if it was a retransmission
+	 */
+	new_tran = seas_f.tmb.t_newtran(msg);
+	if(new_tran<0) {
+		ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
+		goto done;
+	}
+	/*retransmission: script processing should be stopped*/
+	if (new_tran==0 && !(msg->REQ_METHOD==METHOD_ACK)){
+		ret = 0;
+		goto done;
+	}
+	/*new transaction created, let's pass it to an APP SERVER*/
+	if (msg->REQ_METHOD==METHOD_INVITE )
+	{
+		LM_DBG("new INVITE\n");
+		if(!seas_f.tmb.t_reply(msg,100,msg100)){
+			LM_DBG("t_reply (100)\n");
+			goto error;
+		}
+	}
+	as=(struct as_entry *)entry;
+	if(!as->connected){
+		LM_ERR("app server %.*s not connected\n",as->name.len,as->name.s);
+		goto error;
+	}
+	if(as->type==AS_TYPE){
+		if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
+			LM_ERR("no processor found for packet dst %s:%d\n",ip_addr2a(&msg->rcv.dst_ip),msg->rcv.dst_port);
+			goto error;
+		}
+	}else if(as->type==CLUSTER_TYPE){
+		LM_ERR("clustering not fully implemented\n");
+		return 0;
+	}else{
+		LM_ERR("unknown type of as (neither cluster nor as)\n");
+		return -1;
+	}
+	LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
+	if(new_tran==1 && msg->REQ_METHOD==METHOD_ACK){
+		LM_DBG("message handled in transaction callbacks. skipping\n");
+		ret = 0;
+		goto done;
+		/* core should forward statelessly (says t_newtran)
+		 * LM_DBG("forwarding statelessly !!!\n");
+		 * if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
+		 * LM_ERR("create_as_event_sl() unable to create event code\n");
+		 * goto error;
+		 * }
+		 */
+	}else if(!(buffer=create_as_event_t(seas_f.tmb.t_gett(),msg,processor_id,&len,0))){
+		LM_ERR("unable to create event code\n");
+		goto error;
+	}
+	if(!(my_as_ev=shm_malloc(sizeof(as_msg_t)))){
+		LM_ERR("Out of shared mem!\n");
+		goto error;
+	}
+	my_as_ev->msg = buffer;
+	my_as_ev->as = as;
+	my_as_ev->type = T_REQ_IN;
+	my_as_ev->len = len;
+	my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
+	if(use_stats && new_tran>0)
+		as_relay_stat(seas_f.tmb.t_gett());
 again:
-   ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
-   if(ret==-1){
-      if(errno==EINTR)
-	 goto again;
-      else if(errno==EPIPE){
-	 LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
-	 goto error;
-	 /** TODO handle this correctly !!!*/
-      }
-   }
-   /* seas_f.tmb.t_setkr(REQ_FWDED); */
-   ret=0;
+	ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
+	if(ret==-1){
+		if(errno==EINTR)
+			goto again;
+		else if(errno==EPIPE){
+			LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
+			goto error;
+			/** TODO handle this correctly !!!*/
+		}
+	}
+	/* seas_f.tmb.t_setkr(REQ_FWDED); */
+	ret=0;
 done:
-   return ret;
+	return ret;
 error:
-   mycel=seas_f.tmb.t_gett();
-   if(mycel && mycel!=T_UNDEFINED){
-      if(!seas_f.tmb.t_reply(msg,500,msg500)){
-	 LM_ERR("t_reply (500)\n");
-      }
-   }
-   if(my_as_ev)
-      shm_free(my_as_ev);
-   if(buffer)
-      shm_free(buffer);
-   return ret;
+	mycel=seas_f.tmb.t_gett();
+	if(mycel && mycel!=T_UNDEFINED){
+		if(!seas_f.tmb.t_reply(msg,500,msg500)){
+			LM_ERR("t_reply (500)\n");
+		}
+	}
+	if(my_as_ev)
+		shm_free(my_as_ev);
+	if(buffer)
+		shm_free(buffer);
+	return ret;
 }
 
 
@@ -350,274 +349,274 @@ error:
  */
 static int w_as_relay_sl(struct sip_msg *msg, char *as_name, char *foo)
 {
-   as_msg_p my_as_ev=0;
-   int ret=0,len;
-   char *buffer=0,processor_id;
-   struct as_entry *as;
-
-   as=(struct as_entry *)as_name;
-
-   if(as->type==AS_TYPE){
-      if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
-	 LM_ERR("no processor found for packet with dst port:%d\n",msg->rcv.dst_port);
-	 goto error;
-      }
-   }else if (as->type==CLUSTER_TYPE) {
-      LM_ERR("clustering not fully implemented\n");
-      goto error;
-   }else{
-      LM_ERR("unknown type of as\n");
-      goto error;
-   }
-
-   LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
-   if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
-      LM_ERR("unable to create event code\n");
-      goto error;
-   }
-   if(!(my_as_ev=shm_malloc(sizeof(as_msg_t))))
-      goto error;
-   my_as_ev->msg = buffer;
-   my_as_ev->as = as;
-   my_as_ev->type = SL_REQ_IN;
-   my_as_ev->len = len;
-   my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
-   if(use_stats)
-      as_relay_stat(seas_f.tmb.t_gett());
+	as_msg_p my_as_ev=0;
+	int ret=0,len;
+	char *buffer=0,processor_id;
+	struct as_entry *as;
+
+	as=(struct as_entry *)as_name;
+
+	if(as->type==AS_TYPE){
+		if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
+			LM_ERR("no processor found for packet with dst port:%d\n",msg->rcv.dst_port);
+			goto error;
+		}
+	}else if (as->type==CLUSTER_TYPE) {
+		LM_ERR("clustering not fully implemented\n");
+		goto error;
+	}else{
+		LM_ERR("unknown type of as\n");
+		goto error;
+	}
+
+	LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
+	if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
+		LM_ERR("unable to create event code\n");
+		goto error;
+	}
+	if(!(my_as_ev=shm_malloc(sizeof(as_msg_t))))
+		goto error;
+	my_as_ev->msg = buffer;
+	my_as_ev->as = as;
+	my_as_ev->type = SL_REQ_IN;
+	my_as_ev->len = len;
+	my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
+	if(use_stats)
+		as_relay_stat(seas_f.tmb.t_gett());
 again:
-   ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
-   if(ret==-1){
-      if(errno==EINTR)
-	 goto again;
-      else if(errno==EPIPE){
-	 LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
-	 return -2;
-	 /** TODO handle this correctly !!!*/
-      }
-   }
-   //this shouln't be here, because it will remove the transaction from memory, but
-   //if transaction isn't unref'ed iw will be released anyway at t_unref if kr (killreason)==0
-   // a wait timer will be put to run with WT_TIME_OUT (5 seconds, within which the AS should respond)      
-   // this is a bug !!! I think this is why we lose calls at high load !!
-   //t_release(msg, 0, 0);
-   /* seas_f.tmb.t_setkr(REQ_FWDED); */
-
-   ret=0;
-   return ret;
+	ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
+	if(ret==-1){
+		if(errno==EINTR)
+			goto again;
+		else if(errno==EPIPE){
+			LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
+			return -2;
+			/** TODO handle this correctly !!!*/
+		}
+	}
+	//this shouln't be here, because it will remove the transaction from memory, but
+	//if transaction isn't unref'ed iw will be released anyway at t_unref if kr (killreason)==0
+	// a wait timer will be put to run with WT_TIME_OUT (5 seconds, within which the AS should respond)
+	// this is a bug !!! I think this is why we lose calls at high load !!
+	//t_release(msg, 0, 0);
+	/* seas_f.tmb.t_setkr(REQ_FWDED); */
+
+	ret=0;
+	return ret;
 error:
-   if(my_as_ev)
-      shm_free(my_as_ev);
-   if(buffer)
-      shm_free(buffer);
-   return ret;
+	if(my_as_ev)
+		shm_free(my_as_ev);
+	if(buffer)
+		shm_free(buffer);
+	return ret;
 }
 
 /**
  * creates an as_event in shared memory and returns its address or NULL if error.
  * event_length(4) UNSIGNED INT includes the length 4 bytes itself
- * type(1), 
+ * type(1),
  * flags(4),
  * transport(1).
- * src_ip_len(1), 
- * src_ip(4 or 16), 
- * dst_ip_len(1), 
- * dst_ip(4 or 16), 
- * src_port(2), 
- * dst_port(2), 
- * hash index(4), 
- * label(4), 
+ * src_ip_len(1),
+ * src_ip(4 or 16),
+ * dst_ip_len(1),
+ * dst_ip(4 or 16),
+ * src_port(2),
+ * dst_port(2),
+ * hash index(4),
+ * label(4),
  * [cancelled hash_index,label]
  *
  */
 char * create_as_event_t(struct cell *t,struct sip_msg *msg,char processor_id,int *evt_len,int flags)
 {
-   unsigned int i,hash_index,label;
-   unsigned short int port;
-   unsigned int k,len;
-   char *buffer=NULL;
-   struct cell *originalT;
-
-   originalT=0;
-
-   if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
-      LM_ERR("Out Of Memory !!\n");
-      return 0;
-   }
-   *evt_len=0;
-   if(t){
-      hash_index=t->hash_index;
-      label=t->label;
-   }else{
-      /**seas_f.tmb.t_get_trans_ident(msg,&hash_index,&label); this is bad, because it ref-counts !!!*/
-      LM_ERR("no transaction provided...\n");
-      goto error;
-   }
-
-   k=4;
-   /*type*/
-   buffer[k++]=(unsigned char)T_REQ_IN;
-   /*processor_id*/
-   buffer[k++]=(unsigned char)processor_id;
-   /*flags*/
-   if(is_e2e_ack(t,msg)){
-      flags|=E2E_ACK;
-   }else if(msg->REQ_METHOD==METHOD_CANCEL){
-      LM_DBG("new CANCEL\n");
-      originalT=seas_f.tmb.t_lookup_original(msg);
-      if(!originalT || originalT==T_UNDEFINED){
-	 /** we dont even pass the unknown CANCEL to JAIN*/
-	 LM_WARN("CANCEL does not match any existing transaction!!\n");
-	 goto error;
-      }else{
-	 flags|=CANCEL_FOUND;
-	 //seas_f.tmb.unref_cell(originalT);
-      }
-      LM_DBG("Cancelling transaction !!\n");
-   }
-   flags=htonl(flags);
-   memcpy(buffer+k,&flags,4);
-   k+=4;
-   /*protocol should be UDP,TCP,TLS or whatever*/
-   buffer[k++]=(unsigned char)msg->rcv.proto;
-   /*src ip len + src ip*/
-   len=msg->rcv.src_ip.len;
-   buffer[k++]=(unsigned char)len;
-   memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
-   k+=len;
-   /*dst ip len + dst ip*/
-   len=msg->rcv.dst_ip.len;
-   buffer[k++]=(unsigned char)len;
-   memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
-   k+=len;
-   /*src port */
-   port=htons(msg->rcv.src_port);
-   memcpy(buffer+k,&port,2);
-   k+=2;
-   /*dst port */
-   port=htons(msg->rcv.dst_port);
-   memcpy(buffer+k,&port,2);
-   k+=2;
-   /*hash_index*/
-   i=htonl(hash_index);
-   memcpy(buffer+k,&i,4);
-   k+=4;
-   /*label (is the collision slot in the hash-table)*/
-   i=htonl(label);
-   memcpy(buffer+k,&i,4);
-   k+=4;
-   if(msg->REQ_METHOD==METHOD_CANCEL && originalT){
-      LM_DBG("Cancelled transaction: Hash_Index=%d, Label=%d\n",originalT->hash_index,originalT->label);
-      /*hash_index*/
-      i=htonl(originalT->hash_index);
-      memcpy(buffer+k,&i,4);
-      k+=4;
-      /*label (is the collision slot in the hash-table)*/
-      i=htonl(originalT->label);
-      memcpy(buffer+k,&i,4);
-      k+=4;
-   }
-
-   /*length of event (hdr+payload-4), copied at the beginning*/
-   if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
-      LM_ERR("Unable to encode msg\n");
-      goto error;
-   }
-   i = GET_PAY_SIZE(buffer+k);
-   k+=i;
-   *evt_len=k;
-   k=htonl(k);
-   memcpy(buffer,&k,4);
-   return buffer;
+	unsigned int i,hash_index,label;
+	unsigned short int port;
+	unsigned int k,len;
+	char *buffer=NULL;
+	struct cell *originalT;
+
+	originalT=0;
+
+	if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
+		LM_ERR("Out Of Memory !!\n");
+		return 0;
+	}
+	*evt_len=0;
+	if(t){
+		hash_index=t->hash_index;
+		label=t->label;
+	}else{
+		/**seas_f.tmb.t_get_trans_ident(msg,&hash_index,&label); this is bad, because it ref-counts !!!*/
+		LM_ERR("no transaction provided...\n");
+		goto error;
+	}
+
+	k=4;
+	/*type*/
+	buffer[k++]=(unsigned char)T_REQ_IN;
+	/*processor_id*/
+	buffer[k++]=(unsigned char)processor_id;
+	/*flags*/
+	if(is_e2e_ack(t,msg)){
+		flags|=E2E_ACK;
+	}else if(msg->REQ_METHOD==METHOD_CANCEL){
+		LM_DBG("new CANCEL\n");
+		originalT=seas_f.tmb.t_lookup_original(msg);
+		if(!originalT || originalT==T_UNDEFINED){
+			/** we dont even pass the unknown CANCEL to JAIN*/
+			LM_WARN("CANCEL does not match any existing transaction!!\n");
+			goto error;
+		}else{
+			flags|=CANCEL_FOUND;
+			//seas_f.tmb.unref_cell(originalT);
+		}
+		LM_DBG("Cancelling transaction !!\n");
+	}
+	flags=htonl(flags);
+	memcpy(buffer+k,&flags,4);
+	k+=4;
+	/*protocol should be UDP,TCP,TLS or whatever*/
+	buffer[k++]=(unsigned char)msg->rcv.proto;
+	/*src ip len + src ip*/
+	len=msg->rcv.src_ip.len;
+	buffer[k++]=(unsigned char)len;
+	memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
+	k+=len;
+	/*dst ip len + dst ip*/
+	len=msg->rcv.dst_ip.len;
+	buffer[k++]=(unsigned char)len;
+	memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
+	k+=len;
+	/*src port */
+	port=htons(msg->rcv.src_port);
+	memcpy(buffer+k,&port,2);
+	k+=2;
+	/*dst port */
+	port=htons(msg->rcv.dst_port);
+	memcpy(buffer+k,&port,2);
+	k+=2;
+	/*hash_index*/
+	i=htonl(hash_index);
+	memcpy(buffer+k,&i,4);
+	k+=4;
+	/*label (is the collision slot in the hash-table)*/
+	i=htonl(label);
+	memcpy(buffer+k,&i,4);
+	k+=4;
+	if(msg->REQ_METHOD==METHOD_CANCEL && originalT){
+		LM_DBG("Cancelled transaction: Hash_Index=%d, Label=%d\n",originalT->hash_index,originalT->label);
+		/*hash_index*/
+		i=htonl(originalT->hash_index);
+		memcpy(buffer+k,&i,4);
+		k+=4;
+		/*label (is the collision slot in the hash-table)*/
+		i=htonl(originalT->label);
+		memcpy(buffer+k,&i,4);
+		k+=4;
+	}
+
+	/*length of event (hdr+payload-4), copied at the beginning*/
+	if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
+		LM_ERR("Unable to encode msg\n");
+		goto error;
+	}
+	i = GET_PAY_SIZE(buffer+k);
+	k+=i;
+	*evt_len=k;
+	k=htonl(k);
+	memcpy(buffer,&k,4);
+	return buffer;
 error:
-   if(buffer)
-      shm_free(buffer);
-   return 0;
+	if(buffer)
+		shm_free(buffer);
+	return 0;
 }
 
 
 /**
  * creates an as_event in shared memory and returns its address or NULL if error.
  * event_length(4) UNSIGNED INT includes the length 4 bytes itself
- * type(1), 
- * processor_id(4), 
+ * type(1),
+ * processor_id(4),
  * flags(4),
  * transport(1).
- * src_ip_len(1), 
- * src_ip(4 or 16), 
- * dst_ip_len(1), 
- * dst_ip(4 or 16), 
- * src_port(2), 
- * dst_port(2), 
+ * src_ip_len(1),
+ * src_ip(4 or 16),
+ * dst_ip_len(1),
+ * dst_ip(4 or 16),
+ * src_port(2),
+ * dst_port(2),
  *
  */
 char * create_as_event_sl(struct sip_msg *msg,char processor_id,int *evt_len,int flags)
 {
-   unsigned int i;
-   unsigned short int port;
-   unsigned int k,len;
-   char *buffer=NULL;
-
-   if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
-      LM_ERR("create_as_event_t Out Of Memory !!\n");
-      return 0;
-   }
-   *evt_len=0;
-
-   /*leave 4 bytes for event length*/
-   k=4;
-   /*type*/
-   buffer[k++]=(unsigned char)SL_REQ_IN;
-   /*processor_id*/
-   buffer[k++]=(unsigned char)processor_id;
-   /*flags*/
-   flags=htonl(flags);
-   memcpy(buffer+k,&flags,4);
-   k+=4;
-   /*protocol should be UDP,TCP,TLS or whatever*/
-   buffer[k++]=(unsigned char)msg->rcv.proto;
-   /*src ip len + src ip*/
-   len=msg->rcv.src_ip.len;
-   buffer[k++]=(unsigned char)len;
-   memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
-   k+=len;
-   /*dst ip len + dst ip*/
-   len=msg->rcv.dst_ip.len;
-   buffer[k++]=(unsigned char)len;
-   memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
-   k+=len;
-   /*src port */
-   port=htons(msg->rcv.src_port);
-   memcpy(buffer+k,&port,2);
-   k+=2;
-   /*dst port */
-   port=htons(msg->rcv.dst_port);
-   memcpy(buffer+k,&port,2);
-   k+=2;
-   /*length of event (hdr+payload-4), copied at the beginning*/
-   if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
-      LM_ERR("Unable to encode msg\n");
-      goto error;
-   }
-   i = GET_PAY_SIZE(buffer+k);
-   k+=i;
-   *evt_len=k;
-   k=htonl(k);
-   memcpy(buffer,&k,4);
-   return buffer;
+	unsigned int i;
+	unsigned short int port;
+	unsigned int k,len;
+	char *buffer=NULL;
+
+	if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
+		LM_ERR("create_as_event_t Out Of Memory !!\n");
+		return 0;
+	}
+	*evt_len=0;
+
+	/*leave 4 bytes for event length*/
+	k=4;
+	/*type*/
+	buffer[k++]=(unsigned char)SL_REQ_IN;
+	/*processor_id*/
+	buffer[k++]=(unsigned char)processor_id;
+	/*flags*/
+	flags=htonl(flags);
+	memcpy(buffer+k,&flags,4);
+	k+=4;
+	/*protocol should be UDP,TCP,TLS or whatever*/
+	buffer[k++]=(unsigned char)msg->rcv.proto;
+	/*src ip len + src ip*/
+	len=msg->rcv.src_ip.len;
+	buffer[k++]=(unsigned char)len;
+	memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
+	k+=len;
+	/*dst ip len + dst ip*/
+	len=msg->rcv.dst_ip.len;
+	buffer[k++]=(unsigned char)len;
+	memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
+	k+=len;
+	/*src port */
+	port=htons(msg->rcv.src_port);
+	memcpy(buffer+k,&port,2);
+	k+=2;
+	/*dst port */
+	port=htons(msg->rcv.dst_port);
+	memcpy(buffer+k,&port,2);
+	k+=2;
+	/*length of event (hdr+payload-4), copied at the beginning*/
+	if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
+		LM_ERR("Unable to encode msg\n");
+		goto error;
+	}
+	i = GET_PAY_SIZE(buffer+k);
+	k+=i;
+	*evt_len=k;
+	k=htonl(k);
+	memcpy(buffer,&k,4);
+	return buffer;
 error:
-   if(buffer)
-      shm_free(buffer);
-   return 0;
+	if(buffer)
+		shm_free(buffer);
+	return 0;
 }
 
 
 static inline int is_e2e_ack(struct cell *t,struct sip_msg *msg)
 {
-   if(msg->REQ_METHOD != METHOD_ACK)
-      return 0;
-   if (t->uas.status<300)
-      return 1;
-   return 0;
+	if(msg->REQ_METHOD != METHOD_ACK)
+		return 0;
+	if (t->uas.status<300)
+		return 1;
+	return 0;
 }
 
 /** Initializes seas module. It first parses the listen_sockets parameter
@@ -626,75 +625,75 @@ static inline int is_e2e_ack(struct cell *t,struct sip_msg *msg)
  */
 static int seas_init(void)
 {
-   char *p,*port;
-   struct hostent *he;
-   struct socket_info *si;
-   int c_pipe[2],mierr,i;
-   /** Populate seas_functions*/
-   if (load_tm_api(&seas_f.tmb)!=0) {
-      LM_ERR( "can't load TM API\n");
-      return -1;
-   }
-   if(!(seas_f.t_check_orig_trans = find_export("t_check_trans", 0, 0))){
-      LM_ERR( "Seas requires transaction module (t_check_trans not found)\n");
-      return -1;
-   }
-   /** Populate seas_functions*/
-   c_pipe[0]=c_pipe[1]=-1;
-   p=seas_listen_socket;
-   port=(char *)0;
-   seas_listen_port=5080;
-   /*if the seas_listen_socket configuration string is empty, use default values*/
-   if(p==NULL || *p==0){
-      si=get_first_socket();
-      seas_listen_ip=&si->address;
-   } else {/*if config string is not empty, then try to find host first, and maybe port..*/
-      while(*p){
-	 if(*p == ':'){
-	    *p=0;
-	    port=p+1;
-	    break;
-	 }
-	 p++;
-      }
-      if(!(he=resolvehost(seas_listen_socket)))
-	 goto error;
-      if(!(seas_listen_ip=pkg_malloc(sizeof(struct ip_addr))))
-	 goto error;
-      hostent2ip_addr(seas_listen_ip, he, 0);
-      if(port!=(char *)0 && (seas_listen_port=str2s(port,strlen(port),&mierr))==0){
-	 LM_ERR("invalid port %s \n",port);
-	 goto error;
-      }
-   }
-   memset(unc_as_t,0,2*MAX_UNC_AS_NR*sizeof(struct unc_as));//useless because unc_as_t is in bss?
-   if (pipe(c_pipe)==-1) {
-      LM_ERR("cannot create pipe!\n");
-      goto error;
-   }
-   read_pipe=c_pipe[0];
-   write_pipe=c_pipe[1];
-   seas_init_tags();
-   if(0>start_stats_server(seas_stats_socket))
-      goto error;
-   if(0>prepare_ha())
-      goto error;
-   if(0>parse_cluster_cfg())
-      goto error;
-   register_procs(1);
+	char *p,*port;
+	struct hostent *he;
+	struct socket_info *si;
+	int c_pipe[2],mierr,i;
+	/** Populate seas_functions*/
+	if (load_tm_api(&seas_f.tmb)!=0) {
+		LM_ERR( "can't load TM API\n");
+		return -1;
+	}
+	if(!(seas_f.t_check_orig_trans = find_export("t_check_trans", 0, 0))){
+		LM_ERR( "Seas requires transaction module (t_check_trans not found)\n");
+		return -1;
+	}
+	/** Populate seas_functions*/
+	c_pipe[0]=c_pipe[1]=-1;
+	p=seas_listen_socket;
+	port=(char *)0;
+	seas_listen_port=5080;
+	/*if the seas_listen_socket configuration string is empty, use default values*/
+	if(p==NULL || *p==0){
+		si=get_first_socket();
+		seas_listen_ip=&si->address;
+	} else {/*if config string is not empty, then try to find host first, and maybe port..*/
+		while(*p){
+			if(*p == ':'){
+				*p=0;
+				port=p+1;
+				break;
+			}
+			p++;
+		}
+		if(!(he=resolvehost(seas_listen_socket)))
+			goto error;
+		if(!(seas_listen_ip=pkg_malloc(sizeof(struct ip_addr))))
+			goto error;
+		hostent2ip_addr(seas_listen_ip, he, 0);
+		if(port!=(char *)0 && (seas_listen_port=str2s(port,strlen(port),&mierr))==0){
+			LM_ERR("invalid port %s \n",port);
+			goto error;
+		}
+	}
+	memset(unc_as_t,0,2*MAX_UNC_AS_NR*sizeof(struct unc_as));//useless because unc_as_t is in bss?
+	if (pipe(c_pipe)==-1) {
+		LM_ERR("cannot create pipe!\n");
+		goto error;
+	}
+	read_pipe=c_pipe[0];
+	write_pipe=c_pipe[1];
+	seas_init_tags();
+	if(0>start_stats_server(seas_stats_socket))
+		goto error;
+	if(0>prepare_ha())
+		goto error;
+	if(0>parse_cluster_cfg())
+		goto error;
+	register_procs(1);
 	/* add child to update local config framework structures */
 	cfg_register_child(1);
 
-   return 0;
+	return 0;
 error:
-   for(i=0;i<2;i++)
-      if(c_pipe[i]!=-1)
-	 close(c_pipe[i]);
-   if(seas_listen_ip!=0)
-      pkg_free(seas_listen_ip);
-   if(use_stats)
-      stop_stats_server();
-   return -1;
+	for(i=0;i<2;i++)
+		if(c_pipe[i]!=-1)
+			close(c_pipe[i]);
+	if(seas_listen_ip!=0)
+		pkg_free(seas_listen_ip);
+	if(use_stats)
+		stop_stats_server();
+	return -1;
 }
 
 
@@ -702,8 +701,8 @@ error:
 */
 static void seas_init_tags(void)
 {
-   init_tags(seas_tags, &seas_tag_suffix,"VozTele-Seas/tags",'-');
-   LM_DBG("seas_init_tags, seas_tags=%s\n",seas_tags);
+	init_tags(seas_tags, &seas_tag_suffix,"VozTele-Seas/tags",'-');
+	LM_DBG("seas_init_tags, seas_tags=%s\n",seas_tags);
 }
 
 /**
@@ -716,30 +715,30 @@ static void seas_init_tags(void)
  */
 static int seas_child_init(int rank)
 {
-   int pid;
-
-   /* only the child 1 will execute this */
-   if (rank != PROC_MAIN){
-      /* only dispatcher needs to read from the pipe, so close reading fd*/
-      /*close(read_pipe);*/
-      return 0;
-   }
-   if ((pid=fork_process(PROC_NOCHLDINIT,"SEAS",0))<0) {
-      LM_ERR("forking failed\n");
-      return -1;
-   }
-   if (!pid) {
-      /*dispatcher child. we leave writing end open so that new childs spawned
-       * by event dispatcher can also write to pipe.. */
+	int pid;
+
+	/* only the child 1 will execute this */
+	if (rank != PROC_MAIN){
+		/* only dispatcher needs to read from the pipe, so close reading fd*/
+		/*close(read_pipe);*/
+		return 0;
+	}
+	if ((pid=fork_process(PROC_NOCHLDINIT,"SEAS",0))<0) {
+		LM_ERR("forking failed\n");
+		return -1;
+	}
+	if (!pid) {
+		/*dispatcher child. we leave writing end open so that new childs spawned
+		 * by event dispatcher can also write to pipe.. */
 
 		/* initialize the config framework */
 		if (cfg_child_init())
 			return -1;
 
-      /* close(write_pipe); */
-      return dispatcher_main_loop();
-   }
-   return 0;
+		/* close(write_pipe); */
+		return dispatcher_main_loop();
+	}
+	return 0;
 }
 
 /* this should close the sockets open to any of the application servers, and
@@ -748,27 +747,27 @@ static int seas_child_init(int rank)
  */
 static int seas_exit(void)
 {
-   if( seas_listen_ip!=NULL && seas_listen_ip!=&(get_first_socket()->address))
-      pkg_free(seas_listen_ip);
-   return 0;
+	if( seas_listen_ip!=NULL && seas_listen_ip!=&(get_first_socket()->address))
+		pkg_free(seas_listen_ip);
+	return 0;
 }
 
 /**
  * search within a given AS, if any of the registered processors is bound
- * to the receive_info structure passed. If there is one, it returns its 
+ * to the receive_info structure passed. If there is one, it returns its
  * identifier (number between 0 and 128), otherwise it returns -1;
  */
 char get_processor_id(struct receive_info *rcv,as_p as)
 {
-   int i;
-   for(i=0;i<MAX_BINDS;i++){
-      if(as->bound_processor[i]!=0 &&
-	    (rcv->dst_ip.len == as->binds[i]->address.len) &&
-	    (rcv->dst_ip.af==as->binds[i]->address.af) &&
-	    (!memcmp(rcv->dst_ip.u.addr,as->binds[i]->address.u.addr,rcv->dst_ip.len))/* &&
-										       (rcv->dst_port==as->binds[i].dst_port) &&
-										       (rcv->proto==as->binds[i].proto)*/)
-	 return as->bound_processor[i];
-   }
-   return -1;
+	int i;
+	for(i=0;i<MAX_BINDS;i++){
+		if(as->bound_processor[i]!=0 &&
+				(rcv->dst_ip.len == as->binds[i]->address.len) &&
+				(rcv->dst_ip.af==as->binds[i]->address.af) &&
+				(!memcmp(rcv->dst_ip.u.addr,as->binds[i]->address.u.addr,rcv->dst_ip.len))/* &&
+																							(rcv->dst_port==as->binds[i].dst_port) &&
+																							(rcv->proto==as->binds[i].proto)*/)
+			return as->bound_processor[i];
+	}
+	return -1;
 }
diff --git a/src/modules/seas/seas.h b/src/modules/seas/seas.h
index 6a7c03a..9f525f4 100644
--- a/src/modules/seas/seas.h
+++ b/src/modules/seas/seas.h
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,8 +13,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -67,9 +66,9 @@
 #define SPIRAL_FLAG 0x00000001
 
 #define net2hostL(dst,from,index) do{ \
-   memcpy(&(dst),(from)+(index),4); \
-   dst=ntohl(dst); \
-   (index)+=4; \
+	memcpy(&(dst),(from)+(index),4); \
+	dst=ntohl(dst); \
+	(index)+=4; \
 }while(0);
 
 
@@ -94,32 +93,32 @@ extern int servlet_pings_lost;
 extern struct as_entry *as_table;
 
 struct seas_functions{
-   struct tm_binds tmb;
-   cmd_function t_check_orig_trans;
+	struct tm_binds tmb;
+	cmd_function t_check_orig_trans;
 };
 
 /*TODO listen_points should be dynamically allocated ?*/
 typedef struct app_server {
-   int event_fd;
-   int action_fd;
-   str name;
-   pid_t action_pid;
-   struct socket_info *binds[MAX_BINDS];
-   char bound_processor[MAX_BINDS];
-   int num_binds;
-   str ev_buffer;
-   str ac_buffer;
-   struct ha jain_pings;
-   struct ha servlet_pings;
-   struct cluster *cluster;
+	int event_fd;
+	int action_fd;
+	str name;
+	pid_t action_pid;
+	struct socket_info *binds[MAX_BINDS];
+	char bound_processor[MAX_BINDS];
+	int num_binds;
+	str ev_buffer;
+	str ac_buffer;
+	struct ha jain_pings;
+	struct ha servlet_pings;
+	struct cluster *cluster;
 }as_t, *as_p;
 
 struct cluster{
-   str name;
-   int num;
-   int registered;
-   str as_names[MAX_AS_PER_CLUSTER];
-   as_p servers[MAX_AS_PER_CLUSTER];
+	str name;
+	int num;
+	int registered;
+	str as_names[MAX_AS_PER_CLUSTER];
+	as_p servers[MAX_AS_PER_CLUSTER];
 };
 
 /**
@@ -127,32 +126,32 @@ struct cluster{
  * when one matches, they will put the as pointer inside the event that should process
  * that event.
  * If eventually the as becomes unavailable, the dispatcher will set valid=false, which should be
- * atomic operation. This way, we prevent having to put a mutex on the array, which would make 
+ * atomic operation. This way, we prevent having to put a mutex on the array, which would make
  * it slower , as only one process could be accessing it at a time.
  */
 struct as_entry{
-   str name;
-   int type;
-   int connected;
-   union{
-      struct app_server as;
-      struct cluster cs;
-   }u;
-   struct as_entry *next;
+	str name;
+	int type;
+	int connected;
+	union{
+		struct app_server as;
+		struct cluster cs;
+	}u;
+	struct as_entry *next;
 };
 
 
 extern struct as_entry *my_as;
-extern struct seas_functions seas_f; 
+extern struct seas_functions seas_f;
 extern struct as_entry *as_list;
 
 typedef struct as_msg {
-   struct cell *transaction;
-   char *msg;
-   int len;
-   int type;
-   int id;
-   struct as_entry *as;
+	struct cell *transaction;
+	char *msg;
+	int len;
+	int type;
+	int id;
+	struct as_entry *as;
 }as_msg_t,*as_msg_p;
 
 char get_processor_id(struct receive_info *rcv,as_p as);
@@ -162,17 +161,17 @@ char* create_as_event_sl(struct sip_msg *msg,char processor_id,int *evt_len,int
 
 static inline void print_ip_buf(struct ip_addr* ip, char *where,int len)
 {
-   switch(ip->af){
-      case AF_INET:
-	 snprintf(where,len,"%d.%d.%d.%d", ip->u.addr[0], ip->u.addr[1], ip->u.addr[2], ip->u.addr[3]);
-	 break;
-      case AF_INET6:
-	 snprintf(where,len,"%x:%x:%x:%x:%x:%x:%x:%x",htons(ip->u.addr16[0]),htons(ip->u.addr16[1]),htons(ip->u.addr16[2]),
-	       htons(ip->u.addr16[3]), htons(ip->u.addr16[4]), htons(ip->u.addr16[5]), htons(ip->u.addr16[6]),
-	       htons(ip->u.addr16[7]));
-	 break;
-      default:
-	 break;
-   }
+	switch(ip->af){
+		case AF_INET:
+			snprintf(where,len,"%d.%d.%d.%d", ip->u.addr[0], ip->u.addr[1], ip->u.addr[2], ip->u.addr[3]);
+			break;
+		case AF_INET6:
+			snprintf(where,len,"%x:%x:%x:%x:%x:%x:%x:%x",htons(ip->u.addr16[0]),htons(ip->u.addr16[1]),htons(ip->u.addr16[2]),
+					htons(ip->u.addr16[3]), htons(ip->u.addr16[4]), htons(ip->u.addr16[5]), htons(ip->u.addr16[6]),
+					htons(ip->u.addr16[7]));
+			break;
+		default:
+			break;
+	}
 }
 #endif
diff --git a/src/modules/seas/seas_action.c b/src/modules/seas/seas_action.c
index 3cb5513..7c963e6 100644
--- a/src/modules/seas/seas_action.c
+++ b/src/modules/seas/seas_action.c
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
  *
  * This file is part of Kamailio, a free SIP server.
@@ -14,15 +13,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * -------
- * 2008-04-04 added support for local and remote dispaly name in TM dialogs
- *            (by Andrei Pisau <andrei at voice-system dot ro> )
- *
  */
 
 #include <unistd.h>
@@ -496,7 +490,7 @@ int ac_cancel(as_p the_as,unsigned char processor_id,unsigned int flags,char *ac
    the_param->uac_id=uac_id;
    the_param->processor_id=processor_id;
    the_param->destroy_cb_set=0;
-   
+
    /* registers TMCB_RESPONSE_IN|TMCB_LOCAL_COMPLETED tm callbacks */
    ret=seas_f.tmb.t_cancel_uac(&headers,&body,cancelled_hashIdx,cancelled_label,uac_cb,(void*)the_param);
    if (ret == 0) {
@@ -901,15 +895,15 @@ int forward_sl_request(struct sip_msg *msg,str *uri,int proto)
         if ((uri2dst(NULL,&dst, msg,  uri, proto)==0) || (dst.send_sock==0))
 #else
         if ((uri2dst(&dst, msg,  uri, proto)==0) || (dst.send_sock==0))
-#endif 
+#endif
         {
-		LOG(L_ERR, "forward_sl_request: no socket found\n");
+		LM_ERR("no socket found\n");
 		return -1;
 	}
 
         LM_DBG("Sending:\n%.*s.\n", (int)msg->len,msg->buf);
         if (msg_send(&dst, msg->buf,msg->len)<0){
-           LM_ERR("ERROR:seas:forward_sl_request: Error sending message !!\n");
+           LM_ERR("Error sending message !!\n");
            return -1;
         }
 	return ret;
diff --git a/src/modules/sipcapture/README b/src/modules/sipcapture/README
index 451628d..bc33605 100644
--- a/src/modules/sipcapture/README
+++ b/src/modules/sipcapture/README
@@ -49,6 +49,7 @@ Alexandr Dubovikov
               3.18. insert_retry_timeout (integer)
               3.19. callid_aleg_header (str)
               3.20. topoh_unmask (int)
+              3.21. nonsip_hook (int)
 
         4. Functions
 
@@ -84,8 +85,9 @@ Alexandr Dubovikov
    1.18. Set insert_retry_timeout parameter
    1.19. Set callid_aleg_header parameter
    1.20. Set topoh_unmask parameter
-   1.21. sip_capture() usage
-   1.22. report_capture() usage
+   1.21. Set nonsip_hook parameter
+   1.22. sip_capture() usage
+   1.23. report_capture() usage
 
 Chapter 1. Admin Guide
 
@@ -119,6 +121,7 @@ Chapter 1. Admin Guide
         3.18. insert_retry_timeout (integer)
         3.19. callid_aleg_header (str)
         3.20. topoh_unmask (int)
+        3.21. nonsip_hook (int)
 
    4. Functions
 
@@ -186,6 +189,7 @@ Chapter 1. Admin Guide
    3.18. insert_retry_timeout (integer)
    3.19. callid_aleg_header (str)
    3.20. topoh_unmask (int)
+   3.21. nonsip_hook (int)
 
 3.1. db_url (str)
 
@@ -257,7 +261,7 @@ modparam("sipcapture", "db_insert_mode", 1)
 
 3.6. capture_on (integer)
 
-   Parameter to enable/disable capture globaly (on(1)/off(0))
+   Parameter to enable/disable capture globally (on(1)/off(0))
 
    Default value is "0".
 
@@ -456,6 +460,18 @@ modparam("sipcapture", "callid_aleg_header", "X-CallIDALeg")
 modparam("sipcapture", "topoh_unmask", 1)
 ...
 
+3.21. nonsip_hook (int)
+
+   If set to 1, event route sipcapture:siprequest is run when HEP message
+   is received.
+
+   Default value is 0.
+
+   Example 1.21. Set nonsip_hook parameter
+...
+modparam("sipcapture", "nonsip_hook", 1)
+...
+
 4. Functions
 
    4.1. sip_capture([table])
@@ -477,7 +493,7 @@ modparam("sipcapture", "topoh_unmask", 1)
    ONREPLY_ROUTE, BRANCH_ROUTE.
    Default value is "NULL".
 
-   Example 1.21. sip_capture() usage
+   Example 1.22. sip_capture() usage
 ...
 sip_capture();
 ...
@@ -496,7 +512,7 @@ sip_capture("sip_capture_call_20160124");
    ONREPLY_ROUTE, BRANCH_ROUTE.
    Default value is "NULL".
 
-   Example 1.22. report_capture() usage
+   Example 1.23. report_capture() usage
 ...
 report_capture();
 ...
diff --git a/src/modules/sipcapture/doc/sipcapture_admin.xml b/src/modules/sipcapture/doc/sipcapture_admin.xml
index 8916317..c5590b3 100644
--- a/src/modules/sipcapture/doc/sipcapture_admin.xml
+++ b/src/modules/sipcapture/doc/sipcapture_admin.xml
@@ -185,7 +185,7 @@ modparam("sipcapture", "db_insert_mode", 1)
 	<section id="sipcapture.p.capture_on">
 		<title><varname>capture_on</varname> (integer)</title>
 		<para>
-		Parameter to enable/disable capture globaly (on(1)/off(0))
+		Parameter to enable/disable capture globally (on(1)/off(0))
 		</para>
 		<para>
 		<emphasis>
@@ -493,6 +493,26 @@ modparam("sipcapture", "topoh_unmask", 1)
 			</programlisting>
 		</example>
 	</section>
+
+	<section id="sipcapture.p.nonsip_hook">
+		<title><varname>nonsip_hook</varname> (int)</title>
+		<para>
+		If set to 1, event route <emphasis>sipcapture:siprequest</emphasis> is
+		run when HEP message is received.
+		</para>
+		<para>
+			Default value is <emphasis>0</emphasis>.
+		</para>
+		<example>
+			<title>Set <varname>nonsip_hook</varname> parameter</title>
+			<programlisting format="linespecific">
+...
+modparam("sipcapture", "nonsip_hook", 1)
+...
+			</programlisting>
+		</example>
+	</section>
+
 </section>	
 <section>
 	<title>Functions</title>
diff --git a/src/modules/sipcapture/examples/kamailio.cfg b/src/modules/sipcapture/examples/kamailio.cfg
index 3d42a78..14a5641 100644
--- a/src/modules/sipcapture/examples/kamailio.cfg
+++ b/src/modules/sipcapture/examples/kamailio.cfg
@@ -861,10 +861,6 @@ route[STORE] {
 	sip_capture("$var(a)");
 }
 
-event_route[sipcapture:request] {
-	xlog("received sipcapture request from $si:$sp\r\n");
-}
-
 #!ifdef WITH_HOMER_CUSTOM_STATS
 event_route[xhttp:request] {
         set_reply_close();
@@ -908,12 +904,14 @@ event_route[xhttp:request] {
 
 event_route[sipcapture:request] {
 
-        xlog("HEP Request!\n");
-        xlog("received sipcapture request from $si:$sp\r\n");
-        xlog("HEP VERSION $hep(version) request from $si:$sp\r\n");
-        xlog("HEP CHUNK Source IP $hep(0x002) request from $si:$sp\r\n");
+	xlog("HEP Request!\n");
+	xlog("received sipcapture request from $si:$sp\n");
+	xlog("HEP VERSION $hep(version) request from $si:$sp\n");
+	xlog("HEP CHUNK Source IP $hep(0x002) request from $si:$sp\n");
+
 	#Is it SIP ?
-	if($hep(0x00b) == 1){
+	if($hep(0x00b) == 1)
+	{
 
 		#Do parsing internal
 		return 1;
@@ -921,8 +919,8 @@ event_route[sipcapture:request] {
 	else 
 	{
 		#If report lets proceed here with payload
-	        xlog("HEP CHUNK PAYLOAD $hep(0x00f) request from $si:$sp\r\n");
-        	return 0;   
+		xlog("HEP CHUNK PAYLOAD $hep(0x00f) request from $si:$sp\n");
+		return 0;
 	}
 }
 
diff --git a/src/modules/sipcapture/hep.c b/src/modules/sipcapture/hep.c
index 11d2049..6eaf13a 100644
--- a/src/modules/sipcapture/hep.c
+++ b/src/modules/sipcapture/hep.c
@@ -372,16 +372,14 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
                                         break;
                                 case 9:
                                         hg->time_sec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_sec->data = ntohl(hg->time_sec->data);
-                                        heptime->tv_sec = hg->time_sec->data;
+                                        heptime->tv_sec = ntohl(hg->time_sec->data);
                                         i+=chunk_length;
                                         totelem++;
-                                        break;                                                     
-                                                     
+                                        break;
+
                                 case 10:
                                         hg->time_usec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_usec->data = ntohl(hg->time_usec->data);
-                                        heptime->tv_usec = hg->time_usec->data;
+                                        heptime->tv_usec = ntohl(hg->time_usec->data);
                                         i+=chunk_length;
                                         totelem++;
                                         break;      
@@ -394,8 +392,8 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
 
                                 case 12:
                                         hg->capt_id  = (hep_chunk_uint32_t *) (tmp);
-                                        i+=chunk_length;
                                         heptime->captid = ntohl(hg->capt_id->data);
+                                        i+=chunk_length;
                                         totelem++;
                                         break;
 
@@ -483,13 +481,6 @@ int parsing_hepv3_message(char *buf, unsigned int len) {
         si->name.s = si->address_str.s;
         ri.bind_address=si;
 
-
-	/*TIME*/ 
-        heptime->tv_sec = hg->time_sec->data;
-        heptime->tv_usec = hg->time_usec->data;
-        heptime->captid = ntohl(hg->capt_id->data);
-          
-
         if(payload != NULL ) {
                 /* and now recieve message */
                 if (hg->proto_t->data == 5) receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture");
@@ -646,19 +637,17 @@ int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg) {
                                         break;
                                 case 9:
                                         hg->time_sec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_sec->data = ntohl(hg->time_sec->data);
-                                        heptime->tv_sec = hg->time_sec->data;
+                                        heptime->tv_sec = ntohl(hg->time_sec->data);
                                         i+=chunk_length;
                                         totelem++;
-                                        break;                                                     
-                                                     
+                                        break;
+
                                 case 10:
                                         hg->time_usec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_usec->data = ntohl(hg->time_usec->data);
-                                        heptime->tv_usec = hg->time_usec->data;
+                                        heptime->tv_usec = ntohl(hg->time_usec->data);
                                         i+=chunk_length;
                                         totelem++;
-                                        break;      
+                                        break;
 
                                 case 11:
                                         hg->proto_t  = (hep_chunk_uint8_t *) (tmp);
@@ -728,10 +717,10 @@ int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg) {
 
         if(payload != NULL) ret = len - payload_len;
 
-	/*TIME*/ 
-        heptime->tv_sec = hg->time_sec->data;
-        heptime->tv_usec = hg->time_usec->data;
-        heptime->captid = ntohl(hg->capt_id->data);
+
+
+
+
 
 done:
           
@@ -984,14 +973,12 @@ int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_ch
                                         goto done;
                                 case 9:
                                         hg->time_sec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_sec->data = ntohl(hg->time_sec->data);
-                                        ret = pv_get_uintval(msg, param, res, hg->time_sec->data);
+                                        ret = pv_get_uintval(msg, param, res, ntohl(hg->time_sec->data));
                                         goto done;
-                                                     
+
                                 case 10:
                                         hg->time_usec  = (hep_chunk_uint32_t *) (tmp);
-                                        hg->time_usec->data = ntohl(hg->time_usec->data);
-                                        ret = pv_get_uintval(msg, param, res, hg->time_usec->data);
+                                        ret = pv_get_uintval(msg, param, res, ntohl(hg->time_usec->data));
                                         goto done;
 
                                 case 11:
@@ -1001,13 +988,14 @@ int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_ch
 
                                 case 12:
                                         hg->capt_id  = (hep_chunk_uint32_t *) (tmp);
-                                        ret = pv_get_uintval(msg, param, res, ntohs(hg->capt_id->data));
+                                        ret = pv_get_uintval(msg, param, res, ntohl(hg->capt_id->data));
                                         goto done;
 
                                 case 13:
                                         hg->keep_tm  = (hep_chunk_uint16_t *) (tmp);
-                                        ret = pv_get_uintval(msg, param, res, hg->keep_tm->data);                                                                                
+                                        ret = pv_get_uintval(msg, param, res, ntohs(hg->keep_tm->data));
                                         goto done;
+
                                 case 14:
                                         tmpstr.s = (char *) tmp + sizeof(hep_chunk_t);
                                         tmpstr.len = chunk_length - sizeof(hep_chunk_t); 
diff --git a/src/modules/sipcapture/sipcapture.c b/src/modules/sipcapture/sipcapture.c
index 7167cf3..99a1844 100644
--- a/src/modules/sipcapture/sipcapture.c
+++ b/src/modules/sipcapture/sipcapture.c
@@ -271,7 +271,7 @@ enum hash_source source = hs_error;
 
 //unsigned int rr_idx = 0;
 
-struct hep_timehdr* heptime;
+struct hep_timeinfo* heptime;
 
 /*! \brief
  * Exported functions
@@ -446,6 +446,7 @@ int parse_table_names (str table_name, str ** table_names){
 	names = (str*)pkg_malloc(sizeof(str) * no_tables);
 	if(names == NULL) {
 		LM_ERR("no more pkg memory left\n");
+		pkg_free(table_name_cpy);
 		return -1;
 	}
 	p = strtok (table_name_cpy,"| \t");
@@ -1038,6 +1039,9 @@ static int w_float2int(struct sip_msg* _m, char* _val, char* _coof, char* s2)
 		return -1;
 	}
 
+	if(value.s==NULL || coof.s==NULL)
+		return -1;
+	
 	ret = (int) (atof (value.s) * atoi(coof.s));
 
 	return  ret ? ret : -1;
@@ -1150,7 +1154,7 @@ static int child_init(int rank)
 	}
 
 
-	heptime = (struct hep_timehdr*)pkg_malloc(sizeof(struct hep_timehdr));
+	heptime = (struct hep_timeinfo*)pkg_malloc(sizeof(struct hep_timeinfo));
 	if(heptime==NULL) {
 		LM_ERR("no more pkg memory left\n");
 		return -1;
@@ -1887,7 +1891,7 @@ static int sip_capture(struct sip_msg *msg, str *_table, _capture_mode_data_t *
 	else { EMPTY_STR(sco.custom1); }
 	
 	/* Custom - field2 */
-	if(custom_field3_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) {
+	if(custom_field2_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) {
 		sco.custom2 =  tmphdr[5]->body;
 	}
 	else { EMPTY_STR(sco.custom2); }
diff --git a/src/modules/snmpstats/utilities.c b/src/modules/snmpstats/utilities.c
index c57c832..afbca54 100644
--- a/src/modules/snmpstats/utilities.c
+++ b/src/modules/snmpstats/utilities.c
@@ -1,5 +1,5 @@
-/* 
- * SNMPStats Module 
+/*
+ * SNMPStats Module
  * Copyright (C) 2006 SOMA Networks, INC.
  * Written by: Jeffrey Magder (jmagder at somanetworks.com)
  *
@@ -50,13 +50,13 @@ static cfg_ctx_t  *ctx = NULL;
 
 /*!
  * This function copies an Kamailio "str" datatype into a '\\0' terminated char*
- * string. 
+ * string.
  *
  * \note Make sure to free the memory allocated to *copiedString, when you no
  *       longer have any use for it. (It is allocated with shm_malloc(), so make
- *       sure to deallocate it with shm_free()) 
+ *       sure to deallocate it with shm_free())
  */
-int convertStrToCharString(str *strToConvert, char **copiedString) 
+int convertStrToCharString(str *strToConvert, char **copiedString)
 {
 	/* We want enough space for the string, plus 1 for the '\0' character. */
 	*copiedString = shm_malloc(sizeof(char) * (strToConvert->len + 1));
@@ -75,7 +75,7 @@ int convertStrToCharString(str *strToConvert, char **copiedString)
 
 /*! Silently returns 1 if the supplied parameters are sane.  Otherwise, an error
  * message is logged for parameterName, and 0 returned. */
-int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName) 
+int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName)
 {
 	char *theString = (char *)val;
 
@@ -89,7 +89,7 @@ int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName)
 	/* An empty string was supplied.  We consider this illegal */
 	if (theString==0 || (theString[0])==0) {
 		LM_ERR("the %s parameter was specified  with an empty string\n",
-				parameterName); 
+				parameterName);
 		return 0;
 	}
 
@@ -101,7 +101,7 @@ int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName)
 /*!
  * This function is a wrapper around the standard statistic framework.  It will
  * return the value of the statistic denoted with statName, or zero if the
- * statistic was not found. 
+ * statistic was not found.
  */
 int get_statistic(char *statName)
 {
@@ -113,7 +113,7 @@ int get_statistic(char *statName)
 	theStr.len = strlen(statName);
 
 	stat_var *theVar = get_stat(&theStr);
-	
+
 	if (theVar==0) {
 		LM_INFO("failed to retrieve statistics for %s\n", statName);
 	} else {
@@ -126,7 +126,7 @@ int get_statistic(char *statName)
 /*! Returns a pointer to an SNMP DateAndTime OCTET STRING representation of the
  * time structure.  Note that the pointer is to static data, so it shouldn't be
  * counted on to be around if this function is called again. */
-char * convertTMToSNMPDateAndTime(struct tm *timeStructure) 
+char * convertTMToSNMPDateAndTime(struct tm *timeStructure)
 {
 	static char dateAndTime[8];
 
@@ -151,14 +151,14 @@ char * convertTMToSNMPDateAndTime(struct tm *timeStructure)
 int config_context_init(void)
 {
 	if (cfg_register_ctx(&ctx, NULL)) {
-		LOG(L_ERR, "cfg_rpc: failed to register cfg context\n");
+		LM_ERR("failed to register cfg context\n");
 		return -1;
 	}
 
 	return 0;
 }
 
-/*! \brief Get config framework variable 
+/*! \brief Get config framework variable
  * type will return cfg_type - CFG_VAR_INT, CFG_VAR_STRING, CFG_VAR_STR
  * If type is CFG_VAR_UNSET then call failed and return value should be ignored.
 */
@@ -179,13 +179,14 @@ int snmp_cfg_get_int(char *arg_group, char *arg_name, unsigned int *type)
 
 	res = cfg_get_by_name(ctx, &group, NULL, &name, &val, &val_type);
 	if (res < 0) {
-		LM_ERR("Failed to get the variable\n");
+		LM_ERR("failed to get the variable\n");
 		return -1;
 	} else if (res > 0) {
-		LM_ERR("Variable exists, but it is not readable via RPC interface\n");
+		LM_ERR("fariable exists, but it is not readable via RPC interface\n");
 		return -1;
 	}
-	LM_DBG("Config framework variable %s:%s retrieved %d\n", arg_group, arg_name, (int)(long) val);
+	LM_DBG("xonfig framework variable %s:%s retrieved %d\n",
+			arg_group, arg_name, (int)(long) val);
 	*type = val_type;
 	return (int) (long) val;
 }
diff --git a/src/modules/sqlops/sql_api.c b/src/modules/sqlops/sql_api.c
index ddf579c..1649230 100644
--- a/src/modules/sqlops/sql_api.c
+++ b/src/modules/sqlops/sql_api.c
@@ -394,14 +394,15 @@ int sql_do_query(sql_con_t *con, str *query, sql_result_t *res)
 					res->vals[i][j].value.s.len = 0;
 					continue;
 				}
-				res->vals[i][j].value.s.s 
-					= (char*)pkg_malloc(sv.len*sizeof(char));
+				res->vals[i][j].value.s.s
+					= (char*)pkg_malloc((sv.len+1)*sizeof(char));
 				if(res->vals[i][j].value.s.s==NULL)
 				{
 					LM_ERR("no more memory\n");
 					goto error;
 				}
 				memcpy(res->vals[i][j].value.s.s, sv.s, sv.len);
+				res->vals[i][j].value.s.s[sv.len] = '\0';
 				res->vals[i][j].value.s.len = sv.len;
 			}
 		}
diff --git a/src/modules/timer/timer.c b/src/modules/timer/timer.c
index 877c318..944e50b 100644
--- a/src/modules/timer/timer.c
+++ b/src/modules/timer/timer.c
@@ -189,7 +189,7 @@ static ticks_t timer_handler(ticks_t ticks, struct timer_ln* tl, void* data) {
 		/* execute post request-script callbacks */
 		exec_post_script_cb(msg, REQUEST_CB_TYPE);
 	end:
-		reset_avps();
+		ksr_msg_env_reset();
 		DEBUG(MODULE_NAME": handler: cleaning up\n");
 	err:
 		free_sip_msg(msg);
diff --git a/src/modules/tm/t_lookup.c b/src/modules/tm/t_lookup.c
index 265633c..474ad63 100644
--- a/src/modules/tm/t_lookup.c
+++ b/src/modules/tm/t_lookup.c
@@ -930,7 +930,7 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 		*p_branch =(int) branch_id;
 		REF_UNSAFE( T );
 		UNLOCK_HASH(hash_index);
-		LM_DBG("reply matched (T=%p)!\n",T);
+		LM_DBG("reply (%p) matched an active transaction (T=%p)!\n", p_msg, T);
 		if(likely(!(p_msg->msg_flags&FL_TM_RPL_MATCHED))) {
 			/* if this is a 200 for INVITE, we will wish to store to-tags to be
 			 * able to distinguish retransmissions later and not to call
@@ -997,8 +997,8 @@ int t_check_msg( struct sip_msg* p_msg , int *param_branch )
 
 	ret=0;
 	/* is T still up-to-date ? */
-	LM_DBG("msg id=%d global id=%d T start=%p\n",
-			p_msg->id,global_msg_id,T);
+	LM_DBG("msg (%p) id=%d global id=%d T start=%p\n",
+			p_msg,p_msg->id,global_msg_id,T);
 	if ( p_msg->id != global_msg_id || T==T_UNDEFINED )
 	{
 		global_msg_id = p_msg->id;
@@ -1063,17 +1063,17 @@ int t_check_msg( struct sip_msg* p_msg , int *param_branch )
 		if ( T && T!=T_UNDEFINED && T->flags & (T_IN_AGONY)) {
 			LM_WARN("transaction %p scheduled for deletion "
 					"and called from t_check_msg (flags=%x) (but it might be ok)"
-					"\n", T, T->flags);
+					" (msg %p)\n", T, T->flags, p_msg);
 		}
 #endif
-		LM_DBG("msg id=%d global id=%d T end=%p\n",
-				p_msg->id,global_msg_id,T);
+		LM_DBG("msg (%p) id=%d global id=%d T end=%p\n",
+				p_msg,p_msg->id,global_msg_id,T);
 	} else { /*  ( p_msg->id == global_msg_id && T!=T_UNDEFINED ) */
 		if (T){
-			LM_DBG("T already found!\n");
+			LM_DBG("T (%p) already found for msg (%p)!\n", T, p_msg);
 			ret=1;
 		}else{
-			LM_DBG("T previously sought and not found\n");
+			LM_DBG("T previously sought and not found for msg (%p)\n", p_msg);
 			ret=-1;
 		}
 		if (likely(param_branch))
diff --git a/src/modules/tm/t_suspend.c b/src/modules/tm/t_suspend.c
index ac53225..d8f0ee7 100644
--- a/src/modules/tm/t_suspend.c
+++ b/src/modules/tm/t_suspend.c
@@ -166,7 +166,9 @@ int t_continue(unsigned int hash_index, unsigned int label,
 		struct action *route)
 {
 	struct cell	*t;
-	struct sip_msg *faked_req;
+	sip_msg_t *faked_req;
+	sip_msg_t *brpl;
+	void *erpl;
 	int faked_req_len = 0;
 	struct cancel_info cancel_data;
 	int	branch;
@@ -240,6 +242,7 @@ int t_continue(unsigned int hash_index, unsigned int label,
 				/* Either t_continue() has already been
 				* called or the branch has already timed out.
 				* Needless to continue. */
+				t->flags &= ~T_ASYNC_CONTINUE;
 				UNLOCK_ASYNC_CONTINUE(t);
 				UNREF(t); /* t_unref would kill the transaction */
 				return 1;
@@ -254,6 +257,14 @@ int t_continue(unsigned int hash_index, unsigned int label,
 			 * a failure route => deadlock, because both
 			 * of them need the reply lock to be held. */
 			t->uac[branch].last_received=500;
+			if(t->uac[branch].reply!=NULL) {
+				LM_WARN("reply (%p) already set for suspended transaction"
+						" (branch: %d)\n",
+						t->uac[branch].reply, branch);
+			} else {
+				/* set it as a faked reply */
+				t->uac[branch].reply=FAKED_REPLY;
+			}
 			uac = &t->uac[branch];
 		}
 		/* else
@@ -311,7 +322,7 @@ int t_continue(unsigned int hash_index, unsigned int label,
 
 			if (branch == t->nr_of_outgoings) {
 			/* There is not any open branch so there is
-			* no chance that a final response will be received. */
+			 * no chance that a final response will be received. */
 				ret = 0;
 				goto kill_trans;
 			}
@@ -422,40 +433,52 @@ int t_continue(unsigned int hash_index, unsigned int label,
 	}
 
 done:
+	t->flags &= ~T_ASYNC_CONTINUE;
+	if(t->async_backup.backup_route == TM_ONREPLY_ROUTE) {
+		/* response handling */
+		/* backup branch reply to free it later and reset it here under lock */
+		brpl = t->uac[branch].reply;
+		erpl = (void*)t->uac[branch].end_reply;
+		t->uac[branch].reply = 0;
+		t->uac[branch].end_reply = 0;
+	}
 	UNLOCK_ASYNC_CONTINUE(t);
 
 	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
+		/* request handling */
 		/* unref the transaction */
 		t_unref(t->uas.request);
 	} else {
+		/* response handling */
 		tm_ctx_set_branch_index(T_BR_UNDEFINED);
 		/* unref the transaction */
-		t_unref(t->uac[branch].reply);
+		t_unref(brpl);
 		LM_DBG("Freeing earlier cloned reply\n");
 
 		/* free lumps that were added during reply processing */
-		del_nonshm_lump( &(t->uac[branch].reply->add_rm) );
-		del_nonshm_lump( &(t->uac[branch].reply->body_lumps) );
-		del_nonshm_lump_rpl( &(t->uac[branch].reply->reply_lump) );
+		del_nonshm_lump( &(brpl->add_rm) );
+		del_nonshm_lump( &(brpl->body_lumps) );
+		del_nonshm_lump_rpl( &(brpl->reply_lump) );
 
 		/* free header's parsed structures that were added */
-		for( hdr=t->uac[branch].reply->headers ; hdr ; hdr=hdr->next ) {
+		for( hdr=brpl->headers ; hdr ; hdr=hdr->next ) {
 			if ( hdr->parsed && hdr_allocs_parse(hdr) &&
-				(hdr->parsed<(void*)t->uac[branch].reply ||
-				hdr->parsed>=(void*)t->uac[branch].end_reply)) {
+					(hdr->parsed<(void*)brpl ||
+					hdr->parsed>=(void*)erpl)) {
 				clean_hdr_field(hdr);
 				hdr->parsed = 0;
 			}
 		}
 
-		/* now go through hdr_fields themselves and remove the pkg allocated space */
-		hdr = t->uac[branch].reply->headers;
+		/* now go through hdr fields themselves
+		 * and remove the pkg allocated space */
+		hdr = brpl->headers;
 		while (hdr) {
-			if ( hdr && ((void*)hdr<(void*)t->uac[branch].reply ||
-				(void*)hdr>=(void*)t->uac[branch].end_reply)) {
-				//this header needs to be freed and removed form the list.
+			if ( hdr && ((void*)hdr<(void*)brpl ||
+					(void*)hdr>=(void*)erpl)) {
+				/* this header needs to be freed and removed form the list */
 				if (!prev) {
-					t->uac[branch].reply->headers = hdr->next;
+					brpl->headers = hdr->next;
 				} else {
 					prev->next = hdr->next;
 				}
@@ -467,8 +490,7 @@ done:
 				hdr = hdr->next;
 			}
 		}
-		sip_msg_free(t->uac[branch].reply);
-		t->uac[branch].reply = 0;
+		sip_msg_free(brpl);
 	}
 
 
@@ -478,21 +500,24 @@ kill_trans:
 	/* The script has hopefully set the error code. If not,
 	 * let us reply with a default error. */
 	if ((kill_transaction_unsafe(t,
-		tm_error ? tm_error : E_UNSPEC)) <=0
-	) {
+				tm_error ? tm_error : E_UNSPEC)) <=0) {
 		LM_ERR("reply generation failed\n");
 		/* The transaction must be explicitely released,
 		 * no more timer is running */
+		t->flags &= ~T_ASYNC_CONTINUE;
 		UNLOCK_ASYNC_CONTINUE(t);
 		t_release_transaction(t);
 	} else {
+		t->flags &= ~T_ASYNC_CONTINUE;
 		UNLOCK_ASYNC_CONTINUE(t);
 	}
 
+	/* unref the transaction */
 	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
+		/* request handling */
 		t_unref(t->uas.request);
 	} else {
-		/* unref the transaction */
+		/* response handling */
 		t_unref(t->uac[branch].reply);
 	}
 	return ret;
diff --git a/src/modules/tmx/tmx_mod.c b/src/modules/tmx/tmx_mod.c
index 9c5f8b1..27e6d96 100644
--- a/src/modules/tmx/tmx_mod.c
+++ b/src/modules/tmx/tmx_mod.c
@@ -55,26 +55,26 @@ static int mod_init(void);
 static int child_init(int rank);
 static void destroy(void);
 
-static int t_cancel_branches(struct sip_msg* msg, char *k, char *s2);
+static int t_cancel_branches(sip_msg_t* msg, char *k, char *s2);
 static int fixup_cancel_branches(void** param, int param_no);
-static int w_t_cancel_callid_3(struct sip_msg* msg, char *cid, char *cseq,
+static int w_t_cancel_callid_3(sip_msg_t* msg, char *cid, char *cseq,
 		char *flag);
-static int w_t_cancel_callid_4(struct sip_msg* msg, char *cid, char *cseq,
+static int w_t_cancel_callid_4(sip_msg_t* msg, char *cid, char *cseq,
 		char *flag, char *creason);
 static int fixup_cancel_callid(void** param, int param_no);
-static int t_reply_callid(struct sip_msg* msg, char *cid, char *cseq,
+static int t_reply_callid(sip_msg_t* msg, char *cid, char *cseq,
 		char *rc, char *rs);
 static int fixup_reply_callid(void** param, int param_no);
 
-static int t_flush_flags(struct sip_msg* msg, char*, char* );
-static int w_t_is_failure_route(struct sip_msg* msg, char*, char* );
-static int w_t_is_branch_route(struct sip_msg* msg, char*, char* );
-static int w_t_is_reply_route(struct sip_msg* msg, char*, char*);
-static int w_t_is_request_route(struct sip_msg* msg, char*, char*);
+static int t_flush_flags(sip_msg_t* msg, char*, char* );
+static int w_t_is_failure_route(sip_msg_t* msg, char*, char* );
+static int w_t_is_branch_route(sip_msg_t* msg, char*, char* );
+static int w_t_is_reply_route(sip_msg_t* msg, char*, char*);
+static int w_t_is_request_route(sip_msg_t* msg, char*, char*);
 
-static int w_t_suspend(struct sip_msg* msg, char*, char*);
-static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn);
-static int w_t_reuse_branch(struct sip_msg* msg, char*, char*);
+static int w_t_suspend(sip_msg_t* msg, char*, char*);
+static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn);
+static int w_t_reuse_branch(sip_msg_t* msg, char*, char*);
 static int fixup_t_continue(void** param, int param_no);
 static int w_t_precheck_trans(sip_msg_t*, char*, char*);
 
@@ -305,10 +305,10 @@ static int fixup_cancel_branches(void** param, int param_no)
 /**
  *
  */
-static int t_cancel_branches(struct sip_msg* msg, char *k, char *s2)
+static int t_cancel_branches(sip_msg_t* msg, char *k, char *s2)
 {
 	struct cancel_info cancel_data;
-	struct cell *t = 0;
+	tm_cell_t *t = 0;
 	tm_ctx_t *tcx = 0;
 	int n=0;
 	int idx = 0;
@@ -366,10 +366,10 @@ static int fixup_cancel_callid(void** param, int param_no)
 /**
  *
  */
-static int t_cancel_callid(struct sip_msg* msg, char *cid, char *cseq, char *flag, char *creason)
+static int t_cancel_callid(sip_msg_t* msg, char *cid, char *cseq, char *flag, char *creason)
 {
-	struct cell *trans;
-	struct cell *bkt;
+	tm_cell_t *trans;
+	tm_cell_t *bkt;
 	int bkb;
 	struct cancel_info cancel_data;
 	str cseq_s;
@@ -431,7 +431,7 @@ static int t_cancel_callid(struct sip_msg* msg, char *cid, char *cseq, char *fla
 /**
  *
  */
-static int w_t_cancel_callid_3(struct sip_msg* msg, char *cid, char *cseq, char *flag)
+static int w_t_cancel_callid_3(sip_msg_t* msg, char *cid, char *cseq, char *flag)
 {
 	return t_cancel_callid(msg, cid, cseq, flag, NULL);
 }
@@ -439,7 +439,7 @@ static int w_t_cancel_callid_3(struct sip_msg* msg, char *cid, char *cseq, char
 /**
  *
  */
-static int w_t_cancel_callid_4(struct sip_msg* msg, char *cid, char *cseq, char *flag, char *creason)
+static int w_t_cancel_callid_4(sip_msg_t* msg, char *cid, char *cseq, char *flag, char *creason)
 {
 	return t_cancel_callid(msg, cid, cseq, flag, creason);
 }
@@ -461,10 +461,10 @@ static int fixup_reply_callid(void** param, int param_no)
 /**
  *
  */
-static int t_reply_callid(struct sip_msg* msg, char *cid, char *cseq,
+static int t_reply_callid(sip_msg_t* msg, char *cid, char *cseq,
 		char *rc, char *rs)
 {
-	struct cell *trans;
+	tm_cell_t *trans;
 	str cseq_s;
 	str callid_s;
 	str status_s;
@@ -496,11 +496,11 @@ static int t_reply_callid(struct sip_msg* msg, char *cid, char *cseq,
 
 	if(_tmx_tmb.t_lookup_callid(&trans, callid_s, cseq_s) < 0 )
 	{
-		DBG("Lookup failed - no transaction\n");
+		LM_DBG("Lookup failed - no transaction\n");
 		return -1;
 	}
 
-	DBG("Now calling internal replay\n");
+	LM_DBG("Now calling internal replay\n");
 	if(_tmx_tmb.t_reply_trans(trans, trans->uas.request, code, status_s.s)>0)
 		return 1;
 
@@ -510,9 +510,9 @@ static int t_reply_callid(struct sip_msg* msg, char *cid, char *cseq,
 /**
  *
  */
-static int t_flush_flags(struct sip_msg* msg, char *foo, char *bar)
+static int t_flush_flags(sip_msg_t* msg, char *foo, char *bar)
 {
-	struct cell *t;
+	tm_cell_t *t;
 
 	t=_tmx_tmb.t_gett();
 	if ( t==0 || t==T_UNDEFINED) {
@@ -527,7 +527,7 @@ static int t_flush_flags(struct sip_msg* msg, char *foo, char *bar)
 /**
  *
  */
-static int w_t_is_failure_route(struct sip_msg* msg, char *foo, char *bar)
+static int w_t_is_failure_route(sip_msg_t* msg, char *foo, char *bar)
 {
 	if(route_type==FAILURE_ROUTE)
 		return 1;
@@ -547,7 +547,7 @@ static int t_is_failure_route(sip_msg_t* msg)
 /**
  *
  */
-static int w_t_is_branch_route(struct sip_msg* msg, char *foo, char *bar)
+static int w_t_is_branch_route(sip_msg_t* msg, char *foo, char *bar)
 {
 	if(route_type==BRANCH_ROUTE)
 		return 1;
@@ -567,7 +567,7 @@ static int t_is_branch_route(sip_msg_t* msg)
 /**
  *
  */
-static int w_t_is_reply_route(struct sip_msg* msg, char *foo, char *bar)
+static int w_t_is_reply_route(sip_msg_t* msg, char *foo, char *bar)
 {
 	if(route_type & ONREPLY_ROUTE)
 		return 1;
@@ -587,7 +587,7 @@ static int t_is_reply_route(sip_msg_t* msg)
 /**
  *
  */
-static int w_t_is_request_route(struct sip_msg* msg, char *foo, char *bar)
+static int w_t_is_request_route(sip_msg_t* msg, char *foo, char *bar)
 {
 	if(route_type == REQUEST_ROUTE)
 		return 1;
@@ -607,7 +607,7 @@ static int t_is_request_route(sip_msg_t* msg)
 /**
  *
  */
-static int w_t_suspend(struct sip_msg* msg, char *p1, char *p2)
+static int w_t_suspend(sip_msg_t* msg, char *p1, char *p2)
 {
 	unsigned int tindex;
 	unsigned int tlabel;
@@ -641,7 +641,7 @@ static int w_t_suspend(struct sip_msg* msg, char *p1, char *p2)
 /**
  *
  */
-static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn)
+static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn)
 {
 	unsigned int tindex;
 	unsigned int tlabel;
@@ -695,9 +695,9 @@ static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn)
  * Currently the following branch attributes are included:
  * request-uri, ruid, path, instance, and branch flags.
  */
-static int w_t_reuse_branch(struct sip_msg* msg, char *p1, char *p2)
+static int w_t_reuse_branch(sip_msg_t* msg, char *p1, char *p2)
 {
-	struct cell *t;
+	tm_cell_t *t;
 	int branch;
 
 	if (msg == NULL) return -1;
diff --git a/src/modules/uid_auth_db/aaa_avps.h b/src/modules/uid_auth_db/aaa_avps.h
index cbe7b1b..c11c679 100644
--- a/src/modules/uid_auth_db/aaa_avps.h
+++ b/src/modules/uid_auth_db/aaa_avps.h
@@ -41,8 +41,8 @@
  * Parse list of tokens separated by some char and put each token
  * into result array. Caller frees result array!
  */
-static inline int
-parse_token_list(char *p, char *pend, char separator, str **result)
+static inline int parse_token_list(char *p, char *pend, char separator,
+		str **result)
 {
 	int i;
 
@@ -65,29 +65,27 @@ parse_token_list(char *p, char *pend, char separator, str **result)
  * Parse the list of AVP names separated by '|' into an array
  * of names, each element of the array is str string
  */
-static int
-aaa_avps_init(str *avp_list, str **parsed_avps, int *avps_n)
+static int aaa_avps_init(str *avp_list, str **parsed_avps, int *avps_n)
 {
 	int errcode, i;
 	char *cp;
 
 	if (!avp_list->s || !avp_list->len) {
-		     /* AVPs disabled, nothing to do */
+		/* AVPs disabled, nothing to do */
 		*avps_n = 0;
 		return 1;
 	}
 
 	cp = pkg_malloc(avp_list->len + 1);
 	if (cp == NULL) {
-		LOG(L_ERR, "aaa_avps::aaa_avps_init(): can't allocate memory\n");
+		LM_ERR("can't allocate memory\n");
 		errcode = -1;
 		goto bad;
 	}
 	memcpy(cp, avp_list->s, avp_list->len);
 	*avps_n = parse_token_list(cp, cp + avp_list->len, '|', parsed_avps);
 	if (*avps_n == -1) {
-		LOG(L_ERR, "aaa_avps::aaa_avps_init(): can't parse avps_column_int "
-		    "parameter\n");
+		LM_ERR("can't parse avps_column_int parameter\n");
 		errcode = -2;
 		pkg_free(cp);
 		goto bad;
diff --git a/src/modules/uid_auth_db/authorize.c b/src/modules/uid_auth_db/authorize.c
index cc3e980..0dd155a 100644
--- a/src/modules/uid_auth_db/authorize.c
+++ b/src/modules/uid_auth_db/authorize.c
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Digest Authentication - Database support
  *
  * Copyright (C) 2001-2003 FhG Fokus
@@ -22,16 +20,10 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * history:
- * ---------
- * 2003-02-28 scratchpad compatibility abandoned
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
- * 2004-06-06 updated to the new DB api, added auth_db_{init,bind,close,ver}
- *             (andrei)
  */
 
 
@@ -57,31 +49,31 @@
 #define IS_NULL(f)	((f).flags & DB_NULL)
 
 static inline int get_ha1(struct username* username, str* did, str* realm,
-			  authdb_table_info_t *table_info, char* ha1, db_res_t** res, db_rec_t** row)
+		authdb_table_info_t *table_info, char* ha1, db_res_t** res, db_rec_t** row)
 {
 	str result;
 	db_cmd_t *q = NULL;
-   
+
 	if (calc_ha1) {
 		q = table_info->query_password;
-		DBG("querying plain password\n");
+		LM_DBG("querying plain password\n");
 	} else {
 		if (username->domain.len) {
 			q = table_info->query_pass2;
-			DBG("querying ha1b\n");
+			LM_DBG("querying ha1b\n");
 		} else {
 			q = table_info->query_pass;
-			DBG("querying ha1\n");
+			LM_DBG("querying ha1\n");
 		}
 	}
-    
+
 	q->match[0].v.lstr = username->user;
 	q->match[1].v.lstr = *realm;
 
 	if (use_did) q->match[2].v.lstr = *did;
 
 	if (db_exec(res, q) < 0 ) {
-		ERR("Error while querying database\n");
+		LM_ERR("Error while querying database\n");
 		return -1;
 	}
 
@@ -89,8 +81,10 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
 	else *row = NULL;
 	while (*row) {
 		if (IS_NULL((*row)->fld[0]) || IS_NULL((*row)->fld[1])) {
-			LOG(L_ERR, "auth_db:get_ha1: Credentials for '%.*s'@'%.*s' contain NULL value, skipping\n",
-				username->user.len, ZSW(username->user.s), realm->len, ZSW(realm->s));
+			LM_ERR("Credentials for '%.*s'@'%.*s' contain NULL value,"
+					" skipping\n",
+					username->user.len, ZSW(username->user.s),
+					realm->len, ZSW(realm->s));
 		} else {
 			if ((*row)->fld[1].v.int4 & SRDB_DISABLED) {
 				/* disabled rows ignored */
@@ -105,10 +99,11 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
 	}
 
 	if (!*row) {
-		DBG("auth_db:get_ha1: Credentials for '%.*s'@'%.*s' not found\n",
-			username->user.len, ZSW(username->user.s), realm->len, ZSW(realm->s));
+		LM_DBG("Credentials for '%.*s'@'%.*s' not found\n",
+				username->user.len, ZSW(username->user.s),
+				realm->len, ZSW(realm->s));
 		return 1;
-	}		
+	}
 
 	result.s = (*row)->fld[0].v.cstr;
 	result.len = strlen(result.s);
@@ -117,7 +112,7 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
 		/* Only plaintext passwords are stored in database,
 		 * we have to calculate HA1 */
 		auth_api.calc_HA1(HA_MD5, &username->whole, realm, &result, 0, 0, ha1);
-		DBG("auth_db:get_ha1: HA1 string calculated: %s\n", ha1);
+		LM_DBG("HA1 string calculated: %s\n", ha1);
 	} else {
 		memcpy(ha1, result.s, result.len);
 		ha1[result.len] = '\0';
@@ -133,36 +128,36 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
 static inline int check_response(dig_cred_t* cred, str* method, char* ha1)
 {
 	HASHHEX resp, hent;
-    
+
 	/*
 	 * First, we have to verify that the response received has
 	 * the same length as responses created by us
 	 */
 	if (cred->response.len != 32) {
-		DBG("auth_db:check_response: Receive response len != 32\n");
+		LM_DBG("Receive response len != 32\n");
 		return 1;
 	}
-    
+
 	/*
 	 * Now, calculate our response from parameters received
 	 * from the user agent
 	 */
-	auth_api.calc_response(ha1, &(cred->nonce), 
-				  &(cred->nc), &(cred->cnonce), 
-				  &(cred->qop.qop_str), cred->qop.qop_parsed == QOP_AUTHINT,
-				  method, &(cred->uri), hent, resp);
-    
-	DBG("auth_db:check_response: Our result = \'%s\'\n", resp);
-    
+	auth_api.calc_response(ha1, &(cred->nonce),
+			&(cred->nc), &(cred->cnonce),
+			&(cred->qop.qop_str), cred->qop.qop_parsed == QOP_AUTHINT,
+			method, &(cred->uri), hent, resp);
+
+	LM_DBG("Our result = \'%s\'\n", resp);
+
 	/*
 	 * And simply compare the strings, the user is
 	 * authorized if they match
 	 */
 	if (!memcmp(resp, cred->response.s, 32)) {
-		DBG("auth_db:check_response: Authorization is OK\n");
+		LM_DBG("Authorization is OK\n");
 		return 0;
 	} else {
-		DBG("auth_db:check_response: Authorization failed\n");
+		LM_DBG("Authorization failed\n");
 		return 2;
 	}
 }
@@ -177,7 +172,7 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
 	int_str iname, ivalue;
 	str value;
 	char buf[32];
-    
+
 	for (i = 2; i < credentials_n + 2; i++) {
 		value = row->fld[i].v.lstr;
 
@@ -185,18 +180,18 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
 			continue;
 
 		switch (row->fld[i].type) {
-		case DB_STR:
-			value = row->fld[i].v.lstr;
-			break;
-
-		case DB_INT:
-			value.len = sprintf(buf, "%d", row->fld[i].v.int4);
-			value.s = buf;
-			break;
-
-		default:
-			abort();
-			break;
+			case DB_STR:
+				value = row->fld[i].v.lstr;
+				break;
+
+			case DB_INT:
+				value.len = sprintf(buf, "%d", row->fld[i].v.int4);
+				value.s = buf;
+				break;
+
+			default:
+				abort();
+				break;
 		}
 
 		if (value.s == NULL)
@@ -205,15 +200,16 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
 		iname.s = credentials[i - 2];
 		ivalue.s = value;
 
-		if (add_avp(AVP_NAME_STR | AVP_VAL_STR | AVP_CLASS_USER, iname, ivalue) < 0) {
-			LOG(L_ERR, "auth_db:generate_avps: Error while creating AVPs\n");
+		if (add_avp(AVP_NAME_STR | AVP_VAL_STR | AVP_CLASS_USER,
+					iname, ivalue) < 0) {
+			LM_ERR("Error while creating AVPs\n");
 			return -1;
 		}
 
-		DBG("auth_db:generate_avps: set string AVP \'%.*s = %.*s\'\n",
-			iname.s.len, ZSW(iname.s.s), value.len, ZSW(value.s));
+		LM_DBG("set string AVP \'%.*s = %.*s\'\n",
+				iname.s.len, ZSW(iname.s.s), value.len, ZSW(value.s));
 	}
-    
+
 	return 0;
 }
 
@@ -226,32 +222,32 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
  * WARNING: if -1 is returned res _must_ _not_ be freed (it's empty)
  *
  */
-static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr, 
-		dig_cred_t* dig, str* method, str* did, str* realm, 
-		authdb_table_info_t *table_info, db_res_t** res) 
+static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
+		dig_cred_t* dig, str* method, str* did, str* realm,
+		authdb_table_info_t *table_info, db_res_t** res)
 {
 	char ha1[256];
 	db_rec_t *row;
 	str result;
 	db_cmd_t *q;
-   
+
 	if (calc_ha1) {
 		q = table_info->query_password;
-		DBG("querying plain password\n");
+		LM_DBG("querying plain password\n");
 	}
 	else {
-	    if (dig->username.domain.len) {
+		if (dig->username.domain.len) {
 			q = table_info->query_pass2;
-			DBG("querying ha1b\n");
+			LM_DBG("querying ha1b\n");
 		}
 		else {
 			q = table_info->query_pass;
-			DBG("querying ha1\n");
+			LM_DBG("querying ha1\n");
 		}
 	}
-    
+
 	q->match[0].v.lstr = dig->username.user;
-	if (dig->username.domain.len) 
+	if (dig->username.domain.len)
 		q->match[1].v.lstr = dig->username.domain;
 	else
 		q->match[1].v.lstr = *realm;
@@ -259,15 +255,17 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
 	if (use_did) q->match[2].v.lstr = *did;
 
 	if (db_exec(res, q) < 0 ) {
-		ERR("Error while querying database\n");
+		LM_ERR("Error while querying database\n");
 	}
 
 	if (*res) row = db_first(*res);
 	else row = NULL;
 	while (row) {
 		if (IS_NULL(row->fld[0]) || IS_NULL(row->fld[1])) {
-			LOG(L_ERR, "auth_db:check_all_ha1: Credentials for '%.*s'@'%.*s' contain NULL value, skipping\n",
-			    dig->username.user.len, ZSW(dig->username.user.s), realm->len, ZSW(realm->s));
+			LM_ERR("Credentials for '%.*s'@'%.*s' contain NULL value,"
+					" skipping\n",
+					dig->username.user.len, ZSW(dig->username.user.s),
+					realm->len, ZSW(realm->s));
 		}
 		else {
 			if (row->fld[1].v.int4 & SRDB_DISABLED) {
@@ -278,17 +276,19 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
 					result.s = row->fld[0].v.cstr;
 					result.len = strlen(result.s);
 					if (calc_ha1) {
-						 /* Only plaintext passwords are stored in database,
-						  * we have to calculate HA1 */
-						auth_api.calc_HA1(HA_MD5, &(dig->username.whole), realm, &result, 0, 0, ha1);
-						DBG("auth_db:check_all_ha1: HA1 string calculated: %s\n", ha1);
+						/* Only plaintext passwords are stored in database,
+						 * we have to calculate HA1 */
+						auth_api.calc_HA1(HA_MD5, &(dig->username.whole),
+								realm, &result, 0, 0, ha1);
+						LM_DBG("HA1 string calculated: %s\n", ha1);
 					} else {
 						memcpy(ha1, result.s, result.len);
 						ha1[result.len] = '\0';
 					}
 
 					if (!check_response(dig, method, ha1)) {
-						if (auth_api.post_auth(msg, hdr, ha1) == AUTHENTICATED) {
+						if (auth_api.post_auth(msg, hdr, ha1)
+								== AUTHENTICATED) {
 							generate_avps(*res, row);
 							return 0;
 						}
@@ -300,9 +300,10 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
 	}
 
 	if (!row) {
-		DBG("auth_db:check_all_ha1: Credentials for '%.*s'@'%.*s' not found",
-		    dig->username.user.len, ZSW(dig->username.user.s), realm->len, ZSW(realm->s));
-	}		
+		LM_DBG("Credentials for '%.*s'@'%.*s' not found",
+				dig->username.user.len, ZSW(dig->username.user.s),
+				realm->len, ZSW(realm->s));
+	}
 	return 1;
 
 
@@ -317,7 +318,8 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
  *      -1 -- Authentication failed
  *       1 -- Authentication successful
  */
-static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_info_t *table, hdr_types_t hftype)
+static inline int authenticate(struct sip_msg* msg, str* realm,
+		authdb_table_info_t *table, hdr_types_t hftype)
 {
 	char ha1[256];
 	int res, ret;
@@ -326,51 +328,51 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
 	auth_body_t* cred;
 	db_res_t* result;
 	str did;
-    
+
 	cred = 0;
 	result = 0;
 	ret = -1;
-    
+
 	switch(auth_api.pre_auth(msg, realm, hftype, &h, NULL)) {
-	case NONCE_REUSED:
-		LM_DBG("nonce reused");
-		ret = AUTH_NONCE_REUSED;
-		goto end;
-	case STALE_NONCE:
-		LM_DBG("stale nonce\n");
-		ret = AUTH_STALE_NONCE;
-		goto end;
-	case NO_CREDENTIALS:
-		LM_DBG("no credentials\n");
-		ret = AUTH_NO_CREDENTIALS;
-		goto end;
-	case ERROR:
-	case BAD_CREDENTIALS:
-		ret = -3;
-		goto end;
-	case CREATE_CHALLENGE:
-		ERR("auth_db:authenticate: CREATE_CHALLENGE is not a valid state\n");
-		ret = -2;
-		goto end;
-	case DO_RESYNCHRONIZATION:
-		ERR("auth_db:authenticate: DO_RESYNCHRONIZATION is not a valid state\n");
-		ret = -2;
-		goto end;
-		
-	case NOT_AUTHENTICATED: 
-		ret = -1;
-		goto end;
-		
-	case DO_AUTHENTICATION: 
-		break;
-		
-	case AUTHENTICATED:
-		ret = 1; 
-		goto end;
+		case NONCE_REUSED:
+			LM_DBG("nonce reused");
+			ret = AUTH_NONCE_REUSED;
+			goto end;
+		case STALE_NONCE:
+			LM_DBG("stale nonce\n");
+			ret = AUTH_STALE_NONCE;
+			goto end;
+		case NO_CREDENTIALS:
+			LM_DBG("no credentials\n");
+			ret = AUTH_NO_CREDENTIALS;
+			goto end;
+		case ERROR:
+		case BAD_CREDENTIALS:
+			ret = -3;
+			goto end;
+		case CREATE_CHALLENGE:
+			LM_ERR("CREATE_CHALLENGE is not a valid state\n");
+			ret = -2;
+			goto end;
+		case DO_RESYNCHRONIZATION:
+			LM_ERR("DO_RESYNCHRONIZATION is not a valid state\n");
+			ret = -2;
+			goto end;
+
+		case NOT_AUTHENTICATED:
+			ret = -1;
+			goto end;
+
+		case DO_AUTHENTICATION:
+			break;
+
+		case AUTHENTICATED:
+			ret = 1;
+			goto end;
 	}
-    
+
 	cred = (auth_body_t*)h->parsed;
-	
+
 	if (use_did) {
 		if (msg->REQ_METHOD == METHOD_REGISTER) {
 			ret = get_to_did(&did, msg);
@@ -384,11 +386,12 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
 	} else {
 		did.len = 0;
 		did.s = 0;
-	}	
-    
+	}
+
 
 	if (check_all) {
-		res = check_all_ha1(msg, h, &(cred->digest), &msg->first_line.u.request.method, &did, realm, table, &result);
+		res = check_all_ha1(msg, h, &(cred->digest),
+				&msg->first_line.u.request.method, &did, realm, table, &result);
 		if (res < 0) {
 			ret = -2;
 			goto end;
@@ -401,8 +404,9 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
 			ret = 1;
 			goto end;
 		}
-    	} else {
-		res = get_ha1(&cred->digest.username, &did, realm, table, ha1, &result, &row);
+	} else {
+		res = get_ha1(&cred->digest.username, &did, realm, table, ha1,
+				&result, &row);
 		if (res < 0) {
 			ret = -2;
 			goto end;
@@ -411,39 +415,41 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
 			/* Username not found in the database */
 			ret = -1;
 			goto end;
-        	}
-    	}
-    
+		}
+	}
+
 	/* Recalculate response, it must be same to authorize successfully */
-	if (!check_response(&(cred->digest), &msg->first_line.u.request.method, ha1)) {
+	if (!check_response(&(cred->digest), &msg->first_line.u.request.method,
+				ha1)) {
 		switch(auth_api.post_auth(msg, h, ha1)) {
-		case ERROR:
-		case BAD_CREDENTIALS:
-			ret = -2; 
-			break;
-			
-		case NOT_AUTHENTICATED: 
-			ret = -1; 
-			break;
-			
-		case AUTHENTICATED:
-			generate_avps(result, row);
-			ret = 1;
-			break;
-			
-		default:
-			ret = -1;
-			break;
+			case ERROR:
+			case BAD_CREDENTIALS:
+				ret = -2;
+				break;
+
+			case NOT_AUTHENTICATED:
+				ret = -1;
+				break;
+
+			case AUTHENTICATED:
+				generate_avps(result, row);
+				ret = 1;
+				break;
+
+			default:
+				ret = -1;
+				break;
 		}
 	} else {
 		ret = -1;
 	}
 
- end:
+end:
 	if (result) db_res_free(result);
 	if (ret < 0) {
-		if (auth_api.build_challenge(msg, (cred ? cred->stale : 0), realm, NULL, NULL, hftype) < 0) {
-			ERR("Error while creating challenge\n");
+		if (auth_api.build_challenge(msg, (cred ? cred->stale : 0), realm,
+					NULL, NULL, hftype) < 0) {
+			LM_ERR("Error while creating challenge\n");
 			ret = -2;
 		}
 	}
@@ -459,7 +465,8 @@ int proxy_authenticate(struct sip_msg* msg, char* p1, char* p2)
 	str realm;
 
 	if (get_str_fparam(&realm, msg, (fparam_t*)p1) < 0) {
-		ERR("Cannot obtain digest realm from parameter '%s'\n", ((fparam_t*)p1)->orig);
+		LM_ERR("Cannot obtain digest realm from parameter '%s'\n",
+				((fparam_t*)p1)->orig);
 		return -1;
 	}
 
@@ -475,9 +482,11 @@ int www_authenticate(struct sip_msg* msg, char* p1, char* p2)
 	str realm;
 
 	if (get_str_fparam(&realm, msg, (fparam_t*)p1) < 0) {
-		ERR("Cannot obtain digest realm from parameter '%s'\n", ((fparam_t*)p1)->orig);
+		LM_ERR("Cannot obtain digest realm from parameter '%s'\n",
+				((fparam_t*)p1)->orig);
 		return -1;
 	}
 
-	return authenticate(msg, &realm, (authdb_table_info_t*)p2, HDR_AUTHORIZATION_T);
+	return authenticate(msg, &realm, (authdb_table_info_t*)p2,
+			HDR_AUTHORIZATION_T);
 }
diff --git a/src/modules/uid_auth_db/authorize.h b/src/modules/uid_auth_db/authorize.h
index d0f2a07..dbda474 100644
--- a/src/modules/uid_auth_db/authorize.h
+++ b/src/modules/uid_auth_db/authorize.h
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Digest Authentication - Database support
  *
  * Copyright (C) 2001-2003 FhG Fokus
@@ -22,8 +20,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
diff --git a/src/modules/uid_auth_db/uid_auth_db_mod.c b/src/modules/uid_auth_db/uid_auth_db_mod.c
index 56ee952..d67e408 100644
--- a/src/modules/uid_auth_db/uid_auth_db_mod.c
+++ b/src/modules/uid_auth_db/uid_auth_db_mod.c
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Digest Authentication Module
  *
  * Copyright (C) 2001-2003 FhG Fokus
@@ -26,14 +24,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2003-02-26: checks and group moved to separate modules (janakj)
- * 2003-03-11: New module interface (janakj)
- * 2003-03-16: flags export parameter added (janakj)
- * 2003-03-19  all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei)
- * 2003-04-05: default_uri #define used (jiri)
- * 2004-06-06  cleanup: static & auth_db_{init,bind,close.ver} used (andrei)
  */
 
 #include <stdio.h>
@@ -113,11 +103,11 @@ int credentials_n;         /* Number of credentials in the list */
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-    {"www_authenticate",   www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
-    {"www_authorize",      www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
-    {"proxy_authenticate", proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
-    {"proxy_authorize",    proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
-    {0, 0, 0, 0, 0}
+	{"www_authenticate",   www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
+	{"www_authorize",      www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
+	{"proxy_authenticate", proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
+	{"proxy_authorize",    proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
+	{0, 0, 0, 0, 0}
 };
 
 
@@ -125,19 +115,19 @@ static cmd_export_t cmds[] = {
  * Exported parameters
  */
 static param_export_t params[] = {
-    {"db_url",            PARAM_STRING, &db_url          },
-    {"username_column",   PARAM_STR,    &username_column },
-    {"did_column",        PARAM_STR,    &did_column      },
-    {"realm_column",      PARAM_STR,    &realm_column    },
-    {"password_column",   PARAM_STR,    &pass_column     },
-    {"password_column_2", PARAM_STR,    &pass_column_2   },
-    {"plain_password_column",   PARAM_STR,    &plain_password_column },
-    {"flags_column",      PARAM_STR,    &flags_column    },
-    {"calculate_ha1",     PARAM_INT,    &calc_ha1        },
-    {"load_credentials",  PARAM_STR,    &credentials_list},
-    {"use_did",           PARAM_INT,    &use_did         },
-    {"check_all_ha1",     PARAM_INT,    &check_all       },
-    {0, 0, 0}
+	{"db_url",            PARAM_STRING, &db_url          },
+	{"username_column",   PARAM_STR,    &username_column },
+	{"did_column",        PARAM_STR,    &did_column      },
+	{"realm_column",      PARAM_STR,    &realm_column    },
+	{"password_column",   PARAM_STR,    &pass_column     },
+	{"password_column_2", PARAM_STR,    &pass_column_2   },
+	{"plain_password_column",   PARAM_STR,    &plain_password_column },
+	{"flags_column",      PARAM_STR,    &flags_column    },
+	{"calculate_ha1",     PARAM_INT,    &calc_ha1        },
+	{"load_credentials",  PARAM_STR,    &credentials_list},
+	{"use_did",           PARAM_INT,    &use_did         },
+	{"check_all_ha1",     PARAM_INT,    &check_all       },
+	{0, 0, 0}
 };
 
 
@@ -145,15 +135,15 @@ static param_export_t params[] = {
  * Module interface
  */
 struct module_exports exports = {
-    "uid_auth_db",
-    cmds,       /* Exported functions */
-    0,          /* RPC methods */
-    params,     /* Exported parameters */
-    mod_init,   /* module initialization function */
-    0,          /* response function */
-    destroy,    /* destroy function */
-    0,          /* oncancel function */
-    child_init  /* child initialization function */
+	"uid_auth_db",
+	cmds,       /* Exported functions */
+	0,          /* RPC methods */
+	params,     /* Exported parameters */
+	mod_init,   /* module initialization function */
+	0,          /* response function */
+	destroy,    /* destroy function */
+	0,          /* oncancel function */
+	child_init  /* child initialization function */
 };
 
 static authdb_table_info_t *registered_tables = NULL;
@@ -161,14 +151,14 @@ static authdb_table_info_t *registered_tables = NULL;
 static int generate_queries(authdb_table_info_t *info)
 {
 	db_fld_t match_with_did[] = {
-		{ .name = username_column.s, .type = DB_STR }, 
-		{ .name = realm_column.s, .type = DB_STR }, 
-		{ .name = did_column.s, .type = DB_STR }, 
+		{ .name = username_column.s, .type = DB_STR },
+		{ .name = realm_column.s, .type = DB_STR },
+		{ .name = did_column.s, .type = DB_STR },
 		{ .name = NULL }
 	};
 	db_fld_t match_without_did[] = {
-		{ .name = username_column.s, .type = DB_STR }, 
-		{ .name = realm_column.s, .type = DB_STR }, 
+		{ .name = username_column.s, .type = DB_STR },
+		{ .name = realm_column.s, .type = DB_STR },
 		{ .name = NULL }
 	};
 	db_fld_t *result_cols = NULL;
@@ -184,7 +174,7 @@ static int generate_queries(authdb_table_info_t *info)
 
 	result_cols[0].name = pass_column.s;
 	result_cols[0].type = DB_CSTR;
-	
+
 	result_cols[1].name = flags_column.s;
 	result_cols[1].type = DB_INT;
 	for (i = 0; i < credentials_n; i++) {
@@ -194,23 +184,23 @@ static int generate_queries(authdb_table_info_t *info)
 	result_cols[2 + i].name = NULL;
 
 	if (use_did) {
-		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_with_did, NULL);
 		result_cols[0].name = pass_column_2.s;
-		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_with_did, NULL);
 		result_cols[0].name = plain_password_column.s;
-		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_with_did, NULL);
 	}
 	else {
-		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_without_did, NULL);
 		result_cols[0].name = pass_column_2.s;
-		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_without_did, NULL);
 		result_cols[0].name = plain_password_column.s;
-		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s, 
+		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s,
 				result_cols, match_without_did, NULL);
 	}
 
@@ -235,12 +225,12 @@ static int child_init(int rank)
 	i = registered_tables;
 	while (i) {
 		if (generate_queries(i) < 0) {
-			ERR("can't prepare queries\n");
+			LM_ERR("can't prepare queries\n");
 			return -1;
 		}
 		i = i->next;
 	}
-    
+
 	return 0;
 
 err:
@@ -250,56 +240,56 @@ err:
 		db_ctx_free(auth_db_handle);
 	}
 
-	ERR("Error while initializing database layer\n");
+	LM_ERR("Error while initializing database layer\n");
 	return -1;
 }
 
 
 static int mod_init(void)
 {
-    bind_auth_s_t bind_auth;
-    
-    DBG("auth_db module - initializing\n");
-    
-    bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
-    if (!bind_auth) {
-	LOG(L_ERR, "auth_db:mod_init: Unable to find bind_auth function\n");
-	return -1;
-    }
-    if (bind_auth(&auth_api) < 0) {
-	LOG(L_ERR, "auth_db:child_init: Unable to bind auth module\n");
-	return -3;
-    }
-    
-    if (aaa_avps_init(&credentials_list, &credentials, &credentials_n)) {
-	return -1;
-    }
-    
-    return 0;
+	bind_auth_s_t bind_auth;
+
+	LM_DBG("auth_db module - initializing\n");
+
+	bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
+	if (!bind_auth) {
+		LM_ERR("Unable to find bind_auth function\n");
+		return -1;
+	}
+	if (bind_auth(&auth_api) < 0) {
+		LM_ERR("Unable to bind auth module\n");
+		return -3;
+	}
+
+	if (aaa_avps_init(&credentials_list, &credentials, &credentials_n)) {
+		return -1;
+	}
+
+	return 0;
 }
 
 
 static void destroy(void)
 {
-    if (auth_db_handle) {
+	if (auth_db_handle) {
 		db_ctx_free(auth_db_handle);
 		auth_db_handle = NULL;
-    }
+	}
 }
 
 static int str_case_equals(const str *a, const str *b)
 {
 	/* ugly hack: taken from libcds */
 	int i;
-	
+
 	if (!a) {
 		if (!b) return 0;
 		else return (b->len == 0) ? 0 : 1;
 	}
 	if (!b) return (a->len == 0) ? 0 : 1;
 	if (a->len != b->len) return 1;
-	
-	for (i = 0; i < a->len; i++) 
+
+	for (i = 0; i < a->len; i++)
 		if (a->s[i] != b->s[i]) return 1;
 	return 0;
 }
@@ -307,9 +297,9 @@ static int str_case_equals(const str *a, const str *b)
 static authdb_table_info_t *find_table_info(str *table)
 {
 	authdb_table_info_t *i = registered_tables;
-	
+
 	/* sequential search is OK because it is called only in child init */
-	while (i) { 
+	while (i) {
 		if (str_case_equals(&i->table, table) == 0) return i;
 		i = i->next;
 	}
@@ -323,9 +313,10 @@ static authdb_table_info_t *register_table(str *table)
 	info = find_table_info(table);
 	if (info) return info; /* queries for this table already exist */
 
-	info = (authdb_table_info_t*)pkg_malloc(sizeof(authdb_table_info_t) + table->len + 1);
+	info = (authdb_table_info_t*)pkg_malloc(sizeof(authdb_table_info_t)
+			+ table->len + 1);
 	if (!info) {
-		ERR("can't allocate pkg mem\n");
+		LM_ERR("can't allocate pkg mem\n");
 		return NULL;
 	}
 
@@ -359,11 +350,12 @@ static int authdb_fixup(void** param, int param_no)
 				return -1;
 			}
 		} else {
-			ERR("Non-string value of table with credentials is not allowed.\n");
+			LM_ERR("Non-string value of table with credentials"
+					" is not allowed.\n");
 			/* TODO: allow this too */
 			return -1;
 		}
 	}
 
-    return 0;
+	return 0;
 }
diff --git a/src/modules/uid_auth_db/uid_auth_db_mod.h b/src/modules/uid_auth_db/uid_auth_db_mod.h
index 25ae11e..00dc138 100644
--- a/src/modules/uid_auth_db/uid_auth_db_mod.h
+++ b/src/modules/uid_auth_db/uid_auth_db_mod.h
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Digest Authentication - Database support
  *
  * Copyright (C) 2001-2003 FhG Fokus
@@ -22,8 +20,8 @@
  * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -45,8 +43,8 @@ extern str did_column;      /* 'did' column name */
 extern str realm_column;    /* 'realm' column name */
 extern str pass_column;     /* 'password' column name */
 extern str pass_column_2;   /* Column containing HA1 string constructed
-			     * of user at domain username
-			     */
+							 * of user at domain username
+							 */
 extern str flags_column;    /* Flags column in credentials table */
 
 extern int calc_ha1;          /* if set to 1, ha1 is calculated by the server */
diff --git a/src/modules/uid_gflags/uid_gflags.c b/src/modules/uid_gflags/uid_gflags.c
index c3c1e1c..af02697 100644
--- a/src/modules/uid_gflags/uid_gflags.c
+++ b/src/modules/uid_gflags/uid_gflags.c
@@ -1,5 +1,4 @@
-/*
- *
+/**
  * gflags module: global flags; it keeps a bitmap of flags
  * in shared memory and may be used to change behaviour
  * of server based on value of the flags. E.g.,
@@ -131,22 +130,22 @@ static int init_db(void)
 
 	db = db_ctx("gflags");
 	if (db == NULL) {
-		ERR("Error while initializing database layer\n");
+		LM_ERR("failure while initializing database layer\n");
 		return -1;
 	}
 	if (db_add_db(db, db_url) < 0) return -1;
 	if (db_connect(db) < 0) return -1;
-	
+
 	/* SELECT name, type, value, flags FROM global_attrs */
 	load_attrs_cmd = db_cmd(DB_GET, db, attr_table, attr_res, NULL, NULL);
 	if (load_attrs_cmd == NULL) {
-		ERR("Error while building db query to load global attributes\n");
+		LM_ERR("failure while building db query to load global attributes\n");
 		return -1;
 	}
 
 	save_gflags_cmd = db_cmd(DB_PUT, db, attr_table, NULL, NULL, values);
 	if (save_gflags_cmd == NULL) {
-		ERR("Error while building db query to save global flags\n");
+		LM_ERR("failure while building db query to save global flags\n");
 		return -1;
 	}
 
@@ -159,11 +158,11 @@ static int set_gflag(struct sip_msg *bar, char *flag_par, char *foo)
 	unsigned long int flag;
 
 	if (!flag_par || ((fparam_t*)flag_par)->type != FPARAM_INT) {
-	  LOG(L_ERR, "gflags:set_gflag: Invalid parameter\n");
-	  return -1;
+		LM_ERR("invalid parameter\n");
+		return -1;
 	}
-	
-	flag=((fparam_t*)flag_par)->v.i; 
+
+	flag=((fparam_t*)flag_par)->v.i;
 
 	(*gflags) |= 1 << flag;
 	return 1;
@@ -174,11 +173,11 @@ static int reset_gflag(struct sip_msg *bar, char *flag_par, char *foo)
 	unsigned long int flag;
 
 	if (!flag_par || ((fparam_t*)flag_par)->type != FPARAM_INT) {
-	  LOG(L_ERR, "gflags:reset_gflag: Invalid parameter\n");
-	  return -1;
+		LM_ERR("invalid parameter\n");
+		return -1;
 	}
-	
-	flag=((fparam_t*)flag_par)->v.i; 
+
+	flag=((fparam_t*)flag_par)->v.i;
 	(*gflags) &= ~ (1 << flag);
 	return 1;
 }
@@ -188,11 +187,11 @@ static int is_gflag(struct sip_msg *bar, char *flag_par, char *foo)
 	unsigned long int flag;
 
 	if (!flag_par || ((fparam_t*)flag_par)->type != FPARAM_INT) {
-	  LOG(L_ERR, "gflags:is_gflag: Invalid parameter\n");
-	  return -1;
+		LM_ERR("invalid parameter\n");
+		return -1;
 	}
-	
-	flag=((fparam_t*)flag_par)->v.i; 
+
+	flag=((fparam_t*)flag_par)->v.i;
 	return ( (*gflags) & (1<<flag)) ? 1 : -1;
 }
 
@@ -216,7 +215,7 @@ static int load_attrs(avp_list_t* global_avps)
 		if (rec->fld[0].flags & DB_NULL ||
 			rec->fld[1].flags & DB_NULL ||
 			rec->fld[3].flags & DB_NULL) {
-			LOG(L_ERR, "gflags:load_attrs: Skipping row containing NULL entries\n");
+			LM_ERR("skipping row containing NULL entries\n");
 			goto skip;
 		}
 
@@ -224,7 +223,7 @@ static int load_attrs(avp_list_t* global_avps)
 
 		name.s = rec->fld[0].v.lstr;
 
-		     /* Test for NULL value */
+		/* Test for NULL value */
 		if (rec->fld[2].flags & DB_NULL) {
 			avp_val.s = 0;
 			avp_val.len = 0;
@@ -241,15 +240,16 @@ static int load_attrs(avp_list_t* global_avps)
 			/* Integer AVP */
 			str2int(&avp_val, (unsigned*)&v.n);
 			if (rec->fld[0].v.lstr.len == (sizeof(AVP_GFLAGS) - 1) &&
-				!strncmp(rec->fld[0].v.lstr.s, AVP_GFLAGS, sizeof(AVP_GFLAGS) - 1)) {
+					!strncmp(rec->fld[0].v.lstr.s, AVP_GFLAGS,
+						sizeof(AVP_GFLAGS) - 1)) {
 				/* Restore gflags */
 				*gflags = v.n;
 			}
 		}
-		
+
 		if (add_avp_list(global_avps, flags, name, v) < 0) {
-			LOG(L_ERR, "gflags:load_attrs: Error while adding global attribute %.*s, skipping\n",
-			    rec->fld[0].v.lstr.len, ZSW(rec->fld[0].v.lstr.s));
+			LM_ERR("failed adding global attribute %.*s, skipping\n",
+					rec->fld[0].v.lstr.len, ZSW(rec->fld[0].v.lstr.s));
 			goto skip;
 		}
 
@@ -266,20 +266,20 @@ static int mod_init(void)
 {
 	gflags=(unsigned int *) shm_malloc(sizeof(unsigned int));
 	if (!gflags) {
-		LOG(L_ERR, "Error: gflags/mod_init: no shmem\n");
+		LM_ERR("no shared memory\n");
 		return -1;
 	}
 	*gflags=initial;
 
 	avps_1 = shm_malloc(sizeof(*avps_1));
 	if (!avps_1) {
-		ERR("can't allocate memory\n");
+		LM_ERR("can't allocate memory\n");
 		return -1;
 	}
 	*avps_1 = NULL;
 	avps_2 = shm_malloc(sizeof(*avps_2));
 	if (!avps_2) {
-		ERR("can't allocate memory\n");
+		LM_ERR("can't allocate memory\n");
 		return -1;
 	}
 	*avps_2 = NULL;
@@ -290,16 +290,16 @@ static int mod_init(void)
 			shm_free(gflags);
 			return -1;
 		}
-		
+
 		if (load_attrs(*active_global_avps) < 0) {
 			db_cmd_free(load_attrs_cmd);
 			db_cmd_free(save_gflags_cmd);
 			db_ctx_free(db);
 			return -1;
 		}
-		
+
 		set_avp_list(AVP_CLASS_GLOBAL, *active_global_avps);
-		
+
 		db_cmd_free(load_attrs_cmd);
 		db_cmd_free(save_gflags_cmd);
 		db_ctx_free(db);
@@ -345,7 +345,7 @@ int save_gflags(unsigned int flags)
 	str fl;
 
 	if (!load_global_attrs) {
-		LOG(L_ERR, "gflags:save_gflags: You must enable load_global_attrs to make flush_gflag work\n");
+		LM_ERR("enable load_global_attrs to make flush_gflag work\n");
 		return -1;
 	}
 
@@ -357,40 +357,39 @@ int save_gflags(unsigned int flags)
 	save_gflags_cmd->vals[3].v.bitmap = SRDB_LOAD_SER;
 
 	if (db_exec(NULL, save_gflags_cmd) < 0) {
-		LOG(L_ERR, "gflags:save_gflag: Unable to store new value\n");
+		LM_ERR("unable to store new value\n");
 		return -1;
 	}
 
-	DBG("gflags:save_gflags: Successfuly stored in database\n");
+	LM_DBG("successfuly stored in database\n");
 	return 0;
 }
 
 static int reload_global_attributes(void)
 {
 	avp_list_t**  new_global_avps;
-  
-  /* Choose new global AVP list and free its old contents */
-  if (active_global_avps == &avps_1) {
-  	destroy_avp_list(avps_2);
+
+	/* Choose new global AVP list and free its old contents */
+	if (active_global_avps == &avps_1) {
+		destroy_avp_list(avps_2);
 		new_global_avps = &avps_2;
-	} 
-	else {
+	} else {
 		destroy_avp_list(avps_1);
 		new_global_avps = &avps_1;
 	}
-    
-  if (load_attrs(*new_global_avps) < 0) {
-  	goto error;
-  }
-  
-  active_global_avps = new_global_avps;
-  set_avp_list(AVP_CLASS_GLOBAL, *active_global_avps);
-
-  return 0;
-    
+
+	if (load_attrs(*new_global_avps) < 0) {
+		goto error;
+	}
+
+	active_global_avps = new_global_avps;
+	set_avp_list(AVP_CLASS_GLOBAL, *active_global_avps);
+
+	return 0;
+
 error:
 	destroy_avp_list(*new_global_avps);
-  return -1;
+	return -1;
 }
 
 /*
@@ -404,13 +403,13 @@ static int flush_gflags(struct sip_msg* msg, char* s1, char* s2)
 
 
 static const char* rpc_set_doc[] = {
-	"Load a CPL script to the server.", /* Documentation string */
-	0                                   /* Method signature(s) */
+	"Set gflag.", /* Documentation string */
+	0           /* Method signature(s) */
 };
 
 static void rpc_set(rpc_t* rpc, void* c)
 {
-        int flag;
+	int flag;
 
 	if (rpc->scan(c, "d", &flag) < 1) {
 		rpc->fault(c, 400, "Flag number expected");
@@ -424,13 +423,13 @@ static void rpc_set(rpc_t* rpc, void* c)
 
 
 static const char* rpc_is_set_doc[] = {
-	"Load a CPL script to the server.", /* Documentation string */
-	0                                   /* Method signature(s) */
+	"Test if gflag is set.", /* Documentation string */
+	0                      /* Method signature(s) */
 };
 
 static void rpc_is_set(rpc_t* rpc, void* c)
 {
-        int flag;
+	int flag;
 
 	if (rpc->scan(c, "d", &flag) < 1) {
 		rpc->fault(c, 400, "Flag number expected");
@@ -444,13 +443,13 @@ static void rpc_is_set(rpc_t* rpc, void* c)
 
 
 static const char* rpc_reset_doc[] = {
-	"Load a CPL script to the server.", /* Documentation string */
-	0                                   /* Method signature(s) */
+	"Reset gflags.", /* Documentation string */
+	0               /* Method signature(s) */
 };
 
 static void rpc_reset(rpc_t* rpc, void* c)
 {
-        int flag;
+	int flag;
 
 	if (rpc->scan(c, "d", &flag) < 1) {
 		rpc->fault(c, 400, "Flag number expected");
@@ -464,8 +463,8 @@ static void rpc_reset(rpc_t* rpc, void* c)
 
 
 static const char* rpc_flush_doc[] = {
-	"Load a CPL script to the server.", /* Documentation string */
-	0                                   /* Method signature(s) */
+	"Flush gflags.", /* Documentation string */
+	0               /* Method signature(s) */
 };
 
 static void rpc_flush(rpc_t* rpc, void* c)
@@ -477,13 +476,13 @@ static void rpc_flush(rpc_t* rpc, void* c)
 
 
 static const char* rpc_dump_doc[] = {
-	"Load a CPL script to the server.", /* Documentation string */
-	0                                   /* Method signature(s) */
+	"Dump gflags", /* Documentation string */
+	0               /* Method signature(s) */
 };
 
 static void rpc_dump(rpc_t* rpc, void* c)
 {
-        int i;
+	int i;
 	for(i = 0; i < 32; i++) {
 		rpc->add(c, "b", (*gflags >> i) & 1);
 	}
@@ -500,12 +499,12 @@ static const char* rpc_reload_doc[2] = {
 static void rpc_reload(rpc_t* rpc, void* ctx)
 {
 	if (reload_global_attributes() < 0) {
-		LOG(L_ERR, "ERROR: Reloading of global_attrs table has failed\n");
+		LM_ERR("failed reloading of global_attrs table has failed\n");
 		rpc->fault(ctx, 400, "Reloading of global attributes failed");
 	}
 	else {
 		/* reload is successful */
-		LOG(L_INFO, "INFO: global_attrs table reloaded\n");
+		LM_INFO("global_attrs table reloaded\n");
 	}
 }
 
diff --git a/src/modules/uid_uri_db/checks.c b/src/modules/uid_uri_db/checks.c
index 2440d93..2112645 100644
--- a/src/modules/uid_uri_db/checks.c
+++ b/src/modules/uid_uri_db/checks.c
@@ -1,37 +1,28 @@
 /*
- * $Id$
- *
  * Various URI checks
  *
  * Copyright (C) 2001-2004 FhG FOKUS
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of Kamailio, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
+ * 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
  *
- * For a license to use the ser software under conditions
+ * For a license to use the Kamailio software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info at iptel.org
  *
- * ser is distributed in the hope that it will be useful,
+ * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2003-02-26: Created by janakj
- * 2004-03-20: has_totag introduced (jiri)
- * 2004-06-07  updated to the new DB api, added uridb_db_{bind,init,close,ver}
- *              (andrei)
  */
 
-
diff --git a/src/modules/uid_uri_db/checks.h b/src/modules/uid_uri_db/checks.h
index f89a74a..143efd9 100644
--- a/src/modules/uid_uri_db/checks.h
+++ b/src/modules/uid_uri_db/checks.h
@@ -1,34 +1,29 @@
 /*
- * $Id$
- *
  * Various URI checks
  *
  * Copyright (C) 2001-2004 FhG FOKUS
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of Kamailio, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
+ * 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
  *
- * For a license to use the ser software under conditions
+ * For a license to use the Kamailio software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info at iptel.org
  *
- * ser is distributed in the hope that it will be useful,
+ * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2003-03-26 created by janakj
  */
 
 
diff --git a/src/modules/uid_uri_db/uid_uri_db_mod.c b/src/modules/uid_uri_db/uid_uri_db_mod.c
index dba6454..e3887fb 100644
--- a/src/modules/uid_uri_db/uid_uri_db_mod.c
+++ b/src/modules/uid_uri_db/uid_uri_db_mod.c
@@ -1,23 +1,21 @@
 /*
- * $Id$
- *
  * Various URI related functions
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of Kamailio, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
+ * 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
  *
- * For a license to use the ser software under conditions
+ * For a license to use the Kamailio software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info at iptel.org
  *
- * ser is distributed in the hope that it will be useful,
+ * 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.
@@ -26,14 +24,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * -------
- *  2003-03-11: New module interface (janakj)
- *  2003-03-16: flags export parameter added (janakj)
- *  2003-03-19  replaces all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
- *  2003-04-05: default_uri #define used (jiri)
- *  2004-03-20: has_totag introduced (jiri)
- *  2004-06-07  updated to the new DB api (andrei)
  */
 
 
@@ -110,9 +100,12 @@ str default_did	= STR_STATIC_INIT("_default");
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"lookup_user", lookup_user,   1, header_fixup,      REQUEST_ROUTE | FAILURE_ROUTE},
-	{"lookup_user", lookup_user_2, 2, lookup_user_fixup, REQUEST_ROUTE | FAILURE_ROUTE},
-	{"check_uri",   check_uri,     1, header_fixup,      REQUEST_ROUTE | FAILURE_ROUTE},
+	{"lookup_user", lookup_user,   1, header_fixup,
+		REQUEST_ROUTE | FAILURE_ROUTE},
+	{"lookup_user", lookup_user_2, 2, lookup_user_fixup,
+		REQUEST_ROUTE | FAILURE_ROUTE},
+	{"check_uri",   check_uri,     1, header_fixup,
+		REQUEST_ROUTE | FAILURE_ROUTE},
 	{0, 0, 0, 0, 0}
 };
 
@@ -171,15 +164,16 @@ static int child_init(int rank)
 
 	db = db_ctx("uri_db");
 	if (db == NULL) {
-		ERR("Error while initializing database layer\n");
+		LM_ERR("failure initializing database layer\n");
 		return -1;
 	}
 	if (db_add_db(db, db_url.s) < 0) goto error;
 	if (db_connect(db) < 0) goto error;
-	
-	lookup_uid_cmd = db_cmd(DB_GET, db, uri_table.s, lookup_uid_columns, lookup_uid_match, NULL);
+
+	lookup_uid_cmd = db_cmd(DB_GET, db, uri_table.s, lookup_uid_columns,
+			lookup_uid_match, NULL);
 	if (lookup_uid_cmd == NULL) {
-		ERR("Error while building db query to load global attributes\n");
+		LM_ERR("failure building db query to load global attributes\n");
 		goto error;
 	}
 	return 0;
@@ -221,16 +215,16 @@ static int lookup_uid(struct sip_msg* msg, long id, int store)
 		flag = SRDB_IS_FROM;
 
 		if (parse_from_header(msg) < 0) {
-			LOG(L_ERR, "uri_db:lookup_uid: Error while parsing From header\n");
+			LM_ERR("error while parsing From header\n");
 			return -1;
 		}
 		from = get_from(msg);
 		if (!from) {
-			LOG(L_ERR, "uri_db:lookup_uid: Unable to get From username\n");
+			LM_ERR("unable to get From username\n");
 			return -1;
 		}
 		if (parse_uri(from->uri.s, from->uri.len, &puri) < 0) {
-			LOG(L_ERR, "uri_db:lookup_uid: Error while parsing From URI\n");
+			LM_ERR("error while parsing From URI\n");
 			return -1;
 		}
 		lookup_uid_cmd->match[0].v.lstr = puri.user;
@@ -239,17 +233,17 @@ static int lookup_uid(struct sip_msg* msg, long id, int store)
 		get_to_did(&did, msg);
 		if (!msg->to) {
 			if (parse_headers(msg, HDR_TO_F, 0)==-1 || !msg->to) {
-				ERR("unable to parse To header\n");
+				LM_ERR("unable to parse To header\n");
 				return -1;
 			}
 		}
 		to = get_to(msg);
 		if (!to) {
-			LOG(L_ERR, "uri_db:lookup_uid: Unable to get To body\n");
+			LM_ERR("unable to get To body\n");
 			return -1;
 		}
 		if (parse_uri(to->uri.s, to->uri.len, &puri) < 0) {
-			LOG(L_ERR, "uri_db:lookup_uid: Error while parsing To URI\n");
+			LM_ERR("error while parsing To URI\n");
 			return -1;
 		}
 		lookup_uid_cmd->match[0].v.lstr = puri.user;
@@ -267,35 +261,38 @@ static int lookup_uid(struct sip_msg* msg, long id, int store)
 	if (did.s && did.len) {
 		lookup_uid_cmd->match[1].v.lstr = did;
 	} else {
-		LOG(L_DBG, "uri_db:lookup_uid: DID not found, using default value\n");
+		LM_DBG("DID not found, using default value\n");
 		lookup_uid_cmd->match[1].v.lstr = default_did;
 	}
 
 	if (db_exec(&res, lookup_uid_cmd) < 0) {
-		LOG(L_ERR, "uri_db:lookup_uid: Error while executing database query\n");
+		LM_ERR("error while executing database query\n");
 		return -1;
 	}
 
 	rec = db_first(res);
 	while(rec) {
 		if (rec->fld[0].flags & DB_NULL ||
-			rec->fld[1].flags & DB_NULL) {
-			LOG(L_ERR, "uri_db:lookup_uid: Bogus line in %s table\n", uri_table.s);
+				rec->fld[1].flags & DB_NULL) {
+			LM_ERR("bogus line in %s table\n", uri_table.s);
 			goto skip;
 		}
 
-		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip; /* Skip disabled entries */
-		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip; /* Not for SER */
-		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;        /* Not allowed in the header we are interested in */
+		/* Skip disabled entries */
+		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip;
+		/* Not for SER */
+		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip;
+		/* Not allowed in the header we are interested in */
+		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;
 		goto found;
 
-	skip:
+skip:
 		rec = db_next(res);
 	}
 	ret = -1; /* Not found -> not allowed */
 	goto freeres;
 
- found:
+found:
 	if (store) {
 		uid = rec->fld[0].v.lstr;
 		if (id == USE_FROM) {
@@ -303,18 +300,19 @@ static int lookup_uid(struct sip_msg* msg, long id, int store)
 		} else {
 			set_to_uid(&uid);
 			if (id == USE_RURI) {
-				     /* store as str|int avp if alias is canonical or not (1,0) */
+				/* store as str|int avp if alias is canonical or not (1,0) */
 				if ((rec->fld[1].v.int4 & SRDB_CANON) != 0) {
 					avp_name.s = canonical_avp;
 					avp_val.s = canonical_avp_val;
-					add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, avp_name, avp_val);
+					add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR
+							| AVP_VAL_STR, avp_name, avp_val);
 				}
 			}
 		}
 	}
 	ret = 1;
 
- freeres:
+freeres:
 	db_res_free(res);
 	return ret;
 }
@@ -335,98 +333,102 @@ static int lookup_user(struct sip_msg* msg, char* s1, char* s2)
 
 static int lookup_user_2(struct sip_msg* msg, char* attr, char* select)
 {
-    db_res_t* res;
+	db_res_t* res;
 	db_rec_t* rec;
-    str uri, did, uid;
-    struct sip_uri puri;
-    avp_ident_t* avp;
-    int_str avp_val;
-    int flag, ret;
+	str uri, did, uid;
+	struct sip_uri puri;
+	avp_ident_t* avp;
+	int_str avp_val;
+	int flag, ret;
 
-    avp = &((fparam_t*)attr)->v.avp;
+	avp = &((fparam_t*)attr)->v.avp;
 
-    if (!avp) {
-		ERR("lookup_user: Invalid parameter 1, attribute name expected\n");
+	if (!avp) {
+		LM_ERR("invalid parameter 1, attribute name expected\n");
 		return -1;
-    }
+	}
 
-    if (avp->flags & AVP_TRACK_TO) {
+	if (avp->flags & AVP_TRACK_TO) {
 		flag = SRDB_IS_TO;
-    } else {
+	} else {
 		flag = SRDB_IS_FROM;
-    }
+	}
 
-    if (get_str_fparam(&uri, msg, (fparam_t*)select) != 0) {
-		ERR("lookup_user: Unable to get SIP URI from %s\n", ((fparam_t*)select)->orig);
+	if (get_str_fparam(&uri, msg, (fparam_t*)select) != 0) {
+		LM_ERR("unable to get SIP URI from %s\n", ((fparam_t*)select)->orig);
 		return -1;
-    }
+	}
 
-    if (parse_uri(uri.s, uri.len, &puri) < 0) {
-		ERR("Error while parsing URI '%.*s'\n", uri.len, ZSW(uri.s));
+	if (parse_uri(uri.s, uri.len, &puri) < 0) {
+		LM_ERR("error while parsing URI '%.*s'\n", uri.len, ZSW(uri.s));
 		return -1;
-    }
+	}
 
-    if (puri.host.len) {
+	if (puri.host.len) {
 		/* domain name is present */
 		if (dm_get_did(&did, &puri.host) < 0) {
-			DBG("Cannot lookup DID for domain '%.*s', using default value\n", puri.host.len, ZSW(puri.host.s));
+			LM_DBG("cannot lookup DID for domain '%.*s', using default value\n",
+					puri.host.len, ZSW(puri.host.s));
 			did = default_did;
 		}
-    } else {
+	} else {
 		/* domain name is missing -- can be caused by Tel: URI */
-		DBG("There is no domain name, using default value\n");
+		LM_DBG("there is no domain name, using default value\n");
 		did = default_did;
-    }
+	}
 
-    /* don't lookup users with empty username -- wasted DB time */
-    if (puri.user.len==0) {
-    	return -1;
-    }
+	/* don't lookup users with empty username -- wasted DB time */
+	if (puri.user.len==0) {
+		return -1;
+	}
 
 	lookup_uid_cmd->match[0].v.lstr = puri.user;
-    lookup_uid_cmd->match[1].v.lstr = did;
-    uri_type_to_str(puri.type, &(lookup_uid_cmd->match[2].v.lstr));
+	lookup_uid_cmd->match[1].v.lstr = did;
+	uri_type_to_str(puri.type, &(lookup_uid_cmd->match[2].v.lstr));
 
-    if (db_exec(&res, lookup_uid_cmd) < 0) {
-		LOG(L_ERR, "lookup_user: Error in db_query\n");
+	if (db_exec(&res, lookup_uid_cmd) < 0) {
+		LM_ERR("error in db_query\n");
 		return -1;
-    }
+	}
 
 	rec = db_first(res);
 	while(rec) {
 		if (rec->fld[0].flags & DB_NULL ||
-			rec->fld[1].flags & DB_NULL) {
-			LOG(L_ERR, "lookup_user: Bogus line in %s table\n", uri_table.s);
+				rec->fld[1].flags & DB_NULL) {
+			LM_ERR("bogus line in %s table\n", uri_table.s);
 			goto skip;
 		}
-		
-		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip; /* Skip disabled entries */
-		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip; /* Not for SER */
-		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;        /* Not allowed in the header we are interested in */
+
+		/* Skip disabled entries */
+		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip;
+		/* Not for SER */
+		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip;
+		/* Not allowed in the header we are interested in */
+		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;
 		goto found;
 
-	skip:
+skip:
 		rec = db_next(res);
-    }
+	}
 
-    DBG("lookup_user: UID not found for '%.*s'\n", uri.len, ZSW(uri.s));
-    ret = -1;
-    goto freeres;
+	LM_DBG("UID not found for '%.*s'\n", uri.len, ZSW(uri.s));
+	ret = -1;
+	goto freeres;
 
- found:
+found:
 	uid = rec->fld[0].v.lstr;
-    avp_val.s = uid;
+	avp_val.s = uid;
 
-    if (add_avp(avp->flags | AVP_VAL_STR, avp->name, avp_val) < 0) {
-		ERR("lookup_user: Error while creating attribute\n");
+	if (add_avp(avp->flags | AVP_VAL_STR, avp->name, avp_val) < 0) {
+		LM_ERR("error while creating attribute\n");
 		ret = -1;
-    } else {
+	} else {
 		ret = 1;
-    }
+	}
 
- freeres:
-    db_res_free(res);
-    return ret;
+freeres:
+	db_res_free(res);
+	return ret;
 }
 
 
@@ -443,7 +445,7 @@ static int header_fixup(void** param, int param_no)
 		} else if (!strcasecmp(*param, "To")) {
 			id = USE_TO;
 		} else {
-			LOG(L_ERR, "uri_db:header_fixup Unknown parameter\n");
+			LM_ERR("unknown parameter: %d\n", param_no);
 			return -1;
 		}
 	}
@@ -456,18 +458,18 @@ static int header_fixup(void** param, int param_no)
 
 static int lookup_user_fixup(void** param, int param_no)
 {
-    if (param_no == 1) {
+	if (param_no == 1) {
 		if (fix_param(FPARAM_AVP, param) != 0) {
-			ERR("lookup_user: Invalid parameter 1, attribute expected\n");
+			LM_ERR("invalid parameter 1, attribute expected\n");
 			return -1;
 		}
 		dm_get_did = (domain_get_did_t)find_export("get_did", 0, 0);
 		if (!dm_get_did) {
-			ERR("lookup_user: Could not find domain module\n");
+			LM_ERR("could not find domain module\n");
 			return -1;
 		}
 		return 0;
-    } else {
+	} else {
 		return fixup_var_str_12(param, 2);
-    }
+	}
 }
diff --git a/src/modules/uid_uri_db/uid_uri_db_mod.h b/src/modules/uid_uri_db/uid_uri_db_mod.h
index e612082..e4848ec 100644
--- a/src/modules/uid_uri_db/uid_uri_db_mod.h
+++ b/src/modules/uid_uri_db/uid_uri_db_mod.h
@@ -1,34 +1,29 @@
 /*
- * $Id$
- *
  * Various URI related functions
  *
  * Copyright (C) 2001-2004 FhG FOKUS
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of Kamailio, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
+ * 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
  *
- * For a license to use the ser software under conditions
+ * For a license to use the Kamailio software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info at iptel.org
  *
- * ser is distributed in the hope that it will be useful,
+ * 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 
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * History:
- * --------
- * 2003-02-26: created by janakj
  */
 
 
diff --git a/src/modules/xmlrpc/xmlrpc.c b/src/modules/xmlrpc/xmlrpc.c
index e40f32b..7cce800 100644
--- a/src/modules/xmlrpc/xmlrpc.c
+++ b/src/modules/xmlrpc/xmlrpc.c
@@ -1525,7 +1525,13 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...)
 	f=(autoconvert?GET_X_AUTOCONV:0) |
 		(lflf2crlf?GET_X_LFLF2CRLF:0);
 	while(*fmt) {
-		if (!ctx->act_param) goto error;
+		if (!ctx->act_param) {
+			if(*fmt=='*') {
+				break;
+			} else {
+				goto error;
+			}
+		}
 		value = ctx->act_param->xmlChildrenNode;
 
 		switch(*fmt) {
diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 3aaecbd..569ddd8 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -1050,6 +1050,32 @@ db_ops() {
 			fi
 			$DBCMDCONNECT
 			;;
+		version)
+			shift
+			if [ $# -ne 3 ] ; then
+				merr "missing parameters"
+				exit 1
+			fi
+			case $1 in
+				add)
+					QUERY="INSERT INTO version (table_name, table_version) VALUES ('$2', $3);"
+					$DBCMD "$QUERY"
+				;;
+				set)
+					QUERY="DELETE FROM version WHERE table_name='$2';"
+					$DBCMD "$QUERY"
+					QUERY="INSERT INTO version (table_name, table_version) VALUES ('$2', $3);"
+					$DBCMD "$QUERY"
+				;;
+				update)
+					QUERY="UPDATE version SET table_version=$3 WHERE table_name='$2';"
+					$DBCMD "$QUERY"
+				;;
+				*)
+					usage_db_ops
+					exit 1
+			esac
+			;;
 		*)
 			usage_db_ops
 			exit 1
diff --git a/utils/kamctl/kamctl.sqlbase b/utils/kamctl/kamctl.sqlbase
index 2aef980..f821d2a 100644
--- a/utils/kamctl/kamctl.sqlbase
+++ b/utils/kamctl/kamctl.sqlbase
@@ -67,6 +67,9 @@ cat <<EOF
  db nmatch <table> <key> <value>...... display record from table that has
            ........................... column key equal to value as non-string
  db connect .......................... connect to db server via cli
+ db version add <table> <value> ...... add new value in version table
+ db version set <table> <value> ...... set value in version table
+ db version update <table> <value> ... update value in version table
 EOF
 }
 USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops"
@@ -79,7 +82,7 @@ usage_speeddial() {
 cat <<EOF
  speeddial show <speeddial-id> ....... show speeddial details
  speeddial list <sip-id> ............. list speeddial for uri
- speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ... 
+ speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ...
            ........................... add a speedial (*)
  speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*)
  speeddial help ...................... help message
diff --git a/utils/kamctl/kamdbctl.pgsql b/utils/kamctl/kamdbctl.pgsql
index 059b6fa..c41354f 100644
--- a/utils/kamctl/kamdbctl.pgsql
+++ b/utils/kamctl/kamdbctl.pgsql
@@ -241,9 +241,9 @@ done
 for TABLE in $EXTRA_TABLES; do
 	sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE $TABLE TO $DBRWUSER;"
 	sql_query "$1" "GRANT SELECT ON TABLE $TABLE TO $DBROUSER;"
-	if [ $TABLE != "route_tree" ] ; then
+	if [ $TABLE != "route_tree" ] && [ $TABLE != "dr_gateways" ] && [ $TABLE != "dr_rules" ] ; then
 		sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE "$TABLE"_id_seq TO $DBRWUSER;"
-	    sql_query "$1" "GRANT SELECT ON TABLE "$TABLE"_id_seq TO $DBROUSER;"
+		sql_query "$1" "GRANT SELECT ON TABLE "$TABLE"_id_seq TO $DBROUSER;"
 	fi
 	if [ $? -ne 0 ] ; then
 		merr "Grant privileges to extra tables failed!"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/kamailio.git



More information about the Pkg-voip-commits mailing list