'free' and 'stop' functions for HTTP library.

git-svn-id: svn://kolibrios.org@4205 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-11-11 11:35:18 +00:00
parent 34ecc269a0
commit 0c94d22080
3 changed files with 75 additions and 6 deletions

View File

@ -133,7 +133,7 @@ mouse:
exit: exit:
DEBUGF 1, "Exiting\n" DEBUGF 1, "Exiting\n"
mcall 68, 13, [identifier] ; free buffer invoke HTTP_free, [identifier] ; free buffer
fail: fail:
or eax, -1 ; close this program or eax, -1 ; close this program
mcall mcall
@ -208,7 +208,8 @@ library lib_http, 'http.obj', \
import lib_http, \ import lib_http, \
HTTP_get , 'get' , \ HTTP_get , 'get' , \
HTTP_process , 'process' HTTP_process , 'process' ,\
HTTP_free , 'free'
import box_lib, \ import box_lib, \
edit_box_draw, 'edit_box', \ edit_box_draw, 'edit_box', \

View File

@ -57,7 +57,7 @@ macro HTTP_init_buffer buffer, socketnum {
push socketnum push socketnum
popd [eax + http_msg.socket] popd [eax + http_msg.socket]
lea esi, [eax + http_msg.data] lea esi, [eax + http_msg.data]
mov [eax + http_msg.flags], 0 mov [eax + http_msg.flags], FLAG_CONNECTED
mov [eax + http_msg.write_ptr], esi mov [eax + http_msg.write_ptr], esi
mov [eax + http_msg.buffer_length], BUFFERSIZE - http_msg.data mov [eax + http_msg.buffer_length], BUFFERSIZE - http_msg.data
mov [eax + http_msg.chunk_ptr], 0 mov [eax + http_msg.chunk_ptr], 0
@ -413,6 +413,9 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
pusha pusha
mov ebp, [identifier] mov ebp, [identifier]
test [ebp + http_msg.flags], FLAG_CONNECTED
jz .connection_closed
; Receive some data ; Receive some data
mcall recv, [ebp + http_msg.socket], [ebp + http_msg.write_ptr], \ mcall recv, [ebp + http_msg.socket], [ebp + http_msg.write_ptr], \
[ebp + http_msg.buffer_length], MSG_DONTWAIT [ebp + http_msg.buffer_length], MSG_DONTWAIT
@ -700,7 +703,8 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
mov [ebp + http_msg.content_received], eax mov [ebp + http_msg.content_received], eax
.got_all_data: .got_all_data:
DEBUGF 1, "We got all the data! (%u bytes)\n", [ebp + http_msg.content_length] DEBUGF 1, "We got all the data! (%u bytes)\n", [ebp + http_msg.content_length]
or [ebp + http_msg.flags], FLAG_GOT_DATA or [ebp + http_msg.flags], FLAG_GOT_ALL_DATA
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket] mcall close, [ebp + http_msg.socket]
popa popa
xor eax, eax xor eax, eax
@ -712,6 +716,9 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
DEBUGF 1, "ERROR: socket error %u\n", ebx DEBUGF 1, "ERROR: socket error %u\n", ebx
or [ebp + http_msg.flags], FLAG_SOCKET_ERROR or [ebp + http_msg.flags], FLAG_SOCKET_ERROR
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket]
.connection_closed:
popa popa
xor eax, eax xor eax, eax
ret ret
@ -720,6 +727,8 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
pop eax pop eax
DEBUGF 1, "ERROR: invalid header\n" DEBUGF 1, "ERROR: invalid header\n"
or [ebp + http_msg.flags], FLAG_INVALID_HEADER or [ebp + http_msg.flags], FLAG_INVALID_HEADER
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket]
popa popa
xor eax, eax xor eax, eax
ret ret
@ -729,6 +738,8 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
.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
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket]
popa popa
xor eax, eax xor eax, eax
ret ret
@ -737,6 +748,59 @@ endp
;;================================================================================================;;
proc HTTP_free identifier ;///////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Free the http_msg structure ;;
;;------------------------------------------------------------------------------------------------;;
;> identifier = pointer to buffer containing http_msg struct. ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
pusha
mov ebp, [identifier]
test [ebp + http_msg.flags], FLAG_CONNECTED
jz .not_connected
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket]
.not_connected:
invoke mem.free, ebp
popa
ret
endp
;;================================================================================================;;
proc HTTP_stop identifier ;///////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Stops the open connection ;;
;;------------------------------------------------------------------------------------------------;;
;> identifier = pointer to buffer containing http_msg struct. ;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;================================================================================================;;
pusha
mov ebp, [identifier]
and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket]
popa
ret
endp
;;================================================================================================;; ;;================================================================================================;;
proc find_header_field identifier, headername ;///////////////////////////////////////////////////;; proc find_header_field identifier, headername ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
@ -810,6 +874,7 @@ endp
;;================================================================================================;; ;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;; ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;; ;;================================================================================================;;
@ -1079,7 +1144,9 @@ export \
HTTP_head , 'head' , \ HTTP_head , 'head' , \
HTTP_post , 'post' , \ HTTP_post , 'post' , \
find_header_field , 'find_header_field' , \ find_header_field , 'find_header_field' , \
HTTP_process , 'process' HTTP_process , 'process' , \
HTTP_free , 'free' , \
HTTP_stop , 'stop'
; HTTP_put , 'put' , \ ; HTTP_put , 'put' , \
; HTTP_delete , 'delete' , \ ; HTTP_delete , 'delete' , \

View File

@ -15,9 +15,10 @@
FLAG_HTTP11 = 1 shl 0 FLAG_HTTP11 = 1 shl 0
FLAG_GOT_HEADER = 1 shl 1 FLAG_GOT_HEADER = 1 shl 1
FLAG_GOT_DATA = 1 shl 2 FLAG_GOT_ALL_DATA = 1 shl 2
FLAG_CONTENT_LENGTH = 1 shl 3 FLAG_CONTENT_LENGTH = 1 shl 3
FLAG_CHUNKED = 1 shl 4 FLAG_CHUNKED = 1 shl 4
FLAG_CONNECTED = 1 shl 5
; error flags go into the upper word ; error flags go into the upper word
FLAG_INVALID_HEADER = 1 shl 16 FLAG_INVALID_HEADER = 1 shl 16