diff --git a/src/modules/usrloc/Makefile b/src/modules/usrloc/Makefile index 0c8bc3b2898..6f14f11e92c 100644 --- a/src/modules/usrloc/Makefile +++ b/src/modules/usrloc/Makefile @@ -11,7 +11,6 @@ LIBS= DEFS+=-DKAMAILIO_MOD_INTERFACE SERLIBPATH=../../lib -SER_LIBS+=$(SERLIBPATH)/kmi/kmi SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1 SER_LIBS+=$(SERLIBPATH)/srutils/srutils include ../../Makefile.modules diff --git a/src/modules/usrloc/doc/usrloc_admin.xml b/src/modules/usrloc/doc/usrloc_admin.xml index cde30385064..34aebee5b9a 100644 --- a/src/modules/usrloc/doc/usrloc_admin.xml +++ b/src/modules/usrloc/doc/usrloc_admin.xml @@ -10,31 +10,31 @@ - + &adminguide; - +
Overview - The User location module module keeps a user location table and - provides access to the table for other modules. The module exports no + The User location module module keeps a user location table and + provides access to the table for other modules. The module exports no functions that can be used directly from routing scripts.
Contact matching - How the contacts are matched (for the same AOR - Address of Record) is an + How the contacts are matched (for the same AOR - Address of Record) is an important aspect of the usrloc module, especially in the context of NAT - traversal - this raises more problems since contacts from different + traversal - this raises more problems since contacts from different phones of the same user may overlap (if both are behind NATs with the same configuration) or the re-register contact of the same phone may be seen as a new one (due different binding via NAT). - The SIP RFC 3261 publishes a matching algorithm based only on the + The SIP RFC 3261 publishes a matching algorithm based only on the contact string with Call-id and Cseq extra checking (if the Call-ID is the same, it must have a higher Cseq number, otherwise it is invalid). - But as argumented above, this is not enough in NAT traversal context, + But as argumented above, this is not enough in NAT traversal context, so the &kamailio; implementation of contact matching offers more algorithms: @@ -97,7 +97,7 @@
External Libraries or Applications - The following libraries or applications must be installed before + The following libraries or applications must be installed before running &kamailio; with this module loaded: @@ -114,8 +114,8 @@
<varname>nat_bflag</varname> (integer) - The index of the branch flag to be used as NAT marker (if the contact - is or not natted). This is a branch flag and it will be imported and + The index of the branch flag to be used as NAT marker (if the contact + is or not natted). This is a branch flag and it will be imported and used by all other modules depending of usrloc module. @@ -520,7 +520,7 @@ modparam("usrloc", "keepalive_column", "kalive") <varname>use_domain</varname> (integer) If the domain part of the user should be also saved and used for - identifing the user (along with the username part). Useful in + identifing the user (along with the username part). Useful in multi domain scenarios. Non 0 value means true. @@ -563,8 +563,8 @@ modparam("usrloc", "desc_time_order", 1)
<varname>timer_interval</varname> (integer) - Number of seconds between two timer runs. The module uses a timer to - delete expired contacts, synchronize with database and other tasks, + Number of seconds between two timer runs. The module uses a timer to + delete expired contacts, synchronize with database and other tasks, that need to be run periodically. @@ -606,7 +606,7 @@ modparam("usrloc", "db_url", "&exampledb;") <varname>db_mode</varname> (integer) The usrloc module can utilize a database for persistent contact storage. - If a database is used, the location database (contacts) will survive + If a database is used, the location database (contacts) will survive machine restarts or software crashes. The disadvantage is that accessing a database can be very time consuming. Therefore, usrloc module implements four database accessing modes: @@ -614,44 +614,44 @@ modparam("usrloc", "db_url", "&exampledb;") - 0 - This disables database completely. Only memory will be used. - Contacts will not survive restart. Use this value if you need a - really fast usrloc and contact persistence is not necessary or + 0 - This disables database completely. Only memory will be used. + Contacts will not survive restart. Use this value if you need a + really fast usrloc and contact persistence is not necessary or is provided by other means. - 1 - Write-Through scheme. All changes to usrloc are immediately - reflected in database too. This is very slow, but very reliable. - Use this scheme if speed is not your priority but need to make - sure that no registered contacts will be lost during crash or + 1 - Write-Through scheme. All changes to usrloc are immediately + reflected in database too. This is very slow, but very reliable. + Use this scheme if speed is not your priority but need to make + sure that no registered contacts will be lost during crash or reboot. - 2 - Write-Back scheme. This is a combination of previous two - schemes. All changes are made to memory and database - synchronization is done in the timer. The timer deletes all - expired contacts and flushes all modified or new contacts to - database. Use this scheme if you encounter high-load peaks - and want them to process as fast as possible. The mode will - not help at all if the load is high all the time. Also, latency - of this mode is much lower than latency of mode 1, but slightly + 2 - Write-Back scheme. This is a combination of previous two + schemes. All changes are made to memory and database + synchronization is done in the timer. The timer deletes all + expired contacts and flushes all modified or new contacts to + database. Use this scheme if you encounter high-load peaks + and want them to process as fast as possible. The mode will + not help at all if the load is high all the time. Also, latency + of this mode is much lower than latency of mode 1, but slightly higher than latency of mode 0. 3 - DB-Only scheme. No memory cache is kept, all operations being - directly performed with the database. The timer deletes all + directly performed with the database. The timer deletes all expired contacts from database - cleans after clients that didn't un-register or re-register. The mode is useful if you configure more servers sharing the same DB without any replication at SIP level. The mode may be slower due the high number of DB operation. For example NAT pinging is a killer since during each ping cycle - all nated contact are loaded from the DB; The lack of memory + all nated contact are loaded from the DB; The lack of memory caching also disable the statistics exports. @@ -667,8 +667,8 @@ modparam("usrloc", "db_url", "&exampledb;") - In case of crash or restart contacts that are in memory only and - haven't been flushed yet will get lost. If you want minimize the + In case of crash or restart contacts that are in memory only and + haven't been flushed yet will get lost. If you want minimize the risk, use shorter timer interval. @@ -690,8 +690,8 @@ modparam("usrloc", "db_mode", 2)
<varname>matching_mode</varname> (integer) - What contact matching algorithm to be used. Refer to section - for the description of the + What contact matching algorithm to be used. Refer to section + for the description of the algorithms. @@ -704,7 +704,7 @@ modparam("usrloc", "db_mode", 2) - 1 - CONTACT and CALLID based + 1 - CONTACT and CALLID based matching algorithm. @@ -716,7 +716,7 @@ modparam("usrloc", "db_mode", 2) - 3 - CALLID only based + 3 - CALLID only based matching algorithm. This mode will discard any duplicate registration coming through different paths. @@ -741,7 +741,7 @@ modparam("usrloc", "matching_mode", 1) <varname>cseq_delay</varname> (integer) Delay (in seconds) for accepting as retransmissions register requests - with same Call-ID and Cseq. The delay is calculated starting from the + with same Call-ID and Cseq. The delay is calculated starting from the receiving time of the first register with that Call-ID and Cseq. @@ -1110,154 +1110,6 @@ modparam("usrloc", "db_timer_clean", 1)
-
- Functions - - There are no exported functions that could be used in scripts. - -
- -
- MI Commands - -
- - <function moreinfo="none">ul_rm</function> - - - Deletes an entire AOR record (including its contacts). - - Parameters: - - - table name - table where the AOR - is removed from (Ex: location). - - - AOR - user AOR in username[@domain] - format (domain must be supplied only if use_domain option - is on). - - -
- -
- - <function moreinfo="none">ul_rm_contact</function> - - - Deletes a contact from an AOR record. - - Parameters: - - - table name - table where the AOR - is removed from (Ex: location). - - - AOR - user AOR in username[@domain] - format (domain must be supplied only if use_domain option - is on). - - - contact - exact contact to be removed - - -
- -
- - <function moreinfo="none">ul_dump</function> - - - Dumps the entire content of the USRLOC in memory cache - - Parameters: - - - brief - (optional, may not be present); if - equals to string brief, a brief dump will be - done (only AOR and contacts, with no other details) - - -
- -
- - <function moreinfo="none">ul_flush</function> - - - Triggers the flush of USRLOC memory cache into DB. - -
- -
- - <function moreinfo="none">ul_add</function> - - - Adds a new contact for an user AOR. - - Parameters: - - - table name - table where the contact - will be added (Ex: location). - - - AOR - user AOR in username[@domain] - format (domain must be supplied only if use_domain option - is on). - - - contact - contact string to be added - - - expires - expires value of the contact - - - Q - Q value of the contact - - - path value of the contact - - - flags - internal USRLOC flags of the - contact - - - cflags - per branch flags of the - contact - - - methods - mask with supported requests - of the contact - - -
- -
- - <function moreinfo="none">ul_show_contact</function> - - - Dumps the contacts of an user AOR. - - Parameters: - - - table name - table where the AOR - resides (Ex: location). - - - AOR - user AOR in username[@domain] - format (domain must be supplied only if use_domain option - is on). - - -
- -
RPC Commands @@ -1448,15 +1300,15 @@ modparam("usrloc", "db_timer_clean", 1) users Number of AOR existing in the USRLOC memory cache for that domain - - can not be resetted; this statistic will be register for each + - can not be resetted; this statistic will be register for each used domain (Ex: location).
contacts - Number of contacts existing in the USRLOC memory cache for that - domain - can not be resetted; this statistic will be register for + Number of contacts existing in the USRLOC memory cache for that + domain - can not be resetted; this statistic will be register for each used domain (Ex: location).
@@ -1464,7 +1316,7 @@ modparam("usrloc", "db_timer_clean", 1) expires Total number of expired contacts for that domain - can be resetted; - this statistic will be register for each used domain + this statistic will be register for each used domain (Ex: location).
diff --git a/src/modules/usrloc/ul_mi.c b/src/modules/usrloc/ul_mi.c deleted file mode 100644 index 31d00777893..00000000000 --- a/src/modules/usrloc/ul_mi.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - * Copyright (C) 2006 Voice Sistem SRL - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/*! \file - * \brief USRLOC - Usrloc MI functions - * \ingroup usrloc - * - * - Module: \ref usrloc - */ - -#include -#include -#include "../../lib/kmi/mi.h" -#include "../../lib/srutils/sruid.h" -#include "../../core/dprint.h" -#include "../../core/ut.h" -#include "../../core/qvalue.h" -#include "../../core/ip_addr.h" -#include "../../core/dset.h" -#include "../../core/rand/kam_rand.h" -#include "ul_mi.h" -#include "dlist.h" -#include "udomain.h" -#include "utime.h" -#include "usrloc_mod.h" -#include "usrloc.h" - -/*! CSEQ nr used */ -static int MI_UL_CSEQ = 0; -/*! call-id used for ul_add and ul_rm_contact */ -static str mi_ul_cid = {0,0}; /* str_init("dfjrewr12386fd6-343@kamailio.mi");*/ -/*! user agent used for ul_add */ -static str mi_ul_ua = str_init("SIP Router MI Server"); -/*! path used for ul_add and ul_rm_contact */ -static str mi_ul_path = str_init("dummypath"); - -extern sruid_t _ul_sruid; - -static char mi_ul_cid_buf[32]; - -/************************ helper functions ****************************/ - -static void set_mi_ul_cid(void) -{ - int i; - char charset[] = "0123456789" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - if(mi_ul_cid.s!=NULL) return; - - for(i=0; i<19; i++) { - mi_ul_cid_buf[i] = charset[kam_rand()%(sizeof(charset) - 1)]; - } - memcpy(mi_ul_cid_buf+i, "@kamailio.mi", sizeof("@kamailio.mi")); - mi_ul_cid.s = mi_ul_cid_buf; - mi_ul_cid.len = strlen(mi_ul_cid.s); -} - -/*! - * \brief Search a domain in the global domain list - * \param table domain (table) name - * \return pointer to domain if found, 0 if not found - */ -static inline udomain_t* mi_find_domain(str* table) -{ - dlist_t* dom; - - for( dom=root ; dom ; dom=dom->next ) { - if ((dom->name.len == table->len) && - !memcmp(dom->name.s, table->s, table->len)) - return dom->d; - } - return 0; -} - - -/*! - * \brief Convert address of record - * - * Convert an address of record string to lower case, and truncate - * it when use_domain is not set. - * \param aor address of record - * \return 0 on success, -1 on error - */ -static inline int mi_fix_aor(str *aor) -{ - char *p; - - p = memchr( aor->s, '@', aor->len); - if (use_domain) { - if (p==NULL) - return -1; - } else { - if (p) - aor->len = p - aor->s; - } - if(!get_aor_case_sensitive()) - strlower(aor); - - return 0; -} - - -/*! - * \brief Add a node for a address of record - * \param parent parent node - * \param r printed record - * \param t actual time - * \param short_dump 0 means that all informations will be included, 1 that only the AOR is printed - * \return 0 on success, -1 on failure - */ -static inline int mi_add_aor_node(struct mi_node *parent, urecord_t* r, time_t t, int short_dump) -{ - struct mi_node *anode, *cnode, *node; - struct mi_attr *attr; - ucontact_t* c; - char *p; - int len; - - anode = add_mi_node_child( parent, MI_DUP_VALUE, "AOR", 3, - r->aor.s, r->aor.len); - if (anode==0) - return -1; - - if (short_dump) - return 0; - -#if 0 - /* aor hash */ - p = int2str((unsigned long)r->aorhash, &len); - node = add_mi_node_child( anode, MI_DUP_VALUE, "HashID", 6, p, len); - if (node==0) - return -1; -#endif - - for( c=r->contacts ; c ; c=c->next) { - /* contact */ - cnode = add_mi_node_child( anode, MI_DUP_VALUE, "Contact", 7, - c->c.s, c->c.len); - if (cnode==0) - return -1; - - /* expires */ - if (c->expires == 0) { - node = add_mi_node_child( cnode, 0, "Expires", 7, "permanent", 9); - } else if (c->expires == UL_EXPIRED_TIME) { - node = add_mi_node_child( cnode, 0, "Expires", 7, "deleted", 7); - } else if (t > c->expires) { - node = add_mi_node_child( cnode, 0, "Expires", 7, "expired", 7); - } else { - p = int2str((unsigned long)(c->expires - t), &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Expires", 7,p,len); - } - if (node==0) - return -1; - - /* q */ - p = q2str(c->q, (unsigned int*)&len); - attr = add_mi_attr( cnode, MI_DUP_VALUE, "Q", 1, p, len); - if (attr==0) - return -1; - - /* callid */ - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Callid", 6, - c->callid.s, c->callid.len); - if (node==0) - return -1; - - /* cseq */ - p = int2str((unsigned long)c->cseq, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Cseq", 4, p, len); - if (node==0) - return -1; - - /* User-Agent */ - if (c->user_agent.len) { - node = add_mi_node_child( cnode, MI_DUP_VALUE, "User-agent", 10, - c->user_agent.s, c->user_agent.len); - if (node==0) - return -1; - } - - /* received */ - if (c->received.len) { - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Received", 8, - c->received.s, c->received.len); - if (node==0) - return -1; - } - - /* path */ - if (c->path.len) { - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Path", 4, - c->path.s, c->path.len); - if (node==0) - return -1; - } - - /* state */ - if (c->state == CS_NEW) { - node = add_mi_node_child( cnode, 0, "State", 5, "CS_NEW", 6); - } else if (c->state == CS_SYNC) { - node = add_mi_node_child( cnode, 0, "State", 5, "CS_SYNC", 7); - } else if (c->state== CS_DIRTY) { - node = add_mi_node_child( cnode, 0, "State", 5, "CS_DIRTY", 8); - } else { - node = add_mi_node_child( cnode, 0, "State", 5, "CS_UNKNOWN", 10); - } - if (node==0) - return -1; - - /* flags */ - p = int2str((unsigned long)c->flags, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Flags", 5, p, len); - if (node==0) - return -1; - - /* cflags */ - p = int2str((unsigned long)c->cflags, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Cflags", 5, p, len); - if (node==0) - return -1; - - /* socket */ - if (c->sock) { - node = add_mi_node_child( cnode, 0, "Socket", 6, - c->sock->sock_str.s, c->sock->sock_str.len); - if (node==0) - return -1; - } - - /* methods */ - p = int2str((unsigned long)c->methods, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Methods", 7, p, len); - if (node==0) - return -1; - - /* ruid */ - if (c->ruid.len) { - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Ruid", 4, - c->ruid.s, c->ruid.len); - if (node==0) - return -1; - } - - /* instance */ - if (c->instance.len) { - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Instance", 8, - c->instance.s, c->instance.len); - if (node==0) - return -1; - } - - /* reg-id */ - p = int2str((unsigned long)c->reg_id, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Reg-Id", 6, p, len); - if (node==0) - return -1; - - /* last keepalive */ - p = int2str((unsigned long)c->last_keepalive, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Last-Keepalive", - 14, p, len); - if (node==0) - return -1; - - /* last modified */ - p = int2str((unsigned long)c->last_modified, &len); - node = add_mi_node_child( cnode, MI_DUP_VALUE, "Last-Modified", - 13, p, len); - if (node==0) - return -1; - - } /* for */ - - return 0; -} - - -/*************************** MI functions *****************************/ - -/*! - * \brief Delete a address of record including its contacts - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 2 nodes: the table name and the AOR - * \return mi_root with the result - */ -struct mi_root* mi_usrloc_rm_aor(struct mi_root *cmd, void *param) -{ - struct mi_node *node; - udomain_t *dom; - str *aor; - - node = cmd->node.kids; - if (node==NULL || node->next==NULL || node->next->next!=NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - /* look for table */ - dom = mi_find_domain( &node->value ); - if (dom==NULL) - return init_mi_tree( 404, "Table not found", 15); - - /* process the aor */ - aor = &node->next->value; - if ( mi_fix_aor(aor)!=0 ) - return init_mi_tree( 400, "Domain missing in AOR", 21); - - lock_udomain( dom, aor); - if (delete_urecord( dom, aor, 0) < 0) { - unlock_udomain( dom, aor); - return init_mi_tree( 500, "Failed to delete AOR", 20); - } - - unlock_udomain( dom, aor); - return init_mi_tree( 200, MI_OK_S, MI_OK_LEN); -} - - -/*! - * \brief Delete a contact from an AOR record - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 3 nodes: the table name, the AOR and contact - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_rm_contact(struct mi_root *cmd, void *param) -{ - struct mi_node *node; - udomain_t *dom; - urecord_t *rec; - ucontact_t* con; - str *aor, *contact; - int ret; - - node = cmd->node.kids; - if (node==NULL || node->next==NULL || node->next->next==NULL || - node->next->next->next!=NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - /* look for table */ - dom = mi_find_domain( &node->value ); - if (dom==NULL) - return init_mi_tree( 404, "Table not found", 15); - - /* process the aor */ - aor = &node->next->value; - if ( mi_fix_aor(aor)!=0 ) - return init_mi_tree( 400, "Domain missing in AOR", 21); - - lock_udomain( dom, aor); - - ret = get_urecord( dom, aor, &rec); - if (ret == 1) { - unlock_udomain( dom, aor); - return init_mi_tree( 404, "AOR not found", 13); - } - - contact = &node->next->next->value; - set_mi_ul_cid(); - ret = get_ucontact( rec, contact, &mi_ul_cid, &mi_ul_path, MI_UL_CSEQ+1, &con); - if (ret < 0) { - unlock_udomain( dom, aor); - return 0; - } - if (ret > 0) { - unlock_udomain( dom, aor); - return init_mi_tree( 404, "Contact not found", 17); - } - - if (delete_ucontact(rec, con) < 0) { - unlock_udomain( dom, aor); - return 0; - } - - release_urecord(rec); - unlock_udomain( dom, aor); - return init_mi_tree( 200, MI_OK_S, MI_OK_LEN); -} - - -/*! - * \brief Dump the content of the usrloc - * \param cmd mi_root containing the parameter - * \param param not used - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_dump(struct mi_root *cmd, void *param) -{ - struct mi_root *rpl_tree; - struct mi_node *rpl, *node; - struct mi_attr *attr; - struct urecord* r; - dlist_t* dl; - udomain_t* dom; - time_t t; - char *p; - int max, len, n, i, short_dump; - - node = cmd->node.kids; - if (node && node->next) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - if (node && node->value.len==5 && !strncasecmp(node->value.s, "brief", 5)){ - /* short version */ - short_dump = 1; - } else { - short_dump = 0; - } - - rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl_tree==NULL) - return 0; - rpl = &rpl_tree->node; - t = time(0); - - for( dl=root ; dl ; dl=dl->next ) { - /* add a domain node */ - node = add_mi_node_child( rpl, 0, "Domain", 6, - dl->name.s, dl->name.len); - if (node==0) - goto error; - - dom = dl->d; - /* add some attributes to the domain node */ - p= int2str((unsigned long)dom->size, &len); - attr = add_mi_attr( node, MI_DUP_VALUE, "table", 5, p, len); - if (attr==0) - goto error; - - /* add the entries per hash */ - for(i=0,n=0,max=0; isize; i++) { - lock_ulslot( dom, i); - - n += dom->table[i].n; - if(maxtable[i].n) - max= dom->table[i].n; - for( r = dom->table[i].first ; r ; r=r->next ) { - /* add entry */ - if (mi_add_aor_node( node, r, t, short_dump)!=0) { - unlock_ulslot( dom, i); - goto error; - } - } - - unlock_ulslot( dom, i); - } - - /* add more attributes to the domain node */ - p= int2str((unsigned long)n, &len); - attr = add_mi_attr( node, MI_DUP_VALUE, "records", 7, p, len); - if (attr==0) - goto error; - - p= int2str((unsigned long)max, &len); - attr = add_mi_attr( node, MI_DUP_VALUE, "max_slot", 8, p, len); - if (attr==0) - goto error; - - } - - return rpl_tree; -error: - free_mi_tree(rpl_tree); - return 0; -} - - -/*! - * \brief Flush the usrloc memory cache to DB - * \param cmd mi_root containing the parameter - * \param param not used - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_flush(struct mi_root *cmd, void *param) -{ - struct mi_root *rpl_tree; - - rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl_tree==NULL) - return 0; - - synchronize_all_udomains(0, 1); - return rpl_tree; -} - - -/*! - * \brief Add a new contact for an address of record - * \param cmd mi_root containing the parameter - * \param param not used - * \note Expects 9 nodes: table name, AOR, contact, expires, Q, - * path, flags, cflags, methods - * \return mi_root with the result - */ -struct mi_root* mi_usrloc_add(struct mi_root *cmd, void *param) -{ - ucontact_info_t ci; - urecord_t* r; - ucontact_t* c; - struct mi_node *node; - udomain_t *dom; - str *aor, *contact; - unsigned int ui_val; - int n; - - for( n=0,node = cmd->node.kids; n<9 && node ; n++,node=node->next ); - if (n!=9 || node!=0) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - node = cmd->node.kids; - - /* look for table (param 1) */ - dom = mi_find_domain( &node->value ); - if (dom==NULL) - return init_mi_tree( 404, "Table not found", 15); - - /* process the aor (param 2) */ - node = node->next; - aor = &node->value; - if ( mi_fix_aor(aor)!=0 ) - return init_mi_tree( 400, "Domain missing in AOR", 21); - - /* contact (param 3) */ - node = node->next; - contact = &node->value; - - memset( &ci, 0, sizeof(ucontact_info_t)); - - /* expire (param 4) */ - node = node->next; - if (str2int( &node->value, &ui_val) < 0) - goto bad_syntax; - ci.expires = ui_val; - - /* q value (param 5) */ - node = node->next; - if (str2q( &ci.q, node->value.s, node->value.len) < 0) - goto bad_syntax; - - /* path value (param 6) */ - node = node->next; - if(strncmp(node->value.s, "0", 1) != 0 && node->value.len > 1) - ci.path = &node->value; - - /* flags value (param 7) */ - node = node->next; - if (str2int( &node->value, (unsigned int*)&ci.flags) < 0) - goto bad_syntax; - - /* branch flags value (param 8) */ - node = node->next; - if (str2int( &node->value, (unsigned int*)&ci.cflags) < 0) - goto bad_syntax; - - /* methods value (param 9) */ - node = node->next; - if (str2int( &node->value, (unsigned int*)&ci.methods) < 0) - goto bad_syntax; - - if(sruid_next(&_ul_sruid)<0) - goto error; - ci.ruid = _ul_sruid.uid; - - lock_udomain( dom, aor); - - set_mi_ul_cid(); - n = get_urecord( dom, aor, &r); - if ( n==1) { - if (insert_urecord( dom, aor, &r) < 0) - goto lock_error; - c = 0; - } else { - if (get_ucontact( r, contact, &mi_ul_cid, &mi_ul_path, MI_UL_CSEQ+1, &c) < 0) - goto lock_error; - } - - get_act_time(); - - ci.callid = &mi_ul_cid; - ci.user_agent = &mi_ul_ua; - ci.cseq = ++MI_UL_CSEQ; - /* 0 expires means permanent contact */ - if (ci.expires!=0) - ci.expires += act_time; - - if (c) { - if (update_ucontact( r, c, &ci) < 0) - goto release_error; - } else { - if ( insert_ucontact( r, contact, &ci, &c) < 0 ) - goto release_error; - } - - release_urecord(r); - - unlock_udomain( dom, aor); - - return init_mi_tree( 200, MI_OK_S, MI_OK_LEN); -bad_syntax: - return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN); -release_error: - release_urecord(r); -lock_error: - unlock_udomain( dom, aor); -error: - return init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN); -} - - -/*! - * \brief Dumps the contacts of an AOR - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 2 nodes: the table name and the AOR - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_show_contact(struct mi_root *cmd, void *param) -{ - struct mi_root *rpl_tree; - struct mi_node *rpl, *node; - udomain_t *dom; - urecord_t *rec; - ucontact_t* con; - str *aor; - int ret; - - node = cmd->node.kids; - if (node==NULL || node->next==NULL || node->next->next!=NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - /* look for table */ - dom = mi_find_domain( &node->value ); - if (dom==NULL) - return init_mi_tree( 404, "Table not found", 15); - - /* process the aor */ - aor = &node->next->value; - if ( mi_fix_aor(aor)!=0 ) - return init_mi_tree( 400, "Domain missing in AOR", 21); - - lock_udomain( dom, aor); - - ret = get_urecord( dom, aor, &rec); - if (ret == 1) { - unlock_udomain( dom, aor); - return init_mi_tree( 404, "AOR not found", 13); - } - - get_act_time(); - rpl_tree = 0; - rpl = 0; - - for( con=rec->contacts ; con ; con=con->next) { - if (VALID_CONTACT( con, act_time)) { - if (rpl_tree==0) { - rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl_tree==0) - goto error; - rpl = &rpl_tree->node; - } - - node = addf_mi_node_child( rpl, 0, "Contact", 7, - "<%.*s>;q=%s;expires=%d;flags=0x%X;cflags=0x%X;state=%d;socket=<%.*s>;" - "methods=0x%X" - "%s%.*s%s" /*received*/ - "%s%.*s%s" /*user-agent*/ - "%s%.*s%s" /*path*/ - "%s%.*s" /*instance*/ - ";reg-id=%u", - con->c.len, ZSW(con->c.s), - q2str(con->q, 0), (int)(con->expires - act_time), - con->flags, con->cflags, con->state, - con->sock?con->sock->sock_str.len:3, - con->sock?con->sock->sock_str.s:"NULL", - con->methods, - con->received.len?";received=<":"",con->received.len, - ZSW(con->received.s), con->received.len?">":"", - con->user_agent.len?";user_agent=<":"",con->user_agent.len, - ZSW(con->user_agent.s), con->user_agent.len?">":"", - con->path.len?";path=<":"", con->path.len, - ZSW(con->path.s), con->path.len?">":"", - con->instance.len?";+sip.instance=":"", con->instance.len, - ZSW(con->instance.s), - con->reg_id - ); - if (node==0) - goto error; - } - } - - unlock_udomain( dom, aor); - - if (rpl_tree==0) - return init_mi_tree( 404 , "AOR has no contacts", 18); - - return rpl_tree; -error: - if (rpl_tree) - free_mi_tree( rpl_tree ); - unlock_udomain( dom, aor); - return 0; -} diff --git a/src/modules/usrloc/ul_mi.h b/src/modules/usrloc/ul_mi.h deleted file mode 100644 index 6fa10dfcce0..00000000000 --- a/src/modules/usrloc/ul_mi.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2006 Voice Sistem SRL - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/*! \file - * \brief USRLOC - Usrloc MI functions - * \ingroup usrloc - */ - - -#ifndef _USRLOC_MI_H_ -#define _USRLOC_MI_H_ - -#include "../../lib/kmi/mi.h" - -#define MI_USRLOC_RM "ul_rm" -#define MI_USRLOC_RM_CONTACT "ul_rm_contact" -#define MI_USRLOC_DUMP "ul_dump" -#define MI_USRLOC_FLUSH "ul_flush" -#define MI_USRLOC_ADD "ul_add" -#define MI_USRLOC_SHOW_CONTACT "ul_show_contact" - - -/*! - * \brief Delete a address of record including its contacts - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 2 nodes: the table name and the AOR - * \return mi_root with the result - */ -struct mi_root* mi_usrloc_rm_aor(struct mi_root *cmd, void *param); - - -/*! - * \brief Delete a contact from an AOR record - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 3 nodes: the table name, the AOR and contact - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_rm_contact(struct mi_root *cmd, void *param); - - -/*! - * \brief Dump the content of the usrloc - * \param cmd mi_root containing the parameter - * \param param not used - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_dump(struct mi_root *cmd, void *param); - - -/*! - * \brief Flush the usrloc memory cache to DB - * \param cmd mi_root containing the parameter - * \param param not used - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_flush(struct mi_root *cmd, void *param); - - -/*! - * \brief Add a new contact for an address of record - * \param cmd mi_root containing the parameter - * \param param not used - * \note Expects 7 nodes: table name, AOR, contact, expires, Q, - * useless - backward compatible, flags, cflags, methods - * \return mi_root with the result - */ -struct mi_root* mi_usrloc_add(struct mi_root *cmd, void *param); - - -/*! - * \brief Dumps the contacts of an AOR - * \param cmd mi_root containing the parameter - * \param param not used - * \note expects 2 nodes: the table name and the AOR - * \return mi_root with the result or 0 on failure - */ -struct mi_root* mi_usrloc_show_contact(struct mi_root *cmd, void *param); - - -#endif diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c index fa51e96b114..81346de631f 100644 --- a/src/modules/usrloc/usrloc_mod.c +++ b/src/modules/usrloc/usrloc_mod.c @@ -53,7 +53,6 @@ #include "udomain.h" /* {insert,delete,get,release}_urecord */ #include "urecord.h" /* {insert,delete,get}_ucontact */ #include "ucontact.h" /* update_ucontact */ -#include "ul_mi.h" #include "ul_rpc.h" #include "ul_callback.h" #include "usrloc.h" @@ -97,7 +96,6 @@ static void ul_core_timer(unsigned int ticks, void* param); /*!< Core timer han static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */ static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer handler */ static int child_init(int rank); /*!< Per-child init function */ -static int mi_child_init(void); #define UL_PRELOAD_SIZE 8 static char* ul_preload_list[UL_PRELOAD_SIZE]; @@ -188,7 +186,7 @@ static cmd_export_t cmds[] = { /*! \brief - * Exported parameters + * Exported parameters */ static param_export_t params[] = { {"ruid_column", PARAM_STR, &ruid_col }, @@ -245,30 +243,13 @@ stat_export_t mod_stats[] = { }; -static mi_export_t mi_cmds[] = { - { MI_USRLOC_RM, mi_usrloc_rm_aor, 0, 0, - mi_child_init }, - { MI_USRLOC_RM_CONTACT, mi_usrloc_rm_contact, 0, 0, - mi_child_init }, - { MI_USRLOC_DUMP, mi_usrloc_dump, 0, 0, - 0 }, - { MI_USRLOC_FLUSH, mi_usrloc_flush, MI_NO_INPUT_FLAG, 0, - mi_child_init }, - { MI_USRLOC_ADD, mi_usrloc_add, 0, 0, - mi_child_init }, - { MI_USRLOC_SHOW_CONTACT, mi_usrloc_show_contact, 0, 0, - mi_child_init }, - { 0, 0, 0, 0, 0} -}; - - struct module_exports exports = { "usrloc", DEFAULT_DLFLAGS, /*!< dlopen flags */ cmds, /*!< Exported functions */ params, /*!< Export parameters */ mod_stats, /*!< exported statistics */ - mi_cmds, /*!< exported MI functions */ + 0, /*!< exported MI functions */ 0, /*!< exported pseudo-variables */ 0, /*!< extra processes */ mod_init, /*!< Module initialization function */ @@ -296,12 +277,6 @@ static int mod_init(void) return -1; } #endif - - if(register_mi_mod(exports.name, mi_cmds)!=0) - { - LM_ERR("failed to register MI commands\n"); - return -1; - } if (rpc_register_array(ul_rpc)!=0) { @@ -457,30 +432,6 @@ static int child_init(int _rank) } -/* */ -static int mi_child_init(void) -{ - static int done = 0; - - if (done) - return 0; - - if (db_mode != NO_DB) { - ul_dbh = ul_dbf.init(&db_url); - if (!ul_dbh) { - LM_ERR("failed to connect to database\n"); - return -1; - } - } - - if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) - return -1; - done = 1; - - return 0; -} - - /*! \brief * Module destroy function */