int main(void)
{
	char s1[MAX_LEN + 1], s2[MAX_LEN + 1], s3[MAX_LEN + 1],
	     s4[MAX_LEN + 1], s5[MAX_LEN + 1], line[5 * MAX_LEN + 1];
	char *token, delim[] = "...", trash[10];
	int numCase;

	scanf("%d", &numCase);
	gets(trash);
	while(numCase)
	{
		gets(line);
		parseFirstLine(line, s1, s2, s3, s4, s5);
		
		gets(line);
		token = strtok(line, delim);

		printf("%s%s%s%s%s\n", s1, s2, s3, s4, s5);
		if(token != NULL)
			printf("%s%s%s%s%s\n", token, s4, s3, s2, s5);
		else
			printf("%s%s%s%s\n", s4, s3, s2, s5);

		numCase--;
	}

	return 0;
}
bool SimulationInputOutputHelper::parseLine(ParseContext& context)
{
    bool result = false;
    if (context.lineNumber == 1)
    {
        result = parseFirstLine(context);
    }
    else if (context.lineNumber <= context.stationsCount + 1)
    {
        Station station;
        result = parseStation(context.line, station, context.stationId);
        if (result)
        {
            context.simulationInstance.stations.append(station);
        }
    }
    else
    {
        Connection connection;
        result = parseConnection(context.line, connection);
        if (result)
        {
            context.simulationInstance.connections.append(connection);
        }
    }

    return result;
}
Esempio n. 3
0
bool KLUPD::HttpProtocol::HttpHeader::load(const char *headerBuffer, HttpAuthorizationDriver &httpAuthorizationDriver)
{
    if(!headerBuffer)
        return false;

    clear();

    // getting HTTP code
    std::string httpCodeBuffer;
    const size_t bytesReadHeader = getLine(headerBuffer, httpCodeBuffer);
    if(!bytesReadHeader)
        return false;
    headerBuffer += bytesReadHeader;

    if(!parseFirstLine(httpCodeBuffer))
        return false;

    while(*headerBuffer)
    {
        std::string fieldBuffer;
        const size_t bytesReadField = getLine(headerBuffer, fieldBuffer);
        if(!bytesReadField)
            return false;
        headerBuffer += bytesReadField;

        parseHeaderField(asciiToWideChar(fieldBuffer), httpAuthorizationDriver);
    }

    return true;
}
Esempio n. 4
0
/*
 *  Parse a new request. Return true to keep going with this or subsequent request, zero means insufficient data to proceed.
 */
static bool parseRequest(MaConn *conn, MaPacket *packet) 
{
    MaRequest   *req;
    char        *start, *end;
    int         len;

    /*
     *  Must wait until we have the complete set of headers.
     */
    if ((len = mprGetBufLength(packet->content)) == 0) {
        return 0;
    }
    start = mprGetBufStart(packet->content);
    if ((end = mprStrnstr(start, "\r\n\r\n", len)) == 0) {
        return 0;
    }
    len = (int) (end - start);
    if (len >= conn->host->limits->maxHeader) {
        maFailConnection(conn, MPR_HTTP_CODE_REQUEST_TOO_LARGE, "Header too big");
        return 0;
    }
    if (parseFirstLine(conn, packet)) {
        parseHeaders(conn, packet);
    } else {
        return 0;
    }
    maMatchHandler(conn);
    
    /*
     *  Have read the headers. Create the request pipeline. This calls the open() stage entry routines.
     */
    maCreatePipeline(conn);

    req = conn->request;
    if (conn->connectionFailed) {
        /* Discard input data */
        mprAssert(conn->keepAliveCount <= 0);
        conn->state = MPR_HTTP_STATE_PROCESSING;
        maRunPipeline(conn);
    } else if (req->remainingContent > 0) {
        conn->state = MPR_HTTP_STATE_CONTENT;
    } else if (req->length == -1 && (req->method == MA_REQ_POST || req->method == MA_REQ_PUT)) {
        conn->state = MPR_HTTP_STATE_CONTENT;
    } else {
        /*
         *  Can run the request now if there is no incoming data.
         */
        conn->state = MPR_HTTP_STATE_PROCESSING;
        maRunPipeline(conn);
    }
    return !conn->disconnected;
}
Esempio n. 5
0
bool HTTPHeader::loadFromString(const std::string& header) {

	// store the header's length
	this->length = header.length();

	// sanity checks
	if (header.find(HEADER_END, length-4) == std::string::npos) {
		debug(DBG_HEADER, DBG_LVL_ERR, "header does not end with \\r\\n\\r\\n!");
		return false;
	}

	uint32_t start = 0;
	uint32_t end = 0;

	while ( true ) {

		// get position of the next "\r\n"
		end = header.find("\r\n", start);

		// have we found the headers end? (immediately following "\r\n")
		if (start == end) {

			// header empty???
			if (start == 0) {
				debug(DBG_HEADER, DBG_LVL_ERR, "detected an empty header!");
				return false;
			}

			// ok! header seems valid
			break;

		}

		// get this line and parse it's content
		// handle the first line differently
		if (start == 0) {
			if (!parseFirstLine( header.substr(start, end-start) )) {
				return false;
			}
		} else {
			parseLine( header.substr(start, end-start) );
		}

		// proceed after the line-terminating "\r\n"
		start = end + 2;

	}

	// header was valid
	return true;

}