浏览代码

module_k/p_usrloc Refactoring of p_usrloc (it uses the usrloc API include)

Marius Zbihlei 14 年之前
父节点
当前提交
edcca48414

+ 55 - 0
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

+ 1 - 1
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

+ 1 - 3
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

+ 15 - 0
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

+ 48 - 0
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

+ 4 - 0
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;