src/modules/usrloc/usrloc.h
31ccf6a2
 /*
  * Copyright (C) 2001-2003 FhG Fokus
  *
27642a08
  * This file is part of Kamailio, a free SIP server.
31ccf6a2
  *
27642a08
  * Kamailio is free software; you can redistribute it and/or modify
31ccf6a2
  * 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
  *
27642a08
  * Kamailio is distributed in the hope that it will be useful,
31ccf6a2
  * 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.
  *
10d6b2b7
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31ccf6a2
  */
 
adfa93a7
 /*! \file
4d87f9db
  *  \brief USRLOC - module API exports interface
adfa93a7
  *  \ingroup usrloc
  */
31ccf6a2
 
 #ifndef USRLOC_H
 #define USRLOC_H
 
f65d06bc
 #include <time.h>
31ccf6a2
 #include "ul_callback.h"
cf83221d
 #include "../../core/qvalue.h"
 #include "../../core/str.h"
 #include "../../core/xavp.h"
31ccf6a2
 
efe9d9d4
 #define NO_DB         0
 #define WRITE_THROUGH 1
 #define WRITE_BACK    2
 #define DB_ONLY       3
d80ea02f
 #define DB_READONLY   4
efe9d9d4
 
039231a3
 #define GAU_OPT_SERVER_ID  (1<<0)  /* filter query by server_id */
 
f65d06bc
 /*forward declaration necessary for udomain*/
 
 struct udomain;
 typedef struct udomain udomain_t;
 
 /*!
  * \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 */
06408532
 	FL_DMQRPL      = 1 << 1,     /*!< DMQ replication */
3de21172
 	FL_EXPCLB      = 1 << 2,     /*!< Expired callback executed */
f65d06bc
 	FL_ALL         = (int)0xFFFFFFFF  /*!< All flags set */
 } flags_t;
 
 /*! \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))
 
 struct hslot; /*!< Hash table slot */
 struct socket_info;
 /*! \brief Main structure for handling of registered Contact data */
 typedef struct ucontact {
 	str* domain;            /*!< Pointer to domain name (NULL terminated) */
05823430
 	str ruid;               /*!< Pointer to record internal unique id */
f65d06bc
 	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) */
f47700bb
 	unsigned int flags;     /*!< Various internal flags (sync, etc) */
 	unsigned int cflags;    /*!< Custom contact flags (from script - bflags) */
f65d06bc
 	str user_agent;         /*!< User-Agent header field */
d1f525c9
 	str uniq;               /*!< Uniq header field */
f65d06bc
 	struct socket_info *sock; /*!< received socket */
 	time_t last_modified;   /*!< When the record was last modified */
68928e95
 	time_t last_keepalive;  /*!< Last keepalive timestamp */
 	unsigned int ka_roundtrip; /*!< Keepalive roundtrip in microseconds */
f65d06bc
 	unsigned int methods;   /*!< Supported methods */
05823430
 	str instance;           /*!< SIP instance value - gruu */
221073eb
 	unsigned int reg_id;    /*!< reg-id parameters */
67e40ec0
 	int server_id;          /*!< server id */
 	int tcpconn_id;         /*!< unique tcp connection id */
 	int keepalive;          /*!< keepalive */
e6ad428f
 	sr_xavp_t * xavp;       /*!< per contact xavps */
f65d06bc
 	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 {
05823430
 	str ruid;                 /*!< Pointer to record internal unique id */
a7cad776
 	str *c;                   /*!< Contact address */
f65d06bc
 	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 */
05823430
 	str instance;             /*!< SIP instance value - gruu */
221073eb
 	unsigned int reg_id;      /*!< reg-id parameters */
67e40ec0
 	int server_id;            /*!< server id */
 	int tcpconn_id;           /*!< connection id */
 	int keepalive;            /*!< keepalive */
e6ad428f
 	sr_xavp_t * xavp;         /*!< per contact xavps */
f65d06bc
 	time_t last_modified;     /*!< last modified */
 } ucontact_info_t;
 
 typedef struct udomain_head{
     str* name;
 } udomain_head_t;
 
 /*! \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;
 
 typedef int (*insert_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
 
05823430
 typedef int (*get_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
 
 typedef int (*get_urecord_by_ruid_t)(udomain_t* _d, unsigned int _aorhash,
 		str *_ruid, struct urecord** _r, struct ucontact** _c);
f65d06bc
 
 typedef int  (*delete_urecord_t)(struct udomain* _d, str* _aor, struct urecord* _r);
 
6c385398
 typedef int  (*delete_urecord_by_ruid_t)(struct udomain* _d, str* _ruid);
 
f65d06bc
 typedef int (*update_ucontact_t)(struct urecord* _r, struct ucontact* _c,
 		struct ucontact_info* _ci);
 typedef void (*release_urecord_t)(struct urecord* _r);
 
 typedef int (*insert_ucontact_t)(struct urecord* _r, str* _contact,
 		struct ucontact_info* _ci, struct ucontact** _c);
 
 typedef int (*delete_ucontact_t)(struct urecord* _r, struct ucontact* _c);
 
 typedef int (*get_ucontact_t)(struct urecord* _r, str* _c, str* _callid,
 		str* _path, int _cseq,
 		struct ucontact** _co);
 
221073eb
 typedef int (*get_ucontact_by_instance_t)(struct urecord* _r, str* _c,
 		ucontact_info_t* _ci, ucontact_t** _co);
05823430
 
f65d06bc
 typedef void (*lock_udomain_t)(struct udomain* _d, str *_aor);
 
 typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor);
 
 typedef int (*register_udomain_t)(const char* _n, struct udomain** _d);
 
 typedef int  (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
039231a3
 		unsigned int part_idx, unsigned int part_max, int options);
31ccf6a2
 
592e5b81
 typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);
 
05823430
 typedef unsigned int (*ul_get_aorhash_t)(str *_aor);
 unsigned int ul_get_aorhash(str *_aor);
 
36845cc5
 typedef int (*ul_set_keepalive_timeout_t)(int _to);
 int ul_set_keepalive_timeout(int _to);
 
 typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid);
 int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid);
 
68928e95
 int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval,
 		unsigned int rtrip);
8f8d4f5d
 
 typedef void (*ul_set_max_partition_t)(unsigned int m);
 
4d87f9db
 /*! usrloc API export structure */
31ccf6a2
 typedef struct usrloc_api {
4d87f9db
 	int           use_domain; /*! use_domain module parameter */
 	int           db_mode;    /*! db_mode module parameter */
 	unsigned int  nat_flag;   /*! nat_flag module parameter */
cffbf08f
 
31ccf6a2
 	register_udomain_t   register_udomain;
c7e65c0f
 	get_udomain_t        get_udomain;
31ccf6a2
 	get_all_ucontacts_t  get_all_ucontacts;
 
 	insert_urecord_t     insert_urecord;
 	delete_urecord_t     delete_urecord;
6c385398
 	delete_urecord_by_ruid_t     delete_urecord_by_ruid;
31ccf6a2
 	get_urecord_t        get_urecord;
 	lock_udomain_t       lock_udomain;
 	unlock_udomain_t     unlock_udomain;
 
 	release_urecord_t    release_urecord;
 	insert_ucontact_t    insert_ucontact;
 	delete_ucontact_t    delete_ucontact;
 	get_ucontact_t       get_ucontact;
 
05823430
 	get_urecord_by_ruid_t       get_urecord_by_ruid;
 	get_ucontact_by_instance_t  get_ucontact_by_instance;
 
31ccf6a2
 	update_ucontact_t    update_ucontact;
 
 	register_ulcb_t      register_ulcb;
05823430
 	ul_get_aorhash_t     get_aorhash;
36845cc5
 
 	ul_set_keepalive_timeout_t set_keepalive_timeout;
 	ul_refresh_keepalive_t     refresh_keepalive;
8f8d4f5d
 	ul_set_max_partition_t     set_max_partition;
31ccf6a2
 } usrloc_api_t;
 
 
4d87f9db
 /*! usrloc API export bind function */
31ccf6a2
 typedef int (*bind_usrloc_t)(usrloc_api_t* api);
 
4d87f9db
 #endif