aboutsummaryrefslogtreecommitdiff
path: root/protocol.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-01 20:45:13 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-01 20:45:13 -0400
commit1ef40339cc161484b3e70d34ab4d507b758b29eb (patch)
treef1530f7dc01842ffe1dab393ec8fc374dc42b5e5 /protocol.f90
parent4108ae479d67067789f98267175e127e6a2a61ad (diff)
downloadLR-87-1ef40339cc161484b3e70d34ab4d507b758b29eb.zip
LR-87-1ef40339cc161484b3e70d34ab4d507b758b29eb.tar.gz
Simple, single request function for retrieving a gemini page into a unit number
Diffstat (limited to 'protocol.f90')
-rw-r--r--protocol.f9045
1 files changed, 43 insertions, 2 deletions
diff --git a/protocol.f90 b/protocol.f90
index fa36fe7..bd109c1 100644
--- a/protocol.f90
+++ b/protocol.f90
@@ -8,11 +8,14 @@ implicit none
integer, parameter::STATUS_PERMFAIL = 5
integer, parameter::STATUS_CERTREQ = 6
integer, parameter::STATUS_LOCALFAIL = -1
-
+
+ integer, parameter::BUFFER_SIZE = 256
+
contains
function request_url(url, unit_number, server_name) result(returncode)
use request
+ use iso_c_binding
implicit none
character(*), intent(in)::url
@@ -23,7 +26,13 @@ contains
character(:), allocatable::server
+ type(connection)::conn
+
+ integer::bytes_received, i
+ character, dimension(BUFFER_SIZE)::buffer
+
returncode = -1
+ rewind(unit_number)
if(present(server_name)) then
allocate(character(len=len_trim(server_name)) :: server)
@@ -32,8 +41,40 @@ contains
server = get_server_from_url(url)
end if
+ conn = open_connection(server)
-
+ if(conn%code == CONNECTION_OPEN) then
+ if(send_string(conn%ssl, url//c_carriage_return//c_new_line, trimming=.false.)) then
+
+ bytes_received = retrieve_characters(conn%ssl, buffer)
+
+ do while(bytes_received > 0)
+
+ do i=1, bytes_received
+ write(unit_number, '(A1)', advance='no') buffer(i)
+ end do
+
+ bytes_received = retrieve_characters(conn%ssl, buffer)
+ end do
+
+ rewind(unit_number)
+ read(unit_number, '(I1)') returncode
+
+ else
+
+ returncode = -1
+ write(unit_number, *) "Send Error: Could Not Send Request"
+
+ end if
+
+ else
+
+ returncode = -1
+ write(unit_number, *) "Connection Error: "//trim(translate_connection_code(conn%code))
+
+ end if
+
+ call close_connection(conn)
end function request_url