aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-12 10:32:39 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-12 10:32:39 -0400
commitfca71fde0161a59ac650bd690a3413ffd866662d (patch)
tree72b1e6040f0b2401c358d54e1bdec9f0724a7d41 /captain
parent025b5d1dcbb30e727afee3307d49328432bae603 (diff)
downloadlevitating-fca71fde0161a59ac650bd690a3413ffd866662d.tar.gz
levitating-fca71fde0161a59ac650bd690a3413ffd866662d.zip
URLs in instructions can now leave out the server implying download and upload from the server itself. Download and upload both work correctly.
Diffstat (limited to 'captain')
-rw-r--r--captain/api.f901
-rw-r--r--captain/example/levitating.conf4
-rw-r--r--captain/external.f9038
-rw-r--r--captain/gemini.f909
-rw-r--r--captain/log.f902
-rw-r--r--captain/response.f902
-rw-r--r--captain/special.f9027
7 files changed, 77 insertions, 6 deletions
diff --git a/captain/api.f90 b/captain/api.f90
index fc4e248..120f5e3 100644
--- a/captain/api.f90
+++ b/captain/api.f90
@@ -2,7 +2,6 @@ module api_handling
use iso_c_binding
implicit none
- character(*), parameter::RESPONSE_JSON_OKAY = '{"status": "okay"}'
character(*), parameter::RESPONSE_JSON_IDLE = '{"status": "idle"}'
character(*), parameter::RESPONSE_JSON_WORK_AVAILABLE = &
'{"status": "pending",'//c_new_line//' "job": {job_number},'//c_new_line//' "instruction": "{instruction_name}"}'
diff --git a/captain/example/levitating.conf b/captain/example/levitating.conf
index 5726e9b..dc4bcfe 100644
--- a/captain/example/levitating.conf
+++ b/captain/example/levitating.conf
@@ -5,7 +5,7 @@ database = /home/jeff/Workspace/levitating/captain/example/store.db
log-filename = /tmp/levitating.log
-log-level = 4
+log-level = 10
project = misc-build
@@ -24,3 +24,5 @@ static-directory = /home/jeff/Workspace/levitating/captain/example/static
script-directory = /home/jeff/Workspace/levitating/captain/sql
instructions-directory = /home/jeff/Workspace/levitating/captain/example/instructions
+
+release-directory = /home/jeff/Workspace/levitating/captain/example/releases
diff --git a/captain/external.f90 b/captain/external.f90
index 518abcb..c4dcb5a 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -791,4 +791,40 @@ contains
end function external_request_gemini
-end module external_handling \ No newline at end of file
+ function external_request_titan(req) result(resp)
+ use server_response
+ use special_filenames
+ use logging
+ implicit none
+
+ type(titan_request), intent(in)::req
+ type(response)::resp
+
+ character(len=:), pointer::fullpath
+ character(12)::job_text, task_text
+ integer::job_id, task_num
+
+ character(64)::msg
+
+ fullpath => get_full_filename_from_request(req)
+
+ if(associated(fullpath)) then
+
+ ! Write the file
+ call write_log("Storing titan file to "//trim(fullpath), LOG_DEBUG)
+
+ call req%write_to(fullpath)
+
+ resp%code = GEMINI_CODE_SUCCESS
+ call resp%set_body_contents(RESPONSE_JSON_OKAY)
+ resp%body_mimetype = "text/plain"
+
+ else
+
+ resp%code = GEMINI_CODE_PERMFAIL
+
+ end if
+
+ end function external_request_titan
+
+end module external_handling
diff --git a/captain/gemini.f90 b/captain/gemini.f90
index 099a81e..2afd327 100644
--- a/captain/gemini.f90
+++ b/captain/gemini.f90
@@ -177,7 +177,7 @@ contains
use iso_c_binding
use config
use iso_fortran_env
- use external_handling, only: external_request_gemini
+ use external_handling, only: external_request_gemini, external_request_titan
use api_handling
use logging
use server_response
@@ -274,7 +274,12 @@ contains
resp = api_request_titan(treq)
end if
else
- resp = external_request_gemini(req)
+ if(req%protocol == "gemini") then
+ resp = external_request_gemini(req)
+ else if(req%protocol == "titan") then
+ call treq%init_from_request(req, ssl)
+ resp = external_request_titan(treq)
+ end if
end if
call write_log("Handling response", LOG_DEBUG)
diff --git a/captain/log.f90 b/captain/log.f90
index 4289f80..e4cd65b 100644
--- a/captain/log.f90
+++ b/captain/log.f90
@@ -59,7 +59,7 @@ contains
! GNU Extension... :(
write(logunit, *) fdate()//" ("//trim(adjustl(pid_text))//") :: "//string
- call close(logunit)
+ close(logunit)
end if
diff --git a/captain/response.f90 b/captain/response.f90
index efa99bb..09184f9 100644
--- a/captain/response.f90
+++ b/captain/response.f90
@@ -7,6 +7,8 @@ implicit none
integer, parameter::GEMINI_CODE_REDIRECT = 30
integer, parameter::GEMINI_CODE_PERMFAIL = 50
+ character(*), parameter::RESPONSE_JSON_OKAY = '{"status": "okay"}'
+
type :: response
integer::code
diff --git a/captain/special.f90 b/captain/special.f90
index 43a4a6a..9adbb75 100644
--- a/captain/special.f90
+++ b/captain/special.f90
@@ -6,12 +6,16 @@ contains
function get_special_full_filename(category, filename) result(res)
use utilities, only: combine_paths
use config
+ use logging
implicit none
character(*), intent(in)::category, filename
character(len=:), pointer::res
res => null()
+
+ call write_log("category: "//trim(category))
+ call write_log("file: "//trim(filename))
if(trim(category) == "releases") then
allocate(character(len=(len_trim(release_dir)+len_trim(filename)+1)) :: res)
@@ -33,6 +37,8 @@ contains
call combine_paths(instructions_dir, filename, res)
end if
+ call write_log("path: "//trim(res))
+
end function get_special_full_filename
function get_instructions_static_filename(instruction_id) result(res)
@@ -80,4 +86,25 @@ contains
end function get_task_result_static_filename
+ function get_full_filename_from_request(req) result(res)
+ use server_response
+ implicit none
+
+ class(request)::req
+ character(len=:), pointer::res
+
+ character(256)::first
+ character(1024)::remaining
+ integer::i
+
+ call req%path_component(1, first)
+
+ i = index(req%location, trim(first))
+ i = i + len_trim(first) + 1
+ remaining = req%location(i:len_trim(req%location))
+
+ res => get_special_full_filename(first, trim(remaining))
+
+ end function get_full_filename_from_request
+
end module special_filenames