Changes made for RPC

Revision:
2:8653bbcf7e58
Parent:
1:6b7472d5e9ee
Child:
3:d6224049b3bf
--- a/HTTPConnection.cpp	Sun May 26 22:49:42 2013 +0000
+++ b/HTTPConnection.cpp	Sun May 26 23:22:36 2013 +0000
@@ -8,7 +8,7 @@
 
 using std::string;
 
-#if (0 && !defined(TARGET_LPC11U24))
+#if (1 && !defined(TARGET_LPC11U24))
 #define INFO(x, ...) std::printf("[HttpConnection : INFO]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) std::printf("[HttpConnection : WARN]"x"\r\n", ##__VA_ARGS__);
 #define ERR(x, ...) std::printf("[HttpConnection : ERR]"x"\r\n", ##__VA_ARGS__);
@@ -39,7 +39,6 @@
 int HTTPConnection::poll()
 {
     static char buffer[256] = {};
-    static char echoHeader[256] = {};
 
     
     int rcvd= 0;
@@ -58,9 +57,8 @@
     if (rcvd == -1) {
         //  Invalid content received, so close the connection
         INFO("Invalid message received, so sending negative response and closing connection !");
-        sprintf(echoHeader,"HTTP/1.1 400 NOK\n\rContent-Length: %d\n\rContent-Type: text\n\rConnection: Close\n\r\n\r",strlen(buffer));
+        sprintf(buffer,"HTTP/1.1 400 NOK\n\rContent-Length: %d\n\rContent-Type: text\n\rConnection: Close\n\r\n\r",0);
         m_Tcp.set_blocking(true, 1500);
-        m_Tcp.send(echoHeader,strlen(echoHeader));
         m_Tcp.send(buffer,strlen(buffer));
         close();
         rcvd = -1;
@@ -85,17 +83,6 @@
             }
         }
     }             
-    if (rcvd == 0) {
-//        sprintf(echoHeader,"HTTP/1.1 200 OK\n\rContent-Length: %d\n\rContent-Type: text\n\rConnection: Close\n\r\n\r",strlen(buffer));
-//        m_Tcp.set_blocking(true);
-//        m_Tcp.send_all(echoHeader,strlen(echoHeader));
-//        m_Tcp.send_all(buffer,strlen(buffer));
-        
-        /// INSERT PRCESSING OF REQUESST HERE
-        /// END OF PROCESSING REQUEST
-        
-        //  Do not close the connection, it may be reused
-    }
     INFO("Leaving poll function!");
     return rcvd;
 }
@@ -147,7 +134,7 @@
     return i;    
 }
 
-int HTTPConnection::parse(const char* buffer)
+int HTTPConnection::parse(char* buffer)
 {
     if ((buffer == NULL) || (strlen(buffer) < 4)) {
         ERR("Buffer content is invalid or too short.");
@@ -159,14 +146,13 @@
     
     //  decompose string into a list of arguments
     char s = 0; // current starting char
-    static char buff[255] = {};
-    for (int i = 0 ; i < strlen(buffer)+1 ; i++) {
+    int nLen = strlen(buffer)+1;
+    for (int i = 0 ; i < nLen ; i++) {
         if ((buffer[i] == ' ') || (buffer[i] == '\n') || (buffer[i] == 0)) {
             // new arg found
-            strncpy(buff, &buffer[s], i-s);
-            buff[i-s] = 0;
-            INFO("Found argument \"%s\"", buff);
-            args.push_back(std::string(buff));
+            buffer[i] = 0;
+            INFO("Found argument \"%s\"", &buffer[s]);
+            args.push_back(&buffer[s]);
             s = i+1;
         }
     }