buddy: add backend API to refresh properties
[siplcs.git] / src / core / sip-soap.c
blob739fa71ea1254fd31e9bfea0833e2da010bad973
1 /**
2 * @file sip-soap.c
4 * pidgin-sipe
6 * Copyright (C) 2011 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * SOAP requests over SIP SERVICE messages
26 * Specification references:
28 * - [MS-SIP]: http://msdn.microsoft.com/en-us/library/cc246115.aspx
29 * - [MS-PRES]: http://msdn.microsoft.com/en-us/library/cc431501.aspx
33 #include <glib.h>
35 #include "sip-soap.h"
36 #include "sip-transport.h"
37 #include "sipe-core.h"
38 #include "sipe-core-private.h"
39 #include "sipe-utils.h"
41 void sip_soap_raw_request_cb(struct sipe_core_private *sipe_private,
42 const gchar *from,
43 const gchar *soap,
44 SoapTransCallback callback,
45 struct transaction_payload *payload)
47 gchar *contact = get_contact(sipe_private);
48 gchar *hdr = g_strdup_printf("Contact: %s\r\n"
49 "Content-Type: application/SOAP+xml\r\n",
50 contact);
52 struct transaction *trans = sip_transport_service(sipe_private,
53 from,
54 hdr,
55 soap,
56 callback);
57 trans->payload = payload;
59 g_free(contact);
60 g_free(hdr);
63 /**
64 * delta_num != NULL: use user sip: URI as from, include deltanum and increment it
65 * delta_num == NULL; use sip: URI generated from domain name as from
67 static void sip_soap_request_full(struct sipe_core_private *sipe_private,
68 const gchar *method,
69 const gchar *request,
70 const gchar *additional,
71 guint *deltanum,
72 SoapTransCallback callback,
73 struct transaction_payload *payload)
75 gchar *from = deltanum ?
76 sip_uri_self(sipe_private) :
77 sip_uri_from_name(sipe_private->public.sip_domain);
78 gchar *delta = deltanum ?
79 g_strdup_printf("<m:deltaNum>%d</m:deltaNum>", (*deltanum)++) :
80 g_strdup("");
81 gchar *soap = g_strdup_printf("<s:Envelope"
82 " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
83 " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\""
84 ">"
85 "<s:Body>"
86 "<m:%s>"
87 "%s"
88 "%s"
89 "</m:%s>"
90 "%s"
91 "</s:Body>"
92 "</s:Envelope>",
93 method,
94 request,
95 delta,
96 method,
97 additional ? additional : "");
98 sip_soap_raw_request_cb(sipe_private, from, soap, callback, payload);
99 g_free(soap);
100 g_free(delta);
101 g_free(from);
104 void sip_soap_request_cb(struct sipe_core_private *sipe_private,
105 const gchar *method,
106 const gchar *request,
107 SoapTransCallback callback,
108 struct transaction_payload *payload)
110 sip_soap_request_full(sipe_private,
111 method,
112 request,
113 NULL,
114 &sipe_private->deltanum_contacts,
115 callback,
116 payload);
119 void sip_soap_request(struct sipe_core_private *sipe_private,
120 const gchar *method,
121 const gchar *request)
123 sip_soap_request_cb(sipe_private,
124 method,
125 request,
126 NULL,
127 NULL);
130 /* This is the only user of deltanum_acl */
131 void sip_soap_ocs2005_setacl(struct sipe_core_private *sipe_private,
132 const gchar *who,
133 gboolean allow)
135 gchar *request = g_strdup_printf("<m:type>USER</m:type>"
136 "<m:mask>%s</m:mask>"
137 "<m:rights>%s</m:rights>",
138 who,
139 allow ? "AA" : "BD");
140 sip_soap_request_full(sipe_private,
141 "setACE",
142 request,
143 NULL,
144 &sipe_private->deltanum_acl,
145 NULL,
146 NULL);
147 g_free(request);
151 * This request is special:
152 * a) it is send from domain URI and not the users
153 * b) it has XML nodes outside the [MS-PRES] method node
154 * c) doesn't use deltaNum
156 void sip_soap_directory_search(struct sipe_core_private *sipe_private,
157 guint max,
158 const gchar *rows,
159 SoapTransCallback callback,
160 struct transaction_payload *payload)
162 gchar *request = g_strdup_printf("<m:filter m:href=\"#searchArray\"/>"
163 "<m:maxResults>%d</m:maxResults>",
164 max);
165 gchar *additional = g_strdup_printf("<m:Array m:id=\"searchArray\">"
166 "%s"
167 "</m:Array>",
168 rows);
169 sip_soap_request_full(sipe_private,
170 "directorySearch",
171 request,
172 additional,
173 NULL,
174 callback,
175 payload);
176 g_free(additional);
177 g_free(request);
181 Local Variables:
182 mode: c
183 c-file-style: "bsd"
184 indent-tabs-mode: t
185 tab-width: 8
186 End: