Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4201 → Rev 4202

/programs/develop/libraries/http/http.asm
113,9 → 113,9
;;================================================================================================;;
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
 
 
;;================================================================================================;;
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
;;================================================================================================;;
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
;;================================================================================================;;
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
.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
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,11 → 733,12
;;================================================================================================;;
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
 
736,6 → 745,9
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
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
;;================================================================================================;;
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
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,7 → 1026,9
 
ret
 
endp
 
 
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;