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