1 #include <curl/curl.h>
2 #include <Rdefines.h>
3
4 typedef struct {
5 char name[40];
6 int val;
7 } NameValue;
8
9 NameValue CurlErrorNames[] = {
10
11 {"OK", CURLE_OK},
12 {"UNSUPPORTED_PROTOCOL", CURLE_UNSUPPORTED_PROTOCOL},
13 {"FAILED_INIT", CURLE_FAILED_INIT},
14 {"URL_MALFORMAT", CURLE_URL_MALFORMAT},
15 {"URL_MALFORMAT_USER", CURLE_URL_MALFORMAT_USER},
16 {"COULDNT_RESOLVE_PROXY", CURLE_COULDNT_RESOLVE_PROXY},
17 {"COULDNT_RESOLVE_HOST", CURLE_COULDNT_RESOLVE_HOST},
18 {"COULDNT_CONNECT", CURLE_COULDNT_CONNECT},
19 {"FTP_WEIRD_SERVER_REPLY", CURLE_FTP_WEIRD_SERVER_REPLY},
20 {"FTP_ACCESS_DENIED", CURLE_FTP_ACCESS_DENIED},
21 {"FTP_USER_PASSWORD_INCORRECT", CURLE_FTP_USER_PASSWORD_INCORRECT},
22 {"FTP_WEIRD_PASS_REPLY", CURLE_FTP_WEIRD_PASS_REPLY},
23 {"FTP_WEIRD_USER_REPLY", CURLE_FTP_WEIRD_USER_REPLY},
24 {"FTP_WEIRD_PASV_REPLY", CURLE_FTP_WEIRD_PASV_REPLY},
25 {"FTP_WEIRD_227_FORMAT", CURLE_FTP_WEIRD_227_FORMAT},
26 {"FTP_CANT_GET_HOST", CURLE_FTP_CANT_GET_HOST},
27 {"FTP_CANT_RECONNECT", CURLE_FTP_CANT_RECONNECT},
28 {"FTP_COULDNT_SET_BINARY", CURLE_FTP_COULDNT_SET_BINARY},
29 {"PARTIAL_FILE", CURLE_PARTIAL_FILE},
30 {"FTP_COULDNT_RETR_FILE", CURLE_FTP_COULDNT_RETR_FILE},
31 {"FTP_WRITE_ERROR", CURLE_FTP_WRITE_ERROR},
32 {"FTP_QUOTE_ERROR", CURLE_FTP_QUOTE_ERROR},
33 {"HTTP_RETURNED_ERROR", CURLE_HTTP_RETURNED_ERROR},
34 {"WRITE_ERROR", CURLE_WRITE_ERROR},
35 {"MALFORMAT_USER", CURLE_MALFORMAT_USER},
36 {"FTP_COULDNT_STOR_FILE", CURLE_FTP_COULDNT_STOR_FILE},
37 {"READ_ERROR", CURLE_READ_ERROR},
38 {"OUT_OF_MEMORY", CURLE_OUT_OF_MEMORY},
39 {"OPERATION_TIMEOUTED", CURLE_OPERATION_TIMEOUTED},
40 {"FTP_COULDNT_SET_ASCII", CURLE_FTP_COULDNT_SET_ASCII},
41 {"FTP_PORT_FAILED", CURLE_FTP_PORT_FAILED},
42 {"FTP_COULDNT_USE_REST", CURLE_FTP_COULDNT_USE_REST},
43 {"FTP_COULDNT_GET_SIZE", CURLE_FTP_COULDNT_GET_SIZE},
44 {"HTTP_RANGE_ERROR", CURLE_HTTP_RANGE_ERROR},
45 {"HTTP_POST_ERROR", CURLE_HTTP_POST_ERROR},
46 {"SSL_CONNECT_ERROR", CURLE_SSL_CONNECT_ERROR},
47 {"BAD_DOWNLOAD_RESUME", CURLE_BAD_DOWNLOAD_RESUME},
48 {"FILE_COULDNT_READ_FILE", CURLE_FILE_COULDNT_READ_FILE},
49 {"LDAP_CANNOT_BIND", CURLE_LDAP_CANNOT_BIND},
50 {"LDAP_SEARCH_FAILED", CURLE_LDAP_SEARCH_FAILED},
51 {"LIBRARY_NOT_FOUND", CURLE_LIBRARY_NOT_FOUND},
52 {"FUNCTION_NOT_FOUND", CURLE_FUNCTION_NOT_FOUND},
53 {"ABORTED_BY_CALLBACK", CURLE_ABORTED_BY_CALLBACK},
54 {"BAD_FUNCTION_ARGUMENT", CURLE_BAD_FUNCTION_ARGUMENT},
55 {"BAD_CALLING_ORDER", CURLE_BAD_CALLING_ORDER},
56 {"INTERFACE_FAILED", CURLE_HTTP_PORT_FAILED/*This is really CURLE_INTERFACE_FAILED in the newer versions. */},
57 {"BAD_PASSWORD_ENTERED", CURLE_BAD_PASSWORD_ENTERED},
58 {"TOO_MANY_REDIRECTS ", CURLE_TOO_MANY_REDIRECTS },
59 {"UNKNOWN_TELNET_OPTION", CURLE_UNKNOWN_TELNET_OPTION},
60 {"TELNET_OPTION_SYNTAX ", CURLE_TELNET_OPTION_SYNTAX },
61 {"OBSOLETE", CURLE_OBSOLETE},
62 {"SSL_PEER_CERTIFICATE", CURLE_SSL_PEER_CERTIFICATE},
63 {"GOT_NOTHING", CURLE_GOT_NOTHING},
64 {"SSL_ENGINE_NOTFOUND", CURLE_SSL_ENGINE_NOTFOUND},
65 {"SSL_ENGINE_SETFAILED", CURLE_SSL_ENGINE_SETFAILED},
66
67 {"SEND_ERROR", CURLE_SEND_ERROR},
68 {"RECV_ERROR", CURLE_RECV_ERROR},
69 {"SHARE_IN_USE", CURLE_SHARE_IN_USE},
70 {"SSL_CERTPROBLEM", CURLE_SSL_CERTPROBLEM},
71 {"SSL_CIPHER", CURLE_SSL_CIPHER},
72 {"SSL_CACERT", CURLE_SSL_CACERT},
73 {"BAD_CONTENT_ENCODING", CURLE_BAD_CONTENT_ENCODING},
74 {"LDAP_INVALID_URL", CURLE_LDAP_INVALID_URL},
75 {"FILESIZE_EXCEEDED", CURLE_FILESIZE_EXCEEDED},
76 {"FTP_SSL_FAILED", CURLE_FTP_SSL_FAILED}
77 };
78
79 #include "CurlOptEnums.h"
80 #include "CurlInfoEnums.h"
81
82
83 SEXP
createNamedEnum(NameValue * Els,int n)84 createNamedEnum(NameValue *Els, int n)
85 {
86 int i;
87 SEXP ans, names;
88 PROTECT(ans = allocVector(INTSXP, n));
89 PROTECT(names = allocVector(STRSXP, n));
90
91 for(i = 0; i < n ; i++) {
92 INTEGER(ans)[i] = Els[i].val;
93 SET_STRING_ELT(names, i, mkChar(Els[i].name));
94 }
95 SET_NAMES(ans, names);
96 UNPROTECT(2);
97 return(ans);
98 }
99
100 SEXP
R_getCURLOptionEnum(void)101 R_getCURLOptionEnum(void)
102 {
103 return(createNamedEnum(CurlOptionNames, sizeof(CurlOptionNames)/sizeof(CurlOptionNames[0])));
104 }
105
106 SEXP
R_getCURLInfoEnum(void)107 R_getCURLInfoEnum(void)
108 {
109 return(createNamedEnum(CurlInfoNames, sizeof(CurlInfoNames)/sizeof(CurlInfoNames[0])));
110 }
111
112 SEXP
R_getCURLErrorEnum(void)113 R_getCURLErrorEnum(void)
114 {
115 return(createNamedEnum(CurlErrorNames, sizeof(CurlErrorNames)/sizeof(CurlErrorNames[0])));
116 }
117
118