ascii.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef VSFTP_ASCII_H
  2. #define VSFTP_ASCII_H
  3. struct mystr;
  4. /* vsf_ascii_ascii_to_bin()
  5. * PURPOSE
  6. * This function converts an input buffer from ascii format to binary format.
  7. * This entails ripping out all occurences of '\r' that are followed by '\n'.
  8. * The result is stored in "p_out".
  9. * PARAMETERS
  10. * p_in - the input and output buffer, which MUST BE at least as big as
  11. * "in_len" PLUS ONE. This is to cater for a leading '\r' in the
  12. * buffer if certain conditions are met.
  13. * in_len - the length in bytes of the buffer.
  14. * prev_cr - set to non-zero if this buffer fragment was immediately
  15. * preceeded by a '\r'.
  16. * RETURNS
  17. * The number of characters stored in the buffer, the buffer address, and
  18. * if we ended on a '\r'.
  19. */
  20. struct ascii_to_bin_ret
  21. {
  22. unsigned int stored;
  23. int last_was_cr;
  24. char* p_buf;
  25. };
  26. struct ascii_to_bin_ret vsf_ascii_ascii_to_bin(
  27. char* p_in, unsigned int in_len, int prev_cr);
  28. /* vsf_ascii_bin_to_ascii()
  29. * PURPOSE
  30. * This function converts an input buffer from binary format to ascii format.
  31. * This entails replacing all occurences of '\n' with '\r\n'. The result is
  32. * stored in "p_out".
  33. * PARAMETERS
  34. * p_in - the input buffer, which is not modified
  35. * p_out - the output buffer, which MUST BE at least TWICE as big as
  36. * "in_len"
  37. * in_len - the length in bytes of the input buffer
  38. * prev_cr - set to non-zero if this buffer fragment was immediately
  39. * preceeded by a '\r'.
  40. * RETURNS
  41. * The number of characters stored in the output buffer, and whether the last
  42. * character stored was '\r'.
  43. */
  44. struct bin_to_ascii_ret
  45. {
  46. unsigned int stored;
  47. int last_was_cr;
  48. };
  49. struct bin_to_ascii_ret vsf_ascii_bin_to_ascii(const char* p_in,
  50. char* p_out,
  51. unsigned int in_len,
  52. int prev_cr);
  53. #endif /* VSFTP_ASCII_H */