netstr.h 2.7 KB

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