Example #1
0
void AutoStr_Delete(AutoStr *as)
{
    deleteString(as);
}
Example #2
0
void scannerFillToken(Token *token)
{
    ScannerState state = SS_Empty;
    int32_t symbol = 0;
    char hexCode = 0;
    char hexCodeBackup = 0;

    String *tokenStr = &(token->str);

    while (1)
    {
        if (charStreamSwitch) {
            symbol = getc(source);
        }
        else {
            symbol = lastChar;
            charStreamSwitch = 1;
        }

        switch (state) {
            case SS_Empty: {
                if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_')) {
                    state = SS_Identifier;
                    initString(tokenStr);
                    stringPush(tokenStr,symbol);
                }
                else if (symbol >= '0' && symbol <= '9') {
                    state = SS_Number;
                    initString(tokenStr);
                    stringPush(tokenStr,symbol);
                }
                else if (isspace(symbol)) {
                    ;
                }
                else if (symbol == EOF) {
                    token->type = STT_EOF;
                    return;
                }
                else {
                    switch (symbol) {
                        case '"':
                            state = SS_String;
                            initString(tokenStr);
                            break;
                        case '/':
                            state = SS_Divide;
                            break;
                        case '!':
                            state = SS_Exclamation;
                            break;
                        case ';':
                            token->type = STT_Semicolon;
                            return;
                        case '{':
                            token->type = STT_LeftCurlyBracket;
                            return;
                        case '}':
                            token->type = STT_RightCurlyBracket;
                            return;
                        case '*':
                            token->type = STT_Multiply;
                            return;
                        case '+':
                            token->type = STT_Plus;
                            return;
                        case '-':
                            token->type = STT_Minus;
                            return;
                        case '(':
                            token->type = STT_LeftBracket;
                            return;
                        case ')':
                            token->type = STT_RightBracket;
                            return;
                        case ',':
                            token->type = STT_Comma;
                            return;
                        case '.':
                            token->type = STT_Dot;
                            return;
                        case '>':
                            state = SS_Greater;
                            break;
                        case '<':
                            state = SS_Less;
                            break;
                        case '=':
                            state = SS_Assignment;
                            break;
                        case '$':
                            state = SS_Dollar;
                            break;
                        case '&':
                            state = SS_And;
                            break;
                        case '|':
                            state = SS_Or;
                            break;
                        default:
                            setError(ERR_LexFile);
                            return;
                    }
                }
                break;
            }
            case SS_Greater: {
                if (symbol == '=') {
                    token->type = STT_GreaterEqual;
                    return;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Greater;
                    return;
                }
            }
            case SS_Less: {
                if (symbol == '=') {
                    token->type = STT_LessEqual;
                    return;
                }
                else if (symbol == '?') {
                    state = SS_Php_0;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Less;
                    return;
                }
                break;
            }
            case SS_Assignment: {
                if (symbol == '=') {
                    state = SS_Equal;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Assignment;
                    return;
                }
                break;
            }
            case SS_Dollar: {
                if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_')) {
                    state = SS_Variable;
                    initString(tokenStr);
                    stringPush(tokenStr, symbol);
                    break;
                }
                else {
                    setError(ERR_LexFile);
                    return;
                }
                break;
            }
            case SS_Variable: {
                if ((symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol == '_') ||
                     (symbol >= '0' && symbol <= '9')) {
                    stringPush(tokenStr, symbol);
                    state = SS_Variable;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Variable;
                    return;
                }
                break;
            }
            case SS_Number: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_Number;
                    stringPush(tokenStr, symbol);
                }
                else if (symbol == '.') {
                    state = SS_DoubleDecPoint;
                    stringPush(tokenStr, symbol);
                }
                else if ((symbol == 'e') || (symbol == 'E')) {
                    state = SS_DoubleExponent;
                    stringPush(tokenStr, symbol);
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    int n = stringToInt(tokenStr);
                    deleteString(tokenStr);
                    token->n = n;
                    token->type = STT_Number;
                    return;
                }
                break;
            }
            case SS_DoubleDecPoint: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_DoubleDecPart;
                    stringPush(tokenStr, symbol);
                }
                else {
                    deleteString(tokenStr);
                    setError(ERR_LexFile);
                    return;
                }
                break;
            }
            case SS_DoubleExponent: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_DoubleExpPart;
                    stringPush(tokenStr, symbol);
                }
                else if ((symbol == '+') || (symbol == '-')) {
                    state = SS_DoubleExpSign;
                    stringPush(tokenStr, symbol);
                }
                else {
                    deleteString(tokenStr);
                    setError(ERR_LexFile);
                    return;
                }
                break;
            }
            case SS_DoubleExpSign: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_DoubleExpPart;
                    stringPush(tokenStr, symbol);
                }
                else {
                    deleteString(tokenStr);
                    setError(ERR_LexFile);
                    return;
                }
                break;
            }
            case SS_Identifier: {
                if ((symbol == '_') || (symbol >= 'a' && symbol <= 'z') || (symbol >= 'A' && symbol <= 'Z') || (symbol >= '0' && symbol <= '9')) {
                    stringPush(tokenStr, symbol);
                    state = SS_Identifier;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    KeywordTokenType keywordType = strToKeyword(tokenStr); // FUNCTION CHECKS IF IDENTIFIER, WHICH HAS BEEN FOUND AINT A RESERVED ( KEYWORD ) WORD
                    if (keywordType == KTT_None) {
                        token->type = STT_Identifier;
                        return;
                    }
                    else {
                        deleteString(tokenStr);
                        if (keywordType == KTT_True) {
                            token->type = STT_Bool;
                            token->n = 1;
                        }
                        else if (keywordType == KTT_False) {
                            token->type = STT_Bool;
                            token->n = 0;
                        }
                        else if (keywordType == KTT_Null) {
                            token->type = STT_Null;
                        }
                        else if (keywordType == KTT_And) {
                            token->type = STT_AndLow;
                        }
                        else if (keywordType == KTT_Or) {
                            token->type = STT_OrLow;
                        }
                        else {
                            token->type = STT_Keyword;
                            token->keywordType = keywordType;
                        }
                        return;
                    }
                }
                break;
            }
            case SS_DoubleDecPart: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_DoubleDecPart;
                    stringPush(tokenStr, symbol);
                }
                else if (symbol == 'e' || symbol == 'E') {
                    state = SS_DoubleExponent;
                    stringPush(tokenStr, symbol);
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    double d = stringToDouble(tokenStr);
                    deleteString(tokenStr);
                    token->d = d;
                    token->type = STT_Double;
                    return;
                }
                break;
            }
            case SS_DoubleExpPart: {
                if (symbol >= '0' && symbol <= '9') {
                    state = SS_DoubleExpPart;
                    stringPush(tokenStr, symbol);
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    double d = stringToDouble(tokenStr);
                    deleteString(tokenStr);
                    token->d = d;
                    token->type = STT_Double;
                    return;
                }
                break;
            }
            case SS_Divide: {
                if (symbol == '*') {
                    state = SS_BlockComment;
                }
                else if (symbol == '/') {
                    state = SS_Comment;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Divide;
                    return;
                }
                break;
            }
            case SS_BlockComment: {
                if (symbol == '*') {
                    state = SS_BlockCommentFinish;
                }
                else if (symbol == EOF) {
                    setError(ERR_LexFile);
                    return;
                }
                else {
                    state = SS_BlockComment;
                }
                break;
            }
            case SS_BlockCommentFinish: {
                if (symbol == '/') {
                    state = SS_Empty;
                }
                else if (symbol == EOF) {
                    setError(ERR_LexFile);
                    return;
                }
                else {
                    state = SS_BlockComment;
                    lastChar = symbol;
                    charStreamSwitch = 0;
                }
                break;
            }
            case SS_Comment: {
                if (symbol == '\n') {
                    state = SS_Empty;
                }
                else if (symbol == EOF) {
                    token->type = STT_EOF;
                    return;
                }
                else {
                    state = SS_Comment;
                }
                break;
            }
            case SS_Equal: {
                if (symbol == '=') {
                    token->type = STT_Equal;
                    return;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    setError(ERR_LexFile);
                    return;
                }
            }
            case SS_Exclamation: {
                if (symbol == '=') {
                    state = SS_NotEqual;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    token->type = STT_Not;
                    return;
                }
                break;
            }
            case SS_NotEqual: {
                if (symbol == '=') {
                    token->type = STT_NotEqual;
                    return;
                }
                else {
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    setError(ERR_LexFile);
                    return;
                }
            }
            case SS_String: {
                if (symbol == '"') {
                    token->type = STT_String;
                    return;
                }
                else if (symbol == EOF) {
                    deleteString(tokenStr);
                    setError(ERR_LexFile);
                    return;
                }
                else {
                    if (symbol >= MIN_STRING_CHAR_ASCII && symbol != '$') {
                        if (symbol == '\\') {
                            state = SS_StringEscape;
                        }
                        else {
                            state = SS_String;
                            stringPush(tokenStr, symbol);
                        }
                    }
                    else {
                        deleteString(tokenStr);
                        setError(ERR_LexFile);
                        return;
                    }
                }
                break;
            }
            case SS_StringEscape: {
                switch (symbol) {
                    case 'x': {
                        state = SS_StringEscapeHex0;
                        break;
                    }
                    case '$': {
                        state = SS_String;
                        stringPush(tokenStr, symbol);
                        break;
                    }
                    case 'n': {
                        state = SS_String;
                        stringPush(tokenStr, '\n');
                        break;
                    }
                    case 't': {
                        state = SS_String;
                        stringPush(tokenStr, '\t');
                        break;
                    }
                    case '\"': {
                        state = SS_String;
                        stringPush(tokenStr, '\"');
                        break;
                    }
                    case '\\': {
                        state = SS_String;
                        stringPush(tokenStr, '\\');
                        break;
                    }
                    default: {
                        if (symbol < MIN_STRING_CHAR_ASCII) {
                            setError(ERR_LexFile);
                            return;
                        }

                        state = SS_String;
                        stringPush(tokenStr, '\\');
                        stringPush(tokenStr, symbol);
                        break;
                    }
                }
                break;
            }
            case SS_StringEscapeHex0: {
                if (symbol >= '0' && symbol <= '9') {
                    hexCode = symbol - '0';
                    state = SS_StringEscapeHex1;
                }
                else if (symbol >= 'A' && symbol <= 'F') {
                    hexCode = symbol - 'A' + 10;
                    state = SS_StringEscapeHex1;
                }
                else if (symbol >= 'a' && symbol <= 'f') {
                    hexCode = symbol - 'a' + 10;
                    state = SS_StringEscapeHex1;
                }
                else {
                    stringPush(tokenStr, '\\');
                    stringPush(tokenStr, 'x');
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    state = SS_String;
                }
                hexCodeBackup = symbol;
                break;
            }
            case SS_StringEscapeHex1: {
                if (symbol >= '0' && symbol <= '9') {
                    hexCode = (hexCode << 4) + (symbol - '0');
                    stringPush(tokenStr, hexCode);
                    state = SS_String;
                }
                else if (symbol >= 'A' && symbol <= 'F') {
                    hexCode = (hexCode << 4) + (symbol - 'A' + 10);
                    stringPush(tokenStr, hexCode);
                    state = SS_String;
                }
                else if (symbol >= 'a' && symbol <= 'f') {
                    hexCode = (hexCode << 4) + (symbol - 'a' + 10);
                    stringPush(tokenStr, hexCode);
                    state = SS_String;
                }
                else {
                    stringPush(tokenStr, '\\');
                    stringPush(tokenStr, 'x');
                    stringPush(tokenStr, hexCodeBackup);
                    lastChar = symbol;
                    charStreamSwitch = 0;
                    state = SS_String;
                }
                break;
            }
            case SS_Php_0: {
                if (symbol == 'p') {
                    state = SS_Php_1;
                }
                else {
                    setError(ERR_Syntax);
                    return;
                }
                break;
            }
            case SS_Php_1: {
                if (symbol == 'h') {
                    state = SS_Php_2;
                }
                else {
                    setError(ERR_Syntax);
                    return;
                }
                break;
            }
            case SS_Php_2: {
                if (symbol == 'p') {
                    state = SS_Php_3;
                }
                else {
                    setError(ERR_Syntax);
                    return;
                }
                break;
            }
            case SS_Php_3: {
                if (isspace(symbol)) {
                    token->type = STT_Php;
                    return;
                }
                else {
                    setError(ERR_Syntax);
                    return;
                }
            }
            case SS_And:
                if (symbol != '&') {
                    setError(ERR_LexFile);
                    return;
                }

                token->type = STT_And;
                return;
            case SS_Or:
                if (symbol != '|') {
                    setError(ERR_LexFile);
                    return;
                }

                token->type = STT_Or;
                return;
        }
    }
}
Example #3
0
void ATOM_Edit::onKeyDown(ATOM_WidgetKeyDownEvent *event)
{
	ATOM_STACK_TRACE(ATOM_Edit::onKeyDown);

	// 只读情况,不允许输入
	if(EDITTYPE_READONLY & _editType)
	{
		return;
	}

	switch(event->key)
	{
	case KEY_LEFT:
		moveCursor(-1);
		break;

	case KEY_RIGHT:
		moveCursor(1);
		break;

	case KEY_DELETE:
		deleteChar();
		break;

	case KEY_HOME:
		moveCursor(-getStringLength());
		break;

	case KEY_END:
		moveCursor(getStringLength());
		break;

	case KEY_UP:
	case KEY_DOWN:
	case KEY_RETURN:
	case KEY_KP_ENTER:
	case KEY_TAB:
	case KEY_ESCAPE:
	case KEY_SPACE:
	case KEY_COLON:
		{
			ATOM_EditSysKeyEvent keyevent(getId(), event->key);
			_parent->handleEvent(&keyevent);
		}
		break;

	case KEY_v:
		if(GetAsyncKeyState(VK_LCONTROL) &0x8000 || GetAsyncKeyState(VK_RCONTROL) &0x8000)
		{
			pasteFromClipBoard();
		}
		break;
	case KEY_a:
		if(GetAsyncKeyState(VK_LCONTROL) &0x8000 || GetAsyncKeyState(VK_RCONTROL) &0x8000)
		{
			setCursor(_startPosition+_string.size());
			_cusorOldPosition.x = _offsetX;
			_cusorOldPosition.y = 0;
			_cusorNewPosition = _cursorPosition;
		}
		break;
	case KEY_c:
		if(GetAsyncKeyState(VK_LCONTROL) &0x8000|| GetAsyncKeyState(VK_RCONTROL)&0x8000)
		{	
			size_t s = 0,t = 0;
			_selectString = getSelectString(s,t);
			if(_selectString.empty())
				return;
			if(OpenClipboard(NULL))
			{

				HGLOBAL hmem=GlobalAlloc(GHND,_selectString.size()+1);
				char *pmem=(char*)GlobalLock(hmem);

				EmptyClipboard();
				memcpy(pmem,_selectString.c_str(),_selectString.size());
				SetClipboardData(CF_TEXT,hmem);
				CloseClipboard();
				GlobalFree(hmem); 
			}
		}
		break;
	case KEY_x:
		if(GetAsyncKeyState(VK_LCONTROL)&0x8000 || GetAsyncKeyState(VK_RCONTROL)&0x8000)
		{
			size_t s = 0,t = 0;
			_selectString = getSelectString(s,t);
			deleteString(s,t);
			if(_selectString.empty())
				return;
			if(OpenClipboard(NULL))
			{

				HGLOBAL hmem=GlobalAlloc(GHND,_selectString.size()+1);
				char *pmem=(char*)GlobalLock(hmem);

				EmptyClipboard();
				memcpy(pmem,_selectString.c_str(),_selectString.size());
				SetClipboardData(CF_TEXT,hmem);
				CloseClipboard();
				GlobalFree(hmem); 
			}
		}
		break;
	}
	if(_parent)
	{
		_parent->queueEvent (ATOM_NEW(ATOM_WidgetKeyDownEvent, getId(),event->key,event->keymod), ATOM_APP);
	}
}
Example #4
0
void Lz77::compress(ByteStream &in, BitStream &out)
{
	uint32 i;
	uint32 lookAheadBytes;
	uint32 curPosition = 1;
	uint32 replaceCount;
	uint32 matchLength = 0;
	uint32 matchPosition = 0;
	byte   c;
	bool   eos;

	if (!tree)
		tree = new Node[windowSize + 1];

	initWindow();
	initTree(curPosition);

	for (i = 0; i < lookAheadSize; i++)
	{
		eos = in.input(&c);

		if (eos)
		{
			break;
		}

		window[curPosition + i] = c;
	}

	lookAheadBytes = i;

	while (lookAheadBytes > 0)
	{
		if (matchLength > lookAheadBytes)
		{
			matchLength = lookAheadBytes;
		}

		if (matchLength <= breakEven)
		{
			replaceCount = 1;
			out.outputBits(1,1);
			out.outputBits(window[curPosition],8);
		}
		else
		{
			out.outputBits(0,1);
			out.outputBits(matchPosition, indexBitCount);
			out.outputBits(matchLength - (breakEven + 1), lengthBitCount);
			replaceCount = matchLength;
		}

		for (i = 0; i < replaceCount; i++)
		{
			deleteString(modWindow(curPosition + lookAheadSize));

			eos = in.input(&c);

			if (eos)
			{
				lookAheadBytes--;
			}
			else
			{
				window[modWindow(curPosition + lookAheadSize)] = c;
			}

			curPosition = modWindow(curPosition + 1);

			if (lookAheadBytes)
			{
				matchLength = addString(curPosition, &matchPosition);
			}
		}
	}

	out.outputBits(0,1);
	out.outputBits(endOfStream, indexBitCount);
	out.outputRack();
}
Example #5
0
 bool deleteText(const char* context, const char* key) {
   return deleteString(context, key);
 }
Example #6
0
int proxyServerLoadResponse(ProxyServer *p, const char *uniqueId,
        ResponseRecord *rec) {

	reset_response_record(rec);

	char file_name[512];
	struct stat stat_buf;
	snprintf(file_name, sizeof(file_name), "%s/%s.res",
		stringAsCString(p->persistenceFolder), uniqueId);

	rec->fd = open(file_name, O_RDONLY);
	DIE(p, rec->fd, "Failed to open response file.");

	int status = fstat(rec->fd, &stat_buf);
	DIE(p, status, "Failed to get response file size.");

	rec->map.length = stat_buf.st_size; //Save the size

	//If file size is 0 then just return
	if (rec->map.length == 0) {
		return 0;
	}

	rec->map.buffer = mmap(NULL, stat_buf.st_size, PROT_READ,
		MAP_SHARED, rec->fd, 0);
	if (rec->map.buffer == MAP_FAILED) {
		DIE(p, -1, "Failed to map response file.");
	}

	//We are good to go. Start parsing header.
	String *str = newString();
	int state = PARSE_PROTOCOL_VERSION;
	for (size_t i = 0; i < rec->map.length; ++i) {
		char ch = rec->map.buffer[i];

		//printf("[%c %d]", ch, state);
		if (ch == '\r') {
			continue; //Ignored
		}

		if (state == PARSE_PROTOCOL_VERSION) {
			if (ch == ' ') {
				state = PARSE_STATUS_CODE;
				continue;
			}
			//Don't store version
			continue;
		}
		if (state == PARSE_STATUS_CODE) {
			if (ch == ' ') {
				state = PARSE_STATUS_MESSAGE;
				continue;
			}
			stringAppendChar(rec->statusCode, ch);
			continue;
		}
		if (state == PARSE_STATUS_MESSAGE) {
			if (ch == '\n') {
				state = PARSE_HEADER_NAME;
				continue;
			}
			stringAppendChar(rec->statusMessage, ch);
			continue;
		}
		if (state == PARSE_HEADER_NAME) {
			if (ch == ':') {
				arrayAdd(rec->headerNames, 
					newStringWithString(str));
				str->length = 0;
				state = PARSE_HEADER_VALUE;
				continue;
			}
			if (ch == '\n') {
				//End of request headers
				rec->headerBuffer.buffer = 
					rec->map.buffer;
				rec->headerBuffer.length = i + 1;

				rec->bodyBuffer.buffer =
					rec->map.buffer + i + 1;
				rec->bodyBuffer.length = 
					rec->map.length - 
					rec->headerBuffer.length;
				
				//End parsing for now
				break;
			}
			stringAppendChar(str, ch);
			continue;
		}
		if (state == PARSE_HEADER_VALUE) {
			if (ch == '\n') {
				arrayAdd(rec->headerValues, 
					newStringWithString(str));
				str->length = 0;
				state = PARSE_HEADER_NAME;
				continue;
			}
			if ((str->length == 0) && ch == ' ') {
				//Skip leading space.
				continue;
			}
			stringAppendChar(str, ch);
			continue;
		}
	}
	
	deleteString(str);

	//It is safe to close the file now. It will 
	//closed anyway by reset method. 
	close(rec->fd);
	rec->fd = -1;

	return 0;
}
Example #7
0
int proxyServerLoadRequest(ProxyServer *p, const char *uniqueId,
        RequestRecord *rec) {

	reset_request_record(rec);

	char file_name[512];
	struct stat stat_buf;
	snprintf(file_name, sizeof(file_name), "%s/%s.req",
		stringAsCString(p->persistenceFolder), uniqueId);

	rec->fd = open(file_name, O_RDONLY);
	DIE(p, rec->fd, "Failed to open request file.");

	int status = fstat(rec->fd, &stat_buf);
	DIE(p, status, "Failed to get request file size.");

	rec->map.length = stat_buf.st_size; //Save the size

	//If file size is 0 then just return
	if (rec->map.length == 0) {
		return 0;
	}

	rec->map.buffer = mmap(NULL, stat_buf.st_size, PROT_READ,
		MAP_SHARED, rec->fd, 0);
	if (rec->map.buffer == MAP_FAILED) {
		DIE(p, -1, "Failed to map request file.");
	}

	//We are good to go. Start parsing.
	String *str = newString();
	int state = PARSE_METHOD;
	for (size_t i = 0; i < rec->map.length; ++i) {
		char ch = rec->map.buffer[i];

		//printf("[%c %d]", ch, state);
		if (ch == '\r') {
			continue; //Ignored
		}
		if (state == PARSE_METHOD) {
			if (ch == ' ') {
				if (strcmp("CONNECT", 
					stringAsCString(rec->method)) == 0) {
					state = PARSE_CONNECT_ADDRESS;
				} else {
					state = PARSE_PATH;
				}
				continue;
			}
			stringAppendChar(rec->method, ch);
			continue;
		}
		if (state == PARSE_PATH) {
			if (ch == '?') {
				state = PARSE_QUERY_STRING;
				continue;
			}
			if (ch == ' ') {
				state = PARSE_PROTOCOL_VERSION;
				continue;
			}
			stringAppendChar(rec->path, ch);
			continue;
		}
		if (state == PARSE_QUERY_STRING) {
			if (ch == ' ') {
				state = PARSE_PROTOCOL_VERSION;
				continue;
			}
			stringAppendChar(rec->queryString, ch);
			continue;
		}
		if (state == PARSE_PROTOCOL_VERSION) {
			if (ch == '\n') {
				state = PARSE_HEADER_NAME;
				continue;
			}
			//Don't store version
			continue;
		}
		if (state == PARSE_CONNECT_ADDRESS) {
			if (ch == ' ') {
				state = PARSE_PROTOCOL_VERSION;
				continue;
			}
			//Don't store address
			continue;
		}
		if (state == PARSE_HEADER_NAME) {
			if (ch == ':') {
				arrayAdd(rec->headerNames, 
					newStringWithString(str));
				str->length = 0;
				state = PARSE_HEADER_VALUE;
				continue;
			}
			if (ch == '\n') {
				//End of request headers
				rec->headerBuffer.buffer = 
					rec->map.buffer;
				rec->headerBuffer.length = i + 1;

				rec->bodyBuffer.buffer =
					rec->map.buffer + i + 1;
				rec->bodyBuffer.length = 
					rec->map.length - 
					rec->headerBuffer.length;
				
				//End parsing for now
				break;
			}
			stringAppendChar(str, ch);
			continue;
		}
		if (state == PARSE_HEADER_VALUE) {
			if (ch == '\n') {
				arrayAdd(rec->headerValues, 
					newStringWithString(str));
				str->length = 0;
				state = PARSE_HEADER_NAME;
				continue;
			}
			if ((str->length == 0) && ch == ' ') {
				//Skip leading space.
				continue;
			}
			stringAppendChar(str, ch);
			continue;
		}
	}
	
	deleteString(str);

	//Parse URL parameters
	parse_url_params(rec->queryString->buffer, rec->queryString->length, 
		rec->parameterNames, rec->parameterValues);

	//If form post then parse request body for parameters
	String *contentType = get_header_value(CONTENT_TYPE, rec);
	if (contentType != NULL && 
	    stringEqualsCString(contentType, FORM_ENC) &&
	    rec->bodyBuffer.length > 0) {
		parse_url_params(rec->bodyBuffer.buffer, 
			rec->bodyBuffer.length, 
			rec->parameterNames, 
			rec->parameterValues);
	}

	//It is safe to close the file now. It will 
	//closed anyway by reset method. 
	close(rec->fd);
	rec->fd = -1;

	return 0;
}
Example #8
0
FinishLocation::~FinishLocation()
{
	deleteString(m_name);
	deleteString(m_description);
}
Example #9
0
Challenge::~Challenge()
{
	deleteString(m_description);
}
Example #10
0
static void enterProps(const char *s) {
  curProp = addGroup(curObj, s);
  deleteString((char *)s);
}