A simple web server that can be bound to either the EthernetInterface or the WiflyInterface.

Dependents:   Smart-WiFly-WebServer WattEye X10Svr SSDP_Server

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Fri Oct 11 02:33:46 2013 +0000
Parent:
27:90a1f5a5392f
Child:
29:00116fc9da74
Commit message:
Revised the return value from the callback in preparation for more complex transactions.

Changed in this revision

SW_HTTPServer.cpp Show annotated file Show diff for this revision Revisions of this file
SW_HTTPServer.h Show annotated file Show diff for this revision Revisions of this file
--- a/SW_HTTPServer.cpp	Thu Oct 10 20:38:12 2013 +0000
+++ b/SW_HTTPServer.cpp	Fri Oct 11 02:33:46 2013 +0000
@@ -622,7 +622,7 @@
         // Should we check the 'Content-Type' to see if it is
         //   'application/x-www-form-urlencoded'?
         int postBytes = atoi(GetHeaderValue("Content-Length"));
-        bool acceptIt = false;
+        CallBackResults acceptIt = ACCEPT_ERROR;
         if (strcmp(queryType, "POST") == 0 && postBytes > 0 ) {
             if (postBytes) {
                 int ndxHandler = 0;
@@ -637,7 +637,7 @@
                     }
                 }
 
-                if (regHandled && acceptIt) {
+                if (regHandled && acceptIt != ACCEPT_ERROR) {
                     // @todo need to refactor - if the thing is bigger than the buffer,
                     //       then we can receive it a chunk at a time, and hand off
                     //       the chunks to the callback. May need callbacks that
@@ -647,10 +647,12 @@
                     //
                     // If so, we'll make space for it
                     postQueryString = (char *)mymalloc(postBytes + 1);
+                    INFO("Free space %d", Free());
                     if (postQueryString) {
                         char * offset;
                         int len;
 
+                        INFO("Processing");
                         dblCR += 4;                         // If we slurped up any of the POST,
                         while (*dblCR && *dblCR <= ' ')
                             dblCR++;
@@ -661,9 +663,9 @@
                             n = client.receive(offset, postBytes - len);
                             if (n >=0) {
                                 offset[n] = '\0';
-                                //printf("HTTPd: %d of %d: [%s]\r\n", len, postBytes, offset);
+                                INFO("HTTPd: %d of %d: [%s]", len, postBytes, offset);
                             } else if (n < 0) {
-                                //printf("HTTPd: n=%d\r\n", n);
+                                INFO("HTTPd; n=%d", n);
                                 break;      // no more data, before the plan
                             }
                         }
@@ -671,6 +673,7 @@
 //                            UnescapeString(postQueryString);
 //                            ParseParameters(postQueryString);
                             // use the same handler as for the length check
+                            INFO("calling user code");
                             acceptIt = (*handlers[ndxHandler].callback)(this, DATA_TRANSFER, postQueryString, NULL, 0);
                         } else {
                             ERR("HTTPd: len error.");
--- a/SW_HTTPServer.h	Thu Oct 10 20:38:12 2013 +0000
+++ b/SW_HTTPServer.h	Fri Oct 11 02:33:46 2013 +0000
@@ -191,6 +191,12 @@
         SEND_PAGE,              ///< the activated method should now send the page
     } CallBackType;
 
+    typedef enum CALLBACKRESULTS {
+        ACCEPT_ERROR,           ///< client not accepting the request.
+        ACCEPT_COMPLETE,        ///< client accepted the request, the work is done.
+        ACCEPT_CONTINUE,        ///< client accepted the request, additional transactions to complete.
+    } CallBackResults;
+    
     /**
     * This is the prototype for custom handlers that are activated via a callback
     *
@@ -215,7 +221,7 @@
     * @queryParamCount is the number of parameters.
     * @return true if command was accepted
     */
-    typedef bool (* Handler)(HTTPServer * svr, CallBackType type, const char *path, const namevalue *queryParams, int queryParamCount);
+    typedef CallBackResults (* Handler)(HTTPServer * svr, CallBackType type, const char *path, const namevalue *queryParams, int queryParamCount);
 
     /**
     * Create the HTTPServer object.