rls.h

00001 /*
00002  * $Id: rls.h 2230 2007-06-06 07:13:20Z anca_vamanu $
00003  *
00004  * rls module - resource list server
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2007-09-11  initial version (anca)
00027  */
00028 
00029 #ifndef _RLS_H_
00030 #define _RLS_H_
00031 
00032 #include "../../str.h"
00033 #include "../xcap_client/xcap_functions.h"
00034 #include "../pua/send_subscribe.h"
00035 #include "../pua/send_publish.h"
00036 #include "../pua/pidf.h"
00037 #include "../presence/hash.h"
00038 #include "../presence/event_list.h"
00039 #include "../../modules/sl/sl.h"
00040 #include "../../lib/srdb1/db_con.h"
00041 #include "../../lib/srdb1/db.h"
00042 
00043 #define RLS_DB_DEFAULT 0
00044 #define RLS_DB_RESERVED 1
00045 #define RLS_DB_ONLY 2
00046 
00047 #define NO_UPDATE_TYPE     -1 
00048 #define UPDATED_TYPE        1 
00049 
00050 #define NOT_KNOWN_STATE     0
00051 #define ACTIVE_STATE        1<<1
00052 #define PENDING_STATE       1<<2
00053 #define TERMINATED_STATE    1<<3
00054 
00055 typedef struct dialog_id
00056 {
00057         str callid;
00058         str to_tag;
00059         str from_tag;
00060 
00061 }dialog_id_t;
00062 
00063 /*
00064         rls_presentity table structure:
00065 
00066         - LIST URI       (string)
00067         - presentity URI (string)
00068         - presence state (string)
00069         /-- the following ones needed when updating in db on timer --/
00070         - auth_state     (int)
00071         - reason                 (string)
00072         - updated        (int)
00073 */
00074 typedef struct rls_resource
00075 {
00076         str pres_uri;
00077         int auth_state;
00078         str reason;
00079         int updated;
00080         str* instance_id;
00081         str* cid;
00082         struct rls_resource* next;
00083         /* the last 2 parameters say if a query in database is needed */
00084 }rls_res_t;
00085 
00086 extern int dbmode;
00087 extern char* xcap_root;
00088 extern unsigned int xcap_port;
00089 extern str rls_server_address;
00090 extern int waitn_time;
00091 extern int rls_notifier_poll_rate;
00092 extern int rls_notifier_processes;
00093 extern str rlsubs_table;
00094 extern str rlpres_table;
00095 extern str rls_xcap_table;
00096 extern str db_url;
00097 extern int hash_size;
00098 extern shtable_t rls_table;
00099 extern int rls_max_expires;
00100 extern int rls_integrated_xcap_server;
00101 extern int rls_events;
00102 extern int to_presence_code;
00103 extern str rls_outbound_proxy;
00104 extern int rls_max_notify_body_len;
00105 extern int rls_expires_offset;
00106 
00107 extern int rls_disable_remote_presence;
00108 extern int rls_max_backend_subs;
00109 
00110 extern gen_lock_t *rls_update_subs_lock;
00111 
00112 /* database connection */
00113 extern db1_con_t *rls_db;
00114 extern db_func_t rls_dbf;
00115 extern db1_con_t *rls_xcap_db;
00116 extern db_func_t rls_xcap_dbf;
00117 extern db1_con_t *rlpres_db;
00118 extern db_func_t rlpres_dbf;
00119 
00120 extern struct tm_binds tmb;
00121 extern sl_api_t slb;
00122 
00124 extern xmlDocGetNodeByName_t XMLDocGetNodeByName;
00125 extern xmlNodeGetNodeByName_t XMLNodeGetNodeByName;
00126 extern xmlNodeGetNodeContentByName_t XMLNodeGetNodeContentByName;
00127 extern xmlNodeGetAttrContentByName_t XMLNodeGetAttrContentByName;
00128 
00129 /* functions imported from presence to handle subscribe hash table */
00130 extern new_shtable_t pres_new_shtable;
00131 extern insert_shtable_t pres_insert_shtable;
00132 extern search_shtable_t pres_search_shtable;
00133 extern update_shtable_t pres_update_shtable;
00134 extern delete_shtable_t pres_delete_shtable;
00135 extern destroy_shtable_t pres_destroy_shtable;
00136 extern mem_copy_subs_t  pres_copy_subs;
00137 extern extract_sdialog_info_t pres_extract_sdialog_info;
00138 
00139 /* functions imported from pua module*/
00140 extern send_subscribe_t pua_send_subscribe;
00141 extern get_record_id_t pua_get_record_id;
00142 extern get_subs_list_t pua_get_subs_list;
00143 
00144 /* functions imported from presence module */
00145 extern contains_event_t pres_contains_event;
00146 extern search_event_t pres_search_event;
00147 extern get_event_list_t pres_get_ev_list;
00148 
00149 /* xcap client functions */
00150 extern xcapGetNewDoc_t xcap_GetNewDoc;
00151 extern xcap_nodeSel_init_t xcap_IntNodeSel;
00152 extern xcap_nodeSel_add_step_t xcap_AddStep;
00153 extern xcap_nodeSel_add_terminal_t xcap_AddTerminal;
00154 extern xcap_nodeSel_free_t xcap_FreeNodeSel;
00155 
00156 /* rlsdb functions*/
00157 int delete_expired_subs_rlsdb(void);
00158 extern int delete_rlsdb(str *callid, str *to_tag, str *from_tag);
00159 extern int update_dialog_notify_rlsdb(subs_t *s);
00160 extern int update_dialog_subscribe_rlsdb(subs_t *s);
00161 extern int insert_rlsdb(subs_t *s);
00162 extern int get_dialog_subscribe_rlsdb(subs_t *s);
00163 subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag);
00164 extern int update_all_subs_rlsdb(str *watcher_user, str *watcher_domain, str *evt);
00165 
00166 extern int rls_get_service_list(str *service_uri, str *user, str *domain,
00167                         xmlNodePtr *service_node, xmlDocPtr *rootdoc);
00168 
00169 extern str str_rlsubs_did_col;
00170 extern str str_resource_uri_col;
00171 extern str str_updated_col;
00172 extern str str_auth_state_col;
00173 extern str str_reason_col;
00174 extern str str_content_type_col;
00175 extern str str_presence_state_col;
00176 extern str str_expires_col;
00177 extern str str_presentity_uri_col;
00178 extern str str_event_col;
00179 extern str str_event_id_col;
00180 extern str str_to_user_col;
00181 extern str str_to_domain_col;
00182 extern str str_from_user_col;
00183 extern str str_from_domain_col;
00184 extern str str_watcher_username_col;
00185 extern str str_watcher_domain_col;
00186 extern str str_callid_col;
00187 extern str str_to_tag_col;
00188 extern str str_from_tag_col;
00189 extern str str_local_cseq_col;
00190 extern str str_remote_cseq_col;
00191 extern str str_record_route_col;
00192 extern str str_socket_info_col;
00193 extern str str_contact_col;
00194 extern str str_local_contact_col;
00195 extern str str_version_col;
00196 extern str str_status_col;
00197 extern str str_username_col;
00198 extern str str_domain_col;
00199 extern str str_doc_type_col;
00200 extern str str_etag_col;
00201 extern str str_doc_col;
00202 extern str str_doc_uri_col;
00203 
00204 #define RLS_DID_SEP       ";"
00205 #define RLS_DID_SEP_LEN   strlen(RLS_DID_SEP)
00206 #define RLS_DID_INIT_LEN  (2* sizeof(RLS_DID_SEP))
00207 #define RLS_DID_MAX_LEN 255
00208 
00209 /* did_str= *callid*RLS_DID_SEP*from_tag*RLS_DID_SEP*to_tag* */
00210 
00211 static inline int CONSTR_RLSUBS_DID(subs_t* subs, str *did)
00212 {
00213         int len;
00214 
00215         len= (RLS_DID_INIT_LEN+ subs->callid.len+ subs->to_tag.len+
00216                         subs->from_tag.len+ 10)* sizeof(char);
00217         if(len > RLS_DID_MAX_LEN)
00218         {
00219                 LM_ERR("new DID size is too big [%d > %d]\n",
00220                                 len, RLS_DID_MAX_LEN);
00221                 return -1;
00222         }
00223         did->s= (char*)pkg_malloc(len);
00224         if(did->s== NULL) 
00225         {
00226                 ERR_MEM(PKG_MEM_STR); 
00227         }
00228         
00229         did->len= sprintf(did->s, "%.*s%s%.*s%s%.*s", subs->callid.len, 
00230                         subs->callid.s, RLS_DID_SEP,subs->from_tag.len, subs->from_tag.s,
00231                         RLS_DID_SEP, subs->to_tag.len, subs->to_tag.s);
00232 
00233         if(did->len>= len)
00234         {
00235                 LM_ERR("ERROR buffer size overflown\n");
00236                 pkg_free(did->s);
00237                 return -1;
00238         }
00239         did->s[did->len]= '\0';
00240         
00241         LM_DBG("did= %s\n", did->s);
00242         return 0;
00243 error:
00244         return -1;
00245 }
00246 
00247 #endif