fix redundant code, add makefile and example webpage
authorJeremy Tan <[email protected]>
Thu, 15 Aug 2013 13:26:47 +0000 (21:26 +0800)
committerJeremy Tan <[email protected]>
Thu, 15 Aug 2013 13:26:47 +0000 (21:26 +0800)
testing/fastcgi-approach/Makefile [new file with mode: 0644]
testing/fastcgi-approach/fastcgi.c
testing/fastcgi-approach/index.html [new file with mode: 0644]

diff --git a/testing/fastcgi-approach/Makefile b/testing/fastcgi-approach/Makefile
new file mode 100644 (file)
index 0000000..03be42f
--- /dev/null
@@ -0,0 +1,22 @@
+CXX = gcc
+FLAGS = -std=c99 -Wall -Werror -pedantic -g
+LIB = -lpthread -lfcgi
+OBJ = fastcgi.o
+RM = rm -f
+
+BIN = fast
+
+$(BIN) : $(OBJ)
+       $(CXX) $(FLAGS) -o $(BIN) $(OBJ) $(LIB)
+
+%.o : %.c
+       $(CXX) $(FLAGS) -c $<
+
+clean:
+       $(RM) $(BIN)
+       $(RM) *.o
+
+clean_full: #cleans up all backup files
+       $(RM) $(BIN) $(OBJ) $(LINKOBJ)
+       $(RM) *.*~
+       $(RM) *~
index e4b5adb..8ade3f2 100644 (file)
@@ -51,7 +51,7 @@ static char *KeyPair(char *in, const char **key, const char **value) {
        }
        //Split was not found, set to default value
        *value = "";
-       return next ? next : "";
+       return next;
 }
 
 static void BeginResponse(int response_code, const char *module) {
diff --git a/testing/fastcgi-approach/index.html b/testing/fastcgi-approach/index.html
new file mode 100644 (file)
index 0000000..a3ff3ec
--- /dev/null
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html>
+       <head>
+               <meta charset="utf-8">
+               <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+               <title>FastCGI API Test</title>
+               <style>
+                       body {
+                               font-family: "Trebuchet MS", "Verdana", "Arial", "Sans";
+                               font-size: 12px;
+                               margin: 1em;
+                       }
+                       h2 {
+                               border-bottom: 1px solid gray;
+                       }
+                       .io {
+                               border: 1px solid gray;
+                               padding: 0.5em;
+                               margin: 1em;
+                               min-height: 5em;
+                               background-color: GhostWhite;
+                       }
+               </style>
+               
+               <script>
+               $(document).ready(function()
+               {
+                       $('#inputquery').submit(function () 
+                       {
+                               $('#output').text("Submitting query...");
+                               var query = $('#inputquery').find('input[name="query"]').val();
+                               
+                               var d = new Date();
+                               var start = d.getMilliseconds();
+                               var domain = document.domain == "mctx.us.to" ? "mctx.us.to:8080" : document.domain;
+                               $.getJSON('http://'+domain+'/api/'+query, function(data) {
+                                       var items = [];
+                                       var timeDiff = d.getMilliseconds() - start; //Not precise at all, use web console
+                                       
+                                       $.each(data, function(key, val) {
+                                               items.push('<li>"' + key + '" : "' + val + '"</li>'); 
+                                       });
+                                       
+                                       
+                                       $('#output').html("Response ok (" + timeDiff + "ms)! Output:<br>");
+                                       $('<ul/>', {
+                                               html: items.join("\n")
+                                       }).appendTo('#output');
+               
+                               }).fail(function(jqXHR) {
+                                       $('#output').text("Query failed with response code: " + jqXHR.status);
+                               });
+                               return false;
+                       });
+               });
+               </script>
+       </head>
+       
+       <body>
+               <h1>FastCGI API Test</h1>
+               The API is located at: <a href="http://mctx.us.to:8080/api/">http://mctx.us.to:8080/api/</a><br>
+               <h2>Input</h2>
+               Place a query string here. Examples include:<br>
+               <ul>
+                       <li><pre>sensors?key=value&amp;key2</pre></li>
+                       <li><pre>doesntexist?f</pre></li>
+               </ul>
+               Response times are inaccurate via JavaScript. Use the web console of
+               your browser to determine how long the query takes.<br>
+               Hopefully this doesn't break!
+               <div class="io">
+                       <form id="inputquery" name="input" action="#">
+                               Query string: <input type="text" name="query"><br>
+                               <input type="submit" value="Submit">
+                       </form>
+               </div>
+               
+               <h2>Output</h2>
+               <div id="output" class="io">
+               </div>
+       </body>
+</html>

UCC git Repository :: git.ucc.asn.au