modules/rls/rls.h
3865ed69
 /*
4fefa359
  * rls module - resource list server
3865ed69
  *
  * Copyright (C) 2007 Voice Sistem S.R.L.
  *
27642a08
  * This file is part of Kamailio, a free SIP server.
3865ed69
  *
27642a08
  * Kamailio is free software; you can redistribute it and/or modify
3865ed69
  * 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,
3865ed69
  * 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 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
3865ed69
  *
  */
 
 #ifndef _RLS_H_
 #define _RLS_H_
 
 #include "../../str.h"
 #include "../xcap_client/xcap_functions.h"
 #include "../pua/send_subscribe.h"
 #include "../pua/send_publish.h"
 #include "../pua/pidf.h"
 #include "../presence/hash.h"
 #include "../presence/event_list.h"
b3a7238f
 #include "../../modules/sl/sl.h"
e13ee505
 #include "../../lib/srdb1/db_con.h"
 #include "../../lib/srdb1/db.h"
3865ed69
 
7665c794
 #define RLS_DB_DEFAULT 0
 #define RLS_DB_RESERVED 1
 #define RLS_DB_ONLY 2
 
3865ed69
 #define NO_UPDATE_TYPE     -1 
 #define UPDATED_TYPE        1 
 
 #define NOT_KNOWN_STATE     0
 #define ACTIVE_STATE        1<<1
 #define PENDING_STATE       1<<2
 #define TERMINATED_STATE    1<<3
 
 typedef struct dialog_id
 {
 	str callid;
 	str to_tag;
 	str from_tag;
 
 }dialog_id_t;
 
 /*
 	rls_presentity table structure:
 
 	- LIST URI       (string)
 	- presentity URI (string)
 	- presence state (string)
 	/-- the following ones needed when updating in db on timer --/
 	- auth_state     (int)
 	- reason		 (string)
 	- updated        (int)
 */
 typedef struct rls_resource
 {
 	str pres_uri;
 	int auth_state;
 	str reason;
 	int updated;
 	str* instance_id;
 	str* cid;
 	struct rls_resource* next;
 	/* the last 2 parameters say if a query in database is needed */
 }rls_res_t;
 
7665c794
 extern int dbmode;
3865ed69
 extern char* xcap_root;
 extern unsigned int xcap_port;
8d9f412a
 extern str rls_server_address;
aabeca53
 extern int waitn_time;
3bb02db1
 extern int rls_notifier_poll_rate;
2140c307
 extern int rls_notifier_processes;
e2cf6343
 extern str rlsubs_table;
 extern str rlpres_table;
 extern str rls_xcap_table;
3865ed69
 extern str db_url;
 extern int hash_size;
 extern shtable_t rls_table;
 extern int rls_max_expires;
 extern int rls_integrated_xcap_server;
 extern int rls_events;
 extern int to_presence_code;
8d9f412a
 extern str rls_outbound_proxy;
04d7cafb
 extern int rls_max_notify_body_len;
7665c794
 extern int rls_expires_offset;
3865ed69
 
ee94f534
 extern int rls_disable_remote_presence;
c014f8b0
 extern int rls_max_backend_subs;
ee94f534
 
ca8f2211
 extern gen_lock_t *rls_update_subs_lock;
 
3865ed69
 /* database connection */
e13ee505
 extern db1_con_t *rls_db;
3865ed69
 extern db_func_t rls_dbf;
7665c794
 extern db1_con_t *rls_xcap_db;
 extern db_func_t rls_xcap_dbf;
ca6d9012
 extern db1_con_t *rlpres_db;
 extern db_func_t rlpres_dbf;
3865ed69
 
 extern struct tm_binds tmb;
b3a7238f
 extern sl_api_t slb;
3865ed69
 
 /** libxml api */
 extern xmlDocGetNodeByName_t XMLDocGetNodeByName;
 extern xmlNodeGetNodeByName_t XMLNodeGetNodeByName;
 extern xmlNodeGetNodeContentByName_t XMLNodeGetNodeContentByName;
 extern xmlNodeGetAttrContentByName_t XMLNodeGetAttrContentByName;
 
 /* functions imported from presence to handle subscribe hash table */
 extern new_shtable_t pres_new_shtable;
 extern insert_shtable_t pres_insert_shtable;
 extern search_shtable_t pres_search_shtable;
 extern update_shtable_t pres_update_shtable;
 extern delete_shtable_t pres_delete_shtable;
 extern destroy_shtable_t pres_destroy_shtable;
 extern mem_copy_subs_t  pres_copy_subs;
 extern extract_sdialog_info_t pres_extract_sdialog_info;
 
 /* functions imported from pua module*/
 extern send_subscribe_t pua_send_subscribe;
 extern get_record_id_t pua_get_record_id;
5c5e9699
 extern get_subs_list_t pua_get_subs_list;
3865ed69
 
 /* functions imported from presence module */
 extern contains_event_t pres_contains_event;
 extern search_event_t pres_search_event;
 extern get_event_list_t pres_get_ev_list;
 
 /* xcap client functions */
 extern xcapGetNewDoc_t xcap_GetNewDoc;
 extern xcap_nodeSel_init_t xcap_IntNodeSel;
 extern xcap_nodeSel_add_step_t xcap_AddStep;
 extern xcap_nodeSel_add_terminal_t xcap_AddTerminal;
 extern xcap_nodeSel_free_t xcap_FreeNodeSel;
 
7665c794
 /* rlsdb functions*/
6d7e23db
 int delete_expired_subs_rlsdb(void);
 extern int delete_rlsdb(str *callid, str *to_tag, str *from_tag);
 extern int update_dialog_notify_rlsdb(subs_t *s);
 extern int update_dialog_subscribe_rlsdb(subs_t *s);
 extern int insert_rlsdb(subs_t *s);
 extern int get_dialog_subscribe_rlsdb(subs_t *s);
 subs_t *get_dialog_notify_rlsdb(str callid, str to_tag, str from_tag);
b90adb0d
 extern int update_all_subs_rlsdb(str *watcher_user, str *watcher_domain, str *evt);
7665c794
 
dff68160
 extern int rls_get_service_list(str *service_uri, str *user, str *domain,
 			xmlNodePtr *service_node, xmlDocPtr *rootdoc);
 
e2cf6343
 extern str str_rlsubs_did_col;
 extern str str_resource_uri_col;
 extern str str_updated_col;
 extern str str_auth_state_col;
 extern str str_reason_col;
 extern str str_content_type_col;
 extern str str_presence_state_col;
 extern str str_expires_col;
 extern str str_presentity_uri_col;
 extern str str_event_col;
 extern str str_event_id_col;
 extern str str_to_user_col;
 extern str str_to_domain_col;
b90adb0d
 extern str str_from_user_col;
 extern str str_from_domain_col;
e2cf6343
 extern str str_watcher_username_col;
 extern str str_watcher_domain_col;
 extern str str_callid_col;
 extern str str_to_tag_col;
 extern str str_from_tag_col;
 extern str str_local_cseq_col;
 extern str str_remote_cseq_col;
 extern str str_record_route_col;
 extern str str_socket_info_col;
 extern str str_contact_col;
 extern str str_local_contact_col;
 extern str str_version_col;
 extern str str_status_col;
 extern str str_username_col;
 extern str str_domain_col;
 extern str str_doc_type_col;
 extern str str_etag_col;
 extern str str_doc_col;
81ee00f5
 extern str str_doc_uri_col;
e2cf6343
 
b5713562
 #define RLS_DID_SEP       ";"
 #define RLS_DID_SEP_LEN   strlen(RLS_DID_SEP)
 #define RLS_DID_INIT_LEN  (2* sizeof(RLS_DID_SEP))
 #define RLS_DID_MAX_LEN	255
3865ed69
 
b5713562
 /* did_str= *callid*RLS_DID_SEP*from_tag*RLS_DID_SEP*to_tag* */
3865ed69
 
 static inline int CONSTR_RLSUBS_DID(subs_t* subs, str *did)
 {
 	int len;
 
b5713562
 	len= (RLS_DID_INIT_LEN+ subs->callid.len+ subs->to_tag.len+
3865ed69
 			subs->from_tag.len+ 10)* sizeof(char);
b5713562
 	if(len > RLS_DID_MAX_LEN)
 	{
 		LM_ERR("new DID size is too big [%d > %d]\n",
 				len, RLS_DID_MAX_LEN);
 		return -1;
 	}
3865ed69
 	did->s= (char*)pkg_malloc(len);
 	if(did->s== NULL) 
 	{
 		ERR_MEM(PKG_MEM_STR); 
 	}
 	
 	did->len= sprintf(did->s, "%.*s%s%.*s%s%.*s", subs->callid.len, 
b5713562
 			subs->callid.s, RLS_DID_SEP,subs->from_tag.len, subs->from_tag.s,
 			RLS_DID_SEP, subs->to_tag.len, subs->to_tag.s);
3865ed69
 
 	if(did->len>= len)
 	{
 		LM_ERR("ERROR buffer size overflown\n");
 		pkg_free(did->s);
 		return -1;
 	}
 	did->s[did->len]= '\0';
 	
 	LM_DBG("did= %s\n", did->s);
 	return 0;
 error:
 	return -1;
 }
 
 #endif