source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_list.c @ 773

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_list.c@773
Revision 773, 3.1 KB checked in by spascoe, 14 years ago (diff)

Initial import of bbftp source

Line 
1/*
2 * bbftpd/bbftpd_list.c
3 * Copyright (C) 1999, 2000, 2001, 2002 IN2P3, CNRS
4 * bbftp@in2p3.fr
5 * http://doc.in2p3.fr/bbftp
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */ 
21
22/****************************************************************************
23
24 
25 RETURN:
26        0  Keep the connection open (does not mean that the directory has been
27           successfully created)
28        -1 Tell the calling program to close the connection
29 
30 bbftpd_list.c  v 2.0.0  2001/02/27 - Creation of the routine.
31                v 2.0.1  2001/04/23 - Correct indentation
32                v 2.0.2  2001/05/04 - Change the philosophy in order
33                                      to bypass CASTOR rfio_rewinddir bug
34                v 2.1.0  2001/06/01 - Reorganise routines as in bbftp_
35
36 *****************************************************************************/
37#include <dirent.h>
38#include <errno.h>
39#include <fnmatch.h>
40#include <netinet/in.h>
41#include <syslog.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <utime.h>
45
46#include <bbftpd.h>
47#include <common.h>
48#include <daemon.h>
49#include <daemon_proto.h>
50#include <status.h>
51#include <structures.h>
52
53extern int  transferoption ;
54extern int  outcontrolsock ;
55extern  int     recvcontrolto ;
56extern  int     sendcontrolto ;
57
58int bbftpd_list(char *pattern,char *logmessage) 
59{
60
61    char    *filelist ;
62    int     filelistlen ;
63    int     retcode ;
64    char    send_buffer[MINMESSLEN] ;
65    struct message *msg ;
66   
67   
68    if ( (retcode = bbftpd_retrlistdir(pattern,&filelist,&filelistlen,logmessage) ) < 0) {
69        reply(MSG_BAD_NO_RETRY,logmessage) ;
70        return 0 ;
71    } else if ( retcode > 0 ) {
72        reply(MSG_BAD,logmessage) ;
73        return 0 ;
74    } else {
75        msg = (struct message *) send_buffer ;
76        msg->code = MSG_LIST_REPL_V2 ;
77#ifndef WORDS_BIGENDIAN
78        msg->msglen = ntohl(filelistlen) ;
79#else
80        msg->msglen = filelistlen ;
81#endif
82        if ( writemessage(outcontrolsock,send_buffer,MINMESSLEN,recvcontrolto) < 0 ) {
83            syslog(BBFTPD_ERR,"Error sending LISTREPL_V2 part 1") ;
84            FREE(filelist) ;
85            return -1 ;
86        }
87        if (filelistlen != 0 ) {
88            if ( writemessage(outcontrolsock,filelist,filelistlen,recvcontrolto) < 0 ) {
89                FREE(filelist) ;
90                syslog(BBFTPD_ERR,"Error sending filelist") ;
91                return -1 ;
92            }
93            FREE(filelist) ;
94            return 0 ;
95        }
96        return 0 ;
97    }
98}
Note: See TracBrowser for help on using the repository browser.