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
;
35 if (p_readpos
+ left
!= p_readbuf
+ maxlen
)
37 bug("poor buffer accounting in str_netfd_alloc");
39 /* 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");
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
)
61 retval
= (*p_readfunc
)(p_sess
, p_readpos
, i
);
62 if (vsf_sysutil_retval_is_error(retval
) ||
63 (unsigned int) retval
!= i
)
65 die("vsf_sysutil_read_loop");
67 if (p_readpos
[i
- 1] != term
)
69 die("missing terminator in str_netfd_alloc");
71 str_alloc_alt_term(p_str
, p_readbuf
, term
);
75 /* Not found in this read chunk, so consume the data and re-loop */
76 if (bytes_read
> left
)
78 bug("bytes_read > left in str_netfd_alloc");
81 retval
= (*p_readfunc
)(p_sess
, p_readpos
, bytes_read
);
82 if (vsf_sysutil_retval_is_error(retval
) ||
83 (unsigned int) retval
!= bytes_read
)
85 die("vsf_sysutil_read_loop");
87 p_readpos
+= bytes_read
;
92 str_netfd_write(const struct mystr
* p_str
, int fd
)
96 unsigned int str_len
= str_getlen(p_str
);
99 bug("zero str_len in str_netfd_write");
101 retval
= str_write_loop(p_str
, fd
);
102 if (vsf_sysutil_retval_is_error(retval
) || (unsigned int) retval
!= str_len
)
110 str_netfd_read(struct mystr
* p_str
, int fd
, unsigned int len
)
113 str_reserve(p_str
, len
);
114 str_trunc(p_str
, len
);
115 retval
= str_read_loop(p_str
, fd
);
116 if (vsf_sysutil_retval_is_error(retval
) || (unsigned int) retval
!= len
)