Skip to content

Commit 9ad2230

Browse files
mkauftaf2
authored andcommitted
Add new curl features (#331)
For HTTP/2: - CURLOPT_PIPEWAIT - CURL_HTTP_VERSION_2TLS Speed control: - CURLOPT_MAX_RECV_SPEED_LARGE - CURLOPT_MAX_SEND_SPEED_LARGE New errors: - eCurlErrFTPPRETFailed - eCurlErrRTSPCseqError - eCurlErrRTSPSessionError - eCurlErrFTPBadFileList - eCurlErrChunkFailed - eCurlErrNoConnectionAvailable - eCurlErrSSLPinnedPubKeyNotMatch - eCurlErrSSLInvalidCertStatus - eCurlErrHTTP2Stream
1 parent 5b61dda commit 9ad2230

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

ext/curb.c

+7
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ void Init_curb_core() {
609609
#if LIBCURL_VERSION_NUM >= 0x072100 /* 7.33.0 */
610610
CURB_DEFINE(CURL_HTTP_VERSION_2_0);
611611
#endif
612+
#if LIBCURL_VERSION_NUM >= 0x072f00 /* 7.47.0 */
613+
CURB_DEFINE(CURL_HTTP_VERSION_2TLS);
614+
#endif
612615
#if HAVE_CURLOPT_IGNORE_CONTENT_LENGTH
613616
CURB_DEFINE(CURLOPT_IGNORE_CONTENT_LENGTH);
614617
#endif
@@ -1023,6 +1026,10 @@ void Init_curb_core() {
10231026
CURB_DEFINE(CURLOPT_UNIX_SOCKET_PATH);
10241027
#endif
10251028

1029+
#if HAVE_CURLOPT_PIPEWAIT
1030+
CURB_DEFINE(CURLOPT_PIPEWAIT);
1031+
#endif
1032+
10261033
#if LIBCURL_VERSION_NUM >= 0x072B00 /* 7.43.0 */
10271034
CURB_DEFINE(CURLPIPE_NOTHING);
10281035
CURB_DEFINE(CURLPIPE_HTTP1);

ext/curb_easy.c

+13
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,9 @@ static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
32923292
case CURLOPT_NOSIGNAL:
32933293
#if HAVE_CURLOPT_PATH_AS_IS
32943294
case CURLOPT_PATH_AS_IS:
3295+
#endif
3296+
#if HAVE_CURLOPT_PIPEWAIT
3297+
case CURLOPT_PIPEWAIT:
32953298
#endif
32963299
case CURLOPT_HTTPGET:
32973300
case CURLOPT_NOBODY: {
@@ -3359,6 +3362,16 @@ static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
33593362
case CURLOPT_UNIX_SOCKET_PATH: {
33603363
curl_easy_setopt(rbce->curl, CURLOPT_UNIX_SOCKET_PATH, StringValueCStr(val));
33613364
} break;
3365+
#endif
3366+
#if HAVE_CURLOPT_MAX_SEND_SPEED_LARGE
3367+
case CURLOPT_MAX_SEND_SPEED_LARGE: {
3368+
curl_easy_setopt(rbce->curl, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) NUM2LL(val));
3369+
} break;
3370+
#endif
3371+
#if HAVE_CURLOPT_MAX_RECV_SPEED_LARGE
3372+
case CURLOPT_MAX_RECV_SPEED_LARGE: {
3373+
curl_easy_setopt(rbce->curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) NUM2LL(val));
3374+
} break;
33623375
#endif
33633376
default:
33643377
rb_raise(rb_eTypeError, "Curb unsupported option");

ext/curb_errors.c

+79
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ VALUE eCurlErrFileError;
2121
VALUE eCurlErrLDAPError;
2222
VALUE eCurlErrTelnetError;
2323
VALUE eCurlErrTFTPError;
24+
VALUE eCurlErrRTSPError;
2425

2526
/* Specific libcurl errors */
2627
VALUE eCurlErrOK; /* not really an error but a return code */
@@ -127,6 +128,18 @@ VALUE mCurlErrUnknownOption;
127128
VALUE eCurlErrInvalidPostField;
128129

129130

131+
/* new errors */
132+
VALUE eCurlErrFTPPRETFailed;
133+
VALUE eCurlErrRTSPCseqError;
134+
VALUE eCurlErrRTSPSessionError;
135+
VALUE eCurlErrFTPBadFileList;
136+
VALUE eCurlErrChunkFailed;
137+
VALUE eCurlErrNoConnectionAvailable;
138+
VALUE eCurlErrSSLPinnedPubKeyNotMatch;
139+
VALUE eCurlErrSSLInvalidCertStatus;
140+
VALUE eCurlErrHTTP2Stream;
141+
142+
130143
VALUE rb_curl_easy_error(CURLcode code) {
131144
VALUE exclz;
132145
const char *exmsg = NULL;
@@ -445,6 +458,61 @@ VALUE rb_curl_easy_error(CURLcode code) {
445458
exclz = eCurlErrSSLIssuerError;
446459
break;
447460
#endif
461+
462+
#ifdef HAVE_CURLE_FTP_PRET_FAILED
463+
case CURLE_FTP_PRET_FAILED: /* 84 */
464+
exclz = eCurlErrFTPPRETFailed;
465+
break;
466+
#endif
467+
468+
#ifdef HAVE_CURLE_RTSP_CSEQ_ERROR
469+
case CURLE_RTSP_CSEQ_ERROR: /* 85 */
470+
exclz = eCurlErrRTSPCseqError;
471+
break;
472+
#endif
473+
474+
#ifdef HAVE_CURLE_RTSP_SESSION_ERROR
475+
case CURLE_RTSP_SESSION_ERROR: /* 86 */
476+
exclz = eCurlErrRTSPSessionError;
477+
break;
478+
#endif
479+
480+
#ifdef HAVE_CURLE_FTP_BAD_FILE_LIST
481+
case CURLE_FTP_BAD_FILE_LIST: /* 87 */
482+
exclz = eCurlErrFTPBadFileList;
483+
break;
484+
#endif
485+
486+
#ifdef HAVE_CURLE_CHUNK_FAILED
487+
case CURLE_CHUNK_FAILED: /* 88 */
488+
exclz = eCurlErrChunkFailed;
489+
break;
490+
#endif
491+
492+
#ifdef HAVE_CURLE_NO_CONNECTION_AVAILABLE
493+
case CURLE_NO_CONNECTION_AVAILABLE: /* 89 */
494+
exclz = eCurlErrNoConnectionAvailable;
495+
break;
496+
#endif
497+
498+
#ifdef HAVE_CURLE_SSL_PINNEDPUBKEYNOTMATCH
499+
case CURLE_SSL_PINNEDPUBKEYNOTMATCH: /* 90 */
500+
exclz = eCurlErrSSLPinnedPubKeyNotMatch;
501+
break;
502+
#endif
503+
504+
#ifdef HAVE_CURLE_SSL_INVALIDCERTSTATUS
505+
case CURLE_SSL_INVALIDCERTSTATUS: /* 91 */
506+
exclz = eCurlErrSSLInvalidCertStatus;
507+
break;
508+
#endif
509+
510+
#ifdef HAVE_CURLE_HTTP2_STREAM
511+
case CURLE_HTTP2_STREAM: /* 92 */
512+
exclz = eCurlErrHTTP2Stream;
513+
break;
514+
#endif
515+
448516
default:
449517
exclz = eCurlErrError;
450518
exmsg = "Unknown error result from libcurl";
@@ -532,6 +600,7 @@ void init_curb_errors() {
532600
eCurlErrLDAPError = rb_define_class_under(mCurlErr, "LDAPError", eCurlErrError);
533601
eCurlErrTelnetError = rb_define_class_under(mCurlErr, "TelnetError", eCurlErrError);
534602
eCurlErrTFTPError = rb_define_class_under(mCurlErr, "TFTPError", eCurlErrError);
603+
eCurlErrRTSPError = rb_define_class_under(mCurlErr, "RTSPError", eCurlErrError);
535604

536605
eCurlErrOK = rb_define_class_under(mCurlErr, "CurlOK", eCurlErrError);
537606
eCurlErrUnsupportedProtocol = rb_define_class_under(mCurlErr, "UnsupportedProtocolError", eCurlErrError);
@@ -657,4 +726,14 @@ void init_curb_errors() {
657726
eCurlErrTFTPNoSuchUser = rb_define_class_under(mCurlErr, "NoSuchUserError", eCurlErrTFTPError);
658727

659728
eCurlErrInvalidPostField = rb_define_class_under(mCurlErr, "InvalidPostFieldError", eCurlErrError);
729+
730+
eCurlErrFTPPRETFailed = rb_define_class_under(mCurlErr, "PPRETFailedError", eCurlErrFTPError);
731+
eCurlErrRTSPCseqError = rb_define_class_under(mCurlErr, "CseqError", eCurlErrRTSPError);
732+
eCurlErrRTSPSessionError = rb_define_class_under(mCurlErr, "SessionError", eCurlErrRTSPError);
733+
eCurlErrFTPBadFileList = rb_define_class_under(mCurlErr, "BadFileListError", eCurlErrFTPError);
734+
eCurlErrChunkFailed = rb_define_class_under(mCurlErr, "ChunkFailedError", eCurlErrError);
735+
eCurlErrNoConnectionAvailable = rb_define_class_under(mCurlErr, "NoConnectionAvailableError", eCurlErrError);
736+
eCurlErrSSLPinnedPubKeyNotMatch = rb_define_class_under(mCurlErr, "SSLPinnedPubKeyNotMatchError", eCurlErrError);
737+
eCurlErrSSLInvalidCertStatus = rb_define_class_under(mCurlErr, "SSLInvalidCertStatusError", eCurlErrError);
738+
eCurlErrHTTP2Stream = rb_define_class_under(mCurlErr, "HTTP2StreamError", eCurlErrHTTPError);
660739
}

ext/extconf.rb

+13
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ def have_constant(name)
364364

365365
have_constant "curle_obsolete" # removed in 7.24 ?
366366

367+
have_constant "curle_ftp_pret_failed"
368+
have_constant "curle_rtsp_cseq_error"
369+
have_constant "curle_rtsp_session_error"
370+
have_constant "curle_ftp_bad_file_list"
371+
have_constant "curle_chunk_failed"
372+
have_constant "curle_no_connection_available"
373+
have_constant "curle_ssl_pinnedpubkeynotmatch"
374+
have_constant "curle_ssl_invalidcertstatus"
375+
have_constant "curle_http2_stream"
376+
367377
# gssapi/spnego delegation related constants
368378
have_constant "curlopt_gssapi_delegation"
369379
have_constant "curlgssapi_delegation_policy_flag"
@@ -377,6 +387,9 @@ def have_constant(name)
377387
# added in 7.42.0
378388
have_constant "curlopt_path_as_is"
379389

390+
# added in 7.43.0
391+
have_constant "curlopt_pipewait"
392+
380393
if try_compile('int main() { return 0; }','-Wall')
381394
$CFLAGS << ' -Wall'
382395
end

0 commit comments

Comments
 (0)