* converts a series of buckets into a string * XXX: BillS says this function performs essentially the same function as * ap_rgetline() in protocol.c. Deprecate this function and use ap_rgetline() * instead? I think ftp_string_read() will not work properly on non ASCII * (EBCDIC) machines either. */
| 213 | * (EBCDIC) machines either. |
| 214 | */ |
| 215 | static apr_status_t ftp_string_read(conn_rec *c, apr_bucket_brigade *bb, |
| 216 | char *buff, apr_size_t bufflen, int *eos, apr_size_t *outlen) |
| 217 | { |
| 218 | apr_bucket *e; |
| 219 | apr_status_t rv; |
| 220 | char *pos = buff; |
| 221 | char *response; |
| 222 | int found = 0; |
| 223 | apr_size_t len; |
| 224 | |
| 225 | /* start with an empty string */ |
| 226 | buff[0] = 0; |
| 227 | *eos = 0; |
| 228 | *outlen = 0; |
| 229 | |
| 230 | /* loop through each brigade */ |
| 231 | while (!found) { |
| 232 | /* get brigade from network one line at a time */ |
| 233 | if (APR_SUCCESS != (rv = ap_get_brigade(c->input_filters, bb, |
| 234 | AP_MODE_GETLINE, |
| 235 | APR_BLOCK_READ, |
| 236 | 0))) { |
| 237 | return rv; |
| 238 | } |
| 239 | /* loop through each bucket */ |
| 240 | while (!found) { |
| 241 | if (*eos || APR_BRIGADE_EMPTY(bb)) { |
| 242 | /* The connection aborted or timed out */ |
| 243 | return APR_ECONNABORTED; |
| 244 | } |
| 245 | e = APR_BRIGADE_FIRST(bb); |
| 246 | if (APR_BUCKET_IS_EOS(e)) { |
| 247 | *eos = 1; |
| 248 | } |
| 249 | else { |
| 250 | if (APR_SUCCESS != (rv = apr_bucket_read(e, |
| 251 | (const char **)&response, |
| 252 | &len, |
| 253 | APR_BLOCK_READ))) { |
| 254 | return rv; |
| 255 | } |
| 256 | /* |
| 257 | * is string LF terminated? |
| 258 | * XXX: This check can be made more efficient by simply checking |
| 259 | * if the last character in the 'response' buffer is an ASCII_LF. |
| 260 | * See ap_rgetline() for an example. |
| 261 | */ |
| 262 | if (memchr(response, APR_ASCII_LF, len)) { |
| 263 | found = 1; |
| 264 | } |
| 265 | /* concat strings until buff is full - then throw the data away */ |
| 266 | if (len > ((bufflen-1)-(pos-buff))) { |
| 267 | len = (bufflen-1)-(pos-buff); |
| 268 | } |
| 269 | if (len > 0) { |
| 270 | memcpy(pos, response, len); |
| 271 | pos += len; |
| 272 | *outlen += len; |
no test coverage detected