aboutsummaryrefslogtreecommitdiff
path: root/doc/examples/demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/demo.c')
-rw-r--r--doc/examples/demo.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/doc/examples/demo.c b/doc/examples/demo.c
new file mode 100644
index 00000000..5fb43a19
--- /dev/null
+++ b/doc/examples/demo.c
@@ -0,0 +1,66 @@
1
2
3#include <stdio.h>
4#include <stdlib.h>
5
6
7#include "web_server.h"
8
9int PORT=80;
10
11void index_html() {
12 printf("Content-type: text/html\r\n\r\n");
13 printf("<HTML>\n");
14 printf("<BODY bgcolor='EFEFEF'>\n");
15 printf("libwebserver Example<BR><BR>\n");
16 printf("Client info structure:<BR><code>\n");
17 printf("struct ClientInfo {<BR>\n &nbsp;&nbsp;&nbsp;int outfd<BR>\n &nbsp;&nbsp;&nbsp;char *inetname<BR>\n &nbsp;&nbsp;&nbsp;char *request<BR>\n &nbsp;&nbsp;&nbsp;char *method<BR>\n &nbsp;&nbsp;&nbsp;char *user<BR>\n &nbsp;&nbsp;&nbsp;char *pass<BR>\n &nbsp;&nbsp;&nbsp;char *QueryData;<BR>\n &nbsp;&nbsp;&nbsp;struct memrequest *mem;<BR>\n &nbsp;&nbsp;&nbsp;char *(*Header)(char*);<BR>\n &nbsp;&nbsp;&nbsp;char *(*QueryString)(char*);<BR>\n &nbsp;&nbsp;&nbsp;char *(*Post)(char*);<BR>\n &nbsp;&nbsp;&nbsp;char *(*MultiPart)(char*);<BR>\n };<BR>\n");
18 printf("ClientInfo->outfd=%d<BR>\n",ClientInfo->outfd);
19 printf("ClientInfo->request=%s<BR>\n",ClientInfo->request);
20 printf("ClientInfo->method=%s<BR>\n",ClientInfo->method);
21 printf("ClientInfo->Header(\"Host\")=\"%s\"<BR>\n",ClientInfo->Header("Host"));
22 printf("ClientInfo->Header(\"Accept\")=\"%s\"<BR>\n",ClientInfo->Header("Accept"));
23 printf("ClientInfo->Query(\"teste\")=\"%s\"<BR>\n",ClientInfo->Query("teste"));
24 printf("ClientInfo->Query(NULL)=\"%s\"<BR>\n",ClientInfo->Query(NULL));
25 printf("ClientInfo->Post(\"dev\")=\"%s\"<BR>\n",ClientInfo->Post("dev"));
26 printf("ClientInfo->MultiPart(\"teste\").data=\"%s\"<BR>\n",ClientInfo->MultiPart("teste").data);
27 printf("ClientInfo->MultiPart(\"file1\").filename=\"%s\"<BR>\n",ClientInfo->MultiPart("file1").filename);
28 printf("ClientInfo->MultiPart(\"file1\").size=\"%d\"<BR>\n",ClientInfo->MultiPart("file1").size);
29 printf("ClientInfo->MultiPart(\"file1\").data=\"");
30 fwrite(ClientInfo->MultiPart("file1").data,ClientInfo->MultiPart("file1").size,1,stdout);
31 printf("\"<BR>\n");
32 printf("<form action='/?teste=done' method='post' enctype='multipart/form-data'>\n");
33 printf("<input type=file name='file1'><BR>\n");
34 printf("<input type=hidden name='dev' value='Luis Figueiredo'>\n");
35 printf("<input type=text name='teste'>\n");
36 printf("<input type=submit name='GOO' value='send'>\n");
37 printf("</form>\n");
38 printf("Stats:<BR>\n");
39 printf("<a href='http://libwebserver.sourceforge.net'><img border='0' src='/libwebserver.gif'></a><br>\n");
40 printf("</BODY>\n");
41 printf("</HTML>\n");
42};
43
44void logfile() {
45 FILE *log;
46 printf("Content-type: text/plain \r\n\r\n");
47 web_client_addfile("./demo.log");
48 printf("Fim do log\n");
49};
50
51int main() {
52 int pid;
53 struct web_server server;
54 while(!web_server_init(&server,PORT,"demo.log",0)) {
55 PORT++;
56 };
57 printf("http://localhost:%d\n",PORT);
58 web_server_addhandler(&server,"* /",index_html,0);
59 web_server_addhandler(&server,"* /log",logfile,0);
60 while(1) {
61 // DO whatever u want
62 web_server_run(&server); // Process web_server
63 };
64 return 0;
65
66};