void R_FTPClose(void *ctx) { if(!initialized) internet_Init(); if(initialized > 0) (*ptr->FTPClose)(ctx); else error(_("internet routines cannot be loaded")); }
void extR_HTTPDStop(void) { if(!initialized) internet_Init(); if(initialized > 0) (*ptr->HTTPDStop)(); else error(_("internet routines cannot be loaded")); }
int extR_HTTPDCreate(const char *ip, int port) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->HTTPDCreate)(ip, port); else error(_("internet routines cannot be loaded")); return -1; }
SEXP Rdownload(SEXP args) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->download)(args); else { error(_("internet routines cannot be loaded")); return R_NilValue; } }
int R_FTPRead(void *ctx, char *dest, int len) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->FTPRead)(ctx, dest, len); else { error(_("internet routines cannot be loaded")); return 0; } }
void *R_HTTPOpen(const char *url) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->HTTPOpen)(url, NULL, 0); else { error(_("internet routines cannot be loaded")); return NULL; } }
void *R_FTPOpen(const char *url) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->FTPOpen)(url); else { error(_("internet routines cannot be loaded")); return nullptr; } }
SEXP attribute_hidden do_curlDownload(SEXP call, SEXP op, SEXP args, SEXP rho) { checkArity(op, args); if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->curlDownload)(call, op, args, rho); else { error(_("internet routines cannot be loaded")); return R_NilValue; } }
SEXP Rsockopen(SEXP sport) { if (length(sport) != 1) error("invalid 'port' argument"); int port = asInteger(sport); if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockopen)(&port); else error(_("socket routines cannot be loaded")); return ScalarInteger(port); // The socket number }
SEXP Rsockclose(SEXP ssock) { if (length(ssock) != 1) error("invalid 'socket' argument"); int sock = asInteger(ssock); if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockclose)(&sock); else error(_("socket routines cannot be loaded")); return ScalarLogical(sock); }
Rconnection attribute_hidden R_newurl(const char *description, const char * const mode, int type) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->newurl)(description, mode, type); else { error(_("internet routines cannot be loaded")); return RHO_NO_CAST(Rconnection)nullptr; } }
Rconnection attribute_hidden R_newCurlUrl(const char *description, const char * const mode, int type) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->newcurlurl)(description, mode, type); else { error(_("internet routines cannot be loaded")); return (Rconnection)0; } return (Rconnection)0; /* -Wall */ }
attribute_hidden int Rsockselect(int nsock, int *insockfd, int *ready, int *write, double timeout) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->sockselect)(nsock, insockfd, ready, write, timeout); else { error(_("socket routines cannot be loaded")); return 0; } }
Rconnection attribute_hidden R_newsock(const char *host, int port, int server, const char * const mode, int timeout) { if(!initialized) internet_Init(); if(initialized > 0) return (*ptr->newsock)(host, port, server, mode, timeout); else { error(_("internet routines cannot be loaded")); return RHO_NO_CAST(Rconnection)nullptr; } }
SEXP Rsockread(SEXP ssock, SEXP smaxlen) { if (length(ssock) != 1) error("invalid 'socket' argument"); int sock = asInteger(ssock), maxlen = asInteger(smaxlen); char buf[maxlen+1], *abuf[1]; abuf[0] = buf; if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockread)(&sock, abuf, &maxlen); else error(_("socket routines cannot be loaded")); return Rf_ScalarString(mkCharLen(buf, maxlen)); }
SEXP Rsockconnect(SEXP sport, SEXP shost) { if (length(sport) != 1) error("invalid 'socket' argument"); int port = asInteger(sport); char *host[1]; host[0] = const_cast<char *>( translateChar(STRING_ELT(shost, 0))); if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockconnect)(&port, host); else error(_("socket routines cannot be loaded")); return ScalarInteger(port); // The socket number }
SEXP Rsockwrite(SEXP ssock, SEXP sstring) { if (length(ssock) != 1) error("invalid 'socket' argument"); int sock = asInteger(ssock), start = 0, end, len; char *buf = const_cast<char *>( translateChar(STRING_ELT(sstring, 0))), *abuf[1]; end = len = int( strlen(buf)); abuf[0] = buf; if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockwrite)(&sock, abuf, &start, &end, &len); else error(_("socket routines cannot be loaded")); return ScalarInteger(len); }
SEXP Rsocklisten(SEXP ssock) { if (length(ssock) != 1) error("invalid 'socket' argument"); int sock = asInteger(ssock), len = 256; char buf[257], *abuf[1]; abuf[0] = buf; if(!initialized) internet_Init(); if(initialized > 0) (*ptr->socklisten)(&sock, abuf, &len); else error(_("socket routines cannot be loaded")); SEXP ans = PROTECT(ScalarInteger(sock)); // The socket being listened on SEXP host = PROTECT(Rf_ScalarString(mkChar(buf))); setAttrib(ans, install("host"), host); UNPROTECT(2); return ans; }
SEXP Rsockread(SEXP ssock, SEXP smaxlen) { if (length(ssock) != 1) error("invalid 'socket' argument"); int sock = asInteger(ssock), maxlen = asInteger(smaxlen); char buf[maxlen+1], *abuf[1]; abuf[0] = buf; if(!initialized) internet_Init(); if(initialized > 0) (*ptr->sockread)(&sock, abuf, &maxlen); else error(_("socket routines cannot be loaded")); SEXP ans = PROTECT(allocVector(STRSXP, 1)); SET_STRING_ELT(ans, 0, mkCharLen(buf, maxlen)); UNPROTECT(1); return ans; }