presence_xml/add_events.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Voice Sistem S.R.L.
00003  *
00004  * This file is part of Kamailio, a free SIP server.
00005  *
00006  * Kamailio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * Kamailio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License 
00017  * along with this program; if not, write to the Free Software 
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  * History:
00021  * --------
00022  *  2007-04-17  initial version (anca)
00023  */
00024 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <libxml/parser.h>
00036 #include "../../parser/parse_content.h"
00037 #include "../../data_lump_rpl.h"
00038 #include "../../ut.h"
00039 #include "xcap_auth.h"
00040 #include "notify_body.h"
00041 #include "add_events.h"
00042 #include "presence_xml.h"
00043 
00044 extern int disable_presence;
00045 extern int disable_winfo;
00046 extern int disable_bla;
00047 
00048 static str pu_415_rpl  = str_init("Unsupported media type");
00049 
00050 int xml_add_events(void)
00051 {
00052         pres_ev_t event;
00053         
00054         if (!disable_presence) {
00055                 /* constructing presence event */
00056                 memset(&event, 0, sizeof(pres_ev_t));
00057                 event.name.s= "presence";
00058                 event.name.len= 8;
00059 
00060                 event.content_type.s= "application/pidf+xml";
00061                 event.content_type.len= 20;
00062 
00063                 event.type= PUBL_TYPE;
00064                 event.req_auth= 1;
00065                 event.apply_auth_nbody= pres_apply_auth;
00066                 event.get_auth_status= pres_watcher_allowed;
00067                 event.agg_nbody= pres_agg_nbody;
00068                 event.evs_publ_handl= xml_publ_handl;
00069                 event.free_body= free_xml_body;
00070                 event.default_expires= 3600;
00071                 event.get_rules_doc= pres_get_rules_doc;
00072                 if(pres_add_event(&event)< 0)
00073                 {
00074                         LM_ERR("while adding event presence\n");
00075                         return -1;
00076                 }               
00077                 LM_DBG("added 'presence' event to presence module\n");
00078         }
00079 
00080         if (!disable_winfo) {
00081                 /* constructing presence.winfo event */
00082                 memset(&event, 0, sizeof(pres_ev_t));
00083                 event.name.s= "presence.winfo";
00084                 event.name.len= 14;
00085 
00086                 event.content_type.s= "application/watcherinfo+xml";
00087                 event.content_type.len= 27;
00088                 event.type= WINFO_TYPE;
00089                 event.free_body= free_xml_body;
00090                 event.default_expires= 3600;
00091 
00092                 if(pres_add_event(&event)< 0)
00093                 {
00094                         LM_ERR("while adding event presence.winfo\n");
00095                         return -1;
00096                 }
00097                 LM_DBG("added 'presence.winfo' event to presence module\n");
00098         }
00099         
00100         if (!disable_bla) {
00101                 /* constructing bla event */
00102                 memset(&event, 0, sizeof(pres_ev_t));
00103                 event.name.s= "dialog;sla";
00104                 event.name.len= 10;
00105 
00106                 event.etag_not_new= 1;
00107                 event.evs_publ_handl= xml_publ_handl;
00108                 event.content_type.s= "application/dialog-info+xml";
00109                 event.content_type.len= 27;
00110                 event.type= PUBL_TYPE;
00111                 event.free_body= free_xml_body;
00112                 event.default_expires= 3600;
00113                 if(pres_add_event(&event)< 0)
00114                 {
00115                         LM_ERR("while adding event dialog;sla\n");
00116                         return -1;
00117                 }
00118                 LM_DBG("added 'dialog;sla' event to presence module\n");
00119         }
00120         
00121         return 0;
00122 }
00123 /*
00124  * in event specific publish handling - only check is good body format
00125  */
00126 int     xml_publ_handl(struct sip_msg* msg)
00127 {       
00128         str body= {0, 0};
00129         xmlDocPtr doc= NULL;
00130 
00131         if ( get_content_length(msg) == 0 )
00132                 return 1;
00133         
00134         body.s=get_body(msg);
00135         if (body.s== NULL) 
00136         {
00137                 LM_ERR("cannot extract body from msg\n");
00138                 goto error;
00139         }
00140         /* content-length (if present) must be already parsed */
00141 
00142         body.len = get_content_length( msg );
00143         doc= xmlParseMemory( body.s, body.len );
00144         if(doc== NULL)
00145         {
00146                 LM_ERR("bad body format\n");
00147                 if(slb.freply(msg, 415, &pu_415_rpl) < 0)
00148                 {
00149                         LM_ERR("while sending '415 Unsupported media type' reply\n");
00150                 }
00151                 goto error;
00152         }
00153         xmlFreeDoc(doc);
00154         xmlCleanupParser();
00155         xmlMemoryDump();
00156         return 1;
00157 
00158 error:
00159         xmlFreeDoc(doc);
00160         xmlCleanupParser();
00161         xmlMemoryDump();
00162         return -1;
00163 
00164 }