Prechádzať zdrojové kódy

usrloc(k): option to store xavp per contact

- stored only in memory for the moment
- the xavp can contain a list of xavps
- new config parameter to specify the name of xavp
Daniel-Constantin Mierla 12 rokov pred
rodič
commit
e6ad428f66

+ 61 - 46
modules_k/usrloc/README

@@ -68,21 +68,22 @@ Bogdan-Andrei Iancu
               3.30. timer_procs (string)
               3.30. timer_procs (string)
 
 
         4. Functions
         4. Functions
-        5. MI Commands
+        5. xavp_contact (string)
+        6. MI Commands
 
 
-              5.1. ul_rm
-              5.2. ul_rm_contact
-              5.3. ul_dump
-              5.4. ul_flush
-              5.5. ul_add
-              5.6. ul_show_contact
+              6.1. ul_rm
+              6.2. ul_rm_contact
+              6.3. ul_dump
+              6.4. ul_flush
+              6.5. ul_add
+              6.6. ul_show_contact
 
 
-        6. Statistics
+        7. Statistics
 
 
-              6.1. users
-              6.2. contacts
-              6.3. expires
-              6.4. registered_users
+              7.1. users
+              7.2. contacts
+              7.3. expires
+              7.4. registered_users
 
 
    2. Developer Guide
    2. Developer Guide
 
 
@@ -140,6 +141,7 @@ Bogdan-Andrei Iancu
    1.28. Set db_update_as_insert parameter
    1.28. Set db_update_as_insert parameter
    1.29. Set db_check_update parameter
    1.29. Set db_check_update parameter
    1.30. Set timer_procs parameter
    1.30. Set timer_procs parameter
+   1.31. Set xavp_contact parameter
 
 
 Chapter 1. Admin Guide
 Chapter 1. Admin Guide
 
 
@@ -188,21 +190,22 @@ Chapter 1. Admin Guide
         3.30. timer_procs (string)
         3.30. timer_procs (string)
 
 
    4. Functions
    4. Functions
-   5. MI Commands
+   5. xavp_contact (string)
+   6. MI Commands
 
 
-        5.1. ul_rm
-        5.2. ul_rm_contact
-        5.3. ul_dump
-        5.4. ul_flush
-        5.5. ul_add
-        5.6. ul_show_contact
+        6.1. ul_rm
+        6.2. ul_rm_contact
+        6.3. ul_dump
+        6.4. ul_flush
+        6.5. ul_add
+        6.6. ul_show_contact
 
 
-   6. Statistics
+   7. Statistics
 
 
-        6.1. users
-        6.2. contacts
-        6.3. expires
-        6.4. registered_users
+        7.1. users
+        7.2. contacts
+        7.3. expires
+        7.4. registered_users
 
 
 1. Overview
 1. Overview
 
 
@@ -705,16 +708,28 @@ modparam("usrloc", "timer_procs", 4)
 
 
    There are no exported functions that could be used in scripts.
    There are no exported functions that could be used in scripts.
 
 
-5. MI Commands
+5. xavp_contact (string)
 
 
-   5.1. ul_rm
-   5.2. ul_rm_contact
-   5.3. ul_dump
-   5.4. ul_flush
-   5.5. ul_add
-   5.6. ul_show_contact
+   The name of XAVP storring the attributes per contact. They are saved in
+   location record and restored at lookup.
 
 
-5.1. ul_rm
+   Default value is "NULL".
+
+   Example 1.31. Set xavp_contact parameter
+...
+modparam("usrloc", "xavp_contact", "ulattrs")
+...
+
+6. MI Commands
+
+   6.1. ul_rm
+   6.2. ul_rm_contact
+   6.3. ul_dump
+   6.4. ul_flush
+   6.5. ul_add
+   6.6. ul_show_contact
+
+6.1. ul_rm
 
 
    Deletes an entire AOR record (including its contacts).
    Deletes an entire AOR record (including its contacts).
 
 
@@ -723,7 +738,7 @@ modparam("usrloc", "timer_procs", 4)
      * AOR - user AOR in username[@domain] format (domain must be supplied
      * AOR - user AOR in username[@domain] format (domain must be supplied
        only if use_domain option is on).
        only if use_domain option is on).
 
 
-5.2. ul_rm_contact
+6.2. ul_rm_contact
 
 
    Deletes a contact from an AOR record.
    Deletes a contact from an AOR record.
 
 
@@ -733,7 +748,7 @@ modparam("usrloc", "timer_procs", 4)
        only if use_domain option is on).
        only if use_domain option is on).
      * contact - exact contact to be removed
      * contact - exact contact to be removed
 
 
-5.3. ul_dump
+6.3. ul_dump
 
 
    Dumps the entire content of the USRLOC in memory cache
    Dumps the entire content of the USRLOC in memory cache
 
 
@@ -742,11 +757,11 @@ modparam("usrloc", "timer_procs", 4)
        "brief", a brief dump will be done (only AOR and contacts, with no
        "brief", a brief dump will be done (only AOR and contacts, with no
        other details)
        other details)
 
 
-5.4. ul_flush
+6.4. ul_flush
 
 
    Triggers the flush of USRLOC memory cache into DB.
    Triggers the flush of USRLOC memory cache into DB.
 
 
-5.5. ul_add
+6.5. ul_add
 
 
    Adds a new contact for an user AOR.
    Adds a new contact for an user AOR.
 
 
@@ -762,7 +777,7 @@ modparam("usrloc", "timer_procs", 4)
      * cflags - per branch flags of the contact
      * cflags - per branch flags of the contact
      * methods - mask with supported requests of the contact
      * methods - mask with supported requests of the contact
 
 
-5.6. ul_show_contact
+6.6. ul_show_contact
 
 
    Dumps the contacts of an user AOR.
    Dumps the contacts of an user AOR.
 
 
@@ -771,33 +786,33 @@ modparam("usrloc", "timer_procs", 4)
      * AOR - user AOR in username[@domain] format (domain must be supplied
      * AOR - user AOR in username[@domain] format (domain must be supplied
        only if use_domain option is on).
        only if use_domain option is on).
 
 
-6. Statistics
+7. Statistics
 
 
-   6.1. users
-   6.2. contacts
-   6.3. expires
-   6.4. registered_users
+   7.1. users
+   7.2. contacts
+   7.3. expires
+   7.4. registered_users
 
 
    Exported statistics are listed in the next sections.
    Exported statistics are listed in the next sections.
 
 
-6.1. users
+7.1. users
 
 
    Number of AOR existing in the USRLOC memory cache for that domain - can
    Number of AOR existing in the USRLOC memory cache for that domain - can
    not be resetted; this statistic will be register for each used domain
    not be resetted; this statistic will be register for each used domain
    (Ex: location).
    (Ex: location).
 
 
-6.2. contacts
+7.2. contacts
 
 
    Number of contacts existing in the USRLOC memory cache for that domain
    Number of contacts existing in the USRLOC memory cache for that domain
    - can not be resetted; this statistic will be register for each used
    - can not be resetted; this statistic will be register for each used
    domain (Ex: location).
    domain (Ex: location).
 
 
-6.3. expires
+7.3. expires
 
 
    Total number of expired contacts for that domain - can be resetted;
    Total number of expired contacts for that domain - can be resetted;
    this statistic will be register for each used domain (Ex: location).
    this statistic will be register for each used domain (Ex: location).
 
 
-6.4. registered_users
+7.4. registered_users
 
 
    Total number of AOR existing in the USRLOC memory cache for all domains
    Total number of AOR existing in the USRLOC memory cache for all domains
    - can not be resetted.
    - can not be resetted.

+ 21 - 0
modules_k/usrloc/doc/usrloc_admin.xml

@@ -832,6 +832,27 @@ modparam("usrloc", "timer_procs", 4)
 	</para>
 	</para>
 	</section>
 	</section>
 
 
+	<section id="xavp_contact">
+		<title><varname>xavp_contact</varname> (string)</title>
+		<para>
+		The name of XAVP storring the attributes per contact. They are saved
+		in location record and restored at lookup.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>NULL</quote>.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>xavp_contact</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("usrloc", "xavp_contact", "ulattrs")
+...
+</programlisting>
+		</example>
+	</section>
+
 
 
 	<section>
 	<section>
 	<title>MI Commands</title>
 	<title>MI Commands</title>

+ 46 - 0
modules_k/usrloc/ucontact.c

@@ -48,6 +48,38 @@
 #include "ucontact.h"
 #include "ucontact.h"
 #include "usrloc.h"
 #include "usrloc.h"
 
 
+static int ul_xavp_contact_clone = 1;
+
+void ul_set_xavp_contact_clone(int v)
+{
+	ul_xavp_contact_clone = v;
+}
+
+#ifdef WITH_XAVP
+/*!
+ * \brief Store xavp list per contact
+ * \param _c contact structure
+ */
+void ucontact_xavp_store(ucontact_t *_c)
+{
+	sr_xavp_t *xavp;
+	if(_c==NULL)
+		return;
+	if(ul_xavp_contact_clone == 0)
+		return;
+	if(ul_xavp_contact_name.s==NULL)
+		return;
+	/* remove old list if it is set -- update case */
+	if (_c->xavp) xavp_destroy_list(&_c->xavp);
+	xavp = xavp_get(&ul_xavp_contact_name, NULL);
+	if(xavp==NULL)
+		return;
+	/* clone the xavp found in core */
+	_c->xavp = xavp_clone_level_nodata(xavp);
+	return;
+}
+#endif
+
 /*!
 /*!
  * \brief Create a new contact structure
  * \brief Create a new contact structure
  * \param _dom domain
  * \param _dom domain
@@ -97,6 +129,10 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _
 	c->reg_id = _ci->reg_id;
 	c->reg_id = _ci->reg_id;
 	c->last_modified = _ci->last_modified;
 	c->last_modified = _ci->last_modified;
 	c->last_keepalive = _ci->last_modified;
 	c->last_keepalive = _ci->last_modified;
+#ifdef WITH_XAVP
+	ucontact_xavp_store(c);
+#endif
+
 
 
 	return c;
 	return c;
 error:
 error:
@@ -108,6 +144,9 @@ error:
 	if (c->c.s) shm_free(c->c.s);
 	if (c->c.s) shm_free(c->c.s);
 	if (c->ruid.s) shm_free(c->ruid.s);
 	if (c->ruid.s) shm_free(c->ruid.s);
 	if (c->instance.s) shm_free(c->instance.s);
 	if (c->instance.s) shm_free(c->instance.s);
+#ifdef WITH_XAVP
+	if (c->xavp) xavp_destroy_list(&c->xavp);
+#endif
 	shm_free(c);
 	shm_free(c);
 	return 0;
 	return 0;
 }
 }
@@ -128,6 +167,9 @@ void free_ucontact(ucontact_t* _c)
 	if (_c->c.s) shm_free(_c->c.s);
 	if (_c->c.s) shm_free(_c->c.s);
 	if (_c->ruid.s) shm_free(_c->ruid.s);
 	if (_c->ruid.s) shm_free(_c->ruid.s);
 	if (_c->instance.s) shm_free(_c->instance.s);
 	if (_c->instance.s) shm_free(_c->instance.s);
+#ifdef WITH_XAVP
+	if (_c->xavp) xavp_destroy_list(&_c->xavp);
+#endif
 	shm_free( _c );
 	shm_free( _c );
 }
 }
 
 
@@ -245,6 +287,10 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci)
 		_c->path.len = 0;
 		_c->path.len = 0;
 	}
 	}
 
 
+#ifdef WITH_XAVP
+	ucontact_xavp_store(_c);
+#endif
+
 	_c->sock = _ci->sock;
 	_c->sock = _ci->sock;
 	_c->expires = _ci->expires;
 	_c->expires = _ci->expires;
 	_c->q = _ci->q;
 	_c->q = _ci->q;

+ 6 - 0
modules_k/usrloc/ul_mod.c

@@ -110,6 +110,8 @@ int ul_timer_procs = 0;
 int ul_db_check_update = 0;
 int ul_db_check_update = 0;
 int ul_keepalive_timeout = 0;
 int ul_keepalive_timeout = 0;
 
 
+str ul_xavp_contact_name = {0};
+
 /* sruid to get internal uid for mi/rpc commands */
 /* sruid to get internal uid for mi/rpc commands */
 sruid_t _ul_sruid;
 sruid_t _ul_sruid;
 
 
@@ -197,6 +199,7 @@ static param_export_t params[] = {
 	{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
 	{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
 	{"timer_procs",         INT_PARAM, &ul_timer_procs},
 	{"timer_procs",         INT_PARAM, &ul_timer_procs},
 	{"db_check_update",     INT_PARAM, &ul_db_check_update},
 	{"db_check_update",     INT_PARAM, &ul_db_check_update},
+	{"xavp_contact",        STR_PARAM, &ul_xavp_contact_name.s},
 	{0, 0, 0}
 	{0, 0, 0}
 };
 };
 
 
@@ -292,6 +295,9 @@ static int mod_init(void)
 	last_mod_col.len = strlen(last_mod_col.s);
 	last_mod_col.len = strlen(last_mod_col.s);
 	db_url.len = strlen(db_url.s);
 	db_url.len = strlen(db_url.s);
 
 
+	if(ul_xavp_contact_name.s!=NULL)
+		ul_xavp_contact_name.len = strlen(ul_xavp_contact_name.s);
+
 	if(ul_hash_size<=1)
 	if(ul_hash_size<=1)
 		ul_hash_size = 512;
 		ul_hash_size = 512;
 	else
 	else

+ 1 - 0
modules_k/usrloc/ul_mod.h

@@ -81,6 +81,7 @@ extern unsigned int nat_bflag;
 /*! flag to protect against wrong initialization */
 /*! flag to protect against wrong initialization */
 extern unsigned int init_flag;
 extern unsigned int init_flag;
 
 
+extern str ul_xavp_contact_name;
 
 
 extern db1_con_t* ul_dbh;   /* Database connection handle */
 extern db1_con_t* ul_dbh;   /* Database connection handle */
 extern db_func_t ul_dbf;
 extern db_func_t ul_dbf;

+ 9 - 0
modules_k/usrloc/usrloc.h

@@ -32,6 +32,9 @@
 #include "ul_callback.h"
 #include "ul_callback.h"
 #include "../../qvalue.h"
 #include "../../qvalue.h"
 #include "../../str.h"
 #include "../../str.h"
+#ifdef WITH_XAVP
+#include "../../xavp.h"
+#endif
 
 
 #define NO_DB         0
 #define NO_DB         0
 #define WRITE_THROUGH 1
 #define WRITE_THROUGH 1
@@ -87,6 +90,9 @@ typedef struct ucontact {
 	unsigned int methods;   /*!< Supported methods */
 	unsigned int methods;   /*!< Supported methods */
 	str instance;           /*!< SIP instance value - gruu */
 	str instance;           /*!< SIP instance value - gruu */
 	unsigned int reg_id;    /*!< reg-id parameters */
 	unsigned int reg_id;    /*!< reg-id parameters */
+#ifdef WITH_XAVP
+	sr_xavp_t * xavp;       /*!< per contact xavps */
+#endif
 	struct ucontact* next;  /*!< Next contact in the linked list */
 	struct ucontact* next;  /*!< Next contact in the linked list */
 	struct ucontact* prev;  /*!< Previous contact in the linked list */
 	struct ucontact* prev;  /*!< Previous contact in the linked list */
 } ucontact_t;
 } ucontact_t;
@@ -109,6 +115,9 @@ typedef struct ucontact_info {
 	unsigned int methods;     /*!< supported methods */
 	unsigned int methods;     /*!< supported methods */
 	str instance;             /*!< SIP instance value - gruu */
 	str instance;             /*!< SIP instance value - gruu */
 	unsigned int reg_id;      /*!< reg-id parameters */
 	unsigned int reg_id;      /*!< reg-id parameters */
+#ifdef WITH_XAVP
+	sr_xavp_t * xavp;         /*!< per contact xavps */
+#endif
 	time_t last_modified;     /*!< last modified */
 	time_t last_modified;     /*!< last modified */
 } ucontact_info_t;
 } ucontact_info_t;