length(0),
firstentry(0),
lastentry(0),
+ requestsequencenumber(0),
numqueueentries(DEFAULT_SIZE),
fd(-1)
{
closedir(dir);
}
-int IoTQuery::checkDirectory() {
+bool IoTQuery::checkDirectory() {
struct stat s;
int err=stat(directory, &s);
if (-1 == err)
- return 0;
+ return false;
return S_ISDIR(s.st_mode);
}
+void IoTQuery::decodeQuery() {
+ int len=strlen(query);
+ char * str=new char[len+1];
+ memcpy(str, query, len+1);
+ char *tok_ptr=str;
+
+ /* Parse commands */
+ char *command=strsep(&tok_ptr, "&");
+ if (strncmp(command, "putslot", 7) == 0)
+ reqPutSlot = true;
+
+ if (strncmp(command, "getslot", 7) == 0)
+ reqGetSlot = true;
+
+ /* Load Sequence Number for request */
+ char *sequencenumber_str = strsep(&tok_ptr, "&");
+
+ if (sequencenumber_str != NULL)
+ requestsequencenumber = strtol(sequencenumber_str, NULL, 10);
+
+ /* Update size if we get request */
+ char * numqueueentries_str = tok_ptr;
+ if (numqueueentries_str != NULL)
+ numqueueentries = strtol(numqueueentries_str, NULL, 10);
+
+ delete str;
+}
+
+void IoTQuery::getSlot() {
+
+}
+
+void IoTQuery::putSlot() {
+
+}
+
void IoTQuery::processQuery() {
- parseQuery();
+ getQuery();
getDirectory();
readData();
-
+
if (strncmp(method, "POST", 4) != 0)
return;
if (directory == NULL ||
- checkDirectory())
+ !checkDirectory())
return;
- if (openStatusFile() < 0)
+ if (!openStatusFile())
return;
-
- flock(fd, LOCK_EX);
-
- cout << "Content-type: text/html\r\n"
- << "\r\n"
- << "<html>\n"
- << " <head>\n"
- << " <title>Hello, World!</title>\n"
- << " </head>\n"
- << " <body>\n"
- << " <h1>Hello, World!</h1>\n"
- << " </body>\n";
-
- cout << uri_str << " " << uri << "\n";
- cout << query_str << " " << query << "\n";
- cout << method_str << " " << method << "\n";
- cout << iotcloudroot_str << " " << iotcloudroot << "\n";
- if (data)
- cout << "[" << data << "]";
-
-
- cout << "</html>\n";
-}
+ flock(fd, LOCK_EX);
+
+ decodeQuery();
+ if (reqGetSlot)
+ getSlot();
+ else if (reqPutSlot)
+ putSlot();
+ else return;
+}
void IoTQuery::readData() {
if (length) {
} while (!cin.eof());
}
-void IoTQuery::parseQuery() {
+void IoTQuery::getQuery() {
uri = FCGX_GetParam(uri_str, request->envp);
query = FCGX_GetParam(query_str, request->envp);
method = FCGX_GetParam(method_str, request->envp);
pwrite(fd, &lastentry, sizeof(lastentry), OFFSET_LAST);
}
-int IoTQuery::openStatusFile() {
+bool IoTQuery::openStatusFile() {
char statusfile[]="queuestatus";
int len=strlen(directory);
delete filename;
if (fd < 0)
- return fd;
+ return false;
int size;
int needwrite=0;
if (needwrite)
updateStatusFile();
- return fd;
+ return true;
}