Bug fixes + tabbing
[iotcloud.git] / version2 / src / C / CloudComm.h
index bb319c2d4cb8731be28590d7c955b69dff8f2816..ce7cfa07023a3832252f2633cd1973b4b35e1541 100644 (file)
@@ -2,7 +2,7 @@
 #define CLOUDCOMM_H
 
 #include "common.h"
-
+#include <pthread.h>
 /**
  * This class provides a communication API to the webserver.  It also
  * validates the HMACs on the slots and handles encryption.
 #define CloudComm_IV_SIZE 16
 /** Sets the size for the HMAC. */
 #define CloudComm_HMAC_SIZE 32
+#define HttpURLConnection_HTTP_OK 200
+
+typedef struct {
+       int fd;
+       int numBytes;
+} WebConnection;
+
 
 class CloudComm {
 private:
        IoTString *baseurl;
-       SecretKeySpec *key;
+       AESKey *key;
        Mac *mac;
        IoTString *password;
        SecureRandom *random;
        Array<char> *salt;
        Table *table;
-       int32_t listeningPort = -1;
-       Thread *localServerThread = NULL;
-       bool doEnd = false;
-       TimingSingleton *timer = NULL;
+       int32_t listeningPort;
+       pthread_t localServerThread;
+       bool doEnd;
+       TimingSingleton *timer;
+       Array<char> *getslot;
+       Array<char> *putslot;
 
        /**
         * Generates Key from password.
         */
-       SecretKeySpec *initKey();
+       AESKey *initKey();
 
        /**
         * Inits the HMAC generator.
@@ -44,14 +53,14 @@ private:
        /*
         * Builds the URL for the given request.
         */
-       URL buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
+       IoTString *buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
        void setSalt();
        bool getSalt();
        Array<char> *createIV(int64_t machineId, int64_t localSequenceNumber);
        Array<char> *encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes);
        Array<char> *stripIVAndDecryptSlot(Array<char> *rawData);
-       Array<Slot *> *processSlots(DataInputStream dis);
-       void localServerWorkerFunction();
+       Array<Slot *> *processSlots(WebConnection *wc);
+
 
 public:
        /**
@@ -63,6 +72,7 @@ public:
         * Constructor for actual use. Takes in the url and password.
         */
        CloudComm(Table *_table,  IoTString *_baseurl, IoTString *_password, int _listeningPort);
+       ~CloudComm();
 
        /**
         * Inits all the security stuff
@@ -89,6 +99,7 @@ public:
         */
 
        Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString *host, int port);
-       public void close();
+       void closeCloud();
+       void localServerWorkerFunction();
 };
 #endif