diff --git a/config.ini b/config.ini
new file mode 100644
index 0000000..e013c7c
--- /dev/null
+++ b/config.ini
@@ -0,0 +1,25 @@
+; section are between [] = [section]
+; key = value
+; to comment add ";" in front of the line
+[amqp]
+uri = "amqp://guest:guest@127.0.0.1:5672"
+
+[bigcouch]
+compact_automatically = true
+cookie = change_me
+ip = "127.0.0.1"
+port = 5984
+; username = "XXX"
+; password = "XXX"
+admin_port = 5986
+
+[whistle_apps]
+cookie = change_me
+
+[ecallmgr]
+cookie = change_me
+
+[log]
+syslog = info
+console = notice
+file = error
diff --git a/freeswitch/autoload_configs/cepstral.conf.xml b/freeswitch/autoload_configs/cepstral.conf.xml
deleted file mode 100644
index cf4aa92..0000000
--- a/freeswitch/autoload_configs/cepstral.conf.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/freeswitch/autoload_configs/httapi.conf.xml b/freeswitch/autoload_configs/httapi.conf.xml
deleted file mode 100644
index 50bbe78..0000000
--- a/freeswitch/autoload_configs/httapi.conf.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/freeswitch/autoload_configs/kazoo.conf.xml b/freeswitch/autoload_configs/kazoo.conf.xml
index 547e725..4cbd97f 100644
--- a/freeswitch/autoload_configs/kazoo.conf.xml
+++ b/freeswitch/autoload_configs/kazoo.conf.xml
@@ -1,12 +1,13 @@
-
+
+
-
-
-
-
-
-
-
+
+
+
+ -->
+
+
+
-
\ No newline at end of file
+
diff --git a/freeswitch/autoload_configs/modules.conf.xml b/freeswitch/autoload_configs/modules.conf.xml
index 8dc91db..ec0312b 100644
--- a/freeswitch/autoload_configs/modules.conf.xml
+++ b/freeswitch/autoload_configs/modules.conf.xml
@@ -22,13 +22,11 @@
-
-
@@ -39,7 +37,6 @@
-
diff --git a/haproxy/haproxy.cfg b/haproxy/haproxy.cfg
new file mode 100644
index 0000000..a2201fc
--- /dev/null
+++ b/haproxy/haproxy.cfg
@@ -0,0 +1,39 @@
+global
+ log 127.0.0.1 local0
+ log 127.0.0.1 local1 notice
+ maxconn 4096
+ user haproxy
+ group haproxy
+ stats socket /tmp/haproxy.sock mode 777
+
+defaults
+ log global
+ mode http
+ option httplog
+ option dontlognull
+ option redispatch
+ option httpchk GET /
+ option allbackups
+ maxconn 2000
+ retries 3
+ timeout connect 6000ms
+ timeout client 12000ms
+ timeout server 12000ms
+
+listen bigcouch-data 127.0.0.1:15984
+ balance roundrobin
+ server db1.zone1.mydomain.com 127.0.0.1:5984 check
+ server db2.zone1.mydomain.com 127.0.0.2:5984 check
+ server db3.zone2.mydomain.com 127.0.0.3:5984 check backup
+ server db4.zone2.mydomain.com 127.0.0.4:5984 check backup
+
+listen bigcouch-mgr 127.0.0.1:15986
+ balance roundrobin
+ server db1.zone1.mydomain.com 127.0.0.1:5986 check
+ server db2.zone1.mydomain.com 127.0.0.2:5986 check
+ server db3.zone2.mydomain.com 127.0.0.3:5986 check backup
+ server db4.zone2.mydomain.com 127.0.0.4:5986 check backup
+
+listen haproxy-stats 127.0.0.1:22002
+ mode http
+ stats uri /
diff --git a/kamailio/dispatcher.list b/kamailio/dispatcher.list
new file mode 100644
index 0000000..d50f425
--- /dev/null
+++ b/kamailio/dispatcher.list
@@ -0,0 +1 @@
+# setit(integer) destination(sip uri) flags (integer, optional)
diff --git a/kamailio/kamailio.cfg b/kamailio/kamailio.cfg
new file mode 100644
index 0000000..26a8fe4
--- /dev/null
+++ b/kamailio/kamailio.cfg
@@ -0,0 +1,944 @@
+#### Preprocessor Directives #########
+#!define L_ALERT -5
+#!define L_BUG -4
+#!define L_CRIT2 -3
+#!define L_CRIT -2
+#!define L_ERR -1
+#!define L_WARN 0
+#!define L_NOTICE 1
+#!define L_INFO 2
+#!define L_DBG 3
+
+#!define AVP_RECV_PARAM "recv_param"
+#!define AVP_LOG_LEVEL "log_level"
+#!define AVP_ROUTE_CNT "route_cnt"
+#!define AVP_ASSOCIATED_SERVER "associated_server"
+#!define AVP_ASSOCIATE_CONTACT "associate_contact"
+
+####### Global Parameters #########
+fork = yes
+children = 16
+#group =
+#user =
+server_signature = no
+server_header = "Server: Kazoo"
+user_agent_header = "User-Agent: Kazoo"
+shm_force_alloc = yes
+mlock_pages = yes
+phone2tel = 1
+max_while_loops = 500
+
+####### Logging Parameters #########
+debug = L_INFO
+memdbg = 10
+memlog = 10
+corelog = L_ERR
+log_stderror = no
+log_facility = LOG_LOCAL0
+log_name="kamailio"
+
+####### Alias Parameters #########
+auto_aliases = yes
+# alias = "mydomain.net"
+
+####### Binding Parameters #########
+listen = tcp:127.0.0.1:5060
+listen = udp:127.0.0.1:5060
+listen = tcp:127.0.0.1:5080
+listen = udp:127.0.0.1:5080
+listen = tcp:127.0.0.1:7000
+listen = udp:127.0.0.1:7000
+
+#listen = tcp:127.0.0.1:5065
+#listen = udp:127.0.0.1:5065
+tos = IPTOS_LOWDELAY
+
+####### TCP Parameters #########
+tcp_children = 25
+disable_tcp = no
+tcp_max_connections = 4096
+tcp_connection_lifetime = 3605
+tcp_accept_aliases = no
+tcp_async = yes
+tcp_connect_timeout = 10
+tcp_conn_wq_max = 65536
+tcp_crlf_ping = yes
+tcp_delayed_ack = yes
+tcp_fd_cache = yes
+tcp_keepalive = yes
+tcp_keepcnt = 3
+tcp_keepidle = 30
+tcp_keepintvl = 10
+tcp_linger2 = 30
+tcp_rd_buf_size = 4096
+tcp_send_timeout = 10
+tcp_wq_blk_size = 2100
+tcp_wq_max = 10485760
+
+####### UDP Parameters #########
+udp4_raw = -1
+udp4_raw_mtu = 1500
+
+####### DNS Parameters #########
+dns = no
+rev_dns = no
+dns_try_ipv6 = no
+use_dns_cache = on
+dns_cache_del_nonexp = no
+dns_cache_flags = 1
+dns_cache_gc_interval = 120
+dns_cache_init = 1
+dns_cache_mem = 1000
+dns_cache_negative_ttl = 60
+dns_try_naptr = no
+use_dns_failover = off
+dns_srv_lb = off
+
+####### TLS Parameters #########
+enable_tls = yes
+
+####### SCTP Parameters #########
+disable_sctp = yes
+
+####### Custom Parameters #########
+
+
+####### Modules Section ########
+mpath="/usr/local/lib64/kamailio/modules/"
+
+
+####### Flags #######
+flags
+ FLAG_INTERNALLY_SOURCED: 1,
+# FLAG_ITSP_SOURCED: 2,
+ FLAG_ASSOCIATE_SERVER: 3,
+ FLAG_SKIP_NAT_CORRECTION: 4;
+
+#!define FLB_NATB 6
+#!define FLB_NATSIPPING 7
+
+
+######## Kamailio core extensions module ########
+loadmodule "kex.so"
+
+######## Transaction (stateful) module ########
+loadmodule "tm.so"
+loadmodule "tmx.so"
+modparam("tm", "auto_inv_100", 1)
+modparam("tm", "auto_inv_100_reason", "Attempting to connect your call")
+modparam("tm", "cancel_b_method", 2)
+modparam("tm", "ruri_matching", 0)
+modparam("tm", "failure_reply_mode", 3)
+# modparam("tm", "fr_timer", 30000)
+# modparam("tm", "fr_inv_timer", 120000)
+
+######## Stateless replier module ########
+loadmodule "sl.so"
+
+######## Record-Route and Route module ########
+loadmodule "rr.so"
+modparam("rr", "enable_full_lr", 1)
+
+######## Max-Forward processor module ########
+loadmodule "maxfwd.so"
+
+######## SIP utilities [requires sl] ########
+loadmodule "siputils.so"
+
+######## SIP message formatting sanity checks [requires sl] ########
+loadmodule "sanity.so"
+# sip_version, scheme, req_headers, cseq_method/value
+# content_length, parse_uri, digest
+modparam("sanity", "default_checks", 3303)
+modparam("sanity", "uri_checks", 3)
+modparam("sanity", "autodrop", 0)
+
+######## Text operations module ########
+loadmodule "textops.so"
+loadmodule "textopsx.so"
+
+######## Path support for SIP loadbalancer ########
+loadmodule "path.so"
+modparam("path", "use_received", 0)
+
+######## Generic Hash Table container in shared memory ########
+loadmodule "htable.so"
+#modparam("htable", "htable", "associations=>size=14;")
+modparam("htable", "htable", "a=>size=10;")
+
+/*
+######## Memcached connector module ########
+loadmodule "memcached.so"
+modparam("memcached", "servers", "localhost:11211")
+modparam("memcached", "expire", 10800)
+modparam("memcached", "mode", 0)
+modparam("memcached", "timeout", 10000)
+*/
+
+######## Module holding Pseudo-Variables ########
+loadmodule "pv.so"
+
+######## Advanced logger module ########
+loadmodule "xlog.so"
+
+####### FIFO support for Management Interface ########
+loadmodule "mi_fifo.so"
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+####### Different config utilities ########
+loadmodule "cfgutils.so"
+
+####### Dispatcher Module Parameters ########
+loadmodule "dispatcher.so"
+modparam("dispatcher", "list_file", "/etc/kazoo/kamailio/dispatcher.list")
+modparam("dispatcher", "flags", 2)
+modparam("dispatcher", "use_default", 0)
+modparam("dispatcher", "force_dst", 1)
+modparam("dispatcher", "dst_avp", "$avp(ds_dst)")
+modparam("dispatcher", "attrs_avp", "$avp(ds_attrs)")
+modparam("dispatcher", "grp_avp", "$avp(ds_grp)")
+modparam("dispatcher", "cnt_avp", "$avp(ds_cnt)")
+modparam("dispatcher", "hash_pvar", "$avp(ds_grp)")
+# modparam("dispatcher", "setid_pvar", "$var(setid)")
+modparam("dispatcher", "ds_ping_method", "OPTIONS")
+modparam("dispatcher", "ds_ping_from", "sip:sipcheck@127.0.0.1")
+modparam("dispatcher", "ds_ping_interval", 10)
+# modparam("dispatcher", "ds_ping_sock", "udp:{{SIP_IP}}:{{SIP_PORT}}")
+modparam("dispatcher", "ds_probing_threshhold", 3)
+modparam("dispatcher", "ds_probing_mode", 1)
+modparam("dispatcher", "ds_ping_reply_codes", "501,403,404,400,200")
+
+######## Uac_redirect ########
+loadmodule "uac_redirect.so"
+
+
+####### db_kazoo registrar modules ##########
+loadmodule "db_kazoo.so"
+loadmodule "auth.so"
+loadmodule "auth_db.so"
+
+# ----- registrar modules -----
+loadmodule "usrloc.so"
+loadmodule "registrar.so"
+
+modparam("auth_db|usrloc", "db_url", "kazoo://guest:guest@127.0.0.1:5672/callmgr")
+modparam("auth_db", "use_domain", 1)
+modparam("auth_db", "version_table", 0)
+modparam("auth_db", "calculate_ha1", 1)
+modparam("auth_db", "password_column", "password")
+modparam("auth_db", "load_credentials", "$avp(password)=password")
+
+
+/* enable DB persistency for location entries */
+modparam("usrloc", "db_mode", 1)
+modparam("usrloc", "db_update_as_insert", 1)
+modparam("usrloc", "use_domain", 1)
+modparam("usrloc", "nat_bflag", FLB_NATB)
+
+
+######## NAT traversal module - signaling functions ########
+loadmodule "nathelper.so"
+modparam("nathelper|registrar", "received_avp", "$avp(AVP_RECV_PARAM)")
+modparam("nathelper", "natping_interval", 30)
+modparam("nathelper", "ping_nated_only", 1)
+modparam("nathelper", "natping_processes", 5)
+modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
+modparam("nathelper", "sipping_from", "sip:sipcheck@127.0.0.1")
+#modparam("nathelper", "natping_socket", "127.0.0.1:5060")
+
+
+####### Routing Logic ########
+route {
+ # log the basic info regarding this call
+ xlog("L_INFO", "$ci|start|recieved $oP request $rm $ou");
+ xlog("L_INFO", "$ci|log|source $si:$sp");
+ xlog("L_INFO", "$ci|log|from $fu");
+ xlog("L_INFO", "$ci|log|to $tu");
+
+ route(SANITY_CHECK);
+
+ route(SET_LOGGING_FLAGS);
+
+ route(CLASSIFY_SOURCE);
+
+ route(HANDLE_OPTIONS);
+
+ route(HANDLE_IN_DIALOG_REQUESTS);
+
+ route(PREPARE_INITIAL_REQUESTS);
+
+ if (isflagset(FLAG_INTERNALLY_SOURCED)) {
+ route(INTERNAL_TO_EXTERNAL_RELAY);
+ exit();
+ }
+
+ route(HANDLE_MOVE_REQUEST);
+
+ route(FIND_ROUTES);
+
+ $avp(route_attempts) = 1;
+ route(EXTERNAL_TO_INTERNAL_RELAY);
+}
+
+route[SANITY_CHECK] {
+ if (!mf_process_maxfwd_header("10")) {
+ xlog("L_WARN", "$ci|end|max-forward limit reached");
+ sl_send_reply("483", "Too Many Hops");
+ exit;
+ }
+
+ if (!sanity_check()) {
+ xlog("L_WARN", "$ci|end|message is insane");
+ exit;
+ }
+}
+
+route[SET_LOGGING_FLAGS] {
+ return();
+}
+
+route[CLASSIFY_SOURCE]
+{
+ if (ds_is_from_list("1") || ds_is_from_list("3"))
+ {
+ xlog("L_INFO", "$ci|log|originated from internal sources");
+
+ setflag(FLAG_INTERNALLY_SOURCED);
+ }
+ else
+ {
+ xlog("L_INFO", "$ci|log|originated from external sources");
+ }
+}
+
+/*
+route[CLASSIFY_SOURCE] {
+ switch($mct($si)) {
+ case "itsp":
+ xlog("L_INFO", "$ci|log|message is from ITSP");
+ setflag(FLAG_ITSP_SOURCED);
+ break;
+ case "kazoo":
+ xlog("L_INFO", "$ci|log|message is from KAZOO");
+ setflag(FLAG_INTERNALLY_SOURCED);
+ break;
+ default:
+ xlog("L_INFO", "$ci|log|message is from an unknown source");
+ break;
+ }
+}
+*/
+
+route[HANDLE_OPTIONS] {
+ if (is_method("OPTIONS")) {
+ if (isflagset(FLAG_INTERNALLY_SOURCED)) {
+ route(INTERNAL_TO_EXTERNAL_RELAY);
+ } else {
+ sl_send_reply("200", "Rawr!!");
+ }
+ exit;
+ }
+}
+
+# Called on in-dialog requests
+# If the request in an Invite for on hold from external to internal,
+# associate the contact with the media server
+route[MAYBE_ASSOCIATE_USER] {
+ # if Invite for on hold, we need to associate the contact URI with the next hop
+
+ if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) {
+ $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
+ xlog("L_INFO", "$ci|log|associate user $var(contact_uri):$si:$sp with media server $du\n");
+ $sht(associations=>$var(contact_uri))= $du;
+ }
+
+}
+
+route[HANDLE_IN_DIALOG_REQUESTS] {
+ if (has_totag()) {
+ if (loose_route()) {
+ xlog("L_INFO", "$ci|log|loose_route in-dialog message");
+
+ route(MAYBE_ASSOCIATE_USER);
+
+ route(RELAY);
+ } else if (isflagset(FLAG_INTERNALLY_SOURCED)) {
+ xlog("L_INFO", "$ci|log|relay internally sourced in-dialog message without loose_route");
+ if(is_method("INVITE")) {
+ xlog("L_INFO", "$ci|log|re-associate $ci with media server $si:$sp");
+ }
+ route(RELAY);
+ } else if (t_check_trans()) {
+ xlog("L_INFO", "$ci|log|allow message for a known transaction");
+ route(RELAY);
+ } else {
+ xlog("L_INFO", "$ci|log|message had a to-tag but can't be loose routed");
+ sl_send_reply("481", "Call Leg/Transaction Does Not Exist");
+ }
+ exit();
+ }
+}
+
+ route[PREPARE_INITIAL_REQUESTS] {
+ if (is_method("CANCEL")) {
+ if (t_check_trans()) {
+ route(RELAY);
+ } else {
+ sl_send_reply("481", "Call Leg/Transaction Does Not Exist");
+ }
+ exit();
+ } else if (is_method("ACK")) {
+ if (t_check_trans()) {
+ route(RELAY);
+ }
+ exit();
+ }
+
+ t_check_trans();
+
+ if (loose_route()) {
+ sl_send_reply("403", "No pre-loaded routes");
+ exit();
+ }
+
+ if (is_method("REGISTER")) {
+
+ if (nat_uac_test("3")) {
+ xlog("L_INFO", "Nated contact\n");
+# setflag(FLB_NATSIPPING);
+ force_rport();
+ setbflag(FLB_NATB);
+ setbflag(FLB_NATSIPPING);
+
+ fix_nated_register();
+ }
+ # authenticate requests
+ # check iif we have the password in cache
+ if ( is_present_hf("Authorization") ) {
+ if ( $sht(a=>$Au) != $null ) {
+ xlog("L_INFO", "Found stored password for $Au, $sht(a=>$Au)\n");
+ if (!pv_auth_check("$fd", "$sht(a=>$Au)", "0", "0")) {
+ xlog("L_INFO", "Authentication did not work with stored password\n");
+
+ ## RABBITMQ - Credentials fetch
+ if (!auth_check("$fd", "subscriber", "1")) {
+ auth_challenge("$fd", "0");
+ exit;
+ } else {
+ xlog("Credential fetch $avp(password)\n");
+ # xlog("au=$au, ad = $ad, aU=$aU, Au= $Au\n");
+ $sht(a=>$Au) = $avp(password);
+ }
+ }
+ } else {
+ ## RABBITMQ - Credentials fetch
+ if (!auth_check("$fd", "subscriber", "1")) {
+ auth_challenge("$fd", "0");
+ exit;
+ } else {
+ xlog("L_INFO", "Credential fetch $avp(password)\n");
+ # xlog("au=$Au, ad = $ad, aU=$aU, Au= $Au\n");
+ $sht(a=>$Au) = $avp(password);
+ }
+ }
+ } else {
+ auth_challenge("$fd", "0");
+ exit;
+ }
+
+
+ # user authenticated - remove auth header
+ consume_credentials();
+
+# if (!add_path_received()) {
+ # sl_send_reply("503", "Internal path befuddlement");
+ # # route(CLEANUP_DIALOG);
+ # exit();
+ # }
+
+ save("location");
+ exit;
+ /*
+ if (is_method("REGISTER")) {
+ if (!add_path_received()) {
+ sl_send_reply("503", "Internal path befuddlement");
+ # route(CLEANUP_DIALOG);
+ exit();
+ }
+ */
+ } else {
+ if (!is_method("MESSAGE"))
+ record_route();
+ }
+}
+
+# Take the routes from dispatcher - hash over callid
+# If prefered route defined, reorder the destionations
+route[FIND_ROUTES]
+{
+ if (is_method("REGISTER"))
+ {
+ # alg 2 = hash(To URI)
+ # To URI is actually AOR - to help with nounce reusage at reRegister
+ if (!ds_select_dst("3", "2") && !ds_select_dst("1", "2"))
+ {
+ xlog("L_ERR", "$ci|end|no servers avaliable");
+
+ sl_send_reply("480", "All servers busy");
+
+ exit;
+ }
+ }
+ else
+ {
+ # alg 0 = hash(Callid)
+ if (!ds_select_dst("1", "0"))
+ {
+ xlog("L_ERR", "$ci|end|no servers avaliable");
+
+ sl_send_reply("480", "All servers busy");
+
+ exit;
+ }
+
+ # Handle the case when a prefered route is set
+ $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
+
+ if ($sht(associations=>$var(contact_uri)) != $null)
+ {
+ $var(prefered_route) = $sht(associations=>$var(contact_uri));
+
+ xlog("L_INFO", "$ci|log|should route to $var(prefered_route)");
+
+ route(REORDER_ROUTES);
+ }
+
+ }
+}
+
+route[REORDER_ROUTES] {
+ # if the dispatcher list does not start with
+ # the the prefered route, reorder the list so that it does
+
+ if ($(avp(ds_dst)[0]) != $var(prefered_route))
+ {
+ # create a index var for our loop (arrays are start at 0 and this is a count)
+ $var(i) = $avp(ds_cnt) - 1;
+
+ # loop over the dispatcher list
+ while($var(i) > 0)
+ {
+ # if this element in the dispatch list is the same
+ # as the call destination
+ if($(avp(ds_dst)[$var(i)]) == $var(prefered_route))
+ {
+ # replace it with the first element of the list
+ $(avp(ds_dst)[$(var(i))]) = $(avp(ds_dst)[0]);
+
+ # break out of the loop
+ $var(i) = -1;
+ }
+
+ $var(i) = $var(i) - 1;
+ }
+
+ # handles the case were we only have two servers
+ # and the one that we are locked to has failed
+ if ($var(i) >= 0)
+ {
+
+ xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd");
+
+ $sht(associations=>$var(contact_uri)) = "sip:$rd:$rp";
+
+ xlog("L_INFO", "$ci|log|associated contact $var(contact_uri) with media server sip:$rd:$rp");
+ }
+ # the server we are locked to is in the active server list from then
+ # dispatcher so re-arrange the list to try it first
+ else
+ {
+ xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first");
+
+ # set the first element of the list to the destination
+ $(avp(ds_dst)[0]) = $var(prefered_route);
+
+ # set the domain for this request (server IP to route to)
+ $rd = $(var(prefered_route){uri.host});
+
+ # set the port for this request (server IP to route to)
+ $rp = $(var(prefered_route){uri.port});
+ }
+ }
+}
+
+
+
+
+route[HANDLE_MOVE_REQUEST]
+{
+ if (is_method("INVITE") && $rU == "*6683*" && $sht(associations=>$var(contact_uri)) != $null )
+ {
+ $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
+
+ xlog("L_INFO", "$ci|log|remove association for user $var(contact_uri):$si:$sp
+ with media server $sht(associations=>$var(contact_uri))\n");
+
+ $sht(associations=>$var(contact_uri))= $null;
+
+ # TODO - does the test expect smth like $rd:$rp as reason?
+ send_reply("503", "Removed association");
+
+ exit;
+ }
+}
+
+route[RELAY] {
+# if (is_method("CANCEL") || is_method("BYE")) {
+# route(CLEANUP_DIALOG);
+# }
+
+ if (isflagset(FLAG_INTERNALLY_SOURCED)) {
+ route(INTERNAL_TO_EXTERNAL_RELAY);
+ } else {
+ route(EXTERNAL_TO_INTERNAL_RELAY);
+ }
+
+ exit();
+}
+
+route[INTERNAL_TO_EXTERNAL_RELAY] {
+ remove_hf("X-AUTH-IP");
+
+ t_on_reply("EXTERNAL_REPLY");
+
+ t_set_fr(0, 10000);
+
+ route(LOG_DESTINATION);
+
+# xlog("L_INFO", "$ci|log|associate call-id $ci with sip:$sip:$sp");
+# $sht(associations=>$ci) = "sip:" + $si + ":" + $sp;
+
+ t_relay();
+}
+
+route[EXTERNAL_TO_INTERNAL_RELAY] {
+ if (!isflagset(FLAG_INTERNALLY_SOURCED)) {
+ route(NAT_TEST_AND_CORRECT);
+ }
+
+ remove_hf("X-AUTH-IP");
+ append_hf("X-AUTH-IP: $si\r\n");
+
+ t_on_reply("INTERNAL_REPLY");
+ t_on_failure("INTERNAL_FAULT");
+
+ t_set_fr(0, 1000);
+
+ route(LOG_DESTINATION);
+
+ t_relay();
+}
+
+
+
+route[LOG_DESTINATION] {
+ if (isdsturiset()) {
+ $var(port) = $dp;
+ $var(domain) = $dd;
+ } else {
+ $var(port) = $rp;
+ $var(domain) = $rd;
+ }
+
+ if ($(var(port){s.len}) <= 0) {
+ $var(port) = "5060";
+ }
+
+ xlog("L_INFO", "$ci|pass|$var(domain):$var(port)");
+}
+
+route[NAT_TEST_AND_CORRECT] {
+ if (is_present_hf("Record-Route")) {
+ $var(i) = $rr_count;
+ while($var(i) > 0) {
+ $var(i) = $var(i) - 1;
+ $var(rr) = $(hdr(Record-Route)[$var(i)]);
+ if (!is_myself("$(var(rr){nameaddr.uri})")) {
+ setflag(FLAG_SKIP_NAT_CORRECTION);
+ }
+ }
+ } else if ($Rp == "5080") {
+ setflag(FLAG_SKIP_NAT_CORRECTION);
+ }
+
+ if (isflagset(FLAG_SKIP_NAT_CORRECTION)) {
+ return();
+ }
+
+ if (nat_uac_test("3")) {
+ force_rport();
+ fix_nated_contact();
+ }
+
+ if (has_body("application/sdp") && nat_uac_test("8")) {
+ fix_nated_sdp("10");
+ }
+}
+
+onreply_route[EXTERNAL_REPLY] {
+ xlog("L_INFO", "$ci|log|external reply $T_reply_code");
+
+ route(NAT_TEST_AND_CORRECT);
+
+# if (is_method("INVITE") && t_check_status("200")) {
+# $var(user) = $(ct{tobody.user}) + "@" + $(ct{tobody.host});
+# xlog("L_INFO", "$ci|log|associate user $var(user):$si:$sp with media server");
+# $sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER);
+# }
+
+}
+
+
+onreply_route[INTERNAL_REPLY]
+{
+ # this route handles replies that are comming from our media server
+ xlog("L_INFO", "$ci|start|recieved internal reply $T_reply_code $rr");
+ xlog("L_INFO", "$ci|log|source $si:$sp");
+
+ if ($rs < 300)
+ {
+ xlog("L_INFO", "$ci|pass|$T_req($si):$T_req($sp)");
+ }
+
+ # change 6xx to 4xx
+ if (t_check_status("6[0-9][0-9]"))
+ {
+ $var(new_code) = "4" + $(T_reply_code{s.substr,1,0});
+ change_reply_status("$var(new_code)", "$rr");
+ }
+
+}
+
+failure_route[INTERNAL_FAULT]
+{
+ # this branch handles failures (>=300) to our media servers,
+ # which we can sometimes overcome by routing to another server
+
+ # if the failure cause was due to the transaction being
+ # cancelled then we are complete
+ if (t_is_canceled())
+ {
+ xlog("L_INFO", "$ci|log|transaction was cancelled");
+
+ exit;
+ }
+
+ # if the failure case was something that we should recover
+ # from then try to find a new media server
+ if (t_check_status("(401)|(407)"))
+ {
+ xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $rr");
+
+ exit;
+ }
+ else if (t_check_status("403"))
+ {
+ xlog("L_INFO", "$ci|log|failure route overriding reply code 403 with 503");
+
+ xlog("L_INFO", "$ci|pass|$si:$sp");
+
+ send_reply("503", "Error: Services Unavailable. Try Later");
+
+ exit;
+ }
+ else if (t_check_status("402"))
+ {
+ xlog("L_INFO", "$ci|log|failure route overriding reply code 402 with 486");
+
+ xlog("L_INFO", "$ci|pass|$si:$sp");
+
+ send_reply("486", "Insufficient Funds");
+
+ exit;
+ }
+ else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])"))
+ {
+ xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $rr");
+
+ # try to find a new media server to send the call to
+ if ($avp(route_attempts) < 3 && ds_next_domain())
+ {
+ xlog("L_INFO", "$ci|log|attempting retry $avp(route_attempts) of failed request");
+ xlog("L_INFO", "$ci|log|routing call to next media server $rd:$rp");
+
+ # reset the final reply timer
+ $avp(final_reply_timer) = 3;
+
+ t_on_reply("INTERNAL_REPLY");
+
+ t_on_failure("INTERNAL_FAULT");
+
+ # relay the request to the new media server
+ route(EXTERNAL_TO_INTERNAL_RELAY);
+
+ $avp(route_attempts) = $avp(route_attempts) + 1;
+ }
+ else if (t_check_status("404"))
+ {
+ xlog("L_ERR", "$ci|log|no other media servers avaliable, sending 486");
+
+ send_reply("486", "Not found");
+
+ exit;
+ }
+ else
+ {
+ xlog("L_ERR", "$ci|log|no other media servers avaliable");
+
+ exit;
+ }
+ }
+ else if (t_check_status("302"))
+ {
+ ## TODO - test this
+ get_redirects("*");
+
+ route(EXTERNAL_TO_INTERNAL_RELAY);
+
+ /*
+ if( $(hdr(X-Redirect-Server)) && $(ct.fields(uri)) )
+ {
+ $var(redirect_host) = $(hdr(X-Redirect-Server){uri.host});
+
+ $var(redirect_port) = $(hdr(X-Redirect-Server){uri.port});
+
+ cache_store("local", "$(ct.fields(uri))", "sip:$var(redirect_host):$var(redirect_port)", 60);
+
+ xlog("L_INFO", "$ci|log|stored redirect mapping for $(ct.fields(uri)) to sip:$var(redirect_host):$var(redirect_port)");
+
+ remove_hf("X-Redirect-Server");
+ }
+ */
+ }
+ else
+ {
+ xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $rr");
+
+ exit;
+ }
+
+ route(LOG_DESTINATION);
+}
+
+onsend_route {
+ xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)");
+}
+
+
+## Not used routes
+/*
+# Take the routes from memcached
+# Write them in an AVP
+# Randomize
+route[LOAD_KAZOO_ROUTES] {
+ $var(routes) = $mct(available_kazoo_routes);
+ route(LOAD_ROUTES);
+
+ $var(randomizer_pos) = $avp(AVP_ROUTE_CNT);
+ route(RANDOMIZE_ROUTES);
+
+ if (!isflagset(FLAG_ITSP_SOURCED) && is_method("REGISTER|INVITE|SUBSCRIBE")) {
+ setflag(FLAG_ASSOCIATE_SERVER);
+ }
+}
+
+route[LOAD_ROUTES] {
+ if ($var(routes) == $null) {
+ return(-1);
+ }
+
+ $var(i) = 0;
+ $var(route) = $(var(routes){s.select,$var(i),;});
+ while($(var(route){s.len}) > 0) {
+ $var(i) = $var(i) + 1;
+ $avp($var(i)) = $var(route);
+ $var(route) = $(var(routes){s.select,$var(i),;});
+ }
+ $avp(AVP_ROUTE_CNT) = $var(i);
+
+ return(1);
+}
+
+# No longer used
+route[NEXT_ROUTE] {
+ if ($avp(AVP_ROUTE_CNT) <= 0) {
+ return(-1);
+ }
+
+ $var(domain) = $(avp($avp(AVP_ROUTE_CNT)){uri.host});
+ $var(port) = $(avp($avp(AVP_ROUTE_CNT)){uri.port});
+
+ $avp(AVP_ROUTE_CNT) = $avp(AVP_ROUTE_CNT) - 1;
+
+ if ($(var(domain){s.len}) <= 0) {
+ route(NEXT_ROUTE);
+ }
+
+ if ($(var(port){s.len}) <= 4) {
+ $var(port) = "5060";
+ }
+
+ $du = "sip:" + $var(domain) + ":" + $var(port);
+
+ xlog("L_INFO", "$ci|log|associate call-id $ci with $du");
+ $sht(associations=>$ci) = $du;
+
+ return(1);
+}
+
+route[RANDOMIZE_ROUTES] {
+ if ($var(randomizer_pos) <= 0) {
+ return();
+ }
+
+ $var(random_pos) = ($RANDOM mod $var(randomizer_pos) + 1);
+
+ if ($var(random_pos) != $var(randomizer_pos)) {
+ $var(route) = $avp($var(randomizer_pos));
+ $avp($var(randomizer_pos)) = $avp($var(random_pos));
+ $avp($var(random_pos)) = $var(route);
+ }
+
+ $var(randomizer_pos) = $var(randomizer_pos) - 1;
+ route(RANDOMIZE_ROUTES);
+}
+
+route[LOG_ROUTES] {
+ $var(i) = $avp(AVP_ROUTE_CNT);
+ while($var(i) > 0) {
+ $var(value) = $avp($var(i));
+ xlog("L_INFO", "$ci|log|route $var(i): $var(value)");
+ $var(i) = $var(i) - 1;
+ }
+}
+
+route[CLEANUP_DIALOG] {
+ xlog("L_INFO", "$ci|log|remove any association for $ci");
+ sht_rm_name_re("associations=>$ci");
+ return();
+}
+
+route[MAYBE_ASSOCIATE_SERVER] {
+ if (isflagset(FLAG_ASSOCIATE_SERVER) && defined $avp(AVP_ASSOCIATED_SERVER)) {
+ xlog("L_INFO", "$ci|log|associate call-id $ci with $avp(AVP_ASSOCIATED_SERVER)");
+ $sht(associations=>$ci) = $avp(AVP_ASSOCIATED_SERVER);
+
+ if (is_method("INVITE")) {
+ $var(user) = $(ct{tobody.user}) + "@" + $si;
+ xlog("L_INFO", "$ci|log|associate user $var(user) with $avp(AVP_ASSOCIATED_SERVER)");
+ $sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER);
+ }
+ }
+}
+*/
+## vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
diff --git a/rabbitmq/enabled_plugins b/rabbitmq/enabled_plugins
new file mode 100644
index 0000000..352dfc4
--- /dev/null
+++ b/rabbitmq/enabled_plugins
@@ -0,0 +1 @@
+[rabbitmq_management].
diff --git a/rabbitmq/rabbitmq-env.conf b/rabbitmq/rabbitmq-env.conf
new file mode 100644
index 0000000..0b46f76
--- /dev/null
+++ b/rabbitmq/rabbitmq-env.conf
@@ -0,0 +1,5 @@
+NODENAME=rabbit
+NODE_IP_ADDRESS=0.0.0.0
+NODE_PORT=5672
+LOG_BASE=/var/log/rabbitmq
+MNESIA_BASE=/var/lib/rabbitmq/mnesia