l10n: sync translations with transifex.com (es, pt_BR)
[siplcs.git] / src / core / sip-soap.c
blob55dec622327d185b15a44bb0f244c4a467c06041
1 /**
2 * @file sip-soap.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2016 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-backend.h"
38 #include "sipe-core.h"
39 #include "sipe-core-private.h"
40 #include "sipe-utils.h"
42 void sip_soap_raw_request_cb(struct sipe_core_private *sipe_private,
43 const gchar *from,
44 const gchar *soap,
45 SoapTransCallback callback,
46 struct transaction_payload *payload)
48 gchar *contact = get_contact(sipe_private);
49 gchar *hdr = g_strdup_printf("Contact: %s\r\n"
50 "Content-Type: application/SOAP+xml\r\n",
51 contact);
53 struct transaction *trans = sip_transport_service(sipe_private,
54 from,
55 hdr,
56 soap,
57 callback);
58 if (trans) {
59 trans->payload = payload;
60 /* SIP transport is no longer valid - give up */
61 } else if (payload) {
62 if (payload->destroy)
63 (payload->destroy)(payload->data);
64 g_free(payload);
67 g_free(contact);
68 g_free(hdr);
71 /**
72 * delta_num != NULL: use user sip: URI as from, include deltanum and increment it
73 * delta_num == NULL; use sip: URI generated from domain name as from
75 static void sip_soap_request_full(struct sipe_core_private *sipe_private,
76 const gchar *method,
77 const gchar *request,
78 const gchar *additional,
79 guint *deltanum,
80 SoapTransCallback callback,
81 struct transaction_payload *payload)
83 gchar *from = deltanum ?
84 sip_uri_self(sipe_private) :
85 sip_uri_from_name(sipe_private->public.sip_domain);
86 gchar *delta = deltanum ?
87 g_strdup_printf("<m:deltaNum>%d</m:deltaNum>", (*deltanum)++) :
88 g_strdup("");
89 gchar *soap = g_strdup_printf("<s:Envelope"
90 " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
91 " xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\""
92 ">"
93 "<s:Body>"
94 "<m:%s>"
95 "%s"
96 "%s"
97 "</m:%s>"
98 "%s"
99 "</s:Body>"
100 "</s:Envelope>",
101 method,
102 request,
103 delta,
104 method,
105 additional ? additional : "");
106 sip_soap_raw_request_cb(sipe_private, from, soap, callback, payload);
107 g_free(soap);
108 g_free(delta);
109 g_free(from);
112 void sip_soap_request_cb(struct sipe_core_private *sipe_private,
113 const gchar *method,
114 const gchar *request,
115 SoapTransCallback callback,
116 struct transaction_payload *payload)
118 sip_soap_request_full(sipe_private,
119 method,
120 request,
121 NULL,
122 &sipe_private->deltanum_contacts,
123 callback,
124 payload);
127 void sip_soap_request(struct sipe_core_private *sipe_private,
128 const gchar *method,
129 const gchar *request)
131 sip_soap_request_cb(sipe_private,
132 method,
133 request,
134 NULL,
135 NULL);
138 /* This is the only user of deltanum_acl */
139 void sip_soap_ocs2005_setacl(struct sipe_core_private *sipe_private,
140 const gchar *who,
141 gboolean allow)
143 gchar *request = g_strdup_printf("<m:type>USER</m:type>"
144 "<m:mask>%s</m:mask>"
145 "<m:rights>%s</m:rights>",
146 who,
147 allow ? "AA" : "BD");
148 sip_soap_request_full(sipe_private,
149 "setACE",
150 request,
151 NULL,
152 &sipe_private->deltanum_acl,
153 NULL,
154 NULL);
155 g_free(request);
159 * This request is special:
160 * a) it is send from domain URI and not the users
161 * b) it has XML nodes outside the [MS-PRES] method node
162 * c) doesn't use deltaNum
164 void sip_soap_directory_search(struct sipe_core_private *sipe_private,
165 guint max,
166 const gchar *rows,
167 SoapTransCallback callback,
168 struct transaction_payload *payload)
170 gchar *request = g_strdup_printf("<m:filter m:href=\"#searchArray\"/>"
171 "<m:maxResults>%d</m:maxResults>",
172 max);
173 gchar *additional = g_strdup_printf("<m:Array m:id=\"searchArray\">"
174 "%s"
175 "</m:Array>",
176 rows);
177 sip_soap_request_full(sipe_private,
178 "directorySearch",
179 request,
180 additional,
181 NULL,
182 callback,
183 payload);
184 g_free(additional);
185 g_free(request);
189 Local Variables:
190 mode: c
191 c-file-style: "bsd"
192 indent-tabs-mode: t
193 tab-width: 8
194 End: