request_winfo.c

Go to the documentation of this file.
00001 /*
00002  * $Id: request_winfo.c 1666 2007-03-02 13:40:09Z anca_vamanu $
00003  *
00004  * pua_xmpp module - presence SIP - XMPP Gateway
00005  *
00006  * Copyright (C) 2007 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-03-29  initial version (anca)
00027  */
00028 
00029 /*! \file
00030  * \brief Kamailio pua_xmpp :: Winfo support
00031  */
00032 
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <libxml/parser.h>
00036 
00037 #include "pua_xmpp.h"
00038 #include "request_winfo.h"
00039 
00040 #define PRINTBUF_SIZE 256
00041 
00042 int request_winfo(struct sip_msg* msg, char* uri, char* expires)
00043 {
00044    subs_info_t subs;
00045    struct sip_uri puri;
00046    int printbuf_len;
00047    char buffer[PRINTBUF_SIZE];
00048    str uri_str;
00049 
00050    memset(&puri, 0, sizeof(struct sip_uri));
00051    if(uri)
00052    {
00053       printbuf_len = PRINTBUF_SIZE-1;
00054       if(pv_printf(msg, (pv_elem_t*)uri, buffer, &printbuf_len)<0)
00055       {
00056          LM_ERR("cannot print the format\n");
00057          return -1;
00058       }
00059       if(parse_uri(buffer, printbuf_len, &puri)!=0)
00060       {
00061          LM_ERR("bad owner SIP address!\n");
00062          goto error;
00063       } else
00064       {
00065          LM_DBG("using user id [%.*s]\n", printbuf_len,
00066                buffer);
00067       }
00068    } 
00069    if(puri.user.len<=0 || puri.user.s==NULL
00070          || puri.host.len<=0 || puri.host.s==NULL)
00071    {
00072       LM_ERR("bad owner URI!\n");
00073       goto error;
00074    }
00075    uri_str.s= buffer;
00076    uri_str.len=  printbuf_len;
00077    LM_DBG("uri= %.*s:\n", uri_str.len, uri_str.s);
00078 
00079    memset(&subs, 0, sizeof(subs_info_t));
00080    
00081    subs.pres_uri= &uri_str;
00082 
00083    subs.watcher_uri= &uri_str;
00084 
00085    subs.contact= &server_address;
00086    
00087    if(strncmp(expires, "0", 1 )== 0)
00088    {
00089       subs.expires= 0;
00090    }
00091    else
00092    {
00093       subs.expires= -1;
00094    
00095    }
00096    /* -1 - for a subscription with no time limit */
00097    /*  0  -for unsubscribe */
00098 
00099    subs.source_flag |= XMPP_SUBSCRIBE;
00100    subs.event= PWINFO_EVENT;
00101 
00102    if(pua_send_subscribe(&subs)< 0)
00103    {
00104       LM_ERR("while sending subscribe\n");
00105       goto error;
00106    }
00107 
00108    return 1;
00109 
00110 error:
00111    return 0;
00112 }
00113 

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