mirror of
https://github.com/Doczom/simple-httpd.git
synced 2025-09-23 23:53:52 +02:00
Update to 0.2.0 version
## Program interface - Added the function ``` char* find_uri_args(CONNECT_DATA* session, char* key) ``` - Added the function ``` char* find_header(CONNECT_DATA* session, char* key) ``` - Fixed a bug in ``` Get_MIME_Type ``` - Added the function ``` void close_server(); ``` ## Module interface - The initialization function and the request processing function have been changed: ``` uint32_t stdcall httpd_init(IMPORT_DATA* import, char* cmdline) ``` ```` void stdcall httpd_server(CONNECT_DATA* request_data, uint32_t pdata) ``` Added a module shutdown function for a specific uri: ``` void stdcall httpd_close(uint32_t pdata) ``` ## Modules - Added a module for testing parameter transmission during initialization ## Other - Added a build script - Added a single file for the program and modules with constants and structures
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
[MAIN]
|
||||
; server IPv4 address. Non IPv6 address
|
||||
ip=192.168.137.21
|
||||
; server port number
|
||||
port=80
|
||||
; count open connection
|
||||
conn=100
|
||||
|
||||
; 1000 - no parse http headers, raw data in CONNECT_DATA.message_body
|
||||
; This flags using for http/2.0 and other protocol execution.
|
||||
;flags=0000 ; parsing http headers
|
||||
|
||||
; directory for find files
|
||||
work_dir=/usbhd0/3/server_data
|
||||
; directory for find units(library)
|
||||
units_dir=/usbhd0/3
|
||||
|
||||
mime_file=/usbhd0/3/mime_types.bin
|
||||
|
||||
[UNITS]
|
||||
; list units
|
||||
; path = path to lib in units_dir
|
||||
test=test_unit.obj
|
||||
rasp=test_unit_2.obj
|
||||
;database/sqlite3=sqlite3_serv.obj
|
||||
;database/cvs=cvs_table_server.obj
|
||||
|
||||
; server calling function httpd_serv(CONNECT_DATA* struct_server );
|
||||
; for init unit, server calling function httpd_init(void* global_data);
|
@@ -1,70 +1,11 @@
|
||||
format MS COFF
|
||||
public @EXPORT as 'EXPORTS'
|
||||
|
||||
API_VERSION = 0x05
|
||||
FLAG_KEEP_ALIVE = 0x01
|
||||
include "macros.inc"
|
||||
|
||||
include '../module_api.inc'
|
||||
|
||||
NO_DEBUG_INPUT = 0
|
||||
include 'D:\kos\programs\macros.inc'
|
||||
|
||||
struct IMPORT_DATA
|
||||
version rd 1 ; dword for check api
|
||||
sizeof rd 1 ; size struct
|
||||
netfunc_socket rd 1
|
||||
netfunc_close rd 1
|
||||
netfunc_bind rd 1
|
||||
netfunc_accept rd 1
|
||||
netfunc_listen rd 1
|
||||
netfunc_recv rd 1
|
||||
netfunc_send rd 1
|
||||
FileInfo rd 1
|
||||
FileRead rd 1
|
||||
Alloc rd 1
|
||||
Free rd 1
|
||||
parse_http_query rd 1
|
||||
;send_resp(RESPD* ptr, char* content, uint32_t length)
|
||||
;create_resp(CONNECT_DATA* session, uint32_t flags)
|
||||
; FLAG_KEEP_ALIVE = 0x01
|
||||
; FLAG_ADD_DATE = 0x02 ;(not supported)
|
||||
; FLAG_NO_SET_CACHE = 0x04 ;(not supported)
|
||||
; FLAG_NO_CONTENT_ENCODING = 0x08 ;(not supported)
|
||||
;
|
||||
;destruct_resp(RESPD* ptr)
|
||||
;set_http_status(RESPD* ptr, uint32_t status) ; status in '200' format,
|
||||
;add_http_header(RESPD* ptr, char* ptr_header)
|
||||
;del_http_header(RESPD* ptr, char* ptr_header) ; no del std header
|
||||
;set_http_ver(RESPD* ptr, char* version) ; example: RTSP/1.1
|
||||
send_resp rd 1
|
||||
create_resp rd 1
|
||||
destruct_resp rd 1
|
||||
set_http_status rd 1
|
||||
add_http_header rd 1
|
||||
del_http_header rd 1
|
||||
set_http_ver rd 1
|
||||
|
||||
base_response rd 1
|
||||
GLOBAL_DATA rd 1
|
||||
ends
|
||||
|
||||
struct CONNECT_DATA ; 16*4 = 64 bytes
|
||||
socket dd 0 ; номер сокета подключения
|
||||
sockaddr dd 16/4 ; socaddr connection
|
||||
buffer_request dd 0 ; pointer to buffer for geting message socket
|
||||
request_size dd 0 ; size geted data from client
|
||||
end_buffer_request dd 0 ; для парсера
|
||||
buffer_response dd 0 ; pointer to buffwr for resp message
|
||||
http_method dd 0 ; указатель на строку
|
||||
http_verion dd 0 ; указатель на строку
|
||||
num_headers dd 0 ; number items in REQUEST_DATA
|
||||
http_headers dd 0 ; указатель на массив REQUEST_DATA
|
||||
uri_scheme dd 0 ; указатель на схему
|
||||
uri_authority dd 0 ; pointer to struct ?
|
||||
uri_path dd 0 ; указатель на декодированный путь к ресурсу(без параметров)
|
||||
num_uri_args dd 0 ;
|
||||
uri_arg dd 0 ; pointer to array REQUEST_DATA аргументов uri строк
|
||||
uri_fragment dd 0 ; указатель на строку
|
||||
message_body dd 0 ; указатель на тело http запроса
|
||||
ends
|
||||
|
||||
macro board_input message {
|
||||
if NO_DEBUG_INPUT = 0
|
||||
@@ -89,7 +30,7 @@ end if
|
||||
section '.flat' code readable align 16
|
||||
|
||||
unit_init:
|
||||
mov eax, -1
|
||||
xor eax, eax
|
||||
push esi edi
|
||||
mov esi, [esp + 4*2 + 4]
|
||||
mov [import_httpd], esi
|
||||
@@ -102,10 +43,10 @@ unit_init:
|
||||
shr ecx, 2 ; div 4
|
||||
rep movsd
|
||||
|
||||
xor eax, eax
|
||||
mov eax, 1 ;no zero return - unit init successful
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 4
|
||||
ret 8
|
||||
|
||||
|
||||
server_entry:
|
||||
@@ -165,7 +106,7 @@ server_entry:
|
||||
board_input 'create message'
|
||||
; create http message
|
||||
push dword 8*1024
|
||||
call [IMPORT + IMPORT_DATA.Alloc]
|
||||
call [IMPORT.Alloc]
|
||||
test eax, eax
|
||||
jz .exit
|
||||
|
||||
@@ -214,13 +155,18 @@ server_entry:
|
||||
push sceleton_resp.size
|
||||
push edi
|
||||
push dword[esi + CONNECT_DATA.socket]
|
||||
call [IMPORT + IMPORT_DATA.netfunc_send]
|
||||
call [IMPORT.netfunc_send]
|
||||
|
||||
board_input 'send'
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 8
|
||||
|
||||
server_close:
|
||||
|
||||
ret 4
|
||||
|
||||
|
||||
section '.data' data readable writable align 16
|
||||
|
||||
_10: dd 10
|
||||
@@ -263,7 +209,8 @@ text_message:
|
||||
@EXPORT:
|
||||
export \
|
||||
unit_init, 'httpd_init', \
|
||||
server_entry, 'httpd_serv'
|
||||
server_entry, 'httpd_serv',\
|
||||
server_close, 'httpd_close'
|
||||
|
||||
|
||||
IMPORT IMPORT_DATA ;
|
Binary file not shown.
100
example/test_unit4.asm
Normal file
100
example/test_unit4.asm
Normal file
@@ -0,0 +1,100 @@
|
||||
; test api 0.1.0 - get cmd path and get context unit
|
||||
format MS COFF ;<- this is lib format
|
||||
public @EXPORT as 'EXPORTS'
|
||||
|
||||
NO_DEBUG_INPUT = 0
|
||||
include "macros.inc"
|
||||
purge mov,add,sub
|
||||
include "proc32.inc"
|
||||
|
||||
include '../module_api.inc'
|
||||
|
||||
section '.flat' code readable align 16
|
||||
|
||||
unit_init:
|
||||
xor eax, eax
|
||||
push esi edi
|
||||
mov esi, [esp + 4*2 + 4]
|
||||
|
||||
cmp dword[esi + IMPORT_DATA.version], API_VERSION
|
||||
jne .exit
|
||||
|
||||
mov edi, IMPORT
|
||||
mov ecx, [esi + IMPORT_DATA.sizeof]
|
||||
shr ecx, 2 ; div 4
|
||||
rep movsd
|
||||
|
||||
; create unit context
|
||||
invoke IMPORT.Alloc, 4096 ; for cmd path
|
||||
test eax, eax
|
||||
jz .exit
|
||||
|
||||
mov dword[eax], 0
|
||||
mov esi, [esp + 4*2 + 8]
|
||||
lea edi, [eax + 4]
|
||||
test esi, esi
|
||||
jz .exit
|
||||
pushfd
|
||||
cld
|
||||
@@:
|
||||
cmp byte[esi], 0
|
||||
jz @f
|
||||
movsb
|
||||
inc dword[eax]
|
||||
jmp @b
|
||||
@@:
|
||||
popfd
|
||||
;unit init successful
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 8
|
||||
|
||||
|
||||
server_entry:
|
||||
push esi edi
|
||||
mov esi, [esp + 4*2 + 4] ; request context
|
||||
|
||||
mov edi, [esp + 4*2 + 8] ; unit context
|
||||
cmp dword[edi], 0
|
||||
je .no_cmd
|
||||
|
||||
add edi, 4
|
||||
invoke IMPORT.create_resp, esi, 0
|
||||
test eax, eax
|
||||
jz .exit
|
||||
|
||||
push eax
|
||||
invoke IMPORT.send_resp, eax, edi, [edi - 4]
|
||||
invoke IMPORT.destruct_resp ; arg in stack
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 8
|
||||
.no_cmd:
|
||||
invoke IMPORT.create_resp, esi, 0
|
||||
test eax, eax
|
||||
jz .exit
|
||||
|
||||
push eax
|
||||
invoke IMPORT.send_resp, eax, text_no_cmd, text_no_cmd.size
|
||||
invoke IMPORT.destruct_resp
|
||||
jmp .exit
|
||||
|
||||
server_close:
|
||||
|
||||
ret 4
|
||||
|
||||
|
||||
section '.data' data readable writable align 16
|
||||
|
||||
text_no_cmd:
|
||||
db 'For this unit in config not set arguments'
|
||||
.size = $ - $$
|
||||
|
||||
@EXPORT:
|
||||
export \
|
||||
unit_init, 'httpd_init', \
|
||||
server_entry, 'httpd_serv',\
|
||||
server_close, 'httpd_close'
|
||||
|
||||
|
||||
IMPORT IMPORT_DATA
|
@@ -1,72 +1,12 @@
|
||||
format MS COFF
|
||||
public @EXPORT as 'EXPORTS'
|
||||
|
||||
API_VERSION = 0x05
|
||||
FLAG_KEEP_ALIVE = 0x01
|
||||
|
||||
NO_DEBUG_INPUT = 0
|
||||
include 'D:\kos\programs\macros.inc'
|
||||
include "macros.inc"
|
||||
purge mov,add,sub
|
||||
include 'D:\kos\programs\proc32.inc'
|
||||
include "proc32.inc"
|
||||
|
||||
struct IMPORT_DATA
|
||||
version rd 1 ; dword for check api
|
||||
sizeof rd 1 ; size struct
|
||||
netfunc_socket rd 1
|
||||
netfunc_close rd 1
|
||||
netfunc_bind rd 1
|
||||
netfunc_accept rd 1
|
||||
netfunc_listen rd 1
|
||||
netfunc_recv rd 1
|
||||
netfunc_send rd 1
|
||||
FileInfo rd 1
|
||||
FileRead rd 1
|
||||
Alloc rd 1
|
||||
Free rd 1
|
||||
parse_http_query rd 1
|
||||
;send_resp(RESPD* ptr, char* content, uint32_t length)
|
||||
;create_resp(CONNECT_DATA* session, uint32_t flags)
|
||||
; FLAG_KEEP_ALIVE = 0x01
|
||||
; FLAG_ADD_DATE = 0x02 ;(not supported)
|
||||
; FLAG_NO_SET_CACHE = 0x04 ;(not supported)
|
||||
; FLAG_NO_CONTENT_ENCODING = 0x08 ;(not supported)
|
||||
;
|
||||
;destruct_resp(RESPD* ptr)
|
||||
;set_http_status(RESPD* ptr, uint32_t status) ; status in '200' format,
|
||||
;add_http_header(RESPD* ptr, char* ptr_header)
|
||||
;del_http_header(RESPD* ptr, char* ptr_header) ; no del std header
|
||||
;set_http_ver(RESPD* ptr, char* version) ; example: RTSP/1.1
|
||||
send_resp rd 1
|
||||
create_resp rd 1
|
||||
destruct_resp rd 1
|
||||
set_http_status rd 1
|
||||
add_http_header rd 1
|
||||
del_http_header rd 1
|
||||
set_http_ver rd 1
|
||||
|
||||
base_response rd 1
|
||||
GLOBAL_DATA rd 1
|
||||
ends
|
||||
|
||||
struct CONNECT_DATA ; 16*4 = 64 bytes
|
||||
socket dd 0 ; номер сокета подключения
|
||||
sockaddr dd 16/4 ; socaddr connection
|
||||
buffer_request dd 0 ; pointer to buffer for geting message socket
|
||||
request_size dd 0 ; size geted data from client
|
||||
end_buffer_request dd 0 ; для парсера
|
||||
buffer_response dd 0 ; pointer to buffwr for resp message
|
||||
http_method dd 0 ; указатель на строку
|
||||
http_verion dd 0 ; указатель на строку
|
||||
num_headers dd 0 ; number items in REQUEST_DATA
|
||||
http_headers dd 0 ; указатель на массив REQUEST_DATA
|
||||
uri_scheme dd 0 ; указатель на схему
|
||||
uri_authority dd 0 ; pointer to struct ?
|
||||
uri_path dd 0 ; указатель на декодированный путь к ресурсу(без параметров)
|
||||
num_uri_args dd 0 ;
|
||||
uri_arg dd 0 ; pointer to array REQUEST_DATA аргументов uri строк
|
||||
uri_fragment dd 0 ; указатель на строку
|
||||
message_body dd 0 ; указатель на тело http запроса
|
||||
ends
|
||||
include '../module_api.inc'
|
||||
|
||||
macro board_input message {
|
||||
if NO_DEBUG_INPUT = 0
|
||||
@@ -91,7 +31,7 @@ end if
|
||||
section '.flat' code readable align 16
|
||||
|
||||
unit_init:
|
||||
mov eax, -1
|
||||
xor eax, eax
|
||||
push esi edi
|
||||
mov esi, [esp + 4*2 + 4]
|
||||
|
||||
@@ -103,10 +43,10 @@ unit_init:
|
||||
shr ecx, 2 ; div 4
|
||||
rep movsd
|
||||
|
||||
xor eax, eax
|
||||
mov eax, 1 ;no zero return - unit init successful
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 4
|
||||
ret 8
|
||||
|
||||
|
||||
server_entry:
|
||||
@@ -193,7 +133,7 @@ server_entry:
|
||||
invoke IMPORT.destruct_resp ; arg in stack
|
||||
.exit:
|
||||
pop edi esi
|
||||
ret 4
|
||||
ret 8
|
||||
|
||||
.send_data: ; eax - ptr to buffer
|
||||
mov edi, eax
|
||||
@@ -223,7 +163,9 @@ server_entry:
|
||||
invoke IMPORT.destruct_resp, edi
|
||||
jmp .exit
|
||||
|
||||
server_close:
|
||||
|
||||
ret 4
|
||||
|
||||
section '.data' data readable writable align 16
|
||||
|
||||
@@ -258,7 +200,8 @@ btp_name:
|
||||
@EXPORT:
|
||||
export \
|
||||
unit_init, 'httpd_init', \
|
||||
server_entry, 'httpd_serv'
|
||||
server_entry, 'httpd_serv',\
|
||||
server_close, 'httpd_close'
|
||||
|
||||
|
||||
IMPORT IMPORT_DATA ;
|
Binary file not shown.
Reference in New Issue
Block a user