transfer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef HEADER_CURL_TRANSFER_H
  2. #define HEADER_CURL_TRANSFER_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #define Curl_headersep(x) ((((x)==':') || ((x)==';')))
  27. char *Curl_checkheaders(const struct Curl_easy *data,
  28. const char *thisheader,
  29. const size_t thislen);
  30. void Curl_init_CONNECT(struct Curl_easy *data);
  31. CURLcode Curl_pretransfer(struct Curl_easy *data);
  32. CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp);
  33. CURLcode Curl_retry_request(struct Curl_easy *data, char **url);
  34. bool Curl_meets_timecondition(struct Curl_easy *data, time_t timeofdoc);
  35. /**
  36. * Write the transfer raw response bytes, as received from the connection.
  37. * Will handle all passed bytes or return an error. By default, this will
  38. * write the bytes as BODY to the client. Protocols may provide a
  39. * "write_resp" callback in their handler to add specific treatment. E.g.
  40. * HTTP parses response headers and passes them differently to the client.
  41. * @param data the transfer
  42. * @param buf the raw response bytes
  43. * @param blen the amount of bytes in `buf`
  44. * @param is_eos TRUE iff the connection indicates this to be the last
  45. * bytes of the response
  46. */
  47. CURLcode Curl_xfer_write_resp(struct Curl_easy *data,
  48. const char *buf, size_t blen,
  49. bool is_eos);
  50. bool Curl_xfer_write_is_paused(struct Curl_easy *data);
  51. /**
  52. * Write a single "header" line from a server response.
  53. * @param hd0 the null-terminated, single header line
  54. * @param hdlen the length of the header line
  55. * @param is_eos TRUE iff this is the end of the response
  56. */
  57. CURLcode Curl_xfer_write_resp_hd(struct Curl_easy *data,
  58. const char *hd0, size_t hdlen, bool is_eos);
  59. /* The transfer is neither receiving nor sending. */
  60. void Curl_xfer_setup_nop(struct Curl_easy *data);
  61. /* The transfer sends data on the given socket index */
  62. void Curl_xfer_setup_send(struct Curl_easy *data,
  63. int sockindex);
  64. /* The transfer receives data on the given socket index, the
  65. * amount to receive (or -1 if unknown). */
  66. void Curl_xfer_setup_recv(struct Curl_easy *data,
  67. int sockindex,
  68. curl_off_t recv_size);
  69. /* *After* Curl_xfer_setup_xxx(), tell the transfer to shutdown the
  70. * connection at the end. Let the transfer either fail or ignore any
  71. * errors during shutdown. */
  72. void Curl_xfer_set_shutdown(struct Curl_easy *data,
  73. bool shutdown,
  74. bool ignore_errors);
  75. /**
  76. * The transfer will use socket 1 to send/recv. `recv_size` is
  77. * the amount to receive or -1 if unknown.
  78. */
  79. void Curl_xfer_setup_sendrecv(struct Curl_easy *data,
  80. int sockindex,
  81. curl_off_t recv_size);
  82. /**
  83. * Multi has set transfer to DONE. Last chance to trigger
  84. * missing response things like writing an EOS to the client.
  85. */
  86. CURLcode Curl_xfer_write_done(struct Curl_easy *data, bool premature);
  87. /**
  88. * Return TRUE iff transfer has pending data to send. Checks involved
  89. * connection filters.
  90. */
  91. bool Curl_xfer_needs_flush(struct Curl_easy *data);
  92. /**
  93. * Flush any pending send data on the transfer connection.
  94. */
  95. CURLcode Curl_xfer_flush(struct Curl_easy *data);
  96. /**
  97. * Send data on the socket/connection filter designated
  98. * for transfer's outgoing data.
  99. * Will return CURLE_OK on blocking with (*pnwritten == 0).
  100. */
  101. CURLcode Curl_xfer_send(struct Curl_easy *data,
  102. const void *buf, size_t blen, bool eos,
  103. size_t *pnwritten);
  104. /**
  105. * Receive data on the socket/connection filter designated
  106. * for transfer's incoming data.
  107. * Will return CURLE_AGAIN on blocking with (*pnrcvd == 0).
  108. */
  109. CURLcode Curl_xfer_recv(struct Curl_easy *data,
  110. char *buf, size_t blen,
  111. size_t *pnrcvd);
  112. CURLcode Curl_xfer_send_close(struct Curl_easy *data);
  113. CURLcode Curl_xfer_send_shutdown(struct Curl_easy *data, bool *done);
  114. /* Return TRUE if the transfer is not done, but further progress
  115. * is blocked. For example when it is only receiving and its writer
  116. * is PAUSED. */
  117. bool Curl_xfer_is_blocked(struct Curl_easy *data);
  118. /* Query if send/recv for transfer is paused. */
  119. bool Curl_xfer_send_is_paused(struct Curl_easy *data);
  120. bool Curl_xfer_recv_is_paused(struct Curl_easy *data);
  121. /* Enable/Disable pausing of send/recv for the transfer. */
  122. CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable);
  123. CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable);
  124. /* Query if transfer has expire timeout TOOFAST set. */
  125. bool Curl_xfer_is_too_fast(struct Curl_easy *data);
  126. #endif /* HEADER_CURL_TRANSFER_H */