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 '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 0000000000000000000000000000000000000000..9c360f3bf21ebe444aac4d0e261c4024370de88a GIT binary patch literal 1430 zcmZ`(O>7%Q6rTK2tT?Sy4j|NOYDGvOY_FR(Dyz*BnkKXoqT9wwTD3~F*`0W|taq*5 zacM45T#B%}mmVr1Ar3^q0dXmnB2ra#A~^VjwC2u<1BW1Ss6@rdytm^{D^y17nQy*% z?|a|Qj^~4cL85Pe#IBAIGDNW58YrxJCQq^Gz8@gO26%l~%n!pri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#w}aw+ zQxJ(_?KVHXM$TDxn)!9|sdbxq`x^Pq+B1EAjnXA{GEnY0`H~g3dcSe~4sdZp1F50N z?|>|CZHiZz*rcnBj>9%U&PR-n#Vam$BrDi0mTwB>t3oBZtsF-9fl9dJbIYD9gJ&&| znzX+nvsLX@Wq><1!d>Oid7|3hAZNv0`wt~>IxL;g@()XWK4~b4rGPIGkbI$VAQblZ zNrT5vI&6;@@;IHxkBp}CSuBSoANj`aCl$N3E$H);*F=eYVec@9{0&;LKY6)gzhRoj z=?UzW@z^M8Sjl3sY2*^86UF4XqT;5njwX~mN~r3nl1yNwkoV?_g^h%o${=MdkxhHm zd=@3Nlv41Hsp%{_t)$Y-?B9@INa8dm4{Z{rc~4^i&cnL5d2&U>dGG{=m6hayfKK2* zRn9Y}_BGaiGy^~Q8e9jjz?%b{12_N#@F3tVKnQRV&}p~EuF(cQ#%ju=' ; 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 0000000000000000000000000000000000000000..bed7dc88eebee6d610688fa4ec39326060eca3c9 GIT binary patch literal 225 zcmYk0y$!-Z423NLyU>s;NWlaQL1$f#;8X5LITNL03pQW`HefK`B~6M?exLPZ`A9?; za0NHu!3(^>2YkT~9GZuQLEWsT2HH2altnRV*Z5UDPh9LMS<%p0mqs2~B0P6@&Up~a yDk&N$&iaz#c3Zu6V=sYwXAqzvpZVEIG9kOw+etcCy~TG#+Y`yE(^JvWaiBl#S3}$Y literal 0 HcmV?d00001