12 const char * query_str="QUERY_STRING";
13 const char * uri_str="REQUEST_URI";
14 const char * method_str="REQUEST_METHOD";
15 const char * iotcloudroot_str="IOTCLOUD_ROOT";
16 const char * length_str="CONTENT_LENGTH";
18 IoTQuery::IoTQuery(FCGX_Request *request) :
33 IoTQuery::~IoTQuery() {
45 void IoTQuery::processQuery() {
50 if (strncmp(method, "POST", 4) != 0)
53 if (directory == NULL ||
54 (dir = opendir(directory)) == NULL)
57 if (openMaxFile() < 0)
62 cout << "Content-type: text/html\r\n"
66 << " <title>Hello, World!</title>\n"
69 << " <h1>Hello, World!</h1>\n"
72 cout << uri_str << " " << uri << "\n";
73 cout << query_str << " " << query << "\n";
74 cout << method_str << " " << method << "\n";
75 cout << iotcloudroot_str << " " << iotcloudroot << "\n";
77 cout << "[" << data << "]";
85 void IoTQuery::readData() {
87 data = new char[length+1];
88 memset(data, 0, length+1);
89 cin.read(data, length);
98 void IoTQuery::parseQuery() {
99 uri = FCGX_GetParam(uri_str, request->envp);
100 query = FCGX_GetParam(query_str, request->envp);
101 method = FCGX_GetParam(method_str, request->envp);
102 iotcloudroot = FCGX_GetParam(iotcloudroot_str, request->envp);
104 char * reqlength = FCGX_GetParam(length_str, request->envp);
106 length=strtol(reqlength, NULL, 10);
112 void IoTQuery::getDirectory() {
113 char * split = strchr((char *)uri, '?');
116 int split_len = (int) (split-uri);
117 int rootdir_len = strlen(iotcloudroot);
118 int directory_len = split_len + rootdir_len + 1;
119 directory = new char[directory_len];
120 memcpy(directory, iotcloudroot, rootdir_len);
121 memcpy(directory + rootdir_len, uri, split_len);
122 directory[directory_len]=0;
125 int IoTQuery::openMaxFile() {
126 char maxfile[]="queuesize";
127 int len=strlen(directory);
129 char * filename=new char[len+sizeof(maxfile)+2];
130 memcpy(filename, directory, len);
132 memcpy(filename+len+1, maxfile, sizeof(maxfile));
133 filename[len+sizeof(maxfile)+1]=0;
134 fd=open(filename, O_CREAT| O_RDWR, S_IRUSR| S_IWUSR);