pingpong.h
Go to the documentation of this file.
00001 #ifndef HEADER_CURL_PINGPONG_H
00002 #define HEADER_CURL_PINGPONG_H
00003 /***************************************************************************
00004  *                                  _   _ ____  _
00005  *  Project                     ___| | | |  _ \| |
00006  *                             / __| | | | |_) | |
00007  *                            | (__| |_| |  _ <| |___
00008  *                             \___|\___/|_| \_\_____|
00009  *
00010  * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
00011  *
00012  * This software is licensed as described in the file COPYING, which
00013  * you should have received as part of this distribution. The terms
00014  * are also available at https://curl.haxx.se/docs/copyright.html.
00015  *
00016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00017  * copies of the Software, and permit persons to whom the Software is
00018  * furnished to do so, under the terms of the COPYING file.
00019  *
00020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00021  * KIND, either express or implied.
00022  *
00023  ***************************************************************************/
00024 
00025 #include "curl_setup.h"
00026 
00027 #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_FTP) || \
00028   !defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_SMTP)
00029 #define USE_PINGPONG
00030 #endif
00031 
00032 /* forward-declaration, this is defined in urldata.h */
00033 struct connectdata;
00034 
00035 typedef enum {
00036   FTPTRANSFER_BODY, /* yes do transfer a body */
00037   FTPTRANSFER_INFO, /* do still go through to get info/headers */
00038   FTPTRANSFER_NONE, /* don't get anything and don't get info */
00039   FTPTRANSFER_LAST  /* end of list marker, never used */
00040 } curl_pp_transfer;
00041 
00042 /*
00043  * 'pingpong' is the generic struct used for protocols doing server<->client
00044  * conversations in a back-and-forth style such as FTP, IMAP, POP3, SMTP etc.
00045  *
00046  * It holds response cache and non-blocking sending data.
00047  */
00048 struct pingpong {
00049   char *cache;     /* data cache between getresponse()-calls */
00050   size_t cache_size;  /* size of cache in bytes */
00051   size_t nread_resp;  /* number of bytes currently read of a server response */
00052   char *linestart_resp; /* line start pointer for the server response
00053                            reader function */
00054   bool pending_resp;  /* set TRUE when a server response is pending or in
00055                          progress, and is cleared once the last response is
00056                          read */
00057   char *sendthis; /* allocated pointer to a buffer that is to be sent to the
00058                      server */
00059   size_t sendleft; /* number of bytes left to send from the sendthis buffer */
00060   size_t sendsize; /* total size of the sendthis buffer */
00061   struct timeval response; /* set to Curl_tvnow() when a command has been sent
00062                               off, used to time-out response reading */
00063   long response_time; /* When no timeout is given, this is the amount of
00064                          milliseconds we await for a server response. */
00065 
00066   struct connectdata *conn; /* points to the connectdata struct that this
00067                                belongs to */
00068 
00069   /* Function pointers the protocols MUST implement and provide for the
00070      pingpong layer to function */
00071 
00072   CURLcode (*statemach_act)(struct connectdata *conn);
00073 
00074   bool (*endofresp)(struct connectdata *conn, char *ptr, size_t len,
00075                     int *code);
00076 };
00077 
00078 /*
00079  * Curl_pp_statemach()
00080  *
00081  * called repeatedly until done. Set 'wait' to make it wait a while on the
00082  * socket if there's no traffic.
00083  */
00084 CURLcode Curl_pp_statemach(struct pingpong *pp, bool block);
00085 
00086 /* initialize stuff to prepare for reading a fresh new response */
00087 void Curl_pp_init(struct pingpong *pp);
00088 
00089 /* Returns timeout in ms. 0 or negative number means the timeout has already
00090    triggered */
00091 time_t Curl_pp_state_timeout(struct pingpong *pp);
00092 
00093 
00094 /***********************************************************************
00095  *
00096  * Curl_pp_sendf()
00097  *
00098  * Send the formated string as a command to a pingpong server. Note that
00099  * the string should not have any CRLF appended, as this function will
00100  * append the necessary things itself.
00101  *
00102  * made to never block
00103  */
00104 CURLcode Curl_pp_sendf(struct pingpong *pp,
00105                        const char *fmt, ...);
00106 
00107 /***********************************************************************
00108  *
00109  * Curl_pp_vsendf()
00110  *
00111  * Send the formated string as a command to a pingpong server. Note that
00112  * the string should not have any CRLF appended, as this function will
00113  * append the necessary things itself.
00114  *
00115  * made to never block
00116  */
00117 CURLcode Curl_pp_vsendf(struct pingpong *pp,
00118                         const char *fmt,
00119                         va_list args);
00120 
00121 /*
00122  * Curl_pp_readresp()
00123  *
00124  * Reads a piece of a server response.
00125  */
00126 CURLcode Curl_pp_readresp(curl_socket_t sockfd,
00127                           struct pingpong *pp,
00128                           int *code, /* return the server code if done */
00129                           size_t *size); /* size of the response */
00130 
00131 
00132 CURLcode Curl_pp_flushsend(struct pingpong *pp);
00133 
00134 /* call this when a pingpong connection is disconnected */
00135 CURLcode Curl_pp_disconnect(struct pingpong *pp);
00136 
00137 int Curl_pp_getsock(struct pingpong *pp, curl_socket_t *socks,
00138                     int numsocks);
00139 
00140 
00141 /***********************************************************************
00142  *
00143  * Curl_pp_moredata()
00144  *
00145  * Returns whether there are still more data in the cache and so a call
00146  * to Curl_pp_readresp() will not block.
00147  */
00148 bool Curl_pp_moredata(struct pingpong *pp);
00149 
00150 #endif /* HEADER_CURL_PINGPONG_H */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06