2 * Copyright (C) 2006 Voice Sistem S.R.L.
4 * This file is part of Kamailio, a free SIP server.
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
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.
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
24 * \brief Kamailio Presence_XML :: Several event packages, presence, presence.winfo, dialog;sla
25 * \ingroup presence_xml
32 #include <libxml/parser.h>
33 #include "../../core/parser/parse_content.h"
34 #include "../../core/data_lump_rpl.h"
35 #include "../../core/ut.h"
36 #include "xcap_auth.h"
37 #include "notify_body.h"
38 #include "add_events.h"
39 #include "presence_xml.h"
41 extern int disable_presence;
42 extern int disable_winfo;
43 extern int disable_bla;
44 extern int disable_xcapdiff;
46 static str pu_415_rpl = str_init("Unsupported media type");
48 int xml_add_events(void)
52 if(!disable_presence) {
53 /* constructing presence event */
54 memset(&event, 0, sizeof(pres_ev_t));
55 event.name.s = "presence";
58 event.content_type.s = "application/pidf+xml";
59 event.content_type.len = 20;
61 event.type = PUBL_TYPE;
63 event.apply_auth_nbody = pres_apply_auth;
64 event.get_auth_status = pres_watcher_allowed;
65 event.agg_nbody = pres_agg_nbody;
66 event.evs_publ_handl = xml_publ_handl;
67 event.free_body = free_xml_body;
68 event.default_expires = 3600;
69 event.get_rules_doc = pres_get_rules_doc;
70 event.get_pidf_doc = pres_get_pidf_doc;
71 if(psapi.add_event(&event) < 0) {
72 LM_ERR("while adding event presence\n");
75 LM_DBG("added 'presence' event to presence module\n");
79 /* constructing presence.winfo event */
80 memset(&event, 0, sizeof(pres_ev_t));
81 event.name.s = "presence.winfo";
84 event.content_type.s = "application/watcherinfo+xml";
85 event.content_type.len = 27;
86 event.type = WINFO_TYPE;
87 event.free_body = free_xml_body;
88 event.default_expires = 3600;
90 if(psapi.add_event(&event) < 0) {
91 LM_ERR("while adding event presence.winfo\n");
94 LM_DBG("added 'presence.winfo' event to presence module\n");
98 /* constructing bla event */
99 memset(&event, 0, sizeof(pres_ev_t));
100 event.name.s = "dialog;sla";
103 event.etag_not_new = 1;
104 event.evs_publ_handl = xml_publ_handl;
105 event.content_type.s = "application/dialog-info+xml";
106 event.content_type.len = 27;
107 event.type = PUBL_TYPE;
108 event.free_body = free_xml_body;
109 event.default_expires = 3600;
110 if(psapi.add_event(&event) < 0) {
111 LM_ERR("while adding event dialog;sla\n");
114 LM_DBG("added 'dialog;sla' event to presence module\n");
117 if(!disable_xcapdiff) {
118 /* constructing xcap-diff event */
119 memset(&event, 0, sizeof(pres_ev_t));
120 event.name.s = "xcap-diff";
123 event.content_type.s = "application/xcap-diff+xml";
124 event.content_type.len = 25;
126 event.type = PUBL_TYPE;
127 event.default_expires = 3600;
128 if(psapi.add_event(&event) < 0) {
129 LM_ERR("while adding event xcap-diff\n");
132 LM_DBG("added 'xcap-diff' event to presence module\n");
138 * in event specific publish handling - only check is good body format
140 int xml_publ_handl(struct sip_msg *msg)
143 xmlDocPtr doc = NULL;
145 if(get_content_length(msg) == 0)
148 body.s = get_body(msg);
150 LM_ERR("cannot extract body from msg\n");
153 /* content-length (if present) must be already parsed */
155 body.len = get_content_length(msg);
156 doc = xmlParseMemory(body.s, body.len);
158 LM_ERR("bad body format\n");
159 if(slb.freply(msg, 415, &pu_415_rpl) < 0) {
160 LM_ERR("while sending '415 Unsupported media type' reply\n");