1 #ifndef VSFTP_NETSTR_H 2 #define VSFTP_NETSTR_H 3 4 struct mystr; 5 struct vsf_session; 6 7 typedef int (*str_netfd_read_t)(struct vsf_session* 8 p_sess, char*, 9 unsigned int); 10 11 /* str_netfd_alloc() 12 * PURPOSE 13 * Read a string from a network socket into a string buffer object. The string 14 * is delimited by a specified string terminator character. 15 * If any network related errors occur trying to read the string, this call 16 * will exit the program. 17 * This method avoids reading one character at a time from the network. 18 * PARAMETERS 19 * p_sess - the session object, used for passing into the I/O callbacks 20 * p_str - the destination string object 21 * term - the character which will terminate the string. This character 22 * is included in the returned string. 23 * p_readbuf - pointer to a scratch buffer into which to read from the 24 * network. This buffer must be at least "maxlen" characters! 25 * maxlen - maximum length of string to return. If this limit is passed, 26 * an empty string will be returned. 27 * p_peekfunc - a function called to peek data from the network 28 * p_readfunc - a function called to read data from the network 29 * RETURNS 30 * -1 upon reaching max buffer length without seeing terminator, or the number 31 * of bytes read, _including_ the terminator. 0 for an EOF on the socket. 32 * Does not return (exits) for a serious socket error. 33 */ 34 int str_netfd_alloc(struct vsf_session* p_sess, 35 struct mystr* p_str, 36 char term, 37 char* p_readbuf, 38 unsigned int maxlen, 39 str_netfd_read_t p_peekfunc, 40 str_netfd_read_t p_readfunc); 41 42 /* str_netfd_read() 43 * PURPOSE 44 * Fills contents of a string buffer object from a (typically network) file 45 * descriptor. 46 * PARAMETERS 47 * p_str - the string object to be filled 48 * fd - the file descriptor to read from 49 * len - the number of bytes to read 50 * RETURNS 51 * Number read on success, -1 on failure. The read is considered a failure 52 * unless the full requested byte count is read. 53 */ 54 int str_netfd_read(struct mystr* p_str, int fd, unsigned int len); 55 56 /* str_netfd_write() 57 * PURPOSE 58 * Write the contents of a string buffer object out to a (typically network) 59 * file descriptor. 60 * PARAMETERS 61 * p_str - the string object to send 62 * fd - the file descriptor to write to 63 * RETURNS 64 * Number written on success, -1 on failure. The write is considered a failure 65 * unless the full string buffer object is written. 66 */ 67 int str_netfd_write(const struct mystr* p_str, int fd); 68 69 #endif /* VSFTP_NETSTR_H */ 70 71