Module: sip-router
Branch: mariuszbihlei/p_usrloc
Commit: eee864b9cea1451ee1d3a6b6e651ad9ca6dc1350
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=eee864b…
Author: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei(a)1and1.ro>
Date: Thu Jan 20 13:23:56 2011 +0200
Further refactoring of usrloc and p_usrloc
---
modules_k/p_usrloc/udomain.h | 32 +++++++++++++++++++++++--
modules_k/p_usrloc/urecord.h | 1 +
modules_k/usrloc/dlist.h | 49 ++++++++++++++++++++++++++++++++++++++
modules_k/usrloc/ucontact.h | 11 ++++++++
modules_k/usrloc/udomain.h | 42 +++++++++++++++++++++++++++++++++
modules_k/usrloc/urecord.h | 53 ++++++++++++++++++++++++++++++++++++++++++
6 files changed, 185 insertions(+), 3 deletions(-)
diff --git a/modules_k/p_usrloc/udomain.h b/modules_k/p_usrloc/udomain.h
index e6ce0ef..7524b37 100644
--- a/modules_k/p_usrloc/udomain.h
+++ b/modules_k/p_usrloc/udomain.h
@@ -90,9 +90,6 @@ void free_udomain(udomain_t* _d);
void print_udomain(FILE* _f, udomain_t* _d);
-
-
-
/*!
* \brief Timer function to cleanup expired contacts, DB_ONLY db_mode
* \param _d cleaned domain
@@ -158,5 +155,34 @@ void unlock_udomain(udomain_t* _d, str *_aor);
+/*!
+ * \brief Create and insert a new record
+ * \param _d domain to insert the new record
+ * \param _aor address of the record
+ * \param _r new created record
+ * \return return 0 on success, -1 on failure
+ */
+int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+
+
+/*!
+ * \brief Obtain a urecord pointer if the urecord exists in domain
+ * \param _d domain to search the record
+ * \param _aor address of record
+ * \param _r new created record
+ * \return 0 if a record was found, 1 if nothing could be found
+ */
+int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+
+
+/*!
+ * \brief Delete a urecord from domain
+ * \param _d domain where the record should be deleted
+ * \param _aor address of record
+ * \param _r deleted record
+ * \return 0 on success, -1 if the record could not be deleted
+ */
+int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
+
#endif
diff --git a/modules_k/p_usrloc/urecord.h b/modules_k/p_usrloc/urecord.h
index 34442d8..14bafc6 100644
--- a/modules_k/p_usrloc/urecord.h
+++ b/modules_k/p_usrloc/urecord.h
@@ -163,4 +163,5 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
void release_urecord(urecord_t* _r);
+
#endif
diff --git a/modules_k/usrloc/dlist.h b/modules_k/usrloc/dlist.h
index 5602c67..87692df 100644
--- a/modules_k/usrloc/dlist.h
+++ b/modules_k/usrloc/dlist.h
@@ -54,6 +54,19 @@ extern dlist_t* root;
/*!
+ * \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 Free all allocated memory for domains
*/
void free_all_udomains(void);
@@ -74,6 +87,42 @@ int synchronize_all_udomains(void);
/*!
+ * \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 Loops through all domains summing up the number of users
* \return the number of users, could be zero
*/
diff --git a/modules_k/usrloc/ucontact.h b/modules_k/usrloc/ucontact.h
index 9686a07..6a8a4df 100644
--- a/modules_k/usrloc/ucontact.h
+++ b/modules_k/usrloc/ucontact.h
@@ -39,6 +39,7 @@
#include <stdio.h>
#include "usrloc.h"
+
/*! \brief ancient time used for marking the contacts forced to expired */
#define UL_EXPIRED_TIME 10
@@ -137,5 +138,15 @@ int db_update_ucontact(ucontact_t* _c);
*/
int db_delete_ucontact(ucontact_t* _c);
+/* ====== Module interface ====== */
+
+/*!
+ * \brief Update ucontact with new values
+ * \param _r record the contact belongs to
+ * \param _c updated contact
+ * \param _ci new contact informations
+ * \return 0 on success, -1 on failure
+ */
+int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
#endif
diff --git a/modules_k/usrloc/udomain.h b/modules_k/usrloc/udomain.h
index 62509c6..b10df5d 100644
--- a/modules_k/usrloc/udomain.h
+++ b/modules_k/usrloc/udomain.h
@@ -138,6 +138,21 @@ int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord**
_r);
*/
void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
+
+/*! \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);
+
+
/*!
* \brief Get lock for a slot
* \param _d domain
@@ -155,7 +170,34 @@ void unlock_ulslot(udomain_t* _d, int i);
/* ===== module interface ======= */
+/*!
+ * \brief Create and insert a new record
+ * \param _d domain to insert the new record
+ * \param _aor address of the record
+ * \param _r new created record
+ * \return return 0 on success, -1 on failure
+ */
+int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+
+
+/*!
+ * \brief Obtain a urecord pointer if the urecord exists in domain
+ * \param _d domain to search the record
+ * \param _aor address of record
+ * \param _r new created record
+ * \return 0 if a record was found, 1 if nothing could be found
+ */
+int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+
+/*!
+ * \brief Delete a urecord from domain
+ * \param _d domain where the record should be deleted
+ * \param _aor address of record
+ * \param _r deleted record
+ * \return 0 on success, -1 if the record could not be deleted
+ */
+int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
#endif
diff --git a/modules_k/usrloc/urecord.h b/modules_k/usrloc/urecord.h
index 93231d0..5245b2a 100644
--- a/modules_k/usrloc/urecord.h
+++ b/modules_k/usrloc/urecord.h
@@ -38,6 +38,11 @@
#include "ucontact.h"
#include "usrloc.h"
+struct hslot; /*!< Hash table slot */
+
+
+
+
/*!
* \brief Create and initialize new record structure
* \param _dom domain name
@@ -114,6 +119,54 @@ void timer_urecord(urecord_t* _r);
int db_delete_urecord(urecord_t* _r);
+/* ===== 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);
+
+/*!
+ * \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);
#endif