Module: sip-router
Branch: mariuszbihlei/p_usrloc
Commit: a03b115c72508aed5578bd10b3c96d196fc6d693
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a03b115…
Author: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Date: Thu Jan 20 12:08:34 2011 +0200
module_k/p_usrloc Refactoring of p_usrloc (it uses the usrloc API include)
---
modules_k/p_usrloc/dlist.h | 55 +++++++++++++++++++++++++++++++++++++++++
modules_k/p_usrloc/ucontact.c | 2 +-
modules_k/p_usrloc/ucontact.h | 4 +--
modules_k/p_usrloc/udomain.h | 15 +++++++++++
modules_k/p_usrloc/urecord.h | 48 +++++++++++++++++++++++++++++++++++
modules_k/p_usrloc/usrloc.c | 4 +++
6 files changed, 124 insertions(+), 4 deletions(-)
diff --git a/modules_k/p_usrloc/dlist.h b/modules_k/p_usrloc/dlist.h
index 97bbbb3..8ba4b92 100644
--- a/modules_k/p_usrloc/dlist.h
+++ b/modules_k/p_usrloc/dlist.h
@@ -70,5 +70,60 @@ int synchronize_all_udomains(void);
unsigned long get_number_of_users(void);
+/*!
+ * \brief Registers a new domain with usrloc
+ *
+ * Registers a new domain with usrloc. If the domain exists,
+ * a pointer to existing structure will be returned, otherwise
+ * a new domain will be created
+ * \param _n domain name
+ * \param _d new created domain
+ * \return 0 on success, -1 on failure
+ */
+int register_udomain(const char* _n, udomain_t** _d);
+
+/*!
+ * \brief Get all contacts from the usrloc, in partitions if wanted
+ *
+ * Return list of all contacts for all currently registered
+ * users in all domains. The caller must provide buffer of
+ * sufficient length for fitting all those contacts. In the
+ * case when buffer was exhausted, the function returns
+ * estimated amount of additional space needed, in this
+ * case the caller is expected to repeat the call using
+ * this value as the hint.
+ *
+ * Information is packed into the buffer as follows:
+ *
+ * +------------+----------+-----+------+-----+
+ * |contact1.len|contact1.s|sock1|flags1|path1|
+ * +------------+----------+-----+------+-----+
+ * |contact2.len|contact2.s|sock2|flags2|path1|
+ * +------------+----------+-----+------+-----+
+ * |..........................................|
+ * +------------+----------+-----+------+-----+
+ * |contactN.len|contactN.s|sockN|flagsN|pathN|
+ * +------------+----------+-----+------+-----+
+ * |000000000000|
+ * +------------+
+ *
+ * \param buf target buffer
+ * \param len length of buffer
+ * \param flags contact flags
+ * \param part_idx part index
+ * \param part_max maximal part
+ * \return 0 on success, positive if buffer size was not sufficient, negative on failure
+ */
+int get_all_ucontacts(void *, int, unsigned int,
+ unsigned int part_idx, unsigned int part_max);
+
+/*!
+ * \brief Find a particular domain, small wrapper around find_dlist
+ * \param _d domain name
+ * \param _p pointer to domain if found
+ * \return 1 if domain was found, 0 otherwise
+ */
+int find_domain(str* _d, udomain_t** _p);
+
#endif
diff --git a/modules_k/p_usrloc/ucontact.c b/modules_k/p_usrloc/ucontact.c
index b97f0f1..f7c0b9e 100644
--- a/modules_k/p_usrloc/ucontact.c
+++ b/modules_k/p_usrloc/ucontact.c
@@ -46,7 +46,7 @@
#include "urecord.h"
#include "ucontact.h"
#include "ul_db_layer.h"
-
+#include "dlist.h"
/*!
* \brief Create a new contact structure
diff --git a/modules_k/p_usrloc/ucontact.h b/modules_k/p_usrloc/ucontact.h
index 3dcb126..b8cf662 100644
--- a/modules_k/p_usrloc/ucontact.h
+++ b/modules_k/p_usrloc/ucontact.h
@@ -45,9 +45,6 @@
/*! \brief ancient time used for marking the contacts forced to expired */
#define UL_EXPIRED_TIME 10
-/*! \brief Valid contact is a contact that either didn't expire yet or is permanent
*/
-#define VALID_CONTACT(c, t) ((c->expires>t) || (c->expires==0))
-
/*!
* \brief Create a new contact structure
@@ -149,4 +146,5 @@ int db_delete_ucontact(ucontact_t* _c);
struct urecord;
+
#endif
diff --git a/modules_k/p_usrloc/udomain.h b/modules_k/p_usrloc/udomain.h
index 6a9a7a8..e6ce0ef 100644
--- a/modules_k/p_usrloc/udomain.h
+++ b/modules_k/p_usrloc/udomain.h
@@ -40,6 +40,7 @@
#include "../../locking.h"
#include "../../str.h"
#include "../../lib/srdb1/db.h"
+#include "../usrloc/usrloc.h"
#include "urecord.h"
#include "hslot.h"
@@ -142,6 +143,20 @@ void unlock_ulslot(udomain_t* _d, int i);
/* ===== module interface ======= */
+/*! \brief
+ * Timer handler for given domain
+ */
+void lock_udomain(udomain_t* _d, str *_aor);
+
+
+/*!
+ * \brief Release lock for a domain
+ * \param _d domain
+ * \param _aor address of record, uses as hash source for the lock slot
+ */
+void unlock_udomain(udomain_t* _d, str *_aor);
+
+
#endif
diff --git a/modules_k/p_usrloc/urecord.h b/modules_k/p_usrloc/urecord.h
index dfabddc..34442d8 100644
--- a/modules_k/p_usrloc/urecord.h
+++ b/modules_k/p_usrloc/urecord.h
@@ -113,6 +113,54 @@ void timer_urecord(urecord_t* _r);
*/
int db_delete_urecord(struct udomain* _d, urecord_t* _r);
+/*!
+ * \brief Create and insert new contact into urecord
+ * \param _r record into the new contact should be inserted
+ * \param _contact contact string
+ * \param _ci contact information
+ * \param _c new created contact
+ * \return 0 on success, -1 on failure
+ */
+int insert_ucontact(urecord_t* _r, str* _contact,
+ ucontact_info_t* _ci, ucontact_t** _c);
+
+
+/*!
+ * \brief Delete ucontact from urecord
+ * \param _r record where the contact belongs to
+ * \param _c deleted contact
+ * \return 0 on success, -1 on failure
+ */
+int delete_ucontact(urecord_t* _r, struct ucontact* _c);
+
+
+/*!
+ * \brief Get pointer to ucontact with given contact
+ * \param _r record where to search the contacts
+ * \param _c contact string
+ * \param _callid callid
+ * \param _path path
+ * \param _cseq CSEQ number
+ * \param _co found contact
+ * \return 0 - found, 1 - not found, -1 - invalid found,
+ * -2 - found, but to be skipped (same cseq)
+ */
+int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
+ int _cseq,
+ struct ucontact** _co);
+
+/* ===== Module interface ======== */
+
+
+/*!
+ * \brief Release urecord previously obtained through get_urecord
+ * \warning Failing to calls this function after get_urecord will
+ * result in a memory leak when the DB_ONLY mode is used. When
+ * the records is later deleted, e.g. with delete_urecord, then
+ * its not necessary, as this function already releases the record.
+ * \param _r released record
+ */
+void release_urecord(urecord_t* _r);
#endif
diff --git a/modules_k/p_usrloc/usrloc.c b/modules_k/p_usrloc/usrloc.c
index b74632f..3a1b4fc 100644
--- a/modules_k/p_usrloc/usrloc.c
+++ b/modules_k/p_usrloc/usrloc.c
@@ -36,6 +36,10 @@
#include "../usrloc/usrloc.h"
#include "../../sr_module.h"
#include "p_usrloc_mod.h"
+#include "ucontact.h"
+#include "udomain.h"
+#include "dlist.h"
+#include "urecord.h"
/*! nat branch flag */
extern unsigned int nat_bflag;