Allow continuous parsing of length, rather than restarting if unfinished.

This commit is contained in:
Michael Jumper 2013-10-03 17:16:16 -07:00
parent 9910bedb4b
commit ef8a9a29e8

View File

@ -65,6 +65,7 @@ void guac_instruction_reset(guac_instruction* instruction) {
instruction->argc = 0; instruction->argc = 0;
instruction->state = GUAC_INSTRUCTION_PARSE_LENGTH; instruction->state = GUAC_INSTRUCTION_PARSE_LENGTH;
instruction->__elementc = 0; instruction->__elementc = 0;
instruction->__element_length = 0;
} }
int guac_instruction_append(guac_instruction* instr, int guac_instruction_append(guac_instruction* instr,
@ -83,7 +84,7 @@ int guac_instruction_append(guac_instruction* instr,
/* Parse element length */ /* Parse element length */
if (instr->state == GUAC_INSTRUCTION_PARSE_LENGTH) { if (instr->state == GUAC_INSTRUCTION_PARSE_LENGTH) {
int parsed_length = 0; int parsed_length = instr->__element_length;
while (bytes_parsed < length) { while (bytes_parsed < length) {
/* Pull next character */ /* Pull next character */
@ -96,7 +97,6 @@ int guac_instruction_append(guac_instruction* instr,
/* If period, switch to parsing content */ /* If period, switch to parsing content */
else if (c == '.') { else if (c == '.') {
instr->__element_length = parsed_length;
instr->__elementv[instr->__elementc++] = char_buffer; instr->__elementv[instr->__elementc++] = char_buffer;
instr->state = GUAC_INSTRUCTION_PARSE_CONTENT; instr->state = GUAC_INSTRUCTION_PARSE_CONTENT;
break; break;
@ -116,6 +116,9 @@ int guac_instruction_append(guac_instruction* instr,
return 0; return 0;
} }
/* Save length */
instr->__element_length = parsed_length;
} /* end parse length */ } /* end parse length */
/* Parse element content */ /* Parse element content */
@ -168,12 +171,9 @@ int guac_instruction_append(guac_instruction* instr,
} }
return bytes_parsed;
} /* end parse content */ } /* end parse content */
/* If unable to move past reading length, parse failed */ return bytes_parsed;
return 0;
} }