aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-01-23 05:48:21 +0000
committerChristian Grothoff <christian@grothoff.org>2007-01-23 05:48:21 +0000
commita84f9bc7b3896a197a1e4c41a5311d6b52928034 (patch)
tree733d15c414ae09063f074976167400b84b29c54a
parent2d299ede39408b4f4b1f5c817d5df28f1f37a21b (diff)
downloadlibmicrohttpd-a84f9bc7b3896a197a1e4c41a5311d6b52928034.tar.gz
libmicrohttpd-a84f9bc7b3896a197a1e4c41a5311d6b52928034.zip
expanded testcases
-rw-r--r--INSTALL69
-rw-r--r--doc/Makefile.am1
-rw-r--r--src/daemon/daemon.c237
-rw-r--r--src/daemon/daemontest.c148
4 files changed, 421 insertions, 34 deletions
diff --git a/INSTALL b/INSTALL
index 54caf7c1..23e5f25d 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,13 +1,16 @@
1Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software 1Installation Instructions
2Foundation, Inc. 2*************************
3 3
4 This file is free documentation; the Free Software Foundation gives 4Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
5Software Foundation, Inc.
6
7This file is free documentation; the Free Software Foundation gives
5unlimited permission to copy, distribute and modify it. 8unlimited permission to copy, distribute and modify it.
6 9
7Basic Installation 10Basic Installation
8================== 11==================
9 12
10 These are generic installation instructions. 13These are generic installation instructions.
11 14
12 The `configure' shell script attempts to guess correct values for 15 The `configure' shell script attempts to guess correct values for
13various system-dependent variables used during compilation. It uses 16various system-dependent variables used during compilation. It uses
@@ -67,9 +70,9 @@ The simplest way to compile this package is:
67Compilers and Options 70Compilers and Options
68===================== 71=====================
69 72
70 Some systems require unusual options for compilation or linking that 73Some systems require unusual options for compilation or linking that the
71the `configure' script does not know about. Run `./configure --help' 74`configure' script does not know about. Run `./configure --help' for
72for details on some of the pertinent environment variables. 75details on some of the pertinent environment variables.
73 76
74 You can give `configure' initial values for configuration parameters 77 You can give `configure' initial values for configuration parameters
75by setting variables in the command line or in the environment. Here 78by setting variables in the command line or in the environment. Here
@@ -82,7 +85,7 @@ is an example:
82Compiling For Multiple Architectures 85Compiling For Multiple Architectures
83==================================== 86====================================
84 87
85 You can compile the package for more than one kind of computer at the 88You can compile the package for more than one kind of computer at the
86same time, by placing the object files for each architecture in their 89same time, by placing the object files for each architecture in their
87own directory. To do this, you must use a version of `make' that 90own directory. To do this, you must use a version of `make' that
88supports the `VPATH' variable, such as GNU `make'. `cd' to the 91supports the `VPATH' variable, such as GNU `make'. `cd' to the
@@ -99,19 +102,19 @@ for another architecture.
99Installation Names 102Installation Names
100================== 103==================
101 104
102 By default, `make install' will install the package's files in 105By default, `make install' installs the package's commands under
103`/usr/local/bin', `/usr/local/man', etc. You can specify an 106`/usr/local/bin', include files under `/usr/local/include', etc. You
104installation prefix other than `/usr/local' by giving `configure' the 107can specify an installation prefix other than `/usr/local' by giving
105option `--prefix=PATH'. 108`configure' the option `--prefix=PREFIX'.
106 109
107 You can specify separate installation prefixes for 110 You can specify separate installation prefixes for
108architecture-specific files and architecture-independent files. If you 111architecture-specific files and architecture-independent files. If you
109give `configure' the option `--exec-prefix=PATH', the package will use 112pass the option `--exec-prefix=PREFIX' to `configure', the package uses
110PATH as the prefix for installing programs and libraries. 113PREFIX as the prefix for installing programs and libraries.
111Documentation and other data files will still use the regular prefix. 114Documentation and other data files still use the regular prefix.
112 115
113 In addition, if you use an unusual directory layout you can give 116 In addition, if you use an unusual directory layout you can give
114options like `--bindir=PATH' to specify different values for particular 117options like `--bindir=DIR' to specify different values for particular
115kinds of files. Run `configure --help' for a list of the directories 118kinds of files. Run `configure --help' for a list of the directories
116you can set and what kinds of files go in them. 119you can set and what kinds of files go in them.
117 120
@@ -122,7 +125,7 @@ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
122Optional Features 125Optional Features
123================= 126=================
124 127
125 Some packages pay attention to `--enable-FEATURE' options to 128Some packages pay attention to `--enable-FEATURE' options to
126`configure', where FEATURE indicates an optional part of the package. 129`configure', where FEATURE indicates an optional part of the package.
127They may also pay attention to `--with-PACKAGE' options, where PACKAGE 130They may also pay attention to `--with-PACKAGE' options, where PACKAGE
128is something like `gnu-as' or `x' (for the X Window System). The 131is something like `gnu-as' or `x' (for the X Window System). The
@@ -137,11 +140,11 @@ you can use the `configure' options `--x-includes=DIR' and
137Specifying the System Type 140Specifying the System Type
138========================== 141==========================
139 142
140 There may be some features `configure' cannot figure out 143There may be some features `configure' cannot figure out automatically,
141automatically, but needs to determine by the type of machine the package 144but needs to determine by the type of machine the package will run on.
142will run on. Usually, assuming the package is built to be run on the 145Usually, assuming the package is built to be run on the _same_
143_same_ architectures, `configure' can figure that out, but if it prints 146architectures, `configure' can figure that out, but if it prints a
144a message saying it cannot guess the machine type, give it the 147message saying it cannot guess the machine type, give it the
145`--build=TYPE' option. TYPE can either be a short name for the system 148`--build=TYPE' option. TYPE can either be a short name for the system
146type, such as `sun4', or a canonical name which has the form: 149type, such as `sun4', or a canonical name which has the form:
147 150
@@ -156,7 +159,7 @@ where SYSTEM can have one of these forms:
156need to know the machine type. 159need to know the machine type.
157 160
158 If you are _building_ compiler tools for cross-compiling, you should 161 If you are _building_ compiler tools for cross-compiling, you should
159use the `--target=TYPE' option to select the type of system they will 162use the option `--target=TYPE' to select the type of system they will
160produce code for. 163produce code for.
161 164
162 If you want to _use_ a cross compiler, that generates code for a 165 If you want to _use_ a cross compiler, that generates code for a
@@ -167,9 +170,9 @@ eventually be run) with `--host=TYPE'.
167Sharing Defaults 170Sharing Defaults
168================ 171================
169 172
170 If you want to set default values for `configure' scripts to share, 173If you want to set default values for `configure' scripts to share, you
171you can create a site shell script called `config.site' that gives 174can create a site shell script called `config.site' that gives default
172default values for variables like `CC', `cache_file', and `prefix'. 175values for variables like `CC', `cache_file', and `prefix'.
173`configure' looks for `PREFIX/share/config.site' if it exists, then 176`configure' looks for `PREFIX/share/config.site' if it exists, then
174`PREFIX/etc/config.site' if it exists. Or, you can set the 177`PREFIX/etc/config.site' if it exists. Or, you can set the
175`CONFIG_SITE' environment variable to the location of the site script. 178`CONFIG_SITE' environment variable to the location of the site script.
@@ -178,7 +181,7 @@ A warning: not all `configure' scripts look for a site script.
178Defining Variables 181Defining Variables
179================== 182==================
180 183
181 Variables not defined in a site shell script can be set in the 184Variables not defined in a site shell script can be set in the
182environment passed to `configure'. However, some packages may run 185environment passed to `configure'. However, some packages may run
183configure again during the build, and the customized values of these 186configure again during the build, and the customized values of these
184variables may be lost. In order to avoid this problem, you should set 187variables may be lost. In order to avoid this problem, you should set
@@ -186,14 +189,18 @@ them in the `configure' command line, using `VAR=value'. For example:
186 189
187 ./configure CC=/usr/local2/bin/gcc 190 ./configure CC=/usr/local2/bin/gcc
188 191
189will cause the specified gcc to be used as the C compiler (unless it is 192causes the specified `gcc' to be used as the C compiler (unless it is
190overridden in the site shell script). 193overridden in the site shell script). Here is a another example:
194
195 /bin/bash ./configure CONFIG_SHELL=/bin/bash
196
197Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
198configuration-related scripts to be executed by `/bin/bash'.
191 199
192`configure' Invocation 200`configure' Invocation
193====================== 201======================
194 202
195 `configure' recognizes the following options to control how it 203`configure' recognizes the following options to control how it operates.
196operates.
197 204
198`--help' 205`--help'
199`-h' 206`-h'
diff --git a/doc/Makefile.am b/doc/Makefile.am
index dcd0d6e1..0ff49d25 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,2 +1,3 @@
1
1man_MANS = libmicrohttpd.3 2man_MANS = libmicrohttpd.3
2EXTRA_DIST = $(man_MANS) 3EXTRA_DIST = $(man_MANS)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f70ca34d..e8101a23 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -27,3 +27,240 @@
27#include "config.h" 27#include "config.h"
28#include "microhttpd.h" 28#include "microhttpd.h"
29 29
30
31/**
32 * Start a webserver on the given port.
33 * @param port port to bind to
34 * @param apc callback to call to check which clients
35 * will be allowed to connect
36 * @param apc_cls extra argument to apc
37 * @param dh default handler for all URIs
38 * @param dh_cls extra argument to dh
39 * @return NULL on error, handle to daemon on success
40 */
41struct MHD_Daemon *
42MHD_start_daemon(unsigned int options,
43 unsigned short port,
44 MHD_AcceptPolicyCallback apc,
45 void * apc_cls,
46 MHD_AccessHandlerCallback dh,
47 void * dh_cls) {
48 return NULL;
49}
50
51
52
53/**
54 * Shutdown an http daemon.
55 */
56void
57MHD_stop_daemon(struct MHD_Daemon * daemon) {
58}
59
60/**
61 * Obtain the select sets for this daemon.
62 *
63 * @return MHD_YES on success, MHD_NO if this
64 * daemon was not started with the right
65 * options for this call.
66 */
67int
68MHD_get_fdset(struct MHD_Daemon * daemon,
69 fd_set * read_fd_set,
70 fd_set * write_fd_set,
71 fd_set * except_fd_set,
72 int * max_fd) {
73 return 0;
74}
75
76/**
77 * Run webserver operations (without blocking unless
78 * in client callbacks). This method should be called
79 * by clients in combination with MHD_get_fdset
80 * if the client-controlled select method is used.
81 *
82 * @return MHD_YES on success, MHD_NO if this
83 * daemon was not started with the right
84 * options for this call.
85 */
86int
87MHD_run(struct MHD_Daemon * daemon) {
88 return 0;
89}
90
91
92/**
93 * Register an access handler for all URIs beginning with uri_prefix.
94 *
95 * @param uri_prefix
96 * @return MRI_NO if a handler for this exact prefix
97 * already exists
98 */
99int
100MHD_register_handler(struct MHD_Daemon * daemon,
101 const char * uri_prefix,
102 MHD_AccessHandlerCallback dh,
103 void * dh_cls) {
104 return 0;
105}
106
107/**
108 * Unregister an access handler for the URIs beginning with
109 * uri_prefix.
110 *
111 * @param uri_prefix
112 * @return MHD_NO if a handler for this exact prefix
113 * is not known for this daemon
114 */
115int
116MHD_unregister_handler(struct MHD_Daemon * daemon,
117 const char * uri_prefix,
118 MHD_AccessHandlerCallback dh,
119 void * dh_cls) {
120 return 0;
121}
122
123/**
124 * Get all of the headers from the request.
125 *
126 * @param iterator callback to call on each header;
127 * maybe NULL (then just count headers)
128 * @param iterator_cls extra argument to iterator
129 * @return number of entries iterated over
130 */
131int
132MHD_get_session_values(struct MHD_Session * session,
133 enum MHD_ValueKind kind,
134 MHD_KeyValueIterator * iterator,
135 void * iterator_cls);
136
137/**
138 * Get a particular header value. If multiple
139 * values match the kind, return any one of them.
140 *
141 * @param key the header to look for
142 * @return NULL if no such item was found
143 */
144const char *
145MHD_lookup_session_value(struct MHD_Session * session,
146 enum MHD_ValueKind kind,
147 const char * key) {
148 return NULL;
149}
150
151/**
152 * Queue a response to be transmitted to the client (as soon as
153 * possible).
154 *
155 * @param session the session identifying the client
156 * @param status_code HTTP status code (i.e. 200 for OK)
157 * @param response response to transmit
158 * @return MHD_NO on error (i.e. reply already sent),
159 * MHD_YES on success or if message has been queued
160 */
161int
162MHD_queue_response(struct MHD_Session * session,
163 unsigned int status_code,
164 struct MHD_Response * response) {
165 return 0;
166}
167
168
169/**
170 * Create a response object. The response object can be extended with
171 * header information and then be used any number of times.
172 *
173 * @param size size of the data portion of the response, -1 for unknown
174 * @param crc callback to use to obtain response data
175 * @param crc_cls extra argument to crc
176 * @param crfc callback to call to free crc_cls resources
177 * @return NULL on error (i.e. invalid arguments, out of memory)
178 */
179struct MHD_Response *
180MHD_create_response_from_callback(size_t size,
181 MHD_ContentReaderCallback crc,
182 void * crc_cls,
183 MHD_ContentReaderFreeCallback crfc) {
184 return NULL;
185}
186
187/**
188 * Create a response object. The response object can be extended with
189 * header information and then be used any number of times.
190 *
191 * @param size size of the data portion of the response
192 * @param data the data itself
193 * @param must_free libmicrohttpd should free data when done
194 * @param must_copy libmicrohttpd must make a copy of data
195 * right away, the data maybe released anytime after
196 * this call returns
197 * @return NULL on error (i.e. invalid arguments, out of memory)
198 */
199struct MHD_Response *
200MHD_create_response_from_data(size_t size,
201 void * data,
202 int must_free,
203 int must_copy) {
204 return NULL;
205}
206
207/**
208 * Destroy a response object and associated resources. Note that
209 * libmicrohttpd may keep some of the resources around if the response
210 * is still in the queue for some clients, so the memory may not
211 * necessarily be freed immediatley.
212 */
213void
214MHD_destroy_response(struct MHD_Response * response) {
215}
216
217/**
218 * Add a header line to the response.
219 *
220 * @return MHD_NO on error (i.e. invalid header or content format).
221 */
222int
223MHD_add_response_header(struct MHD_Response * response,
224 const char * header,
225 const char * content) {
226 return 0;
227}
228
229/**
230 * Delete a header line from the response.
231 *
232 * @return MHD_NO on error (no such header known)
233 */
234int
235MHD_del_response_header(struct MHD_Response * response,
236 const char * header,
237 const char * content) {
238 return 0;
239}
240
241/**
242 * Get all of the headers added to a response.
243 *
244 * @param iterator callback to call on each header;
245 * maybe NULL (then just count headers)
246 * @param iterator_cls extra argument to iterator
247 * @return number of entries iterated over
248 */
249int
250MHD_get_response_headers(struct MHD_Response * response,
251 MHD_KeyValueIterator * iterator,
252 void * iterator_cls) {
253 return -1;
254}
255
256/**
257 * @return -1 if no data uploaded; otherwise number of bytes
258 * read into buf; 0 for end of transmission
259 */
260int
261MHD_read_file_upload(struct MHD_Session * session,
262 void * buf,
263 size_t len) {
264 return -1;
265}
266
diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c
index 1b36e64f..5ebe1e24 100644
--- a/src/daemon/daemontest.c
+++ b/src/daemon/daemontest.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 YOUR NAME HERE 3 (C) 2007 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,14 +21,156 @@
21/** 21/**
22 * @file daemontest.c 22 * @file daemontest.c
23 * @brief Testcase for libmicrohttpd 23 * @brief Testcase for libmicrohttpd
24 * @author FIXME 24 * @author Christian Grothoff
25 */ 25 */
26 26
27#include "config.h" 27#include "config.h"
28#include "curl/curl.h"
28#include "microhttpd.h" 29#include "microhttpd.h"
30#include <stdlib.h>
31#include <unistd.h>
32#include <string.h>
29 33
34static int testStartError() {
35 return NULL != MHD_start_daemon(0, 0, NULL, NULL, NULL, NULL);
36}
37
38static int apc_nothing(void * cls,
39 const struct sockaddr * addr,
40 socklen_t addrlen) {
41 return MHD_NO;
42}
43
44static int apc_all(void * cls,
45 const struct sockaddr * addr,
46 socklen_t addrlen) {
47 return MHD_YES;
48}
49
50static int ahc_nothing(void * cls,
51 struct MHD_Session * session,
52 const char * url,
53 const char * method) {
54 return MHD_NO;
55}
56
57struct CBC {
58 char * buf;
59 size_t pos;
60 size_t size;
61};
62
63static size_t copyBuffer(void * ptr,
64 size_t size,
65 size_t nmemb,
66 void * ctx) {
67 struct CBC * cbc = ctx;
68
69 if (cbc->pos + size * nmemb > cbc->size)
70 return 0; /* overflow */
71 memcpy(&cbc->buf[cbc->pos],
72 ptr,
73 size * nmemb);
74 cbc->pos += size * nmemb;
75 return size * nmemb;
76}
77
78static int ahc_echo(void * cls,
79 struct MHD_Session * session,
80 const char * url,
81 const char * method) {
82 const char * me = cls;
83 struct MHD_Response * response;
84 int ret;
85
86 if (0 != strcmp(me, method))
87 return MHD_NO; /* unexpected method */
88 response = MHD_create_response_from_data(strlen(url),
89 (void*) url,
90 MHD_NO,
91 MHD_YES);
92 ret = MHD_queue_response(session,
93 MHD_HTTP_OK,
94 response);
95 MHD_destroy_response(response);
96 return ret;
97}
98
99static int testStartStop() {
100 struct MHD_Daemon * d;
101
102 d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv4,
103 1080,
104 &apc_nothing,
105 NULL,
106 &ahc_nothing,
107 NULL);
108 if (d == NULL)
109 return 1;
110 MHD_stop_daemon(d);
111 return 0;
112}
113
114static int testGet() {
115 struct MHD_Daemon * d;
116 CURL * c;
117 int ret;
118 char buf[2048];
119 struct CBC cbc;
120
121 cbc.buf = buf;
122 cbc.size = 2048;
123 cbc.pos = 0;
124 ret = 0;
125 d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv4,
126 1080,
127 &apc_all,
128 NULL,
129 &ahc_echo,
130 "GET");
131 if (d == NULL)
132 return 1;
133 c = curl_easy_init();
134 curl_easy_setopt(c,
135 CURLOPT_URL,
136 "http://localhost:1080/hello_world");
137 curl_easy_setopt(c,
138 CURLOPT_WRITEFUNCTION,
139 &copyBuffer);
140 curl_easy_setopt(c,
141 CURLOPT_WRITEDATA,
142 &cbc);
143 curl_easy_setopt(c,
144 CURLOPT_FAILONERROR,
145 1);
146 curl_easy_setopt(c,
147 CURLOPT_CONNECTTIMEOUT,
148 15L);
149 /* NOTE: use of CONNECTTIMEOUT without also
150 setting NOSIGNAL results in really weird
151 crashes on my system! */
152 curl_easy_setopt(c,
153 CURLOPT_NOSIGNAL,
154 1);
155 if (CURLE_OK != curl_easy_perform(c))
156 ret = 1;
157 curl_easy_cleanup(c);
158 if (cbc.pos != strlen("hello_world"))
159 ret = 2;
160 if (0 != strncmp("hello_world",
161 cbc.buf,
162 strlen("hello_world")))
163 ret = 3;
164 MHD_stop_daemon(d);
165 return ret;
166}
30 167
31int main(int argc, 168int main(int argc,
32 char * const * argv) { 169 char * const * argv) {
33 return 0; /* 0 == pass */ 170 unsigned int errorCount = 0;
171
172 errorCount += testStartError();
173 errorCount += testStartStop();
174 errorCount += testGet();
175 return errorCount != 0; /* 0 == pass */
34} 176}