Explorar o código

modules/p_usrloc Module implement the API of usrloc module.

Marius Zbihlei %!s(int64=14) %!d(string=hai) anos
pai
achega
81f9a40cd0

+ 1 - 18
modules_k/p_usrloc/dlist.h

@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include "udomain.h"
 #include "../../str.h"
+#include "../usrloc/usrloc.h"
 
 
 /*!
@@ -49,30 +50,12 @@ struct domain_list_item {
 	struct domain_list_item*next;
 };
 
-/*!
- * \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
- */
-typedef int (*register_udomain_t)(const char* _n, udomain_t** _d);
-int register_udomain(const char* _n, udomain_t** _d);
-
 
 /*!
  * \brief Free all allocated memory for domains
  */
 void free_all_udomains(void);
 
-typedef int  (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
-              unsigned int part_idx, unsigned int part_max);
-
-int get_all_ucontacts(void *, int, unsigned int,
-                unsigned int part_idx, unsigned int part_max);
 
 /*!
  * \brief Run timer handler of all domains

+ 6 - 3
modules_k/p_usrloc/p_usrloc_mod.c

@@ -60,18 +60,17 @@
 #include "../../timer.h"     /* register_timer */
 #include "../../globals.h"   /* is_main */
 #include "../../ut.h"        /* str_init */
-#include "dlist.h"           /* register_udomain */
 #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_callback.h"
-#include "usrloc.h"
+#include "../usrloc/ul_callback.h"
 #include "ul_db_api.h"
 #include "ul_db_watch.h"
 #include "ul_check.h"
 #include "ul_db.h"
 #include "ul_db_layer.h"
+#include "dlist.h"
 
 MODULE_VERSION
 
@@ -389,6 +388,10 @@ static int mod_init(void)
 		return  -1;
 	}
 
+	if (db_mode == WRITE_BACK) {
+		LM_WARN("The WRITE BACK mode will create discrepancies between memory and db backend");
+	}
+
 	/* Shall we use database ? */
 	if (db_mode != NO_DB) { /* Yes */
 		if(!default_db_url.s || !strlen(default_db_url.s)){

+ 1 - 6
modules_k/p_usrloc/p_usrloc_mod.h

@@ -37,17 +37,12 @@
 #include "../../lib/srdb1/db.h"
 #include "../../str.h"
 #include "../../lib/kmi/mi.h"
+#include "../usrloc/usrloc.h"
 
 /*
  * Module parameters
  */
 
-
-#define NO_DB         0
-#define WRITE_THROUGH 1
-#define WRITE_BACK    2
-#define DB_ONLY       3
-
 #define UL_TABLE_VERSION 1004
 
 /*

+ 1 - 1
modules_k/p_usrloc/ucontact.c

@@ -42,7 +42,7 @@
 #include "../../dprint.h"
 #include "../../lib/srdb1/db.h"
 #include "p_usrloc_mod.h"
-#include "ul_callback.h"
+#include "../usrloc/ul_callback.h"
 #include "urecord.h"
 #include "ucontact.h"
 #include "ul_db_layer.h"

+ 1 - 68
modules_k/p_usrloc/ucontact.h

@@ -40,64 +40,7 @@
 #include <time.h>
 #include "../../qvalue.h"
 #include "../../str.h"
-
-
-/*!
- * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc)
- */
-typedef enum cstate {
-	CS_NEW,        /*!< New contact - not flushed yet */
-	CS_SYNC,       /*!< Synchronized contact with the database */
-	CS_DIRTY       /*!< Update contact - not flushed yet */
-} cstate_t;
-
-
-/*! \brief Flags that can be associated with a Contact */
-typedef enum flags {
-	FL_NONE        = 0,          /*!< No flags set */
-	FL_MEM         = 1 << 0,     /*!< Update memory only */
-	FL_ALL         = (int)0xFFFFFFFF  /*!< All flags set */
-} flags_t;
-
-
-/*! \brief Main structure for handling of registered Contact data */
-typedef struct ucontact {
-	str* domain;            /*!< Pointer to domain name (NULL terminated) */
-	str* aor;               /*!< Pointer to the AOR string in record structure*/
-	str c;                  /*!< Contact address */
-	str received;           /*!< IP+port+protocol we received the REGISTER from */
-	str path;               /*!< Path header */
-	time_t expires;         /*!< Expires parameter */
-	qvalue_t q;             /*!< q parameter */
-	str callid;             /*!< Call-ID header field of registration */
-	int cseq;               /*!< CSeq value */
-	cstate_t state;         /*!< State of the contact (\ref cstate) */
-	unsigned int flags;     /*!< Various flags (NAT, ping type, etc) */
-	unsigned int cflags;    /*!< Custom contact flags (from script) */
-	str user_agent;         /*!< User-Agent header field */
-	struct socket_info *sock; /*!< received socket */
-	time_t last_modified;   /*!< When the record was last modified */
-	unsigned int methods;   /*!< Supported methods */
-	struct ucontact* next;  /*!< Next contact in the linked list */
-	struct ucontact* prev;  /*!< Previous contact in the linked list */
-} ucontact_t;
-
-
-/*! \brief Informations related to a contact */
-typedef struct ucontact_info {
-	str received;             /*!< Received interface */
-	str* path;                /*!< Path informations */
-	time_t expires;           /*!< Contact expires */
-	qvalue_t q;               /*!< Q-value */
-	str* callid;              /*!< call-ID */
-	int cseq;                 /*!< CSEQ number */
-	unsigned int flags;       /*!< message flags */
-	unsigned int cflags;      /*!< contact flags */
-	str *user_agent;          /*!< user agent header */
-	struct socket_info *sock; /*!< socket informations */
-	unsigned int methods;     /*!< supported methods */
-	time_t last_modified;     /*!< last modified */
-} ucontact_info_t;
+#include "../usrloc/usrloc.h"
 
 /*! \brief ancient time used for marking the contacts forced to expired */
 #define UL_EXPIRED_TIME 10
@@ -205,15 +148,5 @@ int db_delete_ucontact(ucontact_t* _c);
 
 struct urecord;
 
-/*!
- * \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
- */
-typedef int (*update_ucontact_t)(struct urecord* _r, ucontact_t* _c,
-		ucontact_info_t* _ci);
-int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
 
 #endif

+ 2 - 49
modules_k/p_usrloc/udomain.h

@@ -51,7 +51,7 @@ struct urecord; /*!< Usrloc record */
 /*! \brief
  * The structure represents a usrloc domain
  */
-typedef struct udomain {
+struct udomain {
 	str* name;                 /*!< Domain name (NULL terminated) */
 	int size;                  /*!< Hash table size */
 	struct hslot* table;       /*!< Hash table - array of collision slots */
@@ -62,7 +62,7 @@ typedef struct udomain {
 	/* for ul_db_layer */
 	int dbt;                   /* type of the database */
 	db1_con_t * dbh;            /* database handle */
-} udomain_t;
+};
 
 
 /*!
@@ -125,21 +125,6 @@ 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
- */
-typedef void (*lock_udomain_t)(udomain_t* _d, str *_aor);
-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
- */
-typedef void (*unlock_udomain_t)(udomain_t* _d, str *_aor);
-void unlock_udomain(udomain_t* _d, str *_aor);
-
 
 /*!
  * \brief  Get lock for a slot
@@ -158,37 +143,5 @@ 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
- */
-typedef int (*insert_urecord_t)(udomain_t* _d, str* _aor, struct urecord** _r);
-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
- */
-typedef int  (*get_urecord_t)(udomain_t* _d, str* _aor, struct urecord** _r);
-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
- */
-typedef int  (*delete_urecord_t)(udomain_t* _d, str* _aor, struct urecord* _r);
-int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
-
 
 #endif

+ 2 - 2
modules_k/p_usrloc/ul_callback.c

@@ -37,8 +37,8 @@
 #include "../../dprint.h"
 #include "../../error.h"
 #include "../../mem/shm_mem.h"
-#include "ul_callback.h"
-
+#include "../usrloc/ul_callback.h"
+#include "udomain.h"
 
 struct ulcb_head_list* ulcb_list = 0;
 

+ 0 - 95
modules_k/p_usrloc/ul_callback.h

@@ -1,95 +0,0 @@
-/*
- * $Id: ul_callback.h 5003 2008-09-26 11:01:51Z henningw $
- *
- * Copyright (C) 2001-2003 FhG Fokus
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * History:
- * --------
- *  2004-03-16  created (bogdan)
- */
-
-/*! \file
- *  \brief USRLOC - Module callbacks
- *  \ingroup usrloc
- */
-
-#ifndef _UL_CALLBACKS_H
-#define _UL_CALLBACKS_H
-
-#include "ucontact.h"
-
-
-#define UL_CONTACT_INSERT      (1<<0)
-#define UL_CONTACT_UPDATE      (1<<1)
-#define UL_CONTACT_DELETE      (1<<2)
-#define UL_CONTACT_EXPIRE      (1<<3)
-#define ULCB_MAX               ((1<<4)-1)
-
-/*! \brief callback function prototype */
-typedef void (ul_cb) (ucontact_t *c, int type, void *param);
-/*! \brief register callback function prototype */
-typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
-
-
-struct ul_callback {
-	int id;                      /*!< id of this callback - useless */
-	int types;                   /*!< types of events that trigger the callback*/
-	ul_cb* callback;             /*!< callback function */
-	void *param;                 /*!< param to be passed to callback function */
-	struct ul_callback* next;
-};
-
-struct ulcb_head_list {
-	struct ul_callback *first;
-	int reg_types;
-};
-
-
-extern struct ulcb_head_list*  ulcb_list;
-
-
-#define exists_ulcb_type(_types_) \
-	( (ulcb_list->reg_types)|(_types_) )
-
-
-int init_ulcb_list(void);
-
-void destroy_ulcb_list(void);
-
-
-/*! \brief register a callback for several types of events */
-int register_ulcb( int types, ul_cb f, void *param );
-
-/*! \brief run all transaction callbacks for an event type */
-static inline void run_ul_callbacks( int type , ucontact_t *c)
-{
-	struct ul_callback *cbp;
-
-	for (cbp=ulcb_list->first; cbp; cbp=cbp->next)  {
-		if(cbp->types&type) {
-			LM_DBG("contact=%p, callback type %d/%d, id %d entered\n",
-				c, type, cbp->types, cbp->id );
-			cbp->callback( c, type, cbp->param );
-		}
-	}
-}
-
-
-
-#endif

+ 1 - 1
modules_k/p_usrloc/ul_db_layer.c

@@ -151,7 +151,7 @@ int ul_db_layer_query(udomain_t * domain, str * user, str * sipdomain,
 	int ret;
 	switch(domain->dbt) {
 			case DB_TYPE_CLUSTER:{ 
-			LM_ERR("CALLING CLUSTER QUERY\n");
+			LM_ERR("CALLING CLUSTER QUERY for %.*s \n" , user->len, user->s);
 			if((ret = p_ul_dbf.query(domain->name, user, sipdomain, &h, _k, _op, _v, _c, _n, _nc, _o, _r)) < 0 || (!_r)) {
 				return -1;
 			}

+ 3 - 1
modules_k/p_usrloc/ul_db_layer.h

@@ -2,7 +2,9 @@
 #define UL_DB_LAYER_H
 
 #include "../../lib/srdb1/db.h"
-#include "usrloc.h"
+#include "../usrloc/usrloc.h"
+#include "udomain.h"
+#include "ucontact.h"
 
 #define DB_TYPE_CLUSTER 0
 #define DB_TYPE_CLUSTER_STR "cluster"

+ 3 - 2
modules_k/p_usrloc/urecord.c

@@ -33,7 +33,7 @@
  * - Module \ref usrloc
  */
 
-
+#include "../usrloc/usrloc.h"
 #include "urecord.h"
 #include <string.h>
 #include "../../mem/shm_mem.h"
@@ -42,7 +42,8 @@
 #include "../../lib/kcore/hash_func.h"
 #include "p_usrloc_mod.h"
 #include "utime.h"
-#include "ul_callback.h"
+#include "../usrloc/ul_callback.h"
+
 #include "ul_db_layer.h"
 
 

+ 1 - 75
modules_k/p_usrloc/urecord.h

@@ -36,27 +36,7 @@
 #include "../../str.h"
 #include "../../qvalue.h"
 #include "ucontact.h"
-
-
-struct hslot; /*!< Hash table slot */
-struct udomain;
-
-/*! \brief
- * Basic hash table element
- */
-typedef struct urecord {
-	str* domain;                   /*!< Pointer to domain we belong to 
-                                    * ( null terminated string) */
-	str aor;                       /*!< Address of record */
-	unsigned int aorhash;          /*!< Hash over address of record */
-	ucontact_t* contacts;          /*!< One or more contact fields */
-
-	struct hslot* slot;            /*!< Collision slot in the hash table 
-                                    * array we belong to */
-	struct urecord* prev;          /*!< Next item in the hash entry */
-	struct urecord* next;          /*!< Previous item in the hash entry */
-} urecord_t;
-
+#include "../usrloc/usrloc.h"
 
 /*!
  * \brief Create and initialize new record structure
@@ -134,59 +114,5 @@ void timer_urecord(urecord_t* _r);
 int db_delete_urecord(struct udomain* _d, 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
- */
-typedef void (*release_urecord_t)(urecord_t* _r);
-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
- */
-typedef int (*insert_ucontact_t)(urecord_t* _r, str* _contact,
-		ucontact_info_t* _ci, ucontact_t** _c);
-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
- */
-typedef int (*delete_ucontact_t)(urecord_t* _r, struct ucontact* _c);
-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 _cseq CSEQ number
- * \param _co found contact
- * \return 0 - found, 1 - not found, -1 - invalid found, 
- * -2 - found, but to be skipped (same cseq)
- */
-typedef int (*get_ucontact_t)(urecord_t* _r, str* _c, str* _callid, str* path, int _cseq,
-		struct ucontact** _co);
-int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* path,  int _cseq,
-		struct ucontact** _co);
-
 
 #endif

+ 1 - 1
modules_k/p_usrloc/usrloc.c

@@ -33,7 +33,7 @@
  * - Module \ref usrloc
  */
 
-#include "usrloc.h"
+#include "../usrloc/usrloc.h"
 #include "../../sr_module.h"
 #include "p_usrloc_mod.h"