Compare commits
45 Commits
curl-7_9_3
...
curl-7_9_3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb5f6e18e6 | ||
|
|
b798e7a5ae | ||
|
|
5deab7ad27 | ||
|
|
12cdfd282d | ||
|
|
eba8035e12 | ||
|
|
edcbf4350b | ||
|
|
9289ea471f | ||
|
|
7d06185aa6 | ||
|
|
01ecb1d7e7 | ||
|
|
e177f14595 | ||
|
|
5c6eddcadd | ||
|
|
b3b4786990 | ||
|
|
fbe2907599 | ||
|
|
343da8d4b3 | ||
|
|
8d97792dbc | ||
|
|
8d07c87be7 | ||
|
|
ed21701df3 | ||
|
|
df01507582 | ||
|
|
f2bda5fd5b | ||
|
|
cba9838e8f | ||
|
|
b6dba9f5dd | ||
|
|
6e9d1617c6 | ||
|
|
ea811fee52 | ||
|
|
7391fd8f6a | ||
|
|
6c00c58f2a | ||
|
|
4931fbce49 | ||
|
|
fefc7ea600 | ||
|
|
d220389647 | ||
|
|
a1f910c159 | ||
|
|
e4866563de | ||
|
|
47f45aa229 | ||
|
|
affe334675 | ||
|
|
ee7e184e26 | ||
|
|
bec0ebacf1 | ||
|
|
5bd6d631c6 | ||
|
|
fd1799f3bb | ||
|
|
d84a0c51e0 | ||
|
|
d9a7c7de51 | ||
|
|
d57e09889a | ||
|
|
eecb86bfb0 | ||
|
|
0b1197936c | ||
|
|
b545ac6391 | ||
|
|
a922132e4a | ||
|
|
9474e8d6d2 | ||
|
|
6328428568 |
62
CHANGES
62
CHANGES
@@ -6,6 +6,68 @@
|
||||
|
||||
History of Changes
|
||||
|
||||
Daniel (17 January 2002)
|
||||
- docs/libcurl-the-guide is a new tutorial for our libcurl programming
|
||||
friends.
|
||||
|
||||
- Richard Archer brought back the ability to compile and build with OpenSSL
|
||||
versions before 0.9.5.
|
||||
[http://sourceforge.net/tracker/?func=detail&atid=100976&aid=504163&group_id=976]
|
||||
|
||||
- The DNS cache code didn't take the port number into account, which made it
|
||||
work rather bad on IPv6-enabled hosts (especially when doing passive
|
||||
FTP). Sterling fixed it.
|
||||
|
||||
Daniel (16 January 2002)
|
||||
- Georg Horn pointed out a timed out transfer without error text. I found it
|
||||
and corrected it.
|
||||
|
||||
- SSL writes didn't work, they return an uninitialized value that caused
|
||||
havoc all over. Georg Horn experienced this.
|
||||
|
||||
- Kevin Roth patched the curl_version() function to use the proper OpenSSL
|
||||
function for version information. This way, curl will report the version of
|
||||
the SSL library actually running right now, not the one that had its headers
|
||||
installed when libcurl was built. Mainly intersting when running with shared
|
||||
OpenSSL libraries.
|
||||
|
||||
Version 7.9.3-pre2
|
||||
|
||||
Daniel (16 January 2002)
|
||||
- Mofied the main transfer loop and related stuff to deal with non-blocking
|
||||
sockets in the upload section. While doing this, I've now separated the
|
||||
connection oriented buffers to have one for downloads and one for uploads
|
||||
(as two can happen simultaneously). I also shrunk the buffers to 20K
|
||||
each. As we have a scratch buffer twice the size of the upload buffer, we
|
||||
arrived at 80K for buffers compared with the previous 150K.
|
||||
|
||||
- Added the --cc option to curl-config command as it enables so very cool
|
||||
one-liners. Have a go a this one, building the simple.c example:
|
||||
|
||||
$ `curl-config --cc --cflags --libs` -o example simple.c
|
||||
|
||||
Daniel (14 January 2002)
|
||||
- I made all socket reads (recv) handle EWOULDBLOCK. I hope nicely. Now we
|
||||
only need to address all writes (send) too and then I'm ready for another
|
||||
pre-release...
|
||||
|
||||
- Stoned Elipot patched the in_addr_t configure test to make it work better on
|
||||
more platforms.
|
||||
|
||||
Daniel (9 January 2002)
|
||||
- Cris Bailiff found out that filling up curl's SSL session cache caused a
|
||||
crash!
|
||||
|
||||
- Posted the curl questionnaire on the web site. If you haven't posted your
|
||||
opinions there yet, go there and do it now while it is still there:
|
||||
|
||||
http://curl.haxx.se/q/
|
||||
|
||||
- Georg Horn quickly found out that the SSL reading no longer worked as
|
||||
supposed since the switch to non-blocking sockets. I've made a quick patch
|
||||
(for reading only) but we should improve it even further.
|
||||
|
||||
Version 7.9.3-pre1
|
||||
|
||||
Daniel (7 January 2002)
|
||||
- I made the 'bool' typedef use an "unsigned char". It makes it the same on
|
||||
|
||||
@@ -176,7 +176,7 @@ AC_DEFUN([TYPE_IN_ADDR_T],
|
||||
AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
|
||||
[type to use in place of in_addr_t if not defined])],
|
||||
[#include <sys/types.h>
|
||||
#include <sys/socket.h>,
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>])
|
||||
])
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Usage: curl-config [OPTION]
|
||||
|
||||
Available values for OPTION include:
|
||||
|
||||
--cc compiler
|
||||
--cflags pre-processor and compiler flags
|
||||
--feature newline separated list of enabled features
|
||||
--help display this help and exit
|
||||
@@ -42,6 +43,10 @@ while test $# -gt 0; do
|
||||
esac
|
||||
|
||||
case "$1" in
|
||||
--cc)
|
||||
echo @CC@
|
||||
;;
|
||||
|
||||
--prefix)
|
||||
echo $prefix
|
||||
;;
|
||||
|
||||
10
docs/BUGS
10
docs/BUGS
@@ -23,11 +23,16 @@ BUGS
|
||||
|
||||
When reporting a bug, you should include information that will help us
|
||||
understand what's wrong, what you expected to happen and how to repeat the
|
||||
bad behaviour. You therefore need to supply your operating system's name and
|
||||
bad behavior. You therefore need to supply your operating system's name and
|
||||
version number (uname -a under a unix is fine), what version of curl you're
|
||||
using (curl -V is fine), what URL you were working with and anything else
|
||||
you think matters.
|
||||
|
||||
Since curl deals with networks, it often helps us a lot if you include a
|
||||
protocol debug dump with your bug report. The output you get by using the -v
|
||||
flag. Usually, you also get more info by using -i so that is likely to be
|
||||
useful when reporting bugs as well.
|
||||
|
||||
If curl crashed, causing a core dump (in unix), there is hardly any use to
|
||||
send that huge file to anyone of us. Unless we have an exact same system
|
||||
setup as you, we can't do much with it. What we instead ask of you is to get
|
||||
@@ -36,8 +41,7 @@ BUGS
|
||||
The address and how to subscribe to the mailing list is detailed in the
|
||||
MANUAL file.
|
||||
|
||||
How To Get A Stack Trace
|
||||
========================
|
||||
HOW TO GET A STACK TRACE
|
||||
|
||||
First, you must make sure that you compile all sources with -g and that you
|
||||
don't 'strip' the final executable. Try to avoid optimizing the code as
|
||||
|
||||
20
docs/INSTALL
20
docs/INSTALL
@@ -326,19 +326,15 @@ QNX
|
||||
===
|
||||
(This section was graciously brought to us by David Bentham)
|
||||
|
||||
By setting FD_SETSIZE early in connect.c we override the QNX default value
|
||||
and thus avoid a crash.
|
||||
As QNX is targetted for resource constrained environments, the QNX headers
|
||||
set conservative limits. This includes the FD_SETSIZE macro, set by default
|
||||
to 32. Socket descriptors returned within the CURL library may exceed this,
|
||||
resulting in memory faults/SIGSEGV crashes when passed into select(..)
|
||||
calls using fd_set macros.
|
||||
|
||||
Fortunately in the QNX headers its defined as
|
||||
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 32
|
||||
#endif
|
||||
|
||||
so its relatively easy to override without changing the original
|
||||
definition. QNX claim posix compliance so this definition style could be
|
||||
standard in other o/s's. Eg Microsoft Visual C++ 6 defines it similarly,
|
||||
but its set to 64.
|
||||
A good all-round solution to this is to override the default when building
|
||||
libcurl, by overriding CFLAGS during configure, example
|
||||
# configure CFLAGS='-DFD_SETSIZE=64 -g -O2'
|
||||
|
||||
CROSS COMPILE
|
||||
=============
|
||||
|
||||
@@ -319,13 +319,54 @@ with \fIcurl_easy_cleanup(3)\fP.
|
||||
.TP
|
||||
.B CURLOPT_SSLCERT
|
||||
Pass a pointer to a zero terminated string as parameter. The string should be
|
||||
the file name of your certificate in PEM format.
|
||||
the file name of your certificate. The default format is "PEM" and can be
|
||||
changed with \fICURLOPT_SSLCERTTYPE\fP.
|
||||
.TP
|
||||
.B CURLOPT_SSLCERTTYPE
|
||||
Pass a pointer to a zero terminated string as parameter. The string should be
|
||||
the format of your certificate. Supported formats are "PEM" and "DER".
|
||||
.TP
|
||||
.B CURLOPT_SSLCERTPASSWD
|
||||
Pass a pointer to a zero terminated string as parameter. It will be used as
|
||||
the password required to use the CURLOPT_SSLCERT certificate. If the password
|
||||
is not supplied, you will be prompted for it. \fICURLOPT_PASSWDFUNCTION\fP can
|
||||
be used to set your own prompt function.
|
||||
|
||||
\fBNOTE:\fPThis option is replaced by \fICURLOPT_SSLKEYPASSWD\fP and only
|
||||
cept for backward compatibility. You never needed a pass phrase to load
|
||||
a certificate but you need one to load your private key.
|
||||
.TP
|
||||
.B CURLOPT_SSLKEY
|
||||
Pass a pointer to a zero terminated string as parameter. The string should be
|
||||
the file name of your private key. The default format is "PEM" and can be
|
||||
changed with \fICURLOPT_SSLKEYTYPE\fP.
|
||||
.TP
|
||||
.B CURLOPT_SSLKEYTYPE
|
||||
Pass a pointer to a zero terminated string as parameter. The string should be
|
||||
the format of your private key. Supported formats are "PEM", "DER" and "ENG".
|
||||
|
||||
\fBNOTE:\fPThe format "ENG" enables you to load the private key from a crypto
|
||||
engine. in this case \fICURLOPT_SSLKEY\fP is used as an identifier passed to
|
||||
the engine. You have to set the crypto engine with \fICURLOPT_SSL_ENGINE\fP.
|
||||
.TP
|
||||
.B CURLOPT_SSLKEYASSWD
|
||||
Pass a pointer to a zero terminated string as parameter. It will be used as
|
||||
the password required to use the \fICURLOPT_SSLKEY\fP private key. If the password
|
||||
is not supplied, you will be prompted for it. \fICURLOPT_PASSWDFUNCTION\fP can
|
||||
be used to set your own prompt function.
|
||||
.TP
|
||||
.B CURLOPT_SSL_ENGINE
|
||||
Pass a pointer to a zero terminated string as parameter. It will be used as
|
||||
the identifier for the crypto engine you want to use for your private key.
|
||||
|
||||
\fBNOTE:\fPIf the crypto device cannot be loaded, \fICURLE_SSL_ENGINE_NOTFOUND\fP
|
||||
is returned.
|
||||
.TP
|
||||
.B CURLOPT_SSL_ENGINEDEFAULT
|
||||
Sets the actual crypto engine as the default for (asymetric) crypto operations.
|
||||
|
||||
\fBNOTE:\fPIf the crypto device cannot be set, \fICURLE_SSL_ENGINE_SETFAILED\fP
|
||||
is returned.
|
||||
.TP
|
||||
.B CURLOPT_CRLF
|
||||
Convert Unix newlines to CRLF newlines on FTP uploads.
|
||||
|
||||
@@ -7,7 +7,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies
|
||||
EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \
|
||||
win32sockets.c persistant.c ftpget.c Makefile.example \
|
||||
multithread.c getinmemory.c ftpupload.c httpput.c \
|
||||
simplessl.c ftpgetresp.c
|
||||
simplessl.c ftpgetresp.c http-post.c
|
||||
|
||||
all:
|
||||
@echo "done"
|
||||
|
||||
@@ -10,6 +10,10 @@ them for submission in future packages and on the web site.
|
||||
The Makefile.example is an example makefile that could be used to build these
|
||||
examples. Just edit the file according to your system and requirements first.
|
||||
|
||||
Most examples should build fine using a command line like this:
|
||||
|
||||
$ gcc `curl-config --cflags` `curl-config --libs` -o example example.c
|
||||
|
||||
Try the php/examples/ directory for PHP programming snippets!
|
||||
|
||||
*PLEASE* do not use the curl.haxx.se site as a test target for your libcurl
|
||||
|
||||
@@ -14,31 +14,70 @@
|
||||
#include <curl/types.h>
|
||||
#include <curl/easy.h>
|
||||
|
||||
/* to make this work under windows, use the win32-functions from the
|
||||
win32socket.c file as well */
|
||||
/*
|
||||
* This is an example showing how to get a single file from an FTP server.
|
||||
* It delays the actual destination file creation until the first write
|
||||
* callback so that it won't create an empty file in case the remote file
|
||||
* doesn't exist or something else fails.
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
struct FtpFile {
|
||||
char *filename;
|
||||
FILE *stream;
|
||||
};
|
||||
|
||||
int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
struct FtpFile *out=(struct FtpFile *)stream;
|
||||
if(out && !out->stream) {
|
||||
/* open file for writing */
|
||||
out->stream=fopen(out->filename, "wb");
|
||||
if(!out->stream)
|
||||
return -1; /* failure, can't open file to write */
|
||||
}
|
||||
return fwrite(buffer, size, nmemb, out->stream);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
FILE *ftpfile;
|
||||
|
||||
/* local file name to store the file as */
|
||||
ftpfile = fopen("curl.tar.gz", "wb"); /* b is binary for win */
|
||||
struct FtpFile ftpfile={
|
||||
"curl.tar.gz", /* name to store the file as if succesful */
|
||||
NULL
|
||||
};
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* Get curl 7.7 from sunet.se's FTP site: */
|
||||
/* Get curl 7.9.2 from sunet.se's FTP site: */
|
||||
curl_easy_setopt(curl, CURLOPT_URL,
|
||||
"ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.7.tar.gz");
|
||||
curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
|
||||
"ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz");
|
||||
/* Define our callback to get called when there's data to be written */
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
||||
/* Set a pointer to our struct to pass to the callback */
|
||||
curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile);
|
||||
|
||||
/* Switch on full protocol/debug output */
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if(CURLE_OK != res) {
|
||||
/* we failed */
|
||||
fprintf(stderr, "curl told us %d\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(ftpfile); /* close the local file */
|
||||
if(ftpfile.stream)
|
||||
fclose(ftpfile.stream); /* close the local file */
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
35
docs/examples/http-post.c
Normal file
35
docs/examples/http-post.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* First set the URL that is about to receive our POST. This URL can
|
||||
just as well be a https:// URL if that is what should receive the
|
||||
data. */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
|
||||
/* Now specify the POST data */
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -9,27 +9,16 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <curl/types.h>
|
||||
#include <curl/easy.h>
|
||||
|
||||
/* to make this work under windows, use the win32-functions from the
|
||||
win32socket.c file as well */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
FILE *headerfile;
|
||||
|
||||
headerfile = fopen("dumpit", "w");
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* what call to write: */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
/* always cleanup */
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
4.2. if the format of the key file is DER, set pKeyType to "DER"
|
||||
|
||||
!! verify of the server certificate is not implemented here !!
|
||||
|
||||
**** This example only works with libcurl 7.9.3 and later! ****
|
||||
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -37,6 +40,7 @@ int main(int argc, char **argv)
|
||||
FILE *headerfile;
|
||||
|
||||
const char *pCertFile = "testcert.pem";
|
||||
const char *pCACertFile="cacert.pem"
|
||||
|
||||
const char *pKeyName;
|
||||
const char *pKeyType;
|
||||
@@ -96,6 +100,10 @@ int main(int argc, char **argv)
|
||||
curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType);
|
||||
/* set the private key (file or ID in engine) */
|
||||
curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);
|
||||
/* set the file with the certs vaildating the server */
|
||||
curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
|
||||
/* disconnect if we can't validate server's cert */
|
||||
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
break; /* we are done... */
|
||||
|
||||
328
docs/libcurl-the-guide
Normal file
328
docs/libcurl-the-guide
Normal file
@@ -0,0 +1,328 @@
|
||||
$Id$
|
||||
_ _ ____ _
|
||||
___| | | | _ \| |
|
||||
/ __| | | | |_) | |
|
||||
| (__| |_| | _ <| |___
|
||||
\___|\___/|_| \_\_____|
|
||||
|
||||
PROGRAMMING WITH LIBCURL
|
||||
|
||||
About this Document
|
||||
|
||||
This document will attempt to describe the general principle and some basic
|
||||
approaches to consider when programming with libcurl. The text will focus
|
||||
mainly on the C/C++ interface but might apply fairly well on other interfaces
|
||||
as well as they usually follow the C one pretty closely.
|
||||
|
||||
This document will refer to 'the user' as the person writing the source code
|
||||
that uses libcurl. That would probably be you or someone in your position.
|
||||
What will be generally refered to as 'the program' will be the collected
|
||||
source code that you write that is using libcurl for transfers. The program
|
||||
is outside libcurl and libcurl is outside of the program.
|
||||
|
||||
|
||||
Building
|
||||
|
||||
There are many different ways to build C programs. This chapter will assume
|
||||
a unix-style build process. If you use a different build system, you can
|
||||
still read this to get general information that may apply to your
|
||||
environment as well.
|
||||
|
||||
Compiling the Program
|
||||
|
||||
Your compiler needs to know where the libcurl headers are
|
||||
located. Therefore you must set your compiler's include path to point to
|
||||
the directory where you installed them. The 'curl-config'[3] tool can be
|
||||
used to get this information:
|
||||
|
||||
$ curl-config --cflags
|
||||
|
||||
Linking the Program with libcurl
|
||||
|
||||
When having compiled the program, you need to link your object files to
|
||||
create a single executable. For that to succeed, you need to link with
|
||||
libcurl and possibly also with other libraries that libcurl itself depends
|
||||
on. Like OpenSSL librararies, but even some standard OS libraries may be
|
||||
needed on the command line. To figure out which flags to use, once again
|
||||
the 'curl-config' tool comes to the rescue:
|
||||
|
||||
$ curl-config --libs
|
||||
|
||||
SSL or Not
|
||||
|
||||
libcurl can be built and customized in many ways. One of the things that
|
||||
varies from different libraries and builds is the support for SSL-based
|
||||
transfers, like HTTPS and FTPS. If OpenSSL was detected properly at
|
||||
build-time, libcurl will be built with SSL support. To figure out if an
|
||||
installed libcurl has been built with SSL support enabled, use
|
||||
'curl-config' like this:
|
||||
|
||||
$ curl-config --feature
|
||||
|
||||
And if SSL is supported, the keyword 'SSL' will be written to stdout,
|
||||
possibly together with a few other features that can be on and off on
|
||||
different libcurls.
|
||||
|
||||
|
||||
Portable Code in a Portable World
|
||||
|
||||
The people behind libcurl have put a considerable effort to make libcurl work
|
||||
on a large amount of different operating systems and environments.
|
||||
|
||||
You program libcurl the same way on all platforms that libcurl runs on. There
|
||||
are only very few minor considerations that differs. If you just make sure to
|
||||
write your code portable enough, you may very well create yourself a very
|
||||
portable program. libcurl shouldn't stop you from that.
|
||||
|
||||
|
||||
Global Preparation
|
||||
|
||||
The program must initialize some of the libcurl functionality globally. That
|
||||
means it should be done exactly once, no matter how many times you intend to
|
||||
use the library. Once for your program's entire life time. This is done using
|
||||
|
||||
curl_global_init()
|
||||
|
||||
and it takes one parameter which is a bit pattern that tells libcurl what to
|
||||
intialize. Using CURL_GLOBAL_ALL will make it initialize all known internal
|
||||
sub modules, and might be a good default option. The current two bits that
|
||||
are specified are:
|
||||
|
||||
CURL_GLOBAL_WIN32 which only does anything on Windows machines. When used on
|
||||
a Windows machine, it'll make libcurl intialize the win32 socket
|
||||
stuff. Without having that initialized properly, your program cannot use
|
||||
sockets properly. You should only do this once for each application, so if
|
||||
your program already does this or of another library in use does it, you
|
||||
should not tell libcurl to do this as well.
|
||||
|
||||
CURL_GLOBAL_SSL which only does anything on libcurls compiled and built
|
||||
SSL-enabled. On these systems, this will make libcurl init OpenSSL properly
|
||||
for this application. This is only needed to do once for each application so
|
||||
if your program or another library already does this, this bit should not be
|
||||
needed.
|
||||
|
||||
libcurl has a default protection mechanism that detects if curl_global_init()
|
||||
hasn't been called by the time curl_easy_perform() is called and if that is
|
||||
the case, libcurl runs the function itself with a guessed bit pattern. Please
|
||||
note that depending solely on this is not considered nice nor very good.
|
||||
|
||||
When the program no longer uses libcurl, it should call
|
||||
curl_global_cleanup(), which is the opposite of the init call. It will then
|
||||
do the reversed operations to cleanup the resources the curl_global_init()
|
||||
call initialized.
|
||||
|
||||
Repeated calls to curl_global_init() and curl_global_cleanup() should be
|
||||
avoided. They should be called once each.
|
||||
|
||||
Handle the easy libcurl
|
||||
|
||||
libcurl version 7 is oriented around the so called easy interface. All
|
||||
operations in the easy interface are prefixed with 'curl_easy'.
|
||||
|
||||
Future libcurls will also offer the multi interface. More about that
|
||||
interface, what it is targeted for and how to use it is still only debated on
|
||||
the libcurl mailing list and developer web pages. Join up to discuss and
|
||||
figure out!
|
||||
|
||||
To use the easy interface, you must first create yourself an easy handle. You
|
||||
need one handle for each easy session you want to perform. Basicly, you
|
||||
should use one handle for every thread you plan to use for transferring. You
|
||||
must never share the same handle in multiple threads.
|
||||
|
||||
Get an easy handle with
|
||||
|
||||
easyhandle = curl_easy_init();
|
||||
|
||||
It returns an easy handle. Using that you proceed to the next step: setting
|
||||
up your preferred actions. A handle is just a logic entity for the upcoming
|
||||
transfer or series of transfers. One of the most basic properties to set in
|
||||
the handle is the URL. You set your preferred URL to transfer with
|
||||
CURLOPT_URL in a manner similar to:
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_URL, "http://curl.haxx.se/");
|
||||
|
||||
Let's assume for a while that you want to receive data as the URL indentifies
|
||||
a remote resource you want to get here. Since you write a sort of application
|
||||
that needs this transfer, I assume that you would like to get the data passed
|
||||
to you directly instead of simply getting it passed to stdout. So, you write
|
||||
your own function that matches this prototype:
|
||||
|
||||
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
|
||||
You tell libcurl to pass all data to this function by issuing a function
|
||||
similar to this:
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
|
||||
You can control what data your function get in the forth argument by setting
|
||||
another property:
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_FILE, &internal_struct);
|
||||
|
||||
Using that property, you can easily pass local data between your application
|
||||
and the function that gets invoked by libcurl. libcurl itself won't touch the
|
||||
data you pass with CURLOPT_FILE.
|
||||
|
||||
libcurl offers its own default internal callback that'll take care of the
|
||||
data if you don't set the callback with CURLOPT_WRITEFUNCTION. It will then
|
||||
simply output the received data to stdout. You can have the default callback
|
||||
write the data to a different file handle by passing a 'FILE *' to a file
|
||||
opened for writing with the CURLOPT_FILE option.
|
||||
|
||||
Now, we need to take a step back and have a deep breath. Here's one of those
|
||||
rare platform-dependent nitpicks. Did you spot it? On some platforms[2],
|
||||
libcurl won't be able to operate on files opened by the program. Thus, if you
|
||||
use the default callback and pass in a an open file with CURLOPT_FILE, it
|
||||
will crash. You should therefore avoid this to make your program run fine
|
||||
virtually everywhere.
|
||||
|
||||
There are of course many more options you can set, and we'll get back to a
|
||||
few of them later. Let's instead continue to the actual transfer:
|
||||
|
||||
success = curl_easy_perform(easyhandle);
|
||||
|
||||
The curl_easy_perform() will connect to the remote site, do the necessary
|
||||
commands and receive the transfer. Whenever it receives data, it calls the
|
||||
callback function we previously set. The function may get one byte at a time,
|
||||
or it may get many kilobytes at once. libcurl delivers as much as possible as
|
||||
often as possible. Your callback function should return the number of bytes
|
||||
it "took care of". If that is not the exact same amount of bytes that was
|
||||
passed to it, libcurl will abort the operation and return with an error code.
|
||||
|
||||
When the transfer is complete, the function returns a return code that
|
||||
informs you if it succeeded in its mission or not. If a return code isn't
|
||||
enough for you, you can use the CURLOPT_ERRORBUFFER to point libcurl to a
|
||||
buffer of yours where it'll store a human readable error message as well.
|
||||
|
||||
If you then want to transfer another file, the handle is ready to be used
|
||||
again. Mind you, it is even preferred that you re-use an existing handle if
|
||||
you intend to make another transfer. libcurl will then attempt to re-use the
|
||||
previous
|
||||
|
||||
|
||||
When It Doesn't Work
|
||||
|
||||
There will always be times when the transfer fails for some reason. You might
|
||||
have set the wrong libcurl option or misunderstood what the libcurl option
|
||||
actually does, or the remote server might return non-standard replies that
|
||||
confuse the library which then confuses your program.
|
||||
|
||||
There's one golden rule when these things occur: set the CURLOPT_VERBOSE
|
||||
option to TRUE. It'll cause the library to spew out the entire protocol
|
||||
details it sends, some internal info and some received protcol data as well
|
||||
(especially when using FTP). If you're using HTTP, adding the headers in the
|
||||
received output to study is also a clever way to get a better understanding
|
||||
wht the server behaves the way it does. Include headers in the normal body
|
||||
output with CURLOPT_HEADER set TRUE.
|
||||
|
||||
Of course there are bugs left. We need to get to know about them to be able
|
||||
to fix them, so we're quite dependent on your bug reports! When you do report
|
||||
suspected bugs in libcurl, please include as much details you possibly can: a
|
||||
protocol dump that CURLOPT_VERBOSE produces, library version, as much as
|
||||
possible of your code that uses libcurl, operating system name and version,
|
||||
compiler name and version etc.
|
||||
|
||||
|
||||
Upload Data to a Remote Site
|
||||
|
||||
libcurl tries to keep a protocol independent approach to most transfers, thus
|
||||
uploading to a remote FTP site is very similar to uploading data to a HTTP
|
||||
server with a PUT request.
|
||||
|
||||
Of course, first you either create an easy handle or you re-use one existing
|
||||
one. Then you set the URL to operate on just like before. This is the remote
|
||||
URL, that we now will upload.
|
||||
|
||||
Since we write an application, we most likely want libcurl to get the upload
|
||||
data by asking us for it. To make it do that, we set the read callback and
|
||||
the custom pointer libcurl will pass to our read callback. The read callback
|
||||
should have a prototype similar to:
|
||||
|
||||
size_t function(char *buffer, size_t size, size_t nitems, void *userp);
|
||||
|
||||
Where buffer is the pointer to a buffer we fill in with data to upload and
|
||||
size*nitems is the size of the buffer. The 'userp' pointer is the custom
|
||||
pointer we set to point to a struct of ours to pass private data between the
|
||||
application and the callback.
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_READFUNCTION, read_function);
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_INFILE, &filedata);
|
||||
|
||||
Tell libcurl that we want to upload:
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, TRUE);
|
||||
|
||||
A few protocols won't behave properly when uploads are done without any prior
|
||||
knowledge of the expected file size. HTTP PUT is one example [1]. So, set the
|
||||
upload file size using the CURLOPT_INFILESIZE like this:
|
||||
|
||||
curl_easy_setopt(easyhandle, CURLOPT_INFILESIZE, file_size);
|
||||
|
||||
So, then you call curl_easy_perform() this time, it'll perform all necessary
|
||||
operations and when it has invoked the upload it'll call your supplied
|
||||
callback to get the data to upload. The program should return as much data as
|
||||
possible in every invoke, as that is likely to make the upload perform as
|
||||
fast as possible. The callback should return the number of bytes it wrote in
|
||||
the buffer. Returning 0 will signal the end of the upload.
|
||||
|
||||
|
||||
Passwords
|
||||
|
||||
Many protocols use or even require that user name and password are provided
|
||||
to be able to download or upload the data of your choice. libcurl offers
|
||||
several ways to specify them.
|
||||
|
||||
[ URL, options, callback ]
|
||||
|
||||
|
||||
Showing Progress
|
||||
|
||||
|
||||
libcurl with C++
|
||||
|
||||
There's basicly only one thing to keep in mind when using C++ instead of C
|
||||
when interfacing libcurl:
|
||||
|
||||
"The Callbacks Must Be Plain C"
|
||||
|
||||
So if you want a write callback set in libcurl, you should put it within
|
||||
'extern'. Similar to this:
|
||||
|
||||
extern "C" {
|
||||
size_t write_data(void *ptr, size_t size, size_t nmemb,
|
||||
void *ourpointer)
|
||||
{
|
||||
/* do what you want with the data */
|
||||
}
|
||||
}
|
||||
|
||||
This will of course effectively turn the callback code into C. There won't be
|
||||
any "this" pointer available etc.
|
||||
|
||||
|
||||
Security Considerations
|
||||
|
||||
|
||||
Certificates and Other SSL Tricks
|
||||
|
||||
|
||||
Future
|
||||
|
||||
|
||||
|
||||
-----
|
||||
Footnotes:
|
||||
|
||||
[1] = HTTP PUT without knowing the size prior to transfer is indeed possible,
|
||||
but libcurl does not support the chunked transfers on uploading that is
|
||||
necessary for this feature to work. We'd gratefully appreciate patches
|
||||
that bring this functionality...
|
||||
|
||||
[2] = This happens on Windows machines when libcurl is built and used as a
|
||||
DLL. However, you can still do this on Windows if you link with a static
|
||||
library.
|
||||
|
||||
[3] = The curl-config tool is generated at build-time (on unix-like systems)
|
||||
and should be installed with the 'make install' or similar instruction
|
||||
that installs the library, header files, man pages etc.
|
||||
@@ -613,7 +613,7 @@ CURLcode curl_global_init(long flags);
|
||||
void curl_global_cleanup(void);
|
||||
|
||||
/* This is the version number */
|
||||
#define LIBCURL_VERSION "7.9.3-pre1"
|
||||
#define LIBCURL_VERSION "7.9.3-pre3"
|
||||
#define LIBCURL_VERSION_NUM 0x070903
|
||||
|
||||
/* linked-list structure for the CURLOPT_QUOTE option (and other) */
|
||||
|
||||
@@ -369,9 +369,11 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
|
||||
/* subtract the passed time */
|
||||
timeout_ms -= (long)has_passed;
|
||||
|
||||
if(timeout_ms < 0)
|
||||
if(timeout_ms < 0) {
|
||||
/* a precaution, no need to continue if time already is up */
|
||||
failf(data, "Connection time-out");
|
||||
return CURLE_OPERATION_TIMEOUTED;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
|
||||
37
lib/ftp.c
37
lib/ftp.c
@@ -267,9 +267,16 @@ int Curl_GetFTPResponse(char *buf,
|
||||
ftp->cache = NULL; /* clear the pointer */
|
||||
ftp->cache_size = 0; /* zero the size just in case */
|
||||
}
|
||||
else if(CURLE_OK != Curl_read(conn, sockfd, ptr,
|
||||
BUFSIZE-nread, &gotbytes))
|
||||
keepon = FALSE;
|
||||
else {
|
||||
int res = Curl_read(conn, sockfd, ptr,
|
||||
BUFSIZE-nread, &gotbytes);
|
||||
if(res < 0)
|
||||
/* EWOULDBLOCK */
|
||||
continue; /* go looping again */
|
||||
|
||||
if(CURLE_OK != res)
|
||||
keepon = FALSE;
|
||||
}
|
||||
|
||||
if(!keepon)
|
||||
;
|
||||
@@ -2051,9 +2058,11 @@ CURLcode Curl_ftp(struct connectdata *conn)
|
||||
CURLcode Curl_ftpsendf(struct connectdata *conn,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
char s[256];
|
||||
size_t write_len;
|
||||
ssize_t write_len;
|
||||
char *sptr=s;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
@@ -2067,9 +2076,23 @@ CURLcode Curl_ftpsendf(struct connectdata *conn,
|
||||
|
||||
bytes_written=0;
|
||||
write_len = strlen(s);
|
||||
Curl_write(conn, conn->firstsocket, s, write_len, &bytes_written);
|
||||
|
||||
return (bytes_written==write_len)?CURLE_OK:CURLE_WRITE_ERROR;
|
||||
do {
|
||||
res = Curl_write(conn, conn->firstsocket, sptr, write_len,
|
||||
&bytes_written);
|
||||
|
||||
if(CURLE_OK != res)
|
||||
break;
|
||||
|
||||
if(bytes_written != write_len) {
|
||||
write_len -= bytes_written;
|
||||
sptr += bytes_written;
|
||||
}
|
||||
else
|
||||
break;
|
||||
} while(1);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "llist.h"
|
||||
|
||||
89
lib/hostip.c
89
lib/hostip.c
@@ -60,6 +60,9 @@
|
||||
#include "hostip.h"
|
||||
#include "hash.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
|
||||
#include "inet_ntoa_r.h"
|
||||
#endif
|
||||
@@ -98,13 +101,71 @@ struct curl_dns_cache_entry {
|
||||
time_t timestamp;
|
||||
};
|
||||
|
||||
/* count the number of characters that an integer takes up */
|
||||
static int _num_chars(int i)
|
||||
{
|
||||
int chars = 0;
|
||||
|
||||
/* While the number divided by 10 is greater than one,
|
||||
* re-divide the number by 10, and increment the number of
|
||||
* characters by 1.
|
||||
*
|
||||
* this relies on the fact that for every multiple of 10,
|
||||
* a new digit is added onto every number
|
||||
*/
|
||||
do {
|
||||
chars++;
|
||||
|
||||
i = (int) i / 10;
|
||||
} while (i > 1);
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
/* Create a hostcache id */
|
||||
static char *
|
||||
_create_hostcache_id(char *server, int port, ssize_t *entry_len)
|
||||
{
|
||||
char *id = NULL;
|
||||
|
||||
/* Get the length of the new entry id */
|
||||
*entry_len = *entry_len + /* Hostname length */
|
||||
1 + /* The ':' seperator */
|
||||
_num_chars(port); /* The number of characters the port will take up */
|
||||
|
||||
/* Allocate the new entry id */
|
||||
id = malloc(*entry_len + 1);
|
||||
if (!id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create the new entry */
|
||||
/* If sprintf() doesn't return the entry length, that signals failure */
|
||||
if (sprintf(id, "%s:%d", server, port) != *entry_len) {
|
||||
/* Free the allocated id, set length to zero and return NULL */
|
||||
*entry_len = 0;
|
||||
free(id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* Macro to save redundant free'ing of entry_id */
|
||||
#define _hostcache_return(__v) \
|
||||
{ \
|
||||
free(entry_id); \
|
||||
return (__v); \
|
||||
}
|
||||
|
||||
Curl_addrinfo *Curl_resolv(struct SessionHandle *data,
|
||||
char *hostname,
|
||||
int port,
|
||||
char **bufp)
|
||||
{
|
||||
char *entry_id = NULL;
|
||||
struct curl_dns_cache_entry *p = NULL;
|
||||
size_t hostname_len;
|
||||
ssize_t entry_len;
|
||||
time_t now;
|
||||
|
||||
/* If the host cache timeout is 0, we don't do DNS cach'ing
|
||||
@@ -113,39 +174,47 @@ Curl_addrinfo *Curl_resolv(struct SessionHandle *data,
|
||||
return Curl_getaddrinfo(data, hostname, port, bufp);
|
||||
}
|
||||
|
||||
hostname_len = strlen(hostname)+1;
|
||||
|
||||
/* Create an entry id, based upon the hostname and port */
|
||||
entry_len = strlen(hostname);
|
||||
entry_id = _create_hostcache_id(hostname, port, &entry_len);
|
||||
/* If we can't create the entry id, don't cache, just fall-through
|
||||
to the plain Curl_getaddrinfo() */
|
||||
if (!entry_id) {
|
||||
return Curl_getaddrinfo(data, hostname, port, bufp);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
/* See if its already in our dns cache */
|
||||
if (curl_hash_find(data->hostcache, hostname, hostname_len, (void **) &p)) {
|
||||
if (entry_id && curl_hash_find(data->hostcache, entry_id, entry_len+1, (void **) &p)) {
|
||||
/* Do we need to check for a cache timeout? */
|
||||
if (data->set.dns_cache_timeout != -1) {
|
||||
/* Return if the entry has not timed out */
|
||||
if ((now - p->timestamp) < data->set.dns_cache_timeout) {
|
||||
return p->addr;
|
||||
_hostcache_return(p->addr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return p->addr;
|
||||
_hostcache_return(p->addr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new cache entry */
|
||||
p = (struct curl_dns_cache_entry *) malloc(sizeof(struct curl_dns_cache_entry));
|
||||
if (!p) {
|
||||
return NULL;
|
||||
_hostcache_return(NULL);
|
||||
}
|
||||
|
||||
p->addr = Curl_getaddrinfo(data, hostname, port, bufp);
|
||||
if (!p->addr) {
|
||||
return NULL;
|
||||
free(p);
|
||||
_hostcache_return(NULL);
|
||||
}
|
||||
p->timestamp = now;
|
||||
|
||||
/* Save it in our host cache */
|
||||
curl_hash_update(data->hostcache, hostname, hostname_len, (const void *) p);
|
||||
curl_hash_update(data->hostcache, entry_id, entry_len+1, (const void *) p);
|
||||
|
||||
return p->addr;
|
||||
_hostcache_return(p->addr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
37
lib/http.c
37
lib/http.c
@@ -128,8 +128,10 @@ static
|
||||
CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
|
||||
long *bytes_written)
|
||||
{
|
||||
size_t amount;
|
||||
CURLcode result;
|
||||
ssize_t amount;
|
||||
CURLcode res;
|
||||
char *ptr;
|
||||
int size;
|
||||
|
||||
if(conn->data->set.verbose) {
|
||||
fputs("> ", conn->data->set.err);
|
||||
@@ -137,7 +139,25 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
|
||||
fwrite(in->buffer, in->size_used, 1, conn->data->set.err);
|
||||
}
|
||||
|
||||
result = Curl_write(conn, sockfd, in->buffer, in->size_used, &amount);
|
||||
/* The looping below is required since we use non-blocking sockets, but due
|
||||
to the circumstances we will just loop and try again and again etc */
|
||||
|
||||
ptr = in->buffer;
|
||||
size = in->size_used;
|
||||
do {
|
||||
res = Curl_write(conn, sockfd, ptr, size, &amount);
|
||||
|
||||
if(CURLE_OK != res)
|
||||
break;
|
||||
|
||||
if(amount != size) {
|
||||
size += amount;
|
||||
ptr += amount;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
} while(1);
|
||||
|
||||
if(in->buffer)
|
||||
free(in->buffer);
|
||||
@@ -145,7 +165,7 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
|
||||
|
||||
*bytes_written = amount;
|
||||
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +255,7 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
|
||||
int subversion=0;
|
||||
struct SessionHandle *data=conn->data;
|
||||
CURLcode result;
|
||||
int res;
|
||||
|
||||
int nread; /* total size read */
|
||||
int perline; /* count bytes per line */
|
||||
@@ -317,8 +338,12 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
|
||||
* to read, but when we use Curl_read() it may do so. Do confirm
|
||||
* that this is still ok and then remove this comment!
|
||||
*/
|
||||
if(CURLE_OK != Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,
|
||||
&gotbytes))
|
||||
res= Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,
|
||||
&gotbytes);
|
||||
if(res< 0)
|
||||
/* EWOULDBLOCK */
|
||||
continue; /* go loop yourself */
|
||||
else if(res)
|
||||
keepon = FALSE;
|
||||
else if(gotbytes <= 0) {
|
||||
keepon = FALSE;
|
||||
|
||||
97
lib/sendf.c
97
lib/sendf.c
@@ -160,7 +160,7 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
struct SessionHandle *data = conn->data;
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
CURLcode result;
|
||||
char *s;
|
||||
va_list ap;
|
||||
@@ -187,26 +187,32 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
|
||||
*/
|
||||
CURLcode Curl_write(struct connectdata *conn, int sockfd,
|
||||
void *mem, size_t len,
|
||||
size_t *written)
|
||||
ssize_t *written)
|
||||
{
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
/* SSL_write() is said to return 'int' while write() and send() returns
|
||||
'size_t' */
|
||||
int ssl_bytes;
|
||||
if (conn->ssl.use) {
|
||||
int loop=100; /* just a precaution to never loop endlessly */
|
||||
while(loop--) {
|
||||
ssl_bytes = SSL_write(conn->ssl.handle, mem, len);
|
||||
if((0 >= ssl_bytes) ||
|
||||
(SSL_ERROR_WANT_WRITE != SSL_get_error(conn->ssl.handle,
|
||||
ssl_bytes) )) {
|
||||
/* this converts from signed to unsigned... */
|
||||
bytes_written = ssl_bytes;
|
||||
break;
|
||||
int err;
|
||||
int rc = SSL_write(conn->ssl.handle, mem, len);
|
||||
|
||||
if(rc < 0) {
|
||||
err = SSL_get_error(conn->ssl.handle, rc);
|
||||
|
||||
switch(err) {
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
/* this is basicly the EWOULDBLOCK equivalent */
|
||||
*written = 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
/* a true error */
|
||||
failf(conn->data, "SSL_write() return error %d\n", err);
|
||||
return CURLE_WRITE_ERROR;
|
||||
}
|
||||
bytes_written = rc;
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
@@ -216,13 +222,27 @@ CURLcode Curl_write(struct connectdata *conn, int sockfd,
|
||||
}
|
||||
else
|
||||
#endif /* KRB4 */
|
||||
{
|
||||
bytes_written = swrite(sockfd, mem, len);
|
||||
}
|
||||
if(-1 == bytes_written) {
|
||||
#ifdef WIN32
|
||||
if(EWOULDBLOCK == GetLastError())
|
||||
#else
|
||||
if(EWOULDBLOCK == errno)
|
||||
#endif
|
||||
{
|
||||
/* this is just a case of EWOULDBLOCK */
|
||||
*written=0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
}
|
||||
#ifdef USE_SSLEAY
|
||||
}
|
||||
#endif
|
||||
|
||||
*written = bytes_written;
|
||||
return (bytes_written==len)?CURLE_OK:CURLE_WRITE_ERROR;
|
||||
return (-1 != bytes_written)?CURLE_OK:CURLE_WRITE_ERROR;
|
||||
}
|
||||
|
||||
/* client_write() sends data to the write callback(s)
|
||||
@@ -266,26 +286,47 @@ CURLcode Curl_client_write(struct SessionHandle *data,
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Internal read-from-socket function. This is meant to deal with plain
|
||||
* sockets, SSL sockets and kerberos sockets.
|
||||
*
|
||||
* If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
|
||||
* a regular CURLcode value.
|
||||
*/
|
||||
CURLcode Curl_read(struct connectdata *conn, int sockfd,
|
||||
char *buf, size_t buffersize,
|
||||
ssize_t *n)
|
||||
int Curl_read(struct connectdata *conn,
|
||||
int sockfd,
|
||||
char *buf,
|
||||
size_t buffersize,
|
||||
ssize_t *n)
|
||||
{
|
||||
ssize_t nread;
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
if (conn->ssl.use) {
|
||||
int loop=100; /* just a precaution to never loop endlessly */
|
||||
while(loop--) {
|
||||
bool loop=TRUE;
|
||||
int err;
|
||||
do {
|
||||
nread = SSL_read(conn->ssl.handle, buf, buffersize);
|
||||
if((-1 != nread) ||
|
||||
(SSL_ERROR_WANT_READ != SSL_get_error(conn->ssl.handle, nread) ))
|
||||
|
||||
if(nread > 0)
|
||||
/* successful read */
|
||||
break;
|
||||
}
|
||||
|
||||
err = SSL_get_error(conn->ssl.handle, nread);
|
||||
|
||||
switch(err) {
|
||||
case SSL_ERROR_NONE: /* this is not an error */
|
||||
case SSL_ERROR_ZERO_RETURN: /* no more data */
|
||||
loop=0; /* get out of loop */
|
||||
break;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
/* if there's data pending, then we re-invoke SSL_read() */
|
||||
break;
|
||||
}
|
||||
} while(0);
|
||||
if(loop && SSL_pending(conn->ssl.handle))
|
||||
return -1; /* basicly EWOULDBLOCK */
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
@@ -295,6 +336,16 @@ CURLcode Curl_read(struct connectdata *conn, int sockfd,
|
||||
else
|
||||
#endif
|
||||
nread = sread (sockfd, buf, buffersize);
|
||||
|
||||
if(-1 == nread) {
|
||||
#ifdef WIN32
|
||||
if(EWOULDBLOCK == GetLastError())
|
||||
#else
|
||||
if(EWOULDBLOCK == errno)
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
|
||||
@@ -45,12 +45,12 @@ CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr,
|
||||
size_t len);
|
||||
|
||||
/* internal read-function, does plain socket, SSL and krb4 */
|
||||
CURLcode Curl_read(struct connectdata *conn, int sockfd,
|
||||
char *buf, size_t buffersize,
|
||||
ssize_t *n);
|
||||
int Curl_read(struct connectdata *conn, int sockfd,
|
||||
char *buf, size_t buffersize,
|
||||
ssize_t *n);
|
||||
/* internal write-function, does plain socket, SSL and krb4 */
|
||||
CURLcode Curl_write(struct connectdata *conn, int sockfd,
|
||||
void *mem, size_t len,
|
||||
size_t *written);
|
||||
ssize_t *written);
|
||||
|
||||
#endif
|
||||
|
||||
34
lib/ssluse.c
34
lib/ssluse.c
@@ -43,6 +43,12 @@
|
||||
#include "memdebug.h"
|
||||
#endif
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0090581fL
|
||||
#define HAVE_SSL_GET1_SESSION 1
|
||||
#else
|
||||
#undef HAVE_SSL_GET1_SESSION
|
||||
#endif
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00904100L
|
||||
#define HAVE_USERDATA_IN_PWD_CALLBACK 1
|
||||
#else
|
||||
@@ -552,23 +558,39 @@ int Curl_SSL_Close_All(struct SessionHandle *data)
|
||||
static int Store_SSL_Session(struct connectdata *conn)
|
||||
{
|
||||
SSL_SESSION *ssl_sessionid;
|
||||
struct curl_ssl_session *store;
|
||||
int i;
|
||||
struct SessionHandle *data=conn->data; /* the mother of all structs */
|
||||
struct curl_ssl_session *store = &data->state.session[0];
|
||||
int oldest_age=data->state.session[0].age; /* zero if unused */
|
||||
|
||||
/* ask OpenSSL, say please */
|
||||
|
||||
#ifdef HAVE_SSL_GET1_SESSION
|
||||
ssl_sessionid = SSL_get1_session(conn->ssl.handle);
|
||||
|
||||
/* SSL_get1_session() will increment the reference
|
||||
count and the session will stay in memory until explicitly freed with
|
||||
SSL_SESSION_free(3), regardless of its state. */
|
||||
SSL_SESSION_free(3), regardless of its state.
|
||||
This function was introduced in openssl 0.9.5a. */
|
||||
#else
|
||||
ssl_sessionid = SSL_get_session(conn->ssl.handle);
|
||||
|
||||
/* if SSL_get1_session() is unavailable, use SSL_get_session().
|
||||
This is an inferior option because the session can be flushed
|
||||
at any time by openssl. It is included only so curl compiles
|
||||
under versions of openssl < 0.9.5a.
|
||||
|
||||
WARNING: How curl behaves if it's session is flushed is
|
||||
untested.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Now we should add the session ID and the host name to the cache, (remove
|
||||
the oldest if necessary) */
|
||||
|
||||
/* find an empty slot for us, or find the oldest */
|
||||
for(i=0; (i<data->set.ssl.numsessions) && data->state.session[i].sessionid; i++) {
|
||||
for(i=1; (i<data->set.ssl.numsessions) &&
|
||||
data->state.session[i].sessionid; i++) {
|
||||
if(data->state.session[i].age < oldest_age) {
|
||||
oldest_age = data->state.session[i].age;
|
||||
store = &data->state.session[i];
|
||||
@@ -783,9 +805,11 @@ Curl_SSLConnect(struct connectdata *conn)
|
||||
/* subtract the passed time */
|
||||
timeout_ms -= (long)has_passed;
|
||||
|
||||
if(timeout_ms < 0)
|
||||
if(timeout_ms < 0) {
|
||||
/* a precaution, no need to continue if time already is up */
|
||||
return CURLE_OPERATION_TIMEOUTED;
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEOUTED;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* no particular time-out has been set */
|
||||
|
||||
@@ -1090,7 +1090,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
|
||||
{
|
||||
unsigned char outbuf[2];
|
||||
int out_count = 0;
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
char *buffer = buf;
|
||||
|
||||
if(!ReadFile(stdin_handle, buf, 255, &nread, NULL)) {
|
||||
@@ -1116,6 +1116,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
|
||||
{
|
||||
if(events.lNetworkEvents & FD_READ)
|
||||
{
|
||||
/* This reallu OUGHT to check its return code. */
|
||||
Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
|
||||
|
||||
telrcv(conn, (unsigned char *)buf, nread);
|
||||
@@ -1159,7 +1160,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
|
||||
if(FD_ISSET(0, &readfd)) { /* read from stdin */
|
||||
unsigned char outbuf[2];
|
||||
int out_count = 0;
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
char *buffer = buf;
|
||||
|
||||
nread = read(0, buf, 255);
|
||||
@@ -1176,6 +1177,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
|
||||
}
|
||||
|
||||
if(FD_ISSET(sockfd, &readfd)) {
|
||||
/* This OUGHT to check the return code... */
|
||||
Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
|
||||
|
||||
/* if we receive 0 or less here, the server closed the connection and
|
||||
|
||||
115
lib/transfer.c
115
lib/transfer.c
@@ -173,7 +173,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||
{
|
||||
struct Curl_transfer_keeper *k = &conn->keep;
|
||||
struct SessionHandle *data = conn->data;
|
||||
CURLcode result;
|
||||
int result;
|
||||
ssize_t nread; /* number of bytes read */
|
||||
int didwhat=0;
|
||||
|
||||
@@ -181,25 +181,28 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||
if((k->keepon & KEEP_READ) &&
|
||||
FD_ISSET(conn->sockfd, &k->readfd)) {
|
||||
|
||||
if ((k->bytecount == 0) && (k->writebytecount == 0))
|
||||
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
||||
|
||||
didwhat |= KEEP_READ;
|
||||
|
||||
/* read! */
|
||||
result = Curl_read(conn, conn->sockfd, k->buf,
|
||||
BUFSIZE -1, &nread);
|
||||
|
||||
if(result)
|
||||
if(0>result)
|
||||
break; /* get out of loop */
|
||||
if(result>0)
|
||||
return result;
|
||||
|
||||
if ((k->bytecount == 0) && (k->writebytecount == 0))
|
||||
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
||||
|
||||
|
||||
didwhat |= KEEP_READ;
|
||||
|
||||
/* NULL terminate, allowing string ops to be used */
|
||||
if (0 < (signed int) nread)
|
||||
if (0 < nread)
|
||||
k->buf[nread] = 0;
|
||||
|
||||
/* if we receive 0 or less here, the server closed the connection and
|
||||
we bail out from this! */
|
||||
else if (0 >= (signed int) nread) {
|
||||
else if (0 >= nread) {
|
||||
k->keepon &= ~KEEP_READ;
|
||||
FD_ZERO(&k->rkeepfd);
|
||||
break;
|
||||
@@ -588,7 +591,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||
/* This is not an 'else if' since it may be a rest from the header
|
||||
parsing, where the beginning of the buffer is headers and the end
|
||||
is non-headers. */
|
||||
if (k->str && !k->header && ((signed int)nread > 0)) {
|
||||
if (k->str && !k->header && (nread > 0)) {
|
||||
|
||||
if(0 == k->bodywrites) {
|
||||
/* These checks are only made the first time we are about to
|
||||
@@ -669,7 +672,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||
if((-1 != conn->maxdownload) &&
|
||||
(k->bytecount + nread >= conn->maxdownload)) {
|
||||
nread = conn->maxdownload - k->bytecount;
|
||||
if((signed int)nread < 0 ) /* this should be unusual */
|
||||
if(nread < 0 ) /* this should be unusual */
|
||||
nread = 0;
|
||||
|
||||
k->keepon &= ~KEEP_READ; /* we're done reading */
|
||||
@@ -696,53 +699,84 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||
/* write */
|
||||
|
||||
int i, si;
|
||||
size_t bytes_written;
|
||||
ssize_t bytes_written;
|
||||
|
||||
if ((k->bytecount == 0) && (k->writebytecount == 0))
|
||||
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
||||
|
||||
didwhat |= KEEP_WRITE;
|
||||
|
||||
nread = data->set.fread(k->buf, 1, conn->upload_bufsize,
|
||||
data->set.in);
|
||||
/* only read more data if there's no upload data already
|
||||
present in the upload buffer */
|
||||
if(0 == conn->upload_present) {
|
||||
/* init the "upload from here" pointer */
|
||||
conn->upload_fromhere = k->uploadbuf;
|
||||
|
||||
/* the signed int typecase of nread of for systems that has
|
||||
unsigned size_t */
|
||||
if ((signed int)nread<=0) {
|
||||
/* done */
|
||||
k->keepon &= ~KEEP_WRITE; /* we're done writing */
|
||||
FD_ZERO(&k->wkeepfd);
|
||||
break;
|
||||
}
|
||||
k->writebytecount += nread;
|
||||
Curl_pgrsSetUploadCounter(data, (double)k->writebytecount);
|
||||
nread = data->set.fread(conn->upload_fromhere, 1,
|
||||
conn->upload_bufsize,
|
||||
data->set.in);
|
||||
|
||||
/* convert LF to CRLF if so asked */
|
||||
if (data->set.crlf) {
|
||||
for(i = 0, si = 0; i < (int)nread; i++, si++) {
|
||||
if (k->buf[i] == 0x0a) {
|
||||
data->state.scratch[si++] = 0x0d;
|
||||
data->state.scratch[si] = 0x0a;
|
||||
}
|
||||
else {
|
||||
data->state.scratch[si] = k->buf[i];
|
||||
}
|
||||
/* the signed int typecase of nread of for systems that has
|
||||
unsigned size_t */
|
||||
if (nread<=0) {
|
||||
/* done */
|
||||
k->keepon &= ~KEEP_WRITE; /* we're done writing */
|
||||
FD_ZERO(&k->wkeepfd);
|
||||
break;
|
||||
}
|
||||
nread = si;
|
||||
k->buf = data->state.scratch; /* point to the new buffer */
|
||||
|
||||
/* store number of bytes available for upload */
|
||||
conn->upload_present = nread;
|
||||
|
||||
/* convert LF to CRLF if so asked */
|
||||
if (data->set.crlf) {
|
||||
for(i = 0, si = 0; i < nread; i++, si++) {
|
||||
if (k->buf[i] == 0x0a) {
|
||||
data->state.scratch[si++] = 0x0d;
|
||||
data->state.scratch[si] = 0x0a;
|
||||
}
|
||||
else {
|
||||
data->state.scratch[si] = k->uploadbuf[i];
|
||||
}
|
||||
}
|
||||
nread = si;
|
||||
k->buf = data->state.scratch; /* point to the new buffer */
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* We have a partial buffer left from a previous "round". Use
|
||||
that instead of reading more data */
|
||||
|
||||
}
|
||||
|
||||
/* write to socket */
|
||||
result = Curl_write(conn, conn->writesockfd, k->buf, nread,
|
||||
result = Curl_write(conn,
|
||||
conn->writesockfd,
|
||||
conn->upload_fromhere,
|
||||
conn->upload_present,
|
||||
&bytes_written);
|
||||
if(result)
|
||||
return result;
|
||||
else if(nread != (int)bytes_written) {
|
||||
failf(data, "Failed uploading data");
|
||||
return CURLE_WRITE_ERROR;
|
||||
else if(conn->upload_present != bytes_written) {
|
||||
/* we only wrote a part of the buffer (if anything), deal with it! */
|
||||
|
||||
/* store the amount of bytes left in the buffer to write */
|
||||
conn->upload_present -= bytes_written;
|
||||
|
||||
/* advance the pointer where to find the buffer when the next send
|
||||
is to happen */
|
||||
conn->upload_fromhere += bytes_written;
|
||||
}
|
||||
else if(data->set.crlf)
|
||||
k->buf = data->state.buffer; /* put it back on the buffer */
|
||||
else {
|
||||
/* we've uploaded that buffer now */
|
||||
conn->upload_fromhere = k->uploadbuf;
|
||||
conn->upload_present = 0; /* no more bytes left */
|
||||
}
|
||||
|
||||
k->writebytecount += nread;
|
||||
Curl_pgrsSetUploadCounter(data, (double)k->writebytecount);
|
||||
|
||||
}
|
||||
|
||||
@@ -835,6 +869,7 @@ CURLcode Curl_readwrite_init(struct connectdata *conn)
|
||||
|
||||
data = conn->data; /* there's the root struct */
|
||||
k->buf = data->state.buffer;
|
||||
k->uploadbuf = data->state.uploadbuffer;
|
||||
k->maxfd = (conn->sockfd>conn->writesockfd?
|
||||
conn->sockfd:conn->writesockfd)+1;
|
||||
k->hbufp = data->state.headerbuff;
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
#include "http_chunks.h" /* for the structs and enum stuff */
|
||||
|
||||
/* Download buffer size, keep it fairly big for speed reasons */
|
||||
#define BUFSIZE (1024*50)
|
||||
#define BUFSIZE (1024*20)
|
||||
|
||||
/* Defaul upload buffer size, keep it smallish to get faster progress meter
|
||||
updates. This is just default, it is dynamic and adjusts to the upload
|
||||
@@ -251,6 +251,7 @@ struct Curl_transfer_keeper {
|
||||
struct SessionHandle *data;
|
||||
struct connectdata *conn;
|
||||
char *buf;
|
||||
char *uploadbuf;
|
||||
int maxfd;
|
||||
|
||||
/* the file descriptors to play with */
|
||||
@@ -409,6 +410,16 @@ struct connectdata {
|
||||
|
||||
/* This struct is inited when needed */
|
||||
struct Curl_transfer_keeper keep;
|
||||
|
||||
/* 'upload_present' is used to keep a byte counter of how much data there is
|
||||
still left in the buffer, aimed for upload. */
|
||||
int upload_present;
|
||||
|
||||
/* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
|
||||
buffer, so the next read should read from where this pointer points to,
|
||||
and the 'upload_present' contains the number of bytes available at this
|
||||
position */
|
||||
char *upload_fromhere;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -495,8 +506,8 @@ struct UrlState {
|
||||
char *headerbuff; /* allocated buffer to store headers in */
|
||||
int headersize; /* size of the allocation */
|
||||
|
||||
char buffer[BUFSIZE+1]; /* buffer with size BUFSIZE */
|
||||
|
||||
char buffer[BUFSIZE+1]; /* download buffer */
|
||||
char uploadbuffer[BUFSIZE+1]; /* upload buffer */
|
||||
double current_speed; /* the ProgressShow() funcion sets this */
|
||||
|
||||
bool this_is_a_follow; /* this is a followed Location: request */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2002, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* In order to be useful for every potential user, curl and libcurl are
|
||||
* dual-licensed under the MPL and the MIT/X-derivate licenses.
|
||||
@@ -38,20 +38,28 @@ char *curl_version(void)
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
|
||||
#if (SSLEAY_VERSION_NUMBER >= 0x906000)
|
||||
#if (SSLEAY_VERSION_NUMBER >= 0x905000)
|
||||
{
|
||||
char sub[2];
|
||||
unsigned long ssleay_value;
|
||||
sub[1]='\0';
|
||||
if(SSLEAY_VERSION_NUMBER&0xff0) {
|
||||
sub[0]=((SSLEAY_VERSION_NUMBER>>4)&0xff) + 'a' -1;
|
||||
}
|
||||
else
|
||||
ssleay_value=SSLeay();
|
||||
if(ssleay_value < 0x906000) {
|
||||
ssleay_value=SSLEAY_VERSION_NUMBER;
|
||||
sub[0]='\0';
|
||||
}
|
||||
else {
|
||||
if(ssleay_value&0xff0) {
|
||||
sub[0]=((ssleay_value>>4)&0xff) + 'a' -1;
|
||||
}
|
||||
else
|
||||
sub[0]='\0';
|
||||
}
|
||||
|
||||
sprintf(ptr, " (OpenSSL %lx.%lx.%lx%s)",
|
||||
(SSLEAY_VERSION_NUMBER>>28)&0xf,
|
||||
(SSLEAY_VERSION_NUMBER>>20)&0xff,
|
||||
(SSLEAY_VERSION_NUMBER>>12)&0xff,
|
||||
(ssleay_value>>28)&0xf,
|
||||
(ssleay_value>>20)&0xff,
|
||||
(ssleay_value>>12)&0xff,
|
||||
sub);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#define CURL_NAME "curl"
|
||||
#define CURL_VERSION "7.9.3-pre1"
|
||||
#define CURL_VERSION "7.9.3-pre3"
|
||||
#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") "
|
||||
|
||||
@@ -14,8 +14,10 @@ specified, that will be checked/used if specified. This document includes all
|
||||
the subsections currently supported.
|
||||
|
||||
<reply>
|
||||
<data>
|
||||
data to sent to the client on its request
|
||||
<data [nocheck=1]>
|
||||
data to sent to the client on its request and later verified that it arrived
|
||||
safely. Set the nocheck=1 to prevent the test script to verify the arrival
|
||||
of this data.
|
||||
</data>
|
||||
<datacheck>
|
||||
if the data is sent but this is what should be checked afterwards
|
||||
@@ -30,16 +32,20 @@ reply is sent
|
||||
<postcmd>
|
||||
special purpose server-command to control its behavior *after* the
|
||||
reply is sent
|
||||
</oistcmd>
|
||||
</postcmd>
|
||||
</reply>
|
||||
|
||||
<client>
|
||||
<name>
|
||||
test case description
|
||||
</name>
|
||||
<command>
|
||||
<command [option=no-output]>
|
||||
command line to run, there's a bunch of %variables that get replaced
|
||||
accordingly. more about them elsewhere
|
||||
|
||||
Set 'option=no-output' to prevent the test script to slap on the --output
|
||||
argument that directs the output to a file. The --output is also not added if
|
||||
the client/stdout section is used.
|
||||
</command>
|
||||
<file name="log/filename">
|
||||
this creates the named file with this content before the test case is run
|
||||
@@ -59,6 +65,9 @@ changing protocol data such as port numbers or user-agent strings.
|
||||
<protocol>
|
||||
the protocol dump curl should transmit
|
||||
</protocol>
|
||||
<stdout>
|
||||
This verfies that this data was passed to stdout.
|
||||
</stdout>
|
||||
<file name="log/filename">
|
||||
the file's contents must be identical to this
|
||||
</file>
|
||||
|
||||
@@ -13,5 +13,5 @@ test102 test111 test120 test16 test21 test30 test400 test7 \
|
||||
test103 test112 test121 test17 test22 test300 test401 test8 \
|
||||
test104 test113 test122 test18 test23 test301 test402 test9 \
|
||||
test105 test114 test123 test19 test24 test302 test43 \
|
||||
test106 test115 test124 test190 test25 test303 test44 \
|
||||
test106 test115 test124 test190 test25 test303 test44 test38 \
|
||||
test107 test116 test125 test2 test26 test33 test45 test126
|
||||
|
||||
49
tests/data/test38
Normal file
49
tests/data/test38
Normal file
@@ -0,0 +1,49 @@
|
||||
# Server-side
|
||||
<reply>
|
||||
<data nocheck=1>
|
||||
HTTP/1.0 200 Mooo
|
||||
Date: Mon, 13 Nov 2000 13:41:09 GMT
|
||||
Server: myown/1.0
|
||||
Connection: close
|
||||
|
||||
todelooooo lalalala yada yada, we know nothing about ranges ;-)
|
||||
</data>
|
||||
</reply>
|
||||
|
||||
# Client-side
|
||||
<client>
|
||||
<name>
|
||||
HTTP resume request without server supporting it
|
||||
</name>
|
||||
<command option="no-output">
|
||||
http://%HOSTIP:%HOSTPORT/want/38 -C - -i -o log/fewl.txt
|
||||
</command>
|
||||
<file name="log/fewl.txt">
|
||||
This text is here to simulate a partly downloaded file to resume
|
||||
download on.
|
||||
</file>
|
||||
</client>
|
||||
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
<errorcode>
|
||||
33
|
||||
</errorcode>
|
||||
<strip>
|
||||
^User-Agent:.*
|
||||
</strip>
|
||||
<protocol>
|
||||
GET /want/38 HTTP/1.1
|
||||
Range: bytes=78-
|
||||
Host: 127.0.0.1:8999
|
||||
Pragma: no-cache
|
||||
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
|
||||
|
||||
</protocol>
|
||||
|
||||
# the download target file must remain untouched
|
||||
<file name="log/fewl.txt">
|
||||
This text is here to simulate a partly downloaded file to resume
|
||||
download on.
|
||||
</file>
|
||||
</verify>
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
my @xml;
|
||||
|
||||
my $warning=0;
|
||||
my $trace=0;
|
||||
|
||||
sub getpartattr {
|
||||
my ($section, $part)=@_;
|
||||
|
||||
@@ -63,12 +66,21 @@ sub getpart {
|
||||
$inside--;
|
||||
}
|
||||
elsif((1==$inside) && ($_ =~ /^ *\<\/$section/)) {
|
||||
if($trace) {
|
||||
print STDERR "*** getpart.pm: $section/$part returned data!\n";
|
||||
}
|
||||
if(!@this && $warning) {
|
||||
print STDERR "*** getpart.pm: $section/$part returned empty!\n";
|
||||
}
|
||||
return @this;
|
||||
}
|
||||
elsif(2==$inside) {
|
||||
push @this, $_;
|
||||
}
|
||||
}
|
||||
if($warning) {
|
||||
print STDERR "*** getpart.pm: $section/$part returned empty!\n";
|
||||
}
|
||||
return @this; #empty!
|
||||
}
|
||||
|
||||
|
||||
@@ -483,9 +483,17 @@ sub singletest {
|
||||
writearray($filename, \@inputfile);
|
||||
}
|
||||
|
||||
my %cmdhash = getpartattr("client", "command");
|
||||
|
||||
my $out="";
|
||||
if (!@validstdout) {
|
||||
$out="--output $CURLOUT ";
|
||||
|
||||
if($cmdhash{'option'} eq "no-output") {
|
||||
#print "*** We don't slap on --output\n";
|
||||
}
|
||||
else {
|
||||
if (!@validstdout) {
|
||||
$out="--output $CURLOUT ";
|
||||
}
|
||||
}
|
||||
|
||||
# run curl, add -v for debug information output
|
||||
@@ -832,7 +840,9 @@ if($testthis[0] ne "") {
|
||||
# Output curl version and host info being tested
|
||||
#
|
||||
|
||||
displaydata();
|
||||
if(!$listonly) {
|
||||
displaydata();
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# clear and create logging directory:
|
||||
|
||||
Reference in New Issue
Block a user