00001 #ifndef VSFTP_NETSTR_H 00002 #define VSFTP_NETSTR_H 00003 00004 struct mystr; 00005 00006 /* str_netfd_alloc() 00007 * PURPOSE 00008 * Read a string from a network socket into a string buffer object. The string 00009 * is delimited by a specified string terminator character. 00010 * If any network related errors occur trying to read the string, this call 00011 * will exit the program. 00012 * This method avoids reading one character at a time from the network. 00013 * PARAMETERS 00014 * p_str - the destination string object 00015 * fd - the file descriptor of the remote network socket 00016 * term - the character which will terminate the string. This character 00017 * is included in the returned string. 00018 * p_readbuf - pointer to a scratch buffer into which to read from the 00019 * network. This buffer must be at least "maxlen" characters! 00020 * maxlen - maximum length of string to return. If this limit is passed, 00021 * an empty string will be returned. 00022 */ 00023 void str_netfd_alloc(struct mystr* p_str, int fd, char term, 00024 char* p_readbuf, unsigned int maxlen); 00025 00026 /* str_netfd_read() 00027 * PURPOSE 00028 * Fills contents of a string buffer object from a (typically network) file 00029 * descriptor. 00030 * PARAMETERS 00031 * p_str - the string object to be filled 00032 * fd - the file descriptor to read from 00033 * len - the number of bytes to read 00034 * RETURNS 00035 * Number read on success, -1 on failure. The read is considered a failure 00036 * unless the full requested byte count is read. 00037 */ 00038 int str_netfd_read(struct mystr* p_str, int fd, unsigned int len); 00039 00040 /* str_netfd_write() 00041 * PURPOSE 00042 * Write the contents of a string buffer object out to a (typically network) 00043 * file descriptor. 00044 * PARAMETERS 00045 * p_str - the string object to send 00046 * fd - the file descriptor to write to 00047 * RETURNS 00048 * Number written on success, -1 on failure. The write is considered a failure 00049 * unless the full string buffer object is written. 00050 */ 00051 int str_netfd_write(const struct mystr* p_str, int fd); 00052 00053 #endif /* VSFTP_NETSTR_H */ 00054