-
Notifications
You must be signed in to change notification settings - Fork 86
/
httpuv.cpp
748 lines (644 loc) · 20.8 KB
/
httpuv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <map>
#include <iomanip>
#include <signal.h>
#include <errno.h>
#include <uv.h>
#include <base64.hpp>
#include "uvutil.h"
#include "http.h"
#include "filedatasource.h"
std::string normalizeHeaderName(const std::string& name) {
std::string result = name;
for (std::string::iterator it = result.begin();
it != result.end();
it++) {
if (*it == '-')
*it = '_';
else if (*it >= 'a' && *it <= 'z')
*it = *it + ('A' - 'a');
}
return result;
}
const std::string& getStatusDescription(int code) {
static std::map<int, std::string> statusDescs;
static std::string unknown("Dunno");
if (statusDescs.size() == 0) {
statusDescs[100] = "Continue";
statusDescs[101] = "Switching Protocols";
statusDescs[200] = "OK";
statusDescs[201] = "Created";
statusDescs[202] = "Accepted";
statusDescs[203] = "Non-Authoritative Information";
statusDescs[204] = "No Content";
statusDescs[205] = "Reset Content";
statusDescs[206] = "Partial Content";
statusDescs[300] = "Multiple Choices";
statusDescs[301] = "Moved Permanently";
statusDescs[302] = "Found";
statusDescs[303] = "See Other";
statusDescs[304] = "Not Modified";
statusDescs[305] = "Use Proxy";
statusDescs[307] = "Temporary Redirect";
statusDescs[400] = "Bad Request";
statusDescs[401] = "Unauthorized";
statusDescs[402] = "Payment Required";
statusDescs[403] = "Forbidden";
statusDescs[404] = "Not Found";
statusDescs[405] = "Method Not Allowed";
statusDescs[406] = "Not Acceptable";
statusDescs[407] = "Proxy Authentication Required";
statusDescs[408] = "Request Timeout";
statusDescs[409] = "Conflict";
statusDescs[410] = "Gone";
statusDescs[411] = "Length Required";
statusDescs[412] = "Precondition Failed";
statusDescs[413] = "Request Entity Too Large";
statusDescs[414] = "Request-URI Too Long";
statusDescs[415] = "Unsupported Media Type";
statusDescs[416] = "Requested Range Not Satisifable";
statusDescs[417] = "Expectation Failed";
statusDescs[500] = "Internal Server Error";
statusDescs[501] = "Not Implemented";
statusDescs[502] = "Bad Gateway";
statusDescs[503] = "Service Unavailable";
statusDescs[504] = "Gateway Timeout";
statusDescs[505] = "HTTP Version Not Supported";
}
std::map<int, std::string>::iterator it = statusDescs.find(code);
if (it != statusDescs.end())
return it->second;
else
return unknown;
}
template <typename T>
std::string externalize(T* pServer) {
std::ostringstream os;
os << reinterpret_cast<uintptr_t>(pServer);
return os.str();
}
template <typename T>
T* internalize(std::string serverHandle) {
std::istringstream is(serverHandle);
uintptr_t result;
is >> result;
return reinterpret_cast<T*>(result);
}
void requestToEnv(HttpRequest* pRequest, Rcpp::Environment* pEnv) {
using namespace Rcpp;
Environment& env = *pEnv;
std::string url = pRequest->url();
size_t qsIndex = url.find('?');
std::string path, queryString;
if (qsIndex == std::string::npos)
path = url;
else {
path = url.substr(0, qsIndex);
queryString = url.substr(qsIndex);
}
env["REQUEST_METHOD"] = pRequest->method();
env["SCRIPT_NAME"] = std::string("");
env["PATH_INFO"] = path;
env["QUERY_STRING"] = queryString;
env["rook.version"] = "1.1-0";
env["rook.url_scheme"] = "http";
Address addr = pRequest->serverAddress();
env["SERVER_NAME"] = addr.host;
std::ostringstream portstr;
portstr << addr.port;
env["SERVER_PORT"] = portstr.str();
Address raddr = pRequest->clientAddress();
env["REMOTE_ADDR"] = raddr.host;
std::ostringstream rportstr;
rportstr << raddr.port;
env["REMOTE_PORT"] = rportstr.str();
const RequestHeaders& headers = pRequest->headers();
for (RequestHeaders::const_iterator it = headers.begin();
it != headers.end();
it++) {
env["HTTP_" + normalizeHeaderName(it->first)] = it->second;
}
}
class RawVectorDataSource : public DataSource {
Rcpp::RawVector _vector;
R_len_t _pos;
public:
RawVectorDataSource(const Rcpp::RawVector& vector) : _vector(vector), _pos(0) {
}
uint64_t size() const {
return _vector.size();
}
uv_buf_t getData(size_t bytesDesired) {
size_t bytes = _vector.size() - _pos;
// Are we at the end?
if (bytes == 0)
return uv_buf_init(NULL, 0);
if (bytesDesired < bytes)
bytes = bytesDesired;
char* buf = (char*)malloc(bytes);
if (!buf) {
throw Rcpp::exception("Couldn't allocate buffer");
}
for (size_t i = 0; i < bytes; i++) {
buf[i] = _vector[_pos + i];
}
_pos += bytes;
return uv_buf_init(buf, bytes);
}
void freeData(uv_buf_t buffer) {
free(buffer.base);
}
void close() {
delete this;
}
};
HttpResponse* listToResponse(HttpRequest* pRequest,
const Rcpp::List& response) {
using namespace Rcpp;
if (response.isNULL() || response.size() == 0)
return NULL;
CharacterVector names = response.names();
int status = Rcpp::as<int>(response["status"]);
std::string statusDesc = getStatusDescription(status);
List responseHeaders = response["headers"];
// Self-frees when response is written
DataSource* pDataSource = NULL;
// The response can either contain:
// - bodyFile: String value that names the file that should be streamed
// - body: Character vector (which is charToRaw-ed) or raw vector, or NULL
if (std::find(names.begin(), names.end(), "bodyFile") != names.end()) {
FileDataSource* pFDS = new FileDataSource();
pFDS->initialize(Rcpp::as<std::string>(response["bodyFile"]),
Rcpp::as<bool>(response["bodyFileOwned"]));
pDataSource = pFDS;
}
else if (Rf_isString(response["body"])) {
RawVector responseBytes = Function("charToRaw")(response["body"]);
pDataSource = new RawVectorDataSource(responseBytes);
}
else {
RawVector responseBytes = response["body"];
pDataSource = new RawVectorDataSource(responseBytes);
}
HttpResponse* pResp = new HttpResponse(pRequest, status, statusDesc,
pDataSource);
CharacterVector headerNames = responseHeaders.names();
for (R_len_t i = 0; i < responseHeaders.size(); i++) {
pResp->addHeader(
std::string((char*)headerNames[i], headerNames[i].size()),
Rcpp::as<std::string>(responseHeaders[i]));
}
return pResp;
}
class RWebApplication : public WebApplication {
private:
Rcpp::Function _onHeaders;
Rcpp::Function _onBodyData;
Rcpp::Function _onRequest;
Rcpp::Function _onWSOpen;
Rcpp::Function _onWSMessage;
Rcpp::Function _onWSClose;
public:
RWebApplication(Rcpp::Function onHeaders,
Rcpp::Function onBodyData,
Rcpp::Function onRequest,
Rcpp::Function onWSOpen,
Rcpp::Function onWSMessage,
Rcpp::Function onWSClose) :
_onHeaders(onHeaders), _onBodyData(onBodyData), _onRequest(onRequest),
_onWSOpen(onWSOpen), _onWSMessage(onWSMessage), _onWSClose(onWSClose) {
}
virtual ~RWebApplication() {
}
virtual HttpResponse* onHeaders(HttpRequest* pRequest) {
if (_onHeaders.isNULL()) {
return NULL;
}
requestToEnv(pRequest, &pRequest->env());
Rcpp::List response(_onHeaders(pRequest->env()));
return listToResponse(pRequest, response);
}
virtual void onBodyData(HttpRequest* pRequest,
const char* pData, size_t length) {
Rcpp::RawVector rawVector(length);
std::copy(pData, pData + length, rawVector.begin());
_onBodyData(pRequest->env(), rawVector);
}
virtual HttpResponse* getResponse(HttpRequest* pRequest) {
Rcpp::List response(_onRequest(pRequest->env()));
return listToResponse(pRequest, response);
}
void onWSOpen(HttpRequest* pRequest) {
requestToEnv(pRequest, &pRequest->env());
_onWSOpen(externalize<WebSocketConnection>(pRequest->websocket()), pRequest->env());
}
void onWSMessage(WebSocketConnection* pConn, bool binary, const char* data, size_t len) {
if (binary)
_onWSMessage(externalize<WebSocketConnection>(pConn), binary, std::vector<uint8_t>(data, data + len));
else
_onWSMessage(externalize<WebSocketConnection>(pConn), binary, std::string(data, len));
}
void onWSClose(WebSocketConnection* pConn) {
_onWSClose(externalize<WebSocketConnection>(pConn));
}
};
// [[Rcpp::export]]
void sendWSMessage(std::string conn, bool binary, Rcpp::RObject message) {
WebSocketConnection* wsc = internalize<WebSocketConnection>(conn);
if (binary) {
Rcpp::RawVector raw = Rcpp::as<Rcpp::RawVector>(message);
wsc->sendWSMessage(Binary, reinterpret_cast<char*>(&raw[0]), raw.size());
} else {
std::string str = Rcpp::as<std::string>(message);
wsc->sendWSMessage(Text, str.c_str(), str.size());
}
}
// [[Rcpp::export]]
void closeWS(std::string conn) {
WebSocketConnection* wsc = internalize<WebSocketConnection>(conn);
wsc->closeWS();
}
void destroyServer(std::string handle);
// [[Rcpp::export]]
Rcpp::RObject makeTcpServer(const std::string& host, int port,
Rcpp::Function onHeaders,
Rcpp::Function onBodyData,
Rcpp::Function onRequest,
Rcpp::Function onWSOpen,
Rcpp::Function onWSMessage,
Rcpp::Function onWSClose) {
using namespace Rcpp;
// Deleted when owning pServer is deleted. If pServer creation fails,
// it's still createTcpServer's responsibility to delete pHandler.
RWebApplication* pHandler =
new RWebApplication(onHeaders, onBodyData, onRequest, onWSOpen,
onWSMessage, onWSClose);
uv_stream_t* pServer = createTcpServer(
uv_default_loop(), host.c_str(), port, (WebApplication*)pHandler);
if (!pServer) {
return R_NilValue;
}
return Rcpp::wrap(externalize<uv_stream_t>(pServer));
}
// [[Rcpp::export]]
Rcpp::RObject makePipeServer(const std::string& name,
int mask,
Rcpp::Function onHeaders,
Rcpp::Function onBodyData,
Rcpp::Function onRequest,
Rcpp::Function onWSOpen,
Rcpp::Function onWSMessage,
Rcpp::Function onWSClose) {
using namespace Rcpp;
// Deleted when owning pServer is deleted. If pServer creation fails,
// it's still createTcpServer's responsibility to delete pHandler.
RWebApplication* pHandler =
new RWebApplication(onHeaders, onBodyData, onRequest, onWSOpen,
onWSMessage, onWSClose);
uv_stream_t* pServer = createPipeServer(
uv_default_loop(), name.c_str(), mask, (WebApplication*)pHandler);
if (!pServer) {
return R_NilValue;
}
return Rcpp::wrap(externalize(pServer));
}
// [[Rcpp::export]]
void destroyServer(std::string handle) {
uv_stream_t* pServer = internalize<uv_stream_t>(handle);
freeServer(pServer);
}
void dummy_close_cb(uv_handle_t* handle) {
}
void stop_loop_timer_cb(uv_timer_t* handle, int status) {
uv_stop(handle->loop);
}
// Run the libuv default loop for roughly timeoutMillis, then stop
// [[Rcpp::export]]
bool run(int timeoutMillis) {
static uv_timer_t timer_req = {0};
int r;
if (!timer_req.loop) {
r = uv_timer_init(uv_default_loop(), &timer_req);
if (r) {
throwLastError(uv_default_loop(),
"Failed to initialize libuv timeout timer: ");
}
}
if (timeoutMillis > 0) {
uv_timer_stop(&timer_req);
r = uv_timer_start(&timer_req, &stop_loop_timer_cb, timeoutMillis, 0);
if (r) {
throwLastError(uv_default_loop(),
"Failed to start libuv timeout timer: ");
}
}
// Must ignore SIGPIPE when libuv code is running, otherwise unexpectedly
// closing connections kill us
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif
return uv_run(uv_default_loop(), timeoutMillis == NA_INTEGER ? UV_RUN_NOWAIT : UV_RUN_ONCE);
}
// [[Rcpp::export]]
void stopLoop() {
uv_stop(uv_default_loop());
}
// [[Rcpp::export]]
std::string base64encode(const Rcpp::RawVector& x) {
return b64encode(x.begin(), x.end());
}
/*
* Daemonizing
*
* On UNIX-like environments: Uses the R event loop to trigger the libuv default loop. This is a similar mechanism as that used by Rhttpd.
* It adds an event listener on the port where the TCP server was created by libuv. This triggers uv_run on the
* default loop any time there is an event on the server port. It also adds an event listener to a file descriptor
* exposed by the uv_default_loop to trigger uv_run whenever necessary. It uses the non-blocking version
* of uv_run (UV_RUN_NOWAIT).
*
* On Windows: creates a thread that runs the libuv default loop. It uses the usual "service" mechanism
* on the new thread (it uses the run function defined above). TODO: check synchronization.
*
*/
#ifndef WIN32
#include <R_ext/eventloop.h>
#define UVSERVERACTIVITY 55
#define UVLOOPACTIVITY 57
#endif
void loop_input_handler(void *data) {
#ifndef WIN32
// this fake loop is here to force
// processing events
// deals with strange behavior in some Ubuntu installations
for (int i=0; i < 5; ++i) {
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
}
#else
bool res = 1;
while (res) {
res = run(100);
Sleep(1);
}
#endif
}
#ifdef WIN32
static DWORD WINAPI ServerThreadProc(LPVOID lpParameter) {
loop_input_handler(lpParameter);
return 0;
}
#endif
class DaemonizedServer {
public:
uv_stream_t *_pServer;
#ifndef WIN32
InputHandler *serverHandler;
InputHandler *loopHandler;
#else
HANDLE server_thread;
#endif
DaemonizedServer(uv_stream_t *pServer)
: _pServer(pServer) {}
~DaemonizedServer() {
#ifndef WIN32
if (loopHandler) {
removeInputHandler(&R_InputHandlers, loopHandler);
}
if (serverHandler) {
removeInputHandler(&R_InputHandlers, serverHandler);
}
#else
if (server_thread) {
DWORD ts = 0;
if (GetExitCodeThread(server_thread, &ts) && ts == STILL_ACTIVE)
TerminateThread(server_thread, 0);
server_thread = 0;
}
#endif
if (_pServer) {
freeServer(_pServer);
}
}
void setup(){
};
};
// [[Rcpp::export]]
Rcpp::RObject daemonize(std::string handle) {
uv_stream_t *pServer = internalize<uv_stream_t >(handle);
DaemonizedServer *dServer = new DaemonizedServer(pServer);
#ifndef WIN32
int fd = pServer->io_watcher.fd;
dServer->serverHandler = addInputHandler(R_InputHandlers, fd, &loop_input_handler, UVSERVERACTIVITY);
fd = uv_backend_fd(uv_default_loop());
dServer->loopHandler = addInputHandler(R_InputHandlers, fd, &loop_input_handler, UVLOOPACTIVITY);
#else
if (dServer->server_thread) {
DWORD ts = 0;
if (GetExitCodeThread(dServer->server_thread, &ts) && ts == STILL_ACTIVE)
TerminateThread(dServer->server_thread, 0);
dServer->server_thread = 0;
}
dServer->server_thread = CreateThread(NULL, 0, ServerThreadProc, 0, 0, 0);
#endif
return Rcpp::wrap(externalize(dServer));
}
// [[Rcpp::export]]
void destroyDaemonizedServer(std::string handle) {
DaemonizedServer *dServer = internalize<DaemonizedServer >(handle);
delete dServer;
}
static std::string allowed = ";,/?:@&=+$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_.!~*'()";
bool isReservedUrlChar(char c) {
switch (c) {
case ';':
case ',':
case '/':
case '?':
case ':':
case '@':
case '&':
case '=':
case '+':
case '$':
return true;
default:
return false;
}
}
bool needsEscape(char c, bool encodeReserved) {
if (c >= 'a' && c <= 'z')
return false;
if (c >= 'A' && c <= 'Z')
return false;
if (c >= '0' && c <= '9')
return false;
if (isReservedUrlChar(c))
return encodeReserved;
switch (c) {
case '-':
case '_':
case '.':
case '!':
case '~':
case '*':
case '\'':
case '(':
case ')':
return false;
}
return true;
}
std::string doEncodeURI(std::string value, bool encodeReserved) {
std::ostringstream os;
os << std::hex << std::uppercase;
for (std::string::const_iterator it = value.begin();
it != value.end();
it++) {
if (!needsEscape(*it, encodeReserved)) {
os << *it;
} else {
os << '%' << std::setw(2) << (int)*it;
}
}
return os.str();
}
//' URI encoding/decoding
//'
//' Encodes/decodes strings using URI encoding/decoding in the same way that web
//' browsers do. The precise behaviors of these functions can be found at
//' developer.mozilla.org:
//' \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI}{encodeURI},
//' \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent}{encodeURIComponent},
//' \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI}{decodeURI},
//' \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent}{decodeURIComponent}
//'
//' Intended as a faster replacement for \code{\link[utils]{URLencode}} and
//' \code{\link[utils]{URLdecode}}.
//'
//' encodeURI differs from encodeURIComponent in that the former will not encode
//' reserved characters: \code{;,/?:@@&=+$}
//'
//' decodeURI differs from decodeURIComponent in that it will refuse to decode
//' encoded sequences that decode to a reserved character. (If in doubt, use
//' decodeURIComponent.)
//'
//' The only way these functions differ from web browsers is in the encoding of
//' non-ASCII characters. All non-ASCII characters will be escaped byte-by-byte.
//' If conformant non-ASCII behavior is important, ensure that your input vector
//' is UTF-8 encoded before calling encodeURI or encodeURIComponent.
//'
//' @param value Character vector to be encoded or decoded.
//' @return Encoded or decoded character vector of the same length as the
//' input value.
//'
//' @export
// [[Rcpp::export]]
std::vector<std::string> encodeURI(std::vector<std::string> value) {
for (std::vector<std::string>::iterator it = value.begin();
it != value.end();
it++) {
*it = doEncodeURI(*it, false);
}
return value;
}
//' @rdname encodeURI
//' @export
// [[Rcpp::export]]
std::vector<std::string> encodeURIComponent(std::vector<std::string> value) {
for (std::vector<std::string>::iterator it = value.begin();
it != value.end();
it++) {
*it = doEncodeURI(*it, true);
}
return value;
}
int hexToInt(char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'A': case 'a': return 10;
case 'B': case 'b': return 11;
case 'C': case 'c': return 12;
case 'D': case 'd': return 13;
case 'E': case 'e': return 14;
case 'F': case 'f': return 15;
default: return -1;
}
}
std::string doDecodeURI(std::string value, bool component) {
std::ostringstream os;
for (std::string::const_iterator it = value.begin();
it != value.end();
it++) {
// If there aren't enough characters left for this to be a
// valid escape code, just use the character and move on
if (it > value.end() - 3) {
os << *it;
continue;
}
if (*it == '%') {
char hi = *(++it);
char lo = *(++it);
int iHi = hexToInt(hi);
int iLo = hexToInt(lo);
if (iHi < 0 || iLo < 0) {
// Invalid escape sequence
os << '%' << hi << lo;
continue;
}
char c = (char)(iHi << 4 | iLo);
if (!component && isReservedUrlChar(c)) {
os << '%' << hi << lo;
} else {
os << c;
}
} else {
os << *it;
}
}
return os.str();
}
//' @rdname encodeURI
//' @export
// [[Rcpp::export]]
std::vector<std::string> decodeURI(std::vector<std::string> value) {
for (std::vector<std::string>::iterator it = value.begin();
it != value.end();
it++) {
*it = doDecodeURI(*it, false);
}
return value;
}
//' @rdname encodeURI
//' @export
// [[Rcpp::export]]
std::vector<std::string> decodeURIComponent(std::vector<std::string> value) {
for (std::vector<std::string>::iterator it = value.begin();
it != value.end();
it++) {
*it = doDecodeURI(*it, true);
}
return value;
}
//' Apply the value of .Random.seed to R's internal RNG state
//'
//' This function is needed in unusual cases where a C++ function calls
//' an R function which sets the value of \code{.Random.seed}. This function
//' should be called at the end of the R function to ensure that the new value
//' \code{.Random.seed} is preserved. Otherwise, Rcpp may overwrite it with a
//' previous value.
//'
//' @keywords internal
//' @export
// [[Rcpp::export]]
void getRNGState() {
GetRNGstate();
}