├── .Rbuildignore ├── .Rinstignore ├── Changes.html ├── CodeGeneration ├── GNUmakefile ├── auth.c ├── enum.c ├── enum.c.001t.tu ├── enum.c.t00.tu ├── generate.R ├── generateDocs.R ├── makeAuthCode.R └── readHTMLDoc.R ├── DESCRIPTION ├── Experiments ├── binary.R └── binary1.R ├── FAQ.html ├── GNUmakefile ├── LICENSE ├── NAMESPACE ├── R ├── aclassesEnums.R ├── base64.R ├── binary.S ├── bitClasses.R ├── classes.S ├── curl.S ├── curlAuthConstants.R ├── curlEnums.R ├── curlError.R ├── curlInfo.S ├── dynamic.R ├── form.S ├── getFormParams.R ├── getURLContent.R ├── header.R ├── http.R ├── httpError.R ├── httpErrors.R ├── iconv.R ├── info.S ├── mime.R ├── multi.S ├── options.S ├── scp.R ├── support.S ├── upload.R ├── urlExists.R ├── xbits.R └── zclone.R ├── README ├── README.windows ├── Todo.html ├── Web ├── GNUmakefile ├── autom4te.cache │ ├── output.0 │ ├── requests │ └── traces.0 ├── configure ├── configure.in ├── ethereal.png ├── index.html └── index.html.in ├── cacert.pem ├── cleanup ├── configure ├── configure.in ├── configure.win ├── cookies.R ├── data └── mimeTypeExtensions.rda ├── dynGC.R ├── encoding.R ├── exampleCode └── encoding.R ├── hang.R ├── inst ├── CurlSSL │ ├── boost.pem │ ├── ca-bundle.crt │ ├── cacert.pem │ ├── certs │ ├── certs.pem │ ├── curlSSL.xml │ ├── cybertrust.pem │ ├── docs │ ├── google.pem │ ├── myBundle.crt │ ├── ok.R │ ├── server.pem │ └── statEth.pem ├── HTTPErrors │ └── makeErrorClasses.R ├── doc │ ├── GNUmakefile │ ├── RCurl.tex │ ├── cookies.xml │ ├── curlCommandLine.xml │ ├── fileUploads.xml │ ├── philosophy.xml │ └── withCookies.Rdb ├── enums │ ├── GNUmakefile │ └── Renums.c └── examples │ ├── CIS │ ├── cis.R │ └── cis1.R │ ├── GNUmakefile │ ├── chunks.S │ ├── cis1.R │ ├── concurrent.S │ ├── concurrent.xml │ ├── cookies.R │ ├── curl.c │ ├── download.R │ ├── elapsed.png │ ├── encoding.R │ ├── ftpList.R │ ├── getinfo.S │ ├── headers.S │ ├── headers2.S │ ├── html.S │ ├── logo.jpg │ ├── multi.S │ ├── nestedHTML.xml │ ├── omg.netrc │ ├── passwd.S │ ├── passwd2.S │ ├── passwdSSL.S │ ├── post.c │ ├── post.html │ ├── postFormPasswd.R │ ├── progress.S │ ├── proxy.R │ ├── readHeader.S │ ├── soap.S │ ├── speakeasy.S │ ├── system.png │ ├── time.R │ ├── upload.R │ ├── user.png │ ├── worm.S │ └── xmlParse.xml ├── libcurlLicense ├── man ├── AUTH.Rd ├── CFILE.Rd ├── CURLHandle-class.Rd ├── CurlFeatureBits.Rd ├── HTTP_VERSION_1_0.Rd ├── MultiCURLHandle-class.Rd ├── RCurl-internal.Rd ├── base64.Rd ├── basicHeaderGatherer.Rd ├── basicTextGatherer.Rd ├── binaryBuffer.Rd ├── chunkToLineReader.Rd ├── clone.Rd ├── complete.Rd ├── curlError.Rd ├── curlEscape.Rd ├── curlGlobalInit.Rd ├── curlOptions.Rd ├── curlPerform.Rd ├── curlSetOpt.Rd ├── curlVersion.Rd ├── dynCurlReader.Rd ├── enums.Rd ├── fileUpload.Rd ├── findHTTPHeaderEncoding.Rd ├── ftpUpload.Rd ├── getBinaryURL.Rd ├── getBitIndicators.Rd ├── getCurlErrorClassNames.Rd ├── getCurlHandle.Rd ├── getCurlInfo.Rd ├── getFormParams.Rd ├── getURIAsynchronous.Rd ├── getURL.Rd ├── guessMIMEType.Rd ├── httpPUT.Rd ├── isBinaryContent.Rd ├── merge.list.Rd ├── mimeTypeExtensions.Rd ├── postForm.Rd ├── reset.Rd ├── scp.Rd └── url.exists.Rd ├── manyConnections.R ├── postFormEg.R ├── src ├── CURLINFOTable.h ├── CURLOptTable.h ├── CurlErrorEnums.h ├── CurlInfoEnums.h ├── CurlOptEnums.h ├── Makevars ├── Makevars.in ├── Makevars.win ├── Rcurl.h ├── b64IntArray.c ├── base64.c ├── curl.c ├── curl.c-expt ├── curlInit.c ├── curl_base64.c ├── enums.c ├── json.c ├── memoryManagement.c └── myUTF8.c ├── testCFile.R ├── tests ├── amazon3.R ├── binaryPost.R ├── biomart.R ├── downloadToConnection.R ├── dynCurlReader.R ├── dynSetReader.R ├── formUpload.R ├── ftpUpload.R ├── info.R ├── jpeg.R ├── multi.R ├── multi2.R ├── multi3.R ├── multi4.R ├── multiPost.R ├── multi_basic.R ├── post.R └── postFormBinary.R └── utf.c /.Rbuildignore: -------------------------------------------------------------------------------- 1 | #*~ 2 | config.log 3 | config.status 4 | .*Web 5 | GNUmakefile 6 | inst/doc/old.xml 7 | .*RCurl.Rcheck 8 | .*autom4te.cache 9 | \.\.Rcheck.* 10 | Rplots.ps 11 | tests/.*.o 12 | .*\.tar\.gz 13 | Experiments 14 | .*.tcp 15 | .*.cache.* 16 | b64IntArray.c 17 | utf.c 18 | cookies.R 19 | hang.R 20 | postFormEg.R 21 | manyConnections.R 22 | .*\.log 23 | .*\.aux 24 | .*~ 25 | .git* 26 | asynchHeaders.R 27 | ^post.R 28 | ^postForm.html 29 | ^testCFile.R 30 | cleanup-mine 31 | dynGC.R 32 | ^encoding.R 33 | exampleCode 34 | ^cacert.pem 35 | brazilEcon.R 36 | ^blockUpload.R 37 | ^CodeGeneration/.*.tu$ 38 | ^CodeGeneration/.*.o 39 | ^CodeGeneration/.*.so 40 | -------------------------------------------------------------------------------- /.Rinstignore: -------------------------------------------------------------------------------- 1 | RCurl.tex 2 | 3 | -------------------------------------------------------------------------------- /CodeGeneration/GNUmakefile: -------------------------------------------------------------------------------- 1 | ../inst/enums/Renums.c: 2 | 3 | -include local.config 4 | 5 | ifndef CURL_CONFIG 6 | CURL_CONFIG= curl-config 7 | endif 8 | 9 | CFLAGS=$(shell $(CURL_CONFIG) --cflags) 10 | 11 | CC=gcc 12 | 13 | %.tu: %.c 14 | $(CC) -o /dev/null -c -fdump-translation-unit $(CFLAGS) $< 15 | 16 | ../inst/enums/Renums.c: enum.tu 17 | R --no-save < generate.R 18 | 19 | auth.so: auth.c 20 | $(R_HOME)/bin/R CMD SHLIB $^ 21 | 22 | -------------------------------------------------------------------------------- /CodeGeneration/auth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | SEXP R_getAuthValues() 4 | { 5 | SEXP ans = NEW_NUMERIC(10); 6 | int i = 0; 7 | REAL(ans)[i++] = CURLAUTH_ONLY; 8 | REAL(ans)[i++] = CURLAUTH_ANY; 9 | REAL(ans)[i++] = CURLAUTH_NTLM; 10 | REAL(ans)[i++] = CURLAUTH_ANYSAFE; 11 | REAL(ans)[i++] = CURLAUTH_NTLM_WB; 12 | REAL(ans)[i++] = CURLAUTH_DIGEST_IE; 13 | REAL(ans)[i++] = CURLAUTH_BASIC; 14 | REAL(ans)[i++] = CURLAUTH_DIGEST; 15 | REAL(ans)[i++] = CURLAUTH_GSSNEGOTIATE; 16 | REAL(ans)[i++] = CURLAUTH_NONE; 17 | return(ans); 18 | } 19 | -------------------------------------------------------------------------------- /CodeGeneration/enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | CURLoption opt; 4 | CURLformoption fopt; 5 | 6 | -------------------------------------------------------------------------------- /CodeGeneration/generateDocs.R: -------------------------------------------------------------------------------- 1 | curl = htmlParse("http://curl.haxx.se/libcurl/c/curl_easy_setopt.html") 2 | els = getNodeSet(curl, "//p[@class='level0' and ./a[@name]]") 3 | topics = sapply(els, function(x) xmlGetAttr(x[[1]], "name")) 4 | 5 | i = !sapply(topics, is.null) 6 | els = els[i] 7 | names(els) = topics[i] 8 | 9 | ########################## 10 | 11 | 12 | ps = getNodeSet(curl, "//table//h1/following-sibling::p") 13 | 14 | ps = getNodeSet(curl, "//table//h1/following-sibling::p[./a][1]") 15 | first = getNodeSet(curl, "//table//h1/following-sibling::p[@class='level0' and ./a[position() = 1]]") 16 | 17 | 18 | p.level = sapply(ps, xmlGetAttr, "class") 19 | 20 | idx = cumsum(p.level == "level0") 21 | 22 | 23 | ############################################################# 24 | # 25 | # This works, somewhat inlegenantly. 26 | # We find all the nodes that identify a parameter. Then we walk 27 | # the sibling list until we find the next one or a section/grouping 28 | # header. 29 | 30 | first = getNodeSet(curl, "//table//h1/following-sibling::p[@class='level0' and ./span[starts-with(string(.), 'CURLOPT_')]]") 31 | names(first) = tolower(gsub("^CURLOPT_", "", sapply(first, function(x) xmlValue(x[["span"]])))) 32 | 33 | isSectionHeading = 34 | function(node) 35 | { 36 | (names(node) == 'a' && xmlValue(node) == "" ) || (xmlName(node) == "h2" && xmlGetAttr(node, "class") == "nroffsh") 37 | } 38 | 39 | f = 40 | function(node) 41 | { 42 | sib = getSibling(node) 43 | txt = character() 44 | while(!is.null(sib) && xmlGetAttr(sib, "class", "") != "level0" && !isSectionHeading(sib)) { 45 | txt = c(txt, xmlValue(sib)) 46 | sib = getSibling(sib) 47 | } 48 | paste(txt, collapse = "\n") 49 | } 50 | 51 | docs = sapply(first, f) 52 | 53 | docs = gsub("char *", "string", docs, fixed = TRUE) 54 | 55 | docText = gsub("CURLOPT_([A-Z_]+)", "\\\\code{\\L\\1}", docs, perl = TRUE) 56 | 57 | x = sprintf("\\item{%s}{%s}", names(docText), docText) 58 | 59 | cat("\\itemize{", x, "}", "\n", sep = "\n") 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /CodeGeneration/makeAuthCode.R: -------------------------------------------------------------------------------- 1 | library(RGCCTranslationUnit) 2 | curl.h = "/usr/local/include/curl/curl.h" 3 | cpp = getCppDefines(curl.h) 4 | defs = RGCCTranslationUnit:::processDefines(cpp, tu = tu, filter = NULL) 5 | i = grep("CURLAUTH", names(defs$macros)) 6 | auth = defs$macros[i] 7 | cat("#include ", 8 | "#include ", 9 | "SEXP R_getAuthValues()", "{", 10 | sprintf("\tSEXP ans = NEW_NUMERIC(%d);", length(auth)), 11 | "\tint i = 0;", 12 | sprintf("\tREAL(ans)[i++] = %s;", names(auth)), 13 | "\treturn(ans);", 14 | "}", sep = '\n', file = "auth.c") 15 | system("make auth.so") 16 | dyn.load("auth.so") 17 | vals = structure(.Call("R_getAuthValues"), names = names(auth)) 18 | 19 | con = textConnection("foo", 'w', local = TRUE) 20 | dput(vals, con) 21 | def = textConnectionValue(con) 22 | close(con) 23 | 24 | 25 | # Add this to 'setClass("CURLAuth", contains = "BitwiseValue")', 26 | # bitClasses.R. 27 | # We get a warning 28 | # class "CURLAuth" is inheriting an inconsistent superclass structure from class "BitwiseValue", inconsistent with "SymbolicConstant" 29 | # if we define the class CURLAuth after we source() xbits.R 30 | code = 31 | c(# 'setClass("CURLAuth", contains = "BitwiseValue")', 32 | paste('CURLAUTHValues =', paste(def, collapse = " ")), 33 | mapply(function(shortName, name, val) 34 | sprintf("%s <- %s <- BitwiseValue(%s, '%s', 'CURLAuth')", 35 | shortName, name, as.character(val), name), 36 | gsub("^CURL", "", names(vals)), names(vals), vals) 37 | ) 38 | 39 | cat(code, file = "../R/curlAuthConstants.R", sep = "\n") 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CodeGeneration/readHTMLDoc.R: -------------------------------------------------------------------------------- 1 | library(XML) 2 | 3 | opts = xpathSApply(doc, "//p[@class='level0']/a[@name]/following-sibling::span[@class='nroffip']/text()", xmlValue) 4 | opts = tolower(gsub("_", ".", gsub("CURLOPT_", "", opts))) 5 | 6 | library(RCurl) 7 | actual = listCurlOptions() 8 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RCurl 2 | Version: 1.98-1 3 | Title: General network (HTTP/FTP/...) client interface for R 4 | Author: Duncan Temple Lang 5 | SystemRequirements: libcurl (version 7.14.0 or higher) http://curl.haxx.se. 6 | On Linux systems, you will often have to explicitly install libcurl-devel 7 | to have the header files and the libcurl library. 8 | Maintainer: Duncan Temple Lang 9 | Description: The package allows one to compose general HTTP requests 10 | and provides convenient functions to fetch URIs, get & post forms, 11 | etc. and process the results returned by the Web server. 12 | This provides a great deal of control over the HTTP/FTP/... connection and the form 13 | of the request while providing a higher-level interface than is available just 14 | using R socket connections. Additionally, the underlying implementation is robust 15 | and extensive, supporting FTP/FTPS/TFTP (uploads and downloads), 16 | SSL/HTTPS, telnet, dict, ldap, and also supports cookies, redirects, authentication, etc. 17 | License: BSD_3_clause + file LICENSE 18 | Depends: R (>= 2.7.0) 19 | Imports: methods, bitops 20 | Suggests: Rcompression, XML 21 | Additional_repositories: http://www.omegahat.org 22 | URL: http://www.omegahat.org/RCurl 23 | Note: This will be used generally to communicate with HTTP servers and specifically 24 | in the SOAP package, HTML forms and for accessing data on Web sites that require 25 | more state information than simply URL access (e.g. cookies). 26 | Note: To run R CMD check, one really needs network access. It is an HTTP client! 27 | This can be problematic as a Web site may be down when you run 28 | but the real tests are important. 29 | Collate: aclassesEnums.R 30 | bitClasses.R 31 | xbits.R 32 | base64.R 33 | binary.S 34 | classes.S 35 | curl.S 36 | curlAuthConstants.R 37 | curlEnums.R 38 | curlError.R 39 | curlInfo.S 40 | dynamic.R 41 | form.S 42 | getFormParams.R 43 | getURLContent.R 44 | header.R 45 | http.R 46 | httpError.R 47 | httpErrors.R 48 | iconv.R 49 | info.S 50 | mime.R 51 | multi.S 52 | options.S 53 | scp.R 54 | support.S 55 | upload.R 56 | urlExists.R 57 | zclone.R 58 | -------------------------------------------------------------------------------- /Experiments/binary.R: -------------------------------------------------------------------------------- 1 | curl = getCurlHandle() 2 | 3 | txt = character() 4 | 5 | f = function(str) { 6 | txt <<- c(txt, str) 7 | header = parseHTTPHeader(txt) 8 | if("Content-Type" %in% names(header)) { 9 | type = strsplit(header["Content-Type"], "/")[[1]] 10 | 11 | if(type[2] %in% c("x-gzip", "gzip")) { 12 | cat("Chaning reader\n") 13 | sym = getNativeSymbolInfo("R_curl_write_binary_data")$address 14 | curlSetOpt(writefunction = sym, curl = curl) 15 | } 16 | } 17 | nchar(str, "bytes") 18 | } 19 | 20 | u = "http://www.omegahat.org/RCurl/data.gz" 21 | 22 | content = getURL(u, headerfunction = f, curl = curl) 23 | 24 | 25 | -------------------------------------------------------------------------------- /Experiments/binary1.R: -------------------------------------------------------------------------------- 1 | adaptiveContentHandler = 2 | function(curl = getCurlHandle()) 3 | { 4 | txt = character() 5 | 6 | h = function(str) { 7 | txt <<- c(txt, str) 8 | header = parseHTTPHeader(txt) 9 | if("Content-Type" %in% names(header)) { 10 | type = strsplit(header["Content-Type"], "/")[[1]] 11 | 12 | if(type[2] %in% c("x-gzip", "gzip")) { 13 | cat("Chaning reader\n") 14 | sym = getNativeSymbolInfo("R_curl_write_binary_data")$address 15 | curlSetOpt(writefunction = sym, curl = curl, ) 16 | } 17 | } 18 | nchar(str, "bytes") 19 | } 20 | } 21 | 22 | u = "http://www.omegahat.org/RCurl/data.gz" 23 | 24 | content = getURL(u, headerfunction = f, curl = curl) 25 | 26 | 27 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | DOC_DIR=inst/doc/ 2 | DOCS=philosophy.html 3 | # philosophy.pdf 4 | DOC_FILES=$(DOCS:%=$(DOC_DIR)/%) 5 | 6 | ifdef R_HOME 7 | R=$(R_HOME)/bin/R 8 | endif 9 | 10 | VERSION=$(shell perl -e 'while(<>) { if(m/Version: (.*)/) {print $$1,"\n";}}' DESCRIPTION) 11 | 12 | configure: configure.in 13 | autoconf 14 | 15 | build: configure $(DOC_FILES) 16 | (cd .. ; $(R) CMD build RCurl ) 17 | 18 | 19 | ship: build 20 | scp ../RCurl_$(VERSION).tar.gz www.omegahat.org:/home3/WebSites/Omega/RCurl/ 21 | 22 | 23 | version: 24 | @echo "$(VERSION)" 25 | 26 | 27 | 28 | docs: $(DOC_FILES) 29 | 30 | check: configure 31 | R CMD check . 32 | 33 | install: configure 34 | R CMD INSTALL . 35 | 36 | 37 | $(DOC_DIR)/philosophy.html: $(DOC_DIR)/philosophy.xml 38 | 39 | %.html: %.xml 40 | $(MAKE) -C $(@D) $(@F) 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2001-2014 2 | COPYRIGHT HOLDER: Duncan Temple Lang 3 | ORGANIZATION: Bell Labs, Lucent Technologies; University of California 4 | 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | import(methods) 2 | import(bitops) 3 | 4 | export(getURL, getURI, postForm, getForm, getURLContent) 5 | export(.postForm) 6 | export(curlGlobalInit,curlVersion) 7 | export(curlOptions) 8 | export(getCurlInfoConstants, getCurlOptionsConstants, listCurlOptions) 9 | export(curlSetOpt, curlPerform, getCurlInfo) 10 | export(getCurlHandle, dupCurlHandle) 11 | export(CurlFeatureBits, CurlGlobalBits, CurlNetrc) 12 | export(basicTextGatherer, debugGatherer, basicHeaderGatherer) 13 | export(curlEscape, curlUnescape, curlPercentEncode) 14 | export(getBitIndicators, setBitIndicators) 15 | export(parseHTTPHeader) 16 | 17 | export(chunkToLineReader) 18 | 19 | S3method("[<-", CURLOptions) 20 | S3method("[[<-", CURLOptions) 21 | 22 | exportMethods("pop", "push") 23 | export(curlMultiPerform, getCurlMultiHandle, getURLAsynchronous, getURIAsynchronous, 24 | multiTextGatherer) 25 | 26 | export(complete) 27 | 28 | exportClasses(MultiCURLHandle, CURLHandle) 29 | 30 | export(merge.list) 31 | 32 | export(binaryBuffer) 33 | exportMethods("coerce") 34 | 35 | export(base64, base64Encode, base64Decode) 36 | 37 | useDynLib(RCurl, R_curl_BinaryData_new, R_curl_BinaryData_to_raw, R_base64_decode, R_base64_encode) 38 | 39 | export(fileUpload) 40 | 41 | 42 | export(findHTTPHeaderEncoding) 43 | export(getBinaryURL) 44 | 45 | export(reset) 46 | exportMethods('reset') 47 | 48 | export(ftpUpload) 49 | 50 | 51 | export(dynCurlReader) 52 | 53 | export(getCurlOptionTypes) 54 | exportPattern("HTTP_VERSION_.*") 55 | exportPattern("SSLVERSION_.*") 56 | 57 | exportClass("CFILE") 58 | export(CFILE) 59 | exportMethods(close) 60 | 61 | 62 | 63 | export(scp) 64 | 65 | export(guessMIMEType) 66 | 67 | # do we want a httpPOST. 68 | export(httpPUT, httpDELETE, httpGET, httpPOST, httpHEAD) 69 | export(httpOPTIONS) 70 | 71 | export(getFormParams) 72 | 73 | 74 | export(url.exists) 75 | export(curlError) 76 | 77 | export(AUTH_ONLY, AUTH_ANY, AUTH_NTLM, AUTH_ANYSAFE, AUTH_NTLM_WB, AUTH_DIGEST_IE, AUTH_BASIC, AUTH_DIGEST, AUTH_GSSNEGOTIATE, AUTH_NONE) 78 | 79 | #export(CURLAUTH_ONLY, CURLAUTH_ANY, CURLAUTH_NTLM, CURLAUTH_ANYSAFE, CURLAUTH_NTLM_WB, 80 | # CURLAUTH_DIGEST_IE, CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NONE) 81 | 82 | export(clone) 83 | exportMethods(clone) 84 | export(getCurlErrorClassNames) 85 | 86 | 87 | export(isBinaryContent, isBinaryFile, guessMIMEType) 88 | -------------------------------------------------------------------------------- /R/aclassesEnums.R: -------------------------------------------------------------------------------- 1 | ../../RAutoGenRunTime/R/aclassesEnums.R -------------------------------------------------------------------------------- /R/base64.R: -------------------------------------------------------------------------------- 1 | # There is some support for this in caTools but 2 | # that didn't install on some of my machines 3 | # and so we add it here since it is already available 4 | # from libcurl and so is a natural facility in RCurl. 5 | # I don't like duplicating functionality in other packages 6 | # and discourage it. 7 | 8 | 9 | base64 = 10 | function(txt, encode = !inherits(txt, "base64"), mode = "character") 11 | { 12 | asRaw = (as.character(mode) == "raw") 13 | 14 | encode 15 | 16 | if(typeof(txt) != "raw") 17 | txt = as.character(txt) 18 | 19 | if(encode) { 20 | ans = .Call(R_base64_encode, txt, asRaw) 21 | class(ans) <- "base64" 22 | ans 23 | } else 24 | .Call(R_base64_decode, txt, asRaw) 25 | 26 | } 27 | 28 | 29 | base64Encode = 30 | function(txt, mode = "character") 31 | base64(txt, TRUE, mode) 32 | 33 | base64Decode = 34 | function(txt, mode = "character") 35 | base64(txt, FALSE, mode) 36 | 37 | -------------------------------------------------------------------------------- /R/binary.S: -------------------------------------------------------------------------------- 1 | setClass("RCurlBinaryBuffer", representation(ref = "externalptr")) 2 | 3 | binaryBuffer = 4 | function(initialSize = 5000) 5 | { 6 | a = .Call(R_curl_BinaryData_new, as.integer(initialSize)) 7 | new("RCurlBinaryBuffer", ref = a) 8 | } 9 | 10 | 11 | setAs("RCurlBinaryBuffer", "raw", 12 | function(from, to) { 13 | .Call(R_curl_BinaryData_to_raw, from@ref) 14 | }) 15 | 16 | 17 | getBinaryURL = 18 | function(url, ..., .opts = list(), curl = getCurlHandle(), .buf = binaryBuffer(.len), .len = 5000) 19 | { 20 | getURL(url, ..., 21 | write = getNativeSymbolInfo("R_curl_write_binary_data")$address, 22 | file = .buf@ref, curl = curl, .opts = .opts) 23 | 24 | as(.buf, "raw") 25 | } 26 | -------------------------------------------------------------------------------- /R/bitClasses.R: -------------------------------------------------------------------------------- 1 | setClass("CURLAuth", contains = "BitwiseValue") 2 | -------------------------------------------------------------------------------- /R/classes.S: -------------------------------------------------------------------------------- 1 | if(FALSE) 2 | .onAttach = 3 | function(...) 4 | library(methods) 5 | 6 | 7 | 8 | setClass("MultiCURLHandle", 9 | representation(ref = "externalptr", 10 | subhandles = "list")) 11 | 12 | if(TRUE) { 13 | setClass("CURLHandle", representation(ref = "externalptr")) 14 | } else 15 | setOldClass("CURLHandle") 16 | 17 | 18 | 19 | setClass("CFILE", representation(ref = "externalptr")) 20 | -------------------------------------------------------------------------------- /R/curlAuthConstants.R: -------------------------------------------------------------------------------- 1 | # RCurl:::AUTH_BASIC | RCurl:::AUTH_DIGEST | RCurl:::AUTH_NTLM 2 | 3 | CURLAUTHValues = structure(c(-.Machine$integer.max, -17, 8, -18, 32, 16, 1, 2, 4, 0), .Names = c("CURLAUTH_ONLY", 4 | "CURLAUTH_ANY", "CURLAUTH_NTLM", "CURLAUTH_ANYSAFE", "CURLAUTH_NTLM_WB", 5 | "CURLAUTH_DIGEST_IE", "CURLAUTH_BASIC", "CURLAUTH_DIGEST", "CURLAUTH_GSSNEGOTIATE", 6 | "CURLAUTH_NONE")) 7 | 8 | # BitwiseValue( ) 9 | 10 | AUTH_ONLY <- CURLAUTH_ONLY <- BitwiseValue(-.Machine$integer.max, 'CURLAUTH_ONLY', 'CURLAuth') 11 | AUTH_ANY <- CURLAUTH_ANY <- BitwiseValue(-17, 'CURLAUTH_ANY', 'CURLAuth') 12 | AUTH_NTLM <- CURLAUTH_NTLM <- BitwiseValue(8, 'CURLAUTH_NTLM', 'CURLAuth') 13 | AUTH_ANYSAFE <- CURLAUTH_ANYSAFE <- BitwiseValue(-18, 'CURLAUTH_ANYSAFE', 'CURLAuth') 14 | AUTH_NTLM_WB <- CURLAUTH_NTLM_WB <- BitwiseValue(32, 'CURLAUTH_NTLM_WB', 'CURLAuth') 15 | AUTH_DIGEST_IE <- CURLAUTH_DIGEST_IE <- BitwiseValue(16, 'CURLAUTH_DIGEST_IE', 'CURLAuth') 16 | AUTH_BASIC <- CURLAUTH_BASIC <- BitwiseValue(1, 'CURLAUTH_BASIC', 'CURLAuth') 17 | AUTH_DIGEST <- CURLAUTH_DIGEST <- BitwiseValue(2, 'CURLAUTH_DIGEST', 'CURLAuth') 18 | AUTH_GSSNEGOTIATE <- CURLAUTH_GSSNEGOTIATE <- BitwiseValue(4, 'CURLAUTH_GSSNEGOTIATE', 'CURLAuth') 19 | AUTH_NONE <- CURLAUTH_NONE <- BitwiseValue(0, 'CURLAUTH_NONE', 'CURLAuth') 20 | -------------------------------------------------------------------------------- /R/curlError.R: -------------------------------------------------------------------------------- 1 | curlError = 2 | function(type, msg, asError = TRUE) 3 | { 4 | if(!is.character(type)) { 5 | i = match(type, CURLcodeValues) 6 | typeName = if(is.na(i)) 7 | character() 8 | else 9 | names(CURLcodeValues)[i] 10 | } 11 | 12 | typeName = gsub("^CURLE_", "", typeName) 13 | 14 | fun = (if(asError) stop else warning) 15 | 16 | fun( structure(list(message = msg, call = sys.call()), class = c(typeName, "GenericCurlError", if(asError) "error" else "warning", "condition")) ) 17 | } 18 | 19 | 20 | getCurlErrorClassNames = 21 | function() 22 | { 23 | gsub("^CURLE_", "", names(CURLcodeValues)) 24 | } 25 | -------------------------------------------------------------------------------- /R/curlInfo.S: -------------------------------------------------------------------------------- 1 | 2 | curlVersion <- 3 | function(id = 0) 4 | { 5 | x = .Call("R_curl_version_info", as.integer(id), PACKAGE = "RCurl") 6 | 7 | # Now break up the features. 8 | x$features = getBitIndicators(x$features, CurlFeatureBits) 9 | 10 | x 11 | } 12 | 13 | 14 | CurlFeatureBits = as.integer(2^(0:15)) 15 | names(CurlFeatureBits) = c("ipv6", "kerberos4", "ssl", "libz", "ntlm", "gssnegotiate", 16 | "debug", "asynchdns", "spnego", "largefile", "idn", "sspi", 17 | "conv", "curldebug", "tlsauth_srp", "ntlm_wb") 18 | class(CurlFeatureBits) = c("CurlFeatureBits", "BitIndicator") 19 | 20 | 21 | 22 | CurlGlobalBits = as.integer(c(0, 1, 2, 3)) 23 | names(CurlGlobalBits) = c("none", "ssl", "win32", "all") 24 | class(CurlGlobalBits) = c("CurlGlobalBits", "BitIndicator") 25 | 26 | 27 | setBitIndicators = 28 | # 29 | # if the caller gives an integer, sum them 30 | # if the give a vector of strings, resolve them relative to the 31 | # names in defs and then sum those. 32 | # 33 | # 34 | # If we hand this a value that is a composition of flags, 35 | # we don't do the right thing. 36 | # 37 | function(vals, defs) 38 | { 39 | if(is.character(vals)) { 40 | i = match(vals, names(defs)) 41 | if(any(is.na(i))) 42 | stop("Unmatched bit field names ", paste(vals[is.na(i)], collapse=", ")) 43 | 44 | vals = defs[i] 45 | } 46 | 47 | as.integer(sum(vals)) 48 | } 49 | 50 | 51 | 52 | getBitIndicators = 53 | function(val, defs) 54 | { 55 | n = length(defs) 56 | ans = .C("R_check_bits", as.integer(val), as.integer(defs), ans = logical(n), n, PACKAGE = "RCurl")$ans 57 | 58 | defs[ans] 59 | } 60 | -------------------------------------------------------------------------------- /R/getFormParams.R: -------------------------------------------------------------------------------- 1 | # This function is for parsing the parameters in a URL 2 | # for a form. 3 | # It is based on mail and a function from Chris Davis (Delft Uni.) 4 | # 5 | 6 | getFormParams = 7 | # 8 | # getFormParams("http://www.omegahat.org/foo/bob.R?xyz=1&abc=verylong") 9 | # getFormParams("xyz=1&abc=verylong") 10 | # getFormParams("xyz=1&abc=") 11 | # getFormParams("xyz=1&abc=&on=true") 12 | # getFormParams("") 13 | # getFormParams(character()) 14 | # This handles but doesn't detect that there is no = 15 | # getFormParams("abc") 16 | 17 | function(query, isURL = grepl("^(http|\\?)", query)) 18 | { 19 | if(length(query) == 0) 20 | return(NULL) 21 | 22 | # allow for either a full URL with the query parameters 23 | # or alternative, just the query parameters. 24 | if(isURL) # use parseURI from the XML package, but could 25 | # use gsub(). 26 | # parseURI(query)$query 27 | query = gsub(".*\\?", "", query) 28 | 29 | if(nchar(query) == 0) 30 | return(character()) 31 | 32 | els = strsplit(query, "[&=]")[[1]] 33 | i = seq(1, by = 2, length = length(els)/2) 34 | ans = structure(els[i+1L], names = els[i]) 35 | # if the last parameter didn't have a value, we'll get an NA 36 | # Not any of the the internal ones. 37 | if(any(i <- is.na(ans))) 38 | ans[i] = "" 39 | 40 | names(ans) = trim(names(ans)) 41 | ans 42 | } 43 | 44 | trim = 45 | function(x) 46 | gsub("(^[[:space:]]+|[[:space:]]$)", "", x) 47 | 48 | 49 | -------------------------------------------------------------------------------- /R/header.R: -------------------------------------------------------------------------------- 1 | parseHTTPHeader = 2 | # 3 | # Reads the lines from the HTTP response 4 | # header and converts them into a 5 | # name=value collection as a character vector. 6 | # 7 | # returns a named list of the fields. Allows duplicates. 8 | function(lines, multi = TRUE) 9 | { 10 | if(length(lines) < 1) 11 | return(NULL) 12 | 13 | if(length(lines) == 1) 14 | lines = strsplit(lines, "\r\n")[[1]] 15 | 16 | if(multi) { 17 | i = grep("^HTTP", lines) 18 | status = lines[max(i)] 19 | lines = lines[seq(max(i), length(lines))] 20 | } else 21 | status = lines[1] 22 | 23 | # Get the status and if it is 100, then throw away the first 2 lines 24 | # e.g. HTTP/1.1 100 Continue 25 | # \r\n 26 | st = getStatus(status) 27 | if(st[["status"]] == 100) { 28 | 29 | # Have to worry about whether we just get a 100 and nothing else 30 | # and so lines[3] won't exist. 31 | if((length(lines) - length(grep("^[[:space:]]*$", lines))) == 1) 32 | return(unlist(st)) 33 | # We seem to jump to the 3 rd line as the real status 34 | # and discard the first two lines. Is this the Expect. 35 | # status = lines[3] 36 | # lines = lines[-(1:2)] 37 | } 38 | 39 | lines = lines[-1] 40 | lines = gsub("\r\n$", "", lines) # was \r\n\0$ 41 | lines = lines[ lines != "" ] 42 | 43 | if(FALSE) { # Doesn't behave. Duplicates! 44 | header = lines[-1] 45 | header <- read.dcf(textConnection(header)) 46 | } else { 47 | # els <- sapply(lines, function(x) strsplit(x, ": *")) 48 | # header <- sapply(els, function(x) paste(x[2]) #XX what if more than 2 els. 49 | # names(header) <- sapply(els, function(x) x[1]) 50 | header = structure(sub("[^:]+: (.*)", "\\1", lines), 51 | names = sub("([^:]+):.*", "\\1", lines)) 52 | } 53 | 54 | # st = getStatus(status) 55 | header[["status"]] = st[["status"]] 56 | header[["statusMessage"]] = st[["message"]] 57 | 58 | header 59 | } 60 | 61 | 62 | getStatus = 63 | # 64 | # Reads the first line of the HTTP header, e.g of the form 65 | # HTTP/1.1 200 OK 66 | # or 67 | # HTTP/1.1 404 Not Found 68 | # and returns 69 | # list(status = 404, message = "Not Found") 70 | function(status) 71 | { 72 | els <- strsplit(status, " ")[[1]] 73 | list(status = as.integer(els[2]), message = paste(els[-c(1,2)], collapse = " ")) 74 | } 75 | 76 | 77 | 78 | 79 | getEncoding = 80 | function(x) { 81 | val = gsub("Content-Type:.*;\\W*charset=", "", x) 82 | if(all(nchar(val) == nchar(x))) # See if there was any substitution done, i.e. a match. 83 | return(NA) 84 | 85 | 86 | switch(val, "UTF-8" =, "utf-8" = 1L, "ISO-8859-1" = 2L, -1L) 87 | } 88 | 89 | findHTTPHeaderEncoding = 90 | function(str) 91 | { 92 | els = strsplit(str, "\\\r\\\n") 93 | v = lapply(els, getEncoding) 94 | 95 | if(any(!is.na(v))) { 96 | v[[!is.na(v)]][[1]] 97 | } else 98 | -1L 99 | } 100 | -------------------------------------------------------------------------------- /R/http.R: -------------------------------------------------------------------------------- 1 | httpGET = 2 | function(url, ..., curl = getCurlHandle()) 3 | { 4 | getURLContent(url, ..., curl = curl) 5 | } 6 | 7 | httpPOST = 8 | function(url, ..., curl = getCurlHandle()) 9 | { 10 | getURLContent(url, .opts = list(customrequest = "POST", ...), curl = curl, post = 1L) 11 | } 12 | 13 | PUT = httpPUT = 14 | function(url, content = NULL, ..., curl = getCurlHandle()) 15 | { 16 | if(!missing(content)) { 17 | val = if(is.character(content)) 18 | charToRaw(paste(content, collapse = "\n")) 19 | else if(is.raw(content)) 20 | content 21 | else 22 | stop("not certain how to convert content to the target type for a PUT request") 23 | 24 | getURLContent(url, infilesize = length(val), 25 | readfunction = val, 26 | upload = TRUE, 27 | ..., curl = curl, customrequest = "PUT") 28 | } else 29 | getURLContent(url, ..., curl = curl, customrequest = "PUT") 30 | } 31 | 32 | DELETE = httpDELETE = 33 | function(url, ..., curl = getCurlHandle()) 34 | { 35 | getURLContent(url, customrequest = "DELETE", ..., curl = curl) 36 | } 37 | 38 | HEAD = httpHEAD = 39 | function(url, ..., curl = getCurlHandle()) 40 | { 41 | getURLContent(url, customrequest = "HEAD", nobody = TRUE, ..., curl = curl) 42 | } 43 | 44 | httpOPTIONS = 45 | function(url, ..., curl = getCurlHandle()) 46 | { 47 | ans = getURLContent(url, customrequest = "OPTIONS", ..., curl = curl, header = TRUE) 48 | ans$header 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /R/httpError.R: -------------------------------------------------------------------------------- 1 | getHTTPErrorClass = 2 | function(status) 3 | { 4 | 5 | if("status" %in% names(status)) 6 | status = status[["status"]] 7 | 8 | 9 | i = match(as.character(status), names(httpErrorClasses)) 10 | 11 | if(is.na(i)) 12 | "GenericHTTPError" 13 | else 14 | c(httpErrorClasses[i], "HTTPError") 15 | } 16 | -------------------------------------------------------------------------------- /R/httpErrors.R: -------------------------------------------------------------------------------- 1 | # Generated from inst/HTTPErrors/makeErrorClasses.R 2 | httpErrorClasses = c( '100' = 'Continue', 3 | '101' = 'Switching_Protocols', 4 | '200' = 'OK', 5 | '201' = 'Created', 6 | '202' = 'Accepted', 7 | '203' = 'Non-Authoritative_Information', 8 | '204' = 'No_Content', 9 | '205' = 'Reset_Content', 10 | '206' = 'Partial_Content', 11 | '300' = 'Multiple_Choices', 12 | '301' = 'Moved_Permanently', 13 | '302' = 'Found', 14 | '303' = 'See_Other', 15 | '304' = 'Not_Modified', 16 | '305' = 'Use_Proxy', 17 | '306' = '(Unused)', 18 | '307' = 'Temporary_Redirect', 19 | '400' = 'Bad_Request', 20 | '401' = 'Unauthorized', 21 | '402' = 'Payment_Required', 22 | '403' = 'Forbidden', 23 | '404' = 'Not_Found', 24 | '405' = 'Method_Not_Allowed', 25 | '406' = 'Not_Acceptable', 26 | '407' = 'Proxy_Authentication_Required', 27 | '408' = 'Request_Timeout', 28 | '409' = 'Conflict', 29 | '410' = 'Gone', 30 | '411' = 'Length_Required', 31 | '412' = 'Precondition_Failed', 32 | '413' = 'Request_Entity_Too_Large', 33 | '414' = 'Request-URI_Too_Long', 34 | '415' = 'Unsupported_Media_Type', 35 | '416' = 'Requested_Range_Not_Satisfiable', 36 | '417' = 'Expectation_Failed', 37 | '500' = 'Internal_Server_Error', 38 | '501' = 'Not_Implemented', 39 | '502' = 'Bad_Gateway', 40 | '503' = 'Service_Unavailable', 41 | '504' = 'Gateway_Timeout', 42 | '505' = 'HTTP_Version_Not_Supported' 43 | ) -------------------------------------------------------------------------------- /R/iconv.R: -------------------------------------------------------------------------------- 1 | 2 | RCurlIconv = 3 | function(str, from = "C99", to = "UTF-8", check = TRUE, quiet = FALSE) 4 | { 5 | to = toupper(to) 6 | from = toupper(from) 7 | 8 | if(check) { 9 | w = c(from, to) %in% iconvlist() 10 | if(!all(w)) { 11 | if(!quiet) 12 | warning(paste(c(from, to)[w], collapse = ", "), " not supported iconv entries") 13 | return(str) 14 | } 15 | } 16 | ans = iconv(str, from, to) 17 | if(is.na(ans)) 18 | str 19 | else 20 | ans 21 | } 22 | -------------------------------------------------------------------------------- /R/info.S: -------------------------------------------------------------------------------- 1 | getCurlInfo = 2 | function(curl, which = getCurlInfoConstants()) 3 | { 4 | rnames = character() 5 | 6 | if(is.character(which)) { 7 | const = getCurlInfoConstants() 8 | i = pmatch(tolower(which), names(const)) 9 | if(any(is.na(i))) 10 | stop("Invalid curl info name", names(which)[is.na(i)]) 11 | 12 | which = getCurlInfoConstants()[i] 13 | } 14 | 15 | x = .Call("R_curl_easy_getinfo", curl, as.integer(which), PACKAGE = "RCurl") 16 | 17 | # put the names back on. 18 | names(x) = names(which) 19 | 20 | x 21 | } 22 | 23 | 24 | getCurlInfoConstants = 25 | function() 26 | { 27 | x = .Call("R_getCURLInfoEnum", PACKAGE = "RCurl") 28 | names(x) = tolower(gsub("_", ".", names(x))) 29 | 30 | x 31 | } 32 | 33 | -------------------------------------------------------------------------------- /R/mime.R: -------------------------------------------------------------------------------- 1 | getExtension = 2 | # 3 | # getExtension("foo.R") 4 | # getExtension("foo.tar.gz") 5 | # 6 | function(name, multiple = FALSE) 7 | { 8 | gsub(".*\\.([a-zA-Z0-9]+)$", "\\1", name) 9 | } 10 | 11 | 12 | otherMIMETypes = c("r" = "text/R-code", # perhaps x-application/r-code 13 | "svg" = "image/svg+xml", 14 | "json" = "application/json") 15 | 16 | guessMIMEType = 17 | # 18 | # Determine the MIME type 19 | # 20 | 21 | # guessMIMEType("foo.txt") 22 | # guessMIMEType("foo.png") 23 | # guessMIMEType("foo.jpeg") 24 | # guessMIMEType("foo.Z") 25 | # guessMIMEType(c("foo.txt", "foo.png", "foo.jpeg", "foo.Z")) 26 | # 27 | # No svg in standard database we constructued, so add in via otherMIMETypes. 28 | # 29 | function(name, default = NA) 30 | { 31 | data("mimeTypeExtensions", package = "RCurl", envir = environment()) 32 | ext = getExtension(name) 33 | ans = mimeTypeExtensions[tolower(ext)] 34 | if(any(i <- is.na(ans)) ) 35 | ans[i] = otherMIMETypes[tolower(ext[i])] 36 | 37 | if(any(i <- is.na(ans))) 38 | ans[i] = default 39 | 40 | structure(ans, names = name) 41 | } 42 | -------------------------------------------------------------------------------- /R/scp.R: -------------------------------------------------------------------------------- 1 | getUserName = 2 | function() 3 | { 4 | Sys.getenv(if(.Platform$OS.type == "windows") "USERNAME" else "USER") 5 | } 6 | 7 | scp = 8 | function(host, path, keypasswd = NA, user = getUserName(), rsa = TRUE, 9 | key = sprintf(c("~/.ssh/id_%s.pub", "~/.ssh/id_%s"), if(rsa) "rsa" else "dsa"), 10 | binary = NA, size = 5000, curl = getCurlHandle(), ...) 11 | { 12 | if(!is.na(user) && length(grep("@", host)) == 0) 13 | host = paste(user, "@", host, sep = "") 14 | 15 | if(length(grep("^scp", host)) == 0) 16 | host = paste("scp://", host, sep = "") 17 | 18 | if(!missing(path)) 19 | host = paste(host, path, sep = "/") 20 | 21 | key = path.expand(key) 22 | opts = list(ssh.public.keyfile = key[1], ssh.private.keyfile = key[2], ...) 23 | if(!is.na(keypasswd)) 24 | opts$keypasswd = keypasswd 25 | 26 | # We don't use getURLContent() as it wants to process the HTTP header 27 | # which isn't part of this. We could provide our own version of the header 28 | # argument but this is essentially what we are doing by specifying writefunction. 29 | # getURLContent(host, .opts = opts) 30 | opts$url = host 31 | 32 | if(is.na(binary) || binary) { 33 | binary = TRUE 34 | opts$writefunction = getNativeSymbolInfo("R_curl_write_binary_data")$address 35 | buf <- binaryBuffer(size) 36 | opts$file = buf@ref 37 | } else { 38 | h = basicTextGatherer() 39 | opts$writefunction = h$update 40 | } 41 | curlPerform(.opts = opts, curl = curl) 42 | 43 | if(binary) 44 | as(buf, "raw") 45 | else 46 | h$value() 47 | } 48 | -------------------------------------------------------------------------------- /R/support.S: -------------------------------------------------------------------------------- 1 | collectChunks = 2 | # Not exported but can be used via RCurl:::collectChunks() 3 | function(max = 10) 4 | { 5 | chunks = character() 6 | ctr = 0 7 | 8 | list(chunks = function() chunks, 9 | read = function(txt) { 10 | 11 | ctr <<- ctr + 1 12 | 13 | chunks[ctr] <<- txt 14 | 15 | if(ctr >= max) 16 | stop("Got enough") 17 | }) 18 | } 19 | 20 | chunkToLineReader = 21 | function(f, verbose = FALSE) 22 | { 23 | leftOvers = "" 24 | 25 | read = function(txt) { 26 | 27 | if(nzchar(leftOvers)) { 28 | txt = paste(leftOvers, txt, sep = "") 29 | leftOvers <<- "" 30 | } 31 | 32 | # Now find the bit at the end if there is any that is not a complete line. 33 | leftOvers <<- gsub('^.*\n', '', txt) 34 | 35 | if(verbose && nchar(leftOvers)) 36 | cat("Left over:", leftOvers, "\n") 37 | 38 | Lines = strsplit(txt, "\n")[[1]] 39 | if(nchar(leftOvers)) 40 | Lines = Lines[-length(Lines)] 41 | 42 | 43 | if(length(Lines)) 44 | f(Lines) 45 | 46 | nchar(txt) 47 | } 48 | 49 | list(read = read, pending = function() leftOvers) 50 | } 51 | -------------------------------------------------------------------------------- /R/upload.R: -------------------------------------------------------------------------------- 1 | ftpUpload = 2 | # 3 | # what is the name of the file or the contents of the file 4 | # 5 | function(what, to, asText = inherits(what, "AsIs") || is.raw(what), 6 | ..., curl = getCurlHandle()) 7 | { 8 | if(!asText && !inherits(what, "connection")) { 9 | file = file(what, "rb") 10 | on.exit(close(file)) 11 | } else 12 | file = what 13 | 14 | curlPerform(url = to, upload = TRUE, 15 | readfunction = uploadFunctionHandler(file, asText), ..., curl = curl) 16 | } 17 | 18 | uploadFunctionHandler = 19 | # 20 | # returns the function that is called as the READFUNCTION callback. 21 | # 22 | # This handles raw, character and file contents. 23 | # 24 | function(file, asText = inherits(file, "AsIs") || is.raw(file)) 25 | { 26 | 27 | if(asText) { 28 | pos = 1 29 | isRaw = is.raw(file) 30 | len = if(isRaw) length(file) else nchar(file) 31 | 32 | function(size) { 33 | 34 | if(pos > len) 35 | return(if(isRaw) raw(0) else character(0)) 36 | 37 | ans = if(isRaw) 38 | file[seq(pos, length = size)] 39 | else 40 | substring(file, pos, pos + size) 41 | pos <<- pos + len 42 | ans 43 | } 44 | 45 | } else 46 | 47 | function(size) { 48 | readBin(file, raw(), size) 49 | } 50 | } 51 | 52 | 53 | CFILE = 54 | function(filename, mode = "r") 55 | { 56 | filename = path.expand(filename) 57 | .Call("R_openFile", filename, as.character(mode)) 58 | } 59 | 60 | 61 | setMethod("close", "CFILE", 62 | function(con, ...) { 63 | .Call("R_closeCFILE", con@ref, PACKAGE = "RCurl") 64 | con 65 | }) 66 | 67 | -------------------------------------------------------------------------------- /R/urlExists.R: -------------------------------------------------------------------------------- 1 | url.exists = 2 | function(url, ..., .opts = list(...), curl = getCurlHandle(.opts = .opts), 3 | .header = FALSE) 4 | { 5 | if(length(url) > 1) { 6 | # Really want to do this with a multi curl so asynchronous. 7 | ap = if(.header) lapply else sapply 8 | return(ap(url, url.exists, curl = curl, .header = .header)) 9 | } 10 | 11 | g = basicTextGatherer() 12 | failed = FALSE 13 | ans = tryCatch(curlPerform(url = url, followlocation = TRUE, headerfunction = g$update, 14 | nobody = TRUE, writefunction = g$update, curl = curl), 15 | COULDNT_RESOLVE_HOST = function(x) failed <<- TRUE, 16 | error = function(x) failed <<- TRUE) 17 | 18 | if(failed) 19 | return(FALSE) 20 | 21 | if(grepl("^s?ftp", url)) { 22 | return(TRUE) 23 | } else 24 | header = parseHTTPHeader(g$value()) 25 | 26 | if(.header) 27 | header 28 | else 29 | as.integer(as.integer(header["status"])/100) == 2 30 | } 31 | -------------------------------------------------------------------------------- /R/xbits.R: -------------------------------------------------------------------------------- 1 | ../../RAutoGenRunTime/R/xbits.R -------------------------------------------------------------------------------- /R/zclone.R: -------------------------------------------------------------------------------- 1 | setGeneric("clone", function(x, ...) standardGeneric("clone")) 2 | setMethod("clone", "ANY", function(x, ...) x) 3 | 4 | setMethod("clone", "CURLHandle", function(x, ...) dupCurlHandle(x, ...)) 5 | setMethod("clone", "environment", 6 | function(x, ...) { 7 | e = new.env(parent = parent.env(x)) 8 | sapply(ls(x, all.names = TRUE), 9 | function(id) 10 | assign(id, get(id, x), e)) 11 | e 12 | }) 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This package is a (currently) simple interface to the 2 | libcurl functionality. This is an extensive and well 3 | tested library that takes care of so many details that 4 | we would have to mimic (probably incompletely and poorly) 5 | if we were to write this in the R language directly. 6 | 7 | You will need to have libcurl installed on your machine. 8 | You can obtain the source and binaries for numerous operating 9 | systems from 10 | http://curl.haxx.se 11 | 12 | -------------------------------------------------------------------------------- /README.windows: -------------------------------------------------------------------------------- 1 | Notes from previous experiences. 2 | These are not current. 3 | 4 | Updated, 19th Sept. 2006 5 | 6 | Fetch the binary version of libcurl from 7 | http://curl.haxx.se/download.html#Win32 8 | 9 | (There is no development version there, i.e. -devel) 10 | 11 | Using MinGW, version 3.4.2, we can link directly 12 | Unzip this into a directory and then 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Download the curl development distribution for mingw32 with ssl. 21 | That is 22 | curl-7.12.0-win32-ssl-devel-mingw32.zip 23 | via 24 | http://curl.haxx.se/download.html#Win32 25 | 26 | If SSL is not needed, obviously retrieve the version 27 | without SSL. 28 | 29 | To make the Curl header and library files available 30 | for the build, it is easiest (?) to copy the 31 | relevant files from the curl distribution into 32 | a centralized location that is shared across 33 | the different development tools that are used 34 | when compiling R packages. This directory 35 | behaves like /usr/local/ in Unix and has 36 | a include/, lib/ and bin/ directory. 37 | We put the header files in the include/, 38 | the libraries in lib/ and the DLLs for run-time 39 | in bin/ as necessary. 40 | 41 | For curl, we copy the contents of the include/ directory in the curl 42 | distribution to $HOME/include to create a directory 43 | $HOME/include/curl/ with the header files. Similarly, we copy the *.a 44 | files to the $HOME/lib/ directory. These .a files are in the top-level 45 | directory of the curl distribution. 46 | 47 | 48 | 49 | SSL 50 | --- 51 | 52 | curl does not come with the SSL libraries it needs (for good 53 | reasons). Instead, you need to fetch them. For me, I downloaded and 54 | built from the source distribution. I am using openssl-0.9.7e. The 55 | files are available at 56 | 57 | www.openssl.org 58 | 59 | Unzip and build the openssl libraries by running the command 60 | 61 | ./Configure mingw 62 | make 63 | 64 | I configured the build with 65 | ./Configure mingw no-asm 66 | to remove the assembler compilation which caused problems with 67 | the MinGW version I was using (as 2.15.91). 68 | 69 | Then, manually copy libssl.a and libcrypto.a to 70 | the $HOME/lib/ directory where we tell the compilation 71 | to find these libraries. See RCurl/src/Makevars.win 72 | and the LOCAL variable. 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Web/GNUmakefile: -------------------------------------------------------------------------------- 1 | PKG_NAME=$(shell grep Package ../DESCRIPTION | sed -e 's/.*: //') 2 | 3 | #index.html: index.html.in configure ../DESCRIPTION 4 | # ./configure 5 | 6 | #configure: configure.in 7 | # autoconf 8 | 9 | include $(OMEGA_HOME)/R/Config/GNUmakefile.Web 10 | #include $(OMEGA_HOME)/R/Config/RPackageWebConfig 11 | 12 | 13 | #WEB_DIR=www.omegahat.org:/home3/WebSites/Omega/RCurl 14 | 15 | #shipIndex: aux 16 | # $(MAKE) -C ../inst/doc ship 17 | 18 | #aux: index.html 19 | # scp index.html $(WEB_DIR)/index.html 20 | # scp ../Changes.html ../FAQ.html $(WEB_DIR) 21 | 22 | #indexInstall indexOnly: index.html 23 | # scp index.html $(WEB_DIR)/index.html 24 | 25 | 26 | #include $(OMEGA_HOME)/R/Config/RPackageWebRules -------------------------------------------------------------------------------- /Web/autom4te.cache/requests: -------------------------------------------------------------------------------- 1 | # This file was generated. 2 | # It contains the lists of macros which have been traced. 3 | # It can be safely removed. 4 | 5 | @request = ( 6 | bless( [ 7 | '0', 8 | 1, 9 | [ 10 | '/usr/share/autoconf' 11 | ], 12 | [ 13 | '/usr/share/autoconf/autoconf/autoconf.m4f', 14 | 'configure.in' 15 | ], 16 | { 17 | '_LT_AC_TAGCONFIG' => 1, 18 | 'AM_PROG_F77_C_O' => 1, 19 | 'AC_INIT' => 1, 20 | 'm4_pattern_forbid' => 1, 21 | 'AC_CANONICAL_TARGET' => 1, 22 | 'AC_SUBST' => 1, 23 | 'AC_CONFIG_LIBOBJ_DIR' => 1, 24 | 'AC_FC_SRCEXT' => 1, 25 | 'AC_CANONICAL_HOST' => 1, 26 | 'AC_PROG_LIBTOOL' => 1, 27 | 'AM_INIT_AUTOMAKE' => 1, 28 | 'AC_CONFIG_SUBDIRS' => 1, 29 | 'AM_AUTOMAKE_VERSION' => 1, 30 | 'LT_CONFIG_LTDL_DIR' => 1, 31 | 'AC_REQUIRE_AUX_FILE' => 1, 32 | 'AC_CONFIG_LINKS' => 1, 33 | 'm4_sinclude' => 1, 34 | 'LT_SUPPORTED_TAG' => 1, 35 | 'AM_MAINTAINER_MODE' => 1, 36 | 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, 37 | '_m4_warn' => 1, 38 | 'AM_PROG_CXX_C_O' => 1, 39 | 'AM_ENABLE_MULTILIB' => 1, 40 | 'AC_CONFIG_FILES' => 1, 41 | 'include' => 1, 42 | 'LT_INIT' => 1, 43 | 'AM_GNU_GETTEXT' => 1, 44 | 'AC_LIBSOURCE' => 1, 45 | 'AM_PROG_FC_C_O' => 1, 46 | 'AC_CANONICAL_BUILD' => 1, 47 | 'AC_FC_FREEFORM' => 1, 48 | 'AH_OUTPUT' => 1, 49 | '_AM_SUBST_NOTMAKE' => 1, 50 | 'AC_CONFIG_AUX_DIR' => 1, 51 | 'sinclude' => 1, 52 | 'm4_pattern_allow' => 1, 53 | 'AM_PROG_CC_C_O' => 1, 54 | 'AC_CANONICAL_SYSTEM' => 1, 55 | 'AM_CONDITIONAL' => 1, 56 | 'AC_CONFIG_HEADERS' => 1, 57 | 'AC_DEFINE_TRACE_LITERAL' => 1, 58 | 'm4_include' => 1, 59 | 'AC_SUBST_TRACE' => 1 60 | } 61 | ], 'Autom4te::Request' ) 62 | ); 63 | 64 | -------------------------------------------------------------------------------- /Web/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT(index.html.in) 2 | 3 | DESC=../DESCRIPTION 4 | 5 | PKG_NAME=`cat $DESC | grep Package | sed -e 's/.*: //'` 6 | VERSION=`cat $DESC | grep Version | sed -e 's/.*: //'` 7 | 8 | DATE=`date +"%d %B %Y"` 9 | 10 | TAR_FILE="${PKG_NAME}_${VERSION}.tar.gz" 11 | 12 | AC_SUBST(PKG_NAME) 13 | AC_SUBST(VERSION) 14 | AC_SUBST(TAR_FILE) 15 | AC_SUBST(DATE) 16 | 17 | 18 | AC_OUTPUT(index.html) 19 | -------------------------------------------------------------------------------- /Web/ethereal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/Web/ethereal.png -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | (cd src; rm *.o ; rm Makevars) 3 | -------------------------------------------------------------------------------- /configure.win: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if test -z "${LIB_CURL}" ; then 4 | echo "Please set LIB_CURL" 5 | fi 6 | 7 | 8 | mkdir -p ${R_PACKAGE_DIR}/libs${R_ARCH} 9 | if test "${R_ARCH}" = "/x64"; then 10 | cp $LIB_CURL/ssl/bin/*.dll $LIB_CURL/bin/libcurl-4.dll \ 11 | $LIB_CURL/bin/libz.dll ${R_PACKAGE_DIR}/libs${R_ARCH} 12 | else 13 | # libeay32.a is an import library 14 | cp $LIB_CURL/bin/libeay32.dll $R_PACKAGE_DIR/libs${R_ARCH} 15 | fi 16 | 17 | # mkdir $R_PACKAGE_DIR/libs 18 | # cp $LIB_CURL/bin/*.dll $R_PACKAGE_DIR/libs 19 | -------------------------------------------------------------------------------- /cookies.R: -------------------------------------------------------------------------------- 1 | # Seems to be that we are losing the finalizer. 2 | # If we set writefunction to R_internalWriteTest, and set no 3 | # parameters. Things are okay 4 | # 5 | # The problem is in the dynCurlReader(). 6 | # Even if we change the update() function in dynCurlReader 7 | # to just return, we still have this problem. 8 | # 9 | library(RCurl) 10 | site <- "http://chr.tx0.org/arch/ml/r/cookie-20101114.cgi" 11 | cookie_1= "cookie1" 12 | 13 | # Should work! 14 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 15 | a = postForm(site, par = "cookie1", curl = h, style = "POST") 16 | rm(h); gc(); gc() 17 | 18 | 19 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 20 | a = getURLContent(site, curl = h) 21 | rm(h) ; gc() 22 | 23 | # not okay. But it is if we just return from the update. 24 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 25 | w = dynCurlReader(h) 26 | a = getURLContent(site, curl = h, header = w) # writefunction = w$update) 27 | rm(h, w) ; gc() 28 | 29 | # but if we let getURLContent() use the default value for header we don't get the freeing 30 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 31 | a = getURLContent(site, curl = h) 32 | rm(h) ; gc() 33 | 34 | 35 | # Fine 36 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 37 | w = dynCurlReader(h) 38 | a = getURL(site, curl = h, write = w$update) 39 | rm(h, w) ; gc() 40 | 41 | 42 | # This works, but the getURLContent() doesn't. 43 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 44 | a = getURL(site, curl = h) 45 | rm(h) ; gc() 46 | 47 | h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "") 48 | a = postForm(site, par = "cookie1", curl = h, style = "POST") 49 | rm(h); gc(); gc() 50 | 51 | # HTTPPOST style 52 | h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "") 53 | a = postForm(site, par = "cookie1", curl = h) 54 | rm(h); gc(); gc() 55 | 56 | h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "") 57 | curlPerform(url = site, postfields = "", curl = curl) 58 | 59 | # Change the write function to a C routine and send no parameters 60 | h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "") 61 | a = postForm(site, curl = h, style = "POST", .opts = list(writefunction = getNativeSymbolInfo("R_internalWriteTest")$address)) 62 | rm(h); gc(); gc() 63 | 64 | # Adding the parameter still works. So it is the writefunction. 65 | h = getCurlHandle(cookiejar = "/tmp/mycookies", cookiefile = "") 66 | a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = getNativeSymbolInfo("R_internalWriteTest")$address)) 67 | rm(h); gc(); gc() 68 | 69 | # So let's try a regular write function. And that still works. So it is our default writefunction for postForm 70 | w = basicTextGatherer() 71 | h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "") 72 | a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update)) 73 | rm(h); gc(); gc() 74 | 75 | 76 | h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "") 77 | w = dynCurlReader(h, verbose = TRUE) 78 | a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update)) 79 | rm(h); gc(); gc() 80 | 81 | 82 | files = sprintf("/tmp/k%d", 1:100) 83 | sapply(files, 84 | function(f) { 85 | h = getCurlHandle(cookiejar = f, cookiefile = "") 86 | w = dynCurlReader(h, verbose = TRUE) 87 | a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update)) 88 | rm(h); gc() 89 | }) 90 | 91 | 92 | h = getCurlHandle(cookiejar = "-", cookiefile = "") 93 | w = dynCurlReader(h, verbose = TRUE) 94 | a = postForm(site, curl = h, par = "cookie1", style = "POST", .opts = list(writefunction = w$update)) 95 | rm(h); invisible(gc()) 96 | 97 | 98 | 99 | 100 | 101 | h = getCurlHandle(cookiejar = "/tmp/mycookies1", cookiefile = "") 102 | a = getURL(site, curl = h) 103 | rm(h) 104 | gc(); gc() 105 | 106 | -------------------------------------------------------------------------------- /data/mimeTypeExtensions.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/data/mimeTypeExtensions.rda -------------------------------------------------------------------------------- /dynGC.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | u = "http://localhost/~duncan" 3 | 4 | curl = getCurlHandle() 5 | r = dynCurlReader(curl) 6 | 7 | x = getURLContent(u, header = r, curl = curl) 8 | r$value() 9 | rm(r, curl) 10 | gc() 11 | 12 | 13 | x = getURLContent(u, followlocation = TRUE) 14 | 15 | curl = getCurlHandle() 16 | x = getURLContent(u, followlocation = TRUE, curl = curl) 17 | 18 | 19 | -------------------------------------------------------------------------------- /encoding.R: -------------------------------------------------------------------------------- 1 | library(XML) 2 | xmlParse("", asText = TRUE) 3 | 4 | myParse = 5 | function(x) 6 | parse(text = x) 7 | 8 | foo = 9 | function(x) { 10 | browser() 11 | iconv(x, "", "UTF8") 12 | } 13 | 14 | foo = 15 | function(x) { 16 | tt = readLines(file(x, encoding = "UTF8")) 17 | browser() 18 | tt 19 | } 20 | 21 | 22 | library(RCurl) 23 | url <- "http://search.twitter.com/search.json?q=%E5%95%A4%E9%85%92&result_type=recent&rpp=1&page=1" 24 | doc <- getURLContent(URLencode(url), .encoding = "UTF-8") 25 | Encoding(doc) 26 | 27 | library(RJSONIO) 28 | j <- fromJSON(doc) 29 | tweet <- j$results[[1]]$text 30 | -------------------------------------------------------------------------------- /exampleCode/encoding.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | sURL <- "http://www.nseindia.com/marketinfo/ipo/ipo_pastissues.jsp?year=ALL#" 3 | tt = getURLContent(sURL, binary = TRUE, useragent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6;en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12") 4 | txt = paste(rawToChar(tt, TRUE), collapse = "") 5 | doc = htmlParse(txt, asText = TRUE) 6 | 7 | length(getNodeSet(doc, "//a")) 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /hang.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | u = "http://photos.prnewswire.com/prnh/20110713/NY34814-b" 3 | system.time(getURL(u, followLocation = TRUE, .opts = list(timeout = 1, maxredirs = 4L))) 4 | 5 | # Gets into recursion constantly trying to download the same URL 6 | # because the server keeps giving us the same URL to follow. 7 | #GET /medias/switch.do?prefix=/appnb&page=/getStoryRemapDetails.do&prnid=20110713%252fNY34814%252db&action=details HTTP/1.1 8 | #GET /medias/switch.do?prefix=/appnb&page=/getStoryRemapDetails.do&prnid=20110713%252fNY34814%252db&action=details HTTP/1.1 9 | 10 | getURL(u, followLocation = TRUE) 11 | print("next line") # programme does not get this far 12 | -------------------------------------------------------------------------------- /inst/CurlSSL/boost.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEcTCCA9qgAwIBAgIBHjANBgkqhkiG9w0BAQQFADCB2jELMAkGA1UEBhMCVVMx 3 | EDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRswGQYDVQQK 4 | ExJJbmRpYW5hIFVuaXZlcnNpdHkxJDAiBgNVBAsTG0NvbXB1dGVyIFNjaWVuY2Ug 5 | RGVwYXJ0bWVudDE6MDgGA1UEAxMxQ29tcHV0ZXIgU2NpZW5jZSBEZXBhcnRtZW50 6 | IENlcnRpZmljYXRlIEF1dGhvcml0eTEkMCIGCSqGSIb3DQEJARYVc2VjdXJlQGNz 7 | LmluZGlhbmEuZWR1MB4XDTA3MDMzMDIyNDI0MFoXDTE3MDMyNzIyNDI0MFowgbYx 8 | CzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtCbG9vbWlu 9 | Z3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQLExtDb21w 10 | dXRlciBTY2llbmNlIERlcGFydG1lbnQxFjAUBgNVBAMTDXN2bi5ib29zdC5vcmcx 11 | JDAiBgkqhkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdTCBnzANBgkqhkiG 12 | 9w0BAQEFAAOBjQAwgYkCgYEAxaxyYumnVOczq/ycW6AP20TcmSPUzDXKc2WgS1Mv 13 | 5tZumKVB7x8gyRPymrNUB/mTEefyypt686d7c7J8cwEpeErqtkc9tgB1qh2aipUK 14 | rcmBVgKGdAUfMS7n1fe5A71Hq7taoD7STF3GCAYilV5LF9xVd333SBJuaJGYSmLo 15 | Al0CAwEAAaOCAWcwggFjMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T 16 | U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBQnKN6rhjiYuGPfnOfh 17 | DX3qhlgygjCCAQcGA1UdIwSB/zCB/IAU1U2MOZn/zew88j8wPTWqzYhNzaKhgeCk 18 | gd0wgdoxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtC 19 | bG9vbWluZ3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQL 20 | ExtDb21wdXRlciBTY2llbmNlIERlcGFydG1lbnQxOjA4BgNVBAMTMUNvbXB1dGVy 21 | IFNjaWVuY2UgRGVwYXJ0bWVudCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxJDAiBgkq 22 | hkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdYIBADANBgkqhkiG9w0BAQQF 23 | AAOBgQATYgcmC1Vq92eH4ZAbRl2v9ZsGpEZxf81Tjq2mZ5gWMjQ1sdvyATLq3lFW 24 | Hcng8m5GIZY60APUYat9KhtnMLPRg4cm4gUTJVG13n5FvvWbqSdnhr96AJOOAKA/ 25 | Rp4U64b3XQCqlYPz8XNkGhPLkP2DlrnwffNQYxT2lZW0t64VdA== 26 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /inst/CurlSSL/certs: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEcTCCA9qgAwIBAgIBHjANBgkqhkiG9w0BAQQFADCB2jELMAkGA1UEBhMCVVMx 3 | EDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRswGQYDVQQK 4 | ExJJbmRpYW5hIFVuaXZlcnNpdHkxJDAiBgNVBAsTG0NvbXB1dGVyIFNjaWVuY2Ug 5 | RGVwYXJ0bWVudDE6MDgGA1UEAxMxQ29tcHV0ZXIgU2NpZW5jZSBEZXBhcnRtZW50 6 | IENlcnRpZmljYXRlIEF1dGhvcml0eTEkMCIGCSqGSIb3DQEJARYVc2VjdXJlQGNz 7 | LmluZGlhbmEuZWR1MB4XDTA3MDMzMDIyNDI0MFoXDTE3MDMyNzIyNDI0MFowgbYx 8 | CzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtCbG9vbWlu 9 | Z3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQLExtDb21w 10 | dXRlciBTY2llbmNlIERlcGFydG1lbnQxFjAUBgNVBAMTDXN2bi5ib29zdC5vcmcx 11 | JDAiBgkqhkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdTCBnzANBgkqhkiG 12 | 9w0BAQEFAAOBjQAwgYkCgYEAxaxyYumnVOczq/ycW6AP20TcmSPUzDXKc2WgS1Mv 13 | 5tZumKVB7x8gyRPymrNUB/mTEefyypt686d7c7J8cwEpeErqtkc9tgB1qh2aipUK 14 | rcmBVgKGdAUfMS7n1fe5A71Hq7taoD7STF3GCAYilV5LF9xVd333SBJuaJGYSmLo 15 | Al0CAwEAAaOCAWcwggFjMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T 16 | U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBQnKN6rhjiYuGPfnOfh 17 | DX3qhlgygjCCAQcGA1UdIwSB/zCB/IAU1U2MOZn/zew88j8wPTWqzYhNzaKhgeCk 18 | gd0wgdoxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtC 19 | bG9vbWluZ3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQL 20 | ExtDb21wdXRlciBTY2llbmNlIERlcGFydG1lbnQxOjA4BgNVBAMTMUNvbXB1dGVy 21 | IFNjaWVuY2UgRGVwYXJ0bWVudCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxJDAiBgkq 22 | hkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdYIBADANBgkqhkiG9w0BAQQF 23 | AAOBgQATYgcmC1Vq92eH4ZAbRl2v9ZsGpEZxf81Tjq2mZ5gWMjQ1sdvyATLq3lFW 24 | Hcng8m5GIZY60APUYat9KhtnMLPRg4cm4gUTJVG13n5FvvWbqSdnhr96AJOOAKA/ 25 | Rp4U64b3XQCqlYPz8XNkGhPLkP2DlrnwffNQYxT2lZW0t64VdA== 26 | -----END CERTIFICATE----- 27 | 28 | -----BEGIN CERTIFICATE----- 29 | MIIE1DCCA7ygAwIBAgILAQAAAAABFIOxMIwwDQYJKoZIhvcNAQEFBQAwXzELMAkG 30 | A1UEBhMCQkUxEzARBgNVBAoTCkN5YmVydHJ1c3QxFzAVBgNVBAsTDkVkdWNhdGlv 31 | bmFsIENBMSIwIAYDVQQDExlDeWJlcnRydXN0IEVkdWNhdGlvbmFsIENBMB4XDTA3 32 | MDgyMDE0MzMyMVoXDTEwMDgyMDE0MzMyMVowYTELMAkGA1UEBhMCQ0gxFDASBgNV 33 | BAoTC0VUSCBadWVyaWNoMRUwEwYDVQQDEwxzdGF0LmV0aHouY2gxJTAjBgkqhkiG 34 | 9w0BCQEWFndlYm1hc3RlckBtYXRoLmV0aHouY2gwggEiMA0GCSqGSIb3DQEBAQUA 35 | A4IBDwAwggEKAoIBAQDW1p/xwECPFrRnBz/5SLDfn+30Q0K0P6zPr6NYykkarg8w 36 | sNg9+DAQmxaINcEliTIOhkkakWgjXlA23u9qq2ftb5mKPfDwHPR9HXHke3XkJNwj 37 | 97WLD6OZkxUGgSGA5akG4ZVnPqCE8h/NCH2Jh3qmGv9mMZdSDcU81s2/PuLuEtMs 38 | jsIgfHepiwE1reV5jsQgcQZRHhRU/dL2t1VD4hm55PV/jhr7HmY6di0IxlbA/YW7 39 | rnE27qSqJshihuAC19stSQ7yljZJpI/hM1yZQQvRxyKUlScqJ9vJv2OT8Sp6vNqc 40 | /pMme2mPGVw7R7GMTK3anWfaplKdD6heu/wUNL9RAgMBAAGjggGNMIIBiTBQBgNV 41 | HSAESTBHMEUGByqGSLE+AQAwOjA4BggrBgEFBQcCARYsaHR0cDovL3d3dy5nbG9i 42 | YWxzaWduLm5ldC9yZXBvc2l0b3J5L2Nwcy5jZm0wDgYDVR0PAQH/BAQDAgWgMB8G 43 | A1UdIwQYMBaAFGVloz3XOxGjCgclN8lCSlt2d1DhMB0GA1UdDgQWBBRphVuajRAc 44 | cWUwWH7PIOIh7Dt5iTA6BgNVHR8EMzAxMC+gLaArhilodHRwOi8vY3JsLmdsb2Jh 45 | bHNpZ24ubmV0L2VkdWNhdGlvbmFsLmNybDBPBggrBgEFBQcBAQRDMEEwPwYIKwYB 46 | BQUHMAKGM2h0dHA6Ly9zZWN1cmUuZ2xvYmFsc2lnbi5uZXQvY2FjZXJ0L2VkdWNh 47 | dGlvbmFsLmNydDAvBgNVHREEKDAmggxzdGF0LmV0aHouY2iBFndlYm1hc3RlckBt 48 | YXRoLmV0aHouY2gwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEF 49 | BQcDBDANBgkqhkiG9w0BAQUFAAOCAQEAJpyATMUdre8Ru6H38vZr2RRblGtWNAUU 50 | Ex0g7vLuign+dvbqOrwai+JaT369ny75R0psJzRDamrS3qH5Z1E9DfpbfBx9ikKe 51 | O1G3hjuj6gSTHWwSMUcg4EYNIrt6Vxa5JLuCkNNuzledVs1jtZe9d2+BKzJQ8gJv 52 | BS2IeokFs0huq8T+BTMgXyPF2p1LRMB89svmtjqvBBAl+R5OzEvkenZMpHghP9EK 53 | bZUpMzr9fHSRCaOeLxwDJ6bH5y0weCgFSjhUDwAM4+05z9DJJj4aoZM69wTFJvM+ 54 | 4LXHpyR/RDwPGatXY53dRhiuq3SaQ8XnbUeOBOJCJv47pRaiQX9oTw== 55 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /inst/CurlSSL/certs.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEcTCCA9qgAwIBAgIBHjANBgkqhkiG9w0BAQQFADCB2jELMAkGA1UEBhMCVVMx 3 | EDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRswGQYDVQQK 4 | ExJJbmRpYW5hIFVuaXZlcnNpdHkxJDAiBgNVBAsTG0NvbXB1dGVyIFNjaWVuY2Ug 5 | RGVwYXJ0bWVudDE6MDgGA1UEAxMxQ29tcHV0ZXIgU2NpZW5jZSBEZXBhcnRtZW50 6 | IENlcnRpZmljYXRlIEF1dGhvcml0eTEkMCIGCSqGSIb3DQEJARYVc2VjdXJlQGNz 7 | LmluZGlhbmEuZWR1MB4XDTA3MDMzMDIyNDI0MFoXDTE3MDMyNzIyNDI0MFowgbYx 8 | CzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtCbG9vbWlu 9 | Z3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQLExtDb21w 10 | dXRlciBTY2llbmNlIERlcGFydG1lbnQxFjAUBgNVBAMTDXN2bi5ib29zdC5vcmcx 11 | JDAiBgkqhkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdTCBnzANBgkqhkiG 12 | 9w0BAQEFAAOBjQAwgYkCgYEAxaxyYumnVOczq/ycW6AP20TcmSPUzDXKc2WgS1Mv 13 | 5tZumKVB7x8gyRPymrNUB/mTEefyypt686d7c7J8cwEpeErqtkc9tgB1qh2aipUK 14 | rcmBVgKGdAUfMS7n1fe5A71Hq7taoD7STF3GCAYilV5LF9xVd333SBJuaJGYSmLo 15 | Al0CAwEAAaOCAWcwggFjMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T 16 | U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBQnKN6rhjiYuGPfnOfh 17 | DX3qhlgygjCCAQcGA1UdIwSB/zCB/IAU1U2MOZn/zew88j8wPTWqzYhNzaKhgeCk 18 | gd0wgdoxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtC 19 | bG9vbWluZ3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQL 20 | ExtDb21wdXRlciBTY2llbmNlIERlcGFydG1lbnQxOjA4BgNVBAMTMUNvbXB1dGVy 21 | IFNjaWVuY2UgRGVwYXJ0bWVudCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxJDAiBgkq 22 | hkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdYIBADANBgkqhkiG9w0BAQQF 23 | AAOBgQATYgcmC1Vq92eH4ZAbRl2v9ZsGpEZxf81Tjq2mZ5gWMjQ1sdvyATLq3lFW 24 | Hcng8m5GIZY60APUYat9KhtnMLPRg4cm4gUTJVG13n5FvvWbqSdnhr96AJOOAKA/ 25 | Rp4U64b3XQCqlYPz8XNkGhPLkP2DlrnwffNQYxT2lZW0t64VdA== 26 | -----END CERTIFICATE----- 27 | 28 | -----BEGIN CERTIFICATE----- 29 | MIIE1DCCA7ygAwIBAgILAQAAAAABFIOxMIwwDQYJKoZIhvcNAQEFBQAwXzELMAkG 30 | A1UEBhMCQkUxEzARBgNVBAoTCkN5YmVydHJ1c3QxFzAVBgNVBAsTDkVkdWNhdGlv 31 | bmFsIENBMSIwIAYDVQQDExlDeWJlcnRydXN0IEVkdWNhdGlvbmFsIENBMB4XDTA3 32 | MDgyMDE0MzMyMVoXDTEwMDgyMDE0MzMyMVowYTELMAkGA1UEBhMCQ0gxFDASBgNV 33 | BAoTC0VUSCBadWVyaWNoMRUwEwYDVQQDEwxzdGF0LmV0aHouY2gxJTAjBgkqhkiG 34 | 9w0BCQEWFndlYm1hc3RlckBtYXRoLmV0aHouY2gwggEiMA0GCSqGSIb3DQEBAQUA 35 | A4IBDwAwggEKAoIBAQDW1p/xwECPFrRnBz/5SLDfn+30Q0K0P6zPr6NYykkarg8w 36 | sNg9+DAQmxaINcEliTIOhkkakWgjXlA23u9qq2ftb5mKPfDwHPR9HXHke3XkJNwj 37 | 97WLD6OZkxUGgSGA5akG4ZVnPqCE8h/NCH2Jh3qmGv9mMZdSDcU81s2/PuLuEtMs 38 | jsIgfHepiwE1reV5jsQgcQZRHhRU/dL2t1VD4hm55PV/jhr7HmY6di0IxlbA/YW7 39 | rnE27qSqJshihuAC19stSQ7yljZJpI/hM1yZQQvRxyKUlScqJ9vJv2OT8Sp6vNqc 40 | /pMme2mPGVw7R7GMTK3anWfaplKdD6heu/wUNL9RAgMBAAGjggGNMIIBiTBQBgNV 41 | HSAESTBHMEUGByqGSLE+AQAwOjA4BggrBgEFBQcCARYsaHR0cDovL3d3dy5nbG9i 42 | YWxzaWduLm5ldC9yZXBvc2l0b3J5L2Nwcy5jZm0wDgYDVR0PAQH/BAQDAgWgMB8G 43 | A1UdIwQYMBaAFGVloz3XOxGjCgclN8lCSlt2d1DhMB0GA1UdDgQWBBRphVuajRAc 44 | cWUwWH7PIOIh7Dt5iTA6BgNVHR8EMzAxMC+gLaArhilodHRwOi8vY3JsLmdsb2Jh 45 | bHNpZ24ubmV0L2VkdWNhdGlvbmFsLmNybDBPBggrBgEFBQcBAQRDMEEwPwYIKwYB 46 | BQUHMAKGM2h0dHA6Ly9zZWN1cmUuZ2xvYmFsc2lnbi5uZXQvY2FjZXJ0L2VkdWNh 47 | dGlvbmFsLmNydDAvBgNVHREEKDAmggxzdGF0LmV0aHouY2iBFndlYm1hc3RlckBt 48 | YXRoLmV0aHouY2gwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEF 49 | BQcDBDANBgkqhkiG9w0BAQUFAAOCAQEAJpyATMUdre8Ru6H38vZr2RRblGtWNAUU 50 | Ex0g7vLuign+dvbqOrwai+JaT369ny75R0psJzRDamrS3qH5Z1E9DfpbfBx9ikKe 51 | O1G3hjuj6gSTHWwSMUcg4EYNIrt6Vxa5JLuCkNNuzledVs1jtZe9d2+BKzJQ8gJv 52 | BS2IeokFs0huq8T+BTMgXyPF2p1LRMB89svmtjqvBBAl+R5OzEvkenZMpHghP9EK 53 | bZUpMzr9fHSRCaOeLxwDJ6bH5y0weCgFSjhUDwAM4+05z9DJJj4aoZM69wTFJvM+ 54 | 4LXHpyR/RDwPGatXY53dRhiuq3SaQ8XnbUeOBOJCJv47pRaiQX9oTw== 55 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /inst/CurlSSL/curlSSL.xml: -------------------------------------------------------------------------------- 1 |
2 | 3 | Let's start with a simple HTTPS request: 4 | 5 | getURL("https://www.google.com") 6 | 7 | We get an error of the form 8 | 9 | Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 10 | SSL certificate problem, verify that the CA cert is OK. Details: 11 | error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 12 | 13 | 14 | 15 | Now, let's get the Certification Authority bundle. 16 | You can install this on your operating system 17 | in one of several ways, e.g. 18 | 19 | sudo apt-get install ca-certificates 20 | 21 | Alternatively, we can download the file cacert.pem 22 | from 23 | 24 | 25 | Next, we have to tell libcurl to use this. 26 | We do this via the cainfo option. 27 | 28 | getURL("https://www.google.com", cainfo = "cacert.pem") 29 | 30 | (We can get the real page by following the redirection with 31 | 32 | getURL("https://www.google.com", cainfo = "cacert.pem", follow = TRUE) 33 | 34 | ) 35 | 36 | 37 | 38 | The same applies to reading data from the R mailing list 39 | site at 40 | 41 | getURL("https://stat.ethz.ch/pipermail/r-help/") 42 | 43 | 44 | 45 | 46 | http://ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html 47 | 48 | http://secure.globalsign.net/cacert/sureserverEDU.pem 49 | 50 | http://curl.haxx.se/docs/caextract.html 51 | 52 |
53 | -------------------------------------------------------------------------------- /inst/CurlSSL/cybertrust.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEQjCCA6ugAwIBAgIEBAAD+zANBgkqhkiG9w0BAQUFADB1MQswCQYDVQQGEwJV 3 | UzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMScwJQYDVQQLEx5HVEUgQ3liZXJU 4 | cnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0IEds 5 | b2JhbCBSb290MB4XDTA2MDMxNDIwMzAwMFoXDTEzMDMxNDIzNTkwMFowXzELMAkG 6 | A1UEBhMCQkUxEzARBgNVBAoTCkN5YmVydHJ1c3QxFzAVBgNVBAsTDkVkdWNhdGlv 7 | bmFsIENBMSIwIAYDVQQDExlDeWJlcnRydXN0IEVkdWNhdGlvbmFsIENBMIIBIjAN 8 | BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlSKhEB1KRmBuBZGb34PC7RKyWnz4 9 | q+H4UFwoLH5+ADiTsItK8cJMPBAsPO+w7KFpL7n8zAgUa41PGPOD0vqpNwggqlyq 10 | gGCi1aUiAM9a5bSX37oevlyOFxlm/a+ffHuJsg4k2MerY8SVMo1I5mNZfQS4M6i9 11 | 111kvGO1900o/fkGcjFcukWUZaPStFjsO2FYRKMvYrObgLSC/dXHzFEl5ZU/Ry8w 12 | e6zIeG7i4W0n6z3MAYLoNXeNq1i7VdHVpIFWjRzQFLGwBt6gkSLz8Kg0F0fG4D72 13 | DFqsflBLzeFpbgb8Bn5qTbSVmaBZXDVm7NlJ1BfgYLBdpdca4ipuZvKvHQIDAQAB 14 | o4IBbzCCAWswRQYDVR0fBD4wPDA6oDigNoY0aHR0cDovL3d3dy5wdWJsaWMtdHJ1 15 | c3QuY29tL2NnaS1iaW4vQ1JMLzIwMTgvY2RwLmNybDAdBgNVHQ4EFgQUZWWjPdc7 16 | EaMKByU3yUJKW3Z3UOEwUwYDVR0gBEwwSjBIBgkrBgEEAbE+AQAwOzA5BggrBgEF 17 | BQcCARYtaHR0cDovL3d3dy5wdWJsaWMtdHJ1c3QuY29tL0NQUy9PbW5pUm9vdC5o 18 | dG1sMIGJBgNVHSMEgYEwf6F5pHcwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD0dU 19 | RSBDb3Jwb3JhdGlvbjEnMCUGA1UECxMeR1RFIEN5YmVyVHJ1c3QgU29sdXRpb25z 20 | LCBJbmMuMSMwIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdIICAaUw 21 | DgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQAwDQYJKoZIhvcNAQEF 22 | BQADgYEAQ7NFg1RxxB/csjxrTr8m8k7yrZpb+oY3iOgUbEEYQl/vZT7rA3egt551 23 | elF8uxVbuK+RoDSSU+1/KkmErLmAS7XHsiMi++vY+27JPPPS0bu+yRz/bQHbaYAO 24 | maXqnnuXmI+3zyKcs7hd5akzF3TGlzcPtOkmgl9hCz8ePWTpK5s= 25 | -----END CERTIFICATE----- 26 | 27 | -------------------------------------------------------------------------------- /inst/CurlSSL/docs: -------------------------------------------------------------------------------- 1 | http://ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html 2 | 3 | http://secure.globalsign.net/cacert/sureserverEDU.pem 4 | 5 | 6 | http://curl.haxx.se/docs/caextract.html 7 | 8 | -------------------------------------------------------------------------------- /inst/CurlSSL/google.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDITCCAoqgAwIBAgIQASo5dg0/T8kL570rz5UuejANBgkqhkiG9w0BAQUFADBM 3 | MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg 4 | THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0wOTAzMjcyMjIwMDdaFw0x 5 | MDAzMjcyMjIwMDdaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh 6 | MRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcw 7 | FQYDVQQDEw53d3cuZ29vZ2xlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC 8 | gYEA1rnhrbhhCx9OtjwJPavo4yu26KQ6eC/TUSAiRZXYAJEzmqeiSOowVyaXZsda 9 | 7/GbDD/huX97w8fMr5zQHzyBFRBY/Aazv7ycArlR3PumuRdC5kbnIs9sJxD+VOaS 10 | bAxgdprO+H+suFoIStyxZL2gdEGyrI+GnRreWAn9bAol4HkCAwEAAaOB5zCB5DAo 11 | BgNVHSUEITAfBggrBgEFBQcDAQYIKwYBBQUHAwIGCWCGSAGG+EIEATA2BgNVHR8E 12 | LzAtMCugKaAnhiVodHRwOi8vY3JsLnRoYXd0ZS5jb20vVGhhd3RlU0dDQ0EuY3Js 13 | MHIGCCsGAQUFBwEBBGYwZDAiBggrBgEFBQcwAYYWaHR0cDovL29jc3AudGhhd3Rl 14 | LmNvbTA+BggrBgEFBQcwAoYyaHR0cDovL3d3dy50aGF3dGUuY29tL3JlcG9zaXRv 15 | cnkvVGhhd3RlX1NHQ19DQS5jcnQwDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQUF 16 | AAOBgQA5tvsRvDMsw5BI427DmzixQtEACVhjoOGYHIXy7xAdYE5RCWL1Bb2dT4ds 17 | mHIHgMNZSBTi1u/QjzNqaDH6t7uFzPfHR3tnkzzDFlGbb4cg/WdMK+pqSdsR0b3X 18 | lSJDegZ7TvY3jqK5zx+l0r07BJc5sw/6OLWvVSCIYJPy3tv/3w== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /inst/CurlSSL/ok.R: -------------------------------------------------------------------------------- 1 | getURL("https://stat.ethz.ch", cainfo = "ca-bundle.crt") 2 | -------------------------------------------------------------------------------- /inst/CurlSSL/server.pem: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 30 (0x1e) 5 | Signature Algorithm: md5WithRSAEncryption 6 | Issuer: C=US, ST=Indiana, L=Bloomington, O=Indiana University, OU=Computer Science Department, CN=Computer Science Department Certificate Authority/emailAddress=secure@cs.indiana.edu 7 | Validity 8 | Not Before: Mar 30 22:42:40 2007 GMT 9 | Not After : Mar 27 22:42:40 2017 GMT 10 | Subject: C=US, ST=Indiana, L=Bloomington, O=Indiana University, OU=Computer Science Department, CN=svn.boost.org/emailAddress=secure@cs.indiana.edu 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | RSA Public Key: (1024 bit) 14 | Modulus (1024 bit): 15 | 00:c5:ac:72:62:e9:a7:54:e7:33:ab:fc:9c:5b:a0: 16 | 0f:db:44:dc:99:23:d4:cc:35:ca:73:65:a0:4b:53: 17 | 2f:e6:d6:6e:98:a5:41:ef:1f:20:c9:13:f2:9a:b3: 18 | 54:07:f9:93:11:e7:f2:ca:9b:7a:f3:a7:7b:73:b2: 19 | 7c:73:01:29:78:4a:ea:b6:47:3d:b6:00:75:aa:1d: 20 | 9a:8a:95:0a:ad:c9:81:56:02:86:74:05:1f:31:2e: 21 | e7:d5:f7:b9:03:bd:47:ab:bb:5a:a0:3e:d2:4c:5d: 22 | c6:08:06:22:95:5e:4b:17:dc:55:77:7d:f7:48:12: 23 | 6e:68:91:98:4a:62:e8:02:5d 24 | Exponent: 65537 (0x10001) 25 | X509v3 extensions: 26 | X509v3 Basic Constraints: 27 | CA:FALSE 28 | Netscape Comment: 29 | OpenSSL Generated Certificate 30 | X509v3 Subject Key Identifier: 31 | 27:28:DE:AB:86:38:98:B8:63:DF:9C:E7:E1:0D:7D:EA:86:58:32:82 32 | X509v3 Authority Key Identifier: 33 | keyid:D5:4D:8C:39:99:FF:CD:EC:3C:F2:3F:30:3D:35:AA:CD:88:4D:CD:A2 34 | DirName:/C=US/ST=Indiana/L=Bloomington/O=Indiana University/OU=Computer Science Department/CN=Computer Science Department Certificate Authority/emailAddress=secure@cs.indiana.edu 35 | serial:00 36 | 37 | Signature Algorithm: md5WithRSAEncryption 38 | 13:62:07:26:0b:55:6a:f7:67:87:e1:90:1b:46:5d:af:f5:9b: 39 | 06:a4:46:71:7f:cd:53:8e:ad:a6:67:98:16:32:34:35:b1:db: 40 | f2:01:32:ea:de:51:56:1d:c9:e0:f2:6e:46:21:96:3a:d0:03: 41 | d4:61:ab:7d:2a:1b:67:30:b3:d1:83:87:26:e2:05:13:25:51: 42 | b5:de:7e:45:be:f5:9b:a9:27:67:86:bf:7a:00:93:8e:00:a0: 43 | 3f:46:9e:14:eb:86:f7:5d:00:aa:95:83:f3:f1:73:64:1a:13: 44 | cb:90:fd:83:96:b9:f0:7d:f3:50:63:14:f6:95:95:b4:b7:ae: 45 | 15:74 46 | -----BEGIN CERTIFICATE----- 47 | MIIEcTCCA9qgAwIBAgIBHjANBgkqhkiG9w0BAQQFADCB2jELMAkGA1UEBhMCVVMx 48 | EDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRswGQYDVQQK 49 | ExJJbmRpYW5hIFVuaXZlcnNpdHkxJDAiBgNVBAsTG0NvbXB1dGVyIFNjaWVuY2Ug 50 | RGVwYXJ0bWVudDE6MDgGA1UEAxMxQ29tcHV0ZXIgU2NpZW5jZSBEZXBhcnRtZW50 51 | IENlcnRpZmljYXRlIEF1dGhvcml0eTEkMCIGCSqGSIb3DQEJARYVc2VjdXJlQGNz 52 | LmluZGlhbmEuZWR1MB4XDTA3MDMzMDIyNDI0MFoXDTE3MDMyNzIyNDI0MFowgbYx 53 | CzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtCbG9vbWlu 54 | Z3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQLExtDb21w 55 | dXRlciBTY2llbmNlIERlcGFydG1lbnQxFjAUBgNVBAMTDXN2bi5ib29zdC5vcmcx 56 | JDAiBgkqhkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdTCBnzANBgkqhkiG 57 | 9w0BAQEFAAOBjQAwgYkCgYEAxaxyYumnVOczq/ycW6AP20TcmSPUzDXKc2WgS1Mv 58 | 5tZumKVB7x8gyRPymrNUB/mTEefyypt686d7c7J8cwEpeErqtkc9tgB1qh2aipUK 59 | rcmBVgKGdAUfMS7n1fe5A71Hq7taoD7STF3GCAYilV5LF9xVd333SBJuaJGYSmLo 60 | Al0CAwEAAaOCAWcwggFjMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5T 61 | U0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBQnKN6rhjiYuGPfnOfh 62 | DX3qhlgygjCCAQcGA1UdIwSB/zCB/IAU1U2MOZn/zew88j8wPTWqzYhNzaKhgeCk 63 | gd0wgdoxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdJbmRpYW5hMRQwEgYDVQQHEwtC 64 | bG9vbWluZ3RvbjEbMBkGA1UEChMSSW5kaWFuYSBVbml2ZXJzaXR5MSQwIgYDVQQL 65 | ExtDb21wdXRlciBTY2llbmNlIERlcGFydG1lbnQxOjA4BgNVBAMTMUNvbXB1dGVy 66 | IFNjaWVuY2UgRGVwYXJ0bWVudCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxJDAiBgkq 67 | hkiG9w0BCQEWFXNlY3VyZUBjcy5pbmRpYW5hLmVkdYIBADANBgkqhkiG9w0BAQQF 68 | AAOBgQATYgcmC1Vq92eH4ZAbRl2v9ZsGpEZxf81Tjq2mZ5gWMjQ1sdvyATLq3lFW 69 | Hcng8m5GIZY60APUYat9KhtnMLPRg4cm4gUTJVG13n5FvvWbqSdnhr96AJOOAKA/ 70 | Rp4U64b3XQCqlYPz8XNkGhPLkP2DlrnwffNQYxT2lZW0t64VdA== 71 | -----END CERTIFICATE----- 72 | -------------------------------------------------------------------------------- /inst/CurlSSL/statEth.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE1DCCA7ygAwIBAgILAQAAAAABFIOxMIwwDQYJKoZIhvcNAQEFBQAwXzELMAkG 3 | A1UEBhMCQkUxEzARBgNVBAoTCkN5YmVydHJ1c3QxFzAVBgNVBAsTDkVkdWNhdGlv 4 | bmFsIENBMSIwIAYDVQQDExlDeWJlcnRydXN0IEVkdWNhdGlvbmFsIENBMB4XDTA3 5 | MDgyMDE0MzMyMVoXDTEwMDgyMDE0MzMyMVowYTELMAkGA1UEBhMCQ0gxFDASBgNV 6 | BAoTC0VUSCBadWVyaWNoMRUwEwYDVQQDEwxzdGF0LmV0aHouY2gxJTAjBgkqhkiG 7 | 9w0BCQEWFndlYm1hc3RlckBtYXRoLmV0aHouY2gwggEiMA0GCSqGSIb3DQEBAQUA 8 | A4IBDwAwggEKAoIBAQDW1p/xwECPFrRnBz/5SLDfn+30Q0K0P6zPr6NYykkarg8w 9 | sNg9+DAQmxaINcEliTIOhkkakWgjXlA23u9qq2ftb5mKPfDwHPR9HXHke3XkJNwj 10 | 97WLD6OZkxUGgSGA5akG4ZVnPqCE8h/NCH2Jh3qmGv9mMZdSDcU81s2/PuLuEtMs 11 | jsIgfHepiwE1reV5jsQgcQZRHhRU/dL2t1VD4hm55PV/jhr7HmY6di0IxlbA/YW7 12 | rnE27qSqJshihuAC19stSQ7yljZJpI/hM1yZQQvRxyKUlScqJ9vJv2OT8Sp6vNqc 13 | /pMme2mPGVw7R7GMTK3anWfaplKdD6heu/wUNL9RAgMBAAGjggGNMIIBiTBQBgNV 14 | HSAESTBHMEUGByqGSLE+AQAwOjA4BggrBgEFBQcCARYsaHR0cDovL3d3dy5nbG9i 15 | YWxzaWduLm5ldC9yZXBvc2l0b3J5L2Nwcy5jZm0wDgYDVR0PAQH/BAQDAgWgMB8G 16 | A1UdIwQYMBaAFGVloz3XOxGjCgclN8lCSlt2d1DhMB0GA1UdDgQWBBRphVuajRAc 17 | cWUwWH7PIOIh7Dt5iTA6BgNVHR8EMzAxMC+gLaArhilodHRwOi8vY3JsLmdsb2Jh 18 | bHNpZ24ubmV0L2VkdWNhdGlvbmFsLmNybDBPBggrBgEFBQcBAQRDMEEwPwYIKwYB 19 | BQUHMAKGM2h0dHA6Ly9zZWN1cmUuZ2xvYmFsc2lnbi5uZXQvY2FjZXJ0L2VkdWNh 20 | dGlvbmFsLmNydDAvBgNVHREEKDAmggxzdGF0LmV0aHouY2iBFndlYm1hc3RlckBt 21 | YXRoLmV0aHouY2gwJwYDVR0lBCAwHgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEF 22 | BQcDBDANBgkqhkiG9w0BAQUFAAOCAQEAJpyATMUdre8Ru6H38vZr2RRblGtWNAUU 23 | Ex0g7vLuign+dvbqOrwai+JaT369ny75R0psJzRDamrS3qH5Z1E9DfpbfBx9ikKe 24 | O1G3hjuj6gSTHWwSMUcg4EYNIrt6Vxa5JLuCkNNuzledVs1jtZe9d2+BKzJQ8gJv 25 | BS2IeokFs0huq8T+BTMgXyPF2p1LRMB89svmtjqvBBAl+R5OzEvkenZMpHghP9EK 26 | bZUpMzr9fHSRCaOeLxwDJ6bH5y0weCgFSjhUDwAM4+05z9DJJj4aoZM69wTFJvM+ 27 | 4LXHpyR/RDwPGatXY53dRhiuq3SaQ8XnbUeOBOJCJv47pRaiQX9oTw== 28 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /inst/HTTPErrors/makeErrorClasses.R: -------------------------------------------------------------------------------- 1 | 2 | doc = htmlTreeParse("http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html", useInternal = TRUE) 3 | types = xpathSApply(doc, "//h3", xmlValue) 4 | 5 | types = gsub("^10\\.[0-9]+(\\.[0-9]+)? ", "", types) 6 | types = types [ - grep("[0-9]xx$", types) ] 7 | 8 | scan(con, what = c("integer", "character")) 9 | 10 | status = gsub("^([0-9]+).*", "\\1", types) 11 | name = gsub("[0-9]+ (.*)", "\\1", types) 12 | name = gsub(" ", "_", name) 13 | 14 | sQuote = function(x) paste("'", x, "'", sep = "") 15 | cat("# Generated from inst/HTTPErrors/makeErrorClasses.R\n", 16 | "httpErrorClasses =\nc(", paste(sQuote( status ), sQuote(name), sep = " = ", collapse = ",\n "), "\n)", 17 | file = "~/Projects/org/omegahat/R/RCurl/R/httpErrors.R") 18 | 19 | 20 | -------------------------------------------------------------------------------- /inst/doc/GNUmakefile: -------------------------------------------------------------------------------- 1 | philosophy.html: 2 | 3 | ifndef DYN_DOCS 4 | DYN_DOCS=$(HOME)/Classes/StatComputing/XDynDocs/inst 5 | endif 6 | 7 | # HOME=D:/cygwin/home/duncan 8 | 9 | XSLTPROC=xsltproc 10 | XSL_FILE=$(HOME)/Projects/org/omegahat/Docs/XSL/article.xsl 11 | #XSL_FILE=$(HOME)/docbook-xsl-1.65.1/html/docbook.xsl $(HOME)/Projects/org/omegahat/Docs/XSL/SLanguage.xsl $(HOME)/Projects/org/omegahat/Docs/XSL/html.xsl 12 | XSL_FILE=$(OMEGA_HOME)/Docs/XSL/myarticle.xsl 13 | 14 | XSLT_PARAMS=-param "html.stylesheet" '"http://www.omegahat.org/OmegaTech.css"' 15 | 16 | # For controlling indentation in the output. Use the instead 17 | # -param chunker.output.indent "'yes'" 18 | 19 | XSLT_OPTS=--nonet --xinclude 20 | 21 | # -v 22 | 23 | #%.html: %.xml GNUmakefile $(XSL_FILE) 24 | # $(XSLTPROC) -o $@ $(XSLT_OPTS) $(XSLT_PARAMS) $(XSL_FILE) $< 25 | 26 | 27 | WEB_SITE=www.omegahat.org:/home3/WebSites/Omega/RCurl 28 | 29 | .PHONY: ship 30 | 31 | ship: philosophy.html 32 | scp $^ $(WEB_SITE) 33 | 34 | include $(DYN_DOCS)/Make/Makefile 35 | -------------------------------------------------------------------------------- /inst/doc/cookies.xml: -------------------------------------------------------------------------------- 1 |
2 | Reading Firefox Cookies 3 | 4 | Firefox stores its cookies in an SQLite database. In the directory 5 | ~/Library/Application Support/Firefox/Profiles there is a 6 | default profile, e.g. abcd2efg.default. 7 | In this directory, there is a file named cookies.sqlite. 8 | We can read this in R using the RSQLite package. 9 | We install this in the usual manner. Then we load it and 10 | create a connection and read the table. 11 | 12 | library(RSQLite) 13 | drv = SQLite() 14 | cookiesDB = sqliteNewConnection(drv, "~/Library/Application Support/Firefox/Profiles/abc.default/cookies.sqlite") 15 | dbListTables(cookiesDB) 16 | cookies = dbReadTable(cookiesDB, "moz_cookies") 17 | 18 | 19 | 20 | 21 | This gives us a data frame with 9 columns. 22 | 23 | names(cookies) 24 | [1] "id" "name" "value" "host" "path" 25 | [2] "expiry" "lastAccessed" "isSecure" "isHttpOnly" 26 | 27 | 28 | 29 | Now we can use cookies with RCurl by extracting the 30 | values from this data frame and then passing them 31 | in RCurl calls. 32 | We use the cookie argument in the form 33 | "name=expr", i.e. a string. 34 | We can specify multiple cookies by separating the name=value pairs 35 | by a semi-colon. 36 | 37 |
-------------------------------------------------------------------------------- /inst/doc/fileUploads.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | Here we discuss different approaches to providing 6 | the ability to include uploaded files in 7 | multipart POST'ed forms via RCurl. 8 | 9 | 10 | 11 | At present, the postForm function in RCurl assumes that all the name = 12 | value pairs passed to it are simple string values. My original notion 13 | for handling the upload of forms was that the R code would know to 14 | read the contents of the specified file into an R string and pass it 15 | to postForm() directly. This is, in many ways, desirable as the 16 | "application" calling postForm knows when it is talking about a file 17 | rather than a simple piece of text. Unfortunately, however, this 18 | won't work particularly well with binary files unless we read them 19 | into R and pass the contents directly to the RCurl C code. We can use 20 | the raw type to do this. 21 | 22 | We also need to allow the caller specify the name of the file rather 23 | than just its contents. And we also need to allow the specification 24 | of the content-type. 25 | 26 | libcurl can also support 27 | 28 | 29 | The following is one interface. We create a new function named 30 | fileUpload which can be told about a filename or given the contents, 31 | the content type and the file from which it came. This puts a class 32 | on the object and when we receive one of these in the C code, we 33 | process it "approrpiately". 34 | 35 |
-------------------------------------------------------------------------------- /inst/enums/GNUmakefile: -------------------------------------------------------------------------------- 1 | ifndef CURL_CONFIG 2 | CURL_CONFIG= curl-config 3 | endif 4 | 5 | CFLAGS=$(shell $(CURL_CONFIG) --cflags --libs) 6 | CC=gcc 7 | 8 | Renums: Renums.c 9 | $(CC) -o $@ $(CFLAGS) $< 10 | 11 | -------------------------------------------------------------------------------- /inst/examples/CIS/cis.R: -------------------------------------------------------------------------------- 1 | # From Roger Koenker. 2 | "http://www.statindex.org/CIS/CIS/CIS/psqlQuery/Searcher?>>> > skip=+&authed=>>> > +&authed=a&authed=e&authorstring=koenker&titlestring=rank&keywordstrin>>> > g=&jnt=jp&jnamestring=&pt=+&pt=b&pt=j&pt=p&pt=+&yearbeg=&yearend=&startDisplay=1&endDisplay=50&fmt=extended 3 | 4 | scis <- "http://www.statindex.org/CIS/CIS/CIS/psqlQuery/Searcher?skip=+&authed=+&authed=a&authed=e&authorstring=koenker&titlestring=rank&keywordstring=&jnt=jp&jnamestring=&pt=+&pt=b&pt=j&pt=p&pt=+&yearbeg=&yearend=&startDisplay=1&endDisplay=50&fmt=extended" 5 | 6 | 7 | 8 | h = getCurlHandle(cookiejar = "/tmp/MyCookies") 9 | 10 | # XXX Fill in user id and password here. 11 | postForm("https://www.amstat.org/membersonly/index.cfm?fuseaction=login", txtUser = "106823", txtPassword = "Jasper8Hazel", curl = h) 12 | 13 | #getURL("https://www.amstat.org/membersonly/index.cfm?fuseaction=CISWeb") 14 | 15 | # This gets us back the _ZopeId cookie 16 | v = getURI("https://www.statindex.org/psqlQuery", curl = h) 17 | 18 | u = "http://www.statindex.org/psqlQuery" 19 | u = "http://www.statindex.org/CIS/psqlQuery/Searcher" 20 | u = "http://www.statindex.org/psqlQuery/Searcher" 21 | 22 | 23 | newHandle = getCurlHandle(cookie = '_ZopeId="44748384A25VQtBtVWY"') 24 | 25 | cookie = '_ZopeId="59407264A25VRGMoY0Q"' 26 | 27 | tmp = postForm(u, 28 | skip = "+", authed = "+", authed = "a", authorstring = "Ihaka", titlestring = "", 29 | keywordstring ="", jnt = "jp", jnamestring = "", pt= "+", pt = "b", pt = "j", pt = "p", pt = "+", 30 | yearbeg = "", yearend = "", 31 | startDisplay = "1", endDisplay = "50", fmt = "extended", 32 | .opts = list(verbose = TRUE), curl = h) 33 | 34 | 35 | 36 | 37 | # cookie = '_ZopeId="95878868A25Ttl.5Nd0"' 38 | 39 | getForm("https://www.statindex.org/psqlQuery") 40 | 41 | 42 | ########################################################################### 43 | 44 | 45 | -------------------------------------------------------------------------------- /inst/examples/CIS/cis1.R: -------------------------------------------------------------------------------- 1 | require(RCurl) 2 | require(XML) 3 | #myCurl = getCurlHandle() 4 | #getURL("http://www.statindex.org/CIS/psqlQuery/", cookiejar = "-", curl = myCurl) 5 | #.opts = list(cookie = '_ZopeId="19324353A25Uc.N15jM"', verbose = TRUE)) 6 | 7 | 8 | zopeId = '"39704374A25hoMfuqVU"' 9 | mycookie <- '_ZopeId="19324353A25Uc.N15jM"' 10 | 11 | 12 | 13 | CISQuery <- function(author = "Ihaka", title = "", keyword = "", 14 | journal = "", yearbeg = "", yearend = "", format = "bib", 15 | url = "http://www.statindex.org/CIS/psqlQuery/Searcher", 16 | zope = zopeId, 17 | cookie= mycookie){ 18 | v <- postForm(url, skip = "+", authed = "+", authed = "a", 19 | authorstring = author, titlestring = title, 20 | keywordstring = keyword, jnt = "jp", jnamestring = journal, pt= "+", 21 | pt = "b", pt = "j", pt = "p", pt = "+", 22 | yearbeg = yearbeg, yearend = yearend, 23 | startDisplay = "1", endDisplay = "50", fmt = format, 24 | .opts = list(cookie = paste('_ZopeId=', zope, sep = ""), verbose = TRUE)) 25 | 26 | g <- htmlTreeParse(v, asText = TRUE, useInternal = TRUE) 27 | if(length(g["//*[. = 'You are not an authenticated user']"])) 28 | stop("Not an authenticated CIS user") 29 | print(saveXML(g)) 30 | h <- h[["pre"]][["text"]] 31 | i <- unlist(strsplit(h$value,"@"))[-1] 32 | j <- gsub("\n+$","",i) 33 | k <- gsub("^","@",j) 34 | l <- sapply(k, function(x) strsplit(x,"\n"),USE.NAMES = FALSE) 35 | lapply(l,function(x) {x; class(x) <- "Bibtex"; x}) 36 | } 37 | f <- CISQuery() 38 | -------------------------------------------------------------------------------- /inst/examples/GNUmakefile: -------------------------------------------------------------------------------- 1 | curl: 2 | 3 | CURL_CONFIG=curl-config 4 | 5 | CFLAGS=$(shell $(CURL_CONFIG) --cflags) 6 | LIBS=$(shell $(CURL_CONFIG) --libs) 7 | 8 | curl: curl.o 9 | $(CC) -o $@ curl.o $(LIBS) 10 | 11 | post: post.o 12 | $(CC) -o $@ $^ $(LIBS) 13 | 14 | %.o: %.c 15 | $(CC) $(CFLAGS) -c -o $@ $< 16 | 17 | 18 | XSL_HTML_STYLE_FILE=$(OMEGA_HOME)/Docs/XSL/Rexample.xsl 19 | ifndef XSLTPROC 20 | XSLTPROC=xsltproc 21 | endif 22 | # %.html: %.xml $(OMEGA_HOME)/Docs/XSL/Rexample.xsl 23 | # $(XSLTPROC) $(XSLT_FLAGS) --output $@ $(XSL_HTML_STYLE_FILE) $< 24 | 25 | ifndef DYN_DOCS 26 | DYN_DOCS=$(HOME)/Classes/StatComputing/XDynDocs/inst 27 | endif 28 | 29 | include $(DYN_DOCS)/Make/Makefile 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /inst/examples/chunks.S: -------------------------------------------------------------------------------- 1 | summer = 2 | function() 3 | { 4 | total = 0.0 5 | numValues = 0 6 | 7 | list(read = function(txt) { 8 | con = textConnection(txt) 9 | on.exit(close(con)) 10 | els = scan(con) 11 | numValues <<- numValues + length(els) 12 | total <<- total + sum(els) 13 | 14 | "" 15 | }, 16 | result = function() c(total = total, numValues = numValues)) 17 | } 18 | 19 | s = summer() 20 | 21 | getURL("http://www.omegahat.org/RCurl/matrix.data", write = chunkToLineReader(s$read)$read) 22 | -------------------------------------------------------------------------------- /inst/examples/cis1.R: -------------------------------------------------------------------------------- 1 | if(FALSE) { 2 | require(RCurl) 3 | require(XML) 4 | #myCurl = getCurlHandle() 5 | #getURL("http://www.statindex.org/CIS/psqlQuery/", cookiejar = "-", curl = myCurl) 6 | #.opts = list(cookie = '_ZopeId="19324353A25Uc.N15jM"', verbose = TRUE)) 7 | 8 | 9 | zopeId = '"39704374A25hoMfuqVU"' 10 | # "39704374A25hoMfuqVU" 11 | mycookie <- '_ZopeId="19324353A25Uc.N15jM"' 12 | 13 | CISQuery <- function(author = "Ihaka", title = "", keyword = "", 14 | journal = "", yearbeg = "", yearend = "", format = "bib", 15 | url = "http://www.statindex.org/CIS/psqlQuery/Searcher", 16 | zope = zopeId, 17 | cookie= mycookie){ 18 | v <- postForm(url, skip = "+", authed = "+", authed = "a", 19 | authorstring = author, titlestring = title, 20 | keywordstring = keyword, jnt = "jp", jnamestring = journal, pt= "+", 21 | pt = "b", pt = "j", pt = "p", pt = "+", 22 | yearbeg = yearbeg, yearend = yearend, 23 | startDisplay = "1", endDisplay = "50", fmt = format, 24 | .opts = list(cookie = paste('_ZopeId=', zope, sep = ""), verbose = TRUE)) 25 | 26 | g <- htmlTreeParse(v, asText = TRUE, useInternal = TRUE) 27 | if(length(g["//*[. = 'You are not an authenticated user']"])) 28 | stop("Not an authenticated CIS user") 29 | print(saveXML(g)) 30 | 31 | x = g[["//body/pre"]] 32 | browser() 33 | h <- h[["pre"]][["text"]] 34 | i <- unlist(strsplit(h$value,"@"))[-1] 35 | j <- gsub("\n+$","",i) 36 | k <- gsub("^","@",j) 37 | l <- sapply(k, function(x) strsplit(x,"\n"),USE.NAMES = FALSE) 38 | lapply(l,function(x) {x; class(x) <- "Bibtex"; x}) 39 | } 40 | f <- CISQuery() 41 | } 42 | -------------------------------------------------------------------------------- /inst/examples/concurrent.S: -------------------------------------------------------------------------------- 1 | # See concurrent.xml for more details 2 | 3 | library(RCurl) 4 | 5 | getURIs = 6 | function(uris, ..., multiHandle = getCurlMultiHandle(), .perform = TRUE) 7 | { 8 | content = list() 9 | curls = list() 10 | 11 | for(i in uris) { 12 | curl = getCurlHandle() 13 | content[[i]] = basicTextGatherer() 14 | opts = curlOptions(URL = i, writefunction = content[[i]]$update, ...) 15 | curlSetOpt(.opts = opts, curl = curl) 16 | multiHandle = push(multiHandle, curl) 17 | } 18 | 19 | 20 | if(.perform) { 21 | complete(multiHandle) 22 | lapply(content, function(x) x$value()) 23 | } else { 24 | return(list(multiHandle = multiHandle, content = content)) 25 | } 26 | } 27 | 28 | 29 | uris = c("http://www.omegahat.org/index.html", 30 | "http://www.r-project.org/src/contrib/PACKAGES.html", 31 | "http://developer.r-project.org/index.html", 32 | "http://www.slashdot.org/philosophy.xml", 33 | "http://fxfeeds.mozilla.org/rss20.xml", 34 | "http://www.nytimes.com/index.html") 35 | 36 | 37 | 38 | #atimes = sapply(1:40, function(i) system.time(getURIs(uris, maxconnects = 100))) 39 | #stimes = sapply(1:40, function(i) system.time(lapply(uris, getURI))) 40 | 41 | n = 100 42 | # do one function call for each URI 43 | serialTimes = replicate(n, system.time(lapply(uris, getURI))) 44 | 45 | # do all in function call but sequentially 46 | vectorizedTimes = replicate(n, system.time(getURI(uris, async = FALSE))) 47 | 48 | # use the asynchronous approach 49 | performingAsyncTimes = replicate(n, 50 | system.time({ 51 | getURIs(uris) 52 | })) 53 | 54 | # And do the asynchronous approach more manually 55 | asyncTimes = replicate(n, 56 | system.time({ 57 | z = getURIs(uris, .perform = FALSE) 58 | complete(z$multiHandle) 59 | lapply(z$content, function(x) x$value()) 60 | # Can fetch the download times of the individual documents 61 | #sapply(z$multiHandle@subhandles, function(x) getCurlInfo(x)$total.time) 62 | })) 63 | 64 | 65 | 66 | timings = 67 | data.frame(user = c(performingAsyncTimes[1,], vectorizedTimes[1,], serialTimes[1,]), 68 | system = c(performingAsyncTimes[2,], vectorizedTimes[2,], serialTimes[2,]), 69 | elapsed = c(performingAsyncTimes[3,], vectorizedTimes[3,], serialTimes[3,]), 70 | mode = factor(rep(c("Asynchronous", "Vectorized", "Serial"), rep(n, 3)))) 71 | 72 | 73 | -------------------------------------------------------------------------------- /inst/examples/cookies.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | # This one expects the cookies to already exist in /tmp/cookies 4 | getURL("http://www.nytimes.com", 5 | cookiefile = "/tmp/cookies", 6 | maxredirs = as.integer(20), followlocation = TRUE) 7 | 8 | 9 | # will write the cookies to the file /tmp/myCookies when the 10 | # curl handle is released. 11 | x = getURL("http://www.nytimes.com", cookiejar= "/tmp/myCookies") 12 | gc() 13 | 14 | 15 | # Will write the cookies to the console (i.e. the equivalent of stdout) 16 | h = getCurlHandle() 17 | x = getURL("http://www.nytimes.com", cookiejar= "-", curl = h) 18 | 19 | h = NULL 20 | gc() 21 | 22 | 23 | dbg = function(msg, type, curl) { cat(" ", msg, "\n")} 24 | x = getURL("http://www.nytimes.com", cookiejar= "/usr/local/myCookies", debugfunction = dbg); gc() 25 | 26 | 27 | h = getCurlHandle() 28 | x = getURL("http://www.nytimes.com", cookiejar= "-", curl = h) 29 | h = NULL 30 | capture.output(gc()) 31 | 32 | 33 | # This doesn't work. Is dupCurlHandle() not copying the cookie. 34 | h = getCurlHandle() 35 | x = getURL("http://www.nytimes.com", cookiejar= "-", curl = h) 36 | h2 = dupCurlHandle(h) 37 | curlSetOpt(cookiejar = "/tmp/currentCookies", curl = h2) 38 | rm(h2) 39 | gc() 40 | 41 | 42 | 43 | # 44 | h = getCurlHandle() 45 | x = getURL("http://www.nytimes.com", cookiejar= "-", curl = h) 46 | # Not compiled at present 47 | if(is.loaded("R_get_Cookies")) 48 | .Call("R_get_Cookies", h, "-") 49 | -------------------------------------------------------------------------------- /inst/examples/curl.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *DefaultURL = "http://www.omegahat.org/index.html"; 4 | 5 | 6 | int 7 | main(int argc, char *argv[]) 8 | { 9 | 10 | CURL *h; 11 | char **url; 12 | CURLcode status; 13 | 14 | *url = DefaultURL; 15 | 16 | h = curl_easy_init(); 17 | status = curl_easy_setopt(h, CURLOPT_URL, NULL); 18 | if(status) { 19 | fprintf(stderr, "Expected error %d", status);fflush(stderr); 20 | } 21 | curl_easy_setopt(h, CURLOPT_URL, *url); 22 | curl_easy_perform(h); 23 | 24 | return(0); 25 | } 26 | -------------------------------------------------------------------------------- /inst/examples/download.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | # From Seth Falcon. 4 | 5 | getDownloadSize = function (url) 6 | { 7 | h <- basicTextGatherer() 8 | junk <- getURI(url, headerfunction = h$update, header = TRUE, nobody = TRUE) 9 | h <- h$value() 10 | ##parseContentLength(h) 11 | h 12 | } 13 | 14 | u = "http://cran.fhcrc.org/src/contrib/PACKAGES.gz" 15 | 16 | # If we do 100 iterations, we fail on the 96th with an error 17 | # about not being able to resolve cran.fchrc.org. 18 | # This is on my linux box at home. If we sleep for a second between 19 | # each call, all is well. If we do just 90 even without sleeping, all is well. 20 | # So looks like there is some maximum number of requests per time period on that 21 | # DNS perhaps for the same machine..... 22 | for (i in 1:90) { 23 | print(i) 24 | # Sys.sleep(1) 25 | jj = getDownloadSize(u) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /inst/examples/elapsed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/inst/examples/elapsed.png -------------------------------------------------------------------------------- /inst/examples/encoding.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | Sys.setlocale(, "en_US.UTF-8") 3 | x = getURL("http://www.omegahat.org/RCurl/index.html") 4 | Encoding(x) 5 | 6 | f = system.file("NAMESPACE", package = "RCurl") 7 | x = postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", "fileData" = fileUpload(f), .opts = list(header =TRUE)) 8 | x = postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", "fileData" = fileUpload(f)) 9 | x = postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", "fileData" = fileUpload(f), 10 | .opts = list(writefunction = function(x) {browser(); nchar(x)})) 11 | 12 | # This determines the encoding from the HTTP header of the response 13 | x = getURL("http://www.cl.cam.ac.uk/%7Emgk25/ucs/examples/UTF-8-demo.txt", 14 | header = TRUE, 15 | write = function(x) {print(Encoding(x)) 16 | # print(nchar(x)) # this causes problems about invalid multibyte string. Why? Are we on a boundary 17 | # i.e. the chunks come 18 | nchar(x, "bytes")}) 19 | -------------------------------------------------------------------------------- /inst/examples/ftpList.R: -------------------------------------------------------------------------------- 1 | 2 | library(RCurl) 3 | url = "ftp://ftp.wwpdb.org/pub/pdb/data/structures/all/pdb/" 4 | fileNames = getURL(url, .opts = list(customrequest = "NLST *.gz") ) 5 | fileNames = strsplit(fileNames, "\\\r\\\n")[[1]] 6 | 7 | # Now you can download these directly but you have to deal 8 | # with the compression. This is possible with RCurl by 9 | # specifying a binary reader. 10 | 11 | # Alternatively, get the entiore directory listing and have to pull 12 | # the names out of this much bigger download. 13 | z = getURL(url, .opts = list(customrequest = "LIST *.gz") ) 14 | -------------------------------------------------------------------------------- /inst/examples/getinfo.S: -------------------------------------------------------------------------------- 1 | curl = getCurlHandle() 2 | x = getURL("http://192.168.0.3", verbose = TRUE, curl = curl) 3 | getCurlInfo(.Call("R_getCURLInfoEnum"), curl) 4 | 5 | 6 | -------------------------------------------------------------------------------- /inst/examples/headers.S: -------------------------------------------------------------------------------- 1 | curl = getCurlHandle() 2 | setCurlHeaders(c("Accept" = "text/html"), curl) 3 | getURL("http://192.168.0.3", verbose = TRUE, curl = curl) 4 | -------------------------------------------------------------------------------- /inst/examples/headers2.S: -------------------------------------------------------------------------------- 1 | x = getURL("http://192.168.0.3", httpheader = c(Accept="text/html", Duncan="bob"), verbose = TRUE) 2 | 3 | -------------------------------------------------------------------------------- /inst/examples/html.S: -------------------------------------------------------------------------------- 1 | 2 | 3 | function() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /inst/examples/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/inst/examples/logo.jpg -------------------------------------------------------------------------------- /inst/examples/multi.S: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | uris = c("http://www.omegahat.org/index.html", "http://www.omegahat.org/RecentActivities.html", 3 | "http://www.omegahat.org/RCurl/index.html", 4 | "http://www.omegahat.org/RCurl/philosophy.xml", 5 | "http://www.omegahat.org/RCurl/philosophy.html") 6 | write = multiTextGatherer(uris) 7 | system.time(ans <- getURIAsynchronous(uris, write = write, perform = 1000)) 8 | 9 | 10 | system.time(invisible(getURI(uris, async = FALSE))) 11 | 12 | 13 | 14 | atimes = sapply(1:40, function(i) system.time(getURI(uris))) 15 | stimes = sapply(1:40, function(i) system.time(getURI(uris, async = FALSE))) 16 | 17 | times = data.frame(user = c(atimes[1,], stimes[1,]), 18 | system = c(atimes[2,], stimes[2,]), 19 | elapsed = c(atimes[3,], stimes[3,]), 20 | style = factor(c(rep("Asynchronous", 40), rep("Serial", 40)))) 21 | 22 | -------------------------------------------------------------------------------- /inst/examples/omg.netrc: -------------------------------------------------------------------------------- 1 | machine www.omegahat.org 2 | login bob 3 | password welcome 4 | 5 | -------------------------------------------------------------------------------- /inst/examples/passwd.S: -------------------------------------------------------------------------------- 1 | promptPassword = 2 | function(prompt, len) 3 | { 4 | cat(prompt, ": (max of ", len, " characters)> ", sep="") 5 | scan(what = "", nmax = 1) 6 | } 7 | 8 | getURL("http://192.168.0.2/stat141/Winter04/Homework/Solutions", 9 | passwdfunction = promptPassword) 10 | 11 | 12 | x = getURL("https://my.ucdavis.edu", userpwd = "", 13 | header = TRUE, verbose = TRUE, 14 | cookiefile = "/home/duncan/Rcookies", 15 | netrc = TRUE, 16 | maxredirs = as.integer(20), 17 | #netrc.file = "/home2/duncan/.netrc1", 18 | followlocation = TRUE) # , passwdfunction = promptPassword) 19 | print(x) 20 | 21 | 22 | -------------------------------------------------------------------------------- /inst/examples/passwd2.S: -------------------------------------------------------------------------------- 1 | x = getURL("http://192.168.0.3/stat141/Winter04/Homework/Solutions/index.html", 2 | # userpwd = "name:passwd:", 3 | # userpwd = "bob:", 4 | header = TRUE, verbose = TRUE, 5 | cookiefile = "/home/duncan/Rcookies", 6 | netrc = TRUE, 7 | maxredirs = as.integer(20), 8 | netrc.file = "/home2/duncan/.netrc1", 9 | followlocation = TRUE) 10 | 11 | # This is no longer supported in libcurl. 12 | # , passwdfunction = promptPassword) 13 | -------------------------------------------------------------------------------- /inst/examples/passwdSSL.S: -------------------------------------------------------------------------------- 1 | # Winnie on home machine. 2 | getURI("https://192.168.0.2/stat141/Winter04/Homework/Solutions/", 3 | userpwd = "bob:ComeIn", 4 | ssl.verifyhost = as.integer(0), ssl.verifypeer = as.integer(0)) 5 | 6 | 7 | # Omitting the verifyhost causes 8 | # SSL: certificate subject name 'localhost.localdomain' does not match target host name '192.168.0.2' 9 | 10 | # However, specifying 1 as its value works even though it should be verifying the host. 11 | # 2 is the default and forces the error. 12 | 13 | -------------------------------------------------------------------------------- /inst/examples/post.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | 8 | CURL *h; 9 | char url[] = "http://www.speakeasy.org/~cgires/perl_form.cgi"; 10 | CURLcode status; 11 | 12 | struct curl_httppost *post = NULL, *last = NULL; 13 | 14 | h = curl_easy_init(); 15 | 16 | curl_easy_setopt(h, CURLOPT_URL, url); 17 | 18 | 19 | curl_formadd(&post, &last, 20 | CURLFORM_PTRNAME, "some_text", 21 | CURLFORM_PTRCONTENTS, "Duncan", 22 | CURLFORM_END); 23 | 24 | curl_formadd(&post, &last, 25 | CURLFORM_PTRNAME, "choice", 26 | CURLFORM_PTRCONTENTS, "Ho", 27 | CURLFORM_END); 28 | 29 | curl_formadd(&post, &last, 30 | CURLFORM_PTRNAME, "radbut", 31 | CURLFORM_PTRCONTENTS, "eep", 32 | CURLFORM_END); 33 | 34 | curl_formadd(&post, &last, 35 | CURLFORM_PTRNAME, "box", 36 | CURLFORM_PTRCONTENTS, "box1", 37 | CURLFORM_END); 38 | 39 | curl_easy_setopt(h, CURLOPT_HTTPPOST, post); 40 | curl_easy_perform(h); 41 | 42 | return(0); 43 | } 44 | -------------------------------------------------------------------------------- /inst/examples/post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

8 | 9 |
10 | Photo to Upload: 11 |

12 | Your Email Address: 13 |

14 | 15 |
16 | 17 |
18 |
Duncan Temple Lang 19 | <duncan@wald.ucdavis.edu>
20 | Last modified: Tue Oct 4 09:01:45 PDT 2005 21 | 22 | -------------------------------------------------------------------------------- /inst/examples/postFormPasswd.R: -------------------------------------------------------------------------------- 1 | # Perl script (and HTML form for testing in the browser) taken from 2 | # http://www.elated.com/articles/form-validation-with-perl-and-cgi/ 3 | 4 | 5 | # Provide the login & password directly 6 | postForm("http://www.omegahat.org/RCurl/testPassword/form_validation.cgi", 7 | your_name = "Duncan", 8 | your_age = "35-55", 9 | your_sex = "m", 10 | submit = "submit", 11 | .opts = list(userpwd = "bob:welcome")) 12 | 13 | # Get the login & password in ~/.netrc 14 | postForm("http://www.omegahat.org/RCurl/testPassword/form_validation.cgi", 15 | your_name = "Duncan", 16 | your_age = "35-55", 17 | your_sex = "m", 18 | submit = "submit", 19 | .opts = list(netrc = TRUE)) 20 | 21 | # Get the login & password from a different netrc file 22 | 23 | postForm("http://www.omegahat.org/RCurl/testPassword/form_validation.cgi", 24 | your_name = "Duncan", 25 | your_age = "35-55", 26 | your_sex = "m", 27 | submit = "submit", 28 | .opts = list(netrc = TRUE, 29 | netrc.file = "/Users/duncan/Projects/org/omegahat/R/RCurl/inst/examples/omg.netrc")) 30 | -------------------------------------------------------------------------------- /inst/examples/progress.S: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | getURL("http://www.omegahat.org/RCurl/index.html", progressfunction = function(down, up) {print(down); print(up)}, noprogress = FALSE) 3 | -------------------------------------------------------------------------------- /inst/examples/proxy.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | if(FALSE) { 3 | getURL("http://curl.haxx.se/mail/archive-2004-04/0035.html", 4 | proxy="wwwproxy.ru.ac.za:3128", proxyauth=TRUE, 5 | proxyuserpwd="mysuername:mypassword") #withrelevant username etc 6 | } 7 | -------------------------------------------------------------------------------- /inst/examples/readHeader.S: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | h = basicTextGatherer() 4 | txt = getURL("http://192.168.0.3", header= TRUE, headerfunction = h[[1]], httpheader = c(Accept="text/html", Duncan="bob"), verbose = TRUE) 5 | read.dcf(textConnection(paste(h$value(NULL)[-1], collapse=""))) 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /inst/examples/soap.S: -------------------------------------------------------------------------------- 1 | body = '\ 2 | \ 7 | \ 8 | \ 9 | \ 10 | \n' 11 | 12 | 13 | curlPerform(url="http://services.soaplite.com/hibye.cgi", 14 | httpheader=c(Accept="text/xml", Accept="multipart/*", 15 | SOAPAction='"http://www.soaplite.com/Demo#hi"', 16 | 'Content-Type' = "text/xml; charset=utf-8"), 17 | postfields=body, 18 | verbose = TRUE 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /inst/examples/speakeasy.S: -------------------------------------------------------------------------------- 1 | print(postForm("http://www.speakeasy.org/~cgires/perl_form.cgi", 2 | "some_text" = "Duncan", 3 | "choice" = "Ho", 4 | "radbut" = "eep", 5 | "box" = "box1, box2" 6 | 7 | # "box" = "box1" 8 | # and try c("box1", "box2") 9 | )) 10 | 11 | -------------------------------------------------------------------------------- /inst/examples/system.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/inst/examples/system.png -------------------------------------------------------------------------------- /inst/examples/time.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | body = ' 4 | 5 | 6 | 7 | GMT 8 | 9 | 10 | ' 11 | 12 | curlPerform( url = "http://www.nanonull.com/TimeService/TimeService.asmx", 13 | httpheader = c(accept = "multipart/*", 14 | "Content-Type" = "text/xml; charset=utf-8", 15 | SOAPAction = '"http://www.Nanonull.com/TimeService/getTimeZoneTime"'), 16 | postfields = body) 17 | -------------------------------------------------------------------------------- /inst/examples/upload.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | upFile = system.file("DESCRIPTION", package = "RCurl") 3 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 4 | "fileData" = fileUpload(upFile), .opts = list(verbose = TRUE)) 5 | 6 | 7 | # Give the contents from R 8 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 9 | "fileData" = fileUpload("", paste(readLines(upFile), collapse = "\n")), 10 | .opts = list(verbose = TRUE, header = TRUE)) 11 | 12 | 13 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 14 | "fileData" = fileUpload("", paste(readLines(upFile), collapse = "\n"), "text/plain"), 15 | .opts = list(verbose = TRUE, header = TRUE)) 16 | -------------------------------------------------------------------------------- /inst/examples/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omegahat/RCurl/e07c076963fc6436e0b05db04bb0b3a20ba378e9/inst/examples/user.png -------------------------------------------------------------------------------- /inst/examples/worm.S: -------------------------------------------------------------------------------- 1 | counter = 2 | function(max = 10) 3 | { 4 | counts = numeric() 5 | numRecords = 0 6 | 7 | read = function(txt) { 8 | 9 | id = gsub("^>(.*) .*", "\\1", txt) 10 | 11 | vals = table(id) 12 | 13 | for(id in names(vals)) 14 | counts[id] <<- ifelse(id %in% names(counts), counts[id], 0) + vals[id] 15 | 16 | numRecords <<- numRecords + 1 17 | 18 | if(numRecords >= max) { 19 | msg = list(message = "Reached maximum count") 20 | class(msg) = c("CountException", "error", "condition") 21 | stop(msg) 22 | } 23 | 24 | # sum(nchar(txt)) 25 | } 26 | 27 | list(read = read, counts = function() counts) 28 | } 29 | 30 | theCount = counter() 31 | f = chunk2LineReader(theCount$read) 32 | 33 | x = postForm("http://www.wormbase.org/db/searches/advanced/dumper", 34 | species = "elegans", 35 | list = "AC3.8 M7 X IV III:1000..4000", 36 | feature = "BLASTX Hits", 37 | DNA = "feature coordinates only", 38 | flank5 = "0", 39 | flank3 = "0", 40 | relative = "Chromosome", 41 | orientation = "Relative to feature", 42 | dump = "Plain TEXT", 43 | DUMP = "DUMP", 44 | .cgifields = c("feature", "orientation", "dump", "relative", "DNA"), 45 | .opts = list(writefunction = f$read)) 46 | 47 | nchar(x) 48 | 49 | 50 | 51 | 52 | 53 | # DNA = 'feature and flanking sequences', 54 | # DUMP = 'DUMP', 55 | #species = 'elegans', 56 | 57 | x = postForm('http://www.wormbase.org/db/searches/advanced/dumper', 58 | species="briggsae", 59 | list="AC3.8 M7 X IV III:1000..4000", 60 | flank3="0", 61 | flank5="0", 62 | feature="Gene Models", 63 | dump = "Plain TEXT", 64 | orientation = "Relative to feature", 65 | relative = "Chromsome", 66 | DNA ="flanking sequences only", 67 | .cgifields = paste(c("feature", "orientation", "DNA", "dump", "relative"), collapse=", ")) 68 | 69 | print(x) 70 | -------------------------------------------------------------------------------- /libcurlLicense: -------------------------------------------------------------------------------- 1 | COPYRIGHT AND PERMISSION NOTICE 2 | 3 | Copyright (c) 1996 - 2006, Daniel Stenberg, . 4 | 5 | All rights reserved. 6 | 7 | Permission to use, copy, modify, and distribute this software for any purpose 8 | with or without fee is hereby granted, provided that the above copyright 9 | notice and this permission notice appear in all copies. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN 14 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 17 | OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | Except as contained in this notice, the name of a copyright holder shall not 20 | be used in advertising or otherwise to promote the sale, use or other dealings 21 | in this Software without prior written authorization of the copyright holder. 22 | -------------------------------------------------------------------------------- /man/AUTH.Rd: -------------------------------------------------------------------------------- 1 | \name{AUTH_ANY} 2 | \alias{AUTH_ANY} 3 | \alias{AUTH_ANYSAFE} 4 | \alias{AUTH_BASIC} 5 | \alias{AUTH_DIGEST} 6 | \alias{AUTH_DIGEST_IE} 7 | \alias{AUTH_GSSNEGOTIATE} 8 | \alias{AUTH_NONE} 9 | \alias{AUTH_NTLM} 10 | \alias{AUTH_NTLM_WB} 11 | \alias{AUTH_ONLY} 12 | \title{Constants for identifying Authentication Schemes} 13 | \description{ 14 | These variables are symbolic constants that allow 15 | use to specify different combinations of schemes 16 | for HTTP authentication in a request to a Web server. 17 | We can combine them via the \code{|} operator to 18 | indicate that libcurl should try them in order until one works. 19 | } 20 | \examples{ 21 | AUTH_BASIC | AUTH_DIGEST 22 | } 23 | \keyword{programming} 24 | -------------------------------------------------------------------------------- /man/CFILE.Rd: -------------------------------------------------------------------------------- 1 | \name{CFILE} 2 | \Rdversion{1.1} 3 | \alias{CFILE} 4 | \alias{CFILE-class} 5 | \alias{close,CFILE-method} 6 | \title{Create a C-level handle for a file} 7 | \description{ 8 | This function and class allow us to work with C-level 9 | \code{FILE} handles. 10 | The intent is to be able to pass these to \code{libcurl} 11 | as options so that it can read or write from or to the file. 12 | We can also do this with R connections and specify callback functions 13 | that manipulate these connections. But using 14 | the C-level FILE handle is likely to be significantly faster for large 15 | files. 16 | 17 | The \code{close} method allows us to explicitly flush and close the file 18 | from within R. 19 | } 20 | \usage{ 21 | CFILE(filename, mode = "r") 22 | } 23 | \arguments{ 24 | \item{filename}{the name of the file on disk} 25 | \item{mode}{a string specifying how to open the file, read or write, text or binary.} 26 | } 27 | \details{ 28 | This is a simple interface to the C routine \code{fopen}. 29 | } 30 | \value{ 31 | An object of class \code{CFILE} which is 32 | has a single slot name \code{ref} which is an external pointer 33 | holding the address of the FILE object in C. 34 | } 35 | \references{ 36 | Man page for \code{fopen} 37 | } 38 | \author{Duncan Temple Lang} 39 | 40 | \seealso{ 41 | \code{\link{curlPerform}} and the \code{readdata} 42 | } 43 | \examples{ 44 | \dontrun{ 45 | filename = system.file("tests", "amazon3.R", package = "RCurl") 46 | f = CFILE(filename) 47 | 48 | if(url.exists('http://s3.amazonaws.com/')) 49 | curlPerform(url = "http://s3.amazonaws.com/RRupload/duncan2", 50 | upload = TRUE, 51 | readdata = f@ref, 52 | infilesize = file.info(filename)[1, "size"]) 53 | } 54 | } 55 | \keyword{IO} 56 | -------------------------------------------------------------------------------- /man/CURLHandle-class.Rd: -------------------------------------------------------------------------------- 1 | \name{CURLHandle-class} 2 | \docType{class} 3 | \alias{CURLHandle-class} 4 | 5 | \title{Class "CURLHandle" for synchronous HTTP requests} 6 | \description{ 7 | This is the basic class used for performing HTTP requests 8 | in the RCurl package. 9 | In R, this is a reference to a C-level data structure 10 | so we treat it as an opaque data type. However, 11 | essentially we can think of this as an with 12 | a set of options that persists across calls, i.e. HTTP requests. 13 | The numerous options that one can set can be see via 14 | \code{\link{getCurlOptionsConstants}}. 15 | The object can keep a connection to a Web server open for a period of time 16 | across calls. 17 | 18 | This class differs from \code{\link{MultiCURLHandle-class}} as it 19 | can handle only one request at a time and blocks until the request 20 | is completed (normally or abnormally). 21 | The other class can handle asynchronous, multiple connections. 22 | } 23 | \section{Objects from the Class}{A virtual Class: No objects may be created from it.} 24 | \section{Extends}{ 25 | Class \code{"oldClass"}, directly. 26 | } 27 | %\section{Methods}{ \describe{}} 28 | \references{ 29 | \url{http://curl.haxx.se}, the libcurl web site. 30 | } 31 | \author{Duncan Temple Lang} 32 | 33 | \seealso{ 34 | \code{\link{getURL}}, \code{\link{getForm}}, \code{\link{postForm}} 35 | \code{\link{dupCurlHandle}}, 36 | \code{\link{getCurlHandle}}, 37 | \code{\link{MultiCURLHandle-class}} 38 | } 39 | %\examples{} 40 | \keyword{classes} 41 | -------------------------------------------------------------------------------- /man/CurlFeatureBits.Rd: -------------------------------------------------------------------------------- 1 | \name{CurlFeatureBits} 2 | \alias{CurlFeatureBits} 3 | \alias{CurlNetrc} 4 | \alias{CurlGlobalBits} 5 | \docType{data} 6 | \title{Constants for libcurl} 7 | \description{ 8 | These are enums and bit fields defining 9 | constants used in libcurl and used in 10 | R to specify values symbolically. 11 | } 12 | \usage{CurlFeatureBits} 13 | \format{ 14 | named integer vectors. 15 | The names give the symbolic constants that can be used 16 | in R and C code. These are mapped to their integer equivalents 17 | and used in C-level computations. 18 | } 19 | \source{ 20 | libcurl (see \url{http://curl.haxx.se}) 21 | } 22 | %\references{} 23 | %\seealso{} 24 | %\examples{} 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/HTTP_VERSION_1_0.Rd: -------------------------------------------------------------------------------- 1 | \name{HTTP_VERSION_1_0} 2 | \Rdversion{1.1} 3 | \alias{HTTP_VERSION_1_0} 4 | \alias{HTTP_VERSION_1_1} 5 | \alias{HTTP_VERSION_LAST} 6 | \alias{HTTP_VERSION_NONE} 7 | \alias{SSLVERSION_DEFAULT} 8 | \alias{SSLVERSION_LAST} 9 | \alias{SSLVERSION_SSLv2} 10 | \alias{SSLVERSION_SSLv3} 11 | \alias{SSLVERSION_TLSv1} 12 | \title{Symbolic constants for specifying HTTP and SSL versions in libcurl} 13 | \description{ 14 | These are values that can be used to set the \code{http.version} and \code{sslversion} 15 | options of \code{\link{curlPerform}}. 16 | } 17 | \usage{HTTP_VERSION_1_0} 18 | \references{ 19 | \url{http://curl.haxx.se/libcurl/c/curl_easy_setopt.html} 20 | } 21 | %\examples{} 22 | \keyword{datasets} 23 | -------------------------------------------------------------------------------- /man/MultiCURLHandle-class.Rd: -------------------------------------------------------------------------------- 1 | \name{MultiCURLHandle-class} 2 | \docType{class} 3 | \alias{MultiCURLHandle-class} 4 | \alias{pop} 5 | \alias{push} 6 | \alias{pop,MultiCURLHandle,CURLHandle-method} 7 | \alias{pop,MultiCURLHandle,character-method} 8 | \alias{pop,MultiCURLHandle,integer-method} 9 | \alias{push,MultiCURLHandle,CURLHandle-method} 10 | 11 | \title{Class "MultiCURLHandle" for asynchronous, concurrent HTTP requests} 12 | \description{ 13 | This is a class that represents a handle to an internal 14 | C-level data structure provided by libcurl to 15 | perform multiple HTTP requests in a single operation 16 | and process the responses in an inter-leaved fashion, 17 | i.e. a chunk from one, followed by a chunk from another. 18 | 19 | Objects of this class contain not only a reference to the 20 | internal C-level data structure, but also have a list 21 | of the \code{\link{CURLHandle-class}} objects 22 | that represent the individual HTTP requests that make up 23 | the collection of concurrent requests. 24 | These are maintained for garbage collection reasons. 25 | 26 | Essentially, the data in objects of this class are for internal use; 27 | this is an opaque class in R. 28 | } 29 | \section{Objects from the Class}{ 30 | The constructor function \code{\link{getCurlMultiHandle}} 31 | is the only way to create meaningful instances of this class. 32 | } 33 | \section{Slots}{ 34 | \describe{ 35 | \item{\code{ref}:}{Object of class \code{"externalptr"}. This is 36 | a reference to the instance of the libcurl data structure 37 | \code{CURLM} pointer. 38 | } 39 | \item{\code{subhandles}:}{Object of class \code{"list"}. 40 | This is a list of \code{\link{CURLHandle-class}} 41 | instances that have been \code{push()}ed onto the 42 | multi-handle stack. 43 | } 44 | } 45 | } 46 | \section{Methods}{ 47 | \describe{ 48 | \item{pop}{\code{signature(obj = "MultiCURLHandle", val = "CURLHandle")}: ... } 49 | \item{pop}{\code{signature(obj = "MultiCURLHandle", val = "character")}: ... } 50 | \item{push}{\code{signature(obj = "MultiCURLHandle", val = "CURLHandle")}: ... } 51 | } 52 | } 53 | 54 | \references{Curl homepage \url{http://curl.haxx.se} 55 | \url{http://www.omegahat.org/RCurl} 56 | } 57 | \author{Duncan Temple Lang } 58 | \seealso{ 59 | \code{\link{getCurlMultiHandle}} 60 | \code{\link{curlMultiPerform}} 61 | \code{\link{multiTextGatherer}} 62 | } 63 | %\examples{} 64 | \keyword{classes} 65 | -------------------------------------------------------------------------------- /man/RCurl-internal.Rd: -------------------------------------------------------------------------------- 1 | \name{RCurlInternal} 2 | \alias{coerce,numeric,NetrcEnum-method} 3 | \title{Internal functions} 4 | \description{Not for human consumption} 5 | 6 | \keyword{programming} 7 | -------------------------------------------------------------------------------- /man/basicHeaderGatherer.Rd: -------------------------------------------------------------------------------- 1 | \name{basicHeaderGatherer} 2 | \alias{basicHeaderGatherer} 3 | \alias{parseHTTPHeader} 4 | \title{Functions for processing the response header of a libcurl request} 5 | \description{ 6 | These two functions are used to collect the contents of the header of 7 | an HTTP response via the \code{headerfunction} option of a curl handle 8 | and then processing that text into both the name: value pairs 9 | and also the initial line of the response that provides the 10 | status of the request. 11 | \code{basicHeaderGatherer} is a simple special case of 12 | \code{\link{basicTextGatherer}} with the built-in post-processing 13 | step done by \code{parseHTTPHeader}. 14 | } 15 | \usage{ 16 | basicHeaderGatherer(txt = character(), max = NA) 17 | parseHTTPHeader(lines, multi = TRUE) 18 | } 19 | \arguments{ 20 | \item{txt}{any initial text that we want included with the header. 21 | This is passed to \code{\link{basicTextGatherer}}. Generally it 22 | should not be specified unless there is a good reason.} 23 | \item{max}{This is passed directly to 24 | \code{\link{basicTextGatherer}}} 25 | \item{lines}{ the text as a character vector from the response header 26 | that 27 | \code{parseHTTPHeader} will convert to a status and name-value 28 | pairs.} 29 | \item{multi}{a logical value controlling whether we check for 30 | multiple HTTP headers in the lines of text. This is caused 31 | by a Continue being concatenated with the actual response. 32 | When this is \code{TRUE}, we look for the lines 33 | that start an HTTP header, e.g. \code{HTTP 200 ...}, 34 | and we use the content from the last of these. 35 | } 36 | } 37 | \value{ 38 | The return value is the same as \code{\link{basicTextGatherer}}, 39 | i.e. a list with 40 | \code{update}, \code{value} and \code{reset} function elements. 41 | The \code{value} element will invoke \code{parseHTTPHeader} 42 | on the contents read during the processing of the libcurl request 43 | and return that value. 44 | } 45 | \references{Curl homepage \url{http://curl.haxx.se}} 46 | \author{Duncan Temple Lang } 47 | 48 | \seealso{ 49 | \code{\link{basicTextGatherer}} 50 | \code{\link{curlPerform}} 51 | \code{\link{curlSetOpt}} 52 | } 53 | \examples{ 54 | if(url.exists("http://www.omegahat.org/RCurl/index.html")) { 55 | h = basicHeaderGatherer() 56 | getURI("http://www.omegahat.org/RCurl/index.html", 57 | headerfunction = h$update) 58 | names(h$value()) 59 | h$value() 60 | } 61 | } 62 | \keyword{IO} 63 | \concept{network client} 64 | 65 | -------------------------------------------------------------------------------- /man/binaryBuffer.Rd: -------------------------------------------------------------------------------- 1 | \name{binaryBuffer} 2 | \alias{binaryBuffer} 3 | \alias{coerce,RCurlBinaryBuffer,raw-method} 4 | \title{Create internal C-level data structure for collecting binary data} 5 | \description{ 6 | This is the constructor function for creating an internal data 7 | structure 8 | that is used when reading binary data from an HTTP request 9 | via RCurl. It is used with the native routine 10 | \code{R_curl_write_binary_data} for collecting 11 | the response from the HTTP query into a buffer that stores 12 | the bytes. The contents can then be brought back into R 13 | as a \code{raw} vector and then used in different ways, 14 | e.g. uncompressed with the \code{Rcompression} package, 15 | or written to a file via \code{\link[base]{writeBin}}. 16 | } 17 | \usage{ 18 | binaryBuffer(initialSize = 5000) 19 | } 20 | \arguments{ 21 | \item{initialSize}{a number giving the size (number of bytes) to 22 | allocate for the buffer. In most cases, the size won't make an 23 | enormous difference. If this is small, the 24 | \code{R_curl_write_binary_data} routine will expand it as necessary 25 | when more daat is received than would fit in it. If it is very 26 | large, i.e. larger than the resulting response, the consequence is 27 | simply unused memory. One can determine the appropriate size by 28 | performing the HTTP request with \code{nobody = TRUE} and looking 29 | at the resulting size indicated by the headers of the response, 30 | i.e. 31 | \code{getCurlInfo(handle)} and then using that size and repeating 32 | the request and receiving the body. This is a trade-off between 33 | network speed and memor consumption and processing speed when 34 | collecting the . 35 | } 36 | } 37 | 38 | \value{ 39 | An object of class \code{RCurlBinaryBuffer} which is to be treated 40 | as an opaque data for the most part. When passing this as the value of 41 | the \code{file} option, one will have to pass the ref slot. 42 | 43 | After the contents have been read, one can convert this object to an R 44 | raw vector using \code{as(buf, "raw")}. 45 | } 46 | \references{Curl homepage \url{http://curl.haxx.se}} 47 | \author{Duncan Temple Lang } 48 | 49 | \seealso{ 50 | \code{R_curl_write_binary_data} 51 | } 52 | \examples{ 53 | if(url.exists("http://www.omegahat.org/RCurl/xmlParse.html.gz")) { 54 | buf = binaryBuffer() 55 | 56 | # Now fetch the binary file. 57 | getURI("http://www.omegahat.org/RCurl/xmlParse.html.gz", 58 | write = getNativeSymbolInfo("R_curl_write_binary_data")$address, 59 | file = buf@ref) 60 | 61 | # Convert the internal data structure into an R raw vector 62 | b = as(buf, "raw") 63 | 64 | if(require(Rcompression)) 65 | gunzip(b) 66 | } 67 | } 68 | \keyword{IO} 69 | \keyword{programming} 70 | \concept{Web} 71 | \concept{binary data} 72 | 73 | -------------------------------------------------------------------------------- /man/chunkToLineReader.Rd: -------------------------------------------------------------------------------- 1 | \name{chunkToLineReader} 2 | \alias{chunkToLineReader} 3 | \title{Utility that collects data from the HTTP reply into lines and 4 | calls user-provided function. 5 | } 6 | \description{ 7 | When one provides an R function to process the body of 8 | the R rep 9 | } 10 | \usage{ 11 | chunkToLineReader(f, verbose = FALSE) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{f}{a function that is to be called each time 16 | the \code{read} function is invoked and there are complete 17 | lines in that input.} 18 | \item{verbose}{a logical value. If \code{TRUE}, 19 | information is displayed when there is any text 20 | that does not form a complete line and is held 21 | for processing in the next chunk. 22 | } 23 | } 24 | \details{ 25 | This constructs a closure and then processes each chunk as 26 | they are passed to the read function. 27 | It strips away any text that does not form a complete line 28 | at the end of the chunk and holds this to be added to the next chunk 29 | being processed. 30 | } 31 | \value{ 32 | A list with two components 33 | \item{read}{the function that will do the actual reading from the 34 | HTTP response stream and call the function \code{f} on each 35 | step (assuming the chunk has a line marker.} 36 | \item{comp2 }{Description of 'comp2'} 37 | ... 38 | } 39 | \references{Curl homepage \url{http://curl.haxx.se}} 40 | \author{Duncan Temple Lang } 41 | 42 | \seealso{ 43 | \code{\link{getURI}} and the \code{write} argument. 44 | \code{\link{getForm}}, \code{\link{postForm}} 45 | \code{\link{curlPerform}} 46 | } 47 | \examples{ 48 | # Read a rectangular table of data into R from the URL 49 | # and add up the values and the number of values read. 50 | 51 | summer = 52 | function() 53 | { 54 | total = 0.0 55 | numValues = 0 56 | 57 | list(read = function(txt) { 58 | con = textConnection(txt) 59 | on.exit(close(con)) 60 | els = scan(con) 61 | numValues <<- numValues + length(els) 62 | total <<- total + sum(els) 63 | 64 | "" 65 | }, 66 | result = function() c(total = total, numValues = numValues)) 67 | } 68 | 69 | s = summer() 70 | 71 | if(url.exists("http://www.omegahat.org/RCurl/matrix.data")) 72 | getURL("http://www.omegahat.org/RCurl/matrix.data", write = chunkToLineReader(s$read)$read) 73 | } 74 | \keyword{IO} 75 | \concept{Web} 76 | \concept{HTTP} 77 | 78 | -------------------------------------------------------------------------------- /man/clone.Rd: -------------------------------------------------------------------------------- 1 | \name{clone} 2 | \alias{clone} 3 | \alias{clone,ANY-method} 4 | \alias{clone,CURLHandle-method} 5 | \alias{clone,environment-method} 6 | \alias{clone,CFILE-method} 7 | \title{Clone/duplicate an object} 8 | \description{ 9 | This is a generic function and methods for making a copy of an 10 | object such as a curl handle, C-level pointer to a file, etc. 11 | } 12 | \usage{ 13 | clone(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{the object to be cloned.} 17 | \item{\dots}{additional parameters for methods} 18 | } 19 | \value{ 20 | Typically, an object of the same class and \dQuote{value} 21 | as the input - \code{x}. 22 | } 23 | \author{ 24 | Duncan Temple Lang 25 | } 26 | 27 | \seealso{ 28 | \code{\link{dupCurlHandle}} 29 | } 30 | \examples{ 31 | h = getCurlHandle(verbose = TRUE) 32 | other = dupCurlHandle(h) 33 | curlSetOpt(curl = h, verbose = FALSE) 34 | } 35 | \keyword{programming} 36 | -------------------------------------------------------------------------------- /man/complete.Rd: -------------------------------------------------------------------------------- 1 | \name{complete} 2 | \alias{complete} 3 | \alias{complete,MultiCURLHandle-method} 4 | \title{Complete an asynchronous HTTP request} 5 | \description{ 6 | This is a generic function that is used within the 7 | RCurl package to force the completion of an 8 | HTTP request. If the request is asynchronous, 9 | this essentially blocks until the request is completed 10 | by repeatedly asking for more information to be 11 | retrieved from the HTTP connection. 12 | } 13 | \usage{ 14 | complete(obj, ...) 15 | } 16 | %- maybe also 'usage' for other objects documented here. 17 | \arguments{ 18 | \item{obj}{the object which is to be completed. This is typically a 19 | \code{\link{MultiCURLHandle-class}} instance.} 20 | \item{\dots}{additional arguments intended to be used by specific methods.} 21 | } 22 | \value{ 23 | The value is typically not of interest, but rather the side effect 24 | of processing the pending requests. 25 | } 26 | \references{ 27 | \url{http://curl.haxx.se}, specifically the multi interface of libcurl. 28 | } 29 | \author{Duncan Temple Lang} 30 | \seealso{ 31 | \code{\link{MultiCURLHandle-class}} 32 | \code{\link{push}}, \code{\link{pop}} 33 | } 34 | \examples{ 35 | if(url.exists("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl")) { 36 | 37 | f = system.file("NAMESPACE", package = "RCurl") 38 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 39 | "fileData" = fileUpload(f)) 40 | 41 | 42 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 43 | "fileData" = fileUpload("", 44 | paste(readLines(f), collapse = "\n"), 45 | "text/plain")) 46 | 47 | postForm("http://eeyore.ucdavis.edu/cgi-bin/testForm1.pl", 48 | "fileData" = fileUpload(f, 49 | paste(readLines(f), collapse = "\n") 50 | ), 51 | .opts = list(verbose = TRUE, header = TRUE)) 52 | } 53 | } 54 | \keyword{IO} 55 | 56 | -------------------------------------------------------------------------------- /man/curlError.Rd: -------------------------------------------------------------------------------- 1 | \name{curlError} 2 | \alias{curlError} 3 | \title{Raise a warning or error about a CURL problem} 4 | \description{ 5 | This function is called to raise an error or warning 6 | that arises from a curl operation when making a request. 7 | This is called from C code that encounters the error 8 | and this function is responsible for generating the error. 9 | } 10 | \usage{ 11 | curlError(type, msg, asError = TRUE) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{type}{the type of the error or a status code identifying the 16 | type of the error. Typically this is an integer value that 17 | identifies the type of the Curl error. The value corresponds 18 | to one of the enumerated value of type \code{CURLcode}.} 19 | \item{msg}{the error message, as a character vector of length 1} 20 | \item{asError}{a logical value that indicates whether to raise an 21 | error or a warning} 22 | } 23 | \value{ 24 | This calls \code{warning} or \code{stop} with the relevant condition 25 | object. 26 | The object is always of basic (S3) class 27 | \code{GenericCurlError, error, condition} 28 | or 29 | \code{GenericCurlError, warning, condition}. 30 | When the \code{type} value corresponds to a 31 | \code{CURLCode} value, the condition has the primary class given by that 32 | \code{CURLCode}'s name, e.g. \code{COULDNT_RESOLVE_HOST}, 33 | \code{TOO_MANY_REDIRECTS} (with the CURLE prefix removed). 34 | 35 | } 36 | \references{ 37 | libcurl documentation. 38 | } 39 | \author{ 40 | Duncan Temple Lang 41 | } 42 | 43 | \seealso{ 44 | \code{\link{curlPerform}} 45 | } 46 | \examples{ 47 | # This illustrates generating and catching an error. 48 | # We intentionally give a mis-spelled URL. 49 | tryCatch(curlPerform(url = "ftp.wcc.nrcs.usda.govx"), 50 | COULDNT_RESOLVE_HOST = function(x) cat("resolve problem\n"), 51 | error = function(x) cat(class(x), "got it\n")) 52 | } 53 | \keyword{programming} 54 | \keyword{IO} 55 | \concept{error handling} 56 | 57 | -------------------------------------------------------------------------------- /man/curlEscape.Rd: -------------------------------------------------------------------------------- 1 | \name{curlEscape} 2 | \alias{curlEscape} 3 | \alias{curlUnescape} 4 | \alias{curlPercentEncode} 5 | \title{Handle characters in URL that need to be escaped} 6 | \description{ 7 | These functions convert between URLs that are 8 | human-readable and those that have special characters 9 | escaped. For example, to send a URL with a space, 10 | we need to represent the space as \code{\%20}. 11 | 12 | \code{curlPercentEncode} uses a different format than the 13 | \code{curlEscape} 14 | function and this is needed for x-www-form-encoded POST submissions. 15 | } 16 | \usage{ 17 | curlEscape(urls) 18 | curlUnescape(urls) 19 | curlPercentEncode(x, amp = TRUE, codes = PercentCodes, post.amp = FALSE) 20 | } 21 | %- maybe also 'usage' for other objects documented here. 22 | \arguments{ 23 | \item{urls}{ a character vector giving the strings to be escaped or 24 | unescaped.} 25 | \item{x}{the strings to be encoded via the percent-encoding method} 26 | \item{amp}{a logical value indicating whether to encode \& 27 | characters.} 28 | \item{codes}{the named character vector giving the encoding map. The 29 | names are the characters we encode, the values are what we encode them 30 | as.} 31 | \item{post.amp}{a logical value controlling whether the resulting 32 | string is further processed to escape the percent (\%) prefixes with 33 | the code for percent, i.e. \%25.} 34 | } 35 | \details{ 36 | This calls \code{curl_escape} or \code{curl_unescape} in the libcurl library. 37 | } 38 | \value{ 39 | A character vector that has corresponding elements 40 | to the input with the characters escaped or not. 41 | } 42 | \references{ 43 | Curl homepage \url{http://curl.haxx.se} 44 | 45 | Percent encoding explained in \url{http://en.wikipedia.org/wiki/Percent-encoding} 46 | } 47 | \author{Duncan Temple Lang } 48 | 49 | \examples{ 50 | curlEscape("http://www.abc.com?x=a is a sentence&a b=and another") 51 | 52 | # Reverse it should get back original 53 | curlUnescape(curlEscape("http://www.abc.com?x=a is a sentence&a b=and another")) 54 | } 55 | \keyword{IO} 56 | 57 | 58 | -------------------------------------------------------------------------------- /man/curlGlobalInit.Rd: -------------------------------------------------------------------------------- 1 | \name{curlGlobalInit} 2 | \alias{curlGlobalInit} 3 | \alias{curlGlobalCleanup} 4 | %- Also NEED an '\alias' for EACH other topic documented here. 5 | \title{Start and stop the Curl library} 6 | \description{ 7 | These functions provide a way to both start/initialize 8 | and stop/uninitialize the libcurl engine. 9 | There is no need to call 10 | \code{curlGlobalInit} as it is done implicitly the 11 | first time one uses the libcurl facilities. 12 | However, this function does permit one to explicitly 13 | control how it is initialized. 14 | Specifically, on Windows one might want to 15 | avoid re-initializing the Win32 socket facilities 16 | if the host application (e.g. R) has already done this. 17 | 18 | \code{curlGlobalInit} should only be called once per R session. 19 | Subsequent calls will have no effect, or may confuse the libcurl engine. 20 | 21 | One can reclaim the resources the libcurl engine is 22 | consuming via the \code{curlGlobalCleanup} function 23 | when one no longer needs the libcurl facilities in 24 | an R session. 25 | } 26 | \usage{ 27 | curlGlobalInit(flags = c("ssl", "win32")) 28 | curlGlobalCleanup() 29 | } 30 | %- maybe also 'usage' for other objects documented here. 31 | \arguments{ 32 | \item{flags}{flags indicating which features to activate. 33 | These come from the \code{\link{CurlGlobalBits}} 34 | bit-field. The default is to activate both SSL and Win32 sockets 35 | (if on Windows). One can specify either the names of the features 36 | that are matched (via \code{\link{setBitIndicators}}) or 37 | the integer value. 38 | } 39 | } 40 | \value{ 41 | \code{curlGobalInit} returns a status code which should be 0. 42 | \code{curlGlobalCleanup} returns \code{NULL} in all cases. 43 | } 44 | 45 | 46 | \references{Curl homepage \url{http://curl.haxx.se}} 47 | \author{Duncan Temple Lang } 48 | 49 | \seealso{ 50 | \code{\link{getCurlHandle}} 51 | \code{\link{curlPerform}} 52 | } 53 | \examples{ 54 | # Activate only the SSL. 55 | curlGlobalInit("ssl") 56 | 57 | \dontrun{ 58 | # Don't run these automatically as we should only call this function 59 | # once per R session 60 | 61 | # Everything, the default. 62 | curlGlobalInit() 63 | 64 | # Nothing. 65 | curlGlobalInit("none") 66 | curlGlobalInit(0) 67 | } 68 | 69 | } 70 | \keyword{IO} 71 | -------------------------------------------------------------------------------- /man/curlOptions.Rd: -------------------------------------------------------------------------------- 1 | \name{curlOptions} 2 | \alias{curlOptions} 3 | \alias{getCurlOptionsConstants} 4 | \alias{getCurlOptionTypes} 5 | \alias{listCurlOptions} 6 | \alias{mapCurlOptNames} 7 | \alias{[<-.CURLOptions} 8 | \alias{[[<-.CURLOptions} 9 | \title{Constructor and accessors for CURLOptions objects} 10 | \description{ 11 | These functions provide a constructor 12 | and accessor methods 13 | for the (currently S3) class \code{CURLOptions}. 14 | This class is a way to group and manage options settings 15 | for CURL. 16 | These functions manage a named list of options 17 | where the names are elements of a fixed. 18 | Not all elements need be set, but 19 | these functions take care of expanding names 20 | to match the fixed set, while allowing callers 21 | to use abbreviated/partial names. 22 | Names that do not match (via \code{\link[base]{pmatch}}) 23 | will cause an error. 24 | 25 | The set of possible names is given by 26 | \code{names(getCurlOptionsConstants())} 27 | or more directly with \code{listCurlOptions()}. 28 | 29 | \code{mapCurlOptNames} handles the partial matching and 30 | expansion of the names of the options for all the functions 31 | that handle CURL options. 32 | Currently this uses \code{\link[base]{pmatch}} to 33 | perform the matching and so rejects words 34 | that are ambiguous, i.e. have multiple matches 35 | within the set of permissible option names. 36 | As a result, "head" will match both 37 | "header" and "headerfunction". 38 | We may change this behavior in the future, but 39 | we encourage using the full names for readability of code if nothing 40 | else. 41 | 42 | 43 | } 44 | \usage{ 45 | curlOptions(..., .opts = list()) 46 | getCurlOptionsConstants() 47 | \method{[}{CURLOptions}(x, i) <- value 48 | \method{[[}{CURLOptions}(x, i) <- value 49 | listCurlOptions() 50 | getCurlOptionTypes(opts = getCurlOptionsConstants()) 51 | } 52 | %"[<-.CURLOptions"(x, i, value) 53 | \arguments{ 54 | \item{\dots}{name-value pairs identifying the settings for the options 55 | of interest.} 56 | \item{.opts}{a named list of options, typically a previously created 57 | \code{CURLOptions} object. These are merged with the options 58 | specified in \code{\dots}.} 59 | \item{x}{a \code{CURLOptions} object} 60 | \item{i}{the name(s) of the option elements being accessed. 61 | These can be partial names matching elements in the set 62 | of known options. Other names will cause an error.} 63 | \item{value}{the values to assign to the options identified via \code{i}.} 64 | \item{opts}{the options whose type description are of interest in the call.} 65 | } 66 | \details{ 67 | These functions use \code{mapCurlOptNames} 68 | to match and hence expand the names the callers 69 | provide. 70 | } 71 | \value{ 72 | \code{curlOptions} returns an object 73 | of class \code{CURLOptions} which is simply 74 | a named list. 75 | 76 | \code{getCurlConstants} returns a named vector identifying 77 | the names of the possible options and their associated 78 | values. These values are used in the C code and also each integer 79 | encodes the type of the argument expected by the C code 80 | for that option. 81 | 82 | \code{getCurlOptionTypes} returns human-readable, 83 | heuristic descriptions of the types expected for the different options. 84 | These are integer/logical corresponding to "long" in the RCurl documentation; 85 | string/object pointer corresponding to "char *" or ; 86 | function corresponding to a function/routine pointer; 87 | large number corresponding to a \code{curl_off_t}. 88 | } 89 | 90 | \references{Curl homepage \url{http://curl.haxx.se}} 91 | \author{Duncan Temple Lang } 92 | 93 | \seealso{ 94 | \code{\link{curlPerform}} 95 | \code{\link{curlSetOpt}} 96 | } 97 | \examples{ 98 | 99 | tt = basicTextGatherer() 100 | myOpts = curlOptions(verbose = TRUE, header = TRUE, writefunc = tt[[1]]) 101 | 102 | # note that the names are expanded, e.g. writefunc is now writefunction. 103 | names(myOpts) 104 | 105 | myOpts[["header"]] 106 | 107 | myOpts[["header"]] <- FALSE 108 | 109 | # Using the abbreviation "hea" is an error as it matches 110 | # both 111 | # myOpts[["hea"]] <- FALSE 112 | 113 | # Remove the option from the list 114 | myOpts[["header"]] <- NULL 115 | } 116 | \keyword{IO} 117 | 118 | -------------------------------------------------------------------------------- /man/curlSetOpt.Rd: -------------------------------------------------------------------------------- 1 | \name{curlSetOpt} 2 | \alias{curlSetOpt} 3 | \title{Set values for the CURL options} 4 | \description{ 5 | This function allows us to set values for the 6 | possible options in the CURL data structure 7 | that defines the HTTP request. 8 | These options persist across calls in the 9 | \code{CURLHandle} object. 10 | } 11 | \usage{ 12 | curlSetOpt(..., .opts = list(), curl = getCurlHandle(), 13 | .encoding = integer(), .forceHeaderNames = FALSE, 14 | .isProtected = FALSE) 15 | } 16 | %- maybe also 'usage' for other objects documented here. 17 | \arguments{ 18 | \item{...}{a named list of curl options to set after the handle has 19 | been created.} 20 | \item{.opts}{a named list or \code{CURLOptions} object identifying the 21 | curl options for the handle.} 22 | \item{curl}{the \code{CURLHandle} object created earlier via 23 | a call to \code{\link{getCurlHandle}} or 24 | \code{\link{dupCurlHandle}}} 25 | \item{.encoding}{an integer or a string that explicitly identifies the 26 | encoding of the content that is returned by the HTTP server in its 27 | response to our query. The possible strings are 28 | \sQuote{UTF-8} or \sQuote{ISO-8859-1} 29 | and the integers should be specified symbolically 30 | as \code{CE_UTF8} and \code{CE_LATIN1}. 31 | Note that, by default, the package attempts to process the header of 32 | the HTTP response to determine the encoding. This argument is used 33 | when such information is erroneous and the caller knows the correct 34 | encoding. 35 | } 36 | \item{.forceHeaderNames}{a logical value which if \code{TRUE} 37 | allows the caller to explicitly indicate that the HTTPHEADER 38 | option needs to have the names prefixed to the strings. 39 | This removes any ambiguity caused by the presence of ':' in the 40 | values appearing to be the separator between the name and the value 41 | of the \code{name: value} pairs of the HTTP header.} 42 | \item{.isProtected}{ 43 | a logical vector (or value that is repeated) specifying which 44 | of the values in \dots and \code{.opts} need to be explicitly 45 | protected from garbage collection or not. 46 | The basic idea is that we specify \code{FALSE} if 47 | the value being set for the curl option may be garbage collected 48 | before the \code{curl} handle is garbage collected. This would leave 49 | the \code{curl} object in an inconsistent state, referring to an R 50 | object (i.e. an R function), which may be used after the R object has been garbage collected. 51 | } 52 | } 53 | \value{ 54 | An integer value giving the status of the return. 55 | This should be 0 as if there was an error in the libcurl 56 | mechiansim, we will throw it there. 57 | } 58 | 59 | \references{Curl homepage \url{http://curl.haxx.se}} 60 | \author{Duncan Temple Lang } 61 | 62 | \seealso{ 63 | \code{\link{getCurlHandle}} 64 | \code{\link{dupCurlHandle}} 65 | } 66 | \examples{ 67 | if(url.exists("http://www.omegahat.org")) { 68 | 69 | curl = getCurlHandle() 70 | # Note the header that extends across two lines with the second line 71 | # prefixed with white space. 72 | curlSetOpt( .opts = list(httpheader = c(Date = "Wed, 1/2/2000 10:01:01", 73 | foo="abc\n extra line"), verbose = TRUE), 74 | curl = curl) 75 | ans = getURL("http://www.omegahat.org", curl = curl) 76 | } 77 | } 78 | \keyword{IO} 79 | 80 | 81 | -------------------------------------------------------------------------------- /man/curlVersion.Rd: -------------------------------------------------------------------------------- 1 | \name{curlVersion} 2 | \alias{curlVersion} 3 | \title{Information describing the Curl library} 4 | \description{ 5 | This function queries the Curl library to provide information 6 | about its characteristics when it was compiled. 7 | This tells the user about its capabilities and can be used 8 | to determine strategies. 9 | } 10 | \usage{ 11 | curlVersion(id = 0) 12 | } 13 | \arguments{ 14 | \item{id}{an integer value between 0 and 3 inclusive. 15 | The idea is that one specifies the identifier for the version of 16 | interest. 17 | In fact, all values seem to yield the same result. 18 | } 19 | } 20 | \value{ 21 | A list 22 | \item{age}{integer giving the number of this libcurl, 0 is FIRST, 1 is 23 | SECOND, 2 is THIRD} 24 | \item{version}{the version identifier as a string, e.g. \code{"7.12.0"}} 25 | \item{version_num}{the value as an integer} 26 | \item{host}{the machine on which the libcurl was configured/built.} 27 | \item{features}{a named integer vector of bits indicating what 28 | features of libcurl were configured and built into this version. 29 | These are features such as 30 | ipv6, ssl, libz, largefile, ntlm (Microsoft "authorization").} 31 | \item{ssl_version}{the string identifying the SSL version.} 32 | \item{ssl_version_num}{the number identifying the SSL version} 33 | \item{libz_version}{the string identifying the version of libz.} 34 | \item{protocols}{a character vector of the supported HTTP protocols, 35 | e.g. http, https, ftp, ldap, gopher, telnet} 36 | \item{ares}{name of the asynchronous DNS (domain name service) lookup 37 | library. This is often simply the empty string indicating it is not there. 38 | } 39 | \item{ares_num}{the number for the ares library} 40 | \item{libidn}{the name of the IDN (internationalized domain names) 41 | library being used. This field only appears in version 3 of libcurl. 42 | If you are using version 2 (e.g. curl-7.11.2), this will be 43 | \code{NA}. 44 | An empty string indicates that the field is present, but has no value. 45 | } 46 | 47 | See the man page for \code{curl_version_info} 48 | for a description of these fields. 49 | \code{features} in R is a named integer vector 50 | detailing the different features. 51 | } 52 | \references{Curl homepage \url{http://curl.haxx.se}} 53 | \author{Duncan Temple Lang } 54 | 55 | \seealso{ 56 | \code{curl_version_info} in the libcurl documentation. 57 | } 58 | \examples{ 59 | curlVersion() 60 | } 61 | \keyword{IO} 62 | \concept{reflectance} 63 | -------------------------------------------------------------------------------- /man/enums.Rd: -------------------------------------------------------------------------------- 1 | \name{CURLEnums} 2 | \alias{|,BitwiseValue,BitwiseValue-method} 3 | \alias{c,BitwiseValue-method} 4 | \alias{&,BitwiseValue-method} 5 | \alias{&,BitwiseValue,BitwiseValue-method} 6 | \alias{[,EnumDef-method} 7 | \alias{[,EnumDef,ANY-method} 8 | \alias{coerce,BitwiseValue,numeric-method} 9 | \alias{curl_infotype-class} 10 | \alias{CURLcode-class} 11 | \alias{curl_proxytype-class} 12 | \alias{curl_usessl-class} 13 | \alias{curl_ftpccc-class} 14 | \alias{curl_ftpauth-class} 15 | \alias{curl_ftpcreatedir-class} 16 | \alias{curl_ftpmethod-class} 17 | \alias{CURL_NETRC_OPTION-class} 18 | \alias{CURLFORMcode-class} 19 | \alias{curl_TimeCond-class} 20 | \alias{curl_closepolicy-class} 21 | \alias{coerce,integer,curl_infotype-method} 22 | \alias{coerce,integer,CURLcode-method} 23 | \alias{coerce,integer,curl_proxytype-method} 24 | \alias{coerce,integer,curl_usessl-method} 25 | \alias{coerce,integer,curl_ftpccc-method} 26 | \alias{coerce,integer,curl_ftpauth-method} 27 | \alias{coerce,integer,curl_ftpcreatedir-method} 28 | \alias{coerce,integer,curl_ftpmethod-method} 29 | \alias{coerce,integer,CURL_NETRC_OPTION-method} 30 | \alias{coerce,integer,CURLFORMcode-method} 31 | \alias{coerce,integer,curl_TimeCond-method} 32 | \alias{coerce,integer,curl_closepolicy-method} 33 | \alias{coerce,numeric,curl_infotype-method} 34 | \alias{coerce,numeric,CURLcode-method} 35 | \alias{coerce,numeric,curl_proxytype-method} 36 | \alias{coerce,numeric,curl_usessl-method} 37 | \alias{coerce,numeric,curl_ftpccc-method} 38 | \alias{coerce,numeric,curl_ftpauth-method} 39 | \alias{coerce,numeric,curl_ftpcreatedir-method} 40 | \alias{coerce,numeric,curl_ftpmethod-method} 41 | \alias{coerce,numeric,CURL_NETRC_OPTION-method} 42 | \alias{coerce,numeric,CURLFORMcode-method} 43 | \alias{coerce,numeric,curl_TimeCond-method} 44 | \alias{coerce,numeric,curl_closepolicy-method} 45 | \alias{coerce,character,curl_infotype-method} 46 | \alias{coerce,character,CURLcode-method} 47 | \alias{coerce,character,curl_proxytype-method} 48 | \alias{coerce,character,curl_usessl-method} 49 | \alias{coerce,character,curl_ftpccc-method} 50 | \alias{coerce,character,curl_ftpauth-method} 51 | \alias{coerce,character,curl_ftpcreatedir-method} 52 | \alias{coerce,character,curl_ftpmethod-method} 53 | \alias{coerce,character,CURL_NETRC_OPTION-method} 54 | \alias{coerce,character,CURLFORMcode-method} 55 | \alias{coerce,character,curl_TimeCond-method} 56 | \alias{coerce,character,curl_closepolicy-method} 57 | \title{Classes and coercion methods for enumerations in libcurl} 58 | \description{These are classes and coercion methods 59 | for enumeration types in RCurl corresponding to symbolic 60 | constants in libcurl. 61 | The actual constants are not exported, but are defined within 62 | the package. So we can use them with code such as 63 | \code{RCurl:::CURLINFO_DATA_IN}. 64 | } 65 | %\usage{} 66 | %\value{} 67 | \author{Duncan Temple Lang} 68 | \keyword{programming} 69 | -------------------------------------------------------------------------------- /man/fileUpload.Rd: -------------------------------------------------------------------------------- 1 | \name{fileUpload} 2 | \alias{fileUpload} 3 | \title{Specify information about a file to upload in an HTTP request} 4 | \description{ 5 | This function creates an object that describes all of the details 6 | needed to include the contents of a file in the submission of an 7 | HTTP request, typically a multi-part form submitted via 8 | \code{\link{postForm}}. 9 | The idea is that we want to transfer the contents of a file or a 10 | buffer of data within R that is not actually stored on the file 11 | system but is resident in the R session. We want to be able to 12 | specify either the name of the file and have RCurl read the contents 13 | when they are needed, or alternatively specify the contents ourselves 14 | if it makes sense that we already have the contents in R, e.g. that 15 | they are dynamically generated. Additionally, we may need to specify 16 | the type of data in the file/buffer via the Content-Type field for 17 | this parameter in the request. 18 | This function allows us to specify either the file name or contents 19 | and optionally the content type. 20 | 21 | This is used as an element in of the \code{params} argument 22 | \code{\link{postForm}} and the native C code understands and processes 23 | objects returned from this function. 24 | 25 | } 26 | \usage{ 27 | fileUpload(filename = character(), contents = character(), contentType = character()) 28 | } 29 | %- maybe also 'usage' for other objects documented here. 30 | \arguments{ 31 | \item{filename}{the name of the file that RCurl is to pass in the form 32 | submission/HTTP request. If this is specified and no value for 33 | \code{contents} is given, this has to identify a valid/existing 34 | file. If \code{contents} is specified, any value provided here 35 | is used simply to provide information about the provenance of the 36 | data in contents. The file need not exist. 37 | The path is expanded by the function, so \code{~} can be used. 38 | } 39 | \item{contents}{ either a character vector or a \code{raw} vector 40 | giving the contents or data to be submitted. If this is provided, 41 | \code{filename} is not needed and not read. 42 | } 43 | \item{contentType}{a character string (vector of length 1) giving the 44 | type of the content, e.g. text/plain, text/html, which helps the 45 | server receiving the data to interpret the contents. If omitted, 46 | this is omitted from the form submission and the recipient left to guess. 47 | } 48 | } 49 | \value{ 50 | An object of (S3) class \code{FileUploadInfo} with fields 51 | \code{filename}, \code{contents} and \code{contentType}. 52 | } 53 | 54 | \references{ 55 | \url{http://curl.haxx.se} 56 | } 57 | \author{Duncan Temple Lang} 58 | \seealso{ 59 | \code{\link{postForm}} 60 | } 61 | %\examples{} 62 | \keyword{IO} 63 | -------------------------------------------------------------------------------- /man/findHTTPHeaderEncoding.Rd: -------------------------------------------------------------------------------- 1 | \name{findHTTPHeaderEncoding} 2 | \alias{findHTTPHeaderEncoding} 3 | \title{Find the encoding of the HTTP response from the HTTP header} 4 | \description{ 5 | This function is currently made available so it can be called 6 | from C code to find the charset from the HTTP header in the 7 | response from an HTTP server. It maps this charset value 8 | to one of the known R encodings (UTF-8 or LATIN1) 9 | or returns the native encoding. 10 | 11 | This will most likely be removed in the future. 12 | } 13 | \usage{ 14 | findHTTPHeaderEncoding(str) 15 | } 16 | \arguments{ 17 | \item{str}{one or more lines from the HTTP header} 18 | } 19 | \value{ 20 | \code{NA} or an integer value indicating the encoding 21 | to be used. This integer corresponds to the \code{cetype_t} enumeration 22 | in Rinternals.h. 23 | } 24 | \references{Writing R Extensions Manual and the section(s) on character encodings} 25 | \author{Duncan Temple Lang} 26 | 27 | \examples{ 28 | findHTTPHeaderEncoding("Content-Type: text/html;charset=ISO-8859-1\r\n") 29 | findHTTPHeaderEncoding("Content-Type: text/html; charset=utf-8\r\n") 30 | } 31 | \keyword{IO} 32 | \keyword{programming} 33 | 34 | -------------------------------------------------------------------------------- /man/ftpUpload.Rd: -------------------------------------------------------------------------------- 1 | \name{ftpUpload} 2 | \alias{ftpUpload} 3 | \title{Upload content via FTP} 4 | \description{ 5 | This function is a relatively simple wrapper for \code{\link{curlPerform}} 6 | which allows the caller to upload a file to an FTP server. 7 | One can upload the contents of a file from the local file system or 8 | the contents already in memory. 9 | One specifies the FTP server and the fully-qualified file name and path where the contents are 10 | to be stored. 11 | One can specify the user login and password via the \code{userpwd} option 12 | for \code{\link{curlPerform}} via the \dots parameter, or 13 | one can put this information directly in the target URL (i.e. \code{to}) 14 | in the form \code{ftp://login:password@machine.name/path/to/file}. 15 | 16 | This function can handle binary or text content. 17 | } 18 | \usage{ 19 | ftpUpload(what, to, asText = inherits(what, "AsIs") || is.raw(what), 20 | ..., curl = getCurlHandle()) 21 | } 22 | %- maybe also 'usage' for other objects documented here. 23 | \arguments{ 24 | \item{what}{the name of a local file or the contents to be uploaded. This can 25 | can be text or binary content. This can also be an open connection. 26 | If this value is \code{raw} or has class \code{AsIs} by being enclosed within \code{I()}, 27 | it is treated as literal content.} 28 | \item{to}{the URL to which the content is to be uploaded. This should be the ftp server 29 | with the prefix \code{ftp://} and optionally the 30 | user login and password, and then the path to the file in which the 31 | content is to be stored.} 32 | \item{asText}{a logical value indicating whether to treat the value of \code{what} 33 | as content, be it text or raw/binary vector. Otherwise, \code{what} is 34 | treated as the name of a file.} 35 | \item{\dots}{additional arguments passed on to \code{\link{curlPerform}}.} 36 | \item{curl}{the curl handle to use for the \code{\link{curlPerform}}} 37 | } 38 | \value{ 39 | The result of the \code{\link{curlPerform}} call. 40 | } 41 | \references{FTP, libcurl} 42 | \author{Duncan Temple Lang} 43 | \note{ 44 | One can also provide additional FTP commands that are executed 45 | before and after the upload as part of the request. 46 | Use the prequote, quote, and postquote options in \code{\link{curlPerform}} for these. 47 | } 48 | \seealso{ 49 | \code{\link{curlPerform}} 50 | \code{\link{getCurlHandle}} 51 | } 52 | \examples{ 53 | \dontrun{ 54 | 55 | ftpUpload(I("Some text to be uploaded into a file\nwith several lines"), 56 | "ftp://login:password@laptop17/ftp/zoe", 57 | ) 58 | 59 | ftpUpload(I("Some text to be uploaded into a file\nwith several lines"), 60 | "ftp://laptop17/ftp/zoe", 61 | userpwd = "login:password" 62 | ) 63 | 64 | ftpUpload(system.file("examples", "system.png", package = "RCurl"), 65 | "ftp://login:password@laptop17/ftp/Election.rda", 66 | postquote = c("CWD subdir", "RNFR Election.rda", "RNTO ElectionPolls.rda") 67 | ) 68 | } 69 | } 70 | \keyword{IO} 71 | \keyword{programming} 72 | -------------------------------------------------------------------------------- /man/getBinaryURL.Rd: -------------------------------------------------------------------------------- 1 | \name{getBinaryURL} 2 | \alias{getBinaryURL} 3 | \title{Download binary content} 4 | \description{ 5 | This function allows one to download binary content. 6 | This is a convenience function that is a call to 7 | \code{\link{getURL}} with suitable values 8 | for the \code{write} and \code{file} options 9 | for the Curl handle. These take care of processing 10 | the body of the response to the Curl request into a 11 | vector of "raw" elements. 12 | 13 | Binary content from POST forms or other requests that are not simple 14 | URL requests can be implemented using the same approach as this 15 | function, i.e., specifying the same values as in the body of this function for 16 | \code{write} and \code{file} in the call to \code{\link{curlPerform}}. 17 | 18 | } 19 | \usage{ 20 | getBinaryURL(url, ..., .opts = list(), curl = getCurlHandle(), 21 | .buf = binaryBuffer(.len), .len = 5000) 22 | } 23 | %- maybe also 'usage' for other objects documented here. 24 | \arguments{ 25 | \item{url}{the URL identifying the content to download. 26 | This can be a regular URL or a 27 | \code{application/x-www-form-urlencoded} URL, 28 | i.e. with name=value parameters appended to the location via a ?, 29 | and separated from each other via a \&.} 30 | \item{\dots}{additional arguments that are passed to \code{\link{getURL}}.} 31 | \item{.opts}{a list of named values that are passed to 32 | \code{\link{getURL}} as the \code{.opts} argument.} 33 | \item{curl}{an optional curl handle used in \code{\link{curlPerform}} 34 | that has been created previously and is to be reused for this 35 | request. 36 | This allows the R user to reuse a curl handle that already has a 37 | connection to the server or has settings for options that have been 38 | set previously.} 39 | \item{.buf}{a raw vector in which to insert the body of the response. 40 | This is a parameter to allow the caller to reuse an existing buffer.} 41 | \item{.len}{an non-negative integer which is used as the length for 42 | the buffer in which to store the binary data in the response. 43 | The buffer is extended if it is not big enough but this allows the 44 | caller to provide context specific knowledge about the length of the 45 | response, e.g. the size of the file being downloaded, and 46 | avoid expanding the buffer as the material is being processed. 47 | } 48 | } 49 | \value{ 50 | A "raw" vector. 51 | } 52 | \author{Duncan Temple Lang} 53 | \seealso{ 54 | \code{\link{getURL}} 55 | \code{\link[base]{raw}} 56 | %\code{\link[Rcompression]{gunzip}} 57 | \code{gunzip} in the \code{Rcompression} package. 58 | } 59 | \examples{ 60 | u = "http://www.omegahat.org/RCurl/data.gz" 61 | 62 | if(url.exists(u)) { 63 | 64 | content = getBinaryURL(u) 65 | 66 | if(require(Rcompression)) { 67 | x = gunzip(content) 68 | read.csv(textConnection(x)) 69 | } else { 70 | tmp = tempfile() 71 | write(content, file = tmp) 72 | read.csv(gzfile(tmp)) 73 | } 74 | 75 | 76 | # Working from the Content-Type in the header of the HTTP response. 77 | h = basicTextGatherer() 78 | content = getBinaryURL(u, .opts = list(headerfunction = h$update)) 79 | header = parseHTTPHeader(h$value()) 80 | type = strsplit(header["Content-Type"], "/")[[1]] 81 | 82 | if(type[2] \%in\% c("x-gzip", "gzip")) { 83 | if(require(Rcompression)) 84 | x = gunzip(content) 85 | } 86 | 87 | } 88 | } 89 | \keyword{IO} 90 | \keyword{programming} 91 | \concept{binary data} 92 | -------------------------------------------------------------------------------- /man/getBitIndicators.Rd: -------------------------------------------------------------------------------- 1 | \name{getBitIndicators} 2 | \alias{getBitIndicators} 3 | \alias{setBitIndicators} 4 | \title{Operate on bit fields} 5 | \description{ 6 | The \code{getBitIndicators} function decompose a value into its respective 7 | bit components. 8 | The \code{setBitIndicators} combines individual components into a 9 | single number 10 | to "set" a bit field value. 11 | } 12 | \usage{ 13 | getBitIndicators(val, defs) 14 | setBitIndicators(vals, defs) 15 | } 16 | %- maybe also 'usage' for other objects documented here. 17 | \arguments{ 18 | \item{val}{the value to break up into the bit field components.} 19 | \item{defs}{the named integer vector that defines the bit field elements.} 20 | \item{vals}{the individual components that are to be combined into a 21 | single integer value representing the collection of components. 22 | These can be given as names or integer values that correspond to the 23 | elements in the defs, either by name or value. 24 | } 25 | } 26 | \value{ 27 | \code{getBitIndicators} returns a named integer vector representing 28 | the components of the bit field in the value. 29 | The names of the vector give the symbolic elements that were set in 30 | the value. 31 | 32 | \code{setBitIndicators} returns a single integer value representing 33 | the value from combining the different components (e.g. ORing the bits 34 | of the different values). 35 | } 36 | 37 | \references{Curl homepage \url{http://curl.haxx.se}} 38 | \author{Duncan Temple Lang } 39 | 40 | 41 | \seealso{ 42 | The features field in \code{\link{curlVersion}}. 43 | } 44 | \examples{ 45 | getBitIndicators(7, c(A = 1, B = 2, C = 4)) 46 | getBitIndicators(3, c(A = 1, B = 2, C = 4)) 47 | getBitIndicators(5, c(A = 1, B = 2, C = 4)) 48 | } 49 | \keyword{manip} 50 | 51 | 52 | -------------------------------------------------------------------------------- /man/getCurlErrorClassNames.Rd: -------------------------------------------------------------------------------- 1 | \name{getCurlErrorClassNames} 2 | \alias{getCurlErrorClassNames} 3 | \title{Retrieve names of all curl error classes} 4 | \description{ 5 | This function returns the names of all of the 6 | error classes that curl can raise as a result 7 | of a request. You can use these names 8 | in calls to \code{tryCatch} 9 | to identify the class of the error for which you 10 | want to provide an error handler. 11 | } 12 | \usage{ 13 | getCurlErrorClassNames() 14 | } 15 | \value{ 16 | A character vector 17 | } 18 | \references{ 19 | libcurl documentation 20 | } 21 | \author{ 22 | Duncan Temple Lang 23 | } 24 | \seealso{ 25 | \code{\link[base]{tryCatch}} 26 | \code{\link{curlPerform}} and higher-level functions 27 | for making requests. 28 | } 29 | %\examples{} 30 | \keyword{programming} 31 | -------------------------------------------------------------------------------- /man/getCurlHandle.Rd: -------------------------------------------------------------------------------- 1 | \name{getCurlHandle} 2 | \alias{getCurlHandle} 3 | \alias{getCurlMultiHandle} 4 | \alias{dupCurlHandle} 5 | \title{Create libcurl handles} 6 | \description{ 7 | These functions create and duplicate curl handles 8 | for use in calls to the HTTP facilities provided by 9 | that low-level language and this R-level interface. 10 | A curl handle is an opaque data type that contains a 11 | reference to the internal C-level data structure 12 | of libcurl for performing HTTP requests. 13 | 14 | The \code{getCurlMutliHandle} returns an object 15 | that can be used for concurrent, multiple requests. 16 | It is quite different from the regular curl handle 17 | and again, should be treated as an opaque data type. 18 | } 19 | \usage{ 20 | getCurlHandle(..., .opts = NULL, .encoding = integer(), 21 | .defaults = getOption("RCurlOptions")) 22 | dupCurlHandle(curl, ..., .opts = NULL, .encoding = integer()) 23 | getCurlMultiHandle(..., .handles = list(...)) 24 | } 25 | \arguments{ 26 | \item{curl}{the existing curl handle that is to be duplicated} 27 | \item{...}{a named list of curl options to set after the handle has 28 | been created. For \code{getCurlMultiHandle}, these values are 29 | invidivual curl handle objects, created via \code{getCurlHandle} or \code{dupCurlHandle}. } 30 | \item{.opts}{a named list or \code{CURLOptions} object identifying the 31 | curl options for the handle. These and the \code{...} arguments are 32 | used after the handle has been created.} 33 | \item{.encoding}{an integer or a string that explicitly identifies the 34 | encoding of the content that is returned by the HTTP server in its 35 | response to our query. The possible strings are 36 | \sQuote{UTF-8} or \sQuote{ISO-8859-1} 37 | and the integers should be specified symbolically 38 | as \code{CE_UTF8} and \code{CE_LATIN1}. 39 | Note that, by default, the package attempts to process the header of 40 | the HTTP response to determine the encoding. This argument is used 41 | when such information is erroneous and the caller knows the correct 42 | encoding. 43 | } 44 | \item{.defaults}{a collection of default values taken from R's 45 | global/session options. This is a parameter so that one can override 46 | it if necessary.} 47 | \item{.handles}{a list of curl handle objects that are used as the 48 | individual request handles within the multi-asynchronous requests} 49 | } 50 | \details{ 51 | These functions create C-level data structures. 52 | } 53 | \value{ 54 | An object of class \code{CURLHandle} 55 | which is simply a pointer to the memory for the C 56 | structure. 57 | } 58 | \references{Curl homepage \url{http://curl.haxx.se}} 59 | \author{Duncan Temple Lang } 60 | 61 | 62 | \seealso{ 63 | \code{\link{getURL}} 64 | \code{\link{curlPerform}} 65 | } 66 | \examples{ 67 | 68 | options(RCurlOptions = list(verbose = TRUE, 69 | followlocation = TRUE, 70 | autoreferer = TRUE, 71 | nosignal = TRUE)) 72 | if(url.exists("http://www.omegahat.org/RCurl")) { 73 | x = getURL("http://www.omegahat.org/RCurl") 74 | # here we override one of these. 75 | x = getURL("http://www.omegahat.org/RCurl", verbose = FALSE) 76 | } 77 | } 78 | \keyword{IO} 79 | 80 | 81 | -------------------------------------------------------------------------------- /man/getCurlInfo.Rd: -------------------------------------------------------------------------------- 1 | \name{getCurlInfo} 2 | \alias{getCurlInfo} 3 | \alias{getCurlInfoConstants} 4 | \title{Access information about a CURL request} 5 | \description{ 6 | This function provides access to data about a previously 7 | executed CURL request that is accessible via a 8 | \code{CURLHandle} object. 9 | This means, of course, that one must have access to the \code{CURLHandle} 10 | object. 11 | The information one can get includes items such as the name of the 12 | file (potentially containing redirects), download time, 13 | 14 | See \code{\link{getCurlInfoConstants}} for the names of the possible fields. 15 | } 16 | \usage{ 17 | getCurlInfo(curl, which = getCurlInfoConstants()) 18 | getCurlInfoConstants() 19 | } 20 | %- maybe also 'usage' for other objects documented here. 21 | \arguments{ 22 | \item{curl}{the \code{CURLHandle} object used to perform the request. 23 | This is a reference to an opaque internal C-level data structure that is 24 | provided and used by libcurl to make a request.} 25 | \item{which}{identifiers for the elements of interest. 26 | These can be specified by integer value or by name. 27 | The names are matched against those in the 28 | \code{\link{getCurlInfoConstants}}}. 29 | } 30 | \details{ 31 | This is an interface to the \code{get_curl_info} routine in 32 | the libcurl package. 33 | } 34 | \value{ 35 | A named list whose elements correspond 36 | to the requested fields. 37 | The names are expanded to match the names of these 38 | fields and the values are either strings or integer values. 39 | } 40 | 41 | \references{Curl homepage \url{http://curl.haxx.se}} 42 | \author{Duncan Temple Lang } 43 | 44 | 45 | 46 | \seealso{ 47 | \code{\link{curlPerform}} 48 | \code{\link{getURL}} 49 | \code{\link{getCurlHandle}} 50 | } 51 | \examples{ 52 | if(url.exists("http://www.omegahat.org/RCurl/index.html")) { 53 | curl = getCurlHandle() 54 | getURL("http://www.omegahat.org/RCurl/index.html", curl = curl) 55 | getCurlInfo(curl) 56 | rm(curl) # release the curl! 57 | } 58 | } 59 | \keyword{IO} 60 | 61 | -------------------------------------------------------------------------------- /man/getFormParams.Rd: -------------------------------------------------------------------------------- 1 | \name{getFormParams} 2 | \alias{getFormParams} 3 | \title{Extract parameters from a form query string} 4 | \description{ 5 | This function facilitates getting the parameter names and values 6 | from a URL that is an parameterized HTML query. 7 | 8 | This is motivated by a function from Chris Davis and Delft University. 9 | } 10 | \usage{ 11 | getFormParams(query, isURL = grepl("^(http|\\\\?)", query)) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{query}{the query string or full URL containing the query} 16 | \item{isURL}{a logical value. If \code{TRUE}, \code{query} is 17 | the full URL and we need to extract the sub-string representing the 18 | parameters. If \code{isURL} is \code{FALSE}, then \code{query} 19 | is assumed to be just the string containing the parameters. 20 | } 21 | } 22 | \value{ 23 | A named character vector 24 | giving the parameter values The names are the parameter names. 25 | } 26 | \author{ 27 | Duncan Temple Lang 28 | } 29 | 30 | \examples{ 31 | if(url.exists("http://www.omegahat.org/foo/bob.R")) { 32 | 33 | getFormParams("http://www.omegahat.org/foo/bob.R?xyz=1&abc=verylong") 34 | 35 | getFormParams("xyz=1&abc=verylong") 36 | getFormParams("xyz=1&abc=&on=true") 37 | getFormParams("xyz=1&abc=") 38 | } 39 | } 40 | % Add one or more standard keywords, see file 'KEYWORDS' in the 41 | % R documentation directory. 42 | \keyword{programming} 43 | \keyword{interface} 44 | 45 | -------------------------------------------------------------------------------- /man/guessMIMEType.Rd: -------------------------------------------------------------------------------- 1 | \name{guessMIMEType} 2 | \alias{guessMIMEType} 3 | \title{Infer the MIME type from a file name} 4 | \description{ 5 | This function returns the MIME type, i.e. part of the value 6 | used in the Content-Type for an HTTP request/response 7 | or in email to identify the nature of the content. 8 | This is a string such as "text/plain" or "text/xml" 9 | or "image/png". 10 | 11 | The function consults an R object constructed 12 | by reading a Web site of known MIME types (not necessarily all) 13 | and matching the extension of the file name to the names of that table. 14 | } 15 | \usage{ 16 | guessMIMEType(name, default = NA) 17 | } 18 | %- maybe also 'usage' for other objects documented here. 19 | \arguments{ 20 | \item{name}{character vector of file names} 21 | \item{default}{the value to use if no MIME type is found in the table 22 | for the given file name/extension.} 23 | } 24 | \value{ 25 | A character vector giving the MIME types for each element of \code{name}. 26 | } 27 | \references{ 28 | The table of MIME types and extensions was programmatically extracted 29 | from \url{http://www.webmaster-toolkit.com/mime-types.shtml} or 30 | \url{http://reference.sitepoint.com/html/mime-types-full} with 31 | \code{ 32 | tbls = readHTMLTable("http://www.webmaster-toolkit.com/mime-types.shtml") 33 | tmp = tbls[[1]][-1,] 34 | mimeTypeExtensions = structure(as.character(tmp[[2]]), names = gsub("^\\.", "", tmp[[1]])) 35 | save(mimeTypeExtensions, file = "data/mimeTypeExtensions.rda") 36 | } 37 | The IANA list is not as convenient to programmatically compile. 38 | \url{http://www.ltsw.se/knbase/internet/mime.htp} 39 | } 40 | \author{ 41 | Duncan Temple Lang 42 | } 43 | 44 | 45 | \seealso{ 46 | Uploading file. 47 | } 48 | \examples{ 49 | guessMIMEType(c("foo.txt", "foo.png", "foo.jpeg", "foo.Z", "foo.R")) 50 | 51 | guessMIMEType("foo.bob") 52 | guessMIMEType("foo.bob", "application/x-binary") 53 | } 54 | \keyword{IO} 55 | 56 | -------------------------------------------------------------------------------- /man/httpPUT.Rd: -------------------------------------------------------------------------------- 1 | \name{httpPUT} 2 | \alias{httpPUT} 3 | \alias{httpPOST} 4 | \alias{httpGET} 5 | \alias{httpDELETE} 6 | \alias{httpHEAD} 7 | \alias{httpOPTIONS} 8 | \title{Simple high-level functions for HTTP PUT and DELETE} 9 | \description{ 10 | These two functions are simple, high-level functions 11 | that implement the HTTP request methods PUT and DELETE. 12 | These can also be done by specifying the method 13 | type using the curl option \code{customrequest}. 14 | These functions merely provide a convenience 15 | wrapper for \code{\link{getURLContent}} 16 | with the HTTP method specified. 17 | } 18 | \usage{ 19 | httpPUT(url, content, ..., curl = getCurlHandle()) 20 | httpPOST(url, ..., curl = getCurlHandle()) 21 | httpDELETE(url, ..., curl = getCurlHandle()) 22 | httpGET(url, ..., curl = getCurlHandle()) 23 | httpHEAD(url, ..., curl = getCurlHandle()) 24 | httpOPTIONS(url, ..., curl = getCurlHandle()) 25 | } 26 | \arguments{ 27 | \item{url}{the URL of the server to which the HTTP request is to be 28 | made} 29 | \item{content}{the value that is to be used as the content of the 30 | \code{PUT} request. This can be a character or a \code{raw} object.} 31 | \item{\dots}{additional arguments passed to \code{\link{getURLContent}}} 32 | \item{curl}{the curl handle to be used to make the request} 33 | } 34 | \value{ 35 | The content returned by the server as a result of the request. 36 | } 37 | \author{ 38 | Duncan Temple Lang 39 | } 40 | 41 | \seealso{ 42 | \code{\link{getURLContent}} 43 | } 44 | \examples{ 45 | \dontrun{ 46 | # create a database in a CouchDB server 47 | httpPUT("http://127.0.0.1:5984/temp_db") 48 | 49 | # Insert an entry into an ElasticSearch dabtabase. 50 | httpPUT("http://localhost:9200/a/b/axyz", '{"abc" : 123}') 51 | 52 | # Then delete the database 53 | httpDELETE("http://127.0.0.1:5984/temp_db") 54 | } 55 | } 56 | \keyword{programming} 57 | \concept{HTTP} 58 | -------------------------------------------------------------------------------- /man/isBinaryContent.Rd: -------------------------------------------------------------------------------- 1 | \name{isBinaryContent} 2 | \alias{isBinaryContent} 3 | \alias{isBinaryFile} 4 | \title{Determines if content appears to be text or binary} 5 | \description{ 6 | These functions attempt to guess if the content is binary or text 7 | by consulting the MIME type or the extension of the file name. 8 | These are made available via the package to allow others to use them 9 | when processing low-level HTTP responses. 10 | } 11 | \usage{ 12 | isBinaryContent(header, type = getContentType(header)[1], 13 | textTypes = getOption("text.content.types", textContentTypes)) 14 | } 15 | \arguments{ 16 | \item{header}{the header from the HTTP response which delivered the content} 17 | \item{type}{the MIME type} 18 | \item{textTypes}{a character vector giving the MIME types that identify text content} 19 | } 20 | \value{ 21 | A logical value 22 | } 23 | \references{ 24 | \url{http://www.webmaster-toolkit.com/mime-types.shtml} 25 | } 26 | \author{ 27 | Duncan Temple Lang 28 | } 29 | 30 | \seealso{ 31 | \code{\link{getURLContent}}, \code{\link{dynCurlReader}} 32 | } 33 | \examples{ 34 | z = getURLContent("http://www.omegahat.org/RCurl/data.gz", header = TRUE) 35 | z$header["Content-Type"] 36 | isBinaryContent( z$header["Content-Type"] ) 37 | 38 | z = getURLContent("http://www.omegahat.org/RCurl/index.html", header = TRUE) 39 | z$header["Content-Type"] 40 | isBinaryContent( z$header["Content-Type"] ) 41 | } 42 | \keyword{programming} 43 | 44 | -------------------------------------------------------------------------------- /man/merge.list.Rd: -------------------------------------------------------------------------------- 1 | \name{merge.list} 2 | \alias{merge.list} 3 | \title{Method for merging two lists by name} 4 | \description{ 5 | This is a method that merges the contents of one list 6 | with another by adding the named elements in the second 7 | that are not in the first. 8 | In other words, the first list is the target template, 9 | and the second one adds any extra elements that it has. 10 | } 11 | \usage{ 12 | merge.list(x, y, ...) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{x}{the list to which elements will be added} 17 | \item{y}{the list which will supply additional elements to \code{x} 18 | that are not already there by name. } 19 | \item{\dots}{not used.} 20 | } 21 | \value{ 22 | A named list whose name set is the union of the elements 23 | in names of x and y and whose values are those taken 24 | from y and then with those in x, overwriting if necessary. 25 | } 26 | \references{Curl homepage \url{http://curl.haxx.se}} 27 | \author{Duncan Temple Lang } 28 | 29 | \seealso{ 30 | \code{\link[base]{merge}}} 31 | \examples{ 32 | \dontrun{ 33 | # Not exported. 34 | 35 | merge.list(list(a=1, b = "xyz", c = function(x, y) {x+y}), 36 | list(a = 2, z = "a string")) 37 | 38 | # No values in y 39 | merge.list(list(a=1, b = "xyz", c = function(x, y) {x+y}), list()) 40 | 41 | # No values in x 42 | merge.list(list(), list(a=1, b = "xyz", c = function(x, y) {x+y})) 43 | } 44 | } 45 | \keyword{manip} 46 | 47 | 48 | -------------------------------------------------------------------------------- /man/mimeTypeExtensions.Rd: -------------------------------------------------------------------------------- 1 | \name{mimeTypeExtensions} 2 | \alias{mimeTypeExtensions} 3 | \docType{data} 4 | \title{Mapping from extension to MIME type} 5 | \description{ 6 | This is a programmatically generated character vector 7 | whose names identify the MIME type typically associated with 8 | the extension which are the values. 9 | This is used in \code{\link[RCurl]{guessMIMEType}}. 10 | We can match an extension and then find the corresponding 11 | MIME type. 12 | There are duplicates. 13 | } 14 | \usage{data(mimeTypeExtensions)} 15 | \format{ 16 | The format is a named character vector 17 | where the names are the MIME types 18 | and the values are the file 19 | extensions. 20 | } 21 | \source{ 22 | The table of MIME types and extensions was programmatically extracted 23 | from \url{http://www.webmaster-toolkit.com/mime-types.shtml} or 24 | \url{http://reference.sitepoint.com/html/mime-types-full} with 25 | \code{ 26 | tbls = readHTMLTable("http://www.webmaster-toolkit.com/mime-types.shtml") 27 | tmp = tbls[[1]][-1,] 28 | mimeTypeExtensions = structure(as.character(tmp[[2]]), names = gsub("^\\.", "", tmp[[1]])) 29 | save(mimeTypeExtensions, file = "data/mimeTypeExtensions.rda") 30 | } 31 | The IANA list is not as convenient to programmatically compile. 32 | \url{http://www.ltsw.se/knbase/internet/mime.htp} 33 | } 34 | %\references{} 35 | \examples{ 36 | data(mimeTypeExtensions) 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/reset.Rd: -------------------------------------------------------------------------------- 1 | \name{reset} 2 | \alias{reset} 3 | \alias{reset,CURLHandle-method} 4 | \title{Generic function for resetting an object} 5 | \description{ 6 | This generic and the associated method for a CURLHandle 7 | allows one to reset the state of the Curl object 8 | to its default state. This is convenient if we want 9 | to reuse the same connection, but want to ensure 10 | that it is in a particular state. 11 | 12 | Unfortunately, we cannot query the state of different 13 | fields in an existing Curl handle and so we need 14 | to be able to reset the state and then update it with 15 | any particular settings we would have liked to keep. 16 | } 17 | \usage{ 18 | reset(x, ...) 19 | } 20 | \arguments{ 21 | \item{x}{the object to be reset. For our method, this is an object of 22 | class \code{CURLHandle}.} 23 | \item{\dots}{additional arguments for methods} 24 | } 25 | \details{ 26 | This calls the C routine \code{curl_easy_reset} in libcurl. 27 | } 28 | \value{ 29 | Methods typically return the updated version of the 30 | object passed to it. This allows the caller to assign 31 | the new result to the same variable rather than 32 | relying on mutating the content of the object in place. 33 | In other words, the object should not be treated as a reference 34 | but a new object with the updated contents should be returned. 35 | } 36 | \references{Curl homepage \url{http://curl.haxx.se}} 37 | \author{Duncan Temple Lang} 38 | \seealso{ 39 | \code{\link{getCurlHandle}} 40 | \code{\link{dupCurlHandle}} 41 | } 42 | \examples{ 43 | h = getCurlHandle() 44 | curlSetOpt(customrequest = "DELETE") 45 | reset(h) 46 | } 47 | \keyword{programming} 48 | 49 | -------------------------------------------------------------------------------- /man/scp.Rd: -------------------------------------------------------------------------------- 1 | \name{scp} 2 | \Rdversion{1.1} 3 | \alias{scp} 4 | \title{Retrieve contents of a file from a remote host via SCP (Secure Copy)} 5 | \description{ 6 | This function allows us to retrieve the contents of a file from a 7 | remote host via SCP. This is done entirely within R, rather than 8 | a command line application and the contents of the file are never 9 | written to disc. The function allows the 10 | } 11 | \usage{ 12 | scp(host, path, keypasswd = NA, user = getUserName(), rsa = TRUE, 13 | key = sprintf(c("~/.ssh/id_\%s.pub", "~/.ssh/id_\%s"), 14 | if (rsa) "rsa" else "dsa"), 15 | binary = NA, size = 5000, curl = getCurlHandle(), ...) 16 | } 17 | %- maybe also 'usage' for other objects documented here. 18 | \arguments{ 19 | \item{host}{the name of the remote host or its IP address} 20 | \item{path}{the path of the file of interest on the remote host's file 21 | systems} 22 | \item{keypasswd}{a password for accessing the local SSH key. This is 23 | the passphrase for the key.} 24 | \item{user}{the name of the user on the remote machine} 25 | \item{rsa}{a logical value indicating whether to use the RSA or DSA key} 26 | \item{key}{the path giving the location of the SSH key. } 27 | \item{binary}{a logical value giving } 28 | \item{size}{an estimate of the size of the buffer needed to store the 29 | contents of the file. This is used to initialize the buffer and 30 | potentially avoid resizing it as needed.} 31 | \item{curl}{a curl handle (\code{\link{getCurlHandle}}) that is to be 32 | reused for this request and which potentially contains numerous 33 | options settings or an existing connection to the host.} 34 | \item{\dots}{additional parameters handed to \code{\link{curlPerform}}.} 35 | } 36 | \details{This uses libcurl's facilities for scp. 37 | Use \code{"scp" \%in\% curlVersion()$protocols} to 38 | see if SCP is supported. 39 | } 40 | \value{ 41 | Either a raw or character vector giving the contents of the file. 42 | } 43 | \references{ 44 | libcurl \url{http://curl.haxx.se} 45 | } 46 | \author{ 47 | Duncan Temple Lang 48 | } 49 | 50 | 51 | \seealso{ 52 | \code{\link{curlPerform}} 53 | \code{\link{getCurlOptionsConstants}} 54 | } 55 | \examples{ 56 | \dontrun{ 57 | x = scp("eeyore.ucdavis.edu", "/home/duncan/OmegaWeb/index.html", 58 | "My.SCP.Passphrase", binary = FALSE) 59 | x = scp("eeyore.ucdavis.edu", 60 | "/home/duncan/OmegaWeb/RCurl/xmlParse.bz2", 61 | "My.SCP.Passphrase") 62 | if(require(Rcompression)) 63 | o = bunzip2(x) 64 | } 65 | } 66 | \keyword{IO} 67 | \keyword{programming} 68 | -------------------------------------------------------------------------------- /man/url.exists.Rd: -------------------------------------------------------------------------------- 1 | \name{url.exists} 2 | \alias{url.exists} 3 | \title{Check if URL exists} 4 | \description{ 5 | This functions is analogous to \code{\link[base]{file.exists}} 6 | and determines whether a request for a specific URL responds 7 | without error. We make the request but ask the server 8 | not to return the body. We just process the header. 9 | } 10 | \usage{ 11 | url.exists(url, ..., .opts = list(...), 12 | curl = getCurlHandle(.opts = .opts), 13 | .header = FALSE) 14 | } 15 | \arguments{ 16 | \item{url}{a vector of one or more URLs whose existence we are to test} 17 | \item{\dots}{name = value pairs of Curl options.} 18 | \item{.opts}{a list of name = value pairs of Curl options.} 19 | \item{curl}{a Curl handle that the caller can specify if she wants to 20 | reuse an existing handle, e.g. with different options already 21 | specified or that has previously established a connection to the Web 22 | server} 23 | \item{.header}{a logical value that if \code{TRUE} causes the header 24 | information to be returned. 25 | } 26 | } 27 | \details{ 28 | This makes an HTTP request but with the nobody option set to 29 | \code{FALSE} so that we don't actually retrieve the contents of the URL. 30 | } 31 | \value{ 32 | If \code{.header} is \code{FALSE}, this returns 33 | \code{TRUE} or \code{FALSE} for each URL indicating whether 34 | the request was successful (had a status with a value 35 | in the 200 range). 36 | 37 | If \code{.header} is \code{TRUE}, the header is returned for the 38 | request for each URL, unless the host could not be resolved. In 39 | the latter case, the header is not meaningful. 40 | } 41 | \references{ 42 | HTTP specification 43 | } 44 | \author{ 45 | Duncan Temple Lang 46 | } 47 | \seealso{ 48 | \code{\link{curlPerform}} 49 | } 50 | \examples{ 51 | url.exists("http://www.omegahat.org/RCurl") 52 | try(url.exists("http://www.omegahat.org/RCurl-xxx")) 53 | } 54 | 55 | -------------------------------------------------------------------------------- /manyConnections.R: -------------------------------------------------------------------------------- 1 | urls = sprintf("http://eeyore.ucdavis.edu/EmptyFiles/f%d", 1:10000) 2 | 3 | library(RCurl) 4 | curl = getCurlHandle() 5 | 6 | N = 2000 7 | u = "http://localhost/~duncan" 8 | ans = lapply(1:N, function(i) { if(i %% 100 == 0) { cat(i, ""); gc()} ;getURLContent(u, curl = curl)}) 9 | 10 | ans = lapply(1:N, function(i) { if(i %% 100 == 0) { cat(i, ""); gc()} ;getURLContent(u)}) 11 | 12 | 13 | ans = lapply(1:N, function(i) { if(i %% 100 == 0) { cat(i, ""); gc()} ;getURL(u)}) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /postFormEg.R: -------------------------------------------------------------------------------- 1 | require(RCurl) 2 | url <- "http://phylodiversity.net/phylomatic/pm/phylomatic.cgi" 3 | string1 <- "asteraceae%2Fhelianthus%2Fhelianthus_annuus%0D%0Afagaceae%2Fquercus%2Fquercus_douglasii%0D%0Apinaceae%2Fpinus%2Fpinus_contorta" 4 | string2 <- "annonaceae%2Fannona%2Fannona_cherimola%0D%0Aannonaceae%2Fannona%2Fannona_muricata" 5 | 6 | # THe following are all the same. 7 | a = postForm(url, format = 'new', tree = string1, .opts = list(verbose = TRUE)) 8 | b = postForm(url, format = 'new', tree = string2, .opts = list(verbose = TRUE)) 9 | c = postForm(url, garbage = "") 10 | 11 | a = postForm(url, format = 'new', tree = curlUnescape(string1)) 12 | b = postForm(url, format = 'new', tree = curlUnescape(string2)) 13 | 14 | urlplus <- paste(url, "?", "format=", "new", "&tree=", string1, sep="") 15 | tt <- getURLContent(urlplus, curl=getCurlHandle()) 16 | tt[[1]] 17 | 18 | urlplus <- paste(url, "?", "format=", "new", "&tree=", string2, sep="") 19 | tt <- getURLContent(urlplus, curl=getCurlHandle()) 20 | tt[[1]] 21 | -------------------------------------------------------------------------------- /src/CURLINFOTable.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CURLINFO_EFFECTIVE_URL 2 | CURLINFO(EFFECTIVE_URL), 3 | #endif 4 | #ifdef HAVE_CURLINFO_RESPONSE_CODE 5 | CURLINFO(RESPONSE_CODE), 6 | #endif 7 | #ifdef HAVE_CURLINFO_TOTAL_TIME 8 | CURLINFO(TOTAL_TIME), 9 | #endif 10 | #ifdef HAVE_CURLINFO_NAMELOOKUP_TIME 11 | CURLINFO(NAMELOOKUP_TIME), 12 | #endif 13 | #ifdef HAVE_CURLINFO_CONNECT_TIME 14 | CURLINFO(CONNECT_TIME), 15 | #endif 16 | #ifdef HAVE_CURLINFO_PRETRANSFER_TIME 17 | CURLINFO(PRETRANSFER_TIME), 18 | #endif 19 | #ifdef HAVE_CURLINFO_SIZE_UPLOAD 20 | CURLINFO(SIZE_UPLOAD), 21 | #endif 22 | #ifdef HAVE_CURLINFO_SIZE_DOWNLOAD 23 | CURLINFO(SIZE_DOWNLOAD), 24 | #endif 25 | #ifdef HAVE_CURLINFO_SPEED_DOWNLOAD 26 | CURLINFO(SPEED_DOWNLOAD), 27 | #endif 28 | #ifdef HAVE_CURLINFO_SPEED_UPLOAD 29 | CURLINFO(SPEED_UPLOAD), 30 | #endif 31 | #ifdef HAVE_CURLINFO_HEADER_SIZE 32 | CURLINFO(HEADER_SIZE), 33 | #endif 34 | #ifdef HAVE_CURLINFO_REQUEST_SIZE 35 | CURLINFO(REQUEST_SIZE), 36 | #endif 37 | #ifdef HAVE_CURLINFO_SSL_VERIFYRESULT 38 | CURLINFO(SSL_VERIFYRESULT), 39 | #endif 40 | #ifdef HAVE_CURLINFO_FILETIME 41 | CURLINFO(FILETIME), 42 | #endif 43 | #ifdef HAVE_CURLINFO_CONTENT_LENGTH_DOWNLOAD 44 | CURLINFO(CONTENT_LENGTH_DOWNLOAD), 45 | #endif 46 | #ifdef HAVE_CURLINFO_CONTENT_LENGTH_UPLOAD 47 | CURLINFO(CONTENT_LENGTH_UPLOAD), 48 | #endif 49 | #ifdef HAVE_CURLINFO_STARTTRANSFER_TIME 50 | CURLINFO(STARTTRANSFER_TIME), 51 | #endif 52 | #ifdef HAVE_CURLINFO_CONTENT_TYPE 53 | CURLINFO(CONTENT_TYPE), 54 | #endif 55 | #ifdef HAVE_CURLINFO_REDIRECT_TIME 56 | CURLINFO(REDIRECT_TIME), 57 | #endif 58 | #ifdef HAVE_CURLINFO_REDIRECT_COUNT 59 | CURLINFO(REDIRECT_COUNT), 60 | #endif 61 | #ifdef HAVE_CURLINFO_PRIVATE 62 | CURLINFO(PRIVATE), 63 | #endif 64 | #ifdef HAVE_CURLINFO_HTTP_CONNECTCODE 65 | CURLINFO(HTTP_CONNECTCODE), 66 | #endif 67 | #ifdef HAVE_CURLINFO_HTTPAUTH_AVAIL 68 | CURLINFO(HTTPAUTH_AVAIL), 69 | #endif 70 | #ifdef HAVE_CURLINFO_PROXYAUTH_AVAIL 71 | CURLINFO(PROXYAUTH_AVAIL), 72 | #endif 73 | #ifdef HAVE_CURLINFO_OS_ERRNO 74 | CURLINFO(OS_ERRNO), 75 | #endif 76 | #ifdef HAVE_CURLINFO_NUM_CONNECTS 77 | CURLINFO(NUM_CONNECTS), 78 | #endif 79 | #ifdef HAVE_CURLINFO_SSL_ENGINES 80 | CURLINFO(SSL_ENGINES), 81 | #endif 82 | #ifdef HAVE_CURLINFO_COOKIELIST 83 | CURLINFO(COOKIELIST), 84 | #endif 85 | #ifdef HAVE_CURLINFO_LASTSOCKET 86 | CURLINFO(LASTSOCKET), 87 | #endif 88 | #ifdef HAVE_CURLINFO_FTP_ENTRY_PATH 89 | CURLINFO(FTP_ENTRY_PATH), 90 | #endif 91 | #ifdef HAVE_CURLINFO_REDIRECT_URL 92 | CURLINFO(REDIRECT_URL), 93 | #endif 94 | #ifdef HAVE_CURLINFO_PRIMARY_IP 95 | CURLINFO(PRIMARY_IP), 96 | #endif 97 | #ifdef HAVE_CURLINFO_APPCONNECT_TIME 98 | CURLINFO(APPCONNECT_TIME), 99 | #endif 100 | #ifdef HAVE_CURLINFO_CERTINFO 101 | CURLINFO(CERTINFO), 102 | #endif 103 | #ifdef HAVE_CURLINFO_CONDITION_UNMET 104 | CURLINFO(CONDITION_UNMET) 105 | #endif 106 | -------------------------------------------------------------------------------- /src/CurlErrorEnums.h: -------------------------------------------------------------------------------- 1 | /* Currently this is not used. */ 2 | 3 | #define CURLE(a) {#a), CURLE_##a} 4 | 5 | NameValue CurlErrorNames[] = 6 | { 7 | CURLE(UNSUPPORTED_PROTOCOL), 8 | CURLE(FAILED_INIT), 9 | CURLE(URL_MALFORMAT), 10 | CURLE(URL_MALFORMAT_USER), 11 | CURLE(COULDNT_RESOLVE_PROXY), 12 | CURLE(COULDNT_RESOLVE_HOST), 13 | CURLE(COULDNT_CONNECT), 14 | CURLE(FTP_WEIRD_SERVER_REPLY), 15 | CURLE(FTP_ACCESS_DENIED), 16 | CURLE(FTP_USER_PASSWORD_INCORRECT), 17 | CURLE(FTP_WEIRD_PASS_REPLY), 18 | CURLE(FTP_WEIRD_USER_REPLY), 19 | CURLE(FTP_WEIRD_PASV_REPLY), 20 | CURLE(FTP_WEIRD_227_FORMAT), 21 | CURLE(FTP_CANT_GET_HOST), 22 | CURLE(FTP_CANT_RECONNECT), 23 | CURLE(FTP_COULDNT_SET_BINARY), 24 | CURLE(PARTIAL_FILE), 25 | CURLE(FTP_COULDNT_RETR_FILE), 26 | CURLE(FTP_WRITE_ERROR), 27 | CURLE(FTP_QUOTE_ERROR), 28 | CURLE(HTTP_RETURNED_ERROR), 29 | CURLE(WRITE_ERROR), 30 | CURLE(MALFORMAT_USER), 31 | CURLE(FTP_COULDNT_STOR_FILE), 32 | CURLE(READ_ERROR), 33 | CURLE(OUT_OF_MEMORY), 34 | CURLE(OPERATION_TIMEOUTED), 35 | CURLE(FTP_COULDNT_SET_ASCII), 36 | CURLE(FTP_PORT_FAILED), 37 | CURLE(FTP_COULDNT_USE_REST), 38 | CURLE(FTP_COULDNT_GET_SIZE), 39 | CURLE(HTTP_RANGE_ERROR), 40 | CURLE(HTTP_POST_ERROR), 41 | CURLE(SSL_CONNECT_ERROR), 42 | CURLE(BAD_DOWNLOAD_RESUME), 43 | CURLE(FILE_COULDNT_READ_FILE), 44 | CURLE(LDAP_CANNOT_BIND), 45 | CURLE(LDAP_SEARCH_FAILED), 46 | CURLE(LIBRARY_NOT_FOUND), 47 | CURLE(FUNCTION_NOT_FOUND), 48 | CURLE(ABORTED_BY_CALLBACK), 49 | CURLE(BAD_FUNCTION_ARGUMENT), 50 | CURLE(BAD_CALLING_ORDER), 51 | CURLE(INTERFACE_FAILED), 52 | CURLE(BAD_PASSWORD_ENTERED), 53 | CURLE(TOO_MANY_REDIRECTS ), 54 | CURLE(UNKNOWN_TELNET_OPTION), 55 | CURLE(TELNET_OPTION_SYNTAX ), 56 | CURLE(OBSOLETE), 57 | CURLE(SSL_PEER_CERTIFICATE), 58 | CURLE(GOT_NOTHING), 59 | CURLE(SSL_ENGINE_NOTFOUND), 60 | CURLE(SSL_ENGINE_SETFAILED), 61 | 62 | CURLE(SEND_ERROR), 63 | CURLE(RECV_ERROR), 64 | CURLE(SHARE_IN_USE), 65 | CURLE(SSL_CERTPROBLEM), 66 | CURLE(SSL_CIPHER), 67 | CURLE(SSL_CACERT), 68 | CURLE(BAD_CONTENT_ENCODING), 69 | CURLE(LDAP_INVALID_URL), 70 | CURLE(FILESIZE_EXCEEDED), 71 | CURLE(FTP_SSL_FAILED) 72 | }; 73 | -------------------------------------------------------------------------------- /src/CurlInfoEnums.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define CURLINFO(a) {#a, CURLINFO_##a} 4 | 5 | NameValue CurlInfoNames[] = 6 | { 7 | #include "CURLINFOTable.h" 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | CURL_CONFIG=/usr/bin/curl-config 2 | 3 | # CURL_CFLAGS=$(shell $(CURL_CONFIG) --cflags) 4 | # CURL_LIBS=$(shell $(CURL_CONFIG) --libs) 5 | 6 | CURL_CFLAGS= 7 | CURL_LIBS=-lcurl 8 | 9 | 10 | # -DRCURL_DEBUG_MEMORY 11 | DEFINES= -DHAVE_LIBIDN_FIELD=1 -DHAVE_CURLOPT_URL=1 -DHAVE_CURLINFO_EFFECTIVE_URL=1 -DHAVE_CURLINFO_RESPONSE_CODE=1 -DHAVE_CURLINFO_TOTAL_TIME=1 -DHAVE_CURLINFO_NAMELOOKUP_TIME=1 -DHAVE_CURLINFO_CONNECT_TIME=1 -DHAVE_CURLINFO_PRETRANSFER_TIME=1 -DHAVE_CURLINFO_SIZE_UPLOAD=1 -DHAVE_CURLINFO_SIZE_DOWNLOAD=1 -DHAVE_CURLINFO_SPEED_DOWNLOAD=1 -DHAVE_CURLINFO_SPEED_UPLOAD=1 -DHAVE_CURLINFO_HEADER_SIZE=1 -DHAVE_CURLINFO_REQUEST_SIZE=1 -DHAVE_CURLINFO_SSL_VERIFYRESULT=1 -DHAVE_CURLINFO_FILETIME=1 -DHAVE_CURLINFO_CONTENT_LENGTH_DOWNLOAD=1 -DHAVE_CURLINFO_CONTENT_LENGTH_UPLOAD=1 -DHAVE_CURLINFO_STARTTRANSFER_TIME=1 -DHAVE_CURLINFO_CONTENT_TYPE=1 -DHAVE_CURLINFO_REDIRECT_TIME=1 -DHAVE_CURLINFO_REDIRECT_COUNT=1 -DHAVE_CURLINFO_PRIVATE=1 -DHAVE_CURLINFO_HTTP_CONNECTCODE=1 -DHAVE_CURLINFO_HTTPAUTH_AVAIL=1 -DHAVE_CURLINFO_PROXYAUTH_AVAIL=1 -DHAVE_CURLINFO_OS_ERRNO=1 -DHAVE_CURLINFO_NUM_CONNECTS=1 -DHAVE_CURLINFO_SSL_ENGINES=1 -DHAVE_CURLINFO_COOKIELIST=1 -DHAVE_CURLINFO_LASTSOCKET=1 -DHAVE_CURLINFO_FTP_ENTRY_PATH=1 -DHAVE_CURLINFO_REDIRECT_URL=1 -DHAVE_CURLINFO_PRIMARY_IP=1 -DHAVE_CURLINFO_APPCONNECT_TIME=1 -DHAVE_CURLINFO_CERTINFO=1 -DHAVE_CURLINFO_CONDITION_UNMET=1 -DHAVE_CURLOPT_KEYPASSWD=1 -DHAVE_CURLOPT_DIRLISTONLY=1 -DHAVE_CURLOPT_APPEND=1 -DHAVE_CURLOPT_KRBLEVEL=1 -DHAVE_CURLOPT_USE_SSL=1 -DHAVE_CURLOPT_TIMEOUT_MS=1 -DHAVE_CURLOPT_CONNECTTIMEOUT_MS=1 -DHAVE_CURLOPT_HTTP_TRANSFER_DECODING=1 -DHAVE_CURLOPT_HTTP_CONTENT_DECODING=1 -DHAVE_CURLOPT_NEW_FILE_PERMS=1 -DHAVE_CURLOPT_NEW_DIRECTORY_PERMS=1 -DHAVE_CURLOPT_POSTREDIR=1 -DHAVE_CURLOPT_OPENSOCKETFUNCTION=1 -DHAVE_CURLOPT_OPENSOCKETDATA=1 -DHAVE_CURLOPT_COPYPOSTFIELDS=1 -DHAVE_CURLOPT_PROXY_TRANSFER_MODE=1 -DHAVE_CURLOPT_SEEKFUNCTION=1 -DHAVE_CURLOPT_SEEKDATA=1 -DHAVE_CURLOPT_CRLFILE=1 -DHAVE_CURLOPT_ISSUERCERT=1 -DHAVE_CURLOPT_ADDRESS_SCOPE=1 -DHAVE_CURLOPT_CERTINFO=1 -DHAVE_CURLOPT_USERNAME=1 -DHAVE_CURLOPT_PASSWORD=1 -DHAVE_CURLOPT_PROXYUSERNAME=1 -DHAVE_CURLOPT_PROXYPASSWORD=1 -DHAVE_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5=1 -DHAVE_CURLOPT_NOPROXY=1 -DHAVE_CURLOPT_TFTP_BLKSIZE=1 -DHAVE_CURLOPT_SOCKS5_GSSAPI_SERVICE=1 -DHAVE_CURLOPT_SOCKS5_GSSAPI_NEC=1 -DHAVE_CURLOPT_PROTOCOLS=1 -DHAVE_CURLOPT_REDIR_PROTOCOLS=1 -DHAVE_CURLOPT_SSH_AUTH_TYPES=1 -DHAVE_CURLOPT_SSH_PUBLIC_KEYFILE=1 -DHAVE_CURLOPT_SSH_PRIVATE_KEYFILE=1 -DHAVE_CURLOPT_FTP_SSL_CCC=1 -DHAVE_CURLOPT_COOKIELIST=1 -DHAVE_CURLOPT_IGNORE_CONTENT_LENGTH=1 -DHAVE_CURLOPT_FTP_SKIP_PASV_IP=1 -DHAVE_CURLOPT_FTP_FILEMETHOD=1 -DHAVE_CURLOPT_LOCALPORT=1 -DHAVE_CURLOPT_LOCALPORTRANGE=1 -DHAVE_CURLOPT_CONNECT_ONLY=1 -DHAVE_CURLOPT_CONV_FROM_NETWORK_FUNCTION=1 -DHAVE_CURLOPT_CONV_TO_NETWORK_FUNCTION=1 -DHAVE_CURLOPT_CONV_FROM_UTF8_FUNCTION=1 -DHAVE_CURLOPT_MAX_SEND_SPEED_LARGE=1 -DHAVE_CURLOPT_MAX_RECV_SPEED_LARGE=1 -DHAVE_CURLOPT_FTP_ALTERNATIVE_TO_USER=1 -DHAVE_CURLOPT_SOCKOPTFUNCTION=1 -DHAVE_CURLOPT_SOCKOPTDATA=1 -DHAVE_CURLOPT_SSL_SESSIONID_CACHE=1 -DHAVE_CURLOPT_GSSAPI_DELEGATION=1 12 | 13 | PKG_CPPFLAGS=$(CURL_CFLAGS) $(DEFINES) $(shell xml2-config --cflags) 14 | PKG_LIBS=$(CURL_LIBS) $(shell xml2-config --libs) 15 | 16 | # enums.o: enums.c CurlOptEnums.h 17 | 18 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | CURL_CONFIG=@CURL_CONFIG@ 2 | 3 | # CURL_CFLAGS=$(shell $(CURL_CONFIG) --cflags) 4 | # CURL_LIBS=$(shell $(CURL_CONFIG) --libs) 5 | 6 | CURL_CFLAGS=@CURL_CFLAGS@ 7 | CURL_LIBS=@CURL_LIBS@ 8 | 9 | 10 | # -DRCURL_DEBUG_MEMORY 11 | DEFINES=@DEFINES@ 12 | 13 | PKG_CPPFLAGS=$(CURL_CFLAGS) $(DEFINES) $(shell xml2-config --cflags) 14 | PKG_LIBS=$(CURL_LIBS) $(shell xml2-config --libs) 15 | 16 | # enums.o: enums.c CurlOptEnums.h 17 | 18 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | 2 | DEFINES= -DHAVE_LIBIDN_FIELD=1 -DHAVE_CURLOPT_URL=1 -DHAVE_CURLINFO_EFFECTIVE_URL=1 -DHAVE_CURLINFO_RESPONSE_CODE=1 -DHAVE_CURLINFO_TOTAL_TIME=1 -DHAVE_CURLINFO_NAMELOOKUP_TIME=1 -DHAVE_CURLINFO_CONNECT_TIME=1 -DHAVE_CURLINFO_PRETRANSFER_TIME=1 -DHAVE_CURLINFO_SIZE_UPLOAD=1 -DHAVE_CURLINFO_SIZE_DOWNLOAD=1 -DHAVE_CURLINFO_SPEED_DOWNLOAD=1 -DHAVE_CURLINFO_SPEED_UPLOAD=1 -DHAVE_CURLINFO_HEADER_SIZE=1 -DHAVE_CURLINFO_REQUEST_SIZE=1 -DHAVE_CURLINFO_SSL_VERIFYRESULT=1 -DHAVE_CURLINFO_FILETIME=1 -DHAVE_CURLINFO_CONTENT_LENGTH_DOWNLOAD=1 -DHAVE_CURLINFO_CONTENT_LENGTH_UPLOAD=1 -DHAVE_CURLINFO_STARTTRANSFER_TIME=1 -DHAVE_CURLINFO_CONTENT_TYPE=1 -DHAVE_CURLINFO_REDIRECT_TIME=1 -DHAVE_CURLINFO_REDIRECT_COUNT=1 -DHAVE_CURLINFO_PRIVATE=1 -DHAVE_CURLINFO_HTTP_CONNECTCODE=1 -DHAVE_CURLINFO_HTTPAUTH_AVAIL=1 -DHAVE_CURLINFO_PROXYAUTH_AVAIL=1 -DHAVE_CURLINFO_OS_ERRNO=1 -DHAVE_CURLINFO_NUM_CONNECTS=1 -DHAVE_CURLINFO_SSL_ENGINES=1 -DHAVE_CURLINFO_COOKIELIST=1 -DHAVE_CURLINFO_LASTSOCKET=1 -DHAVE_CURLINFO_FTP_ENTRY_PATH=1 -DHAVE_CURLINFO_REDIRECT_URL=1 -DHAVE_CURLINFO_PRIMARY_IP=1 -DHAVE_CURLINFO_APPCONNECT_TIME=1 -DHAVE_CURLINFO_CERTINFO=1 -DHAVE_CURLINFO_CONDITION_UNMET=1 -DHAVE_CURLOPT_KEYPASSWD=1 -DHAVE_CURLOPT_DIRLISTONLY=1 -DHAVE_CURLOPT_APPEND=1 -DHAVE_CURLOPT_KRBLEVEL=1 -DHAVE_CURLOPT_USE_SSL=1 -DHAVE_CURLOPT_TIMEOUT_MS=1 -DHAVE_CURLOPT_CONNECTTIMEOUT_MS=1 -DHAVE_CURLOPT_HTTP_TRANSFER_DECODING=1 -DHAVE_CURLOPT_HTTP_CONTENT_DECODING=1 -DHAVE_CURLOPT_NEW_FILE_PERMS=1 -DHAVE_CURLOPT_NEW_DIRECTORY_PERMS=1 -DHAVE_CURLOPT_POSTREDIR=1 -DHAVE_CURLOPT_OPENSOCKETFUNCTION=1 -DHAVE_CURLOPT_OPENSOCKETDATA=1 -DHAVE_CURLOPT_COPYPOSTFIELDS=1 -DHAVE_CURLOPT_PROXY_TRANSFER_MODE=1 -DHAVE_CURLOPT_SEEKFUNCTION=1 -DHAVE_CURLOPT_SEEKDATA=1 -DHAVE_CURLOPT_CRLFILE=1 -DHAVE_CURLOPT_ISSUERCERT=1 -DHAVE_CURLOPT_ADDRESS_SCOPE=1 -DHAVE_CURLOPT_CERTINFO=1 -DHAVE_CURLOPT_USERNAME=1 -DHAVE_CURLOPT_PASSWORD=1 -DHAVE_CURLOPT_PROXYUSERNAME=1 -DHAVE_CURLOPT_PROXYPASSWORD=1 -DHAVE_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5=1 -DHAVE_CURLOPT_NOPROXY=1 -DHAVE_CURLOPT_TFTP_BLKSIZE=1 -DHAVE_CURLOPT_SOCKS5_GSSAPI_SERVICE=1 -DHAVE_CURLOPT_SOCKS5_GSSAPI_NEC=1 -DHAVE_CURLOPT_PROTOCOLS=1 -DHAVE_CURLOPT_REDIR_PROTOCOLS=1 -DHAVE_CURLOPT_SSH_AUTH_TYPES=1 -DHAVE_CURLOPT_SSH_PUBLIC_KEYFILE=1 -DHAVE_CURLOPT_SSH_PRIVATE_KEYFILE=1 -DHAVE_CURLOPT_FTP_SSL_CCC=1 -DHAVE_CURLOPT_COOKIELIST=1 -DHAVE_CURLOPT_IGNORE_CONTENT_LENGTH=1 -DHAVE_CURLOPT_FTP_SKIP_PASV_IP=1 -DHAVE_CURLOPT_FTP_FILEMETHOD=1 -DHAVE_CURLOPT_LOCALPORT=1 -DHAVE_CURLOPT_LOCALPORTRANGE=1 -DHAVE_CURLOPT_CONNECT_ONLY=1 -DHAVE_CURLOPT_CONV_FROM_NETWORK_FUNCTION=1 -DHAVE_CURLOPT_CONV_TO_NETWORK_FUNCTION=1 -DHAVE_CURLOPT_CONV_FROM_UTF8_FUNCTION=1 -DHAVE_CURLOPT_MAX_SEND_SPEED_LARGE=1 -DHAVE_CURLOPT_MAX_RECV_SPEED_LARGE=1 -DHAVE_CURLOPT_FTP_ALTERNATIVE_TO_USER=1 -DHAVE_CURLOPT_SOCKOPTFUNCTION=1 -DHAVE_CURLOPT_SOCKOPTDATA=1 -DHAVE_CURLOPT_SSL_SESSIONID_CACHE=1 3 | 4 | CURL_INCLUDE_DIR=-I${LIB_CURL}/include 5 | CURL_LIB_DIR=-L${LIB_CURL}/lib 6 | 7 | PKG_CPPFLAGS = ${CURL_INCLUDE_DIR} $(DEFINES) 8 | #PKG_LIBS= ${CURL_LIB_DIR} -lcurldll -lws2_32 9 | 10 | ifeq "${R_ARCH}" "/x64" 11 | PKG_LIBS= -L${LIB_CURL}/bin -lcurl-4 -lws2_32 12 | else 13 | DEFINES += -DCURL_STATICLIB 14 | PKG_LIBS= -L${LIB_CURL}/lib -lcurl -lssh2 -lssl -lssl32 -leay32 -lidn -lz -lws2_32 -lwldap32 15 | endif 16 | 17 | -------------------------------------------------------------------------------- /src/Rcurl.h: -------------------------------------------------------------------------------- 1 | #ifndef R_CURL_H 2 | #define R_CURL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | #define RCURL_DEBUG_MEMORY 1 10 | */ 11 | 12 | typedef enum {VOID_TYPE, R_OBJECT} RCurl_OptValueType; 13 | 14 | typedef struct _RCurlMemory RCurlMemory; 15 | 16 | struct _RCurlMemory { 17 | 18 | CURL *curl; /* the CURL object for which this data was allocated.*/ 19 | const void *data; /* the data */ 20 | CURLoption option; /* the option, so we can tell what it was for.*/ 21 | 22 | RCurl_OptValueType type; 23 | 24 | RCurlMemory *next; 25 | }; 26 | 27 | typedef struct _CURLOptionMemoryManager CURLOptionMemoryManager; 28 | 29 | struct _CURLOptionMemoryManager { 30 | CURL *curl; 31 | RCurlMemory *top; 32 | 33 | int numTickets; /* Number of entries in the top. Used for debugging here. */ 34 | 35 | CURLOptionMemoryManager *next; 36 | CURLOptionMemoryManager *last; 37 | }; 38 | 39 | RCurlMemory *RCurl_addMemoryAllocation(CURLoption, const void *, CURL *); 40 | CURLOptionMemoryManager *RCurl_addMemoryTicket(RCurlMemory *); 41 | void RCurl_releaseMemoryTickets(CURL *curl); 42 | CURLOptionMemoryManager* RCurl_getMemoryManager(CURL *curl); 43 | 44 | void RCurl_releaseManagerMemoryTickets(CURLOptionMemoryManager *mgr); 45 | 46 | 47 | 48 | typedef struct { 49 | SEXP fun; 50 | SEXP headerFun; 51 | cetype_t encoding; 52 | int encodingSetByUser; 53 | int nobody; 54 | } RWriteDataInfo; 55 | 56 | 57 | SEXP R_curl_easy_setopt(SEXP handle, SEXP values, SEXP opts, SEXP isProtected, SEXP encoding); 58 | SEXP R_curl_easy_init(void); 59 | SEXP R_curl_easy_duphandle(SEXP); 60 | SEXP R_curl_global_cleanup(); 61 | SEXP R_curl_global_init(SEXP); 62 | SEXP R_curl_version_info(SEXP flag); 63 | SEXP R_curl_easy_perform(SEXP handle, SEXP opts, SEXP isProtected, SEXP encoding); 64 | SEXP R_curl_easy_getinfo(SEXP handle, SEXP which); 65 | SEXP R_curl_escape(SEXP vals, SEXP escape); 66 | SEXP R_post_form(SEXP handle, SEXP opts, SEXP params, SEXP isProtected, SEXP style); 67 | 68 | SEXP R_getCURLErrorEnum(void); 69 | SEXP R_getCURLInfoEnum(void); 70 | SEXP R_getCURLOptionEnum(void); 71 | 72 | 73 | #ifdef USE_LOCAL_BAS64_ENCODING 74 | /* This is going away and we will use the version on*/ 75 | extern size_t Curl_base64_decode(const char *src, unsigned char **outptr); 76 | extern size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr); 77 | #endif 78 | 79 | size_t R_Curl_base64_decode(const char *src, unsigned char **outptr); 80 | size_t R_Curl_base64_encode(const char *inp, size_t insize, char **outptr); 81 | 82 | 83 | SEXP R_curl_easy_reset(SEXP handle); 84 | 85 | 86 | SEXP R_buildForm(SEXP params, SEXP r_curl, SEXP r_set); 87 | 88 | 89 | #ifndef PROBLEM 90 | 91 | #define R_PROBLEM_BUFSIZE 4096 92 | #define PROBLEM {char R_problem_buf[R_PROBLEM_BUFSIZE];(snprintf)(R_problem_buf, R_PROBLEM_BUFSIZE, 93 | #define ERROR ),Rf_error(R_problem_buf);} 94 | #define WARNING(x) ),Rf_warning(R_problem_buf);} 95 | #define WARN WARNING(NULL) 96 | 97 | #endif 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/b64IntArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern size_t R_Curl_base64_encode(const char *inp, size_t insize, char **outptr); 4 | 5 | SEXP 6 | R_encode_int_array(SEXP rarray) 7 | { 8 | char *ans; 9 | int len = 3 * Rf_length(rarray) * sizeof(int); 10 | ans = R_alloc(3 * Rf_length(rarray), sizeof(int)); 11 | memset(ans, '\0', len); 12 | R_Curl_base64_encode((char *) INTEGER(rarray), sizeof(int) * Rf_length(rarray), &ans); 13 | return(ScalarString(mkChar(ans))); 14 | } 15 | 16 | SEXP 17 | R_encode_intAsByte_array(SEXP rarray) 18 | { 19 | char *ans; 20 | int len = 3 * Rf_length(rarray) * sizeof(int), i, n; 21 | char *tmp; 22 | 23 | n = Rf_length(rarray); 24 | tmp = R_alloc(n, sizeof(char)); 25 | 26 | for(i = 0; i < n ; i++) { 27 | tmp[i] = (char) INTEGER(rarray)[i]; 28 | } 29 | ans = R_alloc(3 * Rf_length(rarray), sizeof(int)); 30 | memset(ans, '\0', len); 31 | R_Curl_base64_encode(tmp, n, &ans); 32 | return(ScalarString(mkChar(ans))); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/base64.c: -------------------------------------------------------------------------------- 1 | #include "Rcurl.h" 2 | 3 | /* Not available from the curl headers. Are they are not (?) exported in the library on all 4 | platforms or do we have to pull the code in here. See the license discussion 5 | about this. 6 | */ 7 | 8 | /* 9 | Should we work with RAW objects here. 10 | */ 11 | 12 | #include 13 | 14 | SEXP 15 | R_base64_decode(SEXP r_text, SEXP asRaw) 16 | { 17 | const char *text; 18 | unsigned char *ans; 19 | size_t len; 20 | SEXP r_ans; 21 | 22 | if(TYPEOF(r_text) == STRSXP) 23 | text = CHAR(STRING_ELT(r_text, 0)); 24 | else 25 | text = RAW(r_text); 26 | 27 | len = R_Curl_base64_decode(text, &ans); 28 | 29 | if(len < 1) { 30 | PROBLEM "decoding from base64 failed" 31 | ERROR; 32 | } 33 | 34 | 35 | if(INTEGER(asRaw)[0]) { 36 | r_ans = allocVector(RAWSXP, len); 37 | memcpy(RAW(r_ans), ans, len); 38 | } else { 39 | r_ans = mkString(ans); 40 | } 41 | if(ans && len > -1) 42 | free(ans); 43 | 44 | return(r_ans); 45 | } 46 | 47 | 48 | SEXP 49 | R_base64_encode(SEXP r_text, SEXP asRaw) 50 | { 51 | const char *text; 52 | char *ans; 53 | size_t len, n; 54 | SEXP r_ans; 55 | 56 | if(TYPEOF(r_text) == STRSXP) { 57 | text = CHAR(STRING_ELT(r_text, 0)); 58 | n = strlen(text); 59 | } else { 60 | text = RAW(r_text); 61 | n = Rf_length(r_text); 62 | } 63 | 64 | len = R_Curl_base64_encode(text, n, &ans); 65 | 66 | if(len == -1) { 67 | PROBLEM "failed to encode the data" 68 | ERROR; 69 | } 70 | if(INTEGER(asRaw)[0]) { 71 | r_ans = allocVector(RAWSXP, len); 72 | memcpy(RAW(r_ans), ans, len); 73 | } else { 74 | r_ans = mkString(ans); 75 | } 76 | free(ans); 77 | 78 | return(r_ans); 79 | } 80 | -------------------------------------------------------------------------------- /src/curlInit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Rcurl.h" 3 | 4 | #define RegCallFun(a, b) {#a, (DL_FUNC)&a, b} 5 | 6 | static R_CallMethodDef CallEntries[] = { 7 | RegCallFun(R_curl_global_init, 1), 8 | RegCallFun(R_curl_global_cleanup, 0), 9 | RegCallFun(R_curl_version_info, 1), 10 | 11 | RegCallFun(R_curl_easy_init, 0), 12 | RegCallFun(R_curl_easy_duphandle, 1), 13 | RegCallFun(R_curl_easy_reset, 1), 14 | 15 | RegCallFun(R_curl_easy_perform, 4), 16 | RegCallFun(R_curl_easy_setopt, 5), 17 | RegCallFun(R_curl_easy_getinfo, 2), 18 | 19 | RegCallFun(R_curl_escape, 2), 20 | RegCallFun(R_post_form, 5), 21 | 22 | RegCallFun(R_getCURLErrorEnum, 0), 23 | RegCallFun(R_getCURLInfoEnum, 0), 24 | RegCallFun(R_getCURLOptionEnum, 0), 25 | 26 | RegCallFun(R_buildForm, 3), 27 | 28 | {NULL, NULL, 0} 29 | }; 30 | 31 | 32 | void 33 | R_init_RCurl(DllInfo *dll) 34 | { 35 | R_useDynamicSymbols(dll, TRUE); 36 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /testCFile.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | u = "http://requestb.in/ug0yteug" 3 | input = CFILE("rDrop/README.md") 4 | 5 | 6 | curlPerform(url = u, customrequest = "PUT", upload = TRUE, readdata = input@ref, infilesize = 100, verbose = TRUE) 7 | 8 | curlPerform(url = u, customrequest = "PUT", upload = TRUE, readdata = input@ref, infilesize = 211, verbose = TRUE) 9 | -------------------------------------------------------------------------------- /tests/amazon3.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | if(FALSE) { 3 | f = CFILE("tests/amazon3.R") 4 | curlPerform(url = "http://s3.amazonaws.com/RRupload/fromRUpload", 5 | upload = TRUE, 6 | readdata = f@ref, 7 | verbose = TRUE, 8 | infilesize = file.info("tests/amazon3.R")[1, "size"]) 9 | } 10 | # customrequest = "PUT", 11 | # httpheader = c('Content-Length' = file.info("tests/amazon3.R")[1, "size"]) 12 | -------------------------------------------------------------------------------- /tests/binaryPost.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | buf = as.raw(1:10000) 3 | 4 | dataProvider = 5 | function(buffer) { 6 | pos = 1 7 | function(numEls) { 8 | if(pos >= length(buffer)) 9 | return(character()) 10 | tmp = buffer[seq(pos, min(length(buffer) - pos + 1, numEls))] 11 | pos <<- pos + numEls 12 | tmp 13 | } 14 | } 15 | 16 | myFun = dataProvider(buf) 17 | 18 | curlPerform(url = "http://www.omegahat.org/cgi_bin/formBody.pl", 19 | post = TRUE, 20 | readfunction = myFun, 21 | postfieldsize = length(buf), 22 | httpheader = c('Content-Type' = "application/x-binary"), 23 | verbose = TRUE) 24 | 25 | # or no postfieldsize 26 | # and add 27 | # 'Transfer-Encoding' = "chunked" 28 | # to httpheader 29 | 30 | 31 | ################ 32 | 33 | curlPerform(url = "http://www.omegahat.org/cgi_bin/formBody.pl", 34 | post = TRUE, 35 | readfunction = buf, 36 | postfieldsize = length(buf), 37 | httpheader = c('Content-Type' = "application/x-binary"), 38 | verbose = TRUE) 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/biomart.R: -------------------------------------------------------------------------------- 1 | library("RCurl") 2 | ## debug(postForm) 3 | 4 | xmlQuery = " " 5 | 6 | uri = "http://www.biomart.org:80/biomart/martservice?" 7 | 8 | NoRun = FALSE 9 | 10 | tryCatch( {r = postForm(uri, query = xmlQuery, .opts = list(timeout = 10, nosignal = TRUE))}, 11 | error = function(e) { 12 | cat("problem connecting to biomart. May be temporary.\n") 13 | NoRun <<- TRUE 14 | }) 15 | 16 | 17 | if(NoRun == FALSE && require("biomaRt")) { 18 | h = getCurlHandle(nosignal = 1) 19 | ensembl = useMart("ensembl",dataset="hsapiens_gene_ensembl") 20 | tss = getBM(attributes = c("ensembl_gene_id"), 21 | filters = "ensembl_gene_id", 22 | values = c("ENSG00000171855","ENSG00000102794","ENSG00000175505"), 23 | mart = ensembl, curl = curl) 24 | tss 25 | } 26 | -------------------------------------------------------------------------------- /tests/downloadToConnection.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | downloadFile2 = 3 | function(u, f, curl = getCurlHandle(...), ...) 4 | { 5 | out = file(f, "wb") 6 | on.exit(close(out)) 7 | curlPerform(url = u, writefunction = getNativeSymbolInfo("R_curl_write_binary_data_to_connection")$address, 8 | file = out, curl = curl, .isProtected = c(TRUE, TRUE)) 9 | } 10 | 11 | to = tempfile() 12 | downloadFile2("https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/165px-R_logo.svg.png", to) 13 | -------------------------------------------------------------------------------- /tests/dynCurlReader.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | fetchURL = getURLContent 4 | 5 | u = "http://www.dice.com/job/result/90668400/647068?src=19&q=Data Science" 6 | rr = fetchURL(u, followlocation = TRUE) 7 | cat(class(rr), length(rr), if(is.character(rr)) nchar(rr), attr(rr, "Content-Type"), "\n") 8 | 9 | img = "http://www.dice.com/jobsearch/content/ejv_mercury/esurance/images/banner.jpg" 10 | rr = fetchURL(img, followlocation = TRUE) 11 | cat(class(rr), length(rr), if(is.character(rr)) nchar(rr), attr(rr, "Content-Type"), "\n") 12 | 13 | 14 | cat("Fetching PDF\n") 15 | pdf = "http://eeyore.ucdavis.edu/DTL_UCReview/cv13.pdf" 16 | # We shouldn't need to specify binary here, but for some reason 17 | # we are not seeing the second header from the redirect. 18 | # If we do 19 | # curlPerform(url = "http://eeyore.ucdavis.edu/DTL_UCReview/cv13.pdf", nobody = TRUE, followlocation = TRUE, verbose = TRUE) 20 | # we do see it. 21 | # However, we are getting an error either before this or never seeing it. 22 | # We have the Content-Type as text/html from the first 23 | # 24 | # Should we ignore the content-type in the 302 header? Implemented now. 25 | # 26 | rr = fetchURL(pdf, followlocation = TRUE) 27 | cat(class(rr), length(rr), if(is.character(rr)) nchar(rr), attr(rr, "Content-Type"), "\n") 28 | 29 | cat("Fetching PDF as binary\n") 30 | rr = fetchURL(pdf, binary = TRUE, followlocation = TRUE) 31 | cat(class(rr), length(rr), if(is.character(rr)) nchar(rr), attr(rr, "Content-Type"), "\n") 32 | 33 | 34 | rr = fetchURL('http://www.omegahat.org/RCurl/index.html') 35 | cat(class(rr), length(rr), if(is.character(rr)) nchar(rr), attr(rr, "Content-Type"), "\n") 36 | 37 | 38 | curl = getCurlHandle() 39 | hh = dynCurlReader(curl, header = TRUE, max = 500) 40 | rr = fetchURL(pdf, header = hh, curl = curl, binary = TRUE, followlocation = TRUE) 41 | print(names(rr)) 42 | print(rr$header) 43 | 44 | 45 | curl = getCurlHandle() 46 | hh = dynCurlReader(curl, header = TRUE, max = 500) 47 | try(fetchURL('http://www.omegahat.org/RCurl/index.html', header = hh, curl = curl, binary = TRUE, followlocation = TRUE)) 48 | rr = hh$getResult() 49 | print(nchar(rr$body)) 50 | stopifnot(as.integer(rr$header["Content-Length"]) > nchar(rr$body)) 51 | -------------------------------------------------------------------------------- /tests/dynSetReader.R: -------------------------------------------------------------------------------- 1 | # 2 | # This is an example of where we read the header and then set the options 3 | # in the curl handle to read the body ofthe response. 4 | # 5 | 6 | library(RCurl) 7 | 8 | reader = dynCurlReader() 9 | status = curlPerform(url = "http://ws.audioscrobbler.com/2.0/?method=library%2Egetartists&user=oso&api_key=de933ba987ea45f82a73acd0d82071c3", 10 | headerfunction = reader$update, 11 | curl = reader$curl()) 12 | 13 | Encoding(reader$value()) # UTF-8 14 | 15 | -------------------------------------------------------------------------------- /tests/formUpload.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | txt = paste(readLines("formUpload.R"), collapse = "\n") 3 | z = postForm("http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi", datafile = txt, txt = "some text") 4 | 5 | 6 | h = basicTextGatherer() 7 | curlPerform(url = "http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi", 8 | # postfields = c(file = txt, output = "text"), 9 | postfields = c(datafile = txt, txt = "some text"), 10 | httpheader = c('Content-Type' = 'text/plain'), 11 | header = TRUE, 12 | verbose = TRUE, 13 | writefunction = h$update) 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/ftpUpload.R: -------------------------------------------------------------------------------- 1 | #INFILESIZE_LARGE option. 2 | 3 | if(exists("FTPTestPassword")) { 4 | up = RCurl:::uploadFunctionHandler("Some text to be uploaded into a file", TRUE) 5 | curlPerform(url = "ftp://duncan@laptop17/ftp/zoe", 6 | upload = TRUE, 7 | userpwd = FTPTestPassword, 8 | readfunction = up 9 | ) 10 | } 11 | 12 | if(exists("FTPTestPassword")) { 13 | d = debugGatherer() 14 | curlPerform(url = "ftp://laptop17/ftp/Election.rda", 15 | upload = TRUE, 16 | readfunction = uploadFunction("/Users/duncan/Election08Polls.rda"), 17 | userpwd = FTPTestPassword, 18 | verbose = TRUE, debugfunction = d$update, 19 | postquote = c("CWD subdir", "RNFR Election.rda", "RNTO ElectionPolls.rda") 20 | ) 21 | } 22 | 23 | if(exists("FTPTestPassword")) { 24 | curlPerform(url = "ftp://laptop17/ftp/temp/Election.rda", 25 | upload = TRUE, 26 | userpwd = FTPTestPassword, 27 | readfunction = uploadFunction("/Users/duncan/Election08Polls.rda"), 28 | prequote = c("mkdir /ftp/temp") 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /tests/info.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | curl = getCurlHandle() 4 | u = getURL("http://www.omegahat.org", curl = curl) 5 | getCurlInfo(curl) 6 | 7 | 8 | # From doc/examples in the curl distribution. 9 | 10 | curl = getCurlHandle() 11 | u = getURL("https://www.networking4all.com/", ssl.verifypeer = FALSE, certinfo = TRUE, curl = curl) 12 | sapply(getCurlInfo(curl)$certinfo, paste, collapse = "\n") 13 | 14 | 15 | curl = getCurlHandle() 16 | u = getURL("https://svn.boost.org/", certinfo = TRUE, curl = curl, ssl.verifypeer = FALSE) 17 | sapply(getCurlInfo(curl)$certinfo, paste, collapse = "\n") 18 | 19 | -------------------------------------------------------------------------------- /tests/jpeg.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | url = "http://www.omegahat.net/Rcartogram/demo.jpg" 4 | header = RCurl:::basicTextGatherer() 5 | ans = getBinaryURL(url, headerfunction = header$update) 6 | 7 | 8 | url = "http://eeyore.ucdavis.edu/stat141/data/Elections/NYExitData.rda" 9 | header = RCurl:::basicTextGatherer() 10 | ans = getBinaryURL(url, headerfunction = header$update) 11 | -------------------------------------------------------------------------------- /tests/multi.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | urls = sprintf("http://www.omegahat.org/RCurl/%s", c("index.html", "FAQ.html", "Changes.html")) 3 | a = getURLAsynchronous(urls) # , .opts = list(verbose = TRUE)) 4 | 5 | 6 | mh = getCurlMultiHandle() 7 | a = getURLAsynchronous(urls, multiHandle = mh) # , .opts = list(verbose = TRUE)) 8 | 9 | -------------------------------------------------------------------------------- /tests/multi2.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | urls = sprintf("http://www.omegahat.org/RCurl/%s", c("index.html", "FAQ.html", "Changes.html")) 3 | 4 | h1 = getCurlHandle(url = urls[1]) 5 | h2 = getCurlHandle(url = urls[2]) 6 | 7 | mh = getCurlMultiHandle() 8 | push(mh, h1) 9 | push(mh, h2) 10 | 11 | curlMultiPerform(mh) 12 | gc() 13 | rm(h1, h2) 14 | gc() 15 | rm(mh) 16 | gc() 17 | 18 | -------------------------------------------------------------------------------- /tests/multi3.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | urls = sprintf("http://www.omegahat.org/RCurl/%s", c("index.html", "FAQ.html", "Changes.html")) 3 | 4 | multiHandle <- getCurlMultiHandle() 5 | content <- list() 6 | for(i in seq(along.with = urls)) { 7 | curl <- getCurlHandle() 8 | print(curl) 9 | content[[i]] <- basicTextGatherer() 10 | # opts <- curlOptions() 11 | curlSetOpt(url = urls[i], writefunction = content[[i]]$update, curl = curl) 12 | multiHandle <- push(multiHandle, curl) 13 | } 14 | 15 | rm(curl) 16 | gc() 17 | 18 | request <- list(multiHandle = multiHandle, content = content) 19 | complete(request$multiHandle) 20 | body <- lapply(request$content, function(x) x$value()) 21 | curlInfo <- lapply(request$multiHandle@subhandles, function(x) getCurlInfo(x)) 22 | 23 | 24 | rm(request, multiHandle) 25 | gc() 26 | gc() 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/multi4.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | urls = sprintf("http://www.omegahat.org/RCurl/%s", c("index.html", "FAQ.html", "Changes.html")) 3 | 4 | multiHandle <- getCurlMultiHandle() 5 | content <- list() 6 | for(i in seq(along.with = urls)) { 7 | curl <- getCurlHandle() 8 | print(curl@ref) 9 | content[[i]] <- basicTextGatherer() 10 | # opts <- curlOptions() 11 | curlSetOpt(url = urls[i], writefunction = content[[i]]$update, curl = curl) 12 | multiHandle <- push(multiHandle, curl, as.character(i)) 13 | # pop(multiHandle, as.character(i)) 14 | } 15 | 16 | rm(multiHandle) 17 | gc() 18 | gc() 19 | rm(curl) 20 | gc() 21 | 22 | -------------------------------------------------------------------------------- /tests/multiPost.R: -------------------------------------------------------------------------------- 1 | # This illustrates how to simultaneously make multiple POST requests 2 | # for HTTPPOST forms, i.e., in parallel rather than sequentially. 3 | # 4 | # This is similar to getURLAsynchronous(), but it handles POSTing a form 5 | # where the style is HTTPPOST. 6 | # 7 | 8 | library(RCurl) 9 | 10 | url = "http://requestb.in/1fv3hc61" 11 | 12 | # Fake arguments 13 | args = list(list(a = "1", b = "xyz"), 14 | list(animal = "giraffe"), 15 | list(part1 = "2", part2 = "abc", part3 = "TRUE")) 16 | 17 | # Fake URLs 18 | urls = rep(url, length(args)) 19 | 20 | # Create a multi handle 21 | multiH = getCurlMultiHandle() 22 | # Create a handle for each inividual request 23 | # giving it its own result gatherer, setting 24 | # the form arguments with the new buildPostForm() fn. 25 | gatherers = mapply(function(u, arg) { 26 | h = getCurlHandle() 27 | r = dynCurlReader(h, baseURL = u) 28 | curlSetOpt(url = u, headerfunction = r$update, curl = h, verbose = TRUE) 29 | RCurl:::buildPostForm(arg, h) 30 | push(multiH, h) 31 | r 32 | }, urls, args, SIMPLIFY = FALSE) 33 | 34 | complete(multiH) 35 | 36 | ans = lapply(gatherers, function(x) x$value()) 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/multi_basic.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | 3 | mh <- getCurlMultiHandle() 4 | curl = getCurlHandle() 5 | mh = push(mh, curl) 6 | mh = pop(mh, curl) 7 | 8 | mh = push(mh, curl, "bob") 9 | mh = pop(mh, curl) 10 | 11 | rm(curl) 12 | gc() 13 | 14 | mh@subhandles 15 | rm(mh) 16 | gc() 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/post.R: -------------------------------------------------------------------------------- 1 | library(RCurl) 2 | h = basicHeaderGatherer() 3 | postForm("http://www.omegahat.org/wewanttoget/a404status", 4 | .opts=curlOptions(headerfunction = h$update, writefunction = h$update, verbose=TRUE), 5 | foo="bar") 6 | stopifnot(h$value()[["status"]] == "404") 7 | 8 | 9 | h = basicHeaderGatherer() 10 | b = basicHeaderGatherer() 11 | postForm("http://www.omegahat.org/wewanttoget/a404status", 12 | .opts=curlOptions(headerfunction = h$update, writefunction = b$update, verbose=TRUE), 13 | foo="bar") 14 | stopifnot(h$value()[["status"]] == "404") 15 | 16 | 17 | 18 | 19 | curl = getCurlHandle() 20 | h = dynCurlReader(curl) 21 | postForm("http://www.omegahat.org/wewanttoget/a404status", 22 | .opts=curlOptions(headerfunction = h$update, verbose=TRUE), 23 | foo="bar") 24 | stopifnot(parseHTTPHeader(h$header())[["status"]] == "404") 25 | -------------------------------------------------------------------------------- /tests/postFormBinary.R: -------------------------------------------------------------------------------- 1 | if(FALSE) { 2 | library(RCurl) 3 | 4 | x = postForm("http://www.razorvine.net/test/utf8form/utf8formaccepter.sn", 5 | .params = list(text = "%E2%82%AC%C3%AB%C2%A9%E2%99%A1", outputencoding = "UTF-8"), 6 | style = 'POST', .opts = list(verbose = TRUE)) 7 | 8 | header = dynCurlReader() 9 | x = postForm("http://www.razorvine.net/test/utf8form/utf8formaccepter.sn", 10 | .params = list(text = "%E2%82%AC%C3%AB%C2%A9%E2%99%A1", outputencoding = "UTF-8"), 11 | style = 'POST', .opts = list(verbose = TRUE, writefunction = header$update), curl = header$curl()) 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /utf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SEXP 4 | R_tt() 5 | { 6 | mkCharLenCE(); 7 | } 8 | --------------------------------------------------------------------------------