about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2020-05-23 19:46:58 -0500
committerCase Duckworth2020-05-23 19:46:58 -0500
commitcf12497051da39b4c3e0b233de89b05ca1ad9627 (patch)
treebf750656d8d8d90652b26a65bb4ccd77c12a7760
parentFix redirecting issues (diff)
downloadbollux-cf12497051da39b4c3e0b233de89b05ca1ad9627.tar.gz
bollux-cf12497051da39b4c3e0b233de89b05ca1ad9627.zip
Add URL normalizing functions for use later
-rwxr-xr-xbollux57
1 files changed, 56 insertions, 1 deletions
diff --git a/bollux b/bollux index b9d1443..50b4a81 100755 --- a/bollux +++ b/bollux
@@ -105,7 +105,62 @@ NOT_IMPLEMENTED() { die 200 "NOT IMPLEMENTED!!!"; }
105NOT_FULLY_IMPLEMENTED() { log 1 "NOT FULLY IMPLEMENTED!!!"; } 105NOT_FULLY_IMPLEMENTED() { log 1 "NOT FULLY IMPLEMENTED!!!"; }
106 106
107### gemini ### 107### gemini ###
108# normalize a gemini address 108# url functions
109# normalize a path from /../ /./ /
110normalize_path() { # normalize_path <<< PATH
111 gawk '{
112 if ($0 == "" || $0 ~ /^\/\/[^\/]/) {
113 return -1
114 }
115 split($0, path, /\//)
116 for (c in path) {
117 if (path[c] == "" || path[c] == ".") {
118 continue
119 }
120 if (path[c] == "..") {
121 sub(/[^\/]+$/, "", ret)
122 continue
123 }
124 if (! ret || match(ret, /\/$/)) {
125 slash = ""
126 } else {
127 slash = "/"
128 }
129 ret = ret slash path[c]
130 }
131 print ret
132 }'
133}
134
135# split a url into the URL array
136split_url() {
137 gawk '{
138 if (match($0, /^[A-Za-z]+:/)) {
139 arr["scheme"] = substr($0, RSTART, RLENGTH)
140 $0 = substr($0, RLENGTH + 1)
141 }
142 if (match($0, /^\/\/[^\/?#]+?/) || (match($0, /^[^\/?#]+?/) && scheme)) {
143 arr["authority"] = substr($0, RSTART, RLENGTH)
144 $0 = substr($0, RLENGTH + 1)
145 }
146 if (match($0, /^\/?[^?#]+/)) {
147 arr["path"] = substr($0, RSTART, RLENGTH)
148 $0 = substr($0, RLENGTH + 1)
149 }
150 if (match($0, /^\?[^#]+/)) {
151 arr["query"] = substr($0, RSTART, RLENGTH)
152 $0 = substr($0, RLENGTH + 1)
153 }
154 if (match($0, /^#.*/)) {
155 arr["fragment"] = substr($0, RSTART, RLENGTH)
156 $0 = substr($0, RLENGTH + 1)
157 }
158 for (part in arr) {
159 printf "URL[\"%s\"]=\"%s\"\n", part, arr[part]
160 }
161 }'
162}
163
109# example.com => gemini://example.com/ 164# example.com => gemini://example.com/
110_address() { # _address URL 165_address() { # _address URL
111 addr="$1" 166 addr="$1"