Commit 4b5bcf89c0cc1ba8f06cbae39a266bdd8bb29dac

Authored by Georg Hopp
1 parent 1fdcbd40

a taste of ajax

@@ -43,7 +43,8 @@ HttpResponse httpResponse304( @@ -43,7 +43,8 @@ HttpResponse httpResponse304(
43 const char *, size_t, 43 const char *, size_t,
44 const char *, size_t); 44 const char *, size_t);
45 HttpResponse httpResponse404(); 45 HttpResponse httpResponse404();
46 -HttpResponse httpResponseMe(int); 46 +HttpResponse httpResponseMe();
  47 +HttpResponse httpResponseRandval(int);
47 HttpResponse httpResponseAsset( 48 HttpResponse httpResponseAsset(
48 const char *, 49 const char *,
49 const char *, size_t, 50 const char *, size_t,
@@ -27,7 +27,8 @@ RESP = http/response.c \ @@ -27,7 +27,8 @@ RESP = http/response.c \
27 http/response/304.c \ 27 http/response/304.c \
28 http/response/404.c \ 28 http/response/404.c \
29 http/response/asset.c \ 29 http/response/asset.c \
30 - http/response/me.c 30 + http/response/me.c \
  31 + http/response/randval.c
31 PARSER = http/parser.c \ 32 PARSER = http/parser.c \
32 http/parser/parse.c \ 33 http/parser/parse.c \
33 http/parser/new_message.c \ 34 http/parser/new_message.c \
@@ -39,27 +39,47 @@ @@ -39,27 +39,47 @@
39 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \ 39 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \
40 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" \ 40 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" \
41 "<head>" \ 41 "<head>" \
42 - "<title>200 - OK</title>" \ 42 + "<title>My own little Web-App</title>" \
  43 + "<style type=\"text/css\">" \
  44 + "div#randval {" \
  45 + "width: 120px;" \
  46 + "height: 30px;" \
  47 + "left: 200px;" \
  48 + "top: 100px;" \
  49 + "position: fixed;" \
  50 + "overflow: none;" \
  51 + "background-color: white;" \
  52 + "border: 1px solid black;" \
  53 + "}" \
  54 + "div.hide#randval {" \
  55 + "top: -50px;" \
  56 + "}" \
  57 + "</style>" \
43 "<script type=\"text/javascript\" src=\"/jquery/\"></script>" \ 58 "<script type=\"text/javascript\" src=\"/jquery/\"></script>" \
44 "<script>" \ 59 "<script>" \
45 "$(document).ready(function() {" \ 60 "$(document).ready(function() {" \
46 "$(\"a\").click(function() {" \ 61 "$(\"a\").click(function() {" \
47 - "alert(\"Hello world!\");" \ 62 + "$(\"#randval\").load(\"/randval/\");" \
  63 + "$(\"#randval\").removeClass(\"hide\");" \
  64 + "});" \
  65 + "$(\"#randval\").click(function() {" \
  66 + "$(\"#randval\").addClass(\"hide\");" \
48 "});" \ 67 "});" \
49 "});" \ 68 "});" \
50 "</script>" \ 69 "</script>" \
51 "</head>" \ 70 "</head>" \
52 "<body>" \ 71 "<body>" \
53 - "<h1>Testpage</h1>" \  
54 - "<img src=\"/image/\" />" \  
55 - "<hr />%02d" \  
56 - "<hr /><a href=\"#\">Link</a>" \ 72 + "<div id=\"randval\" class=\"hide\"></div>" \
  73 + "<div id=\"main\">" \
  74 + "<h1>Testpage</h1>" \
  75 + "<img src=\"/image/\" />" \
  76 + "<hr /><a href=\"#\">Link</a>" \
  77 + "</div>" \
57 "</body>" \ 78 "</body>" \
58 "</html>" 79 "</html>"
59 80
60 -  
61 HttpResponse 81 HttpResponse
62 -httpResponseMe(int value) 82 +httpResponseMe()
63 { 83 {
64 char buffer[200]; 84 char buffer[200];
65 HttpResponse response; 85 HttpResponse response;
@@ -89,9 +109,9 @@ httpResponseMe(int value) @@ -89,9 +109,9 @@ httpResponseMe(int value)
89 sizeof("profession=\"coder\"")-1)); 109 sizeof("profession=\"coder\"")-1));
90 110
91 message->type = HTTP_MESSAGE_BUFFERED; 111 message->type = HTTP_MESSAGE_BUFFERED;
92 - message->nbody = sizeof(RESP_DATA)-1-2;  
93 - message->body = malloc(sizeof(RESP_DATA)-2);  
94 - sprintf(message->body, RESP_DATA, value); 112 + message->nbody = sizeof(RESP_DATA)-1;
  113 + message->body = malloc(sizeof(RESP_DATA)-1);
  114 + memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1);
95 115
96 nbuf = sprintf(buffer, "%d", message->nbody); 116 nbuf = sprintf(buffer, "%d", message->nbody);
97 117
@@ -55,7 +55,11 @@ httpWorkerProcess(HttpWorker this, int fd) @@ -55,7 +55,11 @@ httpWorkerProcess(HttpWorker this, int fd)
55 if (0 == strcmp("GET", request->method)) { 55 if (0 == strcmp("GET", request->method)) {
56 56
57 if (0 == strcmp("/me/", request->uri)) { 57 if (0 == strcmp("/me/", request->uri)) {
58 - response = (HttpMessage)httpResponseMe(*(this->val)); 58 + response = (HttpMessage)httpResponseMe();
  59 + }
  60 +
  61 + if (0 == strcmp("/randval/", request->uri)) {
  62 + response = (HttpMessage)httpResponseRandval(*(this->val));
59 } 63 }
60 64
61 if (0 == strcmp("/image/", request->uri)) { 65 if (0 == strcmp("/image/", request->uri)) {
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 #include "interface/logger.h" 24 #include "interface/logger.h"
25 #include "interface/stream_writer.h" 25 #include "interface/stream_writer.h"
26 26
27 -void serverCloseConn(Server, unsigned int); 27 +void serverCloseConn(Server, unsigned int);
28 28
29 ssize_t 29 ssize_t
30 serverWrite(Server this, unsigned int i) 30 serverWrite(Server this, unsigned int i)
@@ -36,7 +36,7 @@ serverWrite(Server this, unsigned int i) @@ -36,7 +36,7 @@ serverWrite(Server this, unsigned int i)
36 loggerLog( 36 loggerLog(
37 this->logger, 37 this->logger,
38 LOGGER_INFO, 38 LOGGER_INFO,
39 - "initialization error: NULL reader"); 39 + "initialization error: NULL worker");
40 return -1; 40 return -1;
41 } 41 }
42 42
Please register or login to post a comment