CURLOPT_PREREQFUNCTION.3 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. .\" generated by cd2nroff 0.1 from CURLOPT_PREREQFUNCTION.md
  2. .TH CURLOPT_PREREQFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_PREREQFUNCTION \- user callback called when a connection has been
  5. established, but before a request has been made.
  6. .SH SYNOPSIS
  7. .nf
  8. #include <curl/curl.h>
  9. /* These are the return codes for the pre-request callback. */
  10. #define CURL_PREREQFUNC_OK 0
  11. #define CURL_PREREQFUNC_ABORT 1 /* fail the entire transfer */
  12. int prereq_callback(void *clientp,
  13. char *conn_primary_ip,
  14. char *conn_local_ip,
  15. int conn_primary_port,
  16. int conn_local_port);
  17. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
  18. .fi
  19. .SH DESCRIPTION
  20. Pass a pointer to your callback function, which should match the prototype
  21. shown above.
  22. This function gets called by libcurl after a connection has been established
  23. or a connection has been reused (including any SSL handshaking), but before any
  24. request is actually made on the connection. For example, for HTTP, this
  25. callback is called once a connection has been established to the server, but
  26. before a GET/HEAD/POST/etc request has been sent.
  27. This function may be called multiple times if redirections are enabled and are
  28. being followed (see \fICURLOPT_FOLLOWLOCATION(3)\fP).
  29. The callback function must return \fICURL_PREREQFUNC_OK\fP on success, or
  30. \fICURL_PREREQFUNC_ABORT\fP to cause the transfer to fail.
  31. This function is passed the following arguments:
  32. .IP conn_primary_ip
  33. A null\-terminated pointer to a C string containing the primary IP of the
  34. remote server established with this connection. For FTP, this is the IP for
  35. the control connection. IPv6 addresses are represented without surrounding
  36. brackets.
  37. .IP conn_local_ip
  38. A null\-terminated pointer to a C string containing the originating IP for this
  39. connection. IPv6 addresses are represented without surrounding brackets.
  40. .IP conn_primary_port
  41. The primary port number on the remote server established with this connection.
  42. For FTP, this is the port for the control connection. This can be a TCP or a
  43. UDP port number depending on the protocol.
  44. .IP conn_local_port
  45. The originating port number for this connection. This can be a TCP or a UDP
  46. port number depending on the protocol.
  47. .IP clientp
  48. The pointer you set with \fICURLOPT_PREREQDATA(3)\fP.
  49. .SH DEFAULT
  50. NULL
  51. .SH PROTOCOLS
  52. This functionality affects all supported protocols
  53. .SH EXAMPLE
  54. .nf
  55. struct priv {
  56. void *custom;
  57. };
  58. static int prereq_callback(void *clientp,
  59. char *conn_primary_ip,
  60. char *conn_local_ip,
  61. int conn_primary_port,
  62. int conn_local_port)
  63. {
  64. printf("Connection made to %s:%d\\n", conn_primary_ip, conn_primary_port);
  65. return CURL_PREREQFUNC_OK;
  66. }
  67. int main(void)
  68. {
  69. struct priv prereq_data;
  70. CURL *curl = curl_easy_init();
  71. if(curl) {
  72. curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
  73. curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
  74. curl_easy_perform(curl);
  75. }
  76. }
  77. .fi
  78. .SH AVAILABILITY
  79. Added in curl 7.80.0
  80. .SH RETURN VALUE
  81. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  82. .SH SEE ALSO
  83. .BR CURLINFO_PRIMARY_IP (3),
  84. .BR CURLINFO_PRIMARY_PORT (3),
  85. .BR CURLOPT_PREREQDATA (3)