aboutsummaryrefslogtreecommitdiff
path: root/favicon.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-02-23 15:44:25 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2021-02-23 15:44:25 -0500
commit36249ebd4dece7ee69cd85e7e169db0dc4315e3e (patch)
tree89b8cdcc7cc57963acac1429f6007b63ca93a595 /favicon.f90
parent6a0d3367e0b314d6c947950f7c3193be3d9d1465 (diff)
downloadLR-87-36249ebd4dece7ee69cd85e7e169db0dc4315e3e.zip
LR-87-36249ebd4dece7ee69cd85e7e169db0dc4315e3e.tar.gz
Added favicon support. Fixed UTF-8 display on dumb renderer.
Diffstat (limited to 'favicon.f90')
-rw-r--r--favicon.f90111
1 files changed, 111 insertions, 0 deletions
diff --git a/favicon.f90 b/favicon.f90
new file mode 100644
index 0000000..6f800db
--- /dev/null
+++ b/favicon.f90
@@ -0,0 +1,111 @@
+module favicon
+implicit none
+
+ private
+
+ public::get_favicon
+
+contains
+
+
+ subroutine get_server_favicon_file(server, filename)
+ use platform, only: dir_sep, get_settings_directory
+ implicit none
+
+ character(*), intent(in)::server
+ character(*), intent(out)::filename
+
+ character(len=256)::dir
+
+ call get_settings_directory(dir)
+ filename = trim(dir)//dir_sep//trim(server)//".favicon.txt"
+
+ end subroutine get_server_favicon_file
+
+ function get_favicon_from_cache(server) result(f)
+ implicit none
+
+ character(len=4)::f
+ character(*), intent(in)::server
+ character(len=384)::filename
+
+ integer::unumber, iostatus
+
+ call get_server_favicon_file(server, filename)
+
+ f = ' '
+
+ open(newunit=unumber, file=filename, &
+ action="read", iostat=iostatus)
+
+ if(iostatus == 0) then
+ ! second line
+ read(unumber, '(A)') f
+ if(trim(f) /= "NA") then
+ read(unumber, '(A)') f
+ end if
+ close(unumber)
+ end if
+
+ end function get_favicon_from_cache
+
+ function request_favicon(server) result(f)
+ use gemini_protocol, only: request_url, is_failure_code
+ implicit none
+
+ character(len=4)::f
+ character(*), intent(in)::server
+ character(len=1024)::url
+ character(len=128)::return_type
+
+ character(len=384)::cache_filename
+
+ integer::return_code, unum, ios
+
+ call get_server_favicon_file(server, cache_filename)
+ open(newunit=unum, file=cache_filename, action="write", iostat=ios)
+ if(ios == 0) then
+
+ ! Per gemini://mozz.us/files/rfc_gemini_favicon.gmi
+ url = "gemini://"//trim(server)//"/favicon.txt"
+
+ return_code = request_url(url, unum, return_type)
+ close(unum)
+
+ if(is_failure_code(return_code)) then
+ open(newunit=unum, file=cache_filename, action="write", iostat=ios)
+ write(unum, '(A2,2X)') "NA"
+ close(unum)
+ end if
+
+ f = get_favicon_from_cache(server)
+
+ else
+
+ f = ' '
+
+ end if
+
+ end function request_favicon
+
+ function get_favicon(server) result(f)
+ implicit none
+
+ character(len=4)::f
+ character(*), intent(in)::server
+
+ f = get_favicon_from_cache(server)
+
+ ! Blank - request it
+ if(len_trim(f) == 0) then
+ f = request_favicon(server)
+ end if
+
+ ! NA - server said no at some point
+ if(trim(f) == "NA") then
+ f = ' '
+ end if
+
+ end function get_favicon
+
+end module favicon