pingpong.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef HEADER_CURL_PINGPONG_H
  2. #define HEADER_CURL_PINGPONG_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, 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 http://curl.haxx.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. ***************************************************************************/
  24. #include "setup.h"
  25. #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_FTP) || \
  26. !defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_SMTP)
  27. #define USE_PINGPONG
  28. #endif
  29. /* forward-declaration, this is defined in urldata.h */
  30. struct connectdata;
  31. /*
  32. * 'pingpong' is the generic struct used for protocols doing server<->client
  33. * conversations in a back-and-forth style such as FTP, IMAP, POP3, SMTP etc.
  34. *
  35. * It holds response cache and non-blocking sending data.
  36. */
  37. struct pingpong {
  38. char *cache; /* data cache between getresponse()-calls */
  39. size_t cache_size; /* size of cache in bytes */
  40. size_t nread_resp; /* number of bytes currently read of a server response */
  41. char *linestart_resp; /* line start pointer for the server response
  42. reader function */
  43. bool pending_resp; /* set TRUE when a server response is pending or in
  44. progress, and is cleared once the last response is
  45. read */
  46. char *sendthis; /* allocated pointer to a buffer that is to be sent to the
  47. server */
  48. size_t sendleft; /* number of bytes left to send from the sendthis buffer */
  49. size_t sendsize; /* total size of the sendthis buffer */
  50. struct timeval response; /* set to Curl_tvnow() when a command has been sent
  51. off, used to time-out response reading */
  52. long response_time; /* When no timeout is given, this is the amount of
  53. milliseconds we await for a server response. */
  54. struct connectdata *conn; /* points to the connectdata struct that this
  55. belongs to */
  56. /* Function pointers the protocols MUST implement and provide for the
  57. pingpong layer to function */
  58. CURLcode (*statemach_act)(struct connectdata *conn);
  59. int (*endofresp)(struct pingpong *pp, int *code);
  60. };
  61. /*
  62. * Curl_pp_multi_statemach()
  63. *
  64. * called repeatedly until done when the multi interface is used.
  65. */
  66. CURLcode Curl_pp_multi_statemach(struct pingpong *pp);
  67. /*
  68. * Curl_pp_easy_statemach()
  69. *
  70. * called repeatedly until done when the easy interface is used.
  71. */
  72. CURLcode Curl_pp_easy_statemach(struct pingpong *pp);
  73. /* initialize stuff to prepare for reading a fresh new response */
  74. void Curl_pp_init(struct pingpong *pp);
  75. /* Returns timeout in ms. 0 or negative number means the timeout has already
  76. triggered */
  77. long Curl_pp_state_timeout(struct pingpong *pp);
  78. /***********************************************************************
  79. *
  80. * Curl_pp_sendf()
  81. *
  82. * Send the formated string as a command to a pingpong server. Note that
  83. * the string should not have any CRLF appended, as this function will
  84. * append the necessary things itself.
  85. *
  86. * made to never block
  87. */
  88. CURLcode Curl_pp_sendf(struct pingpong *pp,
  89. const char *fmt, ...);
  90. /***********************************************************************
  91. *
  92. * Curl_pp_vsendf()
  93. *
  94. * Send the formated string as a command to a pingpong server. Note that
  95. * the string should not have any CRLF appended, as this function will
  96. * append the necessary things itself.
  97. *
  98. * made to never block
  99. */
  100. CURLcode Curl_pp_vsendf(struct pingpong *pp,
  101. const char *fmt,
  102. va_list args);
  103. /*
  104. * Curl_pp_readresp()
  105. *
  106. * Reads a piece of a server response.
  107. */
  108. CURLcode Curl_pp_readresp(curl_socket_t sockfd,
  109. struct pingpong *pp,
  110. int *code, /* return the server code if done */
  111. size_t *size); /* size of the response */
  112. CURLcode Curl_pp_flushsend(struct pingpong *pp);
  113. /* call this when a pingpong connection is disconnected */
  114. CURLcode Curl_pp_disconnect(struct pingpong *pp);
  115. int Curl_pp_getsock(struct pingpong *pp, curl_socket_t *socks,
  116. int numsocks);
  117. #endif /* HEADER_CURL_PINGPONG_H */