all: updated FSF address in GPL text
[sip-router] / modules / pua_xmpp / request_winfo.c
1 /*
2  * $Id: request_winfo.c 1666 2007-03-02 13:40:09Z anca_vamanu $
3  *
4  * pua_xmpp module - presence SIP - XMPP Gateway
5  *
6  * Copyright (C) 2007 Voice Sistem S.R.L.
7  *
8  * This file is part of Kamailio, a free SIP server.
9  *
10  * Kamailio is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * Kamailio is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License 
21  * along with this program; if not, write to the Free Software 
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  * History:
25  * --------
26  *  2007-03-29  initial version (anca)
27  */
28
29 /*! \file
30  * \brief Kamailio pua_xmpp :: Winfo support
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <libxml/parser.h>
36
37 #include "pua_xmpp.h"
38 #include "request_winfo.h"
39
40 #define PRINTBUF_SIZE 256
41
42 int request_winfo(struct sip_msg* msg, char* uri, char* expires)
43 {
44         subs_info_t subs;
45         struct sip_uri puri;
46         int printbuf_len;
47         char buffer[PRINTBUF_SIZE];
48         str uri_str;
49
50         memset(&puri, 0, sizeof(struct sip_uri));
51         if(uri)
52         {
53                 printbuf_len = PRINTBUF_SIZE-1;
54                 if(pv_printf(msg, (pv_elem_t*)uri, buffer, &printbuf_len)<0)
55                 {
56                         LM_ERR("cannot print the format\n");
57                         return -1;
58                 }
59                 if(parse_uri(buffer, printbuf_len, &puri)!=0)
60                 {
61                         LM_ERR("bad owner SIP address!\n");
62                         goto error;
63                 } else
64                 {
65                         LM_DBG("using user id [%.*s]\n", printbuf_len,
66                                         buffer);
67                 }
68         } 
69         if(puri.user.len<=0 || puri.user.s==NULL
70                         || puri.host.len<=0 || puri.host.s==NULL)
71         {
72                 LM_ERR("bad owner URI!\n");
73                 goto error;
74         }
75         uri_str.s= buffer;
76         uri_str.len=  printbuf_len;
77         LM_DBG("uri= %.*s:\n", uri_str.len, uri_str.s);
78
79         memset(&subs, 0, sizeof(subs_info_t));
80         
81         subs.pres_uri= &uri_str;
82
83         subs.watcher_uri= &uri_str;
84
85         subs.contact= &server_address;
86         
87         if(strncmp(expires, "0", 1 )== 0)
88         {
89                 subs.expires= 0;
90         }
91         else
92         {
93                 subs.expires= -1;
94         
95         }
96         /* -1 - for a subscription with no time limit */
97         /*  0  -for unsubscribe */
98
99         subs.source_flag |= XMPP_SUBSCRIBE;
100         subs.event= PWINFO_EVENT;
101
102         if(pua_send_subscribe(&subs)< 0)
103         {
104                 LM_ERR("while sending subscribe\n");
105                 goto error;
106         }
107
108         return 1;
109
110 error:
111         return 0;
112 }
113