9 echo 'usage: hpost [ -l ] [ -[gpm] action ] [ -u ] url [ field:value | field@file ... ]' >[1=2]
16 case -u; shift; url=$1
17 case -g; shift; action=$1; method=mget
18 case -p; shift; action=$1; method=mpost
19 case -m; shift; action=$1; method=multi
35 case *:*@*; at=($1 $at)
48 echo -n $"f`{urlencode /env/i | sed 's!%3A!=!; s!%00$!!'}
52 echo -n $"f`{urlencode /env/i | sed 's!@.*$!=!'}
53 urlencode `{sed 's!^[^@]+@!!' /env/i}
59 cr=`{echo x | tr x \015}
61 k=`{sed 's!:.*$!!; q' /env/i}
63 echo 'Content-Disposition: form-data; name="'$"k'"'$"cr
66 sed '1s!^[^:]+:!!' /env/i
69 k=`{sed 's!@.*$!!; q' /env/i}
70 v=`{sed 's!^[^@]+@!!' /env/i}
74 echo 'Content-Disposition: form-data; name="'$"k'"; filename="'$"n'"'$"cr
75 echo 'Content-Type: '$"t$"cr
89 uenc | $hget -b $url -P $action
93 menc $"f | $hget -r 'Content-Type: multipart/form-data; boundary='$"f -b $url -P $action
102 # serialize $at and $af into a0=... a1=... for awk
103 # to preserve newlines and other special characters
110 hget $url | uhtml | tr '>' '
112 s!^(TAG|ATT)! \1!g; # escape our inline signaling
113 s!<[ ]*!\nTAG !g; # find starttags, mark with TAG name ...
114 s!>[^>"'']*$!!g; # remove garbage after the tag
115 # find attributes, mark with ATT name value
116 s!([a-zA-Z][a-zA-Z0-9:_]*)=("[^"]*"?|''[^'']*''?|[ ]*[^> ]+)!\nATT \1 \2!g;
117 ' | awk -v 'hpost='$"hpost -v 'url='$"url '
119 for(i=0; ENVIRON["a"i]!=""; i++){
121 x=index(s, ":"); y=index(s, "@")
122 if(y > 1 && (x < 1 || x > y))
125 ainput[n]=substr(s, x+1, length(s))
126 atypes[n]=substr(s, x, 1);
130 if(s !~ /[\n\\#;\|\^$=`''{}\(\)<> ]/)
132 gsub(/''/, "''''", s)
137 if(q=="\"" || q=="''"){
138 s=substr(s, 2, length(s))
140 if(x > 0) s=substr(s,1,x-1)
147 if(url!="") printf " -u %s", qw(url)
149 if(enctype=="multipart/form-data")
150 printf " -m %s", qw(action)
152 printf " -p %s", qw(action)
154 printf " -g %s", qw(action)
156 printf " %s%s%s", n, atypes[n], qw(ainput[n])
159 printf " %s%s%s", n, types[n], qw(input[n])
170 action=attr["action"]
171 method=tolower(attr["method"])
172 enctype=tolower(attr["enctype"])
175 selectname=attr["name"]
176 if(tag=="option" && selectname!=""){
177 if(attr["selected"]!=""){
178 input[selectname]=attr["value"]
182 if(tag=="input" || tag=="textarea" || tag=="submit"){
185 if(tolower(attr["type"])=="file"){
189 input[n]=attr["value"]
198 etag=tolower(substr($2, 2, length(etag)-1))
210 for(i=4; i<=NF; i++) $3=$3" "$i
211 attr[tolower(uq($2))]=uq($3)