1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * JP Rosevear <jpr@ximian.com>
5 * Rodrigo Moya <rodrigo@ximian.com>
7 * Copyright 2003, Novell, Inc.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU Lesser General Public
11 * License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
26 #include <libsoup/soup-uri.h>
27 #include "e-gw-message.h"
30 print_header (gpointer name, gpointer value, gpointer data)
32 g_print ("%s: %s\n", (char *) name, (char *) value);
36 debug_handler (SoupMessage *msg, gpointer user_data)
38 g_print ("%d %s\nSOAP-Debug: %p @ %lu\n",
39 msg->status_code, msg->reason_phrase,
43 soup_message_foreach_header (msg->response_headers, print_header, NULL);
46 if (msg->response.length) {
48 fwrite (msg->response.body, 1, msg->response.length, stdout);
54 setup_debug (SoupSoapMessage *msg)
58 suri = soup_message_get_uri (SOUP_MESSAGE (msg));
59 g_print ("%s %s%s%s HTTP/1.1\nSOAP-Debug: %p @ %lu\n",
60 SOUP_MESSAGE (msg)->method, suri->path,
61 suri->query ? "?" : "",
62 suri->query ? suri->query : "",
63 msg, (unsigned long) time (NULL));
65 /* print message headers */
66 print_header ("Host", suri->host, NULL);
67 soup_message_foreach_header (SOUP_MESSAGE (msg)->request_headers, print_header, NULL);
69 soup_message_add_handler (SOUP_MESSAGE (msg), SOUP_HANDLER_POST_BODY, debug_handler, NULL);
73 e_gw_message_new_with_header (const char *uri, const char *session_id, const char *method_name)
77 msg = soup_soap_message_new (SOUP_METHOD_POST, uri, FALSE, NULL, NULL, NULL);
79 g_warning (G_STRLOC ": Could not build SOAP message");
83 soup_message_add_header (SOUP_MESSAGE (msg)->request_headers, "Content-Type", "text/xml");
84 soup_message_add_header (SOUP_MESSAGE (msg)->request_headers, "User-Agent",
85 "Evolution/" VERSION);
86 soup_message_add_header (SOUP_MESSAGE (msg)->request_headers,"Connection", "Keep-Alive");
87 soup_message_add_header (SOUP_MESSAGE (msg)->request_headers, "SOAPAction", method_name);
89 if (g_getenv ("GROUPWISE_DEBUG")) {
90 if (atoi (g_getenv ("GROUPWISE_DEBUG")) == 1)
94 soup_soap_message_start_envelope (msg);
95 if (session_id && *session_id) {
96 soup_soap_message_start_element (msg, "Header","SOAP-ENV", NULL);
97 soup_soap_message_add_attribute (msg, "encodingStyle", "", "SOAP-ENV", NULL);
98 /* FIXME: cannot use e_gw_message_write_string_parameter as it sets prefix -types*/
99 soup_soap_message_start_element (msg, "session", NULL, NULL);
100 soup_soap_message_write_string (msg, session_id);
101 soup_soap_message_end_element (msg);
102 soup_soap_message_end_element (msg);
104 soup_soap_message_start_body (msg);
105 soup_soap_message_add_attribute (msg, "encodingStyle", "", "SOAP-ENV", NULL);
106 soup_soap_message_add_namespace (msg, "types", "http://schemas.novell.com/2003/10/NCSP/types.xsd");
108 soup_soap_message_start_element (msg, method_name, NULL, NULL);
114 e_gw_message_write_string_parameter (SoupSoapMessage *msg, const char *name, const char *prefix, const char *value)
116 soup_soap_message_start_element (msg, name, prefix, NULL);
117 soup_soap_message_write_string (msg, value);
118 soup_soap_message_end_element (msg);
122 e_gw_message_write_string_parameter_with_attribute (SoupSoapMessage *msg,
126 const char *attribute_name,
127 const char *attribute_value)
129 soup_soap_message_start_element (msg, name, prefix, NULL);
130 soup_soap_message_add_attribute (msg, attribute_name, attribute_value, NULL, NULL);
131 soup_soap_message_write_string (msg, value);
132 soup_soap_message_end_element (msg);
136 e_gw_message_write_base64_parameter (SoupSoapMessage *msg, const char *name, const char *prefix, const char *value)
138 soup_soap_message_start_element (msg, name, prefix, NULL);
139 soup_soap_message_write_base64 (msg, value, strlen (value));
140 soup_soap_message_end_element (msg);
144 e_gw_message_write_int_parameter (SoupSoapMessage *msg, const char *name, const char *prefix, long value)
146 soup_soap_message_start_element (msg, name, prefix, NULL);
147 soup_soap_message_write_int (msg, value);
148 soup_soap_message_end_element (msg);
152 e_gw_message_write_footer (SoupSoapMessage *msg)
154 soup_soap_message_end_element (msg);
155 soup_soap_message_end_body (msg);
156 soup_soap_message_end_envelope (msg);
158 soup_soap_message_persist (msg);
160 if (g_getenv ("GROUPWISE_DEBUG") && (atoi (g_getenv ("GROUPWISE_DEBUG")) == 1)) {
161 const char *header = soup_message_get_header (SOUP_MESSAGE (msg)->request_headers, "SOAPAction");
162 if (header && g_str_equal (header, "loginRequest")) {
167 body = g_strndup (SOUP_MESSAGE (msg)->request.body, SOUP_MESSAGE (msg)->request.length);
168 begin = g_strrstr (body, "<types:password>");
170 begin = begin + strlen ("<types:password>");
171 end = g_strrstr (body , "</types:password>");
174 for (tmp = begin; tmp < end; tmp++)
178 fputc ('\n', stdout);
179 fwrite (body, 1, SOUP_MESSAGE (msg)->request.length, stdout);
180 fputc ('\n', stdout);
185 /* print request's body */
186 fputc ('\n', stdout);
187 fwrite (SOUP_MESSAGE (msg)->request.body, 1, SOUP_MESSAGE (msg)->request.length, stdout);
188 fputc ('\n', stdout);