1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 /* Copyright (C) 2003, 2004 Novell, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 /* Generic WebDAV test program */
32 #include "e2k-context.h"
34 #include "e2k-utils.h"
35 #include "e2k-xml-utils.h"
37 #include "test-utils.h"
40 print_header (gpointer name, gpointer value, gpointer data)
42 gboolean *isxml = data;
44 printf ("%s: %s\n", (char *)name, (char *)value);
45 if (!g_ascii_strcasecmp (name, "Content-Type") &&
46 strstr (value, "/xml"))
50 const char *test_program_name = "davcat";
53 test_main (int argc, char **argv)
58 char buf[1024], *base_uri, *root_uri, *eol, *vers, *p;
59 char *method, *path, *uri;
62 gboolean isxml = FALSE;
65 fprintf (stderr, "usage: %s URI\n", argv[0]);
69 ctx = test_get_context (base_uri);
71 input = g_byte_array_new ();
73 nread = read (STDIN_FILENO, buf, sizeof (buf));
75 g_byte_array_append (input, buf, nread);
76 } while (nread > 0 || (nread == -1 && errno == EINTR));
77 g_byte_array_append (input, "", 1);
80 eol = strchr (method, '\n');
81 p = strchr (method, ' ');
82 if (!eol || !p || p > eol) {
83 fprintf (stderr, "Could not parse request method\n");
91 p = strchr (path, ' ');
100 root_uri = g_strdup (base_uri);
101 p = strstr (root_uri, "://");
103 p = strchr (p + 3, '/');
107 uri = e2k_uri_concat (root_uri, path);
109 msg = e2k_soup_message_new (ctx, uri, method);
111 fprintf (stderr, "Could not create message to %s\n", uri);
117 if (strncmp (vers, "HTTP/1.", 7) != 0 ||
118 (vers[7] != '0' && vers[7] != '1')) {
119 fprintf (stderr, "Could not parse HTTP version\n");
123 soup_message_set_http_version (msg, SOUP_HTTP_1_0);
128 eol = strchr (name, '\n');
129 p = strchr (name, ':');
130 if (!eol || eol == name || !p || p > eol || p[1] != ' ')
137 soup_message_add_header (msg->request_headers, name, value);
147 msg->request.body = e2k_lf_to_crlf (p);
148 msg->request.length = strlen (msg->request.body);
149 msg->request.owner = SOUP_BUFFER_SYSTEM_OWNED;
151 if (!soup_message_get_header (msg->request_headers, "Content-Type")) {
152 soup_message_add_header (msg->request_headers,
153 "Content-Type", "text/xml");
157 e2k_context_send_message (ctx, NULL, msg);
159 printf ("%d %s\n", msg->status_code, msg->reason_phrase);
160 if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
163 soup_message_foreach_header (msg->response_headers,
164 print_header, &isxml);
170 doc = e2k_parse_xml (msg->response.body, msg->response.length);
172 xmlDocFormatDump (stdout, doc, 1);
175 fwrite (msg->response.body, 1, msg->response.length, stdout);
177 fwrite (msg->response.body, 1, msg->response.length, stdout);
180 g_object_unref (msg);
181 g_byte_array_free (input, TRUE);
182 g_object_unref (ctx);