[sr-dev] git:master: presence Add RPC command presence.cleanup

Olle E. Johansson oej at edvina.net
Sat Mar 2 09:41:49 CET 2013


Module: sip-router
Branch: master
Commit: 68094dd3639d1f4cc497e4affb1a89909947c7b3
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=68094dd3639d1f4cc497e4affb1a89909947c7b3

Author: Olle E. Johansson <oej at edvina.net>
Committer: Olle E. Johansson <oej at edvina.net>
Date:   Sat Mar  2 09:41:18 2013 +0100

presence Add RPC command presence.cleanup

---

 modules/presence/README                 |   70 ++++++++++++++++++++-----------
 modules/presence/doc/presence_admin.xml |   19 ++++++++
 modules/presence/presence.c             |   41 ++++++++++++++++++
 3 files changed, 106 insertions(+), 24 deletions(-)

diff --git a/modules/presence/README b/modules/presence/README
index 1c202a8..f8681e4 100644
--- a/modules/presence/README
+++ b/modules/presence/README
@@ -16,9 +16,9 @@ Edited by
 
 Juha Heinanen
 
-   Copyright © 2006 Voice Sistem SRL
+   Copyright © 2006 Voice Sistem SRL
 
-   Copyright © 2009 Juha Heinanen
+   Copyright © 2009 Juha Heinanen
      __________________________________________________________________
 
    Table of Contents
@@ -70,7 +70,11 @@ Juha Heinanen
               5.1. refreshWatchers
               5.2. cleanup
 
-        6. Installation
+        6. RPC Commands
+
+              6.1. presence.cleanup
+
+        7. Installation
 
    2. Developer Guide
 
@@ -170,7 +174,11 @@ Chapter 1. Admin Guide
         5.1. refreshWatchers
         5.2. cleanup
 
-   6. Installation
+   6. RPC Commands
+
+        6.1. presence.cleanup
+
+   7. Installation
 
 1. Overview
 
@@ -245,19 +253,19 @@ Chapter 1. Admin Guide
    If set, the module is a fully operational presence server. Otherwise,
    it is used as a 'library', for its exported functions.
 
-   Default value is “NULL”.
+   Default value is "NULL".
 
    Example 1.1. Set db_url parameter
 ...
 modparam("presence", "db_url",
-        "mysql://openser:openserrw@localhost/openser")
+        "mysql://kamailio:kamailiorw@localhost/kamailio")
 ...
 
 3.2. presentity_table(str)
 
    The name of the db table where PUBLISH presence information is stored.
 
-   Default value is “presentity”.
+   Default value is "presentity".
 
    Example 1.2. Set presentity_table parameter
 ...
@@ -269,7 +277,7 @@ modparam("presence", "presentity_table", "presentity")
    The name of the db table where active subscription information is
    stored.
 
-   Default value is “active_watchers”.
+   Default value is "active_watchers".
 
    Example 1.3. Set active_watchers_table parameter
 ...
@@ -280,7 +288,7 @@ modparam("presence", "active_watchers_table", "active_watchers")
 
    The name of the db table where subscription states are stored.
 
-   Default value is “watchers”.
+   Default value is "watchers".
 
    Example 1.4. Set watchers_table parameter
 ...
@@ -292,7 +300,7 @@ modparam("presence", "watchers_table", "watchers")
    The period in seconds between checks if there are expired messages
    stored in database.
 
-   Default value is “100”. A zero or negative value disables this
+   Default value is "100". A zero or negative value disables this
    activity.
 
    Example 1.5. Set clean_period parameter
@@ -305,7 +313,7 @@ modparam("presence", "clean_period", 100)
    The period at which to synchronize cached subscriber info with the
    database.
 
-   Default value is “100”. A zero or negative value disables
+   Default value is "100". A zero or negative value disables
    synchronization.
 
    Example 1.6. Set db_update_period parameter
@@ -323,7 +331,7 @@ modparam("presence", "db_update_period", 100)
    than 0. When notifier_processes is less than or equal to 0 NOTIFY
    requests are sent immediately.
 
-   Default value is “5”.
+   Default value is "5".
 
    Example 1.7. Set waitn_time parameter
 ...
@@ -340,7 +348,7 @@ modparam("presence", "waitn_time", 10)
    Separate notifier processes are only run when subs_db_mode is 3 (DB
    only mode).
 
-   Default value is “10”.
+   Default value is "10".
 
    Example 1.8. Set notifier_poll_rate parameter
 ...
@@ -360,7 +368,7 @@ modparam("presence", "notifier_poll_rate", 20)
    NOTIFY requests can be sent on a dialog at the same time, there are
    race conditions which result in CSeq re-use.
 
-   Default value is “1”.
+   Default value is "1".
 
    Example 1.9. Set notifier_processes parameter
 ...
@@ -372,7 +380,7 @@ modparam("presence", "notifier_processes", 2)
    The prefix used when generating to_tag when sending replies for
    SUBSCRIBE requests.
 
-   Default value is “10”.
+   Default value is "10".
 
    Example 1.10. Set to_tag_pref parameter
 ...
@@ -385,7 +393,7 @@ modparam("presence", "to_tag_pref", 'pres')
    when sending a 200OK for a publish. It is used for forcing the client
    to send an update before the old publish expires.
 
-   Default value is “0”.
+   Default value is "0".
 
    Example 1.11. Set expires_offset parameter
 ...
@@ -397,7 +405,7 @@ modparam("presence", "expires_offset", 10)
    The the maximum admissible expires value for PUBLISH/SUBSCRIBE message
    (in seconds).
 
-   Default value is “3600”.
+   Default value is "3600".
 
    Example 1.12. Set max_expires parameter
 ...
@@ -468,7 +476,7 @@ modparam("presence", "subs_db_mode", 1)
    database or there are other external entities inserting data into the
    presentity table.
 
-   Default value is “1”.
+   Default value is "1".
 
    Example 1.15. Set publ_cache parameter
 ...
@@ -481,7 +489,7 @@ modparam("presence", "publ_cache", 0)
    This parameter will be used as the power of 2 when computing table
    size.
 
-   Default value is “9 (512)”.
+   Default value is "9 (512)".
 
    Example 1.16. Set subs_htable_size parameter
 ...
@@ -493,7 +501,7 @@ modparam("presence", "subs_htable_size", 11)
    The size of the in-memory hash table to store publish records. This
    parameter will be used as the power of 2 when computing table size.
 
-   Default value is “9 (512)”.
+   Default value is "9 (512)".
 
    Example 1.17. Set pres_htable_size parameter
 ...
@@ -508,7 +516,7 @@ modparam("presence", "pres_htable_size", 11)
    empty NOTIFY to an message-summary event. This parameter is enabled by
    default, thus addering to the standard.
 
-   Default value is “1 ”.
+   Default value is "1 ".
 
    Example 1.18. Set send_fast_notify parameter
 ...
@@ -523,7 +531,7 @@ modparam("presence", "send_fast_notify", 0)
    this check requires extra processing that should be avoided if this
    feature is not supported by the clients.
 
-   Default value is “0 ”.
+   Default value is "0 ".
 
    Example 1.19. Set enable_sphere_check parameter
 ...
@@ -538,7 +546,7 @@ modparam("presence", "enable_sphere_check", 1)
    on. Disabling this will keep subscriptions active on unreliable
    networks.
 
-   Default value is “1”.
+   Default value is "1".
 
    Example 1.20. Set timeout_rm_subs parameter
 ...
@@ -740,7 +748,21 @@ pres_update_watchers("sip:test at kamailio.org", "presence");
                 :cleanup:fifo_reply
                 _empty_line_
 
-6. Installation
+6. RPC Commands
+
+   6.1. presence.cleanup
+
+6.1.  presence.cleanup
+
+   Manually triggers the cleanup functions for the active_watchers,
+   presentity, and watchers tables. Useful if you have set clean_period
+   and/or db_update_period to zero or less.
+
+   Name: presence.cleanup
+
+   Parameters: none
+
+7. Installation
 
    The module requires 3 tables in the Kamailio database: "presentity",
    "active_watchers" and "watchers". The SQL syntax to create them can be
diff --git a/modules/presence/doc/presence_admin.xml b/modules/presence/doc/presence_admin.xml
index b2fcf6e..02b3562 100644
--- a/modules/presence/doc/presence_admin.xml
+++ b/modules/presence/doc/presence_admin.xml
@@ -902,6 +902,25 @@ pres_update_watchers("sip:test at kamailio.org", "presence");
 </section>
 
 <section>
+	<title>RPC Commands</title>
+	<section>
+	  <title>
+		<function moreinfo="none">presence.cleanup</function>
+	  </title>
+	  <para>
+		Manually triggers the cleanup functions for the active_watchers, presentity,
+		and watchers tables. Useful if you have set <varname>clean_period</varname>
+		and/or <varname>db_update_period</varname> to zero or less.
+	  </para>
+	  <para>
+		Name: <emphasis>presence.cleanup</emphasis>
+	  </para>
+	  <para>Parameters: <emphasis>none</emphasis></para>
+
+	</section>
+</section>
+
+<section>
 	<title>Installation</title>
 	<para>
 	The module requires 3 tables in the &kamailio; database: "presentity",
diff --git a/modules/presence/presence.c b/modules/presence/presence.c
index ed7f4d1..067a1e1 100644
--- a/modules/presence/presence.c
+++ b/modules/presence/presence.c
@@ -73,6 +73,8 @@
 #include "notify.h"
 #include "../../mod_fix.h"
 #include "../../timer_proc.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
 
 MODULE_VERSION
 
@@ -127,6 +129,7 @@ static int w_pres_update_watchers(struct sip_msg *msg, char *puri,
 		char *pevent);
 static int fixup_refresh_watchers(void** param, int param_no);
 static int fixup_update_watchers(void** param, int param_no);
+static int presence_init_rpc(void);
 
 int counter =0;
 int pid = 0;
@@ -231,6 +234,11 @@ static int mod_init(void)
 		LM_ERR("failed to register MI commands\n");
 		return -1;
 	}
+	if(presence_init_rpc()!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
 
 	db_url.len = db_url.s ? strlen(db_url.s) : 0;
 	LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,db_url.s);
@@ -1780,4 +1788,37 @@ static int fixup_update_watchers(void** param, int param_no)
 		return fixup_spve_null(param, 1);
 	}
 	return 0;
+
+}
+
+void rpc_presence_cleanup(rpc_t* rpc, void* c)
+{
+	LM_DBG("rpc_presence_cleanup:start\n");
+
+	(void) msg_watchers_clean(0,0);
+	(void) msg_presentity_clean(0,0);
+	(void) timer_db_update(0,0);
+		
+	rpc->printf(c, "Reload OK");
+	return;
+}
+
+static const char* rpc_presence_cleanup_doc[2] = {
+	"Manually triggers the cleanup functions for the active_watchers, presentity, and watchers tables.",
+	0
+};
+
+rpc_export_t presence_rpc[] = {
+	{"presence.cleanup", rpc_presence_cleanup, rpc_presence_cleanup_doc, 0},
+	{0, 0, 0, 0}
+};
+
+static int presence_init_rpc(void)
+{
+	if (rpc_register_array(presence_rpc)!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+	return 0;
 }




More information about the sr-dev mailing list