aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2022-06-28 21:12:20 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2022-06-28 21:12:20 -0400
commit6f681035a7c7125a72ce04d6881c1579bdb96d09 (patch)
tree0242bd750f447ab863b375e6e627e2da3abc8bb5 /captain
parent1023ceb58f48c7a01a8d04688a48918ac485d20a (diff)
downloadlevitating-request_refactor.tar.gz
levitating-request_refactor.zip
Titan query strings are now actually processed as queries. Additional cleanup based on refactor of requests.request_refactor
Diffstat (limited to 'captain')
-rw-r--r--captain/external.f902
-rw-r--r--captain/queryutils.f905
-rw-r--r--captain/response.f9058
-rw-r--r--captain/web.f9023
4 files changed, 59 insertions, 29 deletions
diff --git a/captain/external.f90 b/captain/external.f90
index 07f52cb..6fd848c 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -1031,8 +1031,10 @@ contains
proceed_to_create_filename = .false.
+ call write_log("Validating token...")
proceed_to_create_filename = validate_titan_token(req%token)
+ call write_log("Proceeding...")
if(proceed_to_create_filename) then
fullpath => get_full_filename_from_request(req)
end if
diff --git a/captain/queryutils.f90 b/captain/queryutils.f90
index c8a5d44..d6fa0e6 100644
--- a/captain/queryutils.f90
+++ b/captain/queryutils.f90
@@ -144,7 +144,6 @@ contains
class(query), intent(out)::self
character::separator
character(len=*), intent(in), optional::str
- character(64)::msg
integer::ampersands, i, i_end, i_comp, n
@@ -177,12 +176,12 @@ contains
else
i_comp = 1
i = 1
- i_end = index(self%full, '&')
+ i_end = index(self%full, separator)
do while(i_comp < ampersands + 1)
call self%components(i_comp)%parse(self%full(i:i_end-1))
i = i_end + 1
do i_end = i, len_trim(self%full)
- if(self%full(i_end:i_end) == '&') then
+ if(self%full(i_end:i_end) == separator) then
exit
end if
end do
diff --git a/captain/response.f90 b/captain/response.f90
index a82f53d..49f735e 100644
--- a/captain/response.f90
+++ b/captain/response.f90
@@ -199,10 +199,14 @@ contains
call write_log("URL: "//self%url, LOG_NORMAL)
i = index(fullurl, "://")
- allocate(character(len=(i-1)) :: self%protocol)
- self%protocol = fullurl(1:i-1)
- i = i + 3
- call write_log("Protocol: "//self%protocol, LOG_DEBUG)
+ if(i >= 1) then
+ allocate(character(len=(i-1)) :: self%protocol)
+ self%protocol = fullurl(1:i-1)
+ i = i + 3
+ call write_log("Protocol: "//self%protocol, LOG_DEBUG)
+ else
+ i = 1
+ end if
! We only want to "assume" the server if a :// was never found
j = index(fullurl(i:n), "/")
@@ -228,15 +232,10 @@ contains
self%location = fullurl(i:n)
end if
call write_log("Location: "//self%location, LOG_DEBUG)
-
- call self%q%init()
-
else
allocate(character(len=(n-j)) :: self%query_string)
self%query_string = fullurl(j+1:n)
- call self%q%init_with_separator(query_separator, self%query_string)
-
allocate(character(len=(j-i)) :: self%location)
self%location = fullurl(i:j-1)
end if
@@ -252,7 +251,7 @@ contains
deallocate(temppage)
if(associated(self%query_string)) then
- call self%q%init(self%query_string)
+ call self%q%init_with_separator(query_separator, self%query_string)
if(associated(self%q%get_value("token"))) then
self%token => self%q%get_value("token")
@@ -313,23 +312,36 @@ contains
subroutine http_request_init(self, str, server_explicit, protocol_explicit, method, cookiestring)
use captain_db, only: get_session_auth_db
use auth_levels, only: AUTH_NONE
+ use utilities, only: toupper
implicit none
class(http_request), intent(out)::self
character(len=*), intent(in)::str
character(*), intent(in), optional::server_explicit, protocol_explicit, method, cookiestring
- character(len=1024)::fullurl
+ character(len=1024)::fullurl, passurl
fullurl = " "
- if(present(protocol_explicit) .and. present(server_explicit)) then
- fullurl = trim(protocol_explicit)//"://"//trim(server_explicit)//trim(str)
+ if(present(server_explicit)) then
+ if(index(str, server_explicit) == 1) then
+ passurl = str(len_trim(server_explicit)+1:len_trim(str))
+ else
+ passurl = str
+ end if
else
- fullurl = trim(str)
+ passurl = str
end if
+
+ call self%request%init_basics(passurl, "?", "&")
- call self%request%init_basics(fullurl, "?", "&")
+ allocate(character(len=4)::self%protocol)
+ self%protocol = "http"
+
+ if(present(server_explicit)) then
+ allocate(character(len=len_trim(server_explicit)) :: self%server)
+ self%server = server_explicit
+ end if
if(present(method)) then
self%method = method
@@ -535,7 +547,6 @@ contains
implicit none
class(request), intent(inout)::self
- logical::safe_to_deallocate
self%token => null()
self%auth_level = 0
@@ -559,7 +570,7 @@ contains
implicit none
class(request), intent(inout)::self
- character(len=:), pointer::first, newloc
+ character(len=:), pointer::newloc
integer::i, j, n
@@ -797,6 +808,7 @@ contains
end subroutine response_set_filename_using_allocation
subroutine titan_request_init(self, str, ssl_connection)
+ use logging
implicit none
class(titan_request)::self
@@ -804,18 +816,18 @@ contains
type(c_ptr)::ssl_connection
character(len=:), pointer::size_text
- integer::i, ierr
+ integer::ierr
call self%request%init_basics(str, ";", ";")
size_text => self%q%get_value("size")
- read(size_text, '(I16)', iostat=ierr) self%size
- if(ierr /= 0) then
- self%size = 0
+ if(associated(size_text)) then
+ read(size_text, '(I16)', iostat=ierr) self%size
+ if(ierr /= 0) then
+ self%size = 0
+ end if
end if
- deallocate(size_text)
-
self%mimetype => self%q%get_value("mime")
self%token => self%q%get_value("token")
diff --git a/captain/web.f90 b/captain/web.f90
index f808eae..1421f96 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -98,15 +98,22 @@ contains
implicit none
type(http_request), intent(out)::req
- character(len=:), allocatable::url, script_name, cookie
+ character(len=:), allocatable::url, script_name, cookie, server_name, fullurl
character(len=4)::method
- integer::url_size, cookie_size
+ integer::url_size, cookie_size, sn_size
call get_environment_variable("REQUEST_URI", length=url_size)
- allocate(character(len=url_size)::url, script_name)
+ allocate(character(len=url_size)::url)
call get_environment_variable("REQUEST_URI", url)
+
+ call get_environment_variable("SCRIPT_NAME", length=sn_size)
+ allocate(character(len=sn_size)::script_name)
call get_environment_variable("SCRIPT_NAME", script_name)
+ call get_environment_variable("SERVER_NAME", length=sn_size)
+ allocate(character(len=sn_size)::server_name)
+ call get_environment_variable("SERVER_NAME", server_name)
+
call get_environment_variable("REQUEST_METHOD", method)
call get_environment_variable("HTTP_COOKIE", length=cookie_size)
@@ -117,6 +124,15 @@ contains
end if
! If we're in CGI mode, treat the "server" as the script name
+ call write_log("URL IS "//trim(url), level=LOG_DEBUG)
+ call write_log("SE IS "//trim(script_name), level=LOG_DEBUG)
+
+ ! We don't actually use this fabircated URL, but it is helpful for debugging
+ ! whatever the hell is going on when the request object is built...
+ allocate(character(len=(len_trim(server_name) + len_trim(url) + 7)) :: fullurl)
+ fullurl = "http://"//trim(server_name)//trim(url)
+ call write_log("FULL URL WOULD BE "//trim(fullurl), level=LOG_DEBUG)
+
if(allocated(cookie)) then
call req%init(url, server_explicit=script_name, protocol_explicit="http", method=method, cookiestring=cookie)
deallocate(cookie)
@@ -126,6 +142,7 @@ contains
deallocate(url)
deallocate(script_name)
+ deallocate(server_name)
end subroutine build_request_object