aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--captain/captian.f902
-rw-r--r--captain/external.f9025
-rw-r--r--captain/gemini.f9056
-rw-r--r--captain/levitating-captain.prj6
4 files changed, 77 insertions, 12 deletions
diff --git a/captain/captian.f90 b/captain/captian.f90
index 432bb0a..24fc34c 100644
--- a/captain/captian.f90
+++ b/captain/captian.f90
@@ -1,7 +1,7 @@
program captain
use captain_db
use config
-use logging, only: initialize_log => initialize
+use logging, only: initialize_log => initialize, logunit
implicit none
integer::mode
diff --git a/captain/external.f90 b/captain/external.f90
index d33e13d..86efe94 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -4,12 +4,12 @@ implicit none
contains
- subroutine external_request_gemini(request)
+ function external_request_gemini(request) result(renderunit)
use page_template
implicit none
character(*), intent(in)::request
-
+ integer::renderunit
character(1024)::template_file
type(template)::page
@@ -19,25 +19,34 @@ contains
if(trim(request) == "/" .or. trim(request) == "/index.gmi") then
-
-
+ call page%assign('title', 'Home')
+
else if(trim(request) == "/releases.gmi") then
-
+ call page%assign('title', 'Releases')
else if(trim(request) == "/jobs.gmi") then
-
+ call page%assign('title', 'Jobs')
else if(trim(request) == "/players.gmi") then
-
+ call page%assign('title', 'Players')
else if(trim(request) == "/about.gmi") then
+ call page%assign('title', 'About')
+
+ else
+
+ call page%assign('title', 'Not Found')
end if
+
+ open(newunit=renderunit, form="formatted", status="scratch", access='stream')
+
+ call page%render(renderunit)
- end subroutine external_request_gemini
+ end function external_request_gemini
end module external_handling \ No newline at end of file
diff --git a/captain/gemini.f90 b/captain/gemini.f90
index 7f21392..31b1deb 100644
--- a/captain/gemini.f90
+++ b/captain/gemini.f90
@@ -43,11 +43,57 @@ contains
end subroutine read_request
+ function read_into_buffer(unit_number, buffer)
+ implicit none
+
+ integer, intent(in)::unit_number
+ character, dimension(*), intent(out)::buffer
+ integer::read_into_buffer
+
+ integer::i, ierr
+
+ ierr = 0
+ i = 0
+ do while(ierr == 0 .and. i < len(buffer))
+ i = i + 1
+ read(unit_number, iostat=ierr) buffer(i)
+ end do
+
+ if(ierr /= 0) then
+ i = i - 1
+ end if
+
+ read_into_buffer = i
+
+ end function read_into_buffer
+
+ subroutine write_file(ssl, unit_number, mimetype)
+ use iso_c_binding, only: c_ptr, c_carriage_return, c_new_line
+ use jessl, only: ssl_write
+ implicit none
+
+ type(c_ptr)::ssl
+ integer, intent(in)::unit_number
+ character(*), intent(in)::mimetype
+ character, dimension(64)::buf
+ integer::buflen, written
+
+ call write_string(ssl, "20 "//trim(mimetype)//c_carriage_return//c_new_line)
+
+ buflen = read_into_buffer(unit_number, buf)
+ do while(buflen > 0)
+ written = ssl_write(ssl, buf(1:buflen))
+ buflen = read_into_buffer(unit_number, buf)
+ end do
+
+ end subroutine write_file
+
subroutine handle_request()
use jessl
use iso_c_binding
use config
use iso_fortran_env
+ use external_handling, only: external_request_gemini
implicit none
! For our TLS connection
@@ -60,6 +106,8 @@ contains
character(1024)::request
character(512)::mimetype
+ integer::rendered_unit
+
call library_init()
method = tls_server_method()
@@ -124,13 +172,15 @@ contains
if(request(1:4) == '/api') then
!call handle_api_request(request)
else
- call external_request_gemini(request)
+ rendered_unit = external_request_gemini(request)
end if
else
- call external_request_gemini(request)
+ rendered_unit = external_request_gemini(request)
end if
-
+ call write_file(ssl, rendered_unit, "text/gemini")
+
+ close(rendered_unit)
end subroutine handle_request
diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj
index 88c0910..535d37b 100644
--- a/captain/levitating-captain.prj
+++ b/captain/levitating-captain.prj
@@ -51,6 +51,12 @@
"filename":".\\external.f90",
"enabled":"1"
},{
+ "filename":".\\gemini.f90",
+ "enabled":"1"
+ },{
+ "filename":".\\log.f90",
+ "enabled":"1"
+ },{
"filename":".\\sqlite.f90",
"enabled":"1"
},{