aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-05 11:56:54 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-05 11:56:54 -0400
commitb063cac571202757ec25f2c6e2a772684b88d4ae (patch)
treebcdd9426a90d8e9bec4498bffd2f97686ba28d41
parent0ade9914918238b8da35e995fe9782a517988ae2 (diff)
downloadLR-87-b063cac571202757ec25f2c6e2a772684b88d4ae.tar.gz
LR-87-b063cac571202757ec25f2c6e2a772684b88d4ae.zip
Added input handling with escaping, all untested.
-rw-r--r--escape.f9037
-rw-r--r--gemini-windows.prj5
-rw-r--r--main.F9021
-rw-r--r--render.f9042
4 files changed, 103 insertions, 2 deletions
diff --git a/escape.f90 b/escape.f90
new file mode 100644
index 0000000..d960459
--- /dev/null
+++ b/escape.f90
@@ -0,0 +1,37 @@
+module escaper
+
+ character(*), parameter::need_escape = " $&`:<>[]{}+#%@/;=?\^|~',"//'"'
+
+contains
+
+ subroutine escape_string(text)
+ implicit none
+
+ character(*), intent(inout)::text
+ integer::i
+ character(3)::replace_text
+ integer::replace_code
+
+ i=1
+ do while(i < len_trim(text))
+
+ if(index(need_escape, text(i:i)) > 0) then
+ replace_code = iachar(text(i:i))
+ write(replace_text, '(A1,Z2)') "%", replace_code
+ if(i == 1) then
+ text = replace_text//text(2:len_trim(text))
+ else if(i == len_trim(text)) then
+ text = text(1:(i-1))//replace_text
+ else
+ text = text(1:(i-1))//replace_text//text((i+1):len_trim(text))
+ end if
+ i = i + 3
+ else
+ i = i + 1
+ end if
+
+ end do
+
+ end subroutine escape_string
+
+end module escaper \ No newline at end of file
diff --git a/gemini-windows.prj b/gemini-windows.prj
index d70f6cd..79a1595 100644
--- a/gemini-windows.prj
+++ b/gemini-windows.prj
@@ -32,6 +32,9 @@
"filename":".\\dumb_render.f90",
"enabled":"1"
},{
+ "filename":".\\escape.f90",
+ "enabled":"1"
+ },{
"filename":".\\files.f90",
"enabled":"1"
},{
@@ -91,7 +94,7 @@
"Launch Using MPI":"false",
"Keep Console":"true",
"External Console":"true",
- "Command Line Arguments":"gemini://pon.ix.tc",
+ "Command Line Arguments":"",
"Build Before Launch":"true"
},
"Build Options":{
diff --git a/main.F90 b/main.F90
index 9ab1782..a457d01 100644
--- a/main.F90
+++ b/main.F90
@@ -18,6 +18,7 @@ implicit none
logical::running
logical::loaded
+ logical::populated
integer::return_code
@@ -62,11 +63,19 @@ implicit none
do while(running)
+ if(index(current_url, "gemini://") /= 1) then
+ call r%draw_error("Only gemini:// URLs are supported")
+ populated = .false.
+ loaded = .true.
+ return_code = STATUS_LOCALFAIL
+ end if
+
if(.not. loaded) then
call r%report_status("Requesting "//trim(current_url))
return_code = request_url(trim(current_url), io)
+ populated = .true.
call update_status(r, current_url, return_code)
@@ -76,8 +85,18 @@ implicit none
call get_redirect_url(io, current_url)
loaded = .false.
+ populated = .false.
- else
+ else if(return_code == STATUS_INPUT) then
+
+ if(handle_input(r, current_url, io)) then
+ ! Should force a new load
+ loaded = .false.
+ else
+ loaded = .true.
+ end if
+
+ else if(populated) then
first_line => load_unit(io, file_type_gemini)
loaded = .true.
diff --git a/render.f90 b/render.f90
index b3b1c32..405fff9 100644
--- a/render.f90
+++ b/render.f90
@@ -275,4 +275,46 @@ contains
end subroutine render_link
+ function handle_input(r, url, unit_number)
+ use escaper
+ implicit none
+
+ class(renderer)::r
+ character(*), intent(inout)::url
+ integer, intent(in)::unit_number
+
+ logical::handle_input
+
+ character(1024)::response_line
+ character(256)::answer
+ integer::question_index
+
+ rewind(unit_number)
+
+ read(unit_number, '(A1024)') response_line
+ question_index = 3
+ do while(response_line(question_index:question_index) == " " .or. &
+ response_line(question_index:question_index) == char(9))
+
+ question_index = question_index + 1
+
+ end do
+
+ handle_input = r%request_input(response_line(question_index:len_trim(response_line)), &
+ answer)
+
+ if(handle_input) then
+ question_index = index(url, "?")
+ if(question_index < 1) then
+ url = trim(url)//"?"
+ question_index = len_trim(url)
+ end if
+
+ call escape_string(answer)
+
+ url = url(1:question_index)//answer
+ end if
+
+ end function handle_input
+
end module render