1 /*
2  * presence module - presence server implementation
3  *
4  * Copyright (C) 2006 Voice Sistem S.R.L.
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23 
24 /*! \file
25  * \brief Kamailio presence module :: SUBSCRIBE support
26  * \ingroup presence
27  */
28 
29 
30 #ifndef SUBSCRIBE_H
31 #define SUBSCRIBE_H
32 
33 #include "../../core/str.h"
34 #include "../../lib/srdb1/db.h"
35 
36 struct pres_ev;
37 
38 #include "event_list.h"
39 #include "hash.h"
40 
41 #define ACTIVE_STATUS 1
42 #define PENDING_STATUS 2
43 #define TERMINATED_STATUS 3
44 #define WAITING_STATUS 4
45 /* Additional value returned from pres_auth_status when the status is ACTIVE
46  * and reason is polite-block */
47 #define POLITE_BLOCK_STATUS 5
48 
49 #define PRES_SUBSCRIBE_RECV 1
50 
51 #define INTERNAL_UPDATE_FALSE 0
52 #define INTERNAL_UPDATE_TRUE 1
53 
54 struct subscription
55 {
56 	str pres_uri;
57 	str to_user;
58 	str to_domain;
59 	str from_user;
60 	str from_domain;
61 	str watcher_user;
62 	str watcher_domain;
63 	struct pres_ev *event;
64 	str event_id;
65 	str to_tag;
66 	str from_tag;
67 	str callid;
68 	str sockinfo_str;
69 	unsigned int remote_cseq;
70 	unsigned int local_cseq;
71 	str contact;
72 	str local_contact;
73 	str record_route;
74 	unsigned int expires;
75 	unsigned int status;
76 	str reason;
77 	int version;
78 	int send_on_cback;
79 	int db_flag;
80 	str *auth_rules_doc;
81 	int recv_event;
82 	int internal_update_flag;
83 	int updated;
84 	int updated_winfo;
85 	flag_t flags;
86 	str user_agent;
87 	struct subscription *next;
88 };
89 typedef struct subscription subs_t;
90 
91 void ps_watchers_db_timer_clean(unsigned int ticks, void *param);
92 
93 int handle_subscribe0(struct sip_msg *);
94 int w_handle_subscribe0(struct sip_msg *, char *, char *);
95 int w_handle_subscribe(struct sip_msg *, char *watcher_uri, char *p2);
96 int w_handle_subscribe1(struct sip_msg *, char *watcher_uri);
97 int handle_subscribe_uri(struct sip_msg *, str *);
98 int handle_subscribe(struct sip_msg *, str watcher_user, str watcher_domain);
99 
100 void timer_db_update(unsigned int ticks, void *param);
101 
102 int update_subs_db(subs_t *subs, int type);
103 
104 int restore_db_subs(void);
105 
106 typedef int (*handle_expired_func_t)(subs_t *);
107 
108 void update_db_subs_timer(db1_con_t *db, db_func_t *dbf, shtable_t hash_table,
109 		int htable_size, int no_lock,
110 		handle_expired_func_t handle_expired_func);
111 
112 typedef void (*update_db_subs_t)(
113 		db1_con_t *, db_func_t *, shtable_t, int, int, handle_expired_func_t);
114 
115 int extract_sdialog_info_ex(subs_t *subs, struct sip_msg *msg,
116 		uint32_t min_expire, uint32_t max_expire, int *to_tag_gen, str scontact,
117 		str watcher_user, str watcher_domain, int *reply_code, str *reply_txt);
118 int extract_sdialog_info(subs_t *subs, struct sip_msg *msg, int max_expire,
119 		int *to_tag_gen, str scontact, str watcher_user, str watcher_domain);
120 typedef int (*extract_sdialog_info_t)(subs_t *subs, struct sip_msg *msg,
121 		int max_expire, int *to_tag_gen, str scontact, str watcher_user,
122 		str watcher_domain);
123 void delete_subs(
124 		str *pres_uri, str *ev_name, str *to_tag, str *from_tag, str *callid);
125 int get_subscribers_count(struct sip_msg *msg, str pres_uri, str event);
126 
127 #endif
128