• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24%file_chmod1 = (
25  'name'      => 'chmod1',
26  'content'   => "This file should have permissions 444\n",
27  'perm'      => 'r--r--r--',
28  'time'      => 'Jan 11 10:00',
29  'dostime'   => '01-11-10  10:00AM',
30);
31
32%file_chmod2 = (
33  'name'      => 'chmod2',
34  'content'   => "This file should have permissions 666\n",
35  'perm'      => 'rw-rw-rw-',
36  'time'      => 'Feb  1  8:00',
37  'dostime'   => '02-01-10  08:00AM',
38);
39
40%file_chmod3 = (
41  'name'      => 'chmod3',
42  'content'   => "This file should have permissions 777\n",
43  'perm'      => 'rwxrwxrwx',
44  'time'      => 'Feb  1  8:00',
45  'dostime'   => '02-01-10  08:00AM',
46);
47
48%file_chmod4 = (
49  'type'      => 'd',
50  'name'      => 'chmod4',
51  'content'   => "This file should have permissions 001\n",
52  'perm'      => '--S--S--t',
53  'time'      => 'May  4  4:31',
54  'dostime'   => '05-04-10  04:31AM'
55);
56
57%file_chmod5 = (
58  'type'      => 'd',
59  'name'      => 'chmod5',
60  'content'   => "This file should have permissions 110\n",
61  'perm'      => '--s--s--T',
62  'time'      => 'May  4  4:31',
63  'dostime'   => '05-04-10  04:31AM'
64);
65
66%link_link = (
67  'type'      => 'l',
68  'name'      => 'link -> file.txt',
69  'size'      => '8',
70  'perm'      => 'rwxrwxrwx',
71  'time'      => 'Jan  6  4:42'
72);
73
74%link_link_absolute = (
75  'type'      => 'l',
76  'name'      => 'link_absolute -> /data/ftp/file.txt',
77  'size'      => '15',
78  'perm'      => 'rwxrwxrwx',
79  'time'      => 'Jan  6  4:45'
80);
81
82%dir_dot = (
83  'type'      => "d",
84  'name'      => ".",
85  'hlink'     => "4",
86  'time'      => "Apr 27  5:12",
87  'size'      => "20480",
88  'dostime'   => "04-27-10  05:12AM",
89  'perm'      => "rwxrwxrwx"
90);
91
92%dir_ddot = (
93  'type'      => "d",
94  'name'      => "..",
95  'hlink'     => "4",
96  'size'      => "20480",
97  'time'      => "Apr 23  3:12",
98  'dostime'   => "04-23-10  03:12AM",
99  'perm'      => "rwxrwxrwx"
100);
101
102%dir_weirddir_txt = (
103  'type'      => "d",
104  'name'      => "weirddir.txt",
105  'hlink'     => "2",
106  'size'      => "4096",
107  'time'      => "Apr 23  3:12",
108  'dostime'   => "04-23-10  03:12AM",
109  'perm'      => "rwxr-xrwx"
110);
111
112%dir_UNIX = (
113  'type'      => "d",
114  'name'      => "UNIX",
115  'hlink'     => "11",
116  'size'      => "4096",
117  'time'      => "Nov 01  2008",
118  'dostime'   => "11-01-08  11:11AM",
119  'perm'      => "rwx--x--x"
120);
121
122%dir_DOS = (
123  'type'      => "d",
124  'name'      => "DOS",
125  'hlink'     => "11",
126  'size'      => "4096",
127  'time'      => "Nov 01  2008",
128  'dostime'   => "11-01-08  11:11AM",
129  'perm'      => "rwx--x--x"
130);
131
132%dir_dot_NeXT = (
133  'type'      => "d",
134  'name'      => ".NeXT",
135  'hlink'     => "4",
136  'size'      => "4096",
137  'time'      => "Jan 23  2:05",
138  'dostime'   => "01-23-05  02:05AM",
139  'perm'      => "rwxrwxrwx"
140);
141
142%file_empty_file_dat = (
143  'name'      => "empty_file.dat",
144  'content'   => "",
145  'perm'      => "rw-r--r--",
146  'time'      => "Apr 27 11:01",
147  'dostime'   => "04-27-10  11:01AM"
148);
149
150%file_file_txt = (
151  'name'      => "file.txt",
152  'content'   => "This is content of file \"file.txt\"\n",
153  'time'      => "Apr 27 11:01",
154  'dostime'   => "04-27-10  11:01AM",
155  'perm'      => "rw-r--r--"
156);
157
158%file_someothertext_txt = (
159  'name'      => "someothertext.txt",
160  'content'   => "Some junk ;-) This file does not really exist.\n",
161  'time'      => "Apr 27 11:01",
162  'dostime'   => "04-27-10  11:01AM",
163  'perm'      => "rw-r--r--"
164);
165
166%lists = (
167  '/fully_simulated/' => {
168    'files'   => [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ],
169    'eol'     => "\r\n",
170    'type'    => "unix"
171  },
172  '/fully_simulated/UNIX/' => {
173    'files'   => [ \%dir_dot, \%dir_ddot,
174                   \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
175                   \%file_empty_file_dat, \%file_file_txt,
176                   \%link_link, \%link_link_absolute, \%dir_dot_NeXT,
177                   \%file_someothertext_txt, \%dir_weirddir_txt ],
178    'eol'     => "\r\n",
179    'type'    => 'unix'
180  },
181  '/fully_simulated/DOS/' => {
182    'files'   => [ \%dir_dot, \%dir_ddot,
183                   \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
184                   \%file_empty_file_dat, \%file_file_txt,
185                   \%dir_dot_NeXT, \%file_someothertext_txt, \%dir_weirddir_txt ],
186    'eol'     => "\r\n",
187    'type'    => 'dos'
188  }
189);
190
191sub ftp_createcontent($) {
192  my (%list) = @_;
193
194  $type = $$list{'type'};
195  $eol  = $$list{'eol'};
196  $list_ref = $$list{'files'};
197
198  my @diroutput;
199  my @contentlist;
200  if($type eq "unix") {
201    for(@$list_ref) {
202      my %file = %$_;
203      my $line = "";
204      my $ftype  = $file{'type'}  ? $file{'type'}  : "-";
205      my $fperm  = $file{'perm'}  ? $file{'perm'}  : "rwxr-xr-x";
206      my $fuser  = $file{'user'}  ? sprintf("%15s", $file{'user'})   : "ftp-default";
207      my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'})  : "ftp-default";
208      my $fsize = "";
209      if($file{'type'} eq "d") {
210        $fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096);
211      }
212      else {
213        $fsize = sprintf("%7d", length $file{'content'});
214      }
215      my $fhlink = $file{'hlink'} ? sprintf("%4d",  $file{'hlink'})  : "   1";
216      my $ftime  = $file{'time'}  ? sprintf("%10s", $file{'time'})   : "Jan 9  1933";
217      push(@contentlist, "$ftype$fperm $fhlink $fuser $fgroup $fsize $ftime $file{'name'}$eol");
218    }
219
220    return @contentlist;
221  }
222  elsif($type =~ /^dos$/) {
223    for(@$list_ref) {
224      my %file = %$_;
225      my $line = "";
226      my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97  09:12AM";
227      my $size_or_dir;
228      if($file{'type'} =~ /^d$/) {
229        $size_or_dir = "      <DIR>         ";
230      }
231      else {
232        $size_or_dir = sprintf("%20d", length $file{'content'});
233      }
234      push(@contentlist, "$time $size_or_dir $file{'name'}$eol");
235    }
236    return @contentlist;
237  }
238}
239
240sub wildcard_filesize($$) {
241  my ($list_type, $file) = @_;
242  $list = $lists{$list_type};
243  if($list) {
244    my $files = $list->{'files'};
245    for(@$files) {
246      my %f = %$_;
247      if ($f{'name'} eq $file) {
248        if($f{'content'}) {
249          return length $f{'content'};
250        }
251        elsif ($f{'type'} ne "d"){
252          return 0;
253        }
254        else {
255          return -1;
256        }
257      }
258    }
259  }
260  return -1;
261}
262sub wildcard_getfile($$) {
263  my ($list_type, $file) = @_;
264  $list = $lists{$list_type};
265  if($list) {
266    my $files = $list->{'files'};
267    for(@$files) {
268      my %f = %$_;
269      if ($f{'name'} eq $file) {
270        if($f{'content'}) {
271          return (length $f{'content'}, $f{'content'});
272        }
273        elsif ($f{'type'} ne "d"){
274          return (0, "");
275        }
276        else {
277          return (-1, 0);
278        }
279      }
280    }
281  }
282  return (-1, 0);
283}
284
285sub ftp_contentlist {
286  my $listname = $_[0];
287  $list = $lists{$listname};
288  return ftp_createcontent(\$list);
289}
290