diff --git a/example/test_unit.asm b/example/test_unit.asm new file mode 100644 index 0000000..cb275ea --- /dev/null +++ b/example/test_unit.asm @@ -0,0 +1,209 @@ +format MS COFF +public @EXPORT as 'EXPORTS' + +include 'D:\kos\programs\macros.inc' + +struct EXPORT_DATA + 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 + + 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 { + local ..str, ..end + push eax ebx ecx esi + mov esi, ..str +@@: + mov cl, [esi] + mcall 63, 1 + inc esi + + cmp cl, 10 + jne @b + jmp ..end +..str: + db message,13, 10 +..end: + pop esi ecx ebx eax +} + +section '.flat' code readable align 16 + +unit_init: + + mov eax, [esp + 4] + mov [import_httpd], eax + + xor eax, eax + ret 4 + +server_entry: + push esi edi + mov esi, [esp + 4*2 + 4] + ; work + board_input 'first' + inc dword[count_call] + + cmp [esi + CONNECT_DATA.num_uri_args], 1 + jb .no_args + + mov eax, [esi + CONNECT_DATA.uri_arg] + + mov ecx, [eax] + cmp dword[ecx], 'cmd' + jne .no_args + mov edx, [eax + 4] + cmp dword[edx], 'new' + je .no_del + + cmp dword[edx], 'del' + + mov dword[text_message], ' ' + mov dword[text_message + 4], ' ' + mov dword[text_message + 8], ' ' + mov dword[text_message + 12], ' ' + jmp .no_args + +.no_del: + cmp [esi + CONNECT_DATA.num_uri_args], 2 + jb .no_args + + mov ecx, [eax + 8] + cmp dword[ecx], 'txt' + jne .no_args + + push esi edi + mov esi, [eax + 12] + mov edi, text_message + mov ecx, text_message.size +@@: + movsb + dec ecx + jz @f + cmp byte[esi - 1], 0 + jne @b +@@: + pop edi esi +.no_args: + board_input 'create message' + ; create http message + push dword 8*1024 + mov eax, [import_httpd] + call [eax + EXPORT_DATA.Alloc] + test eax, eax + jz .exit + + push esi edi + mov ecx, sceleton_resp.size + mov esi, sceleton_resp + mov edi, eax + rep movsd + pop edi esi + + mov [esi + CONNECT_DATA.buffer_response], eax + ; copy message + mov ecx, [text_message] + mov [eax + sceleton_resp.message], ecx + mov ecx, [text_message + 4] + mov [eax + sceleton_resp.message + 4], ecx + mov ecx, [text_message + 8] + mov [eax + sceleton_resp.message + 8], ecx + mov ecx, [text_message + 12] + mov [eax + sceleton_resp.message + 12], ecx + ; copy count_call + mov edi, eax + xor edx, edx + mov eax, [count_call] + div dword[_10] + add byte[edi + sceleton_resp.count + 2], dl + + ; set httpcode + mov dword[edi + sceleton_resp.code], '200 ' + ; send http message + mov ecx, [import_httpd] + + push dword 0 ; flags + push sceleton_resp.size + push edi + push dword[esi + CONNECT_DATA.socket] + call [ecx + EXPORT_DATA.netfunc_send] + + board_input 'send' +.exit: + pop edi esi + ret 4 + +section '.data' data readable writable align 16 + +_10: dd 10 + +count_call dd 0 + +import_httpd: dd 0 + +sceleton_resp: + db 'HTTP/1.0 ' +.code = $ - sceleton_resp + db '000 ',13, 10 + db 'Server: simple-httpd/0.0.1', 13, 10 + db 'Cache-Control: no-cache', 13, 10 + db 'Content-Encoding: identity', 13, 10 + db 'Content-length: ' + db '0336', 13, 10 + db 'Content-type: text/html ', 13, 10; + db 'Connection: close', 13, 10 + db 13, 10 + db '' + db 'Test Server' + db '' + db '' + db '' + db '
Данные с сервера
Name' + db 'Info ' + db '
Количество запросов ' +.count = $ - sceleton_resp + db '000
Сообщение ' +.message = $ - sceleton_resp + db '
' +.size = $ - sceleton_resp + + +text_message: + db ' ' +.size = $ - text_message + +@EXPORT: +export \ + unit_init, 'httpd_init', \ + server_entry, 'httpd_serv' diff --git a/example/test_unit.obj b/example/test_unit.obj new file mode 100644 index 0000000..9c360f3 Binary files /dev/null and b/example/test_unit.obj differ diff --git a/file_server.inc b/file_server.inc index 032a2c4..2f21adc 100644 --- a/file_server.inc +++ b/file_server.inc @@ -249,30 +249,25 @@ file_server: ; char* stdcall Get_MIME_Type(FILED* fd); //path is ASCIIZ string Get_MIME_Type: push esi edi + mov eax, [esp + 4*2 + 4] + mov eax, [eax + FILED.end_path] mov edx, [GLOBAL_DATA.MIME_types_arr] - mov esi, [esp + 4*2 + 4] - sub edx, 8 -.next: - add edx, 8 - mov ecx, [esi + FILED.end_path] ;pointer to \0 full path - - cmp dword[edx], 0 - jz .found - - mov edi, [edx] - movzx eax, byte[edi] - sub ecx, eax @@: - inc edi - mov al, [edi] - cmp byte[ecx], al - jne .next - - inc ecx - test al, al - jne @b - -.found: - mov eax, [edx + 4] - pop edi esi + mov esi, [edx] + add edx, 4 + cmp dword[esi], 0 + jz .other + + mov edi, eax + movzx ecx, byte [esi] + inc esi + sub edi, ecx + repe cmpsb + jne @b +@@: + mov eax, esi + pop edi esi ret 4 +.other: + add esi, 4 + jmp @b \ No newline at end of file diff --git a/httpd.asm b/httpd.asm index 33cd00c..edf2288 100644 --- a/httpd.asm +++ b/httpd.asm @@ -4,16 +4,19 @@ ; ; ; httpd - Simple http server for Kolibri OS. ; ; ; -; Version 0.0.1, 12 November 2023 ; +; Version 0.0.3, 12 November 2023 ; ; ; ;*****************************************************************************; ;include "macros.inc" -include 'D:\kos\programs\macros.inc' -;include 'D:\kos\programs\network.inc' use32 org 0 db 'MENUET01' dd 1, START, I_END, MEM, STACKTOP, PATH, 0 +include 'D:\kos\programs\macros.inc' +purge mov,add,sub +include 'D:\kos\programs\proc32.inc' +include 'D:\kos\programs\dll.inc' +;include 'D:\kos\programs\network.inc' ;KOS_APP_START include 'sys_func.inc' @@ -24,6 +27,11 @@ START: mcall 68, 11 ; init heap mcall 40, EVM_STACK ;set event bitmap + ; init library + stdcall dll.Load, @IMPORT + test eax, eax + jnz .err_settings + mov ecx, PATH cmp byte[ecx],0 jnz @f @@ -142,15 +150,38 @@ thread_connect: call parse_http_query ; ecx - buffer test eax, eax jz .err_parse - ; вызов нужной функции из списка моделей - - ; TODO + ; вызов нужной функции из списка модулей + cmp dword[GLOBAL_DATA.units], 0 + jz .no_units + mov eax, [GLOBAL_DATA.units] +.next_unit: + push esi edi + mov esi, [esi + CONNECT_DATA.uri_path] + lea edi, [eax + 4*3] +@@: + cmpsb + jne @f + cmp byte[edi - 1], 0 + jne @b + ; found unit + pop edi esi + + push esi + call dword[eax + 4*2] ; httpd_serv + + jmp .end_work +@@: + pop edi esi + + mov eax, [eax] + test eax, eax ; terminate list + jne .next_unit + +.no_units: ; if not found units, call file_server call file_server ; esi - struct - ;TEST SERVER, DELETE ON RELISE - ; end work thread jmp .end_work @@ -184,10 +215,59 @@ include 'file_server.inc' ; DATA AND FUNCTION include 'httpd_lib.inc' -default_ini_path: db 'httpd.ini',0 + I_END: ;DATA +@IMPORT: +library libini, 'libini.obj' + +import libini,\ + ini.get_str, 'ini_get_str',\ + ini.get_int, 'ini_get_int',\ + ini.enum_keys, 'ini_enum_keys' + + +default_ini_path: db 'httpd.ini',0 + +ini_section_units: db 'UNITS',0 +ini_section_main: db 'MAIN', 0 + +ini_key_ip db 'ip',0 +ini_key_port db 'port',0 +ini_key_conn db 'conn',0 +;ini_key_flags db 'flags',0 +ini_key_work_dir db 'work_dir',0 +ini_key_units_dir db 'units_dir',0 +ini_key_mime_file db 'mime_file',0 + +httpd_unit_init db 'httpd_init',0 +httpd_unit_serv db 'httpd_serv',0 + +IMPORT_UNIT: + dd httpd_import, GLOBAL_DATA.unit_dir, 0 + +httpd_import: +.init dd httpd_unit_init +.serv dd httpd_unit_serv + dd 0 + +EXPORT_DATA: + dd netfunc_socket + dd netfunc_close + dd netfunc_bind + dd netfunc_accept + dd netfunc_listen + dd netfunc_recv + dd netfunc_send + dd FileInfo + dd FileRead + dd Alloc + dd Free + + dd base_response + dd GLOBAL_DATA + dd 0 ; DATA ;UDATA @@ -204,16 +284,15 @@ srv_sockaddr: .length = $ - srv_sockaddr GLOBAL_DATA: - .units rd 1 ; указатель на ассоциативный массив пути и указателя на функцию либы(см ниж) - .unit_count rd 1 ; количество записей в массиве - .libs rd 1 ; указатель на массив указателей на ассоциативные массивы библиотек + .units rd 1 ; указатель на двусвязный не кольцевой(null terminator) список + ; next, prev, ptr of httpd_serv(), uri path .work_dir rb 1024 ; max size path to work directory .work_dir.size rd 1 ; length string .unit_dir rb 1024 - .unit_dir.size rd 1 + .unit_dir.end rd 1 .MIME_types_arr rd 1 -;; .flags dd 0 ; 1 - all hosts(элемент hosts не указатель на массив, а на функцию) +; .flags dd 0 ; 1 - all hosts(элемент hosts не указатель на массив, а на функцию) PATH: rb 256 diff --git a/httpd.ini b/httpd.ini index cf72d17..10c21c1 100644 --- a/httpd.ini +++ b/httpd.ini @@ -1,25 +1,27 @@ [MAIN] -# server IPv4 address. Non IPv6 address -ip=127.0.0.1 -# server port number +; server IPv4 address. Non IPv6 address +ip=192.168.137.21 +; server port number port=80 -# count open connection +; 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 +; 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 +; directory for find files work_dir=/sys/http_server/data -# directory for find lib +; directory for find lib units_dir=/sys/http_units -[UNITS] -# list units -# path = path to lib in units_dir -database/sqlite3=sqlite3_serv.obj -database/cvs=cvs_table_server.obj +;mime_file=/sys/network/mime.bin -# server called function httpd_unit_func(CONNECT_DATA* struct_server ); -# for init unit, server called function httpd_unit_init(void* global_data); \ No newline at end of file +;[UNITS] +; list units +; path = path to lib in units_dir +;database/sqlite3=sqlite3_serv.obj +;database/cvs=cvs_table_server.obj + +; server called function httpd_serv(CONNECT_DATA* struct_server ); +; for init unit, server called function httpd_init(void* global_data); \ No newline at end of file diff --git a/httpd.kex b/httpd.kex index 2b23b94..57263c8 100644 Binary files a/httpd.kex and b/httpd.kex differ diff --git a/httpd_lib.inc b/httpd_lib.inc index fcd2741..3f0c284 100644 --- a/httpd_lib.inc +++ b/httpd_lib.inc @@ -69,29 +69,29 @@ http_method: ; db '' ; db '',0 -http_err_response: - db 'HTTP/1.1 ' -.code = $ - http_err_response - db '000 ',13, 10 - db 'Server: simple-httpd/0.0.1', 13, 10 - db 'Date: ' -.date = $ - http_err_response - db 'Sun, 30 Oct 2022 09:29:13 GMT',13, 10 - db 'Content-length: 0', 13, 10 - db 'Content-type: text/plain', 13, 10; - db 'Connection: close', 13, 10 - db 13, 10 -.size = $ - http_err_response +;http_err_response: +; db 'HTTP/1.1 ' +;.code = $ - http_err_response +; db '000 ',13, 10 +; db 'Server: simple-httpd/0.0.1', 13, 10 ; httpd(kolibri os)/0.0.1, 13, 10 +; db 'Date: ' +;.date = $ - http_err_response +; db 'Sun, 30 Oct 2022 09:29:13 GMT',13, 10 +; db 'Content-length: 0', 13, 10 +; db 'Content-type: text/plain', 13, 10; +; db 'Connection: close', 13, 10 +; db 13, 10 +;.size = $ - http_err_response http_response_err_501: db 'HTTP/1.1 ' db '501 ',13, 10 + db 'Error parsing your request message. The version is not supported or another error.' db 'Server: simple-httpd/0.0.1', 13, 10 - db 'Content-length: 91', 13, 10 - db 'Content-type: text/plain', 13, 10; + ;db 'Content-length: 91', 13, 10 + ;db 'Content-type: text/plain', 13, 10; db 'Connection: close', 13, 10 db 13, 10 - db 'Error parsing your request message. The version is not supported or another error.' .size = $ - http_response_err_501 http_response_err_404: @@ -122,7 +122,7 @@ response: db 'HTTP/1.0 ' .code = $ - response db '000 ',13, 10 - db 'Server: simple-httpd/0.0.1', 13, 10 ; httpd(kolibri os)/0.0.1, 13, 10 + db 'Server: simple-httpd/0.0.1', 13, 10 db 'Cache-Control: no-cache', 13, 10 db 'Content-Encoding: ' .content_encod = $ - response @@ -137,7 +137,7 @@ response: .content_type = $ - response db ' ', 13, 10; ;'text/html; charset=utf-8' -;.end_headers: ;нужно, когда базового заголовка не хватает +.end_headers: ;нужно, когда базового заголовка не хватает .connection = $ - response db 'Connection: close', 13, 10 db 13, 10 @@ -147,43 +147,31 @@ response: ; "GET / HTTP/1.1" - 18 byte min_http_size = 18 - -MIME_TYPES: -.html: db 'text/html',0 -.css: db 'text/css',0 -.js: db 'text/javascript',0 -.txt: db 'text/plain',0 -.json: db 'application/json',0 -.pdf: db 'application/pdf',0 - -.png: db 'image/png',0 -.mp3: db 'audio/mpeg',0 -.mp4: db 'video/mp4',0 -.other: db 'application/octet-stream',0 ; for unknow file - all file :) - MIME_FILE_FORMAT: -.html: db 5,'.html',0 -.css: db 4,'.css',0 -.js: db 3,'.js',0 -.txt: db 4,'.txt',0 -.pdf: db 4,'.pdf',0 -.json: db 5,'.json',0 +.html: db 5,'.html', 'text/html',0 +.css: db 4,'.css', 'text/css',0 +.js: db 3,'.js', 'text/javascript',0 +.txt: db 4,'.txt', 'text/plain',0 +.pdf: db 4,'.pdf', 'application/pdf',0 +.json: db 5,'.json', 'application/json',0 -.png: db 4,'.png',0 -.mp3: db 4,'.mp3',0 -.mp4: db 4,'.mp4',0 +.png: db 4,'.png', 'image/png',0 +.mp3: db 4,'.mp3', 'audio/mpeg',0 +.mp4: db 4,'.mp4', 'video/mp4',0 +.other: dd 0 + db 'application/octet-stream',0 ; for unknow file - all file :) STD_MIME_TYPE_ARR: - dd MIME_FILE_FORMAT.html, MIME_TYPES.html,\ - MIME_FILE_FORMAT.css, MIME_TYPES.css,\ - MIME_FILE_FORMAT.js, MIME_TYPES.js,\ - MIME_FILE_FORMAT.txt, MIME_TYPES.txt,\ - MIME_FILE_FORMAT.pdf, MIME_TYPES.pdf,\ - MIME_FILE_FORMAT.json, MIME_TYPES.json,\ - MIME_FILE_FORMAT.png, MIME_TYPES.png,\ - MIME_FILE_FORMAT.mp3, MIME_TYPES.mp3,\ - MIME_FILE_FORMAT.mp4, MIME_TYPES.mp4,\ - 0, MIME_TYPES.other + dd MIME_FILE_FORMAT.html, \ + MIME_FILE_FORMAT.css, \ + MIME_FILE_FORMAT.js, \ + MIME_FILE_FORMAT.txt, \ + MIME_FILE_FORMAT.pdf, \ + MIME_FILE_FORMAT.json, \ + MIME_FILE_FORMAT.png, \ + MIME_FILE_FORMAT.mp3, \ + MIME_FILE_FORMAT.mp4, \ + MIME_FILE_FORMAT.other ; terminate _DIV_10_: dd 10 _DIV_100_: dd 100 diff --git a/parser.inc b/parser.inc index d513902..a154666 100644 --- a/parser.inc +++ b/parser.inc @@ -2,6 +2,8 @@ BASE_ARRAY_ARGS equ (esi - 1024) BASE_ARRAY_HEADERS equ (esi - 2048) +;TODO: fix checking end http packed + ; IN: ; esi - struct ; ecx = ptr to str URI @@ -109,6 +111,9 @@ parse_url: cmp byte[ecx], '&' jne @b + mov byte[ecx], 0 + inc ecx + jmp .get_query_new_arg .get_fragment: @@ -206,7 +211,8 @@ parse_http_query: ; message data mov eax, [esi + CONNECT_DATA.request_size] - mov [esi + CONNECT_DATA.tmp_req_size], eax + add eax, [esi + CONNECT_DATA.buffer_request] + mov [esi + CONNECT_DATA.end_buffer_request], eax ; check size cmp dword[esi + CONNECT_DATA.request_size], min_http_size @@ -215,6 +221,9 @@ parse_http_query: ; get http METHOD this message mov [esi + CONNECT_DATA.http_method], ecx @@: + cmp ecx, [esi + CONNECT_DATA.end_buffer_request] + ja .error_exit + inc ecx cmp byte[ecx - 1], ' ' ; find end method jnz @b @@ -230,17 +239,13 @@ parse_http_query: ; ecx <- uri string ; парсинг uri строки в заголовке запроса(получение схемы, пути аргументов, фрагмента и тд) call parse_url - - ; check size - mov edx, ecx - sub edx, [esi + CONNECT_DATA.buffer_request] - sub edx, 7 ; H/0.0 0x0d0 x0a - cmp dword[esi + CONNECT_DATA.request_size], edx - jle .error_exit ; get http version(HTTP/1.1) mov [esi + CONNECT_DATA.http_verion], ecx @@: + cmp ecx, [esi + CONNECT_DATA.end_buffer_request] + ja .error_exit + inc ecx cmp word[ecx - 1], 0x0A0D jnz @b @@ -259,13 +264,11 @@ parse_http_query: ; check size - mov edx, ecx - sub edx, [esi + CONNECT_DATA.buffer_request] - cmp dword[esi + CONNECT_DATA.request_size], edx - jl .error_exit + cmp ecx, [esi + CONNECT_DATA.end_buffer_request] + je @f mov [esi + CONNECT_DATA.message_body], ecx - ; докачивается всё остальное +@@: mov eax, esi ret diff --git a/settings.inc b/settings.inc index ebf9cbd..3f25584 100644 --- a/settings.inc +++ b/settings.inc @@ -5,7 +5,7 @@ struct CONNECT_DATA ; 16*4 = 64 bytes 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 - tmp_req_size dd 0 ; для парсера + end_buffer_request dd 0 ; для парсера buffer_response dd 0 ; pointer to buffwr for resp message http_method dd 0 ; указатель на строку http_verion dd 0 ; указатель на строку @@ -20,6 +20,13 @@ struct CONNECT_DATA ; 16*4 = 64 bytes message_body dd 0 ; указатель на тело http запроса ends +struct HTTPD_UNIT + next rd 1 + prev rd 1 + httpd_serv rd 1 + uri_path rb 4096-3*4 +ends + struct REQUEST_DATA ptr_name dd 0 ; ptr_data dd 0 ; @@ -29,45 +36,162 @@ ends ; ecx - path to file ; OUT: eax - 0 or err_code load_settings: - ; check file path - ;sub esp, 40 ; size file info struct - ;push esp - ;push ecx - ;call FileInfo - ;lea esp, [esp + 40] - ;test eax, eax - ;jnz .err + mov ebp, ecx + + sub esp, 16 + mov esi, esp + invoke ini.get_str, ebp, ini_section_main, ini_key_ip, esi, 16, 0 ; ip + ; xxx.xxx.xxx.xxx\n - 16 byte max + xor edx, edx + xor eax, eax + mov ecx, 4 ; count '.' +@@: + add al, [esp] + sub al, '0' + inc esp + mul dword[_DIV_10_] + + cmp byte[esp], '0' ; if . , space and other + jae @b + + mov byte[srv_sockaddr.ip], al + ror dword[srv_sockaddr.ip], 8 + add esp, 1 + dec ecx + jnz @b + + mov esp, esi + add esp, 16 + - ; TEST SERVER mov word[srv_sockaddr], AF_INET4 - mov word[srv_sockaddr.port], 0x5000 ; 80 port - mov dword[srv_sockaddr.ip], 0x1589A8C0 ; 192.168.137.21 or 0xc0a88915 ? - mov dword[srv_backlog], 10 - push esi edi + invoke ini.get_int, ebp, ini_section_main, ini_key_port, 80 ; standart port + xchg al, ah + mov [srv_sockaddr.port], ax + + invoke ini.get_int, ebp, ini_section_main, ini_key_conn, 10 ; standart port + mov [srv_backlog], ax + + ; flags + + ; work_dir + invoke ini.get_str, ebp, ini_section_main, ini_key_work_dir, GLOBAL_DATA.work_dir, 1024, 0 ; ip + push edi + mov ecx, 1024 mov edi, GLOBAL_DATA.work_dir - mov esi, test_workdir - mov ecx, test_workdir.size - rep movsb - pop edi esi - mov dword[GLOBAL_DATA.work_dir.size], test_workdir.size - + xor eax, eax + repne scasb + dec edi + sub edi, GLOBAL_DATA.work_dir + mov [GLOBAL_DATA.work_dir.size], edi + pop edi + ; TODO: get mime file mov dword[GLOBAL_DATA.MIME_types_arr], STD_MIME_TYPE_ARR + + ; units_dir + invoke ini.get_str, ebp, ini_section_main, ini_key_units_dir, GLOBAL_DATA.unit_dir, 1024, 0 ; ip + push edi + mov ecx, 1024 + mov edi, GLOBAL_DATA.unit_dir + xor eax, eax + repne scasb + mov byte[edi-1], '/' + mov [GLOBAL_DATA.unit_dir.end], edi + pop edi + + ; get all units + invoke ini.enum_keys, ebp, ini_section_units, .add_unit + + ; TEST SERVER + ;mov word[srv_sockaddr.port], 0x5000 ; 80 port + ;mov dword[srv_sockaddr.ip], 0x1589A8C0 ; 192.168.137.21 or 0xc0a88915 ? + ;mov dword[srv_backlog], 10 + + ;push esi edi + ;mov edi, GLOBAL_DATA.work_dir + ;mov esi, test_workdir + ;mov ecx, test_workdir.size + ;rep movsb + ;pop edi esi + ;mov dword[GLOBAL_DATA.work_dir.size], test_workdir.size xor eax, eax ret + +.add_unit: ; [esp + 4*3] - name [esp + 4*4] - value + ; add new item in list + push dword sizeof.HTTPD_UNIT + call Alloc + test eax, eax + jz .add_unit.exit + + mov ecx, [GLOBAL_DATA.units] + mov [eax], ecx + mov dword[eax + 4], GLOBAL_DATA.units + mov [GLOBAL_DATA.units], eax + test ecx, ecx + jnz @f + mov [ecx + 4], eax +@@: + ; copy uri path + push esi edi + mov esi, [esp + 4*2 + 4*3] ; name + lea edi, [eax + 4*3 + 1] + mov byte[edi - 1], '/' +@@: + movsb + cmp byte[edi - 1], 0 + jne @b + ; copy file name + mov edi, [GLOBAL_DATA.unit_dir.end] + mov esi, [esp + 4*2 + 4*4] +@@: + movsb + cmp byte[edi - 1], 0 + jne @b + + pop edi esi + mov esi, eax + ; load library + push esi + stdcall dll.Load, IMPORT_UNIT + pop esi + test eax, eax + jz @f + + .add_unit.err: + ; error + mov eax, [esi] ; next + mov [GLOBAL_DATA.units], eax + mov dword[eax + 4], GLOBAL_DATA.units + + push esi + call Free + + jmp .add_unit.exit +@@: ; good + ; init httpd unit + push dword EXPORT_DATA + invoke httpd_import.init + test eax, eax + jnz .add_unit.err + + mov eax, [httpd_import.serv] + mov dword[esi + 4*2], eax + + mov [httpd_import.init], httpd_unit_init + mov [httpd_import.serv], httpd_unit_serv +.add_unit.exit: + ret 16 + + + .err: ret -test_workdir: db '/sys' -.size = $ - test_workdir - - -; Config format: -; Standart INI file: -; - ";" or "#" comments -; - [name] name of group -; - arg=val params in group +;test_workdir: db '/sys' +;.size = $ - test_workdir diff --git a/utils/mime_types.asm b/utils/mime_types.asm new file mode 100644 index 0000000..9a55d41 --- /dev/null +++ b/utils/mime_types.asm @@ -0,0 +1,32 @@ +format binary as "bin" +use32 +org 0 + +macro table arg3, [arg1,arg2] { + local ..x,..x_end + forward + dd ..x + common + local ..other + dd ..other + ; size = ($ - ) / 8 + forward + ..x db ..x_end-..x - 1, arg1 + ..x_end db arg2, 0 + common + ..other dd 0 + db arg3, 0 + +} + + +table 'application/octet-stream' ,\ + '.html', 'text/html' ,\ + '.css', 'text/css' ,\ + '.js', 'text/javascript' ,\ + '.txt', 'text/plain' ,\ + '.pdf', 'application/pdf' ,\ + '.json', 'application/json' ,\ + '.png', 'image/png' ,\ + '.mp3', 'audio/mpeg' ,\ + '.mp4', 'video/mp4' diff --git a/utils/mime_types.bin b/utils/mime_types.bin new file mode 100644 index 0000000..bed7dc8 Binary files /dev/null and b/utils/mime_types.bin differ