diff --git a/programs/develop/libraries/http/http.asm b/programs/develop/libraries/http/http.asm index 1b9fbec1bd..c0a63ac034 100644 --- a/programs/develop/libraries/http/http.asm +++ b/programs/develop/libraries/http/http.asm @@ -113,9 +113,9 @@ lib_init: ;//////////////////////////////////////////////////////////////////;; ;;================================================================================================;; proc HTTP_get URL ;///////////////////////////////////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Initiates a HTTP connection, using 'GET' method. ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> URL = pointer to ASCIIZ URL ;; ;;------------------------------------------------------------------------------------------------;; ;< eax = 0 (error) / buffer ptr ;; ;;================================================================================================;; @@ -202,11 +202,11 @@ endp ;;================================================================================================;; -proc HTTP_head URL ;///////////////////////////////////////////////////////////////////////////////;; +proc HTTP_head URL ;//////////////////////////////////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Initiates a HTTP connection, using 'HEAD' method. ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> URL = pointer to ASCIIZ URL ;; ;;------------------------------------------------------------------------------------------------;; ;< eax = 0 (error) / buffer ptr ;; ;;================================================================================================;; @@ -295,9 +295,11 @@ endp ;;================================================================================================;; proc HTTP_post URL, content_type, content_length ;////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Initiates a HTTP connection, using 'GET' method. ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> URL = pointer to ASCIIZ URL ;; +;> content_type = pointer to ASCIIZ string containing content type ;; +;> content_length = length of content (in bytes) ;; ;;------------------------------------------------------------------------------------------------;; ;< eax = 0 (error) / buffer ptr ;; ;;================================================================================================;; @@ -401,9 +403,10 @@ endp ;;================================================================================================;; proc HTTP_process identifier ;////////////////////////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Receive data from the server, parse headers and put data in receive buffer. ;; +;? To complete a transfer, this procedure must be called over and over again untill it returns 0. ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> identifier = pointer to buffer containing http_msg struct. ;; ;;------------------------------------------------------------------------------------------------;; ;< eax = -1 (not finished) / 0 finished ;; ;;================================================================================================;; @@ -601,9 +604,9 @@ endl .chunk_loop: mov ecx, [ebp + http_msg.write_ptr] sub ecx, [ebp + http_msg.chunk_ptr] - jb .need_more_data_chunked + jb .need_more_data_chunked ; TODO: use this ecx !!! -; TODO: make sure we have the complete chunkline header +; Chunkline starts here, convert the ASCII hex number into ebx mov esi, [ebp + http_msg.chunk_ptr] xor ebx, ebx .chunk_hexloop: @@ -625,20 +628,25 @@ endl jmp .chunk_hexloop .chunk_: DEBUGF 1, "got chunk of %u bytes\n", ebx +;; cmp esi, [ebp + http_msg.chunk_ptr] +;; je ; If chunk size is 0, all chunks have been received. test ebx, ebx jz .got_all_data_chunked ; last chunk, hooray! FIXME: what if it wasnt a valid hex number??? - mov edi, [ebp + http_msg.chunk_ptr] ; we'll need this in about 25 lines... - add [ebp + http_msg.chunk_ptr], ebx ; Chunkline ends with a CR, LF or simply LF - .end_of_chunkline?: ; FIXME: buffer overflow possible! + .end_of_chunkline?: cmp al, 10 je .end_of_chunkline lodsb - jmp .end_of_chunkline? + cmp edi, [ebp + http_msg.write_ptr] + jb .end_of_chunkline? + jmp .need_more_data .end_of_chunkline: +; Update chunk ptr, and remember old one + mov edi, [ebp + http_msg.chunk_ptr] + add [ebp + http_msg.chunk_ptr], ebx ; Realloc buffer, make it 'chunksize' bigger. mov eax, [ebp + http_msg.buffer_length] add eax, ebx @@ -725,17 +733,21 @@ endp ;;================================================================================================;; proc find_header_field identifier, headername ;///////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Find a header field in the received HTTP header ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> identifier = ptr to http_msg struct ;; +;> headername = ptr to ASCIIZ string containg field you want to find (must be in lowercase) ;; ;;------------------------------------------------------------------------------------------------;; -;< eax = -1 (error) / 0 ;; +;< eax = 0 (error) / ptr to content of the HTTP header field ;; ;;================================================================================================;; push ebx ecx edx esi edi DEBUGF 1, "Find header field: %s\n", [headername] mov ebx, [identifier] + test [ebx + http_msg.flags], FLAG_GOT_HEADER + jz .fail + lea edx, [ebx + http_msg.data] mov ecx, edx add ecx, [ebx + http_msg.header_length] @@ -789,16 +801,28 @@ proc find_header_field identifier, headername ;///////////////////////////////// endp -; internal procedures start here: + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Internal procedures section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + + ;;================================================================================================;; proc open_connection hostname, port ;/////////////////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Connects to a HTTP server ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> hostname = ptr to ASCIIZ hostname ;; +;> port = port (x86 byte order) ;; ;;------------------------------------------------------------------------------------------------;; -;< eax = -1 (error) / 0 ;; +;< eax = 0 (error) / socketnum ;; ;;================================================================================================;; locals @@ -869,11 +893,12 @@ endp ;;================================================================================================;; proc parse_url URL ;//////////////////////////////////////////////////////////////////////////////;; ;;------------------------------------------------------------------------------------------------;; -;? ;; +;? Split a given URL into hostname and pageaddr ;; ;;------------------------------------------------------------------------------------------------;; -;> _ ;; +;> URL = ptr to ASCIIZ URL ;; ;;------------------------------------------------------------------------------------------------;; -;< eax = -1 (error) / 0 ;; +;< eax = 0 (error) / ptr to ASCIIZ hostname ;; +;< ebx = ptr to ASCIIZ pageaddr ;; ;;================================================================================================;; locals @@ -970,9 +995,16 @@ endl endp -; in: eax = number -; edi = ptr where to store ascii -ascii_dec: +;;================================================================================================;; +proc ascii_dec ;//////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Convert eax to ASCII decimal number ;; +;;------------------------------------------------------------------------------------------------;; +;> eax = number ;; +;> edi = ptr where to write ASCII decimal number ;; +;;------------------------------------------------------------------------------------------------;; +;< / ;; +;;================================================================================================;; push -'0' mov ecx, 10 @@ -994,6 +1026,8 @@ ascii_dec: ret +endp + ;;================================================================================================;; ;;////////////////////////////////////////////////////////////////////////////////////////////////;;