2
0

directories.pm 7.7 KB

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