diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-30 10:52:12 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-30 10:52:12 -0400 |
commit | fbfd194941de48affaa92522ceaff97010abc1c2 (patch) | |
tree | 9be8f652bfaaeb6bc2e11134275098dec23ce92e | |
parent | fde763f60465b28d33260479b64d9555abc5bcbb (diff) | |
download | levitating-fbfd194941de48affaa92522ceaff97010abc1c2.tar.gz levitating-fbfd194941de48affaa92522ceaff97010abc1c2.zip |
Fixed outstanding issues in template variable assignment and player content building. Removed unnecessary logging calls.
-rw-r--r-- | captain/captian.f90 | 3 | ||||
-rw-r--r-- | captain/db.f90 | 9 | ||||
-rw-r--r-- | captain/external.f90 | 29 | ||||
-rw-r--r-- | captain/gemini.f90 | 34 | ||||
-rw-r--r-- | captain/response.f90 | 9 | ||||
-rw-r--r-- | captain/template.f90 | 9 | ||||
-rw-r--r-- | captain/templates/index.gmi | 6 |
7 files changed, 56 insertions, 43 deletions
diff --git a/captain/captian.f90 b/captain/captian.f90 index 2c3cab4..eb278a6 100644 --- a/captain/captian.f90 +++ b/captain/captian.f90 @@ -13,8 +13,9 @@ implicit none call parse_options() - call initialize_db(database_filename) call initialize_log(log_filename) + + call initialize_db(database_filename) select case(mode) case(MODE_GEMINI) diff --git a/captain/db.f90 b/captain/db.f90 index e191af7..2dc1cff 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -10,9 +10,18 @@ implicit none contains subroutine initialize_db(filename) + use logging implicit none character(*), intent(in)::filename + logical::exists + + inquire(file=filename, exist=exists) + if(.not. exists) then + call write_log("Database does not exist, exiting") + call shutdown() + stop + end if if(sqlite3_open(filename, db) == SQLITE_OK) then database_file = filename diff --git a/captain/external.f90 b/captain/external.f90 index 0aefdf8..146060f 100644 --- a/captain/external.f90 +++ b/captain/external.f90 @@ -21,8 +21,7 @@ contains res = "None Yet" else - - res = "## Existing Players" + players => get_player_names() nsize = 1024 @@ -31,15 +30,21 @@ contains end do allocate(character(len=nsize) :: res) + res = "## Existing Players" + do i = 1, n one_player = "=> /players/"//trim(players(i))//".gmi "//trim(players(i)) - res = trim(res)//new_line(res(1:1))//trim(one_player) + if(i == 1) then + res = trim(res)//new_line(res(1:1))//new_line(res(1:1))//trim(one_player) + else + res = trim(res)//new_line(res(1:1))//trim(one_player) + end if end do deallocate(players) end if - res = trim(res)//new_line(res(1:1))//"## Management"// & + res = trim(res)//new_line(res(1:1))//new_line(res(1:1))//"## Management"// & new_line(res(1:1))//"=> /players/add.gmi Add Player" end function generate_players_gemini @@ -178,10 +183,14 @@ contains ! Open the base template call template_filepath("index.gmi", template_file) call page%init(trim(template_file)) + + call write_log("Processing request") if(trim(req%location) == "/" .or. trim(req%location) == "/index.gmi") then + call write_log("Assign") call page%assign('title', 'Home') + call write_log("Assign done") else if(trim(req%location) == "/releases.gmi") then @@ -208,11 +217,14 @@ contains call page%assign('title', 'Not Found') end if - + call page%assign('project', project) + + call write_log("Rendering page for "//req%location) call page%render() - + + call write_log("Finalizing response") resp%temporary_file = .true. resp%body_filename => page%output_filename resp%body_mimetype = "text/gemini" @@ -222,21 +234,26 @@ contains function external_request_gemini(req) result(resp) use server_response + use logging implicit none class(request), intent(in)::req type(response)::resp if(is_input_provided_request(req)) then + call write_log("Input request") resp = external_input_request_gemini(req) else if(is_input_required_request(req)) then + call write_log("Input required") resp = external_input_required_gemini(req) else if(is_request_static(req)) then + call write_log("Req static") resp = external_request_static(req) else + call write_log("Req template") resp = external_request_templated(req) end if diff --git a/captain/gemini.f90 b/captain/gemini.f90 index e3b8be6..0930d17 100644 --- a/captain/gemini.f90 +++ b/captain/gemini.f90 @@ -7,28 +7,6 @@ implicit none contains - subroutine simplify_request(full_request, local_request) - use logging, only: write_log - implicit none - - character(*), intent(in)::full_request - character(*), intent(out)::local_request - - integer::i, j - - ! Get the file of interest - i = index(full_request, "://") - if(i <= 0) then - local_request = full_request - else - j = index(full_request(i+3:len_trim(full_request)), "/") - local_request = full_request((i+j+2):len_trim(full_request)) - end if - - call write_log("Simplified Local Request: "//trim(local_request)) - - end subroutine simplify_request - subroutine read_request(ssl, req) use jessl, only: ssl_read use iso_c_binding @@ -96,6 +74,7 @@ contains subroutine write_status(ssl, code, meta) use iso_c_binding, only: c_ptr, c_carriage_return, c_new_line use jessl, only: ssl_write + use logging implicit none type(c_ptr)::ssl @@ -103,9 +82,9 @@ contains character(*), intent(in)::meta character(8)::int_text + character(1024)::line - write(int_text, *) code - + write(int_text, '(I8)') code call write_string(ssl, trim(adjustl(int_text))//" "//trim(meta)//c_carriage_return//c_new_line) end subroutine write_status @@ -124,7 +103,6 @@ contains integer::buflen, written call write_status(ssl, GEMINI_CODE_SUCCESS, mimetype) - !call write_string(ssl, "20 "//trim(mimetype)//c_carriage_return//c_new_line) buflen = read_into_buffer(unit_number, buf) do while(buflen > 0) @@ -273,8 +251,10 @@ contains ! Do the actual protocol nonsense call read_request(ssl, text_request) + call write_log("Initializing object") call req%init(text_request) + call write_log("Request object created") if(len(req%location) .ge. 4) then if(req%location(1:4) == '/api') then !call handle_api_request(request) @@ -285,6 +265,7 @@ contains resp = external_request_gemini(req) end if + call write_log("Handling response") ! Handle the response select case(resp%code) case(GEMINI_CODE_INPUT) @@ -297,9 +278,12 @@ contains call write_failure(ssl) case(GEMINI_CODE_SUCCESS) + call write_log("Sending '"//trim(resp%body_filename)//"' as "//trim(resp%body_mimetype)) open(newunit=rendered_unit, file=resp%body_filename, status="old", & form="unformatted", iostat=ioerror, access="stream") call write_file(ssl, rendered_unit, resp%body_mimetype) + call write_log("File written") + close(rendered_unit) end select diff --git a/captain/response.f90 b/captain/response.f90 index b0fe9df..efc8655 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -47,6 +47,7 @@ module server_response contains subroutine request_init(self, str) + !use logging implicit none class(request) :: self @@ -57,27 +58,33 @@ contains n = len_trim(str) allocate(character(len=n) :: self%url) self%url = trim(str) + !call write_log("URL: "//self%url) i = index(str, "://") allocate(character(len=(i-1)) :: self%protocol) self%protocol = str(1:i-1) + !call write_log("Protocol: "//self%protocol) i = i + 3 j = index(str(i:n), "/") allocate(character(len=(j-1)) :: self%server) self%server = str(i:(i+j-1)) + !call write_log("Server: "//self%server) - i = j + i = j+i-1 j = index(str, "?") if(j == 0) then allocate(character(len=(n - i + 1)) :: self%location) self%location = str(i:n) + !call write_log("Location: "//self%location) else allocate(character(len=(n-j)) :: self%query_string) self%query_string = str(j+1:n) + !call write_log("Query: "//self%query_string) allocate(character(len=(j-i)) :: self%location) self%location = str(i:j-1) + !call write_log("Location: "//self%location) end if end subroutine request_init diff --git a/captain/template.f90 b/captain/template.f90 index f8a6625..997bef3 100644 --- a/captain/template.f90 +++ b/captain/template.f90 @@ -105,10 +105,6 @@ contains class(variable)::self character(*), intent(in)::v - if(associated(self%vstr)) then - deallocate(self%vstr) - end if - allocate(character(len=max(len_trim(v), 1)) :: self%vstr) if(len_trim(v) == 0) then self%vstr = " " @@ -137,7 +133,6 @@ contains end subroutine variable_assign_integer subroutine variable_assign_string(self, name, str) - use logging implicit none class(variable)::self @@ -146,7 +141,7 @@ contains call self%set_name(name) self%vtype = VTYPE_STRING call self%set_string_value(str) - + end subroutine variable_assign_string subroutine variable_assign_logical(self, name, lg) @@ -259,7 +254,7 @@ contains class(template)::self character(*), intent(in)::name, value integer::i - + i = template_available_variable_index(self) call self%variables(i)%assign(name, value) diff --git a/captain/templates/index.gmi b/captain/templates/index.gmi index 492d25d..ebc7419 100644 --- a/captain/templates/index.gmi +++ b/captain/templates/index.gmi @@ -1,7 +1,7 @@ -# {{ title }} - We're Levitating! +# {{ title }} - I'm Levitating! -The Levitating captain interface for the {{ project }} project. +The Levitating Captain interface for the {{ project }} project. => /index.gmi Home => /releases.gmi Releases @@ -9,7 +9,7 @@ The Levitating captain interface for the {{ project }} project. => /players.gmi Players => /about.gmi About -{{ content }} +{{ contents }} ``` |