Alessandro Vesely helped me improve the --data-urlencode's syntax, parser

and documentation.
This commit is contained in:
Daniel Stenberg 2007-11-22 09:36:28 +00:00
Родитель cb04619de2
Коммит ecfede9b3c
4 изменённых файлов: 61 добавлений и 47 удалений

Просмотреть файл

@ -7,6 +7,10 @@
Changelog
Daniel S (22 Nov 2007)
- Alessandro Vesely helped me improve the --data-urlencode's syntax, parser
and documentation.
Daniel S (21 Nov 2007)
- While inspecting the Negotiate code, I noticed how the proxy auth was using
the same state struct as the host auth, so both could never be used at the

Просмотреть файл

@ -45,6 +45,6 @@ advice from friends like these:
Dan Fandrich, Gisle Vanem, Toby Peterson, Yang Tse, Daniel Black,
Robin Johnson, Michal Marek, Ates Goral, Andres Garcia, Rob Crittenden,
Emil Romanus
Emil Romanus, Alessandro Vesely
Thanks! (and sorry if I forgot to mention someone)

Просмотреть файл

@ -224,56 +224,62 @@ To create remote directories when using FTP or SFTP, try
If this option is used several times, the following occurrences make no
difference.
.IP "-d/--data <data>"
(HTTP) Sends the specified data in a POST request to the HTTP server, in a way
that can emulate as if a user has filled in a HTML form and pressed the submit
button. Note that the data is sent exactly as specified with no extra
processing (with all newlines cut off). The data is expected to be
\&"url-encoded". This will cause curl to pass the data to the server using the
content-type application/x-www-form-urlencoded. Compare to \fI-F/--form\fP. If
this option is used more than once on the same command line, the data pieces
specified will be merged together with a separating &-letter. Thus, using '-d
name=daniel -d skill=lousy' would generate a post chunk that looks like
\&'name=daniel&skill=lousy'.
(HTTP) Sends the specified data in a POST request to the HTTP server, in the
same way that a browser does when a user has filled in an HTML form and
presses the submit button. This will cause curl to pass the data to the server
using the content-type application/x-www-form-urlencoded. Compare to
\fI-F/--form\fP.
\fI-d/--data\fP is the same as \fI--data-ascii\fP. To post data purely binary,
you should instead use the \fI--data-binary\fP option. To URL encode the value
of a form field you may use \fI--data-urlencode\fP.
If any of these options is used more than once on the same command line, the
data pieces specified will be merged together with a separating
&-letter. Thus, using '-d name=daniel -d skill=lousy' would generate a post
chunk that looks like \&'name=daniel&skill=lousy'.
If you start the data with the letter @, the rest should be a file name to
read the data from, or - if you want curl to read the data from stdin. The
contents of the file must already be url-encoded. Multiple files can also be
specified. Posting data from a file named 'foobar' would thus be done with
\fI--data\fP @foobar".
To post data purely binary, you should instead use the \fI--data-binary\fP
option.
\fI-d/--data\fP is the same as \fI--data-ascii\fP.
If this option is used several times, the ones following the first will
append data.
.IP "--data-ascii <data>"
(HTTP) This is an alias for the \fI-d/--data\fP option.
If this option is used several times, the ones following the first will
append data.
\fI--data @foobar\fP.
.IP "--data-binary <data>"
(HTTP) This posts data in a similar manner as \fI--data-ascii\fP does,
although when using this option the entire context of the posted data is kept
as-is. If you want to post a binary file without the strip-newlines feature of
the \fI--data-ascii\fP option, this is for you.
(HTTP) This posts data exactly as specified with no extra processing
whatsoever.
If this option is used several times, the ones following the first will
append data.
If you start the data with the letter @, the rest should be a filename. Data
is posted in a similar manner as \fI--data-ascii\fP does, except that newlines
are preserved and conversions are never done.
If this option is used several times, the ones following the first will append
data. As described in \fI-d/--data\fP.
.IP "--data-urlencode <data>"
(HTTP) This posts data, similar to the other --data options with the exception
that this will do partial URL encoding. (Added in 7.17.2)
that this performs URL encoding. (Added in 7.17.2)
The <data> part should be using one of the two following syntaxes:
To be CGI compliant, the <data> part should begin with a \fIname\fP followed
by a separator and a content specification. The <data> part can be passed to
curl using one of the following syntaxes:
.RS
.IP "content"
This will make curl URL encode the content and pass that on. Just be careful
so that the content doesn't contain any = or @ letters, as that will then make
the syntax match one of the other cases below!
.IP "=content"
This will make curl URL encode the content and pass that on. The preceding =
letter is not included in the data.
.IP "name=content"
This will make curl URL encode the content part and pass that on. Note that
the name part is expected to be URL encoded already.
.IP "@filename"
This will make curl load data from the given file (including any newlines),
URL encode that data and pass it on in the POST.
.IP "name@filename"
This will make curl load data from the given file, URL encode that data and
pass it on in the POST like \fIname=urlencoded-data\fP. Note that the name
is expected to be URL encoded already.
This will make curl load data from the given file (including any newlines),
URL encode that data and pass it on in the POST. The name part gets an equal
sign appended, resulting in \fIname=urlencoded-file-content\fP. Note that the
name is expected to be URL encoded already.
.RE
.IP "--digest"
(HTTP) Enables HTTP Digest authentication. This is a authentication that

Просмотреть файл

@ -2059,19 +2059,21 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
*/
char *p = strchr(nextarg, '=');
long size = 0;
size_t nlen;
int nlen;
char is_file;
if(!p)
p = strchr(nextarg, '@');
if(!p) {
warnf(config, "bad use of --data-urlencode\n");
return PARAM_BAD_USE;
if (p) {
nlen = p - nextarg; /* length of the name part */
is_file = *p++; /* pass the separator */
}
nlen = p - nextarg; /* length of the name part */
if('@' == *p) {
else {
nlen = is_file = -1;
p = nextarg;
}
if('@' == is_file) {
/* a '@' letter, it means that a file name or - (stdin) follows */
p++; /* pass the separator */
if(curlx_strequal("-", p)) {
file = stdin;
SET_BINMODE(stdin);
@ -2090,7 +2092,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
fclose(file);
}
else {
GetStr(&postdata, ++p);
GetStr(&postdata, p);
size = strlen(postdata);
}
@ -2108,8 +2110,10 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
char *n = malloc(outlen);
if(!n)
return PARAM_NO_MEM;
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
if (nlen > 0) /* only append '=' if we have a name */
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
else
strcpy(n, enc);
curl_free(enc);
free(postdata);
if(n) {