4 *** Copyright (c) 2003-2008, Lars Nilsson, <lars@quantumchamaeleon.com>
5 *** Copyright (c) 2009, ygrek, <ygrek@autistici.org>
12 #include <curl/curl.h>
14 #include <caml/alloc.h>
15 #include <caml/memory.h>
16 #include <caml/mlvalues.h>
17 #include <caml/callback.h>
18 #include <caml/fail.h>
19 #include <caml/custom.h>
24 #pragma message("No config file given.")
33 void leave_blocking_section(void);
34 void enter_blocking_section(void);
36 #define Val_none Val_int(0)
43 some
= caml_alloc(1, 0);
44 Store_field( some
, 0, v
);
48 static value
Val_pair(value v1
, value v2
)
52 pair
= caml_alloc_small(2,0);
58 static value
Val_cons(value list
, value v
) { return Val_pair(v
,list
); }
60 typedef struct Connection Connection
;
61 typedef struct ConnectionList ConnectionList
;
63 #define Connection_val(v) ((Connection *)Field(v, 0))
76 OcamlProgressCallback
,
80 OcamlSeekFunctionCallback
,
81 OcamlOpenSocketFunctionCallback
,
113 OcamlFTPAlternativeToUser
,
114 OcamlSSHPublicKeyFile
,
115 OcamlSSHPrivateKeyFile
,
116 OcamlSSHHostPublicKeyMD5
,
119 /* Not used, last for size */
143 struct curl_slist
*httpHeader
;
144 struct curl_httppost
*httpPostFirst
;
145 struct curl_httppost
*httpPostLast
;
146 struct curl_slist
*httpPostStrings
;
147 struct curl_slist
*resolve
;
155 struct curl_slist
*quote
;
156 struct curl_slist
*postQuote
;
167 struct curl_slist
*http200Aliases
;
171 char *ftpAlternativeToUser
;
172 char *sshPublicKeyFile
;
173 char *sshPrivateKeyFile
;
174 char *sshHostPublicKeyMD5
;
175 char *copyPostFields
;
179 struct ConnectionList
185 static ConnectionList connectionList
= {NULL
, NULL
};
187 typedef struct CURLErrorMapping CURLErrorMapping
;
189 struct CURLErrorMapping
195 CURLErrorMapping errorMap
[] =
197 #if HAVE_DECL_CURLE_UNSUPPORTED_PROTOCOL
198 {"CURLE_UNSUPPORTED_PROTOCOL", CURLE_UNSUPPORTED_PROTOCOL
},
200 {"CURLE_UNSUPPORTED_PROTOCOL", -1},
202 #if HAVE_DECL_CURLE_FAILED_INIT
203 {"CURLE_FAILED_INIT", CURLE_FAILED_INIT
},
205 {"CURLE_FAILED_INIT", -1},
207 #if HAVE_DECL_CURLE_URL_MALFORMAT
208 {"CURLE_URL_MALFORMAT", CURLE_URL_MALFORMAT
},
210 {"CURLE_URL_MALFORMAT", -1},
212 #if HAVE_DECL_CURLE_URL_MALFORMAT_USER
213 {"CURLE_URL_MALFORMAT_USER", CURLE_URL_MALFORMAT_USER
},
215 {"CURLE_URL_MALFORMAT_USER", -1},
217 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_PROXY
218 {"CURLE_COULDNT_RESOLVE_PROXY", CURLE_COULDNT_RESOLVE_PROXY
},
220 {"CURLE_COULDNT_RESOLVE_PROXY", -1},
222 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_HOST
223 {"CURLE_COULDNT_RESOLVE_HOST", CURLE_COULDNT_RESOLVE_HOST
},
225 {"CURLE_COULDNT_RESOLVE_HOST", -1},
227 #if HAVE_DECL_CURLE_COULDNT_CONNECT
228 {"CURLE_COULDNT_CONNECT", CURLE_COULDNT_CONNECT
},
230 {"CURLE_COULDNT_CONNECT", -1},
232 #if HAVE_DECL_CURLE_FTP_WEIRD_SERVER_REPLY
233 {"CURLE_FTP_WEIRD_SERVER_REPLY", CURLE_FTP_WEIRD_SERVER_REPLY
},
235 {"CURLE_FTP_WEIRD_SERVER_REPLY", -1},
237 #if HAVE_DECL_CURLE_FTP_ACCESS_DENIED
238 {"CURLE_FTP_ACCESS_DENIED", CURLE_FTP_ACCESS_DENIED
},
240 {"CURLE_FTP_ACCESS_DENIED", -1},
242 #if HAVE_DECL_CURLE_FTP_USER_PASSWORD_INCORRECT
243 {"CURLE_FTP_USER_PASSWORD_INCORRECT", CURLE_FTP_USER_PASSWORD_INCORRECT
},
245 {"CURLE_FTP_USER_PASSWORD_INCORRECT", -1},
247 #if HAVE_DECL_CURLE_FTP_WEIRD_PASS_REPLY
248 {"CURLE_FTP_WEIRD_PASS_REPLY", CURLE_FTP_WEIRD_PASS_REPLY
},
250 {"CURLE_FTP_WEIRD_PASS_REPLY", -1},
252 #if HAVE_DECL_CURLE_FTP_WEIRD_USER_REPLY
253 {"CURLE_FTP_WEIRD_USER_REPLY", CURLE_FTP_WEIRD_USER_REPLY
},
255 {"CURLE_FTP_WEIRD_USER_REPLY", -1},
257 #if HAVE_DECL_CURLE_FTP_WEIRD_PASV_REPLY
258 {"CURLE_FTP_WEIRD_PASV_REPLY", CURLE_FTP_WEIRD_PASV_REPLY
},
260 {"CURLE_FTP_WEIRD_PASV_REPLY", -1},
262 #if HAVE_DECL_CURLE_FTP_WEIRD_227_FORMAT
263 {"CURLE_FTP_WEIRD_227_FORMAT", CURLE_FTP_WEIRD_227_FORMAT
},
265 {"CURLE_FTP_WEIRD_227_FORMAT", -1},
267 #if HAVE_DECL_CURLE_FTP_CANT_GET_HOST
268 {"CURLE_FTP_CANT_GET_HOST", CURLE_FTP_CANT_GET_HOST
},
270 {"CURLE_FTP_CANT_GET_HOST", -1},
272 #if HAVE_DECL_CURLE_FTP_CANT_RECONNECT
273 {"CURLE_FTP_CANT_RECONNECT", CURLE_FTP_CANT_RECONNECT
},
275 {"CURLE_FTP_CANT_RECONNECT", -1},
277 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_BINARY
278 {"CURLE_FTP_COULDNT_SET_BINARY", CURLE_FTP_COULDNT_SET_BINARY
},
280 {"CURLE_FTP_COULDNT_SET_BINARY", -1},
282 #if HAVE_DECL_CURLE_PARTIAL_FILE
283 {"CURLE_PARTIAL_FILE", CURLE_PARTIAL_FILE
},
285 {"CURLE_PARTIAL_FILE", -1},
287 #if HAVE_DECL_CURLE_FTP_COULDNT_RETR_FILE
288 {"CURLE_FTP_COULDNT_RETR_FILE", CURLE_FTP_COULDNT_RETR_FILE
},
290 {"CURLE_FTP_COULDNT_RETR_FILE", -1},
292 #if HAVE_DECL_CURLE_FTP_WRITE_ERROR
293 {"CURLE_FTP_WRITE_ERROR", CURLE_FTP_WRITE_ERROR
},
295 {"CURLE_FTP_WRITE_ERROR", -1},
297 #if HAVE_DECL_CURLE_FTP_QUOTE_ERROR
298 {"CURLE_FTP_QUOTE_ERROR", CURLE_FTP_QUOTE_ERROR
},
300 {"CURLE_FTP_QUOTE_ERROR", -1},
302 #if HAVE_DECL_CURLE_HTTP_NOT_FOUND
303 {"CURLE_HTTP_NOT_FOUND", CURLE_HTTP_NOT_FOUND
},
305 {"CURLE_HTTP_NOT_FOUND", -1},
307 #if HAVE_DECL_CURLE_WRITE_ERROR
308 {"CURLE_WRITE_ERROR", CURLE_WRITE_ERROR
},
310 {"CURLE_WRITE_ERROR", -1},
312 #if HAVE_DECL_CURLE_MALFORMAT_USER
313 {"CURLE_MALFORMAT_USER", CURLE_MALFORMAT_USER
},
315 {"CURLE_MALFORMAT_USER", -1},
317 #if HAVE_DECL_CURLE_FTP_COULDNT_STOR_FILE
318 {"CURLE_FTP_COULDNT_STOR_FILE", CURLE_FTP_COULDNT_STOR_FILE
},
320 {"CURLE_FTP_COULDNT_STOR_FILE", -1},
322 #if HAVE_DECL_CURLE_READ_ERROR
323 {"CURLE_READ_ERROR", CURLE_READ_ERROR
},
325 {"CURLE_READ_ERROR", -1},
327 #if HAVE_DECL_CURLE_OUT_OF_MEMORY
328 {"CURLE_OUT_OF_MEMORY", CURLE_OUT_OF_MEMORY
},
330 {"CURLE_OUT_OF_MEMORY", -1},
332 #if HAVE_DECL_CURLE_OPERATION_TIMEOUTED
333 {"CURLE_OPERATION_TIMEOUTED", CURLE_OPERATION_TIMEOUTED
},
335 {"CURLE_OPERATION_TIMEOUTED", -1},
337 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_ASCII
338 {"CURLE_FTP_COULDNT_SET_ASCII", CURLE_FTP_COULDNT_SET_ASCII
},
340 {"CURLE_FTP_COULDNT_SET_ASCII", -1},
342 #if HAVE_DECL_CURLE_FTP_PORT_FAILED
343 {"CURLE_FTP_PORT_FAILED", CURLE_FTP_PORT_FAILED
},
345 {"CURLE_FTP_PORT_FAILED", -1},
347 #if HAVE_DECL_CURLE_FTP_COULDNT_USE_REST
348 {"CURLE_FTP_COULDNT_USE_REST", CURLE_FTP_COULDNT_USE_REST
},
350 {"CURLE_FTP_COULDNT_USE_REST", -1},
352 #if HAVE_DECL_CURLE_FTP_COULDNT_GET_SIZE
353 {"CURLE_FTP_COULDNT_GET_SIZE", CURLE_FTP_COULDNT_GET_SIZE
},
355 {"CURLE_FTP_COULDNT_GET_SIZE", -1},
357 #if HAVE_DECL_CURLE_HTTP_RANGE_ERROR
358 {"CURLE_HTTP_RANGE_ERROR", CURLE_HTTP_RANGE_ERROR
},
360 {"CURLE_HTTP_RANGE_ERROR", -1},
362 #if HAVE_DECL_CURLE_HTTP_POST_ERROR
363 {"CURLE_HTTP_POST_ERROR", CURLE_HTTP_POST_ERROR
},
365 {"CURLE_HTTP_POST_ERROR", -1},
367 #if HAVE_DECL_CURLE_SSL_CONNECT_ERROR
368 {"CURLE_SSL_CONNECT_ERROR", CURLE_SSL_CONNECT_ERROR
},
370 {"CURLE_SSL_CONNECT_ERROR", -1},
372 #if HAVE_DECL_CURLE_FTP_BAD_DOWNLOAD_RESUME
373 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", CURLE_FTP_BAD_DOWNLOAD_RESUME
},
375 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", -1},
377 #if HAVE_DECL_CURLE_FILE_COULDNT_READ_FILE
378 {"CURLE_FILE_COULDNT_READ_FILE", CURLE_FILE_COULDNT_READ_FILE
},
380 {"CURLE_FILE_COULDNT_READ_FILE", -1},
382 #if HAVE_DECL_CURLE_LDAP_CANNOT_BIND
383 {"CURLE_LDAP_CANNOT_BIND", CURLE_LDAP_CANNOT_BIND
},
385 {"CURLE_LDAP_CANNOT_BIND", -1},
387 #if HAVE_DECL_CURLE_LDAP_SEARCH_FAILED
388 {"CURLE_LDAP_SEARCH_FAILED", CURLE_LDAP_SEARCH_FAILED
},
390 {"CURLE_LDAP_SEARCH_FAILED", -1},
392 #if HAVE_DECL_CURLE_LIBRARY_NOT_FOUND
393 {"CURLE_LIBRARY_NOT_FOUND", CURLE_LIBRARY_NOT_FOUND
},
395 {"CURLE_LIBRARY_NOT_FOUND", -1},
397 #if HAVE_DECL_CURLE_FUNCTION_NOT_FOUND
398 {"CURLE_FUNCTION_NOT_FOUND", CURLE_FUNCTION_NOT_FOUND
},
400 {"CURLE_FUNCTION_NOT_FOUND", -1},
402 #if HAVE_DECL_CURLE_ABORTED_BY_CALLBACK
403 {"CURLE_ABORTED_BY_CALLBACK", CURLE_ABORTED_BY_CALLBACK
},
405 {"CURLE_ABORTED_BY_CALLBACK", -1},
407 #if HAVE_DECL_CURLE_BAD_FUNCTION_ARGUMENT
408 {"CURLE_BAD_FUNCTION_ARGUMENT", CURLE_BAD_FUNCTION_ARGUMENT
},
410 {"CURLE_BAD_FUNCTION_ARGUMENT", -1},
412 #if HAVE_DECL_CURLE_BAD_CALLING_ORDER
413 {"CURLE_BAD_CALLING_ORDER", CURLE_BAD_CALLING_ORDER
},
415 {"CURLE_BAD_CALLING_ORDER", -1},
417 #if HAVE_DECL_CURLE_HTTP_PORT_FAILED
418 {"CURLE_HTTP_PORT_FAILED", CURLE_HTTP_PORT_FAILED
},
420 {"CURLE_HTTP_PORT_FAILED", -1},
422 #if HAVE_DECL_CURLE_BAD_PASSWORD_ENTERED
423 {"CURLE_BAD_PASSWORD_ENTERED", CURLE_BAD_PASSWORD_ENTERED
},
425 {"CURLE_BAD_PASSWORD_ENTERED", -1},
427 #if HAVE_DECL_CURLE_TOO_MANY_REDIRECTS
428 {"CURLE_TOO_MANY_REDIRECTS", CURLE_TOO_MANY_REDIRECTS
},
430 {"CURLE_TOO_MANY_REDIRECTS", -1},
432 #if HAVE_DECL_CURLE_UNKNOWN_TELNET_OPTION
433 {"CURLE_UNKNOWN_TELNET_OPTION", CURLE_UNKNOWN_TELNET_OPTION
},
435 {"CURLE_UNKNOWN_TELNET_OPTION", -1},
437 #if HAVE_DECL_CURLE_TELNET_OPTION_SYNTAX
438 {"CURLE_TELNET_OPTION_SYNTAX", CURLE_TELNET_OPTION_SYNTAX
},
440 {"CURLE_TELNET_OPTION_SYNTAX", -1},
442 #if HAVE_DECL_CURLE_SSL_PEER_CERTIFICATE
443 {"CURLE_SSL_PEER_CERTIFICATE", CURLE_SSL_PEER_CERTIFICATE
},
445 {"CURLE_SSL_PEER_CERTIFICATE", -1},
447 #if HAVE_DECL_CURLE_GOT_NOTHING
448 {"CURLE_GOT_NOTHING", CURLE_GOT_NOTHING
},
450 {"CURLE_GOT_NOTHING", -1},
452 #if HAVE_DECL_CURLE_SSL_ENGINE_NOT_FOUND
453 {"CURLE_SSL_ENGINE_NOT_FOUND", CURLE_SSL_ENGINE_NOTFOUND
},
455 {"CURLE_SSL_ENGINE_NOT_FOUND", -1},
457 #if HAVE_DECL_CURLE_SSL_ENGINE_SET_FAILED
458 {"CURLE_SSL_ENGINE_SET_FAILED", CURLE_SSL_ENGINE_SETFAILED
},
460 {"CURLE_SSL_ENGINE_SET_FAILED", -1},
462 #if HAVE_DECL_CURLE_SEND_ERROR
463 {"CURLE_SEND_ERROR", CURLE_SEND_ERROR
},
465 {"CURLE_SEND_ERROR", -1},
467 #if HAVE_DECL_CURLE_RECV_ERROR
468 {"CURLE_RECV_ERROR", CURLE_RECV_ERROR
},
470 {"CURLE_RECV_ERROR", -1},
472 #if HAVE_DECL_CURLE_SHARE_IN_USE
473 {"CURLE_SHARE_IN_USE", CURLE_SHARE_IN_USE
},
475 {"CURLE_SHARE_IN_USE", -1},
477 #if HAVE_DECL_CURLE_SSL_CERTPROBLEM
478 {"CURLE_SSL_CERTPROBLEN", CURLE_SSL_CERTPROBLEM
},
480 {"CURLE_SSL_CERTPROBLEN", -1},
482 #if HAVE_DECL_CURLE_SSL_CIPHER
483 {"CURLE_SSL_CIPHER", CURLE_SSL_CIPHER
},
485 {"CURLE_SSL_CIPHER", -1},
487 #if HAVE_DECL_CURLE_SSL_CACERT
488 {"CURLE_SSL_CACERT", CURLE_SSL_CACERT
},
490 {"CURLE_SSL_CACERT", -1},
492 #if HAVE_DECL_CURLE_BAD_CONTENT_ENCODING
493 {"CURLE_BAD_CONTENT_ENCODING", CURLE_BAD_CONTENT_ENCODING
},
495 {"CURLE_BAD_CONTENT_ENCODING", -1},
497 #if HAVE_DECL_CURLE_LDAP_INVALID_URL
498 {"CURLE_LDAP_INVALID_URL", CURLE_LDAP_INVALID_URL
},
500 {"CURLE_LDAP_INVALID_URL", -1},
502 #if HAVE_DECL_CURLE_FILESIZE_EXCEEDED
503 {"CURLE_FILESIZE_EXCEEDED", CURLE_FILESIZE_EXCEEDED
},
505 {"CURLE_FILESIZE_EXCEEDED", -1},
507 #if HAVE_DECL_CURLE_FTP_SSL_FAILED
508 {"CURLE_FTP_SSL_FAILED", CURLE_FTP_SSL_FAILED
},
510 {"CURLE_FTP_SSL_FAILED", -1},
512 #if HAVE_DECL_CURLE_SEND_FAIL_REWIND
513 {"CURLE_SEND_FAIL_REWIND", CURLE_SEND_FAIL_REWIND
},
515 {"CURLE_SEND_FAIL_REWIND", -1},
517 #if HAVE_DECL_CURLE_SSL_ENGINE_INITFAILED
518 {"CURLE_SSL_ENGINE_INITFAILED", CURLE_SSL_ENGINE_INITFAILED
},
520 {"CURLE_SSL_ENGINE_INITFAILED", -1},
522 #if HAVE_DECL_CURLE_LOGIN_DENIED
523 {"CURLE_LOGIN_DENIED", CURLE_LOGIN_DENIED
},
525 {"CURLE_LOGIN_DENIED", -1},
527 #if HAVE_DECL_CURLE_TFTP_NOTFOUND
528 {"CURLE_TFTP_NOTFOUND", CURLE_TFTP_NOTFOUND
},
530 {"CURLE_TFTP_NOTFOUND", -1},
532 #if HAVE_DECL_CURLE_TFTP_PERM
533 {"CURLE_TFTP_PERM", CURLE_TFTP_PERM
},
535 {"CURLE_TFTP_PERM", -1},
537 #if HAVE_DECL_CURLE_REMOTE_DISK_FULL
538 {"CURLE_REMOTE_DISK_FULL", CURLE_REMOTE_DISK_FULL
},
540 {"CURLE_REMOTE_DISK_FULL", -1},
542 #if HAVE_DECL_CURLE_TFTP_ILLEGAL
543 {"CURLE_TFTP_ILLEGAL", CURLE_TFTP_ILLEGAL
},
545 {"CURLE_TFTP_ILLEGAL", -1},
547 #if HAVE_DECL_CURLE_TFTP_UNKNOWNID
548 {"CURLE_TFTP_UNKNOWNID", CURLE_TFTP_UNKNOWNID
},
550 {"CURLE_TFTP_UNKNOWNID", -1},
552 #if HAVE_DECL_CURLE_REMOTE_FILE_EXISTS
553 {"CURLE_REMOTE_FILE_EXISTS", CURLE_REMOTE_FILE_EXISTS
},
555 {"CURLE_REMOTE_FILE_EXISTS", -1},
557 #if HAVE_DECL_CURLE_TFTP_NOSUCHUSER
558 {"CURLE_TFTP_NOSUCHUSER", CURLE_TFTP_NOSUCHUSER
},
560 {"CURLE_TFTP_NOSUCHUSER", -1},
562 #if HAVE_DECL_CURLE_CONV_FAILED
563 {"CURLE_CONV_FAILED", CURLE_CONV_FAILED
},
565 {"CURLE_CONV_FAILED", -1},
567 #if HAVE_DECL_CURLE_CONV_REQUIRED
568 {"CURLE_CONV_REQUIRED", CURLE_CONV_REQUIRED
},
570 {"CURLE_CONV_REQUIRED", -1},
572 #if HAVE_DECL_CURLE_SSL_CACERT_BADFILE
573 {"CURLE_SSL_CACERT_BADFILE", CURLE_SSL_CACERT_BADFILE
},
575 {"CURLE_SSL_CACERT_BADFILE", -1},
577 #if HAVE_DECL_CURLE_REMOTE_FILE_NOT_FOUND
578 {"CURLE_REMOTE_FILE_NOT_FOUND", CURLE_REMOTE_FILE_NOT_FOUND
},
580 {"CURLE_REMOTE_FILE_NOT_FOUND", -1},
582 #if HAVE_DECL_CURLE_SSH
583 {"CURLE_SSH", CURLE_SSH
},
587 #if HAVE_DECL_CURLE_SSL_SHUTDOWN_FAILED
588 {"CURLE_SSL_SHUTDOWN_FAILED", CURLE_SSL_SHUTDOWN_FAILED
},
590 {"CURLE_SSL_SHUTDOWN_FAILED", -1},
592 #if HAVE_DECL_CURLE_AGAIN
593 {"CURLE_AGAIN", CURLE_AGAIN
},
597 {"CURLE_OK", CURLE_OK
},
601 typedef struct CURLOptionMapping CURLOptionMapping
;
603 struct CURLOptionMapping
605 void (*optionHandler
)(Connection
*, value
);
610 CURLOptionMapping unimplementedOptionMap
[] =
612 {NULL
, "CURLOPT_STDERR", CURLOPT_STDERR
},
616 static void handleWriteFunction(Connection
*, value
);
617 static void handleReadFunction(Connection
*, value
);
618 static void handleInFileSize(Connection
*, value
);
619 static void handleURL(Connection
*, value
);
620 static void handleProxy(Connection
*, value
);
621 static void handleProxyPort(Connection
*, value
);
622 static void handleHTTPProxyTunnel(Connection
*, value
);
623 static void handleVerbose(Connection
*, value
);
624 static void handleHeader(Connection
*, value
);
625 static void handleNoProgress(Connection
*, value
);
626 static void handleNoSignal(Connection
*, value
);
627 static void handleNoBody(Connection
*, value
);
628 static void handleFailOnError(Connection
*, value
);
629 static void handleUpload(Connection
*, value
);
630 static void handlePost(Connection
*, value
);
631 static void handleFTPListOnly(Connection
*, value
);
632 static void handleFTPAppend(Connection
*, value
);
633 static void handleNETRC(Connection
*, value
);
634 static void handleEncoding(Connection
*, value
);
635 static void handleFollowLocation(Connection
*, value
);
636 static void handleTransferText(Connection
*, value
);
637 static void handlePut(Connection
*, value
);
638 static void handleUserPwd(Connection
*, value
);
639 static void handleProxyUserPwd(Connection
*, value
);
640 static void handleRange(Connection
*, value
);
641 static void handleErrorBuffer(Connection
*, value
);
642 static void handleTimeout(Connection
*, value
);
643 static void handlePostFields(Connection
*, value
);
644 static void handlePostFieldSize(Connection
*, value
);
645 static void handleReferer(Connection
*, value
);
646 static void handleUserAgent(Connection
*, value
);
647 static void handleFTPPort(Connection
*, value
);
648 static void handleLowSpeedLimit(Connection
*, value
);
649 static void handleLowSpeedTime(Connection
*, value
);
650 static void handleResumeFrom(Connection
*, value
);
651 static void handleCookie(Connection
*, value
);
652 static void handleHTTPHeader(Connection
*, value
);
653 static void handleHTTPPost(Connection
*, value
);
654 static void handleSSLCert(Connection
*, value
);
655 static void handleSSLCertType(Connection
*, value
);
656 static void handleSSLCertPasswd(Connection
*, value
);
657 static void handleSSLKey(Connection
*, value
);
658 static void handleSSLKeyType(Connection
*, value
);
659 static void handleSSLKeyPasswd(Connection
*, value
);
660 static void handleSSLEngine(Connection
*, value
);
661 static void handleSSLEngineDefault(Connection
*, value
);
662 static void handleCRLF(Connection
*, value
);
663 static void handleQuote(Connection
*, value
);
664 static void handlePostQuote(Connection
*, value
);
665 static void handleHeaderFunction(Connection
*, value
);
666 static void handleCookieFile(Connection
*, value
);
667 static void handleSSLVersion(Connection
*, value
);
668 static void handleTimeCondition(Connection
*, value
);
669 static void handleTimeValue(Connection
*, value
);
670 static void handleCustomRequest(Connection
*, value
);
671 static void handleInterface(Connection
*, value
);
672 static void handleKRB4Level(Connection
*, value
);
673 static void handleProgressFunction(Connection
*, value
);
674 static void handleSSLVerifyPeer(Connection
*, value
);
675 static void handleCAInfo(Connection
*, value
);
676 static void handleCAPath(Connection
*, value
);
677 static void handleFileTime(Connection
*, value
);
678 static void handleMaxRedirs(Connection
*, value
);
679 static void handleMaxConnects(Connection
*, value
);
680 static void handleClosePolicy(Connection
*, value
);
681 static void handleFreshConnect(Connection
*, value
);
682 static void handleForbidReuse(Connection
*, value
);
683 static void handleRandomFile(Connection
*, value
);
684 static void handleEGDSocket(Connection
*, value
);
685 static void handleConnectTimeout(Connection
*, value
);
686 static void handleHTTPGet(Connection
*, value
);
687 static void handleSSLVerifyHost(Connection
*, value
);
688 static void handleCookieJar(Connection
*, value
);
689 static void handleSSLCipherList(Connection
*, value
);
690 static void handleHTTPVersion(Connection
*, value
);
691 static void handleFTPUseEPSV(Connection
*, value
);
692 static void handleDNSCacheTimeout(Connection
*, value
);
693 static void handleDNSUseGlobalCache(Connection
*, value
);
694 static void handleDebugFunction(Connection
*, value
);
695 static void handlePrivate(Connection
*, value
);
696 static void handleHTTP200Aliases(Connection
*, value
);
697 static void handleUnrestrictedAuth(Connection
*, value
);
698 static void handleFTPUseEPRT(Connection
*, value
);
699 static void handleHTTPAuth(Connection
*, value
);
700 static void handleFTPCreateMissingDirs(Connection
*, value
);
701 static void handleProxyAuth(Connection
*, value
);
702 static void handleFTPResponseTimeout(Connection
*, value
);
703 static void handleIPResolve(Connection
*, value
);
704 static void handleMaxFileSize(Connection
*, value
);
705 static void handleInFileSizeLarge(Connection
*, value
);
706 static void handleResumeFromLarge(Connection
*, value
);
707 static void handleMaxFileSizeLarge(Connection
*, value
);
708 static void handleNETRCFile(Connection
*, value
);
709 static void handleFTPSSL(Connection
*, value
);
710 static void handlePostFieldSizeLarge(Connection
*, value
);
711 static void handleTCPNoDelay(Connection
*, value
);
712 static void handleFTPSSLAuth(Connection
*, value
);
713 static void handleIOCTLFunction(Connection
*, value
);
714 static void handleFTPAccount(Connection
*, value
);
715 static void handleCookieList(Connection
*, value
);
716 static void handleIgnoreContentLength(Connection
*, value
);
717 static void handleFTPSkipPASVIP(Connection
*, value
);
718 static void handleFTPFileMethod(Connection
*, value
);
719 static void handleLocalPort(Connection
*, value
);
720 static void handleLocalPortRange(Connection
*, value
);
721 static void handleConnectOnly(Connection
*, value
);
722 static void handleMaxSendSpeedLarge(Connection
*, value
);
723 static void handleMaxRecvSpeedLarge(Connection
*, value
);
724 static void handleFTPAlternativeToUser(Connection
*, value
);
725 static void handleSSLSessionIdCache(Connection
*, value
);
726 static void handleSSHAuthTypes(Connection
*, value
);
727 static void handleSSHPublicKeyFile(Connection
*, value
);
728 static void handleSSHPrivateKeyFile(Connection
*, value
);
729 static void handleFTPSSLCCC(Connection
*, value
);
730 static void handleTimeoutMS(Connection
*, value
);
731 static void handleConnectTimeoutMS(Connection
*, value
);
732 static void handleHTTPTransferDecoding(Connection
*, value
);
733 static void handleHTTPContentDecoding(Connection
*, value
);
734 static void handleNewFilePerms(Connection
*, value
);
735 static void handleNewDirectoryPerms(Connection
*, value
);
736 static void handlePost301(Connection
*, value
);
737 static void handleSSHHostPublicKeyMD5(Connection
*, value
);
738 static void handleCopyPostFields(Connection
*, value
);
739 static void handleProxyTransferMode(Connection
*, value
);
740 static void handleSeekFunction(Connection
*, value
);
741 static void handleAutoReferer(Connection
*, value
);
742 static void handleOpenSocketFunction(Connection
*, value
);
743 static void handleProxyType(Connection
*, value
);
744 static void handleProtocols(Connection
*, value
);
745 static void handleRedirProtocols(Connection
*, value
);
746 static void handleResolve(Connection
*, value
);
747 static void handleDnsServers(Connection
*, value
);
749 CURLOptionMapping implementedOptionMap
[] =
751 {handleWriteFunction
, "CURLOPT_WRITEFUNCTION", CURLOPT_WRITEFUNCTION
},
752 {handleReadFunction
, "CURLOPT_READFUNCTION", CURLOPT_READFUNCTION
},
753 {handleInFileSize
, "CURLOPT_INFILESIZE", CURLOPT_INFILESIZE
},
754 {handleURL
, "CURLOPT_URL", CURLOPT_URL
},
755 {handleProxy
, "CURLOPT_PROXY", CURLOPT_PROXY
},
756 {handleProxyPort
, "CURLOPT_PROXYPORT", CURLOPT_PROXYPORT
},
757 {handleHTTPProxyTunnel
, "CURLOPT_HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL
},
758 {handleVerbose
, "CURLOPT_VERBOSE", CURLOPT_VERBOSE
},
759 {handleHeader
, "CURLOPT_HEADER", CURLOPT_HEADER
},
760 {handleNoProgress
, "CURLOPT_NOPROGRESS", CURLOPT_NOPROGRESS
},
761 #if HAVE_DECL_CURLOPT_NOSIGNAL
762 {handleNoSignal
, "CURLOPT_NOSIGNAL", CURLOPT_NOSIGNAL
},
764 {handleNoSignal
, "CURLOPT_NOSIGNAL", 0},
766 {handleNoBody
, "CURLOPT_NOBODY", CURLOPT_NOBODY
},
767 {handleFailOnError
, "CURLOPT_FAILONERROR", CURLOPT_FAILONERROR
},
768 {handleUpload
, "CURLOPT_UPLOAD", CURLOPT_UPLOAD
},
769 {handlePost
, "CURLOPT_POST", CURLOPT_POST
},
770 {handleFTPListOnly
, "CURLOPT_FTPLISTONLY", CURLOPT_FTPLISTONLY
},
771 {handleFTPAppend
, "CURLOPT_FTPAPPEND", CURLOPT_FTPAPPEND
},
772 {handleNETRC
, "CURLOPT_NETRC", CURLOPT_NETRC
},
773 #if HAVE_DECL_CURLOPT_ENCODING
774 {handleEncoding
, "CURLOPT_ENCODING", CURLOPT_ENCODING
},
776 {handleEncoding
, "CURLOPT_ENCODING", 0},
778 {handleFollowLocation
, "CURLOPT_FOLLOWLOCATION", CURLOPT_FOLLOWLOCATION
},
779 {handleTransferText
, "CURLOPT_TRANSFERTEXT", CURLOPT_TRANSFERTEXT
},
780 {handlePut
, "CURLOPT_PUT", CURLOPT_PUT
},
781 {handleUserPwd
, "CURLOPT_USERPWD", CURLOPT_USERPWD
},
782 {handleProxyUserPwd
, "CURLOPT_PROXYUSERPWD", CURLOPT_PROXYUSERPWD
},
783 {handleRange
, "CURLOPT_RANGE", CURLOPT_RANGE
},
784 {handleErrorBuffer
, "CURLOPT_ERRORBUFFER", CURLOPT_ERRORBUFFER
},
785 {handleTimeout
, "CURLOPT_TIMEOUT", CURLOPT_TIMEOUT
},
786 {handlePostFields
, "CURLOPT_POSTFIELDS", CURLOPT_POSTFIELDS
},
787 {handlePostFieldSize
, "CURLOPT_POSTFIELDSIZE", CURLOPT_POSTFIELDSIZE
},
788 {handleReferer
, "CURLOPT_REFERER", CURLOPT_REFERER
},
789 {handleUserAgent
, "CURLOPT_USERAGENT", CURLOPT_USERAGENT
},
790 {handleFTPPort
, "CURLOPT_FTPPORT", CURLOPT_FTPPORT
},
791 {handleLowSpeedLimit
, "CURLOPT_LOW_SPEED_LIMIT", CURLOPT_LOW_SPEED_LIMIT
},
792 {handleLowSpeedTime
, "CURLOPT_LOW_SPEED_TIME", CURLOPT_LOW_SPEED_TIME
},
793 {handleResumeFrom
, "CURLOPT_RESUME_FROM", CURLOPT_RESUME_FROM
},
794 {handleCookie
, "CURLOPT_COOKIE", CURLOPT_COOKIE
},
795 {handleHTTPHeader
, "CURLOPT_HTTPHEADER", CURLOPT_HTTPHEADER
},
796 {handleHTTPPost
, "CURLOPT_HTTPPOST", CURLOPT_HTTPPOST
},
797 {handleSSLCert
, "CURLOPT_SSLCERT", CURLOPT_SSLCERT
},
798 {handleSSLCertType
, "CURLOPT_SSLCERTTYPE", CURLOPT_SSLCERTTYPE
},
799 {handleSSLCertPasswd
, "CURLOPT_SSLCERTPASSWD", CURLOPT_SSLCERTPASSWD
},
800 {handleSSLKey
, "CURLOPT_SSLKEY", CURLOPT_SSLKEY
},
801 {handleSSLKeyType
, "CURLOPT_SSLKEYTYPE", CURLOPT_SSLKEYTYPE
},
802 {handleSSLKeyPasswd
, "CURLOPT_SSLKEYPASSWD", CURLOPT_SSLKEYPASSWD
},
803 {handleSSLEngine
, "CURLOPT_SSLENGINE", CURLOPT_SSLENGINE
},
804 {handleSSLEngineDefault
, "CURLOPT_SSLENGINE_DEFAULT", CURLOPT_SSLENGINE_DEFAULT
},
805 {handleCRLF
, "CURLOPT_CRLF", CURLOPT_CRLF
},
806 {handleQuote
, "CURLOPT_QUOTE", CURLOPT_QUOTE
},
807 {handlePostQuote
, "CURLOPT_POSTQUOTE", CURLOPT_POSTQUOTE
},
808 {handleHeaderFunction
, "CURLOPT_HEADERFUNCTION", CURLOPT_HEADERFUNCTION
},
809 {handleCookieFile
, "CURLOPT_COOKIEFILE", CURLOPT_COOKIEFILE
},
810 {handleSSLVersion
, "CURLOPT_SSLVERSION", CURLOPT_SSLVERSION
},
811 {handleTimeCondition
, "CURLOPT_TIMECONDITION", CURLOPT_TIMECONDITION
},
812 {handleTimeValue
, "CURLOPT_TIMEVALUE", CURLOPT_TIMEVALUE
},
813 {handleCustomRequest
, "CURLOPT_CUSTOMREQUEST", CURLOPT_CUSTOMREQUEST
},
814 {handleInterface
, "CURLOPT_INTERFACE", CURLOPT_INTERFACE
},
815 {handleKRB4Level
, "CURLOPT_KRB4LEVEL", CURLOPT_KRB4LEVEL
},
816 {handleProgressFunction
, "CURLOPT_PROGRESSFUNCTION", CURLOPT_PROGRESSFUNCTION
},
817 {handleSSLVerifyPeer
, "CURLOPT_SSLVERIFYPEER", CURLOPT_SSL_VERIFYPEER
},
818 {handleCAInfo
, "CURLOPT_CAINFO", CURLOPT_CAINFO
},
819 {handleCAPath
, "CURLOPT_CAPATH", CURLOPT_CAPATH
},
820 {handleFileTime
, "CURLOPT_FILETIME", CURLOPT_FILETIME
},
821 {handleMaxRedirs
, "CURLOPT_MAXREDIRS", CURLOPT_MAXREDIRS
},
822 {handleMaxConnects
, "CURLOPT_MAXCONNECTS", CURLOPT_MAXCONNECTS
},
823 {handleClosePolicy
, "CURLOPT_CLOSEPOLICY", CURLOPT_CLOSEPOLICY
},
824 {handleFreshConnect
, "CURLOPT_FRESH_CONNECT", CURLOPT_FRESH_CONNECT
},
825 {handleForbidReuse
, "CURLOPT_FORBID_REUSE", CURLOPT_FORBID_REUSE
},
826 {handleRandomFile
, "CURLOPT_RANDOM_FILE", CURLOPT_RANDOM_FILE
},
827 {handleEGDSocket
, "CURLOPT_EGDSOCKET", CURLOPT_EGDSOCKET
},
828 {handleConnectTimeout
, "CURLOPT_CONNECTTIMEOUT", CURLOPT_CONNECTTIMEOUT
},
829 {handleHTTPGet
, "CURLOPT_HTTPGET", CURLOPT_HTTPGET
},
830 {handleSSLVerifyHost
, "CURLOPT_SSL_VERIFYHOST", CURLOPT_SSL_VERIFYHOST
},
831 {handleCookieJar
, "CURLOPT_COOKIEJAR", CURLOPT_COOKIEJAR
},
832 {handleSSLCipherList
, "CURLOPT_SSL_CIPHERLIST", CURLOPT_SSL_CIPHER_LIST
},
833 {handleHTTPVersion
, "CURLOPT_HTTP_VERSION", CURLOPT_HTTP_VERSION
},
834 {handleFTPUseEPSV
, "CURLOPT_FTP_USE_EPSV", CURLOPT_FTP_USE_EPSV
},
835 {handleDNSCacheTimeout
, "CURLOPT_DNS_CACHE_TIMEOUT", CURLOPT_DNS_CACHE_TIMEOUT
},
836 {handleDNSUseGlobalCache
, "CURLOPT_DNS_USE_GLOBAL_CACHE", CURLOPT_DNS_USE_GLOBAL_CACHE
},
837 {handleDebugFunction
, "CURLOPT_DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION
},
838 #if HAVE_DECL_CURLOPT_PRIVATE
839 {handlePrivate
, "CURLOPT_PRIVATE", CURLOPT_PRIVATE
},
841 {handlePrivate
, "CURLOPT_PRIVATE", 0},
843 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
844 {handleHTTP200Aliases
, "CURLOPT_HTTP200ALIASES", CURLOPT_HTTP200ALIASES
},
846 {handleHTTP200Aliases
, "CURLOPT_HTTP200ALIASES", 0},
848 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
849 {handleUnrestrictedAuth
, "CURLOPT_UNRESTRICTED_AUTH", CURLOPT_UNRESTRICTED_AUTH
},
851 {handleUnrestrictedAuth
, "CURLOPT_UNRESTRICTED_AUTH", 0},
853 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
854 {handleFTPUseEPRT
, "CURLOPT_FTP_USE_EPRT", CURLOPT_FTP_USE_EPRT
},
856 {handleFTPUseEPRT
, "CURLOPT_FTP_USE_EPRT", 0},
858 #if HAVE_DECL_CURLOPT_HTTPAUTH
859 {handleHTTPAuth
, "CURLOPT_HTTPAUTH", CURLOPT_HTTPAUTH
},
861 {handleHTTPAuth
, "CURLOPT_HTTPAUTH", 0},
863 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
864 {handleFTPCreateMissingDirs
, "CURLOPT_FTP_CREATE_MISSING_DIRS", CURLOPT_FTP_CREATE_MISSING_DIRS
},
866 {handleFTPCreateMissingDirs
, "CURLOPT_FTP_CREATE_MISSING_DIRS", 0},
868 #if HAVE_DECL_CURLOPT_PROXYAUTH
869 {handleProxyAuth
, "CURLOPT_PROXYAUTH", CURLOPT_PROXYAUTH
},
871 {handleProxyAuth
, "CURLOPT_PROXYAUTH", 0},
873 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
874 {handleFTPResponseTimeout
, "CURLOPT_FTP_RESPONSE_TIMEOUT", CURLOPT_FTP_RESPONSE_TIMEOUT
},
876 {handleFTPResponseTimeout
, "CURLOPT_FTP_RESPONSE_TIMEOUT", 0},
878 #if HAVE_DECL_CURLOPT_IPRESOLVE
879 {handleIPResolve
, "CURLOPT_IPRESOLVE", CURLOPT_IPRESOLVE
},
881 {handleIPResolve
, "CURLOPT_IPRESOLVE", 0},
883 #if HAVE_DECL_CURLOPT_MAXFILESIZE
884 {handleMaxFileSize
, "CURLOPT_MAXFILESIZE", CURLOPT_MAXFILESIZE
},
886 {handleMaxFileSize
, "CURLOPT_MAXFILESIZE", 0},
888 #if HAVE_DECL_CURLOPT_INFILSIZE_LARGE
889 {handleInFileSizeLarge
, "CURLOPT_INFILESIZE_LARGE", CURLOPT_INFILESIZE_LARGE
},
891 {handleInFileSizeLarge
, "CURLOPT_INFILESIZE_LARGE", 0},
893 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
894 {handleResumeFromLarge
, "CURLOPT_RESUME_FROM_LARGE", CURLOPT_RESUME_FROM_LARGE
},
896 {handleResumeFromLarge
, "CURLOPT_RESUME_FROM_LARGE", 0},
898 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
899 {handleMaxFileSizeLarge
, "CURLOPT_MAXFILESIZE_LARGE", CURLOPT_MAXFILESIZE_LARGE
},
901 {handleMaxFileSizeLarge
, "CURLOPT_MAXFILESIZE_LARGE", 0},
903 #if HAVE_DECL_CURLOPT_NETRC_FILE
904 {handleNETRCFile
, "CURLOPT_NETRC_FILE", CURLOPT_NETRC_FILE
},
906 {handleNETRCFile
, "CURLOPT_NETRC_FILE", 0},
908 #if HAVE_DECL_CURLOPT_FTP_SSL
909 {handleFTPSSL
, "CURLOPT_FTP_SSL", CURLOPT_FTP_SSL
},
911 {handleFTPSSL
, "CURLOPT_FTP_SSL", 0},
913 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
914 {handlePostFieldSizeLarge
, "CURLOPT_POSTFIELDSIZE_LARGE", CURLOPT_POSTFIELDSIZE_LARGE
},
916 {handlePostFieldSizeLarge
, "CURLOPT_POSTFIELDSIZE_LARGE", 0},
918 #if HAVE_DECL_CURLOPT_TCP_NODELAY
919 {handleTCPNoDelay
, "CURLOPT_TCP_NODELAY", CURLOPT_TCP_NODELAY
},
921 {handleTCPNoDelay
, "CURLOPT_TCP_NODELAY", 0},
923 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
924 {handleFTPSSLAuth
, "CURLOPT_FTPSSLAUTH", CURLOPT_FTPSSLAUTH
},
926 {handleFTPSSLAuth
, "CURLOPT_FTPSSLAUTH", 0},
928 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
929 {handleIOCTLFunction
, "CURLOPT_IOCTLFUNCTION", CURLOPT_IOCTLFUNCTION
},
931 {handleIOCTLFunction
, "CURLOPT_IOCTLFUNCTION", 0},
933 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
934 {handleFTPAccount
, "CURLOPT_FTP_ACCOUNT", CURLOPT_FTP_ACCOUNT
},
936 {handleFTPAccount
, "CURLOPT_FTP_ACCOUNT", 0},
938 #if HAVE_DECL_CURLOPT_COOKIELIST
939 {handleCookieList
, "CURLOPT_COOKIELIST", CURLOPT_COOKIELIST
},
941 {handleCookieList
, "CURLOPT_COOKIELIST", 0},
943 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
944 {handleIgnoreContentLength
, "CURLOPT_IGNORE_CONTENT_LENGTH", CURLOPT_IGNORE_CONTENT_LENGTH
},
946 {handleIgnoreContentLength
, "CURLOPT_IGNORE_CONTENT_LENGTH", 0},
948 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
949 {handleFTPSkipPASVIP
, "CURLOPT_FTP_SKIP_PASV_IP", CURLOPT_FTP_SKIP_PASV_IP
},
951 {handleFTPSkipPASVIP
, "CURLOPT_FTP_SKIP_PASV_IP", 0},
953 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
954 {handleFTPFileMethod
, "CURLOPT_FTP_FILEMETHOD", CURLOPT_FTP_FILEMETHOD
},
956 {handleFTPFileMethod
, "CURLOPT_FTP_FILEMETHOD", 0},
958 #if HAVE_DECL_CURLOPT_LOCALPORT
959 {handleLocalPort
, "CURLOPT_LOCALPORT", CURLOPT_LOCALPORT
},
961 {handleLocalPort
, "CURLOPT_LOCALPORT", 0},
963 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
964 {handleLocalPortRange
, "CURLOPT_LOCALPORTRANGE", CURLOPT_LOCALPORTRANGE
},
966 {handleLocalPortRange
, "CURLOPT_LOCALPORTRANGE", 0},
968 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
969 {handleConnectOnly
, "CURLOPT_CONNECT_ONLY", CURLOPT_CONNECT_ONLY
},
971 {handleConnectOnly
, "CURLOPT_CONNECT_ONLY", 0},
973 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
974 {handleMaxSendSpeedLarge
, "CURLOPT_MAX_SEND_SPEED_LARGE", CURLOPT_MAX_SEND_SPEED_LARGE
},
976 {handleMaxSendSpeedLarge
, "CURLOPT_MAX_SEND_SPEED_LARGE", 0},
978 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
979 {handleMaxRecvSpeedLarge
, "CURLOPT_MAX_RECV_SPEED_LARGE", CURLOPT_MAX_RECV_SPEED_LARGE
},
981 {handleMaxRecvSpeedLarge
, "CURLOPT_MAX_RECV_SPEED_LARGE", 0},
983 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
984 {handleFTPAlternativeToUser
, "CURLOPT_FTP_ALTERNATIVE_TO_USER", CURLOPT_FTP_ALTERNATIVE_TO_USER
},
986 {handleFTPAlternativeToUser
, "CURLOPT_FTP_ALTERMATIVE_TO_USER", 0},
988 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
989 {handleSSLSessionIdCache
, "CURLOPT_SSL_SESSIONID_CACHE", CURLOPT_SSL_SESSIONID_CACHE
},
991 {handleSSLSessionIdCache
, "CURLOPT_SSL_SESSIONID_CACHE", 0},
993 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
994 {handleSSHAuthTypes
, "CURLOPT_SSH_AUTH_TYPES", CURLOPT_SSH_AUTH_TYPES
},
996 {handleSSHAuthTypes
, "CURLOPT_SSH_AUTH_TYPES", 0},
998 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
999 {handleSSHPublicKeyFile
, "CURLOPT_SSH_PUBLIC_KEYFILE", CURLOPT_SSH_PUBLIC_KEYFILE
},
1001 {handleSSHPublicKeyFile
, "CURLOPT_SSH_PUBLIC_KEYFILE", 0},
1003 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
1004 {handleSSHPrivateKeyFile
, "CURLOPT_SSH_PRIVATE_KEYFILE", CURLOPT_SSH_PRIVATE_KEYFILE
},
1006 {handleSSHPrivateKeyFile
, "CURLOPT_SSH_PRIVATE_KEYFILE", 0},
1008 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
1009 {handleFTPSSLCCC
, "CURLOPT_FTP_SSL_CCC", CURLOPT_FTP_SSL_CCC
},
1011 {handleFTPSSLCCC
, "CURLOPT_FTP_SSL_CCC", 0},
1013 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
1014 {handleTimeoutMS
, "CURLOPT_TIMEOUT_MS", CURLOPT_TIMEOUT_MS
},
1016 {handleTimeoutMS
, "CURLOPT_TIMEOUT_MS", 0},
1018 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
1019 {handleConnectTimeoutMS
, "CURLOPT_CONNECTTIMEOUT_MS", CURLOPT_CONNECTTIMEOUT_MS
},
1021 {handleConnectTimeoutMS
, "CURLOPT_CONNECTTIMEOUT_MS", 0},
1023 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
1024 {handleHTTPTransferDecoding
, "CURLOPT_HTTP_TRANSFER_DECODING", CURLOPT_HTTP_TRANSFER_DECODING
},
1026 {handleHTTPTransferDecoding
, "CURLOPT_HTTP_TRANSFER_DECODING", 0},
1028 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
1029 {handleHTTPContentDecoding
, "CURLOPT_HTTP_CONTENT_DECODING", CURLOPT_HTTP_CONTENT_DECODING
},
1031 {handleHTTPContentDecoding
, "CURLOPT_HTTP_CONTENT_DECODING", 0},
1033 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
1034 {handleNewFilePerms
, "CURLOPT_NEW_FILE_PERMS", CURLOPT_NEW_FILE_PERMS
},
1036 {handleNewFilePerms
, "CURLOPT_NEW_FILE_PERMS", 0},
1038 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
1039 {handleNewDirectoryPerms
, "CURLOPT_NEW_DIRECTORY_PERMS", CURLOPT_NEW_DIRECTORY_PERMS
},
1041 {handleNewDirectoryPerms
, "CURLOPT_NEW_DIRECTORY_PERMS", 0},
1043 #if HAVE_DECL_CURLOPT_POST301
1044 {handlePost301
, "CURLOPT_POST301", CURLOPT_POST301
},
1046 {handlePost301
, "CURLOPT_POST301", 0},
1048 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEY_MD5
1049 {handleSSHHostPublicKeyMD5
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5", CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
},
1051 {handleSSHHostPublicKeyMD5
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5", 0},
1053 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
1054 {handleCopyPostFields
, "CURLOPT_COPYPOSTFIELDS", CURLOPT_COPYPOSTFIELDS
},
1056 {handleCopyPostFields
, "CURLOPT_COPYPOSTFIELDS", 0},
1058 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
1059 {handleProxyTransferMode
, "CURLOPT_PROXY_TRANSFER_MODE", CURLOPT_PROXY_TRANSFER_MODE
},
1061 {handleProxyTransferMode
, "CURLOPT_PROXY_TRANSFER_MODE", 0},
1063 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1064 {handleSeekFunction
, "CURLOPT_SEEKFUNCTION", CURLOPT_SEEKFUNCTION
},
1066 {handleSeekFunction
, "CURLOPT_SEEKFUNCTION", 0},
1068 #if HAVE_DECL_CURLOPT_AUTOREFERER
1069 {handleAutoReferer
, "CURLOPT_AUTOREFERER", CURLOPT_AUTOREFERER
},
1071 {handleAutoReferer
, "CURLOPT_AUTOREFERER", 0},
1073 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1074 {handleOpenSocketFunction
, "CURLOPT_OPENSOCKETFUNCTION", CURLOPT_OPENSOCKETFUNCTION
},
1076 {handleOpenSocketFunction
, "CURLOPT_OPENSOCKETFUNCTION", 0},
1078 #if HAVE_DECL_CURLOPT_PROXYTYPE
1079 {handleProxyType
, "CURLOPT_PROXYTYPE", CURLOPT_PROXYTYPE
},
1081 {handleProxyType
, "CURLOPT_PROXYTYPE", 0},
1083 #if HAVE_DECL_CURLOPT_PROTOCOLS
1084 {handleProtocols
, "CURLOPT_PROTOCOLS", CURLOPT_PROTOCOLS
},
1086 {handleProtocols
, "CURLOPT_PROTOCOLS", 0},
1088 #if HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
1089 {handleRedirProtocols
, "CURLOPT_REDIR_PROTOCOLS", CURLOPT_REDIR_PROTOCOLS
},
1091 {handleRedirProtocols
, "CURLOPT_REDIR_PROTOCOLS", 0},
1093 #if HAVE_DECL_CURLOPT_RESOLVE
1094 {handleResolve
, "CURLOPT_RESOLVE", CURLOPT_RESOLVE
},
1096 {handleResolve
, "CURLOPT_RESOLVE", 0},
1098 #if HAVE_DECL_CURLOPT_DNS_SERVERS
1099 {handleDnsServers
, "CURLOPT_DNS_SERVERS", CURLOPT_DNS_SERVERS
},
1101 {handleDnsServers
, "CURLOPT_DNS_SERVERS", 0},
1105 static char *findOption(CURLOptionMapping optionMap
[],
1108 return optionMap
[option
].name
;
1111 static void free_curl_slist(struct curl_slist
*slist
)
1116 curl_slist_free_all(slist
);
1119 static void raiseError(Connection
*conn
, CURLcode code
)
1122 CAMLlocal1(exceptionData
);
1124 char *errorString
= "Unknown Error";
1127 for (i
= 0; errorMap
[i
].name
!= NULL
; i
++)
1129 if (errorMap
[i
].error
== code
)
1131 errorString
= errorMap
[i
].name
;
1136 exceptionData
= caml_alloc(3, 0);
1138 Store_field(exceptionData
, 0, Val_int(code
));
1139 Store_field(exceptionData
, 1, Val_int(code
));
1140 Store_field(exceptionData
, 2, copy_string(errorString
));
1142 if (conn
!= NULL
&& conn
->errorBuffer
!= NULL
)
1144 Store_field(Field(conn
->ocamlValues
, OcamlErrorBuffer
), 0,
1145 copy_string(conn
->errorBuffer
));
1148 exception
= caml_named_value("CurlException");
1150 if (exception
== NULL
)
1151 caml_failwith("CurlException not registered");
1153 raise_with_arg(*exception
, exceptionData
);
1158 static void resetOcamlValues(Connection
* connection
)
1162 for (i
= 0; i
< OcamlValuesSize
; i
++)
1163 Store_field(connection
->ocamlValues
, i
, Val_unit
);
1166 static Connection
*newConnection(void)
1168 Connection
*connection
;
1170 connection
= (Connection
*)malloc(sizeof(Connection
));
1172 enter_blocking_section();
1173 connection
->connection
= curl_easy_init();
1174 leave_blocking_section();
1176 connection
->next
= NULL
;
1177 connection
->prev
= NULL
;
1179 if (connectionList
.tail
== NULL
)
1181 connectionList
.tail
= connection
;
1182 connectionList
.head
= connection
;
1186 connection
->prev
= connectionList
.head
;
1187 connectionList
.head
->next
= connection
;
1188 connectionList
.head
= connection
;
1191 connection
->ocamlValues
= alloc(OcamlValuesSize
, 0);
1192 resetOcamlValues(connection
);
1193 register_global_root(&connection
->ocamlValues
);
1195 connection
->url
= NULL
;
1196 connection
->proxy
= NULL
;
1197 connection
->userPwd
= NULL
;
1198 connection
->proxyUserPwd
= NULL
;
1199 connection
->range
= NULL
;
1200 connection
->errorBuffer
= NULL
;
1201 connection
->postFields
= NULL
;
1202 connection
->postFieldSize
= -1;
1203 connection
->referer
= NULL
;
1204 connection
->userAgent
= NULL
;
1205 connection
->ftpPort
= NULL
;
1206 connection
->cookie
= NULL
;
1207 connection
->httpHeader
= NULL
;
1208 connection
->httpPostFirst
= NULL
;
1209 connection
->httpPostLast
= NULL
;
1210 connection
->httpPostStrings
= NULL
;
1211 connection
->sslCert
= NULL
;
1212 connection
->sslCertType
= NULL
;
1213 connection
->sslCertPasswd
= NULL
;
1214 connection
->sslKey
= NULL
;
1215 connection
->sslKeyType
= NULL
;
1216 connection
->sslKeyPasswd
= NULL
;
1217 connection
->sslEngine
= NULL
;
1218 connection
->quote
= NULL
;
1219 connection
->postQuote
= NULL
;
1220 connection
->cookieFile
= NULL
;
1221 connection
->customRequest
= NULL
;
1222 connection
->interface
= NULL
;
1223 connection
->caInfo
= NULL
;
1224 connection
->caPath
= NULL
;
1225 connection
->randomFile
= NULL
;
1226 connection
->egdSocket
= NULL
;
1227 connection
->cookieJar
= NULL
;
1228 connection
->sslCipherList
= NULL
;
1229 connection
->private = NULL
;
1230 connection
->http200Aliases
= NULL
;
1231 connection
->netrcFile
= NULL
;
1232 connection
->ftpaccount
= NULL
;
1233 connection
->cookielist
= NULL
;
1234 connection
->ftpAlternativeToUser
= NULL
;
1235 connection
->sshPublicKeyFile
= NULL
;
1236 connection
->sshPrivateKeyFile
= NULL
;
1237 connection
->copyPostFields
= NULL
;
1238 connection
->resolve
= NULL
;
1239 connection
->dns_servers
= NULL
;
1244 static Connection
*duplicateConnection(Connection
*original
)
1246 Connection
*connection
;
1248 connection
= (Connection
*)malloc(sizeof(Connection
));
1250 enter_blocking_section();
1251 connection
->connection
= curl_easy_duphandle(original
->connection
);
1252 leave_blocking_section();
1254 connection
->next
= NULL
;
1255 connection
->prev
= NULL
;
1257 if (connectionList
.tail
== NULL
)
1259 connectionList
.tail
= connection
;
1260 connectionList
.head
= connection
;
1264 connection
->prev
= connectionList
.head
;
1265 connectionList
.head
->next
= connection
;
1266 connectionList
.head
= connection
;
1269 connection
->ocamlValues
= alloc(OcamlValuesSize
, 0);
1270 resetOcamlValues(connection
);
1271 register_global_root(&connection
->ocamlValues
);
1273 Store_field(connection
->ocamlValues
, OcamlWriteCallback
,
1274 Field(original
->ocamlValues
, OcamlWriteCallback
));
1275 Store_field(connection
->ocamlValues
, OcamlReadCallback
,
1276 Field(original
->ocamlValues
, OcamlReadCallback
));
1277 Store_field(connection
->ocamlValues
, OcamlErrorBuffer
,
1278 Field(original
->ocamlValues
, OcamlErrorBuffer
));
1279 Store_field(connection
->ocamlValues
, OcamlPostFields
,
1280 Field(original
->ocamlValues
, OcamlPostFields
));
1281 Store_field(connection
->ocamlValues
, OcamlHTTPHeader
,
1282 Field(original
->ocamlValues
, OcamlHTTPHeader
));
1283 Store_field(connection
->ocamlValues
, OcamlQuote
,
1284 Field(original
->ocamlValues
, OcamlQuote
));
1285 Store_field(connection
->ocamlValues
, OcamlPostQuote
,
1286 Field(original
->ocamlValues
, OcamlPostQuote
));
1287 Store_field(connection
->ocamlValues
, OcamlHeaderCallback
,
1288 Field(original
->ocamlValues
, OcamlHeaderCallback
));
1289 Store_field(connection
->ocamlValues
, OcamlProgressCallback
,
1290 Field(original
->ocamlValues
, OcamlProgressCallback
));
1291 Store_field(connection
->ocamlValues
, OcamlDebugCallback
,
1292 Field(original
->ocamlValues
, OcamlDebugCallback
));
1293 Store_field(connection
->ocamlValues
, OcamlHTTP200Aliases
,
1294 Field(original
->ocamlValues
, OcamlHTTP200Aliases
));
1295 Store_field(connection
->ocamlValues
, OcamlIOCTLCallback
,
1296 Field(original
->ocamlValues
, OcamlIOCTLCallback
));
1297 Store_field(connection
->ocamlValues
, OcamlSeekFunctionCallback
,
1298 Field(original
->ocamlValues
, OcamlSeekFunctionCallback
));
1300 connection
->url
= NULL
;
1301 connection
->proxy
= NULL
;
1302 connection
->userPwd
= NULL
;
1303 connection
->proxyUserPwd
= NULL
;
1304 connection
->range
= NULL
;
1305 connection
->errorBuffer
= NULL
;
1306 connection
->postFields
= NULL
;
1307 connection
->postFieldSize
= -1;
1308 connection
->referer
= NULL
;
1309 connection
->userAgent
= NULL
;
1310 connection
->ftpPort
= NULL
;
1311 connection
->cookie
= NULL
;
1312 connection
->httpHeader
= NULL
;
1313 connection
->httpPostFirst
= NULL
;
1314 connection
->httpPostLast
= NULL
;
1315 connection
->httpPostStrings
= NULL
;
1316 connection
->sslCert
= NULL
;
1317 connection
->sslCertType
= NULL
;
1318 connection
->sslCertPasswd
= NULL
;
1319 connection
->sslKey
= NULL
;
1320 connection
->sslKeyType
= NULL
;
1321 connection
->sslKeyPasswd
= NULL
;
1322 connection
->sslEngine
= NULL
;
1323 connection
->quote
= NULL
;
1324 connection
->postQuote
= NULL
;
1325 connection
->cookieFile
= NULL
;
1326 connection
->customRequest
= NULL
;
1327 connection
->interface
= NULL
;
1328 connection
->caInfo
= NULL
;
1329 connection
->caPath
= NULL
;
1330 connection
->randomFile
= NULL
;
1331 connection
->egdSocket
= NULL
;
1332 connection
->cookieJar
= NULL
;
1333 connection
->sslCipherList
= NULL
;
1334 connection
->private = NULL
;
1335 connection
->http200Aliases
= NULL
;
1336 connection
->netrcFile
= NULL
;
1337 connection
->ftpaccount
= NULL
;
1338 connection
->cookielist
= NULL
;
1339 connection
->sshPublicKeyFile
= NULL
;
1340 connection
->sshPrivateKeyFile
= NULL
;
1341 connection
->copyPostFields
= NULL
;
1342 connection
->resolve
= NULL
;
1343 connection
->dns_servers
= NULL
;
1345 if (Field(original
->ocamlValues
, OcamlURL
) != Val_unit
)
1346 handleURL(connection
, Field(original
->ocamlValues
,
1348 if (Field(original
->ocamlValues
, OcamlProxy
) != Val_unit
)
1349 handleProxy(connection
, Field(original
->ocamlValues
,
1351 if (Field(original
->ocamlValues
, OcamlUserPWD
) != Val_unit
)
1352 handleUserPwd(connection
, Field(original
->ocamlValues
,
1354 if (Field(original
->ocamlValues
, OcamlProxyUserPWD
) != Val_unit
)
1355 handleProxyUserPwd(connection
, Field(original
->ocamlValues
,
1356 OcamlProxyUserPWD
));
1357 if (Field(original
->ocamlValues
, OcamlRange
) != Val_unit
)
1358 handleRange(connection
, Field(original
->ocamlValues
,
1360 if (Field(original
->ocamlValues
, OcamlErrorBuffer
) != Val_unit
)
1361 handleErrorBuffer(connection
, Field(original
->ocamlValues
,
1363 if (Field(original
->ocamlValues
, OcamlPostFields
) != Val_unit
)
1364 handlePostFields(connection
, Field(original
->ocamlValues
,
1366 if (Field(original
->ocamlValues
, OcamlReferer
) != Val_unit
)
1367 handleReferer(connection
, Field(original
->ocamlValues
,
1369 if (Field(original
->ocamlValues
, OcamlUserAgent
) != Val_unit
)
1370 handleUserAgent(connection
, Field(original
->ocamlValues
,
1372 if (Field(original
->ocamlValues
, OcamlFTPPort
) != Val_unit
)
1373 handleFTPPort(connection
, Field(original
->ocamlValues
,
1375 if (Field(original
->ocamlValues
, OcamlCookie
) != Val_unit
)
1376 handleCookie(connection
, Field(original
->ocamlValues
,
1378 if (Field(original
->ocamlValues
, OcamlHTTPHeader
) != Val_unit
)
1379 handleHTTPHeader(connection
, Field(original
->ocamlValues
,
1381 if (Field(original
->ocamlValues
, OcamlHTTPPost
) != Val_unit
)
1382 handleHTTPPost(connection
, Field(original
->ocamlValues
,
1384 if (Field(original
->ocamlValues
, OcamlSSLCert
) != Val_unit
)
1385 handleSSLCert(connection
, Field(original
->ocamlValues
,
1387 if (Field(original
->ocamlValues
, OcamlSSLCertType
) != Val_unit
)
1388 handleSSLCertType(connection
, Field(original
->ocamlValues
,
1390 if (Field(original
->ocamlValues
, OcamlSSLCertPasswd
) != Val_unit
)
1391 handleSSLCertPasswd(connection
, Field(original
->ocamlValues
,
1392 OcamlSSLCertPasswd
));
1393 if (Field(original
->ocamlValues
, OcamlSSLKey
) != Val_unit
)
1394 handleSSLKey(connection
, Field(original
->ocamlValues
,
1396 if (Field(original
->ocamlValues
, OcamlSSLKeyType
) != Val_unit
)
1397 handleSSLKeyType(connection
, Field(original
->ocamlValues
,
1399 if (Field(original
->ocamlValues
, OcamlSSLKeyPasswd
) != Val_unit
)
1400 handleSSLKeyPasswd(connection
, Field(original
->ocamlValues
,
1401 OcamlSSLKeyPasswd
));
1402 if (Field(original
->ocamlValues
, OcamlSSLEngine
) != Val_unit
)
1403 handleSSLEngine(connection
, Field(original
->ocamlValues
,
1405 if (Field(original
->ocamlValues
, OcamlQuote
) != Val_unit
)
1406 handleQuote(connection
, Field(original
->ocamlValues
,
1408 if (Field(original
->ocamlValues
, OcamlPostQuote
) != Val_unit
)
1409 handlePostQuote(connection
, Field(original
->ocamlValues
,
1411 if (Field(original
->ocamlValues
, OcamlCookieFile
) != Val_unit
)
1412 handleCookieFile(connection
, Field(original
->ocamlValues
,
1414 if (Field(original
->ocamlValues
, OcamlCustomRequest
) != Val_unit
)
1415 handleCustomRequest(connection
, Field(original
->ocamlValues
,
1416 OcamlCustomRequest
));
1417 if (Field(original
->ocamlValues
, OcamlInterface
) != Val_unit
)
1418 handleInterface(connection
, Field(original
->ocamlValues
,
1420 if (Field(original
->ocamlValues
, OcamlCAInfo
) != Val_unit
)
1421 handleCAInfo(connection
, Field(original
->ocamlValues
,
1423 if (Field(original
->ocamlValues
, OcamlCAPath
) != Val_unit
)
1424 handleCAPath(connection
, Field(original
->ocamlValues
,
1426 if (Field(original
->ocamlValues
, OcamlRandomFile
) != Val_unit
)
1427 handleRandomFile(connection
, Field(original
->ocamlValues
,
1429 if (Field(original
->ocamlValues
, OcamlEGDSocket
) != Val_unit
)
1430 handleEGDSocket(connection
, Field(original
->ocamlValues
,
1432 if (Field(original
->ocamlValues
, OcamlCookieJar
) != Val_unit
)
1433 handleCookieJar(connection
, Field(original
->ocamlValues
,
1435 if (Field(original
->ocamlValues
, OcamlSSLCipherList
) != Val_unit
)
1436 handleSSLCipherList(connection
, Field(original
->ocamlValues
,
1437 OcamlSSLCipherList
));
1438 if (Field(original
->ocamlValues
, OcamlPrivate
) != Val_unit
)
1439 handlePrivate(connection
, Field(original
->ocamlValues
,
1441 if (Field(original
->ocamlValues
, OcamlHTTP200Aliases
) != Val_unit
)
1442 handleHTTP200Aliases(connection
, Field(original
->ocamlValues
,
1443 OcamlHTTP200Aliases
));
1444 if (Field(original
->ocamlValues
, OcamlNETRCFile
) != Val_unit
)
1445 handleNETRCFile(connection
, Field(original
->ocamlValues
,
1447 if (Field(original
->ocamlValues
, OcamlFTPAccount
) != Val_unit
)
1448 handleFTPAccount(connection
, Field(original
->ocamlValues
,
1450 if (Field(original
->ocamlValues
, OcamlCookieList
) != Val_unit
)
1451 handleCookieList(connection
, Field(original
->ocamlValues
,
1453 if (Field(original
->ocamlValues
, OcamlFTPAlternativeToUser
) != Val_unit
)
1454 handleFTPAlternativeToUser(connection
,
1455 Field(original
->ocamlValues
,
1456 OcamlFTPAlternativeToUser
));
1457 if (Field(original
->ocamlValues
, OcamlSSHPublicKeyFile
) != Val_unit
)
1458 handleSSHPublicKeyFile(connection
,
1459 Field(original
->ocamlValues
,
1460 OcamlSSHPublicKeyFile
));
1461 if (Field(original
->ocamlValues
, OcamlSSHPrivateKeyFile
) != Val_unit
)
1462 handleSSHPrivateKeyFile(connection
,
1463 Field(original
->ocamlValues
,
1464 OcamlSSHPrivateKeyFile
));
1465 if (Field(original
->ocamlValues
, OcamlCopyPostFields
) != Val_unit
)
1466 handleCopyPostFields(connection
,
1467 Field(original
->ocamlValues
,
1468 OcamlCopyPostFields
));
1473 static void free_if(void* p
) { if (NULL
!= p
) free(p
); }
1475 static void removeConnection(Connection
*connection
)
1477 enter_blocking_section();
1478 curl_easy_cleanup(connection
->connection
);
1479 leave_blocking_section();
1481 if (connectionList
.tail
== connection
)
1482 connectionList
.tail
= connectionList
.tail
->next
;
1483 if (connectionList
.head
== connection
)
1484 connectionList
.head
= connectionList
.head
->prev
;
1486 if (connection
->next
!= NULL
)
1487 connection
->next
->prev
= connection
->prev
;
1488 if (connection
->prev
!= NULL
)
1489 connection
->prev
->next
= connection
->next
;
1491 remove_global_root(&connection
->ocamlValues
);
1493 free_if(connection
->url
);
1494 free_if(connection
->proxy
);
1495 free_if(connection
->userPwd
);
1496 free_if(connection
->proxyUserPwd
);
1497 free_if(connection
->range
);
1498 free_if(connection
->errorBuffer
);
1499 free_if(connection
->postFields
);
1500 free_if(connection
->referer
);
1501 free_if(connection
->userAgent
);
1502 free_if(connection
->ftpPort
);
1503 free_if(connection
->cookie
);
1504 free_curl_slist(connection
->httpHeader
);
1505 if (connection
->httpPostFirst
!= NULL
)
1506 curl_formfree(connection
->httpPostFirst
);
1507 free_curl_slist(connection
->httpPostStrings
);
1508 free_curl_slist(connection
->resolve
);
1509 free_if(connection
->sslCert
);
1510 free_if(connection
->sslCertType
);
1511 free_if(connection
->sslCertPasswd
);
1512 free_if(connection
->sslKey
);
1513 free_if(connection
->sslKeyType
);
1514 free_if(connection
->sslKeyPasswd
);
1515 free_if(connection
->sslEngine
);
1516 free_curl_slist(connection
->quote
);
1517 free_curl_slist(connection
->postQuote
);
1518 free_if(connection
->cookieFile
);
1519 free_if(connection
->customRequest
);
1520 free_if(connection
->interface
);
1521 free_if(connection
->caInfo
);
1522 free_if(connection
->caPath
);
1523 free_if(connection
->randomFile
);
1524 free_if(connection
->egdSocket
);
1525 free_if(connection
->cookieJar
);
1526 free_if(connection
->sslCipherList
);
1527 free_if(connection
->private);
1528 free_curl_slist(connection
->http200Aliases
);
1529 free_if(connection
->netrcFile
);
1530 free_if(connection
->ftpaccount
);
1531 free_if(connection
->cookielist
);
1532 free_if(connection
->ftpAlternativeToUser
);
1533 free_if(connection
->sshPublicKeyFile
);
1534 free_if(connection
->sshPrivateKeyFile
);
1535 free_if(connection
->copyPostFields
);
1536 free_if(connection
->dns_servers
);
1542 static void checkConnection(Connection
* connection
)
1547 static void checkConnection(Connection
*connection
)
1549 Connection
*listIter
;
1551 listIter
= connectionList
.tail
;
1553 while (listIter
!= NULL
)
1555 if (listIter
== connection
)
1558 listIter
= listIter
->next
;
1561 failwith("Invalid Connection");
1565 static Connection
* findConnection(CURL
* h
)
1567 Connection
*listIter
;
1569 listIter
= connectionList
.tail
;
1571 while (listIter
!= NULL
)
1573 if (listIter
->connection
== h
)
1576 listIter
= listIter
->next
;
1579 failwith("Unknown handle");
1582 #define WRAP_DATA_CALLBACK(f) \
1583 static size_t f(char *ptr, size_t size, size_t nmemb, void *data)\
1586 leave_blocking_section();\
1587 result = f##_nolock(ptr,size,nmemb,data);\
1588 enter_blocking_section();\
1592 static size_t writeFunction_nolock(char *ptr
, size_t size
, size_t nmemb
, void *data
)
1595 CAMLlocal2(result
, str
);
1596 Connection
*conn
= (Connection
*)data
;
1599 checkConnection(conn
);
1601 str
= alloc_string(size
*nmemb
);
1603 for (i
= 0; i
< size
*nmemb
; i
++)
1604 Byte(str
, i
) = ptr
[i
];
1606 result
= callback(Field(conn
->ocamlValues
, OcamlWriteCallback
), str
);
1608 CAMLreturnT(size_t, Int_val(result
));
1611 WRAP_DATA_CALLBACK(writeFunction
)
1613 static size_t readFunction_nolock(void *ptr
, size_t size
, size_t nmemb
, void *data
)
1617 Connection
*conn
= (Connection
*)data
;
1620 checkConnection(conn
);
1622 result
= callback(Field(conn
->ocamlValues
, OcamlReadCallback
),
1623 Val_int(size
*nmemb
));
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(Field(conn
->ocamlValues
, OcamlHeaderCallback
), str
);
1653 CAMLreturnT(size_t, 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(Field(conn
->ocamlValues
, OcamlProgressCallback
),
1679 CAMLreturnT(int, 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(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(Field(conn
->ocamlValues
, OcamlIOCTLCallback
),
1763 switch (Long_val(camlResult
))
1765 case 0: /* CURLIOE_OK */
1766 result
= CURLIOE_OK
;
1769 case 1: /* CURLIOE_UNKNOWNCMD */
1770 result
= CURLIOE_UNKNOWNCMD
;
1773 case 2: /* CURLIOE_FAILRESTART */
1774 result
= CURLIOE_FAILRESTART
;
1777 default: /* Incorrect return value, but let's handle it */
1778 result
= CURLIOE_FAILRESTART
;
1782 CAMLreturnT(curlioerr
, result
);
1785 static curlioerr
ioctlFunction(CURL
*ioctl
,
1790 leave_blocking_section();
1791 r
= ioctlFunction_nolock(ioctl
, cmd
, data
);
1792 enter_blocking_section();
1796 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1797 static int seekFunction_nolock(void *data
,
1802 CAMLlocal3(camlResult
, camlOffset
, camlOrigin
);
1803 Connection
*conn
= (Connection
*)data
;
1806 camlOffset
= copy_int64(offset
);
1808 if (origin
== SEEK_SET
)
1809 camlOrigin
= Val_long(0);
1810 else if (origin
== SEEK_CUR
)
1811 camlOrigin
= Val_long(1);
1812 else if (origin
== SEEK_END
)
1813 camlOrigin
= Val_long(2);
1815 camlOrigin
= Val_long(0);
1817 camlResult
= callback2(Field(conn
->ocamlValues
,
1818 OcamlSeekFunctionCallback
),
1822 result
= Int_val(camlResult
);
1824 CAMLreturnT(int, result
);
1827 static int seekFunction(void *data
,
1832 leave_blocking_section();
1833 r
= seekFunction_nolock(data
,offset
,origin
);
1834 enter_blocking_section();
1840 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1841 static int openSocketFunction_nolock(void *data
,
1842 curlsocktype purpose
,
1843 struct curl_sockaddr
*addr
)
1846 Connection
*conn
= (Connection
*)data
;
1848 (void)purpose
; /* not used */
1850 sock
= socket(addr
->family
, addr
->socktype
, addr
->protocol
);
1855 callback(Field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
), Val_int(sock
));
1858 CAMLreturnT(int, sock
);
1861 static int openSocketFunction(void *data
,
1862 curlsocktype purpose
,
1863 struct curl_sockaddr
*address
)
1866 leave_blocking_section();
1867 r
= openSocketFunction_nolock(data
,purpose
,address
);
1868 enter_blocking_section();
1875 ** curl_global_init helper function
1878 CAMLprim value
helper_curl_global_init(value initOption
)
1880 CAMLparam1(initOption
);
1882 switch (Long_val(initOption
))
1884 case 0: /* CURLINIT_GLOBALALL */
1885 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_ALL
)));
1888 case 1: /* CURLINIT_GLOBALSSL */
1889 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_SSL
)));
1892 case 2: /* CURLINIT_GLOBALWIN32 */
1893 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_WIN32
)));
1896 case 3: /* CURLINIT_GLOBALNOTHING */
1897 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_NOTHING
)));
1901 failwith("Invalid Initialization Option");
1905 /* Keep compiler happy, we should never get here due to failwith() */
1906 CAMLreturn(Val_unit
);
1910 ** curl_global_cleanup helper function
1913 CAMLprim value
helper_curl_global_cleanup(void)
1917 curl_global_cleanup();
1919 CAMLreturn(Val_unit
);
1923 ** curl_easy_init helper function
1926 CAMLprim value
helper_curl_easy_init(void)
1931 Connection
*conn
= newConnection();
1933 result
= caml_alloc(1, Abstract_tag
);
1934 Field(result
, 0) = (value
)conn
;
1939 CAMLprim value
helper_curl_easy_reset(value conn
)
1942 Connection
*connection
= Connection_val(conn
);
1944 checkConnection(connection
);
1945 curl_easy_reset(connection
->connection
);
1946 resetOcamlValues(connection
);
1948 CAMLreturn(Val_unit
);
1952 ** curl_easy_setopt helper utility functions
1955 static void handleWriteFunction(Connection
*conn
, value option
)
1958 CURLcode result
= CURLE_OK
;
1960 if (Tag_val(option
) == Closure_tag
)
1961 Store_field(conn
->ocamlValues
, OcamlWriteCallback
, option
);
1963 failwith("Not a proper closure");
1965 result
= curl_easy_setopt(conn
->connection
,
1966 CURLOPT_WRITEFUNCTION
,
1969 if (result
!= CURLE_OK
)
1970 raiseError(conn
, result
);
1972 result
= curl_easy_setopt(conn
->connection
,
1976 if (result
!= CURLE_OK
)
1977 raiseError(conn
, result
);
1982 static void handleReadFunction(Connection
*conn
, value option
)
1985 CURLcode result
= CURLE_OK
;
1987 if (Tag_val(option
) == Closure_tag
)
1988 Store_field(conn
->ocamlValues
, OcamlReadCallback
, option
);
1990 failwith("Not a proper closure");
1992 result
= curl_easy_setopt(conn
->connection
,
1993 CURLOPT_READFUNCTION
,
1996 if (result
!= CURLE_OK
)
1997 raiseError(conn
, result
);
1999 result
= curl_easy_setopt(conn
->connection
,
2003 if (result
!= CURLE_OK
)
2004 raiseError(conn
, result
);
2009 static void handleURL(Connection
*conn
, value option
)
2012 CURLcode result
= CURLE_OK
;
2014 Store_field(conn
->ocamlValues
, OcamlURL
, option
);
2016 if (conn
->url
!= NULL
)
2019 conn
->url
= strdup(String_val(option
));
2021 result
= curl_easy_setopt(conn
->connection
,
2025 if (result
!= CURLE_OK
)
2026 raiseError(conn
, result
);
2031 static void handleInFileSize(Connection
*conn
, value option
)
2034 CURLcode result
= CURLE_OK
;
2036 result
= curl_easy_setopt(conn
->connection
,
2040 if (result
!= CURLE_OK
)
2041 raiseError(conn
, result
);
2046 static void handleProxy(Connection
*conn
, value option
)
2049 CURLcode result
= CURLE_OK
;
2051 Store_field(conn
->ocamlValues
, OcamlProxy
, option
);
2053 if (conn
->proxy
!= NULL
)
2056 conn
->proxy
= strdup(String_val(option
));
2058 result
= curl_easy_setopt(conn
->connection
,
2062 if (result
!= CURLE_OK
)
2063 raiseError(conn
, result
);
2068 static void handleProxyPort(Connection
*conn
, value option
)
2071 CURLcode result
= CURLE_OK
;
2073 result
= curl_easy_setopt(conn
->connection
,
2077 if (result
!= CURLE_OK
)
2078 raiseError(conn
, result
);
2083 static void handleHTTPProxyTunnel(Connection
*conn
, value option
)
2086 CURLcode result
= CURLE_OK
;
2088 result
= curl_easy_setopt(conn
->connection
,
2089 CURLOPT_HTTPPROXYTUNNEL
,
2092 if (result
!= CURLE_OK
)
2093 raiseError(conn
, result
);
2098 static void handleVerbose(Connection
*conn
, value option
)
2101 CURLcode result
= CURLE_OK
;
2103 result
= curl_easy_setopt(conn
->connection
,
2107 if (result
!= CURLE_OK
)
2108 raiseError(conn
, result
);
2113 static void handleHeader(Connection
*conn
, value option
)
2116 CURLcode result
= CURLE_OK
;
2118 result
= curl_easy_setopt(conn
->connection
,
2122 if (result
!= CURLE_OK
)
2123 raiseError(conn
, result
);
2128 static void handleNoProgress(Connection
*conn
, value option
)
2131 CURLcode result
= CURLE_OK
;
2133 result
= curl_easy_setopt(conn
->connection
,
2137 if (result
!= CURLE_OK
)
2138 raiseError(conn
, result
);
2143 static void handleNoSignal(Connection
*conn
, value option
)
2145 #if HAVE_DECL_CURLOPT_NOSIGNAL
2147 CURLcode result
= CURLE_OK
;
2149 result
= curl_easy_setopt(conn
->connection
,
2153 if (result
!= CURLE_OK
)
2154 raiseError(conn
, result
);
2158 #pragma message("libcurl does not implement CURLOPT_NOSIGNAL")
2159 failwith("libcurl does not implement CURLOPT_NOSIGNAL");
2163 static void handleNoBody(Connection
*conn
, value option
)
2166 CURLcode result
= CURLE_OK
;
2168 result
= curl_easy_setopt(conn
->connection
,
2172 if (result
!= CURLE_OK
)
2173 raiseError(conn
, result
);
2178 static void handleFailOnError(Connection
*conn
, value option
)
2181 CURLcode result
= CURLE_OK
;
2183 result
= curl_easy_setopt(conn
->connection
,
2184 CURLOPT_FAILONERROR
,
2187 if (result
!= CURLE_OK
)
2188 raiseError(conn
, result
);
2193 static void handleUpload(Connection
*conn
, value option
)
2196 CURLcode result
= CURLE_OK
;
2198 result
= curl_easy_setopt(conn
->connection
,
2202 if (result
!= CURLE_OK
)
2203 raiseError(conn
, result
);
2208 static void handlePost(Connection
*conn
, value option
)
2211 CURLcode result
= CURLE_OK
;
2213 result
= curl_easy_setopt(conn
->connection
,
2217 if (result
!= CURLE_OK
)
2218 raiseError(conn
, result
);
2223 static void handleFTPListOnly(Connection
*conn
, value option
)
2226 CURLcode result
= CURLE_OK
;
2228 result
= curl_easy_setopt(conn
->connection
,
2229 CURLOPT_FTPLISTONLY
,
2232 if (result
!= CURLE_OK
)
2233 raiseError(conn
, result
);
2238 static void handleFTPAppend(Connection
*conn
, value option
)
2241 CURLcode result
= CURLE_OK
;
2243 result
= curl_easy_setopt(conn
->connection
,
2247 if (result
!= CURLE_OK
)
2248 raiseError(conn
, result
);
2253 static void handleNETRC(Connection
*conn
, value option
)
2256 CURLcode result
= CURLE_OK
;
2259 switch (Long_val(option
))
2261 case 0: /* CURL_NETRC_OPTIONAL */
2262 netrc
= CURL_NETRC_OPTIONAL
;
2265 case 1:/* CURL_NETRC_IGNORED */
2266 netrc
= CURL_NETRC_IGNORED
;
2269 case 2: /* CURL_NETRC_REQUIRED */
2270 netrc
= CURL_NETRC_REQUIRED
;
2274 failwith("Invalid NETRC Option");
2278 result
= curl_easy_setopt(conn
->connection
,
2282 if (result
!= CURLE_OK
)
2283 raiseError(conn
, result
);
2288 static void handleEncoding(Connection
*conn
, value option
)
2290 #if HAVE_DECL_CURLOPT_ENCODING
2292 CURLcode result
= CURLE_OK
;
2294 switch (Long_val(option
))
2296 case 0: /* CURL_ENCODING_NONE */
2297 result
= curl_easy_setopt(conn
->connection
,
2302 case 1: /* CURL_ENCODING_DEFLATE */
2303 result
= curl_easy_setopt(conn
->connection
,
2308 case 2: /* CURL_ENCODING_GZIP */
2309 result
= curl_easy_setopt(conn
->connection
,
2314 case 3: /* CURL_ENCODING_ANY */
2315 result
= curl_easy_setopt(conn
->connection
,
2321 failwith("Invalid Encoding Option");
2325 if (result
!= CURLE_OK
)
2326 raiseError(conn
, result
);
2330 #pragma message("libcurl does not implement CURLOPT_ENCODING")
2331 failwith("libcurl does not implement CURLOPT_ENCODING");
2335 static void handleFollowLocation(Connection
*conn
, value option
)
2338 CURLcode result
= CURLE_OK
;
2340 result
= curl_easy_setopt(conn
->connection
,
2341 CURLOPT_FOLLOWLOCATION
,
2344 if (result
!= CURLE_OK
)
2345 raiseError(conn
, result
);
2350 static void handleTransferText(Connection
*conn
, value option
)
2353 CURLcode result
= CURLE_OK
;
2355 result
= curl_easy_setopt(conn
->connection
,
2356 CURLOPT_TRANSFERTEXT
,
2359 if (result
!= CURLE_OK
)
2360 raiseError(conn
, result
);
2365 static void handlePut(Connection
*conn
, value option
)
2368 CURLcode result
= CURLE_OK
;
2370 result
= curl_easy_setopt(conn
->connection
,
2374 if (result
!= CURLE_OK
)
2375 raiseError(conn
, result
);
2380 static void handleUserPwd(Connection
*conn
, value option
)
2383 CURLcode result
= CURLE_OK
;
2385 Store_field(conn
->ocamlValues
, OcamlUserPWD
, option
);
2387 if (conn
->userPwd
!= NULL
)
2388 free(conn
->userPwd
);
2390 conn
->userPwd
= strdup(String_val(option
));
2392 result
= curl_easy_setopt(conn
->connection
,
2396 if (result
!= CURLE_OK
)
2397 raiseError(conn
, result
);
2402 static void handleProxyUserPwd(Connection
*conn
, value option
)
2405 CURLcode result
= CURLE_OK
;
2407 Store_field(conn
->ocamlValues
, OcamlProxyUserPWD
, option
);
2409 if (conn
->proxyUserPwd
!= NULL
)
2410 free(conn
->proxyUserPwd
);
2412 conn
->proxyUserPwd
= strdup(String_val(option
));
2414 result
= curl_easy_setopt(conn
->connection
,
2415 CURLOPT_PROXYUSERPWD
,
2416 conn
->proxyUserPwd
);
2418 if (result
!= CURLE_OK
)
2419 raiseError(conn
, result
);
2424 static void handleRange(Connection
*conn
, value option
)
2427 CURLcode result
= CURLE_OK
;
2429 Store_field(conn
->ocamlValues
, OcamlRange
, option
);
2431 if (conn
->range
!= NULL
)
2434 conn
->range
= strdup(String_val(option
));
2436 result
= curl_easy_setopt(conn
->connection
,
2440 if (result
!= CURLE_OK
)
2441 raiseError(conn
, result
);
2446 static void handleErrorBuffer(Connection
*conn
, value option
)
2449 CURLcode result
= CURLE_OK
;
2451 Store_field(conn
->ocamlValues
, OcamlErrorBuffer
, option
);
2453 if (conn
->errorBuffer
!= NULL
)
2454 free(conn
->errorBuffer
);
2456 conn
->errorBuffer
= malloc(sizeof(char) * CURL_ERROR_SIZE
);
2458 result
= curl_easy_setopt(conn
->connection
,
2459 CURLOPT_ERRORBUFFER
,
2462 if (result
!= CURLE_OK
)
2463 raiseError(conn
, result
);
2468 static void handleTimeout(Connection
*conn
, value option
)
2471 CURLcode result
= CURLE_OK
;
2473 result
= curl_easy_setopt(conn
->connection
,
2477 if (result
!= CURLE_OK
)
2478 raiseError(conn
, result
);
2483 static void handlePostFields(Connection
*conn
, value option
)
2486 CURLcode result
= CURLE_OK
;
2488 Store_field(conn
->ocamlValues
, OcamlPostFields
, option
);
2490 if (conn
->postFields
!= NULL
)
2491 free(conn
->postFields
);
2493 conn
->postFields
= malloc(string_length(option
)+1);
2494 memcpy(conn
->postFields
, String_val(option
), string_length(option
)+1);
2496 result
= curl_easy_setopt(conn
->connection
,
2500 if (result
!= CURLE_OK
)
2501 raiseError(conn
, result
);
2506 static void handlePostFieldSize(Connection
*conn
, value option
)
2509 CURLcode result
= CURLE_OK
;
2511 result
= curl_easy_setopt(conn
->connection
,
2512 CURLOPT_POSTFIELDSIZE
,
2515 if (result
!= CURLE_OK
)
2516 raiseError(conn
, result
);
2521 static void handleReferer(Connection
*conn
, value option
)
2524 CURLcode result
= CURLE_OK
;
2526 Store_field(conn
->ocamlValues
, OcamlReferer
, option
);
2528 if (conn
->referer
!= NULL
)
2529 free(conn
->referer
);
2531 conn
->referer
= strdup(String_val(option
));
2533 result
= curl_easy_setopt(conn
->connection
,
2537 if (result
!= CURLE_OK
)
2538 raiseError(conn
, result
);
2543 static void handleUserAgent(Connection
*conn
, value option
)
2546 CURLcode result
= CURLE_OK
;
2548 Store_field(conn
->ocamlValues
, OcamlUserAgent
, option
);
2550 if (conn
->userAgent
!= NULL
)
2551 free(conn
->userAgent
);
2553 conn
->userAgent
= strdup(String_val(option
));
2555 result
= curl_easy_setopt(conn
->connection
,
2559 if (result
!= CURLE_OK
)
2560 raiseError(conn
, result
);
2565 static void handleFTPPort(Connection
*conn
, value option
)
2568 CURLcode result
= CURLE_OK
;
2570 Store_field(conn
->ocamlValues
, OcamlFTPPort
, option
);
2572 if (conn
->ftpPort
!= NULL
)
2573 free(conn
->ftpPort
);
2575 conn
->ftpPort
= strdup(String_val(option
));
2577 result
= curl_easy_setopt(conn
->connection
,
2581 if (result
!= CURLE_OK
)
2582 raiseError(conn
, result
);
2587 static void handleLowSpeedLimit(Connection
*conn
, value option
)
2590 CURLcode result
= CURLE_OK
;
2592 result
= curl_easy_setopt(conn
->connection
,
2593 CURLOPT_LOW_SPEED_LIMIT
,
2596 if (result
!= CURLE_OK
)
2597 raiseError(conn
, result
);
2602 static void handleLowSpeedTime(Connection
*conn
, value option
)
2605 CURLcode result
= CURLE_OK
;
2607 result
= curl_easy_setopt(conn
->connection
,
2608 CURLOPT_LOW_SPEED_TIME
,
2611 if (result
!= CURLE_OK
)
2612 raiseError(conn
, result
);
2617 static void handleResumeFrom(Connection
*conn
, value option
)
2620 CURLcode result
= CURLE_OK
;
2622 result
= curl_easy_setopt(conn
->connection
,
2623 CURLOPT_RESUME_FROM
,
2626 if (result
!= CURLE_OK
)
2627 raiseError(conn
, result
);
2632 static void handleCookie(Connection
*conn
, value option
)
2635 CURLcode result
= CURLE_OK
;
2637 Store_field(conn
->ocamlValues
, OcamlCookie
, option
);
2639 if (conn
->cookie
!= NULL
)
2642 conn
->cookie
= strdup(String_val(option
));
2644 result
= curl_easy_setopt(conn
->connection
,
2648 if (result
!= CURLE_OK
)
2649 raiseError(conn
, result
);
2654 static void handleHTTPHeader(Connection
*conn
, value option
)
2657 CAMLlocal1(listIter
);
2658 CURLcode result
= CURLE_OK
;
2660 Store_field(conn
->ocamlValues
, OcamlHTTPHeader
, option
);
2662 free_curl_slist(conn
->httpHeader
);
2663 conn
->httpHeader
= NULL
;
2667 while (!Is_long(listIter
))
2669 conn
->httpHeader
= curl_slist_append(conn
->httpHeader
, String_val(Field(listIter
, 0)));
2671 listIter
= Field(listIter
, 1);
2674 result
= curl_easy_setopt(conn
->connection
,
2678 if (result
!= CURLE_OK
)
2679 raiseError(conn
, result
);
2684 static void handleHTTPPost(Connection
*conn
, value option
)
2687 CAMLlocal3(listIter
, formItem
, contentType
);
2688 CURLcode result
= CURLE_OK
;
2689 char *str1
, *str2
, *str3
, *str4
;
2693 Store_field(conn
->ocamlValues
, OcamlHTTPPost
, option
);
2695 if (conn
->httpPostFirst
!= NULL
)
2696 curl_formfree(conn
->httpPostFirst
);
2698 conn
->httpPostFirst
= NULL
;
2699 conn
->httpPostLast
= NULL
;
2701 free_curl_slist(conn
->httpPostStrings
);
2702 conn
->httpPostStrings
= NULL
;
2704 while (!Is_long(listIter
))
2706 formItem
= Field(listIter
, 0);
2708 switch (Tag_val(formItem
))
2710 case 0: /* CURLFORM_CONTENT */
2711 if (Wosize_val(formItem
) < 3)
2713 failwith("Incorrect CURLFORM_CONTENT parameters");
2716 if (Is_long(Field(formItem
, 2)) &&
2717 Long_val(Field(formItem
, 2)) == 0)
2719 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2721 String_val(Field(formItem
, 0)),
2722 string_length(Field(formItem
, 0)));
2723 str1
[string_length(Field(formItem
, 0))] = 0;
2724 conn
->httpPostStrings
=
2725 curl_slist_append(conn
->httpPostStrings
, str1
);
2727 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2729 String_val(Field(formItem
, 1)),
2730 string_length(Field(formItem
, 1)));
2731 str2
[string_length(Field(formItem
, 1))] = 0;
2732 conn
->httpPostStrings
=
2733 curl_slist_append(conn
->httpPostStrings
, str2
);
2735 curl_formadd(&conn
->httpPostFirst
,
2736 &conn
->httpPostLast
,
2739 CURLFORM_NAMELENGTH
,
2740 string_length(Field(formItem
, 0)),
2741 CURLFORM_PTRCONTENTS
,
2743 CURLFORM_CONTENTSLENGTH
,
2744 string_length(Field(formItem
, 1)),
2747 else if (Is_block(Field(formItem
, 2)))
2749 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2751 String_val(Field(formItem
, 0)),
2752 string_length(Field(formItem
, 0)));
2753 str1
[string_length(Field(formItem
, 0))] = 0;
2754 conn
->httpPostStrings
=
2755 curl_slist_append(conn
->httpPostStrings
, str1
);
2757 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2759 String_val(Field(formItem
, 1)),
2760 string_length(Field(formItem
, 1)));
2761 str2
[string_length(Field(formItem
, 1))] = 0;
2762 conn
->httpPostStrings
=
2763 curl_slist_append(conn
->httpPostStrings
, str2
);
2765 contentType
= Field(formItem
, 2);
2767 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2769 String_val(Field(contentType
, 0)),
2770 string_length(Field(contentType
, 0)));
2771 str3
[string_length(Field(contentType
, 0))] = 0;
2772 conn
->httpPostStrings
=
2773 curl_slist_append(conn
->httpPostStrings
, str3
);
2775 curl_formadd(&conn
->httpPostFirst
,
2776 &conn
->httpPostLast
,
2779 CURLFORM_NAMELENGTH
,
2780 string_length(Field(formItem
, 0)),
2781 CURLFORM_PTRCONTENTS
,
2783 CURLFORM_CONTENTSLENGTH
,
2784 string_length(Field(formItem
, 1)),
2785 CURLFORM_CONTENTTYPE
,
2791 failwith("Incorrect CURLFORM_CONTENT parameters");
2795 case 1: /* CURLFORM_FILECONTENT */
2796 if (Wosize_val(formItem
) < 3)
2798 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2801 if (Is_long(Field(formItem
, 2)) &&
2802 Long_val(Field(formItem
, 2)) == 0)
2804 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2806 String_val(Field(formItem
, 0)),
2807 string_length(Field(formItem
, 0)));
2808 str1
[string_length(Field(formItem
, 0))] = 0;
2809 conn
->httpPostStrings
=
2810 curl_slist_append(conn
->httpPostStrings
, str1
);
2812 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2814 String_val(Field(formItem
, 1)),
2815 string_length(Field(formItem
, 1)));
2816 str2
[string_length(Field(formItem
, 1))] = 0;
2817 conn
->httpPostStrings
=
2818 curl_slist_append(conn
->httpPostStrings
, str2
);
2820 curl_formadd(&conn
->httpPostFirst
,
2821 &conn
->httpPostLast
,
2824 CURLFORM_NAMELENGTH
,
2825 string_length(Field(formItem
, 0)),
2826 CURLFORM_FILECONTENT
,
2830 else if (Is_block(Field(formItem
, 2)))
2832 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2834 String_val(Field(formItem
, 0)),
2835 string_length(Field(formItem
, 0)));
2836 str1
[string_length(Field(formItem
, 0))] = 0;
2837 conn
->httpPostStrings
=
2838 curl_slist_append(conn
->httpPostStrings
, str1
);
2840 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2842 String_val(Field(formItem
, 1)),
2843 string_length(Field(formItem
, 1)));
2844 str2
[string_length(Field(formItem
, 1))] = 0;
2845 conn
->httpPostStrings
=
2846 curl_slist_append(conn
->httpPostStrings
, str2
);
2848 contentType
= Field(formItem
, 2);
2850 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2852 String_val(Field(contentType
, 0)),
2853 string_length(Field(contentType
, 0)));
2854 str3
[string_length(Field(contentType
, 0))] = 0;
2855 conn
->httpPostStrings
=
2856 curl_slist_append(conn
->httpPostStrings
, str3
);
2858 curl_formadd(&conn
->httpPostFirst
,
2859 &conn
->httpPostLast
,
2862 CURLFORM_NAMELENGTH
,
2863 string_length(Field(formItem
, 0)),
2864 CURLFORM_FILECONTENT
,
2866 CURLFORM_CONTENTTYPE
,
2872 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2876 case 2: /* CURLFORM_FILE */
2877 if (Wosize_val(formItem
) < 3)
2879 failwith("Incorrect CURLFORM_FILE parameters");
2882 if (Is_long(Field(formItem
, 2)) &&
2883 Long_val(Field(formItem
, 2)) == 0)
2885 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2887 String_val(Field(formItem
, 0)),
2888 string_length(Field(formItem
, 0)));
2889 str1
[string_length(Field(formItem
, 0))] = 0;
2890 conn
->httpPostStrings
=
2891 curl_slist_append(conn
->httpPostStrings
, str1
);
2893 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2895 String_val(Field(formItem
, 1)),
2896 string_length(Field(formItem
, 1)));
2897 str2
[string_length(Field(formItem
, 1))] = 0;
2898 conn
->httpPostStrings
=
2899 curl_slist_append(conn
->httpPostStrings
, str2
);
2901 curl_formadd(&conn
->httpPostFirst
,
2902 &conn
->httpPostLast
,
2905 CURLFORM_NAMELENGTH
,
2906 string_length(Field(formItem
, 0)),
2911 else if (Is_block(Field(formItem
, 2)))
2913 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2915 String_val(Field(formItem
, 0)),
2916 string_length(Field(formItem
, 0)));
2917 str1
[string_length(Field(formItem
, 0))] = 0;
2918 conn
->httpPostStrings
=
2919 curl_slist_append(conn
->httpPostStrings
, str1
);
2921 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2923 String_val(Field(formItem
, 1)),
2924 string_length(Field(formItem
, 1)));
2925 str2
[string_length(Field(formItem
, 1))] = 0;
2926 conn
->httpPostStrings
=
2927 curl_slist_append(conn
->httpPostStrings
, str2
);
2929 contentType
= Field(formItem
, 2);
2931 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2933 String_val(Field(contentType
, 0)),
2934 string_length(Field(contentType
, 0)));
2935 str3
[string_length(Field(contentType
, 0))] = 0;
2936 conn
->httpPostStrings
=
2937 curl_slist_append(conn
->httpPostStrings
, str3
);
2939 curl_formadd(&conn
->httpPostFirst
,
2940 &conn
->httpPostLast
,
2943 CURLFORM_NAMELENGTH
,
2944 string_length(Field(formItem
, 0)),
2947 CURLFORM_CONTENTTYPE
,
2953 failwith("Incorrect CURLFORM_FILE parameters");
2957 case 3: /* CURLFORM_BUFFER */
2958 if (Wosize_val(formItem
) < 4)
2960 failwith("Incorrect CURLFORM_BUFFER parameters");
2963 if (Is_long(Field(formItem
, 3)) &&
2964 Long_val(Field(formItem
, 3)) == 0)
2966 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2968 String_val(Field(formItem
, 0)),
2969 string_length(Field(formItem
, 0)));
2970 str1
[string_length(Field(formItem
, 0))] = 0;
2971 conn
->httpPostStrings
=
2972 curl_slist_append(conn
->httpPostStrings
, str1
);
2974 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2976 String_val(Field(formItem
, 1)),
2977 string_length(Field(formItem
, 1)));
2978 str2
[string_length(Field(formItem
, 1))] = 0;
2979 conn
->httpPostStrings
=
2980 curl_slist_append(conn
->httpPostStrings
, str2
);
2982 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
2984 String_val(Field(formItem
, 2)),
2985 string_length(Field(formItem
, 2)));
2986 str3
[string_length(Field(formItem
, 2))] = 0;
2987 conn
->httpPostStrings
=
2988 curl_slist_append(conn
->httpPostStrings
, str3
);
2990 curl_formadd(&conn
->httpPostFirst
,
2991 &conn
->httpPostLast
,
2994 CURLFORM_NAMELENGTH
,
2995 string_length(Field(formItem
, 0)),
3000 CURLFORM_BUFFERLENGTH
,
3001 string_length(Field(formItem
, 2)),
3004 else if (Is_block(Field(formItem
, 3)))
3006 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
3008 String_val(Field(formItem
, 0)),
3009 string_length(Field(formItem
, 0)));
3010 str1
[string_length(Field(formItem
, 0))] = 0;
3011 conn
->httpPostStrings
=
3012 curl_slist_append(conn
->httpPostStrings
, str1
);
3014 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
3016 String_val(Field(formItem
, 1)),
3017 string_length(Field(formItem
, 1)));
3018 str2
[string_length(Field(formItem
, 1))] = 0;
3019 conn
->httpPostStrings
=
3020 curl_slist_append(conn
->httpPostStrings
, str2
);
3022 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
3024 String_val(Field(formItem
, 2)),
3025 string_length(Field(formItem
, 2)));
3026 str3
[string_length(Field(formItem
, 2))] = 0;
3027 conn
->httpPostStrings
=
3028 curl_slist_append(conn
->httpPostStrings
, str3
);
3030 contentType
= Field(formItem
, 3);
3032 str4
= (char *)malloc(string_length(Field(contentType
, 0))+1);
3034 String_val(Field(contentType
, 0)),
3035 string_length(Field(contentType
, 0)));
3036 str4
[string_length(Field(contentType
, 0))] = 0;
3037 conn
->httpPostStrings
=
3038 curl_slist_append(conn
->httpPostStrings
, str4
);
3040 curl_formadd(&conn
->httpPostFirst
,
3041 &conn
->httpPostLast
,
3044 CURLFORM_NAMELENGTH
,
3045 string_length(Field(formItem
, 0)),
3050 CURLFORM_BUFFERLENGTH
,
3051 string_length(Field(formItem
, 2)),
3052 CURLFORM_CONTENTTYPE
,
3058 failwith("Incorrect CURLFORM_BUFFER parameters");
3063 listIter
= Field(listIter
, 1);
3066 result
= curl_easy_setopt(conn
->connection
,
3068 conn
->httpPostFirst
);
3070 if (result
!= CURLE_OK
)
3071 raiseError(conn
, result
);
3076 static void handleSSLCert(Connection
*conn
, value option
)
3079 CURLcode result
= CURLE_OK
;
3081 Store_field(conn
->ocamlValues
, OcamlSSLCert
, option
);
3083 if (conn
->sslCert
!= NULL
)
3084 free(conn
->sslCert
);
3086 conn
->sslCert
= strdup(String_val(option
));
3088 result
= curl_easy_setopt(conn
->connection
,
3092 if (result
!= CURLE_OK
)
3093 raiseError(conn
, result
);
3098 static void handleSSLCertType(Connection
*conn
, value option
)
3101 CURLcode result
= CURLE_OK
;
3103 Store_field(conn
->ocamlValues
, OcamlSSLCertType
, option
);
3105 if (conn
->sslCertType
!= NULL
)
3106 free(conn
->sslCertType
);
3108 conn
->sslCertType
= strdup(String_val(option
));
3110 result
= curl_easy_setopt(conn
->connection
,
3111 CURLOPT_SSLCERTTYPE
,
3114 if (result
!= CURLE_OK
)
3115 raiseError(conn
, result
);
3120 static void handleSSLCertPasswd(Connection
*conn
, value option
)
3123 CURLcode result
= CURLE_OK
;
3125 Store_field(conn
->ocamlValues
, OcamlSSLCertPasswd
, option
);
3127 if (conn
->sslCertPasswd
!= NULL
)
3128 free(conn
->sslCertPasswd
);
3130 conn
->sslCertPasswd
= strdup(String_val(option
));
3132 result
= curl_easy_setopt(conn
->connection
,
3133 CURLOPT_SSLCERTPASSWD
,
3134 conn
->sslCertPasswd
);
3136 if (result
!= CURLE_OK
)
3137 raiseError(conn
, result
);
3142 static void handleSSLKey(Connection
*conn
, value option
)
3145 CURLcode result
= CURLE_OK
;
3147 Store_field(conn
->ocamlValues
, OcamlSSLKey
, option
);
3149 if (conn
->sslKey
!= NULL
)
3152 conn
->sslKey
= strdup(String_val(option
));
3154 result
= curl_easy_setopt(conn
->connection
,
3158 if (result
!= CURLE_OK
)
3159 raiseError(conn
, result
);
3164 static void handleSSLKeyType(Connection
*conn
, value option
)
3167 CURLcode result
= CURLE_OK
;
3169 Store_field(conn
->ocamlValues
, OcamlSSLKeyType
, option
);
3171 if (conn
->sslKeyType
!= NULL
)
3172 free(conn
->sslKeyType
);
3174 conn
->sslKeyType
= strdup(String_val(option
));
3176 result
= curl_easy_setopt(conn
->connection
,
3180 if (result
!= CURLE_OK
)
3181 raiseError(conn
, result
);
3186 static void handleSSLKeyPasswd(Connection
*conn
, value option
)
3189 CURLcode result
= CURLE_OK
;
3191 Store_field(conn
->ocamlValues
, OcamlSSLKeyPasswd
, option
);
3193 if (conn
->sslKeyPasswd
!= NULL
)
3194 free(conn
->sslKeyPasswd
);
3196 conn
->sslKeyPasswd
= strdup(String_val(option
));
3198 result
= curl_easy_setopt(conn
->connection
,
3199 CURLOPT_SSLKEYPASSWD
,
3200 conn
->sslKeyPasswd
);
3202 if (result
!= CURLE_OK
)
3203 raiseError(conn
, result
);
3208 static void handleSSLEngine(Connection
*conn
, value option
)
3211 CURLcode result
= CURLE_OK
;
3213 Store_field(conn
->ocamlValues
, OcamlSSLEngine
, option
);
3215 if (conn
->sslEngine
!= NULL
)
3216 free(conn
->sslEngine
);
3218 conn
->sslEngine
= strdup(String_val(option
));
3220 result
= curl_easy_setopt(conn
->connection
,
3224 if (result
!= CURLE_OK
)
3225 raiseError(conn
, result
);
3230 static void handleSSLEngineDefault(Connection
*conn
, value option
)
3233 CURLcode result
= CURLE_OK
;
3235 result
= curl_easy_setopt(conn
->connection
,
3236 CURLOPT_SSLENGINE_DEFAULT
,
3239 if (result
!= CURLE_OK
)
3240 raiseError(conn
, result
);
3245 static void handleCRLF(Connection
*conn
, value option
)
3248 CURLcode result
= CURLE_OK
;
3250 result
= curl_easy_setopt(conn
->connection
,
3254 if (result
!= CURLE_OK
)
3255 raiseError(conn
, result
);
3260 static void handleQuote(Connection
*conn
, value option
)
3263 CAMLlocal1(listIter
);
3264 CURLcode result
= CURLE_OK
;
3266 Store_field(conn
->ocamlValues
, OcamlQuote
, option
);
3268 free_curl_slist(conn
->quote
);
3273 while (!Is_long(listIter
))
3275 conn
->quote
= curl_slist_append(conn
->quote
, String_val(Field(listIter
, 0)));
3277 listIter
= Field(listIter
, 1);
3280 result
= curl_easy_setopt(conn
->connection
,
3284 if (result
!= CURLE_OK
)
3285 raiseError(conn
, result
);
3290 static void handlePostQuote(Connection
*conn
, value option
)
3293 CAMLlocal1(listIter
);
3294 CURLcode result
= CURLE_OK
;
3296 Store_field(conn
->ocamlValues
, OcamlPostQuote
, option
);
3298 free_curl_slist(conn
->postQuote
);
3299 conn
->postQuote
= NULL
;
3303 while (!Is_long(listIter
))
3305 conn
->postQuote
= curl_slist_append(conn
->postQuote
, String_val(Field(listIter
, 0)));
3307 listIter
= Field(listIter
, 1);
3310 result
= curl_easy_setopt(conn
->connection
,
3314 if (result
!= CURLE_OK
)
3315 raiseError(conn
, result
);
3320 static void handleHeaderFunction(Connection
*conn
, value option
)
3323 CURLcode result
= CURLE_OK
;
3325 if (Tag_val(option
) == Closure_tag
)
3326 Store_field(conn
->ocamlValues
, OcamlHeaderCallback
, option
);
3328 failwith("Not a proper closure");
3330 result
= curl_easy_setopt(conn
->connection
,
3331 CURLOPT_HEADERFUNCTION
,
3334 if (result
!= CURLE_OK
)
3335 raiseError(conn
, result
);
3337 result
= curl_easy_setopt(conn
->connection
,
3338 CURLOPT_WRITEHEADER
,
3341 if (result
!= CURLE_OK
)
3342 raiseError(conn
, result
);
3347 static void handleCookieFile(Connection
*conn
, value option
)
3350 CURLcode result
= CURLE_OK
;
3352 Store_field(conn
->ocamlValues
, OcamlCookieFile
, option
);
3354 if (conn
->cookieFile
!= NULL
)
3355 free(conn
->cookieFile
);
3357 conn
->cookieFile
= strdup(String_val(option
));
3359 result
= curl_easy_setopt(conn
->connection
,
3363 if (result
!= CURLE_OK
)
3364 raiseError(conn
, result
);
3369 static void handleSSLVersion(Connection
*conn
, value option
)
3372 CURLcode result
= CURLE_OK
;
3374 result
= curl_easy_setopt(conn
->connection
,
3378 if (result
!= CURLE_OK
)
3379 raiseError(conn
, result
);
3384 static void handleTimeCondition(Connection
*conn
, value option
)
3387 CURLcode result
= CURLE_OK
;
3389 switch (Long_val(option
))
3391 case 0: /* TIMECOND_IFMODSINCE */
3392 result
= curl_easy_setopt(conn
->connection
,
3393 CURLOPT_TIMECONDITION
,
3394 CURL_TIMECOND_IFMODSINCE
);
3397 case 1: /* TIMECOND_IFUNMODSINCE */
3398 result
= curl_easy_setopt(conn
->connection
,
3399 CURLOPT_TIMECONDITION
,
3400 CURL_TIMECOND_IFUNMODSINCE
);
3404 failwith("Invalid TIMECOND Option");
3408 if (result
!= CURLE_OK
)
3409 raiseError(conn
, result
);
3414 static void handleTimeValue(Connection
*conn
, value option
)
3417 CURLcode result
= CURLE_OK
;
3419 result
= curl_easy_setopt(conn
->connection
,
3423 if (result
!= CURLE_OK
)
3424 raiseError(conn
, result
);
3429 static void handleCustomRequest(Connection
*conn
, value option
)
3432 CURLcode result
= CURLE_OK
;
3434 Store_field(conn
->ocamlValues
, OcamlCustomRequest
, option
);
3436 if (conn
->customRequest
!= NULL
)
3437 free(conn
->customRequest
);
3439 conn
->customRequest
= strdup(String_val(option
));
3441 result
= curl_easy_setopt(conn
->connection
,
3442 CURLOPT_CUSTOMREQUEST
,
3443 conn
->customRequest
);
3445 if (result
!= CURLE_OK
)
3446 raiseError(conn
, result
);
3451 static void handleInterface(Connection
*conn
, value option
)
3454 CURLcode result
= CURLE_OK
;
3456 Store_field(conn
->ocamlValues
, OcamlInterface
, option
);
3458 if (conn
->interface
!= NULL
)
3459 free(conn
->interface
);
3461 conn
->interface
= strdup(String_val(option
));
3463 result
= curl_easy_setopt(conn
->connection
,
3467 if (result
!= CURLE_OK
)
3468 raiseError(conn
, result
);
3473 static void handleKRB4Level(Connection
*conn
, value option
)
3476 CURLcode result
= CURLE_OK
;
3478 switch (Long_val(option
))
3480 case 0: /* KRB4_NONE */
3481 result
= curl_easy_setopt(conn
->connection
,
3486 case 1: /* KRB4_CLEAR */
3487 result
= curl_easy_setopt(conn
->connection
,
3492 case 2: /* KRB4_SAFE */
3493 result
= curl_easy_setopt(conn
->connection
,
3498 case 3: /* KRB4_CONFIDENTIAL */
3499 result
= curl_easy_setopt(conn
->connection
,
3504 case 4: /* KRB4_PRIVATE */
3505 result
= curl_easy_setopt(conn
->connection
,
3511 failwith("Invalid KRB4 Option");
3515 if (result
!= CURLE_OK
)
3516 raiseError(conn
, result
);
3521 static void handleProgressFunction(Connection
*conn
, value option
)
3524 CURLcode result
= CURLE_OK
;
3526 if (Tag_val(option
) == Closure_tag
)
3527 Store_field(conn
->ocamlValues
, OcamlProgressCallback
, option
);
3529 failwith("Not a proper closure");
3531 result
= curl_easy_setopt(conn
->connection
,
3532 CURLOPT_PROGRESSFUNCTION
,
3534 if (result
!= CURLE_OK
)
3535 raiseError(conn
, result
);
3537 result
= curl_easy_setopt(conn
->connection
,
3538 CURLOPT_PROGRESSDATA
,
3541 if (result
!= CURLE_OK
)
3542 raiseError(conn
, result
);
3547 static void handleSSLVerifyPeer(Connection
*conn
, value option
)
3550 CURLcode result
= CURLE_OK
;
3552 result
= curl_easy_setopt(conn
->connection
,
3553 CURLOPT_SSL_VERIFYPEER
,
3556 if (result
!= CURLE_OK
)
3557 raiseError(conn
, result
);
3562 static void handleCAInfo(Connection
*conn
, value option
)
3565 CURLcode result
= CURLE_OK
;
3567 Store_field(conn
->ocamlValues
, OcamlCAInfo
, option
);
3569 if (conn
->caInfo
!= NULL
)
3572 conn
->caInfo
= strdup(String_val(option
));
3574 result
= curl_easy_setopt(conn
->connection
,
3578 if (result
!= CURLE_OK
)
3579 raiseError(conn
, result
);
3584 static void handleCAPath(Connection
*conn
, value option
)
3587 CURLcode result
= CURLE_OK
;
3589 Store_field(conn
->ocamlValues
, OcamlCAPath
, option
);
3591 if (conn
->caPath
!= NULL
)
3594 conn
->caPath
= strdup(String_val(option
));
3596 result
= curl_easy_setopt(conn
->connection
,
3600 if (result
!= CURLE_OK
)
3601 raiseError(conn
, result
);
3606 static void handleFileTime(Connection
*conn
, value option
)
3609 CURLcode result
= CURLE_OK
;
3611 result
= curl_easy_setopt(conn
->connection
,
3615 if (result
!= CURLE_OK
)
3616 raiseError(conn
, result
);
3621 static void handleMaxRedirs(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 handleMaxConnects(Connection
*conn
, value option
)
3639 CURLcode result
= CURLE_OK
;
3641 result
= curl_easy_setopt(conn
->connection
,
3642 CURLOPT_MAXCONNECTS
,
3645 if (result
!= CURLE_OK
)
3646 raiseError(conn
, result
);
3651 static void handleClosePolicy(Connection
*conn
, value option
)
3654 CURLcode result
= CURLE_OK
;
3656 switch (Long_val(option
))
3658 case 0: /* CLOSEPOLICY_OLDEST */
3659 result
= curl_easy_setopt(conn
->connection
,
3660 CURLOPT_CLOSEPOLICY
,
3661 CURLCLOSEPOLICY_OLDEST
);
3664 case 1: /* CLOSEPOLICY_LEAST_RECENTLY_USED */
3665 result
= curl_easy_setopt(conn
->connection
,
3666 CURLOPT_CLOSEPOLICY
,
3667 CURLCLOSEPOLICY_LEAST_RECENTLY_USED
);
3671 failwith("Invalid CLOSEPOLICY Option");
3675 if (result
!= CURLE_OK
)
3676 raiseError(conn
, result
);
3681 static void handleFreshConnect(Connection
*conn
, value option
)
3684 CURLcode result
= CURLE_OK
;
3686 result
= curl_easy_setopt(conn
->connection
,
3687 CURLOPT_FRESH_CONNECT
,
3690 if (result
!= CURLE_OK
)
3691 raiseError(conn
, result
);
3696 static void handleForbidReuse(Connection
*conn
, value option
)
3699 CURLcode result
= CURLE_OK
;
3701 result
= curl_easy_setopt(conn
->connection
,
3702 CURLOPT_FORBID_REUSE
,
3705 if (result
!= CURLE_OK
)
3706 raiseError(conn
, result
);
3711 static void handleRandomFile(Connection
*conn
, value option
)
3714 CURLcode result
= CURLE_OK
;
3716 Store_field(conn
->ocamlValues
, OcamlRandomFile
, option
);
3718 if (conn
->randomFile
!= NULL
)
3719 free(conn
->randomFile
);
3721 conn
->randomFile
= strdup(String_val(option
));
3723 result
= curl_easy_setopt(conn
->connection
,
3724 CURLOPT_RANDOM_FILE
,
3727 if (result
!= CURLE_OK
)
3728 raiseError(conn
, result
);
3733 static void handleEGDSocket(Connection
*conn
, value option
)
3736 CURLcode result
= CURLE_OK
;
3738 Store_field(conn
->ocamlValues
, OcamlEGDSocket
, option
);
3740 if (conn
->egdSocket
!= NULL
)
3741 free(conn
->egdSocket
);
3743 conn
->egdSocket
= strdup(String_val(option
));
3745 result
= curl_easy_setopt(conn
->connection
,
3749 if (result
!= CURLE_OK
)
3750 raiseError(conn
, result
);
3755 static void handleConnectTimeout(Connection
*conn
, value option
)
3758 CURLcode result
= CURLE_OK
;
3760 result
= curl_easy_setopt(conn
->connection
,
3761 CURLOPT_CONNECTTIMEOUT
,
3764 if (result
!= CURLE_OK
)
3765 raiseError(conn
, result
);
3770 static void handleHTTPGet(Connection
*conn
, value option
)
3773 CURLcode result
= CURLE_OK
;
3775 result
= curl_easy_setopt(conn
->connection
,
3779 if (result
!= CURLE_OK
)
3780 raiseError(conn
, result
);
3785 static void handleSSLVerifyHost(Connection
*conn
, value option
)
3788 CURLcode result
= CURLE_OK
;
3790 switch (Long_val(option
))
3792 case 0: /* SSLVERIFYHOST_NONE */
3793 case 1: /* SSLVERIFYHOST_EXISTENCE */
3794 case 2: /* SSLVERIFYHOST_HOSTNAME */
3795 result
= curl_easy_setopt(conn
->connection
,
3796 CURLOPT_SSL_VERIFYHOST
,
3797 /* map EXISTENCE to HOSTNAME */
3798 Long_val(option
) == 0 ? 0 : 2);
3802 failwith("Invalid SSLVERIFYHOST Option");
3806 if (result
!= CURLE_OK
)
3807 raiseError(conn
, result
);
3812 static void handleCookieJar(Connection
*conn
, value option
)
3815 CURLcode result
= CURLE_OK
;
3817 Store_field(conn
->ocamlValues
, OcamlCookieJar
, option
);
3819 if (conn
->cookieJar
!= NULL
)
3820 free(conn
->cookieJar
);
3822 conn
->cookieJar
= strdup(String_val(option
));
3824 result
= curl_easy_setopt(conn
->connection
,
3828 if (result
!= CURLE_OK
)
3829 raiseError(conn
, result
);
3834 static void handleSSLCipherList(Connection
*conn
, value option
)
3837 CURLcode result
= CURLE_OK
;
3839 Store_field(conn
->ocamlValues
, OcamlSSLCipherList
, option
);
3841 if (conn
->sslCipherList
!= NULL
)
3842 free(conn
->sslCipherList
);
3844 conn
->sslCipherList
= strdup(String_val(option
));
3846 result
= curl_easy_setopt(conn
->connection
,
3847 CURLOPT_SSL_CIPHER_LIST
,
3848 conn
->sslCipherList
);
3850 if (result
!= CURLE_OK
)
3851 raiseError(conn
, result
);
3856 static void handleHTTPVersion(Connection
*conn
, value option
)
3859 CURLcode result
= CURLE_OK
;
3861 switch (Long_val(option
))
3863 case 0: /* HTTP_VERSION_NONE */
3864 result
= curl_easy_setopt(conn
->connection
,
3865 CURLOPT_HTTP_VERSION
,
3866 CURL_HTTP_VERSION_NONE
);
3869 case 1: /* HTTP_VERSION_1_0 */
3870 result
= curl_easy_setopt(conn
->connection
,
3871 CURLOPT_HTTP_VERSION
,
3872 CURL_HTTP_VERSION_1_0
);
3875 case 2: /* HTTP_VERSION_1_1 */
3876 result
= curl_easy_setopt(conn
->connection
,
3877 CURLOPT_HTTP_VERSION
,
3878 CURL_HTTP_VERSION_1_1
);
3882 failwith("Invalid HTTP_VERSION Option");
3886 if (result
!= CURLE_OK
)
3887 raiseError(conn
, result
);
3892 static void handleFTPUseEPSV(Connection
*conn
, value option
)
3895 CURLcode result
= CURLE_OK
;
3897 result
= curl_easy_setopt(conn
->connection
,
3898 CURLOPT_FTP_USE_EPSV
,
3901 if (result
!= CURLE_OK
)
3902 raiseError(conn
, result
);
3907 static void handleDNSCacheTimeout(Connection
*conn
, value option
)
3910 CURLcode result
= CURLE_OK
;
3912 result
= curl_easy_setopt(conn
->connection
,
3913 CURLOPT_DNS_CACHE_TIMEOUT
,
3916 if (result
!= CURLE_OK
)
3917 raiseError(conn
, result
);
3922 static void handleDNSUseGlobalCache(Connection
*conn
, value option
)
3925 CURLcode result
= CURLE_OK
;
3927 result
= curl_easy_setopt(conn
->connection
,
3928 CURLOPT_DNS_USE_GLOBAL_CACHE
,
3931 if (result
!= CURLE_OK
)
3932 raiseError(conn
, result
);
3937 static void handleDebugFunction(Connection
*conn
, value option
)
3940 CURLcode result
= CURLE_OK
;
3942 if (Tag_val(option
) == Closure_tag
)
3943 Store_field(conn
->ocamlValues
, OcamlDebugCallback
, option
);
3945 failwith("Not a proper closure");
3947 result
= curl_easy_setopt(conn
->connection
,
3948 CURLOPT_DEBUGFUNCTION
,
3950 if (result
!= CURLE_OK
)
3951 raiseError(conn
, result
);
3953 result
= curl_easy_setopt(conn
->connection
,
3957 if (result
!= CURLE_OK
)
3958 raiseError(conn
, result
);
3963 static void handlePrivate(Connection
*conn
, value option
)
3965 #if HAVE_DECL_CURLOPT_PRIVATE
3967 CURLcode result
= CURLE_OK
;
3969 Store_field(conn
->ocamlValues
, OcamlPrivate
, option
);
3971 if (conn
->private != NULL
)
3972 free(conn
->private);
3974 conn
->private = strdup(String_val(option
));
3976 result
= curl_easy_setopt(conn
->connection
,
3980 if (result
!= CURLE_OK
)
3981 raiseError(conn
, result
);
3985 #pragma message("libcurl does not implement CURLOPT_PRIVATE")
3986 failwith("libcurl does not implement CURLOPT_PRIVATE");
3990 static void handleHTTP200Aliases(Connection
*conn
, value option
)
3992 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
3994 CAMLlocal1(listIter
);
3995 CURLcode result
= CURLE_OK
;
3997 Store_field(conn
->ocamlValues
, OcamlHTTP200Aliases
, option
);
3999 free_curl_slist(conn
->http200Aliases
);
4000 conn
->http200Aliases
= NULL
;
4004 while (!Is_long(listIter
))
4006 conn
->http200Aliases
= curl_slist_append(conn
->http200Aliases
, String_val(Field(listIter
, 0)));
4008 listIter
= Field(listIter
, 1);
4011 result
= curl_easy_setopt(conn
->connection
,
4012 CURLOPT_HTTP200ALIASES
,
4013 conn
->http200Aliases
);
4015 if (result
!= CURLE_OK
)
4016 raiseError(conn
, result
);
4020 #pragma message("libcurl does not implement CURLOPT_HTTP200ALIASES")
4021 failwith("libcurl does not implement CURLOPT_HTTP200ALIASES");
4025 static void handleUnrestrictedAuth(Connection
*conn
, value option
)
4027 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
4029 CURLcode result
= CURLE_OK
;
4031 result
= curl_easy_setopt(conn
->connection
,
4032 CURLOPT_UNRESTRICTED_AUTH
,
4035 if (result
!= CURLE_OK
)
4036 raiseError(conn
, result
);
4040 #pragma message("libcurl does not implement CURLOPT_UNRESTRICTED_AUTH")
4041 failwith("libcurl does not implement CURLOPT_UNRESTRICTED_AUTH");
4045 static void handleFTPUseEPRT(Connection
*conn
, value option
)
4047 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
4049 CURLcode result
= CURLE_OK
;
4051 result
= curl_easy_setopt(conn
->connection
,
4052 CURLOPT_FTP_USE_EPRT
,
4055 if (result
!= CURLE_OK
)
4056 raiseError(conn
, result
);
4060 #pragma message("libcurl does not implement CURLOPT_FTP_USE_EPRT")
4061 failwith("libcurl does not implement CURLOPT_FTP_USE_EPRT");
4065 static void handleHTTPAuth(Connection
*conn
, value option
)
4067 #if HAVE_DECL_CURLOPT_HTTPAUTH
4069 CAMLlocal1(listIter
);
4070 CURLcode result
= CURLE_OK
;
4071 long auth
= CURLAUTH_NONE
;
4075 while (!Is_long(listIter
))
4077 switch (Long_val(Field(listIter
, 0)))
4079 case 0: /* CURLAUTH_BASIC */
4080 auth
|= CURLAUTH_BASIC
;
4083 case 1: /* CURLAUTH_DIGEST */
4084 auth
|= CURLAUTH_DIGEST
;
4087 case 2: /* CURLAUTH_GSSNEGOTIATE */
4088 auth
|= CURLAUTH_GSSNEGOTIATE
;
4091 case 3: /* CURLAUTH_NTLM */
4092 auth
|= CURLAUTH_NTLM
;
4095 case 4: /* CURLAUTH_ANY */
4096 auth
|= CURLAUTH_ANY
;
4099 case 5: /* CURLAUTH_ANYSAFE */
4100 auth
|= CURLAUTH_ANYSAFE
;
4104 failwith("Invalid HTTPAUTH Value");
4108 listIter
= Field(listIter
, 1);
4111 result
= curl_easy_setopt(conn
->connection
,
4115 if (result
!= CURLE_OK
)
4116 raiseError(conn
, result
);
4120 #pragma message("libcurl does not implement CURLOPT_HTTPAUTH")
4121 failwith("libcurl does not implement CURLOPT_HTTPAUTH");
4125 static void handleFTPCreateMissingDirs(Connection
*conn
, value option
)
4127 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
4129 CURLcode result
= CURLE_OK
;
4131 result
= curl_easy_setopt(conn
->connection
,
4132 CURLOPT_FTP_CREATE_MISSING_DIRS
,
4135 if (result
!= CURLE_OK
)
4136 raiseError(conn
, result
);
4140 #pragma message("libcurl does not implement CURLOPT_FTP_CREATE_MISSING_DIRS")
4141 failwith("libcurl does not implement CURLOPT_FTP_CREATE_MISSING_DIRS");
4145 static void handleProxyAuth(Connection
*conn
, value option
)
4147 #if HAVE_DECL_CURLOPT_PROXYAUTH
4149 CAMLlocal1(listIter
);
4150 CURLcode result
= CURLE_OK
;
4151 long auth
= CURLAUTH_NONE
;
4155 while (!Is_long(listIter
))
4157 switch (Long_val(Field(listIter
, 0)))
4159 case 0: /* CURLAUTH_BASIC */
4160 auth
|= CURLAUTH_BASIC
;
4163 case 1: /* CURLAUTH_DIGEST */
4164 auth
|= CURLAUTH_DIGEST
;
4167 case 2: /* CURLAUTH_GSSNEGOTIATE */
4168 auth
|= CURLAUTH_GSSNEGOTIATE
;
4171 case 3: /* CURLAUTH_NTLM */
4172 auth
|= CURLAUTH_NTLM
;
4175 case 4: /* CURLAUTH_ANY */
4176 auth
|= CURLAUTH_ANY
;
4179 case 5: /* CURLAUTH_ANYSAFE */
4180 auth
|= CURLAUTH_ANYSAFE
;
4184 failwith("Invalid HTTPAUTH Value");
4188 listIter
= Field(listIter
, 1);
4191 result
= curl_easy_setopt(conn
->connection
,
4195 if (result
!= CURLE_OK
)
4196 raiseError(conn
, result
);
4200 #pragma message("libcurl does not implement CURLOPT_PROXYAUTH")
4201 failwith("libcurl does not implement CURLOPT_PROXYAUTH");
4205 static void handleFTPResponseTimeout(Connection
*conn
, value option
)
4207 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
4209 CURLcode result
= CURLE_OK
;
4211 result
= curl_easy_setopt(conn
->connection
,
4212 CURLOPT_FTP_RESPONSE_TIMEOUT
,
4215 if (result
!= CURLE_OK
)
4216 raiseError(conn
, result
);
4220 #pragma message("libcurl does not implement CURLOPT_FTP_RESPONSE_TIMEOUT")
4221 failwith("libcurl does not implement CURLOPT_FTP_RESPONSE_TIMEOUT");
4225 static void handleIPResolve(Connection
*conn
, value option
)
4227 #if HAVE_DECL_CURLOPT_IPRESOLVE
4229 CURLcode result
= CURLE_OK
;
4231 switch (Long_val(option
))
4233 case 0: /* CURL_IPRESOLVE_WHATEVER */
4234 result
= curl_easy_setopt(conn
->connection
,
4236 CURL_IPRESOLVE_WHATEVER
);
4239 case 1: /* CURL_IPRESOLVE_V4 */
4240 result
= curl_easy_setopt(conn
->connection
,
4245 case 2: /* CURL_IPRESOLVE_V6 */
4246 result
= curl_easy_setopt(conn
->connection
,
4252 failwith("Invalid IPRESOLVE Value");
4256 if (result
!= CURLE_OK
)
4257 raiseError(conn
, result
);
4261 #pragma message("libcurl does not implement CURLOPT_IPRESOLVE")
4262 failwith("libcurl does not implement CURLOPT_IPRESOLVE");
4266 static void handleMaxFileSize(Connection
*conn
, value option
)
4268 #if HAVE_DECL_CURLOPT_MAXFILESIZE
4270 CURLcode result
= CURLE_OK
;
4272 result
= curl_easy_setopt(conn
->connection
,
4273 CURLOPT_MAXFILESIZE
,
4276 if (result
!= CURLE_OK
)
4277 raiseError(conn
, result
);
4281 #pragma message("libcurl does not implement CURLOPT_MAXFILESIZE")
4282 failwith("libcurl does not implement CURLOPT_MAXFILESIZE");
4286 static void handleInFileSizeLarge(Connection
*conn
, value option
)
4288 #if HAVE_DECL_CURLOPT_INFILESIZE_LARGE
4290 CURLcode result
= CURLE_OK
;
4292 result
= curl_easy_setopt(conn
->connection
,
4293 CURLOPT_INFILESIZE_LARGE
,
4296 if (result
!= CURLE_OK
)
4297 raiseError(conn
, result
);
4301 #pragma message("libcurl does not implement CURLOPT_INFILESIZE_LARGE")
4302 failwith("libcurl does not implement CURLOPT_INFILESIZE_LARGE");
4306 static void handleResumeFromLarge(Connection
*conn
, value option
)
4308 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
4310 CURLcode result
= CURLE_OK
;
4312 result
= curl_easy_setopt(conn
->connection
,
4313 CURLOPT_RESUME_FROM_LARGE
,
4316 if (result
!= CURLE_OK
)
4317 raiseError(conn
, result
);
4321 #pragma message("libcurl does not implement CURLOPT_RESUME_FROM_LARGE")
4322 failwith("libcurl does not implement CURLOPT_RESUME_FROM_LARGE");
4326 static void handleMaxFileSizeLarge(Connection
*conn
, value option
)
4328 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
4330 CURLcode result
= CURLE_OK
;
4332 result
= curl_easy_setopt(conn
->connection
,
4333 CURLOPT_MAXFILESIZE_LARGE
,
4336 if (result
!= CURLE_OK
)
4337 raiseError(conn
, result
);
4341 #pragma message("libcurl does not implement CURLOPT_MAXFILESIZE_LARGE")
4342 failwith("libcurl does not implement CURLOPT_MAXFILESIZE_LARGE");
4346 static void handleNETRCFile(Connection
*conn
, value option
)
4348 #if HAVE_DECL_CURLOPT_NETRC_FILE
4350 CURLcode result
= CURLE_OK
;
4352 Store_field(conn
->ocamlValues
, OcamlNETRCFile
, option
);
4354 if (conn
->netrcFile
!= NULL
)
4355 free(conn
->netrcFile
);
4357 conn
->netrcFile
= strdup(String_val(option
));
4359 result
= curl_easy_setopt(conn
->connection
,
4363 if (result
!= CURLE_OK
)
4364 raiseError(conn
, result
);
4368 #pragma message("libcurl does not implement CURLOPT_NETRC_FILE")
4369 failwith("libcurl does not implement CURLOPT_NETRC_FILE");
4373 static void handleFTPSSL(Connection
*conn
, value option
)
4375 #if HAVE_DECL_CURLOPT_FTP_SSL
4377 CURLcode result
= CURLE_OK
;
4379 switch (Long_val(option
))
4381 case 0: /* CURLFTPSSL_NONE */
4382 result
= curl_easy_setopt(conn
->connection
,
4387 case 1: /* CURLFTPSSL_TRY */
4388 result
= curl_easy_setopt(conn
->connection
,
4393 case 2: /* CURLFTPSSL_CONTROL */
4394 result
= curl_easy_setopt(conn
->connection
,
4396 CURLFTPSSL_CONTROL
);
4399 case 3: /* CURLFTPSSL_ALL */
4400 result
= curl_easy_setopt(conn
->connection
,
4406 failwith("Invalid FTP_SSL Value");
4410 if (result
!= CURLE_OK
)
4411 raiseError(conn
, result
);
4415 #pragma message("libcurl does not implement CURLOPT_FTP_SSL")
4416 failwith("libcurl does not implement CURLOPT_FTP_SSL");
4420 static void handlePostFieldSizeLarge(Connection
*conn
, value option
)
4422 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
4424 CURLcode result
= CURLE_OK
;
4426 result
= curl_easy_setopt(conn
->connection
,
4427 CURLOPT_POSTFIELDSIZE_LARGE
,
4430 if (result
!= CURLE_OK
)
4431 raiseError(conn
, result
);
4435 #pragma message("libcurl does not implement CURLOPT_POSTFIELDSIZE_LARGE")
4436 failwith("libcurl does not implement CURLOPT_POSTFIELDSIZE_LARGE");
4440 static void handleTCPNoDelay(Connection
*conn
, value option
)
4442 #if HAVE_DECL_CURLOPT_TCP_NODELAY
4444 CURLcode result
= CURLE_OK
;
4446 result
= curl_easy_setopt(conn
->connection
,
4447 CURLOPT_TCP_NODELAY
,
4450 if (result
!= CURLE_OK
)
4451 raiseError(conn
, result
);
4455 #pragma message("libcurl does not implement CURLOPT_TCP_NODELAY")
4456 failwith("libcurl does not implement CURLOPT_TCP_NODELAY");
4460 static void handleFTPSSLAuth(Connection
*conn
, value option
)
4462 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
4464 CURLcode result
= CURLE_OK
;
4466 switch (Long_val(option
))
4468 case 0: /* CURLFTPAUTH_DEFAULT */
4469 result
= curl_easy_setopt(conn
->connection
,
4471 CURLFTPAUTH_DEFAULT
);
4474 case 1: /* CURLFTPAUTH_SSL */
4475 result
= curl_easy_setopt(conn
->connection
,
4480 case 2: /* CURLFTPAUTH_TLS */
4481 result
= curl_easy_setopt(conn
->connection
,
4487 failwith("Invalid FTPSSLAUTH value");
4491 if (result
!= CURLE_OK
)
4492 raiseError(conn
, result
);
4496 #pragma message("libcurl does not implement CURLOPT_FTPSSLAUTH")
4497 failwith("libcurl does not implement CURLOPT_FTPSSLAUTH");
4501 static void handleIOCTLFunction(Connection
*conn
, value option
)
4503 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
4505 CURLcode result
= CURLE_OK
;
4507 if (Tag_val(option
) == Closure_tag
)
4508 Store_field(conn
->ocamlValues
, OcamlIOCTLCallback
, option
);
4510 failwith("Not a proper closure");
4512 result
= curl_easy_setopt(conn
->connection
,
4513 CURLOPT_IOCTLFUNCTION
,
4515 if (result
!= CURLE_OK
)
4516 raiseError(conn
, result
);
4518 result
= curl_easy_setopt(conn
->connection
,
4522 if (result
!= CURLE_OK
)
4523 raiseError(conn
, result
);
4527 #pragma message("libcurl does not implement CURLOPT_IOCTLFUNCTION")
4528 failwith("libcurl does not implement CURLOPT_IOCTLFUNCTION");
4532 static void handleFTPAccount(Connection
*conn
, value option
)
4534 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
4536 CURLcode result
= CURLE_OK
;
4538 Store_field(conn
->ocamlValues
, OcamlFTPAccount
, option
);
4540 if (conn
->ftpaccount
!= NULL
)
4541 free(conn
->ftpaccount
);
4543 conn
->ftpaccount
= strdup(String_val(option
));
4545 result
= curl_easy_setopt(conn
->connection
,
4546 CURLOPT_FTP_ACCOUNT
,
4549 if (result
!= CURLE_OK
)
4550 raiseError(conn
, result
);
4554 #pragma message("libcurl does not implement CURLOPT_FTP_ACCOUNT")
4555 failwith("libcurl does not implement CURLOPT_FTP_ACCOUNT");
4559 static void handleCookieList(Connection
*conn
, value option
)
4561 #if HAVE_DECL_CURLOPT_COOKIELIST
4563 CURLcode result
= CURLE_OK
;
4565 Store_field(conn
->ocamlValues
, OcamlCookieList
, option
);
4567 if (conn
->cookielist
!= NULL
)
4568 free(conn
->cookielist
);
4570 conn
->cookielist
= strdup(String_val(option
));
4572 result
= curl_easy_setopt(conn
->connection
,
4576 if (result
!= CURLE_OK
)
4577 raiseError(conn
, result
);
4581 #pragma message("libcurl does not implement CURLOPT_COOKIELIST")
4582 failwith("libcurl does not implement CURLOPT_COOKIELIST");
4586 static void handleIgnoreContentLength(Connection
*conn
, value option
)
4588 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
4590 CURLcode result
= CURLE_OK
;
4592 result
= curl_easy_setopt(conn
->connection
,
4593 CURLOPT_IGNORE_CONTENT_LENGTH
,
4596 if (result
!= CURLE_OK
)
4597 raiseError(conn
, result
);
4601 #pragma message("libcurl does not implement CURLOPT_IGNORE_CONTENT_LENGTH")
4602 failwith("libcurl does not implement CURLOPT_IGNORE_CONTENT_LENGTH");
4606 static void handleFTPSkipPASVIP(Connection
*conn
, value option
)
4608 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
4610 CURLcode result
= CURLE_OK
;
4612 result
= curl_easy_setopt(conn
->connection
,
4613 CURLOPT_FTP_SKIP_PASV_IP
,
4616 if (result
!= CURLE_OK
)
4617 raiseError(conn
, result
);
4621 #pragma message("libcurl does not implement CURLOPT_FTP_SKIP_PASV_IP")
4622 failwith("libcurl does not implement CURLOPT_FTP_SKIP_PASV_IP");
4626 static void handleFTPFileMethod(Connection
*conn
, value option
)
4628 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
4630 CURLcode result
= CURLE_OK
;
4632 switch (Long_val(option
))
4634 case 0: /* CURLFTPMETHOD_DEFAULT */
4635 result
= curl_easy_setopt(conn
->connection
,
4636 CURLOPT_FTP_FILEMETHOD
,
4637 CURLFTPMETHOD_DEFAULT
);
4640 case 1: /* CURLFTMETHOD_MULTICWD */
4641 result
= curl_easy_setopt(conn
->connection
,
4642 CURLOPT_FTP_FILEMETHOD
,
4643 CURLFTPMETHOD_MULTICWD
);
4646 case 2: /* CURLFTPMETHOD_NOCWD */
4647 result
= curl_easy_setopt(conn
->connection
,
4648 CURLOPT_FTP_FILEMETHOD
,
4649 CURLFTPMETHOD_NOCWD
);
4652 case 3: /* CURLFTPMETHOD_SINGLECWD */
4653 result
= curl_easy_setopt(conn
->connection
,
4654 CURLOPT_FTP_FILEMETHOD
,
4655 CURLFTPMETHOD_SINGLECWD
);
4658 failwith("Invalid FTP_FILEMETHOD value");
4662 if (result
!= CURLE_OK
)
4663 raiseError(conn
, result
);
4667 #pragma message("libcurl does not implement CURLOPT_FTP_FILEMETHOD")
4668 failwith("libcurl does not implement CURLOPT_FTP_FILEMETHOD");
4672 static void handleLocalPort(Connection
*conn
, value option
)
4674 #if HAVE_DECL_CURLOPT_LOCALPORT
4676 CURLcode result
= CURLE_OK
;
4678 result
= curl_easy_setopt(conn
->connection
,
4682 if (result
!= CURLE_OK
)
4683 raiseError(conn
, result
);
4687 #pragma message("libcurl does not implement CURLOPT_LOCALPORT")
4688 failwith("libcurl does not implement CURLOPT_LOCALPORT");
4692 static void handleLocalPortRange(Connection
*conn
, value option
)
4694 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
4696 CURLcode result
= CURLE_OK
;
4698 result
= curl_easy_setopt(conn
->connection
,
4699 CURLOPT_LOCALPORTRANGE
,
4702 if (result
!= CURLE_OK
)
4703 raiseError(conn
, result
);
4707 #pragma message("libcurl does not implement CURLOPT_LOCALPORTRANGE")
4708 failwith("libcurl does not implement CURLOPT_LOCALPORTRANGE");
4712 static void handleConnectOnly(Connection
*conn
, value option
)
4714 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
4716 CURLcode result
= CURLE_OK
;
4718 result
= curl_easy_setopt(conn
->connection
,
4719 CURLOPT_CONNECT_ONLY
,
4722 if (result
!= CURLE_OK
)
4723 raiseError(conn
, result
);
4727 #pragma message("libcurl does not implement CURLOPT_CONNECT_ONLY")
4728 failwith("libcurl does not implement CURLOPT_CONNECT_ONLY");
4732 static void handleMaxSendSpeedLarge(Connection
*conn
, value option
)
4734 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
4736 CURLcode result
= CURLE_OK
;
4738 result
= curl_easy_setopt(conn
->connection
,
4739 CURLOPT_MAX_SEND_SPEED_LARGE
,
4742 if (result
!= CURLE_OK
)
4743 raiseError(conn
, result
);
4747 #pragma message("libcurl does not implement CURLOPT_MAX_SEND_SPEED_LARGE")
4748 failwith("libcurl does not implement CURLOPT_MAX_SEND_SPEED_LARGE");
4752 static void handleMaxRecvSpeedLarge(Connection
*conn
, value option
)
4754 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
4756 CURLcode result
= CURLE_OK
;
4758 result
= curl_easy_setopt(conn
->connection
,
4759 CURLOPT_MAX_RECV_SPEED_LARGE
,
4762 if (result
!= CURLE_OK
)
4763 raiseError(conn
, result
);
4767 #pragma message("libcurl does not implement CURLOPT_MAX_RECV_SPEED_LARGE")
4768 failwith("libcurl does not implement CURLOPT_MAX_RECV_SPEED_LARGE");
4772 static void handleFTPAlternativeToUser(Connection
*conn
, value option
)
4774 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
4776 CURLcode result
= CURLE_OK
;
4778 Store_field(conn
->ocamlValues
, OcamlFTPAlternativeToUser
, option
);
4780 if (conn
->ftpAlternativeToUser
!= NULL
)
4781 free(conn
->ftpAlternativeToUser
);
4783 conn
->ftpAlternativeToUser
= strdup(String_val(option
));
4785 result
= curl_easy_setopt(conn
->connection
,
4786 CURLOPT_FTP_ALTERNATIVE_TO_USER
,
4787 conn
->ftpAlternativeToUser
);
4789 if (result
!= CURLE_OK
)
4790 raiseError(conn
, result
);
4794 #pragma message("libcurl does not implement CURLOPT_FTP_ALTERNATIVE_TO_USER")
4795 failwith("libcurl does not implement CURLOPT_FTP_ALTERNATIVE_TO_USER");
4799 static void handleSSLSessionIdCache(Connection
*conn
, value option
)
4801 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
4803 CURLcode result
= CURLE_OK
;
4805 result
= curl_easy_setopt(conn
->connection
,
4806 CURLOPT_SSL_SESSIONID_CACHE
,
4809 if (result
!= CURLE_OK
)
4810 raiseError(conn
, result
);
4814 #pragma message("libcurl does not implement CURLOPT_SSL_SESSIONID_CACHE")
4815 failwith("libcurl does not implement CURLOPT_SSL_SESSIONID_CACHE");
4819 static void handleSSHAuthTypes(Connection
*conn
, value option
)
4821 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
4823 CAMLlocal1(listIter
);
4824 CURLcode result
= CURLE_OK
;
4825 long authTypes
= CURLSSH_AUTH_NONE
;
4829 while (!Is_long(listIter
))
4831 switch (Long_val(Field(listIter
, 0)))
4833 case 0: /* CURLSSH_AUTH_ANY */
4834 authTypes
|= CURLSSH_AUTH_ANY
;
4837 case 1: /* CURLSSH_AUTH_PUBLICKEY */
4838 authTypes
|= CURLSSH_AUTH_PUBLICKEY
;
4841 case 2: /* CURLSSH_AUTH_PASSWORD */
4842 authTypes
|= CURLSSH_AUTH_PASSWORD
;
4845 case 3: /* CURLSSH_AUTH_HOST */
4846 authTypes
|= CURLSSH_AUTH_HOST
;
4849 case 4: /* CURLSSH_AUTH_KEYBOARD */
4850 authTypes
|= CURLSSH_AUTH_KEYBOARD
;
4854 failwith("Invalid CURLSSH_AUTH_TYPES Value");
4858 listIter
= Field(listIter
, 1);
4861 result
= curl_easy_setopt(conn
->connection
,
4862 CURLOPT_SSH_AUTH_TYPES
,
4865 if (result
!= CURLE_OK
)
4866 raiseError(conn
, result
);
4870 #pragma message("libcurl does not implement CURLOPT_SSH_AUTH_TYPES")
4871 failwith("libcurl does not implement CURLOPT_SSH_AUTH_TYPES");
4875 static void handleSSHPublicKeyFile(Connection
*conn
, value option
)
4877 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
4879 CURLcode result
= CURLE_OK
;
4881 Store_field(conn
->ocamlValues
, OcamlSSHPublicKeyFile
, option
);
4883 if (conn
->sshPublicKeyFile
!= NULL
)
4884 free(conn
->sshPublicKeyFile
);
4886 conn
->sshPublicKeyFile
= strdup(String_val(option
));
4888 result
= curl_easy_setopt(conn
->connection
,
4889 CURLOPT_SSH_PUBLIC_KEYFILE
,
4890 conn
->sshPublicKeyFile
);
4892 if (result
!= CURLE_OK
)
4893 raiseError(conn
, result
);
4897 #pragma message("libcurl does not implement CURLOPT_SSH_PUBLIC_KEYFILE")
4898 failwith("libcurl does not implement CURLOPT_SSH_PUBLIC_KEYFILE");
4902 static void handleSSHPrivateKeyFile(Connection
*conn
, value option
)
4904 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
4906 CURLcode result
= CURLE_OK
;
4908 Store_field(conn
->ocamlValues
, OcamlSSHPrivateKeyFile
, option
);
4910 if (conn
->sshPrivateKeyFile
!= NULL
)
4911 free(conn
->sshPrivateKeyFile
);
4913 conn
->sshPrivateKeyFile
= strdup(String_val(option
));
4915 result
= curl_easy_setopt(conn
->connection
,
4916 CURLOPT_SSH_PRIVATE_KEYFILE
,
4917 conn
->sshPrivateKeyFile
);
4919 if (result
!= CURLE_OK
)
4920 raiseError(conn
, result
);
4924 #pragma message("libcurl does not implement CURLOPT_SSH_PRIVATE_KEYFILE")
4925 failwith("libcurl does not implement CURLOPT_SSH_PRIVATE_KEYFILE");
4929 static void handleFTPSSLCCC(Connection
*conn
, value option
)
4931 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
4933 CURLcode result
= CURLE_OK
;
4935 switch (Long_val(option
))
4937 case 0: /* CURLFTPSSL_CCC_NONE */
4938 result
= curl_easy_setopt(conn
->connection
,
4939 CURLOPT_FTP_SSL_CCC
,
4940 CURLFTPSSL_CCC_NONE
);
4943 case 1: /* CURLFTPSSL_CCC_PASSIVE */
4944 result
= curl_easy_setopt(conn
->connection
,
4945 CURLOPT_FTP_SSL_CCC
,
4946 CURLFTPSSL_CCC_PASSIVE
);
4949 case 2: /* CURLFTPSSL_CCC_ACTIVE */
4950 result
= curl_easy_setopt(conn
->connection
,
4951 CURLOPT_FTP_SSL_CCC
,
4952 CURLFTPSSL_CCC_ACTIVE
);
4956 failwith("Invalid FTPSSL_CCC value");
4960 if (result
!= CURLE_OK
)
4961 raiseError(conn
, result
);
4965 #pragma message("libcurl does not implement CURLOPT_FTP_SSL_CCC")
4966 failwith("libcurl does not implement CURLOPT_FTP_SSL_CCC");
4970 static void handleTimeoutMS(Connection
*conn
, value option
)
4972 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
4974 CURLcode result
= CURLE_OK
;
4976 result
= curl_easy_setopt(conn
->connection
,
4980 if (result
!= CURLE_OK
)
4981 raiseError(conn
, result
);
4985 #pragma message("libcurl does not implement CURLOPT_TIMEOUT_MS")
4986 failwith("libcurl does not implement CURLOPT_TIMEOUT_MS");
4990 static void handleConnectTimeoutMS(Connection
*conn
, value option
)
4992 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
4994 CURLcode result
= CURLE_OK
;
4996 result
= curl_easy_setopt(conn
->connection
,
4997 CURLOPT_CONNECTTIMEOUT_MS
,
5000 if (result
!= CURLE_OK
)
5001 raiseError(conn
, result
);
5005 #pragma message("libcurl does not implement CURLOPT_CONNECTTIMEOUT_MS")
5006 failwith("libcurl does not implement CURLOPT_CONNECTTIMEOUT_MS");
5010 static void handleHTTPTransferDecoding(Connection
*conn
, value option
)
5012 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
5014 CURLcode result
= CURLE_OK
;
5016 result
= curl_easy_setopt(conn
->connection
,
5017 CURLOPT_HTTP_TRANSFER_DECODING
,
5020 if (result
!= CURLE_OK
)
5021 raiseError(conn
, result
);
5025 #pragma message("libcurl does not implement CURLOPT_HTTP_TRANSFER_DECODING")
5026 failwith("libcurl does not implement CURLOPT_HTTP_TRANSFER_DECODING");
5030 static void handleHTTPContentDecoding(Connection
*conn
, value option
)
5032 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
5034 CURLcode result
= CURLE_OK
;
5036 result
= curl_easy_setopt(conn
->connection
,
5037 CURLOPT_HTTP_CONTENT_DECODING
,
5040 if (result
!= CURLE_OK
)
5041 raiseError(conn
, result
);
5045 #pragma message("libcurl does not implement CURLOPT_HTTP_CONTENT_DECODING")
5046 failwith("libcurl does not implement CURLOPT_HTTP_CONTENT_DECODING");
5050 static void handleNewFilePerms(Connection
*conn
, value option
)
5052 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
5054 CURLcode result
= CURLE_OK
;
5056 result
= curl_easy_setopt(conn
->connection
,
5057 CURLOPT_NEW_FILE_PERMS
,
5060 if (result
!= CURLE_OK
)
5061 raiseError(conn
, result
);
5065 #pragma message("libcurl does not implement CURLOPT_NEW_FILE_PERMS")
5066 failwith("libcurl does not implement CURLOPT_NEW_FILE_PERMS");
5070 static void handleNewDirectoryPerms(Connection
*conn
, value option
)
5072 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
5074 CURLcode result
= CURLE_OK
;
5076 result
= curl_easy_setopt(conn
->connection
,
5077 CURLOPT_NEW_DIRECTORY_PERMS
,
5080 if (result
!= CURLE_OK
)
5081 raiseError(conn
, result
);
5085 #pragma message("libcurl does not implement CURLOPT_NEW_DIRECTORY_PERMS")
5086 failwith("libcurl does not implement CURLOPT_NEW_DIRECTORY_PERMS");
5090 static void handlePost301(Connection
*conn
, value option
)
5092 #if HAVE_DECL_CURLOPT_POST301
5094 CURLcode result
= CURLE_OK
;
5096 result
= curl_easy_setopt(conn
->connection
,
5100 if (result
!= CURLE_OK
)
5101 raiseError(conn
, result
);
5105 #pragma message("libcurl does not implement CURLOPT_POST301")
5106 failwith("libcurl does not implement CURLOPT_POST301");
5110 static void handleSSHHostPublicKeyMD5(Connection
*conn
, value option
)
5112 #if HAVE_DECL_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
5114 CURLcode result
= CURLE_OK
;
5116 Store_field(conn
->ocamlValues
, OcamlSSHHostPublicKeyMD5
, option
);
5118 if (conn
->sshHostPublicKeyMD5
!= NULL
)
5119 free(conn
->sshHostPublicKeyMD5
);
5121 conn
->sshHostPublicKeyMD5
= strdup(String_val(option
));
5123 result
= curl_easy_setopt(conn
->connection
,
5124 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
,
5125 conn
->sshHostPublicKeyMD5
);
5127 if (result
!= CURLE_OK
)
5128 raiseError(conn
, result
);
5132 #pragma message("libcurl does not implement CURLOPT_SSH_HOST_PUBLIC_KEY_MD5")
5133 failwith("libcurl does not implement CURLOPT_SSH_HOST_PUBLIC_KEY_MD5");
5137 static void handleCopyPostFields(Connection
*conn
, value option
)
5139 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
5141 CURLcode result
= CURLE_OK
;
5143 Store_field(conn
->ocamlValues
, OcamlCopyPostFields
, option
);
5145 if (conn
->copyPostFields
!= NULL
)
5146 free(conn
->copyPostFields
);
5148 conn
->copyPostFields
= strdup(String_val(option
));
5150 result
= curl_easy_setopt(conn
->connection
,
5151 CURLOPT_COPYPOSTFIELDS
,
5152 conn
->copyPostFields
);
5154 if (result
!= CURLE_OK
)
5155 raiseError(conn
, result
);
5159 #pragma message("libcurl does not implement CURLOPT_COPYPOSTFIELDS")
5160 failwith("libcurl does not implement CURLOPT_COPYPOSTFIELDS");
5164 static void handleProxyTransferMode(Connection
*conn
, value option
)
5166 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
5168 CURLcode result
= CURLE_OK
;
5170 result
= curl_easy_setopt(conn
->connection
,
5171 CURLOPT_PROXY_TRANSFER_MODE
,
5174 if (result
!= CURLE_OK
)
5175 raiseError(conn
, result
);
5179 #pragma message("libcurl does not implement CURLOPT_PROXY_TRANSFER_MODE")
5180 failwith("libcurl does not implement CURLOPT_PROXY_TRANSFER_MODE");
5184 static void handleSeekFunction(Connection
*conn
, value option
)
5186 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
5188 CURLcode result
= CURLE_OK
;
5190 if (Tag_val(option
) == Closure_tag
)
5191 Store_field(conn
->ocamlValues
, OcamlSeekFunctionCallback
, option
);
5193 failwith("Not a proper closure");
5195 result
= curl_easy_setopt(conn
->connection
,
5196 CURLOPT_SEEKFUNCTION
,
5199 if (result
!= CURLE_OK
)
5200 raiseError(conn
, result
);
5202 result
= curl_easy_setopt(conn
->connection
,
5206 if (result
!= CURLE_OK
)
5207 raiseError(conn
, result
);
5211 #pragma message("libcurl does not implement CURLOPT_SEEKFUNCTION")
5212 failwith("libcurl does not implement CURLOPT_SEEKFUNCTION");
5216 static void handleAutoReferer(Connection
*conn
, value option
)
5218 #if HAVE_DECL_CURLOPT_AUTOREFERER
5220 CURLcode result
= curl_easy_setopt(conn
->connection
,
5221 CURLOPT_AUTOREFERER
,
5224 if (result
!= CURLE_OK
)
5225 raiseError(conn
, result
);
5229 #pragma message("libcurl does not implement CURLOPT_AUTOREFERER")
5230 failwith("libcurl does not implement CURLOPT_AUTOREFERER");
5234 static void handleOpenSocketFunction(Connection
*conn
, value option
)
5236 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
5238 CURLcode result
= CURLE_OK
;
5240 Store_field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
, option
);
5242 result
= curl_easy_setopt(conn
->connection
,
5243 CURLOPT_OPENSOCKETDATA
,
5246 if (result
!= CURLE_OK
)
5247 raiseError(conn
, result
);
5249 result
= curl_easy_setopt(conn
->connection
,
5250 CURLOPT_OPENSOCKETFUNCTION
,
5251 openSocketFunction
);
5253 if (result
!= CURLE_OK
)
5254 raiseError(conn
, result
);
5258 #pragma message("libcurl does not implement CURLOPT_OPENSOCKETFUNCTION")
5259 failwith("libcurl does not implement CURLOPT_OPENSOCKETFUNCTION");
5263 static void handleProxyType(Connection
*conn
, value option
)
5265 #if HAVE_DECL_CURLOPT_PROXYTYPE
5267 CURLcode result
= CURLE_OK
;
5270 switch (Long_val(option
))
5272 case 0: proxy_type
= CURLPROXY_HTTP
; break;
5273 case 1: proxy_type
= CURLPROXY_HTTP_1_0
; break;
5274 case 2: proxy_type
= CURLPROXY_SOCKS4
; break;
5275 case 3: proxy_type
= CURLPROXY_SOCKS5
; break;
5276 case 4: proxy_type
= CURLPROXY_SOCKS4A
; break;
5277 case 5: proxy_type
= CURLPROXY_SOCKS5_HOSTNAME
; break;
5279 failwith("Invalid curl proxy type");
5282 result
= curl_easy_setopt(conn
->connection
,
5286 if (result
!= CURLE_OK
)
5287 raiseError(conn
, result
);
5291 #pragma message("libcurl does not implement CURLOPT_PROXYTYPE")
5292 failwith("libcurl does not implement CURLOPT_PROXYTYPE");
5296 #if HAVE_DECL_CURLOPT_PROTOCOLS && HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
5301 CURLPROTO_HTTP
, CURLPROTO_HTTPS
, CURLPROTO_FTP
, CURLPROTO_FTPS
, CURLPROTO_SCP
, CURLPROTO_SFTP
,
5302 CURLPROTO_TELNET
, CURLPROTO_LDAP
, CURLPROTO_LDAPS
, CURLPROTO_DICT
, CURLPROTO_FILE
, CURLPROTO_TFTP
,
5303 /* factor out with autoconf? */
5304 #if defined(CURLPROTO_IMAP)
5309 #if defined(CURLPROTO_IMAPS)
5314 #if defined(CURLPROTO_POP3)
5319 #if defined(CURLPROTO_POP3S)
5324 #if defined(CURLPROTO_SMTP)
5329 #if defined(CURLPROTO_SMTPS)
5334 #if defined(CURLPROTO_RTSP)
5339 #if defined(CURLPROTO_RTMP)
5344 #if defined(CURLPROTO_RTMPT)
5349 #if defined(CURLPROTO_RTMPE)
5354 #if defined(CURLPROTO_RTMPTE)
5359 #if defined(CURLPROTO_RTMPS)
5364 #if defined(CURLPROTO_RTMPTS)
5369 #if defined(CURLPROTO_GOPHER)
5376 static void handleProtocolsOption(CURLoption curlopt
, Connection
*conn
, value option
)
5379 CURLcode result
= CURLE_OK
;
5383 while (Val_emptylist
!= option
)
5385 index
= Int_val(Field(option
, 0));
5386 if ((index
< 0) || ((size_t)index
>= sizeof(protoMap
) / sizeof(protoMap
[0])))
5387 failwith("Invalid curl protocol");
5389 protocols
= protocols
| protoMap
[index
];
5391 option
= Field(option
, 1);
5394 result
= curl_easy_setopt(conn
->connection
,
5398 if (result
!= CURLE_OK
)
5399 raiseError(conn
, result
);
5404 static void handleProtocols(Connection
*conn
, value option
)
5406 handleProtocolsOption(CURLOPT_PROTOCOLS
, conn
, option
);
5409 static void handleRedirProtocols(Connection
*conn
, value option
)
5411 handleProtocolsOption(CURLOPT_REDIR_PROTOCOLS
, conn
, option
);
5415 #pragma message("libcurl does not implement CURLOPT_PROTOCOLS or CURLOPT_REDIR_PROTOCOLS")
5416 static void handleProtocols(Connection
*conn
, value option
)
5418 failwith("libcurl does not implement CURLOPT_PROTOCOLS");
5420 static void handleRedirProtocols(Connection
*conn
, value option
)
5422 failwith("libcurl does not implement CURLOPT_REDIR_PROTOCOLS");
5426 #if HAVE_DECL_CURLOPT_RESOLVE
5427 static void handleResolve(Connection
*conn
, value option
)
5432 CURLcode result
= CURLE_OK
;
5434 free_curl_slist(conn
->resolve
);
5435 conn
->resolve
= NULL
;
5439 while (head
!= Val_emptylist
)
5441 conn
->resolve
= curl_slist_append(conn
->resolve
, String_val(Field(head
,0)));
5442 head
= Field(head
, 1);
5445 result
= curl_easy_setopt(conn
->connection
,
5449 if (result
!= CURLE_OK
)
5450 raiseError(conn
, result
);
5456 #pragma message("libcurl does not implement CURLOPT_RESOLVE")
5457 static void handleResolve(Connection
*conn
, value option
)
5459 failwith("libcurl does not implement CURLOPT_RESOLVE");
5463 #if HAVE_DECL_CURLOPT_DNS_SERVERS
5464 static void handleDnsServers(Connection
*conn
, value option
)
5468 CURLcode result
= CURLE_OK
;
5469 free_if(conn
->dns_servers
);
5471 conn
->dns_servers
= strdup(String_val(option
));
5473 result
= curl_easy_setopt(conn
->connection
,
5474 CURLOPT_DNS_SERVERS
,
5477 if (result
!= CURLE_OK
)
5478 raiseError(conn
, result
);
5483 #pragma message("libcurl does not implement CURLOPT_DNS_SERVERS")
5484 static void handleDnsServers(Connection
*conn
, value option
)
5486 failwith("libcurl does not implement CURLOPT_DNS_SERVERS");
5491 ** curl_easy_setopt helper function
5494 CAMLprim value
helper_curl_easy_setopt(value conn
, value option
)
5496 CAMLparam2(conn
, option
);
5498 Connection
*connection
= Connection_val(conn
);
5500 checkConnection(connection
);
5502 if (Is_long(option
))
5506 sprintf(error
, "Unimplemented Option: %s",
5507 findOption(unimplementedOptionMap
,
5508 (CURLoption
)(Long_val(option
))));
5513 if (!Is_block(option
))
5514 failwith("Not a block");
5516 if (Wosize_val(option
) < 1)
5517 failwith("Insufficient data in block");
5519 data
= Field(option
, 0);
5521 if (Tag_val(option
) < sizeof(implementedOptionMap
)/sizeof(CURLOptionMapping
))
5522 (*implementedOptionMap
[Tag_val(option
)].optionHandler
)(connection
,
5525 failwith("Invalid CURLOPT Option");
5527 CAMLreturn(Val_unit
);
5531 ** curl_easy_perform helper function
5534 CAMLprim value
helper_curl_easy_perform(value conn
)
5537 CURLcode result
= CURLE_OK
;
5538 Connection
*connection
= Connection_val(conn
);
5540 checkConnection(connection
);
5542 enter_blocking_section();
5543 result
= curl_easy_perform(connection
->connection
);
5544 leave_blocking_section();
5546 if (result
!= CURLE_OK
)
5547 raiseError(connection
, result
);
5549 CAMLreturn(Val_unit
);
5553 ** curl_easy_cleanup helper function
5556 CAMLprim value
helper_curl_easy_cleanup(value conn
)
5559 Connection
*connection
= Connection_val(conn
);
5561 checkConnection(connection
);
5563 removeConnection(connection
);
5565 CAMLreturn(Val_unit
);
5569 ** curl_easy_duphandle helper function
5572 CAMLprim value
helper_curl_easy_duphandle(value conn
)
5576 Connection
*connection
= Connection_val(conn
);
5578 checkConnection(connection
);
5580 result
= caml_alloc(1, Abstract_tag
);
5581 Field(result
, 0) = (value
)duplicateConnection(connection
);
5587 ** curl_easy_getinfo helper function
5590 enum GetInfoResultType
{
5591 StringValue
, LongValue
, DoubleValue
, StringListValue
5594 value
convertStringList(struct curl_slist
*slist
)
5597 CAMLlocal3(result
, current
, next
);
5598 struct curl_slist
*p
= slist
;
5600 result
= Val_int(0);
5601 current
= Val_int(0);
5606 next
= alloc_tuple(2);
5607 Store_field(next
, 0, copy_string(p
->data
));
5608 Store_field(next
, 1, Val_int(0));
5610 if (result
== Val_int(0))
5613 if (current
!= Val_int(0))
5614 Store_field(current
, 1, next
);
5621 curl_slist_free_all(slist
);
5626 CAMLprim value
helper_curl_easy_getinfo(value conn
, value option
)
5628 CAMLparam2(conn
, option
);
5630 CURLcode curlResult
;
5631 Connection
*connection
= Connection_val(conn
);
5632 enum GetInfoResultType resultType
;
5633 char *strValue
= NULL
;
5636 struct curl_slist
*stringListValue
= NULL
;
5638 checkConnection(connection
);
5640 switch(Long_val(option
))
5642 #if HAVE_DECL_CURLINFO_EFFECTIVE_URL
5643 case 0: /* CURLINFO_EFFECTIVE_URL */
5644 resultType
= StringValue
;
5646 curlResult
= curl_easy_getinfo(connection
->connection
,
5647 CURLINFO_EFFECTIVE_URL
,
5651 #pragma message("libcurl does not provide CURLINFO_EFFECTIVE_URL")
5654 #if HAVE_DECL_CURLINFO_RESPONSE_CODE || HAVE_DECL_CURLINFO_HTTP_CODE
5655 case 1: /* CURLINFO_HTTP_CODE */
5656 case 2: /* CURLINFO_RESPONSE_CODE */
5657 #if HAVE_DECL_CURLINFO_RESPONSE_CODE
5658 resultType
= LongValue
;
5660 curlResult
= curl_easy_getinfo(connection
->connection
,
5661 CURLINFO_RESPONSE_CODE
,
5664 resultType
= LongValue
;
5666 curlResult
= curl_easy_getinfo(connection
->connection
,
5673 #if HAVE_DECL_CURLINFO_TOTAL_TIME
5674 case 3: /* CURLINFO_TOTAL_TIME */
5675 resultType
= DoubleValue
;
5677 curlResult
= curl_easy_getinfo(connection
->connection
,
5678 CURLINFO_TOTAL_TIME
,
5683 #if HAVE_DECL_CURLINFO_NAMELOOKUP_TIME
5684 case 4: /* CURLINFO_NAMELOOKUP_TIME */
5685 resultType
= DoubleValue
;
5687 curlResult
= curl_easy_getinfo(connection
->connection
,
5688 CURLINFO_NAMELOOKUP_TIME
,
5693 #if HAVE_DECL_CURLINFO_CONNECT_TIME
5694 case 5: /* CURLINFO_CONNECT_TIME */
5695 resultType
= DoubleValue
;
5697 curlResult
= curl_easy_getinfo(connection
->connection
,
5698 CURLINFO_CONNECT_TIME
,
5703 #if HAVE_DECL_CURLINFO_PRETRANSFER_TIME
5704 case 6: /* CURLINFO_PRETRANSFER_TIME */
5705 resultType
= DoubleValue
;
5707 curlResult
= curl_easy_getinfo(connection
->connection
,
5708 CURLINFO_PRETRANSFER_TIME
,
5713 #if HAVE_DECL_CURLINFO_SIZE_UPLOAD
5714 case 7: /* CURLINFO_SIZE_UPLOAD */
5715 resultType
= DoubleValue
;
5717 curlResult
= curl_easy_getinfo(connection
->connection
,
5718 CURLINFO_SIZE_UPLOAD
,
5723 #if HAVE_DECL_CURLINFO_SIZE_DOWNLOAD
5724 case 8: /* CURLINFO_SIZE_DOWNLOAD */
5725 resultType
= DoubleValue
;
5727 curlResult
= curl_easy_getinfo(connection
->connection
,
5728 CURLINFO_SIZE_DOWNLOAD
,
5733 #if HAVE_DECL_CURLINFO_SPEED_DOWNLOAD
5734 case 9: /* CURLINFO_SPEED_DOWNLOAD */
5735 resultType
= DoubleValue
;
5737 curlResult
= curl_easy_getinfo(connection
->connection
,
5738 CURLINFO_SPEED_DOWNLOAD
,
5743 #if HAVE_DECL_CURLINFO_SPEED_UPLOAD
5744 case 10: /* CURLINFO_SPEED_UPLOAD */
5745 resultType
= DoubleValue
;
5747 curlResult
= curl_easy_getinfo(connection
->connection
,
5748 CURLINFO_SPEED_UPLOAD
,
5754 #if HAVE_DECL_CURLINFO_HEADER_SIZE
5755 case 11: /* CURLINFO_HEADER_SIZE */
5756 resultType
= LongValue
;
5758 curlResult
= curl_easy_getinfo(connection
->connection
,
5759 CURLINFO_HEADER_SIZE
,
5764 #if HAVE_DECL_CURLINFO_REQUEST_SIZE
5765 case 12: /* CURLINFO_REQUEST_SIZE */
5766 resultType
= LongValue
;
5768 curlResult
= curl_easy_getinfo(connection
->connection
,
5769 CURLINFO_REQUEST_SIZE
,
5774 #if HAVE_DECL_CURLINFO_SSL_VERIFYRESULT
5775 case 13: /* CURLINFO_SSL_VERIFYRESULT */
5776 resultType
= LongValue
;
5778 curlResult
= curl_easy_getinfo(connection
->connection
,
5779 CURLINFO_SSL_VERIFYRESULT
,
5784 #if HAVE_DECL_CURLINFO_FILETIME
5785 case 14: /* CURLINFO_FILETIME */
5786 resultType
= DoubleValue
;
5788 curlResult
= curl_easy_getinfo(connection
->connection
,
5792 doubleValue
= longValue
;
5796 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_DOWNLOAD
5797 case 15: /* CURLINFO_CONTENT_LENGTH_DOWNLOAD */
5798 resultType
= DoubleValue
;
5800 curlResult
= curl_easy_getinfo(connection
->connection
,
5801 CURLINFO_CONTENT_LENGTH_DOWNLOAD
,
5806 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_UPLOAD
5807 case 16: /* CURLINFO_CONTENT_LENGTH_UPLOAD */
5808 resultType
= DoubleValue
;
5810 curlResult
= curl_easy_getinfo(connection
->connection
,
5811 CURLINFO_CONTENT_LENGTH_UPLOAD
,
5816 #if HAVE_DECL_CURLINFO_STARTTRANSFER_TIME
5817 case 17: /* CURLINFO_STARTTRANSFER_TIME */
5818 resultType
= DoubleValue
;
5820 curlResult
= curl_easy_getinfo(connection
->connection
,
5821 CURLINFO_STARTTRANSFER_TIME
,
5826 #if HAVE_DECL_CURLINFO_CONTENT_TYPE
5827 case 18: /* CURLINFO_CONTENT_TYPE */
5828 resultType
= StringValue
;
5830 curlResult
= curl_easy_getinfo(connection
->connection
,
5831 CURLINFO_CONTENT_TYPE
,
5836 #if HAVE_DECL_CURLINFO_REDIRECT_TIME
5837 case 19: /* CURLINFO_REDIRECT_TIME */
5838 resultType
= DoubleValue
;
5840 curlResult
= curl_easy_getinfo(connection
->connection
,
5841 CURLINFO_REDIRECT_TIME
,
5846 #if HAVE_DECL_CURLINFO_REDIRECT_COUNT
5847 case 20: /* CURLINFO_REDIRECT_COUNT */
5848 resultType
= LongValue
;
5850 curlResult
= curl_easy_getinfo(connection
->connection
,
5851 CURLINFO_REDIRECT_COUNT
,
5856 #if HAVE_DECL_CURLINFO_PRIVATE
5857 case 21: /* CURLINFO_PRIVATE */
5858 resultType
= StringValue
;
5860 curlResult
= curl_easy_getinfo(connection
->connection
,
5866 #if HAVE_DECL_CURLINFO_HTTP_CONNECTCODE
5867 case 22: /* CURLINFO_HTTP_CONNECTCODE */
5868 resultType
= LongValue
;
5870 curlResult
= curl_easy_getinfo(connection
->connection
,
5871 CURLINFO_HTTP_CONNECTCODE
,
5876 #if HAVE_DECL_CURLINFO_HTTPAUTH_AVAIL
5877 case 23: /* CURLINFO_HTTPAUTH_AVAIL */
5878 resultType
= LongValue
;
5880 curlResult
= curl_easy_getinfo(connection
->connection
,
5881 CURLINFO_HTTPAUTH_AVAIL
,
5886 #if HAVE_DECL_CURLINFO_PROXYAUTH_AVAIL
5887 case 24: /* CURLINFO_PROXYAUTH_AVAIL */
5888 resultType
= LongValue
;
5890 curlResult
= curl_easy_getinfo(connection
->connection
,
5891 CURLINFO_PROXYAUTH_AVAIL
,
5896 #if HAVE_DECL_CURLINFO_OS_ERRNO
5897 case 25: /* CURLINFO_OS_ERRNO */
5898 resultType
= LongValue
;
5900 curlResult
= curl_easy_getinfo(connection
->connection
,
5906 #if HAVE_DECL_CURLINFO_NUM_CONNECTS
5907 case 26: /* CURLINFO_NUM_CONNECTS */
5908 resultType
= LongValue
;
5910 curlResult
= curl_easy_getinfo(connection
->connection
,
5911 CURLINFO_NUM_CONNECTS
,
5916 #if HAVE_DECL_CURLINFO_SSL_ENGINES
5917 case 27: /* CURLINFO_SSL_ENGINES */
5918 resultType
= StringListValue
;
5920 curlResult
= curl_easy_getinfo(connection
->connection
,
5921 CURLINFO_SSL_ENGINES
,
5926 #if HAVE_DECL_CURLINFO_COOKIELIST
5927 case 28: /* CURLINFO_COOKIELIST */
5928 resultType
= StringListValue
;
5930 curlResult
= curl_easy_getinfo(connection
->connection
,
5931 CURLINFO_COOKIELIST
,
5936 #if HAVE_DECL_CURLINFO_LASTSOCKET
5937 case 29: /* CURLINFO_LASTSOCKET */
5938 resultType
= LongValue
;
5940 curlResult
= curl_easy_getinfo(connection
->connection
,
5941 CURLINFO_LASTSOCKET
,
5946 #if HAVE_DECL_CURLINFO_FTP_ENTRY_PATH
5947 case 30: /* CURLINFO_FTP_ENTRY_PATH */
5948 resultType
= StringValue
;
5950 curlResult
= curl_easy_getinfo(connection
->connection
,
5951 CURLINFO_FTP_ENTRY_PATH
,
5956 #if HAVE_DECL_CURLINFO_REDIRECT_URL
5957 case 31: /* CURLINFO_REDIRECT_URL */
5958 resultType
= StringValue
;
5960 curlResult
= curl_easy_getinfo(connection
->connection
,
5961 CURLINFO_REDIRECT_URL
,
5965 #pragma message("libcurl does not provide CURLINFO_REDIRECT_URL")
5968 #if HAVE_DECL_CURLINFO_PRIMARY_IP
5969 case 32: /* CURLINFO_PRIMARY_IP */
5970 resultType
= StringValue
;
5972 curlResult
= curl_easy_getinfo(connection
->connection
,
5973 CURLINFO_PRIMARY_IP
,
5977 #pragma message("libcurl does not provide CURLINFO_PRIMARY_IP")
5980 #if HAVE_DECL_CURLINFO_LOCAL_IP
5981 case 33: /* CURLINFO_LOCAL_IP */
5982 resultType
= StringValue
;
5984 curlResult
= curl_easy_getinfo(connection
->connection
,
5989 #pragma message("libcurl does not provide CURLINFO_LOCAL_IP")
5992 #if HAVE_DECL_CURLINFO_LOCAL_PORT
5993 case 34: /* CURLINFO_LOCAL_PORT */
5994 resultType
= LongValue
;
5996 curlResult
= curl_easy_getinfo(connection
->connection
,
5997 CURLINFO_LOCAL_PORT
,
6001 #pragma message("libcurl does not provide CURLINFO_LOCAL_PORT")
6004 #if HAVE_DECL_CURLINFO_CONDITION_UNMET
6005 case 35: /* CURLINFO_CONDITION_UNMET */
6006 resultType
= LongValue
;
6008 curlResult
= curl_easy_getinfo(connection
->connection
,
6009 CURLINFO_CONDITION_UNMET
,
6013 #pragma message("libcurl does not provide CURLINFO_CONDITION_UNMET")
6017 failwith("Invalid CURLINFO Option");
6021 if (curlResult
!= CURLE_OK
)
6022 raiseError(connection
, curlResult
);
6027 result
= alloc(1, StringValue
);
6028 Store_field(result
, 0, copy_string(strValue
?strValue
:""));
6032 result
= alloc(1, LongValue
);
6033 Store_field(result
, 0, Val_long(longValue
));
6037 result
= alloc(1, DoubleValue
);
6038 Store_field(result
, 0, copy_double(doubleValue
));
6041 case StringListValue
:
6042 result
= alloc(1, StringListValue
);
6043 Store_field(result
, 0, convertStringList(stringListValue
));
6051 ** curl_escape helper function
6054 CAMLprim value
helper_curl_escape(value str
)
6060 curlResult
= curl_escape(String_val(str
), string_length(str
));
6061 result
= copy_string(curlResult
);
6068 ** curl_unescape helper function
6071 CAMLprim value
helper_curl_unescape(value str
)
6077 curlResult
= curl_unescape(String_val(str
), string_length(str
));
6078 result
= copy_string(curlResult
);
6085 ** curl_getdate helper function
6088 CAMLprim value
helper_curl_getdate(value str
, value now
)
6090 CAMLparam2(str
, now
);
6095 curlNow
= (time_t)Double_val(now
);
6096 curlResult
= curl_getdate(String_val(str
), &curlNow
);
6097 result
= copy_double((double)curlResult
);
6103 ** curl_version helper function
6106 CAMLprim value
helper_curl_version(void)
6112 str
= curl_version();
6113 result
= copy_string(str
);
6118 struct CURLVersionBitsMapping
6124 struct CURLVersionBitsMapping versionBitsMap
[] =
6126 {CURL_VERSION_IPV6
, "ipv6"},
6127 {CURL_VERSION_KERBEROS4
, "kerberos4"},
6128 {CURL_VERSION_SSL
, "ssl"},
6129 {CURL_VERSION_LIBZ
, "libz"},
6130 {CURL_VERSION_NTLM
, "ntlm"},
6131 {CURL_VERSION_GSSNEGOTIATE
, "gssnegotiate"},
6132 {CURL_VERSION_DEBUG
, "debug"},
6133 {CURL_VERSION_CURLDEBUG
, "curldebug"},
6134 {CURL_VERSION_ASYNCHDNS
, "asynchdns"},
6135 {CURL_VERSION_SPNEGO
, "spnego"},
6136 {CURL_VERSION_LARGEFILE
, "largefile"},
6137 {CURL_VERSION_IDN
, "idn"},
6138 {CURL_VERSION_SSPI
, "sspi"},
6139 {CURL_VERSION_CONV
, "conv"},
6140 #if HAVE_DECL_CURL_VERSION_TLSAUTH_SRP
6141 {CURL_VERSION_TLSAUTH_SRP
, "srp"},
6143 #if HAVE_DECL_CURL_VERSION_NTLM_WB
6144 {CURL_VERSION_NTLM_WB
, "wb"},
6148 CAMLprim value
caml_curl_version_info(value unit
)
6151 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6152 const char* const* p
= NULL
;
6155 curl_version_info_data
* data
= curl_version_info(CURLVERSION_NOW
);
6156 if (NULL
== data
) caml_failwith("curl_version_info");
6158 vlist
= Val_emptylist
;
6159 for (p
= data
->protocols
; NULL
!= *p
; p
++)
6161 vlist
= Val_cons(vlist
, caml_copy_string(*p
));
6164 vfeatures
= Val_emptylist
;
6165 for (i
= 0; i
< sizeof(versionBitsMap
)/sizeof(versionBitsMap
[0]); i
++)
6167 if (0 != (versionBitsMap
[i
].code
& data
->features
))
6168 vfeatures
= Val_cons(vfeatures
, caml_copy_string(versionBitsMap
[i
].name
));
6171 vnum
= caml_alloc_tuple(3);
6172 Store_field(vnum
,0,Val_int(0xFF & (data
->version_num
>> 16)));
6173 Store_field(vnum
,1,Val_int(0xFF & (data
->version_num
>> 8)));
6174 Store_field(vnum
,2,Val_int(0xFF & (data
->version_num
)));
6176 v
= caml_alloc_tuple(12);
6177 Store_field(v
,0,caml_copy_string(data
->version
));
6178 Store_field(v
,1,vnum
);
6179 Store_field(v
,2,caml_copy_string(data
->host
));
6180 Store_field(v
,3,vfeatures
);
6181 Store_field(v
,4,data
->ssl_version
? Val_some(caml_copy_string(data
->ssl_version
)) : Val_none
);
6182 Store_field(v
,5,data
->libz_version
? Val_some(caml_copy_string(data
->libz_version
)) : Val_none
);
6183 Store_field(v
,6,vlist
);
6184 Store_field(v
,7,caml_copy_string((data
->age
>= 1 && data
->ares
) ? data
->ares
: ""));
6185 Store_field(v
,8,Val_int((data
->age
>= 1) ? data
->ares_num
: 0));
6186 Store_field(v
,9,caml_copy_string((data
->age
>= 2 && data
->libidn
) ? data
->libidn
: ""));
6187 Store_field(v
,10,Val_int((data
->age
>= 3) ? data
->iconv_ver_num
: 0));
6188 Store_field(v
,11,caml_copy_string((data
->age
>= 3 && data
->libssh_version
) ? data
->libssh_version
: ""));
6193 CAMLprim value
caml_curl_pause(value conn
, value opts
)
6195 CAMLparam2(conn
, opts
);
6196 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6197 Connection
*connection
= Connection_val(conn
);
6201 while (Val_emptylist
!= opts
)
6203 switch (Int_val(Field(opts
,0)))
6205 case 0: bitmask
|= CURLPAUSE_SEND
; break;
6206 case 1: bitmask
|= CURLPAUSE_RECV
; break;
6207 case 2: bitmask
|= CURLPAUSE_ALL
; break;
6208 default: caml_failwith("wrong pauseOption");
6210 opts
= Field(opts
,1);
6213 result
= curl_easy_pause(connection
->connection
,bitmask
);
6214 if (result
!= CURLE_OK
)
6215 raiseError(connection
, result
);
6217 CAMLreturn(Val_unit
);
6221 * Curl multi stack support
6223 * Exported thin wrappers for libcurl are prefixed with caml_curl_multi_.
6224 * Other exported functions are prefixed with caml_curlm_, some of them
6225 * can/should be decomposed into smaller parts.
6228 struct ml_multi_handle
6231 value values
; /* callbacks */
6236 curlmopt_socket_function
,
6237 curlmopt_timer_function
,
6239 /* last, not used */
6243 typedef struct ml_multi_handle ml_multi_handle
;
6245 #define Multi_val(v) (*(ml_multi_handle**)Data_custom_val(v))
6246 #define CURLM_val(v) (Multi_val(v)->handle)
6248 static struct custom_operations curl_multi_ops
= {
6250 custom_finalize_default
,
6251 custom_compare_default
,
6252 custom_hash_default
,
6253 custom_serialize_default
,
6254 custom_deserialize_default
,
6255 #if defined(custom_compare_ext_default)
6256 custom_compare_ext_default
,
6260 CAMLprim value
caml_curl_multi_init(value unit
)
6264 ml_multi_handle
* multi
= (ml_multi_handle
*)caml_stat_alloc(sizeof(ml_multi_handle
));
6265 CURLM
* h
= curl_multi_init();
6269 caml_stat_free(multi
);
6270 failwith("caml_curl_multi_init");
6274 multi
->values
= caml_alloc(multi_values_total
, 0);
6275 caml_register_generational_global_root(&multi
->values
);
6277 v
= caml_alloc_custom(&curl_multi_ops
, sizeof(ml_multi_handle
*), 0, 1);
6278 Multi_val(v
) = multi
;
6283 CAMLprim value
caml_curl_multi_cleanup(value handle
)
6286 ml_multi_handle
* h
= Multi_val(handle
);
6289 CAMLreturn(Val_unit
);
6291 caml_remove_generational_global_root(&h
->values
);
6293 if (CURLM_OK
!= curl_multi_cleanup(h
->handle
))
6294 failwith("caml_curl_multi_cleanup");
6296 Multi_val(handle
) = (ml_multi_handle
*)NULL
;
6298 CAMLreturn(Val_unit
);
6301 static CURL
* curlm_remove_finished(CURLM
* multi_handle
, CURLcode
* result
)
6303 int msgs_in_queue
= 0;
6307 CURLMsg
* msg
= curl_multi_info_read(multi_handle
, &msgs_in_queue
);
6308 if (NULL
== msg
) return NULL
;
6309 if (CURLMSG_DONE
== msg
->msg
)
6311 CURL
* easy_handle
= msg
->easy_handle
;
6312 if (result
) *result
= msg
->data
.result
;
6313 if (CURLM_OK
!= curl_multi_remove_handle(multi_handle
, easy_handle
))
6315 /*failwith("curlm_remove_finished");*/
6322 CAMLprim value
caml_curlm_remove_finished(value v_multi
)
6324 CAMLparam1(v_multi
);
6325 CAMLlocal2(v_easy
, v_tuple
);
6327 CURLM
* multi_handle
;
6330 multi_handle
= CURLM_val(v_multi
);
6332 caml_enter_blocking_section();
6333 handle
= curlm_remove_finished(multi_handle
,&result
);
6334 caml_leave_blocking_section();
6338 CAMLreturn(Val_none
);
6342 /* not good: same handle, but different block */
6343 v_easy
= caml_alloc(1, Abstract_tag
);
6344 Field(v_easy
, 0) = (value
)findConnection(handle
);
6345 v_tuple
= caml_alloc(2, 0);
6346 Store_field(v_tuple
,0,v_easy
);
6347 Store_field(v_tuple
,1,Val_int(result
)); /* CURLcode */
6348 CAMLreturn(Val_some(v_tuple
));
6352 static int curlm_wait_data(CURLM
* multi_handle
)
6354 struct timeval timeout
;
6366 /* set a suitable timeout */
6368 timeout
.tv_usec
= 0;
6370 /* get file descriptors from the transfers */
6371 ret
= curl_multi_fdset(multi_handle
, &fdread
, &fdwrite
, &fdexcep
, &maxfd
);
6373 if (ret
== CURLM_OK
&& maxfd
>= 0)
6375 int rc
= select(maxfd
+1, &fdread
, &fdwrite
, &fdexcep
, &timeout
);
6376 if (-1 != rc
) return 0;
6381 CAMLprim value
caml_curlm_wait_data(value v_multi
)
6383 CAMLparam1(v_multi
);
6385 CURLM
* h
= CURLM_val(v_multi
);
6387 caml_enter_blocking_section();
6388 ret
= curlm_wait_data(h
);
6389 caml_leave_blocking_section();
6391 CAMLreturn(Val_bool(0 == ret
));
6394 CAMLprim value
caml_curl_multi_add_handle(value v_multi
, value v_easy
)
6396 CAMLparam2(v_multi
,v_easy
);
6397 CURLM
* multi
= CURLM_val(v_multi
);
6398 CURL
* easy
= Connection_val(v_easy
)->connection
;
6400 /* may invoke callbacks so need to be consistent with locks */
6401 caml_enter_blocking_section();
6402 if (CURLM_OK
!= curl_multi_add_handle(multi
, easy
))
6404 caml_leave_blocking_section();
6405 failwith("caml_curl_multi_add_handle");
6407 caml_leave_blocking_section();
6409 CAMLreturn(Val_unit
);
6412 CAMLprim value
caml_curl_multi_perform_all(value v_multi
)
6414 CAMLparam1(v_multi
);
6415 int still_running
= 0;
6416 CURLM
* h
= CURLM_val(v_multi
);
6418 caml_enter_blocking_section();
6419 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(h
, &still_running
));
6420 caml_leave_blocking_section();
6422 CAMLreturn(Val_int(still_running
));
6425 CAMLprim value
helper_curl_easy_strerror(value v_code
)
6428 CAMLreturn(caml_copy_string(curl_easy_strerror(Int_val(v_code
))));
6432 * Wrappers for the curl_multi_socket_action infrastructure
6433 * Based on curl hiperfifo.c example
6436 /* FIXME win32unix */
6437 #define Socket_val(v) Int_val(v)
6438 #define Val_socket(v) Val_int(v)
6440 static void raise_error(char const* msg
)
6442 static value
* exception
= NULL
;
6444 if (NULL
== exception
)
6446 exception
= caml_named_value("Curl.Multi.Error");
6447 if (NULL
== exception
) caml_invalid_argument("Curl.Multi.Error");
6450 caml_raise_with_string(*exception
, msg
);
6453 static void check_mcode(CURLMcode code
)
6455 char const *s
= NULL
;
6458 case CURLM_OK
: return;
6459 case CURLM_CALL_MULTI_PERFORM
: s
="CURLM_CALL_MULTI_PERFORM"; break;
6460 case CURLM_BAD_HANDLE
: s
="CURLM_BAD_HANDLE"; break;
6461 case CURLM_BAD_EASY_HANDLE
: s
="CURLM_BAD_EASY_HANDLE"; break;
6462 case CURLM_OUT_OF_MEMORY
: s
="CURLM_OUT_OF_MEMORY"; break;
6463 case CURLM_INTERNAL_ERROR
: s
="CURLM_INTERNAL_ERROR"; break;
6464 case CURLM_UNKNOWN_OPTION
: s
="CURLM_UNKNOWN_OPTION"; break;
6465 case CURLM_LAST
: s
="CURLM_LAST"; break;
6466 case CURLM_BAD_SOCKET
: s
="CURLM_BAD_SOCKET"; break;
6467 default : s
="CURLM_unknown"; break;
6472 CAMLprim value
caml_curl_multi_socket_action(value v_multi
, value v_fd
, value v_kind
)
6474 CAMLparam3(v_multi
, v_fd
, v_kind
);
6475 CURLM
* h
= CURLM_val(v_multi
);
6476 int still_running
= 0;
6477 CURLMcode rc
= CURLM_OK
;
6478 int socket
= Socket_val(v_fd
);
6481 switch (Int_val(v_kind
))
6484 case 1 : kind
|= CURL_CSELECT_IN
; break;
6485 case 2 : kind
|= CURL_CSELECT_OUT
; break;
6486 case 3 : kind
|= CURL_CSELECT_IN
| CURL_CSELECT_OUT
; break;
6488 raise_error("caml_curl_multi_socket_action");
6491 /* fprintf(stdout,"fd %u kind %u\n",Socket_val(v_fd), kind); fflush(stdout); */
6493 caml_enter_blocking_section();
6495 rc
= curl_multi_socket_action(h
, socket
, kind
, &still_running
);
6496 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6497 caml_leave_blocking_section();
6501 CAMLreturn(Val_int(still_running
));
6504 CAMLprim value
caml_curl_multi_socket_all(value v_multi
)
6506 CAMLparam1(v_multi
);
6507 int still_running
= 0;
6508 CURLMcode rc
= CURLM_OK
;
6509 CURLM
* h
= CURLM_val(v_multi
);
6511 caml_enter_blocking_section();
6513 rc
= curl_multi_socket_all(h
, &still_running
);
6514 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6515 caml_leave_blocking_section();
6519 CAMLreturn(Val_int(still_running
));
6522 static int curlm_sock_cb_nolock(CURL
*e
, curl_socket_t sock
, int what
, ml_multi_handle
* multi
, void *sockp
)
6527 (void)sockp
; /* not used */
6529 /* v_what = Val_int(what); */
6532 case CURL_POLL_NONE
: v_what
= Val_int(0); break;
6533 case CURL_POLL_IN
: v_what
= Val_int(1); break;
6534 case CURL_POLL_OUT
: v_what
= Val_int(2); break;
6535 case CURL_POLL_INOUT
: v_what
= Val_int(3); break;
6536 case CURL_POLL_REMOVE
: v_what
= Val_int(4); break;
6538 fprintf(stderr
, "curlm_sock_cb sock=%d what=%d\n", sock
, what
);
6540 raise_error("curlm_sock_cb"); /* FIXME exception from callback */
6543 caml_callback2(Field(multi
->values
,curlmopt_socket_function
),
6544 Val_socket(sock
), v_what
);
6549 static int curlm_sock_cb(CURL
*e
, curl_socket_t sock
, int what
, void *cbp
, void *sockp
)
6552 caml_leave_blocking_section();
6553 ret
= curlm_sock_cb_nolock(e
, sock
, what
, (ml_multi_handle
*)cbp
, sockp
);
6554 caml_enter_blocking_section();
6558 CAMLprim value
caml_curl_multi_socketfunction(value v_multi
, value v_cb
)
6560 CAMLparam2(v_multi
, v_cb
);
6561 ml_multi_handle
* multi
= Multi_val(v_multi
);
6563 Store_field(multi
->values
, curlmopt_socket_function
, v_cb
);
6565 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETFUNCTION
, curlm_sock_cb
);
6566 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETDATA
, multi
);
6568 CAMLreturn(Val_unit
);
6571 static void curlm_timer_cb_nolock(ml_multi_handle
*multi
, long timeout_ms
)
6574 caml_callback(Field(multi
->values
,curlmopt_timer_function
), Val_long(timeout_ms
));
6578 static int curlm_timer_cb(CURLM
*multi
, long timeout_ms
, void *userp
)
6582 caml_leave_blocking_section();
6583 curlm_timer_cb_nolock((ml_multi_handle
*)userp
, timeout_ms
);
6584 caml_enter_blocking_section();
6588 CAMLprim value
caml_curl_multi_timerfunction(value v_multi
, value v_cb
)
6590 CAMLparam2(v_multi
, v_cb
);
6591 ml_multi_handle
* multi
= Multi_val(v_multi
);
6593 Store_field(multi
->values
, curlmopt_timer_function
, v_cb
);
6595 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERFUNCTION
, curlm_timer_cb
);
6596 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERDATA
, multi
);
6598 CAMLreturn(Val_unit
);
6601 CAMLprim value
caml_curl_multi_timeout(value v_multi
)
6603 CAMLparam1(v_multi
);
6605 CURLMcode rc
= CURLM_OK
;
6606 ml_multi_handle
* multi
= Multi_val(v_multi
);
6608 rc
= curl_multi_timeout(multi
->handle
, &ms
);
6612 CAMLreturn(Val_long(ms
));