2 diff -c squid/src/ftp.c:1.316.2.26 squid/src/ftp.c:1.316.2.27
3 *** squid/src/ftp.c:1.316.2.26 Tue Jun 21 16:18:19 2005
4 --- squid/src/ftp.c Tue Jun 21 16:21:31 2005
8 unsigned int http_header_sent:1;
9 unsigned int tried_nlst:1;
10 unsigned int use_base:1;
11 + unsigned int dir_slash:1;
12 unsigned int root_dir:1;
13 unsigned int no_dotdot:1;
14 unsigned int html_header_sent:1;
32 squid_off_t restart_offset;
33 squid_off_t restarted_offset;
38 storeAppendPrintf(e, "</PRE>\n");
39 if (ftpState->flags.listformat_unknown && !ftpState->flags.tried_nlst) {
40 ! storeAppendPrintf(e, "<A HREF=\"./;type=d\">[As plain directory]</A>\n");
41 } else if (ftpState->typecode == 'D') {
42 ! const char *path = ftpState->filepath ? ftpState->filepath : ".";
43 storeAppendPrintf(e, "<A HREF=\"%s/\">[As extended directory]</A>\n", html_quote(path));
45 storeAppendPrintf(e, "<HR noshade size=\"1px\">\n");
48 storeAppendPrintf(e, "</PRE>\n");
49 if (ftpState->flags.listformat_unknown && !ftpState->flags.tried_nlst) {
50 ! storeAppendPrintf(e, "<A HREF=\"%s/;type=d\">[As plain directory]</A>\n",
51 ! ftpState->flags.dir_slash ? rfc1738_escape_part(ftpState->filepath) : ".");
52 } else if (ftpState->typecode == 'D') {
53 ! const char *path = ftpState->flags.dir_slash ? ftpState->filepath : ".";
54 storeAppendPrintf(e, "<A HREF=\"%s/\">[As extended directory]</A>\n", html_quote(path));
56 storeAppendPrintf(e, "<HR noshade size=\"1px\">\n");
60 LOCAL_ARRAY(char, download, 2048 + 40);
61 LOCAL_ARRAY(char, link, 2048 + 40);
62 LOCAL_ARRAY(char, html, 8192);
63 + LOCAL_ARRAY(char, prefix, 2048);
64 size_t width = Config.Ftp.list_width;
66 *icon = *href = *text = *size = *chdir = *view = *download = *link = *html = '\0';
70 snprintf(html, 8192, "%s\n", line);
73 + if (ftpState->flags.dir_slash)
74 + snprintf(prefix, sizeof(prefix), "%s/", rfc1738_escape_part(ftpState->dirpath));
77 /* Handle builtin <dirup> */
78 if (strcmp(line, "<internal-dirup>") == 0) {
79 /* <A HREF="{href}">{icon}</A> <A HREF="{href}">{text}</A> {link} */
83 if (!ftpState->flags.no_dotdot && !ftpState->flags.root_dir) {
84 /* Normal directory */
85 ! strcpy(href, "../");
86 strcpy(text, "Parent Directory");
87 } else if (!ftpState->flags.no_dotdot && ftpState->flags.root_dir) {
88 /* "Top level" directory */
91 if (!ftpState->flags.no_dotdot && !ftpState->flags.root_dir) {
92 /* Normal directory */
93 ! if (!ftpState->flags.dir_slash)
94 ! strcpy(href, "../");
97 strcpy(text, "Parent Directory");
98 } else if (!ftpState->flags.no_dotdot && ftpState->flags.root_dir) {
99 /* "Top level" directory */
102 strcpy(href, "%2e%2e/");
103 strcpy(text, "Parent Directory");
104 snprintf(link, 2048, "(<A HREF=\"%s\">%s</A>)",
107 } else { /* NO_DOTDOT && ROOT_DIR */
108 /* "UNIX Root" directory */
110 strcpy(href, "%2e%2e/");
111 strcpy(text, "Parent Directory");
112 snprintf(link, 2048, "(<A HREF=\"%s\">%s</A>)",
113 ! !ftpState->flags.dir_slash ? "../" : "./",
115 } else { /* NO_DOTDOT && ROOT_DIR */
116 /* "UNIX Root" directory */
119 /* sometimes there is an 'l' flag, but no "->" link */
121 char *link2 = xstrdup(html_quote(rfc1738_escape(parts->link)));
122 ! snprintf(link, 2048, " -> <A HREF=\"%s\">%s</A>",
124 html_quote(parts->link));
128 /* sometimes there is an 'l' flag, but no "->" link */
130 char *link2 = xstrdup(html_quote(rfc1738_escape(parts->link)));
131 ! snprintf(link, 2048, " -> <A HREF=\"%s%s\">%s</A>",
132 ! *link2 != '/' ? prefix : "", link2,
133 html_quote(parts->link));
139 if (parts->type != 'd') {
140 if (mimeGetViewOption(parts->name)) {
141 ! snprintf(view, 2048, " <A HREF=\"%s;type=a\"><IMG border=\"0\" SRC=\"%s\" "
142 "ALT=\"[VIEW]\"></A>",
143 ! href, mimeGetIconURL("internal-view"));
145 if (mimeGetDownloadOption(parts->name)) {
146 ! snprintf(download, 2048, " <A HREF=\"%s;type=i\"><IMG border=\"0\" SRC=\"%s\" "
147 "ALT=\"[DOWNLOAD]\"></A>",
148 ! href, mimeGetIconURL("internal-download"));
151 /* <A HREF="{href}">{icon}</A> <A HREF="{href}">{text}</A> . . . {date}{size}{chdir}{view}{download}{link}\n */
152 if (parts->type != '\0') {
153 ! snprintf(html, 8192, "<A HREF=\"%s\">%s</A> <A HREF=\"%s\">%s</A>%s "
155 ! href, icon, href, html_quote(text), dots_fill(strlen(text)),
156 parts->date, size, chdir, view, download, link);
158 /* Plain listing. {icon} {text} ... {chdir}{view}{download} */
159 ! snprintf(html, 8192, "<A HREF=\"%s\">%s</A> <A HREF=\"%s\">%s</A>%s "
161 ! href, icon, href, html_quote(text), dots_fill(strlen(text)),
162 chdir, view, download, link);
164 ftpListPartsFree(&parts);
167 if (parts->type != 'd') {
168 if (mimeGetViewOption(parts->name)) {
169 ! snprintf(view, 2048, " <A HREF=\"%s%s;type=a\"><IMG border=\"0\" SRC=\"%s\" "
170 "ALT=\"[VIEW]\"></A>",
171 ! prefix, href, mimeGetIconURL("internal-view"));
173 if (mimeGetDownloadOption(parts->name)) {
174 ! snprintf(download, 2048, " <A HREF=\"%s%s;type=i\"><IMG border=\"0\" SRC=\"%s\" "
175 "ALT=\"[DOWNLOAD]\"></A>",
176 ! prefix, href, mimeGetIconURL("internal-download"));
179 /* <A HREF="{href}">{icon}</A> <A HREF="{href}">{text}</A> . . . {date}{size}{chdir}{view}{download}{link}\n */
180 if (parts->type != '\0') {
181 ! snprintf(html, 8192, "<A HREF=\"%s%s\">%s</A> <A HREF=\"%s%s\">%s</A>%s "
183 ! prefix, href, icon, prefix, href, html_quote(text), dots_fill(strlen(text)),
184 parts->date, size, chdir, view, download, link);
186 /* Plain listing. {icon} {text} ... {chdir}{view}{download} */
187 ! snprintf(html, 8192, "<A HREF=\"%s%s\">%s</A> <A HREF=\"%s%s\">%s</A>%s "
189 ! prefix, href, icon, prefix, href, html_quote(text), dots_fill(strlen(text)),
190 chdir, view, download, link);
192 ftpListPartsFree(&parts);
195 debug(9, 4) ("ftpTraverseDirectory %s\n",
196 ftpState->filepath ? ftpState->filepath : "<NULL>");
198 ! safe_free(ftpState->filepath);
200 if (ftpState->pathcomps == NULL) {
201 debug(9, 3) ("the final component was a directory\n");
203 debug(9, 4) ("ftpTraverseDirectory %s\n",
204 ftpState->filepath ? ftpState->filepath : "<NULL>");
206 ! safe_free(ftpState->dirpath);
207 ! ftpState->dirpath = ftpState->filepath;
208 ! ftpState->filepath = NULL;
211 if (ftpState->pathcomps == NULL) {
212 debug(9, 3) ("the final component was a directory\n");
215 debug(9, 3) ("Directory path did not end in /\n");
216 strCat(ftpState->title_url, "/");
217 ftpState->flags.isdir = 1;
218 ! ftpState->flags.use_base = 1;
220 ftpSendPasv(ftpState);
223 debug(9, 3) ("Directory path did not end in /\n");
224 strCat(ftpState->title_url, "/");
225 ftpState->flags.isdir = 1;
226 ! ftpState->flags.dir_slash = 1;
228 ftpSendPasv(ftpState);