request_winfo.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00097
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