author | llornkcor <llornkcor> | 2002-03-24 14:14:49 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-24 14:14:49 (UTC) |
commit | 807ea39f3ccfbc26e769fc16a79d459327e13437 (patch) (unidiff) | |
tree | fa25defd4f0d6f6630cecad2f7eb274dcac30db6 | |
parent | 5c17e8b168cf27ac2922e7c118cb886b116eab42 (diff) | |
download | opie-807ea39f3ccfbc26e769fc16a79d459327e13437.zip opie-807ea39f3ccfbc26e769fc16a79d459327e13437.tar.gz opie-807ea39f3ccfbc26e769fc16a79d459327e13437.tar.bz2 |
radnom fixes
-rw-r--r-- | noncore/net/opieftp/ftplib.c | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 278 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 9 |
3 files changed, 168 insertions, 121 deletions
diff --git a/noncore/net/opieftp/ftplib.c b/noncore/net/opieftp/ftplib.c index b9ca746..5116170 100644 --- a/noncore/net/opieftp/ftplib.c +++ b/noncore/net/opieftp/ftplib.c | |||
@@ -1,1294 +1,1294 @@ | |||
1 | /***************************************************************************/ | 1 | /***************************************************************************/ |
2 | /* ftplib.c - callable ftp access routines */ | 2 | /* ftplib.c - callable ftp access routines */ |
3 | /* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */ | 3 | /* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */ |
4 | /* 73 Catherine Street, South Bound Brook, NJ, 08880 */ | 4 | /* 73 Catherine Street, South Bound Brook, NJ, 08880 */ |
5 | /* */ | 5 | /* */ |
6 | /* This library is free software; you can redistribute it and/or */ | 6 | /* This library is free software; you can redistribute it and/or */ |
7 | /* modify it under the terms of the GNU Library General Public */ | 7 | /* modify it under the terms of the GNU Library General Public */ |
8 | /* License as published by the Free Software Foundation; either */ | 8 | /* License as published by the Free Software Foundation; either */ |
9 | /* version 2 of the License, or (at your option) any later version. */ | 9 | /* version 2 of the License, or (at your option) any later version. */ |
10 | /* */ | 10 | /* */ |
11 | /* This library is distributed in the hope that it will be useful, */ | 11 | /* This library is distributed in the hope that it will be useful, */ |
12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ | 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ |
14 | /* Library General Public License for more details. */ | 14 | /* Library General Public License for more details. */ |
15 | /* */ | 15 | /* */ |
16 | /* You should have received a copy of the GNU Library General Public */ | 16 | /* You should have received a copy of the GNU Library General Public */ |
17 | /* License along with this progam; if not, write to the */ | 17 | /* License along with this progam; if not, write to the */ |
18 | /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ | 18 | /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ |
19 | /* Boston, MA 02111-1307, USA. */ | 19 | /* Boston, MA 02111-1307, USA. */ |
20 | /* */ | 20 | /* */ |
21 | /***************************************************************************/ | 21 | /***************************************************************************/ |
22 | 22 | ||
23 | #if defined(__unix__) || defined(__VMS) | 23 | #if defined(__unix__) || defined(__VMS) |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #endif | 25 | #endif |
26 | #if defined(_WIN32) | 26 | #if defined(_WIN32) |
27 | #include <windows.h> | 27 | #include <windows.h> |
28 | #endif | 28 | #endif |
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #if defined(__unix__) | 34 | #if defined(__unix__) |
35 | #include <sys/time.h> | 35 | #include <sys/time.h> |
36 | #include <sys/types.h> | 36 | #include <sys/types.h> |
37 | #include <sys/socket.h> | 37 | #include <sys/socket.h> |
38 | #include <netinet/in.h> | 38 | #include <netinet/in.h> |
39 | #include <netdb.h> | 39 | #include <netdb.h> |
40 | #include <arpa/inet.h> | 40 | #include <arpa/inet.h> |
41 | #elif defined(VMS) | 41 | #elif defined(VMS) |
42 | #include <types.h> | 42 | #include <types.h> |
43 | #include <socket.h> | 43 | #include <socket.h> |
44 | #include <in.h> | 44 | #include <in.h> |
45 | #include <netdb.h> | 45 | #include <netdb.h> |
46 | #include <inet.h> | 46 | #include <inet.h> |
47 | #elif defined(_WIN32) | 47 | #elif defined(_WIN32) |
48 | #include <winsock.h> | 48 | #include <winsock.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #define BUILDING_LIBRARY | 51 | #define BUILDING_LIBRARY |
52 | #include "ftplib.h" | 52 | #include "ftplib.h" |
53 | 53 | ||
54 | #if defined(_WIN32) | 54 | #if defined(_WIN32) |
55 | #define SETSOCKOPT_OPTVAL_TYPE (const char *) | 55 | #define SETSOCKOPT_OPTVAL_TYPE (const char *) |
56 | #else | 56 | #else |
57 | #define SETSOCKOPT_OPTVAL_TYPE (void *) | 57 | #define SETSOCKOPT_OPTVAL_TYPE (void *) |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | #define FTPLIB_BUFSIZ 8192 | 60 | #define FTPLIB_BUFSIZ 8192 |
61 | #define ACCEPT_TIMEOUT 30 | 61 | #define ACCEPT_TIMEOUT 15 |
62 | 62 | ||
63 | #define FTPLIB_CONTROL 0 | 63 | #define FTPLIB_CONTROL 0 |
64 | #define FTPLIB_READ 1 | 64 | #define FTPLIB_READ 1 |
65 | #define FTPLIB_WRITE 2 | 65 | #define FTPLIB_WRITE 2 |
66 | 66 | ||
67 | #if !defined FTPLIB_DEFMODE | 67 | #if !defined FTPLIB_DEFMODE |
68 | #define FTPLIB_DEFMODE FTPLIB_PASSIVE | 68 | #define FTPLIB_DEFMODE FTPLIB_PASSIVE |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | struct NetBuf { | 71 | struct NetBuf { |
72 | char *cput,*cget; | 72 | char *cput,*cget; |
73 | int handle; | 73 | int handle; |
74 | int cavail,cleft; | 74 | int cavail,cleft; |
75 | char *buf; | 75 | char *buf; |
76 | int dir; | 76 | int dir; |
77 | netbuf *ctrl; | 77 | netbuf *ctrl; |
78 | netbuf *data; | 78 | netbuf *data; |
79 | int cmode; | 79 | int cmode; |
80 | struct timeval idletime; | 80 | struct timeval idletime; |
81 | FtpCallback idlecb; | 81 | FtpCallback idlecb; |
82 | void *idlearg; | 82 | void *idlearg; |
83 | int xfered; | 83 | int xfered; |
84 | int cbbytes; | 84 | int cbbytes; |
85 | int xfered1; | 85 | int xfered1; |
86 | char response[256]; | 86 | char response[256]; |
87 | }; | 87 | }; |
88 | 88 | ||
89 | static char *version = | 89 | static char *version = |
90 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; | 90 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; |
91 | 91 | ||
92 | GLOBALDEF int ftplib_debug = 0; | 92 | GLOBALDEF int ftplib_debug = 0; |
93 | 93 | ||
94 | #if defined(__unix__) || defined(VMS) | 94 | #if defined(__unix__) || defined(VMS) |
95 | #define net_read read | 95 | #define net_read read |
96 | #define net_write write | 96 | #define net_write write |
97 | #define net_close close | 97 | #define net_close close |
98 | #elif defined(_WIN32) | 98 | #elif defined(_WIN32) |
99 | #define net_read(x,y,z) recv(x,y,z,0) | 99 | #define net_read(x,y,z) recv(x,y,z,0) |
100 | #define net_write(x,y,z) send(x,y,z,0) | 100 | #define net_write(x,y,z) send(x,y,z,0) |
101 | #define net_close closesocket | 101 | #define net_close closesocket |
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | #if defined(NEED_MEMCCPY) | 104 | #if defined(NEED_MEMCCPY) |
105 | /* | 105 | /* |
106 | * VAX C does not supply a memccpy routine so I provide my own | 106 | * VAX C does not supply a memccpy routine so I provide my own |
107 | */ | 107 | */ |
108 | void *memccpy(void *dest, const void *src, int c, size_t n) | 108 | void *memccpy(void *dest, const void *src, int c, size_t n) |
109 | { | 109 | { |
110 | int i=0; | 110 | int i=0; |
111 | const unsigned char *ip=src; | 111 | const unsigned char *ip=src; |
112 | unsigned char *op=dest; | 112 | unsigned char *op=dest; |
113 | 113 | ||
114 | while (i < n) | 114 | while (i < n) |
115 | { | 115 | { |
116 | if ((*op++ = *ip++) == c) | 116 | if ((*op++ = *ip++) == c) |
117 | break; | 117 | break; |
118 | i++; | 118 | i++; |
119 | } | 119 | } |
120 | if (i == n) | 120 | if (i == n) |
121 | return NULL; | 121 | return NULL; |
122 | return op; | 122 | return op; |
123 | } | 123 | } |
124 | #endif | 124 | #endif |
125 | #if defined(NEED_STRDUP) | 125 | #if defined(NEED_STRDUP) |
126 | /* | 126 | /* |
127 | * strdup - return a malloc'ed copy of a string | 127 | * strdup - return a malloc'ed copy of a string |
128 | */ | 128 | */ |
129 | char *strdup(const char *src) | 129 | char *strdup(const char *src) |
130 | { | 130 | { |
131 | int l = strlen(src) + 1; | 131 | int l = strlen(src) + 1; |
132 | char *dst = malloc(l); | 132 | char *dst = malloc(l); |
133 | if (dst) | 133 | if (dst) |
134 | strcpy(dst,src); | 134 | strcpy(dst,src); |
135 | return dst; | 135 | return dst; |
136 | } | 136 | } |
137 | #endif | 137 | #endif |
138 | 138 | ||
139 | /* | 139 | /* |
140 | * socket_wait - wait for socket to receive or flush data | 140 | * socket_wait - wait for socket to receive or flush data |
141 | * | 141 | * |
142 | * return 1 if no user callback, otherwise, return value returned by | 142 | * return 1 if no user callback, otherwise, return value returned by |
143 | * user callback | 143 | * user callback |
144 | */ | 144 | */ |
145 | static int socket_wait(netbuf *ctl) | 145 | static int socket_wait(netbuf *ctl) |
146 | { | 146 | { |
147 | fd_set fd,*rfd = NULL,*wfd = NULL; | 147 | fd_set fd,*rfd = NULL,*wfd = NULL; |
148 | struct timeval tv; | 148 | struct timeval tv; |
149 | int rv = 0; | 149 | int rv = 0; |
150 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) | 150 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) |
151 | return 1; | 151 | return 1; |
152 | if (ctl->dir == FTPLIB_WRITE) | 152 | if (ctl->dir == FTPLIB_WRITE) |
153 | wfd = &fd; | 153 | wfd = &fd; |
154 | else | 154 | else |
155 | rfd = &fd; | 155 | rfd = &fd; |
156 | FD_ZERO(&fd); | 156 | FD_ZERO(&fd); |
157 | do | 157 | do |
158 | { | 158 | { |
159 | FD_SET(ctl->handle,&fd); | 159 | FD_SET(ctl->handle,&fd); |
160 | tv = ctl->idletime; | 160 | tv = ctl->idletime; |
161 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); | 161 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); |
162 | if (rv == -1) | 162 | if (rv == -1) |
163 | { | 163 | { |
164 | rv = 0; | 164 | rv = 0; |
165 | strncpy(ctl->ctrl->response, strerror(errno), | 165 | strncpy(ctl->ctrl->response, strerror(errno), |
166 | sizeof(ctl->ctrl->response)); | 166 | sizeof(ctl->ctrl->response)); |
167 | break; | 167 | break; |
168 | } | 168 | } |
169 | else if (rv > 0) | 169 | else if (rv > 0) |
170 | { | 170 | { |
171 | rv = 1; | 171 | rv = 1; |
172 | break; | 172 | break; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); | 175 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); |
176 | return rv; | 176 | return rv; |
177 | } | 177 | } |
178 | 178 | ||
179 | /* | 179 | /* |
180 | * read a line of text | 180 | * read a line of text |
181 | * | 181 | * |
182 | * return -1 on error or bytecount | 182 | * return -1 on error or bytecount |
183 | */ | 183 | */ |
184 | static int readline(char *buf,int max,netbuf *ctl) | 184 | static int readline(char *buf,int max,netbuf *ctl) |
185 | { | 185 | { |
186 | int x,retval = 0; | 186 | int x,retval = 0; |
187 | char *end,*bp=buf; | 187 | char *end,*bp=buf; |
188 | int eof = 0; | 188 | int eof = 0; |
189 | 189 | ||
190 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) | 190 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) |
191 | return -1; | 191 | return -1; |
192 | if (max == 0) | 192 | if (max == 0) |
193 | return 0; | 193 | return 0; |
194 | do | 194 | do |
195 | { | 195 | { |
196 | if (ctl->cavail > 0) | 196 | if (ctl->cavail > 0) |
197 | { | 197 | { |
198 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; | 198 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; |
199 | end = memccpy(bp,ctl->cget,'\n',x); | 199 | end = memccpy(bp,ctl->cget,'\n',x); |
200 | if (end != NULL) | 200 | if (end != NULL) |
201 | x = end - bp; | 201 | x = end - bp; |
202 | retval += x; | 202 | retval += x; |
203 | bp += x; | 203 | bp += x; |
204 | *bp = '\0'; | 204 | *bp = '\0'; |
205 | max -= x; | 205 | max -= x; |
206 | ctl->cget += x; | 206 | ctl->cget += x; |
207 | ctl->cavail -= x; | 207 | ctl->cavail -= x; |
208 | if (end != NULL) | 208 | if (end != NULL) |
209 | { | 209 | { |
210 | bp -= 2; | 210 | bp -= 2; |
211 | if (strcmp(bp,"\r\n") == 0) | 211 | if (strcmp(bp,"\r\n") == 0) |
212 | { | 212 | { |
213 | *bp++ = '\n'; | 213 | *bp++ = '\n'; |
214 | *bp++ = '\0'; | 214 | *bp++ = '\0'; |
215 | --retval; | 215 | --retval; |
216 | } | 216 | } |
217 | break; | 217 | break; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | if (max == 1) | 220 | if (max == 1) |
221 | { | 221 | { |
222 | *buf = '\0'; | 222 | *buf = '\0'; |
223 | break; | 223 | break; |
224 | } | 224 | } |
225 | if (ctl->cput == ctl->cget) | 225 | if (ctl->cput == ctl->cget) |
226 | { | 226 | { |
227 | ctl->cput = ctl->cget = ctl->buf; | 227 | ctl->cput = ctl->cget = ctl->buf; |
228 | ctl->cavail = 0; | 228 | ctl->cavail = 0; |
229 | ctl->cleft = FTPLIB_BUFSIZ; | 229 | ctl->cleft = FTPLIB_BUFSIZ; |
230 | } | 230 | } |
231 | if (eof) | 231 | if (eof) |
232 | { | 232 | { |
233 | if (retval == 0) | 233 | if (retval == 0) |
234 | retval = -1; | 234 | retval = -1; |
235 | break; | 235 | break; |
236 | } | 236 | } |
237 | if (!socket_wait(ctl)) | 237 | if (!socket_wait(ctl)) |
238 | return retval; | 238 | return retval; |
239 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) | 239 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) |
240 | { | 240 | { |
241 | perror("read"); | 241 | perror("read"); |
242 | retval = -1; | 242 | retval = -1; |
243 | break; | 243 | break; |
244 | } | 244 | } |
245 | if (x == 0) | 245 | if (x == 0) |
246 | eof = 1; | 246 | eof = 1; |
247 | ctl->cleft -= x; | 247 | ctl->cleft -= x; |
248 | ctl->cavail += x; | 248 | ctl->cavail += x; |
249 | ctl->cput += x; | 249 | ctl->cput += x; |
250 | } | 250 | } |
251 | while (1); | 251 | while (1); |
252 | return retval; | 252 | return retval; |
253 | } | 253 | } |
254 | 254 | ||
255 | /* | 255 | /* |
256 | * write lines of text | 256 | * write lines of text |
257 | * | 257 | * |
258 | * return -1 on error or bytecount | 258 | * return -1 on error or bytecount |
259 | */ | 259 | */ |
260 | static int writeline(char *buf, int len, netbuf *nData) | 260 | static int writeline(char *buf, int len, netbuf *nData) |
261 | { | 261 | { |
262 | int x, nb=0, w; | 262 | int x, nb=0, w; |
263 | char *ubp = buf, *nbp; | 263 | char *ubp = buf, *nbp; |
264 | char lc=0; | 264 | char lc=0; |
265 | 265 | ||
266 | if (nData->dir != FTPLIB_WRITE) | 266 | if (nData->dir != FTPLIB_WRITE) |
267 | return -1; | 267 | return -1; |
268 | nbp = nData->buf; | 268 | nbp = nData->buf; |
269 | for (x=0; x < len; x++) | 269 | for (x=0; x < len; x++) |
270 | { | 270 | { |
271 | if ((*ubp == '\n') && (lc != '\r')) | 271 | if ((*ubp == '\n') && (lc != '\r')) |
272 | { | 272 | { |
273 | if (nb == FTPLIB_BUFSIZ) | 273 | if (nb == FTPLIB_BUFSIZ) |
274 | { | 274 | { |
275 | if (!socket_wait(nData)) | 275 | if (!socket_wait(nData)) |
276 | return x; | 276 | return x; |
277 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | 277 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); |
278 | if (w != FTPLIB_BUFSIZ) | 278 | if (w != FTPLIB_BUFSIZ) |
279 | { | 279 | { |
280 | printf("net_write(1) returned %d, errno = %d\n", w, errno); | 280 | printf("net_write(1) returned %d, errno = %d\n", w, errno); |
281 | return(-1); | 281 | return(-1); |
282 | } | 282 | } |
283 | nb = 0; | 283 | nb = 0; |
284 | } | 284 | } |
285 | nbp[nb++] = '\r'; | 285 | nbp[nb++] = '\r'; |
286 | } | 286 | } |
287 | if (nb == FTPLIB_BUFSIZ) | 287 | if (nb == FTPLIB_BUFSIZ) |
288 | { | 288 | { |
289 | if (!socket_wait(nData)) | 289 | if (!socket_wait(nData)) |
290 | return x; | 290 | return x; |
291 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | 291 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); |
292 | if (w != FTPLIB_BUFSIZ) | 292 | if (w != FTPLIB_BUFSIZ) |
293 | { | 293 | { |
294 | printf("net_write(2) returned %d, errno = %d\n", w, errno); | 294 | printf("net_write(2) returned %d, errno = %d\n", w, errno); |
295 | return(-1); | 295 | return(-1); |
296 | } | 296 | } |
297 | nb = 0; | 297 | nb = 0; |
298 | } | 298 | } |
299 | nbp[nb++] = lc = *ubp++; | 299 | nbp[nb++] = lc = *ubp++; |
300 | } | 300 | } |
301 | if (nb) | 301 | if (nb) |
302 | { | 302 | { |
303 | if (!socket_wait(nData)) | 303 | if (!socket_wait(nData)) |
304 | return x; | 304 | return x; |
305 | w = net_write(nData->handle, nbp, nb); | 305 | w = net_write(nData->handle, nbp, nb); |
306 | if (w != nb) | 306 | if (w != nb) |
307 | { | 307 | { |
308 | printf("net_write(3) returned %d, errno = %d\n", w, errno); | 308 | printf("net_write(3) returned %d, errno = %d\n", w, errno); |
309 | return(-1); | 309 | return(-1); |
310 | } | 310 | } |
311 | } | 311 | } |
312 | return len; | 312 | return len; |
313 | } | 313 | } |
314 | 314 | ||
315 | /* | 315 | /* |
316 | * read a response from the server | 316 | * read a response from the server |
317 | * | 317 | * |
318 | * return 0 if first char doesn't match | 318 | * return 0 if first char doesn't match |
319 | * return 1 if first char matches | 319 | * return 1 if first char matches |
320 | */ | 320 | */ |
321 | static int readresp(char c, netbuf *nControl) | 321 | static int readresp(char c, netbuf *nControl) |
322 | { | 322 | { |
323 | char match[5]; | 323 | char match[5]; |
324 | if (readline(nControl->response,256,nControl) == -1) | 324 | if (readline(nControl->response,256,nControl) == -1) |
325 | { | 325 | { |
326 | perror("Control socket read failed"); | 326 | perror("Control socket read failed"); |
327 | return 0; | 327 | return 0; |
328 | } | 328 | } |
329 | if (ftplib_debug > 1) | 329 | if (ftplib_debug > 1) |
330 | fprintf(stderr,"%s",nControl->response); | 330 | fprintf(stderr,"%s",nControl->response); |
331 | if (nControl->response[3] == '-') | 331 | if (nControl->response[3] == '-') |
332 | { | 332 | { |
333 | strncpy(match,nControl->response,3); | 333 | strncpy(match,nControl->response,3); |
334 | match[3] = ' '; | 334 | match[3] = ' '; |
335 | match[4] = '\0'; | 335 | match[4] = '\0'; |
336 | do | 336 | do |
337 | { | 337 | { |
338 | if (readline(nControl->response,256,nControl) == -1) | 338 | if (readline(nControl->response,256,nControl) == -1) |
339 | { | 339 | { |
340 | perror("Control socket read failed"); | 340 | perror("Control socket read failed"); |
341 | return 0; | 341 | return 0; |
342 | } | 342 | } |
343 | if (ftplib_debug > 1) | 343 | if (ftplib_debug > 1) |
344 | fprintf(stderr,"%s",nControl->response); | 344 | fprintf(stderr,"%s",nControl->response); |
345 | } | 345 | } |
346 | while (strncmp(nControl->response,match,4)); | 346 | while (strncmp(nControl->response,match,4)); |
347 | } | 347 | } |
348 | if (nControl->response[0] == c) | 348 | if (nControl->response[0] == c) |
349 | return 1; | 349 | return 1; |
350 | return 0; | 350 | return 0; |
351 | } | 351 | } |
352 | 352 | ||
353 | /* | 353 | /* |
354 | * FtpInit for stupid operating systems that require it (Windows NT) | 354 | * FtpInit for stupid operating systems that require it (Windows NT) |
355 | */ | 355 | */ |
356 | GLOBALDEF void FtpInit(void) | 356 | GLOBALDEF void FtpInit(void) |
357 | { | 357 | { |
358 | #if defined(_WIN32) | 358 | #if defined(_WIN32) |
359 | WORD wVersionRequested; | 359 | WORD wVersionRequested; |
360 | WSADATA wsadata; | 360 | WSADATA wsadata; |
361 | int err; | 361 | int err; |
362 | wVersionRequested = MAKEWORD(1,1); | 362 | wVersionRequested = MAKEWORD(1,1); |
363 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) | 363 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) |
364 | fprintf(stderr,"Network failed to start: %d\n",err); | 364 | fprintf(stderr,"Network failed to start: %d\n",err); |
365 | #endif | 365 | #endif |
366 | } | 366 | } |
367 | 367 | ||
368 | /* | 368 | /* |
369 | * FtpLastResponse - return a pointer to the last response received | 369 | * FtpLastResponse - return a pointer to the last response received |
370 | */ | 370 | */ |
371 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) | 371 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) |
372 | { | 372 | { |
373 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) | 373 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) |
374 | return nControl->response; | 374 | return nControl->response; |
375 | return NULL; | 375 | return NULL; |
376 | } | 376 | } |
377 | 377 | ||
378 | /* | 378 | /* |
379 | * FtpConnect - connect to remote server | 379 | * FtpConnect - connect to remote server |
380 | * | 380 | * |
381 | * return 1 if connected, 0 if not | 381 | * return 1 if connected, 0 if not |
382 | */ | 382 | */ |
383 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) | 383 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) |
384 | { | 384 | { |
385 | int sControl; | 385 | int sControl; |
386 | struct sockaddr_in sin; | 386 | struct sockaddr_in sin; |
387 | struct hostent *phe; | 387 | struct hostent *phe; |
388 | struct servent *pse; | 388 | struct servent *pse; |
389 | int on=1; | 389 | int on=1; |
390 | netbuf *ctrl; | 390 | netbuf *ctrl; |
391 | char *lhost; | 391 | char *lhost; |
392 | char *pnum; | 392 | char *pnum; |
393 | 393 | ||
394 | memset(&sin,0,sizeof(sin)); | 394 | memset(&sin,0,sizeof(sin)); |
395 | sin.sin_family = AF_INET; | 395 | sin.sin_family = AF_INET; |
396 | lhost = strdup(host); | 396 | lhost = strdup(host); |
397 | pnum = strchr(lhost,':'); | 397 | pnum = strchr(lhost,':'); |
398 | if (pnum == NULL) | 398 | if (pnum == NULL) |
399 | { | 399 | { |
400 | #if defined(VMS) | 400 | #if defined(VMS) |
401 | sin.sin_port = htons(21); | 401 | sin.sin_port = htons(21); |
402 | #else | 402 | #else |
403 | if ((pse = getservbyname("ftp","tcp")) == NULL) | 403 | if ((pse = getservbyname("ftp","tcp")) == NULL) |
404 | { | 404 | { |
405 | perror("getservbyname"); | 405 | perror("getservbyname"); |
406 | return 0; | 406 | return 0; |
407 | } | 407 | } |
408 | sin.sin_port = pse->s_port; | 408 | sin.sin_port = pse->s_port; |
409 | #endif | 409 | #endif |
410 | } | 410 | } |
411 | else | 411 | else |
412 | { | 412 | { |
413 | *pnum++ = '\0'; | 413 | *pnum++ = '\0'; |
414 | if (isdigit(*pnum)) | 414 | if (isdigit(*pnum)) |
415 | sin.sin_port = htons(atoi(pnum)); | 415 | sin.sin_port = htons(atoi(pnum)); |
416 | else | 416 | else |
417 | { | 417 | { |
418 | pse = getservbyname(pnum,"tcp"); | 418 | pse = getservbyname(pnum,"tcp"); |
419 | sin.sin_port = pse->s_port; | 419 | sin.sin_port = pse->s_port; |
420 | } | 420 | } |
421 | } | 421 | } |
422 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) | 422 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) |
423 | { | 423 | { |
424 | if ((phe = gethostbyname(lhost)) == NULL) | 424 | if ((phe = gethostbyname(lhost)) == NULL) |
425 | { | 425 | { |
426 | perror("gethostbyname"); | 426 | perror("gethostbyname"); |
427 | return 0; | 427 | return 0; |
428 | } | 428 | } |
429 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); | 429 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); |
430 | } | 430 | } |
431 | free(lhost); | 431 | free(lhost); |
432 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); | 432 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
433 | if (sControl == -1) | 433 | if (sControl == -1) |
434 | { | 434 | { |
435 | perror("socket"); | 435 | perror("socket"); |
436 | return 0; | 436 | return 0; |
437 | } | 437 | } |
438 | if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, | 438 | if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, |
439 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) | 439 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) |
440 | { | 440 | { |
441 | perror("setsockopt"); | 441 | perror("setsockopt"); |
442 | net_close(sControl); | 442 | net_close(sControl); |
443 | return 0; | 443 | return 0; |
444 | } | 444 | } |
445 | if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1) | 445 | if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1) |
446 | { | 446 | { |
447 | perror("connect"); | 447 | perror("connect"); |
448 | net_close(sControl); | 448 | net_close(sControl); |
449 | return 0; | 449 | return 0; |
450 | } | 450 | } |
451 | ctrl = calloc(1,sizeof(netbuf)); | 451 | ctrl = calloc(1,sizeof(netbuf)); |
452 | if (ctrl == NULL) | 452 | if (ctrl == NULL) |
453 | { | 453 | { |
454 | perror("calloc"); | 454 | perror("calloc"); |
455 | net_close(sControl); | 455 | net_close(sControl); |
456 | return 0; | 456 | return 0; |
457 | } | 457 | } |
458 | ctrl->buf = malloc(FTPLIB_BUFSIZ); | 458 | ctrl->buf = malloc(FTPLIB_BUFSIZ); |
459 | if (ctrl->buf == NULL) | 459 | if (ctrl->buf == NULL) |
460 | { | 460 | { |
461 | perror("calloc"); | 461 | perror("calloc"); |
462 | net_close(sControl); | 462 | net_close(sControl); |
463 | free(ctrl); | 463 | free(ctrl); |
464 | return 0; | 464 | return 0; |
465 | } | 465 | } |
466 | ctrl->handle = sControl; | 466 | ctrl->handle = sControl; |
467 | ctrl->dir = FTPLIB_CONTROL; | 467 | ctrl->dir = FTPLIB_CONTROL; |
468 | ctrl->ctrl = NULL; | 468 | ctrl->ctrl = NULL; |
469 | ctrl->cmode = FTPLIB_DEFMODE; | 469 | ctrl->cmode = FTPLIB_DEFMODE; |
470 | ctrl->idlecb = NULL; | 470 | ctrl->idlecb = NULL; |
471 | ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; | 471 | ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; |
472 | ctrl->idlearg = NULL; | 472 | ctrl->idlearg = NULL; |
473 | ctrl->xfered = 0; | 473 | ctrl->xfered = 0; |
474 | ctrl->xfered1 = 0; | 474 | ctrl->xfered1 = 0; |
475 | ctrl->cbbytes = 0; | 475 | ctrl->cbbytes = 0; |
476 | if (readresp('2', ctrl) == 0) | 476 | if (readresp('2', ctrl) == 0) |
477 | { | 477 | { |
478 | net_close(sControl); | 478 | net_close(sControl); |
479 | free(ctrl->buf); | 479 | free(ctrl->buf); |
480 | free(ctrl); | 480 | free(ctrl); |
481 | return 0; | 481 | return 0; |
482 | } | 482 | } |
483 | *nControl = ctrl; | 483 | *nControl = ctrl; |
484 | return 1; | 484 | return 1; |
485 | } | 485 | } |
486 | 486 | ||
487 | /* | 487 | /* |
488 | * FtpOptions - change connection options | 488 | * FtpOptions - change connection options |
489 | * | 489 | * |
490 | * returns 1 if successful, 0 on error | 490 | * returns 1 if successful, 0 on error |
491 | */ | 491 | */ |
492 | GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) | 492 | GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) |
493 | { | 493 | { |
494 | int v,rv=0; | 494 | int v,rv=0; |
495 | switch (opt) | 495 | switch (opt) |
496 | { | 496 | { |
497 | case FTPLIB_CONNMODE: | 497 | case FTPLIB_CONNMODE: |
498 | v = (int) val; | 498 | v = (int) val; |
499 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) | 499 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) |
500 | { | 500 | { |
501 | nControl->cmode = v; | 501 | nControl->cmode = v; |
502 | rv = 1; | 502 | rv = 1; |
503 | } | 503 | } |
504 | break; | 504 | break; |
505 | case FTPLIB_CALLBACK: | 505 | case FTPLIB_CALLBACK: |
506 | nControl->idlecb = (FtpCallback) val; | 506 | nControl->idlecb = (FtpCallback) val; |
507 | rv = 1; | 507 | rv = 1; |
508 | break; | 508 | break; |
509 | case FTPLIB_IDLETIME: | 509 | case FTPLIB_IDLETIME: |
510 | v = (int) val; | 510 | v = (int) val; |
511 | rv = 1; | 511 | rv = 1; |
512 | nControl->idletime.tv_sec = v / 1000; | 512 | nControl->idletime.tv_sec = v / 1000; |
513 | nControl->idletime.tv_usec = (v % 1000) * 1000; | 513 | nControl->idletime.tv_usec = (v % 1000) * 1000; |
514 | break; | 514 | break; |
515 | case FTPLIB_CALLBACKARG: | 515 | case FTPLIB_CALLBACKARG: |
516 | rv = 1; | 516 | rv = 1; |
517 | nControl->idlearg = (void *) val; | 517 | nControl->idlearg = (void *) val; |
518 | break; | 518 | break; |
519 | case FTPLIB_CALLBACKBYTES: | 519 | case FTPLIB_CALLBACKBYTES: |
520 | rv = 1; | 520 | rv = 1; |
521 | nControl->cbbytes = (int) val; | 521 | nControl->cbbytes = (int) val; |
522 | break; | 522 | break; |
523 | } | 523 | } |
524 | return rv; | 524 | return rv; |
525 | } | 525 | } |
526 | 526 | ||
527 | /* | 527 | /* |
528 | * FtpSendCmd - send a command and wait for expected response | 528 | * FtpSendCmd - send a command and wait for expected response |
529 | * | 529 | * |
530 | * return 1 if proper response received, 0 otherwise | 530 | * return 1 if proper response received, 0 otherwise |
531 | */ | 531 | */ |
532 | static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) | 532 | static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) |
533 | { | 533 | { |
534 | char buf[256]; | 534 | char buf[256]; |
535 | if (nControl->dir != FTPLIB_CONTROL) | 535 | if (nControl->dir != FTPLIB_CONTROL) |
536 | return 0; | 536 | return 0; |
537 | if (ftplib_debug > 2) | 537 | if (ftplib_debug > 2) |
538 | fprintf(stderr,"%s\n",cmd); | 538 | fprintf(stderr,"%s\n",cmd); |
539 | if ((strlen(cmd) + 3) > sizeof(buf)) | 539 | if ((strlen(cmd) + 3) > sizeof(buf)) |
540 | return 0; | 540 | return 0; |
541 | sprintf(buf,"%s\r\n",cmd); | 541 | sprintf(buf,"%s\r\n",cmd); |
542 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) | 542 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) |
543 | { | 543 | { |
544 | perror("write"); | 544 | perror("write"); |
545 | return 0; | 545 | return 0; |
546 | } | 546 | } |
547 | return readresp(expresp, nControl); | 547 | return readresp(expresp, nControl); |
548 | } | 548 | } |
549 | 549 | ||
550 | /* | 550 | /* |
551 | * FtpLogin - log in to remote server | 551 | * FtpLogin - log in to remote server |
552 | * | 552 | * |
553 | * return 1 if logged in, 0 otherwise | 553 | * return 1 if logged in, 0 otherwise |
554 | */ | 554 | */ |
555 | GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) | 555 | GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) |
556 | { | 556 | { |
557 | char tempbuf[64]; | 557 | char tempbuf[64]; |
558 | 558 | ||
559 | if (((strlen(user) + 7) > sizeof(tempbuf)) || | 559 | if (((strlen(user) + 7) > sizeof(tempbuf)) || |
560 | ((strlen(pass) + 7) > sizeof(tempbuf))) | 560 | ((strlen(pass) + 7) > sizeof(tempbuf))) |
561 | return 0; | 561 | return 0; |
562 | sprintf(tempbuf,"USER %s",user); | 562 | sprintf(tempbuf,"USER %s",user); |
563 | if (!FtpSendCmd(tempbuf,'3',nControl)) | 563 | if (!FtpSendCmd(tempbuf,'3',nControl)) |
564 | { | 564 | { |
565 | if (nControl->response[0] == '2') | 565 | if (nControl->response[0] == '2') |
566 | return 1; | 566 | return 1; |
567 | return 0; | 567 | return 0; |
568 | } | 568 | } |
569 | sprintf(tempbuf,"PASS %s",pass); | 569 | sprintf(tempbuf,"PASS %s",pass); |
570 | return FtpSendCmd(tempbuf,'2',nControl); | 570 | return FtpSendCmd(tempbuf,'2',nControl); |
571 | } | 571 | } |
572 | 572 | ||
573 | /* | 573 | /* |
574 | * FtpOpenPort - set up data connection | 574 | * FtpOpenPort - set up data connection |
575 | * | 575 | * |
576 | * return 1 if successful, 0 otherwise | 576 | * return 1 if successful, 0 otherwise |
577 | */ | 577 | */ |
578 | static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) | 578 | static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) |
579 | { | 579 | { |
580 | int sData; | 580 | int sData; |
581 | union { | 581 | union { |
582 | struct sockaddr sa; | 582 | struct sockaddr sa; |
583 | struct sockaddr_in in; | 583 | struct sockaddr_in in; |
584 | } sin; | 584 | } sin; |
585 | struct linger lng = { 0, 0 }; | 585 | struct linger lng = { 0, 0 }; |
586 | unsigned int l; | 586 | unsigned int l; |
587 | int on=1; | 587 | int on=1; |
588 | netbuf *ctrl; | 588 | netbuf *ctrl; |
589 | char *cp; | 589 | char *cp; |
590 | unsigned int v[6]; | 590 | unsigned int v[6]; |
591 | char buf[256]; | 591 | char buf[256]; |
592 | 592 | ||
593 | if (nControl->dir != FTPLIB_CONTROL) | 593 | if (nControl->dir != FTPLIB_CONTROL) |
594 | return -1; | 594 | return -1; |
595 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) | 595 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) |
596 | { | 596 | { |
597 | sprintf(nControl->response, "Invalid direction %d\n", dir); | 597 | sprintf(nControl->response, "Invalid direction %d\n", dir); |
598 | return -1; | 598 | return -1; |
599 | } | 599 | } |
600 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) | 600 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) |
601 | { | 601 | { |
602 | sprintf(nControl->response, "Invalid mode %c\n", mode); | 602 | sprintf(nControl->response, "Invalid mode %c\n", mode); |
603 | return -1; | 603 | return -1; |
604 | } | 604 | } |
605 | l = sizeof(sin); | 605 | l = sizeof(sin); |
606 | if (nControl->cmode == FTPLIB_PASSIVE) | 606 | if (nControl->cmode == FTPLIB_PASSIVE) |
607 | { | 607 | { |
608 | memset(&sin, 0, l); | 608 | memset(&sin, 0, l); |
609 | sin.in.sin_family = AF_INET; | 609 | sin.in.sin_family = AF_INET; |
610 | if (!FtpSendCmd("PASV",'2',nControl)) | 610 | if (!FtpSendCmd("PASV",'2',nControl)) |
611 | return -1; | 611 | return -1; |
612 | cp = strchr(nControl->response,'('); | 612 | cp = strchr(nControl->response,'('); |
613 | if (cp == NULL) | 613 | if (cp == NULL) |
614 | return -1; | 614 | return -1; |
615 | cp++; | 615 | cp++; |
616 | sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); | 616 | sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); |
617 | sin.sa.sa_data[2] = v[2]; | 617 | sin.sa.sa_data[2] = v[2]; |
618 | sin.sa.sa_data[3] = v[3]; | 618 | sin.sa.sa_data[3] = v[3]; |
619 | sin.sa.sa_data[4] = v[4]; | 619 | sin.sa.sa_data[4] = v[4]; |
620 | sin.sa.sa_data[5] = v[5]; | 620 | sin.sa.sa_data[5] = v[5]; |
621 | sin.sa.sa_data[0] = v[0]; | 621 | sin.sa.sa_data[0] = v[0]; |
622 | sin.sa.sa_data[1] = v[1]; | 622 | sin.sa.sa_data[1] = v[1]; |
623 | } | 623 | } |
624 | else | 624 | else |
625 | { | 625 | { |
626 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) | 626 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) |
627 | { | 627 | { |
628 | perror("getsockname"); | 628 | perror("getsockname"); |
629 | return 0; | 629 | return 0; |
630 | } | 630 | } |
631 | } | 631 | } |
632 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); | 632 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); |
633 | if (sData == -1) | 633 | if (sData == -1) |
634 | { | 634 | { |
635 | perror("socket"); | 635 | perror("socket"); |
636 | return -1; | 636 | return -1; |
637 | } | 637 | } |
638 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, | 638 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, |
639 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) | 639 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) |
640 | { | 640 | { |
641 | perror("setsockopt"); | 641 | perror("setsockopt"); |
642 | net_close(sData); | 642 | net_close(sData); |
643 | return -1; | 643 | return -1; |
644 | } | 644 | } |
645 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, | 645 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, |
646 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) | 646 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) |
647 | { | 647 | { |
648 | perror("setsockopt"); | 648 | perror("setsockopt"); |
649 | net_close(sData); | 649 | net_close(sData); |
650 | return -1; | 650 | return -1; |
651 | } | 651 | } |
652 | if (nControl->cmode == FTPLIB_PASSIVE) | 652 | if (nControl->cmode == FTPLIB_PASSIVE) |
653 | { | 653 | { |
654 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) | 654 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) |
655 | { | 655 | { |
656 | perror("connect"); | 656 | perror("connect"); |
657 | net_close(sData); | 657 | net_close(sData); |
658 | return -1; | 658 | return -1; |
659 | } | 659 | } |
660 | } | 660 | } |
661 | else | 661 | else |
662 | { | 662 | { |
663 | sin.in.sin_port = 0; | 663 | sin.in.sin_port = 0; |
664 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) | 664 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) |
665 | { | 665 | { |
666 | perror("bind"); | 666 | perror("bind"); |
667 | net_close(sData); | 667 | net_close(sData); |
668 | return 0; | 668 | return 0; |
669 | } | 669 | } |
670 | if (listen(sData, 1) < 0) | 670 | if (listen(sData, 1) < 0) |
671 | { | 671 | { |
672 | perror("listen"); | 672 | perror("listen"); |
673 | net_close(sData); | 673 | net_close(sData); |
674 | return 0; | 674 | return 0; |
675 | } | 675 | } |
676 | if (getsockname(sData, &sin.sa, &l) < 0) | 676 | if (getsockname(sData, &sin.sa, &l) < 0) |
677 | return 0; | 677 | return 0; |
678 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", | 678 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", |
679 | (unsigned char) sin.sa.sa_data[2], | 679 | (unsigned char) sin.sa.sa_data[2], |
680 | (unsigned char) sin.sa.sa_data[3], | 680 | (unsigned char) sin.sa.sa_data[3], |
681 | (unsigned char) sin.sa.sa_data[4], | 681 | (unsigned char) sin.sa.sa_data[4], |
682 | (unsigned char) sin.sa.sa_data[5], | 682 | (unsigned char) sin.sa.sa_data[5], |
683 | (unsigned char) sin.sa.sa_data[0], | 683 | (unsigned char) sin.sa.sa_data[0], |
684 | (unsigned char) sin.sa.sa_data[1]); | 684 | (unsigned char) sin.sa.sa_data[1]); |
685 | if (!FtpSendCmd(buf,'2',nControl)) | 685 | if (!FtpSendCmd(buf,'2',nControl)) |
686 | { | 686 | { |
687 | net_close(sData); | 687 | net_close(sData); |
688 | return 0; | 688 | return 0; |
689 | } | 689 | } |
690 | } | 690 | } |
691 | ctrl = calloc(1,sizeof(netbuf)); | 691 | ctrl = calloc(1,sizeof(netbuf)); |
692 | if (ctrl == NULL) | 692 | if (ctrl == NULL) |
693 | { | 693 | { |
694 | perror("calloc"); | 694 | perror("calloc"); |
695 | net_close(sData); | 695 | net_close(sData); |
696 | return -1; | 696 | return -1; |
697 | } | 697 | } |
698 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) | 698 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) |
699 | { | 699 | { |
700 | perror("calloc"); | 700 | perror("calloc"); |
701 | net_close(sData); | 701 | net_close(sData); |
702 | free(ctrl); | 702 | free(ctrl); |
703 | return -1; | 703 | return -1; |
704 | } | 704 | } |
705 | ctrl->handle = sData; | 705 | ctrl->handle = sData; |
706 | ctrl->dir = dir; | 706 | ctrl->dir = dir; |
707 | ctrl->idletime = nControl->idletime; | 707 | ctrl->idletime = nControl->idletime; |
708 | ctrl->idlearg = nControl->idlearg; | 708 | ctrl->idlearg = nControl->idlearg; |
709 | ctrl->xfered = 0; | 709 | ctrl->xfered = 0; |
710 | ctrl->xfered1 = 0; | 710 | ctrl->xfered1 = 0; |
711 | ctrl->cbbytes = nControl->cbbytes; | 711 | ctrl->cbbytes = nControl->cbbytes; |
712 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) | 712 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) |
713 | ctrl->idlecb = nControl->idlecb; | 713 | ctrl->idlecb = nControl->idlecb; |
714 | else | 714 | else |
715 | ctrl->idlecb = NULL; | 715 | ctrl->idlecb = NULL; |
716 | *nData = ctrl; | 716 | *nData = ctrl; |
717 | return 1; | 717 | return 1; |
718 | } | 718 | } |
719 | 719 | ||
720 | /* | 720 | /* |
721 | * FtpAcceptConnection - accept connection from server | 721 | * FtpAcceptConnection - accept connection from server |
722 | * | 722 | * |
723 | * return 1 if successful, 0 otherwise | 723 | * return 1 if successful, 0 otherwise |
724 | */ | 724 | */ |
725 | static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) | 725 | static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) |
726 | { | 726 | { |
727 | int sData; | 727 | int sData; |
728 | struct sockaddr addr; | 728 | struct sockaddr addr; |
729 | unsigned int l; | 729 | unsigned int l; |
730 | int i; | 730 | int i; |
731 | struct timeval tv; | 731 | struct timeval tv; |
732 | fd_set mask; | 732 | fd_set mask; |
733 | int rv; | 733 | int rv; |
734 | 734 | ||
735 | FD_ZERO(&mask); | 735 | FD_ZERO(&mask); |
736 | FD_SET(nControl->handle, &mask); | 736 | FD_SET(nControl->handle, &mask); |
737 | FD_SET(nData->handle, &mask); | 737 | FD_SET(nData->handle, &mask); |
738 | tv.tv_usec = 0; | 738 | tv.tv_usec = 0; |
739 | tv.tv_sec = ACCEPT_TIMEOUT; | 739 | tv.tv_sec = ACCEPT_TIMEOUT; |
740 | i = nControl->handle; | 740 | i = nControl->handle; |
741 | if (i < nData->handle) | 741 | if (i < nData->handle) |
742 | i = nData->handle; | 742 | i = nData->handle; |
743 | i = select(i+1, &mask, NULL, NULL, &tv); | 743 | i = select(i+1, &mask, NULL, NULL, &tv); |
744 | if (i == -1) | 744 | if (i == -1) |
745 | { | 745 | { |
746 | strncpy(nControl->response, strerror(errno), | 746 | strncpy(nControl->response, strerror(errno), |
747 | sizeof(nControl->response)); | 747 | sizeof(nControl->response)); |
748 | net_close(nData->handle); | 748 | net_close(nData->handle); |
749 | nData->handle = 0; | 749 | nData->handle = 0; |
750 | rv = 0; | 750 | rv = 0; |
751 | } | 751 | } |
752 | else if (i == 0) | 752 | else if (i == 0) |
753 | { | 753 | { |
754 | strcpy(nControl->response, "timed out waiting for connection"); | 754 | strcpy(nControl->response, "timed out waiting for connection"); |
755 | net_close(nData->handle); | 755 | net_close(nData->handle); |
756 | nData->handle = 0; | 756 | nData->handle = 0; |
757 | rv = 0; | 757 | rv = 0; |
758 | } | 758 | } |
759 | else | 759 | else |
760 | { | 760 | { |
761 | if (FD_ISSET(nData->handle, &mask)) | 761 | if (FD_ISSET(nData->handle, &mask)) |
762 | { | 762 | { |
763 | l = sizeof(addr); | 763 | l = sizeof(addr); |
764 | sData = accept(nData->handle, &addr, &l); | 764 | sData = accept(nData->handle, &addr, &l); |
765 | i = errno; | 765 | i = errno; |
766 | net_close(nData->handle); | 766 | net_close(nData->handle); |
767 | if (sData > 0) | 767 | if (sData > 0) |
768 | { | 768 | { |
769 | rv = 1; | 769 | rv = 1; |
770 | nData->handle = sData; | 770 | nData->handle = sData; |
771 | } | 771 | } |
772 | else | 772 | else |
773 | { | 773 | { |
774 | strncpy(nControl->response, strerror(i), | 774 | strncpy(nControl->response, strerror(i), |
775 | sizeof(nControl->response)); | 775 | sizeof(nControl->response)); |
776 | nData->handle = 0; | 776 | nData->handle = 0; |
777 | rv = 0; | 777 | rv = 0; |
778 | } | 778 | } |
779 | } | 779 | } |
780 | else if (FD_ISSET(nControl->handle, &mask)) | 780 | else if (FD_ISSET(nControl->handle, &mask)) |
781 | { | 781 | { |
782 | net_close(nData->handle); | 782 | net_close(nData->handle); |
783 | nData->handle = 0; | 783 | nData->handle = 0; |
784 | readresp('2', nControl); | 784 | readresp('2', nControl); |
785 | rv = 0; | 785 | rv = 0; |
786 | } | 786 | } |
787 | } | 787 | } |
788 | return rv; | 788 | return rv; |
789 | } | 789 | } |
790 | 790 | ||
791 | /* | 791 | /* |
792 | * FtpAccess - return a handle for a data stream | 792 | * FtpAccess - return a handle for a data stream |
793 | * | 793 | * |
794 | * return 1 if successful, 0 otherwise | 794 | * return 1 if successful, 0 otherwise |
795 | */ | 795 | */ |
796 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, | 796 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, |
797 | netbuf **nData) | 797 | netbuf **nData) |
798 | { | 798 | { |
799 | char buf[256]; | 799 | char buf[256]; |
800 | int dir; | 800 | int dir; |
801 | if ((path == NULL) && | 801 | if ((path == NULL) && |
802 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) | 802 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) |
803 | { | 803 | { |
804 | sprintf(nControl->response, | 804 | sprintf(nControl->response, |
805 | "Missing path argument for file transfer\n"); | 805 | "Missing path argument for file transfer\n"); |
806 | return 0; | 806 | return 0; |
807 | } | 807 | } |
808 | sprintf(buf, "TYPE %c", mode); | 808 | sprintf(buf, "TYPE %c", mode); |
809 | if (!FtpSendCmd(buf, '2', nControl)) | 809 | if (!FtpSendCmd(buf, '2', nControl)) |
810 | return 0; | 810 | return 0; |
811 | switch (typ) | 811 | switch (typ) |
812 | { | 812 | { |
813 | case FTPLIB_DIR: | 813 | case FTPLIB_DIR: |
814 | strcpy(buf,"NLST"); | 814 | strcpy(buf,"NLST"); |
815 | dir = FTPLIB_READ; | 815 | dir = FTPLIB_READ; |
816 | break; | 816 | break; |
817 | case FTPLIB_DIR_VERBOSE: | 817 | case FTPLIB_DIR_VERBOSE: |
818 | strcpy(buf,"LIST"); | 818 | strcpy(buf,"LIST"); |
819 | dir = FTPLIB_READ; | 819 | dir = FTPLIB_READ; |
820 | break; | 820 | break; |
821 | case FTPLIB_FILE_READ: | 821 | case FTPLIB_FILE_READ: |
822 | strcpy(buf,"RETR"); | 822 | strcpy(buf,"RETR"); |
823 | dir = FTPLIB_READ; | 823 | dir = FTPLIB_READ; |
824 | break; | 824 | break; |
825 | case FTPLIB_FILE_WRITE: | 825 | case FTPLIB_FILE_WRITE: |
826 | strcpy(buf,"STOR"); | 826 | strcpy(buf,"STOR"); |
827 | dir = FTPLIB_WRITE; | 827 | dir = FTPLIB_WRITE; |
828 | break; | 828 | break; |
829 | default: | 829 | default: |
830 | sprintf(nControl->response, "Invalid open type %d\n", typ); | 830 | sprintf(nControl->response, "Invalid open type %d\n", typ); |
831 | return 0; | 831 | return 0; |
832 | } | 832 | } |
833 | if (path != NULL) | 833 | if (path != NULL) |
834 | { | 834 | { |
835 | int i = strlen(buf); | 835 | int i = strlen(buf); |
836 | buf[i++] = ' '; | 836 | buf[i++] = ' '; |
837 | if ((strlen(path) + i) >= sizeof(buf)) | 837 | if ((strlen(path) + i) >= sizeof(buf)) |
838 | return 0; | 838 | return 0; |
839 | strcpy(&buf[i],path); | 839 | strcpy(&buf[i],path); |
840 | } | 840 | } |
841 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) | 841 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) |
842 | return 0; | 842 | return 0; |
843 | if (!FtpSendCmd(buf, '1', nControl)) | 843 | if (!FtpSendCmd(buf, '1', nControl)) |
844 | { | 844 | { |
845 | FtpClose(*nData); | 845 | FtpClose(*nData); |
846 | *nData = NULL; | 846 | *nData = NULL; |
847 | return 0; | 847 | return 0; |
848 | } | 848 | } |
849 | (*nData)->ctrl = nControl; | 849 | (*nData)->ctrl = nControl; |
850 | nControl->data = *nData; | 850 | nControl->data = *nData; |
851 | if (nControl->cmode == FTPLIB_PORT) | 851 | if (nControl->cmode == FTPLIB_PORT) |
852 | { | 852 | { |
853 | if (!FtpAcceptConnection(*nData,nControl)) | 853 | if (!FtpAcceptConnection(*nData,nControl)) |
854 | { | 854 | { |
855 | FtpClose(*nData); | 855 | FtpClose(*nData); |
856 | *nData = NULL; | 856 | *nData = NULL; |
857 | nControl->data = NULL; | 857 | nControl->data = NULL; |
858 | return 0; | 858 | return 0; |
859 | } | 859 | } |
860 | } | 860 | } |
861 | return 1; | 861 | return 1; |
862 | } | 862 | } |
863 | 863 | ||
864 | /* | 864 | /* |
865 | * FtpRead - read from a data connection | 865 | * FtpRead - read from a data connection |
866 | */ | 866 | */ |
867 | GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) | 867 | GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) |
868 | { | 868 | { |
869 | int i; | 869 | int i; |
870 | if (nData->dir != FTPLIB_READ) | 870 | if (nData->dir != FTPLIB_READ) |
871 | return 0; | 871 | return 0; |
872 | if (nData->buf) | 872 | if (nData->buf) |
873 | i = readline(buf, max, nData); | 873 | i = readline(buf, max, nData); |
874 | else | 874 | else |
875 | { | 875 | { |
876 | i = socket_wait(nData); | 876 | i = socket_wait(nData); |
877 | if (i != 1) | 877 | if (i != 1) |
878 | return 0; | 878 | return 0; |
879 | i = net_read(nData->handle, buf, max); | 879 | i = net_read(nData->handle, buf, max); |
880 | } | 880 | } |
881 | if (i == -1) | 881 | if (i == -1) |
882 | return 0; | 882 | return 0; |
883 | nData->xfered += i; | 883 | nData->xfered += i; |
884 | if (nData->idlecb && nData->cbbytes) | 884 | if (nData->idlecb && nData->cbbytes) |
885 | { | 885 | { |
886 | nData->xfered1 += i; | 886 | nData->xfered1 += i; |
887 | if (nData->xfered1 > nData->cbbytes) | 887 | if (nData->xfered1 > nData->cbbytes) |
888 | { | 888 | { |
889 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) | 889 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) |
890 | return 0; | 890 | return 0; |
891 | nData->xfered1 = 0; | 891 | nData->xfered1 = 0; |
892 | } | 892 | } |
893 | } | 893 | } |
894 | return i; | 894 | return i; |
895 | } | 895 | } |
896 | 896 | ||
897 | /* | 897 | /* |
898 | * FtpWrite - write to a data connection | 898 | * FtpWrite - write to a data connection |
899 | */ | 899 | */ |
900 | GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) | 900 | GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) |
901 | { | 901 | { |
902 | int i; | 902 | int i; |
903 | if (nData->dir != FTPLIB_WRITE) | 903 | if (nData->dir != FTPLIB_WRITE) |
904 | return 0; | 904 | return 0; |
905 | if (nData->buf) | 905 | if (nData->buf) |
906 | i = writeline(buf, len, nData); | 906 | i = writeline(buf, len, nData); |
907 | else | 907 | else |
908 | { | 908 | { |
909 | socket_wait(nData); | 909 | socket_wait(nData); |
910 | i = net_write(nData->handle, buf, len); | 910 | i = net_write(nData->handle, buf, len); |
911 | } | 911 | } |
912 | if (i == -1) | 912 | if (i == -1) |
913 | return 0; | 913 | return 0; |
914 | nData->xfered += i; | 914 | nData->xfered += i; |
915 | if (nData->idlecb && nData->cbbytes) | 915 | if (nData->idlecb && nData->cbbytes) |
916 | { | 916 | { |
917 | nData->xfered1 += i; | 917 | nData->xfered1 += i; |
918 | if (nData->xfered1 > nData->cbbytes) | 918 | if (nData->xfered1 > nData->cbbytes) |
919 | { | 919 | { |
920 | nData->idlecb(nData, nData->xfered, nData->idlearg); | 920 | nData->idlecb(nData, nData->xfered, nData->idlearg); |
921 | nData->xfered1 = 0; | 921 | nData->xfered1 = 0; |
922 | } | 922 | } |
923 | } | 923 | } |
924 | return i; | 924 | return i; |
925 | } | 925 | } |
926 | 926 | ||
927 | /* | 927 | /* |
928 | * FtpClose - close a data connection | 928 | * FtpClose - close a data connection |
929 | */ | 929 | */ |
930 | GLOBALDEF int FtpClose(netbuf *nData) | 930 | GLOBALDEF int FtpClose(netbuf *nData) |
931 | { | 931 | { |
932 | netbuf *ctrl; | 932 | netbuf *ctrl; |
933 | switch (nData->dir) | 933 | switch (nData->dir) |
934 | { | 934 | { |
935 | case FTPLIB_WRITE: | 935 | case FTPLIB_WRITE: |
936 | /* potential problem - if buffer flush fails, how to notify user? */ | 936 | /* potential problem - if buffer flush fails, how to notify user? */ |
937 | if (nData->buf != NULL) | 937 | if (nData->buf != NULL) |
938 | writeline(NULL, 0, nData); | 938 | writeline(NULL, 0, nData); |
939 | case FTPLIB_READ: | 939 | case FTPLIB_READ: |
940 | if (nData->buf) | 940 | if (nData->buf) |
941 | free(nData->buf); | 941 | free(nData->buf); |
942 | shutdown(nData->handle,2); | 942 | shutdown(nData->handle,2); |
943 | net_close(nData->handle); | 943 | net_close(nData->handle); |
944 | ctrl = nData->ctrl; | 944 | ctrl = nData->ctrl; |
945 | free(nData); | 945 | free(nData); |
946 | if (ctrl) | 946 | if (ctrl) |
947 | { | 947 | { |
948 | ctrl->data = NULL; | 948 | ctrl->data = NULL; |
949 | return(readresp('2', ctrl)); | 949 | return(readresp('2', ctrl)); |
950 | } | 950 | } |
951 | return 1; | 951 | return 1; |
952 | case FTPLIB_CONTROL: | 952 | case FTPLIB_CONTROL: |
953 | if (nData->data) | 953 | if (nData->data) |
954 | { | 954 | { |
955 | nData->ctrl = NULL; | 955 | nData->ctrl = NULL; |
956 | FtpClose(nData); | 956 | FtpClose(nData); |
957 | } | 957 | } |
958 | net_close(nData->handle); | 958 | net_close(nData->handle); |
959 | free(nData); | 959 | free(nData); |
960 | return 0; | 960 | return 0; |
961 | } | 961 | } |
962 | return 1; | 962 | return 1; |
963 | } | 963 | } |
964 | 964 | ||
965 | /* | 965 | /* |
966 | * FtpSite - send a SITE command | 966 | * FtpSite - send a SITE command |
967 | * | 967 | * |
968 | * return 1 if command successful, 0 otherwise | 968 | * return 1 if command successful, 0 otherwise |
969 | */ | 969 | */ |
970 | GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) | 970 | GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) |
971 | { | 971 | { |
972 | char buf[256]; | 972 | char buf[256]; |
973 | 973 | ||
974 | if ((strlen(cmd) + 7) > sizeof(buf)) | 974 | if ((strlen(cmd) + 7) > sizeof(buf)) |
975 | return 0; | 975 | return 0; |
976 | sprintf(buf,"SITE %s",cmd); | 976 | sprintf(buf,"SITE %s",cmd); |
977 | if (!FtpSendCmd(buf,'2',nControl)) | 977 | if (!FtpSendCmd(buf,'2',nControl)) |
978 | return 0; | 978 | return 0; |
979 | return 1; | 979 | return 1; |
980 | } | 980 | } |
981 | 981 | ||
982 | /* | 982 | /* |
983 | * FtpSysType - send a SYST command | 983 | * FtpSysType - send a SYST command |
984 | * | 984 | * |
985 | * Fills in the user buffer with the remote system type. If more | 985 | * Fills in the user buffer with the remote system type. If more |
986 | * information from the response is required, the user can parse | 986 | * information from the response is required, the user can parse |
987 | * it out of the response buffer returned by FtpLastResponse(). | 987 | * it out of the response buffer returned by FtpLastResponse(). |
988 | * | 988 | * |
989 | * return 1 if command successful, 0 otherwise | 989 | * return 1 if command successful, 0 otherwise |
990 | */ | 990 | */ |
991 | GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) | 991 | GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) |
992 | { | 992 | { |
993 | int l = max; | 993 | int l = max; |
994 | char *b = buf; | 994 | char *b = buf; |
995 | char *s; | 995 | char *s; |
996 | if (!FtpSendCmd("SYST",'2',nControl)) | 996 | if (!FtpSendCmd("SYST",'2',nControl)) |
997 | return 0; | 997 | return 0; |
998 | s = &nControl->response[4]; | 998 | s = &nControl->response[4]; |
999 | while ((--l) && (*s != ' ')) | 999 | while ((--l) && (*s != ' ')) |
1000 | *b++ = *s++; | 1000 | *b++ = *s++; |
1001 | *b++ = '\0'; | 1001 | *b++ = '\0'; |
1002 | return 1; | 1002 | return 1; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | /* | 1005 | /* |
1006 | * FtpMkdir - create a directory at server | 1006 | * FtpMkdir - create a directory at server |
1007 | * | 1007 | * |
1008 | * return 1 if successful, 0 otherwise | 1008 | * return 1 if successful, 0 otherwise |
1009 | */ | 1009 | */ |
1010 | GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) | 1010 | GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) |
1011 | { | 1011 | { |
1012 | char buf[256]; | 1012 | char buf[256]; |
1013 | 1013 | ||
1014 | if ((strlen(path) + 6) > sizeof(buf)) | 1014 | if ((strlen(path) + 6) > sizeof(buf)) |
1015 | return 0; | 1015 | return 0; |
1016 | sprintf(buf,"MKD %s",path); | 1016 | sprintf(buf,"MKD %s",path); |
1017 | if (!FtpSendCmd(buf,'2', nControl)) | 1017 | if (!FtpSendCmd(buf,'2', nControl)) |
1018 | return 0; | 1018 | return 0; |
1019 | return 1; | 1019 | return 1; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | /* | 1022 | /* |
1023 | * FtpChdir - change path at remote | 1023 | * FtpChdir - change path at remote |
1024 | * | 1024 | * |
1025 | * return 1 if successful, 0 otherwise | 1025 | * return 1 if successful, 0 otherwise |
1026 | */ | 1026 | */ |
1027 | GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) | 1027 | GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) |
1028 | { | 1028 | { |
1029 | char buf[256]; | 1029 | char buf[256]; |
1030 | 1030 | ||
1031 | if ((strlen(path) + 6) > sizeof(buf)) | 1031 | if ((strlen(path) + 6) > sizeof(buf)) |
1032 | return 0; | 1032 | return 0; |
1033 | sprintf(buf,"CWD %s",path); | 1033 | sprintf(buf,"CWD %s",path); |
1034 | if (!FtpSendCmd(buf,'2',nControl)) | 1034 | if (!FtpSendCmd(buf,'2',nControl)) |
1035 | return 0; | 1035 | return 0; |
1036 | return 1; | 1036 | return 1; |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | /* | 1039 | /* |
1040 | * FtpCDUp - move to parent directory at remote | 1040 | * FtpCDUp - move to parent directory at remote |
1041 | * | 1041 | * |
1042 | * return 1 if successful, 0 otherwise | 1042 | * return 1 if successful, 0 otherwise |
1043 | */ | 1043 | */ |
1044 | GLOBALDEF int FtpCDUp(netbuf *nControl) | 1044 | GLOBALDEF int FtpCDUp(netbuf *nControl) |
1045 | { | 1045 | { |
1046 | if (!FtpSendCmd("CDUP",'2',nControl)) | 1046 | if (!FtpSendCmd("CDUP",'2',nControl)) |
1047 | return 0; | 1047 | return 0; |
1048 | return 1; | 1048 | return 1; |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | /* | 1051 | /* |
1052 | * FtpRmdir - remove directory at remote | 1052 | * FtpRmdir - remove directory at remote |
1053 | * | 1053 | * |
1054 | * return 1 if successful, 0 otherwise | 1054 | * return 1 if successful, 0 otherwise |
1055 | */ | 1055 | */ |
1056 | GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) | 1056 | GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) |
1057 | { | 1057 | { |
1058 | char buf[256]; | 1058 | char buf[256]; |
1059 | 1059 | ||
1060 | if ((strlen(path) + 6) > sizeof(buf)) | 1060 | if ((strlen(path) + 6) > sizeof(buf)) |
1061 | return 0; | 1061 | return 0; |
1062 | sprintf(buf,"RMD %s",path); | 1062 | sprintf(buf,"RMD %s",path); |
1063 | if (!FtpSendCmd(buf,'2',nControl)) | 1063 | if (!FtpSendCmd(buf,'2',nControl)) |
1064 | return 0; | 1064 | return 0; |
1065 | return 1; | 1065 | return 1; |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | /* | 1068 | /* |
1069 | * FtpPwd - get working directory at remote | 1069 | * FtpPwd - get working directory at remote |
1070 | * | 1070 | * |
1071 | * return 1 if successful, 0 otherwise | 1071 | * return 1 if successful, 0 otherwise |
1072 | */ | 1072 | */ |
1073 | GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) | 1073 | GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) |
1074 | { | 1074 | { |
1075 | int l = max; | 1075 | int l = max; |
1076 | char *b = path; | 1076 | char *b = path; |
1077 | char *s; | 1077 | char *s; |
1078 | if (!FtpSendCmd("PWD",'2',nControl)) | 1078 | if (!FtpSendCmd("PWD",'2',nControl)) |
1079 | return 0; | 1079 | return 0; |
1080 | s = strchr(nControl->response, '"'); | 1080 | s = strchr(nControl->response, '"'); |
1081 | if (s == NULL) | 1081 | if (s == NULL) |
1082 | return 0; | 1082 | return 0; |
1083 | s++; | 1083 | s++; |
1084 | while ((--l) && (*s) && (*s != '"')) | 1084 | while ((--l) && (*s) && (*s != '"')) |
1085 | *b++ = *s++; | 1085 | *b++ = *s++; |
1086 | *b++ = '\0'; | 1086 | *b++ = '\0'; |
1087 | return 1; | 1087 | return 1; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | /* | 1090 | /* |
1091 | * FtpXfer - issue a command and transfer data | 1091 | * FtpXfer - issue a command and transfer data |
1092 | * | 1092 | * |
1093 | * return 1 if successful, 0 otherwise | 1093 | * return 1 if successful, 0 otherwise |
1094 | */ | 1094 | */ |
1095 | static int FtpXfer(const char *localfile, const char *path, | 1095 | static int FtpXfer(const char *localfile, const char *path, |
1096 | netbuf *nControl, int typ, int mode) | 1096 | netbuf *nControl, int typ, int mode) |
1097 | { | 1097 | { |
1098 | int l,c; | 1098 | int l,c; |
1099 | char *dbuf; | 1099 | char *dbuf; |
1100 | FILE *local = NULL; | 1100 | FILE *local = NULL; |
1101 | netbuf *nData; | 1101 | netbuf *nData; |
1102 | int rv=1; | 1102 | int rv=1; |
1103 | 1103 | ||
1104 | if (localfile != NULL) | 1104 | if (localfile != NULL) |
1105 | { | 1105 | { |
1106 | char ac[4] = "w"; | 1106 | char ac[4] = "w"; |
1107 | if (typ == FTPLIB_FILE_WRITE) | 1107 | if (typ == FTPLIB_FILE_WRITE) |
1108 | ac[0] = 'r'; | 1108 | ac[0] = 'r'; |
1109 | if (mode == FTPLIB_IMAGE) | 1109 | if (mode == FTPLIB_IMAGE) |
1110 | ac[1] = 'b'; | 1110 | ac[1] = 'b'; |
1111 | local = fopen(localfile, ac); | 1111 | local = fopen(localfile, ac); |
1112 | if (local == NULL) | 1112 | if (local == NULL) |
1113 | { | 1113 | { |
1114 | strncpy(nControl->response, strerror(errno), | 1114 | strncpy(nControl->response, strerror(errno), |
1115 | sizeof(nControl->response)); | 1115 | sizeof(nControl->response)); |
1116 | return 0; | 1116 | return 0; |
1117 | } | 1117 | } |
1118 | } | 1118 | } |
1119 | if (local == NULL) | 1119 | if (local == NULL) |
1120 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; | 1120 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; |
1121 | if (!FtpAccess(path, typ, mode, nControl, &nData)) | 1121 | if (!FtpAccess(path, typ, mode, nControl, &nData)) |
1122 | return 0; | 1122 | return 0; |
1123 | dbuf = malloc(FTPLIB_BUFSIZ); | 1123 | dbuf = malloc(FTPLIB_BUFSIZ); |
1124 | if (typ == FTPLIB_FILE_WRITE) | 1124 | if (typ == FTPLIB_FILE_WRITE) |
1125 | { | 1125 | { |
1126 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) | 1126 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) |
1127 | if ((c = FtpWrite(dbuf, l, nData)) < l) | 1127 | if ((c = FtpWrite(dbuf, l, nData)) < l) |
1128 | { | 1128 | { |
1129 | printf("short write: passed %d, wrote %d\n", l, c); | 1129 | printf("short write: passed %d, wrote %d\n", l, c); |
1130 | rv = 0; | 1130 | rv = 0; |
1131 | break; | 1131 | break; |
1132 | } | 1132 | } |
1133 | } | 1133 | } |
1134 | else | 1134 | else |
1135 | { | 1135 | { |
1136 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) | 1136 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) |
1137 | if (fwrite(dbuf, 1, l, local) <= 0) | 1137 | if (fwrite(dbuf, 1, l, local) <= 0) |
1138 | { | 1138 | { |
1139 | perror("localfile write"); | 1139 | perror("localfile write"); |
1140 | rv = 0; | 1140 | rv = 0; |
1141 | break; | 1141 | break; |
1142 | } | 1142 | } |
1143 | } | 1143 | } |
1144 | free(dbuf); | 1144 | free(dbuf); |
1145 | fflush(local); | 1145 | fflush(local); |
1146 | if (localfile != NULL) | 1146 | if (localfile != NULL) |
1147 | fclose(local); | 1147 | fclose(local); |
1148 | FtpClose(nData); | 1148 | FtpClose(nData); |
1149 | return rv; | 1149 | return rv; |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | /* | 1152 | /* |
1153 | * FtpNlst - issue an NLST command and write response to output | 1153 | * FtpNlst - issue an NLST command and write response to output |
1154 | * | 1154 | * |
1155 | * return 1 if successful, 0 otherwise | 1155 | * return 1 if successful, 0 otherwise |
1156 | */ | 1156 | */ |
1157 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, | 1157 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, |
1158 | netbuf *nControl) | 1158 | netbuf *nControl) |
1159 | { | 1159 | { |
1160 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); | 1160 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | /* | 1163 | /* |
1164 | * FtpDir - issue a LIST command and write response to output | 1164 | * FtpDir - issue a LIST command and write response to output |
1165 | * | 1165 | * |
1166 | * return 1 if successful, 0 otherwise | 1166 | * return 1 if successful, 0 otherwise |
1167 | */ | 1167 | */ |
1168 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) | 1168 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) |
1169 | { | 1169 | { |
1170 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); | 1170 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | /* | 1173 | /* |
1174 | * FtpSize - determine the size of a remote file | 1174 | * FtpSize - determine the size of a remote file |
1175 | * | 1175 | * |
1176 | * return 1 if successful, 0 otherwise | 1176 | * return 1 if successful, 0 otherwise |
1177 | */ | 1177 | */ |
1178 | GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) | 1178 | GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) |
1179 | { | 1179 | { |
1180 | char cmd[256]; | 1180 | char cmd[256]; |
1181 | int resp,sz,rv=1; | 1181 | int resp,sz,rv=1; |
1182 | 1182 | ||
1183 | if ((strlen(path) + 7) > sizeof(cmd)) | 1183 | if ((strlen(path) + 7) > sizeof(cmd)) |
1184 | return 0; | 1184 | return 0; |
1185 | sprintf(cmd, "TYPE %c", mode); | 1185 | sprintf(cmd, "TYPE %c", mode); |
1186 | if (!FtpSendCmd(cmd, '2', nControl)) | 1186 | if (!FtpSendCmd(cmd, '2', nControl)) |
1187 | return 0; | 1187 | return 0; |
1188 | sprintf(cmd,"SIZE %s",path); | 1188 | sprintf(cmd,"SIZE %s",path); |
1189 | if (!FtpSendCmd(cmd,'2',nControl)) | 1189 | if (!FtpSendCmd(cmd,'2',nControl)) |
1190 | rv = 0; | 1190 | rv = 0; |
1191 | else | 1191 | else |
1192 | { | 1192 | { |
1193 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) | 1193 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) |
1194 | *size = sz; | 1194 | *size = sz; |
1195 | else | 1195 | else |
1196 | rv = 0; | 1196 | rv = 0; |
1197 | } | 1197 | } |
1198 | return rv; | 1198 | return rv; |
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | /* | 1201 | /* |
1202 | * FtpModDate - determine the modification date of a remote file | 1202 | * FtpModDate - determine the modification date of a remote file |
1203 | * | 1203 | * |
1204 | * return 1 if successful, 0 otherwise | 1204 | * return 1 if successful, 0 otherwise |
1205 | */ | 1205 | */ |
1206 | GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) | 1206 | GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) |
1207 | { | 1207 | { |
1208 | char buf[256]; | 1208 | char buf[256]; |
1209 | int rv = 1; | 1209 | int rv = 1; |
1210 | 1210 | ||
1211 | if ((strlen(path) + 7) > sizeof(buf)) | 1211 | if ((strlen(path) + 7) > sizeof(buf)) |
1212 | return 0; | 1212 | return 0; |
1213 | sprintf(buf,"MDTM %s",path); | 1213 | sprintf(buf,"MDTM %s",path); |
1214 | if (!FtpSendCmd(buf,'2',nControl)) | 1214 | if (!FtpSendCmd(buf,'2',nControl)) |
1215 | rv = 0; | 1215 | rv = 0; |
1216 | else | 1216 | else |
1217 | strncpy(dt, &nControl->response[4], max); | 1217 | strncpy(dt, &nControl->response[4], max); |
1218 | return rv; | 1218 | return rv; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | /* | 1221 | /* |
1222 | * FtpGet - issue a GET command and write received data to output | 1222 | * FtpGet - issue a GET command and write received data to output |
1223 | * | 1223 | * |
1224 | * return 1 if successful, 0 otherwise | 1224 | * return 1 if successful, 0 otherwise |
1225 | */ | 1225 | */ |
1226 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, | 1226 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, |
1227 | char mode, netbuf *nControl) | 1227 | char mode, netbuf *nControl) |
1228 | { | 1228 | { |
1229 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); | 1229 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); |
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | /* | 1232 | /* |
1233 | * FtpPut - issue a PUT command and send data from input | 1233 | * FtpPut - issue a PUT command and send data from input |
1234 | * | 1234 | * |
1235 | * return 1 if successful, 0 otherwise | 1235 | * return 1 if successful, 0 otherwise |
1236 | */ | 1236 | */ |
1237 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, | 1237 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, |
1238 | netbuf *nControl) | 1238 | netbuf *nControl) |
1239 | { | 1239 | { |
1240 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); | 1240 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | /* | 1243 | /* |
1244 | * FtpRename - rename a file at remote | 1244 | * FtpRename - rename a file at remote |
1245 | * | 1245 | * |
1246 | * return 1 if successful, 0 otherwise | 1246 | * return 1 if successful, 0 otherwise |
1247 | */ | 1247 | */ |
1248 | GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) | 1248 | GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) |
1249 | { | 1249 | { |
1250 | char cmd[256]; | 1250 | char cmd[256]; |
1251 | 1251 | ||
1252 | if (((strlen(src) + 7) > sizeof(cmd)) || | 1252 | if (((strlen(src) + 7) > sizeof(cmd)) || |
1253 | ((strlen(dst) + 7) > sizeof(cmd))) | 1253 | ((strlen(dst) + 7) > sizeof(cmd))) |
1254 | return 0; | 1254 | return 0; |
1255 | sprintf(cmd,"RNFR %s",src); | 1255 | sprintf(cmd,"RNFR %s",src); |
1256 | if (!FtpSendCmd(cmd,'3',nControl)) | 1256 | if (!FtpSendCmd(cmd,'3',nControl)) |
1257 | return 0; | 1257 | return 0; |
1258 | sprintf(cmd,"RNTO %s",dst); | 1258 | sprintf(cmd,"RNTO %s",dst); |
1259 | if (!FtpSendCmd(cmd,'2',nControl)) | 1259 | if (!FtpSendCmd(cmd,'2',nControl)) |
1260 | return 0; | 1260 | return 0; |
1261 | return 1; | 1261 | return 1; |
1262 | } | 1262 | } |
1263 | 1263 | ||
1264 | /* | 1264 | /* |
1265 | * FtpDelete - delete a file at remote | 1265 | * FtpDelete - delete a file at remote |
1266 | * | 1266 | * |
1267 | * return 1 if successful, 0 otherwise | 1267 | * return 1 if successful, 0 otherwise |
1268 | */ | 1268 | */ |
1269 | GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) | 1269 | GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) |
1270 | { | 1270 | { |
1271 | char cmd[256]; | 1271 | char cmd[256]; |
1272 | 1272 | ||
1273 | if ((strlen(fnm) + 7) > sizeof(cmd)) | 1273 | if ((strlen(fnm) + 7) > sizeof(cmd)) |
1274 | return 0; | 1274 | return 0; |
1275 | sprintf(cmd,"DELE %s",fnm); | 1275 | sprintf(cmd,"DELE %s",fnm); |
1276 | if (!FtpSendCmd(cmd,'2', nControl)) | 1276 | if (!FtpSendCmd(cmd,'2', nControl)) |
1277 | return 0; | 1277 | return 0; |
1278 | return 1; | 1278 | return 1; |
1279 | } | 1279 | } |
1280 | 1280 | ||
1281 | /* | 1281 | /* |
1282 | * FtpQuit - disconnect from remote | 1282 | * FtpQuit - disconnect from remote |
1283 | * | 1283 | * |
1284 | * return 1 if successful, 0 otherwise | 1284 | * return 1 if successful, 0 otherwise |
1285 | */ | 1285 | */ |
1286 | GLOBALDEF void FtpQuit(netbuf *nControl) | 1286 | GLOBALDEF void FtpQuit(netbuf *nControl) |
1287 | { | 1287 | { |
1288 | if (nControl->dir != FTPLIB_CONTROL) | 1288 | if (nControl->dir != FTPLIB_CONTROL) |
1289 | return; | 1289 | return; |
1290 | FtpSendCmd("QUIT",'2',nControl); | 1290 | FtpSendCmd("QUIT",'2',nControl); |
1291 | net_close(nControl->handle); | 1291 | net_close(nControl->handle); |
1292 | free(nControl->buf); | 1292 | free(nControl->buf); |
1293 | free(nControl); | 1293 | free(nControl); |
1294 | } | 1294 | } |
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index eed133e..d74c55b 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp | |||
@@ -1,1072 +1,1116 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | opieftp.cpp | 2 | opieftp.cpp |
3 | ------------------- | 3 | ------------------- |
4 | ** Created: Sat Mar 9 23:33:09 2002 | 4 | ** Created: Sat Mar 9 23:33:09 2002 |
5 | copyright : (C) 2002 by ljp | 5 | copyright : (C) 2002 by ljp |
6 | email : ljp@llornkcor.com | 6 | email : ljp@llornkcor.com |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | ***************************************************************************/ | 11 | ***************************************************************************/ |
12 | //#define DEVELOPER_VERSION | 12 | #define DEVELOPERS_VERSION |
13 | 13 | ||
14 | #include "opieftp.h" | 14 | #include "opieftp.h" |
15 | #include "ftplib.h" | 15 | #include "ftplib.h" |
16 | #include "inputDialog.h" | 16 | #include "inputDialog.h" |
17 | 17 | ||
18 | #include <qpe/qpemenubar.h> | 18 | #include <qpe/qpemenubar.h> |
19 | #include <qpe/qpetoolbar.h> | 19 | #include <qpe/qpetoolbar.h> |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
24 | 24 | ||
25 | #include <qtextstream.h> | 25 | #include <qtextstream.h> |
26 | #include <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #include <qpopupmenu.h> | 33 | #include <qpopupmenu.h> |
34 | #include <qlistview.h> | 34 | #include <qlistview.h> |
35 | #include <qmainwindow.h> | 35 | #include <qmainwindow.h> |
36 | #include <qlabel.h> | 36 | #include <qlabel.h> |
37 | #include <qprogressbar.h> | 37 | #include <qprogressbar.h> |
38 | #include <qspinbox.h> | 38 | #include <qspinbox.h> |
39 | #include <qtabwidget.h> | 39 | #include <qtabwidget.h> |
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qimage.h> | 42 | #include <qimage.h> |
43 | #include <qpixmap.h> | 43 | #include <qpixmap.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qlineedit.h> | 45 | #include <qlineedit.h> |
46 | #include <qregexp.h> | 46 | #include <qregexp.h> |
47 | 47 | ||
48 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | #include <stdlib.h> | 49 | #include <stdlib.h> |
50 | 50 | ||
51 | 51 | ||
52 | QProgressBar *ProgressBar; | 52 | QProgressBar *ProgressBar; |
53 | static netbuf *conn=NULL; | 53 | static netbuf *conn=NULL; |
54 | 54 | ||
55 | static int log_progress(netbuf *ctl, int xfered, void *arg) | 55 | static int log_progress(netbuf *ctl, int xfered, void *arg) |
56 | { | 56 | { |
57 | int fsz = *(int *)arg; | 57 | int fsz = *(int *)arg; |
58 | int pct = (xfered * 100) / fsz; | 58 | int pct = (xfered * 100) / fsz; |
59 | // printf("%3d%%\r", pct); | 59 | // printf("%3d%%\r", pct); |
60 | // fflush(stdout); | 60 | // fflush(stdout); |
61 | ProgressBar->setProgress(xfered); | 61 | ProgressBar->setProgress(xfered); |
62 | qApp->processEvents(); | 62 | qApp->processEvents(); |
63 | return 1; | 63 | return 1; |
64 | } | 64 | } |
65 | 65 | ||
66 | OpieFtp::OpieFtp( ) | 66 | OpieFtp::OpieFtp( ) |
67 | : QMainWindow( ) | 67 | : QMainWindow( ) |
68 | { | 68 | { |
69 | setCaption( tr( "OpieFtp" ) ); | 69 | setCaption( tr( "OpieFtp" ) ); |
70 | 70 | ||
71 | QGridLayout *layout = new QGridLayout( this ); | 71 | QGridLayout *layout = new QGridLayout( this ); |
72 | layout->setSpacing( 2); | 72 | layout->setSpacing( 2); |
73 | layout->setMargin( 2); | 73 | layout->setMargin( 2); |
74 | 74 | ||
75 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 75 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
76 | 76 | ||
77 | QPEMenuBar *menuBar = new QPEMenuBar(this); | 77 | QPEMenuBar *menuBar = new QPEMenuBar(this); |
78 | connectionMenu = new QPopupMenu( this ); | 78 | connectionMenu = new QPopupMenu( this ); |
79 | localMenu = new QPopupMenu( this ); | 79 | localMenu = new QPopupMenu( this ); |
80 | remoteMenu = new QPopupMenu( this ); | 80 | remoteMenu = new QPopupMenu( this ); |
81 | tabMenu = new QPopupMenu( this ); | 81 | tabMenu = new QPopupMenu( this ); |
82 | 82 | ||
83 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 3 ); | 83 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 3 ); |
84 | 84 | ||
85 | menuBar->insertItem( tr( "Connection" ), connectionMenu); | 85 | menuBar->insertItem( tr( "Connection" ), connectionMenu); |
86 | menuBar->insertItem( tr( "Local" ), localMenu); | 86 | menuBar->insertItem( tr( "Local" ), localMenu); |
87 | menuBar->insertItem( tr( "Remote" ), remoteMenu); | 87 | menuBar->insertItem( tr( "Remote" ), remoteMenu); |
88 | menuBar->insertItem( tr( "View" ), tabMenu); | 88 | menuBar->insertItem( tr( "View" ), tabMenu); |
89 | 89 | ||
90 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); | 90 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); |
91 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); | 91 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); |
92 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); | 92 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); |
93 | 93 | ||
94 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 94 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
95 | localMenu->insertSeparator(); | 95 | localMenu->insertSeparator(); |
96 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 96 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
97 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 97 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
98 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 98 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
99 | localMenu->insertSeparator(); | 99 | localMenu->insertSeparator(); |
100 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 100 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
101 | localMenu->setCheckable(TRUE); | 101 | localMenu->setCheckable(TRUE); |
102 | 102 | ||
103 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 103 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
104 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 104 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
105 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 105 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
106 | remoteMenu->insertSeparator(); | 106 | remoteMenu->insertSeparator(); |
107 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 107 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
108 | 108 | ||
109 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); | 109 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); |
110 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); | 110 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); |
111 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); | 111 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); |
112 | tabMenu->setCheckable(TRUE); | 112 | tabMenu->setCheckable(TRUE); |
113 | 113 | ||
114 | TabWidget = new QTabWidget( this, "TabWidget" ); | 114 | TabWidget = new QTabWidget( this, "TabWidget" ); |
115 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 3 ); | 115 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 3 ); |
116 | 116 | ||
117 | TabWidget->setTabShape(QTabWidget::Triangular); | 117 | TabWidget->setTabShape(QTabWidget::Triangular); |
118 | 118 | ||
119 | tab = new QWidget( TabWidget, "tab" ); | 119 | tab = new QWidget( TabWidget, "tab" ); |
120 | tabLayout = new QGridLayout( tab ); | 120 | tabLayout = new QGridLayout( tab ); |
121 | tabLayout->setSpacing( 2); | 121 | tabLayout->setSpacing( 2); |
122 | tabLayout->setMargin( 2); | 122 | tabLayout->setMargin( 2); |
123 | 123 | ||
124 | Local_View = new QListView( tab, "Local_View" ); | 124 | Local_View = new QListView( tab, "Local_View" ); |
125 | // Local_View->setResizePolicy( QListView::AutoOneFit ); | 125 | // Local_View->setResizePolicy( QListView::AutoOneFit ); |
126 | Local_View->addColumn( tr("File"),120); | 126 | Local_View->addColumn( tr("File"),120); |
127 | Local_View->addColumn( tr("Size"),-1); | 127 | Local_View->addColumn( tr("Size"),-1); |
128 | Local_View->setColumnAlignment(1,QListView::AlignRight); | 128 | Local_View->setColumnAlignment(1,QListView::AlignRight); |
129 | Local_View->addColumn( tr("Date"),-1); | 129 | Local_View->addColumn( tr("Date"),-1); |
130 | Local_View->setColumnAlignment(2,QListView::AlignRight); | 130 | Local_View->setColumnAlignment(2,QListView::AlignRight); |
131 | Local_View->setAllColumnsShowFocus(TRUE); | 131 | Local_View->setAllColumnsShowFocus(TRUE); |
132 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); | 132 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); |
133 | 133 | ||
134 | tabLayout->addWidget( Local_View, 0, 0 ); | 134 | tabLayout->addWidget( Local_View, 0, 0 ); |
135 | 135 | ||
136 | connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), | 136 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), |
137 | this,SLOT( localListClicked(QListViewItem *)) ); | 137 | this,SLOT( localListClicked(QListViewItem *)) ); |
138 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 138 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
139 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | 139 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); |
140 | 140 | ||
141 | TabWidget->insertTab( tab, tr( "Local" ) ); | 141 | TabWidget->insertTab( tab, tr( "Local" ) ); |
142 | 142 | ||
143 | tab_2 = new QWidget( TabWidget, "tab_2" ); | 143 | tab_2 = new QWidget( TabWidget, "tab_2" ); |
144 | tabLayout_2 = new QGridLayout( tab_2 ); | 144 | tabLayout_2 = new QGridLayout( tab_2 ); |
145 | tabLayout_2->setSpacing( 2); | 145 | tabLayout_2->setSpacing( 2); |
146 | tabLayout_2->setMargin( 2); | 146 | tabLayout_2->setMargin( 2); |
147 | 147 | ||
148 | Remote_View = new QListView( tab_2, "Remote_View" ); | 148 | Remote_View = new QListView( tab_2, "Remote_View" ); |
149 | Remote_View->addColumn( tr("File"),120); | 149 | Remote_View->addColumn( tr("File"),120); |
150 | Remote_View->addColumn( tr("Size"),-1); | 150 | Remote_View->addColumn( tr("Size"),-1); |
151 | Remote_View->setColumnAlignment(1,QListView::AlignRight); | 151 | Remote_View->setColumnAlignment(1,QListView::AlignRight); |
152 | Remote_View->addColumn( tr("Date"),-1); | 152 | Remote_View->addColumn( tr("Date"),-1); |
153 | Remote_View->setColumnAlignment(2,QListView::AlignRight); | 153 | Remote_View->setColumnAlignment(2,QListView::AlignRight); |
154 | Remote_View->setAllColumnsShowFocus(TRUE); | 154 | Remote_View->setAllColumnsShowFocus(TRUE); |
155 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); | 155 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); |
156 | 156 | ||
157 | connect( Remote_View, SIGNAL( doubleClicked( QListViewItem*)), | 157 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), |
158 | this,SLOT( remoteListClicked(QListViewItem *)) ); | 158 | this,SLOT( remoteListClicked(QListViewItem *)) ); |
159 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 159 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
160 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); | 160 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); |
161 | 161 | ||
162 | tabLayout_2->addWidget( Remote_View, 0, 0 ); | 162 | tabLayout_2->addWidget( Remote_View, 0, 0 ); |
163 | 163 | ||
164 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); | 164 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); |
165 | 165 | ||
166 | tab_3 = new QWidget( TabWidget, "tab_3" ); | 166 | tab_3 = new QWidget( TabWidget, "tab_3" ); |
167 | tabLayout_3 = new QGridLayout( tab_3 ); | 167 | tabLayout_3 = new QGridLayout( tab_3 ); |
168 | tabLayout_3->setSpacing( 2); | 168 | tabLayout_3->setSpacing( 2); |
169 | tabLayout_3->setMargin( 2); | 169 | tabLayout_3->setMargin( 2); |
170 | 170 | ||
171 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); | 171 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); |
172 | TextLabel1->setText( tr( "Username" ) ); | 172 | TextLabel1->setText( tr( "Username" ) ); |
173 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); | 173 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); |
174 | 174 | ||
175 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); | 175 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); |
176 | UsernameComboBox->setEditable(TRUE); | 176 | UsernameComboBox->setEditable(TRUE); |
177 | // UsernameComboBox->lineEdit()->setText("anonymous"); | ||
178 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); | 177 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); |
179 | 178 | ||
180 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); | 179 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); |
181 | TextLabel2->setText( tr( "Password" ) ); | 180 | TextLabel2->setText( tr( "Password" ) ); |
182 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); | 181 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); |
183 | 182 | ||
184 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); | 183 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); |
185 | PasswordEdit->setEchoMode(QLineEdit::Password); | 184 | PasswordEdit->setEchoMode(QLineEdit::Password); |
186 | // PasswordEdit->setText( tr( "me@opieftp.org" ) ); | ||
187 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); | 185 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); |
188 | 186 | ||
189 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); | 187 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); |
190 | TextLabel3->setText( tr( "Remote server" ) ); | 188 | TextLabel3->setText( tr( "Remote server" ) ); |
191 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); | 189 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); |
192 | 190 | ||
193 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); | 191 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); |
194 | ServerComboBox->setEditable(TRUE); | 192 | ServerComboBox->setEditable(TRUE); |
195 | // ServerComboBox->lineEdit()->setText( tr( "" ) ); | ||
196 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); | 193 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); |
197 | 194 | ||
198 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); | 195 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); |
196 | connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this,SLOT(serverComboEdited(const QString & ) )); | ||
199 | 197 | ||
200 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); | 198 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); |
201 | TextLabel5->setText( tr( "Remote path" ) ); | 199 | TextLabel5->setText( tr( "Remote path" ) ); |
202 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); | 200 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); |
203 | 201 | ||
204 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); | 202 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); |
205 | remotePath->setText( currentRemoteDir = "/"); | ||
206 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); | 203 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); |
207 | 204 | ||
208 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); | 205 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); |
209 | TextLabel4->setText( tr( "Port" ) ); | 206 | TextLabel4->setText( tr( "Port" ) ); |
210 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); | 207 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); |
211 | 208 | ||
212 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); | 209 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); |
213 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); | 210 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); |
214 | PortSpinBox->setMaxValue(32786); | 211 | PortSpinBox->setMaxValue(32786); |
215 | PortSpinBox->setValue( 21); | ||
216 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); | 212 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); |
217 | 213 | ||
218 | QPushButton *deleteServerBtn; | 214 | QPushButton *deleteServerBtn; |
219 | deleteServerBtn = new QPushButton( "Delete Server",this, "OpenButton" ); | 215 | deleteServerBtn = new QPushButton( "Delete Server", tab_3 , "OpenButton" ); |
220 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 5, 5, 2, 3); | 216 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 5, 5, 2, 3); |
221 | 217 | ||
222 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); | 218 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); |
223 | 219 | ||
224 | QPushButton *connectServerBtn; | 220 | connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); |
225 | connectServerBtn = new QPushButton( "Connect",this, "ConnectButton" ); | ||
226 | tabLayout_3->addMultiCellWidget( connectServerBtn, 5, 5, 0, 1); | 221 | tabLayout_3->addMultiCellWidget( connectServerBtn, 5, 5, 0, 1); |
227 | connect(connectServerBtn,SIGNAL( clicked()),SLOT( connector() )); | 222 | connectServerBtn->setToggleButton(TRUE); |
223 | connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); | ||
228 | 224 | ||
229 | 225 | ||
230 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 226 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
231 | tabLayout_3->addItem( spacer, 5, 0 ); | 227 | tabLayout_3->addItem( spacer, 5, 0 ); |
232 | 228 | ||
233 | TabWidget->insertTab( tab_3, tr( "Config" ) ); | 229 | TabWidget->insertTab( tab_3, tr( "Config" ) ); |
234 | 230 | ||
235 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), | 231 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), |
236 | this,SLOT(tabChanged(QWidget*))); | 232 | this,SLOT(tabChanged(QWidget*))); |
237 | 233 | ||
238 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 234 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
239 | currentDir.setPath( QDir::currentDirPath()); | 235 | currentDir.setPath( QDir::currentDirPath()); |
240 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 236 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
241 | currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" ); | 237 | currentPathEdit = new QLineEdit( "/", this, "currentPathEdit" ); |
242 | layout->addMultiCellWidget( currentPathEdit, 3, 3, 0, 3 ); | 238 | layout->addMultiCellWidget( currentPathEdit, 3, 3, 0, 3 ); |
243 | 239 | ||
244 | currentPathEdit->setText( currentDir.canonicalPath()); | 240 | currentPathEdit->setText( currentDir.canonicalPath()); |
245 | connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged())); | 241 | connect( currentPathEdit,SIGNAL(returnPressed()),this,SLOT(currentPathEditChanged())); |
246 | 242 | ||
247 | ProgressBar = new QProgressBar( this, "ProgressBar" ); | 243 | ProgressBar = new QProgressBar( this, "ProgressBar" ); |
248 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 3 ); | 244 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 3 ); |
249 | 245 | ||
250 | serverComboSelected(0); | 246 | serverComboSelected(0); |
251 | #ifdef DEVELOPER_VERSION | 247 | fillCombos(); |
252 | // ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) ); | 248 | |
249 | #ifdef DEVELOPERS_VERSION | ||
253 | ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); | 250 | ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); |
254 | UsernameComboBox->lineEdit()->setText("root"); | 251 | UsernameComboBox->lineEdit()->setText("root"); |
255 | // UsernameComboBox->lineEdit()->setText("llornkcor"); | ||
256 | PortSpinBox->setValue( 4242); | 252 | PortSpinBox->setValue( 4242); |
257 | remotePath->setText( currentRemoteDir = "/"); | 253 | remotePath->setText( currentRemoteDir = "/"); |
254 | // ServerComboBox->lineEdit()->setText( tr( "llornkcor.com" ) ); | ||
255 | // UsernameComboBox->lineEdit()->setText("llornkcor"); | ||
256 | // PortSpinBox->setValue( 21); | ||
257 | // remotePath->setText( currentRemoteDir = "/home/llornkcor"); | ||
258 | PasswordEdit->setText( tr( "" ) ); | 258 | PasswordEdit->setText( tr( "" ) ); |
259 | 259 | #endif | |
260 | #endif | ||
261 | fillCombos(); | ||
262 | filterStr="*"; | 260 | filterStr="*"; |
263 | b=FALSE; | 261 | b=FALSE; |
264 | populateLocalView(); | 262 | populateLocalView(); |
265 | TabWidget->setCurrentPage(2); | 263 | TabWidget->setCurrentPage(2); |
266 | } | 264 | } |
267 | 265 | ||
268 | OpieFtp::~OpieFtp() | 266 | OpieFtp::~OpieFtp() |
269 | { | 267 | { |
270 | } | 268 | } |
271 | 269 | ||
272 | void OpieFtp::cleanUp() | 270 | void OpieFtp::cleanUp() |
273 | { | 271 | { |
274 | if(conn) | 272 | if(conn) |
275 | FtpQuit(conn); | 273 | FtpQuit(conn); |
276 | QString sfile=QDir::homeDirPath(); | 274 | QString sfile=QDir::homeDirPath(); |
277 | if(sfile.right(1) != "/") | 275 | if(sfile.right(1) != "/") |
278 | sfile+="/._temp"; | 276 | sfile+="/._temp"; |
279 | else | 277 | else |
280 | sfile+="._temp"; | 278 | sfile+="._temp"; |
281 | QFile file( sfile); | 279 | QFile file( sfile); |
282 | if(file.exists()) | 280 | if(file.exists()) |
283 | file.remove(); | 281 | file.remove(); |
284 | } | 282 | } |
285 | 283 | ||
286 | void OpieFtp::tabChanged(QWidget *w) | 284 | void OpieFtp::tabChanged(QWidget *w) |
287 | { | 285 | { |
288 | if (TabWidget->currentPageIndex() == 0) { | 286 | if (TabWidget->currentPageIndex() == 0) { |
289 | currentPathEdit->setText( currentDir.canonicalPath()); | 287 | currentPathEdit->setText( currentDir.canonicalPath()); |
290 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); | 288 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); |
291 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 289 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
292 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 290 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
293 | } | 291 | } |
294 | if (TabWidget->currentPageIndex() == 1) { | 292 | if (TabWidget->currentPageIndex() == 1) { |
295 | currentPathEdit->setText( currentRemoteDir ); | 293 | currentPathEdit->setText( currentRemoteDir ); |
296 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); | 294 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); |
297 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 295 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
298 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 296 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
299 | } | 297 | } |
300 | if (TabWidget->currentPageIndex() == 2) { | 298 | if (TabWidget->currentPageIndex() == 2) { |
301 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); | 299 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); |
302 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 300 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
303 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 301 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
304 | } | 302 | } |
305 | } | 303 | } |
306 | 304 | ||
305 | void OpieFtp::newConnection() | ||
306 | { | ||
307 | UsernameComboBox->lineEdit()->setText(""); | ||
308 | PasswordEdit->setText( "" ); | ||
309 | ServerComboBox->lineEdit()->setText( ""); | ||
310 | remotePath->setText( currentRemoteDir = "/"); | ||
311 | PortSpinBox->setValue( 21); | ||
312 | TabWidget->setCurrentPage(2); | ||
313 | currentServerConfig = -1; | ||
314 | } | ||
315 | |||
316 | void OpieFtp::serverComboEdited(const QString & edit) { | ||
317 | if( !edit.isEmpty() ) { | ||
318 | currentServerConfig = -1; | ||
319 | qDebug("comboedited"); | ||
320 | } | ||
321 | } | ||
322 | |||
323 | void OpieFtp::connectorBtnToggled(bool On) | ||
324 | { | ||
325 | if(On) { | ||
326 | connector(); | ||
327 | } else { | ||
328 | disConnector(); | ||
329 | } | ||
330 | |||
331 | } | ||
332 | |||
333 | void OpieFtp::connector() | ||
334 | { | ||
335 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
336 | qApp->processEvents(); | ||
337 | currentRemoteDir=remotePath->text(); | ||
338 | if(ServerComboBox->currentText().isEmpty()) { | ||
339 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); | ||
340 | TabWidget->setCurrentPage(2); | ||
341 | ServerComboBox->setFocus(); | ||
342 | connectServerBtn->setOn(FALSE); | ||
343 | connectServerBtn->setText( tr("Connect")); | ||
344 | return; | ||
345 | } | ||
346 | FtpInit(); | ||
347 | TabWidget->setCurrentPage(1); | ||
348 | QString ftp_host = ServerComboBox->currentText(); | ||
349 | QString ftp_user = UsernameComboBox->currentText(); | ||
350 | QString ftp_pass = PasswordEdit->text(); | ||
351 | QString port=PortSpinBox->cleanText(); | ||
352 | port.stripWhiteSpace(); | ||
353 | |||
354 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) | ||
355 | ftp_host=ftp_host.right(ftp_host.length()-6); | ||
356 | ftp_host+=":"+port; | ||
357 | if (!FtpConnect( ftp_host.latin1(), &conn)) { | ||
358 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); | ||
359 | connectServerBtn->setOn(FALSE); | ||
360 | connectServerBtn->setText( tr("Connect")); | ||
361 | return ; | ||
362 | } | ||
363 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { | ||
364 | QString msg; | ||
365 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); | ||
366 | msg.replace(QRegExp(":"),"\n"); | ||
367 | QMessageBox::message(tr("Note"),msg); | ||
368 | if(conn) | ||
369 | FtpQuit(conn); | ||
370 | connectServerBtn->setOn(FALSE); | ||
371 | connectServerBtn->setText( tr("Connect")); | ||
372 | return ; | ||
373 | } | ||
374 | remoteDirList("/") ; | ||
375 | setCaption(ftp_host); | ||
376 | writeConfig(); | ||
377 | connectServerBtn->setText( tr("Disconnect")); | ||
378 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
379 | } | ||
380 | |||
381 | void OpieFtp::disConnector() | ||
382 | { | ||
383 | if(conn) | ||
384 | FtpQuit(conn); | ||
385 | setCaption("OpieFtp"); | ||
386 | currentRemoteDir="/"; | ||
387 | Remote_View->clear(); | ||
388 | connectServerBtn->setText( tr("Connect")); | ||
389 | connectServerBtn->setOn(FALSE); | ||
390 | |||
391 | } | ||
392 | |||
307 | void OpieFtp::localUpload() | 393 | void OpieFtp::localUpload() |
308 | { | 394 | { |
309 | int fsz; | 395 | int fsz; |
310 | QCopEnvelope ( "QPE/System", "busy()" ); | 396 | QCopEnvelope ( "QPE/System", "busy()" ); |
311 | qApp->processEvents(); | 397 | qApp->processEvents(); |
312 | QString strItem = Local_View->currentItem()->text(0); | 398 | QString strItem = Local_View->currentItem()->text(0); |
313 | QString localFile = currentDir.canonicalPath()+"/"+strItem; | 399 | QString localFile = currentDir.canonicalPath()+"/"+strItem; |
314 | QString remoteFile= currentRemoteDir+strItem; | 400 | QString remoteFile= currentRemoteDir+strItem; |
315 | QFileInfo fi(localFile); | 401 | QFileInfo fi(localFile); |
316 | if( !fi.isDir()) { | 402 | if( !fi.isDir()) { |
317 | fsz=fi.size(); | 403 | fsz=fi.size(); |
318 | ProgressBar->setTotalSteps(fsz); | 404 | ProgressBar->setTotalSteps(fsz); |
319 | 405 | ||
320 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 406 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
321 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 407 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
322 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 408 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
323 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 409 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
324 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); | 410 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); |
325 | 411 | ||
326 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 412 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
327 | QString msg; | 413 | QString msg; |
328 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); | 414 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); |
329 | msg.replace(QRegExp(":"),"\n"); | 415 | msg.replace(QRegExp(":"),"\n"); |
330 | QMessageBox::message(tr("Note"),msg); | 416 | QMessageBox::message(tr("Note"),msg); |
331 | // FtpQuit(conn); | ||
332 | } | 417 | } |
333 | ProgressBar->reset(); | 418 | ProgressBar->reset(); |
334 | nullifyCallBack(); | 419 | nullifyCallBack(); |
335 | } else { | 420 | } else { |
336 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); | 421 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); |
337 | } | 422 | } |
338 | TabWidget->setCurrentPage(1); | 423 | TabWidget->setCurrentPage(1); |
339 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 424 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
340 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 425 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
341 | } | 426 | } |
342 | 427 | ||
343 | void OpieFtp::nullifyCallBack() | 428 | void OpieFtp::nullifyCallBack() |
344 | { | 429 | { |
345 | FtpOptions(FTPLIB_CALLBACK, NULL, conn); | 430 | FtpOptions(FTPLIB_CALLBACK, NULL, conn); |
346 | FtpOptions(FTPLIB_IDLETIME, NULL, conn); | 431 | FtpOptions(FTPLIB_IDLETIME, NULL, conn); |
347 | FtpOptions(FTPLIB_CALLBACKARG, NULL, conn); | 432 | FtpOptions(FTPLIB_CALLBACKARG, NULL, conn); |
348 | FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn); | 433 | FtpOptions(FTPLIB_CALLBACKBYTES, NULL, conn); |
349 | 434 | ||
350 | } | 435 | } |
351 | 436 | ||
352 | void OpieFtp::remoteDownload() | 437 | void OpieFtp::remoteDownload() |
353 | { | 438 | { |
354 | int fsz; | 439 | int fsz; |
355 | QCopEnvelope ( "QPE/System", "busy()" ); | 440 | QCopEnvelope ( "QPE/System", "busy()" ); |
356 | qApp->processEvents(); | 441 | qApp->processEvents(); |
357 | QString strItem = Remote_View->currentItem()->text(0); | 442 | QString strItem = Remote_View->currentItem()->text(0); |
358 | // strItem=strItem.right(strItem.length()-1); | 443 | // strItem=strItem.right(strItem.length()-1); |
359 | 444 | ||
360 | QString localFile = currentDir.canonicalPath(); | 445 | QString localFile = currentDir.canonicalPath(); |
361 | if(localFile.right(1).find("/",0,TRUE) == -1) | 446 | if(localFile.right(1).find("/",0,TRUE) == -1) |
362 | localFile += "/"; | 447 | localFile += "/"; |
363 | localFile += strItem; | 448 | localFile += strItem; |
364 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; | 449 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; |
365 | QString remoteFile= currentRemoteDir+strItem; | 450 | QString remoteFile= currentRemoteDir+strItem; |
366 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) | 451 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) |
367 | fsz = 0; | 452 | fsz = 0; |
368 | QString temp; | 453 | QString temp; |
369 | temp.sprintf( remoteFile+" "+" %dkb", fsz); | 454 | temp.sprintf( remoteFile+" "+" %dkb", fsz); |
370 | 455 | ||
371 | ProgressBar->setTotalSteps(fsz); | 456 | ProgressBar->setTotalSteps(fsz); |
372 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 457 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
373 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 458 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
374 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 459 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
375 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 460 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
376 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); | 461 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); |
377 | 462 | ||
378 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 463 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
379 | QString msg; | 464 | QString msg; |
380 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); | 465 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); |
381 | msg.replace(QRegExp(":"),"\n"); | 466 | msg.replace(QRegExp(":"),"\n"); |
382 | QMessageBox::message(tr("Note"),msg); | 467 | QMessageBox::message(tr("Note"),msg); |
383 | // FtpQuit(conn); | ||
384 | } | 468 | } |
385 | ProgressBar->reset(); | 469 | ProgressBar->reset(); |
386 | nullifyCallBack(); | 470 | nullifyCallBack(); |
387 | TabWidget->setCurrentPage(0); | 471 | TabWidget->setCurrentPage(0); |
388 | populateLocalView(); | 472 | populateLocalView(); |
389 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 473 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
390 | } | 474 | } |
391 | 475 | ||
392 | |||
393 | void OpieFtp::newConnection() | ||
394 | { | ||
395 | UsernameComboBox->lineEdit()->setText(""); | ||
396 | PasswordEdit->setText( "" ); | ||
397 | ServerComboBox->lineEdit()->setText( ""); | ||
398 | remotePath->setText( currentRemoteDir = "/"); | ||
399 | PortSpinBox->setValue( 21); | ||
400 | TabWidget->setCurrentPage(2); | ||
401 | |||
402 | } | ||
403 | |||
404 | void OpieFtp::connector() | ||
405 | { | ||
406 | QCopEnvelope ( "QPE/System", "busy()" ); | ||
407 | qApp->processEvents(); | ||
408 | currentRemoteDir=remotePath->text(); | ||
409 | if(ServerComboBox->currentText().isEmpty()) { | ||
410 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); | ||
411 | TabWidget->setCurrentPage(2); | ||
412 | ServerComboBox->setFocus(); | ||
413 | return; | ||
414 | } | ||
415 | FtpInit(); | ||
416 | TabWidget->setCurrentPage(1); | ||
417 | QString ftp_host = ServerComboBox->currentText(); | ||
418 | QString ftp_user = UsernameComboBox->currentText(); | ||
419 | QString ftp_pass = PasswordEdit->text(); | ||
420 | QString port=PortSpinBox->cleanText(); | ||
421 | port.stripWhiteSpace(); | ||
422 | |||
423 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) | ||
424 | ftp_host=ftp_host.right(ftp_host.length()-6); | ||
425 | ftp_host+=":"+port; | ||
426 | if (!FtpConnect( ftp_host.latin1(), &conn)) { | ||
427 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); | ||
428 | return ; | ||
429 | } | ||
430 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { | ||
431 | QString msg; | ||
432 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); | ||
433 | msg.replace(QRegExp(":"),"\n"); | ||
434 | QMessageBox::message(tr("Note"),msg); | ||
435 | FtpQuit(conn); | ||
436 | return ; | ||
437 | } | ||
438 | remoteDirList("/") ; | ||
439 | setCaption(ftp_host); | ||
440 | writeConfig(); | ||
441 | QCopEnvelope ( "QPE/System", "notBusy()" ); | ||
442 | } | ||
443 | |||
444 | void OpieFtp::disConnector() | ||
445 | { | ||
446 | FtpQuit(conn); | ||
447 | setCaption("OpieFtp"); | ||
448 | currentRemoteDir="/"; | ||
449 | Remote_View->clear(); | ||
450 | } | ||
451 | |||
452 | bool OpieFtp::remoteDirList(const QString &dir) | 476 | bool OpieFtp::remoteDirList(const QString &dir) |
453 | { | 477 | { |
454 | QString tmp = QDir::homeDirPath(); | 478 | QString tmp = QDir::homeDirPath(); |
455 | if(tmp.right(1) != "/") | 479 | if(tmp.right(1) != "/") |
456 | tmp+="/._temp"; | 480 | tmp+="/._temp"; |
457 | else | 481 | else |
458 | tmp+="._temp"; | 482 | tmp+="._temp"; |
459 | // qDebug("Listing remote dir "+tmp); | 483 | // qDebug("Listing remote dir "+tmp); |
460 | QCopEnvelope ( "QPE/System", "busy()" ); | 484 | QCopEnvelope ( "QPE/System", "busy()" ); |
461 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { | 485 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { |
462 | QString msg; | 486 | QString msg; |
463 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); | 487 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); |
464 | msg.replace(QRegExp(":"),"\n"); | 488 | msg.replace(QRegExp(":"),"\n"); |
465 | QMessageBox::message(tr("Note"),msg); | 489 | QMessageBox::message(tr("Note"),msg); |
466 | // FtpQuit(conn); | ||
467 | return false; | 490 | return false; |
468 | } | 491 | } |
469 | populateRemoteView() ; | 492 | populateRemoteView() ; |
470 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 493 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
471 | return true; | 494 | return true; |
472 | } | 495 | } |
473 | 496 | ||
474 | bool OpieFtp::remoteChDir(const QString &dir) | 497 | bool OpieFtp::remoteChDir(const QString &dir) |
475 | { | 498 | { |
476 | QCopEnvelope ( "QPE/System", "busy()" ); | 499 | QCopEnvelope ( "QPE/System", "busy()" ); |
477 | if (!FtpChdir( dir.latin1(), conn )) { | 500 | if (!FtpChdir( dir.latin1(), conn )) { |
478 | QString msg; | 501 | QString msg; |
479 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); | 502 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); |
480 | msg.replace(QRegExp(":"),"\n"); | 503 | msg.replace(QRegExp(":"),"\n"); |
481 | QMessageBox::message(tr("Note"),msg); | 504 | QMessageBox::message(tr("Note"),msg); |
482 | qDebug(msg); | 505 | qDebug(msg); |
483 | // FtpQuit(conn); | ||
484 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 506 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
485 | return FALSE; | 507 | return FALSE; |
486 | } | 508 | } |
487 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 509 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
488 | return TRUE; | 510 | return TRUE; |
489 | } | 511 | } |
490 | 512 | ||
491 | void OpieFtp::populateLocalView() | 513 | void OpieFtp::populateLocalView() |
492 | { | 514 | { |
493 | Local_View->clear(); | 515 | Local_View->clear(); |
494 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 516 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
495 | currentDir.setMatchAllDirs(TRUE); | 517 | currentDir.setMatchAllDirs(TRUE); |
496 | currentDir.setNameFilter(filterStr); | 518 | currentDir.setNameFilter(filterStr); |
497 | QString fileL, fileS, fileDate; | 519 | QString fileL, fileS, fileDate; |
498 | bool isDir=FALSE; | 520 | bool isDir=FALSE; |
499 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 521 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
500 | QFileInfoListIterator it(*list); | 522 | QFileInfoListIterator it(*list); |
501 | QFileInfo *fi; | 523 | QFileInfo *fi; |
502 | while ( (fi=it.current()) ) { | 524 | while ( (fi=it.current()) ) { |
503 | if (fi->isSymLink() ){ | 525 | if (fi->isSymLink() ){ |
504 | QString symLink=fi->readLink(); | 526 | QString symLink=fi->readLink(); |
505 | // qDebug("Symlink detected "+symLink); | 527 | // qDebug("Symlink detected "+symLink); |
506 | QFileInfo sym( symLink); | 528 | QFileInfo sym( symLink); |
507 | fileS.sprintf( "%10li", sym.size() ); | 529 | fileS.sprintf( "%10li", sym.size() ); |
508 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 530 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
509 | fileDate = sym.lastModified().toString(); | 531 | fileDate = sym.lastModified().toString(); |
510 | } else { | 532 | } else { |
511 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 533 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
512 | fileS.sprintf( "%10li", fi->size() ); | 534 | fileS.sprintf( "%10li", fi->size() ); |
513 | fileL.sprintf( "%s",fi->fileName().data() ); | 535 | fileL.sprintf( "%s",fi->fileName().data() ); |
514 | fileDate= fi->lastModified().toString(); | 536 | fileDate= fi->lastModified().toString(); |
515 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 537 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
516 | fileL+="/"; | 538 | fileL+="/"; |
517 | isDir=TRUE; | 539 | isDir=TRUE; |
518 | // qDebug( fileL); | 540 | // qDebug( fileL); |
519 | } | 541 | } |
520 | } | 542 | } |
521 | if(fileL !="./") { | 543 | if(fileL !="./") { |
522 | item = new QListViewItem( Local_View,fileL,fileS, fileDate); | 544 | item = new QListViewItem( Local_View,fileL,fileS, fileDate); |
523 | if(isDir || fileL.find("/",0,TRUE) != -1) | 545 | if(isDir || fileL.find("/",0,TRUE) != -1) |
524 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); | 546 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); |
525 | else | 547 | else |
526 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); | 548 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); |
527 | } | 549 | } |
528 | isDir=FALSE; | 550 | isDir=FALSE; |
529 | ++it; | 551 | ++it; |
530 | } | 552 | } |
531 | Local_View->setSorting( 3,FALSE); | 553 | Local_View->setSorting( 3,FALSE); |
532 | currentPathEdit->setText( currentDir.canonicalPath() ); | 554 | currentPathEdit->setText( currentDir.canonicalPath() ); |
533 | } | 555 | } |
534 | 556 | ||
535 | bool OpieFtp::populateRemoteView( ) | 557 | bool OpieFtp::populateRemoteView( ) |
536 | { | 558 | { |
537 | // qDebug("populate remoteview"); | 559 | // qDebug("populate remoteview"); |
538 | QString sfile=QDir::homeDirPath(); | 560 | QString sfile=QDir::homeDirPath(); |
539 | if(sfile.right(1) != "/") | 561 | if(sfile.right(1) != "/") |
540 | sfile+="/._temp"; | 562 | sfile+="/._temp"; |
541 | else | 563 | else |
542 | sfile+="._temp"; | 564 | sfile+="._temp"; |
543 | QFile file( sfile); | 565 | QFile file( sfile); |
544 | Remote_View->clear(); | 566 | Remote_View->clear(); |
545 | QString s, File_Name; | 567 | QString s, File_Name; |
546 | QListViewItem *itemDir=NULL, *itemFile=NULL; | 568 | QListViewItem *itemDir=NULL, *itemFile=NULL; |
547 | QString fileL, fileS, fileDate; | 569 | QString fileL, fileS, fileDate; |
548 | if ( file.open(IO_ReadOnly)) { | 570 | if ( file.open(IO_ReadOnly)) { |
549 | QTextStream t( &file ); // use a text stream | 571 | QTextStream t( &file ); // use a text stream |
550 | while ( !t.eof()) { | 572 | while ( !t.eof()) { |
551 | s = t.readLine(); | 573 | s = t.readLine(); |
552 | fileL = s.right(s.length()-55); | 574 | fileL = s.right(s.length()-55); |
553 | fileL = fileL.stripWhiteSpace(); | 575 | fileL = fileL.stripWhiteSpace(); |
554 | if(s.left(1) == "d") | 576 | if(s.left(1) == "d") |
555 | fileL = fileL+"/"; | 577 | fileL = fileL+"/"; |
556 | // fileL = "/"+fileL+"/"; | 578 | // fileL = "/"+fileL+"/"; |
557 | fileS = s.mid( 30, 42-30); | 579 | fileS = s.mid( 30, 42-30); |
558 | fileS = fileS.stripWhiteSpace(); | 580 | fileS = fileS.stripWhiteSpace(); |
559 | fileDate = s.mid( 42, 55-42); | 581 | fileDate = s.mid( 42, 55-42); |
560 | fileDate = fileDate.stripWhiteSpace(); | 582 | fileDate = fileDate.stripWhiteSpace(); |
561 | if(fileL.find("total",0,TRUE) == -1) { | 583 | if(fileL.find("total",0,TRUE) == -1) { |
562 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate); | 584 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileS, fileDate); |
563 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { | 585 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { |
564 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); | 586 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); |
565 | if(itemDir) | 587 | if(itemDir) |
566 | item->moveItem(itemDir); | 588 | item->moveItem(itemDir); |
567 | itemDir=item; | 589 | itemDir=item; |
568 | } else { | 590 | } else { |
569 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); | 591 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); |
570 | if(itemFile) | 592 | if(itemFile) |
571 | item->moveItem(itemFile); | 593 | item->moveItem(itemFile); |
572 | itemFile=item; | 594 | itemFile=item; |
573 | } | 595 | } |
574 | } | 596 | } |
575 | } | 597 | } |
576 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); | 598 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); |
577 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); | 599 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); |
578 | file.close(); | 600 | file.close(); |
579 | if( file.exists()) | 601 | if( file.exists()) |
580 | file. remove(); | 602 | file. remove(); |
581 | } else | 603 | } else |
582 | qDebug("temp file not opened successfullly "+sfile); | 604 | qDebug("temp file not opened successfullly "+sfile); |
583 | Remote_View->setSorting( 4,TRUE); | 605 | Remote_View->setSorting( 4,TRUE); |
584 | 606 | ||
585 | return true; | 607 | return true; |
586 | } | 608 | } |
587 | 609 | ||
588 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) | 610 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) |
589 | { | 611 | { |
590 | QCopEnvelope ( "QPE/System", "busy()" ); | 612 | QCopEnvelope ( "QPE/System", "busy()" ); |
591 | QString oldRemoteCurrentDir = currentRemoteDir; | 613 | QString oldRemoteCurrentDir = currentRemoteDir; |
592 | QString strItem=selectedItem->text(0); | 614 | QString strItem=selectedItem->text(0); |
593 | strItem=strItem.simplifyWhiteSpace(); | 615 | strItem=strItem.simplifyWhiteSpace(); |
594 | if(strItem == "../") { // the user wants to go ^ | 616 | if(strItem == "../") { // the user wants to go ^ |
595 | if( FtpCDUp( conn) == 0) { | 617 | if( FtpCDUp( conn) == 0) { |
596 | QString msg; | 618 | QString msg; |
597 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); | 619 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); |
598 | msg.replace(QRegExp(":"),"\n"); | 620 | msg.replace(QRegExp(":"),"\n"); |
599 | QMessageBox::message(tr("Note"),msg); | 621 | QMessageBox::message(tr("Note"),msg); |
600 | qDebug(msg); | 622 | qDebug(msg); |
601 | } | 623 | } |
602 | char path[256]; | 624 | char path[256]; |
603 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string | 625 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string |
604 | QString msg; | 626 | QString msg; |
605 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); | 627 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); |
606 | msg.replace(QRegExp(":"),"\n"); | 628 | msg.replace(QRegExp(":"),"\n"); |
607 | QMessageBox::message(tr("Note"),msg); | 629 | QMessageBox::message(tr("Note"),msg); |
608 | qDebug(msg); | 630 | qDebug(msg); |
609 | } | 631 | } |
610 | currentRemoteDir=path; | 632 | currentRemoteDir=path; |
611 | } else { | 633 | } else { |
612 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers | 634 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers |
613 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); | 635 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); |
614 | strItem = strItem.stripWhiteSpace(); | 636 | strItem = strItem.stripWhiteSpace(); |
615 | currentRemoteDir = strItem; | 637 | currentRemoteDir = strItem; |
616 | if( !remoteChDir( (const QString &)strItem)) { | 638 | if( !remoteChDir( (const QString &)strItem)) { |
617 | currentRemoteDir = oldRemoteCurrentDir; | 639 | currentRemoteDir = oldRemoteCurrentDir; |
618 | strItem=""; | 640 | strItem=""; |
619 | qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 641 | qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
620 | } | 642 | } |
621 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory | 643 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory |
622 | qDebug("trying directory"); | 644 | qDebug("trying directory"); |
623 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { | 645 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { |
624 | currentRemoteDir = oldRemoteCurrentDir; | 646 | currentRemoteDir = oldRemoteCurrentDir; |
625 | strItem=""; | 647 | strItem=""; |
626 | qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 648 | qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
627 | 649 | ||
628 | } else { | 650 | } else { |
629 | currentRemoteDir = currentRemoteDir+strItem; | 651 | currentRemoteDir = currentRemoteDir+strItem; |
630 | } | 652 | } |
631 | } else { | 653 | } else { |
632 | qDebug("download "+strItem); | 654 | qDebug("download "+strItem); |
633 | } | 655 | } |
634 | } | 656 | } |
635 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 657 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
636 | if(currentRemoteDir.right(1) !="/") | 658 | if(currentRemoteDir.right(1) !="/") |
637 | currentRemoteDir +="/"; | 659 | currentRemoteDir +="/"; |
638 | currentPathEdit->setText( currentRemoteDir ); | 660 | currentPathEdit->setText( currentRemoteDir ); |
639 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 661 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
640 | } | 662 | } |
641 | 663 | ||
642 | void OpieFtp::localListClicked(QListViewItem *selectedItem) | 664 | void OpieFtp::localListClicked(QListViewItem *selectedItem) |
643 | { | 665 | { |
644 | QString strItem=selectedItem->text(0); | 666 | QString strItem=selectedItem->text(0); |
645 | QString strSize=selectedItem->text(1); | 667 | QString strSize=selectedItem->text(1); |
646 | strSize=strSize.stripWhiteSpace(); | 668 | strSize=strSize.stripWhiteSpace(); |
647 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 669 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
648 | // is symlink | 670 | // is symlink |
649 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | 671 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); |
650 | if(QDir(strItem2).exists() ) { | 672 | if(QDir(strItem2).exists() ) { |
651 | currentDir.cd(strItem2, TRUE); | 673 | currentDir.cd(strItem2, TRUE); |
652 | populateLocalView(); | 674 | populateLocalView(); |
653 | } | 675 | } |
654 | } else { // not a symlink | 676 | } else { // not a symlink |
655 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 677 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
656 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 678 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
657 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 679 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
658 | currentDir.cd(strItem,FALSE); | 680 | currentDir.cd(strItem,FALSE); |
659 | populateLocalView(); | 681 | populateLocalView(); |
660 | } else { | 682 | } else { |
661 | currentDir.cdUp(); | 683 | currentDir.cdUp(); |
662 | populateLocalView(); | 684 | populateLocalView(); |
663 | } | 685 | } |
664 | if(QDir(strItem).exists()){ | 686 | if(QDir(strItem).exists()){ |
665 | currentDir.cd(strItem, TRUE); | 687 | currentDir.cd(strItem, TRUE); |
666 | populateLocalView(); | 688 | populateLocalView(); |
667 | } | 689 | } |
668 | } else { | 690 | } else { |
669 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 691 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
670 | if( QFile::exists(strItem ) ) { | 692 | if( QFile::exists(strItem ) ) { |
671 | qDebug("upload "+strItem); | 693 | qDebug("upload "+strItem); |
672 | } | 694 | } |
673 | } //end not symlink | 695 | } //end not symlink |
674 | chdir(strItem.latin1()); | 696 | chdir(strItem.latin1()); |
675 | } | 697 | } |
676 | } | 698 | } |
677 | 699 | ||
678 | void OpieFtp::doLocalCd() | 700 | void OpieFtp::doLocalCd() |
679 | { | 701 | { |
680 | localListClicked( Local_View->currentItem()); | 702 | localListClicked( Local_View->currentItem()); |
681 | } | 703 | } |
682 | 704 | ||
683 | void OpieFtp:: doRemoteCd() | 705 | void OpieFtp:: doRemoteCd() |
684 | { | 706 | { |
685 | remoteListClicked( Remote_View->currentItem()); | 707 | remoteListClicked( Remote_View->currentItem()); |
686 | 708 | ||
687 | } | 709 | } |
688 | 710 | ||
689 | void OpieFtp::showHidden() | 711 | void OpieFtp::showHidden() |
690 | { | 712 | { |
691 | if (!b) { | 713 | if (!b) { |
692 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 714 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
693 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); | 715 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); |
694 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 716 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
695 | b=TRUE; | 717 | b=TRUE; |
696 | 718 | ||
697 | } else { | 719 | } else { |
698 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 720 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
699 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); | 721 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); |
700 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 722 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
701 | b=FALSE; | 723 | b=FALSE; |
702 | } | 724 | } |
703 | populateLocalView(); | 725 | populateLocalView(); |
704 | } | 726 | } |
705 | 727 | ||
706 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | 728 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) |
707 | { | 729 | { |
708 | switch (mouse) { | 730 | switch (mouse) { |
709 | case 1: | 731 | case 1: |
710 | break; | 732 | break; |
711 | case 2: | 733 | case 2: |
712 | showLocalMenu(item); | 734 | showLocalMenu(item); |
713 | break; | 735 | break; |
714 | }; | 736 | }; |
715 | } | 737 | } |
716 | 738 | ||
717 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | 739 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) |
718 | { | 740 | { |
719 | switch (mouse) { | 741 | switch (mouse) { |
720 | case 1: | 742 | case 1: |
721 | break; | 743 | break; |
722 | case 2: | 744 | case 2: |
723 | showRemoteMenu(item); | 745 | showRemoteMenu(item); |
724 | break; | 746 | break; |
725 | }; | 747 | }; |
726 | } | 748 | } |
727 | 749 | ||
728 | void OpieFtp::showRemoteMenu(QListViewItem * item) | 750 | void OpieFtp::showRemoteMenu(QListViewItem * item) |
729 | { | 751 | { |
730 | QPopupMenu m;// = new QPopupMenu( Local_View ); | 752 | QPopupMenu m;// = new QPopupMenu( Local_View ); |
731 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) != -1) | 753 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) != -1) |
732 | m.insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); | 754 | m.insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); |
733 | else | 755 | else |
734 | m.insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 756 | m.insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
735 | m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 757 | m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
736 | m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 758 | m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
737 | m.insertSeparator(); | 759 | m.insertSeparator(); |
738 | m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 760 | m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
739 | m.exec( QCursor::pos() ); | 761 | m.exec( QCursor::pos() ); |
740 | } | 762 | } |
741 | 763 | ||
742 | void OpieFtp::showLocalMenu(QListViewItem * item) | 764 | void OpieFtp::showLocalMenu(QListViewItem * item) |
743 | { | 765 | { |
744 | QPopupMenu m; | 766 | QPopupMenu m; |
745 | m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 767 | m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
746 | m.insertSeparator(); | 768 | m.insertSeparator(); |
747 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) | 769 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) |
748 | m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); | 770 | m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); |
749 | else | 771 | else |
750 | m.insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 772 | m.insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
751 | m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 773 | m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
752 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 774 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
753 | m.insertSeparator(); | 775 | m.insertSeparator(); |
754 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 776 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
755 | m.setCheckable(TRUE); | 777 | m.setCheckable(TRUE); |
756 | if (b) | 778 | if (b) |
757 | m.setItemChecked(m.idAt(0),TRUE); | 779 | m.setItemChecked(m.idAt(0),TRUE); |
758 | else | 780 | else |
759 | m.setItemChecked(m.idAt(0),FALSE); | 781 | m.setItemChecked(m.idAt(0),FALSE); |
760 | 782 | ||
761 | m.exec( QCursor::pos() ); | 783 | m.exec( QCursor::pos() ); |
762 | } | 784 | } |
763 | 785 | ||
764 | void OpieFtp::localMakDir() | 786 | void OpieFtp::localMakDir() |
765 | { | 787 | { |
766 | InputDialog *fileDlg; | 788 | InputDialog *fileDlg; |
767 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 789 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
768 | fileDlg->exec(); | 790 | fileDlg->exec(); |
769 | if( fileDlg->result() == 1 ) { | 791 | if( fileDlg->result() == 1 ) { |
770 | QString filename = fileDlg->LineEdit1->text(); | 792 | QString filename = fileDlg->LineEdit1->text(); |
771 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | 793 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); |
772 | } | 794 | } |
773 | populateLocalView(); | 795 | populateLocalView(); |
774 | } | 796 | } |
775 | 797 | ||
776 | void OpieFtp::localDelete() | 798 | void OpieFtp::localDelete() |
777 | { | 799 | { |
778 | QString f = Local_View->currentItem()->text(0); | 800 | QString f = Local_View->currentItem()->text(0); |
779 | if(QDir(f).exists() ) { | 801 | if(QDir(f).exists() ) { |
780 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ | 802 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ |
781 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { | 803 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { |
782 | case 0: { | 804 | case 0: { |
783 | f=currentDir.canonicalPath()+"/"+f; | 805 | f=currentDir.canonicalPath()+"/"+f; |
784 | QString cmd="rmdir "+f; | 806 | QString cmd="rmdir "+f; |
785 | system( cmd.latin1()); | 807 | system( cmd.latin1()); |
786 | populateLocalView(); | 808 | populateLocalView(); |
787 | } | 809 | } |
788 | break; | 810 | break; |
789 | case 1: | 811 | case 1: |
790 | // exit | 812 | // exit |
791 | break; | 813 | break; |
792 | }; | 814 | }; |
793 | 815 | ||
794 | } else { | 816 | } else { |
795 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f | 817 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f |
796 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | 818 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { |
797 | case 0: { | 819 | case 0: { |
798 | f=currentDir.canonicalPath()+"/"+f; | 820 | f=currentDir.canonicalPath()+"/"+f; |
799 | QString cmd="rm "+f; | 821 | QString cmd="rm "+f; |
800 | system( cmd.latin1()); | 822 | system( cmd.latin1()); |
801 | populateLocalView(); | 823 | populateLocalView(); |
802 | } | 824 | } |
803 | break; | 825 | break; |
804 | case 1: | 826 | case 1: |
805 | // exit | 827 | // exit |
806 | break; | 828 | break; |
807 | }; | 829 | }; |
808 | } | 830 | } |
809 | } | 831 | } |
810 | 832 | ||
811 | void OpieFtp::remoteMakDir() | 833 | void OpieFtp::remoteMakDir() |
812 | { | 834 | { |
813 | InputDialog *fileDlg; | 835 | InputDialog *fileDlg; |
814 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 836 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
815 | fileDlg->exec(); | 837 | fileDlg->exec(); |
816 | if( fileDlg->result() == 1 ) { | 838 | if( fileDlg->result() == 1 ) { |
817 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; | 839 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; |
818 | QString tmp=currentRemoteDir+filename; | 840 | QString tmp=currentRemoteDir+filename; |
819 | QCopEnvelope ( "QPE/System", "busy()" ); | 841 | QCopEnvelope ( "QPE/System", "busy()" ); |
820 | if(FtpMkdir( tmp.latin1(), conn) == 0) { | 842 | if(FtpMkdir( tmp.latin1(), conn) == 0) { |
821 | QString msg; | 843 | QString msg; |
822 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); | 844 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); |
823 | msg.replace(QRegExp(":"),"\n"); | 845 | msg.replace(QRegExp(":"),"\n"); |
824 | QMessageBox::message(tr("Note"),msg); | 846 | QMessageBox::message(tr("Note"),msg); |
825 | } | 847 | } |
826 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 848 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
827 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 849 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
828 | } | 850 | } |
829 | } | 851 | } |
830 | 852 | ||
831 | void OpieFtp::remoteDelete() | 853 | void OpieFtp::remoteDelete() |
832 | { | 854 | { |
833 | QString f = Remote_View->currentItem()->text(0); | 855 | QString f = Remote_View->currentItem()->text(0); |
834 | QCopEnvelope ( "QPE/System", "busy()" ); | 856 | QCopEnvelope ( "QPE/System", "busy()" ); |
835 | if( f.right(1) =="/") { | 857 | if( f.right(1) =="/") { |
836 | QString path= currentRemoteDir+f; | 858 | QString path= currentRemoteDir+f; |
837 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 859 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
838 | ,tr("Yes"),tr("No"),0,0,1) ) { | 860 | ,tr("Yes"),tr("No"),0,0,1) ) { |
839 | case 0: { | 861 | case 0: { |
840 | f=currentDir.canonicalPath()+"/"+f; | 862 | f=currentDir.canonicalPath()+"/"+f; |
841 | if(FtpRmdir( path.latin1(), conn) ==0) { | 863 | if(FtpRmdir( path.latin1(), conn) ==0) { |
842 | QString msg; | 864 | QString msg; |
843 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); | 865 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); |
844 | msg.replace(QRegExp(":"),"\n"); | 866 | msg.replace(QRegExp(":"),"\n"); |
845 | QMessageBox::message(tr("Note"),msg); | 867 | QMessageBox::message(tr("Note"),msg); |
846 | } | 868 | } |
847 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 869 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
848 | 870 | ||
849 | } | 871 | } |
850 | break; | 872 | break; |
851 | }; | 873 | }; |
852 | } else { | 874 | } else { |
853 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 875 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
854 | ,tr("Yes"),tr("No"),0,0,1) ) { | 876 | ,tr("Yes"),tr("No"),0,0,1) ) { |
855 | case 0: { | 877 | case 0: { |
856 | QString path= currentRemoteDir+f; | 878 | QString path= currentRemoteDir+f; |
857 | if(FtpDelete( path.latin1(), conn)==0) { | 879 | if(FtpDelete( path.latin1(), conn)==0) { |
858 | QString msg; | 880 | QString msg; |
859 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); | 881 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); |
860 | msg.replace(QRegExp(":"),"\n"); | 882 | msg.replace(QRegExp(":"),"\n"); |
861 | QMessageBox::message(tr("Note"),msg); | 883 | QMessageBox::message(tr("Note"),msg); |
862 | } | 884 | } |
863 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 885 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
864 | } | 886 | } |
865 | break; | 887 | break; |
866 | }; | 888 | }; |
867 | } | 889 | } |
868 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 890 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
869 | } | 891 | } |
870 | 892 | ||
871 | void OpieFtp::remoteRename() | 893 | void OpieFtp::remoteRename() |
872 | { | 894 | { |
873 | QString curFile = Remote_View->currentItem()->text(0); | 895 | QString curFile = Remote_View->currentItem()->text(0); |
874 | InputDialog *fileDlg; | 896 | InputDialog *fileDlg; |
875 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 897 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
876 | fileDlg->inputText = curFile; | 898 | fileDlg->inputText = curFile; |
877 | fileDlg->exec(); | 899 | fileDlg->exec(); |
878 | if( fileDlg->result() == 1 ) { | 900 | if( fileDlg->result() == 1 ) { |
879 | QString oldName = currentRemoteDir +"/"+ curFile; | 901 | QString oldName = currentRemoteDir +"/"+ curFile; |
880 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; | 902 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; |
881 | QCopEnvelope ( "QPE/System", "busy()" ); | 903 | QCopEnvelope ( "QPE/System", "busy()" ); |
882 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { | 904 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { |
883 | QString msg; | 905 | QString msg; |
884 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); | 906 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); |
885 | msg.replace(QRegExp(":"),"\n"); | 907 | msg.replace(QRegExp(":"),"\n"); |
886 | QMessageBox::message(tr("Note"),msg); | 908 | QMessageBox::message(tr("Note"),msg); |
887 | } | 909 | } |
888 | QCopEnvelope ( "QPE/System", "notBusy()" ); | 910 | QCopEnvelope ( "QPE/System", "notBusy()" ); |
889 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 911 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
890 | } | 912 | } |
891 | } | 913 | } |
892 | 914 | ||
893 | void OpieFtp::localRename() | 915 | void OpieFtp::localRename() |
894 | { | 916 | { |
895 | QString curFile = Local_View->currentItem()->text(0); | 917 | QString curFile = Local_View->currentItem()->text(0); |
896 | InputDialog *fileDlg; | 918 | InputDialog *fileDlg; |
897 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 919 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
898 | fileDlg->inputText = curFile; | 920 | fileDlg->inputText = curFile; |
899 | fileDlg->exec(); | 921 | fileDlg->exec(); |
900 | if( fileDlg->result() == 1 ) { | 922 | if( fileDlg->result() == 1 ) { |
901 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | 923 | QString oldname = currentDir.canonicalPath() + "/" + curFile; |
902 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | 924 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; |
903 | if( rename(oldname.latin1(), newName.latin1())== -1) | 925 | if( rename(oldname.latin1(), newName.latin1())== -1) |
904 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 926 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
905 | } | 927 | } |
906 | populateLocalView(); | 928 | populateLocalView(); |
907 | } | 929 | } |
908 | 930 | ||
909 | void OpieFtp::currentPathEditChanged() | 931 | void OpieFtp::currentPathEditChanged() |
910 | { | 932 | { |
911 | QString oldRemoteCurrentDir = currentRemoteDir; | 933 | QString oldRemoteCurrentDir = currentRemoteDir; |
912 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); | 934 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); |
913 | if (TabWidget->currentPageIndex() == 0) { | 935 | if (TabWidget->currentPageIndex() == 0) { |
914 | if(QDir( currentPathEdit->text()).exists()) { | 936 | if(QDir( currentPathEdit->text()).exists()) { |
915 | currentDir.setPath( currentPathEdit->text() ); | 937 | currentDir.setPath( currentPathEdit->text() ); |
916 | populateLocalView(); | 938 | populateLocalView(); |
917 | } else { | 939 | } else { |
918 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | 940 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); |
919 | } | 941 | } |
920 | } | 942 | } |
921 | if (TabWidget->currentPageIndex() == 1) { | 943 | if (TabWidget->currentPageIndex() == 1) { |
922 | currentRemoteDir = currentPathEdit->text(); | 944 | currentRemoteDir = currentPathEdit->text(); |
923 | if(currentRemoteDir.right(1) !="/") { | 945 | if(currentRemoteDir.right(1) !="/") { |
924 | currentRemoteDir = currentRemoteDir +"/"; | 946 | currentRemoteDir = currentRemoteDir +"/"; |
925 | currentPathEdit->setText( currentRemoteDir ); | 947 | currentPathEdit->setText( currentRemoteDir ); |
926 | } | 948 | } |
927 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { | 949 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { |
928 | currentRemoteDir = oldRemoteCurrentDir; | 950 | currentRemoteDir = oldRemoteCurrentDir; |
929 | currentPathEdit->setText( currentRemoteDir ); | 951 | currentPathEdit->setText( currentRemoteDir ); |
930 | } | 952 | } |
931 | 953 | ||
932 | remoteDirList( (const QString &)currentRemoteDir); | 954 | remoteDirList( (const QString &)currentRemoteDir); |
933 | } | 955 | } |
934 | } | 956 | } |
935 | 957 | ||
936 | void OpieFtp::switchToLocalTab() | 958 | void OpieFtp::switchToLocalTab() |
937 | { | 959 | { |
938 | TabWidget->setCurrentPage(0); | 960 | TabWidget->setCurrentPage(0); |
939 | } | 961 | } |
940 | 962 | ||
941 | void OpieFtp::switchToRemoteTab() | 963 | void OpieFtp::switchToRemoteTab() |
942 | { | 964 | { |
943 | TabWidget->setCurrentPage(1); | 965 | TabWidget->setCurrentPage(1); |
944 | } | 966 | } |
945 | 967 | ||
946 | void OpieFtp::switchToConfigTab() | 968 | void OpieFtp::switchToConfigTab() |
947 | { | 969 | { |
948 | TabWidget->setCurrentPage(2); | 970 | TabWidget->setCurrentPage(2); |
949 | } | 971 | } |
950 | 972 | ||
951 | void OpieFtp::readConfig() { | 973 | void OpieFtp::readConfig() |
974 | { | ||
952 | 975 | ||
953 | Config cfg("opieftp"); | 976 | Config cfg("opieftp"); |
954 | cfg.setGroup("Server"); | 977 | cfg.setGroup("Server"); |
955 | QString username, remoteServer, remotePathStr, password, port, temp; | 978 | QString username, remoteServer, remotePathStr, password, port, temp; |
956 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 979 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
957 | for (int i = 0; i <= numberOfEntries; i++) { | 980 | for (int i = 0; i <= numberOfEntries; i++) { |
958 | temp.setNum(i+1); | 981 | temp.setNum(i+1); |
959 | cfg.setGroup("Server"); | 982 | cfg.setGroup("Server"); |
960 | remoteServer = cfg.readEntry( temp,""); | 983 | remoteServer = cfg.readEntry( temp,""); |
961 | ServerComboBox->insertItem( remoteServer ); | 984 | ServerComboBox->insertItem( remoteServer ); |
962 | cfg.setGroup(temp); | 985 | cfg.setGroup(temp); |
963 | 986 | ||
964 | remotePathStr = cfg.readEntry(remoteServer,""); | 987 | remotePathStr = cfg.readEntry(remoteServer,""); |
965 | int divider = remoteServer.length() - remoteServer.find(":",0,TRUE); | 988 | int divider = remoteServer.length() - remoteServer.find(":",0,TRUE); |
966 | port = remoteServer.right( divider+1); | 989 | port = remoteServer.right( divider+1); |
967 | bool ok; | 990 | bool ok; |
968 | PortSpinBox->setValue( port.toInt(&ok,10)); | 991 | PortSpinBox->setValue( port.toInt(&ok,10)); |
969 | 992 | ||
970 | remoteServer = remoteServer.left(divider - 1); | 993 | remoteServer = remoteServer.left(divider - 1); |
971 | remotePath->setText( remotePathStr); | 994 | remotePath->setText( remotePathStr); |
972 | username = cfg.readEntry(temp); | 995 | username = cfg.readEntry(temp); |
973 | UsernameComboBox->insertItem(username); | 996 | UsernameComboBox->insertItem(username); |
974 | password = cfg.readEntryCrypt(username,""); | 997 | password = cfg.readEntryCrypt(username,""); |
975 | PasswordEdit->setText(password); | 998 | PasswordEdit->setText(password); |
976 | |||
977 | } | 999 | } |
978 | |||
979 | } | 1000 | } |
980 | 1001 | ||
981 | void OpieFtp::writeConfig() { | 1002 | void OpieFtp::writeConfig() |
1003 | { | ||
982 | 1004 | ||
983 | Config cfg("opieftp"); | 1005 | Config cfg("opieftp"); |
984 | cfg.setGroup("Server"); | 1006 | cfg.setGroup("Server"); |
985 | QString temp; | 1007 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
986 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1008 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1009 | if( currentServerConfig == -1) { | ||
1010 | |||
1011 | temp.setNum( numberOfEntries + 1); | ||
1012 | cfg.setGroup("Server"); | ||
1013 | remoteServerStr = cfg.readEntry( temp,""); | ||
1014 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | ||
1015 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | ||
1016 | |||
987 | temp.setNum(numberOfEntries+1); | 1017 | temp.setNum(numberOfEntries+1); |
988 | cfg.setGroup("Server"); | 1018 | cfg.setGroup("Server"); |
989 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); | 1019 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); |
990 | cfg.setGroup(temp); | 1020 | cfg.setGroup(temp); |
991 | cfg.writeEntry("RemotePath", remotePath->text()); | 1021 | cfg.writeEntry("RemotePath", remotePath->text()); |
992 | cfg.writeEntry("Username", UsernameComboBox->currentText()); | 1022 | cfg.writeEntry("Username", UsernameComboBox->currentText()); |
993 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); | 1023 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); |
994 | cfg.setGroup("Server"); | 1024 | cfg.setGroup("Server"); |
995 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); | 1025 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); |
996 | 1026 | ||
1027 | } | ||
997 | } | 1028 | } |
998 | 1029 | ||
999 | void OpieFtp::fillCombos() { | 1030 | void OpieFtp::fillCombos() |
1000 | Config cfg("opieftp"); | 1031 | { |
1032 | Config cfg("opieftp"); | ||
1001 | cfg.setGroup("Server"); | 1033 | cfg.setGroup("Server"); |
1002 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1034 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1003 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1035 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1004 | for (int i = 1; i <= numberOfEntries; i++) { | 1036 | for (int i = 1; i <= numberOfEntries; i++) { |
1005 | temp.setNum(i); | 1037 | temp.setNum(i); |
1006 | cfg.setGroup("Server"); | 1038 | cfg.setGroup("Server"); |
1007 | remoteServerStr = cfg.readEntry( temp,""); | 1039 | remoteServerStr = cfg.readEntry( temp,""); |
1008 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1040 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1009 | port = remoteServerStr.right( divider - 1); | 1041 | port = remoteServerStr.right( divider - 1); |
1010 | bool ok; | 1042 | bool ok; |
1011 | PortSpinBox->setValue( port.toInt(&ok,10)); | 1043 | PortSpinBox->setValue( port.toInt(&ok,10)); |
1012 | 1044 | ||
1013 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | 1045 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); |
1014 | ServerComboBox->insertItem( remoteServerStr ); | 1046 | ServerComboBox->insertItem( remoteServerStr ); |
1015 | // cfg.setGroup(temp); | 1047 | // cfg.setGroup(temp); |
1016 | 1048 | ||
1017 | // remotePathStr = cfg.readEntry(remoteServer,""); | 1049 | // remotePathStr = cfg.readEntry(remoteServer,""); |
1018 | // int divider = remoteServer.length() - remoteServer.find(":",0,TRUE); | 1050 | // int divider = remoteServer.length() - remoteServer.find(":",0,TRUE); |
1019 | // port = remoteServer.right( divider+1); | 1051 | // port = remoteServer.right( divider+1); |
1020 | // PortSpinBox->setValue( port); | 1052 | // PortSpinBox->setValue( port); |
1021 | 1053 | ||
1022 | // remoteServer = remoteServer.left(divider - 1); | 1054 | // remoteServer = remoteServer.left(divider - 1); |
1023 | // remotePath->setText( remotePathStr); | 1055 | // remotePath->setText( remotePathStr); |
1024 | 1056 | ||
1025 | // username = cfg.readEntry(temp); | 1057 | // username = cfg.readEntry(temp); |
1026 | // UsernameComboBox->insertItem(username); | 1058 | // UsernameComboBox->insertItem(username); |
1027 | // password = cfg.readEntryCrypt(username,""); | 1059 | // password = cfg.readEntryCrypt(username,""); |
1028 | // PasswordEdit->setText(password); | 1060 | // PasswordEdit->setText(password); |
1029 | |||
1030 | } | 1061 | } |
1031 | |||
1032 | } | 1062 | } |
1033 | 1063 | ||
1034 | 1064 | ||
1035 | void OpieFtp::serverComboSelected(int index) { | 1065 | void OpieFtp::serverComboSelected(int index) |
1036 | 1066 | { | |
1067 | currentServerConfig = index; | ||
1037 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1068 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1038 | // remoteServerStr = ServerComboBox->text(index); | 1069 | // remoteServerStr = ServerComboBox->text(index); |
1039 | Config cfg("opieftp"); | 1070 | Config cfg("opieftp"); |
1040 | cfg.setGroup("Server"); | 1071 | cfg.setGroup("Server"); |
1041 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1072 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1042 | 1073 | ||
1043 | // for (int i = 0; i <= numberOfEntries; i++) { | 1074 | temp.setNum(index+1); |
1044 | temp.setNum(index+1); | 1075 | remoteServerStr = cfg.readEntry( temp,""); |
1045 | remoteServerStr = cfg.readEntry( temp,""); | 1076 | cfg.setGroup(temp); |
1046 | // if( remoteServerStr.find( ServerComboBox->text(index),0,TRUE) != -1 ) { | 1077 | qDebug(temp); |
1047 | cfg.setGroup(temp); | 1078 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1048 | qDebug(temp); | 1079 | port = remoteServerStr.right( divider - 1); |
1049 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1080 | bool ok; |
1050 | port = remoteServerStr.right( divider - 1); | 1081 | int portInt = port.toInt(&ok,10); |
1051 | bool ok; | 1082 | if( portInt == 0) portInt = 21; |
1052 | PortSpinBox->setValue( port.toInt(&ok,10)); | ||
1053 | 1083 | ||
1054 | remotePath->setText(cfg.readEntry("RemotePath", "")); | 1084 | PortSpinBox->setValue( portInt); |
1055 | username = cfg.readEntry("Username", ""); | ||
1056 | UsernameComboBox->lineEdit()->setText(username); | ||
1057 | PasswordEdit->setText(cfg.readEntryCrypt(username, "")); | ||
1058 | 1085 | ||
1059 | // } | 1086 | remotePath->setText(cfg.readEntry("RemotePath", "/")); |
1060 | 1087 | ||
1061 | // } | 1088 | username = cfg.readEntry("Username", "anonymous"); |
1062 | update(); | 1089 | UsernameComboBox->lineEdit()->setText(username); |
1090 | PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); | ||
1091 | update(); | ||
1063 | } | 1092 | } |
1064 | // UsernameComboBox->lineEdit()->setText("root"); | 1093 | // UsernameComboBox->lineEdit()->setText("root"); |
1065 | // PasswordEdit->setText( tr( "" ) ); | 1094 | // PasswordEdit->setText( tr( "" ) ); |
1066 | // ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); | 1095 | // ServerComboBox->lineEdit()->setText( tr( "192.168.129.201" ) ); |
1067 | // remotePath->setText( currentRemoteDir = "/home/llornkcor/"); | 1096 | // remotePath->setText( currentRemoteDir = "/home/llornkcor/"); |
1068 | // PortSpinBox->setValue( 4242); | 1097 | // PortSpinBox->setValue( 4242); |
1069 | 1098 | ||
1070 | void OpieFtp::deleteServer() { | 1099 | void OpieFtp::deleteServer() |
1071 | 1100 | { | |
1101 | QString username, remoteServerStr, remotePathStr, password, port, temp; | ||
1102 | remoteServerStr = ServerComboBox->currentText( ); | ||
1103 | username = UsernameComboBox->currentText(); | ||
1104 | Config cfg("opieftp"); | ||
1105 | cfg.setGroup("Server"); | ||
1106 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | ||
1107 | for (int i = 0; i <= numberOfEntries; i++) { | ||
1108 | temp.setNum(i+1); | ||
1109 | cfg.setGroup("Server"); | ||
1110 | if( cfg.readEntry( temp,"").find( remoteServerStr,0,TRUE) != -1 | ||
1111 | && cfg.readEntry(temp).find(username,0,TRUE) != -1 | ||
1112 | && !remoteServerStr.isEmpty()) { | ||
1113 | qDebug(temp); | ||
1114 | } | ||
1115 | } | ||
1072 | } | 1116 | } |
diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index c88a15b..52ed885 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h | |||
@@ -1,108 +1,111 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | opieftp.h | 2 | opieftp.h |
3 | ------------------- | 3 | ------------------- |
4 | ** Created: Sat Mar 9 23:33:09 2002 | 4 | ** Created: Sat Mar 9 23:33:09 2002 |
5 | copyright : (C) 2002 by ljp | 5 | copyright : (C) 2002 by ljp |
6 | email : ljp@llornkcor.com | 6 | email : ljp@llornkcor.com |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | ***************************************************************************/ | 11 | ***************************************************************************/ |
12 | #ifndef OPIEFTP_H | 12 | #ifndef OPIEFTP_H |
13 | #define OPIEFTP_H | 13 | #define OPIEFTP_H |
14 | 14 | ||
15 | #include <qvariant.h> | 15 | #include <qvariant.h> |
16 | #include <qdialog.h> | 16 | #include <qdialog.h> |
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qdir.h> | 18 | #include <qdir.h> |
19 | #include <qstring.h> | 19 | #include <qstring.h> |
20 | #include <qpoint.h> | 20 | #include <qpoint.h> |
21 | 21 | ||
22 | class QVBoxLayout; | 22 | class QVBoxLayout; |
23 | class QHBoxLayout; | 23 | class QHBoxLayout; |
24 | class QGridLayout; | 24 | class QGridLayout; |
25 | class QComboBox; | 25 | class QComboBox; |
26 | class QListView; | 26 | class QListView; |
27 | class QListviewItem; | 27 | class QListviewItem; |
28 | class QLabel; | 28 | class QLabel; |
29 | class QProgressBar; | 29 | class QProgressBar; |
30 | class QSpinBox; | 30 | class QSpinBox; |
31 | class QTabWidget; | 31 | class QTabWidget; |
32 | class QWidget; | 32 | class QWidget; |
33 | class QPEToolBar; | 33 | class QPEToolBar; |
34 | class QPEMenuBar; | 34 | class QPEMenuBar; |
35 | class QPopupMenu; | 35 | class QPopupMenu; |
36 | class QFile; | 36 | class QFile; |
37 | class QListViewItem; | 37 | class QListViewItem; |
38 | class QLineEdit; | 38 | class QLineEdit; |
39 | class QPushButton; | ||
39 | 40 | ||
40 | class OpieFtp : public QMainWindow | 41 | class OpieFtp : public QMainWindow |
41 | { | 42 | { |
42 | Q_OBJECT | 43 | Q_OBJECT |
43 | 44 | ||
44 | public: | 45 | public: |
45 | OpieFtp( ); | 46 | OpieFtp( ); |
46 | ~OpieFtp(); | 47 | ~OpieFtp(); |
47 | 48 | ||
48 | QTabWidget *TabWidget; | 49 | QTabWidget *TabWidget; |
49 | QWidget *tab, *tab_2, *tab_3; | 50 | QWidget *tab, *tab_2, *tab_3; |
50 | QListView *Local_View, *Remote_View; | 51 | QListView *Local_View, *Remote_View; |
51 | 52 | ||
52 | QComboBox *UsernameComboBox, *ServerComboBox; | 53 | QComboBox *UsernameComboBox, *ServerComboBox; |
53 | QLineEdit *PasswordEdit, *remotePath, *currentPathEdit; | 54 | QLineEdit *PasswordEdit, *remotePath, *currentPathEdit; |
54 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; | 55 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; |
55 | QSpinBox* PortSpinBox; | 56 | QSpinBox* PortSpinBox; |
56 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu; | 57 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu; |
57 | QDir currentDir; | 58 | QDir currentDir; |
58 | QString currentRemoteDir; | 59 | QString currentRemoteDir; |
59 | QString filterStr; | 60 | QString filterStr; |
60 | QListViewItem * item; | 61 | QListViewItem * item; |
62 | QPushButton *connectServerBtn; | ||
61 | bool b; | 63 | bool b; |
62 | 64 | int currentServerConfig; | |
63 | protected slots: | 65 | protected slots: |
66 | void serverComboEdited(const QString & ); | ||
64 | void showLocalMenu( QListViewItem *); | 67 | void showLocalMenu( QListViewItem *); |
65 | void showRemoteMenu( QListViewItem *); | 68 | void showRemoteMenu( QListViewItem *); |
66 | void doLocalCd(); | 69 | void doLocalCd(); |
67 | void doRemoteCd(); | 70 | void doRemoteCd(); |
68 | void localUpload(); | 71 | void localUpload(); |
69 | void remoteDownload(); | 72 | void remoteDownload(); |
70 | void newConnection(); | 73 | void newConnection(); |
71 | void connector(); | 74 | void connector(); |
72 | void disConnector(); | 75 | void disConnector(); |
73 | void populateLocalView(); | 76 | void populateLocalView(); |
74 | bool populateRemoteView(); | 77 | bool populateRemoteView(); |
75 | void showHidden(); | 78 | void showHidden(); |
76 | void writeConfig(); | 79 | void writeConfig(); |
77 | void readConfig(); | 80 | void readConfig(); |
78 | void localListClicked(QListViewItem *); | 81 | void localListClicked(QListViewItem *); |
79 | void remoteListClicked(QListViewItem *); | 82 | void remoteListClicked(QListViewItem *); |
80 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 83 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
81 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); | 84 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); |
82 | void localMakDir(); | 85 | void localMakDir(); |
83 | void localDelete(); | 86 | void localDelete(); |
84 | void remoteMakDir(); | 87 | void remoteMakDir(); |
85 | void remoteDelete(); | 88 | void remoteDelete(); |
86 | bool remoteDirList(const QString &); | 89 | bool remoteDirList(const QString &); |
87 | bool remoteChDir(const QString &); | 90 | bool remoteChDir(const QString &); |
88 | void tabChanged(QWidget*); | 91 | void tabChanged(QWidget*); |
89 | void cleanUp(); | 92 | void cleanUp(); |
90 | void remoteRename(); | 93 | void remoteRename(); |
91 | void localRename(); | 94 | void localRename(); |
92 | void currentPathEditChanged(); | 95 | void currentPathEditChanged(); |
93 | void switchToLocalTab(); | 96 | void switchToLocalTab(); |
94 | void switchToRemoteTab(); | 97 | void switchToRemoteTab(); |
95 | void switchToConfigTab(); | 98 | void switchToConfigTab(); |
96 | void fillCombos(); | 99 | void fillCombos(); |
97 | void serverComboSelected(int); | 100 | void serverComboSelected(int); |
98 | void deleteServer(); | 101 | void deleteServer(); |
99 | 102 | void connectorBtnToggled(bool); | |
100 | protected: | 103 | protected: |
101 | void nullifyCallBack(); | 104 | void nullifyCallBack(); |
102 | QGridLayout* tabLayout; | 105 | QGridLayout* tabLayout; |
103 | QGridLayout* tabLayout_2; | 106 | QGridLayout* tabLayout_2; |
104 | QGridLayout* tabLayout_3; | 107 | QGridLayout* tabLayout_3; |
105 | 108 | ||
106 | }; | 109 | }; |
107 | 110 | ||
108 | #endif // OPIEFTP_H | 111 | #endif // OPIEFTP_H |