1 /* 2 * Copyright (C) 2001-2003 FhG Fokus 3 * 4 * This file is part of Kamailio, a free SIP server. 5 * 6 * Kamailio is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version 10 * 11 * Kamailio is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /*! \file 22 * \brief USRLOC - module API exports interface 23 * \ingroup usrloc 24 */ 25 26 #ifndef USRLOC_H 27 #define USRLOC_H 28 29 #include <time.h> 30 #include "ul_callback.h" 31 #include "../../core/qvalue.h" 32 #include "../../core/str.h" 33 #include "../../core/xavp.h" 34 35 #define NO_DB 0 36 #define WRITE_THROUGH 1 37 #define WRITE_BACK 2 38 #define DB_ONLY 3 39 #define DB_READONLY 4 40 41 #define GAU_OPT_SERVER_ID (1<<0) /* filter query by server_id */ 42 43 /*forward declaration necessary for udomain*/ 44 45 struct udomain; 46 typedef struct udomain udomain_t; 47 48 /*! 49 * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc) 50 */ 51 typedef enum cstate { 52 CS_NEW, /*!< New contact - not flushed yet */ 53 CS_SYNC, /*!< Synchronized contact with the database */ 54 CS_DIRTY /*!< Update contact - not flushed yet */ 55 } cstate_t; 56 57 58 /*! \brief Flags that can be associated with a Contact */ 59 typedef enum flags { 60 FL_NONE = 0, /*!< No flags set */ 61 FL_MEM = 1 << 0, /*!< Update memory only */ 62 FL_DMQRPL = 1 << 1, /*!< DMQ replication */ 63 FL_EXPCLB = 1 << 2, /*!< Expired callback executed */ 64 FL_ALL = (int)0xFFFFFFFF /*!< All flags set */ 65 } flags_t; 66 67 /*! \brief Valid contact is a contact that either didn't expire yet or is permanent */ 68 #define VALID_CONTACT(c, t) ((c->expires>t) || (c->expires==0)) 69 70 struct hslot; /*!< Hash table slot */ 71 struct socket_info; 72 /*! \brief Main structure for handling of registered Contact data */ 73 typedef struct ucontact { 74 str* domain; /*!< Pointer to domain name (NULL terminated) */ 75 str ruid; /*!< Pointer to record internal unique id */ 76 str* aor; /*!< Pointer to the AOR string in record structure*/ 77 str c; /*!< Contact address */ 78 str received; /*!< IP+port+protocol we received the REGISTER from */ 79 str path; /*!< Path header */ 80 time_t expires; /*!< Expires parameter */ 81 qvalue_t q; /*!< q parameter */ 82 str callid; /*!< Call-ID header field of registration */ 83 int cseq; /*!< CSeq value */ 84 cstate_t state; /*!< State of the contact (\ref cstate) */ 85 unsigned int flags; /*!< Various internal flags (sync, etc) */ 86 unsigned int cflags; /*!< Custom contact flags (from script - bflags) */ 87 str user_agent; /*!< User-Agent header field */ 88 str uniq; /*!< Uniq header field */ 89 struct socket_info *sock; /*!< received socket */ 90 time_t last_modified; /*!< When the record was last modified */ 91 time_t last_keepalive; /*!< Last keepalive timestamp */ 92 unsigned int ka_roundtrip; /*!< Keepalive roundtrip in microseconds */ 93 unsigned int methods; /*!< Supported methods */ 94 str instance; /*!< SIP instance value - gruu */ 95 unsigned int reg_id; /*!< reg-id parameters */ 96 int server_id; /*!< server id */ 97 int tcpconn_id; /*!< unique tcp connection id */ 98 int keepalive; /*!< keepalive */ 99 sr_xavp_t * xavp; /*!< per contact xavps */ 100 struct ucontact* next; /*!< Next contact in the linked list */ 101 struct ucontact* prev; /*!< Previous contact in the linked list */ 102 } ucontact_t; 103 104 105 /*! \brief Informations related to a contact */ 106 typedef struct ucontact_info { 107 str ruid; /*!< Pointer to record internal unique id */ 108 str *c; /*!< Contact address */ 109 str received; /*!< Received interface */ 110 str* path; /*!< Path informations */ 111 time_t expires; /*!< Contact expires */ 112 qvalue_t q; /*!< Q-value */ 113 str* callid; /*!< call-ID */ 114 int cseq; /*!< CSEQ number */ 115 unsigned int flags; /*!< message flags */ 116 unsigned int cflags; /*!< contact flags */ 117 str *user_agent; /*!< user agent header */ 118 struct socket_info *sock; /*!< socket informations */ 119 unsigned int methods; /*!< supported methods */ 120 str instance; /*!< SIP instance value - gruu */ 121 unsigned int reg_id; /*!< reg-id parameters */ 122 int server_id; /*!< server id */ 123 int tcpconn_id; /*!< connection id */ 124 int keepalive; /*!< keepalive */ 125 sr_xavp_t * xavp; /*!< per contact xavps */ 126 time_t last_modified; /*!< last modified */ 127 } ucontact_info_t; 128 129 typedef struct udomain_head{ 130 str* name; 131 } udomain_head_t; 132 133 /*! \brief 134 * Basic hash table element 135 */ 136 typedef struct urecord { 137 str* domain; /*!< Pointer to domain we belong to 138 * ( null terminated string) */ 139 str aor; /*!< Address of record */ 140 unsigned int aorhash; /*!< Hash over address of record */ 141 ucontact_t* contacts; /*!< One or more contact fields */ 142 143 struct hslot* slot; /*!< Collision slot in the hash table 144 * array we belong to */ 145 struct urecord* prev; /*!< Next item in the hash entry */ 146 struct urecord* next; /*!< Previous item in the hash entry */ 147 } urecord_t; 148 149 typedef int (*insert_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r); 150 151 typedef int (*get_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r); 152 153 typedef int (*get_urecord_by_ruid_t)(udomain_t* _d, unsigned int _aorhash, 154 str *_ruid, struct urecord** _r, struct ucontact** _c); 155 156 typedef int (*delete_urecord_t)(struct udomain* _d, str* _aor, struct urecord* _r); 157 158 typedef int (*delete_urecord_by_ruid_t)(struct udomain* _d, str* _ruid); 159 160 typedef int (*update_ucontact_t)(struct urecord* _r, struct ucontact* _c, 161 struct ucontact_info* _ci); 162 typedef void (*release_urecord_t)(struct urecord* _r); 163 164 typedef int (*insert_ucontact_t)(struct urecord* _r, str* _contact, 165 struct ucontact_info* _ci, struct ucontact** _c); 166 167 typedef int (*delete_ucontact_t)(struct urecord* _r, struct ucontact* _c); 168 169 typedef int (*get_ucontact_t)(struct urecord* _r, str* _c, str* _callid, 170 str* _path, int _cseq, 171 struct ucontact** _co); 172 173 typedef int (*get_ucontact_by_instance_t)(struct urecord* _r, str* _c, 174 ucontact_info_t* _ci, ucontact_t** _co); 175 176 typedef void (*lock_udomain_t)(struct udomain* _d, str *_aor); 177 178 typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor); 179 180 typedef int (*register_udomain_t)(const char* _n, struct udomain** _d); 181 182 typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags, 183 unsigned int part_idx, unsigned int part_max, int options); 184 185 typedef int (*get_udomain_t)(const char* _n, udomain_t** _d); 186 187 typedef unsigned int (*ul_get_aorhash_t)(str *_aor); 188 unsigned int ul_get_aorhash(str *_aor); 189 190 typedef int (*ul_set_keepalive_timeout_t)(int _to); 191 int ul_set_keepalive_timeout(int _to); 192 193 typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid); 194 int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid); 195 196 int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval, 197 unsigned int rtrip); 198 199 typedef void (*ul_set_max_partition_t)(unsigned int m); 200 201 /*! usrloc API export structure */ 202 typedef struct usrloc_api { 203 int use_domain; /*! use_domain module parameter */ 204 int db_mode; /*! db_mode module parameter */ 205 unsigned int nat_flag; /*! nat_flag module parameter */ 206 207 register_udomain_t register_udomain; 208 get_udomain_t get_udomain; 209 get_all_ucontacts_t get_all_ucontacts; 210 211 insert_urecord_t insert_urecord; 212 delete_urecord_t delete_urecord; 213 delete_urecord_by_ruid_t delete_urecord_by_ruid; 214 get_urecord_t get_urecord; 215 lock_udomain_t lock_udomain; 216 unlock_udomain_t unlock_udomain; 217 218 release_urecord_t release_urecord; 219 insert_ucontact_t insert_ucontact; 220 delete_ucontact_t delete_ucontact; 221 get_ucontact_t get_ucontact; 222 223 get_urecord_by_ruid_t get_urecord_by_ruid; 224 get_ucontact_by_instance_t get_ucontact_by_instance; 225 226 update_ucontact_t update_ucontact; 227 228 register_ulcb_t register_ulcb; 229 ul_get_aorhash_t get_aorhash; 230 231 ul_set_keepalive_timeout_t set_keepalive_timeout; 232 ul_refresh_keepalive_t refresh_keepalive; 233 ul_set_max_partition_t set_max_partition; 234 } usrloc_api_t; 235 236 237 /*! usrloc API export bind function */ 238 typedef int (*bind_usrloc_t)(usrloc_api_t* api); 239 240 #endif 241