Module: sip-router
Branch: master
Commit: d0d298070fdbb015a96f209fa3c925ba71e3a37b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d0d2980…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Mon May 27 13:54:23 2013 +0300
modules/usrloc: added two new rpc commands ul.users and ul.contacts
- for accessing number of different AoRs and contacts in a location table
---
modules/usrloc/README | 22 +++++++
modules/usrloc/doc/usrloc_admin.xml | 31 ++++++++++
modules/usrloc/ul_rpc.c | 111 +++++++++++++++++++++++++++++++++++
3 files changed, 164 insertions(+), 0 deletions(-)
diff --git a/modules/usrloc/README b/modules/usrloc/README
index 05b8535..02227b0 100644
--- a/modules/usrloc/README
+++ b/modules/usrloc/README
@@ -87,6 +87,8 @@ Bogdan-Andrei Iancu
6.4. ul.rm_contact table AOR contact
6.5. ul.flush
6.6. ul.add
+ 6.7. ul.users
+ 6.8. ul.contacts
7. Statistics
@@ -221,6 +223,8 @@ Chapter 1. Admin Guide
6.4. ul.rm_contact table AOR contact
6.5. ul.flush
6.6. ul.add
+ 6.7. ul.users
+ 6.8. ul.contacts
7. Statistics
@@ -836,6 +840,8 @@ modparam("usrloc", "db_ops_ruid", 1)
6.4. ul.rm_contact table AOR contact
6.5. ul.flush
6.6. ul.add
+ 6.7. ul.users
+ 6.8. ul.contacts
6.1. ul.dump
@@ -892,6 +898,22 @@ modparam("usrloc", "db_ops_ruid", 1)
* cflags - per branch flags of the contact
* methods - mask with supported requests of the contact
+6.7. ul.users
+
+ Tell number of different users (AoRs) in a location table.
+
+ Parameters:
+ * table name - location table where the users are looked for, for
+ example, location.
+
+6.8. ul.contacts
+
+ Tell number of contacts in a location table.
+
+ Parameters:
+ * table name - location table where the contacts are looked for, for
+ example, location.
+
7. Statistics
7.1. users
diff --git a/modules/usrloc/doc/usrloc_admin.xml b/modules/usrloc/doc/usrloc_admin.xml
index 78be5e8..7745ffe 100644
--- a/modules/usrloc/doc/usrloc_admin.xml
+++ b/modules/usrloc/doc/usrloc_admin.xml
@@ -1157,6 +1157,37 @@ modparam("usrloc", "db_ops_ruid", 1)
</para></listitem>
</itemizedlist>
</section>
+
+ <section>
+ <title>
+ <function moreinfo="none">ul.users</function>
+ </title>
+ <para>
+ Tell number of different users (AoRs) in a location table.
+ </para>
+ <para>Parameters: </para>
+ <itemizedlist>
+ <listitem><para>
+ <emphasis>table name</emphasis> - location table where the users are
looked for, for example, location.
+ </para></listitem>
+ </itemizedlist>
+ </section>
+
+ <section>
+ <title>
+ <function moreinfo="none">ul.contacts</function>
+ </title>
+ <para>
+ Tell number of contacts in a location table.
+ </para>
+ <para>Parameters: </para>
+ <itemizedlist>
+ <listitem><para>
+ <emphasis>table name</emphasis> - location table where the contacts are
looked for, for example, location.
+ </para></listitem>
+ </itemizedlist>
+ </section>
+
</section><!-- RPC commands -->
diff --git a/modules/usrloc/ul_rpc.c b/modules/usrloc/ul_rpc.c
index 7c10584..e0ebaf4 100644
--- a/modules/usrloc/ul_rpc.c
+++ b/modules/usrloc/ul_rpc.c
@@ -637,6 +637,115 @@ static const char* ul_rpc_add_doc[2] = {
0
};
+#define QUERY_LEN 256
+
+static void ul_rpc_users(rpc_t* rpc, void* ctx)
+{
+ str table = {0, 0};
+ char query[QUERY_LEN];
+ str query_str;
+ db1_res_t* res;
+ int count;
+
+ if (db_mode == NO_DB) {
+ rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
+ return;
+ }
+
+ if (rpc->scan(ctx, "S", &table) != 1) {
+ rpc->fault(ctx, 500, "Not enough parameters (table to lookup)");
+ return;
+ }
+
+ if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) {
+ rpc->fault(ctx, 500, "Too long database query");
+ return;
+ }
+
+ if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) {
+ rpc->fault(ctx, 500, "Database does not support raw queries");
+ return;
+ }
+ if (ul_dbf.use_table(ul_dbh, &table) < 0) {
+ rpc->fault(ctx, 500, "Failed to use table");
+ return;
+ }
+
+ memset(query, 0, QUERY_LEN);
+ query_str.len = snprintf(query, QUERY_LEN,
+ "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s",
+ user_col.len, user_col.s,
+ domain_col.len, domain_col.s,
+ table.len, table.s);
+ query_str.s = query;
+ if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
+ rpc->fault(ctx, 500, "Failed to query AoR count");
+ return;
+ }
+
+ count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
+ ul_dbf.free_result(ul_dbh, res);
+
+ rpc->add(ctx, "d", count);
+}
+
+static const char* ul_rpc_users_doc[2] = {
+ "Tell number of different users (AoRs) in database table (db_mode!=0 only)",
+ 0
+};
+
+static void ul_rpc_contacts(rpc_t* rpc, void* ctx)
+{
+ str table = {0, 0};
+ char query[QUERY_LEN];
+ str query_str;
+ db1_res_t* res;
+ int count;
+
+ if (db_mode == NO_DB) {
+ rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
+ return;
+ }
+
+ if (rpc->scan(ctx, "S", &table) != 1) {
+ rpc->fault(ctx, 500, "Not enough parameters (table to lookup)");
+ return;
+ }
+
+ if (table.len + 22 > QUERY_LEN) {
+ rpc->fault(ctx, 500, "Too long database query");
+ return;
+ }
+
+ if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) {
+ rpc->fault(ctx, 500, "Database does not support raw queries");
+ return;
+ }
+ if (ul_dbf.use_table(ul_dbh, &table) < 0) {
+ rpc->fault(ctx, 500, "Failed to use table");
+ return;
+ }
+
+ memset(query, 0, QUERY_LEN);
+ query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s",
+ table.len, table.s);
+ query_str.s = query;
+ if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
+ rpc->fault(ctx, 500, "Failed to query contact count");
+ return;
+ }
+
+ count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
+ ul_dbf.free_result(ul_dbh, res);
+
+ rpc->add(ctx, "d", count);
+}
+
+static const char* ul_rpc_contacts_doc[2] = {
+ "Tell number of contacts in database table (db_mode=3 only)",
+ 0
+};
+
rpc_export_t ul_rpc[] = {
{"ul.dump", ul_rpc_dump, ul_rpc_dump_doc, 0},
{"ul.lookup", ul_rpc_lookup, ul_rpc_lookup_doc, 0},
@@ -644,6 +753,8 @@ rpc_export_t ul_rpc[] = {
{"ul.rm_contact", ul_rpc_rm_contact, ul_rpc_rm_contact_doc, 0},
{"ul.flush", ul_rpc_flush, ul_rpc_flush_doc, 0},
{"ul.add", ul_rpc_add, ul_rpc_add_doc, 0},
+ {"ul.users", ul_rpc_users, ul_rpc_users_doc, 0},
+ {"ul.contacts", ul_rpc_contacts, ul_rpc_contacts_doc, 0},
{0, 0, 0, 0}
};