File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / directories.pm
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:16 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>