HTTP library: ignore replies with code 100, some optimizations.

git-svn-id: svn://kolibrios.org@4212 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-11-11 21:25:11 +00:00
parent 869ad0e00a
commit daa2b8868e

View File

@ -105,13 +105,13 @@ lib_init: ;//////////////////////////////////////////////////////////////////;;
invoke ini.get_str, inifile, sec_proxy, key_user, proxyUser, 256, proxyUser invoke ini.get_str, inifile, sec_proxy, key_user, proxyUser, 256, proxyUser
invoke ini.get_str, inifile, sec_proxy, key_password, proxyPassword, 256, proxyPassword invoke ini.get_str, inifile, sec_proxy, key_password, proxyPassword, 256, proxyPassword
DEBUGF 1, "HTTP library: init OK" DEBUGF 1, "HTTP library: init OK\n"
xor eax, eax xor eax, eax
ret ret
.error: .error:
DEBUGF 1, "ERROR loading libraries" DEBUGF 1, "ERROR loading libraries\n"
xor eax, eax xor eax, eax
inc eax inc eax
@ -452,48 +452,54 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
test [ebp + http_msg.flags], FLAG_CHUNKED test [ebp + http_msg.flags], FLAG_CHUNKED
jnz .chunk_loop jnz .chunk_loop
; Did we detect the header yet? ; Did we detect the (final) header yet?
test [ebp + http_msg.flags], FLAG_GOT_HEADER test [ebp + http_msg.flags], FLAG_GOT_HEADER
jnz .header_parsed jnz .header_parsed
push eax ; We havent found the (final) header yet, search for it..
.scan_again:
; We havent found the header yet, search for it.. ; eax = total number of bytes received so far
sub eax, 4 mov eax, [ebp + http_msg.write_ptr]
jl .need_more_data_pop sub eax, http_msg.data
inc eax sub eax, ebp
.scan: sub eax, [ebp + http_msg.header_length]
; edi is ptr to begin of header
lea edi, [ebp + http_msg.data]
add edi, [ebp + http_msg.header_length]
; put it in esi for next proc too
mov esi, edi
sub eax, 3
jle .need_more_data
.scan_loop:
; scan for end of header (empty line) ; scan for end of header (empty line)
cmp dword[edi], 0x0a0d0a0d ; end of header cmp dword[edi], 0x0a0d0a0d ; end of header
je .end_of_header je .end_of_header
cmp word[edi+2], 0x0a0a cmp word[edi+2], 0x0a0a ; notice the use of offset + 2, to calculate header length correctly :)
je .end_of_header je .end_of_header
inc edi inc edi
dec eax dec eax
jnz .scan jnz .scan_loop
jmp .need_more_data_pop jmp .need_more_data
.end_of_header: .end_of_header:
add edi, 4 - http_msg.data add edi, 4 - http_msg.data
sub edi, ebp sub edi, ebp
mov [ebp + http_msg.header_length], edi mov [ebp + http_msg.header_length], edi ; If this isnt the final header, we'll use this as an offset to find real header.
or [ebp + http_msg.flags], FLAG_GOT_HEADER
DEBUGF 1, "Header length: %u\n", edi DEBUGF 1, "Header length: %u\n", edi
; Ok, we have found header: ; Ok, we have found header:
cmp dword[ebp + http_msg.data], 'HTTP' cmp dword[esi], 'HTTP'
jne .invalid_header jne .invalid_header
cmp dword[ebp + http_msg.data+4], '/1.0' cmp dword[esi+4], '/1.0'
je .http_1.0 je .http_1.0
cmp dword[ebp + http_msg.data+4], '/1.1' cmp dword[esi+4], '/1.1'
jne .invalid_header jne .invalid_header
or [ebp + http_msg.flags], FLAG_HTTP11 or [ebp + http_msg.flags], FLAG_HTTP11
.http_1.0: .http_1.0:
cmp byte[ebp + http_msg.data+8], ' ' cmp byte[esi+8], ' '
jne .invalid_header jne .invalid_header
DEBUGF 1, "Header seems valid.\n"
lea esi, [ebp + http_msg.data+9] add esi, 9
xor eax, eax xor eax, eax
xor ebx, ebx xor ebx, ebx
mov ecx, 3 mov ecx, 3
@ -508,8 +514,14 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
add ebx, eax add ebx, eax
dec ecx dec ecx
jnz .statusloop jnz .statusloop
mov [ebp + http_msg.status], ebx
; Ignore "100 - Continue" headers
cmp ebx, 100
je .scan_again
DEBUGF 1, "Status: %u\n", ebx DEBUGF 1, "Status: %u\n", ebx
mov [ebp + http_msg.status], ebx
or [ebp + http_msg.flags], FLAG_GOT_HEADER
; Now, convert all header names to lowercase. ; Now, convert all header names to lowercase.
; This way, it will be much easier to find certain header fields, later on. ; This way, it will be much easier to find certain header fields, later on.
@ -589,10 +601,12 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
invoke mem.realloc, ebp, edx invoke mem.realloc, ebp, edx
or eax, eax or eax, eax
jz .no_ram_pop jz .no_ram
pop eax mov eax, [ebp + http_msg.write_ptr]
sub eax, [ebp + http_msg.header_length] sub eax, [ebp + http_msg.header_length]
sub eax, http_msg.data
sub eax, ebp
jmp .header_parsed ; hooray! jmp .header_parsed ; hooray!
.no_content: .no_content:
@ -617,8 +631,6 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
or [ebp + http_msg.flags], FLAG_CHUNKED or [ebp + http_msg.flags], FLAG_CHUNKED
DEBUGF 1, "Transfer type is: chunked\n" DEBUGF 1, "Transfer type is: chunked\n"
pop eax
; Set chunk pointer where first chunk should begin. ; Set chunk pointer where first chunk should begin.
lea eax, [ebp + http_msg.data] lea eax, [ebp + http_msg.data]
add eax, [ebp + http_msg.header_length] add eax, [ebp + http_msg.header_length]
@ -698,8 +710,7 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
cmp eax, [ebp + http_msg.content_received] cmp eax, [ebp + http_msg.content_received]
jae .got_all_data jae .got_all_data
jmp .need_more_data jmp .need_more_data
.need_more_data_pop:
pop eax
.need_more_data: .need_more_data:
popa popa
xor eax, eax xor eax, eax
@ -747,8 +758,6 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
or [ebp + http_msg.flags], FLAG_INVALID_HEADER or [ebp + http_msg.flags], FLAG_INVALID_HEADER
jmp .disconnect jmp .disconnect
.no_ram_pop:
pop eax
.no_ram: .no_ram:
DEBUGF 1, "ERROR: out of RAM\n" DEBUGF 1, "ERROR: out of RAM\n"
or [ebp + http_msg.flags], FLAG_NO_RAM or [ebp + http_msg.flags], FLAG_NO_RAM