1 /* More complex example shared object script showing parameter parsing.
2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: show_params.c,v 1.4 2002/12/01 16:16:04 rich Exp $
25 #include "rws_request.h"
28 handle_request (rws_request rq)
30 pool pool = pth_get_pool (current_pth);
31 http_request http_request = rws_request_http_request (rq);
32 io_handle io = rws_request_io (rq);
36 http_response http_response;
37 vector headers, params;
38 struct http_header header;
39 const char *name, *value;
41 /* Parse CGI parameters. */
42 cgi = new_cgi (pool, http_request, io);
45 http_response = new_http_response (pool, http_request, io,
47 http_response_send_headers (http_response,
49 "Content-Type", "text/plain",
52 close = http_response_end_headers (http_response);
54 if (http_request_is_HEAD (http_request)) return close;
56 io_fprintf (io, "This is the show_params shared object script.\r\n\r\n");
57 io_fprintf (io, "Your browser sent the following headers:\r\n\r\n");
59 headers = http_request_get_headers (http_request);
60 for (i = 0; i < vector_size (headers); ++i)
62 vector_get (headers, i, header);
63 io_fprintf (io, "\t%s: %s\r\n", header.key, header.value);
66 io_fprintf (io, "----- end of headers -----\r\n");
68 io_fprintf (io, "The URL was: %s\r\n",
69 http_request_get_url (http_request));
70 io_fprintf (io, "The path component was: %s\r\n",
71 http_request_path (http_request));
72 io_fprintf (io, "The query string was: %s\r\n",
73 http_request_query_string (http_request));
74 io_fprintf (io, "The query arguments were:\r\n");
76 params = cgi_params (cgi);
77 for (i = 0; i < vector_size (params); ++i)
79 vector_get (params, i, name);
80 value = cgi_param (cgi, name);
81 io_fprintf (io, "\t%s=%s\r\n", name, value);
84 io_fprintf (io, "----- end of parameters -----\r\n");