Example #1
0
const std::string ScriptTokeniser::getToken ()
{
	if (m_unget) {
		m_unget = false;
		return m_token;
	}

	const char *token = fillToken();
	if (token)
		return std::string(token);

	return "";
}
Example #2
0
void PaloHttpRequest::extractHeader(char* begin, char* end)
{
#ifdef ENABLE_TRACE_OPTION
	headerString = string(begin, end);

	if (Logger::isTrace()) {
		Logger::trace << "header " << headerString << endl;
	}
#endif

	// 1. split header into lines at "\r\n"
	// 2. split lines at " "
	// 3. split GET/POST etc. requests

	//
	// check for '\n' (we check for '\r' later)
	//

	static const char CR = '\r';
	static const char NL = '\n';
	static const char SPC = ' ';

	int lineNum = 0;

	for (char* start = begin; start < end;) {
		char* findnl = start;

		for (; findnl < end && *findnl != NL; ++findnl) {
		}

		if (findnl == end) {
			break;
		}

		char* endnl = findnl;

		//
		// check for '\r'
		//

		if (endnl > start && *(endnl - 1) == CR) {
			endnl--;
		}

		if (endnl > start) {

			//
			// split line at spaces
			//

			char* space = start;

			for (; space < endnl && *space != SPC; ++space) {
			}

			if (space < endnl) {
				if (space > start) {
					char* colon = space;

					if (*(colon - 1) == ':') {
						--colon;
					}

					// check for request type (GET/POST in line 0),
					// path and parameters
					if (lineNum == 0) {
						if (start + 4 == colon && strncmp(start, "POST", 4) == 0) {
							type = HTTP_REQUEST_POST;
						} else if (start + 3 == colon && strncmp(start, "GET", 3) == 0) {
							type = HTTP_REQUEST_GET;
						}

						if (type != HTTP_REQUEST_ILLEGAL) {
							char* reqe = space + 1;

							// delete "HTTP/1.1" from request
							for (; reqe < endnl && *reqe != SPC; reqe++) {
							}

							// split requestPath and parameters
							char* parm = space + 1;

							for (; parm < reqe && *parm != '?'; parm++) {
							}

							if (parm < reqe) {
								setKeyValues(parm + 1, reqe);
							}
						}
					} else {
						*colon = '\0';
						*endnl = '\0';
						++space;

						if (loginRequest) { // has to save HTTP headers
							string key = string(start, colon);
							string value = string(space, endnl);
							headerFields[key] = value;
						}

						const struct CommandOption * option = Perfect_Hash::PaloValue(start, (unsigned int)(colon - start));

						if (option != 0) {
							switch (option->code) {
							case PaloRequestHandler::CMD_X_PALO_SERVER:
								fillToken(paloJobRequest->serverToken, space, endnl);
								break;

							case PaloRequestHandler::CMD_X_PALO_DATABASE:
								fillToken(paloJobRequest->databaseToken, space, endnl);
								break;

							case PaloRequestHandler::CMD_X_PALO_DIMENSION:
								fillToken(paloJobRequest->dimensionToken, space, endnl);
								break;

							case PaloRequestHandler::CMD_X_PALO_CUBE:
								fillToken(paloJobRequest->cubeToken, space, endnl);
								break;

							case PaloRequestHandler::CMD_X_PALO_CUBE_CLIENT_CACHE:
								fillToken(paloJobRequest->clientCacheToken, space, endnl);
								break;

							case PaloRequestHandler::CMD_CONTENT_LENGTH: {
								char *p;
								long int result = ::strtol(space, &p, 10);

								if (*p == '\0') {
									contentLength = result;
								}

								break;
							}

							default:
								break;
							}
						}
					}
				}
			} else {
			}

			start = end + 1;
		}

		start = findnl + 1;
		lineNum++;
	}
}