4 *** Copyright (c) 2003-2008, Lars Nilsson, <lars@quantumchamaeleon.com>
5 *** Copyright (c) 2009, ygrek, <ygrek@autistici.org>
13 /* suppress false gcc warning on seekFunction */
14 #define CURL_DISABLE_TYPECHECK
15 #include <curl/curl.h>
17 #include <caml/alloc.h>
18 #include <caml/memory.h>
19 #include <caml/mlvalues.h>
20 #include <caml/callback.h>
21 #include <caml/fail.h>
22 #include <caml/unixsupport.h>
23 #include <caml/custom.h>
28 #pragma message("No config file given.")
31 void leave_blocking_section(void);
32 void enter_blocking_section(void);
34 #define Val_none Val_int(0)
41 some
= caml_alloc(1, 0);
42 Store_field( some
, 0, v
);
46 static value
Val_pair(value v1
, value v2
)
50 pair
= caml_alloc_small(2,0);
56 static value
Val_cons(value list
, value v
) { return Val_pair(v
,list
); }
58 typedef struct Connection Connection
;
59 typedef struct ConnectionList ConnectionList
;
61 #define Connection_val(v) (*(Connection**)Data_custom_val(v))
74 OcamlProgressCallback
,
78 OcamlSeekFunctionCallback
,
79 OcamlOpenSocketFunctionCallback
,
111 OcamlFTPAlternativeToUser
,
112 OcamlSSHPublicKeyFile
,
113 OcamlSSHPrivateKeyFile
,
114 OcamlSSHHostPublicKeyMD5
,
122 /* Not used, last for size */
134 size_t refcount
; /* number of references to this structure */
148 struct curl_slist
*httpHeader
;
149 struct curl_httppost
*httpPostFirst
;
150 struct curl_httppost
*httpPostLast
;
151 struct curl_slist
*httpPostStrings
;
152 struct curl_slist
*resolve
;
160 struct curl_slist
*quote
;
161 struct curl_slist
*postQuote
;
164 char *interface_
; /* `interface` gives problems on windows */
172 struct curl_slist
*http200Aliases
;
176 char *ftpAlternativeToUser
;
177 char *sshPublicKeyFile
;
178 char *sshPrivateKeyFile
;
179 char *sshHostPublicKeyMD5
;
180 char *copyPostFields
;
183 struct curl_slist
*mailRcpt
;
186 struct ConnectionList
192 static ConnectionList connectionList
= {NULL
, NULL
};
194 typedef struct CURLErrorMapping CURLErrorMapping
;
196 struct CURLErrorMapping
202 CURLErrorMapping errorMap
[] =
204 #if HAVE_DECL_CURLE_UNSUPPORTED_PROTOCOL
205 {"CURLE_UNSUPPORTED_PROTOCOL", CURLE_UNSUPPORTED_PROTOCOL
},
207 {"CURLE_UNSUPPORTED_PROTOCOL", -1},
209 #if HAVE_DECL_CURLE_FAILED_INIT
210 {"CURLE_FAILED_INIT", CURLE_FAILED_INIT
},
212 {"CURLE_FAILED_INIT", -1},
214 #if HAVE_DECL_CURLE_URL_MALFORMAT
215 {"CURLE_URL_MALFORMAT", CURLE_URL_MALFORMAT
},
217 {"CURLE_URL_MALFORMAT", -1},
219 #if HAVE_DECL_CURLE_URL_MALFORMAT_USER
220 {"CURLE_URL_MALFORMAT_USER", CURLE_URL_MALFORMAT_USER
},
222 {"CURLE_URL_MALFORMAT_USER", -1},
224 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_PROXY
225 {"CURLE_COULDNT_RESOLVE_PROXY", CURLE_COULDNT_RESOLVE_PROXY
},
227 {"CURLE_COULDNT_RESOLVE_PROXY", -1},
229 #if HAVE_DECL_CURLE_COULDNT_RESOLVE_HOST
230 {"CURLE_COULDNT_RESOLVE_HOST", CURLE_COULDNT_RESOLVE_HOST
},
232 {"CURLE_COULDNT_RESOLVE_HOST", -1},
234 #if HAVE_DECL_CURLE_COULDNT_CONNECT
235 {"CURLE_COULDNT_CONNECT", CURLE_COULDNT_CONNECT
},
237 {"CURLE_COULDNT_CONNECT", -1},
239 #if HAVE_DECL_CURLE_FTP_WEIRD_SERVER_REPLY
240 {"CURLE_FTP_WEIRD_SERVER_REPLY", CURLE_FTP_WEIRD_SERVER_REPLY
},
242 {"CURLE_FTP_WEIRD_SERVER_REPLY", -1},
244 #if HAVE_DECL_CURLE_FTP_ACCESS_DENIED
245 {"CURLE_FTP_ACCESS_DENIED", CURLE_FTP_ACCESS_DENIED
},
247 {"CURLE_FTP_ACCESS_DENIED", -1},
249 #if HAVE_DECL_CURLE_FTP_USER_PASSWORD_INCORRECT
250 {"CURLE_FTP_USER_PASSWORD_INCORRECT", CURLE_FTP_USER_PASSWORD_INCORRECT
},
252 {"CURLE_FTP_USER_PASSWORD_INCORRECT", -1},
254 #if HAVE_DECL_CURLE_FTP_WEIRD_PASS_REPLY
255 {"CURLE_FTP_WEIRD_PASS_REPLY", CURLE_FTP_WEIRD_PASS_REPLY
},
257 {"CURLE_FTP_WEIRD_PASS_REPLY", -1},
259 #if HAVE_DECL_CURLE_FTP_WEIRD_USER_REPLY
260 {"CURLE_FTP_WEIRD_USER_REPLY", CURLE_FTP_WEIRD_USER_REPLY
},
262 {"CURLE_FTP_WEIRD_USER_REPLY", -1},
264 #if HAVE_DECL_CURLE_FTP_WEIRD_PASV_REPLY
265 {"CURLE_FTP_WEIRD_PASV_REPLY", CURLE_FTP_WEIRD_PASV_REPLY
},
267 {"CURLE_FTP_WEIRD_PASV_REPLY", -1},
269 #if HAVE_DECL_CURLE_FTP_WEIRD_227_FORMAT
270 {"CURLE_FTP_WEIRD_227_FORMAT", CURLE_FTP_WEIRD_227_FORMAT
},
272 {"CURLE_FTP_WEIRD_227_FORMAT", -1},
274 #if HAVE_DECL_CURLE_FTP_CANT_GET_HOST
275 {"CURLE_FTP_CANT_GET_HOST", CURLE_FTP_CANT_GET_HOST
},
277 {"CURLE_FTP_CANT_GET_HOST", -1},
279 #if HAVE_DECL_CURLE_FTP_CANT_RECONNECT
280 {"CURLE_FTP_CANT_RECONNECT", CURLE_FTP_CANT_RECONNECT
},
282 {"CURLE_FTP_CANT_RECONNECT", -1},
284 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_BINARY
285 {"CURLE_FTP_COULDNT_SET_BINARY", CURLE_FTP_COULDNT_SET_BINARY
},
287 {"CURLE_FTP_COULDNT_SET_BINARY", -1},
289 #if HAVE_DECL_CURLE_PARTIAL_FILE
290 {"CURLE_PARTIAL_FILE", CURLE_PARTIAL_FILE
},
292 {"CURLE_PARTIAL_FILE", -1},
294 #if HAVE_DECL_CURLE_FTP_COULDNT_RETR_FILE
295 {"CURLE_FTP_COULDNT_RETR_FILE", CURLE_FTP_COULDNT_RETR_FILE
},
297 {"CURLE_FTP_COULDNT_RETR_FILE", -1},
299 #if HAVE_DECL_CURLE_FTP_WRITE_ERROR
300 {"CURLE_FTP_WRITE_ERROR", CURLE_FTP_WRITE_ERROR
},
302 {"CURLE_FTP_WRITE_ERROR", -1},
304 #if HAVE_DECL_CURLE_FTP_QUOTE_ERROR
305 {"CURLE_FTP_QUOTE_ERROR", CURLE_FTP_QUOTE_ERROR
},
307 {"CURLE_FTP_QUOTE_ERROR", -1},
309 #if HAVE_DECL_CURLE_HTTP_NOT_FOUND
310 {"CURLE_HTTP_NOT_FOUND", CURLE_HTTP_NOT_FOUND
},
312 {"CURLE_HTTP_NOT_FOUND", -1},
314 #if HAVE_DECL_CURLE_WRITE_ERROR
315 {"CURLE_WRITE_ERROR", CURLE_WRITE_ERROR
},
317 {"CURLE_WRITE_ERROR", -1},
319 #if HAVE_DECL_CURLE_MALFORMAT_USER
320 {"CURLE_MALFORMAT_USER", CURLE_MALFORMAT_USER
},
322 {"CURLE_MALFORMAT_USER", -1},
324 #if HAVE_DECL_CURLE_FTP_COULDNT_STOR_FILE
325 {"CURLE_FTP_COULDNT_STOR_FILE", CURLE_FTP_COULDNT_STOR_FILE
},
327 {"CURLE_FTP_COULDNT_STOR_FILE", -1},
329 #if HAVE_DECL_CURLE_READ_ERROR
330 {"CURLE_READ_ERROR", CURLE_READ_ERROR
},
332 {"CURLE_READ_ERROR", -1},
334 #if HAVE_DECL_CURLE_OUT_OF_MEMORY
335 {"CURLE_OUT_OF_MEMORY", CURLE_OUT_OF_MEMORY
},
337 {"CURLE_OUT_OF_MEMORY", -1},
339 #if HAVE_DECL_CURLE_OPERATION_TIMEOUTED
340 {"CURLE_OPERATION_TIMEOUTED", CURLE_OPERATION_TIMEOUTED
},
342 {"CURLE_OPERATION_TIMEOUTED", -1},
344 #if HAVE_DECL_CURLE_FTP_COULDNT_SET_ASCII
345 {"CURLE_FTP_COULDNT_SET_ASCII", CURLE_FTP_COULDNT_SET_ASCII
},
347 {"CURLE_FTP_COULDNT_SET_ASCII", -1},
349 #if HAVE_DECL_CURLE_FTP_PORT_FAILED
350 {"CURLE_FTP_PORT_FAILED", CURLE_FTP_PORT_FAILED
},
352 {"CURLE_FTP_PORT_FAILED", -1},
354 #if HAVE_DECL_CURLE_FTP_COULDNT_USE_REST
355 {"CURLE_FTP_COULDNT_USE_REST", CURLE_FTP_COULDNT_USE_REST
},
357 {"CURLE_FTP_COULDNT_USE_REST", -1},
359 #if HAVE_DECL_CURLE_FTP_COULDNT_GET_SIZE
360 {"CURLE_FTP_COULDNT_GET_SIZE", CURLE_FTP_COULDNT_GET_SIZE
},
362 {"CURLE_FTP_COULDNT_GET_SIZE", -1},
364 #if HAVE_DECL_CURLE_HTTP_RANGE_ERROR
365 {"CURLE_HTTP_RANGE_ERROR", CURLE_HTTP_RANGE_ERROR
},
367 {"CURLE_HTTP_RANGE_ERROR", -1},
369 #if HAVE_DECL_CURLE_HTTP_POST_ERROR
370 {"CURLE_HTTP_POST_ERROR", CURLE_HTTP_POST_ERROR
},
372 {"CURLE_HTTP_POST_ERROR", -1},
374 #if HAVE_DECL_CURLE_SSL_CONNECT_ERROR
375 {"CURLE_SSL_CONNECT_ERROR", CURLE_SSL_CONNECT_ERROR
},
377 {"CURLE_SSL_CONNECT_ERROR", -1},
379 #if HAVE_DECL_CURLE_FTP_BAD_DOWNLOAD_RESUME
380 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", CURLE_FTP_BAD_DOWNLOAD_RESUME
},
382 {"CURLE_FTP_BAD_DOWNLOAD_RESUME", -1},
384 #if HAVE_DECL_CURLE_FILE_COULDNT_READ_FILE
385 {"CURLE_FILE_COULDNT_READ_FILE", CURLE_FILE_COULDNT_READ_FILE
},
387 {"CURLE_FILE_COULDNT_READ_FILE", -1},
389 #if HAVE_DECL_CURLE_LDAP_CANNOT_BIND
390 {"CURLE_LDAP_CANNOT_BIND", CURLE_LDAP_CANNOT_BIND
},
392 {"CURLE_LDAP_CANNOT_BIND", -1},
394 #if HAVE_DECL_CURLE_LDAP_SEARCH_FAILED
395 {"CURLE_LDAP_SEARCH_FAILED", CURLE_LDAP_SEARCH_FAILED
},
397 {"CURLE_LDAP_SEARCH_FAILED", -1},
399 #if HAVE_DECL_CURLE_LIBRARY_NOT_FOUND
400 {"CURLE_LIBRARY_NOT_FOUND", CURLE_LIBRARY_NOT_FOUND
},
402 {"CURLE_LIBRARY_NOT_FOUND", -1},
404 #if HAVE_DECL_CURLE_FUNCTION_NOT_FOUND
405 {"CURLE_FUNCTION_NOT_FOUND", CURLE_FUNCTION_NOT_FOUND
},
407 {"CURLE_FUNCTION_NOT_FOUND", -1},
409 #if HAVE_DECL_CURLE_ABORTED_BY_CALLBACK
410 {"CURLE_ABORTED_BY_CALLBACK", CURLE_ABORTED_BY_CALLBACK
},
412 {"CURLE_ABORTED_BY_CALLBACK", -1},
414 #if HAVE_DECL_CURLE_BAD_FUNCTION_ARGUMENT
415 {"CURLE_BAD_FUNCTION_ARGUMENT", CURLE_BAD_FUNCTION_ARGUMENT
},
417 {"CURLE_BAD_FUNCTION_ARGUMENT", -1},
419 #if HAVE_DECL_CURLE_BAD_CALLING_ORDER
420 {"CURLE_BAD_CALLING_ORDER", CURLE_BAD_CALLING_ORDER
},
422 {"CURLE_BAD_CALLING_ORDER", -1},
424 #if HAVE_DECL_CURLE_HTTP_PORT_FAILED
425 {"CURLE_HTTP_PORT_FAILED", CURLE_HTTP_PORT_FAILED
},
427 {"CURLE_HTTP_PORT_FAILED", -1},
429 #if HAVE_DECL_CURLE_BAD_PASSWORD_ENTERED
430 {"CURLE_BAD_PASSWORD_ENTERED", CURLE_BAD_PASSWORD_ENTERED
},
432 {"CURLE_BAD_PASSWORD_ENTERED", -1},
434 #if HAVE_DECL_CURLE_TOO_MANY_REDIRECTS
435 {"CURLE_TOO_MANY_REDIRECTS", CURLE_TOO_MANY_REDIRECTS
},
437 {"CURLE_TOO_MANY_REDIRECTS", -1},
439 #if HAVE_DECL_CURLE_UNKNOWN_TELNET_OPTION
440 {"CURLE_UNKNOWN_TELNET_OPTION", CURLE_UNKNOWN_TELNET_OPTION
},
442 {"CURLE_UNKNOWN_TELNET_OPTION", -1},
444 #if HAVE_DECL_CURLE_TELNET_OPTION_SYNTAX
445 {"CURLE_TELNET_OPTION_SYNTAX", CURLE_TELNET_OPTION_SYNTAX
},
447 {"CURLE_TELNET_OPTION_SYNTAX", -1},
449 #if HAVE_DECL_CURLE_SSL_PEER_CERTIFICATE
450 {"CURLE_SSL_PEER_CERTIFICATE", CURLE_SSL_PEER_CERTIFICATE
},
452 {"CURLE_SSL_PEER_CERTIFICATE", -1},
454 #if HAVE_DECL_CURLE_GOT_NOTHING
455 {"CURLE_GOT_NOTHING", CURLE_GOT_NOTHING
},
457 {"CURLE_GOT_NOTHING", -1},
459 #if HAVE_DECL_CURLE_SSL_ENGINE_NOT_FOUND
460 {"CURLE_SSL_ENGINE_NOT_FOUND", CURLE_SSL_ENGINE_NOTFOUND
},
462 {"CURLE_SSL_ENGINE_NOT_FOUND", -1},
464 #if HAVE_DECL_CURLE_SSL_ENGINE_SET_FAILED
465 {"CURLE_SSL_ENGINE_SET_FAILED", CURLE_SSL_ENGINE_SETFAILED
},
467 {"CURLE_SSL_ENGINE_SET_FAILED", -1},
469 #if HAVE_DECL_CURLE_SEND_ERROR
470 {"CURLE_SEND_ERROR", CURLE_SEND_ERROR
},
472 {"CURLE_SEND_ERROR", -1},
474 #if HAVE_DECL_CURLE_RECV_ERROR
475 {"CURLE_RECV_ERROR", CURLE_RECV_ERROR
},
477 {"CURLE_RECV_ERROR", -1},
479 #if HAVE_DECL_CURLE_SHARE_IN_USE
480 {"CURLE_SHARE_IN_USE", CURLE_SHARE_IN_USE
},
482 {"CURLE_SHARE_IN_USE", -1},
484 #if HAVE_DECL_CURLE_SSL_CERTPROBLEM
485 {"CURLE_SSL_CERTPROBLEN", CURLE_SSL_CERTPROBLEM
},
487 {"CURLE_SSL_CERTPROBLEN", -1},
489 #if HAVE_DECL_CURLE_SSL_CIPHER
490 {"CURLE_SSL_CIPHER", CURLE_SSL_CIPHER
},
492 {"CURLE_SSL_CIPHER", -1},
494 #if HAVE_DECL_CURLE_SSL_CACERT
495 {"CURLE_SSL_CACERT", CURLE_SSL_CACERT
},
497 {"CURLE_SSL_CACERT", -1},
499 #if HAVE_DECL_CURLE_BAD_CONTENT_ENCODING
500 {"CURLE_BAD_CONTENT_ENCODING", CURLE_BAD_CONTENT_ENCODING
},
502 {"CURLE_BAD_CONTENT_ENCODING", -1},
504 #if HAVE_DECL_CURLE_LDAP_INVALID_URL
505 {"CURLE_LDAP_INVALID_URL", CURLE_LDAP_INVALID_URL
},
507 {"CURLE_LDAP_INVALID_URL", -1},
509 #if HAVE_DECL_CURLE_FILESIZE_EXCEEDED
510 {"CURLE_FILESIZE_EXCEEDED", CURLE_FILESIZE_EXCEEDED
},
512 {"CURLE_FILESIZE_EXCEEDED", -1},
514 #if HAVE_DECL_CURLE_FTP_SSL_FAILED
515 {"CURLE_FTP_SSL_FAILED", CURLE_FTP_SSL_FAILED
},
517 {"CURLE_FTP_SSL_FAILED", -1},
519 #if HAVE_DECL_CURLE_SEND_FAIL_REWIND
520 {"CURLE_SEND_FAIL_REWIND", CURLE_SEND_FAIL_REWIND
},
522 {"CURLE_SEND_FAIL_REWIND", -1},
524 #if HAVE_DECL_CURLE_SSL_ENGINE_INITFAILED
525 {"CURLE_SSL_ENGINE_INITFAILED", CURLE_SSL_ENGINE_INITFAILED
},
527 {"CURLE_SSL_ENGINE_INITFAILED", -1},
529 #if HAVE_DECL_CURLE_LOGIN_DENIED
530 {"CURLE_LOGIN_DENIED", CURLE_LOGIN_DENIED
},
532 {"CURLE_LOGIN_DENIED", -1},
534 #if HAVE_DECL_CURLE_TFTP_NOTFOUND
535 {"CURLE_TFTP_NOTFOUND", CURLE_TFTP_NOTFOUND
},
537 {"CURLE_TFTP_NOTFOUND", -1},
539 #if HAVE_DECL_CURLE_TFTP_PERM
540 {"CURLE_TFTP_PERM", CURLE_TFTP_PERM
},
542 {"CURLE_TFTP_PERM", -1},
544 #if HAVE_DECL_CURLE_REMOTE_DISK_FULL
545 {"CURLE_REMOTE_DISK_FULL", CURLE_REMOTE_DISK_FULL
},
547 {"CURLE_REMOTE_DISK_FULL", -1},
549 #if HAVE_DECL_CURLE_TFTP_ILLEGAL
550 {"CURLE_TFTP_ILLEGAL", CURLE_TFTP_ILLEGAL
},
552 {"CURLE_TFTP_ILLEGAL", -1},
554 #if HAVE_DECL_CURLE_TFTP_UNKNOWNID
555 {"CURLE_TFTP_UNKNOWNID", CURLE_TFTP_UNKNOWNID
},
557 {"CURLE_TFTP_UNKNOWNID", -1},
559 #if HAVE_DECL_CURLE_REMOTE_FILE_EXISTS
560 {"CURLE_REMOTE_FILE_EXISTS", CURLE_REMOTE_FILE_EXISTS
},
562 {"CURLE_REMOTE_FILE_EXISTS", -1},
564 #if HAVE_DECL_CURLE_TFTP_NOSUCHUSER
565 {"CURLE_TFTP_NOSUCHUSER", CURLE_TFTP_NOSUCHUSER
},
567 {"CURLE_TFTP_NOSUCHUSER", -1},
569 #if HAVE_DECL_CURLE_CONV_FAILED
570 {"CURLE_CONV_FAILED", CURLE_CONV_FAILED
},
572 {"CURLE_CONV_FAILED", -1},
574 #if HAVE_DECL_CURLE_CONV_REQUIRED
575 {"CURLE_CONV_REQUIRED", CURLE_CONV_REQUIRED
},
577 {"CURLE_CONV_REQUIRED", -1},
579 #if HAVE_DECL_CURLE_SSL_CACERT_BADFILE
580 {"CURLE_SSL_CACERT_BADFILE", CURLE_SSL_CACERT_BADFILE
},
582 {"CURLE_SSL_CACERT_BADFILE", -1},
584 #if HAVE_DECL_CURLE_REMOTE_FILE_NOT_FOUND
585 {"CURLE_REMOTE_FILE_NOT_FOUND", CURLE_REMOTE_FILE_NOT_FOUND
},
587 {"CURLE_REMOTE_FILE_NOT_FOUND", -1},
589 #if HAVE_DECL_CURLE_SSH
590 {"CURLE_SSH", CURLE_SSH
},
594 #if HAVE_DECL_CURLE_SSL_SHUTDOWN_FAILED
595 {"CURLE_SSL_SHUTDOWN_FAILED", CURLE_SSL_SHUTDOWN_FAILED
},
597 {"CURLE_SSL_SHUTDOWN_FAILED", -1},
599 #if HAVE_DECL_CURLE_AGAIN
600 {"CURLE_AGAIN", CURLE_AGAIN
},
604 {"CURLE_OK", CURLE_OK
},
608 typedef struct CURLOptionMapping CURLOptionMapping
;
610 struct CURLOptionMapping
612 void (*optionHandler
)(Connection
*, value
);
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
);
748 static void handleMailFrom(Connection
*, value
);
749 static void handleMailRcpt(Connection
*, value
);
751 CURLOptionMapping implementedOptionMap
[] =
753 {handleWriteFunction
, "CURLOPT_WRITEFUNCTION"},
754 {handleReadFunction
, "CURLOPT_READFUNCTION"},
755 {handleInFileSize
, "CURLOPT_INFILESIZE"},
756 {handleURL
, "CURLOPT_URL"},
757 {handleProxy
, "CURLOPT_PROXY"},
758 {handleProxyPort
, "CURLOPT_PROXYPORT"},
759 {handleHTTPProxyTunnel
, "CURLOPT_HTTPPROXYTUNNEL"},
760 {handleVerbose
, "CURLOPT_VERBOSE"},
761 {handleHeader
, "CURLOPT_HEADER"},
762 {handleNoProgress
, "CURLOPT_NOPROGRESS"},
763 #if HAVE_DECL_CURLOPT_NOSIGNAL
764 {handleNoSignal
, "CURLOPT_NOSIGNAL"},
766 {NULL
, "CURLOPT_NOSIGNAL"},
768 {handleNoBody
, "CURLOPT_NOBODY"},
769 {handleFailOnError
, "CURLOPT_FAILONERROR"},
770 {handleUpload
, "CURLOPT_UPLOAD"},
771 {handlePost
, "CURLOPT_POST"},
772 {handleFTPListOnly
, "CURLOPT_FTPLISTONLY"},
773 {handleFTPAppend
, "CURLOPT_FTPAPPEND"},
774 {handleNETRC
, "CURLOPT_NETRC"},
775 #if HAVE_DECL_CURLOPT_ENCODING
776 {handleEncoding
, "CURLOPT_ENCODING"},
778 {NULL
, "CURLOPT_ENCODING"},
780 {handleFollowLocation
, "CURLOPT_FOLLOWLOCATION"},
781 {handleTransferText
, "CURLOPT_TRANSFERTEXT"},
782 {handlePut
, "CURLOPT_PUT"},
783 {handleUserPwd
, "CURLOPT_USERPWD"},
784 {handleProxyUserPwd
, "CURLOPT_PROXYUSERPWD"},
785 {handleRange
, "CURLOPT_RANGE"},
786 {handleErrorBuffer
, "CURLOPT_ERRORBUFFER"},
787 {handleTimeout
, "CURLOPT_TIMEOUT"},
788 {handlePostFields
, "CURLOPT_POSTFIELDS"},
789 {handlePostFieldSize
, "CURLOPT_POSTFIELDSIZE"},
790 {handleReferer
, "CURLOPT_REFERER"},
791 {handleUserAgent
, "CURLOPT_USERAGENT"},
792 {handleFTPPort
, "CURLOPT_FTPPORT"},
793 {handleLowSpeedLimit
, "CURLOPT_LOW_SPEED_LIMIT"},
794 {handleLowSpeedTime
, "CURLOPT_LOW_SPEED_TIME"},
795 {handleResumeFrom
, "CURLOPT_RESUME_FROM"},
796 {handleCookie
, "CURLOPT_COOKIE"},
797 {handleHTTPHeader
, "CURLOPT_HTTPHEADER"},
798 {handleHTTPPost
, "CURLOPT_HTTPPOST"},
799 {handleSSLCert
, "CURLOPT_SSLCERT"},
800 {handleSSLCertType
, "CURLOPT_SSLCERTTYPE"},
801 {handleSSLCertPasswd
, "CURLOPT_SSLCERTPASSWD"},
802 {handleSSLKey
, "CURLOPT_SSLKEY"},
803 {handleSSLKeyType
, "CURLOPT_SSLKEYTYPE"},
804 {handleSSLKeyPasswd
, "CURLOPT_SSLKEYPASSWD"},
805 {handleSSLEngine
, "CURLOPT_SSLENGINE"},
806 {handleSSLEngineDefault
, "CURLOPT_SSLENGINE_DEFAULT"},
807 {handleCRLF
, "CURLOPT_CRLF"},
808 {handleQuote
, "CURLOPT_QUOTE"},
809 {handlePostQuote
, "CURLOPT_POSTQUOTE"},
810 {handleHeaderFunction
, "CURLOPT_HEADERFUNCTION"},
811 {handleCookieFile
, "CURLOPT_COOKIEFILE"},
812 {handleSSLVersion
, "CURLOPT_SSLVERSION"},
813 {handleTimeCondition
, "CURLOPT_TIMECONDITION"},
814 {handleTimeValue
, "CURLOPT_TIMEVALUE"},
815 {handleCustomRequest
, "CURLOPT_CUSTOMREQUEST"},
816 {handleInterface
, "CURLOPT_INTERFACE"},
817 {handleKRB4Level
, "CURLOPT_KRB4LEVEL"},
818 {handleProgressFunction
, "CURLOPT_PROGRESSFUNCTION"},
819 {handleSSLVerifyPeer
, "CURLOPT_SSLVERIFYPEER"},
820 {handleCAInfo
, "CURLOPT_CAINFO"},
821 {handleCAPath
, "CURLOPT_CAPATH"},
822 {handleFileTime
, "CURLOPT_FILETIME"},
823 {handleMaxRedirs
, "CURLOPT_MAXREDIRS"},
824 {handleMaxConnects
, "CURLOPT_MAXCONNECTS"},
825 {handleClosePolicy
, "CURLOPT_CLOSEPOLICY"},
826 {handleFreshConnect
, "CURLOPT_FRESH_CONNECT"},
827 {handleForbidReuse
, "CURLOPT_FORBID_REUSE"},
828 {handleRandomFile
, "CURLOPT_RANDOM_FILE"},
829 {handleEGDSocket
, "CURLOPT_EGDSOCKET"},
830 {handleConnectTimeout
, "CURLOPT_CONNECTTIMEOUT"},
831 {handleHTTPGet
, "CURLOPT_HTTPGET"},
832 {handleSSLVerifyHost
, "CURLOPT_SSL_VERIFYHOST"},
833 {handleCookieJar
, "CURLOPT_COOKIEJAR"},
834 {handleSSLCipherList
, "CURLOPT_SSL_CIPHERLIST"},
835 {handleHTTPVersion
, "CURLOPT_HTTP_VERSION"},
836 {handleFTPUseEPSV
, "CURLOPT_FTP_USE_EPSV"},
837 {handleDNSCacheTimeout
, "CURLOPT_DNS_CACHE_TIMEOUT"},
838 {handleDNSUseGlobalCache
, "CURLOPT_DNS_USE_GLOBAL_CACHE"},
839 {handleDebugFunction
, "CURLOPT_DEBUGFUNCTION"},
840 #if HAVE_DECL_CURLOPT_PRIVATE
841 {handlePrivate
, "CURLOPT_PRIVATE"},
843 {NULL
, "CURLOPT_PRIVATE"},
845 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
846 {handleHTTP200Aliases
, "CURLOPT_HTTP200ALIASES"},
848 {NULL
, "CURLOPT_HTTP200ALIASES"},
850 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
851 {handleUnrestrictedAuth
, "CURLOPT_UNRESTRICTED_AUTH"},
853 {NULL
, "CURLOPT_UNRESTRICTED_AUTH"},
855 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
856 {handleFTPUseEPRT
, "CURLOPT_FTP_USE_EPRT"},
858 {NULL
, "CURLOPT_FTP_USE_EPRT"},
860 #if HAVE_DECL_CURLOPT_HTTPAUTH
861 {handleHTTPAuth
, "CURLOPT_HTTPAUTH"},
863 {NULL
, "CURLOPT_HTTPAUTH"},
865 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
866 {handleFTPCreateMissingDirs
, "CURLOPT_FTP_CREATE_MISSING_DIRS"},
868 {NULL
, "CURLOPT_FTP_CREATE_MISSING_DIRS"},
870 #if HAVE_DECL_CURLOPT_PROXYAUTH
871 {handleProxyAuth
, "CURLOPT_PROXYAUTH"},
873 {NULL
, "CURLOPT_PROXYAUTH"},
875 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
876 {handleFTPResponseTimeout
, "CURLOPT_FTP_RESPONSE_TIMEOUT"},
878 {NULL
, "CURLOPT_FTP_RESPONSE_TIMEOUT"},
880 #if HAVE_DECL_CURLOPT_IPRESOLVE
881 {handleIPResolve
, "CURLOPT_IPRESOLVE"},
883 {NULL
, "CURLOPT_IPRESOLVE"},
885 #if HAVE_DECL_CURLOPT_MAXFILESIZE
886 {handleMaxFileSize
, "CURLOPT_MAXFILESIZE"},
888 {NULL
, "CURLOPT_MAXFILESIZE"},
890 #if HAVE_DECL_CURLOPT_INFILESIZE_LARGE
891 {handleInFileSizeLarge
, "CURLOPT_INFILESIZE_LARGE"},
893 {NULL
, "CURLOPT_INFILESIZE_LARGE"},
895 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
896 {handleResumeFromLarge
, "CURLOPT_RESUME_FROM_LARGE"},
898 {NULL
, "CURLOPT_RESUME_FROM_LARGE"},
900 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
901 {handleMaxFileSizeLarge
, "CURLOPT_MAXFILESIZE_LARGE"},
903 {NULL
, "CURLOPT_MAXFILESIZE_LARGE"},
905 #if HAVE_DECL_CURLOPT_NETRC_FILE
906 {handleNETRCFile
, "CURLOPT_NETRC_FILE"},
908 {NULL
, "CURLOPT_NETRC_FILE"},
910 #if HAVE_DECL_CURLOPT_FTP_SSL
911 {handleFTPSSL
, "CURLOPT_FTP_SSL"},
913 {NULL
, "CURLOPT_FTP_SSL"},
915 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
916 {handlePostFieldSizeLarge
, "CURLOPT_POSTFIELDSIZE_LARGE"},
918 {NULL
, "CURLOPT_POSTFIELDSIZE_LARGE"},
920 #if HAVE_DECL_CURLOPT_TCP_NODELAY
921 {handleTCPNoDelay
, "CURLOPT_TCP_NODELAY"},
923 {NULL
, "CURLOPT_TCP_NODELAY"},
925 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
926 {handleFTPSSLAuth
, "CURLOPT_FTPSSLAUTH"},
928 {NULL
, "CURLOPT_FTPSSLAUTH"},
930 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
931 {handleIOCTLFunction
, "CURLOPT_IOCTLFUNCTION"},
933 {NULL
, "CURLOPT_IOCTLFUNCTION"},
935 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
936 {handleFTPAccount
, "CURLOPT_FTP_ACCOUNT"},
938 {NULL
, "CURLOPT_FTP_ACCOUNT"},
940 #if HAVE_DECL_CURLOPT_COOKIELIST
941 {handleCookieList
, "CURLOPT_COOKIELIST"},
943 {NULL
, "CURLOPT_COOKIELIST"},
945 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
946 {handleIgnoreContentLength
, "CURLOPT_IGNORE_CONTENT_LENGTH"},
948 {NULL
, "CURLOPT_IGNORE_CONTENT_LENGTH"},
950 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
951 {handleFTPSkipPASVIP
, "CURLOPT_FTP_SKIP_PASV_IP"},
953 {NULL
, "CURLOPT_FTP_SKIP_PASV_IP"},
955 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
956 {handleFTPFileMethod
, "CURLOPT_FTP_FILEMETHOD"},
958 {NULL
, "CURLOPT_FTP_FILEMETHOD"},
960 #if HAVE_DECL_CURLOPT_LOCALPORT
961 {handleLocalPort
, "CURLOPT_LOCALPORT"},
963 {NULL
, "CURLOPT_LOCALPORT"},
965 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
966 {handleLocalPortRange
, "CURLOPT_LOCALPORTRANGE"},
968 {NULL
, "CURLOPT_LOCALPORTRANGE"},
970 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
971 {handleConnectOnly
, "CURLOPT_CONNECT_ONLY"},
973 {NULL
, "CURLOPT_CONNECT_ONLY"},
975 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
976 {handleMaxSendSpeedLarge
, "CURLOPT_MAX_SEND_SPEED_LARGE"},
978 {NULL
, "CURLOPT_MAX_SEND_SPEED_LARGE"},
980 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
981 {handleMaxRecvSpeedLarge
, "CURLOPT_MAX_RECV_SPEED_LARGE"},
983 {NULL
, "CURLOPT_MAX_RECV_SPEED_LARGE"},
985 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
986 {handleFTPAlternativeToUser
, "CURLOPT_FTP_ALTERNATIVE_TO_USER"},
988 {NULL
, "CURLOPT_FTP_ALTERMATIVE_TO_USER"},
990 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
991 {handleSSLSessionIdCache
, "CURLOPT_SSL_SESSIONID_CACHE"},
993 {NULL
, "CURLOPT_SSL_SESSIONID_CACHE"},
995 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
996 {handleSSHAuthTypes
, "CURLOPT_SSH_AUTH_TYPES"},
998 {NULL
, "CURLOPT_SSH_AUTH_TYPES"},
1000 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
1001 {handleSSHPublicKeyFile
, "CURLOPT_SSH_PUBLIC_KEYFILE"},
1003 {NULL
, "CURLOPT_SSH_PUBLIC_KEYFILE"},
1005 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
1006 {handleSSHPrivateKeyFile
, "CURLOPT_SSH_PRIVATE_KEYFILE"},
1008 {NULL
, "CURLOPT_SSH_PRIVATE_KEYFILE"},
1010 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
1011 {handleFTPSSLCCC
, "CURLOPT_FTP_SSL_CCC"},
1013 {NULL
, "CURLOPT_FTP_SSL_CCC"},
1015 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
1016 {handleTimeoutMS
, "CURLOPT_TIMEOUT_MS"},
1018 {NULL
, "CURLOPT_TIMEOUT_MS"},
1020 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
1021 {handleConnectTimeoutMS
, "CURLOPT_CONNECTTIMEOUT_MS"},
1023 {NULL
, "CURLOPT_CONNECTTIMEOUT_MS"},
1025 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
1026 {handleHTTPTransferDecoding
, "CURLOPT_HTTP_TRANSFER_DECODING"},
1028 {NULL
, "CURLOPT_HTTP_TRANSFER_DECODING"},
1030 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
1031 {handleHTTPContentDecoding
, "CURLOPT_HTTP_CONTENT_DECODING"},
1033 {NULL
, "CURLOPT_HTTP_CONTENT_DECODING"},
1035 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
1036 {handleNewFilePerms
, "CURLOPT_NEW_FILE_PERMS"},
1038 {NULL
, "CURLOPT_NEW_FILE_PERMS"},
1040 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
1041 {handleNewDirectoryPerms
, "CURLOPT_NEW_DIRECTORY_PERMS"},
1043 {NULL
, "CURLOPT_NEW_DIRECTORY_PERMS"},
1045 #if HAVE_DECL_CURLOPT_POST301
1046 {handlePost301
, "CURLOPT_POST301"},
1048 {NULL
, "CURLOPT_POST301"},
1050 #if HAVE_DECL_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
1051 {handleSSHHostPublicKeyMD5
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5"},
1053 {NULL
, "CURLOPT_SSH_HOST_PUBLIC_KEY_MD5"},
1055 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
1056 {handleCopyPostFields
, "CURLOPT_COPYPOSTFIELDS"},
1058 {NULL
, "CURLOPT_COPYPOSTFIELDS"},
1060 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
1061 {handleProxyTransferMode
, "CURLOPT_PROXY_TRANSFER_MODE"},
1063 {NULL
, "CURLOPT_PROXY_TRANSFER_MODE"},
1065 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1066 {handleSeekFunction
, "CURLOPT_SEEKFUNCTION"},
1068 {NULL
, "CURLOPT_SEEKFUNCTION"},
1070 #if HAVE_DECL_CURLOPT_AUTOREFERER
1071 {handleAutoReferer
, "CURLOPT_AUTOREFERER"},
1073 {NULL
, "CURLOPT_AUTOREFERER"},
1075 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1076 {handleOpenSocketFunction
, "CURLOPT_OPENSOCKETFUNCTION"},
1078 {NULL
, "CURLOPT_OPENSOCKETFUNCTION"},
1080 #if HAVE_DECL_CURLOPT_PROXYTYPE
1081 {handleProxyType
, "CURLOPT_PROXYTYPE"},
1083 {NULL
, "CURLOPT_PROXYTYPE"},
1085 #if HAVE_DECL_CURLOPT_PROTOCOLS
1086 {handleProtocols
, "CURLOPT_PROTOCOLS"},
1088 {NULL
, "CURLOPT_PROTOCOLS"},
1090 #if HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
1091 {handleRedirProtocols
, "CURLOPT_REDIR_PROTOCOLS"},
1093 {NULL
, "CURLOPT_REDIR_PROTOCOLS"},
1095 #if HAVE_DECL_CURLOPT_RESOLVE
1096 {handleResolve
, "CURLOPT_RESOLVE"},
1098 {NULL
, "CURLOPT_RESOLVE"},
1100 #if HAVE_DECL_CURLOPT_DNS_SERVERS
1101 {handleDnsServers
, "CURLOPT_DNS_SERVERS"},
1103 {NULL
, "CURLOPT_DNS_SERVERS"},
1105 #if HAVE_DECL_CURLOPT_MAIL_FROM
1106 {handleMailFrom
, "CURLOPT_MAIL_FROM"},
1108 {NULL
, "CURLOPT_MAIL_FROM"},
1110 #if HAVE_DECL_CURLOPT_MAIL_RCPT
1111 {handleMailRcpt
, "CURLOPT_MAIL_RCPT"},
1113 {NULL
, "CURLOPT_MAIL_RCPT"},
1117 static void free_curl_slist(struct curl_slist
*slist
)
1122 curl_slist_free_all(slist
);
1125 static void raiseError(Connection
*conn
, CURLcode code
)
1128 CAMLlocal1(exceptionData
);
1130 char *errorString
= "Unknown Error";
1133 for (i
= 0; errorMap
[i
].name
!= NULL
; i
++)
1135 if (errorMap
[i
].error
== code
)
1137 errorString
= errorMap
[i
].name
;
1142 exceptionData
= caml_alloc(3, 0);
1144 Store_field(exceptionData
, 0, Val_int(code
));
1145 Store_field(exceptionData
, 1, Val_int(code
));
1146 Store_field(exceptionData
, 2, copy_string(errorString
));
1148 if (conn
!= NULL
&& conn
->errorBuffer
!= NULL
)
1150 Store_field(Field(conn
->ocamlValues
, OcamlErrorBuffer
), 0,
1151 copy_string(conn
->errorBuffer
));
1154 exception
= caml_named_value("CurlException");
1156 if (exception
== NULL
)
1157 caml_failwith("CurlException not registered");
1159 raise_with_arg(*exception
, exceptionData
);
1164 static void resetOcamlValues(Connection
* connection
)
1168 for (i
= 0; i
< OcamlValuesSize
; i
++)
1169 Store_field(connection
->ocamlValues
, i
, Val_unit
);
1172 static Connection
* allocConnection(CURL
* h
)
1174 Connection
* connection
= (Connection
*)malloc(sizeof(Connection
));
1176 connection
->ocamlValues
= caml_alloc(OcamlValuesSize
, 0);
1177 resetOcamlValues(connection
);
1178 register_global_root(&connection
->ocamlValues
);
1180 connection
->connection
= h
;
1182 connection
->next
= NULL
;
1183 connection
->prev
= NULL
;
1185 if (connectionList
.tail
== NULL
)
1187 connectionList
.tail
= connection
;
1188 connectionList
.head
= connection
;
1192 connection
->prev
= connectionList
.head
;
1193 connectionList
.head
->next
= connection
;
1194 connectionList
.head
= connection
;
1197 connection
->refcount
= 0;
1199 connection
->url
= NULL
;
1200 connection
->proxy
= NULL
;
1201 connection
->userPwd
= NULL
;
1202 connection
->proxyUserPwd
= NULL
;
1203 connection
->range
= NULL
;
1204 connection
->errorBuffer
= NULL
;
1205 connection
->postFields
= NULL
;
1206 connection
->postFieldSize
= -1;
1207 connection
->referer
= NULL
;
1208 connection
->userAgent
= NULL
;
1209 connection
->ftpPort
= NULL
;
1210 connection
->cookie
= NULL
;
1211 connection
->httpHeader
= NULL
;
1212 connection
->httpPostFirst
= NULL
;
1213 connection
->httpPostLast
= NULL
;
1214 connection
->httpPostStrings
= NULL
;
1215 connection
->sslCert
= NULL
;
1216 connection
->sslCertType
= NULL
;
1217 connection
->sslCertPasswd
= NULL
;
1218 connection
->sslKey
= NULL
;
1219 connection
->sslKeyType
= NULL
;
1220 connection
->sslKeyPasswd
= NULL
;
1221 connection
->sslEngine
= NULL
;
1222 connection
->quote
= NULL
;
1223 connection
->postQuote
= NULL
;
1224 connection
->cookieFile
= NULL
;
1225 connection
->customRequest
= NULL
;
1226 connection
->interface_
= NULL
;
1227 connection
->caInfo
= NULL
;
1228 connection
->caPath
= NULL
;
1229 connection
->randomFile
= NULL
;
1230 connection
->egdSocket
= NULL
;
1231 connection
->cookieJar
= NULL
;
1232 connection
->sslCipherList
= NULL
;
1233 connection
->private = NULL
;
1234 connection
->http200Aliases
= NULL
;
1235 connection
->netrcFile
= NULL
;
1236 connection
->ftpaccount
= NULL
;
1237 connection
->cookielist
= NULL
;
1238 connection
->ftpAlternativeToUser
= NULL
;
1239 connection
->sshPublicKeyFile
= NULL
;
1240 connection
->sshPrivateKeyFile
= NULL
;
1241 connection
->copyPostFields
= NULL
;
1242 connection
->resolve
= NULL
;
1243 connection
->dns_servers
= NULL
;
1244 connection
->mailFrom
= NULL
;
1245 connection
->mailRcpt
= NULL
;
1250 static Connection
*newConnection(void)
1254 caml_enter_blocking_section();
1255 h
= curl_easy_init();
1256 caml_leave_blocking_section();
1258 return allocConnection(h
);
1261 static Connection
*duplicateConnection(Connection
*original
)
1263 Connection
*connection
;
1266 caml_enter_blocking_section();
1267 h
= curl_easy_duphandle(original
->connection
);
1268 caml_leave_blocking_section();
1270 connection
= allocConnection(h
);
1272 Store_field(connection
->ocamlValues
, OcamlWriteCallback
,
1273 Field(original
->ocamlValues
, OcamlWriteCallback
));
1274 Store_field(connection
->ocamlValues
, OcamlReadCallback
,
1275 Field(original
->ocamlValues
, OcamlReadCallback
));
1276 Store_field(connection
->ocamlValues
, OcamlErrorBuffer
,
1277 Field(original
->ocamlValues
, OcamlErrorBuffer
));
1278 Store_field(connection
->ocamlValues
, OcamlPostFields
,
1279 Field(original
->ocamlValues
, OcamlPostFields
));
1280 Store_field(connection
->ocamlValues
, OcamlHTTPHeader
,
1281 Field(original
->ocamlValues
, OcamlHTTPHeader
));
1282 Store_field(connection
->ocamlValues
, OcamlQuote
,
1283 Field(original
->ocamlValues
, OcamlQuote
));
1284 Store_field(connection
->ocamlValues
, OcamlPostQuote
,
1285 Field(original
->ocamlValues
, OcamlPostQuote
));
1286 Store_field(connection
->ocamlValues
, OcamlHeaderCallback
,
1287 Field(original
->ocamlValues
, OcamlHeaderCallback
));
1288 Store_field(connection
->ocamlValues
, OcamlProgressCallback
,
1289 Field(original
->ocamlValues
, OcamlProgressCallback
));
1290 Store_field(connection
->ocamlValues
, OcamlDebugCallback
,
1291 Field(original
->ocamlValues
, OcamlDebugCallback
));
1292 Store_field(connection
->ocamlValues
, OcamlHTTP200Aliases
,
1293 Field(original
->ocamlValues
, OcamlHTTP200Aliases
));
1294 Store_field(connection
->ocamlValues
, OcamlIOCTLCallback
,
1295 Field(original
->ocamlValues
, OcamlIOCTLCallback
));
1296 Store_field(connection
->ocamlValues
, OcamlSeekFunctionCallback
,
1297 Field(original
->ocamlValues
, OcamlSeekFunctionCallback
));
1299 if (Field(original
->ocamlValues
, OcamlURL
) != Val_unit
)
1300 handleURL(connection
, Field(original
->ocamlValues
,
1302 if (Field(original
->ocamlValues
, OcamlProxy
) != Val_unit
)
1303 handleProxy(connection
, Field(original
->ocamlValues
,
1305 if (Field(original
->ocamlValues
, OcamlUserPWD
) != Val_unit
)
1306 handleUserPwd(connection
, Field(original
->ocamlValues
,
1308 if (Field(original
->ocamlValues
, OcamlProxyUserPWD
) != Val_unit
)
1309 handleProxyUserPwd(connection
, Field(original
->ocamlValues
,
1310 OcamlProxyUserPWD
));
1311 if (Field(original
->ocamlValues
, OcamlRange
) != Val_unit
)
1312 handleRange(connection
, Field(original
->ocamlValues
,
1314 if (Field(original
->ocamlValues
, OcamlErrorBuffer
) != Val_unit
)
1315 handleErrorBuffer(connection
, Field(original
->ocamlValues
,
1317 if (Field(original
->ocamlValues
, OcamlPostFields
) != Val_unit
)
1318 handlePostFields(connection
, Field(original
->ocamlValues
,
1320 if (Field(original
->ocamlValues
, OcamlReferer
) != Val_unit
)
1321 handleReferer(connection
, Field(original
->ocamlValues
,
1323 if (Field(original
->ocamlValues
, OcamlUserAgent
) != Val_unit
)
1324 handleUserAgent(connection
, Field(original
->ocamlValues
,
1326 if (Field(original
->ocamlValues
, OcamlFTPPort
) != Val_unit
)
1327 handleFTPPort(connection
, Field(original
->ocamlValues
,
1329 if (Field(original
->ocamlValues
, OcamlCookie
) != Val_unit
)
1330 handleCookie(connection
, Field(original
->ocamlValues
,
1332 if (Field(original
->ocamlValues
, OcamlHTTPHeader
) != Val_unit
)
1333 handleHTTPHeader(connection
, Field(original
->ocamlValues
,
1335 if (Field(original
->ocamlValues
, OcamlHTTPPost
) != Val_unit
)
1336 handleHTTPPost(connection
, Field(original
->ocamlValues
,
1338 if (Field(original
->ocamlValues
, OcamlSSLCert
) != Val_unit
)
1339 handleSSLCert(connection
, Field(original
->ocamlValues
,
1341 if (Field(original
->ocamlValues
, OcamlSSLCertType
) != Val_unit
)
1342 handleSSLCertType(connection
, Field(original
->ocamlValues
,
1344 if (Field(original
->ocamlValues
, OcamlSSLCertPasswd
) != Val_unit
)
1345 handleSSLCertPasswd(connection
, Field(original
->ocamlValues
,
1346 OcamlSSLCertPasswd
));
1347 if (Field(original
->ocamlValues
, OcamlSSLKey
) != Val_unit
)
1348 handleSSLKey(connection
, Field(original
->ocamlValues
,
1350 if (Field(original
->ocamlValues
, OcamlSSLKeyType
) != Val_unit
)
1351 handleSSLKeyType(connection
, Field(original
->ocamlValues
,
1353 if (Field(original
->ocamlValues
, OcamlSSLKeyPasswd
) != Val_unit
)
1354 handleSSLKeyPasswd(connection
, Field(original
->ocamlValues
,
1355 OcamlSSLKeyPasswd
));
1356 if (Field(original
->ocamlValues
, OcamlSSLEngine
) != Val_unit
)
1357 handleSSLEngine(connection
, Field(original
->ocamlValues
,
1359 if (Field(original
->ocamlValues
, OcamlQuote
) != Val_unit
)
1360 handleQuote(connection
, Field(original
->ocamlValues
,
1362 if (Field(original
->ocamlValues
, OcamlPostQuote
) != Val_unit
)
1363 handlePostQuote(connection
, Field(original
->ocamlValues
,
1365 if (Field(original
->ocamlValues
, OcamlCookieFile
) != Val_unit
)
1366 handleCookieFile(connection
, Field(original
->ocamlValues
,
1368 if (Field(original
->ocamlValues
, OcamlCustomRequest
) != Val_unit
)
1369 handleCustomRequest(connection
, Field(original
->ocamlValues
,
1370 OcamlCustomRequest
));
1371 if (Field(original
->ocamlValues
, OcamlInterface
) != Val_unit
)
1372 handleInterface(connection
, Field(original
->ocamlValues
,
1374 if (Field(original
->ocamlValues
, OcamlCAInfo
) != Val_unit
)
1375 handleCAInfo(connection
, Field(original
->ocamlValues
,
1377 if (Field(original
->ocamlValues
, OcamlCAPath
) != Val_unit
)
1378 handleCAPath(connection
, Field(original
->ocamlValues
,
1380 if (Field(original
->ocamlValues
, OcamlRandomFile
) != Val_unit
)
1381 handleRandomFile(connection
, Field(original
->ocamlValues
,
1383 if (Field(original
->ocamlValues
, OcamlEGDSocket
) != Val_unit
)
1384 handleEGDSocket(connection
, Field(original
->ocamlValues
,
1386 if (Field(original
->ocamlValues
, OcamlCookieJar
) != Val_unit
)
1387 handleCookieJar(connection
, Field(original
->ocamlValues
,
1389 if (Field(original
->ocamlValues
, OcamlSSLCipherList
) != Val_unit
)
1390 handleSSLCipherList(connection
, Field(original
->ocamlValues
,
1391 OcamlSSLCipherList
));
1392 if (Field(original
->ocamlValues
, OcamlPrivate
) != Val_unit
)
1393 handlePrivate(connection
, Field(original
->ocamlValues
,
1395 if (Field(original
->ocamlValues
, OcamlHTTP200Aliases
) != Val_unit
)
1396 handleHTTP200Aliases(connection
, Field(original
->ocamlValues
,
1397 OcamlHTTP200Aliases
));
1398 if (Field(original
->ocamlValues
, OcamlNETRCFile
) != Val_unit
)
1399 handleNETRCFile(connection
, Field(original
->ocamlValues
,
1401 if (Field(original
->ocamlValues
, OcamlFTPAccount
) != Val_unit
)
1402 handleFTPAccount(connection
, Field(original
->ocamlValues
,
1404 if (Field(original
->ocamlValues
, OcamlCookieList
) != Val_unit
)
1405 handleCookieList(connection
, Field(original
->ocamlValues
,
1407 if (Field(original
->ocamlValues
, OcamlFTPAlternativeToUser
) != Val_unit
)
1408 handleFTPAlternativeToUser(connection
,
1409 Field(original
->ocamlValues
,
1410 OcamlFTPAlternativeToUser
));
1411 if (Field(original
->ocamlValues
, OcamlSSHPublicKeyFile
) != Val_unit
)
1412 handleSSHPublicKeyFile(connection
,
1413 Field(original
->ocamlValues
,
1414 OcamlSSHPublicKeyFile
));
1415 if (Field(original
->ocamlValues
, OcamlSSHPrivateKeyFile
) != Val_unit
)
1416 handleSSHPrivateKeyFile(connection
,
1417 Field(original
->ocamlValues
,
1418 OcamlSSHPrivateKeyFile
));
1419 if (Field(original
->ocamlValues
, OcamlCopyPostFields
) != Val_unit
)
1420 handleCopyPostFields(connection
,
1421 Field(original
->ocamlValues
,
1422 OcamlCopyPostFields
));
1423 if (Field(original
->ocamlValues
, OcamlDNSServers
) != Val_unit
)
1424 handleDnsServers(connection
,
1425 Field(original
->ocamlValues
,
1427 if (Field(original
->ocamlValues
, OcamlMailFrom
) != Val_unit
)
1428 handleMailFrom(connection
,
1429 Field(original
->ocamlValues
,
1431 if (Field(original
->ocamlValues
, OcamlMailRcpt
) != Val_unit
)
1432 handleMailRcpt(connection
,
1433 Field(original
->ocamlValues
,
1439 static void free_if(void* p
) { if (NULL
!= p
) free(p
); }
1441 static void removeConnection(Connection
*connection
, int finalization
)
1443 const char* fin_url
= NULL
;
1445 if (!connection
->connection
)
1447 return; /* already cleaned up */
1452 /* cannot engage OCaml runtime at finalization, just report leak */
1453 if (CURLE_OK
!= curl_easy_getinfo(connection
->connection
, CURLINFO_EFFECTIVE_URL
, &fin_url
) || NULL
== fin_url
)
1455 fin_url
= "unknown";
1457 fprintf(stderr
,"Curl: handle %p leaked, conn %p, url %s\n", connection
->connection
, connection
, fin_url
);
1462 enter_blocking_section();
1463 curl_easy_cleanup(connection
->connection
);
1464 leave_blocking_section();
1467 connection
->connection
= NULL
;
1469 if (connectionList
.tail
== connection
)
1470 connectionList
.tail
= connectionList
.tail
->next
;
1471 if (connectionList
.head
== connection
)
1472 connectionList
.head
= connectionList
.head
->prev
;
1474 if (connection
->next
!= NULL
)
1475 connection
->next
->prev
= connection
->prev
;
1476 if (connection
->prev
!= NULL
)
1477 connection
->prev
->next
= connection
->next
;
1479 remove_global_root(&connection
->ocamlValues
);
1481 free_if(connection
->url
);
1482 free_if(connection
->proxy
);
1483 free_if(connection
->userPwd
);
1484 free_if(connection
->proxyUserPwd
);
1485 free_if(connection
->range
);
1486 free_if(connection
->errorBuffer
);
1487 free_if(connection
->postFields
);
1488 free_if(connection
->referer
);
1489 free_if(connection
->userAgent
);
1490 free_if(connection
->ftpPort
);
1491 free_if(connection
->cookie
);
1492 free_curl_slist(connection
->httpHeader
);
1493 if (connection
->httpPostFirst
!= NULL
)
1494 curl_formfree(connection
->httpPostFirst
);
1495 free_curl_slist(connection
->httpPostStrings
);
1496 free_curl_slist(connection
->resolve
);
1497 free_if(connection
->sslCert
);
1498 free_if(connection
->sslCertType
);
1499 free_if(connection
->sslCertPasswd
);
1500 free_if(connection
->sslKey
);
1501 free_if(connection
->sslKeyType
);
1502 free_if(connection
->sslKeyPasswd
);
1503 free_if(connection
->sslEngine
);
1504 free_curl_slist(connection
->quote
);
1505 free_curl_slist(connection
->postQuote
);
1506 free_if(connection
->cookieFile
);
1507 free_if(connection
->customRequest
);
1508 free_if(connection
->interface_
);
1509 free_if(connection
->caInfo
);
1510 free_if(connection
->caPath
);
1511 free_if(connection
->randomFile
);
1512 free_if(connection
->egdSocket
);
1513 free_if(connection
->cookieJar
);
1514 free_if(connection
->sslCipherList
);
1515 free_if(connection
->private);
1516 free_curl_slist(connection
->http200Aliases
);
1517 free_if(connection
->netrcFile
);
1518 free_if(connection
->ftpaccount
);
1519 free_if(connection
->cookielist
);
1520 free_if(connection
->ftpAlternativeToUser
);
1521 free_if(connection
->sshPublicKeyFile
);
1522 free_if(connection
->sshPrivateKeyFile
);
1523 free_if(connection
->copyPostFields
);
1524 free_if(connection
->dns_servers
);
1525 free_if(connection
->mailFrom
);
1526 free_curl_slist(connection
->mailRcpt
);
1530 static void checkConnection(Connection
* connection
)
1535 static void checkConnection(Connection
*connection
)
1537 Connection
*listIter
;
1539 listIter
= connectionList
.tail
;
1541 while (listIter
!= NULL
)
1543 if (listIter
== connection
)
1546 listIter
= listIter
->next
;
1549 failwith("Invalid Connection");
1553 static Connection
* findConnection(CURL
* h
)
1555 Connection
*listIter
;
1557 listIter
= connectionList
.tail
;
1559 while (listIter
!= NULL
)
1561 if (listIter
->connection
== h
)
1564 listIter
= listIter
->next
;
1567 failwith("Unknown handle");
1570 void op_curl_easy_finalize(value v
)
1572 Connection
* conn
= Connection_val(v
);
1573 /* same connection may be referenced by several different
1574 OCaml values, see e.g. caml_curl_multi_remove_finished */
1576 if (0 == conn
->refcount
)
1578 removeConnection(conn
, 1);
1583 int op_curl_easy_compare(value v1
, value v2
)
1585 size_t p1
= (size_t)Connection_val(v1
);
1586 size_t p2
= (size_t)Connection_val(v2
);
1587 return (p1
== p2
? 0 : (p1
> p2
? 1 : -1)); /* compare addresses */
1590 intnat
op_curl_easy_hash(value v
)
1592 return (size_t)Connection_val(v
); /* address */
1595 static struct custom_operations curl_easy_ops
= {
1597 op_curl_easy_finalize
,
1598 op_curl_easy_compare
,
1600 custom_serialize_default
,
1601 custom_deserialize_default
,
1602 #if defined(custom_compare_ext_default)
1603 custom_compare_ext_default
,
1607 value
caml_curl_alloc(Connection
* conn
)
1609 value v
= caml_alloc_custom(&curl_easy_ops
, sizeof(Connection
*), 0, 1);
1610 Connection_val(v
) = conn
;
1615 #define WRAP_DATA_CALLBACK(f) \
1616 static size_t f(char *ptr, size_t size, size_t nmemb, void *data)\
1619 leave_blocking_section();\
1620 result = f##_nolock(ptr,size,nmemb,data);\
1621 enter_blocking_section();\
1625 static size_t writeFunction_nolock(char *ptr
, size_t size
, size_t nmemb
, void *data
)
1628 CAMLlocal2(result
, str
);
1629 Connection
*conn
= (Connection
*)data
;
1632 checkConnection(conn
);
1634 str
= alloc_string(size
*nmemb
);
1636 for (i
= 0; i
< size
*nmemb
; i
++)
1637 Byte(str
, i
) = ptr
[i
];
1639 result
= callback_exn(Field(conn
->ocamlValues
, OcamlWriteCallback
), str
);
1641 CAMLreturnT(size_t, Is_exception_result(result
) ? 0 : Int_val(result
));
1644 WRAP_DATA_CALLBACK(writeFunction
)
1646 static size_t readFunction_nolock(void *ptr
, size_t size
, size_t nmemb
, void *data
)
1650 Connection
*conn
= (Connection
*)data
;
1653 checkConnection(conn
);
1655 result
= callback_exn(Field(conn
->ocamlValues
, OcamlReadCallback
),
1656 Val_int(size
*nmemb
));
1658 if (Is_exception_result(result
))
1660 CAMLreturnT(size_t,CURL_READFUNC_ABORT
);
1663 length
= string_length(result
);
1665 if (length
<= size
*nmemb
)
1667 memcpy(ptr
, String_val(result
), length
);
1669 CAMLreturnT(size_t,length
);
1673 CAMLreturnT(size_t,CURL_READFUNC_ABORT
);
1677 WRAP_DATA_CALLBACK(readFunction
)
1679 static size_t headerFunction_nolock(char *ptr
, size_t size
, size_t nmemb
, void *data
)
1682 CAMLlocal2(result
,str
);
1683 Connection
*conn
= (Connection
*)data
;
1686 checkConnection(conn
);
1688 str
= alloc_string(size
*nmemb
);
1690 for (i
= 0; i
< size
*nmemb
; i
++)
1691 Byte(str
, i
) = ptr
[i
];
1693 result
= callback_exn(Field(conn
->ocamlValues
, OcamlHeaderCallback
), str
);
1695 CAMLreturnT(size_t, Is_exception_result(result
) ? 0 : Int_val(result
));
1698 WRAP_DATA_CALLBACK(headerFunction
)
1700 static int progressFunction_nolock(void *data
,
1708 CAMLlocalN(callbackData
, 4);
1709 Connection
*conn
= (Connection
*)data
;
1711 checkConnection(conn
);
1713 callbackData
[0] = copy_double(dlTotal
);
1714 callbackData
[1] = copy_double(dlNow
);
1715 callbackData
[2] = copy_double(ulTotal
);
1716 callbackData
[3] = copy_double(ulNow
);
1718 result
= callbackN_exn(Field(conn
->ocamlValues
, OcamlProgressCallback
),
1721 CAMLreturnT(int, Is_exception_result(result
) ? 1 : Bool_val(result
));
1724 static int progressFunction(void *data
,
1731 leave_blocking_section();
1732 r
= progressFunction_nolock(data
,dlTotal
,dlNow
,ulTotal
,ulNow
);
1733 enter_blocking_section();
1737 static int debugFunction_nolock(CURL
*debugConnection
,
1738 curl_infotype infoType
,
1740 size_t bufferLength
,
1744 CAMLlocal3(camlDebugConnection
, camlInfoType
, camlMessage
);
1746 Connection
*conn
= (Connection
*)data
;
1747 (void)debugConnection
; /* not used */
1749 checkConnection(conn
);
1751 camlDebugConnection
= (value
)conn
;
1752 camlInfoType
= Val_long(infoType
);
1753 camlMessage
= alloc_string(bufferLength
);
1755 for (i
= 0; i
< bufferLength
; i
++)
1756 Byte(camlMessage
, i
) = buffer
[i
];
1758 callback3_exn(Field(conn
->ocamlValues
, OcamlDebugCallback
),
1759 camlDebugConnection
,
1763 CAMLreturnT(int, 0);
1766 static int debugFunction(CURL
*debugConnection
,
1767 curl_infotype infoType
,
1769 size_t bufferLength
,
1773 leave_blocking_section();
1774 r
= debugFunction_nolock(debugConnection
, infoType
, buffer
, bufferLength
, data
);
1775 enter_blocking_section();
1779 static curlioerr
ioctlFunction_nolock(CURL
*ioctl
,
1784 CAMLlocal3(camlResult
, camlConnection
, camlCmd
);
1785 Connection
*conn
= (Connection
*)data
;
1786 curlioerr result
= CURLIOE_OK
;
1787 (void)ioctl
; /* not used */
1789 checkConnection(conn
);
1791 if (cmd
== CURLIOCMD_NOP
)
1792 camlCmd
= Val_long(0);
1793 else if (cmd
== CURLIOCMD_RESTARTREAD
)
1794 camlCmd
= Val_long(1);
1796 failwith("Invalid IOCTL Cmd!");
1798 camlConnection
= caml_curl_alloc(conn
);
1800 camlResult
= callback2_exn(Field(conn
->ocamlValues
, OcamlIOCTLCallback
),
1804 if (Is_exception_result(camlResult
))
1806 result
= CURLIOE_FAILRESTART
;
1809 switch (Long_val(camlResult
))
1811 case 0: /* CURLIOE_OK */
1812 result
= CURLIOE_OK
;
1815 case 1: /* CURLIOE_UNKNOWNCMD */
1816 result
= CURLIOE_UNKNOWNCMD
;
1819 case 2: /* CURLIOE_FAILRESTART */
1820 result
= CURLIOE_FAILRESTART
;
1823 default: /* Incorrect return value, but let's handle it */
1824 result
= CURLIOE_FAILRESTART
;
1828 CAMLreturnT(curlioerr
, result
);
1831 static curlioerr
ioctlFunction(CURL
*ioctl
,
1836 leave_blocking_section();
1837 r
= ioctlFunction_nolock(ioctl
, cmd
, data
);
1838 enter_blocking_section();
1842 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
1843 static int seekFunction_nolock(void *data
,
1848 CAMLlocal3(camlResult
, camlOffset
, camlOrigin
);
1849 Connection
*conn
= (Connection
*)data
;
1851 camlOffset
= copy_int64(offset
);
1853 if (origin
== SEEK_SET
)
1854 camlOrigin
= Val_long(0);
1855 else if (origin
== SEEK_CUR
)
1856 camlOrigin
= Val_long(1);
1857 else if (origin
== SEEK_END
)
1858 camlOrigin
= Val_long(2);
1860 failwith("Invalid seek code");
1862 camlResult
= callback2_exn(Field(conn
->ocamlValues
,
1863 OcamlSeekFunctionCallback
),
1868 if (Is_exception_result(camlResult
))
1869 result
= CURL_SEEKFUNC_FAIL
;
1871 switch (Int_val(camlResult
))
1873 case 0: result
= CURL_SEEKFUNC_OK
; break;
1874 case 1: result
= CURL_SEEKFUNC_FAIL
; break;
1875 case 2: result
= CURL_SEEKFUNC_CANTSEEK
; break;
1876 default: failwith("Invalid seek result");
1879 CAMLreturnT(int, result
);
1882 static int seekFunction(void *data
,
1887 leave_blocking_section();
1888 r
= seekFunction_nolock(data
,offset
,origin
);
1889 enter_blocking_section();
1895 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
1896 static int openSocketFunction_nolock(void *data
,
1897 curlsocktype purpose
,
1898 struct curl_sockaddr
*addr
)
1902 Connection
*conn
= (Connection
*)data
;
1904 (void)purpose
; /* not used */
1906 sock
= socket(addr
->family
, addr
->socktype
, addr
->protocol
);
1911 result
= callback_exn(Field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
), Val_int(sock
));
1912 if (Is_exception_result(result
))
1919 CAMLreturnT(int, (sock
== -1) ? CURL_SOCKET_BAD
: sock
);
1922 static int openSocketFunction(void *data
,
1923 curlsocktype purpose
,
1924 struct curl_sockaddr
*address
)
1927 leave_blocking_section();
1928 r
= openSocketFunction_nolock(data
,purpose
,address
);
1929 enter_blocking_section();
1936 ** curl_global_init helper function
1939 CAMLprim value
helper_curl_global_init(value initOption
)
1941 CAMLparam1(initOption
);
1943 switch (Long_val(initOption
))
1945 case 0: /* CURLINIT_GLOBALALL */
1946 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_ALL
)));
1949 case 1: /* CURLINIT_GLOBALSSL */
1950 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_SSL
)));
1953 case 2: /* CURLINIT_GLOBALWIN32 */
1954 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_WIN32
)));
1957 case 3: /* CURLINIT_GLOBALNOTHING */
1958 CAMLreturn(Val_long(curl_global_init(CURL_GLOBAL_NOTHING
)));
1962 failwith("Invalid Initialization Option");
1966 /* Keep compiler happy, we should never get here due to failwith() */
1967 CAMLreturn(Val_unit
);
1971 ** curl_global_cleanup helper function
1974 CAMLprim value
helper_curl_global_cleanup(void)
1978 curl_global_cleanup();
1980 CAMLreturn(Val_unit
);
1984 ** curl_easy_init helper function
1986 CAMLprim value
helper_curl_easy_init(void)
1991 result
= caml_curl_alloc(newConnection());
1996 CAMLprim value
helper_curl_easy_reset(value conn
)
1999 Connection
*connection
= Connection_val(conn
);
2001 checkConnection(connection
);
2002 curl_easy_reset(connection
->connection
);
2003 resetOcamlValues(connection
);
2005 CAMLreturn(Val_unit
);
2009 ** curl_easy_setopt helper utility functions
2012 static void handleWriteFunction(Connection
*conn
, value option
)
2015 CURLcode result
= CURLE_OK
;
2017 if (Tag_val(option
) == Closure_tag
)
2018 Store_field(conn
->ocamlValues
, OcamlWriteCallback
, option
);
2020 failwith("Not a proper closure");
2022 result
= curl_easy_setopt(conn
->connection
,
2023 CURLOPT_WRITEFUNCTION
,
2026 if (result
!= CURLE_OK
)
2027 raiseError(conn
, result
);
2029 result
= curl_easy_setopt(conn
->connection
,
2033 if (result
!= CURLE_OK
)
2034 raiseError(conn
, result
);
2039 static void handleReadFunction(Connection
*conn
, value option
)
2042 CURLcode result
= CURLE_OK
;
2044 if (Tag_val(option
) == Closure_tag
)
2045 Store_field(conn
->ocamlValues
, OcamlReadCallback
, option
);
2047 failwith("Not a proper closure");
2049 result
= curl_easy_setopt(conn
->connection
,
2050 CURLOPT_READFUNCTION
,
2053 if (result
!= CURLE_OK
)
2054 raiseError(conn
, result
);
2056 result
= curl_easy_setopt(conn
->connection
,
2060 if (result
!= CURLE_OK
)
2061 raiseError(conn
, result
);
2066 static void handleURL(Connection
*conn
, value option
)
2069 CURLcode result
= CURLE_OK
;
2071 Store_field(conn
->ocamlValues
, OcamlURL
, option
);
2073 if (conn
->url
!= NULL
)
2076 conn
->url
= strdup(String_val(option
));
2078 result
= curl_easy_setopt(conn
->connection
,
2082 if (result
!= CURLE_OK
)
2083 raiseError(conn
, result
);
2088 static void handleInFileSize(Connection
*conn
, value option
)
2091 CURLcode result
= CURLE_OK
;
2093 result
= curl_easy_setopt(conn
->connection
,
2097 if (result
!= CURLE_OK
)
2098 raiseError(conn
, result
);
2103 static void handleProxy(Connection
*conn
, value option
)
2106 CURLcode result
= CURLE_OK
;
2108 Store_field(conn
->ocamlValues
, OcamlProxy
, option
);
2110 if (conn
->proxy
!= NULL
)
2113 conn
->proxy
= strdup(String_val(option
));
2115 result
= curl_easy_setopt(conn
->connection
,
2119 if (result
!= CURLE_OK
)
2120 raiseError(conn
, result
);
2125 static void handleProxyPort(Connection
*conn
, value option
)
2128 CURLcode result
= CURLE_OK
;
2130 result
= curl_easy_setopt(conn
->connection
,
2134 if (result
!= CURLE_OK
)
2135 raiseError(conn
, result
);
2140 static void handleHTTPProxyTunnel(Connection
*conn
, value option
)
2143 CURLcode result
= CURLE_OK
;
2145 result
= curl_easy_setopt(conn
->connection
,
2146 CURLOPT_HTTPPROXYTUNNEL
,
2149 if (result
!= CURLE_OK
)
2150 raiseError(conn
, result
);
2155 static void handleVerbose(Connection
*conn
, value option
)
2158 CURLcode result
= CURLE_OK
;
2160 result
= curl_easy_setopt(conn
->connection
,
2164 if (result
!= CURLE_OK
)
2165 raiseError(conn
, result
);
2170 static void handleHeader(Connection
*conn
, value option
)
2173 CURLcode result
= CURLE_OK
;
2175 result
= curl_easy_setopt(conn
->connection
,
2179 if (result
!= CURLE_OK
)
2180 raiseError(conn
, result
);
2185 static void handleNoProgress(Connection
*conn
, value option
)
2188 CURLcode result
= CURLE_OK
;
2190 result
= curl_easy_setopt(conn
->connection
,
2194 if (result
!= CURLE_OK
)
2195 raiseError(conn
, result
);
2200 #if HAVE_DECL_CURLOPT_NOSIGNAL
2201 static void handleNoSignal(Connection
*conn
, value option
)
2204 CURLcode result
= CURLE_OK
;
2206 result
= curl_easy_setopt(conn
->connection
,
2210 if (result
!= CURLE_OK
)
2211 raiseError(conn
, result
);
2217 static void handleNoBody(Connection
*conn
, value option
)
2220 CURLcode result
= CURLE_OK
;
2222 result
= curl_easy_setopt(conn
->connection
,
2226 if (result
!= CURLE_OK
)
2227 raiseError(conn
, result
);
2232 static void handleFailOnError(Connection
*conn
, value option
)
2235 CURLcode result
= CURLE_OK
;
2237 result
= curl_easy_setopt(conn
->connection
,
2238 CURLOPT_FAILONERROR
,
2241 if (result
!= CURLE_OK
)
2242 raiseError(conn
, result
);
2247 static void handleUpload(Connection
*conn
, value option
)
2250 CURLcode result
= CURLE_OK
;
2252 result
= curl_easy_setopt(conn
->connection
,
2256 if (result
!= CURLE_OK
)
2257 raiseError(conn
, result
);
2262 static void handlePost(Connection
*conn
, value option
)
2265 CURLcode result
= CURLE_OK
;
2267 result
= curl_easy_setopt(conn
->connection
,
2271 if (result
!= CURLE_OK
)
2272 raiseError(conn
, result
);
2277 static void handleFTPListOnly(Connection
*conn
, value option
)
2280 CURLcode result
= CURLE_OK
;
2282 result
= curl_easy_setopt(conn
->connection
,
2283 CURLOPT_FTPLISTONLY
,
2286 if (result
!= CURLE_OK
)
2287 raiseError(conn
, result
);
2292 static void handleFTPAppend(Connection
*conn
, value option
)
2295 CURLcode result
= CURLE_OK
;
2297 result
= curl_easy_setopt(conn
->connection
,
2301 if (result
!= CURLE_OK
)
2302 raiseError(conn
, result
);
2307 static void handleNETRC(Connection
*conn
, value option
)
2310 CURLcode result
= CURLE_OK
;
2313 switch (Long_val(option
))
2315 case 0: /* CURL_NETRC_OPTIONAL */
2316 netrc
= CURL_NETRC_OPTIONAL
;
2319 case 1:/* CURL_NETRC_IGNORED */
2320 netrc
= CURL_NETRC_IGNORED
;
2323 case 2: /* CURL_NETRC_REQUIRED */
2324 netrc
= CURL_NETRC_REQUIRED
;
2328 failwith("Invalid NETRC Option");
2332 result
= curl_easy_setopt(conn
->connection
,
2336 if (result
!= CURLE_OK
)
2337 raiseError(conn
, result
);
2342 #if HAVE_DECL_CURLOPT_ENCODING
2343 static void handleEncoding(Connection
*conn
, value option
)
2346 CURLcode result
= CURLE_OK
;
2348 switch (Long_val(option
))
2350 case 0: /* CURL_ENCODING_NONE */
2351 result
= curl_easy_setopt(conn
->connection
,
2356 case 1: /* CURL_ENCODING_DEFLATE */
2357 result
= curl_easy_setopt(conn
->connection
,
2362 case 2: /* CURL_ENCODING_GZIP */
2363 result
= curl_easy_setopt(conn
->connection
,
2368 case 3: /* CURL_ENCODING_ANY */
2369 result
= curl_easy_setopt(conn
->connection
,
2375 failwith("Invalid Encoding Option");
2379 if (result
!= CURLE_OK
)
2380 raiseError(conn
, result
);
2386 static void handleFollowLocation(Connection
*conn
, value option
)
2389 CURLcode result
= CURLE_OK
;
2391 result
= curl_easy_setopt(conn
->connection
,
2392 CURLOPT_FOLLOWLOCATION
,
2395 if (result
!= CURLE_OK
)
2396 raiseError(conn
, result
);
2401 static void handleTransferText(Connection
*conn
, value option
)
2404 CURLcode result
= CURLE_OK
;
2406 result
= curl_easy_setopt(conn
->connection
,
2407 CURLOPT_TRANSFERTEXT
,
2410 if (result
!= CURLE_OK
)
2411 raiseError(conn
, result
);
2416 static void handlePut(Connection
*conn
, value option
)
2419 CURLcode result
= CURLE_OK
;
2421 result
= curl_easy_setopt(conn
->connection
,
2425 if (result
!= CURLE_OK
)
2426 raiseError(conn
, result
);
2431 static void handleUserPwd(Connection
*conn
, value option
)
2434 CURLcode result
= CURLE_OK
;
2436 Store_field(conn
->ocamlValues
, OcamlUserPWD
, option
);
2438 if (conn
->userPwd
!= NULL
)
2439 free(conn
->userPwd
);
2441 conn
->userPwd
= strdup(String_val(option
));
2443 result
= curl_easy_setopt(conn
->connection
,
2447 if (result
!= CURLE_OK
)
2448 raiseError(conn
, result
);
2453 static void handleProxyUserPwd(Connection
*conn
, value option
)
2456 CURLcode result
= CURLE_OK
;
2458 Store_field(conn
->ocamlValues
, OcamlProxyUserPWD
, option
);
2460 if (conn
->proxyUserPwd
!= NULL
)
2461 free(conn
->proxyUserPwd
);
2463 conn
->proxyUserPwd
= strdup(String_val(option
));
2465 result
= curl_easy_setopt(conn
->connection
,
2466 CURLOPT_PROXYUSERPWD
,
2467 conn
->proxyUserPwd
);
2469 if (result
!= CURLE_OK
)
2470 raiseError(conn
, result
);
2475 static void handleRange(Connection
*conn
, value option
)
2478 CURLcode result
= CURLE_OK
;
2480 Store_field(conn
->ocamlValues
, OcamlRange
, option
);
2482 if (conn
->range
!= NULL
)
2485 conn
->range
= strdup(String_val(option
));
2487 result
= curl_easy_setopt(conn
->connection
,
2491 if (result
!= CURLE_OK
)
2492 raiseError(conn
, result
);
2497 static void handleErrorBuffer(Connection
*conn
, value option
)
2500 CURLcode result
= CURLE_OK
;
2502 Store_field(conn
->ocamlValues
, OcamlErrorBuffer
, option
);
2504 if (conn
->errorBuffer
!= NULL
)
2505 free(conn
->errorBuffer
);
2507 conn
->errorBuffer
= malloc(sizeof(char) * CURL_ERROR_SIZE
);
2509 result
= curl_easy_setopt(conn
->connection
,
2510 CURLOPT_ERRORBUFFER
,
2513 if (result
!= CURLE_OK
)
2514 raiseError(conn
, result
);
2519 static void handleTimeout(Connection
*conn
, value option
)
2522 CURLcode result
= CURLE_OK
;
2524 result
= curl_easy_setopt(conn
->connection
,
2528 if (result
!= CURLE_OK
)
2529 raiseError(conn
, result
);
2534 static void handlePostFields(Connection
*conn
, value option
)
2537 CURLcode result
= CURLE_OK
;
2539 Store_field(conn
->ocamlValues
, OcamlPostFields
, option
);
2541 if (conn
->postFields
!= NULL
)
2542 free(conn
->postFields
);
2544 conn
->postFields
= malloc(string_length(option
)+1);
2545 memcpy(conn
->postFields
, String_val(option
), string_length(option
)+1);
2547 result
= curl_easy_setopt(conn
->connection
,
2551 if (result
!= CURLE_OK
)
2552 raiseError(conn
, result
);
2557 static void handlePostFieldSize(Connection
*conn
, value option
)
2560 CURLcode result
= CURLE_OK
;
2562 result
= curl_easy_setopt(conn
->connection
,
2563 CURLOPT_POSTFIELDSIZE
,
2566 if (result
!= CURLE_OK
)
2567 raiseError(conn
, result
);
2572 static void handleReferer(Connection
*conn
, value option
)
2575 CURLcode result
= CURLE_OK
;
2577 Store_field(conn
->ocamlValues
, OcamlReferer
, option
);
2579 if (conn
->referer
!= NULL
)
2580 free(conn
->referer
);
2582 conn
->referer
= strdup(String_val(option
));
2584 result
= curl_easy_setopt(conn
->connection
,
2588 if (result
!= CURLE_OK
)
2589 raiseError(conn
, result
);
2594 static void handleUserAgent(Connection
*conn
, value option
)
2597 CURLcode result
= CURLE_OK
;
2599 Store_field(conn
->ocamlValues
, OcamlUserAgent
, option
);
2601 if (conn
->userAgent
!= NULL
)
2602 free(conn
->userAgent
);
2604 conn
->userAgent
= strdup(String_val(option
));
2606 result
= curl_easy_setopt(conn
->connection
,
2610 if (result
!= CURLE_OK
)
2611 raiseError(conn
, result
);
2616 static void handleFTPPort(Connection
*conn
, value option
)
2619 CURLcode result
= CURLE_OK
;
2621 Store_field(conn
->ocamlValues
, OcamlFTPPort
, option
);
2623 if (conn
->ftpPort
!= NULL
)
2624 free(conn
->ftpPort
);
2626 conn
->ftpPort
= strdup(String_val(option
));
2628 result
= curl_easy_setopt(conn
->connection
,
2632 if (result
!= CURLE_OK
)
2633 raiseError(conn
, result
);
2638 static void handleLowSpeedLimit(Connection
*conn
, value option
)
2641 CURLcode result
= CURLE_OK
;
2643 result
= curl_easy_setopt(conn
->connection
,
2644 CURLOPT_LOW_SPEED_LIMIT
,
2647 if (result
!= CURLE_OK
)
2648 raiseError(conn
, result
);
2653 static void handleLowSpeedTime(Connection
*conn
, value option
)
2656 CURLcode result
= CURLE_OK
;
2658 result
= curl_easy_setopt(conn
->connection
,
2659 CURLOPT_LOW_SPEED_TIME
,
2662 if (result
!= CURLE_OK
)
2663 raiseError(conn
, result
);
2668 static void handleResumeFrom(Connection
*conn
, value option
)
2671 CURLcode result
= CURLE_OK
;
2673 result
= curl_easy_setopt(conn
->connection
,
2674 CURLOPT_RESUME_FROM
,
2677 if (result
!= CURLE_OK
)
2678 raiseError(conn
, result
);
2683 static void handleCookie(Connection
*conn
, value option
)
2686 CURLcode result
= CURLE_OK
;
2688 Store_field(conn
->ocamlValues
, OcamlCookie
, option
);
2690 if (conn
->cookie
!= NULL
)
2693 conn
->cookie
= strdup(String_val(option
));
2695 result
= curl_easy_setopt(conn
->connection
,
2699 if (result
!= CURLE_OK
)
2700 raiseError(conn
, result
);
2705 static void handleHTTPHeader(Connection
*conn
, value option
)
2708 CAMLlocal1(listIter
);
2709 CURLcode result
= CURLE_OK
;
2711 Store_field(conn
->ocamlValues
, OcamlHTTPHeader
, option
);
2713 free_curl_slist(conn
->httpHeader
);
2714 conn
->httpHeader
= NULL
;
2718 while (!Is_long(listIter
))
2720 conn
->httpHeader
= curl_slist_append(conn
->httpHeader
, String_val(Field(listIter
, 0)));
2722 listIter
= Field(listIter
, 1);
2725 result
= curl_easy_setopt(conn
->connection
,
2729 if (result
!= CURLE_OK
)
2730 raiseError(conn
, result
);
2735 static void handleHTTPPost(Connection
*conn
, value option
)
2738 CAMLlocal3(listIter
, formItem
, contentType
);
2739 CURLcode result
= CURLE_OK
;
2740 char *str1
, *str2
, *str3
, *str4
;
2744 Store_field(conn
->ocamlValues
, OcamlHTTPPost
, option
);
2746 if (conn
->httpPostFirst
!= NULL
)
2747 curl_formfree(conn
->httpPostFirst
);
2749 conn
->httpPostFirst
= NULL
;
2750 conn
->httpPostLast
= NULL
;
2752 free_curl_slist(conn
->httpPostStrings
);
2753 conn
->httpPostStrings
= NULL
;
2755 while (!Is_long(listIter
))
2757 formItem
= Field(listIter
, 0);
2759 switch (Tag_val(formItem
))
2761 case 0: /* CURLFORM_CONTENT */
2762 if (Wosize_val(formItem
) < 3)
2764 failwith("Incorrect CURLFORM_CONTENT parameters");
2767 if (Is_long(Field(formItem
, 2)) &&
2768 Long_val(Field(formItem
, 2)) == 0)
2770 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2772 String_val(Field(formItem
, 0)),
2773 string_length(Field(formItem
, 0)));
2774 str1
[string_length(Field(formItem
, 0))] = 0;
2775 conn
->httpPostStrings
=
2776 curl_slist_append(conn
->httpPostStrings
, str1
);
2778 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2780 String_val(Field(formItem
, 1)),
2781 string_length(Field(formItem
, 1)));
2782 str2
[string_length(Field(formItem
, 1))] = 0;
2783 conn
->httpPostStrings
=
2784 curl_slist_append(conn
->httpPostStrings
, str2
);
2786 curl_formadd(&conn
->httpPostFirst
,
2787 &conn
->httpPostLast
,
2790 CURLFORM_NAMELENGTH
,
2791 string_length(Field(formItem
, 0)),
2792 CURLFORM_PTRCONTENTS
,
2794 CURLFORM_CONTENTSLENGTH
,
2795 string_length(Field(formItem
, 1)),
2798 else if (Is_block(Field(formItem
, 2)))
2800 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2802 String_val(Field(formItem
, 0)),
2803 string_length(Field(formItem
, 0)));
2804 str1
[string_length(Field(formItem
, 0))] = 0;
2805 conn
->httpPostStrings
=
2806 curl_slist_append(conn
->httpPostStrings
, str1
);
2808 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2810 String_val(Field(formItem
, 1)),
2811 string_length(Field(formItem
, 1)));
2812 str2
[string_length(Field(formItem
, 1))] = 0;
2813 conn
->httpPostStrings
=
2814 curl_slist_append(conn
->httpPostStrings
, str2
);
2816 contentType
= Field(formItem
, 2);
2818 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2820 String_val(Field(contentType
, 0)),
2821 string_length(Field(contentType
, 0)));
2822 str3
[string_length(Field(contentType
, 0))] = 0;
2823 conn
->httpPostStrings
=
2824 curl_slist_append(conn
->httpPostStrings
, str3
);
2826 curl_formadd(&conn
->httpPostFirst
,
2827 &conn
->httpPostLast
,
2830 CURLFORM_NAMELENGTH
,
2831 string_length(Field(formItem
, 0)),
2832 CURLFORM_PTRCONTENTS
,
2834 CURLFORM_CONTENTSLENGTH
,
2835 string_length(Field(formItem
, 1)),
2836 CURLFORM_CONTENTTYPE
,
2842 failwith("Incorrect CURLFORM_CONTENT parameters");
2846 case 1: /* CURLFORM_FILECONTENT */
2847 if (Wosize_val(formItem
) < 3)
2849 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2852 if (Is_long(Field(formItem
, 2)) &&
2853 Long_val(Field(formItem
, 2)) == 0)
2855 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2857 String_val(Field(formItem
, 0)),
2858 string_length(Field(formItem
, 0)));
2859 str1
[string_length(Field(formItem
, 0))] = 0;
2860 conn
->httpPostStrings
=
2861 curl_slist_append(conn
->httpPostStrings
, str1
);
2863 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2865 String_val(Field(formItem
, 1)),
2866 string_length(Field(formItem
, 1)));
2867 str2
[string_length(Field(formItem
, 1))] = 0;
2868 conn
->httpPostStrings
=
2869 curl_slist_append(conn
->httpPostStrings
, str2
);
2871 curl_formadd(&conn
->httpPostFirst
,
2872 &conn
->httpPostLast
,
2875 CURLFORM_NAMELENGTH
,
2876 string_length(Field(formItem
, 0)),
2877 CURLFORM_FILECONTENT
,
2881 else if (Is_block(Field(formItem
, 2)))
2883 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2885 String_val(Field(formItem
, 0)),
2886 string_length(Field(formItem
, 0)));
2887 str1
[string_length(Field(formItem
, 0))] = 0;
2888 conn
->httpPostStrings
=
2889 curl_slist_append(conn
->httpPostStrings
, str1
);
2891 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2893 String_val(Field(formItem
, 1)),
2894 string_length(Field(formItem
, 1)));
2895 str2
[string_length(Field(formItem
, 1))] = 0;
2896 conn
->httpPostStrings
=
2897 curl_slist_append(conn
->httpPostStrings
, str2
);
2899 contentType
= Field(formItem
, 2);
2901 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2903 String_val(Field(contentType
, 0)),
2904 string_length(Field(contentType
, 0)));
2905 str3
[string_length(Field(contentType
, 0))] = 0;
2906 conn
->httpPostStrings
=
2907 curl_slist_append(conn
->httpPostStrings
, str3
);
2909 curl_formadd(&conn
->httpPostFirst
,
2910 &conn
->httpPostLast
,
2913 CURLFORM_NAMELENGTH
,
2914 string_length(Field(formItem
, 0)),
2915 CURLFORM_FILECONTENT
,
2917 CURLFORM_CONTENTTYPE
,
2923 failwith("Incorrect CURLFORM_FILECONTENT parameters");
2927 case 2: /* CURLFORM_FILE */
2928 if (Wosize_val(formItem
) < 3)
2930 failwith("Incorrect CURLFORM_FILE parameters");
2933 if (Is_long(Field(formItem
, 2)) &&
2934 Long_val(Field(formItem
, 2)) == 0)
2936 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2938 String_val(Field(formItem
, 0)),
2939 string_length(Field(formItem
, 0)));
2940 str1
[string_length(Field(formItem
, 0))] = 0;
2941 conn
->httpPostStrings
=
2942 curl_slist_append(conn
->httpPostStrings
, str1
);
2944 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2946 String_val(Field(formItem
, 1)),
2947 string_length(Field(formItem
, 1)));
2948 str2
[string_length(Field(formItem
, 1))] = 0;
2949 conn
->httpPostStrings
=
2950 curl_slist_append(conn
->httpPostStrings
, str2
);
2952 curl_formadd(&conn
->httpPostFirst
,
2953 &conn
->httpPostLast
,
2956 CURLFORM_NAMELENGTH
,
2957 string_length(Field(formItem
, 0)),
2962 else if (Is_block(Field(formItem
, 2)))
2964 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
2966 String_val(Field(formItem
, 0)),
2967 string_length(Field(formItem
, 0)));
2968 str1
[string_length(Field(formItem
, 0))] = 0;
2969 conn
->httpPostStrings
=
2970 curl_slist_append(conn
->httpPostStrings
, str1
);
2972 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
2974 String_val(Field(formItem
, 1)),
2975 string_length(Field(formItem
, 1)));
2976 str2
[string_length(Field(formItem
, 1))] = 0;
2977 conn
->httpPostStrings
=
2978 curl_slist_append(conn
->httpPostStrings
, str2
);
2980 contentType
= Field(formItem
, 2);
2982 str3
= (char *)malloc(string_length(Field(contentType
, 0))+1);
2984 String_val(Field(contentType
, 0)),
2985 string_length(Field(contentType
, 0)));
2986 str3
[string_length(Field(contentType
, 0))] = 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)),
2998 CURLFORM_CONTENTTYPE
,
3004 failwith("Incorrect CURLFORM_FILE parameters");
3008 case 3: /* CURLFORM_BUFFER */
3009 if (Wosize_val(formItem
) < 4)
3011 failwith("Incorrect CURLFORM_BUFFER parameters");
3014 if (Is_long(Field(formItem
, 3)) &&
3015 Long_val(Field(formItem
, 3)) == 0)
3017 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
3019 String_val(Field(formItem
, 0)),
3020 string_length(Field(formItem
, 0)));
3021 str1
[string_length(Field(formItem
, 0))] = 0;
3022 conn
->httpPostStrings
=
3023 curl_slist_append(conn
->httpPostStrings
, str1
);
3025 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
3027 String_val(Field(formItem
, 1)),
3028 string_length(Field(formItem
, 1)));
3029 str2
[string_length(Field(formItem
, 1))] = 0;
3030 conn
->httpPostStrings
=
3031 curl_slist_append(conn
->httpPostStrings
, str2
);
3033 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
3035 String_val(Field(formItem
, 2)),
3036 string_length(Field(formItem
, 2)));
3037 str3
[string_length(Field(formItem
, 2))] = 0;
3038 conn
->httpPostStrings
=
3039 curl_slist_append(conn
->httpPostStrings
, str3
);
3041 curl_formadd(&conn
->httpPostFirst
,
3042 &conn
->httpPostLast
,
3045 CURLFORM_NAMELENGTH
,
3046 string_length(Field(formItem
, 0)),
3051 CURLFORM_BUFFERLENGTH
,
3052 string_length(Field(formItem
, 2)),
3055 else if (Is_block(Field(formItem
, 3)))
3057 str1
= (char *)malloc(string_length(Field(formItem
, 0))+1);
3059 String_val(Field(formItem
, 0)),
3060 string_length(Field(formItem
, 0)));
3061 str1
[string_length(Field(formItem
, 0))] = 0;
3062 conn
->httpPostStrings
=
3063 curl_slist_append(conn
->httpPostStrings
, str1
);
3065 str2
= (char *)malloc(string_length(Field(formItem
, 1))+1);
3067 String_val(Field(formItem
, 1)),
3068 string_length(Field(formItem
, 1)));
3069 str2
[string_length(Field(formItem
, 1))] = 0;
3070 conn
->httpPostStrings
=
3071 curl_slist_append(conn
->httpPostStrings
, str2
);
3073 str3
= (char *)malloc(string_length(Field(formItem
, 2))+1);
3075 String_val(Field(formItem
, 2)),
3076 string_length(Field(formItem
, 2)));
3077 str3
[string_length(Field(formItem
, 2))] = 0;
3078 conn
->httpPostStrings
=
3079 curl_slist_append(conn
->httpPostStrings
, str3
);
3081 contentType
= Field(formItem
, 3);
3083 str4
= (char *)malloc(string_length(Field(contentType
, 0))+1);
3085 String_val(Field(contentType
, 0)),
3086 string_length(Field(contentType
, 0)));
3087 str4
[string_length(Field(contentType
, 0))] = 0;
3088 conn
->httpPostStrings
=
3089 curl_slist_append(conn
->httpPostStrings
, str4
);
3091 curl_formadd(&conn
->httpPostFirst
,
3092 &conn
->httpPostLast
,
3095 CURLFORM_NAMELENGTH
,
3096 string_length(Field(formItem
, 0)),
3101 CURLFORM_BUFFERLENGTH
,
3102 string_length(Field(formItem
, 2)),
3103 CURLFORM_CONTENTTYPE
,
3109 failwith("Incorrect CURLFORM_BUFFER parameters");
3114 listIter
= Field(listIter
, 1);
3117 result
= curl_easy_setopt(conn
->connection
,
3119 conn
->httpPostFirst
);
3121 if (result
!= CURLE_OK
)
3122 raiseError(conn
, result
);
3127 static void handleSSLCert(Connection
*conn
, value option
)
3130 CURLcode result
= CURLE_OK
;
3132 Store_field(conn
->ocamlValues
, OcamlSSLCert
, option
);
3134 if (conn
->sslCert
!= NULL
)
3135 free(conn
->sslCert
);
3137 conn
->sslCert
= strdup(String_val(option
));
3139 result
= curl_easy_setopt(conn
->connection
,
3143 if (result
!= CURLE_OK
)
3144 raiseError(conn
, result
);
3149 static void handleSSLCertType(Connection
*conn
, value option
)
3152 CURLcode result
= CURLE_OK
;
3154 Store_field(conn
->ocamlValues
, OcamlSSLCertType
, option
);
3156 if (conn
->sslCertType
!= NULL
)
3157 free(conn
->sslCertType
);
3159 conn
->sslCertType
= strdup(String_val(option
));
3161 result
= curl_easy_setopt(conn
->connection
,
3162 CURLOPT_SSLCERTTYPE
,
3165 if (result
!= CURLE_OK
)
3166 raiseError(conn
, result
);
3171 static void handleSSLCertPasswd(Connection
*conn
, value option
)
3174 CURLcode result
= CURLE_OK
;
3176 Store_field(conn
->ocamlValues
, OcamlSSLCertPasswd
, option
);
3178 if (conn
->sslCertPasswd
!= NULL
)
3179 free(conn
->sslCertPasswd
);
3181 conn
->sslCertPasswd
= strdup(String_val(option
));
3183 result
= curl_easy_setopt(conn
->connection
,
3184 CURLOPT_SSLCERTPASSWD
,
3185 conn
->sslCertPasswd
);
3187 if (result
!= CURLE_OK
)
3188 raiseError(conn
, result
);
3193 static void handleSSLKey(Connection
*conn
, value option
)
3196 CURLcode result
= CURLE_OK
;
3198 Store_field(conn
->ocamlValues
, OcamlSSLKey
, option
);
3200 if (conn
->sslKey
!= NULL
)
3203 conn
->sslKey
= strdup(String_val(option
));
3205 result
= curl_easy_setopt(conn
->connection
,
3209 if (result
!= CURLE_OK
)
3210 raiseError(conn
, result
);
3215 static void handleSSLKeyType(Connection
*conn
, value option
)
3218 CURLcode result
= CURLE_OK
;
3220 Store_field(conn
->ocamlValues
, OcamlSSLKeyType
, option
);
3222 if (conn
->sslKeyType
!= NULL
)
3223 free(conn
->sslKeyType
);
3225 conn
->sslKeyType
= strdup(String_val(option
));
3227 result
= curl_easy_setopt(conn
->connection
,
3231 if (result
!= CURLE_OK
)
3232 raiseError(conn
, result
);
3237 static void handleSSLKeyPasswd(Connection
*conn
, value option
)
3240 CURLcode result
= CURLE_OK
;
3242 Store_field(conn
->ocamlValues
, OcamlSSLKeyPasswd
, option
);
3244 if (conn
->sslKeyPasswd
!= NULL
)
3245 free(conn
->sslKeyPasswd
);
3247 conn
->sslKeyPasswd
= strdup(String_val(option
));
3249 result
= curl_easy_setopt(conn
->connection
,
3250 CURLOPT_SSLKEYPASSWD
,
3251 conn
->sslKeyPasswd
);
3253 if (result
!= CURLE_OK
)
3254 raiseError(conn
, result
);
3259 static void handleSSLEngine(Connection
*conn
, value option
)
3262 CURLcode result
= CURLE_OK
;
3264 Store_field(conn
->ocamlValues
, OcamlSSLEngine
, option
);
3266 if (conn
->sslEngine
!= NULL
)
3267 free(conn
->sslEngine
);
3269 conn
->sslEngine
= strdup(String_val(option
));
3271 result
= curl_easy_setopt(conn
->connection
,
3275 if (result
!= CURLE_OK
)
3276 raiseError(conn
, result
);
3281 static void handleSSLEngineDefault(Connection
*conn
, value option
)
3284 CURLcode result
= CURLE_OK
;
3286 result
= curl_easy_setopt(conn
->connection
,
3287 CURLOPT_SSLENGINE_DEFAULT
,
3290 if (result
!= CURLE_OK
)
3291 raiseError(conn
, result
);
3296 static void handleCRLF(Connection
*conn
, value option
)
3299 CURLcode result
= CURLE_OK
;
3301 result
= curl_easy_setopt(conn
->connection
,
3305 if (result
!= CURLE_OK
)
3306 raiseError(conn
, result
);
3311 static void handleQuote(Connection
*conn
, value option
)
3314 CAMLlocal1(listIter
);
3315 CURLcode result
= CURLE_OK
;
3317 Store_field(conn
->ocamlValues
, OcamlQuote
, option
);
3319 free_curl_slist(conn
->quote
);
3324 while (!Is_long(listIter
))
3326 conn
->quote
= curl_slist_append(conn
->quote
, String_val(Field(listIter
, 0)));
3328 listIter
= Field(listIter
, 1);
3331 result
= curl_easy_setopt(conn
->connection
,
3335 if (result
!= CURLE_OK
)
3336 raiseError(conn
, result
);
3341 static void handlePostQuote(Connection
*conn
, value option
)
3344 CAMLlocal1(listIter
);
3345 CURLcode result
= CURLE_OK
;
3347 Store_field(conn
->ocamlValues
, OcamlPostQuote
, option
);
3349 free_curl_slist(conn
->postQuote
);
3350 conn
->postQuote
= NULL
;
3354 while (!Is_long(listIter
))
3356 conn
->postQuote
= curl_slist_append(conn
->postQuote
, String_val(Field(listIter
, 0)));
3358 listIter
= Field(listIter
, 1);
3361 result
= curl_easy_setopt(conn
->connection
,
3365 if (result
!= CURLE_OK
)
3366 raiseError(conn
, result
);
3371 static void handleHeaderFunction(Connection
*conn
, value option
)
3374 CURLcode result
= CURLE_OK
;
3376 if (Tag_val(option
) == Closure_tag
)
3377 Store_field(conn
->ocamlValues
, OcamlHeaderCallback
, option
);
3379 failwith("Not a proper closure");
3381 result
= curl_easy_setopt(conn
->connection
,
3382 CURLOPT_HEADERFUNCTION
,
3385 if (result
!= CURLE_OK
)
3386 raiseError(conn
, result
);
3388 result
= curl_easy_setopt(conn
->connection
,
3389 CURLOPT_WRITEHEADER
,
3392 if (result
!= CURLE_OK
)
3393 raiseError(conn
, result
);
3398 static void handleCookieFile(Connection
*conn
, value option
)
3401 CURLcode result
= CURLE_OK
;
3403 Store_field(conn
->ocamlValues
, OcamlCookieFile
, option
);
3405 if (conn
->cookieFile
!= NULL
)
3406 free(conn
->cookieFile
);
3408 conn
->cookieFile
= strdup(String_val(option
));
3410 result
= curl_easy_setopt(conn
->connection
,
3414 if (result
!= CURLE_OK
)
3415 raiseError(conn
, result
);
3420 static void handleSSLVersion(Connection
*conn
, value option
)
3423 CURLcode result
= CURLE_OK
;
3425 result
= curl_easy_setopt(conn
->connection
,
3429 if (result
!= CURLE_OK
)
3430 raiseError(conn
, result
);
3435 static void handleTimeCondition(Connection
*conn
, value option
)
3438 CURLcode result
= CURLE_OK
;
3439 int timecond
= CURL_TIMECOND_NONE
;
3441 switch (Long_val(option
))
3443 case 0: timecond
= CURL_TIMECOND_NONE
; break;
3444 case 1: timecond
= CURL_TIMECOND_IFMODSINCE
; break;
3445 case 2: timecond
= CURL_TIMECOND_IFUNMODSINCE
; break;
3446 case 3: timecond
= CURL_TIMECOND_LASTMOD
; break;
3448 failwith("Invalid TIMECOND Option");
3452 result
= curl_easy_setopt(conn
->connection
, CURLOPT_TIMECONDITION
, timecond
);
3454 if (result
!= CURLE_OK
)
3455 raiseError(conn
, result
);
3460 static void handleTimeValue(Connection
*conn
, value option
)
3463 CURLcode result
= CURLE_OK
;
3465 result
= curl_easy_setopt(conn
->connection
,
3469 if (result
!= CURLE_OK
)
3470 raiseError(conn
, result
);
3475 static void handleCustomRequest(Connection
*conn
, value option
)
3478 CURLcode result
= CURLE_OK
;
3480 Store_field(conn
->ocamlValues
, OcamlCustomRequest
, option
);
3482 if (conn
->customRequest
!= NULL
)
3483 free(conn
->customRequest
);
3485 conn
->customRequest
= strdup(String_val(option
));
3487 result
= curl_easy_setopt(conn
->connection
,
3488 CURLOPT_CUSTOMREQUEST
,
3489 conn
->customRequest
);
3491 if (result
!= CURLE_OK
)
3492 raiseError(conn
, result
);
3497 static void handleInterface(Connection
*conn
, value option
)
3500 CURLcode result
= CURLE_OK
;
3502 Store_field(conn
->ocamlValues
, OcamlInterface
, option
);
3504 if (conn
->interface_
!= NULL
)
3505 free(conn
->interface_
);
3507 conn
->interface_
= strdup(String_val(option
));
3509 result
= curl_easy_setopt(conn
->connection
,
3513 if (result
!= CURLE_OK
)
3514 raiseError(conn
, result
);
3519 static void handleKRB4Level(Connection
*conn
, value option
)
3522 CURLcode result
= CURLE_OK
;
3524 switch (Long_val(option
))
3526 case 0: /* KRB4_NONE */
3527 result
= curl_easy_setopt(conn
->connection
,
3532 case 1: /* KRB4_CLEAR */
3533 result
= curl_easy_setopt(conn
->connection
,
3538 case 2: /* KRB4_SAFE */
3539 result
= curl_easy_setopt(conn
->connection
,
3544 case 3: /* KRB4_CONFIDENTIAL */
3545 result
= curl_easy_setopt(conn
->connection
,
3550 case 4: /* KRB4_PRIVATE */
3551 result
= curl_easy_setopt(conn
->connection
,
3557 failwith("Invalid KRB4 Option");
3561 if (result
!= CURLE_OK
)
3562 raiseError(conn
, result
);
3567 static void handleProgressFunction(Connection
*conn
, value option
)
3570 CURLcode result
= CURLE_OK
;
3572 if (Tag_val(option
) == Closure_tag
)
3573 Store_field(conn
->ocamlValues
, OcamlProgressCallback
, option
);
3575 failwith("Not a proper closure");
3577 result
= curl_easy_setopt(conn
->connection
,
3578 CURLOPT_PROGRESSFUNCTION
,
3580 if (result
!= CURLE_OK
)
3581 raiseError(conn
, result
);
3583 result
= curl_easy_setopt(conn
->connection
,
3584 CURLOPT_PROGRESSDATA
,
3587 if (result
!= CURLE_OK
)
3588 raiseError(conn
, result
);
3593 static void handleSSLVerifyPeer(Connection
*conn
, value option
)
3596 CURLcode result
= CURLE_OK
;
3598 result
= curl_easy_setopt(conn
->connection
,
3599 CURLOPT_SSL_VERIFYPEER
,
3602 if (result
!= CURLE_OK
)
3603 raiseError(conn
, result
);
3608 static void handleCAInfo(Connection
*conn
, value option
)
3611 CURLcode result
= CURLE_OK
;
3613 Store_field(conn
->ocamlValues
, OcamlCAInfo
, option
);
3615 if (conn
->caInfo
!= NULL
)
3618 conn
->caInfo
= strdup(String_val(option
));
3620 result
= curl_easy_setopt(conn
->connection
,
3624 if (result
!= CURLE_OK
)
3625 raiseError(conn
, result
);
3630 static void handleCAPath(Connection
*conn
, value option
)
3633 CURLcode result
= CURLE_OK
;
3635 Store_field(conn
->ocamlValues
, OcamlCAPath
, option
);
3637 if (conn
->caPath
!= NULL
)
3640 conn
->caPath
= strdup(String_val(option
));
3642 result
= curl_easy_setopt(conn
->connection
,
3646 if (result
!= CURLE_OK
)
3647 raiseError(conn
, result
);
3652 static void handleFileTime(Connection
*conn
, value option
)
3655 CURLcode result
= CURLE_OK
;
3657 result
= curl_easy_setopt(conn
->connection
,
3661 if (result
!= CURLE_OK
)
3662 raiseError(conn
, result
);
3667 static void handleMaxRedirs(Connection
*conn
, value option
)
3670 CURLcode result
= CURLE_OK
;
3672 result
= curl_easy_setopt(conn
->connection
,
3676 if (result
!= CURLE_OK
)
3677 raiseError(conn
, result
);
3682 static void handleMaxConnects(Connection
*conn
, value option
)
3685 CURLcode result
= CURLE_OK
;
3687 result
= curl_easy_setopt(conn
->connection
,
3688 CURLOPT_MAXCONNECTS
,
3691 if (result
!= CURLE_OK
)
3692 raiseError(conn
, result
);
3697 static void handleClosePolicy(Connection
*conn
, value option
)
3700 CURLcode result
= CURLE_OK
;
3702 switch (Long_val(option
))
3704 case 0: /* CLOSEPOLICY_OLDEST */
3705 result
= curl_easy_setopt(conn
->connection
,
3706 CURLOPT_CLOSEPOLICY
,
3707 CURLCLOSEPOLICY_OLDEST
);
3710 case 1: /* CLOSEPOLICY_LEAST_RECENTLY_USED */
3711 result
= curl_easy_setopt(conn
->connection
,
3712 CURLOPT_CLOSEPOLICY
,
3713 CURLCLOSEPOLICY_LEAST_RECENTLY_USED
);
3717 failwith("Invalid CLOSEPOLICY Option");
3721 if (result
!= CURLE_OK
)
3722 raiseError(conn
, result
);
3727 static void handleFreshConnect(Connection
*conn
, value option
)
3730 CURLcode result
= CURLE_OK
;
3732 result
= curl_easy_setopt(conn
->connection
,
3733 CURLOPT_FRESH_CONNECT
,
3736 if (result
!= CURLE_OK
)
3737 raiseError(conn
, result
);
3742 static void handleForbidReuse(Connection
*conn
, value option
)
3745 CURLcode result
= CURLE_OK
;
3747 result
= curl_easy_setopt(conn
->connection
,
3748 CURLOPT_FORBID_REUSE
,
3751 if (result
!= CURLE_OK
)
3752 raiseError(conn
, result
);
3757 static void handleRandomFile(Connection
*conn
, value option
)
3760 CURLcode result
= CURLE_OK
;
3762 Store_field(conn
->ocamlValues
, OcamlRandomFile
, option
);
3764 if (conn
->randomFile
!= NULL
)
3765 free(conn
->randomFile
);
3767 conn
->randomFile
= strdup(String_val(option
));
3769 result
= curl_easy_setopt(conn
->connection
,
3770 CURLOPT_RANDOM_FILE
,
3773 if (result
!= CURLE_OK
)
3774 raiseError(conn
, result
);
3779 static void handleEGDSocket(Connection
*conn
, value option
)
3782 CURLcode result
= CURLE_OK
;
3784 Store_field(conn
->ocamlValues
, OcamlEGDSocket
, option
);
3786 if (conn
->egdSocket
!= NULL
)
3787 free(conn
->egdSocket
);
3789 conn
->egdSocket
= strdup(String_val(option
));
3791 result
= curl_easy_setopt(conn
->connection
,
3795 if (result
!= CURLE_OK
)
3796 raiseError(conn
, result
);
3801 static void handleConnectTimeout(Connection
*conn
, value option
)
3804 CURLcode result
= CURLE_OK
;
3806 result
= curl_easy_setopt(conn
->connection
,
3807 CURLOPT_CONNECTTIMEOUT
,
3810 if (result
!= CURLE_OK
)
3811 raiseError(conn
, result
);
3816 static void handleHTTPGet(Connection
*conn
, value option
)
3819 CURLcode result
= CURLE_OK
;
3821 result
= curl_easy_setopt(conn
->connection
,
3825 if (result
!= CURLE_OK
)
3826 raiseError(conn
, result
);
3831 static void handleSSLVerifyHost(Connection
*conn
, value option
)
3834 CURLcode result
= CURLE_OK
;
3836 switch (Long_val(option
))
3838 case 0: /* SSLVERIFYHOST_NONE */
3839 case 1: /* SSLVERIFYHOST_EXISTENCE */
3840 case 2: /* SSLVERIFYHOST_HOSTNAME */
3841 result
= curl_easy_setopt(conn
->connection
,
3842 CURLOPT_SSL_VERIFYHOST
,
3843 /* map EXISTENCE to HOSTNAME */
3844 Long_val(option
) == 0 ? 0 : 2);
3848 failwith("Invalid SSLVERIFYHOST Option");
3852 if (result
!= CURLE_OK
)
3853 raiseError(conn
, result
);
3858 static void handleCookieJar(Connection
*conn
, value option
)
3861 CURLcode result
= CURLE_OK
;
3863 Store_field(conn
->ocamlValues
, OcamlCookieJar
, option
);
3865 if (conn
->cookieJar
!= NULL
)
3866 free(conn
->cookieJar
);
3868 conn
->cookieJar
= strdup(String_val(option
));
3870 result
= curl_easy_setopt(conn
->connection
,
3874 if (result
!= CURLE_OK
)
3875 raiseError(conn
, result
);
3880 static void handleSSLCipherList(Connection
*conn
, value option
)
3883 CURLcode result
= CURLE_OK
;
3885 Store_field(conn
->ocamlValues
, OcamlSSLCipherList
, option
);
3887 if (conn
->sslCipherList
!= NULL
)
3888 free(conn
->sslCipherList
);
3890 conn
->sslCipherList
= strdup(String_val(option
));
3892 result
= curl_easy_setopt(conn
->connection
,
3893 CURLOPT_SSL_CIPHER_LIST
,
3894 conn
->sslCipherList
);
3896 if (result
!= CURLE_OK
)
3897 raiseError(conn
, result
);
3902 static void handleHTTPVersion(Connection
*conn
, value option
)
3905 CURLcode result
= CURLE_OK
;
3907 switch (Long_val(option
))
3909 case 0: /* HTTP_VERSION_NONE */
3910 result
= curl_easy_setopt(conn
->connection
,
3911 CURLOPT_HTTP_VERSION
,
3912 CURL_HTTP_VERSION_NONE
);
3915 case 1: /* HTTP_VERSION_1_0 */
3916 result
= curl_easy_setopt(conn
->connection
,
3917 CURLOPT_HTTP_VERSION
,
3918 CURL_HTTP_VERSION_1_0
);
3921 case 2: /* HTTP_VERSION_1_1 */
3922 result
= curl_easy_setopt(conn
->connection
,
3923 CURLOPT_HTTP_VERSION
,
3924 CURL_HTTP_VERSION_1_1
);
3928 failwith("Invalid HTTP_VERSION Option");
3932 if (result
!= CURLE_OK
)
3933 raiseError(conn
, result
);
3938 static void handleFTPUseEPSV(Connection
*conn
, value option
)
3941 CURLcode result
= CURLE_OK
;
3943 result
= curl_easy_setopt(conn
->connection
,
3944 CURLOPT_FTP_USE_EPSV
,
3947 if (result
!= CURLE_OK
)
3948 raiseError(conn
, result
);
3953 static void handleDNSCacheTimeout(Connection
*conn
, value option
)
3956 CURLcode result
= CURLE_OK
;
3958 result
= curl_easy_setopt(conn
->connection
,
3959 CURLOPT_DNS_CACHE_TIMEOUT
,
3962 if (result
!= CURLE_OK
)
3963 raiseError(conn
, result
);
3968 static void handleDNSUseGlobalCache(Connection
*conn
, value option
)
3971 CURLcode result
= CURLE_OK
;
3973 result
= curl_easy_setopt(conn
->connection
,
3974 CURLOPT_DNS_USE_GLOBAL_CACHE
,
3977 if (result
!= CURLE_OK
)
3978 raiseError(conn
, result
);
3983 static void handleDebugFunction(Connection
*conn
, value option
)
3986 CURLcode result
= CURLE_OK
;
3988 if (Tag_val(option
) == Closure_tag
)
3989 Store_field(conn
->ocamlValues
, OcamlDebugCallback
, option
);
3991 failwith("Not a proper closure");
3993 result
= curl_easy_setopt(conn
->connection
,
3994 CURLOPT_DEBUGFUNCTION
,
3996 if (result
!= CURLE_OK
)
3997 raiseError(conn
, result
);
3999 result
= curl_easy_setopt(conn
->connection
,
4003 if (result
!= CURLE_OK
)
4004 raiseError(conn
, result
);
4009 #if HAVE_DECL_CURLOPT_PRIVATE
4010 static void handlePrivate(Connection
*conn
, value option
)
4013 CURLcode result
= CURLE_OK
;
4015 Store_field(conn
->ocamlValues
, OcamlPrivate
, option
);
4017 if (conn
->private != NULL
)
4018 free(conn
->private);
4020 conn
->private = strdup(String_val(option
));
4022 result
= curl_easy_setopt(conn
->connection
,
4026 if (result
!= CURLE_OK
)
4027 raiseError(conn
, result
);
4033 #if HAVE_DECL_CURLOPT_HTTP200ALIASES
4034 static void handleHTTP200Aliases(Connection
*conn
, value option
)
4037 CAMLlocal1(listIter
);
4038 CURLcode result
= CURLE_OK
;
4040 Store_field(conn
->ocamlValues
, OcamlHTTP200Aliases
, option
);
4042 free_curl_slist(conn
->http200Aliases
);
4043 conn
->http200Aliases
= NULL
;
4047 while (!Is_long(listIter
))
4049 conn
->http200Aliases
= curl_slist_append(conn
->http200Aliases
, String_val(Field(listIter
, 0)));
4051 listIter
= Field(listIter
, 1);
4054 result
= curl_easy_setopt(conn
->connection
,
4055 CURLOPT_HTTP200ALIASES
,
4056 conn
->http200Aliases
);
4058 if (result
!= CURLE_OK
)
4059 raiseError(conn
, result
);
4065 #if HAVE_DECL_CURLOPT_UNRESTRICTED_AUTH
4066 static void handleUnrestrictedAuth(Connection
*conn
, value option
)
4069 CURLcode result
= CURLE_OK
;
4071 result
= curl_easy_setopt(conn
->connection
,
4072 CURLOPT_UNRESTRICTED_AUTH
,
4075 if (result
!= CURLE_OK
)
4076 raiseError(conn
, result
);
4082 #if HAVE_DECL_CURLOPT_FTP_USE_EPRT
4083 static void handleFTPUseEPRT(Connection
*conn
, value option
)
4086 CURLcode result
= CURLE_OK
;
4088 result
= curl_easy_setopt(conn
->connection
,
4089 CURLOPT_FTP_USE_EPRT
,
4092 if (result
!= CURLE_OK
)
4093 raiseError(conn
, result
);
4099 #if HAVE_DECL_CURLOPT_HTTPAUTH
4100 static void handleHTTPAuth(Connection
*conn
, value option
)
4103 CAMLlocal1(listIter
);
4104 CURLcode result
= CURLE_OK
;
4105 long auth
= CURLAUTH_NONE
;
4109 while (!Is_long(listIter
))
4111 switch (Long_val(Field(listIter
, 0)))
4113 case 0: /* CURLAUTH_BASIC */
4114 auth
|= CURLAUTH_BASIC
;
4117 case 1: /* CURLAUTH_DIGEST */
4118 auth
|= CURLAUTH_DIGEST
;
4121 case 2: /* CURLAUTH_GSSNEGOTIATE */
4122 auth
|= CURLAUTH_GSSNEGOTIATE
;
4125 case 3: /* CURLAUTH_NTLM */
4126 auth
|= CURLAUTH_NTLM
;
4129 case 4: /* CURLAUTH_ANY */
4130 auth
|= CURLAUTH_ANY
;
4133 case 5: /* CURLAUTH_ANYSAFE */
4134 auth
|= CURLAUTH_ANYSAFE
;
4138 failwith("Invalid HTTPAUTH Value");
4142 listIter
= Field(listIter
, 1);
4145 result
= curl_easy_setopt(conn
->connection
,
4149 if (result
!= CURLE_OK
)
4150 raiseError(conn
, result
);
4156 #if HAVE_DECL_CURLOPT_FTP_CREATE_MISSING_DIRS
4157 static void handleFTPCreateMissingDirs(Connection
*conn
, value option
)
4160 CURLcode result
= CURLE_OK
;
4162 result
= curl_easy_setopt(conn
->connection
,
4163 CURLOPT_FTP_CREATE_MISSING_DIRS
,
4166 if (result
!= CURLE_OK
)
4167 raiseError(conn
, result
);
4173 #if HAVE_DECL_CURLOPT_PROXYAUTH
4174 static void handleProxyAuth(Connection
*conn
, value option
)
4177 CAMLlocal1(listIter
);
4178 CURLcode result
= CURLE_OK
;
4179 long auth
= CURLAUTH_NONE
;
4183 while (!Is_long(listIter
))
4185 switch (Long_val(Field(listIter
, 0)))
4187 case 0: /* CURLAUTH_BASIC */
4188 auth
|= CURLAUTH_BASIC
;
4191 case 1: /* CURLAUTH_DIGEST */
4192 auth
|= CURLAUTH_DIGEST
;
4195 case 2: /* CURLAUTH_GSSNEGOTIATE */
4196 auth
|= CURLAUTH_GSSNEGOTIATE
;
4199 case 3: /* CURLAUTH_NTLM */
4200 auth
|= CURLAUTH_NTLM
;
4203 case 4: /* CURLAUTH_ANY */
4204 auth
|= CURLAUTH_ANY
;
4207 case 5: /* CURLAUTH_ANYSAFE */
4208 auth
|= CURLAUTH_ANYSAFE
;
4212 failwith("Invalid HTTPAUTH Value");
4216 listIter
= Field(listIter
, 1);
4219 result
= curl_easy_setopt(conn
->connection
,
4223 if (result
!= CURLE_OK
)
4224 raiseError(conn
, result
);
4230 #if HAVE_DECL_CURLOPT_FTP_RESPONSE_TIMEOUT
4231 static void handleFTPResponseTimeout(Connection
*conn
, value option
)
4234 CURLcode result
= CURLE_OK
;
4236 result
= curl_easy_setopt(conn
->connection
,
4237 CURLOPT_FTP_RESPONSE_TIMEOUT
,
4240 if (result
!= CURLE_OK
)
4241 raiseError(conn
, result
);
4247 #if HAVE_DECL_CURLOPT_IPRESOLVE
4248 static void handleIPResolve(Connection
*conn
, value option
)
4251 CURLcode result
= CURLE_OK
;
4253 switch (Long_val(option
))
4255 case 0: /* CURL_IPRESOLVE_WHATEVER */
4256 result
= curl_easy_setopt(conn
->connection
,
4258 CURL_IPRESOLVE_WHATEVER
);
4261 case 1: /* CURL_IPRESOLVE_V4 */
4262 result
= curl_easy_setopt(conn
->connection
,
4267 case 2: /* CURL_IPRESOLVE_V6 */
4268 result
= curl_easy_setopt(conn
->connection
,
4274 failwith("Invalid IPRESOLVE Value");
4278 if (result
!= CURLE_OK
)
4279 raiseError(conn
, result
);
4285 #if HAVE_DECL_CURLOPT_MAXFILESIZE
4286 static void handleMaxFileSize(Connection
*conn
, value option
)
4289 CURLcode result
= CURLE_OK
;
4291 result
= curl_easy_setopt(conn
->connection
,
4292 CURLOPT_MAXFILESIZE
,
4295 if (result
!= CURLE_OK
)
4296 raiseError(conn
, result
);
4302 #if HAVE_DECL_CURLOPT_INFILESIZE_LARGE
4303 static void handleInFileSizeLarge(Connection
*conn
, value option
)
4306 CURLcode result
= CURLE_OK
;
4308 result
= curl_easy_setopt(conn
->connection
,
4309 CURLOPT_INFILESIZE_LARGE
,
4312 if (result
!= CURLE_OK
)
4313 raiseError(conn
, result
);
4319 #if HAVE_DECL_CURLOPT_RESUME_FROM_LARGE
4320 static void handleResumeFromLarge(Connection
*conn
, value option
)
4323 CURLcode result
= CURLE_OK
;
4325 result
= curl_easy_setopt(conn
->connection
,
4326 CURLOPT_RESUME_FROM_LARGE
,
4329 if (result
!= CURLE_OK
)
4330 raiseError(conn
, result
);
4336 #if HAVE_DECL_CURLOPT_MAXFILESIZE_LARGE
4337 static void handleMaxFileSizeLarge(Connection
*conn
, value option
)
4340 CURLcode result
= CURLE_OK
;
4342 result
= curl_easy_setopt(conn
->connection
,
4343 CURLOPT_MAXFILESIZE_LARGE
,
4346 if (result
!= CURLE_OK
)
4347 raiseError(conn
, result
);
4353 #if HAVE_DECL_CURLOPT_NETRC_FILE
4354 static void handleNETRCFile(Connection
*conn
, value option
)
4357 CURLcode result
= CURLE_OK
;
4359 Store_field(conn
->ocamlValues
, OcamlNETRCFile
, option
);
4361 if (conn
->netrcFile
!= NULL
)
4362 free(conn
->netrcFile
);
4364 conn
->netrcFile
= strdup(String_val(option
));
4366 result
= curl_easy_setopt(conn
->connection
,
4370 if (result
!= CURLE_OK
)
4371 raiseError(conn
, result
);
4377 #if HAVE_DECL_CURLOPT_FTP_SSL
4378 static void handleFTPSSL(Connection
*conn
, value option
)
4381 CURLcode result
= CURLE_OK
;
4383 switch (Long_val(option
))
4385 case 0: /* CURLFTPSSL_NONE */
4386 result
= curl_easy_setopt(conn
->connection
,
4391 case 1: /* CURLFTPSSL_TRY */
4392 result
= curl_easy_setopt(conn
->connection
,
4397 case 2: /* CURLFTPSSL_CONTROL */
4398 result
= curl_easy_setopt(conn
->connection
,
4400 CURLFTPSSL_CONTROL
);
4403 case 3: /* CURLFTPSSL_ALL */
4404 result
= curl_easy_setopt(conn
->connection
,
4410 failwith("Invalid FTP_SSL Value");
4414 if (result
!= CURLE_OK
)
4415 raiseError(conn
, result
);
4421 #if HAVE_DECL_CURLOPT_POSTFIELDSIZE_LARGE
4422 static void handlePostFieldSizeLarge(Connection
*conn
, value option
)
4425 CURLcode result
= CURLE_OK
;
4427 result
= curl_easy_setopt(conn
->connection
,
4428 CURLOPT_POSTFIELDSIZE_LARGE
,
4431 if (result
!= CURLE_OK
)
4432 raiseError(conn
, result
);
4438 #if HAVE_DECL_CURLOPT_TCP_NODELAY
4439 static void handleTCPNoDelay(Connection
*conn
, value option
)
4442 CURLcode result
= CURLE_OK
;
4444 result
= curl_easy_setopt(conn
->connection
,
4445 CURLOPT_TCP_NODELAY
,
4448 if (result
!= CURLE_OK
)
4449 raiseError(conn
, result
);
4455 #if HAVE_DECL_CURLOPT_FTPSSLAUTH
4456 static void handleFTPSSLAuth(Connection
*conn
, value option
)
4459 CURLcode result
= CURLE_OK
;
4461 switch (Long_val(option
))
4463 case 0: /* CURLFTPAUTH_DEFAULT */
4464 result
= curl_easy_setopt(conn
->connection
,
4466 CURLFTPAUTH_DEFAULT
);
4469 case 1: /* CURLFTPAUTH_SSL */
4470 result
= curl_easy_setopt(conn
->connection
,
4475 case 2: /* CURLFTPAUTH_TLS */
4476 result
= curl_easy_setopt(conn
->connection
,
4482 failwith("Invalid FTPSSLAUTH value");
4486 if (result
!= CURLE_OK
)
4487 raiseError(conn
, result
);
4493 #if HAVE_DECL_CURLOPT_IOCTLFUNCTION
4494 static void handleIOCTLFunction(Connection
*conn
, value option
)
4497 CURLcode result
= CURLE_OK
;
4499 if (Tag_val(option
) == Closure_tag
)
4500 Store_field(conn
->ocamlValues
, OcamlIOCTLCallback
, option
);
4502 failwith("Not a proper closure");
4504 result
= curl_easy_setopt(conn
->connection
,
4505 CURLOPT_IOCTLFUNCTION
,
4507 if (result
!= CURLE_OK
)
4508 raiseError(conn
, result
);
4510 result
= curl_easy_setopt(conn
->connection
,
4514 if (result
!= CURLE_OK
)
4515 raiseError(conn
, result
);
4521 #if HAVE_DECL_CURLOPT_FTP_ACCOUNT
4522 static void handleFTPAccount(Connection
*conn
, value option
)
4525 CURLcode result
= CURLE_OK
;
4527 Store_field(conn
->ocamlValues
, OcamlFTPAccount
, option
);
4529 if (conn
->ftpaccount
!= NULL
)
4530 free(conn
->ftpaccount
);
4532 conn
->ftpaccount
= strdup(String_val(option
));
4534 result
= curl_easy_setopt(conn
->connection
,
4535 CURLOPT_FTP_ACCOUNT
,
4538 if (result
!= CURLE_OK
)
4539 raiseError(conn
, result
);
4545 #if HAVE_DECL_CURLOPT_COOKIELIST
4546 static void handleCookieList(Connection
*conn
, value option
)
4549 CURLcode result
= CURLE_OK
;
4551 Store_field(conn
->ocamlValues
, OcamlCookieList
, option
);
4553 if (conn
->cookielist
!= NULL
)
4554 free(conn
->cookielist
);
4556 conn
->cookielist
= strdup(String_val(option
));
4558 result
= curl_easy_setopt(conn
->connection
,
4562 if (result
!= CURLE_OK
)
4563 raiseError(conn
, result
);
4569 #if HAVE_DECL_CURLOPT_IGNORE_CONTENT_LENGTH
4570 static void handleIgnoreContentLength(Connection
*conn
, value option
)
4573 CURLcode result
= CURLE_OK
;
4575 result
= curl_easy_setopt(conn
->connection
,
4576 CURLOPT_IGNORE_CONTENT_LENGTH
,
4579 if (result
!= CURLE_OK
)
4580 raiseError(conn
, result
);
4586 #if HAVE_DECL_CURLOPT_FTP_SKIP_PASV_IP
4587 static void handleFTPSkipPASVIP(Connection
*conn
, value option
)
4590 CURLcode result
= CURLE_OK
;
4592 result
= curl_easy_setopt(conn
->connection
,
4593 CURLOPT_FTP_SKIP_PASV_IP
,
4596 if (result
!= CURLE_OK
)
4597 raiseError(conn
, result
);
4603 #if HAVE_DECL_CURLOPT_FTP_FILEMETHOD
4604 static void handleFTPFileMethod(Connection
*conn
, value option
)
4607 CURLcode result
= CURLE_OK
;
4609 switch (Long_val(option
))
4611 case 0: /* CURLFTPMETHOD_DEFAULT */
4612 result
= curl_easy_setopt(conn
->connection
,
4613 CURLOPT_FTP_FILEMETHOD
,
4614 CURLFTPMETHOD_DEFAULT
);
4617 case 1: /* CURLFTMETHOD_MULTICWD */
4618 result
= curl_easy_setopt(conn
->connection
,
4619 CURLOPT_FTP_FILEMETHOD
,
4620 CURLFTPMETHOD_MULTICWD
);
4623 case 2: /* CURLFTPMETHOD_NOCWD */
4624 result
= curl_easy_setopt(conn
->connection
,
4625 CURLOPT_FTP_FILEMETHOD
,
4626 CURLFTPMETHOD_NOCWD
);
4629 case 3: /* CURLFTPMETHOD_SINGLECWD */
4630 result
= curl_easy_setopt(conn
->connection
,
4631 CURLOPT_FTP_FILEMETHOD
,
4632 CURLFTPMETHOD_SINGLECWD
);
4635 failwith("Invalid FTP_FILEMETHOD value");
4639 if (result
!= CURLE_OK
)
4640 raiseError(conn
, result
);
4646 #if HAVE_DECL_CURLOPT_LOCALPORT
4647 static void handleLocalPort(Connection
*conn
, value option
)
4650 CURLcode result
= CURLE_OK
;
4652 result
= curl_easy_setopt(conn
->connection
,
4656 if (result
!= CURLE_OK
)
4657 raiseError(conn
, result
);
4663 #if HAVE_DECL_CURLOPT_LOCALPORTRANGE
4664 static void handleLocalPortRange(Connection
*conn
, value option
)
4667 CURLcode result
= CURLE_OK
;
4669 result
= curl_easy_setopt(conn
->connection
,
4670 CURLOPT_LOCALPORTRANGE
,
4673 if (result
!= CURLE_OK
)
4674 raiseError(conn
, result
);
4680 #if HAVE_DECL_CURLOPT_CONNECT_ONLY
4681 static void handleConnectOnly(Connection
*conn
, value option
)
4684 CURLcode result
= CURLE_OK
;
4686 result
= curl_easy_setopt(conn
->connection
,
4687 CURLOPT_CONNECT_ONLY
,
4690 if (result
!= CURLE_OK
)
4691 raiseError(conn
, result
);
4697 #if HAVE_DECL_CURLOPT_MAX_SEND_SPEED_LARGE
4698 static void handleMaxSendSpeedLarge(Connection
*conn
, value option
)
4701 CURLcode result
= CURLE_OK
;
4703 result
= curl_easy_setopt(conn
->connection
,
4704 CURLOPT_MAX_SEND_SPEED_LARGE
,
4707 if (result
!= CURLE_OK
)
4708 raiseError(conn
, result
);
4714 #if HAVE_DECL_CURLOPT_MAX_RECV_SPEED_LARGE
4715 static void handleMaxRecvSpeedLarge(Connection
*conn
, value option
)
4718 CURLcode result
= CURLE_OK
;
4720 result
= curl_easy_setopt(conn
->connection
,
4721 CURLOPT_MAX_RECV_SPEED_LARGE
,
4724 if (result
!= CURLE_OK
)
4725 raiseError(conn
, result
);
4731 #if HAVE_DECL_CURLOPT_FTP_ALTERNATIVE_TO_USER
4732 static void handleFTPAlternativeToUser(Connection
*conn
, value option
)
4735 CURLcode result
= CURLE_OK
;
4737 Store_field(conn
->ocamlValues
, OcamlFTPAlternativeToUser
, option
);
4739 if (conn
->ftpAlternativeToUser
!= NULL
)
4740 free(conn
->ftpAlternativeToUser
);
4742 conn
->ftpAlternativeToUser
= strdup(String_val(option
));
4744 result
= curl_easy_setopt(conn
->connection
,
4745 CURLOPT_FTP_ALTERNATIVE_TO_USER
,
4746 conn
->ftpAlternativeToUser
);
4748 if (result
!= CURLE_OK
)
4749 raiseError(conn
, result
);
4755 #if HAVE_DECL_CURLOPT_SSL_SESSIONID_CACHE
4756 static void handleSSLSessionIdCache(Connection
*conn
, value option
)
4759 CURLcode result
= CURLE_OK
;
4761 result
= curl_easy_setopt(conn
->connection
,
4762 CURLOPT_SSL_SESSIONID_CACHE
,
4765 if (result
!= CURLE_OK
)
4766 raiseError(conn
, result
);
4772 #if HAVE_DECL_CURLOPT_SSH_AUTH_TYPES
4773 static void handleSSHAuthTypes(Connection
*conn
, value option
)
4776 CAMLlocal1(listIter
);
4777 CURLcode result
= CURLE_OK
;
4778 long authTypes
= CURLSSH_AUTH_NONE
;
4782 while (!Is_long(listIter
))
4784 switch (Long_val(Field(listIter
, 0)))
4786 case 0: /* CURLSSH_AUTH_ANY */
4787 authTypes
|= CURLSSH_AUTH_ANY
;
4790 case 1: /* CURLSSH_AUTH_PUBLICKEY */
4791 authTypes
|= CURLSSH_AUTH_PUBLICKEY
;
4794 case 2: /* CURLSSH_AUTH_PASSWORD */
4795 authTypes
|= CURLSSH_AUTH_PASSWORD
;
4798 case 3: /* CURLSSH_AUTH_HOST */
4799 authTypes
|= CURLSSH_AUTH_HOST
;
4802 case 4: /* CURLSSH_AUTH_KEYBOARD */
4803 authTypes
|= CURLSSH_AUTH_KEYBOARD
;
4807 failwith("Invalid CURLSSH_AUTH_TYPES Value");
4811 listIter
= Field(listIter
, 1);
4814 result
= curl_easy_setopt(conn
->connection
,
4815 CURLOPT_SSH_AUTH_TYPES
,
4818 if (result
!= CURLE_OK
)
4819 raiseError(conn
, result
);
4825 #if HAVE_DECL_CURLOPT_SSH_PUBLIC_KEYFILE
4826 static void handleSSHPublicKeyFile(Connection
*conn
, value option
)
4829 CURLcode result
= CURLE_OK
;
4831 Store_field(conn
->ocamlValues
, OcamlSSHPublicKeyFile
, option
);
4833 if (conn
->sshPublicKeyFile
!= NULL
)
4834 free(conn
->sshPublicKeyFile
);
4836 conn
->sshPublicKeyFile
= strdup(String_val(option
));
4838 result
= curl_easy_setopt(conn
->connection
,
4839 CURLOPT_SSH_PUBLIC_KEYFILE
,
4840 conn
->sshPublicKeyFile
);
4842 if (result
!= CURLE_OK
)
4843 raiseError(conn
, result
);
4849 #if HAVE_DECL_CURLOPT_SSH_PRIVATE_KEYFILE
4850 static void handleSSHPrivateKeyFile(Connection
*conn
, value option
)
4853 CURLcode result
= CURLE_OK
;
4855 Store_field(conn
->ocamlValues
, OcamlSSHPrivateKeyFile
, option
);
4857 if (conn
->sshPrivateKeyFile
!= NULL
)
4858 free(conn
->sshPrivateKeyFile
);
4860 conn
->sshPrivateKeyFile
= strdup(String_val(option
));
4862 result
= curl_easy_setopt(conn
->connection
,
4863 CURLOPT_SSH_PRIVATE_KEYFILE
,
4864 conn
->sshPrivateKeyFile
);
4866 if (result
!= CURLE_OK
)
4867 raiseError(conn
, result
);
4873 #if HAVE_DECL_CURLOPT_FTP_SSL_CCC
4874 static void handleFTPSSLCCC(Connection
*conn
, value option
)
4877 CURLcode result
= CURLE_OK
;
4879 switch (Long_val(option
))
4881 case 0: /* CURLFTPSSL_CCC_NONE */
4882 result
= curl_easy_setopt(conn
->connection
,
4883 CURLOPT_FTP_SSL_CCC
,
4884 CURLFTPSSL_CCC_NONE
);
4887 case 1: /* CURLFTPSSL_CCC_PASSIVE */
4888 result
= curl_easy_setopt(conn
->connection
,
4889 CURLOPT_FTP_SSL_CCC
,
4890 CURLFTPSSL_CCC_PASSIVE
);
4893 case 2: /* CURLFTPSSL_CCC_ACTIVE */
4894 result
= curl_easy_setopt(conn
->connection
,
4895 CURLOPT_FTP_SSL_CCC
,
4896 CURLFTPSSL_CCC_ACTIVE
);
4900 failwith("Invalid FTPSSL_CCC value");
4904 if (result
!= CURLE_OK
)
4905 raiseError(conn
, result
);
4911 #if HAVE_DECL_CURLOPT_TIMEOUT_MS
4912 static void handleTimeoutMS(Connection
*conn
, value option
)
4915 CURLcode result
= CURLE_OK
;
4917 result
= curl_easy_setopt(conn
->connection
,
4921 if (result
!= CURLE_OK
)
4922 raiseError(conn
, result
);
4928 #if HAVE_DECL_CURLOPT_CONNECTTIMEOUT_MS
4929 static void handleConnectTimeoutMS(Connection
*conn
, value option
)
4932 CURLcode result
= CURLE_OK
;
4934 result
= curl_easy_setopt(conn
->connection
,
4935 CURLOPT_CONNECTTIMEOUT_MS
,
4938 if (result
!= CURLE_OK
)
4939 raiseError(conn
, result
);
4945 #if HAVE_DECL_CURLOPT_HTTP_TRANSFER_DECODING
4946 static void handleHTTPTransferDecoding(Connection
*conn
, value option
)
4949 CURLcode result
= CURLE_OK
;
4951 result
= curl_easy_setopt(conn
->connection
,
4952 CURLOPT_HTTP_TRANSFER_DECODING
,
4955 if (result
!= CURLE_OK
)
4956 raiseError(conn
, result
);
4962 #if HAVE_DECL_CURLOPT_HTTP_CONTENT_DECODING
4963 static void handleHTTPContentDecoding(Connection
*conn
, value option
)
4966 CURLcode result
= CURLE_OK
;
4968 result
= curl_easy_setopt(conn
->connection
,
4969 CURLOPT_HTTP_CONTENT_DECODING
,
4972 if (result
!= CURLE_OK
)
4973 raiseError(conn
, result
);
4979 #if HAVE_DECL_CURLOPT_NEW_FILE_PERMS
4980 static void handleNewFilePerms(Connection
*conn
, value option
)
4983 CURLcode result
= CURLE_OK
;
4985 result
= curl_easy_setopt(conn
->connection
,
4986 CURLOPT_NEW_FILE_PERMS
,
4989 if (result
!= CURLE_OK
)
4990 raiseError(conn
, result
);
4996 #if HAVE_DECL_CURLOPT_NEW_DIRECTORY_PERMS
4997 static void handleNewDirectoryPerms(Connection
*conn
, value option
)
5000 CURLcode result
= CURLE_OK
;
5002 result
= curl_easy_setopt(conn
->connection
,
5003 CURLOPT_NEW_DIRECTORY_PERMS
,
5006 if (result
!= CURLE_OK
)
5007 raiseError(conn
, result
);
5013 #if HAVE_DECL_CURLOPT_POST301
5014 static void handlePost301(Connection
*conn
, value option
)
5017 CURLcode result
= CURLE_OK
;
5019 result
= curl_easy_setopt(conn
->connection
,
5023 if (result
!= CURLE_OK
)
5024 raiseError(conn
, result
);
5030 #if HAVE_DECL_CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
5031 static void handleSSHHostPublicKeyMD5(Connection
*conn
, value option
)
5034 CURLcode result
= CURLE_OK
;
5036 Store_field(conn
->ocamlValues
, OcamlSSHHostPublicKeyMD5
, option
);
5038 if (conn
->sshHostPublicKeyMD5
!= NULL
)
5039 free(conn
->sshHostPublicKeyMD5
);
5041 conn
->sshHostPublicKeyMD5
= strdup(String_val(option
));
5043 result
= curl_easy_setopt(conn
->connection
,
5044 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
,
5045 conn
->sshHostPublicKeyMD5
);
5047 if (result
!= CURLE_OK
)
5048 raiseError(conn
, result
);
5054 #if HAVE_DECL_CURLOPT_COPYPOSTFIELDS
5055 static void handleCopyPostFields(Connection
*conn
, value option
)
5058 CURLcode result
= CURLE_OK
;
5060 Store_field(conn
->ocamlValues
, OcamlCopyPostFields
, option
);
5062 if (conn
->copyPostFields
!= NULL
)
5063 free(conn
->copyPostFields
);
5065 conn
->copyPostFields
= strdup(String_val(option
));
5067 result
= curl_easy_setopt(conn
->connection
,
5068 CURLOPT_COPYPOSTFIELDS
,
5069 conn
->copyPostFields
);
5071 if (result
!= CURLE_OK
)
5072 raiseError(conn
, result
);
5078 #if HAVE_DECL_CURLOPT_PROXY_TRANSFER_MODE
5079 static void handleProxyTransferMode(Connection
*conn
, value option
)
5082 CURLcode result
= CURLE_OK
;
5084 result
= curl_easy_setopt(conn
->connection
,
5085 CURLOPT_PROXY_TRANSFER_MODE
,
5088 if (result
!= CURLE_OK
)
5089 raiseError(conn
, result
);
5095 #if HAVE_DECL_CURLOPT_SEEKFUNCTION
5096 static void handleSeekFunction(Connection
*conn
, value option
)
5099 CURLcode result
= CURLE_OK
;
5101 if (Tag_val(option
) == Closure_tag
)
5102 Store_field(conn
->ocamlValues
, OcamlSeekFunctionCallback
, option
);
5104 failwith("Not a proper closure");
5106 result
= curl_easy_setopt(conn
->connection
,
5107 CURLOPT_SEEKFUNCTION
,
5110 if (result
!= CURLE_OK
)
5111 raiseError(conn
, result
);
5113 result
= curl_easy_setopt(conn
->connection
,
5117 if (result
!= CURLE_OK
)
5118 raiseError(conn
, result
);
5124 #if HAVE_DECL_CURLOPT_AUTOREFERER
5125 static void handleAutoReferer(Connection
*conn
, value option
)
5128 CURLcode result
= curl_easy_setopt(conn
->connection
,
5129 CURLOPT_AUTOREFERER
,
5132 if (result
!= CURLE_OK
)
5133 raiseError(conn
, result
);
5139 #if HAVE_DECL_CURLOPT_OPENSOCKETFUNCTION
5140 static void handleOpenSocketFunction(Connection
*conn
, value option
)
5143 CURLcode result
= CURLE_OK
;
5145 Store_field(conn
->ocamlValues
, OcamlOpenSocketFunctionCallback
, option
);
5147 result
= curl_easy_setopt(conn
->connection
,
5148 CURLOPT_OPENSOCKETDATA
,
5151 if (result
!= CURLE_OK
)
5152 raiseError(conn
, result
);
5154 result
= curl_easy_setopt(conn
->connection
,
5155 CURLOPT_OPENSOCKETFUNCTION
,
5156 openSocketFunction
);
5158 if (result
!= CURLE_OK
)
5159 raiseError(conn
, result
);
5165 #if HAVE_DECL_CURLOPT_PROXYTYPE
5166 static void handleProxyType(Connection
*conn
, value option
)
5169 CURLcode result
= CURLE_OK
;
5172 switch (Long_val(option
))
5174 case 0: proxy_type
= CURLPROXY_HTTP
; break;
5175 case 1: proxy_type
= CURLPROXY_HTTP_1_0
; break;
5176 case 2: proxy_type
= CURLPROXY_SOCKS4
; break;
5177 case 3: proxy_type
= CURLPROXY_SOCKS5
; break;
5178 case 4: proxy_type
= CURLPROXY_SOCKS4A
; break;
5179 case 5: proxy_type
= CURLPROXY_SOCKS5_HOSTNAME
; break;
5181 failwith("Invalid curl proxy type");
5184 result
= curl_easy_setopt(conn
->connection
,
5188 if (result
!= CURLE_OK
)
5189 raiseError(conn
, result
);
5195 #if HAVE_DECL_CURLOPT_PROTOCOLS || HAVE_DECL_CURLOPT_REDIR_PROTOCOLS
5200 CURLPROTO_HTTP
, CURLPROTO_HTTPS
, CURLPROTO_FTP
, CURLPROTO_FTPS
, CURLPROTO_SCP
, CURLPROTO_SFTP
,
5201 CURLPROTO_TELNET
, CURLPROTO_LDAP
, CURLPROTO_LDAPS
, CURLPROTO_DICT
, CURLPROTO_FILE
, CURLPROTO_TFTP
,
5202 /* factor out with autoconf? */
5203 #if defined(CURLPROTO_IMAP)
5208 #if defined(CURLPROTO_IMAPS)
5213 #if defined(CURLPROTO_POP3)
5218 #if defined(CURLPROTO_POP3S)
5223 #if defined(CURLPROTO_SMTP)
5228 #if defined(CURLPROTO_SMTPS)
5233 #if defined(CURLPROTO_RTSP)
5238 #if defined(CURLPROTO_RTMP)
5243 #if defined(CURLPROTO_RTMPT)
5248 #if defined(CURLPROTO_RTMPE)
5253 #if defined(CURLPROTO_RTMPTE)
5258 #if defined(CURLPROTO_RTMPS)
5263 #if defined(CURLPROTO_RTMPTS)
5268 #if defined(CURLPROTO_GOPHER)
5275 static void handleProtocolsOption(CURLoption curlopt
, Connection
*conn
, value option
)
5278 CURLcode result
= CURLE_OK
;
5282 while (Val_emptylist
!= option
)
5284 index
= Int_val(Field(option
, 0));
5285 if ((index
< 0) || ((size_t)index
>= sizeof(protoMap
) / sizeof(protoMap
[0])))
5286 failwith("Invalid curl protocol");
5288 protocols
= protocols
| protoMap
[index
];
5290 option
= Field(option
, 1);
5293 result
= curl_easy_setopt(conn
->connection
,
5297 if (result
!= CURLE_OK
)
5298 raiseError(conn
, result
);
5304 #if HAVE_DECL_CURLOPT_PROTOCOLS
5305 static void handleProtocols(Connection
*conn
, value option
)
5307 handleProtocolsOption(CURLOPT_PROTOCOLS
, conn
, option
);
5311 #if HAVE_DECL_CURLOPT_PROTOCOLS
5312 static void handleRedirProtocols(Connection
*conn
, value option
)
5314 handleProtocolsOption(CURLOPT_REDIR_PROTOCOLS
, conn
, option
);
5318 #if HAVE_DECL_CURLOPT_RESOLVE
5319 static void handleResolve(Connection
*conn
, value option
)
5324 CURLcode result
= CURLE_OK
;
5326 free_curl_slist(conn
->resolve
);
5327 conn
->resolve
= NULL
;
5331 while (head
!= Val_emptylist
)
5333 conn
->resolve
= curl_slist_append(conn
->resolve
, String_val(Field(head
,0)));
5334 head
= Field(head
, 1);
5337 result
= curl_easy_setopt(conn
->connection
,
5341 if (result
!= CURLE_OK
)
5342 raiseError(conn
, result
);
5348 #if HAVE_DECL_CURLOPT_DNS_SERVERS
5349 static void handleDnsServers(Connection
*conn
, value option
)
5353 Store_field(conn
->ocamlValues
, OcamlDNSServers
, option
);
5355 CURLcode result
= CURLE_OK
;
5356 free_if(conn
->dns_servers
);
5358 conn
->dns_servers
= strdup(String_val(option
));
5360 result
= curl_easy_setopt(conn
->connection
,
5361 CURLOPT_DNS_SERVERS
,
5364 if (result
!= CURLE_OK
)
5365 raiseError(conn
, result
);
5371 #if HAVE_DECL_CURLOPT_MAIL_FROM
5372 static void handleMailFrom(Connection
*conn
, value option
)
5375 CURLcode result
= CURLE_OK
;
5377 Store_field(conn
->ocamlValues
, OcamlMailFrom
, option
);
5379 if (conn
->mailFrom
!= NULL
)
5380 free(conn
->mailFrom
);
5382 conn
->mailFrom
= strdup(String_val(option
));
5384 result
= curl_easy_setopt(conn
->connection
,
5388 if (result
!= CURLE_OK
)
5389 raiseError(conn
, result
);
5395 #if HAVE_DECL_CURLOPT_MAIL_RCPT
5396 static void handleMailRcpt(Connection
*conn
, value option
)
5399 CAMLlocal1(listIter
);
5400 CURLcode result
= CURLE_OK
;
5402 Store_field(conn
->ocamlValues
, OcamlMailRcpt
, option
);
5404 free_curl_slist(conn
->mailRcpt
);
5405 conn
->mailRcpt
= NULL
;
5409 while (Val_emptylist
!= listIter
)
5411 conn
->mailRcpt
= curl_slist_append(conn
->mailRcpt
, String_val(Field(listIter
, 0)));
5413 listIter
= Field(listIter
, 1);
5416 result
= curl_easy_setopt(conn
->connection
,
5420 if (result
!= CURLE_OK
)
5421 raiseError(conn
, result
);
5428 ** curl_easy_setopt helper function
5431 CAMLprim value
helper_curl_easy_setopt(value conn
, value option
)
5433 CAMLparam2(conn
, option
);
5435 Connection
*connection
= Connection_val(conn
);
5436 CURLOptionMapping
* thisOption
= NULL
;
5438 checkConnection(connection
);
5440 if (!Is_block(option
))
5441 failwith("Not a block");
5443 if (Wosize_val(option
) < 1)
5444 failwith("Insufficient data in block");
5446 data
= Field(option
, 0);
5448 if (Tag_val(option
) < sizeof(implementedOptionMap
)/sizeof(CURLOptionMapping
))
5450 thisOption
= &implementedOptionMap
[Tag_val(option
)];
5451 if (thisOption
->optionHandler
)
5452 thisOption
->optionHandler(connection
, data
);
5454 failwith(thisOption
->name
);
5457 failwith("Invalid CURLOPT Option");
5459 CAMLreturn(Val_unit
);
5463 ** curl_easy_perform helper function
5466 CAMLprim value
helper_curl_easy_perform(value conn
)
5469 CURLcode result
= CURLE_OK
;
5470 Connection
*connection
= Connection_val(conn
);
5472 checkConnection(connection
);
5474 enter_blocking_section();
5475 result
= curl_easy_perform(connection
->connection
);
5476 leave_blocking_section();
5478 if (result
!= CURLE_OK
)
5479 raiseError(connection
, result
);
5481 CAMLreturn(Val_unit
);
5485 ** curl_easy_cleanup helper function
5488 CAMLprim value
helper_curl_easy_cleanup(value conn
)
5491 Connection
*connection
= Connection_val(conn
);
5493 checkConnection(connection
);
5495 removeConnection(connection
, 0);
5497 CAMLreturn(Val_unit
);
5501 ** curl_easy_duphandle helper function
5504 CAMLprim value
helper_curl_easy_duphandle(value conn
)
5508 Connection
*connection
= Connection_val(conn
);
5510 checkConnection(connection
);
5512 result
= caml_curl_alloc(duplicateConnection(connection
));
5518 ** curl_easy_getinfo helper function
5521 enum GetInfoResultType
{
5522 StringValue
, LongValue
, DoubleValue
, StringListValue
5525 value
convertStringList(struct curl_slist
*slist
)
5528 CAMLlocal3(result
, current
, next
);
5529 struct curl_slist
*p
= slist
;
5531 result
= Val_int(0);
5532 current
= Val_int(0);
5537 next
= alloc_tuple(2);
5538 Store_field(next
, 0, copy_string(p
->data
));
5539 Store_field(next
, 1, Val_int(0));
5541 if (result
== Val_int(0))
5544 if (current
!= Val_int(0))
5545 Store_field(current
, 1, next
);
5552 curl_slist_free_all(slist
);
5557 CAMLprim value
helper_curl_easy_getinfo(value conn
, value option
)
5559 CAMLparam2(conn
, option
);
5561 CURLcode curlResult
;
5562 Connection
*connection
= Connection_val(conn
);
5563 enum GetInfoResultType resultType
;
5564 char *strValue
= NULL
;
5567 struct curl_slist
*stringListValue
= NULL
;
5569 checkConnection(connection
);
5571 switch(Long_val(option
))
5573 #if HAVE_DECL_CURLINFO_EFFECTIVE_URL
5574 case 0: /* CURLINFO_EFFECTIVE_URL */
5575 resultType
= StringValue
;
5577 curlResult
= curl_easy_getinfo(connection
->connection
,
5578 CURLINFO_EFFECTIVE_URL
,
5582 #pragma message("libcurl does not provide CURLINFO_EFFECTIVE_URL")
5585 #if HAVE_DECL_CURLINFO_RESPONSE_CODE || HAVE_DECL_CURLINFO_HTTP_CODE
5586 case 1: /* CURLINFO_HTTP_CODE */
5587 case 2: /* CURLINFO_RESPONSE_CODE */
5588 #if HAVE_DECL_CURLINFO_RESPONSE_CODE
5589 resultType
= LongValue
;
5591 curlResult
= curl_easy_getinfo(connection
->connection
,
5592 CURLINFO_RESPONSE_CODE
,
5595 resultType
= LongValue
;
5597 curlResult
= curl_easy_getinfo(connection
->connection
,
5604 #if HAVE_DECL_CURLINFO_TOTAL_TIME
5605 case 3: /* CURLINFO_TOTAL_TIME */
5606 resultType
= DoubleValue
;
5608 curlResult
= curl_easy_getinfo(connection
->connection
,
5609 CURLINFO_TOTAL_TIME
,
5614 #if HAVE_DECL_CURLINFO_NAMELOOKUP_TIME
5615 case 4: /* CURLINFO_NAMELOOKUP_TIME */
5616 resultType
= DoubleValue
;
5618 curlResult
= curl_easy_getinfo(connection
->connection
,
5619 CURLINFO_NAMELOOKUP_TIME
,
5624 #if HAVE_DECL_CURLINFO_CONNECT_TIME
5625 case 5: /* CURLINFO_CONNECT_TIME */
5626 resultType
= DoubleValue
;
5628 curlResult
= curl_easy_getinfo(connection
->connection
,
5629 CURLINFO_CONNECT_TIME
,
5634 #if HAVE_DECL_CURLINFO_PRETRANSFER_TIME
5635 case 6: /* CURLINFO_PRETRANSFER_TIME */
5636 resultType
= DoubleValue
;
5638 curlResult
= curl_easy_getinfo(connection
->connection
,
5639 CURLINFO_PRETRANSFER_TIME
,
5644 #if HAVE_DECL_CURLINFO_SIZE_UPLOAD
5645 case 7: /* CURLINFO_SIZE_UPLOAD */
5646 resultType
= DoubleValue
;
5648 curlResult
= curl_easy_getinfo(connection
->connection
,
5649 CURLINFO_SIZE_UPLOAD
,
5654 #if HAVE_DECL_CURLINFO_SIZE_DOWNLOAD
5655 case 8: /* CURLINFO_SIZE_DOWNLOAD */
5656 resultType
= DoubleValue
;
5658 curlResult
= curl_easy_getinfo(connection
->connection
,
5659 CURLINFO_SIZE_DOWNLOAD
,
5664 #if HAVE_DECL_CURLINFO_SPEED_DOWNLOAD
5665 case 9: /* CURLINFO_SPEED_DOWNLOAD */
5666 resultType
= DoubleValue
;
5668 curlResult
= curl_easy_getinfo(connection
->connection
,
5669 CURLINFO_SPEED_DOWNLOAD
,
5674 #if HAVE_DECL_CURLINFO_SPEED_UPLOAD
5675 case 10: /* CURLINFO_SPEED_UPLOAD */
5676 resultType
= DoubleValue
;
5678 curlResult
= curl_easy_getinfo(connection
->connection
,
5679 CURLINFO_SPEED_UPLOAD
,
5685 #if HAVE_DECL_CURLINFO_HEADER_SIZE
5686 case 11: /* CURLINFO_HEADER_SIZE */
5687 resultType
= LongValue
;
5689 curlResult
= curl_easy_getinfo(connection
->connection
,
5690 CURLINFO_HEADER_SIZE
,
5695 #if HAVE_DECL_CURLINFO_REQUEST_SIZE
5696 case 12: /* CURLINFO_REQUEST_SIZE */
5697 resultType
= LongValue
;
5699 curlResult
= curl_easy_getinfo(connection
->connection
,
5700 CURLINFO_REQUEST_SIZE
,
5705 #if HAVE_DECL_CURLINFO_SSL_VERIFYRESULT
5706 case 13: /* CURLINFO_SSL_VERIFYRESULT */
5707 resultType
= LongValue
;
5709 curlResult
= curl_easy_getinfo(connection
->connection
,
5710 CURLINFO_SSL_VERIFYRESULT
,
5715 #if HAVE_DECL_CURLINFO_FILETIME
5716 case 14: /* CURLINFO_FILETIME */
5717 resultType
= DoubleValue
;
5719 curlResult
= curl_easy_getinfo(connection
->connection
,
5723 doubleValue
= longValue
;
5727 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_DOWNLOAD
5728 case 15: /* CURLINFO_CONTENT_LENGTH_DOWNLOAD */
5729 resultType
= DoubleValue
;
5731 curlResult
= curl_easy_getinfo(connection
->connection
,
5732 CURLINFO_CONTENT_LENGTH_DOWNLOAD
,
5737 #if HAVE_DECL_CURLINFO_CONTENT_LENGTH_UPLOAD
5738 case 16: /* CURLINFO_CONTENT_LENGTH_UPLOAD */
5739 resultType
= DoubleValue
;
5741 curlResult
= curl_easy_getinfo(connection
->connection
,
5742 CURLINFO_CONTENT_LENGTH_UPLOAD
,
5747 #if HAVE_DECL_CURLINFO_STARTTRANSFER_TIME
5748 case 17: /* CURLINFO_STARTTRANSFER_TIME */
5749 resultType
= DoubleValue
;
5751 curlResult
= curl_easy_getinfo(connection
->connection
,
5752 CURLINFO_STARTTRANSFER_TIME
,
5757 #if HAVE_DECL_CURLINFO_CONTENT_TYPE
5758 case 18: /* CURLINFO_CONTENT_TYPE */
5759 resultType
= StringValue
;
5761 curlResult
= curl_easy_getinfo(connection
->connection
,
5762 CURLINFO_CONTENT_TYPE
,
5767 #if HAVE_DECL_CURLINFO_REDIRECT_TIME
5768 case 19: /* CURLINFO_REDIRECT_TIME */
5769 resultType
= DoubleValue
;
5771 curlResult
= curl_easy_getinfo(connection
->connection
,
5772 CURLINFO_REDIRECT_TIME
,
5777 #if HAVE_DECL_CURLINFO_REDIRECT_COUNT
5778 case 20: /* CURLINFO_REDIRECT_COUNT */
5779 resultType
= LongValue
;
5781 curlResult
= curl_easy_getinfo(connection
->connection
,
5782 CURLINFO_REDIRECT_COUNT
,
5787 #if HAVE_DECL_CURLINFO_PRIVATE
5788 case 21: /* CURLINFO_PRIVATE */
5789 resultType
= StringValue
;
5791 curlResult
= curl_easy_getinfo(connection
->connection
,
5797 #if HAVE_DECL_CURLINFO_HTTP_CONNECTCODE
5798 case 22: /* CURLINFO_HTTP_CONNECTCODE */
5799 resultType
= LongValue
;
5801 curlResult
= curl_easy_getinfo(connection
->connection
,
5802 CURLINFO_HTTP_CONNECTCODE
,
5807 #if HAVE_DECL_CURLINFO_HTTPAUTH_AVAIL
5808 case 23: /* CURLINFO_HTTPAUTH_AVAIL */
5809 resultType
= LongValue
;
5811 curlResult
= curl_easy_getinfo(connection
->connection
,
5812 CURLINFO_HTTPAUTH_AVAIL
,
5817 #if HAVE_DECL_CURLINFO_PROXYAUTH_AVAIL
5818 case 24: /* CURLINFO_PROXYAUTH_AVAIL */
5819 resultType
= LongValue
;
5821 curlResult
= curl_easy_getinfo(connection
->connection
,
5822 CURLINFO_PROXYAUTH_AVAIL
,
5827 #if HAVE_DECL_CURLINFO_OS_ERRNO
5828 case 25: /* CURLINFO_OS_ERRNO */
5829 resultType
= LongValue
;
5831 curlResult
= curl_easy_getinfo(connection
->connection
,
5837 #if HAVE_DECL_CURLINFO_NUM_CONNECTS
5838 case 26: /* CURLINFO_NUM_CONNECTS */
5839 resultType
= LongValue
;
5841 curlResult
= curl_easy_getinfo(connection
->connection
,
5842 CURLINFO_NUM_CONNECTS
,
5847 #if HAVE_DECL_CURLINFO_SSL_ENGINES
5848 case 27: /* CURLINFO_SSL_ENGINES */
5849 resultType
= StringListValue
;
5851 curlResult
= curl_easy_getinfo(connection
->connection
,
5852 CURLINFO_SSL_ENGINES
,
5857 #if HAVE_DECL_CURLINFO_COOKIELIST
5858 case 28: /* CURLINFO_COOKIELIST */
5859 resultType
= StringListValue
;
5861 curlResult
= curl_easy_getinfo(connection
->connection
,
5862 CURLINFO_COOKIELIST
,
5867 #if HAVE_DECL_CURLINFO_LASTSOCKET
5868 case 29: /* CURLINFO_LASTSOCKET */
5869 resultType
= LongValue
;
5871 curlResult
= curl_easy_getinfo(connection
->connection
,
5872 CURLINFO_LASTSOCKET
,
5877 #if HAVE_DECL_CURLINFO_FTP_ENTRY_PATH
5878 case 30: /* CURLINFO_FTP_ENTRY_PATH */
5879 resultType
= StringValue
;
5881 curlResult
= curl_easy_getinfo(connection
->connection
,
5882 CURLINFO_FTP_ENTRY_PATH
,
5887 #if HAVE_DECL_CURLINFO_REDIRECT_URL
5888 case 31: /* CURLINFO_REDIRECT_URL */
5889 resultType
= StringValue
;
5891 curlResult
= curl_easy_getinfo(connection
->connection
,
5892 CURLINFO_REDIRECT_URL
,
5896 #pragma message("libcurl does not provide CURLINFO_REDIRECT_URL")
5899 #if HAVE_DECL_CURLINFO_PRIMARY_IP
5900 case 32: /* CURLINFO_PRIMARY_IP */
5901 resultType
= StringValue
;
5903 curlResult
= curl_easy_getinfo(connection
->connection
,
5904 CURLINFO_PRIMARY_IP
,
5908 #pragma message("libcurl does not provide CURLINFO_PRIMARY_IP")
5911 #if HAVE_DECL_CURLINFO_LOCAL_IP
5912 case 33: /* CURLINFO_LOCAL_IP */
5913 resultType
= StringValue
;
5915 curlResult
= curl_easy_getinfo(connection
->connection
,
5920 #pragma message("libcurl does not provide CURLINFO_LOCAL_IP")
5923 #if HAVE_DECL_CURLINFO_LOCAL_PORT
5924 case 34: /* CURLINFO_LOCAL_PORT */
5925 resultType
= LongValue
;
5927 curlResult
= curl_easy_getinfo(connection
->connection
,
5928 CURLINFO_LOCAL_PORT
,
5932 #pragma message("libcurl does not provide CURLINFO_LOCAL_PORT")
5935 #if HAVE_DECL_CURLINFO_CONDITION_UNMET
5936 case 35: /* CURLINFO_CONDITION_UNMET */
5937 resultType
= LongValue
;
5939 curlResult
= curl_easy_getinfo(connection
->connection
,
5940 CURLINFO_CONDITION_UNMET
,
5944 #pragma message("libcurl does not provide CURLINFO_CONDITION_UNMET")
5948 failwith("Invalid CURLINFO Option");
5952 if (curlResult
!= CURLE_OK
)
5953 raiseError(connection
, curlResult
);
5958 result
= alloc(1, StringValue
);
5959 Store_field(result
, 0, copy_string(strValue
?strValue
:""));
5963 result
= alloc(1, LongValue
);
5964 Store_field(result
, 0, Val_long(longValue
));
5968 result
= alloc(1, DoubleValue
);
5969 Store_field(result
, 0, copy_double(doubleValue
));
5972 case StringListValue
:
5973 result
= alloc(1, StringListValue
);
5974 Store_field(result
, 0, convertStringList(stringListValue
));
5982 ** curl_escape helper function
5985 CAMLprim value
helper_curl_escape(value str
)
5991 curlResult
= curl_escape(String_val(str
), string_length(str
));
5992 result
= copy_string(curlResult
);
5999 ** curl_unescape helper function
6002 CAMLprim value
helper_curl_unescape(value str
)
6008 curlResult
= curl_unescape(String_val(str
), string_length(str
));
6009 result
= copy_string(curlResult
);
6016 ** curl_getdate helper function
6019 CAMLprim value
helper_curl_getdate(value str
, value now
)
6021 CAMLparam2(str
, now
);
6026 curlNow
= (time_t)Double_val(now
);
6027 curlResult
= curl_getdate(String_val(str
), &curlNow
);
6028 result
= copy_double((double)curlResult
);
6034 ** curl_version helper function
6037 CAMLprim value
helper_curl_version(void)
6043 str
= curl_version();
6044 result
= copy_string(str
);
6049 struct CURLVersionBitsMapping
6055 struct CURLVersionBitsMapping versionBitsMap
[] =
6057 {CURL_VERSION_IPV6
, "ipv6"},
6058 {CURL_VERSION_KERBEROS4
, "kerberos4"},
6059 {CURL_VERSION_SSL
, "ssl"},
6060 {CURL_VERSION_LIBZ
, "libz"},
6061 {CURL_VERSION_NTLM
, "ntlm"},
6062 {CURL_VERSION_GSSNEGOTIATE
, "gssnegotiate"},
6063 {CURL_VERSION_DEBUG
, "debug"},
6064 {CURL_VERSION_CURLDEBUG
, "curldebug"},
6065 {CURL_VERSION_ASYNCHDNS
, "asynchdns"},
6066 {CURL_VERSION_SPNEGO
, "spnego"},
6067 {CURL_VERSION_LARGEFILE
, "largefile"},
6068 {CURL_VERSION_IDN
, "idn"},
6069 {CURL_VERSION_SSPI
, "sspi"},
6070 {CURL_VERSION_CONV
, "conv"},
6071 #if HAVE_DECL_CURL_VERSION_TLSAUTH_SRP
6072 {CURL_VERSION_TLSAUTH_SRP
, "srp"},
6074 #if HAVE_DECL_CURL_VERSION_NTLM_WB
6075 {CURL_VERSION_NTLM_WB
, "wb"},
6079 CAMLprim value
caml_curl_version_info(value unit
)
6082 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6083 const char* const* p
= NULL
;
6086 curl_version_info_data
* data
= curl_version_info(CURLVERSION_NOW
);
6087 if (NULL
== data
) caml_failwith("curl_version_info");
6089 vlist
= Val_emptylist
;
6090 for (p
= data
->protocols
; NULL
!= *p
; p
++)
6092 vlist
= Val_cons(vlist
, caml_copy_string(*p
));
6095 vfeatures
= Val_emptylist
;
6096 for (i
= 0; i
< sizeof(versionBitsMap
)/sizeof(versionBitsMap
[0]); i
++)
6098 if (0 != (versionBitsMap
[i
].code
& data
->features
))
6099 vfeatures
= Val_cons(vfeatures
, caml_copy_string(versionBitsMap
[i
].name
));
6102 vnum
= caml_alloc_tuple(3);
6103 Store_field(vnum
,0,Val_int(0xFF & (data
->version_num
>> 16)));
6104 Store_field(vnum
,1,Val_int(0xFF & (data
->version_num
>> 8)));
6105 Store_field(vnum
,2,Val_int(0xFF & (data
->version_num
)));
6107 v
= caml_alloc_tuple(12);
6108 Store_field(v
,0,caml_copy_string(data
->version
));
6109 Store_field(v
,1,vnum
);
6110 Store_field(v
,2,caml_copy_string(data
->host
));
6111 Store_field(v
,3,vfeatures
);
6112 Store_field(v
,4,data
->ssl_version
? Val_some(caml_copy_string(data
->ssl_version
)) : Val_none
);
6113 Store_field(v
,5,data
->libz_version
? Val_some(caml_copy_string(data
->libz_version
)) : Val_none
);
6114 Store_field(v
,6,vlist
);
6115 Store_field(v
,7,caml_copy_string((data
->age
>= 1 && data
->ares
) ? data
->ares
: ""));
6116 Store_field(v
,8,Val_int((data
->age
>= 1) ? data
->ares_num
: 0));
6117 Store_field(v
,9,caml_copy_string((data
->age
>= 2 && data
->libidn
) ? data
->libidn
: ""));
6118 Store_field(v
,10,Val_int((data
->age
>= 3) ? data
->iconv_ver_num
: 0));
6119 Store_field(v
,11,caml_copy_string((data
->age
>= 3 && data
->libssh_version
) ? data
->libssh_version
: ""));
6124 CAMLprim value
caml_curl_pause(value conn
, value opts
)
6126 CAMLparam2(conn
, opts
);
6127 CAMLlocal4(v
, vlist
, vnum
, vfeatures
);
6128 Connection
*connection
= Connection_val(conn
);
6132 while (Val_emptylist
!= opts
)
6134 switch (Int_val(Field(opts
,0)))
6136 case 0: bitmask
|= CURLPAUSE_SEND
; break;
6137 case 1: bitmask
|= CURLPAUSE_RECV
; break;
6138 case 2: bitmask
|= CURLPAUSE_ALL
; break;
6139 default: caml_failwith("wrong pauseOption");
6141 opts
= Field(opts
,1);
6144 result
= curl_easy_pause(connection
->connection
,bitmask
);
6145 if (result
!= CURLE_OK
)
6146 raiseError(connection
, result
);
6148 CAMLreturn(Val_unit
);
6152 * Curl multi stack support
6154 * Exported thin wrappers for libcurl are prefixed with caml_curl_multi_.
6155 * Other exported functions are prefixed with caml_curlm_, some of them
6156 * can/should be decomposed into smaller parts.
6159 struct ml_multi_handle
6162 value values
; /* callbacks */
6167 curlmopt_socket_function
,
6168 curlmopt_timer_function
,
6170 /* last, not used */
6174 typedef struct ml_multi_handle ml_multi_handle
;
6176 #define Multi_val(v) (*(ml_multi_handle**)Data_custom_val(v))
6177 #define CURLM_val(v) (Multi_val(v)->handle)
6179 static struct custom_operations curl_multi_ops
= {
6181 custom_finalize_default
,
6182 custom_compare_default
,
6183 custom_hash_default
,
6184 custom_serialize_default
,
6185 custom_deserialize_default
,
6186 #if defined(custom_compare_ext_default)
6187 custom_compare_ext_default
,
6191 CAMLprim value
caml_curl_multi_init(value unit
)
6195 ml_multi_handle
* multi
= (ml_multi_handle
*)caml_stat_alloc(sizeof(ml_multi_handle
));
6196 CURLM
* h
= curl_multi_init();
6200 caml_stat_free(multi
);
6201 failwith("caml_curl_multi_init");
6205 multi
->values
= caml_alloc(multi_values_total
, 0);
6206 caml_register_generational_global_root(&multi
->values
);
6208 v
= caml_alloc_custom(&curl_multi_ops
, sizeof(ml_multi_handle
*), 0, 1);
6209 Multi_val(v
) = multi
;
6214 CAMLprim value
caml_curl_multi_cleanup(value handle
)
6217 ml_multi_handle
* h
= Multi_val(handle
);
6220 CAMLreturn(Val_unit
);
6222 caml_remove_generational_global_root(&h
->values
);
6224 if (CURLM_OK
!= curl_multi_cleanup(h
->handle
))
6225 failwith("caml_curl_multi_cleanup");
6227 Multi_val(handle
) = (ml_multi_handle
*)NULL
;
6229 CAMLreturn(Val_unit
);
6232 static CURL
* curlm_remove_finished(CURLM
* multi_handle
, CURLcode
* result
)
6234 int msgs_in_queue
= 0;
6238 CURLMsg
* msg
= curl_multi_info_read(multi_handle
, &msgs_in_queue
);
6239 if (NULL
== msg
) return NULL
;
6240 if (CURLMSG_DONE
== msg
->msg
)
6242 CURL
* easy_handle
= msg
->easy_handle
;
6243 if (result
) *result
= msg
->data
.result
;
6244 if (CURLM_OK
!= curl_multi_remove_handle(multi_handle
, easy_handle
))
6246 /*failwith("curlm_remove_finished");*/
6253 CAMLprim value
caml_curlm_remove_finished(value v_multi
)
6255 CAMLparam1(v_multi
);
6256 CAMLlocal2(v_easy
, v_tuple
);
6258 CURLM
* multi_handle
;
6260 Connection
* conn
= NULL
;
6262 multi_handle
= CURLM_val(v_multi
);
6264 caml_enter_blocking_section();
6265 handle
= curlm_remove_finished(multi_handle
,&result
);
6266 caml_leave_blocking_section();
6270 CAMLreturn(Val_none
);
6274 conn
= findConnection(handle
);
6275 if (conn
->errorBuffer
!= NULL
)
6277 Store_field(Field(conn
->ocamlValues
, OcamlErrorBuffer
), 0, caml_copy_string(conn
->errorBuffer
));
6280 /* NB: same handle, but different block */
6281 v_easy
= caml_curl_alloc(conn
);
6282 v_tuple
= caml_alloc(2, 0);
6283 Store_field(v_tuple
,0,v_easy
);
6284 Store_field(v_tuple
,1,Val_int(result
)); /* CURLcode */
6285 CAMLreturn(Val_some(v_tuple
));
6289 static int curlm_wait_data(CURLM
* multi_handle
)
6291 struct timeval timeout
;
6303 /* set a suitable timeout */
6305 timeout
.tv_usec
= 0;
6307 /* get file descriptors from the transfers */
6308 ret
= curl_multi_fdset(multi_handle
, &fdread
, &fdwrite
, &fdexcep
, &maxfd
);
6310 if (ret
== CURLM_OK
&& maxfd
>= 0)
6312 int rc
= select(maxfd
+1, &fdread
, &fdwrite
, &fdexcep
, &timeout
);
6313 if (-1 != rc
) return 0;
6318 CAMLprim value
caml_curlm_wait_data(value v_multi
)
6320 CAMLparam1(v_multi
);
6322 CURLM
* h
= CURLM_val(v_multi
);
6324 caml_enter_blocking_section();
6325 ret
= curlm_wait_data(h
);
6326 caml_leave_blocking_section();
6328 CAMLreturn(Val_bool(0 == ret
));
6331 CAMLprim value
caml_curl_multi_add_handle(value v_multi
, value v_easy
)
6333 CAMLparam2(v_multi
,v_easy
);
6334 CURLM
* multi
= CURLM_val(v_multi
);
6335 Connection
* conn
= Connection_val(v_easy
);
6337 /* prevent collection of OCaml value while the easy handle is used
6338 and may invoke callbacks registered on OCaml side */
6341 /* may invoke callbacks so need to be consistent with locks */
6342 caml_enter_blocking_section();
6343 if (CURLM_OK
!= curl_multi_add_handle(multi
, conn
->connection
))
6345 conn
->refcount
--; /* not added, revert */
6346 caml_leave_blocking_section();
6347 failwith("caml_curl_multi_add_handle");
6349 caml_leave_blocking_section();
6351 CAMLreturn(Val_unit
);
6354 CAMLprim value
caml_curl_multi_remove_handle(value v_multi
, value v_easy
)
6356 CAMLparam2(v_multi
,v_easy
);
6357 CURLM
* multi
= CURLM_val(v_multi
);
6358 Connection
* conn
= Connection_val(v_easy
);
6360 /* may invoke callbacks so need to be consistent with locks */
6361 caml_enter_blocking_section();
6362 if (CURLM_OK
!= curl_multi_remove_handle(multi
, conn
->connection
))
6364 caml_leave_blocking_section();
6365 failwith("caml_curl_multi_remove_handle");
6368 caml_leave_blocking_section();
6370 CAMLreturn(Val_unit
);
6373 CAMLprim value
caml_curl_multi_perform_all(value v_multi
)
6375 CAMLparam1(v_multi
);
6376 int still_running
= 0;
6377 CURLM
* h
= CURLM_val(v_multi
);
6379 caml_enter_blocking_section();
6380 while (CURLM_CALL_MULTI_PERFORM
== curl_multi_perform(h
, &still_running
));
6381 caml_leave_blocking_section();
6383 CAMLreturn(Val_int(still_running
));
6386 CAMLprim value
helper_curl_easy_strerror(value v_code
)
6389 CAMLreturn(caml_copy_string(curl_easy_strerror(Int_val(v_code
))));
6393 * Wrappers for the curl_multi_socket_action infrastructure
6394 * Based on curl hiperfifo.c example
6399 #define Val_socket(v) win_alloc_socket(v)
6402 #error Socket_val not defined in unixsupport.h
6406 #define Socket_val(v) Long_val(v)
6409 #define Val_socket(v) Val_int(v)
6413 static void raise_error(char const* msg
)
6415 static value
* exception
= NULL
;
6417 if (NULL
== exception
)
6419 exception
= caml_named_value("Curl.Multi.Error");
6420 if (NULL
== exception
) caml_invalid_argument("Curl.Multi.Error");
6423 caml_raise_with_string(*exception
, msg
);
6426 static void check_mcode(CURLMcode code
)
6428 char const *s
= NULL
;
6431 case CURLM_OK
: return;
6432 case CURLM_CALL_MULTI_PERFORM
: s
="CURLM_CALL_MULTI_PERFORM"; break;
6433 case CURLM_BAD_HANDLE
: s
="CURLM_BAD_HANDLE"; break;
6434 case CURLM_BAD_EASY_HANDLE
: s
="CURLM_BAD_EASY_HANDLE"; break;
6435 case CURLM_OUT_OF_MEMORY
: s
="CURLM_OUT_OF_MEMORY"; break;
6436 case CURLM_INTERNAL_ERROR
: s
="CURLM_INTERNAL_ERROR"; break;
6437 case CURLM_UNKNOWN_OPTION
: s
="CURLM_UNKNOWN_OPTION"; break;
6438 case CURLM_LAST
: s
="CURLM_LAST"; break;
6439 case CURLM_BAD_SOCKET
: s
="CURLM_BAD_SOCKET"; break;
6440 default : s
="CURLM_unknown"; break;
6445 CAMLprim value
caml_curl_multi_socket_action(value v_multi
, value v_fd
, value v_kind
)
6447 CAMLparam3(v_multi
, v_fd
, v_kind
);
6448 CURLM
* h
= CURLM_val(v_multi
);
6449 int still_running
= 0;
6450 CURLMcode rc
= CURLM_OK
;
6451 curl_socket_t socket
;
6454 if (Val_none
== v_fd
)
6456 socket
= CURL_SOCKET_TIMEOUT
;
6460 socket
= Socket_val(Field(v_fd
, 0));
6463 switch (Int_val(v_kind
))
6466 case 1 : kind
|= CURL_CSELECT_IN
; break;
6467 case 2 : kind
|= CURL_CSELECT_OUT
; break;
6468 case 3 : kind
|= CURL_CSELECT_IN
| CURL_CSELECT_OUT
; break;
6470 raise_error("caml_curl_multi_socket_action");
6473 /* fprintf(stdout,"fd %u kind %u\n",socket, kind); fflush(stdout); */
6475 caml_enter_blocking_section();
6477 rc
= curl_multi_socket_action(h
, socket
, kind
, &still_running
);
6478 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6479 caml_leave_blocking_section();
6483 CAMLreturn(Val_int(still_running
));
6486 CAMLprim value
caml_curl_multi_socket_all(value v_multi
)
6488 CAMLparam1(v_multi
);
6489 int still_running
= 0;
6490 CURLMcode rc
= CURLM_OK
;
6491 CURLM
* h
= CURLM_val(v_multi
);
6493 caml_enter_blocking_section();
6495 rc
= curl_multi_socket_all(h
, &still_running
);
6496 } while (rc
== CURLM_CALL_MULTI_PERFORM
);
6497 caml_leave_blocking_section();
6501 CAMLreturn(Val_int(still_running
));
6504 static int curlm_sock_cb_nolock(CURL
*e
, curl_socket_t sock
, int what
, ml_multi_handle
* multi
, void *sockp
)
6507 CAMLlocal2(v_what
,csock
);
6509 (void)sockp
; /* not used */
6511 /* v_what = Val_int(what); */
6514 case CURL_POLL_NONE
: v_what
= Val_int(0); break;
6515 case CURL_POLL_IN
: v_what
= Val_int(1); break;
6516 case CURL_POLL_OUT
: v_what
= Val_int(2); break;
6517 case CURL_POLL_INOUT
: v_what
= Val_int(3); break;
6518 case CURL_POLL_REMOVE
: v_what
= Val_int(4); break;
6520 fprintf(stderr
, "curlm_sock_cb sock=%d what=%d\n", sock
, what
);
6522 raise_error("curlm_sock_cb"); /* FIXME exception from callback */
6524 csock
=Val_socket(sock
);
6525 caml_callback2(Field(multi
->values
,curlmopt_socket_function
),
6531 static int curlm_sock_cb(CURL
*e
, curl_socket_t sock
, int what
, void *cbp
, void *sockp
)
6534 caml_leave_blocking_section();
6535 ret
= curlm_sock_cb_nolock(e
, sock
, what
, (ml_multi_handle
*)cbp
, sockp
);
6536 caml_enter_blocking_section();
6540 CAMLprim value
caml_curl_multi_socketfunction(value v_multi
, value v_cb
)
6542 CAMLparam2(v_multi
, v_cb
);
6543 ml_multi_handle
* multi
= Multi_val(v_multi
);
6545 Store_field(multi
->values
, curlmopt_socket_function
, v_cb
);
6547 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETFUNCTION
, curlm_sock_cb
);
6548 curl_multi_setopt(multi
->handle
, CURLMOPT_SOCKETDATA
, multi
);
6550 CAMLreturn(Val_unit
);
6553 static void curlm_timer_cb_nolock(ml_multi_handle
*multi
, long timeout_ms
)
6556 caml_callback(Field(multi
->values
,curlmopt_timer_function
), Val_long(timeout_ms
));
6560 static int curlm_timer_cb(CURLM
*multi
, long timeout_ms
, void *userp
)
6564 caml_leave_blocking_section();
6565 curlm_timer_cb_nolock((ml_multi_handle
*)userp
, timeout_ms
);
6566 caml_enter_blocking_section();
6570 CAMLprim value
caml_curl_multi_timerfunction(value v_multi
, value v_cb
)
6572 CAMLparam2(v_multi
, v_cb
);
6573 ml_multi_handle
* multi
= Multi_val(v_multi
);
6575 Store_field(multi
->values
, curlmopt_timer_function
, v_cb
);
6577 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERFUNCTION
, curlm_timer_cb
);
6578 curl_multi_setopt(multi
->handle
, CURLMOPT_TIMERDATA
, multi
);
6580 CAMLreturn(Val_unit
);
6583 CAMLprim value
caml_curl_multi_timeout(value v_multi
)
6585 CAMLparam1(v_multi
);
6587 CURLMcode rc
= CURLM_OK
;
6588 ml_multi_handle
* multi
= Multi_val(v_multi
);
6590 rc
= curl_multi_timeout(multi
->handle
, &ms
);
6594 CAMLreturn(Val_long(ms
));