all: updated FSF address in GPL text
[sip-router] / modules / presence_xml / add_events.c
1 /*
2  * Copyright (C) 2006 Voice Sistem S.R.L.
3  *
4  * This file is part of Kamailio, a free SIP server.
5  *
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
10  *
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.
15  *
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
19  *
20  * History:
21  * --------
22  *  2007-04-17  initial version (anca)
23  */
24
25 /*!
26  * \file
27  * \brief Kamailio Presence_XML :: Several event packages, presence, presence.winfo, dialog;sla 
28  * \ingroup presence_xml
29  */
30
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <libxml/parser.h>
36 #include "../../parser/parse_content.h"
37 #include "../../data_lump_rpl.h"
38 #include "../../ut.h"
39 #include "xcap_auth.h"
40 #include "notify_body.h"
41 #include "add_events.h"
42 #include "presence_xml.h"
43
44 extern int disable_presence;
45 extern int disable_winfo;
46 extern int disable_bla;
47 extern int disable_xcapdiff;
48
49 static str pu_415_rpl  = str_init("Unsupported media type");
50
51 int xml_add_events(void)
52 {
53         pres_ev_t event;
54         
55         if (!disable_presence) {
56                 /* constructing presence event */
57                 memset(&event, 0, sizeof(pres_ev_t));
58                 event.name.s= "presence";
59                 event.name.len= 8;
60
61                 event.content_type.s= "application/pidf+xml";
62                 event.content_type.len= 20;
63
64                 event.type= PUBL_TYPE;
65                 event.req_auth= 1;
66                 event.apply_auth_nbody= pres_apply_auth;
67                 event.get_auth_status= pres_watcher_allowed;
68                 event.agg_nbody= pres_agg_nbody;
69                 event.evs_publ_handl= xml_publ_handl;
70                 event.free_body= free_xml_body;
71                 event.default_expires= 3600;
72                 event.get_rules_doc= pres_get_rules_doc;
73                 event.get_pidf_doc= pres_get_pidf_doc;
74                 if(pres_add_event(&event)< 0)
75                 {
76                         LM_ERR("while adding event presence\n");
77                         return -1;
78                 }               
79                 LM_DBG("added 'presence' event to presence module\n");
80         }
81
82         if (!disable_winfo) {
83                 /* constructing presence.winfo event */
84                 memset(&event, 0, sizeof(pres_ev_t));
85                 event.name.s= "presence.winfo";
86                 event.name.len= 14;
87
88                 event.content_type.s= "application/watcherinfo+xml";
89                 event.content_type.len= 27;
90                 event.type= WINFO_TYPE;
91                 event.free_body= free_xml_body;
92                 event.default_expires= 3600;
93
94                 if(pres_add_event(&event)< 0)
95                 {
96                         LM_ERR("while adding event presence.winfo\n");
97                         return -1;
98                 }
99                 LM_DBG("added 'presence.winfo' event to presence module\n");
100         }
101         
102         if (!disable_bla) {
103                 /* constructing bla event */
104                 memset(&event, 0, sizeof(pres_ev_t));
105                 event.name.s= "dialog;sla";
106                 event.name.len= 10;
107
108                 event.etag_not_new= 1;
109                 event.evs_publ_handl= xml_publ_handl;
110                 event.content_type.s= "application/dialog-info+xml";
111                 event.content_type.len= 27;
112                 event.type= PUBL_TYPE;
113                 event.free_body= free_xml_body;
114                 event.default_expires= 3600;
115                 if(pres_add_event(&event)< 0)
116                 {
117                         LM_ERR("while adding event dialog;sla\n");
118                         return -1;
119                 }
120                 LM_DBG("added 'dialog;sla' event to presence module\n");
121         }
122         
123         if (!disable_xcapdiff) {
124                 /* constructing xcap-diff event */
125                 memset(&event, 0, sizeof(pres_ev_t));
126                 event.name.s= "xcap-diff";
127                 event.name.len= 9;
128
129                 event.content_type.s= "application/xcap-diff+xml";
130                 event.content_type.len= 25;
131
132                 event.type= PUBL_TYPE;
133                 event.default_expires= 3600;
134                 if(pres_add_event(&event)< 0)
135                 {
136                         LM_ERR("while adding event xcap-diff\n");
137                         return -1;
138                 }
139                 LM_DBG("added 'xcap-diff' event to presence module\n");
140         }
141
142         return 0;
143 }
144 /*
145  * in event specific publish handling - only check is good body format
146  */
147 int     xml_publ_handl(struct sip_msg* msg)
148 {       
149         str body= {0, 0};
150         xmlDocPtr doc= NULL;
151
152         if ( get_content_length(msg) == 0 )
153                 return 1;
154         
155         body.s=get_body(msg);
156         if (body.s== NULL) 
157         {
158                 LM_ERR("cannot extract body from msg\n");
159                 goto error;
160         }
161         /* content-length (if present) must be already parsed */
162
163         body.len = get_content_length( msg );
164         doc= xmlParseMemory( body.s, body.len );
165         if(doc== NULL)
166         {
167                 LM_ERR("bad body format\n");
168                 if(slb.freply(msg, 415, &pu_415_rpl) < 0)
169                 {
170                         LM_ERR("while sending '415 Unsupported media type' reply\n");
171                 }
172                 goto error;
173         }
174         xmlFreeDoc(doc);
175         xmlCleanupParser();
176         xmlMemoryDump();
177         return 1;
178
179 error:
180         xmlFreeDoc(doc);
181         xmlCleanupParser();
182         xmlMemoryDump();
183         return -1;
184
185 }