http://prdownloads.sourceforge.net/lufs/lufs-0.9.7.tar.gz?download
[lufs.git] / filesystems / ftpfs / ftpsys_windows.cpp
1 /*
2  * ftpsys_windows.cpp
3  * Copyleft (C) 2002 Zachary Bedell <aramis@adirondack.net>
4  *  Based on ftpsys_unix.cpp which is:
5  * Copyright (C) 2002 Florin Malita <mali@go.ro>
6  *
7  * This file is part of LUFS, a free userspace filesystem implementation.
8  * See http://lufs.sourceforge.net/ for updates.
9  *
10  * LUFS is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * LUFS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <ctype.h>
30 #include <string.h>
31
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #ifndef __USE_XOPEN
36 #define __USE_XOPEN
37 #endif
38
39 #include <time.h>
40
41 #include <lufs/proto.h>
42 #include <lufs/fs.h>
43
44 #include "ftpsys.h"
45 #include "ftpsys_windows.h"
46
47 static char*
48 next_word(char *c){
49     while( (*c != ' ') && (*c != 0))
50         c++;
51     if(! *c)
52         return c;
53
54     while(*c == ' ')
55         c++;    
56     return c;
57 }
58
59 ftpsys_windows::ftpsys_windows(){
60     CMD_LIST = "LIST -al";
61 }
62
63 ftpsys_windows::~ftpsys_windows(){
64
65 }
66
67 int
68 ftpsys_windows::parse_line(char *buf, char *file, struct lufs_fattr *fattr, char *link, struct credentials *cred){
69     unsigned long size = 0;
70     int res;
71     struct tm tm;
72     time_t tt;
73     char sDate[20], sTime[20], datetime[40];
74
75     *file = *link = sDate[0] = sTime[0] = datetime[0] = 0;
76
77     if(tolower(buf[25]) == 'd') {
78         res = sscanf(buf, "%8s %7s %*5s %1024s", sDate, sTime, file);
79     } else {
80         res = sscanf(buf, "%8s %7s %lu %1024s", sDate, sTime, &size, file);
81     }
82
83     if(res < 2) {
84         TRACE("could only match "<<res<<" attributes");
85         return -1;
86     }
87
88     sprintf(datetime, "%s %s", sDate, sTime);
89
90     tt = time(NULL);
91     gmtime_r(&tt, &tm);
92     tm.tm_sec = 0;
93
94     strptime(datetime, "%m-%e-%y  %I:%M%p", &tm);
95
96     memset(fattr, 0, sizeof(struct lufs_fattr));
97
98     fattr->f_uid = 1;
99     fattr->f_gid = 1;
100
101     fattr->f_nlink = 0;
102     fattr->f_size = size;
103     fattr->f_ctime = fattr->f_mtime = fattr->f_atime = mktime(&tm);
104     
105     if(tolower(buf[25]) == 'd') fattr->f_mode = S_IFDIR;
106     else fattr->f_mode = S_IFREG;
107
108     fattr->f_mode |= S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
109
110     TRACE("file: " << file<<", link: " << link);
111     return 0;
112 }
113
114