From 69cfdd07ccec299efc3944377f4d62e2ef472458 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Sun, 11 Mar 2012 21:19:26 +0100 Subject: [PATCH] moved several static content to various files --- assets/html/main.html | 48 ++++++++++++++++++++++ assets/{ => image}/waldschrat.jpg | Bin assets/{ => js}/jquery-1.7.1.js | 0 assets/{ => js}/jquery-1.7.1.min.js | 0 assets/js/serverval.js | 60 ++++++++++++++++++++++++++++ assets/style/common.css | 41 +++++++++++++++++++ src/Makefile.am | 1 - src/http/response/me.c | 57 +++++--------------------- src/http/worker/process.c | 43 ++++++++++++++------ src/webgameserver.c | 2 +- 10 files changed, 192 insertions(+), 60 deletions(-) create mode 100644 assets/html/main.html rename assets/{ => image}/waldschrat.jpg (100%) rename assets/{ => js}/jquery-1.7.1.js (100%) rename assets/{ => js}/jquery-1.7.1.min.js (100%) create mode 100644 assets/js/serverval.js create mode 100644 assets/style/common.css diff --git a/assets/html/main.html b/assets/html/main.html new file mode 100644 index 0000000..3a60027 --- /dev/null +++ b/assets/html/main.html @@ -0,0 +1,48 @@ + + + + + My own little Web-App + + + + + + + +
+ + Value created at:
+
+ Next value in:
+
+ Value: +
+
+

Testpage

+ Welcome You!!!
+ +
+
+
+ + + + diff --git a/assets/waldschrat.jpg b/assets/image/waldschrat.jpg similarity index 100% rename from assets/waldschrat.jpg rename to assets/image/waldschrat.jpg diff --git a/assets/jquery-1.7.1.js b/assets/js/jquery-1.7.1.js similarity index 100% rename from assets/jquery-1.7.1.js rename to assets/js/jquery-1.7.1.js diff --git a/assets/jquery-1.7.1.min.js b/assets/js/jquery-1.7.1.min.js similarity index 100% rename from assets/jquery-1.7.1.min.js rename to assets/js/jquery-1.7.1.min.js diff --git a/assets/js/serverval.js b/assets/js/serverval.js new file mode 100644 index 0000000..3753157 --- /dev/null +++ b/assets/js/serverval.js @@ -0,0 +1,60 @@ +function ServerVal(eId) +{ + this.eId = eId; + this.eCtime = eId + " span:eq(1)"; + this.eVnext = eId + " span:eq(2)"; + this.eValue = eId + " span:eq(3)"; + + this.interval = null; + this.ctime = null; + this.vnext = 0; + this.value = null; +} + +ServerVal.prototype.loadJSON = function(data) +{ + this.ctime = new Date(data.ctime * 1000); + this.vnext = data.vnext; + this.value = data.value; + + this.show(); +} + +ServerVal.prototype.show = function() +{ + $(this.eCtime).empty().append(this.ctime.toString()); + $(this.eVnext).empty().append(this.vnext); + $(this.eValue).empty().append(this.value); + + if ($(this.eId).hasClass("hide")) { + $(this.eId).removeClass("hide"); + } +} + +ServerVal.prototype.start = function() +{ + this.interval = setInterval($.proxy(this.process, this), 1000); +} + +ServerVal.prototype.process = function() +{ + if (0 >= this.vnext) { + $.getJSON("/randval/", $.proxy(this.loadJSON, this)); + } + + else { + this.vnext--; + $(this.eVnext).empty().append(this.vnext); + } +} + +ServerVal.prototype.stop = function() +{ + $(this.eId).addClass("hide"); + + clearInterval(this.interval); + this.interval = null; + this.vnext = 0; +} + +// vim: set ts=4 sw=4: diff --git a/assets/style/common.css b/assets/style/common.css new file mode 100644 index 0000000..5f54fe0 --- /dev/null +++ b/assets/style/common.css @@ -0,0 +1,41 @@ +div#randval { + left: 200px; + top: 100px; + padding: 10px; + position: fixed; + background-color: white; + border: 1px solid black; + border-radius: 10px; +} + +div.hide#randval { + top: -500px; +} + +.small { + font-size: small; +} + +ul#menu { + list-style: none inside; + margin: 0px; + padding: 1px 0px 0px; + border-bottom: 1px solid #7b0b2b; + display: inline-block; + width: 100%; +} + +ul#menu li { + padding: 2px; + border-top-left-radius: 10px; + border-top-right-radius: 10px; + border-top: 1px solid #7b0b2b; + border-left: 1px solid #7b0b2b; + border-right: 1px solid #7b0b2b; + text-align: center; + cursor: pointer; + + float: left; + margin-right: 1px; +} +/* vim: set st=4 sw=4: */ diff --git a/src/Makefile.am b/src/Makefile.am index 90bd522..a466572 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,7 +30,6 @@ RESP = http/response.c \ http/response/403.c \ http/response/login_form.c \ http/response/asset.c \ - http/response/me.c \ http/response/randval.c PARSER = http/parser.c \ http/parser/parse.c \ diff --git a/src/http/response/me.c b/src/http/response/me.c index 47bff72..741f5a9 100644 --- a/src/http/response/me.c +++ b/src/http/response/me.c @@ -57,67 +57,32 @@ "font-size: small;" \ "}" \ "" \ - "" \ + "" \ + "" \ "" \ "" \ - "" \ + "" + "" \ "
" \ "" \ - "Value created at:

" \ - "Next value in:
" \ + "Value created at:

" \ + "Next value in:
" \ "
" \ - "Value: " \ + "Value: " \ "
" \ "
" \ "

Testpage

" \ "Welcome %s
" \ "" \ - "
Link" \ "
" \ "
" \ "" \ diff --git a/src/http/worker/process.c b/src/http/worker/process.c index 6cc78d2..db010c3 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -108,7 +108,10 @@ httpWorkerProcess(HttpWorker this, Stream st) new(Session, val, nval)); nbuf = sprintf(buffer, "sid=%lu;Path=/", this->session->id); - response = (HttpMessage)httpResponseMe(this->session->username); + response = httpWorkerGetAsset( + request, + "./assets/html/main.html", + CSTRA("text/html")); httpHeaderAdd( &(response->header), @@ -122,34 +125,50 @@ httpWorkerProcess(HttpWorker this, Stream st) response = (HttpMessage)httpResponseLoginForm(); } - if (0 == strcmp("/me/", request->uri)) { - char * uname = (NULL != this->session)? this->session->username : ""; - response = (HttpMessage)httpResponseMe(uname); + if (0 == strcmp("/", request->uri)) { + response = httpWorkerGetAsset( + request, + "./assets/html/main.html", + CSTRA("text/html")); } if (0 == strcmp("/randval/", request->uri)) { - if (NULL != this->session) { + //if (NULL != this->session) { response = (HttpMessage)httpResponseRandval( this->val->timestamp, this->val->value); - } else { - response = (HttpMessage)httpResponse403(); - } + //} else { + // response = (HttpMessage)httpResponse403(); + //} } - if (0 == strcmp("/image/", request->uri)) { + if (0 == strcmp("/image/me", request->uri)) { response = httpWorkerGetAsset( request, - "./assets/waldschrat.jpg", + "./assets/image/waldschrat.jpg", CSTRA("image/jpeg")); } - if (0 == strcmp("/jquery/", request->uri)) { + if (0 == strcmp("/assets/js/jquery", request->uri)) { response = httpWorkerGetAsset( request, - "./assets/jquery-1.7.1.min.js", + "./assets/js/jquery-1.7.1.min.js", CSTRA("text/javascript")); } + + if (0 == strcmp("/assets/js/serverval", request->uri)) { + response = httpWorkerGetAsset( + request, + "./assets/js/serverval.js", + CSTRA("text/javascript")); + } + + if (0 == strcmp("/assets/style/common", request->uri)) { + response = httpWorkerGetAsset( + request, + "./assets/style/common.css", + CSTRA("text/css")); + } } if (NULL == response) { diff --git a/src/webgameserver.c b/src/webgameserver.c index 5125956..9764cec 100644 --- a/src/webgameserver.c +++ b/src/webgameserver.c @@ -135,7 +135,7 @@ main() shm_unlink("/fooshm"); close(shm); - logger = new(LoggerStderr, LOGGER_DEBUG); + logger = new(LoggerSyslog, LOGGER_ERR); worker = new(HttpWorker, "testserver", value); server = new(Server, logger, worker, 11212, SOMAXCONN);