2
0

CURLOPT_PREREQFUNCTION.3 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_PREREQFUNCTION 3 "2 Aug 2021" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_PREREQFUNCTION \- user callback called when a connection has been
  28. established, but before a request has been made.
  29. .SH SYNOPSIS
  30. .nf
  31. #include <curl/curl.h>
  32. /* These are the return codes for the pre-request callback. */
  33. #define CURL_PREREQFUNC_OK 0
  34. #define CURL_PREREQFUNC_ABORT 1 /* fail the entire transfer */
  35. int prereq_callback(void *clientp,
  36. char *conn_primary_ip,
  37. char *conn_local_ip,
  38. int conn_primary_port,
  39. int conn_local_port);
  40. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
  41. .SH DESCRIPTION
  42. Pass a pointer to your callback function, which should match the prototype
  43. shown above.
  44. This function gets called by libcurl after a connection has been established
  45. or a connection has been reused (including any SSL handshaking), but before any
  46. request is actually made on the connection. For example, for HTTP, this
  47. callback is called once a connection has been established to the server, but
  48. before a GET/HEAD/POST/etc request has been sent.
  49. This function may be called multiple times if redirections are enabled and are
  50. being followed (see \fICURLOPT_FOLLOWLOCATION(3)\fP).
  51. The callback function must return \fICURL_PREREQFUNC_OK\fP on success, or
  52. \fICURL_PREREQFUNC_ABORT\fP to cause the transfer to fail.
  53. This function is passed the following arguments:
  54. .IP conn_primary_ip
  55. A null-terminated pointer to a C string containing the primary IP of the
  56. remote server established with this connection. For FTP, this is the IP for
  57. the control connection. IPv6 addresses are represented without surrounding
  58. brackets.
  59. .IP conn_local_ip
  60. A null-terminated pointer to a C string containing the originating IP for this
  61. connection. IPv6 addresses are represented without surrounding brackets.
  62. .IP conn_primary_port
  63. The primary port number on the remote server established with this connection.
  64. For FTP, this is the port for the control connection. This can be a TCP or a
  65. UDP port number depending on the protocol.
  66. .IP conn_local_port
  67. The originating port number for this connection. This can be a TCP or a UDP
  68. port number depending on the protocol.
  69. .IP clientp
  70. The pointer you set with \fICURLOPT_PREREQDATA(3)\fP.
  71. .SH DEFAULT
  72. By default, this is NULL and unused.
  73. .SH PROTOCOLS
  74. ALL
  75. .SH EXAMPLE
  76. .nf
  77. static int prereq_callback(void *clientp,
  78. char *conn_primary_ip,
  79. char *conn_local_ip,
  80. int conn_primary_port,
  81. int conn_local_port)
  82. {
  83. printf("Connection made to %s:%s\\n", conn_primary_ip, conn_primary_port);
  84. return CURL_PREREQFUNC_OK;
  85. }
  86. {
  87. struct data prereq_data;
  88. curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
  89. curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, &prereq_data);
  90. }
  91. .fi
  92. .SH AVAILABILITY
  93. Added in 7.80.0
  94. .SH RETURN VALUE
  95. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  96. .SH "SEE ALSO"
  97. .BR CURLOPT_PREREQDATA "(3) "