diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index fee6835..5549575 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -748,7 +748,7 @@ define String *** [2.3] A set of state variables for the server. -type SState: +public type SState: sstate ( Var(List(Word8)) unput_chars, // for reading requests @@ -1822,8 +1822,8 @@ define Result(Error,Int) { [ ] then ok(0), [h . t] then if h is http_header(name,value) then - if name = "content-length" - then if decimal_scan(value) is + if name = "content-length" then + if decimal_scan(value) is { failure then error(incorrect_content_length_value), success(n) then ok(n) @@ -1831,15 +1831,7 @@ define Result(Error,Int) else get_body_size(t) }. - - - - - - - - - + *** [4.10] Reading the body of the request. The body of the request may be very big (it contains uploaded files, if any). We read @@ -2737,21 +2729,23 @@ define Maybe((String,Maybe(String))) *** [5.7.4] Saving an uploaded file under a temporary filename. define Maybe(String) // returns the temporary file name - save_uploaded_file - ( - Web_Site_Description desc, - RStream body_fd, + save_uploaded_file + ( + String web_site_dir, +// Web_Site_Description desc, + + RStream body_fd, // ByteArray body, - Int start, - Int end, - SState s - ) = + Int start, + Int end, + SState s + ) = s.uploaded_file_count <- 1 + *(s.uploaded_file_count); with tfn = "_"+to_decimal(virtual_machine_id)+"_"+to_decimal(*(s.uploaded_file_count)), // println("save_uploaded_file to :"+site_directory(desc)+"/upload_temporary/"+tfn); // println("start offset = "+start+" end offset = "+end); //make data_io which is the size of the file to extract - if copy_Data_IO_to_file(make_data_io(body_fd, start, end - start), site_directory(desc)+"/upload_temporary/"+tfn) is copy_ok(_) + if copy_Data_IO_to_file(make_data_io(body_fd, start, end - start), web_site_dir+"/upload_temporary/"+tfn) is copy_ok(_) then success(tfn) else failure . @@ -2818,11 +2812,12 @@ define String define Maybe(Web_arg) get_multipart_entity ( - Web_Site_Description desc, - String body_temp_file, - Int start_offset, //real offset in source file of the part - Int end_offset, //real offset in source file of the part - SState s + //Web_Site_Description desc, + String web_site_dir, + String body_temp_file, + Int start_offset, //real offset in source file of the part + Int end_offset, //real offset in source file of the part + SState s )= //Get header of the part if find_the_first(body_temp_file, crlf+crlf, start_offset, end_offset) is @@ -2849,10 +2844,10 @@ define Maybe(Web_arg) failure, success(fn) then - if save_uploaded_file(desc, body_fd, start_offset+k+4, end_offset-2, s) is + if save_uploaded_file(web_site_dir, body_fd, start_offset+k+4, end_offset-2, s) is { failure then failure, - success(tfn) then success(upload(name, remove_path(fn), site_directory(desc)+"/upload_temporary/"+tfn)) + success(tfn) then success(upload(name, remove_path(fn), web_site_dir+"/upload_temporary/"+tfn)) } } @@ -2864,39 +2859,40 @@ define Maybe(Web_arg) -define List(Web_arg) +public define List(Web_arg) read_multipart_form_data_encoded_web_args ( - Web_Site_Description desc, + String web_site_dir, + //Web_Site_Description desc, String body_temp_file, String __boundary, Int file_offset, SState s ) = with boundary_length = length(__boundary), -// println( -//"read_multipart_form_data_encoded_web_args -// boundary["+__boundary+"] -// body_temp_file : "+body_temp_file+" -// file_offset : "+file_offset); + println( +"read_multipart_form_data_encoded_web_args + boundary["+__boundary+"] + body_temp_file : "+body_temp_file+" + file_offset : "+file_offset); //get the first boundary position if find_the_first(body_temp_file, __boundary, file_offset) is { - failure then println("first boundary not found");[ ], + failure then println("first boundary NOT found");[ ], success(first) then with first = first + file_offset, //adjust the offset to real offset in file //get the second boundary position if find_the_first(body_temp_file, __boundary, first + boundary_length) is { - failure then println("last boundary found");[ ], + failure then println("last boundary NOT found");[ ], success(last) then with last = last + first + boundary_length, //adjust the offset to real offset in file //Extract the file content here - if get_multipart_entity(desc, body_temp_file, first+boundary_length, last, s) is + if get_multipart_entity(web_site_dir, body_temp_file, first+boundary_length, last, s) is { failure then [ ], success(wa) then - [wa . read_multipart_form_data_encoded_web_args(desc, body_temp_file, __boundary, last, s)] + [wa . read_multipart_form_data_encoded_web_args(web_site_dir, body_temp_file, __boundary, last, s)] } } }. @@ -2921,7 +2917,7 @@ define One failure then unique, success(boundary) then with all_web_args = query_string(request_line) + - read_multipart_form_data_encoded_web_args(desc, + read_multipart_form_data_encoded_web_args(desc.site_directory, body_temp_file, "--"+boundary, 0, @@ -3204,7 +3200,7 @@ define One if get_body_size(headers) is { error(msg) then log_journal_msg(desc,format(msg)), - ok(body_size) then + ok(body_size) then if rqline is request_line(type, uri, qstring) then with rqline2 = request_line(type, handle_redirection(redirections(desc), uri, headers), qstring), @@ -3215,7 +3211,7 @@ define One { //WWW_URL www_url then - if read_http_body(connection,body_size,constant_byte_array(0,0),1000) is + if read_http_body(connection, body_size, constant_byte_array(0,0), 1000) is { error(msg) then log_journal_msg(desc,format(msg)), ok(body) then @@ -3228,8 +3224,7 @@ define One if body_size > 0 then with t0 = (UTime)unow, - println("read body, size "+body_size); - + if get_socket_from_connection(conn(connection)) is { failure then println("can't get socket"), @@ -3264,7 +3259,7 @@ define One println("Can't copy data from stream to temporary file ") }}} else - println("bbody_size = 0 !") + println("body_size = 0 !") } //print_delta("before send_answer"); -- libgit2 0.21.4