aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
Diffstat (limited to 'captain')
-rw-r--r--captain/postutils.f9011
-rw-r--r--captain/queryutils.f907
-rw-r--r--captain/response.f9011
-rw-r--r--captain/web.f9018
4 files changed, 34 insertions, 13 deletions
diff --git a/captain/postutils.f90 b/captain/postutils.f90
index c5af8bd..2961f98 100644
--- a/captain/postutils.f90
+++ b/captain/postutils.f90
@@ -7,6 +7,7 @@ contains
function read_post_contents() result(res)
use query_utilities, only: query
+ use logging
implicit none
type(query)::res
@@ -17,17 +18,19 @@ contains
call get_environment_variable("CONTENT_LENGTH", header_info, status=istat)
if(istat == 0) then
- read(header_info, '(I8)') content_length
+ read(header_info, *) content_length
else
content_length = 0
end if
+ call write_log("Content Length is: "//trim(header_info), LOG_DEBUG)
call get_environment_variable("CONTENT_TYPE", header_info, status=istat)
if(content_length > 0 .and. &
istat == 0 .and. &
- trim(header_info) /= content_type_required) &
+ trim(header_info) == content_type_required) &
then
-
+ call write_log("Processing post", LOG_DEBUG)
+
allocate(character(len=content_length) :: transfered)
do i = 1, content_length
@@ -39,6 +42,8 @@ contains
deallocate(transfered)
end if
+
+ call write_log("Content Type is: "//trim(header_info), LOG_DEBUG)
end function read_post_contents
diff --git a/captain/queryutils.f90 b/captain/queryutils.f90
index 5e97023..e59713f 100644
--- a/captain/queryutils.f90
+++ b/captain/queryutils.f90
@@ -66,6 +66,7 @@ contains
if(i_equals == 0) then
allocate(character(len=len_trim(decoded)) :: self%value)
self%value = decoded
+ self%key => null()
else
allocate(character(len=i_equals-1) :: self%key)
self%key = decoded(1:i_equals-1)
@@ -200,8 +201,10 @@ contains
integer::i
do i = 1, self%component_count()
- if(associated(self%components(i)%key) .and. self%components(i)%key == trim(k)) then
- res => get_query_value_from_index(self, i)
+ if(self%components(i)%has_key()) then
+ if(self%components(i)%key == trim(k)) then
+ res => get_query_value_from_index(self, i)
+ end if
end if
end do
diff --git a/captain/response.f90 b/captain/response.f90
index dfce5e7..748dd39 100644
--- a/captain/response.f90
+++ b/captain/response.f90
@@ -109,6 +109,8 @@ contains
character(len=:), allocatable::temppage
integer::i, j, n
+ character(64)::msg
+
n = len_trim(str)
allocate(character(len=n) :: self%url)
self%url = trim(str)
@@ -135,7 +137,7 @@ contains
! so we need to skip ahead of it in the URL if it is there...
i = index(str, self%server)
if(i > 0) then
- i = i + len(self%server)+1
+ i = i + len(self%server)
else
i = 1
end if
@@ -149,17 +151,22 @@ contains
allocate(character(len=(j-1)) :: self%server)
self%server = str(i:(i+j-1))
+ i = j+i-1
+
end if
call write_log("Server: "//self%server//"|", LOG_DEBUG)
- i = j+i-1
j = index(str, "?")
if(j == 0) then
if(n-i+1 == 0) then
allocate(character(len=1) :: self%location)
self%location = "/"
else
+ write(msg, '(I12,1X,I12)') i, n
+ call write_log("i n: "//trim(msg), LOG_DEBUG)
+
allocate(character(len=(n - i + 1)) :: self%location)
+ call write_log("str(i:n): "//str(i:n), LOG_DEBUG)
self%location = str(i:n)
end if
call write_log("Location: "//self%location, LOG_DEBUG)
diff --git a/captain/web.f90 b/captain/web.f90
index 57f57f9..dab017a 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -288,7 +288,7 @@ contains
end if
res = trim(res)//new_line(' ')//"<h2>Management</h2>"// &
- new_line(' ')//'<form action="players/add.html" method="post"><label for="name">Name:</label>'// &
+ new_line(' ')//'<form action="players/add.html" method="POST"><label for="name">Name:</label>'// &
'<input name="name" id="name" /><input type="submit" value="Add"/></form>'
end function generate_players_html
@@ -644,12 +644,12 @@ contains
end function request_templated
function handle_post(req) result(resp)
+ use captain_db, only: add_player_db
use page_template
- use config, only: template_filepath, project
+ use config, only: template_filepath
use logging
use server_response, only:request, response
- use http, only: HTTP_CODE_SUCCESS, HTTP_CODE_NOTFOUND
- use request_utils, only: get_job_page_title, handle_instruction_command
+ use http, only: HTTP_CODE_FAILURE, HTTP_CODE_SUCCESS
use http_post_utilities
use query_utilities, only: query
implicit none
@@ -664,6 +664,8 @@ contains
character(64)::category, second
posted = read_post_contents()
+ call write_log("Post Contents: "//posted%full, LOG_DEBUG)
+
if(posted%component_count() > 0) then
! We will immediately redirect after the command is handled
@@ -674,13 +676,15 @@ contains
call req%path_component(1, category)
if(trim(category) == "players") then
call req%path_component(2, second)
+ call write_log("Handling command for players: "//trim(second), LOG_INFO)
! Add a player
if(trim(second) == "add.html") then
+
call add_player_db(posted%get_value("name"))
call page%assign('destination', 'players.html')
-
+
end if
end if
@@ -693,12 +697,13 @@ contains
resp%temporary_file = .true.
resp%body_filename => page%output_filename
resp%body_mimetype = "text/html"
+ resp%code = HTTP_CODE_SUCCESS
call posted%destroy()
else
- resp%code = 500
+ resp%code = HTTP_CODE_FAILURE
end if
@@ -726,6 +731,7 @@ contains
resp = request_static(req)
else if(req%is_post()) then
+ call write_log("POST operation", LOG_INFO)
resp = handle_post(req)
else