-
Notifications
You must be signed in to change notification settings - Fork 910
/
add_events.c
185 lines (162 loc) · 5.02 KB
/
add_events.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2006 Voice Sistem S.R.L.
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio is free software; you can redistribute it and/or modify
* 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
*
* Kamailio is distributed in the hope that it will be useful,
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*!
* \file
* \brief Kamailio Presence_XML :: Several event packages, presence, presence.winfo, dialog;sla
* \ingroup presence_xml
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
#include "../../core/parser/parse_content.h"
#include "../../core/data_lump_rpl.h"
#include "../../core/ut.h"
#include "../../core/sr_module.h"
#include "../presence/presence.h"
#include "xcap_auth.h"
#include "notify_body.h"
#include "add_events.h"
#include "presence_xml.h"
extern int pxml_disable_presence;
extern int pxml_disable_winfo;
extern int pxml_disable_bla;
extern int pxml_disable_xcapdiff;
static str pu_415_rpl = str_init("Unsupported media type");
int xml_add_events(void)
{
pres_ev_t event;
/* read default expires from presence, if exists */
int pres_default_expires = 3600;
modparam_t type = 0;
int *param = find_param_export(find_module_by_name("presence"), "default_expires", INT_PARAM, &type);
if ( param && (type == INT_PARAM) )
pres_default_expires = *param;
else
LOG(L_WARN, "cannot find pres_default_expires parameter or type is not correct in the presence module\n");
if(!pxml_disable_presence) {
/* constructing presence event */
memset(&event, 0, sizeof(pres_ev_t));
event.name.s = "presence";
event.name.len = 8;
event.content_type.s = "application/pidf+xml";
event.content_type.len = 20;
event.type = PUBL_TYPE;
event.req_auth = 1;
event.apply_auth_nbody = pres_apply_auth;
event.get_auth_status = pres_watcher_allowed;
event.agg_nbody = pres_agg_nbody;
event.evs_publ_handl = xml_publ_handl;
event.free_body = free_xml_body;
event.default_expires = pres_default_expires;
event.get_rules_doc = pres_get_rules_doc;
event.get_pidf_doc = pres_get_pidf_doc;
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event presence\n");
return -1;
}
LM_DBG("added 'presence' event to presence module\n");
}
if(!pxml_disable_winfo) {
/* constructing presence.winfo event */
memset(&event, 0, sizeof(pres_ev_t));
event.name.s = "presence.winfo";
event.name.len = 14;
event.content_type.s = "application/watcherinfo+xml";
event.content_type.len = 27;
event.type = WINFO_TYPE;
event.free_body = free_xml_body;
event.default_expires = pres_default_expires;
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event presence.winfo\n");
return -1;
}
LM_DBG("added 'presence.winfo' event to presence module\n");
}
if(!pxml_disable_bla) {
/* constructing bla event */
memset(&event, 0, sizeof(pres_ev_t));
event.name.s = "dialog;sla";
event.name.len = 10;
event.etag_not_new = 1;
event.evs_publ_handl = xml_publ_handl;
event.content_type.s = "application/dialog-info+xml";
event.content_type.len = 27;
event.type = PUBL_TYPE;
event.free_body = free_xml_body;
event.default_expires = pres_default_expires;
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event dialog;sla\n");
return -1;
}
LM_DBG("added 'dialog;sla' event to presence module\n");
}
if(!pxml_disable_xcapdiff) {
/* constructing xcap-diff event */
memset(&event, 0, sizeof(pres_ev_t));
event.name.s = "xcap-diff";
event.name.len = 9;
event.content_type.s = "application/xcap-diff+xml";
event.content_type.len = 25;
event.type = PUBL_TYPE;
event.default_expires = pres_default_expires;
if(psapi.add_event(&event) < 0) {
LM_ERR("while adding event xcap-diff\n");
return -1;
}
LM_DBG("added 'xcap-diff' event to presence module\n");
}
return 0;
}
/*
* in event specific publish handling - only check is good body format
*/
int xml_publ_handl(struct sip_msg *msg)
{
str body = {0, 0};
xmlDocPtr doc = NULL;
if(get_content_length(msg) == 0)
return 1;
body.s = get_body(msg);
if(body.s == NULL) {
LM_ERR("cannot extract body from msg\n");
goto error;
}
/* content-length (if present) must be already parsed */
body.len = get_content_length(msg);
doc = xmlParseMemory(body.s, body.len);
if(doc == NULL) {
LM_ERR("bad body format\n");
if(slb.freply(msg, 415, &pu_415_rpl) < 0) {
LM_ERR("while sending '415 Unsupported media type' reply\n");
}
goto error;
}
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
return 1;
error:
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
return -1;
}