Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4202 → Rev 4201

/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,11 → 295,9
;;================================================================================================;;
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 ;;
;;================================================================================================;;
403,10 → 401,9
;;================================================================================================;;
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 ;;
;;================================================================================================;;
604,9 → 601,9
.chunk_loop:
mov ecx, [ebp + http_msg.write_ptr]
sub ecx, [ebp + http_msg.chunk_ptr]
jb .need_more_data_chunked ; TODO: use this ecx !!!
jb .need_more_data_chunked
 
; Chunkline starts here, convert the ASCII hex number into ebx
; TODO: make sure we have the complete chunkline header
mov esi, [ebp + http_msg.chunk_ptr]
xor ebx, ebx
.chunk_hexloop:
628,25 → 625,20
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?:
.end_of_chunkline?: ; FIXME: buffer overflow possible!
cmp al, 10
je .end_of_chunkline
lodsb
cmp edi, [ebp + http_msg.write_ptr]
jb .end_of_chunkline?
jmp .need_more_data
jmp .end_of_chunkline?
 
.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
733,12 → 725,11
;;================================================================================================;;
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 = 0 (error) / ptr to content of the HTTP header field ;;
;< eax = -1 (error) / 0 ;;
;;================================================================================================;;
push ebx ecx edx esi edi
 
745,9 → 736,6
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]
801,28 → 789,16
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 = 0 (error) / socketnum ;;
;< eax = -1 (error) / 0 ;;
;;================================================================================================;;
 
locals
893,12 → 869,11
;;================================================================================================;;
proc parse_url URL ;//////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Split a given URL into hostname and pageaddr ;;
;? ;;
;;------------------------------------------------------------------------------------------------;;
;> URL = ptr to ASCIIZ URL ;;
;> _ ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (error) / ptr to ASCIIZ hostname ;;
;< ebx = ptr to ASCIIZ pageaddr ;;
;< eax = -1 (error) / 0 ;;
;;================================================================================================;;
 
locals
995,16 → 970,9
endp
 
 
;;================================================================================================;;
proc ascii_dec ;//////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Convert eax to ASCII decimal number ;;
;;------------------------------------------------------------------------------------------------;;
;> eax = number ;;
;> edi = ptr where to write ASCII decimal number ;;
;;------------------------------------------------------------------------------------------------;;
;< / ;;
;;================================================================================================;;
; in: eax = number
; edi = ptr where to store ascii
ascii_dec:
 
push -'0'
mov ecx, 10
1026,9 → 994,7
 
ret
 
endp
 
 
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;