CURLOPT_PREREQFUNCTION.3 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 2021 - 2022, Max Dymond, <max.dymond@microsoft.com>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_PREREQFUNCTION 3 "2 Aug 2021" "libcurl 7.80.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_PREREQFUNCTION \- user callback called when a connection has been
  26. established, but before a request has been made.
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. /* These are the return codes for the pre-request callback. */
  31. #define CURL_PREREQFUNC_OK 0
  32. #define CURL_PREREQFUNC_ABORT 1 /* fail the entire transfer */
  33. int prereq_callback(void *clientp,
  34. char *conn_primary_ip,
  35. char *conn_local_ip,
  36. int conn_primary_port,
  37. int conn_local_port);
  38. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
  39. .SH DESCRIPTION
  40. Pass a pointer to your callback function, which should match the prototype
  41. shown above.
  42. This function gets called by libcurl after a connection has been established
  43. or a connection has been reused (including any SSL handshaking), but before any
  44. request is actually made on the connection. For example, for HTTP, this
  45. callback is called once a connection has been established to the server, but
  46. before a GET/HEAD/POST/etc request has been sent.
  47. This function may be called multiple times if redirections are enabled and are
  48. being followed (see \fICURLOPT_FOLLOWLOCATION(3)\fP).
  49. The callback function must return \fICURL_PREREQFUNC_OK\fP on success, or
  50. \fICURL_PREREQFUNC_ABORT\fP to cause the transfer to fail.
  51. This function is passed the following arguments:
  52. .IP conn_primary_ip
  53. A nul-terminated pointer to a C string containing the primary IP of the remote
  54. server established with this connection. For FTP, this is the IP for the
  55. control connection. IPv6 addresses are represented without surrounding
  56. brackets.
  57. .IP conn_local_ip
  58. A nul-terminated pointer to a C string containing the originating IP for this
  59. connection. IPv6 addresses are represented without surrounding brackets.
  60. .IP conn_primary_port
  61. The primary port number on the remote server established with this connection.
  62. For FTP, this is the port for the control connection. This can be a TCP or a
  63. UDP port number dependending on the protocol.
  64. .IP conn_local_port
  65. The originating port number for this connection. This can be a TCP or a UDP
  66. port number dependending on the protocol.
  67. .IP clientp
  68. The pointer you set with \fICURLOPT_PREREQDATA(3)\fP.
  69. .SH DEFAULT
  70. By default, this is NULL and unused.
  71. .SH PROTOCOLS
  72. ALL
  73. .SH EXAMPLE
  74. .nf
  75. static int prereq_callback(void *clientp,
  76. char *conn_primary_ip,
  77. char *conn_local_ip,
  78. int conn_primary_port,
  79. int conn_local_port)
  80. {
  81. printf("Connection made to %s:%s\\n", conn_primary_ip, conn_primary_port);
  82. return CURL_PREREQFUNC_OK;
  83. }
  84. {
  85. struct data prereq_data;
  86. curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
  87. curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, &prereq_data);
  88. }
  89. .fi
  90. .SH AVAILABILITY
  91. Added in 7.80.0
  92. .SH RETURN VALUE
  93. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  94. .SH "SEE ALSO"
  95. .BR CURLOPT_PREREQDATA "(3) "