2 * Part of Very Secure FTPd
7 * The netstr interface extends the standard string interface, adding
8 * functions which can cope safely with building strings from the network,
9 * and send them out too.
19 str_netfd_alloc(struct vsf_session
* p_sess
,
24 str_netfd_read_t p_peekfunc
,
25 str_netfd_read_t p_readfunc
)
28 unsigned int bytes_read
;
30 char* p_readpos
= p_readbuf
;
31 unsigned int left
= maxlen
;
34 if (p_readpos
+ left
!= p_readbuf
+ maxlen
)
36 bug("poor buffer accounting in str_netfd_alloc");
38 /* Did we hit the max? */
44 retval
= (*p_peekfunc
)(p_sess
, p_readpos
, left
);
45 if (vsf_sysutil_retval_is_error(retval
))
47 die("vsf_sysutil_recv_peek");
51 die("vsf_sysutil_recv_peek: no data");
53 bytes_read
= (unsigned int) retval
;
54 /* Search for the terminator */
55 for (i
=0; i
< bytes_read
; i
++)
57 if (p_readpos
[i
] == term
)
60 retval
= (*p_readfunc
)(p_sess
, p_readpos
, i
+ 1);
61 if (vsf_sysutil_retval_is_error(retval
) ||
62 (unsigned int) retval
!= i
+ 1)
64 die("vsf_sysutil_read_loop");
66 if (p_readpos
[i
] != term
)
68 die("missing terminator in str_netfd_alloc");
70 str_alloc_alt_term(p_str
, p_readbuf
, term
);
74 /* Not found in this read chunk, so consume the data and re-loop */
75 if (bytes_read
> left
)
77 bug("bytes_read > left in str_netfd_alloc");
80 retval
= (*p_readfunc
)(p_sess
, p_readpos
, bytes_read
);
81 if (vsf_sysutil_retval_is_error(retval
) ||
82 (unsigned int) retval
!= bytes_read
)
84 die("vsf_sysutil_read_loop");
86 p_readpos
+= bytes_read
;
91 str_netfd_write(const struct mystr
* p_str
, int fd
)
95 unsigned int str_len
= str_getlen(p_str
);
98 bug("zero str_len in str_netfd_write");
100 retval
= str_write_loop(p_str
, fd
);
101 if (vsf_sysutil_retval_is_error(retval
) || (unsigned int) retval
!= str_len
)
109 str_netfd_read(struct mystr
* p_str
, int fd
, unsigned int len
)
112 str_reserve(p_str
, len
);
113 str_trunc(p_str
, len
);
114 retval
= str_read_loop(p_str
, fd
);
115 if (vsf_sysutil_retval_is_error(retval
) || (unsigned int) retval
!= len
)