Georg Horn's updates, this is _also_ called 1.1.3 ! ;-)

This commit is contained in:
Daniel Stenberg 2001-04-18 13:41:04 +00:00
parent 80fbcdf2f2
commit 8e9f0a73d0
4 changed files with 62 additions and 68 deletions

View File

@ -2,9 +2,9 @@ Revision history for Perl extension Curl::easy.
Check out the file README for more info. Check out the file README for more info.
1.1.3 Wed Apr 18 2001: - Cris Bailiff <c.bailiff@devsecure.com> 1.1.3 Wed Apr 18 2001: - Cris Bailiff <c.bailiff@devsecure.com>
- Change/shorten module function names: - Change/shorten module function names: Curl::easy::curl_easy_setopt
Curl::easy::curl_easy_setopt becomes Curl::easy::setopt etc. becomes Curl::easy::setopt etc. This requires minor changes to existing
This requires minor changes to existing scripts.... scripts....
- Added callback function support to pass arbitrary SV * (including - Added callback function support to pass arbitrary SV * (including
FILE globs) from perl through libcurl to the perl callback. FILE globs) from perl through libcurl to the perl callback.
- Make callbacks still work with existing scripts which use STDIO - Make callbacks still work with existing scripts which use STDIO

View File

@ -1,6 +1,7 @@
Changes Changes
MANIFEST MANIFEST
Makefile.PL Makefile.PL
README
easy.pm easy.pm
easy.xs easy.xs
test.pl test.pl

View File

@ -12,16 +12,16 @@ installed. You then may install this module via the usual way:
make install make install
The module provides the same functionality as libcurl provides to C programs, The module provides the same functionality as libcurl provides to C programs,
please refer to the documentation of libcurl. please refer to the documentation of libcurl. Some examples may be found in
test.pl.
A short example how to use the module may be found in test.pl. This software is distributed AS IS, WITHOUT WARRANTY OF ANY KIND, either
express or implied. Send praise, patches, money, beer and pizza to the author.
Send complaints to /dev/null. ;-)
This Software is distributed AS IS, WITHOUT WARRANTY OF ANY KIND, The author of this software is Georg Horn <horn@koblenz-net.de>
either express or implied. Send praise, patches, money, beer and Parts of the callback support have been added by Cris Bailiff
pizza to the author. Send complaints to /dev/null. ;-) <c.bailiff@awayweb.com> and Forrest Cahoon <forrest.cahoon@merrillcorp.com>
The author of this module is Georg Horn <horn@koblenz-net.de> The latest version can be downloaded from http://koblenz-net.de/~horn/export/
The latest version of this module can be dowloaded from
http://koblenz-net.de/~horn/export/

View File

@ -29,8 +29,8 @@ static char *errbufvarname = NULL;
static SV *read_callback = NULL, *write_callback = NULL, static SV *read_callback = NULL, *write_callback = NULL,
*progress_callback = NULL, *passwd_callback = NULL, *progress_callback = NULL, *passwd_callback = NULL,
*header_callback = NULL; *header_callback = NULL;
/* *closepolicy_callback = NULL; */ /* *closepolicy_callback = NULL; */
/* For storing the content */ /* For storing the content */
@ -87,58 +87,58 @@ fwrite_wrapper (const void *ptr,
void *stream, void *stream,
void *call_function) void *call_function)
{ {
dSP ; dSP;
int count,status; int count, status;
SV *sv; SV *sv;
if (call_function) { if (call_function) {
/* then we are doing a callback to perl */ /* then we are doing a callback to perl */
ENTER ; ENTER;
SAVETMPS ; SAVETMPS;
PUSHMARK(SP) ;
if (stream == stdout) { PUSHMARK(SP);
sv = newSViv(0); /* FIXME: should cast stdout to GLOB somehow? */
} else { /* its already an SV */ if (stream == stdout) {
sv = stream; sv = newSViv(0); /* FIXME: should cast stdout to GLOB somehow? */
} } else { /* its already an SV */
sv = stream;
if (ptr != NULL) { }
XPUSHs(sv_2mortal(newSVpvn(ptr, size * nmemb)));
if (ptr != NULL) {
XPUSHs(sv_2mortal(newSVpvn(ptr, size * nmemb)));
} else { } else {
XPUSHs(sv_2mortal(newSVpv("",0))); XPUSHs(sv_2mortal(newSVpv("", 0)));
} }
XPUSHs(sv_2mortal(newSVsv(sv))); /* CURLOPT_FILE SV* */ XPUSHs(sv_2mortal(newSVsv(sv))); /* CURLOPT_FILE SV* */
PUTBACK ; PUTBACK;
count = call_sv((SV *)call_function, G_SCALAR); count = perl_call_sv((SV *) call_function, G_SCALAR);
SPAGAIN;
if (count != 1)
croak("Big trouble, perl_call_sv(write_callback) didn't return status\n");
status = POPi; SPAGAIN;
if (count != 1)
croak("Big trouble, perl_call_sv(write_callback) didn't return status\n");
PUTBACK ; status = POPi;
FREETMPS ;
LEAVE ;
return status;
} else { PUTBACK;
/* default to a normal 'fwrite' */
/* stream could be a FILE * or an SV * */
FILE *f;
if (stream == stdout) { /* the only possible FILE ? Think so*/
f = stream;
} else { /* its a GLOB */
f = IoIFP(sv_2io(stream)); /* may barf if not a GLOB */
}
return fwrite(ptr,size,nmemb,f); FREETMPS;
LEAVE;
return status;
} else {
/* default to a normal 'fwrite' */
/* stream could be a FILE * or an SV * */
FILE *f;
if (stream == stdout) { /* the only possible FILE ? Think so */
f = stream;
} else { /* its a GLOB */
f = IoIFP(sv_2io(stream)); /* may barf if not a GLOB */
}
return fwrite(ptr, size, nmemb, f);
} }
} }
@ -192,7 +192,7 @@ read_callback_func( void *ptr, size_t size,
XPUSHs(sv_2mortal(newSVsv(sv))); /* CURLOPT_INFILE SV* */ XPUSHs(sv_2mortal(newSVsv(sv))); /* CURLOPT_INFILE SV* */
PUTBACK ; PUTBACK ;
count = call_sv(read_callback, G_SCALAR); count = perl_call_sv(read_callback, G_SCALAR);
SPAGAIN; SPAGAIN;
if (count != 1) if (count != 1)
@ -209,7 +209,6 @@ read_callback_func( void *ptr, size_t size,
FREETMPS ; FREETMPS ;
LEAVE ; LEAVE ;
return (size_t) (mylen/size); return (size_t) (mylen/size);
} else { } else {
/* default to a normal 'fread' */ /* default to a normal 'fread' */
/* stream could be a FILE * or an SV * */ /* stream could be a FILE * or an SV * */
@ -284,7 +283,7 @@ static int passwd_callback_func(void *clientp, char *prompt, char *buffer,
count = perl_call_sv(passwd_callback, G_ARRAY); count = perl_call_sv(passwd_callback, G_ARRAY);
SPAGAIN; SPAGAIN;
if (count != 2) if (count != 2)
croak("Big trouble, perl_call_sv(passwd_callback) didn't return status + data\n"); croak("Big trouble, perl_call_sv(passwd_callback) didn't return status + data\n");
sv = POPs; sv = POPs;
count = POPi; count = POPi;
@ -294,7 +293,7 @@ static int passwd_callback_func(void *clientp, char *prompt, char *buffer,
/* only allowed to return the number of bytes asked for */ /* only allowed to return the number of bytes asked for */
mylen = len<(buflen-1) ? len : (buflen-1); mylen = len<(buflen-1) ? len : (buflen-1);
memcpy(buffer,p,mylen); memcpy(buffer,p,mylen);
buffer[buflen]=0; /* ensure C string terminates */ buffer[buflen]=0; /* ensure C string terminates */
PUTBACK; PUTBACK;
FREETMPS; FREETMPS;
@ -318,12 +317,11 @@ closepolicy_callback_func(void *clientp)
PUSHMARK(SP); PUSHMARK(SP);
PUTBACK; PUTBACK;
argc = call_sv(closepolicy_callback, G_SCALAR); argc = perl_call_sv(closepolicy_callback, G_SCALAR);
SPAGAIN; SPAGAIN;
if (argc != 1) { if (argc != 1) {
croak croak("Unexpected number of arguments returned from closefunction callback\n");
("Unexpected number of arguments returned from closefunction callback\n");
} }
pl_status = POPs; pl_status = POPs;
status = SvTRUE(pl_status) ? 0 : 1; status = SvTRUE(pl_status) ? 0 : 1;
@ -560,22 +558,18 @@ int option
SV * value SV * value
CODE: CODE:
if (option < CURLOPTTYPE_OBJECTPOINT) { if (option < CURLOPTTYPE_OBJECTPOINT) {
/* This is an option specifying an integer value: */ /* This is an option specifying an integer value: */
RETVAL = curl_easy_setopt(curl, option, (long)SvIV(value)); RETVAL = curl_easy_setopt(curl, option, (long)SvIV(value));
} else if (option == CURLOPT_FILE || option == CURLOPT_INFILE || } else if (option == CURLOPT_FILE || option == CURLOPT_INFILE ||
option == CURLOPT_WRITEHEADER || option == CURLOPT_PROGRESSDATA || option == CURLOPT_WRITEHEADER || option == CURLOPT_PROGRESSDATA ||
option == CURLOPT_PASSWDDATA) { option == CURLOPT_PASSWDDATA) {
/* This is an option specifying an SV * value: */ /* This is an option specifying an SV * value: */
RETVAL = curl_easy_setopt(curl, option, newSVsv(ST(2))); RETVAL = curl_easy_setopt(curl, option, newSVsv(ST(2)));
} else if (option == CURLOPT_ERRORBUFFER) { } else if (option == CURLOPT_ERRORBUFFER) {
/* Pass in variable name for storing error messages... */ /* Pass in variable name for storing error messages... */
RETVAL = curl_easy_setopt(curl, option, errbuf); RETVAL = curl_easy_setopt(curl, option, errbuf);
if (errbufvarname) free(errbufvarname); if (errbufvarname) free(errbufvarname);
errbufvarname = strdup((char *)SvPV(value, PL_na)); errbufvarname = strdup((char *)SvPV(value, PL_na));
} else if (option == CURLOPT_WRITEFUNCTION || option == } else if (option == CURLOPT_WRITEFUNCTION || option ==
CURLOPT_READFUNCTION || option == CURLOPT_PROGRESSFUNCTION || CURLOPT_READFUNCTION || option == CURLOPT_PROGRESSFUNCTION ||
option == CURLOPT_PASSWDFUNCTION || option == CURLOPT_HEADERFUNCTION) { option == CURLOPT_PASSWDFUNCTION || option == CURLOPT_HEADERFUNCTION) {
@ -608,7 +602,6 @@ CODE:
*/ */
} }
RETVAL = -1; RETVAL = -1;
} else if (option == CURLOPT_HTTPHEADER || option == CURLOPT_QUOTE || } else if (option == CURLOPT_HTTPHEADER || option == CURLOPT_QUOTE ||
option == CURLOPT_POSTQUOTE) { option == CURLOPT_POSTQUOTE) {
/* This is an option specifying a list of curl_slist structs: */ /* This is an option specifying a list of curl_slist structs: */