diff --git a/kamailio/custom-init.cfg b/kamailio/custom-init.cfg new file mode 100644 index 0000000..e4096a1 --- /dev/null +++ b/kamailio/custom-init.cfg @@ -0,0 +1,16 @@ + +#!ifdef PRESENCE_ROLE + +######## async operations module ######## +loadmodule "async.so" +modparam("async", "workers", 5) + + +event_route[core:worker-one-init] +{ +// t_newtran(); + async_route("PRESENCE_INITIAL_CLEANUP", "20"); +// t_drop(); +## route(PRESENCE_INITIAL_CLEANUP); +} +#!endif diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql new file mode 100644 index 0000000..5e9c9c5 --- /dev/null +++ b/kamailio/db_scripts/db_extra_check.sql @@ -0,0 +1,23 @@ + +do_db_extra_check() { + +# location +KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" +KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" + +## presence +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('terminated','available'));" +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers_log where id in(select id from active_watchers_log a where not exists(select callid from active_watchers b where b.callid = a.callid and b.watcher_username = a.watcher_username and b.watcher_domain = a.watcher_domain));" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities a where not exists(select * from active_watchers where presentity_uri = a.presentity_uri));" + +## notify watchers of pending calls +## 'create temp table as' because it will be dropped as soon as we ended the session +KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" +KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct b.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri where state in('early', 'confirmed', 'onthephone', 'busy');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" + +} diff --git a/kamailio/presence-custom-cleanup.cfg b/kamailio/presence-custom-cleanup.cfg new file mode 100644 index 0000000..91f6078 --- /dev/null +++ b/kamailio/presence-custom-cleanup.cfg @@ -0,0 +1,15 @@ + +route[PRESENCE_INITIAL_CLEANUP] +{ + xlog("L_INFO", "processing presence initial cleanup\n"); + if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) + { + while($xavp(ra) != $null) { + xlog("L_WARNING", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); + pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); + pv_unset("$xavp(ra)"); + } + } +// t_release(); +// t_drop(); +}