1 #ifndef HEADER_CURL_PINGPONG_H
2 #define HEADER_CURL_PINGPONG_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 #include "curl_setup.h"
27 #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_FTP) || \
28 !defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_SMTP)
32 /* forward-declaration, this is defined in urldata.h */
36 FTPTRANSFER_BODY, /* yes do transfer a body */
37 FTPTRANSFER_INFO, /* do still go through to get info/headers */
38 FTPTRANSFER_NONE, /* don't get anything and don't get info */
39 FTPTRANSFER_LAST /* end of list marker, never used */
43 * 'pingpong' is the generic struct used for protocols doing server<->client
44 * conversations in a back-and-forth style such as FTP, IMAP, POP3, SMTP etc.
46 * It holds response cache and non-blocking sending data.
49 char *cache; /* data cache between getresponse()-calls */
50 size_t cache_size; /* size of cache in bytes */
51 size_t nread_resp; /* number of bytes currently read of a server response */
52 char *linestart_resp; /* line start pointer for the server response
54 bool pending_resp; /* set TRUE when a server response is pending or in
55 progress, and is cleared once the last response is
57 char *sendthis; /* allocated pointer to a buffer that is to be sent to the
59 size_t sendleft; /* number of bytes left to send from the sendthis buffer */
60 size_t sendsize; /* total size of the sendthis buffer */
61 struct curltime response; /* set to Curl_now() when a command has been sent
62 off, used to time-out response reading */
63 timediff_t response_time; /* When no timeout is given, this is the amount of
64 milliseconds we await for a server response. */
65 struct connectdata *conn; /* points to the connectdata struct that this
67 struct dynbuf sendbuf;
69 /* Function pointers the protocols MUST implement and provide for the
70 pingpong layer to function */
72 CURLcode (*statemach_act)(struct connectdata *conn);
74 bool (*endofresp)(struct connectdata *conn, char *ptr, size_t len,
81 * called repeatedly until done. Set 'wait' to make it wait a while on the
82 * socket if there's no traffic.
84 CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
87 /* initialize stuff to prepare for reading a fresh new response */
88 void Curl_pp_init(struct pingpong *pp);
90 /* setup for the transfer */
91 void Curl_pp_setup(struct pingpong *pp);
93 /* Returns timeout in ms. 0 or negative number means the timeout has already
95 timediff_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting);
98 /***********************************************************************
102 * Send the formatted string as a command to a pingpong server. Note that
103 * the string should not have any CRLF appended, as this function will
104 * append the necessary things itself.
106 * made to never block
108 CURLcode Curl_pp_sendf(struct pingpong *pp,
109 const char *fmt, ...);
111 /***********************************************************************
115 * Send the formatted string as a command to a pingpong server. Note that
116 * the string should not have any CRLF appended, as this function will
117 * append the necessary things itself.
119 * made to never block
121 CURLcode Curl_pp_vsendf(struct pingpong *pp,
128 * Reads a piece of a server response.
130 CURLcode Curl_pp_readresp(curl_socket_t sockfd,
132 int *code, /* return the server code if done */
133 size_t *size); /* size of the response */
136 CURLcode Curl_pp_flushsend(struct pingpong *pp);
138 /* call this when a pingpong connection is disconnected */
139 CURLcode Curl_pp_disconnect(struct pingpong *pp);
141 int Curl_pp_getsock(struct pingpong *pp, curl_socket_t *socks);
144 /***********************************************************************
148 * Returns whether there are still more data in the cache and so a call
149 * to Curl_pp_readresp() will not block.
151 bool Curl_pp_moredata(struct pingpong *pp);
153 #endif /* HEADER_CURL_PINGPONG_H */