static void test_five_headers(void) { SXE_HTTP_MESSAGE message; unsigned line_len; tap_test_case_name("Five Headers - Normal Long Normal Long-With-Continuations Normal"); max_buffer_size = 70; memset(message_headers, 0, sizeof(message_headers)); snprintf(message_headers, sizeof(message_headers), "\r\n%s: %s\r\n%s: %s\r\n%s: %s\r\n%s: %s\r\n CONTINUE_LINE1\r\n\tCONTINUE_LINE2\r\n%s: %s\r\n\r\n", HEADER(1), VALUE(1), HEADER(2), LONG_VALUE(2), HEADER(333), VALUE(3333), LONG_HEADER(4), VALUE(4), HEADER(55), VALUE(5)); sxe_http_message_construct(&message, message_headers, max_buffer_size); line_len = strlen(message_headers); diag("Five Headers: The header is %u bytes, the max buffer size is %u bytes", line_len, max_buffer_size); is(sxe_http_message_parse_next_line_element(&message, SXE_HTTP_LINE_ELEMENT_TYPE_END_OF_LINE), SXE_RETURN_END_OF_FILE, "Parsed message request line"); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_OK, "Get header 1"); is(message.ignore_length, 0, "No ignore"); is(message.ignore_length, 0, "Ignore length is 0"); is_strncmp(sxe_http_message_get_header_name(&message), HEADER(1), strlen(HEADER(1)), "Name is " HEADER(1)); is(sxe_http_message_get_header_name_length(&message), strlen(HEADER(1)), "Name length is %u", (unsigned)strlen(HEADER(1))); is_strncmp(sxe_http_message_get_header_value(&message), VALUE(1), strlen(VALUE(1)), "Value is " VALUE(1)); is(sxe_http_message_get_header_value_length(&message), strlen(VALUE(1)), "Value length is %u", (unsigned)strlen(VALUE(1))); /* Don't do any consume since last sxe_http_message_parse_next_header() returns OK */ is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(message.ignore_length, 0, "No ignore"); /* 21 == 2 + strlen(HEADER(1)) + 2 + strlen(VALUE(1)) + 2 */ is(sxe_http_message_consume_parsed_headers(&message), 21, "Consuming the request line and header 1"); /* Simulate sxe_buf_consume() */ memmove(message_headers, &message_headers[21], sizeof(message_headers) - 21); diag("Five Headers: Consumed 21 bytes"); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(sxe_http_message_consume_parsed_headers(&message), 0, "Buffer is full"); /* Start ignoring */ memmove(message_headers, &message_headers[max_buffer_size], sizeof(message_headers) - max_buffer_size); diag("Five Headers: Consumed %u bytes", max_buffer_size); message.ignore_line = 1; sxe_http_message_increase_buffer_length(&message, max_buffer_size); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(message.ignore_line, 0, "Ignore buffer flag is clear, since found the end of long header 2"); /* 55 = strlen(HEADER(2)) + 2 + strlen(LONG_VALUE(2)) + 2 - 70 */ is(message.ignore_length, 55, "Ignore length is right"); memmove(message_headers, &message_headers[55], sizeof(message_headers) - 55); diag("Five Headers: Consumed 55 bytes"); sxe_http_message_increase_buffer_length(&message, max_buffer_size); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_OK, "Get normal header 3"); is(message.ignore_length, 0, "No ignore"); is_strncmp(sxe_http_message_get_header_name(&message), HEADER(333), strlen(HEADER(333)), "Name is " HEADER(333)); is(sxe_http_message_get_header_name_length(&message), strlen(HEADER(333)), "Name length is %u", (unsigned)strlen(HEADER(333))); is_strncmp(sxe_http_message_get_header_value(&message), VALUE(3333), strlen(VALUE(3333)), "Value is " VALUE(3333)); is(sxe_http_message_get_header_value_length(&message), strlen(VALUE(3333)), "Value length is %u", (unsigned)strlen(VALUE(3333))); /* Don't do any consume since last sxe_http_message_parse_next_header() returns OK */ is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(message.ignore_length, 0, "No ignore"); /* 24 == strlen(HEADER(333)) + 2 + strlen(VALUE(3333)) + 2 */ is(sxe_http_message_consume_parsed_headers(&message), 24, "Consuming the header 3"); /* Simulate sxe_buf_consume() */ memmove(message_headers, &message_headers[24], sizeof(message_headers) - 24); diag("Five Headers: Consumed 24 bytes"); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(sxe_http_message_consume_parsed_headers(&message), 0, "Buffer is full"); /* Start ignoring */ memmove(message_headers, &message_headers[max_buffer_size], sizeof(message_headers) - max_buffer_size); diag("Five Headers: Consumed %u bytes", max_buffer_size); message.ignore_line = 1; sxe_http_message_increase_buffer_length(&message, max_buffer_size); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header 4"); is(message.ignore_line, 1, "Ignore buffer flag is set, the end of long header 4 not found yet"); /* 55 = strlen(HEADER(2)) + 2 + strlen(LONG_VALUE(2)) + 2 - 70 */ is(message.ignore_length, max_buffer_size, "Ignore length is right"); memmove(message_headers, &message_headers[max_buffer_size], sizeof(message_headers) - max_buffer_size); diag("Five Headers: Consumed %u bytes", max_buffer_size); /* 41 = 351(line_len) - 21 - 55 - 24 - 3 * 210 */ sxe_http_message_increase_buffer_length(&message, 41); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header 4"); is(message.ignore_line, 0, "Ignore buffer flag is set, the end of long header 4 not found yet"); /* 19 = strlen("\r\n\tCONTINUE_LINE2\r\n") */ is(message.ignore_length, 19, "Ignore length is right"); memmove(message_headers, &message_headers[19], sizeof(message_headers) - 19); diag("Five Headers: Consumed 19 bytes, the left part of long header 4"); /* 22 = 41 - 19 */ sxe_http_message_increase_buffer_length(&message, 22); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_OK, "Get the header 5"); is(message.ignore_line, 0, "Ignore buffer flag is clear"); is(message.ignore_length, 0, "Ignore length is 0"); is_strncmp(sxe_http_message_get_header_name(&message), HEADER(55), strlen(HEADER(55)), "Name is " HEADER(55)); is(sxe_http_message_get_header_name_length(&message), strlen(HEADER(55)), "Name length is %u", (unsigned)strlen(HEADER(55))); is_strncmp(sxe_http_message_get_header_value(&message), VALUE(5), strlen(VALUE(5)), "Value is " VALUE(5)); is(sxe_http_message_get_header_value_length(&message), strlen(VALUE(5)), "Value length is %u", (unsigned)strlen(VALUE(5))); /* Don't do any consume since last sxe_http_message_parse_next_header() returns OK */ is(sxe_http_message_parse_next_header(&message), SXE_RETURN_END_OF_FILE, "Get long header"); /* 22 = strlen("HEADER-55: VALUE_5\r\n\r\n") */ is(sxe_http_message_consume_parsed_headers(&message), 22, "Consumed the rest of 22 bytes which are header 5 and eof"); }
int icqv8_downloadUserList(HICQ icq, ICQV8 *cfg, int sz, const UCHAR *pkt) { #ifdef EXTENDED_LOG char buffer[0x0100]; #endif unsigned short groups; unsigned char prefix[80]; unsigned short szString; unsigned short tag; unsigned short id; unsigned short type; unsigned short recSize; unsigned short gCount = 0; HUSER usr; /* Marca todos os usuarios como nao confirmados */ if(*pkt) { icqDumpPacket(icq, NULL, "Unexpected contact-list update", sz, (unsigned char *) pkt); return -1; } icqWriteSysLog(icq,PROJECT,"Receiving contact-list update from server"); pkt++; groups = icqv8_convertShort( *( (USHORT *) pkt ) ); DBGTrace(groups); pkt += 2; sz -= 3; for(usr = icqQueryNextUser(icq, NULL); usr; usr = icqQueryNextUser(icq, usr)) usr->c2sFlags |= USRV8_NOTCONFIRMED; while(sz > 0 && groups > 0) { szString = icqv8_convertShort( *( (USHORT *) pkt ) ); pkt += 2; sz -= 2; if(szString) { szString = min(szString,79); strncpy(prefix,pkt,szString); *(prefix+szString) = 0; pkt += szString; } else { *prefix = 0; } tag = icqv8_convertShort( *( (USHORT *) pkt ) ); pkt += 2; id = icqv8_convertShort( *( (USHORT *) pkt ) ); pkt += 2; type = icqv8_convertShort( *( (USHORT *) pkt ) ); pkt += 2; recSize = icqv8_convertShort( *( (USHORT *) pkt ) ); pkt += 2; sz -= 8; switch(type) { case 0x0000: // A normal contact list entry procUser(icq,atol(prefix),tag,id,(const struct userinfo *) pkt); break; case 0x0001: // Larger grouping header procGroup(icq, gCount++, tag, prefix); break; default: DBGTracex(tag); DBGTracex(id); DBGTracex(type); DBGTracex(recSize); icqDumpPacket(icq, NULL, prefix, recSize, (unsigned char *) pkt); } pkt += recSize; sz -= recSize; groups--; } if(sz < 4) { icqWriteSysLog(icq,PROJECT,"Unexpected size of contact-list update packet"); return -1; } if( ! *((ULONG *)pkt) ) { icqDumpPacket(icq, NULL, "Unexpected ending of contact-list update packet", sz, (unsigned char *) pkt); return -1; } else { DBGTracex(LONG_VALUE( *( (ULONG *) pkt) )); #ifdef EXTENDED_LOG sprintf(buffer,"Current update level: %08lx",LONG_VALUE( *( (ULONG *) pkt) ) ); icqWriteSysLog(icq,PROJECT,buffer); #endif // icqSaveValue(icq, "v8.modified", LONG_VALUE( *( (ULONG *) pkt) )); icqSaveValue(icq, "SSUL.Update", LONG_VALUE( *( (ULONG *) pkt) )); pkt += 4; sz -= 4; } /* Verifica os usuarios nao confirmados */ for(usr = icqQueryNextUser(icq, NULL); usr; usr = icqQueryNextUser(icq, usr)) { if(usr->c2sFlags & USRV8_NOTCONFIRMED) { // if( !(usr->flags & (USRF_TEMPORARY|USRF_DISABLED)) ) if(usr->flags & USRF_ONLIST) { icqUpdateUserFlag(icq, usr, TRUE, USRF_WAITING); icqWriteUserLog(icq,PROJECT,usr,"Not confirmed by server"); icqAjustUserIcon(icq, usr, TRUE); } } } return 0; }
static void test_long_value_with_line_continuations(void) { SXE_HTTP_MESSAGE message; unsigned line_len; tap_test_case_name("With Line Continuations"); max_buffer_size = 60; memset(message_headers, 0, sizeof(message_headers)); snprintf(message_headers, sizeof(message_headers), "\r\n%s: %s\r\n CONTINUE_LINE1\r\n\tCONTINUE_LINE2\r\n\r\n", HEADER(1), LONG_VALUE(1)); sxe_http_message_construct(&message, message_headers, max_buffer_size); line_len = strlen(message_headers); diag("With Line Continuations: The header is %u bytes, the max buffer size is %u bytes", line_len, max_buffer_size); is(sxe_http_message_parse_next_line_element(&message, SXE_HTTP_LINE_ELEMENT_TYPE_END_OF_LINE), SXE_RETURN_END_OF_FILE, "Parsed message request line"); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(sxe_http_message_consume_parsed_headers(&message), 2, "Consuming the request line"); /* Simulate sxe_buf_consume() */ memmove(message_headers, &message_headers[2], sizeof(message_headers) - 2); diag("With Line Continuations: Consumed %u bytes", 2); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(sxe_http_message_consume_parsed_headers(&message), 0, "Buffer is full"); /* Start ignoring */ memmove(message_headers, &message_headers[max_buffer_size], sizeof(message_headers) - max_buffer_size); diag("With Line Continuations: Consumed %u bytes", max_buffer_size); message.ignore_line = 1; sxe_http_message_increase_buffer_length(&message, max_buffer_size); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_WARN_WOULD_BLOCK, "Get long header"); is(message.ignore_line, 1, "Ignore buffer flag is set"); is(message.ignore_length, max_buffer_size, "Ignore length is right"); memmove(message_headers, &message_headers[max_buffer_size], sizeof(message_headers) - max_buffer_size); diag("With Line Continuations: Consumed %u bytes", max_buffer_size); sxe_http_message_increase_buffer_length(&message, line_len - 2 - 2 * max_buffer_size); is(sxe_http_message_parse_next_header(&message), SXE_RETURN_END_OF_FILE, "Get the end of line"); is(message.ignore_line, 0, "Ignore buffer flag is clear"); is(message.ignore_length, 41, "Ignore length is right"); is(sxe_http_message_consume_parsed_headers(&message), 41, "Consumed the rest of 41 bytes"); }