presence_xml/add_events.c

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

Generated on Thu May 24 08:00:46 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6