Skip to content

Commit

Permalink
can't recall
Browse files Browse the repository at this point in the history
  • Loading branch information
duncantl committed Aug 7, 2012
1 parent b1f88c1 commit 26638f8
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 27 deletions.
46 changes: 44 additions & 2 deletions Changes.html
Expand Up @@ -3,6 +3,36 @@
<title>Change log for RCurl</title>
</head>
<body>

<h2>1.94-1</h2>
<dl>

<dt>
<li> Field httpHeader added to the error/condition object when an
HTTP error is raised.
<dd>

<dt>
<dd> Added close() method for CFILE.
<dt>

<li> stop.if.HTTP.error() now raises an error for 4xx and 5xx status codes.
<dd> Thanks to Thomas Themel.
</dl>

<h2>1.94-0</h2>
<dl>
<dt>
<li> Fix to getForm() to allow the URL to contain a ?, e.g. with
some parameters specified in the URL
<dd>

<dt>
<li> getM
<dd>

</dl>

<h2>1.93-0</h2>
<dl>
<dt>
Expand All @@ -18,13 +48,25 @@ <h2>1.93-0</h2>
<dt>
<li> postForm() checks the header in the response and throws an
error if the request was not successful.

<dt>
<li> Added finalizer for CFILE()
<dd>

<dt>
<li> Allow writefunction and headerfunction to return TRUE to
indicate success.
<dd>
<dt>
<li> Exported AUTH_* variables, e.g. AUTH_BASIC, AUTH_DIGEST, etc.
<dd>
<dd>
</dl>
<h2>1.92-1</h2>
<dl>
<dt>
<li> Set the error buffer when we call reset for a curl object.
<dd> Thanks to Hadley Wickham for bring this to my attention.
<dd> Thanks to Hadley Wickham for bringing this to my attention.
</dl>

<h2>1.92-0</h2>
Expand Down Expand Up @@ -957,6 +999,6 @@ <h2>0.3-0</h2>
<address><a href="http://www.stat.ucdavis.edu/~duncan">Duncan Temple Lang</a>
<a href=mailto:duncan@wald.ucdavis.edu>&lt;duncan@wald.ucdavis.edu&gt;</a></address>
<!-- hhmts start -->
Last modified: Mon Jun 4 07:02:40 PDT 2012
Last modified: Fri Jul 20 06:46:07 PDT 2012
<!-- hhmts end -->
</body> </html>
4 changes: 3 additions & 1 deletion NAMESPACE
Expand Up @@ -55,6 +55,8 @@ exportPattern("SSLVERSION_.*")

exportClass("CFILE")
export(CFILE)
exportMethods(close)



export(scp)
Expand All @@ -71,7 +73,7 @@ export(getFormParams)
export(url.exists)
export(curlError)


export(AUTH_ONLY, AUTH_ANY, AUTH_NTLM, AUTH_ANYSAFE, AUTH_NTLM_WB, AUTH_DIGEST_IE, AUTH_BASIC, AUTH_DIGEST, AUTH_GSSNEGOTIATE, AUTH_NONE)

#export(CURLAUTH_ONLY, CURLAUTH_ANY, CURLAUTH_NTLM, CURLAUTH_ANYSAFE, CURLAUTH_NTLM_WB,
# CURLAUTH_DIGEST_IE, CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NONE)
Expand Down
6 changes: 6 additions & 0 deletions R/classes.S
@@ -1,3 +1,9 @@
.onAttach =
function(...)
library(methods)



setClass("MultiCURLHandle",
representation(ref = "externalptr",
subhandles = "list"))
Expand Down
10 changes: 9 additions & 1 deletion R/curl.S
Expand Up @@ -25,9 +25,12 @@ debugGatherer =
function()
{
els = NULL
info = NULL

update = function(msg, type, curl) {
els[[type + 1]] <<- c(els[[type + 1]], msg)
info[[length(info) + 1]] <<- msg
names(info)[length(info)] <<- names(type)
0
}

Expand All @@ -39,10 +42,15 @@ function()
dataOut = character(),
sslDataIn = character(),
sslDataOut = character())

info <<- list()
}

ans = list(update = update,
value = function(collapse="", ...) {
value = function(collapse = "", ordered = FALSE, ...) {
if(ordered)
return(info)

if(is.null(collapse))
return(els)

Expand Down
5 changes: 3 additions & 2 deletions R/curlInfo.S
Expand Up @@ -11,9 +11,10 @@ function(id = 0)
}


CurlFeatureBits = as.integer(2^(0:10))
CurlFeatureBits = as.integer(2^(0:15))
names(CurlFeatureBits) = c("ipv6", "kerberos4", "ssl", "libz", "ntlm", "gssnegotiate",
"debug", "asynchdns", "spnego", "largefile")
"debug", "asynchdns", "spnego", "largefile", "idn", "sspi",
"conv", "curldebug", "tlsauth_srp", "ntlm_wb")
class(CurlFeatureBits) = c("CurlFeatureBits", "BitIndicator")


Expand Down
4 changes: 2 additions & 2 deletions R/form.S
Expand Up @@ -25,9 +25,9 @@ function(uri, ..., .params = character(), .opts = list(), curl = getCurlHandle()
paste(id, curlEscape(val), sep="=", collapse="&")
}, names(.params), .params)

args = paste(els, collapse="&")
args = paste(els, collapse = "&")

uri = paste(uri, args, sep="?")
uri = paste(uri, args, sep = if(grepl("\\?", uri)) "&" else "?")

getURLContent(uri, .opts = .opts, .encoding = .encoding, binary = binary, curl = curl)
}
Expand Down
6 changes: 6 additions & 0 deletions R/getFormParams.R
Expand Up @@ -37,6 +37,12 @@ function(query, isURL = grepl("^(http|\\?)", query))
if(any(i <- is.na(ans)))
ans[i] = ""

names(ans) = trim(names(ans))
ans
}

trim =
function(x)
gsub("(^[[:space:]]+|[[:space:]]$)", "", x)


3 changes: 2 additions & 1 deletion R/getURLContent.R
Expand Up @@ -60,9 +60,10 @@ function(http.header)
if(length(http.header) == 0)
return(NA) # or TRUE

if( floor(as.integer(http.header[["status"]])/100) == 4) {
if( floor(as.integer(http.header[["status"]])/100) >= 4) {
klass = RCurl:::getHTTPErrorClass(http.header[["status"]])
err = simpleError(http.header[["statusMessage"]])
err$httpHeader = http.header
class(err) = c(klass, class(err))
#signalCondition(err)
stop(err)
Expand Down
2 changes: 1 addition & 1 deletion R/http.R
Expand Up @@ -38,7 +38,7 @@ function(url, ..., curl = getCurlHandle())
HEAD = httpHEAD =
function(url, ..., curl = getCurlHandle())
{
getURLContent(url, customrequest = "HEAD", ..., curl = curl)
getURLContent(url, customrequest = "HEAD", nobody = TRUE, ..., curl = curl)
}

httpOPTIONS =
Expand Down
45 changes: 33 additions & 12 deletions R/multi.S
Expand Up @@ -12,10 +12,12 @@ getURLAsynchronous = getURIAsynchronous =

# If you call this function, you get to download the
#
function(url, ..., .opts = list(), write = multiTextGatherer(url), curl = getCurlHandle(),
multiHandle = getCurlMultiHandle(), perform = Inf, .encoding = integer())
function(url, ..., .opts = list(), write = NULL, curl = getCurlHandle(),
multiHandle = getCurlMultiHandle(), perform = Inf, .encoding = integer(), binary = rep(NA, length(url)))
{
if(!is.list(write))
writeSupplied = !missing(write)

if(!is.null(write) && !is.list(write))
write = replicate(length(url), write)


Expand All @@ -26,17 +28,33 @@ function(url, ..., .opts = list(), write = multiTextGatherer(url), curl = getCur

if(length(.encoding))
.encoding = rep(.encoding, length = length(url))

if(is.null(write)) {
writeSupplied = FALSE
write = mapply(function(curl, url, binary) {
force(url); force(curl); force(binary)
dynCurlReader(curl, baseURL = url, binary = binary)
},
curl, url, binary, SIMPLIFY = FALSE)
}


for(i in seq(along = url)) {
w = write[[i]]
if(inherits(w, "RCurlCallbackFunction"))
w = w$update
opts = curlOptions(URL = url[i], writefunction = w, ..., .opts = .opts)
if(inherits(w, "DynamicRCurlTextHandler")) {
.opts[["headerfunction"]] = w$update
.opts[["writefunction"]] = w$update
} else if(inherits(w, "RCurlCallbackFunction"))
.opts[["writefunction"]] = w$update
else
.opts[["writefunction"]] = w

opts = curlOptions(URL = url[i], ..., .opts = .opts)
curlSetOpt(.opts = opts, curl = curl[[i]], .encoding = if(length(.encoding)) .encoding[i] else integer())

multiHandle = push(multiHandle, curl[[i]])
}

if(perform > 0) {
ctr = 0
while(TRUE) {
Expand All @@ -45,8 +63,9 @@ function(url, ..., .opts = list(), write = multiTextGatherer(url), curl = getCur
if(status[2] == 0 || ctr > perform)
break
}
if(status[2] == 0 && inherits(write, "MultiTextGatherer"))
return(sapply(write, function(w) w$value()))
if(status[2] == 0 && (!writeSupplied || inherits(write, "MultiTextGatherer")))
return(sapply(write, function(w) w$value()))

}

# Need to get the new write functions back if we didn't
Expand All @@ -66,7 +85,7 @@ setMethod("complete", "MultiCURLHandle",


multiTextGatherer =
function(uris)
function(uris, binary = rep(NA, length(uris)))
{
if(is.numeric(uris))
ans = lapply(1:uris, basicTextGatherer)
Expand All @@ -81,9 +100,11 @@ function(uris)
}

getCurlMultiHandle =
function()
function(..., .handles = list(...))
{
.Call("R_getCurlMultiHandle", PACKAGE = "RCurl")
ans = .Call("R_getCurlMultiHandle", PACKAGE = "RCurl")
lapply(.handles, function(h) push(ans, h))
ans
}


Expand Down
8 changes: 8 additions & 0 deletions R/upload.R
Expand Up @@ -56,3 +56,11 @@ function(filename, mode = "r")
filename = path.expand(filename)
.Call("R_openFile", filename, as.character(mode))
}


setMethod("close", "CFILE",
function(con, ...) {
.Call("R_closeCFILE", con@ref, PACKAGE = "RCurl")
con
})

2 changes: 1 addition & 1 deletion src/Makevars
Expand Up @@ -4,7 +4,7 @@ CURL_CONFIG=/usr/local/bin/curl-config
# CURL_LIBS=$(shell $(CURL_CONFIG) --libs)

CURL_CFLAGS=-I/usr/local/include
CURL_LIBS=-L/usr/local/lib -lcurl -lssh2 -lssl -lcrypto -lldap -lssl -lcrypto -lz -lz
CURL_LIBS=-L/usr/local/lib -lcurl -lidn -lssh2 -lssl -lcrypto -lldap -lssl -lcrypto -lz -lz


# -DRCURL_DEBUG_MEMORY
Expand Down
40 changes: 36 additions & 4 deletions src/curl.c
Expand Up @@ -255,13 +255,31 @@ R_curl_easy_setopt(SEXP handle, SEXP values, SEXP opts, SEXP isProtected, SEXP e
return(makeCURLcodeRObject(status));
}

void
R_closeFILE(SEXP r_file)
{
FILE *f = (FILE *) R_ExternalPtrAddr(r_file);
if(f) {
fflush(f);
fclose(f);
R_SetExternalPtrAddr(r_file, NULL); // R_NilValue);
}
}

SEXP
R_closeCFILE(SEXP r_file)
{
R_closeFILE(r_file);
return(r_file);
}

SEXP
R_openFile(SEXP r_filename, SEXP r_mode)
{
const char *filename = CHAR(STRING_ELT(r_filename, 0));
const char *mode = CHAR(STRING_ELT(r_mode, 0));
FILE *ans;
SEXP r_ans, klass;
SEXP r_ans, klass, tmp;

ans = fopen(filename, mode);
if(!ans) {
Expand All @@ -270,7 +288,8 @@ R_openFile(SEXP r_filename, SEXP r_mode)
}
PROTECT(klass = MAKE_CLASS("CFILE"));
PROTECT(r_ans = NEW(klass));
SET_SLOT(r_ans, Rf_install("ref"), R_MakeExternalPtr(ans, Rf_install("FILE"), R_NilValue));
SET_SLOT(r_ans, Rf_install("ref"), tmp = R_MakeExternalPtr(ans, Rf_install("FILE"), R_NilValue));
R_RegisterCFinalizer(tmp, R_closeFILE);
UNPROTECT(2);
return(r_ans);
}
Expand Down Expand Up @@ -996,8 +1015,14 @@ R_call_R_write_function(SEXP fun, void *buffer, size_t size, size_t nmemb, RWrit

PROTECT(ans = Rf_eval(e, R_GlobalEnv)); /* , &errorOccurred); */
if(TYPEOF(ans) == LGLSXP) {
if(LOGICAL(ans)[0])
numRead = size*nmemb;
else
numRead = 0;
/*
if(LOGICAL(ans)[0] == 1)
errorOccurred = 1;
*/
} else if(TYPEOF(ans) == INTSXP) {
numRead = INTEGER(ans)[0];
} else
Expand Down Expand Up @@ -1077,10 +1102,16 @@ R_curl_write_data(void *buffer, size_t size, size_t nmemb, RWriteDataInfo *data)

#include <Rversion.h>

const char const *CurlInfoTypeNames[] = {
"TEXT", "HEADER_IN", "HEADER_OUT",
"DATA_IN", "DATA_OUT", "SSL_DATA_IN", "SSL_DATA_OUT",
"END"
};

int
R_curl_debug_callback (CURL *curl, curl_infotype type, char *msg, size_t len, SEXP fun)
{
SEXP str, e;
SEXP str, e, tmp;
int errorOccurred;

PROTECT(e = allocVector(LANGSXP, 4));
Expand Down Expand Up @@ -1110,7 +1141,8 @@ R_curl_debug_callback (CURL *curl, curl_infotype type, char *msg, size_t len,
#endif
SETCAR(CDR(e), ScalarString(str));

SETCAR(CDR(CDR(e)), ScalarInteger(type));
SETCAR(CDR(CDR(e)), tmp = ScalarInteger(type));
SET_NAMES(tmp, mkString( CurlInfoTypeNames[type] ));

SETCAR(CDR(CDR(CDR(e))), makeCURLPointerRObject(curl, FALSE));

Expand Down

0 comments on commit 26638f8

Please sign in to comment.