FIAP (IEEE1888) library

Dependents:   Fetch_IEEE1888_Storage IEEE1888_MULTI_SENSOR_GW

Fork of FiapV2 by Yasushi TAUCHI

Revision:
10:b355957e01f4
Parent:
9:02ae92c06e52
Child:
11:db42339d6cce
--- a/fiap.cpp	Wed Feb 20 16:12:27 2013 +0000
+++ b/fiap.cpp	Thu Feb 21 16:43:59 2013 +0000
@@ -51,6 +51,45 @@
     strcpy(_soap_action,"\"http://soap.fiap.org/query\"");
 }
 
+char* FIAP::HTTPStatusText(HTTPResult r)
+{
+    if (r==HTTP_OK) {
+        return "Success \n";
+    }
+    if (r==HTTP_PROCESSING) {
+        return "Processing \n";
+    }
+    if (r==HTTP_PARSE) {
+        return "URI Parse error \n";
+    }
+    if (r==HTTP_DNS) {
+        return "Could not resolve name\n";
+    }
+    if (r==HTTP_PRTCL) {
+        return "Protocol error\n";
+    }
+    if (r==HTTP_NOTFOUND) {
+        return "HTTP 404 Error\n";
+    }
+    if (r==HTTP_REFUSED) {
+        return "HTTP 403 Error \n";
+    }
+    if (r==HTTP_ERROR) {
+        return "HTTP xxx error \n ";
+    }
+    if (r==HTTP_TIMEOUT) {
+        return "Connection timeout\n";
+    }
+    if (r==HTTP_CONN) {
+        return "Connection error\n";
+    }
+    if (r==HTTP_CLOSED) {
+        return "Connection error\n";
+    }
+
+    return "Unknown Network Error\n";
+}
+
 FIAP::FIAP()
 {
     debug_mode=false;
@@ -99,53 +138,12 @@
         printf(rstr);
         printf("\n\r****\n\r");
     }
-    if(!r) {
-        if (debug_mode)printf("Success \n");
-    } else {
-
-        if (r==HTTP_PROCESSING) {
-            if (debug_mode)printf("Processing \n");
-            return -1;
-        }
-        if (r==HTTP_PARSE) {
-            if (debug_mode) printf("URI Parse error \n");
-            return -1;
-        }
-        if (r==HTTP_DNS) {
-            if (debug_mode) printf("Could not resolve name\n");
-            return -1;
-        }
-        if (r==HTTP_PRTCL) {
-            if (debug_mode)printf("Protocol error\n");
-            return -1;
-        }
-        if (r==HTTP_NOTFOUND) {
-            if (debug_mode)printf("HTTP 404 Error\n");
-            return -1;
-        }
-        if (r==HTTP_REFUSED) {
-            if (debug_mode) printf("HTTP 403 Error \n");
-            return -1;
-        }
-        if (r==HTTP_ERROR) {
-            if (debug_mode)printf("HTTP xxx error %d  \n ",r);
-            return -1;
-        }
-        if (r==HTTP_TIMEOUT) {
-            if (debug_mode)printf("Connection timeout\n");
-            return -1;
-        }
-        if (r==HTTP_CONN) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (r==HTTP_CLOSED) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (debug_mode)printf("Unknown Network Error\n");
+    
+    if (debug_mode)printf(HTTPStatusText(r));
+    if (r != HTTP_OK) {
         return -1;
     }
+    
     SP_XmlNodeList * points;
     SP_XmlNodeList * trans_point;
     if (strlen(rstr)>0) {
@@ -247,52 +245,12 @@
     if (debug_mode)printf("post.start \n\r");
     HTTPResult r = http.postXML(_fiap_storage,"http://soap.fiap.org/query",InData,&stream);
     if (debug_mode)printf("post.end \n\r");
-    if(!r) {
-        if (debug_mode)printf("Success \n");
-    } else {
-        if (r==HTTP_PROCESSING) {
-            if (debug_mode)printf("Processing \n");
-            return -1;
-        }
-        if (r==HTTP_PARSE) {
-            if (debug_mode) printf("URI Parse error \n");
-            return -1;
-        }
-        if (r==HTTP_DNS) {
-            if (debug_mode) printf("Could not resolve name\n");
-            return -1;
-        }
-        if (r==HTTP_PRTCL) {
-            if (debug_mode)printf("Protocol error\n");
-            return -1;
-        }
-        if (r==HTTP_NOTFOUND) {
-            if (debug_mode)printf("HTTP 404 Error\n");
-            return -1;
-        }
-        if (r==HTTP_REFUSED) {
-            if (debug_mode) printf("HTTP 403 Error \n");
-            return -1;
-        }
-        if (r==HTTP_ERROR) {
-            if (debug_mode)printf("HTTP xxx error %d  \n ",r);
-            return -1;
-        }
-        if (r==HTTP_TIMEOUT) {
-            if (debug_mode)printf("Connection timeout\n");
-            return -1;
-        }
-        if (r==HTTP_CONN) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (r==HTTP_CLOSED) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (debug_mode)printf("Unknown Network Error\n");
+    
+    if (debug_mode)printf(HTTPStatusText(r));
+    if (r != HTTP_OK) {
         return -1;
     }
+    
     SP_XmlNodeList * points;
     if (strlen(rstr)>0) {
         if (debug_mode)printf("\n\r data Get Ok\n\r");
@@ -379,56 +337,16 @@
     HTTPText InData(_soap_text);
     HTTPText OutData(rstr,1200);
     HTTPResult r = http.postXML(_fiap_storage,"http://soap.fiap.org/data",InData,&OutData);
-    if(!r) {
-        if (debug_mode)printf("Success \n");
-        if (debug_mode) {
-            printf("****\n\r");
-            printf(rstr);
-            printf("\n\r****\n\r");
-        }
-    } else {
-        if (r==HTTP_PROCESSING) {
-            if (debug_mode)printf("Processing \n");
-            return -1;
-        }
-        if (r==HTTP_PARSE) {
-            if (debug_mode) printf("URI Parse error \n");
-            return -1;
-        }
-        if (r==HTTP_DNS) {
-            if (debug_mode) printf("Could not resolve name\n");
-            return -1;
-        }
-        if (r==HTTP_PRTCL) {
-            if (debug_mode)printf("Protocol error\n");
-            return -1;
-        }
-        if (r==HTTP_NOTFOUND) {
-            if (debug_mode)printf("HTTP 404 Error\n");
-            return -1;
-        }
-        if (r==HTTP_REFUSED) {
-            if (debug_mode) printf("HTTP 403 Error \n");
-            return -1;
-        }
-        if (r==HTTP_ERROR) {
-            if (debug_mode)printf("HTTP xxx error \n");
-            return -1;
-        }
-        if (r==HTTP_TIMEOUT) {
-            if (debug_mode)printf("Connection timeout\n");
-            return -1;
-        }
-        if (r==HTTP_CONN) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (r==HTTP_CLOSED) {
-            if (debug_mode)printf("Connection error\n");
-            return -1;
-        }
-        if (debug_mode)printf("Unknown Network Error\n");
+    
+    if (debug_mode)printf(HTTPStatusText(r));
+    if (r != HTTP_OK) {
         return -1;
     }
+
+    if (debug_mode) {
+        printf("****\n\r");
+        printf(rstr);
+        printf("\n\r****\n\r");
+    }
     return 0;
 }
\ No newline at end of file