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}
71 ' v=`{sed 's!^[^@]+@!!' /env/i}
75 echo 'Content-Disposition: form-data; name="'$"k'"; filename="'$"n'"'$"cr
76 echo 'Content-Type: '$"t$"cr
90 uenc | $hget -b $url -P $action
94 menc $"f | $hget -r 'Content-Type: multipart/form-data; boundary='$"f -b $url -P $action
103 # serialize $at and $af into a0=... a1=... for awk
104 # to preserve newlines and other special characters
111 hget $url | uhtml | tr '>' '
113 s!^(TAG|ATT)! \1!g; # escape our inline signaling
114 s!<[ ]*!\nTAG !g; # find starttags, mark with TAG name ...
115 s!>[^>"'']*$!!g; # remove garbage after the tag
116 # find attributes, mark with ATT name value
117 s!([a-zA-Z][a-zA-Z0-9:_]*)=("[^"]*"?|''[^'']*''?|[ ]*[^> ]+)!\nATT \1 \2!g;
118 ' | awk -v 'hpost='$"hpost -v 'url='$"url '
120 for(i=0; ENVIRON["a"i]!=""; i++){
122 x=index(s, ":"); y=index(s, "@")
123 if(y > 1 && (x < 1 || x > y))
126 ainput[n]=substr(s, x+1, length(s))
127 atypes[n]=substr(s, x, 1);
131 if(s !~ /[\n\\#;\|\^$=`''{}\(\)<> ]/)
133 gsub(/''/, "''''", s)
138 if(q=="\"" || q=="''"){
139 s=substr(s, 2, length(s))
141 if(x > 0) s=substr(s,1,x-1)
148 if(url!="") printf " -u %s", qw(url)
150 if(enctype=="multipart/form-data")
151 printf " -m %s", qw(action)
153 printf " -p %s", qw(action)
155 printf " -g %s", qw(action)
157 printf " %s%s%s", n, atypes[n], qw(ainput[n])
160 printf " %s%s%s", n, types[n], qw(input[n])
171 action=attr["action"]
172 method=tolower(attr["method"])
173 enctype=tolower(attr["enctype"])
176 selectname=attr["name"]
177 if(tag=="option" && selectname!=""){
178 if(attr["selected"]!=""){
179 input[selectname]=attr["value"]
183 if(tag=="input" || tag=="textarea" || tag=="submit"){
186 if(tolower(attr["type"])=="file"){
190 input[n]=attr["value"]
199 etag=tolower(substr($2, 2, length(etag)-1))
211 for(i=4; i<=NF; i++) $3=$3" "$i
212 attr[tolower(uq($2))]=uq($3)