aboutsummaryrefslogtreecommitdiff
path: root/main.F90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-05 07:54:53 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-05 07:54:53 -0400
commit723324ae71f8209e4b1757a3f84bd0e66b6c6319 (patch)
tree91737e20dba6e06068ea37bb9bcb79122a12d427 /main.F90
parent1ef40339cc161484b3e70d34ab4d507b758b29eb (diff)
downloadLR-87-723324ae71f8209e4b1757a3f84bd0e66b6c6319.zip
LR-87-723324ae71f8209e4b1757a3f84bd0e66b6c6319.tar.gz
Actual client can now load and display a page using dumb_renderer
Diffstat (limited to 'main.F90')
-rw-r--r--main.F90137
1 files changed, 137 insertions, 0 deletions
diff --git a/main.F90 b/main.F90
new file mode 100644
index 0000000..cb9e8b1
--- /dev/null
+++ b/main.F90
@@ -0,0 +1,137 @@
+program gemini
+use request
+use dumb_render
+use gemini_protocol
+use layout
+use file_handling
+
+#ifdef WINDOWS
+use wsa_network, only: windows_network_startup => startup
+#endif
+
+implicit none
+
+ character(256)::initial_site
+ character(1024)::current_url
+ type(connection)::conn
+ type(dumb_renderer)::r
+
+ logical::running
+ logical::loaded
+
+ integer::return_code
+
+ integer, parameter::io = 100
+
+ type(line), pointer::first_line
+
+#ifdef WINDOWS
+ call windows_network_startup()
+#endif
+
+ if(command_argument_count() > 0) then
+
+ call get_command_argument(1, initial_site)
+
+ if(index(initial_site, "//") > 0) then
+
+ if(index(initial_site, "gemini://") /= 1) then
+ Print *, "Please provide a gemini URL to start (or nothing at all)"
+ stop
+ end if
+
+ else
+
+ initial_site = "gemini://"//trim(initial_site)
+
+ end if
+
+ else
+
+ initial_site = "gemini://gemini.circumlunar.space/" ! gemini://pon.ix.tc/
+
+ end if
+
+ running = .true.
+ loaded = .false.
+ call r%initialize()
+
+ current_url = initial_site
+
+ open(unit=io, form="formatted", status="scratch", access='stream')
+
+ do while(running)
+
+ if(.not. loaded) then
+
+ call r%report_status("Requesting "//trim(current_url))
+
+ return_code = request_url(trim(current_url), io)
+
+ call update_status(r, current_url, return_code)
+
+ loaded = .true.
+
+ end if
+
+ if(return_code == STATUS_REDIRECT) then
+
+ call get_redirect_url(io, current_url)
+ loaded = .false.
+
+ else
+
+ first_line => load_unit(io, file_type_gemini)
+
+ call r%report_status("Performing Layout")
+ call layout_lines(first_line, r)
+
+ end if
+
+
+ running = .not. loaded
+
+
+
+ end do
+
+ close(io)
+
+contains
+
+ subroutine update_status(r, url, code)
+ use gemini_protocol
+ implicit none
+
+ class(renderer)::r
+ character(*), intent(in)::url
+ integer, intent(in)::code
+
+ select case (code)
+
+ case (STATUS_LOCALFAIL)
+ call r%report_status("Network failure loading "//trim(url))
+
+ case (STATUS_INPUT)
+ call r%report_status("Ok (input)")
+
+ case (STATUS_SUCCESS)
+ call r%report_status("Ok")
+
+ case (STATUS_REDIRECT)
+ call r%report_status("Ok (redirect)")
+
+ case (STATUS_TEMPFAIL)
+ call r%report_status("Server reports temporary failure")
+
+ case (STATUS_PERMFAIL)
+ call r%report_status("Server reports permanent failure")
+
+ case (STATUS_CERTREQ)
+ call r%report_status("Server requesting certificate (unsupported)")
+
+ end select
+
+ end subroutine update_status
+
+end program gemini