aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/cuturl.c
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2015-04-23 04:53:35 -0500
committerepochqwert <epoch@hacking.allowed.org>2015-04-23 04:53:35 -0500
commita36652959e52e8c810b7d2d76a283b2ae9718d96 (patch)
treea8c9712f7eb243d72bfdb492c0c14e630e78a03d /src/bin/cuturl.c
parent318b3220d191011bb9132efd4dbd5e6fb467b4e7 (diff)
downloadmisc-a36652959e52e8c810b7d2d76a283b2ae9718d96.tar.gz
misc-a36652959e52e8c810b7d2d76a283b2ae9718d96.zip
elapsedtime handles partial seconds better
unescape now handles multiple lines from stdin clump can now have an optional argument to specify input separator cuturl can now take compressed short options. (like: cuturl -dPs) filemon... I don't remember. just reformatted it looks like. ipconvert. looks like I added explainations before output. normalpath now uses getenv("PWD") instead of getcwd() so you can pick what you want to be the base for relative paths. urcdump... nothing I guess. probably a space or something dumb. httpd... more environment variables set for CGIs
Diffstat (limited to 'src/bin/cuturl.c')
-rw-r--r--src/bin/cuturl.c95
1 files changed, 46 insertions, 49 deletions
diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c
index d706fd3..40b7766 100644
--- a/src/bin/cuturl.c
+++ b/src/bin/cuturl.c
@@ -2,9 +2,10 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+
/*
schemes are case sensitive but cononicals are lower case.
- domain is case insensitive. return it lowercased.
+ domain is case insensitive. return it lowercased?
port is optional and in decimal
path
scheme://username:password@domain:port/path?query_string#fragment_id
@@ -14,23 +15,6 @@
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"
-*/
-
#define AorB(a,b) ((a)?(a):(b))
#define F_SCHEME 1<<0
@@ -46,7 +30,7 @@ char *long_opts[]={"scheme","username","password","domain","port","path","query_
char *short_opts[]={"s","u","k","d","P","p","q","f"};
int main(int argc,char *argv[]) {
- char *line;
+ char *line=0;
char *scheme=0;
char *username=0;
char *password=0;
@@ -56,11 +40,11 @@ int main(int argc,char *argv[]) {
char *query_string=0;
char *fragment_id=0;
char sport[10];
+ char args[256];
struct servent *serv;
- //exactly 8 parts! let's store that in a byte.
- unsigned char flags=0;
- int i;
+ int i,j,c=0;
int size=1024;
+ char fixme=0;
char using_stdin=1;
char malloced=0;
if(argc > 1) {
@@ -74,6 +58,8 @@ int main(int argc,char *argv[]) {
printf("To set default values use environment variables like: CUTURL_[OPTION]\n");
return 2;
}
+ argc--;
+ argv++;
}
while(1) {
scheme=0;
@@ -84,24 +70,33 @@ int main(int argc,char *argv[]) {
path=0;
query_string=0;
fragment_id=0;
- if(!using_stdin) flags=0;
- if(argc > 1) {
- for(argc--,argv++;argc>0;argc--,argv++) {
+ if(!using_stdin) c=0;
+ if(argc >= 1) {
+ for(;argc>0;argc--,argv++) {
for(i=0;long_opts[i];i++) {
if(!strncmp(*argv,"--",2)) {
if(!strcmp(*argv+2,long_opts[i])) {
- flags|=(1<<i);
+ args[c]=1<<i;
+ c++;
break;
}
}
- else if(**argv=='-') {
- if(*(*argv+1)==*short_opts[i]) {
- flags|=(1<<i);
- break;
+ }
+ fixme=0;
+ if(**argv=='-' && argv[0][1] != '-') {
+ for(j=1;argv[0][j];j++) {
+ for(i=0;short_opts[i];i++) {
+ if(argv[0][j]==*short_opts[i]) {
+ args[c]=1<<i;
+ c++;
+ fixme=1;
+ }
}
}
}
+ if(fixme) continue;
if(long_opts[i]) continue;
+ //if we get here we are at data instead of flags. work on it.
line=*argv;
using_stdin=0;
argc--;
@@ -109,6 +104,9 @@ int main(int argc,char *argv[]) {
break;
}
}
+ if(!argc && !line) {//if we are out of arguments and it didn't include data
+ using_stdin=1;
+ }
if(using_stdin) {
line=malloc(size+1);
malloced=1;
@@ -120,6 +118,9 @@ int main(int argc,char *argv[]) {
for(i=0;line[i] && line[i] != '\n' && line[i] != '\r';i++);
line[i]=0;
+/// end of interface logic
+/// beginning of business logic
+
//split at first single / into line and path
for(i=0;line[i];i++) {
if(line[i] == '/' && line[i+1] == '/') {
@@ -198,7 +199,7 @@ int main(int argc,char *argv[]) {
}
}
- if(domain) {
+ if(domain) {//for magnet links.
if(strchr(domain,'?')) {
query_string=strchr(domain,'?');
*query_string=0;
@@ -218,11 +219,7 @@ int main(int argc,char *argv[]) {
password=0;
}
-// before deciding to also handle magnets
-// if(!domain) {
-// fprintf(stderr,"how the fuck is this supposed to be a URL?\n");
-// return 1;
-// }
+/// end of business logic
// printf("scheme://username:password@domain:port/path?query_string#fragment_id\n\n");
//let's set them to what'll get printed now...
@@ -234,22 +231,21 @@ int main(int argc,char *argv[]) {
serv=getservbyname(scheme,strcmp(scheme,"udp")?"tcp":"udp");
if(serv) snprintf(sport,sizeof(sport)-1,"%d",ntohs(serv->s_port));
port=AorB(port,AorB(getenv("CUTURL_PORT"),(serv?sport:"DEFAULT")));
- //port=AorB(port,AorB(getenv("CUTURL_PORT"),"DEFAULT"));
-
-
path=AorB(path,AorB(getenv("CUTURL_PATH"),"DEFAULT"));
query_string=AorB(query_string,AorB(getenv("CUTURL_QUERY_STRING"),"DEFAULT"));
fragment_id=AorB(fragment_id,AorB(getenv("CUTURL_FRAGMENT_ID"),"DEFAULT"));
- if(flags) {
- if(flags&F_SCHEME) printf("%s\n",scheme);
- if(flags&F_USERNAME) printf("%s\n",username);
- if(flags&F_PASSWORD) printf("%s\n",password);
- if(flags&F_DOMAIN) printf("%s\n",domain);
- if(flags&F_PORT) printf("%s\n",port);
- if(flags&F_PATH) printf("%s\n",path);
- if(flags&F_QUERY_STRING) printf("%s\n",query_string);
- if(flags&F_FRAGMENT_ID) printf("%s\n",fragment_id);
+ if(c) {
+ for(i=0;i<c;i++) {
+ if(args[i]&F_SCHEME) printf("%s\n",scheme);
+ if(args[i]&F_USERNAME) printf("%s\n",username);
+ if(args[i]&F_PASSWORD) printf("%s\n",password);
+ if(args[i]&F_DOMAIN) printf("%s\n",domain);
+ if(args[i]&F_PORT) printf("%s\n",port);
+ if(args[i]&F_PATH) printf("%s\n",path);
+ if(args[i]&F_QUERY_STRING) printf("%s\n",query_string);
+ if(args[i]&F_FRAGMENT_ID) printf("%s\n",fragment_id);
+ }
} else {
printf("scheme: %s\n",scheme);
printf("username: %s\n",username);
@@ -263,8 +259,9 @@ int main(int argc,char *argv[]) {
if(malloced) {
free(line);
malloced=0;
- } else {
line=0;
+ } else {
+ line=0;//???
}
}
return 0;