From 28f8ec49640eb563c41c77da6d4870d31a3d3065 Mon Sep 17 00:00:00 2001 From: Doczom <78043169+Doczom@users.noreply.github.com> Date: Sun, 3 Dec 2023 04:14:48 +0500 Subject: [PATCH] Add support units in server Added support for loading and calling server modules. Added the download of the configuration file(httpd.ini). Several bugs have been fixed. Added simple example for generating server units and mime types file. --- example/test_unit.asm | 209 ++++++++++++++++++++++++++++++++++++++++++ example/test_unit.obj | Bin 0 -> 1430 bytes file_server.inc | 43 ++++----- httpd.asm | 107 ++++++++++++++++++--- httpd.ini | 34 +++---- httpd.kex | Bin 3118 -> 3935 bytes httpd_lib.inc | 90 ++++++++---------- parser.inc | 29 +++--- settings.inc | 182 ++++++++++++++++++++++++++++++------ utils/mime_types.asm | 32 +++++++ utils/mime_types.bin | Bin 0 -> 225 bytes 11 files changed, 579 insertions(+), 147 deletions(-) create mode 100644 example/test_unit.asm create mode 100644 example/test_unit.obj create mode 100644 utils/mime_types.asm create mode 100644 utils/mime_types.bin 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 '
Name' + db ' | Info |
---|---|
Количество запросов | ' +.count = $ - sceleton_resp + db '000 |
Сообщение | ' +.message = $ - sceleton_resp + db ' |
' ; db '