Ejemplo n.º 1
0
int Dynamo::PostReq(const string &op, const rapidjson::Value &request) {
	string req;
	if (0 != Json2str(request, req)) {
		return -1;
	}
	return PostReq(op, req);
}
Ejemplo n.º 2
0
int Dynamo::Scan(const Value & req) {
	return PostReq(AWS_DYNAMO_SCAN, req);
}
Ejemplo n.º 3
0
int Dynamo::Query(const Value & req) {
	return PostReq(AWS_DYNAMO_QUERY, req);
}
Ejemplo n.º 4
0
int Dynamo::DelItem(const Value & req) {
	return PostReq(AWS_DYNAMO_DELETE_ITEM, req);
}
Ejemplo n.º 5
0
int Dynamo::BatchGetItem(const Value & req) {
	return PostReq(AWS_DYNAMO_BATCH_GET_ITEM, req);
}
Ejemplo n.º 6
0
int Dynamo::UpdateItem(const Value & req) {
	return PostReq(AWS_DYNAMO_UPDATE_ITEM, req);
}
Ejemplo n.º 7
0
int Dynamo::BatchWriteItem(const Value &request) {
	return PostReq(AWS_DYNAMO_BATCH_WRITE_ITEM, request);
}
Ejemplo n.º 8
0
int Dynamo::PutItem(const Value & req) {
	return PostReq(AWS_DYNAMO_PUT_ITEM, req);
}
Ejemplo n.º 9
0
int Dynamo::Scan(const string & req) {
	return PostReq(AWS_DYNAMO_SCAN, req);
}
Ejemplo n.º 10
0
int Dynamo::Query(const string & req) {
	return PostReq(AWS_DYNAMO_QUERY, req);
}
Ejemplo n.º 11
0
int Dynamo::GetItem(const string & req) {
	return PostReq(AWS_DYNAMO_GET_ITEM, req);
}
Ejemplo n.º 12
0
// @brief: handles webclient
// @param[in]: socket - socket that client is connected on
// @param[in]: ip_addr - ip address of the client
void WebHostEmulator::HandleClient(SOCKET* socket, const std::string ip_addr)
{
#ifdef __DEBUG
	static int ThreadCounter = 0;
	const int ThreadID = ThreadCounter++;
	printf("Thread %i started\n", ThreadID);
#endif

	std::queue <std::string> RecvQueue;
	std::string Received, overflow;

	while (1) {
		// Recieve
		std::string RecvBuffer;
		RecvBuffer.resize(8192);
	
		int iResult = recv(*socket, &RecvBuffer[0], RecvBuffer.length(), 0);

		if (iResult <= 0) {
#ifdef __DEBUG
			printf("Thread %i ended\n", ThreadID);
#endif
			closesocket(*socket);
			delete socket;
			return;
		}

		RecvBuffer.resize(iResult);

		if (parseHTTP (RecvBuffer, Received, overflow) != 0) {
			continue;
		}
		
#ifdef __DEBUG
		printf("Received Message:-----\n%s\nEnd Received-----\n\n", Received.c_str());
#endif

		// Send
		size_t found;
		std::string Body, ContentLength, ContentType, Header, Response;

		found = Received.find("GET");
		if (found == 0) {
			size_t start = Received.find("/");
			size_t end = Received.find(" ", start);

			ContentType = GetReq(std::string(Received, start, end - start), Body);
			Header = BuildHeader(Body, 200, ContentType, true);

			Response = Header + Body;

			iResult = send(*socket, Response.c_str(), Response.size(), 0);
		}

		found = Received.find("POST");
		if (found == 0) {

			size_t start = Received.find("/");
			size_t end = Received.find(" ", start);

			std::string Result = PostReq(
				std::string(Received, start, end - start),
				GetBody(Received),
				ip_addr
				);

			ContentType = "text/html"; // This is a temp fix.

			Body = BuildResult(Result, std::string("result.html"));
			Header = BuildHeader(Body, 200, ContentType, false);

			Response = Header + Body;

			iResult = send(*socket, Response.c_str(), Response.size(), 0);
		}

		Received.clear();
	}

#ifdef __DEBUG
	printf("Thread %i ended\n", ThreadID);
#endif

	closesocket(*socket);

	delete socket;
	return;
}