<div dir="ltr">I have kamailio 4.0.2 installed with the websockets module, and when I try to connect from my test page (running sipml5) I get this error:<br><div class="gmail_quote"><div><br></div><div><div>root@phcdevel:/usr/local/src# 15(27061) DEBUG: <core> [ip_addr.c:247]: print_ip(): tcpconn_new: new tcp connection: 192.168.10.141</div>
<div>15(27061) DEBUG: <core> [tcp_main.c:1102]: tcpconn_new(): tcpconn_new: on port 53756, type 2</div><div>15(27061) DEBUG: <core> [tcp_main.c:1416]: tcpconn_add(): tcpconn_add: hashes: 3014:920:113, 1</div><div>
15(27061) DEBUG: <core> [io_wait.h:390]: io_watch_add(): DBG: io_watch_add(0x8270e00, 30, 2, 0xb2a5bc58), fd_no=19</div><div>15(27061) DEBUG: <core> [io_wait.h:617]: io_watch_del(): DBG: io_watch_del (0x8270e00, 30, -1, 0x0) fd_no=20 called</div>
<div>15(27061) DEBUG: <core> [tcp_main.c:4312]: handle_tcpconn_ev(): tcp: DBG: sending to child, events 1</div><div>15(27061) DEBUG: <core> [tcp_main.c:3983]: send2child(): selected tcp worker 0 11(27056) for activity on [tcp:<a href="http://192.168.10.202:5070/" target="_blank">192.168.10.202:5070</a>], 0xb2a5bc58</div>
<div>11(27056) DEBUG: <core> [tcp_read.c:1521]: handle_io(): received n=4 con=0xb2a5bc58, fd=10</div><div>11(27056) DEBUG: <core> [tcp_read.c:572]: tcp_read_headers(): tcp_read_headers: ERROR: no clen, p=A</div>
<div>11(27056) ERROR: <core> [tcp_read.c:1310]: tcp_read_req(): ERROR: tcp_read_req: bad request, state=7, error=4 buf:</div><div>GET / HTTP/1.1</div><div>Upgrade: websocket</div><div>Connection: Upgrade</div><div>Host: <a href="http://192.168.10.202:5070/" target="_blank">192.168.10.202:5070</a></div>
<div>Origin: <a href="http://sipml5.devel.phemium.com/" target="_blank">http://sipml5.devel.phemium.com</a></div><div>Sec-WebSocket-Protocol: sip</div><div>Pragma: no-cache</div><div>Cache-Control: no-cache</div><div>Sec-WebSocket-Key: nEzBXhDED/hlJnGieFvp1w==</div>
<div>Sec-WebSocket-Version: 13</div><div>Sec-WebSocket-Extensions: x-webkit-deflate-frame</div><div>User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36</div>
<div><br></div><div><br></div><div>parsed:</div><div>GET / HTTP/1.1</div><div>Upgrade: websocket</div><div>Connection: Upgrade</div><div>Host: <a href="http://192.168.10.202:5070/" target="_blank">192.168.10.202:5070</a></div>
<div>Origin: <a href="http://sipml5.devel.phemium.com/" target="_blank">http://sipml5.devel.phemium.com</a></div><div>Sec-WebSocket-Protocol: sip</div><div>Pragma: no-cache</div><div>Cache-Control: no-cache</div><div>Sec-WebSocket-Key: nEzBXhDED/hlJnGieFvp1w==</div>
<div>Sec-WebSocket-Version: 13</div><div>Sec-WebSocket-Extensions: x-webkit-deflate-frame</div><div>User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36</div>
<div><br></div><div><br></div><div>11(27056) DEBUG: <core> [tcp_read.c:1311]: tcp_read_req(): - received from: port 53756</div><div>11(27056) DEBUG: <core> [ip_addr.c:247]: print_ip(): - received from: ip 192.168.10.141</div>
<div>11(27056) DEBUG: <core> [tcp_read.c:1448]: release_tcpconn(): releasing con 0xb2a5bc58, state -2, fd=10, id=1</div><div>11(27056) DEBUG: <core> [tcp_read.c:1449]: release_tcpconn():  extra_data (nil)</div>
<div>15(27061) DEBUG: <core> [tcp_main.c:3395]: handle_tcp_child(): handle_tcp_child: reader response= b2a5bc58, -2 from 0</div><div><br></div><div>It looks like the packet never reaches the routing config. Even when I changed the websockets listen port to 8081, it tghrows the same error.</div>
<div><br></div><div><br></div><div>Here is my kamailio.cfg file:</div><div><br></div><div><div>#!KAMAILIO</div><div>#</div><div># Several features can be enabled using '#!define WITH_FEATURE' directives:</div><div>
#</div><div># *** To run in debug mode:</div><div>#     - define WITH_DEBUG</div><div>#</div><div># *** To enable mysql:</div><div>#     - define WITH_MYSQL</div><div>#</div><div># *** To enable authentication execute:</div>
<div>#     - enable mysql</div><div>#     - define WITH_AUTH</div><div>#     - add users using 'kamctl'</div><div>#</div><div># *** To enable IP authentication execute:</div><div>#     - enable mysql</div><div>#     - enable authentication</div>
<div>#     - define WITH_IPAUTH</div><div>#     - add IP addresses with group id '1' to 'address' table</div><div>#</div><div># *** To enable persistent user location execute:</div><div>#     - enable mysql</div>
<div>#     - define WITH_USRLOCDB</div><div>#</div><div># *** To enable presence server execute:</div><div>#     - enable mysql</div><div>#     - define WITH_PRESENCE</div><div>#</div><div># *** To enable nat traversal execute:</div>
<div>#     - define WITH_NAT</div><div>#     - install RTPProxy: <a href="http://www.rtpproxy.org">http://www.rtpproxy.org</a></div><div>#     - start RTPProxy:</div><div>#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722</div>
<div>#</div><div># *** To enable PSTN gateway routing execute:</div><div>#     - define WITH_PSTN</div><div>#     - set the value of pstn.gw_ip</div><div>#     - check route[PSTN] for regexp routing condition</div><div>#</div>
<div># *** To enable database aliases lookup execute:</div><div>#     - enable mysql</div><div>#     - define WITH_ALIASDB</div><div>#</div><div># *** To enable speed dial lookup execute:</div><div>#     - enable mysql</div>
<div>#     - define WITH_SPEEDDIAL</div><div>#</div><div># *** To enable multi-domain support execute:</div><div>#     - enable mysql</div><div>#     - define WITH_MULTIDOMAIN</div><div>#</div><div># *** To enable TLS support execute:</div>
<div>#     - adjust CFGDIR/tls.cfg as needed</div><div>#     - define WITH_TLS</div><div>#</div><div># *** To enable XMLRPC support execute:</div><div>#     - define WITH_XMLRPC</div><div>#     - adjust route[XMLRPC] for access policy</div>
<div>#</div><div># *** To enable the embedded http server:</div><div>#     - define WITH_XHTTP</div><div>#</div><div># *** To enable the RPC web interface execute:</div><div>#     - enable xhttp</div><div>#     - define WITH_XHTTP_RPC</div>
<div>#</div><div># *** To enable the provisioning web interface execute:</div><div>#     - enable mysql</div><div>#     - enable xhttp</div><div>#     - define WITH_XHTTP_PI</div><div>#</div><div># *** To enable anti-flood detection execute:</div>
<div>#     - adjust pike and htable=>ipban settings as needed (default is</div><div>#       block if more than 16 requests in 2 seconds and ban for 300 seconds)</div><div>#     - define WITH_ANTIFLOOD</div><div>#</div>
<div># *** To block 3XX redirect replies execute:</div><div>#     - define WITH_BLOCK3XX</div><div>#</div><div># *** To enable VoiceMail routing execute:</div><div>#     - define WITH_VOICEMAIL</div><div>#     - set the value of voicemail.srv_ip</div>
<div>#     - adjust the value of voicemail.srv_port</div><div>#</div><div># *** To enhance accounting execute:</div><div>#     - enable mysql</div><div>#     - define WITH_ACCDB</div><div>#     - add following columns to database</div>
<div>#!ifdef ACCDB_COMMENT</div><div>  ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';</div>
<div>  ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div>
<div>  ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';</div>
<div>  ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div>  ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div>
<div>#!endif</div><div><br></div><div>####### Include Local Config If Exists #########</div><div>import_file "kamailio-local.cfg"</div><div><br></div><div>####### Defined Values #########</div><div><br></div><div>
#!define WITH_NAT</div><div>#!define WITH_USRLOCDB</div><div>#!define WITH_AUTH</div><div>#!define WITH_MULTIDOMAIN</div><div>#!define WITH_POSTGRES</div><div>#!define WITH XHTTP</div><div>#!define DBURL "postgres://<a href="http://postgres@127.0.0.1/openser">postgres@127.0.0.1/openser</a>"</div>
<div>##!define WITH_TLS</div><div><br></div><div>#!ifdef WITH_MULTIDOMAIN</div><div># - the value for 'use_domain' parameters</div><div>#!define MULTIDOMAIN 1</div><div>#!else</div><div>#!define MULTIDOMAIN 0</div>
<div>#!endif</div><div><br></div><div># - flags</div><div>#   FLT_ - per transaction (message) flags</div><div>#<span class="" style="white-space:pre">   </span>FLB_ - per branch flags</div><div>#!define FLT_ACC 1</div><div>
#!define FLT_ACCMISSED 2</div><div>#!define FLT_ACCFAILED 3</div><div>#!define FLT_NATS 5</div><div><br></div><div>#!define FLB_NATB 6</div><div>#!define FLB_NATSIPPING 7</div><div>#!define WITH_WEBSOCKETS</div><div>#!define WITH_DEBUG</div>
<div><br></div><div>####### Global Parameters #########</div><div><br></div><div>#!ifdef WITH_DEBUG</div><div>debug=9</div><div>log_stderror=yes</div><div>#!else</div><div>debug=2</div><div>log_stderror=no</div><div>#!endif</div>
<div><br></div><div>memdbg=5</div><div>memlog=5</div><div><br></div><div>log_facility=LOG_LOCAL0</div><div><br></div><div>fork=yes</div><div>children=4</div><div><br></div><div>/* uncomment the next line to disable TCP (default on) */</div>
<div>#disable_tcp=yes</div><div><br></div><div>/* uncomment the next line to disable the auto discovery of local aliases</div><div>   based on reverse DNS on IPs (default on) */</div><div>#auto_aliases=no</div><div><br></div>
<div>/* add local domain aliases */</div><div>#alias="<a href="http://sip.mydomain.com">sip.mydomain.com</a>"</div><div><br></div><div>/* uncomment and configure the following line if you want Kamailio to</div><div>
   bind on a specific interface/port/proto (default bind on all available) */</div><div>listen=<a href="http://192.168.10.202:5070">192.168.10.202:5070</a></div><div>alias=<a href="http://devel.phemium.com">devel.phemium.com</a></div>
<div><br></div><div>#!ifdef WITH_WEBSOCKETS</div><div>listen=<a href="http://192.168.10.202:8081">192.168.10.202:8081</a></div><div>#!endif</div><div><br></div><div>/* port to listen to</div><div> * - can be specified more than once if needed to listen on many ports */</div>
<div>#port=5070</div><div><br></div><div>#!ifdef WITH_TLS</div><div>enable_tls=yes</div><div>#!endif</div><div><br></div><div># life time of TCP connection when there is no traffic</div><div># - a bit higher than registration expires to cope with UA behind NAT</div>
<div>tcp_connection_lifetime=3605</div><div><br></div><div>#!ifdef WITH_XHTTP</div><div>tcp_accept_no_cl=yes</div><div>#!endif</div><div><br></div><div>####### Custom Parameters #########</div><div><br></div><div># These parameters can be modified runtime via RPC interface</div>
<div># - see the documentation of 'cfg_rpc' module.</div><div>#</div><div># Format: <a href="http://group.id">group.id</a> = value 'desc' description</div><div># Access: $sel(<a href="http://cfg_get.group.id">cfg_get.group.id</a>) or @<a href="http://cfg_get.group.id">cfg_get.group.id</a></div>
<div>#</div><div><br></div><div>#!ifdef WITH_PSTN</div><div># PSTN GW Routing</div><div>#</div><div># - pstn.gw_ip: valid IP or hostname as string value, example:</div><div># pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"</div>
<div>#</div><div># - by default is empty to avoid misrouting</div><div>pstn.gw_ip = "" desc "PSTN GW Address"</div><div>pstn.gw_port = "" desc "PSTN GW Port"</div><div>#!endif</div>
<div><br></div><div>#!ifdef WITH_VOICEMAIL</div><div># VoiceMail Routing on offline, busy or no answer</div><div>#</div><div># - by default Voicemail server IP is empty to avoid misrouting</div><div>voicemail.srv_ip = "" desc "VoiceMail IP Address"</div>
<div>voicemail.srv_port = "5060" desc "VoiceMail Port"</div><div>#!endif</div><div><br></div><div>####### Modules Section ########</div><div><br></div><div># set paths to location of modules (to sources or installation folders)</div>
<div>#!ifdef WITH_SRCPATH</div><div>mpath="modules_k:modules"</div><div>#!else</div><div>mpath="/usr/local/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"</div><div>#!endif</div><div><br></div><div>
#!ifdef WITH_MYSQL</div><div>loadmodule "db_mysql.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_POSTGRES</div><div>loadmodule "db_postgres.so"</div><div>#!endif</div><div><br></div><div>loadmodule "mi_fifo.so"</div>
<div>loadmodule "kex.so"</div><div>loadmodule "corex.so"</div><div>loadmodule "tm.so"</div><div>loadmodule "tmx.so"</div><div>loadmodule "sl.so"</div><div>loadmodule "rr.so"</div>
<div>loadmodule "pv.so"</div><div>loadmodule "maxfwd.so"</div><div>loadmodule "usrloc.so"</div><div>loadmodule "registrar.so"</div><div>loadmodule "textops.so"</div><div>loadmodule "siputils.so"</div>
<div>loadmodule "xlog.so"</div><div>loadmodule "sanity.so"</div><div>loadmodule "ctl.so"</div><div>loadmodule "cfg_rpc.so"</div><div>loadmodule "mi_rpc.so"</div><div>loadmodule "acc.so"</div>
<div><br></div><div>#!ifdef WITH_AUTH</div><div>loadmodule "auth.so"</div><div>loadmodule "auth_db.so"</div><div>#!ifdef WITH_IPAUTH</div><div>loadmodule "permissions.so"</div><div>#!endif</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_ALIASDB</div><div>loadmodule "alias_db.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_SPEEDDIAL</div><div>loadmodule "speeddial.so"</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_MULTIDOMAIN</div><div>loadmodule "domain.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div>loadmodule "presence.so"</div>
<div>loadmodule "presence_xml.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_NAT</div><div>loadmodule "nathelper.so"</div><div>loadmodule "rtpproxy.so"</div><div>#!endif</div><div>
<br></div><div>#!ifdef WITH_TLS</div><div>loadmodule "tls.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_WEBSOCKETS</div><div>loadmodule "xhttp.so"</div><div>loadmodule "websocket.so"</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_ANTIFLOOD</div><div>loadmodule "htable.so"</div><div>loadmodule "pike.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XMLRPC</div><div>loadmodule "xmlrpc.so"</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_DEBUG</div><div>loadmodule "debugger.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XHTTP</div><div>loadmodule "xhttp.so"</div><div>#!endif</div>
<div><br></div><div>#!ifdef WITH_XHTTP_RPC</div><div>loadmodule "xhttp_rpc.so"</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XHTTP_PI</div><div>loadmodule "xhttp_pi.so"</div><div>#!endif</div>
<div><br></div><div>loadmodule "avpops.so"</div><div><br></div><div># ----------------- setting module-specific parameters ---------------</div><div><br></div><div><br></div><div># ----- mi_fifo params -----</div>
<div>modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")</div><div><br></div><div><br></div><div># ----- tm params -----</div><div># auto-discard branches from previous serial forking leg</div>
<div>modparam("tm", "failure_reply_mode", 3)</div><div># default retransmission timeout: 30sec</div><div>modparam("tm", "fr_timer", 30000)</div><div># default invite retransmission timeout after 1xx: 120sec</div>
<div>modparam("tm", "fr_inv_timer", 120000)</div><div><br></div><div><br></div><div># ----- rr params -----</div><div># add value to ;lr param to cope with most of the UAs</div><div>modparam("rr", "enable_full_lr", 1)</div>
<div># do not append from tag to the RR (no need for this script)</div><div>modparam("rr", "append_fromtag", 0)</div><div><br></div><div><br></div><div># ----- registrar params -----</div><div>modparam("registrar", "method_filtering", 1)</div>
<div>/* uncomment the next line to disable parallel forking via location */</div><div># modparam("registrar", "append_branches", 0)</div><div>/* uncomment the next line not to allow more than 10 contacts per AOR */</div>
<div>#modparam("registrar", "max_contacts", 10)</div><div># max value for expires of registrations</div><div>modparam("registrar", "max_expires", 3600)</div><div># set it to 1 to enable GRUU</div>
<div>modparam("registrar", "gruu_enabled", 0)</div><div><br></div><div><br></div><div># ----- acc params -----</div><div>/* what special events should be accounted ? */</div><div>modparam("acc", "early_media", 0)</div>
<div>modparam("acc", "report_ack", 0)</div><div>modparam("acc", "report_cancels", 0)</div><div>/* by default ww do not adjust the direct of the sequential requests.</div><div>   if you enable this parameter, be sure the enable "append_fromtag"</div>
<div>   in "rr" module */</div><div>modparam("acc", "detect_direction", 0)</div><div>/* account triggers (flags) */</div><div>modparam("acc", "log_flag", FLT_ACC)</div><div>
modparam("acc", "log_missed_flag", FLT_ACCMISSED)</div><div>modparam("acc", "log_extra",</div><div><span class="" style="white-space:pre">    </span>"src_user=$fU;src_domain=$fd;src_ip=$si;"</div>
<div><span class="" style="white-space:pre">    </span>"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div><div>modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)</div><div>/* enhanced DB accounting */</div>
<div>#!ifdef WITH_ACCDB</div><div>modparam("acc", "db_flag", FLT_ACC)</div><div>modparam("acc", "db_missed_flag", FLT_ACCMISSED)</div><div>modparam("acc", "db_url", DBURL)</div>
<div>modparam("acc", "db_extra",</div><div><span class="" style="white-space:pre">      </span>"src_user=$fU;src_domain=$fd;src_ip=$si;"</div><div><span class="" style="white-space:pre">        </span>"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div>
<div>#!endif</div><div><br></div><div><br></div><div># ----- usrloc params -----</div><div>/* enable DB persistency for location entries */</div><div>#!ifdef WITH_USRLOCDB</div><div>modparam("usrloc", "db_url", DBURL)</div>
<div>modparam("usrloc", "db_mode", 2)</div><div>modparam("usrloc", "use_domain", MULTIDOMAIN)</div><div>#!endif</div><div><br></div><div><br></div><div># ----- auth_db params -----</div>
<div>#!ifdef WITH_AUTH</div><div>modparam("auth_db", "db_url", DBURL)</div><div>modparam("auth_db", "calculate_ha1", yes)</div><div>modparam("auth_db", "password_column", "password")</div>
<div>modparam("auth_db", "load_credentials", "")</div><div>modparam("auth_db", "use_domain", MULTIDOMAIN)</div><div><br></div><div># ----- permissions params -----</div><div>
#!ifdef WITH_IPAUTH</div><div>modparam("permissions", "db_url", DBURL)</div><div>modparam("permissions", "db_mode", 1)</div><div>#!endif</div><div><br></div><div>#!endif</div><div><br>
</div><div><br></div><div># ----- alias_db params -----</div><div>#!ifdef WITH_ALIASDB</div><div>modparam("alias_db", "db_url", DBURL)</div><div>modparam("alias_db", "use_domain", MULTIDOMAIN)</div>
<div>#!endif</div><div><br></div><div><br></div><div># ----- speeddial params -----</div><div>#!ifdef WITH_SPEEDDIAL</div><div>modparam("speeddial", "db_url", DBURL)</div><div>modparam("speeddial", "use_domain", MULTIDOMAIN)</div>
<div>#!endif</div><div><br></div><div><br></div><div># ----- domain params -----</div><div>#!ifdef WITH_MULTIDOMAIN</div><div>modparam("domain", "db_url", DBURL)</div><div># register callback to match myself condition with domains list</div>
<div>modparam("domain", "register_myself", 1)</div><div>#!endif</div><div><br></div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div># ----- presence params -----</div><div>modparam("presence", "db_url", DBURL)</div>
<div><br></div><div># ----- presence_xml params -----</div><div>modparam("presence_xml", "db_url", DBURL)</div><div>modparam("presence_xml", "force_active", 1)</div><div>#!endif</div>
<div><br></div><div><br></div><div>#!ifdef WITH_NAT</div><div># ----- rtpproxy params -----</div><div>modparam("rtpproxy", "rtpproxy_sock", "udp:<a href="http://127.0.0.1:7899">127.0.0.1:7899</a>")</div>
<div><br></div><div># ----- nathelper params -----</div><div>modparam("nathelper", "natping_interval", 30)</div><div>modparam("nathelper", "ping_nated_only", 1)</div><div>modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)</div>
<div>modparam("nathelper", "sipping_from", "<a href="mailto:sip%3Apinger@devel.phemium.com">sip:pinger@devel.phemium.com</a>")</div><div><br></div><div># params needed for NAT traversal in other modules</div>
<div>modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")</div><div>modparam("usrloc", "nat_bflag", FLB_NATB)</div><div>#!endif</div><div><br></div><div><br></div>
<div>#!ifdef WITH_TLS</div><div># ----- tls params -----</div><div>modparam("tls", "config", "/etc/kamailio/tls.cfg")</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_ANTIFLOOD</div><div>
# ----- pike params -----</div><div>modparam("pike", "sampling_time_unit", 2)</div><div>modparam("pike", "reqs_density_per_unit", 16)</div><div>modparam("pike", "remove_latency", 4)</div>
<div><br></div><div># ----- htable params -----</div><div># ip ban htable with autoexpire after 5 minutes</div><div>modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")</div><div>
#!endif</div><div><br></div><div>#!ifdef WITH_XMLRPC</div><div># ----- xmlrpc params -----</div><div>modparam("xmlrpc", "route", "XMLRPC");</div><div>modparam("xmlrpc", "url_match", "^/RPC")</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_DEBUG</div><div># ----- debugger params -----</div><div>modparam("debugger", "cfgtrace", 1)</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XHTTP_RPC</div>
<div>modparam("xhttp_rpc", "xhttp_rpc_root", "http_rpc")</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_XHTTP_PI</div><div>modparam("xhttp_pi", "xhttp_pi_root", "http_pi")</div>
<div>modparam("xhttp_pi", "framework", "/etc/kamailio/pi_framework.xml")</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_WEBSOCKETS</div><div># ----- nathelper params -----</div><div>
#modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")</div><div># Note: leaving NAT pings turned off here as nathelper is _only_ being used for</div><div>#       WebSocket connections.  NAT pings are not needed as WebSockets have</div>
<div>#       their own keep-alives.</div><div>modparam("websocket", "sub_protocols", 1)</div><div>#!endif</div><div><br></div><div>####### Routing Logic ########</div><div><br></div><div><br></div><div>
# Main SIP request routing logic</div><div># - processing of any incoming SIP request starts with this route</div><div># - note: this is the same as route { ... }</div><div>request_route {</div><div>  xlog("PHEMIUM Init request_route\n");</div>
<div><br></div><div><span class="" style="white-space:pre">   </span># per request initial checks</div><div><span class="" style="white-space:pre">       </span>route(REQINIT);</div><div><br></div><div><span class="" style="white-space:pre">   </span># NAT detection</div>
<div><span class="" style="white-space:pre">    </span>route(NATDETECT);</div><div><br></div><div>        route(WESIP);</div><div><br></div><div><span class="" style="white-space:pre">    </span># CANCEL processing</div><div><span class="" style="white-space:pre">        </span>if (is_method("CANCEL"))</div>
<div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>if (t_check_trans())</div><div><span class="" style="white-space:pre">                       </span>t_relay();</div><div><span class="" style="white-space:pre">         </span>exit;</div>
<div><span class="" style="white-space:pre">    </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># handle requests within SIP dialogs</div><div><span class="" style="white-space:pre">       </span>route(WITHINDLG);</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>### only initial requests (no To tag)</div><div><br></div><div><span class="" style="white-space:pre">     </span>t_check_trans();</div><div><br></div><div><span class="" style="white-space:pre">  </span># authentication</div>
<div><span class="" style="white-space:pre">    </span>route(AUTH);</div><div><br></div><div><span class="" style="white-space:pre">      </span># record routing for dialog forming requests (in case they are routed)</div><div><span class="" style="white-space:pre">     </span># - remove preloaded route headers</div>
<div><span class="" style="white-space:pre">    </span>remove_hf("Route");</div><div><span class="" style="white-space:pre">      </span>if (is_method("INVITE|SUBSCRIBE"))</div><div><span class="" style="white-space:pre">               </span>record_route();</div>
<div><br></div><div><span class="" style="white-space:pre">   </span># account only INVITEs</div><div><span class="" style="white-space:pre">     </span>if (is_method("INVITE"))</div><div><span class="" style="white-space:pre"> </span>{</div>
<div><span class="" style="white-space:pre">            </span>setflag(FLT_ACC); # do accounting</div><div><span class="" style="white-space:pre">  </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># dispatch requests to foreign domains</div>
<div><span class="" style="white-space:pre">    </span>route(SIPOUT);</div><div><br></div><div><span class="" style="white-space:pre">    </span>### requests for my local domains</div><div><br></div><div><span class="" style="white-space:pre"> </span># handle presence related requests</div>
<div><span class="" style="white-space:pre">    </span>route(PRESENCE);</div><div><br></div><div><span class="" style="white-space:pre">  </span># handle registrations</div><div><span class="" style="white-space:pre">     </span>route(REGISTRAR);</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>if ($rU==$null)</div><div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span># request with no Username in RURI</div>
<div><span class="" style="white-space:pre">            </span>sl_send_reply("484","Address Incomplete");</div><div><span class="" style="white-space:pre">             </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div>
<div><br></div><div><span class="" style="white-space:pre">   </span># dispatch destinations to PSTN</div><div><span class="" style="white-space:pre">    </span>route(PSTN);</div><div><br></div><div><span class="" style="white-space:pre">      </span># user location service</div>
<div><span class="" style="white-space:pre">    </span>route(LOCATION);</div><div><br></div><div><span class="" style="white-space:pre">  </span>route(RELAY);</div><div>}</div><div><br></div><div><br></div><div># Wesip forwarding</div>
<div># is IP based. Anything not coming from Wesip is</div><div># sent there. Anything coming from there, continues</div><div># its route</div><div>route[WESIP] {</div><div>  if ( $si == "192.168.10.202" ) {</div>
<div>    if ( is_present_hf("X-Phemium-Reason") ) {</div><div>      $avp(phemreason) = $hdr(X-Phemium-Reason);</div><div>    }</div><div>    if ( is_present_hf("X-Phemium-Register") ) {</div><div>      $avp(phemreg) = $hdr(X-Phemium-Register);</div>
<div>      if (!avp_check("$avp(phemreg)","eq/yes/i")) {</div><div>        if (is_avp_set("$avp(phemreason)")) {</div><div>          sl_send_reply("403","$avp(phemreason)");</div>
<div>        } else {</div><div>          sl_send_reply("403","Request not accepted");</div><div>        }</div><div>        exit;</div><div>      }</div><div>    }</div><div>  } else {</div><div>    $avp(RECEIVED) = "sip:"+$si+":"+$sp;</div>
<div>    if ( is_method("REGISTER") ) {</div><div>      append_hf("P-Received: $avp(RECEIVED)\r\n");</div><div>    }</div><div>    record_route();</div><div>    t_relay_to_udp("192.168.10.202","50060");</div>
<div>    exit;</div><div>  }</div><div>}</div><div><br></div><div># Initial fixes</div><div>route[FIXUP] {</div><div>  if ( $rd == "192.168.10.202" ) {</div><div>    rewritehost("<a href="http://devel.phemium.com">devel.phemium.com</a>");</div>
<div>  }</div><div>}</div><div><br></div><div># Check accepted domains</div><div>route[ACCDOMAIN] {</div><div>   if ! ( $rd == "<a href="http://devel.phemium.com">devel.phemium.com</a>"</div><div>       || $si == "192.168.10.202"</div>
<div>       #OR_ACCEPTED_DOMAINS</div><div>    ) {</div><div>    sl_send_reply("403", "Not accepted domain");</div><div>    exit;</div><div>  }</div><div>}</div><div><br></div><div># Keepalive request responding</div>
<div>route[KEEPALIVE] {</div><div>  if (   is_method("NOTIFY")</div><div>      && is_uri_host_local()</div><div>      && (    strempty($rU)</div><div>           || search("^Event: keep-alive") ) ) {</div>
<div>    sl_send_reply("200", "OK - keepalive");</div><div>    exit;</div><div>  }</div><div>  if (    is_method("OPTIONS")</div><div>       && is_uri_host_local()</div><div>       && strempty($rU) ) {</div>
<div>    sl_send_reply("200", "OK - keepalive");</div><div>    exit;</div><div>  }</div><div>}</div><div><br></div><div># Mirror service routing</div><div>route[MIRROR] {</div><div>  if ( uri=~"^sip:(.+@)?<a href="http://conf.devel.phemium.com">conf.devel.phemium.com</a>" )</div>
<div>  {</div><div>    remove_hf("P-Asserted-Identity");</div><div>    avp_printf("$avp(i:1)", "<$fu>");</div><div>    append_hf( "P-Asserted-Identity: $avp(i:1)\r\n" );</div>
<div>    avp_delete("$avp(i:1)");</div><div>    record_route();</div><div>    t_relay_to_udp("192.168.10.202","50070");</div><div>    exit;</div><div>  }</div><div>  # Record route backwards from mirror</div>
<div>  if (    $si == "192.168.10.202"</div><div>       && from_uri=~"^sip:(.+@)?<a href="http://conf.devel.phemium.com">conf.devel.phemium.com</a>") {</div><div>       record_route();</div><div>
       t_relay();</div><div>  }</div><div>}</div><div><br></div><div><br></div><div>route[RELAY] {</div><div><br></div><div><span class="" style="white-space:pre">     </span># enable additional event routes for forwarded requests</div>
<div><span class="" style="white-space:pre">    </span># - serial forking, RTP relaying handling, a.s.o.</div><div><span class="" style="white-space:pre">  </span>if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {</div>
<div><span class="" style="white-space:pre">            </span>if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");</div><div><span class="" style="white-space:pre">    </span>}</div><div><span class="" style="white-space:pre">  </span>if (is_method("INVITE|SUBSCRIBE|UPDATE")) {</div>
<div><span class="" style="white-space:pre">            </span>if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");</div><div><span class="" style="white-space:pre">     </span>}</div><div><span class="" style="white-space:pre">  </span>if (is_method("INVITE")) {</div>
<div><span class="" style="white-space:pre">            </span>if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");</div><div><span class="" style="white-space:pre"> </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (!t_relay()) {</div>
<div><span class="" style="white-space:pre">            </span>sl_reply_error();</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span>exit;</div><div>}</div><div><br></div>
<div># Per SIP request initial checks</div><div>route[REQINIT] {</div><div>#!ifdef WITH_ANTIFLOOD</div><div><span class="" style="white-space:pre"> </span># flood dection from same IP and traffic ban for a while</div><div>
<span class="" style="white-space:pre">       </span># be sure you exclude checking trusted peers, such as pstn gateways</div><div><span class="" style="white-space:pre">        </span># - local host excluded (e.g., loop to self)</div>
<div><span class="" style="white-space:pre">    </span>if(src_ip!=myself)</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>if($sht(ipban=>$si)!=$null)</div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span># ip is already blocked</div><div><span class="" style="white-space:pre">                    </span>xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");</div>
<div><span class="" style="white-space:pre">                    </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">          </span>if (!pike_check_req())</div><div><span class="" style="white-space:pre">             </span>{</div>
<div><span class="" style="white-space:pre">                    </span>xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");</div><div><span class="" style="white-space:pre">                    </span>$sht(ipban=>$si) = 1;</div>
<div><span class="" style="white-space:pre">                    </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div>#!endif</div><div><br></div><div>
<span class="" style="white-space:pre">       </span>if (!mf_process_maxfwd_header("10")) {</div><div><span class="" style="white-space:pre">           </span>sl_send_reply("483","Too Many Hops");</div><div>
<span class="" style="white-space:pre">               </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if(!sanity_check("1511", "7"))</div>
<div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>xlog("Malformed SIP message from $si:$sp\n");</div><div><span class="" style="white-space:pre">            </span>exit;</div>
<div><span class="" style="white-space:pre">    </span>}</div><div>}</div><div><br></div><div># Handle requests within SIP dialogs</div><div>route[WITHINDLG] {</div><div><span class="" style="white-space:pre">     </span>if (has_totag()) {</div>
<div><span class="" style="white-space:pre">            </span># sequential request withing a dialog should</div><div><span class="" style="white-space:pre">               </span># take the path determined by record-routing</div><div><span class="" style="white-space:pre">               </span>if (loose_route()) {</div>
<div><span class="" style="white-space:pre">                    </span>route(DLGURI);</div><div><span class="" style="white-space:pre">                     </span>if (is_method("BYE")) {</div><div><span class="" style="white-space:pre">                          </span>setflag(FLT_ACC); # do accounting ...</div>
<div><span class="" style="white-space:pre">                            </span>setflag(FLT_ACCFAILED); # ... even if the transaction fails</div><div><span class="" style="white-space:pre">                        </span>}</div><div><span class="" style="white-space:pre">                  </span>else if ( is_method("ACK") ) {</div>
<div><span class="" style="white-space:pre">                            </span># ACK is forwarded statelessy</div><div><span class="" style="white-space:pre">                              </span>route(NATMANAGE);</div><div><span class="" style="white-space:pre">                  </span>}</div>
<div><span class="" style="white-space:pre">                    </span>else if ( is_method("NOTIFY") ) {</div><div><span class="" style="white-space:pre">                                </span># Add Record-Route for in-dialog NOTIFY as per RFC 6665.</div><div>
<span class="" style="white-space:pre">                               </span>record_route();</div><div><span class="" style="white-space:pre">                    </span>}</div><div><span class="" style="white-space:pre">                  </span>route(RELAY);</div><div><span class="" style="white-space:pre">              </span>} else {</div>
<div><span class="" style="white-space:pre">                    </span>if (is_method("SUBSCRIBE") && uri == myself) {</div><div><span class="" style="white-space:pre">                           </span># in-dialog subscribe requests</div><div><span class="" style="white-space:pre">                             </span>route(PRESENCE);</div>
<div><span class="" style="white-space:pre">                            </span>exit;</div><div><span class="" style="white-space:pre">                      </span>}</div><div><span class="" style="white-space:pre">                  </span>if ( is_method("ACK") ) {</div>
<div><span class="" style="white-space:pre">                            </span>if ( t_check_trans() ) {</div><div><span class="" style="white-space:pre">                                   </span># no loose-route, but stateful ACK;</div><div><span class="" style="white-space:pre">                                        </span># must be an ACK after a 487</div>
<div><span class="" style="white-space:pre">                                    </span># or e.g. 404 from upstream server</div><div><span class="" style="white-space:pre">                                 </span>t_relay();</div><div><span class="" style="white-space:pre">                                 </span>exit;</div>
<div><span class="" style="white-space:pre">                            </span>} else {</div><div><span class="" style="white-space:pre">                                   </span># ACK without matching transaction ... ignore and discard</div><div><span class="" style="white-space:pre">                                  </span>exit;</div>
<div><span class="" style="white-space:pre">                            </span>}</div><div><span class="" style="white-space:pre">                  </span>}</div><div><span class="" style="white-space:pre">                  </span>sl_send_reply("404","Not here");</div>
<div><span class="" style="white-space:pre">            </span>}</div><div><span class="" style="white-space:pre">          </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div># Handle SIP registrations</div>
<div>route[REGISTRAR] {</div><div><span class="" style="white-space:pre">   </span>if (is_method("REGISTER"))</div><div><span class="" style="white-space:pre">       </span>{</div><div><span class="" style="white-space:pre">          </span>if(isflagset(FLT_NATS))</div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>setbflag(FLB_NATB);</div><div><span class="" style="white-space:pre">                        </span># uncomment next line to do SIP NAT pinging</div>
<div><span class="" style="white-space:pre">                    </span>## setbflag(FLB_NATSIPPING);</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">          </span>if (!save("location"))</div>
<div><span class="" style="white-space:pre">                    </span>sl_reply_error();</div><div><br></div><div><span class="" style="white-space:pre">         </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div>}</div>
<div><br></div><div># USER location service</div><div>route[LOCATION] {</div><div><br></div><div>#!ifdef WITH_SPEEDDIAL</div><div><span class="" style="white-space:pre">       </span># search for short dialing - 2-digit extension</div>
<div><span class="" style="white-space:pre">    </span>if($rU=~"^[0-9][0-9]$")</div><div><span class="" style="white-space:pre">          </span>if(sd_lookup("speed_dial"))</div><div><span class="" style="white-space:pre">                      </span>route(SIPOUT);</div>
<div>#!endif</div><div><br></div><div>#!ifdef WITH_ALIASDB</div><div><span class="" style="white-space:pre">  </span># search in DB-based aliases</div><div><span class="" style="white-space:pre">       </span>if(alias_db_lookup("dbaliases"))</div>
<div><span class="" style="white-space:pre">            </span>route(SIPOUT);</div><div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">      </span>$avp(oexten) = $rU;</div><div><span class="" style="white-space:pre">        </span>if (!lookup("location")) {</div>
<div><span class="" style="white-space:pre">            </span>$var(rc) = $rc;</div><div><span class="" style="white-space:pre">            </span>route(TOVOICEMAIL);</div><div><span class="" style="white-space:pre">                </span>t_newtran();</div>
<div><span class="" style="white-space:pre">            </span>switch ($var(rc)) {</div><div><span class="" style="white-space:pre">                        </span>case -1:</div><div><span class="" style="white-space:pre">                   </span>case -3:</div><div><span class="" style="white-space:pre">                           </span>send_reply("404", "Not Found");</div>
<div><span class="" style="white-space:pre">                            </span>exit;</div><div><span class="" style="white-space:pre">                      </span>case -2:</div><div><span class="" style="white-space:pre">                           </span>send_reply("405", "Method Not Allowed");</div>
<div><span class="" style="white-space:pre">                            </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span># when routing via usrloc, log the missed calls also</div>
<div><span class="" style="white-space:pre">    </span>if (is_method("INVITE"))</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre">          </span>setflag(FLT_ACCMISSED);</div>
<div><span class="" style="white-space:pre">    </span>}</div><div>}</div><div><br></div><div># Presence server route</div><div>route[PRESENCE] {</div><div><span class="" style="white-space:pre">   </span>if(!is_method("PUBLISH|SUBSCRIBE"))</div>
<div><span class="" style="white-space:pre">            </span>return;</div><div><br></div><div>#!ifdef WITH_PRESENCE</div><div><span class="" style="white-space:pre">       </span>if (!t_newtran())</div><div><span class="" style="white-space:pre">  </span>{</div>
<div><span class="" style="white-space:pre">            </span>sl_reply_error();</div><div><span class="" style="white-space:pre">          </span>exit;</div><div><span class="" style="white-space:pre">      </span>};</div><div><br></div><div><span class="" style="white-space:pre">        </span>if(is_method("PUBLISH"))</div>
<div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>handle_publish();</div><div><span class="" style="white-space:pre">          </span>t_release();</div><div><span class="" style="white-space:pre">       </span>}</div>
<div><span class="" style="white-space:pre">    </span>else</div><div><span class="" style="white-space:pre">       </span>if( is_method("SUBSCRIBE"))</div><div><span class="" style="white-space:pre">      </span>{</div><div>
<span class="" style="white-space:pre">               </span>handle_subscribe();</div><div><span class="" style="white-space:pre">                </span>t_release();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>exit;</div>
<div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">     </span># if presence enabled, this part will not be executed</div><div><span class="" style="white-space:pre">      </span>if (is_method("PUBLISH") || $rU==$null)</div>
<div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>sl_send_reply("404", "Not here");</div><div><span class="" style="white-space:pre">              </span>exit;</div>
<div><span class="" style="white-space:pre">    </span>}</div><div><span class="" style="white-space:pre">  </span>return;</div><div>}</div><div><br></div><div># Authentication route</div><div>route[AUTH] {</div><div>#!ifdef WITH_AUTH</div>
<div><br></div><div>#!ifdef WITH_IPAUTH</div><div><span class="" style="white-space:pre"> </span>if((!is_method("REGISTER")) && allow_source_address())</div><div><span class="" style="white-space:pre">   </span>{</div>
<div><span class="" style="white-space:pre">            </span># source IP allowed</div><div><span class="" style="white-space:pre">                </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div><div>#!endif</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>if (is_method("REGISTER") || from_uri==myself)</div><div><span class="" style="white-space:pre">   </span>{</div><div><span class="" style="white-space:pre">          </span># authenticate requests</div>
<div><span class="" style="white-space:pre">            </span>if (!auth_check("$fd", "subscriber", "1")) {</div><div><span class="" style="white-space:pre">                 </span>auth_challenge("$fd", "0");</div>
<div><span class="" style="white-space:pre">                    </span>exit;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">          </span># user authenticated - remove auth header</div>
<div><span class="" style="white-space:pre">            </span>if(!is_method("REGISTER|PUBLISH"))</div><div><span class="" style="white-space:pre">                       </span>consume_credentials();</div><div><span class="" style="white-space:pre">     </span>}</div>
<div><span class="" style="white-space:pre">    </span># if caller is not local subscriber, then check if it calls</div><div><span class="" style="white-space:pre">        </span># a local destination, otherwise deny, not an open relay here</div>
<div><span class="" style="white-space:pre">    </span>if (from_uri!=myself && uri!=myself)</div><div><span class="" style="white-space:pre">       </span>{</div><div><span class="" style="white-space:pre">          </span>sl_send_reply("403","Not relaying");</div>
<div><span class="" style="white-space:pre">            </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div>#!endif</div><div><span class="" style="white-space:pre">   </span>return;</div>
<div>}</div><div><br></div><div># Caller NAT detection route</div><div>route[NATDETECT] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">        </span>force_rport();</div><div><span class="" style="white-space:pre">     </span>if (nat_uac_test("19")) {</div>
<div><span class="" style="white-space:pre">            </span>if (is_method("REGISTER")) {</div><div><span class="" style="white-space:pre">                     </span>fix_nated_register();</div><div><span class="" style="white-space:pre">              </span>} else {</div>
<div><span class="" style="white-space:pre">                    </span>add_contact_alias();</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">          </span>setflag(FLT_NATS);</div><div>
<span class="" style="white-space:pre">       </span>}</div><div>#!endif</div><div><span class="" style="white-space:pre">    </span>return;</div><div>}</div><div><br></div><div># RTPProxy control</div><div>route[NATMANAGE] {</div>
<div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">     </span>if (is_request()) {</div><div><span class="" style="white-space:pre">                </span>if(has_totag()) {</div><div><span class="" style="white-space:pre">                  </span>if(check_route_param("nat=yes")) {</div>
<div><span class="" style="white-space:pre">                            </span>setbflag(FLB_NATB);</div><div><span class="" style="white-space:pre">                        </span>}</div><div><span class="" style="white-space:pre">          </span>}</div><div><span class="" style="white-space:pre">  </span>}</div>
<div><span class="" style="white-space:pre">    </span>if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))</div><div><span class="" style="white-space:pre">                </span>return;</div><div><br></div><div><span class="" style="white-space:pre">   </span>rtpproxy_manage();</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>if (is_request()) {</div><div><span class="" style="white-space:pre">                </span>if (!has_totag()) {</div><div><span class="" style="white-space:pre">                        </span>add_rr_param(";nat=yes");</div>
<div><span class="" style="white-space:pre">            </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span>if (is_reply()) {</div><div><span class="" style="white-space:pre">          </span>if(isbflagset(FLB_NATB)) {</div>
<div><span class="" style="white-space:pre">                    </span>add_contact_alias();</div><div><span class="" style="white-space:pre">               </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div>#!endif</div><div>
<span class="" style="white-space:pre">       </span>return;</div><div>}</div><div><br></div><div># URI update for dialog requests</div><div>route[DLGURI] {</div><div>#!ifdef WITH_NAT</div><div><span class="" style="white-space:pre">       </span>if(!isdsturiset()) {</div>
<div><span class="" style="white-space:pre">            </span>handle_ruri_alias();</div><div><span class="" style="white-space:pre">       </span>}</div><div>#!endif</div><div><span class="" style="white-space:pre">    </span>return;</div>
<div>}</div><div><br></div><div># Routing to foreign domains</div><div>route[SIPOUT] {</div><div><span class="" style="white-space:pre">  </span>if (!uri==myself)</div><div><span class="" style="white-space:pre">  </span>{</div>
<div><span class="" style="white-space:pre">            </span>append_hf("P-hint: outbound\r\n");</div><div><span class="" style="white-space:pre">               </span>route(RELAY);</div><div><span class="" style="white-space:pre">      </span>}</div>
<div>}</div><div><br></div><div># PSTN GW routing</div><div>route[PSTN] {</div><div>#!ifdef WITH_PSTN</div><div><span class="" style="white-space:pre">       </span># check if PSTN GW IP is defined</div><div><span class="" style="white-space:pre">   </span>if (strempty($sel(cfg_get.pstn.gw_ip))) {</div>
<div><span class="" style="white-space:pre">            </span>xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");</div><div><span class="" style="white-space:pre">               </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div>
<div><br></div><div><span class="" style="white-space:pre">   </span># route to PSTN dialed numbers starting with '+' or '00'</div><div><span class="" style="white-space:pre">   </span>#     (international format)</div>
<div><span class="" style="white-space:pre">    </span># - update the condition to match your dialing rules for PSTN routing</div><div><span class="" style="white-space:pre">      </span>if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))</div>
<div><span class="" style="white-space:pre">            </span>return;</div><div><br></div><div><span class="" style="white-space:pre">   </span># only local users allowed to call</div><div><span class="" style="white-space:pre"> </span>if(from_uri!=myself) {</div>
<div><span class="" style="white-space:pre">            </span>sl_send_reply("403", "Not Allowed");</div><div><span class="" style="white-space:pre">           </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>if (strempty($sel(cfg_get.pstn.gw_port))) {</div><div><span class="" style="white-space:pre">                </span>$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);</div>
<div><span class="" style="white-space:pre">    </span>} else {</div><div><span class="" style="white-space:pre">           </span>$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":"</div><div><span class="" style="white-space:pre">                                    </span>+ $sel(cfg_get.pstn.gw_port);</div>
<div><span class="" style="white-space:pre">    </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>route(RELAY);</div><div><span class="" style="white-space:pre">      </span>exit;</div><div>#!endif</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>return;</div><div>}</div><div><br></div><div># XMLRPC routing</div><div>#!ifdef WITH_XMLRPC</div><div>route[XMLRPC] {</div><div><span class="" style="white-space:pre">    </span># allow XMLRPC from localhost</div>
<div><span class="" style="white-space:pre">    </span>if ((method=="POST" || method=="GET")</div><div><span class="" style="white-space:pre">                  </span>&& (src_ip==127.0.0.1)) {</div><div><span class="" style="white-space:pre">          </span># close connection only for xmlrpclib user agents (there is a bug in</div>
<div><span class="" style="white-space:pre">            </span># xmlrpclib: it waits for EOF before interpreting the response).</div><div><span class="" style="white-space:pre">           </span>if ($hdr(User-Agent) =~ "xmlrpclib")</div>
<div><span class="" style="white-space:pre">                    </span>set_reply_close();</div><div><span class="" style="white-space:pre">         </span>set_reply_no_connect();</div><div><span class="" style="white-space:pre">            </span>dispatch_rpc();</div>
<div><span class="" style="white-space:pre">            </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><span class="" style="white-space:pre">  </span>send_reply("403", "Forbidden");</div>
<div><span class="" style="white-space:pre">    </span>exit;</div><div>}</div><div>#!endif</div><div><br></div><div># route to voicemail server</div><div>route[TOVOICEMAIL] {</div><div>#!ifdef WITH_VOICEMAIL</div><div><span class="" style="white-space:pre">     </span>if(!is_method("INVITE"))</div>
<div><span class="" style="white-space:pre">            </span>return;</div><div><br></div><div><span class="" style="white-space:pre">   </span># check if VoiceMail server IP is defined</div><div><span class="" style="white-space:pre">  </span>if (strempty($sel(cfg_get.voicemail.srv_ip))) {</div>
<div><span class="" style="white-space:pre">            </span>xlog("SCRIPT: VoiceMail rotuing enabled but IP not defined\n");</div><div><span class="" style="white-space:pre">          </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div>
<div><span class="" style="white-space:pre">    </span>if($avp(oexten)==$null)</div><div><span class="" style="white-space:pre">            </span>return;</div><div><br></div><div><span class="" style="white-space:pre">   </span>$ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip)</div>
<div><span class="" style="white-space:pre">                            </span>+ ":" + $sel(cfg_get.voicemail.srv_port);</div><div><span class="" style="white-space:pre">        </span>route(RELAY);</div><div><span class="" style="white-space:pre">      </span>exit;</div>
<div>#!endif</div><div><br></div><div><span class="" style="white-space:pre">     </span>return;</div><div>}</div><div><br></div><div># manage outgoing branches</div><div>branch_route[MANAGE_BRANCH] {</div><div><span class="" style="white-space:pre">      </span>xdbg("new branch [$T_branch_idx] to $ru\n");</div>
<div><span class="" style="white-space:pre">    </span>route(NATMANAGE);</div><div>}</div><div><br></div><div># manage incoming replies</div><div>onreply_route[MANAGE_REPLY] {</div><div><span class="" style="white-space:pre">     </span>xdbg("incoming reply\n");</div>
<div><span class="" style="white-space:pre">    </span>if(status=~"[12][0-9][0-9]")</div><div><span class="" style="white-space:pre">             </span>route(NATMANAGE);</div><div>}</div><div><br></div><div># manage failure routing cases</div>
<div>failure_route[MANAGE_FAILURE] {</div><div><br></div><div>  xlog( "PHEMIUM failure route\n" );</div><div><span class="" style="white-space:pre">        </span>route(NATMANAGE);</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (t_is_canceled()) {</div>
<div><span class="" style="white-space:pre">            </span>exit;</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div>#!ifdef WITH_BLOCK3XX</div><div><span class="" style="white-space:pre">     </span># block call redirect based on 3xx replies.</div>
<div><span class="" style="white-space:pre">    </span>if (t_check_status("3[0-9][0-9]")) {</div><div><span class="" style="white-space:pre">             </span>t_reply("404","Not found");</div><div><span class="" style="white-space:pre">            </span>exit;</div>
<div><span class="" style="white-space:pre">    </span>}</div><div>#!endif</div><div><br></div><div>#!ifdef WITH_VOICEMAIL</div><div><span class="" style="white-space:pre">      </span># serial forking</div><div><span class="" style="white-space:pre">   </span># - route to voicemail on busy or no answer (timeout)</div>
<div><span class="" style="white-space:pre">    </span>if (t_check_status("486|408")) {</div><div><span class="" style="white-space:pre">         </span>route(TOVOICEMAIL);</div><div><span class="" style="white-space:pre">                </span>exit;</div>
<div><span class="" style="white-space:pre">    </span>}</div><div>#!endif</div><div>}</div><div><br></div><div>#!ifdef WITH_XHTTP</div><div>event_route[xhttp:request] {</div><div>xlog("Entering XHTTP\n");</div><div>
#!ifdef WITH_XHTTP_RPC</div><div><span class="" style="white-space:pre">  </span>$var(xhttp_rpc_root) = $(hu{s.substr,0,9});</div><div><span class="" style="white-space:pre">        </span>if ($var(xhttp_rpc_root) == "/http_rpc") {</div>
<div><span class="" style="white-space:pre">            </span>dispatch_xhttp_rpc();</div><div><span class="" style="white-space:pre">      </span>}</div><div>#!endif</div><div><br></div><div><br></div><div>#!ifdef WITH_XHTTP_PI</div><div>
<span class="" style="white-space:pre">       </span>$var(xhttp_rpc_root) = $(hu{s.substr,0,8});</div><div><span class="" style="white-space:pre">        </span>if ($var(xhttp_rpc_root) == "/http_pi") {</div><div><span class="" style="white-space:pre">                </span>dispatch_xhttp_pi();</div>
<div><span class="" style="white-space:pre">    </span>}</div><div>#!endif</div><div><span class="" style="white-space:pre">    </span>xhttp_reply("200", "OK", "text/html",</div><div><span class="" style="white-space:pre">                </span>"<html><body>Wrong URL $hu</body></html>");</div>
<div>}</div><div>#!endif</div><div><br></div><div><br></div><div><br></div></div><div><br></div><div><br></div><div>Any thoughts??</div><div><br></div><div>Thank you in advanced!</div></div></div><div><br></div>-- <br><div dir="ltr">
<p align="left" style="font-size:12pt;margin:0cm 0cm 0pt;font-family:'Times New Roman'"><font face="Arial" size="3"><span style="font-size:13px"><b>Dani Castaños Sánchez</b></span></font></p><p style="font-size:12pt;margin:0cm 0cm 0pt;font-family:'Times New Roman'">
<em><span style="font-size:10pt;font-family:Arial">Business Development</span></em></p><p style="font-size:12pt;margin:0cm 0cm 0pt;font-family:'Times New Roman'"><span style="font-size:10pt;color:rgb(218,25,80);font-family:Arial"><span style="color:rgb(218,25,80);text-decoration:none"><a href="mailto:dcastanos@androme.es" target="_blank">dcastanos@androme.es</a></span></span></p>
<p style="font-size:12pt;margin:0cm 0cm 0pt;font-family:'Times New Roman'"><span style="font-size:small;font-family:arial"></span></p><p style="margin:0cm 0cm 0pt"><br></p><p style="margin:0cm 0cm 0pt">Tel: +34 93 184 52 83<br>
</p><p style="margin:0cm 0cm 0pt"><a href="http://www.phemium.com" target="_blank">http://www.phemium.com</a></p></div>
</div>