pua: added pua.cleanup rpc command
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 2 Jan 2017 14:21:48 +0000 (15:21 +0100)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 2 Jan 2017 14:33:29 +0000 (15:33 +0100)
- removed mi command

src/modules/pua/Makefile
src/modules/pua/doc/pua_admin.xml
src/modules/pua/pua.c

index c6e7c57..ae94262 100644 (file)
@@ -21,6 +21,5 @@ endif
 DEFS+=-DKAMAILIO_MOD_INTERFACE
 
 SERLIBPATH=../../lib
-SER_LIBS+=$(SERLIBPATH)/kmi/kmi
 SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
 include ../../Makefile.modules
index 09fe52a..8df2c27 100644 (file)
 <!-- Module User's Guide -->
 
 <chapter>
-       
+
        <title>&adminguide;</title>
-       
+
        <section>
        <title>Overview</title>
        <para>
                This module offer the functionality of a presence user agent client,
-               sending SUBSCRIBE and PUBLISH SIP  messages. It's a core part of &kamailio;'s 
+               sending SUBSCRIBE and PUBLISH SIP  messages. It's a core part of &kamailio;'s
                SIP presence package, implementing SIMPLE and various shared line appearance
                implementations.
        </para>
@@ -30,8 +30,8 @@
                 elementary presence information, such as basic status "open" or "closed",
                 for clients that do not implement client-to-server presence.
                 Through <emphasis>pua_bla</emphasis> , BRIDGED LINE APPEARANCE features are added to &kamailio;
-                The <emphasis>pua_xmpp</emphasis> module represents a gateway between SIP and XMPP, so that 
-                jabber and SIP clients can exchange presence information. 
+                The <emphasis>pua_xmpp</emphasis> module represents a gateway between SIP and XMPP, so that
+                jabber and SIP clients can exchange presence information.
                 The <emphasis>pua_reginfo</emphasis> modules presents registration information from the usrloc module
                 using the reginfo event package.
        </para>
@@ -401,26 +401,27 @@ if(method=="NOTIFY")
 </section>
 
 <section>
-       <title>MI Commands</title>
-       <section>
+       <title>RPC Commands</title>
+       <section id="pua.r.cleanup">
          <title>
-               <function moreinfo="none">pua_cleanup</function>
+               <function moreinfo="none">pua.cleanup</function>
          </title>
          <para>
                Manually triggers the cleanup functions for the pua table.
                Useful if you have set <varname>update_period</varname> to zero or less.
          </para>
          <para>
-               Name: <emphasis>pua_cleanup</emphasis>
+               Name: <emphasis>pua.cleanup</emphasis>
          </para>
          <para>Parameters: <emphasis>none</emphasis></para>
 
          <para>
-               MI FIFO Command Format:
+               RPC Command Format:
          </para>
          <programlisting  format="linespecific">
-               :pua_cleanup:fifo_reply
-               _empty_line_
+...
+&kamcmd; pua.cleanup
+...
          </programlisting>
        </section>
 </section>
index 52fe654..360ba2d 100644 (file)
@@ -36,8 +36,9 @@
 #include "../../core/str.h"
 #include "../../core/mem/mem.h"
 #include "../../core/pt.h"
+#include "../../core/rpc.h"
+#include "../../core/rpc_lookup.h"
 #include "../../lib/srdb1/db.h"
-#include "../../lib/kmi/mi.h"
 #include "../../modules/tm/tm_load.h"
 #include "pua.h"
 #include "send_publish.h"
@@ -101,9 +102,7 @@ static str str_version_col = str_init("version");
 
 static int mod_init(void);
 static int child_init(int);
-static int mi_child_init(void);
 static void destroy(void);
-static struct mi_root* mi_cleanup(struct mi_root* cmd, void* param);
 
 static ua_pres_t* build_uppubl_cbparam(ua_pres_t* p);
 
@@ -111,6 +110,8 @@ static int db_restore(void);
 static void db_update(unsigned int ticks,void *param);
 static void hashT_clean(unsigned int ticks,void *param);
 
+static int pua_rpc_init(void);
+
 static cmd_export_t cmds[]=
 {
        {"bind_libxml_api",          (cmd_function)bind_libxml_api, 1, 0, 0, 0},
@@ -136,11 +137,6 @@ static param_export_t params[]={
        {0,                          0,         0}
 };
 
-static mi_export_t mi_cmds[] = {
-       { "pua_cleanup",        mi_cleanup,             0,  0,  mi_child_init},
-       { 0,                    0,                      0,  0,  0}
-};
-
 /** module exports */
 struct module_exports exports= {
        "pua",                          /* module name */
@@ -148,7 +144,7 @@ struct module_exports exports= {
        cmds,                           /* exported functions */
        params,                         /* exported parameters */
        0,                              /* exported statistics */
-       mi_cmds,                        /* exported MI functions */
+       0,                              /* exported MI functions */
        0,                              /* exported pseudo-variables */
        0,                              /* extra processes */
        mod_init,                       /* module initialization function */
@@ -164,18 +160,16 @@ static int mod_init(void)
 {
        LM_DBG("...\n");
 
-       if (register_mi_mod(exports.name, mi_cmds)!=0)
-       {
-               LM_ERR("failed to register MI commands\n");
-               return -1;
-       }
-
        if(min_expires< 0)
                min_expires= 0;
 
        if(default_expires< 600)
                default_expires= 3600;
 
+       if(pua_rpc_init()<0) {
+               LM_ERR("failed to register RPC commands\n");
+               return -1;
+       }
        /* load TM API */
        if(load_tm_api(&tmb)==-1)
        {
@@ -321,35 +315,6 @@ static int child_init(int rank)
        return 0;
 }
 
-static int mi_child_init(void)
-{
-       if (pua_dbf.init==0)
-       {
-               LM_CRIT("database not bound\n");
-               return -1;
-       }
-       /* In DB only mode do not pool the connections where possible. */
-       if (dbmode == PUA_DB_ONLY && pua_dbf.init2)
-               pua_db = pua_dbf.init2(&db_url, DB_POOLING_NONE);
-       else
-               pua_db = pua_dbf.init(&db_url);
-       if (!pua_db)
-       {
-               LM_ERR("connecting to database failed\n");
-               return -1;
-       }
-
-       if (pua_dbf.use_table(pua_db, &db_table) < 0)
-       {
-               LM_ERR("Error in use_table pua\n");
-               return -1;
-       }
-
-       LM_DBG("Database connection opened successfully\n");
-
-       return 0;
-}
-
 static void destroy(void)
 {
        if (puacb_list)
@@ -1240,11 +1205,29 @@ static ua_pres_t* build_uppubl_cbparam(ua_pres_t* p)
        return cb_param;
 }
 
-static struct mi_root* mi_cleanup(struct mi_root* cmd, void *param)
+static void  pua_rpc_cleanup(rpc_t* rpc, void* ctx)
 {
-       LM_DBG("mi_cleanup:start\n");
+       LM_DBG("cleaning up\n");
 
        (void)hashT_clean(0,0);
+}
+
+static const char* pua_rpc_cleanup_doc[2] = {
+       "Execute pua cleanup.",
+       0
+};
+
+rpc_export_t pua_rpc[] = {
+       {"pua.cleanup", pua_rpc_cleanup, pua_rpc_cleanup_doc, 0},
+       {0, 0, 0, 0}
+};
 
-       return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+static int pua_rpc_init(void)
+{
+       if (rpc_register_array(pua_rpc)!=0)
+       {
+               LM_ERR("failed to register RPC commands\n");
+               return -1;
+       }
+       return 0;
 }