summaryrefslogtreecommitdiff
path: root/libftpconn/names.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1997-08-07 20:10:39 +0000
committerMiles Bader <miles@gnu.org>1997-08-07 20:10:39 +0000
commitcd46e31a3aa381c6a1d2c24191dffcf7993b0277 (patch)
treeed5d47612641b7f01095c6bffafec91e8eede60a /libftpconn/names.c
parent09d60d4145058c1b4e34b00da430c6e0e783f2e3 (diff)
(ftp_conn_cont_get_names):
Support FIX_NLIST_NAME hook. Free S->dir if necessary. Close or abort connection when done. (ftp_conn_start_get_names): Fill in S->dir field if necessary. (struct get_names_state): Add DIR field.
Diffstat (limited to 'libftpconn/names.c')
-rw-r--r--libftpconn/names.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/libftpconn/names.c b/libftpconn/names.c
index ced741f6..2d631bf9 100644
--- a/libftpconn/names.c
+++ b/libftpconn/names.c
@@ -31,6 +31,8 @@ struct get_names_state
size_t name_alloced; /* Allocated size of NAME (>= NAME_LEN). */
int name_partial; /* True if NAME isn't complete. */
+ char *dir; /* Directory being listed. */
+
size_t buf_len; /* Length of contents in BUF. */
char buf[7000];
};
@@ -48,6 +50,19 @@ ftp_conn_start_get_names (struct ftp_conn *conn,
if (! s)
return ENOMEM;
+ if (conn->syshooks.fix_nlist_name)
+ /* We only need save the directory name if calling this hook. */
+ {
+ s->dir = strdup (name);
+ if (! s->dir)
+ {
+ free (s);
+ return ENOMEM;
+ }
+ }
+ else
+ s->dir = 0;
+
err = ftp_conn_start_list (conn, name, fd);
if (err)
@@ -141,8 +156,23 @@ ftp_conn_cont_get_names (struct ftp_conn *conn, int fd, void *state,
if (nl)
{
+ /* Fixup any screwy names returned by the server. */
+ char *name = s->name;
+
+ if (conn->syshooks.fix_nlist_name)
+ {
+ err = (*conn->syshooks.fix_nlist_name) (conn, s->dir, &name);
+ if (err)
+ goto finished;
+ }
+
/* Call the callback function to process the current entry. */
- err = (*add_name) (s->name, hook);
+ err = (*add_name) (name, hook);
+
+ if (name < s->name || name > s->name + s->name_len)
+ /* User-allocated NAME from the fix_nlist_name hook. */
+ free (name);
+
if (err)
goto finished;
@@ -181,9 +211,18 @@ finished:
return. */
if (s->name)
free (s->name);
+ if (s->dir)
+ free (s->dir);
free (s);
close (fd);
+ if (err && rd > 0)
+ ftp_conn_abort (conn);
+ else if (err)
+ ftp_conn_finish_transfer (conn);
+ else
+ err = ftp_conn_finish_transfer (conn);
+
return err;
}
@@ -191,7 +230,7 @@ finished:
(HOOK is passed to ADD_NAME). This function may block. */
error_t
ftp_conn_get_names (struct ftp_conn *conn, const char *name,
- ftp_conn_add_name_fun_t add_name, void *hook)
+ ftp_conn_add_name_fun_t add_name, void *hook)
{
int fd;
void *state;