2011-07-26 23:23:27 +08:00
|
|
|
#ifndef HEADER_CURL_PINGPONG_H
|
|
|
|
#define HEADER_CURL_PINGPONG_H
|
2009-12-13 05:54:01 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2021-01-09 00:58:15 +08:00
|
|
|
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2009-12-13 05:54:01 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2009-12-13 05:54:01 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_FTP) || \
|
|
|
|
!defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_SMTP)
|
|
|
|
#define USE_PINGPONG
|
|
|
|
#endif
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
/* forward-declaration, this is defined in urldata.h */
|
2009-12-13 05:54:01 +08:00
|
|
|
struct connectdata;
|
|
|
|
|
2013-02-23 23:26:26 +08:00
|
|
|
typedef enum {
|
|
|
|
FTPTRANSFER_BODY, /* yes do transfer a body */
|
|
|
|
FTPTRANSFER_INFO, /* do still go through to get info/headers */
|
|
|
|
FTPTRANSFER_NONE, /* don't get anything and don't get info */
|
|
|
|
FTPTRANSFER_LAST /* end of list marker, never used */
|
2013-02-24 01:09:24 +08:00
|
|
|
} curl_pp_transfer;
|
2013-02-23 23:26:26 +08:00
|
|
|
|
2009-12-13 05:54:01 +08:00
|
|
|
/*
|
|
|
|
* 'pingpong' is the generic struct used for protocols doing server<->client
|
|
|
|
* conversations in a back-and-forth style such as FTP, IMAP, POP3, SMTP etc.
|
|
|
|
*
|
|
|
|
* It holds response cache and non-blocking sending data.
|
|
|
|
*/
|
|
|
|
struct pingpong {
|
|
|
|
char *cache; /* data cache between getresponse()-calls */
|
|
|
|
size_t cache_size; /* size of cache in bytes */
|
|
|
|
size_t nread_resp; /* number of bytes currently read of a server response */
|
|
|
|
char *linestart_resp; /* line start pointer for the server response
|
|
|
|
reader function */
|
|
|
|
bool pending_resp; /* set TRUE when a server response is pending or in
|
|
|
|
progress, and is cleared once the last response is
|
|
|
|
read */
|
|
|
|
char *sendthis; /* allocated pointer to a buffer that is to be sent to the
|
|
|
|
server */
|
|
|
|
size_t sendleft; /* number of bytes left to send from the sendthis buffer */
|
|
|
|
size_t sendsize; /* total size of the sendthis buffer */
|
2017-10-25 17:59:43 +08:00
|
|
|
struct curltime response; /* set to Curl_now() when a command has been sent
|
|
|
|
off, used to time-out response reading */
|
2020-05-29 06:08:03 +08:00
|
|
|
timediff_t response_time; /* When no timeout is given, this is the amount of
|
|
|
|
milliseconds we await for a server response. */
|
2021-01-09 00:58:15 +08:00
|
|
|
struct connectdata *conn; /* the connection */
|
2020-09-23 15:22:02 +08:00
|
|
|
struct dynbuf sendbuf;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
/* Function pointers the protocols MUST implement and provide for the
|
|
|
|
pingpong layer to function */
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode (*statemachine)(struct Curl_easy *data, struct connectdata *conn);
|
|
|
|
bool (*endofresp)(struct Curl_easy *data, struct connectdata *conn,
|
|
|
|
char *ptr, size_t len, int *code);
|
2009-12-13 05:54:01 +08:00
|
|
|
};
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
#define PINGPONG_SETUP(pp,s,e) \
|
|
|
|
do { \
|
|
|
|
pp->response_time = RESP_TIMEOUT; \
|
|
|
|
pp->statemachine = s; \
|
|
|
|
pp->endofresp = e; \
|
|
|
|
pp->conn = conn; \
|
|
|
|
} while(0)
|
|
|
|
|
2009-12-13 05:54:01 +08:00
|
|
|
/*
|
2013-02-15 18:03:42 +08:00
|
|
|
* Curl_pp_statemach()
|
2009-12-13 05:54:01 +08:00
|
|
|
*
|
2013-02-15 18:03:42 +08:00
|
|
|
* called repeatedly until done. Set 'wait' to make it wait a while on the
|
|
|
|
* socket if there's no traffic.
|
2009-12-13 05:54:01 +08:00
|
|
|
*/
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode Curl_pp_statemach(struct Curl_easy *data, struct pingpong *pp,
|
|
|
|
bool block, bool disconnecting);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
/* initialize stuff to prepare for reading a fresh new response */
|
2021-01-09 00:58:15 +08:00
|
|
|
void Curl_pp_init(struct Curl_easy *data, struct pingpong *pp);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2020-09-23 15:22:02 +08:00
|
|
|
/* setup for the transfer */
|
|
|
|
void Curl_pp_setup(struct pingpong *pp);
|
|
|
|
|
2009-12-13 05:54:01 +08:00
|
|
|
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
|
|
|
triggered */
|
2021-01-09 00:58:15 +08:00
|
|
|
timediff_t Curl_pp_state_timeout(struct Curl_easy *data,
|
|
|
|
struct pingpong *pp, bool disconnecting);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Curl_pp_sendf()
|
|
|
|
*
|
2017-03-26 23:02:22 +08:00
|
|
|
* Send the formatted string as a command to a pingpong server. Note that
|
2009-12-13 05:54:01 +08:00
|
|
|
* the string should not have any CRLF appended, as this function will
|
|
|
|
* append the necessary things itself.
|
|
|
|
*
|
|
|
|
* made to never block
|
|
|
|
*/
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode Curl_pp_sendf(struct Curl_easy *data,
|
|
|
|
struct pingpong *pp,
|
2009-12-13 05:54:01 +08:00
|
|
|
const char *fmt, ...);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Curl_pp_vsendf()
|
|
|
|
*
|
2017-03-26 23:02:22 +08:00
|
|
|
* Send the formatted string as a command to a pingpong server. Note that
|
2009-12-13 05:54:01 +08:00
|
|
|
* the string should not have any CRLF appended, as this function will
|
|
|
|
* append the necessary things itself.
|
|
|
|
*
|
|
|
|
* made to never block
|
|
|
|
*/
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode Curl_pp_vsendf(struct Curl_easy *data,
|
|
|
|
struct pingpong *pp,
|
2009-12-13 05:54:01 +08:00
|
|
|
const char *fmt,
|
|
|
|
va_list args);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Curl_pp_readresp()
|
|
|
|
*
|
|
|
|
* Reads a piece of a server response.
|
|
|
|
*/
|
2021-01-09 00:58:15 +08:00
|
|
|
CURLcode Curl_pp_readresp(struct Curl_easy *data,
|
|
|
|
curl_socket_t sockfd,
|
2009-12-13 05:54:01 +08:00
|
|
|
struct pingpong *pp,
|
|
|
|
int *code, /* return the server code if done */
|
|
|
|
size_t *size); /* size of the response */
|
|
|
|
|
|
|
|
|
2021-01-18 18:56:50 +08:00
|
|
|
CURLcode Curl_pp_flushsend(struct Curl_easy *data,
|
|
|
|
struct pingpong *pp);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
/* call this when a pingpong connection is disconnected */
|
|
|
|
CURLcode Curl_pp_disconnect(struct pingpong *pp);
|
|
|
|
|
2019-07-30 17:02:03 +08:00
|
|
|
int Curl_pp_getsock(struct pingpong *pp, curl_socket_t *socks);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-02-15 02:36:43 +08:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Curl_pp_moredata()
|
|
|
|
*
|
|
|
|
* Returns whether there are still more data in the cache and so a call
|
|
|
|
* to Curl_pp_readresp() will not block.
|
|
|
|
*/
|
|
|
|
bool Curl_pp_moredata(struct pingpong *pp);
|
|
|
|
|
2011-07-26 23:23:27 +08:00
|
|
|
#endif /* HEADER_CURL_PINGPONG_H */
|