From e23c6287bb1124397c126c83cc73fed17fda998f Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Thu, 1 Jan 2015 02:29:26 -0600 Subject: added zengoph which is a zenity based gopher browser cuturl is for getting parts out of URLs easier --- nocompile/bin/zengoph.sh | 48 ++++++++++++++++ src/bin/cuturl.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100755 nocompile/bin/zengoph.sh create mode 100644 src/bin/cuturl.c diff --git a/nocompile/bin/zengoph.sh b/nocompile/bin/zengoph.sh new file mode 100755 index 0000000..defac73 --- /dev/null +++ b/nocompile/bin/zengoph.sh @@ -0,0 +1,48 @@ +#!/usr/pkg/bin/bash +### +### I just wrote this so I could have a little gopher client of my own +### requires zenity. I just like using it for scripted GUIs. +### + +PATH=$PATH:/usr/pkg/sbin +if [ "_$1" = "_" ];then + printf "usage: $0 gopher://hacking.allowed.org/" + exit 1 +fi + +domain=$(printf "%s" "$1" | ./cuturl | grep ^domain | cut '-d ' -f2) +port=70 +request=$(printf "%s\r\n" "$1" | ./cuturl | grep ^path | cut '-d ' -f2) + +while true;do + +echo $domain +echo $port +echo $request + +tmp="$(printf "%s" "$request" \ + | nc $domain $port \ + | tr -d '\r' \ + | tr '\t' '\n' \ + | zenity --width=1000 --height=500 --list --column=a --column=b --column=c --column=d --print-column=1,2 + )" +echo $tmp +request=$(printf "%s" "$tmp" | cut '-d|' -f2) +name_and_type=$(printf "%s" "$tmp" | cut '-d|' -f1) +type=$(printf "%s" "$name_and_type" | cut -b1) +name=$(printf "%s" "$name_and_type" | cut -b2-) + +echo request $request +echo type $type +echo name $name +if [ "_$type" = "_7" ];then + args="$(zenity --entry)" + request=$(printf "%s\t%s\r\n" "$request" "$args") +else + request=$(printf "%s\r\n" "$request") +fi +if [ "_$tmp" = "_" ];then + exit +fi + +done diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c new file mode 100644 index 0000000..945d640 --- /dev/null +++ b/src/bin/cuturl.c @@ -0,0 +1,141 @@ +#include +#include +/* + schemes are case sensitive but cononicals are lower case. + domain is case insensitive. return it lowercased. + port is optional and in decimal + path + scheme://username:password@domain:port/path?query_string#fragment_id + mailto:username@domain + + optional stuff: + scheme, username, password, port, path, query_string, fragment_id +*/ + +/* +#define DEFAULT_SCHEME "http" +#define DEFAULT_USERNAME "anonymous" +#define DEFAULT_PASSWORD "anonymous" +#define DEFAULT_PORT "80" +#define DEFAULT_QUERY_STRING "" +#define DEFAULT_FRAGMENT_ID "" +*/ +#define DEFAULT_SCHEME "DEFAULT" +#define DEFAULT_USERNAME "DEFAULT" +#define DEFAULT_PASSWORD "DEFAULT" +#define DEFAULT_PORT "DEFAULT" +#define DEFAULT_PATH "DEFAULT" +#define DEFAULT_QUERY_STRING "DEFAULT" +#define DEFAULT_FRAGMENT_ID "DEFAULT" + +int main() { + char line[1024]; + char *scheme=0; + char *username=0; + char *password=0; + char *domain=0; + char *port=0; + char *path=0; + char *query_string=0; + char *fragment_id=0; + int i; + fgets(line,sizeof(line),stdin); + for(i=0;line[i] && line[i] != '\n' && line[i] != '\r';i++); + line[i]=0; + + //split at first single / into line and path + for(i=0;line[i];i++) { + if(line[i] == '/' && line[i+1] == '/') { + i++; + continue; + } + if(line[i] == '/') { + line[i]=0; + path=line+i+1; + break; + } + } + + if(path) { + if(strchr(path,'?')) { + query_string=strchr(path,'?'); + *query_string=0; + query_string++; + } + } + + if(query_string) { + if(strchr(query_string,'#')) { + fragment_id=strchr(query_string,'#'); + *fragment_id=0; + fragment_id++; + } + } + + if(strstr(line,"://")) { + scheme=line; + domain=strstr(line,"://"); + *domain=0; + domain+=3; + } else { + domain=line; + } + + if(domain) { + if(strchr(domain,'@')) { + username=domain; + domain=strchr(domain,'@'); + *domain=0; + domain++; + } + } + + if(username) { + if(strchr(username,':')) { + password=strchr(username,':'); + *password=0; + password++; + } + } + + if(domain) { + if(strchr(domain,']')) { + if(strchr(strchr(domain,']'),':')) { + port=strchr(strchr(domain,']'),':'); + *port=0; + port++; + } + } else { + if(strchr(domain,':')) { + port=strchr(domain,':'); + *port=0; + port++; + } + } + } + + if(domain) { + if(strchr(domain,'?')) { + query_string=strchr(domain,'?'); + *query_string=0; + query_string++; + } + } + + if(!scheme && username) { + scheme=username; + username=password; + password=0; + } + +// printf("scheme://username:password@domain:port/path?query_string#fragment_id\n\n"); + printf("scheme: %s\n",scheme); + printf("username: %s\n",username); + printf("password: %s\n",password); + printf("domain: %s\n",domain); + printf("port: %s\n",port); + printf("path: %s\n",path); + printf("query_string: %s\n",query_string); + printf("fragment_id: %s\n",fragment_id); + return 0; +} -- cgit v1.2.3