| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 1999-2008 Novell, Inc. (www.novell.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include <libedataserver/libedataserver.h> |
| 9 |
|
| 10 |
#include <string.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <errno.h> |
| 13 |
#include <libsoup/soup.h> |
| 14 |
|
| 15 |
#include "e-ews-connection-utils.h" |
| 16 |
#include "e-ews-debug.h" |
| 17 |
|
| 18 |
#include "e-soap-request.h" |
| 19 |
|
| 20 |
struct _ESoapRequestPrivate { |
| 21 |
gchar *method; |
| 22 |
GUri *uri; |
| 23 |
|
| 24 |
ESoapResponseProgressFn progress_fn; |
| 25 |
gpointer progress_data; |
| 26 |
|
| 27 |
ESoapRequestCustomProcessFn custom_process_fn; |
| 28 |
gpointer custom_process_data; |
| 29 |
|
| 30 |
gchar *custom_body_content_type; |
| 31 |
gpointer custom_body_data; |
| 32 |
gssize custom_body_data_len; |
| 33 |
|
| 34 |
gchar *etag; |
| 35 |
|
| 36 |
gchar *store_node_data_nodename; |
| 37 |
gchar *store_node_data_directory; |
| 38 |
gboolean store_node_data_base64; |
| 39 |
|
| 40 |
gchar *certificate_pem; |
| 41 |
GTlsCertificateFlags certificate_errors; |
| 42 |
|
| 43 |
xmlDocPtr doc; |
| 44 |
xmlNodePtr last_node; |
| 45 |
xmlNsPtr soap_ns; |
| 46 |
xmlNsPtr xsi_ns; |
| 47 |
xmlChar *env_prefix; |
| 48 |
xmlChar *env_uri; |
| 49 |
gboolean body_started; |
| 50 |
gchar *action; |
| 51 |
}; |
| 52 |
|
| 53 |
G_DEFINE_TYPE_WITH_PRIVATE (ESoapRequest, e_soap_request, G_TYPE_OBJECT) |
| 54 |
|
| 55 |
static void |
| 56 |
soap_request_finalize (GObject *object) |
| 57 |
{ |
| 58 |
ESoapRequest *req = E_SOAP_REQUEST (object); |
| 59 |
|
| 60 |
g_clear_pointer (&req->priv->method, g_free); |
| 61 |
g_clear_pointer (&req->priv->uri, g_uri_unref); |
| 62 |
g_clear_pointer (&req->priv->custom_body_content_type, g_free); |
| 63 |
g_clear_pointer (&req->priv->custom_body_data, g_free); |
| 64 |
g_clear_pointer (&req->priv->etag, g_free); |
| 65 |
g_clear_pointer (&req->priv->certificate_pem, g_free); |
| 66 |
g_clear_pointer (&req->priv->store_node_data_nodename, g_free); |
| 67 |
g_clear_pointer (&req->priv->store_node_data_directory, g_free); |
| 68 |
|
| 69 |
g_clear_pointer (&req->priv->doc, xmlFreeDoc); |
| 70 |
g_clear_pointer (&req->priv->action, g_free); |
| 71 |
g_clear_pointer (&req->priv->env_uri, xmlFree); |
| 72 |
g_clear_pointer (&req->priv->env_prefix, xmlFree); |
| 73 |
|
| 74 |
/* Chain up to parent's method. */ |
| 75 |
G_OBJECT_CLASS (e_soap_request_parent_class)->finalize (object); |
| 76 |
} |
| 77 |
|
| 78 |
static void |
| 79 |
e_soap_request_class_init (ESoapRequestClass *class) |
| 80 |
{ |
| 81 |
GObjectClass *object_class; |
| 82 |
|
| 83 |
object_class = G_OBJECT_CLASS (class); |
| 84 |
object_class->finalize = soap_request_finalize; |
| 85 |
} |
| 86 |
|
| 87 |
static void |
| 88 |
e_soap_request_init (ESoapRequest *req) |
| 89 |
{ |
| 90 |
req->priv = e_soap_request_get_instance_private (req); |
| 91 |
|
| 92 |
/* initialize XML structures */ |
| 93 |
req->priv->doc = xmlNewDoc ((const xmlChar *) "1.0"); |
| 94 |
req->priv->doc->standalone = FALSE; |
| 95 |
req->priv->doc->encoding = xmlCharStrdup ("UTF-8"); |
| 96 |
} |
| 97 |
|
| 98 |
static xmlNsPtr |
| 99 |
fetch_ns (ESoapRequest *req, |
| 100 |
const gchar *prefix, |
| 101 |
const gchar *ns_uri) |
| 102 |
{ |
| 103 |
xmlNsPtr ns = NULL; |
| 104 |
|
| 105 |
if (prefix && ns_uri) |
| 106 |
ns = xmlNewNs ( |
| 107 |
req->priv->last_node, |
| 108 |
(const xmlChar *) ns_uri, |
| 109 |
(const xmlChar *) prefix); |
| 110 |
else if (prefix && !ns_uri) { |
| 111 |
ns = xmlSearchNs ( |
| 112 |
req->priv->doc, req->priv->last_node, |
| 113 |
(const xmlChar *) prefix); |
| 114 |
if (!ns) |
| 115 |
ns = xmlNewNs ( |
| 116 |
req->priv->last_node, |
| 117 |
(const xmlChar *) "", |
| 118 |
(const xmlChar *) prefix); |
| 119 |
} |
| 120 |
|
| 121 |
return ns; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* e_soap_request_new: |
| 126 |
* @method: the HTTP method for the created request. |
| 127 |
* @uri_string: the destination endpoint (as a string). |
| 128 |
* @standalone: ??? FIXME |
| 129 |
* @xml_encoding: ??? FIXME |
| 130 |
* @env_prefix: ??? FIXME |
| 131 |
* @env_uri: ??? FIXME |
| 132 |
* @error: a #GError, or %NULL |
| 133 |
* |
| 134 |
* Creates a new empty #ESoapRequest, which will connect to @uri_string. |
| 135 |
* |
| 136 |
* Returns: the new #ESoapRequest (or %NULL if @uri_string could not be |
| 137 |
* parsed). |
| 138 |
*/ |
| 139 |
ESoapRequest * |
| 140 |
e_soap_request_new (const gchar *method, |
| 141 |
const gchar *uri_string, |
| 142 |
gboolean standalone, |
| 143 |
const gchar *xml_encoding, |
| 144 |
const gchar *env_prefix, |
| 145 |
const gchar *env_uri, |
| 146 |
GError **error) |
| 147 |
{ |
| 148 |
ESoapRequest *req; |
| 149 |
GUri *uri; |
| 150 |
|
| 151 |
uri = g_uri_parse (uri_string, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, error); |
| 152 |
if (!uri) |
| 153 |
return NULL; |
| 154 |
|
| 155 |
req = e_soap_request_new_from_uri ( |
| 156 |
method, uri, standalone, |
| 157 |
xml_encoding, env_prefix, env_uri); |
| 158 |
|
| 159 |
g_uri_unref (uri); |
| 160 |
|
| 161 |
return req; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* e_soap_request_new_from_uri: |
| 166 |
* @method: the HTTP method for the created request. |
| 167 |
* @uri: the destination endpoint (as a #GUri). |
| 168 |
* @standalone: ??? FIXME |
| 169 |
* @xml_encoding: ??? FIXME |
| 170 |
* @env_prefix: ??? FIXME |
| 171 |
* @env_uri: ??? FIXME |
| 172 |
* |
| 173 |
* Creates a new empty #ESoapRequest, which will connect to @uri |
| 174 |
* |
| 175 |
* Returns: the new #ESoapRequest |
| 176 |
*/ |
| 177 |
ESoapRequest * |
| 178 |
e_soap_request_new_from_uri (const gchar *method, |
| 179 |
GUri *uri, |
| 180 |
gboolean standalone, |
| 181 |
const gchar *xml_encoding, |
| 182 |
const gchar *env_prefix, |
| 183 |
const gchar *env_uri) |
| 184 |
{ |
| 185 |
ESoapRequest *req; |
| 186 |
|
| 187 |
req = g_object_new (E_TYPE_SOAP_REQUEST, NULL); |
| 188 |
|
| 189 |
req->priv->method = g_strdup (method); |
| 190 |
req->priv->uri = g_uri_ref (uri); |
| 191 |
req->priv->doc->standalone = standalone; |
| 192 |
|
| 193 |
if (xml_encoding) { |
| 194 |
xmlFree ((xmlChar *) req->priv->doc->encoding); |
| 195 |
req->priv->doc->encoding = xmlCharStrdup (xml_encoding); |
| 196 |
} |
| 197 |
|
| 198 |
if (env_prefix != NULL) |
| 199 |
req->priv->env_prefix = xmlCharStrdup (env_prefix); |
| 200 |
if (env_uri != NULL) |
| 201 |
req->priv->env_uri = xmlCharStrdup (env_uri); |
| 202 |
|
| 203 |
return req; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* e_soap_request_start_envelope: |
| 208 |
* @req: the %ESoapRequest. |
| 209 |
* |
| 210 |
* Starts the top level SOAP Envelope element. |
| 211 |
*/ |
| 212 |
void |
| 213 |
e_soap_request_start_envelope (ESoapRequest *req) |
| 214 |
{ |
| 215 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 216 |
|
| 217 |
req->priv->doc->xmlRootNode = xmlNewDocNode ( |
| 218 |
req->priv->doc, NULL, |
| 219 |
(const xmlChar *) "Envelope", |
| 220 |
(const xmlChar *) NULL); |
| 221 |
req->priv->last_node = req->priv->doc->xmlRootNode; |
| 222 |
|
| 223 |
req->priv->soap_ns = xmlNewNs ( |
| 224 |
req->priv->doc->xmlRootNode, |
| 225 |
req->priv->env_uri ? req->priv->env_uri : |
| 226 |
(const xmlChar *) "http://schemas.xmlsoap.org/soap/envelope/", |
| 227 |
req->priv->env_prefix ? req->priv->env_prefix : |
| 228 |
(const xmlChar *) "SOAP-ENV"); |
| 229 |
|
| 230 |
if (req->priv->env_uri != NULL) { |
| 231 |
xmlFree (req->priv->env_uri); |
| 232 |
req->priv->env_uri = NULL; |
| 233 |
} |
| 234 |
|
| 235 |
if (req->priv->env_prefix) { |
| 236 |
xmlFree (req->priv->env_prefix); |
| 237 |
req->priv->env_prefix = NULL; |
| 238 |
} |
| 239 |
|
| 240 |
xmlSetNs ( |
| 241 |
req->priv->doc->xmlRootNode, |
| 242 |
req->priv->soap_ns); |
| 243 |
xmlNewNs ( |
| 244 |
req->priv->doc->xmlRootNode, |
| 245 |
(const xmlChar *) "http://schemas.xmlsoap.org/soap/encoding/", |
| 246 |
(const xmlChar *) "SOAP-ENC"); |
| 247 |
xmlNewNs ( |
| 248 |
req->priv->doc->xmlRootNode, |
| 249 |
(const xmlChar *) "http://www.w3.org/2001/XMLSchema", |
| 250 |
(const xmlChar *) "xsd"); |
| 251 |
xmlNewNs ( |
| 252 |
req->priv->doc->xmlRootNode, |
| 253 |
(const xmlChar *) "http://schemas.xmlsoap.org/soap/envelope/", |
| 254 |
(const xmlChar *) "SOAP-ENV"); |
| 255 |
req->priv->xsi_ns = xmlNewNs ( |
| 256 |
req->priv->doc->xmlRootNode, |
| 257 |
(const xmlChar *) "http://www.w3.org/2001/XMLSchema-instance", |
| 258 |
(const xmlChar *) "xsi"); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* e_soap_request_end_envelope: |
| 263 |
* @req: the %ESoapRequest. |
| 264 |
* |
| 265 |
* Closes the top level SOAP Envelope element. |
| 266 |
*/ |
| 267 |
void |
| 268 |
e_soap_request_end_envelope (ESoapRequest *req) |
| 269 |
{ |
| 270 |
e_soap_request_end_element (req); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* e_soap_request_start_body: |
| 275 |
* @req: the %ESoapRequest. |
| 276 |
* |
| 277 |
* Starts the SOAP Body element. |
| 278 |
*/ |
| 279 |
void |
| 280 |
e_soap_request_start_body (ESoapRequest *req) |
| 281 |
{ |
| 282 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 283 |
|
| 284 |
if (req->priv->body_started) |
| 285 |
return; |
| 286 |
|
| 287 |
req->priv->last_node = xmlNewChild ( |
| 288 |
req->priv->last_node, |
| 289 |
req->priv->soap_ns, |
| 290 |
(const xmlChar *) "Body", NULL); |
| 291 |
|
| 292 |
req->priv->body_started = TRUE; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* e_soap_request_end_body: |
| 297 |
* @req: the %ESoapRequest. |
| 298 |
* |
| 299 |
* Closes the SOAP Body element. |
| 300 |
*/ |
| 301 |
void |
| 302 |
e_soap_request_end_body (ESoapRequest *req) |
| 303 |
{ |
| 304 |
e_soap_request_end_element (req); |
| 305 |
} |
| 306 |
|
| 307 |
/** |
| 308 |
* e_soap_request_start_element: |
| 309 |
* @req: the #ESoapRequest. |
| 310 |
* @name: the element name. |
| 311 |
* @prefix: the namespace prefix |
| 312 |
* @ns_uri: the namespace URI |
| 313 |
* |
| 314 |
* Starts a new arbitrary request element, with @name as the element |
| 315 |
* name, @prefix as the XML Namespace prefix, and @ns_uri as the XML |
| 316 |
* Namespace uri for * the created element. |
| 317 |
* |
| 318 |
* Passing @prefix with no @ns_uri will cause a recursive search for |
| 319 |
* an existing namespace with the same prefix. Failing that a new ns |
| 320 |
* will be created with an empty uri. |
| 321 |
* |
| 322 |
* Passing both @prefix and @ns_uri always causes new namespace |
| 323 |
* attribute creation. |
| 324 |
* |
| 325 |
* Passing NULL for both @prefix and @ns_uri causes no prefix to be |
| 326 |
* used, and the element will be in the default namespace. |
| 327 |
*/ |
| 328 |
void |
| 329 |
e_soap_request_start_element (ESoapRequest *req, |
| 330 |
const gchar *name, |
| 331 |
const gchar *prefix, |
| 332 |
const gchar *ns_uri) |
| 333 |
{ |
| 334 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 335 |
|
| 336 |
req->priv->last_node = xmlNewChild ( |
| 337 |
req->priv->last_node, NULL, |
| 338 |
(const xmlChar *) name, NULL); |
| 339 |
|
| 340 |
xmlSetNs (req->priv->last_node, fetch_ns (req, prefix, ns_uri)); |
| 341 |
|
| 342 |
if (ns_uri == NULL) |
| 343 |
ns_uri = ""; |
| 344 |
|
| 345 |
if (req->priv->body_started && req->priv->action == NULL) |
| 346 |
req->priv->action = g_strconcat (ns_uri, "#", name, NULL); |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* e_soap_request_end_element: |
| 351 |
* @req: the #ESoapRequest. |
| 352 |
* |
| 353 |
* Closes the current request element. |
| 354 |
*/ |
| 355 |
void |
| 356 |
e_soap_request_end_element (ESoapRequest *req) |
| 357 |
{ |
| 358 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 359 |
|
| 360 |
req->priv->last_node = req->priv->last_node->parent; |
| 361 |
} |
| 362 |
|
| 363 |
/** |
| 364 |
* e_soap_request_start_fault: |
| 365 |
* @req: the #ESoapRequest. |
| 366 |
* @faultcode: faultcode element value |
| 367 |
* @faultstring: faultstring element value |
| 368 |
* @faultfactor: faultfactor element value |
| 369 |
* |
| 370 |
* Starts a new SOAP Fault element, creating faultcode, faultstring, |
| 371 |
* and faultfactor child elements. |
| 372 |
* |
| 373 |
* If you wish to add the faultdetail element, use |
| 374 |
* e_soap_request_start_fault_detail(), and then |
| 375 |
* e_soap_request_start_element() to add arbitrary sub-elements. |
| 376 |
*/ |
| 377 |
void |
| 378 |
e_soap_request_start_fault (ESoapRequest *req, |
| 379 |
const gchar *faultcode, |
| 380 |
const gchar *faultstring, |
| 381 |
const gchar *faultfactor) |
| 382 |
{ |
| 383 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 384 |
|
| 385 |
req->priv->last_node = xmlNewChild ( |
| 386 |
req->priv->last_node, |
| 387 |
req->priv->soap_ns, |
| 388 |
(const xmlChar *) "Fault", NULL); |
| 389 |
xmlNewChild ( |
| 390 |
req->priv->last_node, |
| 391 |
req->priv->soap_ns, |
| 392 |
(const xmlChar *) "faultcode", |
| 393 |
(const xmlChar *) faultcode); |
| 394 |
xmlNewChild ( |
| 395 |
req->priv->last_node, |
| 396 |
req->priv->soap_ns, |
| 397 |
(const xmlChar *) "faultstring", |
| 398 |
(const xmlChar *) faultstring); |
| 399 |
|
| 400 |
req->priv->last_node = xmlNewChild ( |
| 401 |
req->priv->last_node, |
| 402 |
req->priv->soap_ns, |
| 403 |
(const xmlChar *) "faultfactor", |
| 404 |
(const xmlChar *) faultfactor); |
| 405 |
if (faultfactor == NULL) |
| 406 |
e_soap_request_set_null (req); |
| 407 |
|
| 408 |
e_soap_request_end_element (req); |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* e_soap_request_end_fault: |
| 413 |
* @req: the #ESoapRequest. |
| 414 |
* |
| 415 |
* Closes the current SOAP Fault element. |
| 416 |
*/ |
| 417 |
void |
| 418 |
e_soap_request_end_fault (ESoapRequest *req) |
| 419 |
{ |
| 420 |
e_soap_request_end_element (req); |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* e_soap_request_start_fault_detail: |
| 425 |
* @req: the #ESoapRequest. |
| 426 |
* |
| 427 |
* Start the faultdetail child element of the current SOAP Fault |
| 428 |
* element. The faultdetail element allows arbitrary data to be sent |
| 429 |
* in a returned fault. |
| 430 |
**/ |
| 431 |
void |
| 432 |
e_soap_request_start_fault_detail (ESoapRequest *req) |
| 433 |
{ |
| 434 |
|
| 435 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 436 |
|
| 437 |
req->priv->last_node = xmlNewChild ( |
| 438 |
req->priv->last_node, |
| 439 |
req->priv->soap_ns, |
| 440 |
(const xmlChar *) "detail", |
| 441 |
(const xmlChar *) NULL); |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* e_soap_request_end_fault_detail: |
| 446 |
* @req: the #ESoapRequest. |
| 447 |
* |
| 448 |
* Closes the current SOAP faultdetail element. |
| 449 |
*/ |
| 450 |
void |
| 451 |
e_soap_request_end_fault_detail (ESoapRequest *req) |
| 452 |
{ |
| 453 |
e_soap_request_end_element (req); |
| 454 |
} |
| 455 |
|
| 456 |
/** |
| 457 |
* e_soap_request_start_header: |
| 458 |
* @req: the #ESoapRequest. |
| 459 |
* |
| 460 |
* Creates a new SOAP Header element. You can call |
| 461 |
* e_soap_request_start_header_element() after this to add a new |
| 462 |
* header child element. SOAP Header elements allow out-of-band data |
| 463 |
* to be transferred while not interfering with the request body. |
| 464 |
* |
| 465 |
* This should be called after e_soap_request_start_envelope() and |
| 466 |
* before e_soap_request_start_body(). |
| 467 |
*/ |
| 468 |
void |
| 469 |
e_soap_request_start_header (ESoapRequest *req) |
| 470 |
{ |
| 471 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 472 |
|
| 473 |
req->priv->last_node = xmlNewChild ( |
| 474 |
req->priv->last_node, |
| 475 |
req->priv->soap_ns, |
| 476 |
(const xmlChar *) "Header", |
| 477 |
(const xmlChar *) NULL); |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* e_soap_request_end_header: |
| 482 |
* @req: the #ESoapRequest. |
| 483 |
* |
| 484 |
* Closes the current SOAP Header element. |
| 485 |
*/ |
| 486 |
void |
| 487 |
e_soap_request_end_header (ESoapRequest *req) |
| 488 |
{ |
| 489 |
e_soap_request_end_element (req); |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* e_soap_request_start_header_element: |
| 494 |
* @req: the #ESoapRequest. |
| 495 |
* @name: name of the header element |
| 496 |
* @must_understand: whether the recipient must understand the header in order |
| 497 |
* to proceed with processing the request |
| 498 |
* @actor_uri: the URI which represents the destination actor for this header. |
| 499 |
* @prefix: the namespace prefix |
| 500 |
* @ns_uri: the namespace URI |
| 501 |
* |
| 502 |
* Starts a new SOAP arbitrary header element. |
| 503 |
*/ |
| 504 |
void |
| 505 |
e_soap_request_start_header_element (ESoapRequest *req, |
| 506 |
const gchar *name, |
| 507 |
gboolean must_understand, |
| 508 |
const gchar *actor_uri, |
| 509 |
const gchar *prefix, |
| 510 |
const gchar *ns_uri) |
| 511 |
{ |
| 512 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 513 |
|
| 514 |
e_soap_request_start_element (req, name, prefix, ns_uri); |
| 515 |
if (actor_uri != NULL) |
| 516 |
xmlNewNsProp ( |
| 517 |
req->priv->last_node, |
| 518 |
req->priv->soap_ns, |
| 519 |
(const xmlChar *) "actorUri", |
| 520 |
(const xmlChar *) actor_uri); |
| 521 |
if (must_understand) |
| 522 |
xmlNewNsProp ( |
| 523 |
req->priv->last_node, |
| 524 |
req->priv->soap_ns, |
| 525 |
(const xmlChar *) "mustUnderstand", |
| 526 |
(const xmlChar *) "1"); |
| 527 |
} |
| 528 |
|
| 529 |
/** |
| 530 |
* e_soap_request_end_header_element: |
| 531 |
* @req: the #ESoapRequest. |
| 532 |
* |
| 533 |
* Closes the current SOAP header element. |
| 534 |
*/ |
| 535 |
void |
| 536 |
e_soap_request_end_header_element (ESoapRequest *req) |
| 537 |
{ |
| 538 |
e_soap_request_end_element (req); |
| 539 |
} |
| 540 |
|
| 541 |
/** |
| 542 |
* e_soap_request_write_int: |
| 543 |
* @req: the #ESoapRequest. |
| 544 |
* @i: the integer value to write. |
| 545 |
* |
| 546 |
* Writes the stringified value of @i as the current element's content. |
| 547 |
*/ |
| 548 |
void |
| 549 |
e_soap_request_write_int (ESoapRequest *req, |
| 550 |
glong i) |
| 551 |
{ |
| 552 |
gchar *string; |
| 553 |
|
| 554 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 555 |
|
| 556 |
string = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) i); |
| 557 |
e_soap_request_write_string (req, string); |
| 558 |
g_free (string); |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* e_soap_request_write_double: |
| 563 |
* @req: the #ESoapRequest. |
| 564 |
* @d: the double value to write. |
| 565 |
* |
| 566 |
* Writes the stringified value of @d as the current element's content. |
| 567 |
*/ |
| 568 |
void |
| 569 |
e_soap_request_write_double (ESoapRequest *req, |
| 570 |
gdouble d) |
| 571 |
{ |
| 572 |
gchar buffer[G_ASCII_DTOSTR_BUF_SIZE + 1]; |
| 573 |
|
| 574 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 575 |
|
| 576 |
g_ascii_dtostr (buffer, sizeof (buffer), d); |
| 577 |
e_soap_request_write_string (req, buffer); |
| 578 |
} |
| 579 |
|
| 580 |
/** |
| 581 |
* e_soap_request_write_base64: |
| 582 |
* @req: the #ESoapRequest |
| 583 |
* @string: the binary data buffer to encode |
| 584 |
* @len: the length of data to encode |
| 585 |
* |
| 586 |
* Writes the Base-64 encoded value of @string as the current |
| 587 |
* element's content. |
| 588 |
**/ |
| 589 |
void |
| 590 |
e_soap_request_write_base64 (ESoapRequest *req, |
| 591 |
const gchar *string, |
| 592 |
gint len) |
| 593 |
{ |
| 594 |
gchar *encoded; |
| 595 |
|
| 596 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 597 |
|
| 598 |
encoded = g_base64_encode ((const guchar *) string, len); |
| 599 |
e_soap_request_write_string (req, encoded); |
| 600 |
g_free (encoded); |
| 601 |
} |
| 602 |
|
| 603 |
/** |
| 604 |
* e_soap_request_write_time: |
| 605 |
* @req: the #ESoapRequest. |
| 606 |
* @timeval: the time_t to encode |
| 607 |
* |
| 608 |
* Writes the iso8601 value of @timeval as the current element's |
| 609 |
* content. |
| 610 |
**/ |
| 611 |
void |
| 612 |
e_soap_request_write_time (ESoapRequest *req, |
| 613 |
time_t timeval) |
| 614 |
{ |
| 615 |
GTimeVal tv; |
| 616 |
gchar *iso_time; |
| 617 |
|
| 618 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 619 |
|
| 620 |
tv.tv_usec = 0; |
| 621 |
tv.tv_sec = timeval; |
| 622 |
|
| 623 |
iso_time = g_time_val_to_iso8601 (&tv); |
| 624 |
e_soap_request_write_string (req, iso_time); |
| 625 |
g_free (iso_time); |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* e_soap_request_write_string: |
| 630 |
* @req: the #ESoapRequest. |
| 631 |
* @string: string to write. |
| 632 |
* |
| 633 |
* Writes the @string as the current element's content. |
| 634 |
*/ |
| 635 |
void |
| 636 |
e_soap_request_write_string (ESoapRequest *req, |
| 637 |
const gchar *string) |
| 638 |
{ |
| 639 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 640 |
|
| 641 |
xmlNodeAddContent ( |
| 642 |
req->priv->last_node, |
| 643 |
(const xmlChar *) string); |
| 644 |
} |
| 645 |
|
| 646 |
/** |
| 647 |
* e_soap_request_write_buffer: |
| 648 |
* @req: the #ESoapRequest. |
| 649 |
* @buffer: the string data buffer to write. |
| 650 |
* @len: length of @buffer. |
| 651 |
* |
| 652 |
* Writes the string buffer pointed to by @buffer as the current |
| 653 |
* element's content. |
| 654 |
*/ |
| 655 |
void |
| 656 |
e_soap_request_write_buffer (ESoapRequest *req, |
| 657 |
const gchar *buffer, |
| 658 |
gint len) |
| 659 |
{ |
| 660 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 661 |
|
| 662 |
xmlNodeAddContentLen ( |
| 663 |
req->priv->last_node, |
| 664 |
(const xmlChar *) buffer, len); |
| 665 |
} |
| 666 |
|
| 667 |
/** |
| 668 |
* e_soap_request_set_element_type: |
| 669 |
* @req: the #ESoapRequest. |
| 670 |
* @xsi_type: the type name for the element. |
| 671 |
* |
| 672 |
* Sets the current element's XML schema xsi:type attribute, which |
| 673 |
* specifies the element's type name. |
| 674 |
*/ |
| 675 |
void |
| 676 |
e_soap_request_set_element_type (ESoapRequest *req, |
| 677 |
const gchar *xsi_type) |
| 678 |
{ |
| 679 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 680 |
|
| 681 |
xmlNewNsProp ( |
| 682 |
req->priv->last_node, |
| 683 |
req->priv->xsi_ns, |
| 684 |
(const xmlChar *) "type", |
| 685 |
(const xmlChar *) xsi_type); |
| 686 |
} |
| 687 |
|
| 688 |
/** |
| 689 |
* e_soap_request_set_null: |
| 690 |
* @req: the #ESoapRequest. |
| 691 |
* |
| 692 |
* Sets the current element's XML Schema xsi:null attribute. |
| 693 |
*/ |
| 694 |
void |
| 695 |
e_soap_request_set_null (ESoapRequest *req) |
| 696 |
{ |
| 697 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 698 |
|
| 699 |
xmlNewNsProp ( |
| 700 |
req->priv->last_node, |
| 701 |
req->priv->xsi_ns, |
| 702 |
(const xmlChar *) "null", |
| 703 |
(const xmlChar *) "1"); |
| 704 |
} |
| 705 |
|
| 706 |
/** |
| 707 |
* e_soap_request_add_attribute: |
| 708 |
* @req: the #ESoapRequest. |
| 709 |
* @name: name of the attribute |
| 710 |
* @value: value of the attribute |
| 711 |
* @prefix: the namespace prefix |
| 712 |
* @ns_uri: the namespace URI |
| 713 |
* |
| 714 |
* Adds an XML attribute to the current element. |
| 715 |
*/ |
| 716 |
void |
| 717 |
e_soap_request_add_attribute (ESoapRequest *req, |
| 718 |
const gchar *name, |
| 719 |
const gchar *value, |
| 720 |
const gchar *prefix, |
| 721 |
const gchar *ns_uri) |
| 722 |
{ |
| 723 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 724 |
|
| 725 |
xmlNewNsProp ( |
| 726 |
req->priv->last_node, |
| 727 |
fetch_ns (req, prefix, ns_uri), |
| 728 |
(const xmlChar *) name, |
| 729 |
(const xmlChar *) value); |
| 730 |
} |
| 731 |
|
| 732 |
/** |
| 733 |
* e_soap_request_add_namespace: |
| 734 |
* @req: the #ESoapRequest. |
| 735 |
* @prefix: the namespace prefix |
| 736 |
* @ns_uri: the namespace URI, or NULL for empty namespace |
| 737 |
* |
| 738 |
* Adds a new XML namespace to the current element. |
| 739 |
*/ |
| 740 |
void |
| 741 |
e_soap_request_add_namespace (ESoapRequest *req, |
| 742 |
const gchar *prefix, |
| 743 |
const gchar *ns_uri) |
| 744 |
{ |
| 745 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 746 |
|
| 747 |
if (ns_uri == NULL) |
| 748 |
ns_uri = ""; |
| 749 |
|
| 750 |
xmlNewNs ( |
| 751 |
req->priv->last_node, |
| 752 |
(const xmlChar *) ns_uri, |
| 753 |
(const xmlChar *) prefix); |
| 754 |
} |
| 755 |
|
| 756 |
/** |
| 757 |
* e_soap_request_set_default_namespace: |
| 758 |
* @req: the #ESoapRequest. |
| 759 |
* @ns_uri: the namespace URI. |
| 760 |
* |
| 761 |
* Sets the default namespace to the URI specified in @ns_uri. The |
| 762 |
* default namespace becomes the namespace all non-explicitly |
| 763 |
* namespaced child elements fall into. |
| 764 |
*/ |
| 765 |
void |
| 766 |
e_soap_request_set_default_namespace (ESoapRequest *req, |
| 767 |
const gchar *ns_uri) |
| 768 |
{ |
| 769 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 770 |
|
| 771 |
e_soap_request_add_namespace (req, NULL, ns_uri); |
| 772 |
} |
| 773 |
|
| 774 |
/** |
| 775 |
* e_soap_request_set_encoding_style: |
| 776 |
* @req: the #ESoapRequest. |
| 777 |
* @enc_style: the new encodingStyle value |
| 778 |
* |
| 779 |
* Sets the encodingStyle attribute on the current element to the |
| 780 |
* value of @enc_style. |
| 781 |
*/ |
| 782 |
void |
| 783 |
e_soap_request_set_encoding_style (ESoapRequest *req, |
| 784 |
const gchar *enc_style) |
| 785 |
{ |
| 786 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 787 |
|
| 788 |
xmlNewNsProp ( |
| 789 |
req->priv->last_node, |
| 790 |
req->priv->soap_ns, |
| 791 |
(const xmlChar *) "encodingStyle", |
| 792 |
(const xmlChar *) enc_style); |
| 793 |
} |
| 794 |
|
| 795 |
/** |
| 796 |
* e_soap_request_reset: |
| 797 |
* @req: the #ESoapRequest. |
| 798 |
* |
| 799 |
* Resets the internal XML representation of the SOAP request. |
| 800 |
*/ |
| 801 |
void |
| 802 |
e_soap_request_reset (ESoapRequest *req) |
| 803 |
{ |
| 804 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 805 |
|
| 806 |
xmlFreeDoc (req->priv->doc); |
| 807 |
req->priv->doc = xmlNewDoc ((const xmlChar *) "1.0"); |
| 808 |
req->priv->last_node = NULL; |
| 809 |
|
| 810 |
g_free (req->priv->action); |
| 811 |
req->priv->action = NULL; |
| 812 |
req->priv->body_started = FALSE; |
| 813 |
|
| 814 |
if (req->priv->env_uri != NULL) { |
| 815 |
xmlFree (req->priv->env_uri); |
| 816 |
req->priv->env_uri = NULL; |
| 817 |
} |
| 818 |
|
| 819 |
if (req->priv->env_prefix != NULL) { |
| 820 |
xmlFree (req->priv->env_prefix); |
| 821 |
req->priv->env_prefix = NULL; |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
/** |
| 826 |
* e_soap_request_get_namespace_prefix: |
| 827 |
* @req: the #ESoapRequest. |
| 828 |
* @ns_uri: the namespace URI. |
| 829 |
* |
| 830 |
* Returns the namespace prefix for @ns_uri (or an empty string if |
| 831 |
* @ns_uri is set to the default namespace) |
| 832 |
* |
| 833 |
* Returns: The namespace prefix, or %NULL if no namespace exists |
| 834 |
* for the URI given. |
| 835 |
*/ |
| 836 |
const gchar * |
| 837 |
e_soap_request_get_namespace_prefix (ESoapRequest *req, |
| 838 |
const gchar *ns_uri) |
| 839 |
{ |
| 840 |
xmlNsPtr ns = NULL; |
| 841 |
|
| 842 |
g_return_val_if_fail (E_IS_SOAP_REQUEST (req), NULL); |
| 843 |
g_return_val_if_fail (ns_uri != NULL, NULL); |
| 844 |
|
| 845 |
ns = xmlSearchNsByHref ( |
| 846 |
req->priv->doc, |
| 847 |
req->priv->last_node, |
| 848 |
(const xmlChar *) ns_uri); |
| 849 |
if (ns != NULL) { |
| 850 |
if (ns->prefix != NULL) |
| 851 |
return (const gchar *) ns->prefix; |
| 852 |
else |
| 853 |
return ""; |
| 854 |
} |
| 855 |
|
| 856 |
return NULL; |
| 857 |
} |
| 858 |
|
| 859 |
/** |
| 860 |
* e_soap_request_get_xml_doc: |
| 861 |
* @req: the #ESoapRequest. |
| 862 |
* |
| 863 |
* Returns the internal XML representation tree of the |
| 864 |
* #ESoapRequest pointed to by @req. |
| 865 |
* |
| 866 |
* Returns: the #xmlDocPtr representing the SOAP request. |
| 867 |
*/ |
| 868 |
xmlDocPtr |
| 869 |
e_soap_request_get_xml_doc (ESoapRequest *req) |
| 870 |
{ |
| 871 |
g_return_val_if_fail (E_IS_SOAP_REQUEST (req), NULL); |
| 872 |
|
| 873 |
return req->priv->doc; |
| 874 |
} |
| 875 |
|
| 876 |
void |
| 877 |
e_soap_request_set_progress_fn (ESoapRequest *req, |
| 878 |
ESoapResponseProgressFn fn, |
| 879 |
gpointer user_data) |
| 880 |
{ |
| 881 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 882 |
|
| 883 |
req->priv->progress_fn = fn; |
| 884 |
req->priv->progress_data = user_data; |
| 885 |
} |
| 886 |
|
| 887 |
void |
| 888 |
e_soap_request_get_progress_fn (ESoapRequest *req, |
| 889 |
ESoapResponseProgressFn *out_fn, |
| 890 |
gpointer *out_user_data) |
| 891 |
{ |
| 892 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 893 |
g_return_if_fail (out_fn != NULL); |
| 894 |
g_return_if_fail (out_user_data != NULL); |
| 895 |
|
| 896 |
*out_fn = req->priv->progress_fn; |
| 897 |
*out_user_data = req->priv->progress_data; |
| 898 |
} |
| 899 |
|
| 900 |
/** |
| 901 |
* e_soap_request_set_custom_body: |
| 902 |
* @req: the #ESoapRequest. |
| 903 |
* @content_type: (optional): content type of the custom body |
| 904 |
* @body: (optional): the custom message body, or %NULL; ignored when @content_type is %NULL |
| 905 |
* @body_len: length of the @body; ignored when @content_type is %NULL |
| 906 |
* |
| 907 |
* Stores custom body for the request, to be used instead of the SOAP @req content. |
| 908 |
* The @content_type can be %NULL to unset the custom body, or an empty string to indicate |
| 909 |
* no body should be set. The @body and @body_len parameters are ignored in these cases, |
| 910 |
* otherwise they are required. |
| 911 |
* |
| 912 |
* This function exists only to make internal API simpler. |
| 913 |
**/ |
| 914 |
void |
| 915 |
e_soap_request_set_custom_body (ESoapRequest *req, |
| 916 |
const gchar *content_type, |
| 917 |
gconstpointer body, |
| 918 |
gssize body_len) |
| 919 |
{ |
| 920 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 921 |
|
| 922 |
if (content_type && *content_type) |
| 923 |
g_return_if_fail (body != NULL); |
| 924 |
|
| 925 |
g_clear_pointer (&req->priv->custom_body_content_type, g_free); |
| 926 |
g_clear_pointer (&req->priv->custom_body_data, g_free); |
| 927 |
req->priv->custom_body_data_len = 0; |
| 928 |
|
| 929 |
if (content_type) { |
| 930 |
req->priv->custom_body_content_type = g_strdup (content_type); |
| 931 |
|
| 932 |
if (*content_type) { |
| 933 |
req->priv->custom_body_data = g_memdup2 (body, body_len); |
| 934 |
req->priv->custom_body_data_len = body_len; |
| 935 |
} |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
void |
| 940 |
e_soap_request_set_custom_process_fn (ESoapRequest *req, |
| 941 |
ESoapRequestCustomProcessFn fn, |
| 942 |
gpointer user_data) |
| 943 |
{ |
| 944 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 945 |
|
| 946 |
req->priv->custom_process_fn = fn; |
| 947 |
req->priv->custom_process_data = user_data; |
| 948 |
} |
| 949 |
|
| 950 |
void |
| 951 |
e_soap_request_get_custom_process_fn (ESoapRequest *req, |
| 952 |
ESoapRequestCustomProcessFn *out_fn, |
| 953 |
gpointer *out_user_data) |
| 954 |
{ |
| 955 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 956 |
g_return_if_fail (out_fn != NULL); |
| 957 |
g_return_if_fail (out_user_data != NULL); |
| 958 |
|
| 959 |
*out_fn = req->priv->custom_process_fn; |
| 960 |
*out_user_data = req->priv->custom_process_data; |
| 961 |
} |
| 962 |
|
| 963 |
/** |
| 964 |
* e_soap_request_take_tls_error_details: |
| 965 |
* @req: an #ESoapRequest |
| 966 |
* @certificate_pem: (transfer full) (nullable): a certificate in PEM format as string, or %NULL |
| 967 |
* @certificate_errors: a %GTlsCertificateFlags describing the errors |
| 968 |
* |
| 969 |
* Set the TLS/SSL error details for the @req. Read it back |
| 970 |
* with e_soap_request_get_tls_error_details(). |
| 971 |
* |
| 972 |
* The function assumes ownership of the @certificate_pem. |
| 973 |
**/ |
| 974 |
void |
| 975 |
e_soap_request_take_tls_error_details (ESoapRequest *req, |
| 976 |
gchar *certificate_pem, |
| 977 |
GTlsCertificateFlags certificate_errors) |
| 978 |
{ |
| 979 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 980 |
|
| 981 |
g_clear_pointer (&req->priv->certificate_pem, g_free); |
| 982 |
|
| 983 |
req->priv->certificate_pem = certificate_pem; |
| 984 |
req->priv->certificate_errors = certificate_errors; |
| 985 |
} |
| 986 |
|
| 987 |
/** |
| 988 |
* e_soap_request_get_tls_error_details: |
| 989 |
* @req: an #ESoapRequest |
| 990 |
* @out_certificate_pem: (out) (transfer none) (optional) (nullable): the certificatete in PEM format as string, or %NULL if not set |
| 991 |
* @out_certificate_errors: (out) (optional): certificate errors, or 0 when none set |
| 992 |
* |
| 993 |
* Retries previously set TLS error details by e_soap_request_take_tls_error_details(). |
| 994 |
* The @out_certificate_pem is owned by the @req and is valid until the @req is freed |
| 995 |
* or another call to e_soap_request_take_tls_error_details() is made. |
| 996 |
* |
| 997 |
* Returns: %TRUE, when the certificate PEM was set and the requested arguments |
| 998 |
* populated; %FALSE otherwise |
| 999 |
**/ |
| 1000 |
gboolean |
| 1001 |
e_soap_request_get_tls_error_details (ESoapRequest *req, |
| 1002 |
const gchar **out_certificate_pem, |
| 1003 |
GTlsCertificateFlags *out_certificate_errors) |
| 1004 |
{ |
| 1005 |
g_return_val_if_fail (E_IS_SOAP_REQUEST (req), FALSE); |
| 1006 |
|
| 1007 |
if (!req->priv->certificate_pem) |
| 1008 |
return FALSE; |
| 1009 |
|
| 1010 |
if (out_certificate_pem) |
| 1011 |
*out_certificate_pem = req->priv->certificate_pem; |
| 1012 |
|
| 1013 |
if (out_certificate_errors) |
| 1014 |
*out_certificate_errors = req->priv->certificate_errors; |
| 1015 |
|
| 1016 |
return TRUE; |
| 1017 |
} |
| 1018 |
|
| 1019 |
void |
| 1020 |
e_soap_request_set_etag (ESoapRequest *req, |
| 1021 |
const gchar *etag) |
| 1022 |
{ |
| 1023 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 1024 |
|
| 1025 |
if (g_strcmp0 (req->priv->etag, etag) != 0) { |
| 1026 |
g_clear_pointer (&req->priv->etag, g_free); |
| 1027 |
req->priv->etag = g_strdup ((etag && *etag) ? etag : NULL); |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
const gchar * |
| 1032 |
e_soap_request_get_etag (ESoapRequest *req) |
| 1033 |
{ |
| 1034 |
g_return_val_if_fail (E_IS_SOAP_REQUEST (req), NULL); |
| 1035 |
|
| 1036 |
return req->priv->etag; |
| 1037 |
} |
| 1038 |
|
| 1039 |
void |
| 1040 |
e_soap_request_set_store_node_data (ESoapRequest *req, |
| 1041 |
const gchar *nodename, |
| 1042 |
const gchar *directory, |
| 1043 |
gboolean base64) |
| 1044 |
{ |
| 1045 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 1046 |
|
| 1047 |
if (g_strcmp0 (req->priv->store_node_data_nodename, nodename) != 0) { |
| 1048 |
g_free (req->priv->store_node_data_nodename); |
| 1049 |
req->priv->store_node_data_nodename = g_strdup (nodename); |
| 1050 |
} |
| 1051 |
|
| 1052 |
if (g_strcmp0 (req->priv->store_node_data_directory, directory) != 0) { |
| 1053 |
g_free (req->priv->store_node_data_directory); |
| 1054 |
req->priv->store_node_data_directory = g_strdup (directory); |
| 1055 |
} |
| 1056 |
|
| 1057 |
req->priv->store_node_data_base64 = base64; |
| 1058 |
} |
| 1059 |
|
| 1060 |
void |
| 1061 |
e_soap_request_get_store_node_data (ESoapRequest *req, |
| 1062 |
const gchar **out_nodename, |
| 1063 |
const gchar **out_directory, |
| 1064 |
gboolean *out_base64) |
| 1065 |
{ |
| 1066 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 1067 |
g_return_if_fail (out_nodename != NULL); |
| 1068 |
g_return_if_fail (out_directory != NULL); |
| 1069 |
g_return_if_fail (out_base64 != NULL); |
| 1070 |
|
| 1071 |
*out_nodename = req->priv->store_node_data_nodename; |
| 1072 |
*out_directory = req->priv->store_node_data_directory; |
| 1073 |
*out_base64 = req->priv->store_node_data_base64; |
| 1074 |
} |
| 1075 |
|
| 1076 |
/** |
| 1077 |
* e_soap_request_persist: |
| 1078 |
* @req: the #ESoapRequest. |
| 1079 |
* @soup_session: an #ESoupSession to create the #SoupMessage for |
| 1080 |
* @settings: a #CamelEwsSettings object, to read User-Agent header information from |
| 1081 |
* @error: (optional) (out): return location for a #GError, or %NULL |
| 1082 |
* |
| 1083 |
* Writes the serialized XML tree to the #SoupMessage's buffer. |
| 1084 |
* |
| 1085 |
* When a custom body was set with e_soap_request_set_custom_body(), then that body |
| 1086 |
* is used instead. |
| 1087 |
* |
| 1088 |
* Returns: (nullable) (transfer full): a #SoupMessage containing the SOAP request |
| 1089 |
* as its request body, or %NULL on error. |
| 1090 |
*/ |
| 1091 |
SoupMessage * |
| 1092 |
e_soap_request_persist (ESoapRequest *req, |
| 1093 |
ESoupSession *soup_session, |
| 1094 |
CamelEwsSettings *settings, |
| 1095 |
GError **error) |
| 1096 |
{ |
| 1097 |
SoupMessage *message; |
| 1098 |
|
| 1099 |
g_return_val_if_fail (E_IS_SOAP_REQUEST (req), NULL); |
| 1100 |
|
| 1101 |
message = e_soup_session_new_message_from_uri (soup_session, req->priv->method, req->priv->uri, error); |
| 1102 |
|
| 1103 |
if (!message) |
| 1104 |
return NULL; |
| 1105 |
|
| 1106 |
if (req->priv->custom_body_content_type) { |
| 1107 |
/* Can use empty string as content_type to indicate no body to be set */ |
| 1108 |
if (*req->priv->custom_body_content_type && req->priv->custom_body_data) { |
| 1109 |
e_soup_session_util_set_message_request_body_from_data (message, TRUE, |
| 1110 |
req->priv->custom_body_content_type, |
| 1111 |
req->priv->custom_body_data, |
| 1112 |
req->priv->custom_body_data_len, NULL); |
| 1113 |
} |
| 1114 |
} else { |
| 1115 |
xmlChar *body; |
| 1116 |
gint len; |
| 1117 |
|
| 1118 |
xmlDocDumpMemory (req->priv->doc, &body, &len); |
| 1119 |
|
| 1120 |
e_soup_session_util_set_message_request_body_from_data (message, FALSE, |
| 1121 |
"text/xml; charset=utf-8", body, len, (GDestroyNotify) xmlFree); |
| 1122 |
} |
| 1123 |
|
| 1124 |
e_ews_connection_utils_set_user_agent_header (message, settings); |
| 1125 |
|
| 1126 |
soup_message_headers_replace (soup_message_get_request_headers (message), "Connection", "Keep-Alive"); |
| 1127 |
|
| 1128 |
if (req->priv->etag && *req->priv->etag) |
| 1129 |
soup_message_headers_replace (soup_message_get_request_headers (message), "If-None-Match", req->priv->etag); |
| 1130 |
|
| 1131 |
return message; |
| 1132 |
} |
| 1133 |
|
| 1134 |
void |
| 1135 |
e_soap_request_setup_response (ESoapRequest *req, |
| 1136 |
ESoapResponse *response) |
| 1137 |
{ |
| 1138 |
g_return_if_fail (E_IS_SOAP_REQUEST (req)); |
| 1139 |
g_return_if_fail (E_IS_SOAP_RESPONSE (response)); |
| 1140 |
|
| 1141 |
e_soap_response_set_progress_fn (response, req->priv->progress_fn, req->priv->progress_data); |
| 1142 |
e_soap_response_set_store_node_data (response, req->priv->store_node_data_nodename, |
| 1143 |
req->priv->store_node_data_directory, req->priv->store_node_data_base64); |
| 1144 |
} |