aboutsummaryrefslogtreecommitdiff
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
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.
-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
-rw-r--r--player/levitating-player.prj4
-rw-r--r--player/tasks.f9040
9 files changed, 110 insertions, 17 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
diff --git a/player/levitating-player.prj b/player/levitating-player.prj
index 3817ee4..fef15ef 100644
--- a/player/levitating-player.prj
+++ b/player/levitating-player.prj
@@ -32,9 +32,7 @@
"enabled":"1"
},{
"filename":"instructions.f90",
- "enabled":"1",
- "panel":1,
- "open":"1"
+ "enabled":"1"
},{
"filename":"player.F90",
"enabled":"1"
diff --git a/player/tasks.f90 b/player/tasks.f90
index c64cb40..87b7d66 100644
--- a/player/tasks.f90
+++ b/player/tasks.f90
@@ -70,7 +70,7 @@ contains
end function shell
function upload(url, source_filename)
- use config, only: token
+ use config, only: token, captain
use gemini_protocol, only: titan_post_url, STATUS_SUCCESS
implicit none
@@ -81,15 +81,26 @@ contains
character(len=:), allocatable::mod_url
integer(kind=8)::file_size
- integer::unit_number, istatus
+ integer::unit_number, istatus, url_length
inquire(file=source_filename, size=file_size)
open(newunit=unit_number, file=trim(source_filename), status='UNKNOWN', &
access='STREAM', form='UNFORMATTED', iostat=istatus)
-
- allocate(character(len=len_trim(url)) :: mod_url)
- mod_url = url
+
+ if(index(url, "://") > 0) then
+ allocate(character(len=len_trim(url)) :: mod_url)
+ mod_url = url
+ else
+ url_length = len_trim(url) + len_trim(captain) + 16
+ allocate(character(len=url_length) :: mod_url)
+ mod_url = "titan://"//trim(captain)
+ if(url(1:1) == "/") then
+ mod_url = trim(mod_url)//trim(url)
+ else
+ mod_url = trim(mod_url)//"/"//trim(url)
+ end if
+ end if
if(istatus == 0) then
istatus = titan_post_url(mod_url, unit_number, file_size, token)
@@ -105,6 +116,7 @@ contains
function download(url, destination_filename)
use gemini_protocol, only: request_url, STATUS_SUCCESS
+ use config, only: captain
implicit none
logical::download
@@ -114,14 +126,26 @@ contains
character(len=256)::mimetype
character(len=:), allocatable::mod_url
+ integer::url_length
integer::unit_number, istatus
- allocate(character(len=len_trim(url)) :: mod_url)
- mod_url = url
+ if(index(url, "://") > 0) then
+ allocate(character(len=len_trim(url)) :: mod_url)
+ mod_url = url
+ else
+ url_length = len_trim(url) + len_trim(captain) + 16
+ allocate(character(len=url_length) :: mod_url)
+ mod_url = "gemini://"//trim(captain)
+ if(url(1:1) == "/") then
+ mod_url = trim(mod_url)//trim(url)
+ else
+ mod_url = trim(mod_url)//"/"//trim(url)
+ end if
+ end if
open(newunit=unit_number, file=trim(destination_filename), status='UNKNOWN', &
- access='STREAM', form='UNFORMATTED', iostat=istatus)
+ access='STREAM', form='FORMATTED', iostat=istatus)
if(istatus == 0) then
istatus = request_url(mod_url, unit_number, mimetype)