4 *** Copyright (c) 2003-2008, Lars Nilsson, <lars@quantumchamaeleon.com>
5 *** Copyright (c) 2009, ygrek, <ygrek@autistici.org>
13 #include <curl/curl.h>
15 #include <caml/alloc.h>
16 #include <caml/memory.h>
17 #include <caml/mlvalues.h>
18 #include <caml/callback.h>
19 #include <caml/fail.h>
20 #include <caml/custom.h>
25 #pragma message("No config file given.")
28 void leave_blocking_section(void);
29 void enter_blocking_section(void);
31 #define Val_none Val_int(0)
38 some
= caml_alloc(1, 0);
39 Store_field( some
, 0, v
);
43 static value
Val_pair(value v1
, value v2
)
47 pair
= caml_alloc_small(2,0);
53 static value
Val_cons(value list
, value v
) { return Val_pair(v
,list
); }
55 typedef struct Connection Connection
;
56 typedef struct ConnectionList ConnectionList
;
58 #define Connection_val(v) ((Connection *)Field(v, 0))
71 OcamlProgressCallback
,
75 OcamlSeekFunctionCallback
,
76 OcamlOpenSocketFunctionCallback
,
108 OcamlFTPAlternativeToUser
,
109 OcamlSSHPublicKeyFile
,
110 OcamlSSHPrivateKeyFile
,
111 OcamlSSHHostPublicKeyMD5
,
114 /* Not used, last for size */
138 struct curl_slist
*httpHeader
;
139 struct curl_httppost
*httpPostFirst
;
140 struct curl_httppost
*httpPostLast
;
141 struct curl_slist
*httpPostStrings
;
142 struct curl_slist
*resolve
;
150 struct curl_slist
*quote
;
151 struct curl_slist
*postQuote
;
154 char *interface_
; /* `interface` gives problems on windows */
162 struct curl_slist
*http200Aliases
;
166 char *ftpAlternativeToUser
;
167 char *sshPublicKeyFile
;
168 char *sshPrivateKeyFile
;
169 char *sshHostPublicKeyMD5
;
170 char *copyPostFields
;
174 struct ConnectionList
180 static ConnectionList connectionList
= {NULL
, NULL
};
182 typedef struct CURLErrorMapping CURLErrorMapping
;
184 struct CURLErrorMapping
190 CURLErrorMapping errorMap
[] =
192 #if HAVE_DECL_CURLE_UNSUPPORTED_PROTOCOL
193 {"CURLE_UNSUPPORTED_PROTOCOL", CURLE_UNSUPPORTED_PROTOCOL
},
195 {"CURLE_UNSUPPORTED_PROTOCOL", -1},
197 #if HAVE_DECL_CURLE_FAILED_INIT
198 {"CURLE_FAILED_INIT", CURLE_FAILED_INIT
},
200 {"CURLE_FAILED_INIT", -1},
202 #if HAVE_DECL_CURLE_URL_MALFORMAT
203 {"CURLE_URL_MALFORMAT", CURLE_URL_MALFORMAT
},
205 {"CURLE_URL_MALFORMAT", -1},
207 #if HAVE_DECL_CURLE_URL_MALFORMAT_USER
208 {"CURLE_URL_MALFORMAT_USER", CURLE_URL_MALFORMAT_USER
},
210 {"CURLE_URL_MALFORMAT_USER", -1},
212 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_PROXY
213 {"CURLE_COULDNT_RESOLVE_PROXY", CURLE_COULDNT_RESOLVE_PROXY
},
215 {"CURLE_COULDNT_RESOLVE_PROXY", -1},
217 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_HOST
218 {"CURLE_COULDNT_RESOLVE_HOST", CURLE_COULDNT_RESOLVE_HOST
},
220 {"CURLE_COULDNT_RESOLVE_HOST", -1},
222 #if HAVE_DECL_CURLE_COULDNT_CONNECT
223 {"CURLE_COULDNT_CONNECT", CURLE_COULDNT_CONNECT
},
225 {"CURLE_COULDNT_CONNECT", -1},
227 #if HAVE_DECL_CURLE_FTP_WEIRD_SERVER_REPLY
228 {"CURLE_FTP_WEIRD_SERVER_REPLY", CURLE_FTP_WEIRD_SERVER_REPLY
},
230 {"CURLE_FTP_WEIRD_SERVER_REPLY", -1},
232 #if HAVE_DECL_CURLE_FTP_ACCESS_DENIED
233 {"CURLE_FTP_ACCESS_DENIED", CURLE_FTP_ACCESS_DENIED
},
235 {"CURLE_FTP_ACCESS_DENIED", -1},
237 #if HAVE_DECL_CURLE_FTP_USER_PASSWORD_INCORRECT
238 {"CURLE_FTP_USER_PASSWORD_INCORRECT", CURLE_FTP_USER_PASSWORD_INCORRECT
},
240 {"CURLE_FTP_USER_PASSWORD_INCORRECT", -1},
242 #if HAVE_DECL_CURLE_FTP_WEIRD_PASS_REPLY
243 {"CURLE_FTP_WEIRD_PASS_REPLY", CURLE_FTP_WEIRD_PASS_REPLY
},
245 {"CURLE_FTP_WEIRD_PASS_REPLY", -1},
247 #if HAVE_DECL_CURLE_FTP_WEIRD_USER_REPLY
248 {"CURLE_FTP_WEIRD_USER_REPLY", CURLE_FTP_WEIRD_USER_REPLY
},
250 {"CURLE_FTP_WEIRD_USER_REPLY", -1},
252 #if HAVE_DECL_CURLE_FTP_WEIRD_PASV_REPLY
253 {"CURLE_FTP_WEIRD_PASV_REPLY", CURLE_FTP_WEIRD_PASV_REPLY
},
255 {"CURLE_FTP_WEIRD_PASV_REPLY", -1},
257 #if HAVE_DECL_CURLE_FTP_WEIRD_227_FORMAT
258 {"CURLE_FTP_WEIRD_227_FORMAT", CURLE_FTP_WEIRD_227_FORMAT
},
260 {"CURLE_FTP_WEIRD_227_FORMAT", -1},
262 #if HAVE_DECL_CURLE_FTP_CANT_GET_HOST
263 {"CURLE_FTP_CANT_GET_HOST", CURLE_FTP_CANT_GET_HOST
},
265 {"CURLE_FTP_CANT_GET_HOST", -1},
267 #if HAVE_DECL_CURLE_FTP_CANT_RECONNECT
268 {"CURLE_FTP_CANT_RECONNECT", CURLE_FTP_CANT_RECONNECT
},
270 {"CURLE_FTP_CANT_RECONNECT", -1},
272 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_BINARY
273 {"CURLE_FTP_COULDNT_SET_BINARY", CURLE_FTP_COULDNT_SET_BINARY
},
275 {"CURLE_FTP_COULDNT_SET_BINARY", -1},
277 #if HAVE_DECL_CURLE_PARTIAL_FILE
278 {"CURLE_PARTIAL_FILE", CURLE_PARTIAL_FILE
},
280 {"CURLE_PARTIAL_FILE", -1},
282 #if HAVE_DECL_CURLE_FTP_COULDNT_RETR_FILE
283 {"CURLE_FTP_COULDNT_RETR_FILE", CURLE_FTP_COULDNT_RETR_FILE
},
285 {"CURLE_FTP_COULDNT_RETR_FILE", -1},
287 #if HAVE_DECL_CURLE_FTP_WRITE_ERROR
288 {"CURLE_FTP_WRITE_ERROR", CURLE_FTP_WRITE_ERROR
},
290 {"CURLE_FTP_WRITE_ERROR", -1},
292 #if HAVE_DECL_CURLE_FTP_QUOTE_ERROR
293 {"CURLE_FTP_QUOTE_ERROR", CURLE_FTP_QUOTE_ERROR
},
295 {"CURLE_FTP_QUOTE_ERROR", -1},
297 #if HAVE_DECL_CURLE_HTTP_NOT_FOUND
298 {"CURLE_HTTP_NOT_FOUND", CURLE_HTTP_NOT_FOUND
},
300 {"CURLE_HTTP_NOT_FOUND", -1},
302 #if HAVE_DECL_CURLE_WRITE_ERROR
303 {"CURLE_WRITE_ERROR", CURLE_WRITE_ERROR
},
305 {"CURLE_WRITE_ERROR", -1},
307 #if HAVE_DECL_CURLE_MALFORMAT_USER
308 {"CURLE_MALFORMAT_USER", CURLE_MALFORMAT_USER
},
310 {"CURLE_MALFORMAT_USER", -1},
312 #if HAVE_DECL_CURLE_FTP_COULDNT_STOR_FILE
313 {"CURLE_FTP_COULDNT_STOR_FILE", CURLE_FTP_COULDNT_STOR_FILE
},
315 {"CURLE_FTP_COULDNT_STOR_FILE", -1},
317 #if HAVE_DECL_CURLE_READ_ERROR
318 {"CURLE_READ_ERROR", CURLE_READ_ERROR
},
320 {"CURLE_READ_ERROR", -1},
322 #if HAVE_DECL_CURLE_OUT_OF_MEMORY
323 {"CURLE_OUT_OF_MEMORY", CURLE_OUT_OF_MEMORY
},
325 {"CURLE_OUT_OF_MEMORY", -1},
327 #if HAVE_DECL_CURLE_OPERATION_TIMEOUTED
328 {"CURLE_OPERATION_TIMEOUTED", CURLE_OPERATION_TIMEOUTED
},
330 {"CURLE_OPERATION_TIMEOUTED", -1},
332 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_ASCII
333 {"CURLE_FTP_COULDNT_SET_ASCII", CURLE_FTP_COULDNT_SET_ASCII
},
335 {"CURLE_FTP_COULDNT_SET_ASCII", -1},
337 #if HAVE_DECL_CURLE_FTP_PORT_FAILED
338 {"CURLE_FTP_PORT_FAILED", CURLE_FTP_PORT_FAILED
},
340 {"CURLE_FTP_PORT_FAILED", -1},
342 #if HAVE_DECL_CURLE_FTP_COULDNT_USE_REST
343 {"CURLE_FTP_COULDNT_USE_REST", CURLE_FTP_COULDNT_USE_REST
},
345 {"CURLE_FTP_COULDNT_USE_REST", -1},
347 #if HAVE_DECL_CURLE_FTP_COULDNT_GET_SIZE
348 {"CURLE_FTP_COULDNT_GET_SIZE", CURLE_FTP_COULDNT_GET_SIZE
},
350 {"CURLE_FTP_COULDNT_GET_SIZE", -1},
352 #if HAVE_DECL_CURLE_HTTP_RANGE_ERROR
353 {"CURLE_HTTP_RANGE_ERROR", CURLE_HTTP_RANGE_ERROR
},
355 {"CURLE_HTTP_RANGE_ERROR", -1},
357 #if HAVE_DECL_CURLE_HTTP_POST_ERROR
358 {"CURLE_HTTP_POST_ERROR", CURLE_HTTP_POST_ERROR
},
360 {"CURLE_HTTP_POST_ERROR", -1},
362 #if HAVE_DECL_CURLE_SSL_CONNECT_ERROR
363 {"CURLE_SSL_CONNECT_ERROR", CURLE_SSL_CONNECT_ERROR
},
365 {"CURLE_SSL_CONNECT_ERROR", -1},
367 #if HAVE_DECL_CURLE_FTP_BAD_DOWNLOAD_RESUME
368 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", CURLE_FTP_BAD_DOWNLOAD_RESUME
},
370 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", -1},
372 #if HAVE_DECL_CURLE_FILE_COULDNT_READ_FILE
373 {"CURLE_FILE_COULDNT_READ_FILE", CURLE_FILE_COULDNT_READ_FILE
},
375 {"CURLE_FILE_COULDNT_READ_FILE", -1},
377 #if HAVE_DECL_CURLE_LDAP_CANNOT_BIND
378 {"CURLE_LDAP_CANNOT_BIND", CURLE_LDAP_CANNOT_BIND
},
380 {"CURLE_LDAP_CANNOT_BIND", -1},
382 #if HAVE_DECL_CURLE_LDAP_SEARCH_FAILED
383 {"CURLE_LDAP_SEARCH_FAILED", CURLE_LDAP_SEARCH_FAILED
},
385 {"CURLE_LDAP_SEARCH_FAILED", -1},
387 #if HAVE_DECL_CURLE_LIBRARY_NOT_FOUND
388 {"CURLE_LIBRARY_NOT_FOUND", CURLE_LIBRARY_NOT_FOUND
},
390 {"CURLE_LIBRARY_NOT_FOUND", -1},
392 #if HAVE_DECL_CURLE_FUNCTION_NOT_FOUND
393 {"CURLE_FUNCTION_NOT_FOUND", CURLE_FUNCTION_NOT_FOUND
},
395 {"CURLE_FUNCTION_NOT_FOUND", -1},
397 #if HAVE_DECL_CURLE_ABORTED_BY_CALLBACK
398 {"CURLE_ABORTED_BY_CALLBACK", CURLE_ABORTED_BY_CALLBACK
},
400 {"CURLE_ABORTED_BY_CALLBACK", -1},
402 #if HAVE_DECL_CURLE_BAD_FUNCTION_ARGUMENT
403 {"CURLE_BAD_FUNCTION_ARGUMENT", CURLE_BAD_FUNCTION_ARGUMENT
},
405 {"CURLE_BAD_FUNCTION_ARGUMENT", -1},
407 #if HAVE_DECL_CURLE_BAD_CALLING_ORDER
408 {"CURLE_BAD_CALLING_ORDER", CURLE_BAD_CALLING_ORDER
},
410 {"CURLE_BAD_CALLING_ORDER", -1},
412 #if HAVE_DECL_CURLE_HTTP_PORT_FAILED
413 {"CURLE_HTTP_PORT_FAILED", CURLE_HTTP_PORT_FAILED
},
415 {"CURLE_HTTP_PORT_FAILED", -1},
417 #if HAVE_DECL_CURLE_BAD_PASSWORD_ENTERED
418 {"CURLE_BAD_PASSWORD_ENTERED", CURLE_BAD_PASSWORD_ENTERED
},
420 {"CURLE_BAD_PASSWORD_ENTERED", -1},
422 #if HAVE_DECL_CURLE_TOO_MANY_REDIRECTS
423 {"CURLE_TOO_MANY_REDIRECTS", CURLE_TOO_MANY_REDIRECTS
},
425 {"CURLE_TOO_MANY_REDIRECTS", -1},
427 #if HAVE_DECL_CURLE_UNKNOWN_TELNET_OPTION
428 {"CURLE_UNKNOWN_TELNET_OPTION", CURLE_UNKNOWN_TELNET_OPTION
},
430 {"CURLE_UNKNOWN_TELNET_OPTION", -1},
432 #if HAVE_DECL_CURLE_TELNET_OPTION_SYNTAX
433 {"CURLE_TELNET_OPTION_SYNTAX", CURLE_TELNET_OPTION_SYNTAX
},
435 {"CURLE_TELNET_OPTION_SYNTAX", -1},
437 #if HAVE_DECL_CURLE_SSL_PEER_CERTIFICATE
438 {"CURLE_SSL_PEER_CERTIFICATE", CURLE_SSL_PEER_CERTIFICATE
},
440 {"CURLE_SSL_PEER_CERTIFICATE", -1},
442 #if HAVE_DECL_CURLE_GOT_NOTHING
443 {"CURLE_GOT_NOTHING", CURLE_GOT_NOTHING
},
445 {"CURLE_GOT_NOTHING", -1},
447 #if HAVE_DECL_CURLE_SSL_ENGINE_NOT_FOUND
448 {"CURLE_SSL_ENGINE_NOT_FOUND", CURLE_SSL_ENGINE_NOTFOUND
},
450 {"CURLE_SSL_ENGINE_NOT_FOUND", -1},
452 #if HAVE_DECL_CURLE_SSL_ENGINE_SET_FAILED
453 {"CURLE_SSL_ENGINE_SET_FAILED", CURLE_SSL_ENGINE_SETFAILED
},
455 {"CURLE_SSL_ENGINE_SET_FAILED", -1},
457 #if HAVE_DECL_CURLE_SEND_ERROR
458 {"CURLE_SEND_ERROR", CURLE_SEND_ERROR
},
460 {"CURLE_SEND_ERROR", -1},
462 #if HAVE_DECL_CURLE_RECV_ERROR
463 {"CURLE_RECV_ERROR", CURLE_RECV_ERROR
},
465 {"CURLE_RECV_ERROR", -1},
467 #if HAVE_DECL_CURLE_SHARE_IN_USE
468 {"CURLE_SHARE_IN_USE", CURLE_SHARE_IN_USE
},
470 {"CURLE_SHARE_IN_USE", -1},
472 #if HAVE_DECL_CURLE_SSL_CERTPROBLEM
473 {"CURLE_SSL_CERTPROBLEN", CURLE_SSL_CERTPROBLEM
},
475 {"CURLE_SSL_CERTPROBLEN", -1},
477 #if HAVE_DECL_CURLE_SSL_CIPHER
478 {"CURLE_SSL_CIPHER", CURLE_SSL_CIPHER
},
480 {"CURLE_SSL_CIPHER", -1},
482 #if HAVE_DECL_CURLE_SSL_CACERT
483 {"CURLE_SSL_CACERT", CURLE_SSL_CACERT
},
485 {"CURLE_SSL_CACERT", -1},
487 #if HAVE_DECL_CURLE_BAD_CONTENT_ENCODING
488 {"CURLE_BAD_CONTENT_ENCODING", CURLE_BAD_CONTENT_ENCODING
},
490 {"CURLE_BAD_CONTENT_ENCODING", -1},
492 #if HAVE_DECL_CURLE_LDAP_INVALID_URL
493 {"CURLE_LDAP_INVALID_URL", CURLE_LDAP_INVALID_URL
},
495 {"CURLE_LDAP_INVALID_URL", -1},
497 #if HAVE_DECL_CURLE_FILESIZE_EXCEEDED
498 {"CURLE_FILESIZE_EXCEEDED", CURLE_FILESIZE_EXCEEDED
},
500 {"CURLE_FILESIZE_EXCEEDED", -1},
502 #if HAVE_DECL_CURLE_FTP_SSL_FAILED
503 {"CURLE_FTP_SSL_FAILED", CURLE_FTP_SSL_FAILED
},
505 {"CURLE_FTP_SSL_FAILED", -1},
507 #if HAVE_DECL_CURLE_SEND_FAIL_REWIND
508 {"CURLE_SEND_FAIL_REWIND", CURLE_SEND_FAIL_REWIND
},
510 {"CURLE_SEND_FAIL_REWIND", -1},
512 #if HAVE_DECL_CURLE_SSL_ENGINE_INITFAILED
513 {"CURLE_SSL_ENGINE_INITFAILED", CURLE_SSL_ENGINE_INITFAILED
},
515 {"CURLE_SSL_ENGINE_INITFAILED", -1},
517 #if HAVE_DECL_CURLE_LOGIN_DENIED
518 {"CURLE_LOGIN_DENIED", CURLE_LOGIN_DENIED
},
520 {"CURLE_LOGIN_DENIED", -1},
522 #if HAVE_DECL_CURLE_TFTP_NOTFOUND
523 {"CURLE_TFTP_NOTFOUND", CURLE_TFTP_NOTFOUND
},
525 {"CURLE_TFTP_NOTFOUND", -1},
527 #if HAVE_DECL_CURLE_TFTP_PERM
528 {"CURLE_TFTP_PERM", CURLE_TFTP_PERM
},
530 {"CURLE_TFTP_PERM", -1},
532 #if HAVE_DECL_CURLE_REMOTE_DISK_FULL
533 {"CURLE_REMOTE_DISK_FULL", CURLE_REMOTE_DISK_FULL
},
535 {"CURLE_REMOTE_DISK_FULL", -1},
537 #if HAVE_DECL_CURLE_TFTP_ILLEGAL
538 {"CURLE_TFTP_ILLEGAL", CURLE_TFTP_ILLEGAL
},
540 {"CURLE_TFTP_ILLEGAL", -1},
542 #if HAVE_DECL_CURLE_TFTP_UNKNOWNID
543 {"CURLE_TFTP_UNKNOWNID", CURLE_TFTP_UNKNOWNID
},
545 {"CURLE_TFTP_UNKNOWNID", -1},
547 #if HAVE_DECL_CURLE_REMOTE_FILE_EXISTS
548 {"CURLE_REMOTE_FILE_EXISTS", CURLE_REMOTE_FILE_EXISTS
},
550 {"CURLE_REMOTE_FILE_EXISTS", -1},
552 #if HAVE_DECL_CURLE_TFTP_NOSUCHUSER
553 {"CURLE_TFTP_NOSUCHUSER", CURLE_TFTP_NOSUCHUSER
},
555 {"CURLE_TFTP_NOSUCHUSER", -1},
557 #if HAVE_DECL_CURLE_CONV_FAILED
558 {"CURLE_CONV_FAILED", CURLE_CONV_FAILED
},
560 {"CURLE_CONV_FAILED", -1},
562 #if HAVE_DECL_CURLE_CONV_REQUIRED
563 {"CURLE_CONV_REQUIRED", CURLE_CONV_REQUIRED
},
565 {"CURLE_CONV_REQUIRED", -1},
567 #if HAVE_DECL_CURLE_SSL_CACERT_BADFILE
568 {"CURLE_SSL_CACERT_BADFILE", CURLE_SSL_CACERT_BADFILE
},
570 {"CURLE_SSL_CACERT_BADFILE", -1},
572 #if HAVE_DECL_CURLE_REMOTE_FILE_NOT_FOUND
573 {"CURLE_REMOTE_FILE_NOT_FOUND", CURLE_REMOTE_FILE_NOT_FOUND
},
575 {"CURLE_REMOTE_FILE_NOT_FOUND", -1},
577 #if HAVE_DECL_CURLE_SSH
578 {"CURLE_SSH", CURLE_SSH
},
582 #if HAVE_DECL_CURLE_SSL_SHUTDOWN_FAILED
583 {"CURLE_SSL_SHUTDOWN_FAILED", CURLE_SSL_SHUTDOWN_FAILED
},
585 {"CURLE_SSL_SHUTDOWN_FAILED", -1},
587 #if HAVE_DECL_CURLE_AGAIN
588 {"CURLE_AGAIN", CURLE_AGAIN
},
592 {"CURLE_OK", CURLE_OK
},
596 typedef struct CURLOptionMapping CURLOptionMapping
;
598 struct CURLOptionMapping
600 void (*optionHandler
)(Connection
*, value
);
605 CURLOptionMapping unimplementedOptionMap
[] =
607 {NULL
, "CURLOPT_STDERR", CURLOPT_STDERR
},
611 static void handleWriteFunction(Connection
*, value
);
612 static void handleReadFunction(Connection
*, value
);
613 static void handleInFileSize(Connection
*, value
);
614 static void handleURL(Connection
*, value
);
615 static void handleProxy(Connection
*, value
);
616 static void handleProxyPort(Connection
*, value
);
617 static void handleHTTPProxyTunnel(Connection
*, value
);
618 static void handleVerbose(Connection
*, value
);
619 static void handleHeader(Connection
*, value
);
620 static void handleNoProgress(Connection
*, value
);
621 static void handleNoSignal(Connection
*, value
);
622 static void handleNoBody(Connection
*, value
);
623 static void handleFailOnError(Connection
*, value
);
624 static void handleUpload(Connection
*, value
);
625 static void handlePost(Connection
*, value
);
626 static void handleFTPListOnly(Connection
*, value
);
627 static void handleFTPAppend(Connection
*, value
);
628 static void handleNETRC(Connection
*, value
);
629 static void handleEncoding(Connection
*, value
);
630 static void handleFollowLocation(Connection
*, value
);
631 static void handleTransferText(Connection
*, value
);
632 static void handlePut(Connection
*, value
);
633 static void handleUserPwd(Connection
*, value
);
634 static void handleProxyUserPwd(Connection
*, value
);
635 static void handleRange(Connection
*, value
);
636 static void handleErrorBuffer(Connection
*, value
);
637 static void handleTimeout(Connection
*, value
);
638 static void handlePostFields(Connection
*, value
);
639 static void handlePostFieldSize(Connection
*, value
);
640 static void handleReferer(Connection
*, value
);
641 static void handleUserAgent(Connection
*, value
);
642 static void handleFTPPort(Connection
*, value
);
643 static void handleLowSpeedLimit(Connection
*, value
);
644 static void handleLowSpeedTime(Connection
*, value
);
645 static void handleResumeFrom(Connection
*, value
);
646 static void handleCookie(Connection
*, value
);
647 static void handleHTTPHeader(Connection
*, value
);
648 static void handleHTTPPost(Connection
*, value
);
649 static void handleSSLCert(Connection
*, value
);
650 static void handleSSLCertType(Connection
*, value
);
651 static void handleSSLCertPasswd(Connection
*, value
);
652 static void handleSSLKey(Connection
*, value
);
653 static void handleSSLKeyType(Connection
*, value
);
654 static void handleSSLKeyPasswd(Connection
*, value
);
655 static void handleSSLEngine(Connection
*, value
);
656 static void handleSSLEngineDefault(Connection
*, value
);
657 static void handleCRLF(Connection
*, value
);
658 static void handleQuote(Connection
*, value
);
659 static void handlePostQuote(Connection
*, value
);
660 static void handleHeaderFunction(Connection
*, value
);
661 static void handleCookieFile(Connection
*, value
);
662 static void handleSSLVersion(Connection
*, value
);
663 static void handleTimeCondition(Connection
*, value
);
664 static void handleTimeValue(Connection
*, value
);
665 static void handleCustomRequest(Connection
*, value
);
666 static void handleInterface(Connection
*, value
);
667 static void handleKRB4Level(Connection
*, value
);
668 static void handleProgressFunction(Connection
*, value
);
669 static void handleSSLVerifyPeer(Connection
*, value
);
670 static void handleCAInfo(Connection
*, value
);
671 static void handleCAPath(Connection
*, value
);
672 static void handleFileTime(Connection
*, value
);
673 static void handleMaxRedirs(Connection
*, value
);
674 static void handleMaxConnects(Connection
*, value
);
675 static void handleClosePolicy(Connection
*, value
);
676 static void handleFreshConnect(Connection
*, value
);
677 static void handleForbidReuse(Connection
*, value
);
678 static void handleRandomFile(Connection
*, value
);
679 static void handleEGDSocket(Connection
*, value
);
680 static void handleConnectTimeout(Connection
*, value
);
681 static void handleHTTPGet(Connection
*, value
);
682 static void handleSSLVerifyHost(Connection
*, value
);
683 static void handleCookieJar(Connection
*, value
);
684 static void handleSSLCipherList(Connection
*, value
);
685 static void handleHTTPVersion(Connection
*, value
);
686 static void handleFTPUseEPSV(Connection
*, value
);
687 static void handleDNSCacheTimeout(Connection
*, value
);
688 static void handleDNSUseGlobalCache(Connection
*, value
);
689 static void handleDebugFunction(Connection
*, value
);
690 static void handlePrivate(Connection
*, value
);
691 static void handleHTTP200Aliases(Connection
*, value
);
692 static void handleUnrestrictedAuth(Connection
*, value
);
693 static void handleFTPUseEPRT(Connection
*, value
);
694 static void handleHTTPAuth(Connection
*, value
);
695 static void handleFTPCreateMissingDirs(Connection
*, value
);
696 static void handleProxyAuth(Connection
*, value
);
697 static void handleFTPResponseTimeout(Connection
*, value
);
698 static void handleIPResolve(Connection
*, value
);
699 static void handleMaxFileSize(Connection
*, value
);
700 static void handleInFileSizeLarge(Connection
*, value
);
701 static void handleResumeFromLarge(Connection
*, value
);
702 static void handleMaxFileSizeLarge(Connection
*, value
);
703 static void handleNETRCFile(Connection
*, value
);
704 static void handleFTPSSL(Connection
*, value
);
705 static void handlePostFieldSizeLarge(Connection
*, value
);
706 static void handleTCPNoDelay(Connection
*, value
);
707 static void handleFTPSSLAuth(Connection
*, value
);
708 static void handleIOCTLFunction(Connection
*, value
);
709 static void handleFTPAccount(Connection
*, value
);
710 static void handleCookieList(Connection
*, value
);
711 static void handleIgnoreContentLength(Connection
*, value
);
712 static void handleFTPSkipPASVIP(Connection
*, value
);
713 static void handleFTPFileMethod(Connection
*, value
);
714 static void handleLocalPort(Connection
*, value
);
715 static void handleLocalPortRange(Connection
*, value
);
716 static void handleConnectOnly(Connection
*, value
);
717 static void handleMaxSendSpeedLarge(Connection
*, value
);
718 static void handleMaxRecvSpeedLarge(Connection
*, value
);
719 static void handleFTPAlternativeToUser(Connection
*, value
);
720 static void handleSSLSessionIdCache(Connection
*, value
);
721 static void handleSSHAuthTypes(Connection
*, value
);
722 static void handleSSHPublicKeyFile(Connection
*, value
);
723 static void handleSSHPrivateKeyFile(Connection
*, value
);
724 static void handleFTPSSLCCC(Connection
*, value
);
725 static void handleTimeoutMS(Connection
*, value
);
726 static void handleConnectTimeoutMS(Connection
*, value
);
727 static void handleHTTPTransferDecoding(Connection
*, value
);
728 static void handleHTTPContentDecoding(Connection
*, value
);
729 static void handleNewFilePerms(Connection
*, value
);
730 static void handleNewDirectoryPerms(Connection
*, value
);
731 static void handlePost301(Connection
*, value
);
732 static void handleSSHHostPublicKeyMD5(Connection
*, value
);
733 static void handleCopyPostFields(Connection
*, value
);
734 static void handleProxyTransferMode(Connection
*, value
);
735 static void handleSeekFunction(Connection
*, value
);
736 static void handleAutoReferer(Connection
*, value
);
737 static void handleOpenSocketFunction(Connection
*, value
);
738 static void handleProxyType(Connection
*, value
);
739 static void handleProtocols(Connection
*, value
);
740 static void handleRedirProtocols(Connection
*, value
);
741 static void handleResolve(Connection
*, value
);
742 static void handleDnsServers(Connection
*, value
);
744 CURLOptionMapping implementedOptionMap
[] =
746 {handleWriteFunction
, "CURLOPT_WRITEFUNCTION", CURLOPT_WRITEFUNCTION
},
747 {handleReadFunction
, "CURLOPT_READFUNCTION", CURLOPT_READFUNCTION
},
748 {handleInFileSize
, "CURLOPT_INFILESIZE", CURLOPT_INFILESIZE
},
749 {handleURL
, "CURLOPT_URL", CURLOPT_URL
},
750 {handleProxy
, "CURLOPT_PROXY", CURLOPT_PROXY
},
751 {handleProxyPort
, "CURLOPT_PROXYPORT", CURLOPT_PROXYPORT
},
752 {handleHTTPProxyTunnel
, "CURLOPT_HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL
},
753 {handleVerbose
, "CURLOPT_VERBOSE", CURLOPT_VERBOSE
},
754 {handleHeader
, "CURLOPT_HEADER", CURLOPT_HEADER
},
755 {handleNoProgress
, "CURLOPT_NOPROGRESS", CURLOPT_NOPROGRESS
},
756 #if HAVE_DECL_CURLOPT_NOSIGNAL
757 {handleNoSignal
, "CURLOPT_NOSIGNAL", CURLOPT_NOSIGNAL
},
759 {handleNoSignal
, "CURLOPT_NOSIGNAL", 0},
761 {handleNoBody
, "CURLOPT_NOBODY", CURLOPT_NOBODY
},
762 {handleFailOnError
, "CURLOPT_FAILONERROR", CURLOPT_FAILONERROR
},
763 {handleUpload
, "CURLOPT_UPLOAD", CURLOPT_UPLOAD
},
764 {handlePost
, "CURLOPT_POST", CURLOPT_POST
},
765 {handleFTPListOnly
, "CURLOPT_FTPLISTONLY", CURLOPT_FTPLISTONLY
},
766 {handleFTPAppend
, "CURLOPT_FTPAPPEND", CURLOPT_FTPAPPEND
},
767 {handleNETRC
, "CURLOPT_NETRC", CURLOPT_NETRC
},
768 #if HAVE_DECL_CURLOPT_ENCODING
769 {handleEncoding
, "CURLOPT_ENCODING", CURLOPT_ENCODING
},
771 {handleEncoding
, "CURLOPT_ENCODING", 0},
773 {handleFollowLocation
, "CURLOPT_FOLLOWLOCATION", CURLOPT_FOLLOWLOCATION
},
774 {handleTransferText
, "CURLOPT_TRANSFERTEXT", CURLOPT_TRANSFERTEXT
},
775 {handlePut
, "CURLOPT_PUT", CURLOPT_PUT
},
776 {handleUserPwd
, "CURLOPT_USERPWD", CURLOPT_USERPWD
},
777 {handleProxyUserPwd
, "CURLOPT_PROXYUSERPWD", CURLOPT_PROXYUSERPWD
},
778 {handleRange
, "CURLOPT_RANGE", CURLOPT_RANGE
},
779 {handleErrorBuffer
, "CURLOPT_ERRORBUFFER", CURLOPT_ERRORBUFFER
},
780 {handleTimeout
, "CURLOPT_TIMEOUT", CURLOPT_TIMEOUT
},
781 {handlePostFields
, "CURLOPT_POSTFIELDS", CURLOPT_POSTFIELDS
},
782 {handlePostFieldSize
, "CURLOPT_POSTFIELDSIZE", CURLOPT_POSTFIELDSIZE
},
783 {handleReferer
, "CURLOPT_REFERER", CURLOPT_REFERER
},
784 {handleUserAgent
, "CURLOPT_USERAGENT", CURLOPT_USERAGENT
},
785 {handleFTPPort
, "CURLOPT_FTPPORT", CURLOPT_FTPPORT
},
786 {handleLowSpeedLimit
, "CURLOPT_LOW_SPEED_LIMIT", CURLOPT_LOW_SPEED_LIMIT
},
787 {handleLowSpeedTime
, "CURLOPT_LOW_SPEED_TIME", CURLOPT_LOW_SPEED_TIME
},
788 {handleResumeFrom
, "CURLOPT_RESUME_FROM", CURLOPT_RESUME_FROM
},
789 {handleCookie
, "CURLOPT_COOKIE", CURLOPT_COOKIE
},
790 {handleHTTPHeader
, "CURLOPT_HTTPHEADER", CURLOPT_HTTPHEADER
},
791 {handleHTTPPost
, "CURLOPT_HTTPPOST", CURLOPT_HTTPPOST
},
792 {handleSSLCert
, "CURLOPT_SSLCERT", CURLOPT_SSLCERT
},
793 {handleSSLCertType
, "CURLOPT_SSLCERTTYPE", CURLOPT_SSLCERTTYPE
},
794 {handleSSLCertPasswd
, "CURLOPT_SSLCERTPASSWD", CURLOPT_SSLCERTPASSWD
},
795 {handleSSLKey
, "CURLOPT_SSLKEY", CURLOPT_SSLKEY
},
796 {handleSSLKeyType
, "CURLOPT_SSLKEYTYPE", CURLOPT_SSLKEYTYPE
},
797 {handleSSLKeyPasswd
, "CURLOPT_SSLKEYPASSWD", CURLOPT_SSLKEYPASSWD
},
798 {handleSSLEngine
, "CURLOPT_SSLENGINE", CURLOPT_SSLENGINE
},
799 {handleSSLEngineDefault
, "CURLOPT_SSLENGINE_DEFAULT", CURLOPT_SSLENGINE_DEFAULT
},
800 {handleCRLF
, "CURLOPT_CRLF", CURLOPT_CRLF
},
801 {handleQuote
, "CURLOPT_QUOTE", CURLOPT_QUOTE
},
802 {handlePostQuote
, "CURLOPT_POSTQUOTE", CURLOPT_POSTQUOTE
},
803 {handleHeaderFunction
, "CURLOPT_HEADERFUNCTION", CURLOPT_HEADERFUNCTION
},
804 {handleCookieFile
, "CURLOPT_COOKIEFILE", CURLOPT_COOKIEFILE
},
805 {handleSSLVersion
, "CURLOPT_SSLVERSION", CURLOPT_SSLVERSION
},
806 {handleTimeCondition
, "CURLOPT_TIMECONDITION", CURLOPT_TIMECONDITION
},
807 {handleTimeValue
, "CURLOPT_TIMEVALUE", CURLOPT_TIMEVALUE
},
808 {handleCustomRequest
, "CURLOPT_CUSTOMREQUEST", CURLOPT_CUSTOMREQUEST
},
809 {handleInterface
, "CURLOPT_INTERFACE", CURLOPT_INTERFACE
},
810 {handleKRB4Level
, "CURLOPT_KRB4LEVEL", CURLOPT_KRB4LEVEL
},
811 {handleProgressFunction
, "CURLOPT_PROGRESSFUNCTION", CURLOPT_PROGRESSFUNCTION
},
812 {handleSSLVerifyPeer
, "CURLOPT_SSLVERIFYPEER", CURLOPT_SSL_VERIFYPEER
},
813 {handleCAInfo
, "CURLOPT_CAINFO", CURLOPT_CAINFO
},
814 {handleCAPath
, "CURLOPT_CAPATH", CURLOPT_CAPATH
},
815 {handleFileTime
, "CURLOPT_FILETIME", CURLOPT_FILETIME
},
816 {handleMaxRedirs
, "CURLOPT_MAXREDIRS", CURLOPT_MAXREDIRS
},
817 {handleMaxConnects
, "CURLOPT_MAXCONNECTS", CURLOPT_MAXCONNECTS
},
818 {handleClosePolicy
, "CURLOPT_CLOSEPOLICY", CURLOPT_CLOSEPOLICY
},
819 {handleFreshConnect
, "CURLOPT_FRESH_CONNECT", CURLOPT_FRESH_CONNECT
},
820 {handleForbidReuse
, "CURLOPT_FORBID_REUSE", CURLOPT_FORBID_REUSE
},
821 {handleRandomFile
, "CURLOPT_RANDOM_FILE", CURLOPT_RANDOM_FILE
},
822 {handleEGDSocket
, "CURLOPT_EGDSOCKET", CURLOPT_EGDSOCKET
},
823 {handleConnectTimeout
, "CURLOPT_CONNECTTIMEOUT", CURLOPT_CONNECTTIMEOUT
},
824 {handleHTTPGet
, "CURLOPT_HTTPGET", CURLOPT_HTTPGET
},
825 {handleSSLVerifyHost
, "CURLOPT_SSL_VERIFYHOST", CURLOPT_SSL_VERIFYHOST
},
826 {handleCookieJar
, "CURLOPT_COOKIEJAR", CURLOPT_COOKIEJAR
},
827 {handleSSLCipherList
, "CURLOPT_SSL_CIPHERLIST", CURLOPT_SSL_CIPHER_LIST
},
828 {handleHTTPVersion
, "CURLOPT_HTTP_VERSION", CURLOPT_HTTP_VERSION
},
829 {handleFTPUseEPSV
, "CURLOPT_FTP_USE_EPSV", CURLOPT_FTP_USE_EPSV
},
830 {handleDNSCacheTimeout
, "CURLOPT_DNS_CACHE_TIMEOUT", CURLOPT_DNS_CACHE_TIMEOUT
},
831 {handleDNSUseGlobalCache
, "CURLOPT_DNS_USE_GLOBAL_CACHE", CURLOPT_DNS_USE_GLOBAL_CACHE
},
832 {handleDebugFunction
, "CURLOPT_DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION
},
833 #if HAVE_DECL_CURLOPT_PRIVATE
834 {handlePrivate
, "CURLOPT_PRIVATE", CURLOPT_PRIVATE
},
836 {handlePrivate
, "CURLOPT_PRIVATE", 0},
838 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
839 {handleHTTP200Aliases
, "CURLOPT_HTTP200ALIASES", CURLOPT_HTTP200ALIASES
},
841 {handleHTTP200Aliases
, "CURLOPT_HTTP200ALIASES", 0},
843 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
844 {handleUnrestrictedAuth
, "CURLOPT_UNRESTRICTED_AUTH", CURLOPT_UNRESTRICTED_AUTH
},
846 {handleUnrestrictedAuth
, "CURLOPT_UNRESTRICTED_AUTH", 0},
848 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
849 {handleFTPUseEPRT
, "CURLOPT_FTP_USE_EPRT", CURLOPT_FTP_USE_EPRT
},
851 {handleFTPUseEPRT
, "CURLOPT_FTP_USE_EPRT", 0},
853 #if HAVE_DECL_CURLOPT_HTTPAUTH
854 {handleHTTPAuth
, "CURLOPT_HTTPAUTH", CURLOPT_HTTPAUTH
},
856 {handleHTTPAuth
, "CURLOPT_HTTPAUTH", 0},
858 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
859 {handleFTPCreateMissingDirs
, "CURLOPT_FTP_CREATE_MISSING_DIRS", CURLOPT_FTP_CREATE_MISSING_DIRS
},
861 {handleFTPCreateMissingDirs
, "CURLOPT_FTP_CREATE_MISSING_DIRS", 0},
863 #if HAVE_DECL_CURLOPT_PROXYAUTH
864 {handleProxyAuth
, "CURLOPT_PROXYAUTH", CURLOPT_PROXYAUTH
},
866 {handleProxyAuth
, "CURLOPT_PROXYAUTH", 0},
868 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
869 {handleFTPResponseTimeout
, "CURLOPT_FTP_RESPONSE_TIMEOUT", CURLOPT_FTP_RESPONSE_TIMEOUT
},
871 {handleFTPResponseTimeout
, "CURLOPT_FTP_RESPONSE_TIMEOUT", 0},
873 #if HAVE_DECL_CURLOPT_IPRESOLVE
874 {handleIPResolve
, "CURLOPT_IPRESOLVE", CURLOPT_IPRESOLVE
},
876 {handleIPResolve
, "CURLOPT_IPRESOLVE", 0},
878 #if HAVE_DECL_CURLOPT_MAXFILESIZE
879 {handleMaxFileSize
, "CURLOPT_MAXFILESIZE", CURLOPT_MAXFILESIZE
},
881 {handleMaxFileSize
, "CURLOPT_MAXFILESIZE", 0},
883 #if HAVE_DECL_CURLOPT_INFILSIZE_LARGE
884 {handleInFileSizeLarge
, "CURLOPT_INFILESIZE_LARGE", CURLOPT_INFILESIZE_LARGE
},
886 {handleInFileSizeLarge
, "CURLOPT_INFILESIZE_LARGE", 0},
888 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
889 {handleResumeFromLarge
, "CURLOPT_RESUME_FROM_LARGE", CURLOPT_RESUME_FROM_LARGE
},
891 {handleResumeFromLarge
, "CURLOPT_RESUME_FROM_LARGE", 0},
893 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
894 {handleMaxFileSizeLarge
, "CURLOPT_MAXFILESIZE_LARGE", CURLOPT_MAXFILESIZE_LARGE
},
896 {handleMaxFileSizeLarge
, "CURLOPT_MAXFILESIZE_LARGE", 0},
898 #if HAVE_DECL_CURLOPT_NETRC_FILE
899 {handleNETRCFile
, "CURLOPT_NETRC_FILE", CURLOPT_NETRC_FILE
},
901 {handleNETRCFile
, "CURLOPT_NETRC_FILE", 0},
903 #if HAVE_DECL_CURLOPT_FTP_SSL
904 {handleFTPSSL
, "CURLOPT_FTP_SSL", CURLOPT_FTP_SSL
},
906 {handleFTPSSL
, "CURLOPT_FTP_SSL", 0},
908 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
909 {handlePostFieldSizeLarge
, "CURLOPT_POSTFIELDSIZE_LARGE", CURLOPT_POSTFIELDSIZE_LARGE
},
911 {handlePostFieldSizeLarge
, "CURLOPT_POSTFIELDSIZE_LARGE", 0},
913 #if HAVE_DECL_CURLOPT_TCP_NODELAY
914 {handleTCPNoDelay
, "CURLOPT_TCP_NODELAY", CURLOPT_TCP_NODELAY
},
916 {handleTCPNoDelay
, "CURLOPT_TCP_NODELAY", 0},
918 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
919 {handleFTPSSLAuth
, "CURLOPT_FTPSSLAUTH", CURLOPT_FTPSSLAUTH
},
921 {handleFTPSSLAuth
, "CURLOPT_FTPSSLAUTH", 0},
923 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
924 {handleIOCTLFunction
, "CURLOPT_IOCTLFUNCTION", CURLOPT_IOCTLFUNCTION
},
926 {handleIOCTLFunction
, "CURLOPT_IOCTLFUNCTION", 0},
928 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
929 {handleFTPAccount
, "CURLOPT_FTP_ACCOUNT", CURLOPT_FTP_ACCOUNT
},
931 {handleFTPAccount
, "CURLOPT_FTP_ACCOUNT", 0},
933 #if HAVE_DECL_CURLOPT_COOKIELIST
934 {handleCookieList
, "CURLOPT_COOKIELIST", CURLOPT_COOKIELIST
},
936 {handleCookieList
, "CURLOPT_COOKIELIST", 0},
938 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
939 {handleIgnoreContentLength
, "CURLOPT_IGNORE_CONTENT_LENGTH", CURLOPT_IGNORE_CONTENT_LENGTH
},
941 {handleIgnoreContentLength
, "CURLOPT_IGNORE_CONTENT_LENGTH", 0},
943 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
944 {handleFTPSkipPASVIP
, "CURLOPT_FTP_SKIP_PASV_IP", CURLOPT_FTP_SKIP_PASV_IP
},
946 {handleFTPSkipPASVIP
, "CURLOPT_FTP_SKIP_PASV_IP", 0},
948 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
949 {handleFTPFileMethod
, "CURLOPT_FTP_FILEMETHOD", CURLOPT_FTP_FILEMETHOD
},
951 {handleFTPFileMethod
, "CURLOPT_FTP_FILEMETHOD", 0},
953 #if HAVE_DECL_CURLOPT_LOCALPORT
954 {handleLocalPort
, "CURLOPT_LOCALPORT", CURLOPT_LOCALPORT
},
956 {handleLocalPort
, "CURLOPT_LOCALPORT", 0},
958 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
959 {handleLocalPortRange
, "CURLOPT_LOCALPORTRANGE", CURLOPT_LOCALPORTRANGE
},
961 {handleLocalPortRange
, "CURLOPT_LOCALPORTRANGE", 0},
963 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
964 {handleConnectOnly
, "CURLOPT_CONNECT_ONLY", CURLOPT_CONNECT_ONLY
},
966 {handleConnectOnly
, "CURLOPT_CONNECT_ONLY", 0},
968 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
969 {handleMaxSendSpeedLarge
, "CURLOPT_MAX_SEND_SPEED_LARGE", CURLOPT_MAX_SEND_SPEED_LARGE
},
971 {handleMaxSendSpeedLarge
, "CURLOPT_MAX_SEND_SPEED_LARGE", 0},
973 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
974 {handleMaxRecvSpeedLarge
, "CURLOPT_MAX_RECV_SPEED_LARGE", CURLOPT_MAX_RECV_SPEED_LARGE
},
976 {handleMaxRecvSpeedLarge
, "CURLOPT_MAX_RECV_SPEED_LARGE", 0},
978 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
979 {handleFTPAlternativeToUser
, "CURLOPT_FTP_ALTERNATIVE_TO_USER", CURLOPT_FTP_ALTERNATIVE_TO_USER
},
981 {handleFTPAlternativeToUser
, "CURLOPT_FTP_ALTERMATIVE_TO_USER", 0},
983 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
984 {handleSSLSessionIdCache
, "CURLOPT_SSL_SESSIONID_CACHE", CURLOPT_SSL_SESSIONID_CACHE
},
986 {handleSSLSessionIdCache
, "CURLOPT_SSL_SESSIONID_CACHE", 0},
988 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
989 {handleSSHAuthTypes
, "CURLOPT_SSH_AUTH_TYPES", CURLOPT_SSH_AUTH_TYPES
},
991 {handleSSHAuthTypes
, "CURLOPT_SSH_AUTH_TYPES", 0},
993 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
994 {handleSSHPublicKeyFile
, "CURLOPT_SSH_PUBLIC_KEYFILE", CURLOPT_SSH_PUBLIC_KEYFILE
},
996 {handleSSHPublicKeyFile
, "CURLOPT_SSH_PUBLIC_KEYFILE", 0},
998 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
999 {handleSSHPrivateKeyFile
, "CURLOPT_SSH_PRIVATE_KEYFILE", CURLOPT_SSH_PRIVATE_KEYFILE
},
1001 {handleSSHPrivateKeyFile
, "CURLOPT_SSH_PRIVATE_KEYFILE", 0},
1003 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
1004 {handleFTPSSLCCC
, "CURLOPT_FTP_SSL_CCC", CURLOPT_FTP_SSL_CCC
},
1006 {handleFTPSSLCCC
, "CURLOPT_FTP_SSL_CCC", 0},
1008 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
1009 {handleTimeoutMS
, "CURLOPT_TIMEOUT_MS", CURLOPT_TIMEOUT_MS
},
1011 {handleTimeoutMS
, "CURLOPT_TIMEOUT_MS", 0},
1013 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
1014 {handleConnectTimeoutMS
, "CURLOPT_CONNECTTIMEOUT_MS", CURLOPT_CONNECTTIMEOUT_MS
},
1016 {handleConnectTimeoutMS
, "CURLOPT_CONNECTTIMEOUT_MS", 0},
1018 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
1019 {handleHTTPTransferDecoding
, "CURLOPT_HTTP_TRANSFER_DECODING", CURLOPT_HTTP_TRANSFER_DECODING
},
1021 {handleHTTPTransferDecoding
, "CURLOPT_HTTP_TRANSFER_DECODING", 0},
1023 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
1024 {handleHTTPContentDecoding
, "CURLOPT_HTTP_CONTENT_DECODING", CURLOPT_HTTP_CONTENT_DECODING
},
1026 {handleHTTPContentDecoding
, "CURLOPT_HTTP_CONTENT_DECODING", 0},
1028 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
1029 {handleNewFilePerms
, "CURLOPT_NEW_FILE_PERMS", CURLOPT_NEW_FILE_PERMS
},
1031 {handleNewFilePerms
, "CURLOPT_NEW_FILE_PERMS", 0},
1033 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
1034 {handleNewDirectoryPerms
, "CURLOPT_NEW_DIRECTORY_PERMS", CURLOPT_NEW_DIRECTORY_PERMS
},
1036 {handleNewDirectoryPerms
, "CURLOPT_NEW_DIRECTORY_PERMS", 0},
1038 #if HAVE_DECL_CURLOPT_POST301
1039 {handlePost301
, "CURLOPT_POST301", CURLOPT_POST301
},
1041 {handlePost301
, "CURLOPT_POST301", 0},
1043 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEY_MD5
1044 {handleSSHHostPublicKeyMD5
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5", CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
},
1046 {handleSSHHostPublicKeyMD5
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5", 0},
1048 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
1049 {handleCopyPostFields
, "CURLOPT_COPYPOSTFIELDS", CURLOPT_COPYPOSTFIELDS
},
1051 {handleCopyPostFields
, "CURLOPT_COPYPOSTFIELDS", 0},
1053 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
1054 {handleProxyTransferMode
, "CURLOPT_PROXY_TRANSFER_MODE", CURLOPT_PROXY_TRANSFER_MODE
},
1056 {handleProxyTransferMode
, "CURLOPT_PROXY_TRANSFER_MODE", 0},
1058 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1059 {handleSeekFunction
, "CURLOPT_SEEKFUNCTION", CURLOPT_SEEKFUNCTION
},
1061 {handleSeekFunction
, "CURLOPT_SEEKFUNCTION", 0},
1063 #if HAVE_DECL_CURLOPT_AUTOREFERER
1064 {handleAutoReferer
, "CURLOPT_AUTOREFERER", CURLOPT_AUTOREFERER
},
1066 {handleAutoReferer
, "CURLOPT_AUTOREFERER", 0},
1068 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1069 {handleOpenSocketFunction
, "CURLOPT_OPENSOCKETFUNCTION", CURLOPT_OPENSOCKETFUNCTION
},
1071 {handleOpenSocketFunction
, "CURLOPT_OPENSOCKETFUNCTION", 0},
1073 #if HAVE_DECL_CURLOPT_PROXYTYPE
1074 {handleProxyType
, "CURLOPT_PROXYTYPE", CURLOPT_PROXYTYPE
},
1076 {handleProxyType
, "CURLOPT_PROXYTYPE", 0},
1078 #if HAVE_DECL_CURLOPT_PROTOCOLS
1079 {handleProtocols
, "CURLOPT_PROTOCOLS", CURLOPT_PROTOCOLS
},
1081 {handleProtocols
, "CURLOPT_PROTOCOLS", 0},
1083 #if HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
1084 {handleRedirProtocols
, "CURLOPT_REDIR_PROTOCOLS", CURLOPT_REDIR_PROTOCOLS
},
1086 {handleRedirProtocols
, "CURLOPT_REDIR_PROTOCOLS", 0},
1088 #if HAVE_DECL_CURLOPT_RESOLVE
1089 {handleResolve
, "CURLOPT_RESOLVE", CURLOPT_RESOLVE
},
1091 {handleResolve
, "CURLOPT_RESOLVE", 0},
1093 #if HAVE_DECL_CURLOPT_DNS_SERVERS
1094 {handleDnsServers
, "CURLOPT_DNS_SERVERS", CURLOPT_DNS_SERVERS
},
1096 {handleDnsServers
, "CURLOPT_DNS_SERVERS", 0},
1100 static char *findOption(CURLOptionMapping optionMap
[],
1103 return optionMap
[option
].name
;
1106 static void free_curl_slist(struct curl_slist
*slist
)
1111 curl_slist_free_all(slist
);
1114 static void raiseError(Connection
*conn
, CURLcode code
)
1117 CAMLlocal1(exceptionData
);
1119 char *errorString
= "Unknown Error";
1122 for (i
= 0; errorMap
[i
].name
!= NULL
; i
++)
1124 if (errorMap
[i
].error
== code
)
1126 errorString
= errorMap
[i
].name
;
1131 exceptionData
= caml_alloc(3, 0);
1133 Store_field(exceptionData
, 0, Val_int(code
));
1134 Store_field(exceptionData
, 1, Val_int(code
));
1135 Store_field(exceptionData
, 2, copy_string(errorString
));
1137 if (conn
!= NULL
&& conn
->errorBuffer
!= NULL
)
1139 Store_field(Field(conn
->ocamlValues
, OcamlErrorBuffer
), 0,
1140 copy_string(conn
->errorBuffer
));
1143 exception
= caml_named_value("CurlException");
1145 if (exception
== NULL
)
1146 caml_failwith("CurlException not registered");
1148 raise_with_arg(*exception
, exceptionData
);
1153 static void resetOcamlValues(Connection
* connection
)
1157 for (i
= 0; i
< OcamlValuesSize
; i
++)
1158 Store_field(connection
->ocamlValues
, i
, Val_unit
);
1161 static Connection
*newConnection(void)
1163 Connection
*connection
;
1165 connection
= (Connection
*)malloc(sizeof(Connection
));
1167 enter_blocking_section();
1168 connection
->connection
= curl_easy_init();
1169 leave_blocking_section();
1171 connection
->next
= NULL
;
1172 connection
->prev
= NULL
;
1174 if (connectionList
.tail
== NULL
)
1176 connectionList
.tail
= connection
;
1177 connectionList
.head
= connection
;
1181 connection
->prev
= connectionList
.head
;
1182 connectionList
.head
->next
= connection
;
1183 connectionList
.head
= connection
;
1186 connection
->ocamlValues
= alloc(OcamlValuesSize
, 0);
1187 resetOcamlValues(connection
);
1188 register_global_root(&connection
->ocamlValues
);
1190 connection
->url
= NULL
;
1191 connection
->proxy
= NULL
;
1192 connection
->userPwd
= NULL
;
1193 connection
->proxyUserPwd
= NULL
;
1194 connection
->range
= NULL
;
1195 connection
->errorBuffer
= NULL
;
1196 connection
->postFields
= NULL
;
1197 connection
->postFieldSize
= -1;
1198 connection
->referer
= NULL
;
1199 connection
->userAgent
= NULL
;
1200 connection
->ftpPort
= NULL
;
1201 connection
->cookie
= NULL
;
1202 connection
->httpHeader
= NULL
;
1203 connection
->httpPostFirst
= NULL
;
1204 connection
->httpPostLast
= NULL
;
1205 connection
->httpPostStrings
= NULL
;
1206 connection
->sslCert
= NULL
;
1207 connection
->sslCertType
= NULL
;
1208 connection
->sslCertPasswd
= NULL
;
1209 connection
->sslKey
= NULL
;
1210 connection
->sslKeyType
= NULL
;
1211 connection
->sslKeyPasswd
= NULL
;
1212 connection
->sslEngine
= NULL
;
1213 connection
->quote
= NULL
;
1214 connection
->postQuote
= NULL
;
1215 connection
->cookieFile
= NULL
;
1216 connection
->customRequest
= NULL
;
1217 connection
->interface_
= NULL
;
1218 connection
->caInfo
= NULL
;
1219 connection
->caPath
= NULL
;
1220 connection
->randomFile
= NULL
;
1221 connection
->egdSocket
= NULL
;
1222 connection
->cookieJar
= NULL
;
1223 connection
->sslCipherList
= NULL
;
1224 connection
->private = NULL
;
1225 connection
->http200Aliases
= NULL
;
1226 connection
->netrcFile
= NULL
;
1227 connection
->ftpaccount
= NULL
;
1228 connection
->cookielist
= NULL
;
1229 connection
->ftpAlternativeToUser
= NULL
;
1230 connection
->sshPublicKeyFile
= NULL
;
1231 connection
->sshPrivateKeyFile
= NULL
;
1232 connection
->copyPostFields
= NULL
;
1233 connection
->resolve
= NULL
;
1234 connection
->dns_servers
= NULL
;
1239 static Connection
*duplicateConnection(Connection
*original
)
1241 Connection
*connection
;
1243 connection
= (Connection
*)malloc(sizeof(Connection
));
1245 enter_blocking_section();
1246 connection
->connection
= curl_easy_duphandle(original
->connection
);
1247 leave_blocking_section();
1249 connection
->next
= NULL
;
1250 connection
->prev
= NULL
;
1252 if (connectionList
.tail
== NULL
)
1254 connectionList
.tail
= connection
;
1255 connectionList
.head
= connection
;
1259 connection
->prev
= connectionList
.head
;
1260 connectionList
.head
->next
= connection
;
1261 connectionList
.head
= connection
;
1264 connection
->ocamlValues
= alloc(OcamlValuesSize
, 0);
1265 resetOcamlValues(connection
);
1266 register_global_root(&connection
->ocamlValues
);
1268 Store_field(connection
->ocamlValues
, OcamlWriteCallback
,
1269 Field(original
->ocamlValues
, OcamlWriteCallback
));
1270 Store_field(connection
->ocamlValues
, OcamlReadCallback
,
1271 Field(original
->ocamlValues
, OcamlReadCallback
));
1272 Store_field(connection
->ocamlValues
, OcamlErrorBuffer
,
1273 Field(original
->ocamlValues
, OcamlErrorBuffer
));
1274 Store_field(connection
->ocamlValues
, OcamlPostFields
,
1275 Field(original
->ocamlValues
, OcamlPostFields
));
1276 Store_field(connection
->ocamlValues
, OcamlHTTPHeader
,
1277 Field(original
->ocamlValues
, OcamlHTTPHeader
));
1278 Store_field(connection
->ocamlValues
, OcamlQuote
,
1279 Field(original
->ocamlValues
, OcamlQuote
));
1280 Store_field(connection
->ocamlValues
, OcamlPostQuote
,
1281 Field(original
->ocamlValues
, OcamlPostQuote
));
1282 Store_field(connection
->ocamlValues
, OcamlHeaderCallback
,
1283 Field(original
->ocamlValues
, OcamlHeaderCallback
));
1284 Store_field(connection
->ocamlValues
, OcamlProgressCallback
,
1285 Field(original
->ocamlValues
, OcamlProgressCallback
));
1286 Store_field(connection
->ocamlValues
, OcamlDebugCallback
,
1287 Field(original
->ocamlValues
, OcamlDebugCallback
));
1288 Store_field(connection
->ocamlValues
, OcamlHTTP200Aliases
,
1289 Field(original
->ocamlValues
, OcamlHTTP200Aliases
));
1290 Store_field(connection
->ocamlValues
, OcamlIOCTLCallback
,
1291 Field(original
->ocamlValues
, OcamlIOCTLCallback
));
1292 Store_field(connection
->ocamlValues
, OcamlSeekFunctionCallback
,
1293 Field(original
->ocamlValues
, OcamlSeekFunctionCallback
));
1295 connection
->url
= NULL
;
1296 connection
->proxy
= NULL
;
1297 connection
->userPwd
= NULL
;
1298 connection
->proxyUserPwd
= NULL
;
1299 connection
->range
= NULL
;
1300 connection
->errorBuffer
= NULL
;
1301 connection
->postFields
= NULL
;
1302 connection
->postFieldSize
= -1;
1303 connection
->referer
= NULL
;
1304 connection
->userAgent
= NULL
;
1305 connection
->ftpPort
= NULL
;
1306 connection
->cookie
= NULL
;
1307 connection
->httpHeader
= NULL
;
1308 connection
->httpPostFirst
= NULL
;
1309 connection
->httpPostLast
= NULL
;
1310 connection
->httpPostStrings
= NULL
;
1311 connection
->sslCert
= NULL
;
1312 connection
->sslCertType
= NULL
;
1313 connection
->sslCertPasswd
= NULL
;
1314 connection
->sslKey
= NULL
;
1315 connection
->sslKeyType
= NULL
;
1316 connection
->sslKeyPasswd
= NULL
;
1317 connection
->sslEngine
= NULL
;
1318 connection
->quote
= NULL
;
1319 connection
->postQuote
= NULL
;
1320 connection
->cookieFile
= NULL
;
1321 connection
->customRequest
= NULL
;
1322 connection
->interface_
= NULL
;
1323 connection
->caInfo
= NULL
;
1324 connection
->caPath
= NULL
;
1325 connection
->randomFile
= NULL
;
1326 connection
->egdSocket
= NULL
;
1327 connection
->cookieJar
= NULL
;
1328 connection
->sslCipherList
= NULL
;
1329 connection
->private = NULL
;
1330 connection
->http200Aliases
= NULL
;
1331 connection
->netrcFile
= NULL
;
1332 connection
->ftpaccount
= NULL
;
1333 connection
->cookielist
= NULL
;
1334 connection
->sshPublicKeyFile
= NULL
;
1335 connection
->sshPrivateKeyFile
= NULL
;
1336 connection
->copyPostFields
= NULL
;
1337 connection
->resolve
= NULL
;
1338 connection
->dns_servers
= NULL
;
1340 if (Field(original
->ocamlValues
, OcamlURL
) != Val_unit
)
1341 handleURL(connection
, Field(original
->ocamlValues
,
1343 if (Field(original
->ocamlValues
, OcamlProxy
) != Val_unit
)
1344 handleProxy(connection
, Field(original
->ocamlValues
,
1346 if (Field(original
->ocamlValues
, OcamlUserPWD
) != Val_unit
)
1347 handleUserPwd(connection
, Field(original
->ocamlValues
,
1349 if (Field(original
->ocamlValues
, OcamlProxyUserPWD
) != Val_unit
)
1350 handleProxyUserPwd(connection
, Field(original
->ocamlValues
,
1351 OcamlProxyUserPWD
));
1352 if (Field(original
->ocamlValues
, OcamlRange
) != Val_unit
)
1353 handleRange(connection
, Field(original
->ocamlValues
,
1355 if (Field(original
->ocamlValues
, OcamlErrorBuffer
) != Val_unit
)
1356 handleErrorBuffer(connection
, Field(original
->ocamlValues
,
1358 if (Field(original
->ocamlValues
, OcamlPostFields
) != Val_unit
)
1359 handlePostFields(connection
, Field(original
->ocamlValues
,
1361 if (Field(original
->ocamlValues
, OcamlReferer
) != Val_unit
)
1362 handleReferer(connection
, Field(original
->ocamlValues
,
1364 if (Field(original
->ocamlValues
, OcamlUserAgent
) != Val_unit
)
1365 handleUserAgent(connection
, Field(original
->ocamlValues
,
1367 if (Field(original
->ocamlValues
, OcamlFTPPort
) != Val_unit
)
1368 handleFTPPort(connection
, Field(original
->ocamlValues
,
1370 if (Field(original
->ocamlValues
, OcamlCookie
) != Val_unit
)
1371 handleCookie(connection
, Field(original
->ocamlValues
,
1373 if (Field(original
->ocamlValues
, OcamlHTTPHeader
) != Val_unit
)
1374 handleHTTPHeader(connection
, Field(original
->ocamlValues
,
1376 if (Field(original
->ocamlValues
, OcamlHTTPPost
) != Val_unit
)
1377 handleHTTPPost(connection
, Field(original
->ocamlValues
,
1379 if (Field(original
->ocamlValues
, OcamlSSLCert
) != Val_unit
)
1380 handleSSLCert(connection
, Field(original
->ocamlValues
,
1382 if (Field(original
->ocamlValues
, OcamlSSLCertType
) != Val_unit
)
1383 handleSSLCertType(connection
, Field(original
->ocamlValues
,
1385 if (Field(original
->ocamlValues
, OcamlSSLCertPasswd
) != Val_unit
)
1386 handleSSLCertPasswd(connection
, Field(original
->ocamlValues
,
1387 OcamlSSLCertPasswd
));
1388 if (Field(original
->ocamlValues
, OcamlSSLKey
) != Val_unit
)
1389 handleSSLKey(connection
, Field(original
->ocamlValues
,
1391 if (Field(original
->ocamlValues
, OcamlSSLKeyType
) != Val_unit
)
1392 handleSSLKeyType(connection
, Field(original
->ocamlValues
,
1394 if (Field(original
->ocamlValues
, OcamlSSLKeyPasswd
) != Val_unit
)
1395 handleSSLKeyPasswd(connection
, Field(original
->ocamlValues
,
1396 OcamlSSLKeyPasswd
));
1397 if (Field(original
->ocamlValues
, OcamlSSLEngine
) != Val_unit
)
1398 handleSSLEngine(connection
, Field(original
->ocamlValues
,
1400 if (Field(original
->ocamlValues
, OcamlQuote
) != Val_unit
)
1401 handleQuote(connection
, Field(original
->ocamlValues
,
1403 if (Field(original
->ocamlValues
, OcamlPostQuote
) != Val_unit
)
1404 handlePostQuote(connection
, Field(original
->ocamlValues
,
1406 if (Field(original
->ocamlValues
, OcamlCookieFile
) != Val_unit
)
1407 handleCookieFile(connection
, Field(original
->ocamlValues
,
1409 if (Field(original
->ocamlValues
, OcamlCustomRequest
) != Val_unit
)
1410 handleCustomRequest(connection
, Field(original
->ocamlValues
,
1411 OcamlCustomRequest
));
1412 if (Field(original
->ocamlValues
, OcamlInterface
) != Val_unit
)
1413 handleInterface(connection
, Field(original
->ocamlValues
,
1415 if (Field(original
->ocamlValues
, OcamlCAInfo
) != Val_unit
)
1416 handleCAInfo(connection
, Field(original
->ocamlValues
,
1418 if (Field(original
->ocamlValues
, OcamlCAPath
) != Val_unit
)
1419 handleCAPath(connection
, Field(original
->ocamlValues
,
1421 if (Field(original
->ocamlValues
, OcamlRandomFile
) != Val_unit
)
1422 handleRandomFile(connection
, Field(original
->ocamlValues
,
1424 if (Field(original
->ocamlValues
, OcamlEGDSocket
) != Val_unit
)
1425 handleEGDSocket(connection
, Field(original
->ocamlValues
,
1427 if (Field(original
->ocamlValues
, OcamlCookieJar
) != Val_unit
)
1428 handleCookieJar(connection
, Field(original
->ocamlValues
,
1430 if (Field(original
->ocamlValues
, OcamlSSLCipherList
) != Val_unit
)
1431 handleSSLCipherList(connection
, Field(original
->ocamlValues
,
1432 OcamlSSLCipherList
));
1433 if (Field(original
->ocamlValues
, OcamlPrivate
) != Val_unit
)
1434 handlePrivate(connection
, Field(original
->ocamlValues
,
1436 if (Field(original
->ocamlValues
, OcamlHTTP200Aliases
) != Val_unit
)
1437 handleHTTP200Aliases(connection
, Field(original
->ocamlValues
,
1438 OcamlHTTP200Aliases
));
1439 if (Field(original
->ocamlValues
, OcamlNETRCFile
) != Val_unit
)
1440 handleNETRCFile(connection
, Field(original
->ocamlValues
,
1442 if (Field(original
->ocamlValues
, OcamlFTPAccount
) != Val_unit
)
1443 handleFTPAccount(connection
, Field(original
->ocamlValues
,
1445 if (Field(original
->ocamlValues
, OcamlCookieList
) != Val_unit
)
1446 handleCookieList(connection
, Field(original
->ocamlValues
,
1448 if (Field(original
->ocamlValues
, OcamlFTPAlternativeToUser
) != Val_unit
)
1449 handleFTPAlternativeToUser(connection
,
1450 Field(original
->ocamlValues
,
1451 OcamlFTPAlternativeToUser
));
1452 if (Field(original
->ocamlValues
, OcamlSSHPublicKeyFile
) != Val_unit
)
1453 handleSSHPublicKeyFile(connection
,
1454 Field(original
->ocamlValues
,
1455 OcamlSSHPublicKeyFile
));
1456 if (Field(original
->ocamlValues
, OcamlSSHPrivateKeyFile
) != Val_unit
)
1457 handleSSHPrivateKeyFile(connection
,
1458 Field(original
->ocamlValues
,
1459 OcamlSSHPrivateKeyFile
));
1460 if (Field(original
->ocamlValues
, OcamlCopyPostFields
) != Val_unit
)
1461 handleCopyPostFields(connection
,
1462 Field(original
->ocamlValues
,
1463 OcamlCopyPostFields
));
1468 static void free_if(void* p
) { if (NULL
!= p
) free(p
); }
1470 static void removeConnection(Connection
*connection
)
1472 enter_blocking_section();
1473 curl_easy_cleanup(connection
->connection
);
1474 leave_blocking_section();
1476 if (connectionList
.tail
== connection
)
1477 connectionList
.tail
= connectionList
.tail
->next
;
1478 if (connectionList
.head
== connection
)
1479 connectionList
.head
= connectionList
.head
->prev
;
1481 if (connection
->next
!= NULL
)
1482 connection
->next
->prev
= connection
->prev
;
1483 if (connection
->prev
!= NULL
)
1484 connection
->prev
->next
= connection
->next
;
1486 remove_global_root(&connection
->ocamlValues
);
1488 free_if(connection
->url
);
1489 free_if(connection
->proxy
);
1490 free_if(connection
->userPwd
);
1491 free_if(connection
->proxyUserPwd
);
1492 free_if(connection
->range
);
1493 free_if(connection
->errorBuffer
);
1494 free_if(connection
->postFields
);
1495 free_if(connection
->referer
);
1496 free_if(connection
->userAgent
);
1497 free_if(connection
->ftpPort
);
1498 free_if(connection
->cookie
);
1499 free_curl_slist(connection
->httpHeader
);
1500 if (connection
->httpPostFirst
!= NULL
)
1501 curl_formfree(connection
->httpPostFirst
);
1502 free_curl_slist(connection
->httpPostStrings
);
1503 free_curl_slist(connection
->resolve
);
1504 free_if(connection
->sslCert
);
1505 free_if(connection
->sslCertType
);
1506 free_if(connection
->sslCertPasswd
);
1507 free_if(connection
->sslKey
);
1508 free_if(connection
->sslKeyType
);
1509 free_if(connection
->sslKeyPasswd
);
1510 free_if(connection
->sslEngine
);
1511 free_curl_slist(connection
->quote
);
1512 free_curl_slist(connection
->postQuote
);
1513 free_if(connection
->cookieFile
);
1514 free_if(connection
->customRequest
);
1515 free_if(connection
->interface_
);
1516 free_if(connection
->caInfo
);
1517 free_if(connection
->caPath
);
1518 free_if(connection
->randomFile
);
1519 free_if(connection
->egdSocket
);
1520 free_if(connection
->cookieJar
);
1521 free_if(connection
->sslCipherList
);
1522 free_if(connection
->private);
1523 free_curl_slist(connection
->http200Aliases
);
1524 free_if(connection
->netrcFile
);
1525 free_if(connection
->ftpaccount
);
1526 free_if(connection
->cookielist
);
1527 free_if(connection
->ftpAlternativeToUser
);
1528 free_if(connection
->sshPublicKeyFile
);
1529 free_if(connection
->sshPrivateKeyFile
);
1530 free_if(connection
->copyPostFields
);
1531 free_if(connection
->dns_servers
);
1537 static void checkConnection(Connection
* connection
)
1542 static void checkConnection(Connection
*connection
)
1544 Connection
*listIter
;
1546 listIter
= connectionList
.tail
;
1548 while (listIter
!= NULL
)
1550 if (listIter
== connection
)
1553 listIter
= listIter
->next
;
1556 failwith("Invalid Connection");
1560 static Connection
* findConnection(CURL
* h
)
1562 Connection
*listIter
;
1564 listIter
= connectionList
.tail
;
1566 while (listIter
!= NULL
)
1568 if (listIter
->connection
== h
)
1571 listIter
= listIter
->next
;
1574 failwith("Unknown handle");
1577 #define WRAP_DATA_CALLBACK(f) \
1578 static size_t f(char *ptr, size_t size, size_t nmemb, void *data)\
1581 leave_blocking_section();\
1582 result = f##_nolock(ptr,size,nmemb,data);\
1583 enter_blocking_section();\
1587 static size_t writeFunction_nolock(char *ptr
, size_t size
, size_t nmemb
, void *data
)
1590 CAMLlocal2(result
, str
);
1591 Connection
*conn
= (Connection
*)data
;
1594 checkConnection(conn
);
1596 str
= alloc_string(size
*nmemb
);
1598 for (i
= 0; i
< size
*nmemb
; i
++)
1599 Byte(str
, i
) = ptr
[i
];
1601 result
= callback_exn(Field(conn
->ocamlValues
, OcamlWriteCallback
), str
);
1603 CAMLreturnT(size_t, Is_exception_result(result
) ? 0 : Int_val(result
));
1606 WRAP_DATA_CALLBACK(writeFunction
)
1608 static size_t readFunction_nolock(void *ptr
, size_t size
, size_t nmemb
, void *data
)
1612 Connection
*conn
= (Connection
*)data
;
1615 checkConnection(conn
);
1617 result
= callback_exn(Field(conn
->ocamlValues
, OcamlReadCallback
),
1618 Val_int(size
*nmemb
));
1620 if (Is_exception_result(result
))
1622 CAMLreturnT(size_t,CURL_READFUNC_ABORT
);
1625 length
= string_length(result
);
1627 if (length
>= size
*nmemb
)
1628 length
= size
*nmemb
;
1630 memcpy(ptr
, String_val(result
), length
);
1632 CAMLreturnT(size_t,length
);
1635 WRAP_DATA_CALLBACK(readFunction
)
1637 static size_t headerFunction_nolock(char *ptr
, size_t size
, size_t nmemb
, void *data
)
1640 CAMLlocal2(result
,str
);
1641 Connection
*conn
= (Connection
*)data
;
1644 checkConnection(conn
);
1646 str
= alloc_string(size
*nmemb
);
1648 for (i
= 0; i
< size
*nmemb
; i
++)
1649 Byte(str
, i
) = ptr
[i
];
1651 result
= callback_exn(Field(conn
->ocamlValues
, OcamlHeaderCallback
), str
);
1653 CAMLreturnT(size_t, Is_exception_result(result
) ? 0 : Int_val(result
));
1656 WRAP_DATA_CALLBACK(headerFunction
)
1658 static int progressFunction_nolock(void *data
,
1666 CAMLlocalN(callbackData
, 4);
1667 Connection
*conn
= (Connection
*)data
;
1669 checkConnection(conn
);
1671 callbackData
[0] = copy_double(dlTotal
);
1672 callbackData
[1] = copy_double(dlNow
);
1673 callbackData
[2] = copy_double(ulTotal
);
1674 callbackData
[3] = copy_double(ulNow
);
1676 result
= callbackN_exn(Field(conn
->ocamlValues
, OcamlProgressCallback
),
1679 CAMLreturnT(int, Is_exception_result(result
) ? 1 : Bool_val(result
));
1682 static int progressFunction(void *data
,
1689 leave_blocking_section();
1690 r
= progressFunction_nolock(data
,dlTotal
,dlNow
,ulTotal
,ulNow
);
1691 enter_blocking_section();
1695 static int debugFunction_nolock(CURL
*debugConnection
,
1696 curl_infotype infoType
,
1698 size_t bufferLength
,
1702 CAMLlocal3(camlDebugConnection
, camlInfoType
, camlMessage
);
1704 Connection
*conn
= (Connection
*)data
;
1705 (void)debugConnection
; /* not used */
1707 checkConnection(conn
);
1709 camlDebugConnection
= (value
)conn
;
1710 camlInfoType
= Val_long(infoType
);
1711 camlMessage
= alloc_string(bufferLength
);
1713 for (i
= 0; i
< bufferLength
; i
++)
1714 Byte(camlMessage
, i
) = buffer
[i
];
1716 callback3_exn(Field(conn
->ocamlValues
, OcamlDebugCallback
),
1717 camlDebugConnection
,
1721 CAMLreturnT(int, 0);
1724 static int debugFunction(CURL
*debugConnection
,
1725 curl_infotype infoType
,
1727 size_t bufferLength
,
1731 leave_blocking_section();
1732 r
= debugFunction_nolock(debugConnection
, infoType
, buffer
, bufferLength
, data
);
1733 enter_blocking_section();
1737 static curlioerr
ioctlFunction_nolock(CURL
*ioctl
,
1742 CAMLlocal3(camlResult
, camlConnection
, camlCmd
);
1743 Connection
*conn
= (Connection
*)data
;
1744 curlioerr result
= CURLIOE_OK
;
1745 (void)ioctl
; /* not used */
1747 checkConnection(conn
);
1749 if (cmd
== CURLIOCMD_NOP
)
1750 camlCmd
= Val_long(0);
1751 else if (cmd
== CURLIOCMD_RESTARTREAD
)
1752 camlCmd
= Val_long(1);
1754 failwith("Invalid IOCTL Cmd!");
1756 camlConnection
= caml_alloc(1, Abstract_tag
);
1757 Field(camlConnection
, 0) = (value
)conn
;
1759 camlResult
= callback2_exn(Field(conn
->ocamlValues
, OcamlIOCTLCallback
),
1763 if (Is_exception_result(camlResult
))
1765 result
= CURLIOE_FAILRESTART
;
1768 switch (Long_val(camlResult
))
1770 case 0: /* CURLIOE_OK */
1771 result
= CURLIOE_OK
;
1774 case 1: /* CURLIOE_UNKNOWNCMD */
1775 result
= CURLIOE_UNKNOWNCMD
;
1778 case 2: /* CURLIOE_FAILRESTART */
1779 result
= CURLIOE_FAILRESTART
;
1782 default: /* Incorrect return value, but let's handle it */
1783 result
= CURLIOE_FAILRESTART
;
1787 CAMLreturnT(curlioerr
, result
);
1790 static curlioerr
ioctlFunction(CURL
*ioctl
,
1795 leave_blocking_section();
1796 r
= ioctlFunction_nolock(ioctl
, cmd
, data
);
1797 enter_blocking_section();
1801 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1802 static int seekFunction_nolock(void *data
,
1807 CAMLlocal3(camlResult
, camlOffset
, camlOrigin
);
1808 Connection
*conn
= (Connection
*)data
;
1810 camlOffset
= copy_int64(offset
);
1812 if (origin
== SEEK_SET
)
1813 camlOrigin
= Val_long(0);
1814 else if (origin
== SEEK_CUR
)
1815 camlOrigin
= Val_long(1);
1816 else if (origin
== SEEK_END
)
1817 camlOrigin
= Val_long(2);
1819 failwith("Invalid seek code");
1821 camlResult
= callback2_exn(Field(conn
->ocamlValues
,
1822 OcamlSeekFunctionCallback
),
1827 if (Is_exception_result(camlResult
))
1828 result
= CURL_SEEKFUNC_FAIL
;
1830 switch (Int_val(camlResult
))
1832 case 0: result
= CURL_SEEKFUNC_OK
; break;
1833 case 1: result
= CURL_SEEKFUNC_FAIL
; break;
1834 case 2: result
= CURL_SEEKFUNC_CANTSEEK
; break;
1835 default: failwith("Invalid seek result");
1838 CAMLreturnT(int, result
);
1841 static int seekFunction(void *data
,
1846 leave_blocking_section();
1847 r
= seekFunction_nolock(data
,offset
,origin
);
1848 enter_blocking_section();
1854 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1855 static int openSocketFunction_nolock(void *data
,
1856 curlsocktype purpose
,
1857 struct curl_sockaddr
*addr
)
1861 Connection
*conn
= (Connection
*)data
;
1863 (void)purpose
; /* not used */
1865 sock
= socket(addr
->family
, addr
->socktype
, addr
->protocol
);
1870 result
= callback_exn(Field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
), Val_int(sock
));
1871 if (Is_exception_result(result
))
1878 CAMLreturnT(int, (sock
== -1) ? CURL_SOCKET_BAD
: sock
);
1881 static int openSocketFunction(void *data
,
1882 curlsocktype purpose
,
1883 struct curl_sockaddr
*address
)
1886 leave_blocking_section();
1887 r
= openSocketFunction_nolock(data
,purpose
,address
);
1888 enter_blocking_section();
1895 ** curl_global_init helper function
1898 CAMLprim value
helper_curl_global_init(value initOption
)
1900 CAMLparam1(initOption
);
1902 switch (Long_val(initOption
))
1904 case 0: /* CURLINIT_GLOBALALL */
1905 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_ALL
)));
1908 case 1: /* CURLINIT_GLOBALSSL */
1909 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_SSL
)));
1912 case 2: /* CURLINIT_GLOBALWIN32 */
1913 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_WIN32
)));
1916 case 3: /* CURLINIT_GLOBALNOTHING */
1917 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_NOTHING
)));
1921 failwith("Invalid Initialization Option");
1925 /* Keep compiler happy, we should never get here due to failwith() */
1926 CAMLreturn(Val_unit
);
1930 ** curl_global_cleanup helper function
1933 CAMLprim value
helper_curl_global_cleanup(void)
1937 curl_global_cleanup();
1939 CAMLreturn(Val_unit
);
1943 ** curl_easy_init helper function
1946 CAMLprim value
helper_curl_easy_init(void)
1951 Connection
*conn
= newConnection();
1953 result
= caml_alloc(1, Abstract_tag
);
1954 Field(result
, 0) = (value
)conn
;
1959 CAMLprim value
helper_curl_easy_reset(value conn
)
1962 Connection
*connection
= Connection_val(conn
);
1964 checkConnection(connection
);
1965 curl_easy_reset(connection
->connection
);
1966 resetOcamlValues(connection
);
1968 CAMLreturn(Val_unit
);
1972 ** curl_easy_setopt helper utility functions
1975 static void handleWriteFunction(Connection
*conn
, value option
)
1978 CURLcode result
= CURLE_OK
;
1980 if (Tag_val(option
) == Closure_tag
)
1981 Store_field(conn
->ocamlValues
, OcamlWriteCallback
, option
);
1983 failwith("Not a proper closure");
1985 result
= curl_easy_setopt(conn
->connection
,
1986 CURLOPT_WRITEFUNCTION
,
1989 if (result
!= CURLE_OK
)
1990 raiseError(conn
, result
);
1992 result
= curl_easy_setopt(conn
->connection
,
1996 if (result
!= CURLE_OK
)
1997 raiseError(conn
, result
);
2002 static void handleReadFunction(Connection
*conn
, value option
)
2005 CURLcode result
= CURLE_OK
;
2007 if (Tag_val(option
) == Closure_tag
)
2008 Store_field(conn
->ocamlValues
, OcamlReadCallback
, option
);
2010 failwith("Not a proper closure");
2012 result
= curl_easy_setopt(conn
->connection
,
2013 CURLOPT_READFUNCTION
,
2016 if (result
!= CURLE_OK
)
2017 raiseError(conn
, result
);
2019 result
= curl_easy_setopt(conn
->connection
,
2023 if (result
!= CURLE_OK
)
2024 raiseError(conn
, result
);
2029 static void handleURL(Connection
*conn
, value option
)
2032 CURLcode result
= CURLE_OK
;
2034 Store_field(conn
->ocamlValues
, OcamlURL
, option
);
2036 if (conn
->url
!= NULL
)
2039 conn
->url
= strdup(String_val(option
));
2041 result
= curl_easy_setopt(conn
->connection
,
2045 if (result
!= CURLE_OK
)
2046 raiseError(conn
, result
);
2051 static void handleInFileSize(Connection
*conn
, value option
)
2054 CURLcode result
= CURLE_OK
;
2056 result
= curl_easy_setopt(conn
->connection
,
2060 if (result
!= CURLE_OK
)
2061 raiseError(conn
, result
);
2066 static void handleProxy(Connection
*conn
, value option
)
2069 CURLcode result
= CURLE_OK
;
2071 Store_field(conn
->ocamlValues
, OcamlProxy
, option
);
2073 if (conn
->proxy
!= NULL
)
2076 conn
->proxy
= strdup(String_val(option
));
2078 result
= curl_easy_setopt(conn
->connection
,
2082 if (result
!= CURLE_OK
)
2083 raiseError(conn
, result
);
2088 static void handleProxyPort(Connection
*conn
, value option
)
2091 CURLcode result
= CURLE_OK
;
2093 result
= curl_easy_setopt(conn
->connection
,
2097 if (result
!= CURLE_OK
)
2098 raiseError(conn
, result
);
2103 static void handleHTTPProxyTunnel(Connection
*conn
, value option
)
2106 CURLcode result
= CURLE_OK
;
2108 result
= curl_easy_setopt(conn
->connection
,
2109 CURLOPT_HTTPPROXYTUNNEL
,
2112 if (result
!= CURLE_OK
)
2113 raiseError(conn
, result
);
2118 static void handleVerbose(Connection
*conn
, value option
)
2121 CURLcode result
= CURLE_OK
;
2123 result
= curl_easy_setopt(conn
->connection
,
2127 if (result
!= CURLE_OK
)
2128 raiseError(conn
, result
);
2133 static void handleHeader(Connection
*conn
, value option
)
2136 CURLcode result
= CURLE_OK
;
2138 result
= curl_easy_setopt(conn
->connection
,
2142 if (result
!= CURLE_OK
)
2143 raiseError(conn
, result
);
2148 static void handleNoProgress(Connection
*conn
, value option
)
2151 CURLcode result
= CURLE_OK
;
2153 result
= curl_easy_setopt(conn
->connection
,
2157 if (result
!= CURLE_OK
)
2158 raiseError(conn
, result
);
2163 static void handleNoSignal(Connection
*conn
, value option
)
2165 #if HAVE_DECL_CURLOPT_NOSIGNAL
2167 CURLcode result
= CURLE_OK
;
2169 result
= curl_easy_setopt(conn
->connection
,
2173 if (result
!= CURLE_OK
)
2174 raiseError(conn
, result
);
2178 #pragma message("libcurl does not implement CURLOPT_NOSIGNAL")
2179 failwith("libcurl does not implement CURLOPT_NOSIGNAL");
2183 static void handleNoBody(Connection
*conn
, value option
)
2186 CURLcode result
= CURLE_OK
;
2188 result
= curl_easy_setopt(conn
->connection
,
2192 if (result
!= CURLE_OK
)
2193 raiseError(conn
, result
);
2198 static void handleFailOnError(Connection
*conn
, value option
)
2201 CURLcode result
= CURLE_OK
;
2203 result
= curl_easy_setopt(conn
->connection
,
2204 CURLOPT_FAILONERROR
,
2207 if (result
!= CURLE_OK
)
2208 raiseError(conn
, result
);
2213 static void handleUpload(Connection
*conn
, value option
)
2216 CURLcode result
= CURLE_OK
;
2218 result
= curl_easy_setopt(conn
->connection
,
2222 if (result
!= CURLE_OK
)
2223 raiseError(conn
, result
);
2228 static void handlePost(Connection
*conn
, value option
)
2231 CURLcode result
= CURLE_OK
;
2233 result
= curl_easy_setopt(conn
->connection
,
2237 if (result
!= CURLE_OK
)
2238 raiseError(conn
, result
);
2243 static void handleFTPListOnly(Connection
*conn
, value option
)
2246 CURLcode result
= CURLE_OK
;
2248 result
= curl_easy_setopt(conn
->connection
,
2249 CURLOPT_FTPLISTONLY
,
2252 if (result
!= CURLE_OK
)
2253 raiseError(conn
, result
);
2258 static void handleFTPAppend(Connection
*conn
, value option
)
2261 CURLcode result
= CURLE_OK
;
2263 result
= curl_easy_setopt(conn
->connection
,
2267 if (result
!= CURLE_OK
)
2268 raiseError(conn
, result
);
2273 static void handleNETRC(Connection
*conn
, value option
)
2276 CURLcode result
= CURLE_OK
;
2279 switch (Long_val(option
))
2281 case 0: /* CURL_NETRC_OPTIONAL */
2282 netrc
= CURL_NETRC_OPTIONAL
;
2285 case 1:/* CURL_NETRC_IGNORED */
2286 netrc
= CURL_NETRC_IGNORED
;
2289 case 2: /* CURL_NETRC_REQUIRED */
2290 netrc
= CURL_NETRC_REQUIRED
;
2294 failwith("Invalid NETRC Option");
2298 result
= curl_easy_setopt(conn
->connection
,
2302 if (result
!= CURLE_OK
)
2303 raiseError(conn
, result
);
2308 static void handleEncoding(Connection
*conn
, value option
)
2310 #if HAVE_DECL_CURLOPT_ENCODING
2312 CURLcode result
= CURLE_OK
;
2314 switch (Long_val(option
))
2316 case 0: /* CURL_ENCODING_NONE */
2317 result
= curl_easy_setopt(conn
->connection
,
2322 case 1: /* CURL_ENCODING_DEFLATE */
2323 result
= curl_easy_setopt(conn
->connection
,
2328 case 2: /* CURL_ENCODING_GZIP */
2329 result
= curl_easy_setopt(conn
->connection
,
2334 case 3: /* CURL_ENCODING_ANY */
2335 result
= curl_easy_setopt(conn
->connection
,
2341 failwith("Invalid Encoding Option");
2345 if (result
!= CURLE_OK
)
2346 raiseError(conn
, result
);
2350 #pragma message("libcurl does not implement CURLOPT_ENCODING")
2351 failwith("libcurl does not implement CURLOPT_ENCODING");
2355 static void handleFollowLocation(Connection
*conn
, value option
)
2358 CURLcode result
= CURLE_OK
;
2360 result
= curl_easy_setopt(conn
->connection
,
2361 CURLOPT_FOLLOWLOCATION
,
2364 if (result
!= CURLE_OK
)
2365 raiseError(conn
, result
);
2370 static void handleTransferText(Connection
*conn
, value option
)
2373 CURLcode result
= CURLE_OK
;
2375 result
= curl_easy_setopt(conn
->connection
,
2376 CURLOPT_TRANSFERTEXT
,
2379 if (result
!= CURLE_OK
)
2380 raiseError(conn
, result
);
2385 static void handlePut(Connection
*conn
, value option
)
2388 CURLcode result
= CURLE_OK
;
2390 result
= curl_easy_setopt(conn
->connection
,
2394 if (result
!= CURLE_OK
)
2395 raiseError(conn
, result
);
2400 static void handleUserPwd(Connection
*conn
, value option
)
2403 CURLcode result
= CURLE_OK
;
2405 Store_field(conn
->ocamlValues
, OcamlUserPWD
, option
);
2407 if (conn
->userPwd
!= NULL
)
2408 free(conn
->userPwd
);
2410 conn
->userPwd
= strdup(String_val(option
));
2412 result
= curl_easy_setopt(conn
->connection
,
2416 if (result
!= CURLE_OK
)
2417 raiseError(conn
, result
);
2422 static void handleProxyUserPwd(Connection
*conn
, value option
)
2425 CURLcode result
= CURLE_OK
;
2427 Store_field(conn
->ocamlValues
, OcamlProxyUserPWD
, option
);
2429 if (conn
->proxyUserPwd
!= NULL
)
2430 free(conn
->proxyUserPwd
);
2432 conn
->proxyUserPwd
= strdup(String_val(option
));
2434 result
= curl_easy_setopt(conn
->connection
,
2435 CURLOPT_PROXYUSERPWD
,
2436 conn
->proxyUserPwd
);
2438 if (result
!= CURLE_OK
)
2439 raiseError(conn
, result
);
2444 static void handleRange(Connection
*conn
, value option
)
2447 CURLcode result
= CURLE_OK
;
2449 Store_field(conn
->ocamlValues
, OcamlRange
, option
);
2451 if (conn
->range
!= NULL
)
2454 conn
->range
= strdup(String_val(option
));
2456 result
= curl_easy_setopt(conn
->connection
,
2460 if (result
!= CURLE_OK
)
2461 raiseError(conn
, result
);
2466 static void handleErrorBuffer(Connection
*conn
, value option
)
2469 CURLcode result
= CURLE_OK
;
2471 Store_field(conn
->ocamlValues
, OcamlErrorBuffer
, option
);
2473 if (conn
->errorBuffer
!= NULL
)
2474 free(conn
->errorBuffer
);
2476 conn
->errorBuffer
= malloc(sizeof(char) * CURL_ERROR_SIZE
);
2478 result
= curl_easy_setopt(conn
->connection
,
2479 CURLOPT_ERRORBUFFER
,
2482 if (result
!= CURLE_OK
)
2483 raiseError(conn
, result
);
2488 static void handleTimeout(Connection
*conn
, value option
)
2491 CURLcode result
= CURLE_OK
;
2493 result
= curl_easy_setopt(conn
->connection
,
2497 if (result
!= CURLE_OK
)
2498 raiseError(conn
, result
);
2503 static void handlePostFields(Connection
*conn
, value option
)
2506 CURLcode result
= CURLE_OK
;
2508 Store_field(conn
->ocamlValues
, OcamlPostFields
, option
);
2510 if (conn
->postFields
!= NULL
)
2511 free(conn
->postFields
);
2513 conn
->postFields
= malloc(string_length(option
)+1);
2514 memcpy(conn
->postFields
, String_val(option
), string_length(option
)+1);
2516 result
= curl_easy_setopt(conn
->connection
,
2520 if (result
!= CURLE_OK
)
2521 raiseError(conn
, result
);
2526 static void handlePostFieldSize(Connection
*conn
, value option
)
2529 CURLcode result
= CURLE_OK
;
2531 result
= curl_easy_setopt(conn
->connection
,
2532 CURLOPT_POSTFIELDSIZE
,
2535 if (result
!= CURLE_OK
)
2536 raiseError(conn
, result
);
2541 static void handleReferer(Connection
*conn
, value option
)
2544 CURLcode result
= CURLE_OK
;
2546 Store_field(conn
->ocamlValues
, OcamlReferer
, option
);
2548 if (conn
->referer
!= NULL
)
2549 free(conn
->referer
);
2551 conn
->referer
= strdup(String_val(option
));
2553 result
= curl_easy_setopt(conn
->connection
,
2557 if (result
!= CURLE_OK
)
2558 raiseError(conn
, result
);
2563 static void handleUserAgent(Connection
*conn
, value option
)
2566 CURLcode result
= CURLE_OK
;
2568 Store_field(conn
->ocamlValues
, OcamlUserAgent
, option
);
2570 if (conn
->userAgent
!= NULL
)
2571 free(conn
->userAgent
);
2573 conn
->userAgent
= strdup(String_val(option
));
2575 result
= curl_easy_setopt(conn
->connection
,
2579 if (result
!= CURLE_OK
)
2580 raiseError(conn
, result
);
2585 static void handleFTPPort(Connection
*conn
, value option
)
2588 CURLcode result
= CURLE_OK
;
2590 Store_field(conn
->ocamlValues
, OcamlFTPPort
, option
);
2592 if (conn
->ftpPort
!= NULL
)
2593 free(conn
->ftpPort
);
2595 conn
->ftpPort
= strdup(String_val(option
));
2597 result
= curl_easy_setopt(conn
->connection
,
2601 if (result
!= CURLE_OK
)
2602 raiseError(conn
, result
);
2607 static void handleLowSpeedLimit(Connection
*conn
, value option
)
2610 CURLcode result
= CURLE_OK
;
2612 result
= curl_easy_setopt(conn
->connection
,
2613 CURLOPT_LOW_SPEED_LIMIT
,
2616 if (result
!= CURLE_OK
)
2617 raiseError(conn
, result
);
2622 static void handleLowSpeedTime(Connection
*conn
, value option
)
2625 CURLcode result
= CURLE_OK
;
2627 result
= curl_easy_setopt(conn
->connection
,
2628 CURLOPT_LOW_SPEED_TIME
,
2631 if (result
!= CURLE_OK
)
2632 raiseError(conn
, result
);
2637 static void handleResumeFrom(Connection
*conn
, value option
)
2640 CURLcode result
= CURLE_OK
;
2642 result
= curl_easy_setopt(conn
->connection
,
2643 CURLOPT_RESUME_FROM
,
2646 if (result
!= CURLE_OK
)
2647 raiseError(conn
, result
);
2652 static void handleCookie(Connection
*conn
, value option
)
2655 CURLcode result
= CURLE_OK
;
2657 Store_field(conn
->ocamlValues
, OcamlCookie
, option
);
2659 if (conn
->cookie
!= NULL
)
2662 conn
->cookie
= strdup(String_val(option
));
2664 result
= curl_easy_setopt(conn
->connection
,
2668 if (result
!= CURLE_OK
)
2669 raiseError(conn
, result
);
2674 static void handleHTTPHeader(Connection
*conn
, value option
)
2677 CAMLlocal1(listIter
);
2678 CURLcode result
= CURLE_OK
;
2680 Store_field(conn
->ocamlValues
, OcamlHTTPHeader
, option
);
2682 free_curl_slist(conn
->httpHeader
);
2683 conn
->httpHeader
= NULL
;
2687 while (!Is_long(listIter
))
2689 conn
->httpHeader
= curl_slist_append(conn
->httpHeader
, String_val(Field(listIter
, 0)));
2691 listIter
= Field(listIter
, 1);
2694 result
= curl_easy_setopt(conn
->connection
,
2698 if (result
!= CURLE_OK
)
2699 raiseError(conn
, result
);
2704 static void handleHTTPPost(Connection
*conn
, value option
)
2707 CAMLlocal3(listIter
, formItem
, contentType
);
2708 CURLcode result
= CURLE_OK
;
2709 char *str1
, *str2
, *str3
, *str4
;
2713 Store_field(conn
->ocamlValues
, OcamlHTTPPost
, option
);
2715 if (conn
->httpPostFirst
!= NULL
)
2716 curl_formfree(conn
->httpPostFirst
);
2718 conn
->httpPostFirst
= NULL
;
2719 conn
->httpPostLast
= NULL
;
2721 free_curl_slist(conn
->httpPostStrings
);
2722 conn
->httpPostStrings
= NULL
;
2724 while (!Is_long(listIter
))
2726 formItem
= Field(listIter
, 0);
2728 switch (Tag_val(formItem
))
2730 case 0: /* CURLFORM_CONTENT */
2731 if (Wosize_val(formItem
) < 3)
2733 failwith("Incorrect CURLFORM_CONTENT parameters");
2736 if (Is_long(Field(formItem
, 2)) &&
2737 Long_val(Field(formItem
, 2)) == 0)
2739 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2741 String_val(Field(formItem
, 0)),
2742 string_length(Field(formItem
, 0)));
2743 str1
[string_length(Field(formItem
, 0))] = 0;
2744 conn
->httpPostStrings
=
2745 curl_slist_append(conn
->httpPostStrings
, str1
);
2747 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2749 String_val(Field(formItem
, 1)),
2750 string_length(Field(formItem
, 1)));
2751 str2
[string_length(Field(formItem
, 1))] = 0;
2752 conn
->httpPostStrings
=
2753 curl_slist_append(conn
->httpPostStrings
, str2
);
2755 curl_formadd(&conn
->httpPostFirst
,
2756 &conn
->httpPostLast
,
2759 CURLFORM_NAMELENGTH
,
2760 string_length(Field(formItem
, 0)),
2761 CURLFORM_PTRCONTENTS
,
2763 CURLFORM_CONTENTSLENGTH
,
2764 string_length(Field(formItem
, 1)),
2767 else if (Is_block(Field(formItem
, 2)))
2769 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2771 String_val(Field(formItem
, 0)),
2772 string_length(Field(formItem
, 0)));
2773 str1
[string_length(Field(formItem
, 0))] = 0;
2774 conn
->httpPostStrings
=
2775 curl_slist_append(conn
->httpPostStrings
, str1
);
2777 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2779 String_val(Field(formItem
, 1)),
2780 string_length(Field(formItem
, 1)));
2781 str2
[string_length(Field(formItem
, 1))] = 0;
2782 conn
->httpPostStrings
=
2783 curl_slist_append(conn
->httpPostStrings
, str2
);
2785 contentType
= Field(formItem
, 2);
2787 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2789 String_val(Field(contentType
, 0)),
2790 string_length(Field(contentType
, 0)));
2791 str3
[string_length(Field(contentType
, 0))] = 0;
2792 conn
->httpPostStrings
=
2793 curl_slist_append(conn
->httpPostStrings
, str3
);
2795 curl_formadd(&conn
->httpPostFirst
,
2796 &conn
->httpPostLast
,
2799 CURLFORM_NAMELENGTH
,
2800 string_length(Field(formItem
, 0)),
2801 CURLFORM_PTRCONTENTS
,
2803 CURLFORM_CONTENTSLENGTH
,
2804 string_length(Field(formItem
, 1)),
2805 CURLFORM_CONTENTTYPE
,
2811 failwith("Incorrect CURLFORM_CONTENT parameters");
2815 case 1: /* CURLFORM_FILECONTENT */
2816 if (Wosize_val(formItem
) < 3)
2818 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2821 if (Is_long(Field(formItem
, 2)) &&
2822 Long_val(Field(formItem
, 2)) == 0)
2824 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2826 String_val(Field(formItem
, 0)),
2827 string_length(Field(formItem
, 0)));
2828 str1
[string_length(Field(formItem
, 0))] = 0;
2829 conn
->httpPostStrings
=
2830 curl_slist_append(conn
->httpPostStrings
, str1
);
2832 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2834 String_val(Field(formItem
, 1)),
2835 string_length(Field(formItem
, 1)));
2836 str2
[string_length(Field(formItem
, 1))] = 0;
2837 conn
->httpPostStrings
=
2838 curl_slist_append(conn
->httpPostStrings
, str2
);
2840 curl_formadd(&conn
->httpPostFirst
,
2841 &conn
->httpPostLast
,
2844 CURLFORM_NAMELENGTH
,
2845 string_length(Field(formItem
, 0)),
2846 CURLFORM_FILECONTENT
,
2850 else if (Is_block(Field(formItem
, 2)))
2852 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2854 String_val(Field(formItem
, 0)),
2855 string_length(Field(formItem
, 0)));
2856 str1
[string_length(Field(formItem
, 0))] = 0;
2857 conn
->httpPostStrings
=
2858 curl_slist_append(conn
->httpPostStrings
, str1
);
2860 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2862 String_val(Field(formItem
, 1)),
2863 string_length(Field(formItem
, 1)));
2864 str2
[string_length(Field(formItem
, 1))] = 0;
2865 conn
->httpPostStrings
=
2866 curl_slist_append(conn
->httpPostStrings
, str2
);
2868 contentType
= Field(formItem
, 2);
2870 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2872 String_val(Field(contentType
, 0)),
2873 string_length(Field(contentType
, 0)));
2874 str3
[string_length(Field(contentType
, 0))] = 0;
2875 conn
->httpPostStrings
=
2876 curl_slist_append(conn
->httpPostStrings
, str3
);
2878 curl_formadd(&conn
->httpPostFirst
,
2879 &conn
->httpPostLast
,
2882 CURLFORM_NAMELENGTH
,
2883 string_length(Field(formItem
, 0)),
2884 CURLFORM_FILECONTENT
,
2886 CURLFORM_CONTENTTYPE
,
2892 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2896 case 2: /* CURLFORM_FILE */
2897 if (Wosize_val(formItem
) < 3)
2899 failwith("Incorrect CURLFORM_FILE parameters");
2902 if (Is_long(Field(formItem
, 2)) &&
2903 Long_val(Field(formItem
, 2)) == 0)
2905 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2907 String_val(Field(formItem
, 0)),
2908 string_length(Field(formItem
, 0)));
2909 str1
[string_length(Field(formItem
, 0))] = 0;
2910 conn
->httpPostStrings
=
2911 curl_slist_append(conn
->httpPostStrings
, str1
);
2913 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2915 String_val(Field(formItem
, 1)),
2916 string_length(Field(formItem
, 1)));
2917 str2
[string_length(Field(formItem
, 1))] = 0;
2918 conn
->httpPostStrings
=
2919 curl_slist_append(conn
->httpPostStrings
, str2
);
2921 curl_formadd(&conn
->httpPostFirst
,
2922 &conn
->httpPostLast
,
2925 CURLFORM_NAMELENGTH
,
2926 string_length(Field(formItem
, 0)),
2931 else if (Is_block(Field(formItem
, 2)))
2933 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2935 String_val(Field(formItem
, 0)),
2936 string_length(Field(formItem
, 0)));
2937 str1
[string_length(Field(formItem
, 0))] = 0;
2938 conn
->httpPostStrings
=
2939 curl_slist_append(conn
->httpPostStrings
, str1
);
2941 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2943 String_val(Field(formItem
, 1)),
2944 string_length(Field(formItem
, 1)));
2945 str2
[string_length(Field(formItem
, 1))] = 0;
2946 conn
->httpPostStrings
=
2947 curl_slist_append(conn
->httpPostStrings
, str2
);
2949 contentType
= Field(formItem
, 2);
2951 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2953 String_val(Field(contentType
, 0)),
2954 string_length(Field(contentType
, 0)));
2955 str3
[string_length(Field(contentType
, 0))] = 0;
2956 conn
->httpPostStrings
=
2957 curl_slist_append(conn
->httpPostStrings
, str3
);
2959 curl_formadd(&conn
->httpPostFirst
,
2960 &conn
->httpPostLast
,
2963 CURLFORM_NAMELENGTH
,
2964 string_length(Field(formItem
, 0)),
2967 CURLFORM_CONTENTTYPE
,
2973 failwith("Incorrect CURLFORM_FILE parameters");
2977 case 3: /* CURLFORM_BUFFER */
2978 if (Wosize_val(formItem
) < 4)
2980 failwith("Incorrect CURLFORM_BUFFER parameters");
2983 if (Is_long(Field(formItem
, 3)) &&
2984 Long_val(Field(formItem
, 3)) == 0)
2986 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2988 String_val(Field(formItem
, 0)),
2989 string_length(Field(formItem
, 0)));
2990 str1
[string_length(Field(formItem
, 0))] = 0;
2991 conn
->httpPostStrings
=
2992 curl_slist_append(conn
->httpPostStrings
, str1
);
2994 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2996 String_val(Field(formItem
, 1)),
2997 string_length(Field(formItem
, 1)));
2998 str2
[string_length(Field(formItem
, 1))] = 0;
2999 conn
->httpPostStrings
=
3000 curl_slist_append(conn
->httpPostStrings
, str2
);
3002 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
3004 String_val(Field(formItem
, 2)),
3005 string_length(Field(formItem
, 2)));
3006 str3
[string_length(Field(formItem
, 2))] = 0;
3007 conn
->httpPostStrings
=
3008 curl_slist_append(conn
->httpPostStrings
, str3
);
3010 curl_formadd(&conn
->httpPostFirst
,
3011 &conn
->httpPostLast
,
3014 CURLFORM_NAMELENGTH
,
3015 string_length(Field(formItem
, 0)),
3020 CURLFORM_BUFFERLENGTH
,
3021 string_length(Field(formItem
, 2)),
3024 else if (Is_block(Field(formItem
, 3)))
3026 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
3028 String_val(Field(formItem
, 0)),
3029 string_length(Field(formItem
, 0)));
3030 str1
[string_length(Field(formItem
, 0))] = 0;
3031 conn
->httpPostStrings
=
3032 curl_slist_append(conn
->httpPostStrings
, str1
);
3034 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
3036 String_val(Field(formItem
, 1)),
3037 string_length(Field(formItem
, 1)));
3038 str2
[string_length(Field(formItem
, 1))] = 0;
3039 conn
->httpPostStrings
=
3040 curl_slist_append(conn
->httpPostStrings
, str2
);
3042 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
3044 String_val(Field(formItem
, 2)),
3045 string_length(Field(formItem
, 2)));
3046 str3
[string_length(Field(formItem
, 2))] = 0;
3047 conn
->httpPostStrings
=
3048 curl_slist_append(conn
->httpPostStrings
, str3
);
3050 contentType
= Field(formItem
, 3);
3052 str4
= (char *)malloc(string_length(Field(contentType
, 0))+1);
3054 String_val(Field(contentType
, 0)),
3055 string_length(Field(contentType
, 0)));
3056 str4
[string_length(Field(contentType
, 0))] = 0;
3057 conn
->httpPostStrings
=
3058 curl_slist_append(conn
->httpPostStrings
, str4
);
3060 curl_formadd(&conn
->httpPostFirst
,
3061 &conn
->httpPostLast
,
3064 CURLFORM_NAMELENGTH
,
3065 string_length(Field(formItem
, 0)),
3070 CURLFORM_BUFFERLENGTH
,
3071 string_length(Field(formItem
, 2)),
3072 CURLFORM_CONTENTTYPE
,
3078 failwith("Incorrect CURLFORM_BUFFER parameters");
3083 listIter
= Field(listIter
, 1);
3086 result
= curl_easy_setopt(conn
->connection
,
3088 conn
->httpPostFirst
);
3090 if (result
!= CURLE_OK
)
3091 raiseError(conn
, result
);
3096 static void handleSSLCert(Connection
*conn
, value option
)
3099 CURLcode result
= CURLE_OK
;
3101 Store_field(conn
->ocamlValues
, OcamlSSLCert
, option
);
3103 if (conn
->sslCert
!= NULL
)
3104 free(conn
->sslCert
);
3106 conn
->sslCert
= strdup(String_val(option
));
3108 result
= curl_easy_setopt(conn
->connection
,
3112 if (result
!= CURLE_OK
)
3113 raiseError(conn
, result
);
3118 static void handleSSLCertType(Connection
*conn
, value option
)
3121 CURLcode result
= CURLE_OK
;
3123 Store_field(conn
->ocamlValues
, OcamlSSLCertType
, option
);
3125 if (conn
->sslCertType
!= NULL
)
3126 free(conn
->sslCertType
);
3128 conn
->sslCertType
= strdup(String_val(option
));
3130 result
= curl_easy_setopt(conn
->connection
,
3131 CURLOPT_SSLCERTTYPE
,
3134 if (result
!= CURLE_OK
)
3135 raiseError(conn
, result
);
3140 static void handleSSLCertPasswd(Connection
*conn
, value option
)
3143 CURLcode result
= CURLE_OK
;
3145 Store_field(conn
->ocamlValues
, OcamlSSLCertPasswd
, option
);
3147 if (conn
->sslCertPasswd
!= NULL
)
3148 free(conn
->sslCertPasswd
);
3150 conn
->sslCertPasswd
= strdup(String_val(option
));
3152 result
= curl_easy_setopt(conn
->connection
,
3153 CURLOPT_SSLCERTPASSWD
,
3154 conn
->sslCertPasswd
);
3156 if (result
!= CURLE_OK
)
3157 raiseError(conn
, result
);
3162 static void handleSSLKey(Connection
*conn
, value option
)
3165 CURLcode result
= CURLE_OK
;
3167 Store_field(conn
->ocamlValues
, OcamlSSLKey
, option
);
3169 if (conn
->sslKey
!= NULL
)
3172 conn
->sslKey
= strdup(String_val(option
));
3174 result
= curl_easy_setopt(conn
->connection
,
3178 if (result
!= CURLE_OK
)
3179 raiseError(conn
, result
);
3184 static void handleSSLKeyType(Connection
*conn
, value option
)
3187 CURLcode result
= CURLE_OK
;
3189 Store_field(conn
->ocamlValues
, OcamlSSLKeyType
, option
);
3191 if (conn
->sslKeyType
!= NULL
)
3192 free(conn
->sslKeyType
);
3194 conn
->sslKeyType
= strdup(String_val(option
));
3196 result
= curl_easy_setopt(conn
->connection
,
3200 if (result
!= CURLE_OK
)
3201 raiseError(conn
, result
);
3206 static void handleSSLKeyPasswd(Connection
*conn
, value option
)
3209 CURLcode result
= CURLE_OK
;
3211 Store_field(conn
->ocamlValues
, OcamlSSLKeyPasswd
, option
);
3213 if (conn
->sslKeyPasswd
!= NULL
)
3214 free(conn
->sslKeyPasswd
);
3216 conn
->sslKeyPasswd
= strdup(String_val(option
));
3218 result
= curl_easy_setopt(conn
->connection
,
3219 CURLOPT_SSLKEYPASSWD
,
3220 conn
->sslKeyPasswd
);
3222 if (result
!= CURLE_OK
)
3223 raiseError(conn
, result
);
3228 static void handleSSLEngine(Connection
*conn
, value option
)
3231 CURLcode result
= CURLE_OK
;
3233 Store_field(conn
->ocamlValues
, OcamlSSLEngine
, option
);
3235 if (conn
->sslEngine
!= NULL
)
3236 free(conn
->sslEngine
);
3238 conn
->sslEngine
= strdup(String_val(option
));
3240 result
= curl_easy_setopt(conn
->connection
,
3244 if (result
!= CURLE_OK
)
3245 raiseError(conn
, result
);
3250 static void handleSSLEngineDefault(Connection
*conn
, value option
)
3253 CURLcode result
= CURLE_OK
;
3255 result
= curl_easy_setopt(conn
->connection
,
3256 CURLOPT_SSLENGINE_DEFAULT
,
3259 if (result
!= CURLE_OK
)
3260 raiseError(conn
, result
);
3265 static void handleCRLF(Connection
*conn
, value option
)
3268 CURLcode result
= CURLE_OK
;
3270 result
= curl_easy_setopt(conn
->connection
,
3274 if (result
!= CURLE_OK
)
3275 raiseError(conn
, result
);
3280 static void handleQuote(Connection
*conn
, value option
)
3283 CAMLlocal1(listIter
);
3284 CURLcode result
= CURLE_OK
;
3286 Store_field(conn
->ocamlValues
, OcamlQuote
, option
);
3288 free_curl_slist(conn
->quote
);
3293 while (!Is_long(listIter
))
3295 conn
->quote
= curl_slist_append(conn
->quote
, String_val(Field(listIter
, 0)));
3297 listIter
= Field(listIter
, 1);
3300 result
= curl_easy_setopt(conn
->connection
,
3304 if (result
!= CURLE_OK
)
3305 raiseError(conn
, result
);
3310 static void handlePostQuote(Connection
*conn
, value option
)
3313 CAMLlocal1(listIter
);
3314 CURLcode result
= CURLE_OK
;
3316 Store_field(conn
->ocamlValues
, OcamlPostQuote
, option
);
3318 free_curl_slist(conn
->postQuote
);
3319 conn
->postQuote
= NULL
;
3323 while (!Is_long(listIter
))
3325 conn
->postQuote
= curl_slist_append(conn
->postQuote
, String_val(Field(listIter
, 0)));
3327 listIter
= Field(listIter
, 1);
3330 result
= curl_easy_setopt(conn
->connection
,
3334 if (result
!= CURLE_OK
)
3335 raiseError(conn
, result
);
3340 static void handleHeaderFunction(Connection
*conn
, value option
)
3343 CURLcode result
= CURLE_OK
;
3345 if (Tag_val(option
) == Closure_tag
)
3346 Store_field(conn
->ocamlValues
, OcamlHeaderCallback
, option
);
3348 failwith("Not a proper closure");
3350 result
= curl_easy_setopt(conn
->connection
,
3351 CURLOPT_HEADERFUNCTION
,
3354 if (result
!= CURLE_OK
)
3355 raiseError(conn
, result
);
3357 result
= curl_easy_setopt(conn
->connection
,
3358 CURLOPT_WRITEHEADER
,
3361 if (result
!= CURLE_OK
)
3362 raiseError(conn
, result
);
3367 static void handleCookieFile(Connection
*conn
, value option
)
3370 CURLcode result
= CURLE_OK
;
3372 Store_field(conn
->ocamlValues
, OcamlCookieFile
, option
);
3374 if (conn
->cookieFile
!= NULL
)
3375 free(conn
->cookieFile
);
3377 conn
->cookieFile
= strdup(String_val(option
));
3379 result
= curl_easy_setopt(conn
->connection
,
3383 if (result
!= CURLE_OK
)
3384 raiseError(conn
, result
);
3389 static void handleSSLVersion(Connection
*conn
, value option
)
3392 CURLcode result
= CURLE_OK
;
3394 result
= curl_easy_setopt(conn
->connection
,
3398 if (result
!= CURLE_OK
)
3399 raiseError(conn
, result
);
3404 static void handleTimeCondition(Connection
*conn
, value option
)
3407 CURLcode result
= CURLE_OK
;
3408 int timecond
= CURL_TIMECOND_NONE
;
3410 switch (Long_val(option
))
3412 case 0: timecond
= CURL_TIMECOND_NONE
; break;
3413 case 1: timecond
= CURL_TIMECOND_IFMODSINCE
; break;
3414 case 2: timecond
= CURL_TIMECOND_IFUNMODSINCE
; break;
3415 case 3: timecond
= CURL_TIMECOND_LASTMOD
; break;
3417 failwith("Invalid TIMECOND Option");
3421 result
= curl_easy_setopt(conn
->connection
, CURLOPT_TIMECONDITION
, timecond
);
3423 if (result
!= CURLE_OK
)
3424 raiseError(conn
, result
);
3429 static void handleTimeValue(Connection
*conn
, value option
)
3432 CURLcode result
= CURLE_OK
;
3434 result
= curl_easy_setopt(conn
->connection
,
3438 if (result
!= CURLE_OK
)
3439 raiseError(conn
, result
);
3444 static void handleCustomRequest(Connection
*conn
, value option
)
3447 CURLcode result
= CURLE_OK
;
3449 Store_field(conn
->ocamlValues
, OcamlCustomRequest
, option
);
3451 if (conn
->customRequest
!= NULL
)
3452 free(conn
->customRequest
);
3454 conn
->customRequest
= strdup(String_val(option
));
3456 result
= curl_easy_setopt(conn
->connection
,
3457 CURLOPT_CUSTOMREQUEST
,
3458 conn
->customRequest
);
3460 if (result
!= CURLE_OK
)
3461 raiseError(conn
, result
);
3466 static void handleInterface(Connection
*conn
, value option
)
3469 CURLcode result
= CURLE_OK
;
3471 Store_field(conn
->ocamlValues
, OcamlInterface
, option
);
3473 if (conn
->interface_
!= NULL
)
3474 free(conn
->interface_
);
3476 conn
->interface_
= strdup(String_val(option
));
3478 result
= curl_easy_setopt(conn
->connection
,
3482 if (result
!= CURLE_OK
)
3483 raiseError(conn
, result
);
3488 static void handleKRB4Level(Connection
*conn
, value option
)
3491 CURLcode result
= CURLE_OK
;
3493 switch (Long_val(option
))
3495 case 0: /* KRB4_NONE */
3496 result
= curl_easy_setopt(conn
->connection
,
3501 case 1: /* KRB4_CLEAR */
3502 result
= curl_easy_setopt(conn
->connection
,
3507 case 2: /* KRB4_SAFE */
3508 result
= curl_easy_setopt(conn
->connection
,
3513 case 3: /* KRB4_CONFIDENTIAL */
3514 result
= curl_easy_setopt(conn
->connection
,
3519 case 4: /* KRB4_PRIVATE */
3520 result
= curl_easy_setopt(conn
->connection
,
3526 failwith("Invalid KRB4 Option");
3530 if (result
!= CURLE_OK
)
3531 raiseError(conn
, result
);
3536 static void handleProgressFunction(Connection
*conn
, value option
)
3539 CURLcode result
= CURLE_OK
;
3541 if (Tag_val(option
) == Closure_tag
)
3542 Store_field(conn
->ocamlValues
, OcamlProgressCallback
, option
);
3544 failwith("Not a proper closure");
3546 result
= curl_easy_setopt(conn
->connection
,
3547 CURLOPT_PROGRESSFUNCTION
,
3549 if (result
!= CURLE_OK
)
3550 raiseError(conn
, result
);
3552 result
= curl_easy_setopt(conn
->connection
,
3553 CURLOPT_PROGRESSDATA
,
3556 if (result
!= CURLE_OK
)
3557 raiseError(conn
, result
);
3562 static void handleSSLVerifyPeer(Connection
*conn
, value option
)
3565 CURLcode result
= CURLE_OK
;
3567 result
= curl_easy_setopt(conn
->connection
,
3568 CURLOPT_SSL_VERIFYPEER
,
3571 if (result
!= CURLE_OK
)
3572 raiseError(conn
, result
);
3577 static void handleCAInfo(Connection
*conn
, value option
)
3580 CURLcode result
= CURLE_OK
;
3582 Store_field(conn
->ocamlValues
, OcamlCAInfo
, option
);
3584 if (conn
->caInfo
!= NULL
)
3587 conn
->caInfo
= strdup(String_val(option
));
3589 result
= curl_easy_setopt(conn
->connection
,
3593 if (result
!= CURLE_OK
)
3594 raiseError(conn
, result
);
3599 static void handleCAPath(Connection
*conn
, value option
)
3602 CURLcode result
= CURLE_OK
;
3604 Store_field(conn
->ocamlValues
, OcamlCAPath
, option
);
3606 if (conn
->caPath
!= NULL
)
3609 conn
->caPath
= strdup(String_val(option
));
3611 result
= curl_easy_setopt(conn
->connection
,
3615 if (result
!= CURLE_OK
)
3616 raiseError(conn
, result
);
3621 static void handleFileTime(Connection
*conn
, value option
)
3624 CURLcode result
= CURLE_OK
;
3626 result
= curl_easy_setopt(conn
->connection
,
3630 if (result
!= CURLE_OK
)
3631 raiseError(conn
, result
);
3636 static void handleMaxRedirs(Connection
*conn
, value option
)
3639 CURLcode result
= CURLE_OK
;
3641 result
= curl_easy_setopt(conn
->connection
,
3645 if (result
!= CURLE_OK
)
3646 raiseError(conn
, result
);
3651 static void handleMaxConnects(Connection
*conn
, value option
)
3654 CURLcode result
= CURLE_OK
;
3656 result
= curl_easy_setopt(conn
->connection
,
3657 CURLOPT_MAXCONNECTS
,
3660 if (result
!= CURLE_OK
)
3661 raiseError(conn
, result
);
3666 static void handleClosePolicy(Connection
*conn
, value option
)
3669 CURLcode result
= CURLE_OK
;
3671 switch (Long_val(option
))
3673 case 0: /* CLOSEPOLICY_OLDEST */
3674 result
= curl_easy_setopt(conn
->connection
,
3675 CURLOPT_CLOSEPOLICY
,
3676 CURLCLOSEPOLICY_OLDEST
);
3679 case 1: /* CLOSEPOLICY_LEAST_RECENTLY_USED */
3680 result
= curl_easy_setopt(conn
->connection
,
3681 CURLOPT_CLOSEPOLICY
,
3682 CURLCLOSEPOLICY_LEAST_RECENTLY_USED
);
3686 failwith("Invalid CLOSEPOLICY Option");
3690 if (result
!= CURLE_OK
)
3691 raiseError(conn
, result
);
3696 static void handleFreshConnect(Connection
*conn
, value option
)
3699 CURLcode result
= CURLE_OK
;
3701 result
= curl_easy_setopt(conn
->connection
,
3702 CURLOPT_FRESH_CONNECT
,
3705 if (result
!= CURLE_OK
)
3706 raiseError(conn
, result
);
3711 static void handleForbidReuse(Connection
*conn
, value option
)
3714 CURLcode result
= CURLE_OK
;
3716 result
= curl_easy_setopt(conn
->connection
,
3717 CURLOPT_FORBID_REUSE
,
3720 if (result
!= CURLE_OK
)
3721 raiseError(conn
, result
);
3726 static void handleRandomFile(Connection
*conn
, value option
)
3729 CURLcode result
= CURLE_OK
;
3731 Store_field(conn
->ocamlValues
, OcamlRandomFile
, option
);
3733 if (conn
->randomFile
!= NULL
)
3734 free(conn
->randomFile
);
3736 conn
->randomFile
= strdup(String_val(option
));
3738 result
= curl_easy_setopt(conn
->connection
,
3739 CURLOPT_RANDOM_FILE
,
3742 if (result
!= CURLE_OK
)
3743 raiseError(conn
, result
);
3748 static void handleEGDSocket(Connection
*conn
, value option
)
3751 CURLcode result
= CURLE_OK
;
3753 Store_field(conn
->ocamlValues
, OcamlEGDSocket
, option
);
3755 if (conn
->egdSocket
!= NULL
)
3756 free(conn
->egdSocket
);
3758 conn
->egdSocket
= strdup(String_val(option
));
3760 result
= curl_easy_setopt(conn
->connection
,
3764 if (result
!= CURLE_OK
)
3765 raiseError(conn
, result
);
3770 static void handleConnectTimeout(Connection
*conn
, value option
)
3773 CURLcode result
= CURLE_OK
;
3775 result
= curl_easy_setopt(conn
->connection
,
3776 CURLOPT_CONNECTTIMEOUT
,
3779 if (result
!= CURLE_OK
)
3780 raiseError(conn
, result
);
3785 static void handleHTTPGet(Connection
*conn
, value option
)
3788 CURLcode result
= CURLE_OK
;
3790 result
= curl_easy_setopt(conn
->connection
,
3794 if (result
!= CURLE_OK
)
3795 raiseError(conn
, result
);
3800 static void handleSSLVerifyHost(Connection
*conn
, value option
)
3803 CURLcode result
= CURLE_OK
;
3805 switch (Long_val(option
))
3807 case 0: /* SSLVERIFYHOST_NONE */
3808 case 1: /* SSLVERIFYHOST_EXISTENCE */
3809 case 2: /* SSLVERIFYHOST_HOSTNAME */
3810 result
= curl_easy_setopt(conn
->connection
,
3811 CURLOPT_SSL_VERIFYHOST
,
3812 /* map EXISTENCE to HOSTNAME */
3813 Long_val(option
) == 0 ? 0 : 2);
3817 failwith("Invalid SSLVERIFYHOST Option");
3821 if (result
!= CURLE_OK
)
3822 raiseError(conn
, result
);
3827 static void handleCookieJar(Connection
*conn
, value option
)
3830 CURLcode result
= CURLE_OK
;
3832 Store_field(conn
->ocamlValues
, OcamlCookieJar
, option
);
3834 if (conn
->cookieJar
!= NULL
)
3835 free(conn
->cookieJar
);
3837 conn
->cookieJar
= strdup(String_val(option
));
3839 result
= curl_easy_setopt(conn
->connection
,
3843 if (result
!= CURLE_OK
)
3844 raiseError(conn
, result
);
3849 static void handleSSLCipherList(Connection
*conn
, value option
)
3852 CURLcode result
= CURLE_OK
;
3854 Store_field(conn
->ocamlValues
, OcamlSSLCipherList
, option
);
3856 if (conn
->sslCipherList
!= NULL
)
3857 free(conn
->sslCipherList
);
3859 conn
->sslCipherList
= strdup(String_val(option
));
3861 result
= curl_easy_setopt(conn
->connection
,
3862 CURLOPT_SSL_CIPHER_LIST
,
3863 conn
->sslCipherList
);
3865 if (result
!= CURLE_OK
)
3866 raiseError(conn
, result
);
3871 static void handleHTTPVersion(Connection
*conn
, value option
)
3874 CURLcode result
= CURLE_OK
;
3876 switch (Long_val(option
))
3878 case 0: /* HTTP_VERSION_NONE */
3879 result
= curl_easy_setopt(conn
->connection
,
3880 CURLOPT_HTTP_VERSION
,
3881 CURL_HTTP_VERSION_NONE
);
3884 case 1: /* HTTP_VERSION_1_0 */
3885 result
= curl_easy_setopt(conn
->connection
,
3886 CURLOPT_HTTP_VERSION
,
3887 CURL_HTTP_VERSION_1_0
);
3890 case 2: /* HTTP_VERSION_1_1 */
3891 result
= curl_easy_setopt(conn
->connection
,
3892 CURLOPT_HTTP_VERSION
,
3893 CURL_HTTP_VERSION_1_1
);
3897 failwith("Invalid HTTP_VERSION Option");
3901 if (result
!= CURLE_OK
)
3902 raiseError(conn
, result
);
3907 static void handleFTPUseEPSV(Connection
*conn
, value option
)
3910 CURLcode result
= CURLE_OK
;
3912 result
= curl_easy_setopt(conn
->connection
,
3913 CURLOPT_FTP_USE_EPSV
,
3916 if (result
!= CURLE_OK
)
3917 raiseError(conn
, result
);
3922 static void handleDNSCacheTimeout(Connection
*conn
, value option
)
3925 CURLcode result
= CURLE_OK
;
3927 result
= curl_easy_setopt(conn
->connection
,
3928 CURLOPT_DNS_CACHE_TIMEOUT
,
3931 if (result
!= CURLE_OK
)
3932 raiseError(conn
, result
);
3937 static void handleDNSUseGlobalCache(Connection
*conn
, value option
)
3940 CURLcode result
= CURLE_OK
;
3942 result
= curl_easy_setopt(conn
->connection
,
3943 CURLOPT_DNS_USE_GLOBAL_CACHE
,
3946 if (result
!= CURLE_OK
)
3947 raiseError(conn
, result
);
3952 static void handleDebugFunction(Connection
*conn
, value option
)
3955 CURLcode result
= CURLE_OK
;
3957 if (Tag_val(option
) == Closure_tag
)
3958 Store_field(conn
->ocamlValues
, OcamlDebugCallback
, option
);
3960 failwith("Not a proper closure");
3962 result
= curl_easy_setopt(conn
->connection
,
3963 CURLOPT_DEBUGFUNCTION
,
3965 if (result
!= CURLE_OK
)
3966 raiseError(conn
, result
);
3968 result
= curl_easy_setopt(conn
->connection
,
3972 if (result
!= CURLE_OK
)
3973 raiseError(conn
, result
);
3978 static void handlePrivate(Connection
*conn
, value option
)
3980 #if HAVE_DECL_CURLOPT_PRIVATE
3982 CURLcode result
= CURLE_OK
;
3984 Store_field(conn
->ocamlValues
, OcamlPrivate
, option
);
3986 if (conn
->private != NULL
)
3987 free(conn
->private);
3989 conn
->private = strdup(String_val(option
));
3991 result
= curl_easy_setopt(conn
->connection
,
3995 if (result
!= CURLE_OK
)
3996 raiseError(conn
, result
);
4000 #pragma message("libcurl does not implement CURLOPT_PRIVATE")
4001 failwith("libcurl does not implement CURLOPT_PRIVATE");
4005 static void handleHTTP200Aliases(Connection
*conn
, value option
)
4007 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
4009 CAMLlocal1(listIter
);
4010 CURLcode result
= CURLE_OK
;
4012 Store_field(conn
->ocamlValues
, OcamlHTTP200Aliases
, option
);
4014 free_curl_slist(conn
->http200Aliases
);
4015 conn
->http200Aliases
= NULL
;
4019 while (!Is_long(listIter
))
4021 conn
->http200Aliases
= curl_slist_append(conn
->http200Aliases
, String_val(Field(listIter
, 0)));
4023 listIter
= Field(listIter
, 1);
4026 result
= curl_easy_setopt(conn
->connection
,
4027 CURLOPT_HTTP200ALIASES
,
4028 conn
->http200Aliases
);
4030 if (result
!= CURLE_OK
)
4031 raiseError(conn
, result
);
4035 #pragma message("libcurl does not implement CURLOPT_HTTP200ALIASES")
4036 failwith("libcurl does not implement CURLOPT_HTTP200ALIASES");
4040 static void handleUnrestrictedAuth(Connection
*conn
, value option
)
4042 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
4044 CURLcode result
= CURLE_OK
;
4046 result
= curl_easy_setopt(conn
->connection
,
4047 CURLOPT_UNRESTRICTED_AUTH
,
4050 if (result
!= CURLE_OK
)
4051 raiseError(conn
, result
);
4055 #pragma message("libcurl does not implement CURLOPT_UNRESTRICTED_AUTH")
4056 failwith("libcurl does not implement CURLOPT_UNRESTRICTED_AUTH");
4060 static void handleFTPUseEPRT(Connection
*conn
, value option
)
4062 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
4064 CURLcode result
= CURLE_OK
;
4066 result
= curl_easy_setopt(conn
->connection
,
4067 CURLOPT_FTP_USE_EPRT
,
4070 if (result
!= CURLE_OK
)
4071 raiseError(conn
, result
);
4075 #pragma message("libcurl does not implement CURLOPT_FTP_USE_EPRT")
4076 failwith("libcurl does not implement CURLOPT_FTP_USE_EPRT");
4080 static void handleHTTPAuth(Connection
*conn
, value option
)
4082 #if HAVE_DECL_CURLOPT_HTTPAUTH
4084 CAMLlocal1(listIter
);
4085 CURLcode result
= CURLE_OK
;
4086 long auth
= CURLAUTH_NONE
;
4090 while (!Is_long(listIter
))
4092 switch (Long_val(Field(listIter
, 0)))
4094 case 0: /* CURLAUTH_BASIC */
4095 auth
|= CURLAUTH_BASIC
;
4098 case 1: /* CURLAUTH_DIGEST */
4099 auth
|= CURLAUTH_DIGEST
;
4102 case 2: /* CURLAUTH_GSSNEGOTIATE */
4103 auth
|= CURLAUTH_GSSNEGOTIATE
;
4106 case 3: /* CURLAUTH_NTLM */
4107 auth
|= CURLAUTH_NTLM
;
4110 case 4: /* CURLAUTH_ANY */
4111 auth
|= CURLAUTH_ANY
;
4114 case 5: /* CURLAUTH_ANYSAFE */
4115 auth
|= CURLAUTH_ANYSAFE
;
4119 failwith("Invalid HTTPAUTH Value");
4123 listIter
= Field(listIter
, 1);
4126 result
= curl_easy_setopt(conn
->connection
,
4130 if (result
!= CURLE_OK
)
4131 raiseError(conn
, result
);
4135 #pragma message("libcurl does not implement CURLOPT_HTTPAUTH")
4136 failwith("libcurl does not implement CURLOPT_HTTPAUTH");
4140 static void handleFTPCreateMissingDirs(Connection
*conn
, value option
)
4142 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
4144 CURLcode result
= CURLE_OK
;
4146 result
= curl_easy_setopt(conn
->connection
,
4147 CURLOPT_FTP_CREATE_MISSING_DIRS
,
4150 if (result
!= CURLE_OK
)
4151 raiseError(conn
, result
);
4155 #pragma message("libcurl does not implement CURLOPT_FTP_CREATE_MISSING_DIRS")
4156 failwith("libcurl does not implement CURLOPT_FTP_CREATE_MISSING_DIRS");
4160 static void handleProxyAuth(Connection
*conn
, value option
)
4162 #if HAVE_DECL_CURLOPT_PROXYAUTH
4164 CAMLlocal1(listIter
);
4165 CURLcode result
= CURLE_OK
;
4166 long auth
= CURLAUTH_NONE
;
4170 while (!Is_long(listIter
))
4172 switch (Long_val(Field(listIter
, 0)))
4174 case 0: /* CURLAUTH_BASIC */
4175 auth
|= CURLAUTH_BASIC
;
4178 case 1: /* CURLAUTH_DIGEST */
4179 auth
|= CURLAUTH_DIGEST
;
4182 case 2: /* CURLAUTH_GSSNEGOTIATE */
4183 auth
|= CURLAUTH_GSSNEGOTIATE
;
4186 case 3: /* CURLAUTH_NTLM */
4187 auth
|= CURLAUTH_NTLM
;
4190 case 4: /* CURLAUTH_ANY */
4191 auth
|= CURLAUTH_ANY
;
4194 case 5: /* CURLAUTH_ANYSAFE */
4195 auth
|= CURLAUTH_ANYSAFE
;
4199 failwith("Invalid HTTPAUTH Value");
4203 listIter
= Field(listIter
, 1);
4206 result
= curl_easy_setopt(conn
->connection
,
4210 if (result
!= CURLE_OK
)
4211 raiseError(conn
, result
);
4215 #pragma message("libcurl does not implement CURLOPT_PROXYAUTH")
4216 failwith("libcurl does not implement CURLOPT_PROXYAUTH");
4220 static void handleFTPResponseTimeout(Connection
*conn
, value option
)
4222 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
4224 CURLcode result
= CURLE_OK
;
4226 result
= curl_easy_setopt(conn
->connection
,
4227 CURLOPT_FTP_RESPONSE_TIMEOUT
,
4230 if (result
!= CURLE_OK
)
4231 raiseError(conn
, result
);
4235 #pragma message("libcurl does not implement CURLOPT_FTP_RESPONSE_TIMEOUT")
4236 failwith("libcurl does not implement CURLOPT_FTP_RESPONSE_TIMEOUT");
4240 static void handleIPResolve(Connection
*conn
, value option
)
4242 #if HAVE_DECL_CURLOPT_IPRESOLVE
4244 CURLcode result
= CURLE_OK
;
4246 switch (Long_val(option
))
4248 case 0: /* CURL_IPRESOLVE_WHATEVER */
4249 result
= curl_easy_setopt(conn
->connection
,
4251 CURL_IPRESOLVE_WHATEVER
);
4254 case 1: /* CURL_IPRESOLVE_V4 */
4255 result
= curl_easy_setopt(conn
->connection
,
4260 case 2: /* CURL_IPRESOLVE_V6 */
4261 result
= curl_easy_setopt(conn
->connection
,
4267 failwith("Invalid IPRESOLVE Value");
4271 if (result
!= CURLE_OK
)
4272 raiseError(conn
, result
);
4276 #pragma message("libcurl does not implement CURLOPT_IPRESOLVE")
4277 failwith("libcurl does not implement CURLOPT_IPRESOLVE");
4281 static void handleMaxFileSize(Connection
*conn
, value option
)
4283 #if HAVE_DECL_CURLOPT_MAXFILESIZE
4285 CURLcode result
= CURLE_OK
;
4287 result
= curl_easy_setopt(conn
->connection
,
4288 CURLOPT_MAXFILESIZE
,
4291 if (result
!= CURLE_OK
)
4292 raiseError(conn
, result
);
4296 #pragma message("libcurl does not implement CURLOPT_MAXFILESIZE")
4297 failwith("libcurl does not implement CURLOPT_MAXFILESIZE");
4301 static void handleInFileSizeLarge(Connection
*conn
, value option
)
4303 #if HAVE_DECL_CURLOPT_INFILESIZE_LARGE
4305 CURLcode result
= CURLE_OK
;
4307 result
= curl_easy_setopt(conn
->connection
,
4308 CURLOPT_INFILESIZE_LARGE
,
4311 if (result
!= CURLE_OK
)
4312 raiseError(conn
, result
);
4316 #pragma message("libcurl does not implement CURLOPT_INFILESIZE_LARGE")
4317 failwith("libcurl does not implement CURLOPT_INFILESIZE_LARGE");
4321 static void handleResumeFromLarge(Connection
*conn
, value option
)
4323 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
4325 CURLcode result
= CURLE_OK
;
4327 result
= curl_easy_setopt(conn
->connection
,
4328 CURLOPT_RESUME_FROM_LARGE
,
4331 if (result
!= CURLE_OK
)
4332 raiseError(conn
, result
);
4336 #pragma message("libcurl does not implement CURLOPT_RESUME_FROM_LARGE")
4337 failwith("libcurl does not implement CURLOPT_RESUME_FROM_LARGE");
4341 static void handleMaxFileSizeLarge(Connection
*conn
, value option
)
4343 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
4345 CURLcode result
= CURLE_OK
;
4347 result
= curl_easy_setopt(conn
->connection
,
4348 CURLOPT_MAXFILESIZE_LARGE
,
4351 if (result
!= CURLE_OK
)
4352 raiseError(conn
, result
);
4356 #pragma message("libcurl does not implement CURLOPT_MAXFILESIZE_LARGE")
4357 failwith("libcurl does not implement CURLOPT_MAXFILESIZE_LARGE");
4361 static void handleNETRCFile(Connection
*conn
, value option
)
4363 #if HAVE_DECL_CURLOPT_NETRC_FILE
4365 CURLcode result
= CURLE_OK
;
4367 Store_field(conn
->ocamlValues
, OcamlNETRCFile
, option
);
4369 if (conn
->netrcFile
!= NULL
)
4370 free(conn
->netrcFile
);
4372 conn
->netrcFile
= strdup(String_val(option
));
4374 result
= curl_easy_setopt(conn
->connection
,
4378 if (result
!= CURLE_OK
)
4379 raiseError(conn
, result
);
4383 #pragma message("libcurl does not implement CURLOPT_NETRC_FILE")
4384 failwith("libcurl does not implement CURLOPT_NETRC_FILE");
4388 static void handleFTPSSL(Connection
*conn
, value option
)
4390 #if HAVE_DECL_CURLOPT_FTP_SSL
4392 CURLcode result
= CURLE_OK
;
4394 switch (Long_val(option
))
4396 case 0: /* CURLFTPSSL_NONE */
4397 result
= curl_easy_setopt(conn
->connection
,
4402 case 1: /* CURLFTPSSL_TRY */
4403 result
= curl_easy_setopt(conn
->connection
,
4408 case 2: /* CURLFTPSSL_CONTROL */
4409 result
= curl_easy_setopt(conn
->connection
,
4411 CURLFTPSSL_CONTROL
);
4414 case 3: /* CURLFTPSSL_ALL */
4415 result
= curl_easy_setopt(conn
->connection
,
4421 failwith("Invalid FTP_SSL Value");
4425 if (result
!= CURLE_OK
)
4426 raiseError(conn
, result
);
4430 #pragma message("libcurl does not implement CURLOPT_FTP_SSL")
4431 failwith("libcurl does not implement CURLOPT_FTP_SSL");
4435 static void handlePostFieldSizeLarge(Connection
*conn
, value option
)
4437 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
4439 CURLcode result
= CURLE_OK
;
4441 result
= curl_easy_setopt(conn
->connection
,
4442 CURLOPT_POSTFIELDSIZE_LARGE
,
4445 if (result
!= CURLE_OK
)
4446 raiseError(conn
, result
);
4450 #pragma message("libcurl does not implement CURLOPT_POSTFIELDSIZE_LARGE")
4451 failwith("libcurl does not implement CURLOPT_POSTFIELDSIZE_LARGE");
4455 static void handleTCPNoDelay(Connection
*conn
, value option
)
4457 #if HAVE_DECL_CURLOPT_TCP_NODELAY
4459 CURLcode result
= CURLE_OK
;
4461 result
= curl_easy_setopt(conn
->connection
,
4462 CURLOPT_TCP_NODELAY
,
4465 if (result
!= CURLE_OK
)
4466 raiseError(conn
, result
);
4470 #pragma message("libcurl does not implement CURLOPT_TCP_NODELAY")
4471 failwith("libcurl does not implement CURLOPT_TCP_NODELAY");
4475 static void handleFTPSSLAuth(Connection
*conn
, value option
)
4477 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
4479 CURLcode result
= CURLE_OK
;
4481 switch (Long_val(option
))
4483 case 0: /* CURLFTPAUTH_DEFAULT */
4484 result
= curl_easy_setopt(conn
->connection
,
4486 CURLFTPAUTH_DEFAULT
);
4489 case 1: /* CURLFTPAUTH_SSL */
4490 result
= curl_easy_setopt(conn
->connection
,
4495 case 2: /* CURLFTPAUTH_TLS */
4496 result
= curl_easy_setopt(conn
->connection
,
4502 failwith("Invalid FTPSSLAUTH value");
4506 if (result
!= CURLE_OK
)
4507 raiseError(conn
, result
);
4511 #pragma message("libcurl does not implement CURLOPT_FTPSSLAUTH")
4512 failwith("libcurl does not implement CURLOPT_FTPSSLAUTH");
4516 static void handleIOCTLFunction(Connection
*conn
, value option
)
4518 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
4520 CURLcode result
= CURLE_OK
;
4522 if (Tag_val(option
) == Closure_tag
)
4523 Store_field(conn
->ocamlValues
, OcamlIOCTLCallback
, option
);
4525 failwith("Not a proper closure");
4527 result
= curl_easy_setopt(conn
->connection
,
4528 CURLOPT_IOCTLFUNCTION
,
4530 if (result
!= CURLE_OK
)
4531 raiseError(conn
, result
);
4533 result
= curl_easy_setopt(conn
->connection
,
4537 if (result
!= CURLE_OK
)
4538 raiseError(conn
, result
);
4542 #pragma message("libcurl does not implement CURLOPT_IOCTLFUNCTION")
4543 failwith("libcurl does not implement CURLOPT_IOCTLFUNCTION");
4547 static void handleFTPAccount(Connection
*conn
, value option
)
4549 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
4551 CURLcode result
= CURLE_OK
;
4553 Store_field(conn
->ocamlValues
, OcamlFTPAccount
, option
);
4555 if (conn
->ftpaccount
!= NULL
)
4556 free(conn
->ftpaccount
);
4558 conn
->ftpaccount
= strdup(String_val(option
));
4560 result
= curl_easy_setopt(conn
->connection
,
4561 CURLOPT_FTP_ACCOUNT
,
4564 if (result
!= CURLE_OK
)
4565 raiseError(conn
, result
);
4569 #pragma message("libcurl does not implement CURLOPT_FTP_ACCOUNT")
4570 failwith("libcurl does not implement CURLOPT_FTP_ACCOUNT");
4574 static void handleCookieList(Connection
*conn
, value option
)
4576 #if HAVE_DECL_CURLOPT_COOKIELIST
4578 CURLcode result
= CURLE_OK
;
4580 Store_field(conn
->ocamlValues
, OcamlCookieList
, option
);
4582 if (conn
->cookielist
!= NULL
)
4583 free(conn
->cookielist
);
4585 conn
->cookielist
= strdup(String_val(option
));
4587 result
= curl_easy_setopt(conn
->connection
,
4591 if (result
!= CURLE_OK
)
4592 raiseError(conn
, result
);
4596 #pragma message("libcurl does not implement CURLOPT_COOKIELIST")
4597 failwith("libcurl does not implement CURLOPT_COOKIELIST");
4601 static void handleIgnoreContentLength(Connection
*conn
, value option
)
4603 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
4605 CURLcode result
= CURLE_OK
;
4607 result
= curl_easy_setopt(conn
->connection
,
4608 CURLOPT_IGNORE_CONTENT_LENGTH
,
4611 if (result
!= CURLE_OK
)
4612 raiseError(conn
, result
);
4616 #pragma message("libcurl does not implement CURLOPT_IGNORE_CONTENT_LENGTH")
4617 failwith("libcurl does not implement CURLOPT_IGNORE_CONTENT_LENGTH");
4621 static void handleFTPSkipPASVIP(Connection
*conn
, value option
)
4623 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
4625 CURLcode result
= CURLE_OK
;
4627 result
= curl_easy_setopt(conn
->connection
,
4628 CURLOPT_FTP_SKIP_PASV_IP
,
4631 if (result
!= CURLE_OK
)
4632 raiseError(conn
, result
);
4636 #pragma message("libcurl does not implement CURLOPT_FTP_SKIP_PASV_IP")
4637 failwith("libcurl does not implement CURLOPT_FTP_SKIP_PASV_IP");
4641 static void handleFTPFileMethod(Connection
*conn
, value option
)
4643 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
4645 CURLcode result
= CURLE_OK
;
4647 switch (Long_val(option
))
4649 case 0: /* CURLFTPMETHOD_DEFAULT */
4650 result
= curl_easy_setopt(conn
->connection
,
4651 CURLOPT_FTP_FILEMETHOD
,
4652 CURLFTPMETHOD_DEFAULT
);
4655 case 1: /* CURLFTMETHOD_MULTICWD */
4656 result
= curl_easy_setopt(conn
->connection
,
4657 CURLOPT_FTP_FILEMETHOD
,
4658 CURLFTPMETHOD_MULTICWD
);
4661 case 2: /* CURLFTPMETHOD_NOCWD */
4662 result
= curl_easy_setopt(conn
->connection
,
4663 CURLOPT_FTP_FILEMETHOD
,
4664 CURLFTPMETHOD_NOCWD
);
4667 case 3: /* CURLFTPMETHOD_SINGLECWD */
4668 result
= curl_easy_setopt(conn
->connection
,
4669 CURLOPT_FTP_FILEMETHOD
,
4670 CURLFTPMETHOD_SINGLECWD
);
4673 failwith("Invalid FTP_FILEMETHOD value");
4677 if (result
!= CURLE_OK
)
4678 raiseError(conn
, result
);
4682 #pragma message("libcurl does not implement CURLOPT_FTP_FILEMETHOD")
4683 failwith("libcurl does not implement CURLOPT_FTP_FILEMETHOD");
4687 static void handleLocalPort(Connection
*conn
, value option
)
4689 #if HAVE_DECL_CURLOPT_LOCALPORT
4691 CURLcode result
= CURLE_OK
;
4693 result
= curl_easy_setopt(conn
->connection
,
4697 if (result
!= CURLE_OK
)
4698 raiseError(conn
, result
);
4702 #pragma message("libcurl does not implement CURLOPT_LOCALPORT")
4703 failwith("libcurl does not implement CURLOPT_LOCALPORT");
4707 static void handleLocalPortRange(Connection
*conn
, value option
)
4709 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
4711 CURLcode result
= CURLE_OK
;
4713 result
= curl_easy_setopt(conn
->connection
,
4714 CURLOPT_LOCALPORTRANGE
,
4717 if (result
!= CURLE_OK
)
4718 raiseError(conn
, result
);
4722 #pragma message("libcurl does not implement CURLOPT_LOCALPORTRANGE")
4723 failwith("libcurl does not implement CURLOPT_LOCALPORTRANGE");
4727 static void handleConnectOnly(Connection
*conn
, value option
)
4729 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
4731 CURLcode result
= CURLE_OK
;
4733 result
= curl_easy_setopt(conn
->connection
,
4734 CURLOPT_CONNECT_ONLY
,
4737 if (result
!= CURLE_OK
)
4738 raiseError(conn
, result
);
4742 #pragma message("libcurl does not implement CURLOPT_CONNECT_ONLY")
4743 failwith("libcurl does not implement CURLOPT_CONNECT_ONLY");
4747 static void handleMaxSendSpeedLarge(Connection
*conn
, value option
)
4749 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
4751 CURLcode result
= CURLE_OK
;
4753 result
= curl_easy_setopt(conn
->connection
,
4754 CURLOPT_MAX_SEND_SPEED_LARGE
,
4757 if (result
!= CURLE_OK
)
4758 raiseError(conn
, result
);
4762 #pragma message("libcurl does not implement CURLOPT_MAX_SEND_SPEED_LARGE")
4763 failwith("libcurl does not implement CURLOPT_MAX_SEND_SPEED_LARGE");
4767 static void handleMaxRecvSpeedLarge(Connection
*conn
, value option
)
4769 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
4771 CURLcode result
= CURLE_OK
;
4773 result
= curl_easy_setopt(conn
->connection
,
4774 CURLOPT_MAX_RECV_SPEED_LARGE
,
4777 if (result
!= CURLE_OK
)
4778 raiseError(conn
, result
);
4782 #pragma message("libcurl does not implement CURLOPT_MAX_RECV_SPEED_LARGE")
4783 failwith("libcurl does not implement CURLOPT_MAX_RECV_SPEED_LARGE");
4787 static void handleFTPAlternativeToUser(Connection
*conn
, value option
)
4789 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
4791 CURLcode result
= CURLE_OK
;
4793 Store_field(conn
->ocamlValues
, OcamlFTPAlternativeToUser
, option
);
4795 if (conn
->ftpAlternativeToUser
!= NULL
)
4796 free(conn
->ftpAlternativeToUser
);
4798 conn
->ftpAlternativeToUser
= strdup(String_val(option
));
4800 result
= curl_easy_setopt(conn
->connection
,
4801 CURLOPT_FTP_ALTERNATIVE_TO_USER
,
4802 conn
->ftpAlternativeToUser
);
4804 if (result
!= CURLE_OK
)
4805 raiseError(conn
, result
);
4809 #pragma message("libcurl does not implement CURLOPT_FTP_ALTERNATIVE_TO_USER")
4810 failwith("libcurl does not implement CURLOPT_FTP_ALTERNATIVE_TO_USER");
4814 static void handleSSLSessionIdCache(Connection
*conn
, value option
)
4816 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
4818 CURLcode result
= CURLE_OK
;
4820 result
= curl_easy_setopt(conn
->connection
,
4821 CURLOPT_SSL_SESSIONID_CACHE
,
4824 if (result
!= CURLE_OK
)
4825 raiseError(conn
, result
);
4829 #pragma message("libcurl does not implement CURLOPT_SSL_SESSIONID_CACHE")
4830 failwith("libcurl does not implement CURLOPT_SSL_SESSIONID_CACHE");
4834 static void handleSSHAuthTypes(Connection
*conn
, value option
)
4836 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
4838 CAMLlocal1(listIter
);
4839 CURLcode result
= CURLE_OK
;
4840 long authTypes
= CURLSSH_AUTH_NONE
;
4844 while (!Is_long(listIter
))
4846 switch (Long_val(Field(listIter
, 0)))
4848 case 0: /* CURLSSH_AUTH_ANY */
4849 authTypes
|= CURLSSH_AUTH_ANY
;
4852 case 1: /* CURLSSH_AUTH_PUBLICKEY */
4853 authTypes
|= CURLSSH_AUTH_PUBLICKEY
;
4856 case 2: /* CURLSSH_AUTH_PASSWORD */
4857 authTypes
|= CURLSSH_AUTH_PASSWORD
;
4860 case 3: /* CURLSSH_AUTH_HOST */
4861 authTypes
|= CURLSSH_AUTH_HOST
;
4864 case 4: /* CURLSSH_AUTH_KEYBOARD */
4865 authTypes
|= CURLSSH_AUTH_KEYBOARD
;
4869 failwith("Invalid CURLSSH_AUTH_TYPES Value");
4873 listIter
= Field(listIter
, 1);
4876 result
= curl_easy_setopt(conn
->connection
,
4877 CURLOPT_SSH_AUTH_TYPES
,
4880 if (result
!= CURLE_OK
)
4881 raiseError(conn
, result
);
4885 #pragma message("libcurl does not implement CURLOPT_SSH_AUTH_TYPES")
4886 failwith("libcurl does not implement CURLOPT_SSH_AUTH_TYPES");
4890 static void handleSSHPublicKeyFile(Connection
*conn
, value option
)
4892 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
4894 CURLcode result
= CURLE_OK
;
4896 Store_field(conn
->ocamlValues
, OcamlSSHPublicKeyFile
, option
);
4898 if (conn
->sshPublicKeyFile
!= NULL
)
4899 free(conn
->sshPublicKeyFile
);
4901 conn
->sshPublicKeyFile
= strdup(String_val(option
));
4903 result
= curl_easy_setopt(conn
->connection
,
4904 CURLOPT_SSH_PUBLIC_KEYFILE
,
4905 conn
->sshPublicKeyFile
);
4907 if (result
!= CURLE_OK
)
4908 raiseError(conn
, result
);
4912 #pragma message("libcurl does not implement CURLOPT_SSH_PUBLIC_KEYFILE")
4913 failwith("libcurl does not implement CURLOPT_SSH_PUBLIC_KEYFILE");
4917 static void handleSSHPrivateKeyFile(Connection
*conn
, value option
)
4919 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
4921 CURLcode result
= CURLE_OK
;
4923 Store_field(conn
->ocamlValues
, OcamlSSHPrivateKeyFile
, option
);
4925 if (conn
->sshPrivateKeyFile
!= NULL
)
4926 free(conn
->sshPrivateKeyFile
);
4928 conn
->sshPrivateKeyFile
= strdup(String_val(option
));
4930 result
= curl_easy_setopt(conn
->connection
,
4931 CURLOPT_SSH_PRIVATE_KEYFILE
,
4932 conn
->sshPrivateKeyFile
);
4934 if (result
!= CURLE_OK
)
4935 raiseError(conn
, result
);
4939 #pragma message("libcurl does not implement CURLOPT_SSH_PRIVATE_KEYFILE")
4940 failwith("libcurl does not implement CURLOPT_SSH_PRIVATE_KEYFILE");
4944 static void handleFTPSSLCCC(Connection
*conn
, value option
)
4946 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
4948 CURLcode result
= CURLE_OK
;
4950 switch (Long_val(option
))
4952 case 0: /* CURLFTPSSL_CCC_NONE */
4953 result
= curl_easy_setopt(conn
->connection
,
4954 CURLOPT_FTP_SSL_CCC
,
4955 CURLFTPSSL_CCC_NONE
);
4958 case 1: /* CURLFTPSSL_CCC_PASSIVE */
4959 result
= curl_easy_setopt(conn
->connection
,
4960 CURLOPT_FTP_SSL_CCC
,
4961 CURLFTPSSL_CCC_PASSIVE
);
4964 case 2: /* CURLFTPSSL_CCC_ACTIVE */
4965 result
= curl_easy_setopt(conn
->connection
,
4966 CURLOPT_FTP_SSL_CCC
,
4967 CURLFTPSSL_CCC_ACTIVE
);
4971 failwith("Invalid FTPSSL_CCC value");
4975 if (result
!= CURLE_OK
)
4976 raiseError(conn
, result
);
4980 #pragma message("libcurl does not implement CURLOPT_FTP_SSL_CCC")
4981 failwith("libcurl does not implement CURLOPT_FTP_SSL_CCC");
4985 static void handleTimeoutMS(Connection
*conn
, value option
)
4987 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
4989 CURLcode result
= CURLE_OK
;
4991 result
= curl_easy_setopt(conn
->connection
,
4995 if (result
!= CURLE_OK
)
4996 raiseError(conn
, result
);
5000 #pragma message("libcurl does not implement CURLOPT_TIMEOUT_MS")
5001 failwith("libcurl does not implement CURLOPT_TIMEOUT_MS");
5005 static void handleConnectTimeoutMS(Connection
*conn
, value option
)
5007 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
5009 CURLcode result
= CURLE_OK
;
5011 result
= curl_easy_setopt(conn
->connection
,
5012 CURLOPT_CONNECTTIMEOUT_MS
,
5015 if (result
!= CURLE_OK
)
5016 raiseError(conn
, result
);
5020 #pragma message("libcurl does not implement CURLOPT_CONNECTTIMEOUT_MS")
5021 failwith("libcurl does not implement CURLOPT_CONNECTTIMEOUT_MS");
5025 static void handleHTTPTransferDecoding(Connection
*conn
, value option
)
5027 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
5029 CURLcode result
= CURLE_OK
;
5031 result
= curl_easy_setopt(conn
->connection
,
5032 CURLOPT_HTTP_TRANSFER_DECODING
,
5035 if (result
!= CURLE_OK
)
5036 raiseError(conn
, result
);
5040 #pragma message("libcurl does not implement CURLOPT_HTTP_TRANSFER_DECODING")
5041 failwith("libcurl does not implement CURLOPT_HTTP_TRANSFER_DECODING");
5045 static void handleHTTPContentDecoding(Connection
*conn
, value option
)
5047 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
5049 CURLcode result
= CURLE_OK
;
5051 result
= curl_easy_setopt(conn
->connection
,
5052 CURLOPT_HTTP_CONTENT_DECODING
,
5055 if (result
!= CURLE_OK
)
5056 raiseError(conn
, result
);
5060 #pragma message("libcurl does not implement CURLOPT_HTTP_CONTENT_DECODING")
5061 failwith("libcurl does not implement CURLOPT_HTTP_CONTENT_DECODING");
5065 static void handleNewFilePerms(Connection
*conn
, value option
)
5067 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
5069 CURLcode result
= CURLE_OK
;
5071 result
= curl_easy_setopt(conn
->connection
,
5072 CURLOPT_NEW_FILE_PERMS
,
5075 if (result
!= CURLE_OK
)
5076 raiseError(conn
, result
);
5080 #pragma message("libcurl does not implement CURLOPT_NEW_FILE_PERMS")
5081 failwith("libcurl does not implement CURLOPT_NEW_FILE_PERMS");
5085 static void handleNewDirectoryPerms(Connection
*conn
, value option
)
5087 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
5089 CURLcode result
= CURLE_OK
;
5091 result
= curl_easy_setopt(conn
->connection
,
5092 CURLOPT_NEW_DIRECTORY_PERMS
,
5095 if (result
!= CURLE_OK
)
5096 raiseError(conn
, result
);
5100 #pragma message("libcurl does not implement CURLOPT_NEW_DIRECTORY_PERMS")
5101 failwith("libcurl does not implement CURLOPT_NEW_DIRECTORY_PERMS");
5105 static void handlePost301(Connection
*conn
, value option
)
5107 #if HAVE_DECL_CURLOPT_POST301
5109 CURLcode result
= CURLE_OK
;
5111 result
= curl_easy_setopt(conn
->connection
,
5115 if (result
!= CURLE_OK
)
5116 raiseError(conn
, result
);
5120 #pragma message("libcurl does not implement CURLOPT_POST301")
5121 failwith("libcurl does not implement CURLOPT_POST301");
5125 static void handleSSHHostPublicKeyMD5(Connection
*conn
, value option
)
5127 #if HAVE_DECL_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
5129 CURLcode result
= CURLE_OK
;
5131 Store_field(conn
->ocamlValues
, OcamlSSHHostPublicKeyMD5
, option
);
5133 if (conn
->sshHostPublicKeyMD5
!= NULL
)
5134 free(conn
->sshHostPublicKeyMD5
);
5136 conn
->sshHostPublicKeyMD5
= strdup(String_val(option
));
5138 result
= curl_easy_setopt(conn
->connection
,
5139 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
,
5140 conn
->sshHostPublicKeyMD5
);
5142 if (result
!= CURLE_OK
)
5143 raiseError(conn
, result
);
5147 #pragma message("libcurl does not implement CURLOPT_SSH_HOST_PUBLIC_KEY_MD5")
5148 failwith("libcurl does not implement CURLOPT_SSH_HOST_PUBLIC_KEY_MD5");
5152 static void handleCopyPostFields(Connection
*conn
, value option
)
5154 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
5156 CURLcode result
= CURLE_OK
;
5158 Store_field(conn
->ocamlValues
, OcamlCopyPostFields
, option
);
5160 if (conn
->copyPostFields
!= NULL
)
5161 free(conn
->copyPostFields
);
5163 conn
->copyPostFields
= strdup(String_val(option
));
5165 result
= curl_easy_setopt(conn
->connection
,
5166 CURLOPT_COPYPOSTFIELDS
,
5167 conn
->copyPostFields
);
5169 if (result
!= CURLE_OK
)
5170 raiseError(conn
, result
);
5174 #pragma message("libcurl does not implement CURLOPT_COPYPOSTFIELDS")
5175 failwith("libcurl does not implement CURLOPT_COPYPOSTFIELDS");
5179 static void handleProxyTransferMode(Connection
*conn
, value option
)
5181 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
5183 CURLcode result
= CURLE_OK
;
5185 result
= curl_easy_setopt(conn
->connection
,
5186 CURLOPT_PROXY_TRANSFER_MODE
,
5189 if (result
!= CURLE_OK
)
5190 raiseError(conn
, result
);
5194 #pragma message("libcurl does not implement CURLOPT_PROXY_TRANSFER_MODE")
5195 failwith("libcurl does not implement CURLOPT_PROXY_TRANSFER_MODE");
5199 static void handleSeekFunction(Connection
*conn
, value option
)
5201 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
5203 CURLcode result
= CURLE_OK
;
5205 if (Tag_val(option
) == Closure_tag
)
5206 Store_field(conn
->ocamlValues
, OcamlSeekFunctionCallback
, option
);
5208 failwith("Not a proper closure");
5210 result
= curl_easy_setopt(conn
->connection
,
5211 CURLOPT_SEEKFUNCTION
,
5214 if (result
!= CURLE_OK
)
5215 raiseError(conn
, result
);
5217 result
= curl_easy_setopt(conn
->connection
,
5221 if (result
!= CURLE_OK
)
5222 raiseError(conn
, result
);
5226 #pragma message("libcurl does not implement CURLOPT_SEEKFUNCTION")
5227 failwith("libcurl does not implement CURLOPT_SEEKFUNCTION");
5231 static void handleAutoReferer(Connection
*conn
, value option
)
5233 #if HAVE_DECL_CURLOPT_AUTOREFERER
5235 CURLcode result
= curl_easy_setopt(conn
->connection
,
5236 CURLOPT_AUTOREFERER
,
5239 if (result
!= CURLE_OK
)
5240 raiseError(conn
, result
);
5244 #pragma message("libcurl does not implement CURLOPT_AUTOREFERER")
5245 failwith("libcurl does not implement CURLOPT_AUTOREFERER");
5249 static void handleOpenSocketFunction(Connection
*conn
, value option
)
5251 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
5253 CURLcode result
= CURLE_OK
;
5255 Store_field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
, option
);
5257 result
= curl_easy_setopt(conn
->connection
,
5258 CURLOPT_OPENSOCKETDATA
,
5261 if (result
!= CURLE_OK
)
5262 raiseError(conn
, result
);
5264 result
= curl_easy_setopt(conn
->connection
,
5265 CURLOPT_OPENSOCKETFUNCTION
,
5266 openSocketFunction
);
5268 if (result
!= CURLE_OK
)
5269 raiseError(conn
, result
);
5273 #pragma message("libcurl does not implement CURLOPT_OPENSOCKETFUNCTION")
5274 failwith("libcurl does not implement CURLOPT_OPENSOCKETFUNCTION");
5278 static void handleProxyType(Connection
*conn
, value option
)
5280 #if HAVE_DECL_CURLOPT_PROXYTYPE
5282 CURLcode result
= CURLE_OK
;
5285 switch (Long_val(option
))
5287 case 0: proxy_type
= CURLPROXY_HTTP
; break;
5288 case 1: proxy_type
= CURLPROXY_HTTP_1_0
; break;
5289 case 2: proxy_type
= CURLPROXY_SOCKS4
; break;
5290 case 3: proxy_type
= CURLPROXY_SOCKS5
; break;
5291 case 4: proxy_type
= CURLPROXY_SOCKS4A
; break;
5292 case 5: proxy_type
= CURLPROXY_SOCKS5_HOSTNAME
; break;
5294 failwith("Invalid curl proxy type");
5297 result
= curl_easy_setopt(conn
->connection
,
5301 if (result
!= CURLE_OK
)
5302 raiseError(conn
, result
);
5306 #pragma message("libcurl does not implement CURLOPT_PROXYTYPE")
5307 failwith("libcurl does not implement CURLOPT_PROXYTYPE");
5311 #if HAVE_DECL_CURLOPT_PROTOCOLS && HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
5316 CURLPROTO_HTTP
, CURLPROTO_HTTPS
, CURLPROTO_FTP
, CURLPROTO_FTPS
, CURLPROTO_SCP
, CURLPROTO_SFTP
,
5317 CURLPROTO_TELNET
, CURLPROTO_LDAP
, CURLPROTO_LDAPS
, CURLPROTO_DICT
, CURLPROTO_FILE
, CURLPROTO_TFTP
,
5318 /* factor out with autoconf? */
5319 #if defined(CURLPROTO_IMAP)
5324 #if defined(CURLPROTO_IMAPS)
5329 #if defined(CURLPROTO_POP3)
5334 #if defined(CURLPROTO_POP3S)
5339 #if defined(CURLPROTO_SMTP)
5344 #if defined(CURLPROTO_SMTPS)
5349 #if defined(CURLPROTO_RTSP)
5354 #if defined(CURLPROTO_RTMP)
5359 #if defined(CURLPROTO_RTMPT)
5364 #if defined(CURLPROTO_RTMPE)
5369 #if defined(CURLPROTO_RTMPTE)
5374 #if defined(CURLPROTO_RTMPS)
5379 #if defined(CURLPROTO_RTMPTS)
5384 #if defined(CURLPROTO_GOPHER)
5391 static void handleProtocolsOption(CURLoption curlopt
, Connection
*conn
, value option
)
5394 CURLcode result
= CURLE_OK
;
5398 while (Val_emptylist
!= option
)
5400 index
= Int_val(Field(option
, 0));
5401 if ((index
< 0) || ((size_t)index
>= sizeof(protoMap
) / sizeof(protoMap
[0])))
5402 failwith("Invalid curl protocol");
5404 protocols
= protocols
| protoMap
[index
];
5406 option
= Field(option
, 1);
5409 result
= curl_easy_setopt(conn
->connection
,
5413 if (result
!= CURLE_OK
)
5414 raiseError(conn
, result
);
5419 static void handleProtocols(Connection
*conn
, value option
)
5421 handleProtocolsOption(CURLOPT_PROTOCOLS
, conn
, option
);
5424 static void handleRedirProtocols(Connection
*conn
, value option
)
5426 handleProtocolsOption(CURLOPT_REDIR_PROTOCOLS
, conn
, option
);
5430 #pragma message("libcurl does not implement CURLOPT_PROTOCOLS or CURLOPT_REDIR_PROTOCOLS")
5431 static void handleProtocols(Connection
*conn
, value option
)
5433 failwith("libcurl does not implement CURLOPT_PROTOCOLS");
5435 static void handleRedirProtocols(Connection
*conn
, value option
)
5437 failwith("libcurl does not implement CURLOPT_REDIR_PROTOCOLS");
5441 #if HAVE_DECL_CURLOPT_RESOLVE
5442 static void handleResolve(Connection
*conn
, value option
)
5447 CURLcode result
= CURLE_OK
;
5449 free_curl_slist(conn
->resolve
);
5450 conn
->resolve
= NULL
;
5454 while (head
!= Val_emptylist
)
5456 conn
->resolve
= curl_slist_append(conn
->resolve
, String_val(Field(head
,0)));
5457 head
= Field(head
, 1);
5460 result
= curl_easy_setopt(conn
->connection
,
5464 if (result
!= CURLE_OK
)
5465 raiseError(conn
, result
);
5471 #pragma message("libcurl does not implement CURLOPT_RESOLVE")
5472 static void handleResolve(Connection
*conn
, value option
)
5474 failwith("libcurl does not implement CURLOPT_RESOLVE");
5478 #if HAVE_DECL_CURLOPT_DNS_SERVERS
5479 static void handleDnsServers(Connection
*conn
, value option
)
5483 CURLcode result
= CURLE_OK
;
5484 free_if(conn
->dns_servers
);
5486 conn
->dns_servers
= strdup(String_val(option
));
5488 result
= curl_easy_setopt(conn
->connection
,
5489 CURLOPT_DNS_SERVERS
,
5492 if (result
!= CURLE_OK
)
5493 raiseError(conn
, result
);
5498 #pragma message("libcurl does not implement CURLOPT_DNS_SERVERS")
5499 static void handleDnsServers(Connection
*conn
, value option
)
5501 failwith("libcurl does not implement CURLOPT_DNS_SERVERS");
5506 ** curl_easy_setopt helper function
5509 CAMLprim value
helper_curl_easy_setopt(value conn
, value option
)
5511 CAMLparam2(conn
, option
);
5513 Connection
*connection
= Connection_val(conn
);
5515 checkConnection(connection
);
5517 if (Is_long(option
))
5521 sprintf(error
, "Unimplemented Option: %s",
5522 findOption(unimplementedOptionMap
,
5523 (CURLoption
)(Long_val(option
))));
5528 if (!Is_block(option
))
5529 failwith("Not a block");
5531 if (Wosize_val(option
) < 1)
5532 failwith("Insufficient data in block");
5534 data
= Field(option
, 0);
5536 if (Tag_val(option
) < sizeof(implementedOptionMap
)/sizeof(CURLOptionMapping
))
5537 (*implementedOptionMap
[Tag_val(option
)].optionHandler
)(connection
,
5540 failwith("Invalid CURLOPT Option");
5542 CAMLreturn(Val_unit
);
5546 ** curl_easy_perform helper function
5549 CAMLprim value
helper_curl_easy_perform(value conn
)
5552 CURLcode result
= CURLE_OK
;
5553 Connection
*connection
= Connection_val(conn
);
5555 checkConnection(connection
);
5557 enter_blocking_section();
5558 result
= curl_easy_perform(connection
->connection
);
5559 leave_blocking_section();
5561 if (result
!= CURLE_OK
)
5562 raiseError(connection
, result
);
5564 CAMLreturn(Val_unit
);
5568 ** curl_easy_cleanup helper function
5571 CAMLprim value
helper_curl_easy_cleanup(value conn
)
5574 Connection
*connection
= Connection_val(conn
);
5576 checkConnection(connection
);
5578 removeConnection(connection
);
5580 CAMLreturn(Val_unit
);
5584 ** curl_easy_duphandle helper function
5587 CAMLprim value
helper_curl_easy_duphandle(value conn
)
5591 Connection
*connection
= Connection_val(conn
);
5593 checkConnection(connection
);
5595 result
= caml_alloc(1, Abstract_tag
);
5596 Field(result
, 0) = (value
)duplicateConnection(connection
);
5602 ** curl_easy_getinfo helper function
5605 enum GetInfoResultType
{
5606 StringValue
, LongValue
, DoubleValue
, StringListValue
5609 value
convertStringList(struct curl_slist
*slist
)
5612 CAMLlocal3(result
, current
, next
);
5613 struct curl_slist
*p
= slist
;
5615 result
= Val_int(0);
5616 current
= Val_int(0);
5621 next
= alloc_tuple(2);
5622 Store_field(next
, 0, copy_string(p
->data
));
5623 Store_field(next
, 1, Val_int(0));
5625 if (result
== Val_int(0))
5628 if (current
!= Val_int(0))
5629 Store_field(current
, 1, next
);
5636 curl_slist_free_all(slist
);
5641 CAMLprim value
helper_curl_easy_getinfo(value conn
, value option
)
5643 CAMLparam2(conn
, option
);
5645 CURLcode curlResult
;
5646 Connection
*connection
= Connection_val(conn
);
5647 enum GetInfoResultType resultType
;
5648 char *strValue
= NULL
;
5651 struct curl_slist
*stringListValue
= NULL
;
5653 checkConnection(connection
);
5655 switch(Long_val(option
))
5657 #if HAVE_DECL_CURLINFO_EFFECTIVE_URL
5658 case 0: /* CURLINFO_EFFECTIVE_URL */
5659 resultType
= StringValue
;
5661 curlResult
= curl_easy_getinfo(connection
->connection
,
5662 CURLINFO_EFFECTIVE_URL
,
5666 #pragma message("libcurl does not provide CURLINFO_EFFECTIVE_URL")
5669 #if HAVE_DECL_CURLINFO_RESPONSE_CODE || HAVE_DECL_CURLINFO_HTTP_CODE
5670 case 1: /* CURLINFO_HTTP_CODE */
5671 case 2: /* CURLINFO_RESPONSE_CODE */
5672 #if HAVE_DECL_CURLINFO_RESPONSE_CODE
5673 resultType
= LongValue
;
5675 curlResult
= curl_easy_getinfo(connection
->connection
,
5676 CURLINFO_RESPONSE_CODE
,
5679 resultType
= LongValue
;
5681 curlResult
= curl_easy_getinfo(connection
->connection
,
5688 #if HAVE_DECL_CURLINFO_TOTAL_TIME
5689 case 3: /* CURLINFO_TOTAL_TIME */
5690 resultType
= DoubleValue
;
5692 curlResult
= curl_easy_getinfo(connection
->connection
,
5693 CURLINFO_TOTAL_TIME
,
5698 #if HAVE_DECL_CURLINFO_NAMELOOKUP_TIME
5699 case 4: /* CURLINFO_NAMELOOKUP_TIME */
5700 resultType
= DoubleValue
;
5702 curlResult
= curl_easy_getinfo(connection
->connection
,
5703 CURLINFO_NAMELOOKUP_TIME
,
5708 #if HAVE_DECL_CURLINFO_CONNECT_TIME
5709 case 5: /* CURLINFO_CONNECT_TIME */
5710 resultType
= DoubleValue
;
5712 curlResult
= curl_easy_getinfo(connection
->connection
,
5713 CURLINFO_CONNECT_TIME
,
5718 #if HAVE_DECL_CURLINFO_PRETRANSFER_TIME
5719 case 6: /* CURLINFO_PRETRANSFER_TIME */
5720 resultType
= DoubleValue
;
5722 curlResult
= curl_easy_getinfo(connection
->connection
,
5723 CURLINFO_PRETRANSFER_TIME
,
5728 #if HAVE_DECL_CURLINFO_SIZE_UPLOAD
5729 case 7: /* CURLINFO_SIZE_UPLOAD */
5730 resultType
= DoubleValue
;
5732 curlResult
= curl_easy_getinfo(connection
->connection
,
5733 CURLINFO_SIZE_UPLOAD
,
5738 #if HAVE_DECL_CURLINFO_SIZE_DOWNLOAD
5739 case 8: /* CURLINFO_SIZE_DOWNLOAD */
5740 resultType
= DoubleValue
;
5742 curlResult
= curl_easy_getinfo(connection
->connection
,
5743 CURLINFO_SIZE_DOWNLOAD
,
5748 #if HAVE_DECL_CURLINFO_SPEED_DOWNLOAD
5749 case 9: /* CURLINFO_SPEED_DOWNLOAD */
5750 resultType
= DoubleValue
;
5752 curlResult
= curl_easy_getinfo(connection
->connection
,
5753 CURLINFO_SPEED_DOWNLOAD
,
5758 #if HAVE_DECL_CURLINFO_SPEED_UPLOAD
5759 case 10: /* CURLINFO_SPEED_UPLOAD */
5760 resultType
= DoubleValue
;
5762 curlResult
= curl_easy_getinfo(connection
->connection
,
5763 CURLINFO_SPEED_UPLOAD
,
5769 #if HAVE_DECL_CURLINFO_HEADER_SIZE
5770 case 11: /* CURLINFO_HEADER_SIZE */
5771 resultType
= LongValue
;
5773 curlResult
= curl_easy_getinfo(connection
->connection
,
5774 CURLINFO_HEADER_SIZE
,
5779 #if HAVE_DECL_CURLINFO_REQUEST_SIZE
5780 case 12: /* CURLINFO_REQUEST_SIZE */
5781 resultType
= LongValue
;
5783 curlResult
= curl_easy_getinfo(connection
->connection
,
5784 CURLINFO_REQUEST_SIZE
,
5789 #if HAVE_DECL_CURLINFO_SSL_VERIFYRESULT
5790 case 13: /* CURLINFO_SSL_VERIFYRESULT */
5791 resultType
= LongValue
;
5793 curlResult
= curl_easy_getinfo(connection
->connection
,
5794 CURLINFO_SSL_VERIFYRESULT
,
5799 #if HAVE_DECL_CURLINFO_FILETIME
5800 case 14: /* CURLINFO_FILETIME */
5801 resultType
= DoubleValue
;
5803 curlResult
= curl_easy_getinfo(connection
->connection
,
5807 doubleValue
= longValue
;
5811 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_DOWNLOAD
5812 case 15: /* CURLINFO_CONTENT_LENGTH_DOWNLOAD */
5813 resultType
= DoubleValue
;
5815 curlResult
= curl_easy_getinfo(connection
->connection
,
5816 CURLINFO_CONTENT_LENGTH_DOWNLOAD
,
5821 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_UPLOAD
5822 case 16: /* CURLINFO_CONTENT_LENGTH_UPLOAD */
5823 resultType
= DoubleValue
;
5825 curlResult
= curl_easy_getinfo(connection
->connection
,
5826 CURLINFO_CONTENT_LENGTH_UPLOAD
,
5831 #if HAVE_DECL_CURLINFO_STARTTRANSFER_TIME
5832 case 17: /* CURLINFO_STARTTRANSFER_TIME */
5833 resultType
= DoubleValue
;
5835 curlResult
= curl_easy_getinfo(connection
->connection
,
5836 CURLINFO_STARTTRANSFER_TIME
,
5841 #if HAVE_DECL_CURLINFO_CONTENT_TYPE
5842 case 18: /* CURLINFO_CONTENT_TYPE */
5843 resultType
= StringValue
;
5845 curlResult
= curl_easy_getinfo(connection
->connection
,
5846 CURLINFO_CONTENT_TYPE
,
5851 #if HAVE_DECL_CURLINFO_REDIRECT_TIME
5852 case 19: /* CURLINFO_REDIRECT_TIME */
5853 resultType
= DoubleValue
;
5855 curlResult
= curl_easy_getinfo(connection
->connection
,
5856 CURLINFO_REDIRECT_TIME
,
5861 #if HAVE_DECL_CURLINFO_REDIRECT_COUNT
5862 case 20: /* CURLINFO_REDIRECT_COUNT */
5863 resultType
= LongValue
;
5865 curlResult
= curl_easy_getinfo(connection
->connection
,
5866 CURLINFO_REDIRECT_COUNT
,
5871 #if HAVE_DECL_CURLINFO_PRIVATE
5872 case 21: /* CURLINFO_PRIVATE */
5873 resultType
= StringValue
;
5875 curlResult
= curl_easy_getinfo(connection
->connection
,
5881 #if HAVE_DECL_CURLINFO_HTTP_CONNECTCODE
5882 case 22: /* CURLINFO_HTTP_CONNECTCODE */
5883 resultType
= LongValue
;
5885 curlResult
= curl_easy_getinfo(connection
->connection
,
5886 CURLINFO_HTTP_CONNECTCODE
,
5891 #if HAVE_DECL_CURLINFO_HTTPAUTH_AVAIL
5892 case 23: /* CURLINFO_HTTPAUTH_AVAIL */
5893 resultType
= LongValue
;
5895 curlResult
= curl_easy_getinfo(connection
->connection
,
5896 CURLINFO_HTTPAUTH_AVAIL
,
5901 #if HAVE_DECL_CURLINFO_PROXYAUTH_AVAIL
5902 case 24: /* CURLINFO_PROXYAUTH_AVAIL */
5903 resultType
= LongValue
;
5905 curlResult
= curl_easy_getinfo(connection
->connection
,
5906 CURLINFO_PROXYAUTH_AVAIL
,
5911 #if HAVE_DECL_CURLINFO_OS_ERRNO
5912 case 25: /* CURLINFO_OS_ERRNO */
5913 resultType
= LongValue
;
5915 curlResult
= curl_easy_getinfo(connection
->connection
,
5921 #if HAVE_DECL_CURLINFO_NUM_CONNECTS
5922 case 26: /* CURLINFO_NUM_CONNECTS */
5923 resultType
= LongValue
;
5925 curlResult
= curl_easy_getinfo(connection
->connection
,
5926 CURLINFO_NUM_CONNECTS
,
5931 #if HAVE_DECL_CURLINFO_SSL_ENGINES
5932 case 27: /* CURLINFO_SSL_ENGINES */
5933 resultType
= StringListValue
;
5935 curlResult
= curl_easy_getinfo(connection
->connection
,
5936 CURLINFO_SSL_ENGINES
,
5941 #if HAVE_DECL_CURLINFO_COOKIELIST
5942 case 28: /* CURLINFO_COOKIELIST */
5943 resultType
= StringListValue
;
5945 curlResult
= curl_easy_getinfo(connection
->connection
,
5946 CURLINFO_COOKIELIST
,
5951 #if HAVE_DECL_CURLINFO_LASTSOCKET
5952 case 29: /* CURLINFO_LASTSOCKET */
5953 resultType
= LongValue
;
5955 curlResult
= curl_easy_getinfo(connection
->connection
,
5956 CURLINFO_LASTSOCKET
,
5961 #if HAVE_DECL_CURLINFO_FTP_ENTRY_PATH
5962 case 30: /* CURLINFO_FTP_ENTRY_PATH */
5963 resultType
= StringValue
;
5965 curlResult
= curl_easy_getinfo(connection
->connection
,
5966 CURLINFO_FTP_ENTRY_PATH
,
5971 #if HAVE_DECL_CURLINFO_REDIRECT_URL
5972 case 31: /* CURLINFO_REDIRECT_URL */
5973 resultType
= StringValue
;
5975 curlResult
= curl_easy_getinfo(connection
->connection
,
5976 CURLINFO_REDIRECT_URL
,
5980 #pragma message("libcurl does not provide CURLINFO_REDIRECT_URL")
5983 #if HAVE_DECL_CURLINFO_PRIMARY_IP
5984 case 32: /* CURLINFO_PRIMARY_IP */
5985 resultType
= StringValue
;
5987 curlResult
= curl_easy_getinfo(connection
->connection
,
5988 CURLINFO_PRIMARY_IP
,
5992 #pragma message("libcurl does not provide CURLINFO_PRIMARY_IP")
5995 #if HAVE_DECL_CURLINFO_LOCAL_IP
5996 case 33: /* CURLINFO_LOCAL_IP */
5997 resultType
= StringValue
;
5999 curlResult
= curl_easy_getinfo(connection
->connection
,
6004 #pragma message("libcurl does not provide CURLINFO_LOCAL_IP")
6007 #if HAVE_DECL_CURLINFO_LOCAL_PORT
6008 case 34: /* CURLINFO_LOCAL_PORT */
6009 resultType
= LongValue
;
6011 curlResult
= curl_easy_getinfo(connection
->connection
,
6012 CURLINFO_LOCAL_PORT
,
6016 #pragma message("libcurl does not provide CURLINFO_LOCAL_PORT")
6019 #if HAVE_DECL_CURLINFO_CONDITION_UNMET
6020 case 35: /* CURLINFO_CONDITION_UNMET */
6021 resultType
= LongValue
;
6023 curlResult
= curl_easy_getinfo(connection
->connection
,
6024 CURLINFO_CONDITION_UNMET
,
6028 #pragma message("libcurl does not provide CURLINFO_CONDITION_UNMET")
6032 failwith("Invalid CURLINFO Option");
6036 if (curlResult
!= CURLE_OK
)
6037 raiseError(connection
, curlResult
);
6042 result
= alloc(1, StringValue
);
6043 Store_field(result
, 0, copy_string(strValue
?strValue
:""));
6047 result
= alloc(1, LongValue
);
6048 Store_field(result
, 0, Val_long(longValue
));
6052 result
= alloc(1, DoubleValue
);
6053 Store_field(result
, 0, copy_double(doubleValue
));
6056 case StringListValue
:
6057 result
= alloc(1, StringListValue
);
6058 Store_field(result
, 0, convertStringList(stringListValue
));
6066 ** curl_escape helper function
6069 CAMLprim value
helper_curl_escape(value str
)
6075 curlResult
= curl_escape(String_val(str
), string_length(str
));
6076 result
= copy_string(curlResult
);
6083 ** curl_unescape helper function
6086 CAMLprim value
helper_curl_unescape(value str
)
6092 curlResult
= curl_unescape(String_val(str
), string_length(str
));
6093 result
= copy_string(curlResult
);
6100 ** curl_getdate helper function
6103 CAMLprim value
helper_curl_getdate(value str
, value now
)
6105 CAMLparam2(str
, now
);
6110 curlNow
= (time_t)Double_val(now
);
6111 curlResult
= curl_getdate(String_val(str
), &curlNow
);
6112 result
= copy_double((double)curlResult
);
6118 ** curl_version helper function
6121 CAMLprim value
helper_curl_version(void)
6127 str
= curl_version();
6128 result
= copy_string(str
);
6133 struct CURLVersionBitsMapping
6139 struct CURLVersionBitsMapping versionBitsMap
[] =
6141 {CURL_VERSION_IPV6
, "ipv6"},
6142 {CURL_VERSION_KERBEROS4
, "kerberos4"},
6143 {CURL_VERSION_SSL
, "ssl"},
6144 {CURL_VERSION_LIBZ
, "libz"},
6145 {CURL_VERSION_NTLM
, "ntlm"},
6146 {CURL_VERSION_GSSNEGOTIATE
, "gssnegotiate"},
6147 {CURL_VERSION_DEBUG
, "debug"},
6148 {CURL_VERSION_CURLDEBUG
, "curldebug"},
6149 {CURL_VERSION_ASYNCHDNS
, "asynchdns"},
6150 {CURL_VERSION_SPNEGO
, "spnego"},
6151 {CURL_VERSION_LARGEFILE
, "largefile"},
6152 {CURL_VERSION_IDN
, "idn"},
6153 {CURL_VERSION_SSPI
, "sspi"},
6154 {CURL_VERSION_CONV
, "conv"},
6155 #if HAVE_DECL_CURL_VERSION_TLSAUTH_SRP
6156 {CURL_VERSION_TLSAUTH_SRP
, "srp"},
6158 #if HAVE_DECL_CURL_VERSION_NTLM_WB
6159 {CURL_VERSION_NTLM_WB
, "wb"},
6163 CAMLprim value
caml_curl_version_info(value unit
)
6166 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6167 const char* const* p
= NULL
;
6170 curl_version_info_data
* data
= curl_version_info(CURLVERSION_NOW
);
6171 if (NULL
== data
) caml_failwith("curl_version_info");
6173 vlist
= Val_emptylist
;
6174 for (p
= data
->protocols
; NULL
!= *p
; p
++)
6176 vlist
= Val_cons(vlist
, caml_copy_string(*p
));
6179 vfeatures
= Val_emptylist
;
6180 for (i
= 0; i
< sizeof(versionBitsMap
)/sizeof(versionBitsMap
[0]); i
++)
6182 if (0 != (versionBitsMap
[i
].code
& data
->features
))
6183 vfeatures
= Val_cons(vfeatures
, caml_copy_string(versionBitsMap
[i
].name
));
6186 vnum
= caml_alloc_tuple(3);
6187 Store_field(vnum
,0,Val_int(0xFF & (data
->version_num
>> 16)));
6188 Store_field(vnum
,1,Val_int(0xFF & (data
->version_num
>> 8)));
6189 Store_field(vnum
,2,Val_int(0xFF & (data
->version_num
)));
6191 v
= caml_alloc_tuple(12);
6192 Store_field(v
,0,caml_copy_string(data
->version
));
6193 Store_field(v
,1,vnum
);
6194 Store_field(v
,2,caml_copy_string(data
->host
));
6195 Store_field(v
,3,vfeatures
);
6196 Store_field(v
,4,data
->ssl_version
? Val_some(caml_copy_string(data
->ssl_version
)) : Val_none
);
6197 Store_field(v
,5,data
->libz_version
? Val_some(caml_copy_string(data
->libz_version
)) : Val_none
);
6198 Store_field(v
,6,vlist
);
6199 Store_field(v
,7,caml_copy_string((data
->age
>= 1 && data
->ares
) ? data
->ares
: ""));
6200 Store_field(v
,8,Val_int((data
->age
>= 1) ? data
->ares_num
: 0));
6201 Store_field(v
,9,caml_copy_string((data
->age
>= 2 && data
->libidn
) ? data
->libidn
: ""));
6202 Store_field(v
,10,Val_int((data
->age
>= 3) ? data
->iconv_ver_num
: 0));
6203 Store_field(v
,11,caml_copy_string((data
->age
>= 3 && data
->libssh_version
) ? data
->libssh_version
: ""));
6208 CAMLprim value
caml_curl_pause(value conn
, value opts
)
6210 CAMLparam2(conn
, opts
);
6211 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6212 Connection
*connection
= Connection_val(conn
);
6216 while (Val_emptylist
!= opts
)
6218 switch (Int_val(Field(opts
,0)))
6220 case 0: bitmask
|= CURLPAUSE_SEND
; break;
6221 case 1: bitmask
|= CURLPAUSE_RECV
; break;
6222 case 2: bitmask
|= CURLPAUSE_ALL
; break;
6223 default: caml_failwith("wrong pauseOption");
6225 opts
= Field(opts
,1);
6228 result
= curl_easy_pause(connection
->connection
,bitmask
);
6229 if (result
!= CURLE_OK
)
6230 raiseError(connection
, result
);
6232 CAMLreturn(Val_unit
);
6236 * Curl multi stack support
6238 * Exported thin wrappers for libcurl are prefixed with caml_curl_multi_.
6239 * Other exported functions are prefixed with caml_curlm_, some of them
6240 * can/should be decomposed into smaller parts.
6243 struct ml_multi_handle
6246 value values
; /* callbacks */
6251 curlmopt_socket_function
,
6252 curlmopt_timer_function
,
6254 /* last, not used */
6258 typedef struct ml_multi_handle ml_multi_handle
;
6260 #define Multi_val(v) (*(ml_multi_handle**)Data_custom_val(v))
6261 #define CURLM_val(v) (Multi_val(v)->handle)
6263 static struct custom_operations curl_multi_ops
= {
6265 custom_finalize_default
,
6266 custom_compare_default
,
6267 custom_hash_default
,
6268 custom_serialize_default
,
6269 custom_deserialize_default
,
6270 #if defined(custom_compare_ext_default)
6271 custom_compare_ext_default
,
6275 CAMLprim value
caml_curl_multi_init(value unit
)
6279 ml_multi_handle
* multi
= (ml_multi_handle
*)caml_stat_alloc(sizeof(ml_multi_handle
));
6280 CURLM
* h
= curl_multi_init();
6284 caml_stat_free(multi
);
6285 failwith("caml_curl_multi_init");
6289 multi
->values
= caml_alloc(multi_values_total
, 0);
6290 caml_register_generational_global_root(&multi
->values
);
6292 v
= caml_alloc_custom(&curl_multi_ops
, sizeof(ml_multi_handle
*), 0, 1);
6293 Multi_val(v
) = multi
;
6298 CAMLprim value
caml_curl_multi_cleanup(value handle
)
6301 ml_multi_handle
* h
= Multi_val(handle
);
6304 CAMLreturn(Val_unit
);
6306 caml_remove_generational_global_root(&h
->values
);
6308 if (CURLM_OK
!= curl_multi_cleanup(h
->handle
))
6309 failwith("caml_curl_multi_cleanup");
6311 Multi_val(handle
) = (ml_multi_handle
*)NULL
;
6313 CAMLreturn(Val_unit
);
6316 static CURL
* curlm_remove_finished(CURLM
* multi_handle
, CURLcode
* result
)
6318 int msgs_in_queue
= 0;
6322 CURLMsg
* msg
= curl_multi_info_read(multi_handle
, &msgs_in_queue
);
6323 if (NULL
== msg
) return NULL
;
6324 if (CURLMSG_DONE
== msg
->msg
)
6326 CURL
* easy_handle
= msg
->easy_handle
;
6327 if (result
) *result
= msg
->data
.result
;
6328 if (CURLM_OK
!= curl_multi_remove_handle(multi_handle
, easy_handle
))
6330 /*failwith("curlm_remove_finished");*/
6337 CAMLprim value
caml_curlm_remove_finished(value v_multi
)
6339 CAMLparam1(v_multi
);
6340 CAMLlocal2(v_easy
, v_tuple
);
6342 CURLM
* multi_handle
;
6345 multi_handle
= CURLM_val(v_multi
);
6347 caml_enter_blocking_section();
6348 handle
= curlm_remove_finished(multi_handle
,&result
);
6349 caml_leave_blocking_section();
6353 CAMLreturn(Val_none
);
6357 /* not good: same handle, but different block */
6358 v_easy
= caml_alloc(1, Abstract_tag
);
6359 Field(v_easy
, 0) = (value
)findConnection(handle
);
6360 v_tuple
= caml_alloc(2, 0);
6361 Store_field(v_tuple
,0,v_easy
);
6362 Store_field(v_tuple
,1,Val_int(result
)); /* CURLcode */
6363 CAMLreturn(Val_some(v_tuple
));
6367 static int curlm_wait_data(CURLM
* multi_handle
)
6369 struct timeval timeout
;
6381 /* set a suitable timeout */
6383 timeout
.tv_usec
= 0;
6385 /* get file descriptors from the transfers */
6386 ret
= curl_multi_fdset(multi_handle
, &fdread
, &fdwrite
, &fdexcep
, &maxfd
);
6388 if (ret
== CURLM_OK
&& maxfd
>= 0)
6390 int rc
= select(maxfd
+1, &fdread
, &fdwrite
, &fdexcep
, &timeout
);
6391 if (-1 != rc
) return 0;
6396 CAMLprim value
caml_curlm_wait_data(value v_multi
)
6398 CAMLparam1(v_multi
);
6400 CURLM
* h
= CURLM_val(v_multi
);
6402 caml_enter_blocking_section();
6403 ret
= curlm_wait_data(h
);
6404 caml_leave_blocking_section();
6406 CAMLreturn(Val_bool(0 == ret
));
6409 CAMLprim value
caml_curl_multi_add_handle(value v_multi
, value v_easy
)
6411 CAMLparam2(v_multi
,v_easy
);
6412 CURLM
* multi
= CURLM_val(v_multi
);
6413 CURL
* easy
= Connection_val(v_easy
)->connection
;
6415 /* may invoke callbacks so need to be consistent with locks */
6416 caml_enter_blocking_section();
6417 if (CURLM_OK
!= curl_multi_add_handle(multi
, easy
))
6419 caml_leave_blocking_section();
6420 failwith("caml_curl_multi_add_handle");
6422 caml_leave_blocking_section();
6424 CAMLreturn(Val_unit
);
6427 CAMLprim value
caml_curl_multi_perform_all(value v_multi
)
6429 CAMLparam1(v_multi
);
6430 int still_running
= 0;
6431 CURLM
* h
= CURLM_val(v_multi
);
6433 caml_enter_blocking_section();
6434 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(h
, &still_running
));
6435 caml_leave_blocking_section();
6437 CAMLreturn(Val_int(still_running
));
6440 CAMLprim value
helper_curl_easy_strerror(value v_code
)
6443 CAMLreturn(caml_copy_string(curl_easy_strerror(Int_val(v_code
))));
6447 * Wrappers for the curl_multi_socket_action infrastructure
6448 * Based on curl hiperfifo.c example
6451 /* FIXME win32unix */
6452 #define Socket_val(v) Int_val(v)
6453 #define Val_socket(v) Val_int(v)
6455 static void raise_error(char const* msg
)
6457 static value
* exception
= NULL
;
6459 if (NULL
== exception
)
6461 exception
= caml_named_value("Curl.Multi.Error");
6462 if (NULL
== exception
) caml_invalid_argument("Curl.Multi.Error");
6465 caml_raise_with_string(*exception
, msg
);
6468 static void check_mcode(CURLMcode code
)
6470 char const *s
= NULL
;
6473 case CURLM_OK
: return;
6474 case CURLM_CALL_MULTI_PERFORM
: s
="CURLM_CALL_MULTI_PERFORM"; break;
6475 case CURLM_BAD_HANDLE
: s
="CURLM_BAD_HANDLE"; break;
6476 case CURLM_BAD_EASY_HANDLE
: s
="CURLM_BAD_EASY_HANDLE"; break;
6477 case CURLM_OUT_OF_MEMORY
: s
="CURLM_OUT_OF_MEMORY"; break;
6478 case CURLM_INTERNAL_ERROR
: s
="CURLM_INTERNAL_ERROR"; break;
6479 case CURLM_UNKNOWN_OPTION
: s
="CURLM_UNKNOWN_OPTION"; break;
6480 case CURLM_LAST
: s
="CURLM_LAST"; break;
6481 case CURLM_BAD_SOCKET
: s
="CURLM_BAD_SOCKET"; break;
6482 default : s
="CURLM_unknown"; break;
6487 CAMLprim value
caml_curl_multi_socket_action(value v_multi
, value v_fd
, value v_kind
)
6489 CAMLparam3(v_multi
, v_fd
, v_kind
);
6490 CURLM
* h
= CURLM_val(v_multi
);
6491 int still_running
= 0;
6492 CURLMcode rc
= CURLM_OK
;
6493 int socket
= Socket_val(v_fd
);
6496 switch (Int_val(v_kind
))
6499 case 1 : kind
|= CURL_CSELECT_IN
; break;
6500 case 2 : kind
|= CURL_CSELECT_OUT
; break;
6501 case 3 : kind
|= CURL_CSELECT_IN
| CURL_CSELECT_OUT
; break;
6503 raise_error("caml_curl_multi_socket_action");
6506 /* fprintf(stdout,"fd %u kind %u\n",Socket_val(v_fd), kind); fflush(stdout); */
6508 caml_enter_blocking_section();
6510 rc
= curl_multi_socket_action(h
, socket
, kind
, &still_running
);
6511 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6512 caml_leave_blocking_section();
6516 CAMLreturn(Val_int(still_running
));
6519 CAMLprim value
caml_curl_multi_socket_all(value v_multi
)
6521 CAMLparam1(v_multi
);
6522 int still_running
= 0;
6523 CURLMcode rc
= CURLM_OK
;
6524 CURLM
* h
= CURLM_val(v_multi
);
6526 caml_enter_blocking_section();
6528 rc
= curl_multi_socket_all(h
, &still_running
);
6529 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6530 caml_leave_blocking_section();
6534 CAMLreturn(Val_int(still_running
));
6537 static int curlm_sock_cb_nolock(CURL
*e
, curl_socket_t sock
, int what
, ml_multi_handle
* multi
, void *sockp
)
6542 (void)sockp
; /* not used */
6544 /* v_what = Val_int(what); */
6547 case CURL_POLL_NONE
: v_what
= Val_int(0); break;
6548 case CURL_POLL_IN
: v_what
= Val_int(1); break;
6549 case CURL_POLL_OUT
: v_what
= Val_int(2); break;
6550 case CURL_POLL_INOUT
: v_what
= Val_int(3); break;
6551 case CURL_POLL_REMOVE
: v_what
= Val_int(4); break;
6553 fprintf(stderr
, "curlm_sock_cb sock=%d what=%d\n", sock
, what
);
6555 raise_error("curlm_sock_cb"); /* FIXME exception from callback */
6558 caml_callback2(Field(multi
->values
,curlmopt_socket_function
),
6559 Val_socket(sock
), v_what
);
6564 static int curlm_sock_cb(CURL
*e
, curl_socket_t sock
, int what
, void *cbp
, void *sockp
)
6567 caml_leave_blocking_section();
6568 ret
= curlm_sock_cb_nolock(e
, sock
, what
, (ml_multi_handle
*)cbp
, sockp
);
6569 caml_enter_blocking_section();
6573 CAMLprim value
caml_curl_multi_socketfunction(value v_multi
, value v_cb
)
6575 CAMLparam2(v_multi
, v_cb
);
6576 ml_multi_handle
* multi
= Multi_val(v_multi
);
6578 Store_field(multi
->values
, curlmopt_socket_function
, v_cb
);
6580 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETFUNCTION
, curlm_sock_cb
);
6581 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETDATA
, multi
);
6583 CAMLreturn(Val_unit
);
6586 static void curlm_timer_cb_nolock(ml_multi_handle
*multi
, long timeout_ms
)
6589 caml_callback(Field(multi
->values
,curlmopt_timer_function
), Val_long(timeout_ms
));
6593 static int curlm_timer_cb(CURLM
*multi
, long timeout_ms
, void *userp
)
6597 caml_leave_blocking_section();
6598 curlm_timer_cb_nolock((ml_multi_handle
*)userp
, timeout_ms
);
6599 caml_enter_blocking_section();
6603 CAMLprim value
caml_curl_multi_timerfunction(value v_multi
, value v_cb
)
6605 CAMLparam2(v_multi
, v_cb
);
6606 ml_multi_handle
* multi
= Multi_val(v_multi
);
6608 Store_field(multi
->values
, curlmopt_timer_function
, v_cb
);
6610 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERFUNCTION
, curlm_timer_cb
);
6611 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERDATA
, multi
);
6613 CAMLreturn(Val_unit
);
6616 CAMLprim value
caml_curl_multi_timeout(value v_multi
)
6618 CAMLparam1(v_multi
);
6620 CURLMcode rc
= CURLM_OK
;
6621 ml_multi_handle
* multi
= Multi_val(v_multi
);
6623 rc
= curl_multi_timeout(multi
->handle
, &ms
);
6627 CAMLreturn(Val_long(ms
));