Skip to content

Commit

Permalink
Merge branch 'usrlocCID'
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutrazvanionita committed Aug 6, 2015
2 parents 570d7d7 + 7d20a36 commit 7ef4eaa
Show file tree
Hide file tree
Showing 42 changed files with 1,131 additions and 435 deletions.
12 changes: 6 additions & 6 deletions db/schema/location.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN"
"http://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
Expand All @@ -9,20 +9,20 @@

<table id="location" xmlns:db="http://docbook.org/ns/docbook">
<name>location</name>
<version>1009</version>
<version>1010</version>
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
<description>
<db:para>Persistent user location information for the usrloc module. More information can be found at: &OPENSIPS_MOD_DOC;usrloc.html
</db:para>
</description>

<column id="id">
<name>id</name>
<type>unsigned int</type>
<column id="contact_id">
<name>contact_id</name>
<type>unsigned long</type>
<size>&table_id_len;</size>
<autoincrement/>
<primary/>
<type db="dbtext">int,auto</type>
<type db="dbtext">long,auto</type>
<description>unique ID</description>
</column>

Expand Down
4 changes: 4 additions & 0 deletions doc/dbschema/xsl/sqlite.xsl
Expand Up @@ -51,6 +51,10 @@
</xsl:variable>

<xsl:choose>
<!--transform bigint primary key autoincrement to integer -->
<xsl:when test="$type='long' and primary and autoincrement">
<xsl:text> INTEGER PRIMARY KEY AUTOINCREMENT </xsl:text>
</xsl:when>
<xsl:when test="type[@db=$db]">
<xsl:value-of select="normalize-space(type[@db=$db])"/>
</xsl:when>
Expand Down
20 changes: 20 additions & 0 deletions modules/db_sqlite/res.c
Expand Up @@ -184,6 +184,7 @@ static db_type_t get_type_from_decltype(const char *decltype)
int db_sqlite_get_columns(const db_con_t* _h, db_res_t* _r)
{
int col;
int autoincrement;
const char *decltype;
const char* name;

Expand Down Expand Up @@ -213,6 +214,25 @@ int db_sqlite_get_columns(const db_con_t* _h, db_res_t* _r)
RES_NAMES(_r)[col]->s = *((char**)&name);
RES_NAMES(_r)[col]->len = strlen(RES_NAMES(_r)[col]->s);

/* check if column is autoincrement */
if (sqlite3_table_column_metadata(
CON_CONNECTION(_h),
NULL, /* db name*/
CON_TABLE(_h)->s, /* table name */
name, /* column name */
NULL, NULL, NULL, NULL,
&autoincrement) != 0) {
LM_ERR("failed to fetch column metadata\n");
return -1;
}

/* since DB_BITMAP not used in SQLITE we will use it
* here to know if value is PRIMARY KEY AUTOINCREMENT */
if (autoincrement) {
RES_TYPES(_r)[col] = DB_BITMAP;
continue;
}

decltype = sqlite3_column_decltype(CON_SQLITE_PS(_h), col);
RES_TYPES(_r)[col] = get_type_from_decltype(decltype);

Expand Down
11 changes: 10 additions & 1 deletion modules/db_sqlite/row.c
Expand Up @@ -66,8 +66,17 @@ int db_sqlite_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r)
}

switch (RES_TYPES(_res)[col]) {
case DB_BITMAP:
/* value considered to be int; but stored as bigint;
* can be used as VAL_INT() to be called
* also can be used as VAL_BIGINT() */
VAL_BIGINT(_v) = sqlite3_column_int64(CON_SQLITE_PS(_h), col);
VAL_TYPE(_v) = DB_INT;

break;
case DB_INT:
VAL_INT(_v) = sqlite3_column_int(CON_SQLITE_PS(_h), col);

VAL_INT(_v) =sqlite3_column_int(CON_SQLITE_PS(_h), col);
VAL_TYPE(_v) = DB_INT;

break;
Expand Down
4 changes: 2 additions & 2 deletions modules/nathelper/nathelper.c
Expand Up @@ -1271,7 +1271,7 @@ nh_timer(unsigned int ticks, void *timer_idx)
}
rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
natping_partitions*natping_interval);
natping_partitions*natping_interval, 0/* no contact id */);
if (rval<0) {
LM_ERR("failed to fetch contacts\n");
goto done;
Expand All @@ -1287,7 +1287,7 @@ nh_timer(unsigned int ticks, void *timer_idx)
}
rval = ul.get_all_ucontacts(buf,cblen,(ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
natping_partitions*natping_interval);
natping_partitions*natping_interval, 0/* no contact id */);
if (rval != 0) {
goto done;
}
Expand Down
34 changes: 20 additions & 14 deletions modules/registrar/save.c
Expand Up @@ -552,14 +552,17 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
if (_sctx->flags&REG_SAVE_FORCE_REG_FLAG) {
/* we are overflowing the number of maximum contacts,
so remove the oldest valid one to prevent this */
for( c_it=_r->contacts,c_last=NULL ; c_it ; c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time)) c_last=c_it;
for( c_it=_r->contacts,c_last=NULL ; c_it ;
c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time))
c_last=c_it;
if (c_last==NULL) {
LM_CRIT("BUG - overflow detected but no valid contacts found :( \n");
LM_CRIT("BUG - overflow detected but no valid "
"contacts found :( \n");
goto error;
}
LM_DBG("overflow on inserting new contact -> removing <%.*s>\n",
c_last->c.len, c_last->c.s);
LM_DBG("overflow on inserting new contact -> removing "
"<%.*s>\n", c_last->c.len, c_last->c.s);
if (ul.delete_ucontact( _r, c_last, 0)!=0) {
LM_ERR("failed to remove contact\n");
goto error;
Expand Down Expand Up @@ -601,23 +604,26 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
}
} else {
/* do update */
/* if the contact to be updated is not valid, it will be after update, so need
* to compensate the total number of contact */
/* if the contact to be updated is not valid, it will be after
* update, so need to compensate the total number of contact */
if ( !VALID_CONTACT(c,act_time) )
num++;
while ( _sctx->max_contacts && num>_sctx->max_contacts ) {
if (_sctx->flags&REG_SAVE_FORCE_REG_FLAG) {
/* we are overflowing the number of maximum contacts,
so remove the first (oldest) one to prevent this (but not the one
to be updated !) */
for( c_it=_r->contacts,c_last=NULL ; c_it ; c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time) && c_it!=c) c_last=c_it;
so remove the first (oldest) one to prevent this
(but not the one to be updated !) */
for( c_it=_r->contacts,c_last=NULL ; c_it ;
c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time) && c_it!=c)
c_last=c_it;
if (c_last==NULL) {
LM_CRIT("BUG - overflow detected but no valid contacts found :( \n");
LM_CRIT("BUG - overflow detected but no "
"valid contacts found :( \n");
goto error;
}
LM_DBG("overflow on update -> removing contact <%.*s>\n",
c_last->c.len, c_last->c.s);
LM_DBG("overflow on update -> removing contact "
"<%.*s>\n", c_last->c.len, c_last->c.s);
if (ul.delete_ucontact( _r, c_last, 0)!=0) {
LM_ERR("failed to remove contact\n");
goto error;
Expand Down
73 changes: 58 additions & 15 deletions modules/usrloc/README
Expand Up @@ -114,14 +114,20 @@ Ovidiu Sas
2.1.9. ul_delete_ucontact (record, contact,
is_replicated)

2.1.10. ul_get_ucontact(record, contact)
2.1.11. ul_get_all_ucontacts (buf, len, flags)
2.1.12. ul_update_ucontact(record, contact,
2.1.10. ul_delete_ucontact_from_id (domain,
contact_id)

2.1.11. ul_get_ucontact(record, contact)
2.1.12. ul_get_domain_ucontacts (domain, buf, len,
flags)

2.1.13. ul_get_all_ucontacts (buf, len, flags)
2.1.14. ul_update_ucontact(record, contact,
contact_info, is_replicated)

2.1.13. ul_bind_ursloc( api )
2.1.14. ul_register_ulcb(type ,callback, param)
2.1.15. ul_get_num_users()
2.1.15. ul_bind_ursloc( api )
2.1.16. ul_register_ulcb(type ,callback, param)
2.1.17. ul_get_num_users()

List of Examples

Expand Down Expand Up @@ -479,8 +485,8 @@ modparam("usrloc", "timer_interval", 120)

Example 1.21. Set db_url parameter
...
modparam("usrloc", "db_url", "dbdriver://username:password@dbhost/dbnam
e")
modparam("usrloc", "db_url", "dbdriver://username:password@dbhost/dbname
")
...

1.3.22. db_mode (integer)
Expand Down Expand Up @@ -627,7 +633,9 @@ modparam("usrloc", "skip_replicated_db_ops", 1)

The number of entries of the hash table used by usrloc to store
the location records is 2^hash_size. For hash_size=4, the
number of entries of the hash table is 16.
number of entries of the hash table is 16. Since version 2.2,
the maximu size of this parameter is 16, meaning that the hash
supports maximum 65536 entries.

Default value is “9”.

Expand Down Expand Up @@ -931,7 +939,18 @@ is_replicated)
be called from the context of a Binary Interface callback.
If uncertain, simply use 0.

2.1.10. ul_get_ucontact(record, contact)
2.1.10. ul_delete_ucontact_from_id (domain, contact_id)

The function deletes a contact with the given contact_id from
the given domain.

Meaning of the parameters is as follows:
* udomain_t* domain - Domain where the contact can be found.

* uint64_t contact_id - Contact_id identifying the contact to
be deleted.

2.1.11. ul_get_ucontact(record, contact)

The function tries to find contact with given Contact URI and
returns pointer to structure representing the contact.
Expand All @@ -941,7 +960,31 @@ is_replicated)

* str_t* contact - URI of the request contact.

2.1.11. ul_get_all_ucontacts (buf, len, flags)
2.1.12. ul_get_domain_ucontacts (domain, buf, len, flags)

The function retrieves all contacts of all registered users
from the given doamin and returns them in the caller-supplied
buffer. If the buffer is too small, the function returns
positive value indicating how much additional space would be
necessary to accommodate all of them. Please note that the
positive return value should be used only as a “hint”, as there
is no guarantee that during the time between two subsequent
calls number of registered contacts will remain the same.

If flag parameter is set to non-zero value then only contacts
that have the specified flags set will be returned. It is, for
example, possible to list only contacts that are behind NAT.

Meaning of the parameters is as follows:
* udomaint_t* domain - Domain from which to get the contacts

* void* buf - Buffer for returning contacts.

* int len - Length of the buffer.

* unsigned int flags - Flags that must be set.

2.1.13. ul_get_all_ucontacts (buf, len, flags)

The function retrieves all contacts of all registered users and
returns them in the caller-supplied buffer. If the buffer is
Expand All @@ -963,7 +1006,7 @@ is_replicated)

* unsigned int flags - Flags that must be set.

2.1.12. ul_update_ucontact(record, contact, contact_info,
2.1.14. ul_update_ucontact(record, contact, contact_info,
is_replicated)

The function updates contact with new values.
Expand All @@ -978,7 +1021,7 @@ is_replicated)
be called from the context of a Binary Interface callback.
If uncertain, simply use 0.

2.1.13. ul_bind_ursloc( api )
2.1.15. ul_bind_ursloc( api )

The function imports all functions that are exported by the
USRLOC module. Overs for other modules which want to user the
Expand All @@ -988,7 +1031,7 @@ is_replicated)
Meaning of the parameters is as follows:
* usrloc_api_t* api - USRLOC API

2.1.14. ul_register_ulcb(type ,callback, param)
2.1.16. ul_register_ulcb(type ,callback, param)

The function register with USRLOC a callback function to be
called when some event occures inside USRLOC.
Expand All @@ -1001,7 +1044,7 @@ is_replicated)
* void *param - some parameter to be passed to the callback
each time when it is called.

2.1.15. ul_get_num_users()
2.1.17. ul_get_num_users()

The function loops through all domains summing up the number of
users.

0 comments on commit 7ef4eaa

Please sign in to comment.