soap: fix crash in temporary hack
[siplcs.git] / src / core / sip-soap.c
blobf8ec116fe1d0bae0d1575df13cc9e927adbf9be9
1 /**
2 * @file sip-soap.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2013 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 "sipmsg.h" /* TEMPORARY */
36 #include "sip-soap.h"
37 #include "sip-transport.h"
38 #include "sipe-backend.h" /* TEMPORARY */
39 #include "sipe-core.h"
40 #include "sipe-core-private.h"
41 #include "sipe-ucs.h" /* TEMPORARY */
42 #include "sipe-utils.h"
44 void sip_soap_raw_request_cb(struct sipe_core_private *sipe_private,
45 const gchar *from,
46 const gchar *soap,
47 SoapTransCallback callback,
48 struct transaction_payload *payload)
51 * TEMPORARY
53 * contact list has been migrated to UCS -> SOAP requests will fail
55 if (sipe_ucs_is_migrated(sipe_private)) {
56 if (callback) {
57 struct sipmsg msg;
58 struct transaction trans;
59 msg.response = 500;
60 trans.payload = payload;
61 (*callback)(sipe_private, &msg, &trans);
63 sipe_backend_notify_error(SIPE_CORE_PUBLIC,
64 "Contact list migrated",
65 "Operation NOT supported (yet)!");
66 } else {
67 gchar *contact = get_contact(sipe_private);
68 gchar *hdr = g_strdup_printf("Contact: %s\r\n"
69 "Content-Type: application/SOAP+xml\r\n",
70 contact);
72 struct transaction *trans = sip_transport_service(sipe_private,
73 from,
74 hdr,
75 soap,
76 callback);
77 trans->payload = payload;
79 g_free(contact);
80 g_free(hdr);
84 /**
85 * delta_num != NULL: use user sip: URI as from, include deltanum and increment it
86 * delta_num == NULL; use sip: URI generated from domain name as from
88 static void sip_soap_request_full(struct sipe_core_private *sipe_private,
89 const gchar *method,
90 const gchar *request,
91 const gchar *additional,
92 guint *deltanum,
93 SoapTransCallback callback,
94 struct transaction_payload *payload)
96 gchar *from = deltanum ?
97 sip_uri_self(sipe_private) :
98 sip_uri_from_name(sipe_private->public.sip_domain);
99 gchar *delta = deltanum ?
100 g_strdup_printf("<m:deltaNum>%d</m:deltaNum>", (*deltanum)++) :
101 g_strdup("");
102 gchar *soap = g_strdup_printf("<s:Envelope"
103 " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
104 " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\""
106 "<s:Body>"
107 "<m:%s>"
108 "%s"
109 "%s"
110 "</m:%s>"
111 "%s"
112 "</s:Body>"
113 "</s:Envelope>",
114 method,
115 request,
116 delta,
117 method,
118 additional ? additional : "");
119 sip_soap_raw_request_cb(sipe_private, from, soap, callback, payload);
120 g_free(soap);
121 g_free(delta);
122 g_free(from);
125 void sip_soap_request_cb(struct sipe_core_private *sipe_private,
126 const gchar *method,
127 const gchar *request,
128 SoapTransCallback callback,
129 struct transaction_payload *payload)
131 sip_soap_request_full(sipe_private,
132 method,
133 request,
134 NULL,
135 &sipe_private->deltanum_contacts,
136 callback,
137 payload);
140 void sip_soap_request(struct sipe_core_private *sipe_private,
141 const gchar *method,
142 const gchar *request)
144 sip_soap_request_cb(sipe_private,
145 method,
146 request,
147 NULL,
148 NULL);
151 /* This is the only user of deltanum_acl */
152 void sip_soap_ocs2005_setacl(struct sipe_core_private *sipe_private,
153 const gchar *who,
154 gboolean allow)
156 gchar *request = g_strdup_printf("<m:type>USER</m:type>"
157 "<m:mask>%s</m:mask>"
158 "<m:rights>%s</m:rights>",
159 who,
160 allow ? "AA" : "BD");
161 sip_soap_request_full(sipe_private,
162 "setACE",
163 request,
164 NULL,
165 &sipe_private->deltanum_acl,
166 NULL,
167 NULL);
168 g_free(request);
172 * This request is special:
173 * a) it is send from domain URI and not the users
174 * b) it has XML nodes outside the [MS-PRES] method node
175 * c) doesn't use deltaNum
177 void sip_soap_directory_search(struct sipe_core_private *sipe_private,
178 guint max,
179 const gchar *rows,
180 SoapTransCallback callback,
181 struct transaction_payload *payload)
183 gchar *request = g_strdup_printf("<m:filter m:href=\"#searchArray\"/>"
184 "<m:maxResults>%d</m:maxResults>",
185 max);
186 gchar *additional = g_strdup_printf("<m:Array m:id=\"searchArray\">"
187 "%s"
188 "</m:Array>",
189 rows);
190 sip_soap_request_full(sipe_private,
191 "directorySearch",
192 request,
193 additional,
194 NULL,
195 callback,
196 payload);
197 g_free(additional);
198 g_free(request);
202 Local Variables:
203 mode: c
204 c-file-style: "bsd"
205 indent-tabs-mode: t
206 tab-width: 8
207 End: