author | llornkcor <llornkcor> | 2002-11-09 15:27:29 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-09 15:27:29 (UTC) |
commit | fee37fd9a7c038dbf5cce74172721ca3cdc8745b (patch) (unidiff) | |
tree | dc9ed0da618d4ef6e96777e992cfc88fa619656c | |
parent | d5d079c5bfaa10c310628d1ef7905d98b64dfa81 (diff) | |
download | opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.zip opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.tar.gz opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.tar.bz2 |
move ftp stuff from opieftp to shared lib
-rw-r--r-- | noncore/net/ftplib/ftplib.c (renamed from noncore/net/opieftp/ftplib.c) | 1160 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.control | 9 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.h (renamed from noncore/net/opieftp/ftplib.h) | 0 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.pro | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.control | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.pro | 4 |
8 files changed, 631 insertions, 558 deletions
diff --git a/noncore/net/opieftp/ftplib.c b/noncore/net/ftplib/ftplib.c index 5116170..421f855 100644 --- a/noncore/net/opieftp/ftplib.c +++ b/noncore/net/ftplib/ftplib.c | |||
@@ -1,1294 +1,1346 @@ | |||
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 | // changes made by Lorn Potter <llornkcor@handhelds.org> | |
23 | // | ||
23 | #if defined(__unix__) || defined(__VMS) | 24 | #if defined(__unix__) || defined(__VMS) |
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | #endif | 26 | #endif |
26 | #if defined(_WIN32) | 27 | #if defined(_WIN32) |
27 | #include <windows.h> | 28 | #include <windows.h> |
28 | #endif | 29 | #endif |
30 | |||
29 | #include <stdio.h> | 31 | #include <stdio.h> |
30 | #include <stdlib.h> | 32 | #include <stdlib.h> |
31 | #include <string.h> | 33 | #include <string.h> |
32 | #include <errno.h> | 34 | #include <errno.h> |
33 | #include <ctype.h> | 35 | #include <ctype.h> |
36 | |||
34 | #if defined(__unix__) | 37 | #if defined(__unix__) |
38 | |||
39 | #include <sys/types.h> | ||
40 | #include <unistd.h> | ||
41 | #include <fcntl.h> | ||
35 | #include <sys/time.h> | 42 | #include <sys/time.h> |
36 | #include <sys/types.h> | 43 | #include <sys/types.h> |
37 | #include <sys/socket.h> | 44 | #include <sys/socket.h> |
38 | #include <netinet/in.h> | 45 | #include <netinet/in.h> |
39 | #include <netdb.h> | 46 | #include <netdb.h> |
40 | #include <arpa/inet.h> | 47 | #include <arpa/inet.h> |
48 | |||
41 | #elif defined(VMS) | 49 | #elif defined(VMS) |
50 | |||
42 | #include <types.h> | 51 | #include <types.h> |
43 | #include <socket.h> | 52 | #include <socket.h> |
44 | #include <in.h> | 53 | #include <in.h> |
45 | #include <netdb.h> | 54 | #include <netdb.h> |
46 | #include <inet.h> | 55 | #include <inet.h> |
56 | |||
47 | #elif defined(_WIN32) | 57 | #elif defined(_WIN32) |
58 | |||
48 | #include <winsock.h> | 59 | #include <winsock.h> |
60 | |||
49 | #endif | 61 | #endif |
50 | 62 | ||
51 | #define BUILDING_LIBRARY | 63 | #define BUILDING_LIBRARY |
52 | #include "ftplib.h" | 64 | #include "ftplib.h" |
53 | 65 | ||
54 | #if defined(_WIN32) | 66 | #if defined(_WIN32) |
55 | #define SETSOCKOPT_OPTVAL_TYPE (const char *) | 67 | #define SETSOCKOPT_OPTVAL_TYPE (const char *) |
56 | #else | 68 | #else |
57 | #define SETSOCKOPT_OPTVAL_TYPE (void *) | 69 | #define SETSOCKOPT_OPTVAL_TYPE (void *) |
58 | #endif | 70 | #endif |
59 | 71 | ||
60 | #define FTPLIB_BUFSIZ 8192 | 72 | #define FTPLIB_BUFSIZ 8192 |
61 | #define ACCEPT_TIMEOUT 15 | 73 | #define ACCEPT_TIMEOUT 10 |
62 | 74 | ||
63 | #define FTPLIB_CONTROL 0 | 75 | #define FTPLIB_CONTROL 0 |
64 | #define FTPLIB_READ 1 | 76 | #define FTPLIB_READ 1 |
65 | #define FTPLIB_WRITE 2 | 77 | #define FTPLIB_WRITE 2 |
66 | 78 | ||
67 | #if !defined FTPLIB_DEFMODE | 79 | #if !defined FTPLIB_DEFMODE |
68 | #define FTPLIB_DEFMODE FTPLIB_PASSIVE | 80 | #define FTPLIB_DEFMODE FTPLIB_PASSIVE |
69 | #endif | 81 | #endif |
70 | 82 | ||
71 | struct NetBuf { | 83 | struct NetBuf { |
72 | char *cput,*cget; | 84 | char *cput,*cget; |
73 | int handle; | 85 | int handle; |
74 | int cavail,cleft; | 86 | int cavail,cleft; |
75 | char *buf; | 87 | char *buf; |
76 | int dir; | 88 | int dir; |
77 | netbuf *ctrl; | 89 | netbuf *ctrl; |
78 | netbuf *data; | 90 | netbuf *data; |
79 | int cmode; | 91 | int cmode; |
80 | struct timeval idletime; | 92 | struct timeval idletime; |
81 | FtpCallback idlecb; | 93 | FtpCallback idlecb; |
82 | void *idlearg; | 94 | void *idlearg; |
83 | int xfered; | 95 | int xfered; |
84 | int cbbytes; | 96 | int cbbytes; |
85 | int xfered1; | 97 | int xfered1; |
86 | char response[256]; | 98 | char response[256]; |
87 | }; | 99 | }; |
88 | 100 | ||
89 | static char *version = | 101 | static char *version = |
90 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; | 102 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; |
91 | 103 | ||
92 | GLOBALDEF int ftplib_debug = 0; | 104 | GLOBALDEF int ftplib_debug = 0; |
93 | 105 | ||
94 | #if defined(__unix__) || defined(VMS) | 106 | #if defined(__unix__) || defined(VMS) |
95 | #define net_read read | 107 | #define net_read read |
96 | #define net_write write | 108 | #define net_write write |
97 | #define net_close close | 109 | #define net_close close |
98 | #elif defined(_WIN32) | 110 | #elif defined(_WIN32) |
99 | #define net_read(x,y,z) recv(x,y,z,0) | 111 | #define net_read(x,y,z) recv(x,y,z,0) |
100 | #define net_write(x,y,z) send(x,y,z,0) | 112 | #define net_write(x,y,z) send(x,y,z,0) |
101 | #define net_close closesocket | 113 | #define net_close closesocket |
102 | #endif | 114 | #endif |
103 | 115 | ||
104 | #if defined(NEED_MEMCCPY) | 116 | #if defined(NEED_MEMCCPY) |
105 | /* | 117 | /* |
106 | * VAX C does not supply a memccpy routine so I provide my own | 118 | * VAX C does not supply a memccpy routine so I provide my own |
107 | */ | 119 | */ |
108 | void *memccpy(void *dest, const void *src, int c, size_t n) | 120 | void *memccpy(void *dest, const void *src, int c, size_t n) |
109 | { | 121 | { |
110 | int i=0; | 122 | int i=0; |
111 | const unsigned char *ip=src; | 123 | const unsigned char *ip=src; |
112 | unsigned char *op=dest; | 124 | unsigned char *op=dest; |
113 | 125 | ||
114 | while (i < n) | 126 | while (i < n) |
115 | { | 127 | { |
116 | if ((*op++ = *ip++) == c) | 128 | if ((*op++ = *ip++) == c) |
117 | break; | 129 | break; |
118 | i++; | 130 | i++; |
119 | } | 131 | } |
120 | if (i == n) | 132 | if (i == n) |
121 | return NULL; | 133 | return NULL; |
122 | return op; | 134 | return op; |
123 | } | 135 | } |
124 | #endif | 136 | #endif |
125 | #if defined(NEED_STRDUP) | 137 | #if defined(NEED_STRDUP) |
126 | /* | 138 | /* |
127 | * strdup - return a malloc'ed copy of a string | 139 | * strdup - return a malloc'ed copy of a string |
128 | */ | 140 | */ |
129 | char *strdup(const char *src) | 141 | char *strdup(const char *src) |
130 | { | 142 | { |
131 | int l = strlen(src) + 1; | 143 | int l = strlen(src) + 1; |
132 | char *dst = malloc(l); | 144 | char *dst = malloc(l); |
133 | if (dst) | 145 | if (dst) |
134 | strcpy(dst,src); | 146 | strcpy(dst,src); |
135 | return dst; | 147 | return dst; |
136 | } | 148 | } |
137 | #endif | 149 | #endif |
138 | 150 | ||
139 | /* | 151 | /* |
140 | * socket_wait - wait for socket to receive or flush data | 152 | * socket_wait - wait for socket to receive or flush data |
141 | * | 153 | * |
142 | * return 1 if no user callback, otherwise, return value returned by | 154 | * return 1 if no user callback, otherwise, return value returned by |
143 | * user callback | 155 | * user callback |
144 | */ | 156 | */ |
145 | static int socket_wait(netbuf *ctl) | 157 | static int socket_wait(netbuf *ctl) |
146 | { | 158 | { |
147 | fd_set fd,*rfd = NULL,*wfd = NULL; | 159 | fd_set fd,*rfd = NULL,*wfd = NULL; |
148 | struct timeval tv; | 160 | struct timeval tv; |
149 | int rv = 0; | 161 | int rv = 0; |
150 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) | 162 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) |
151 | return 1; | 163 | return 1; |
152 | if (ctl->dir == FTPLIB_WRITE) | 164 | if (ctl->dir == FTPLIB_WRITE) |
153 | wfd = &fd; | 165 | wfd = &fd; |
154 | else | 166 | else |
155 | rfd = &fd; | 167 | rfd = &fd; |
156 | FD_ZERO(&fd); | 168 | FD_ZERO(&fd); |
157 | do | 169 | do |
158 | { | 170 | { |
159 | FD_SET(ctl->handle,&fd); | 171 | FD_SET(ctl->handle,&fd); |
160 | tv = ctl->idletime; | 172 | tv = ctl->idletime; |
161 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); | 173 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); |
162 | if (rv == -1) | 174 | if (rv == -1) |
163 | { | 175 | { |
164 | rv = 0; | 176 | rv = 0; |
165 | strncpy(ctl->ctrl->response, strerror(errno), | 177 | strncpy(ctl->ctrl->response, strerror(errno), |
166 | sizeof(ctl->ctrl->response)); | 178 | sizeof(ctl->ctrl->response)); |
167 | break; | 179 | break; |
168 | } | 180 | } |
169 | else if (rv > 0) | 181 | else if (rv > 0) |
170 | { | 182 | { |
171 | rv = 1; | 183 | rv = 1; |
172 | break; | 184 | break; |
173 | } | 185 | } |
174 | } | 186 | } |
175 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); | 187 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); |
176 | return rv; | 188 | return rv; |
177 | } | 189 | } |
178 | 190 | ||
179 | /* | 191 | /* |
180 | * read a line of text | 192 | * read a line of text |
181 | * | 193 | * |
182 | * return -1 on error or bytecount | 194 | * return -1 on error or bytecount |
183 | */ | 195 | */ |
184 | static int readline(char *buf,int max,netbuf *ctl) | 196 | static int readline(char *buf,int max,netbuf *ctl) |
185 | { | 197 | { |
186 | int x,retval = 0; | 198 | int x,retval = 0; |
187 | char *end,*bp=buf; | 199 | char *end,*bp=buf; |
188 | int eof = 0; | 200 | int eof = 0; |
189 | 201 | ||
190 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) | 202 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) |
191 | return -1; | 203 | return -1; |
192 | if (max == 0) | 204 | if (max == 0) |
193 | return 0; | 205 | return 0; |
194 | do | 206 | do |
195 | { | ||
196 | if (ctl->cavail > 0) | ||
197 | { | ||
198 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; | ||
199 | end = memccpy(bp,ctl->cget,'\n',x); | ||
200 | if (end != NULL) | ||
201 | x = end - bp; | ||
202 | retval += x; | ||
203 | bp += x; | ||
204 | *bp = '\0'; | ||
205 | max -= x; | ||
206 | ctl->cget += x; | ||
207 | ctl->cavail -= x; | ||
208 | if (end != NULL) | ||
209 | { | ||
210 | bp -= 2; | ||
211 | if (strcmp(bp,"\r\n") == 0) | ||
212 | { | ||
213 | *bp++ = '\n'; | ||
214 | *bp++ = '\0'; | ||
215 | --retval; | ||
216 | } | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | if (max == 1) | ||
221 | { | 207 | { |
222 | *buf = '\0'; | 208 | if (ctl->cavail > 0) |
223 | break; | 209 | { |
210 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; | ||
211 | end = memccpy(bp,ctl->cget,'\n',x); | ||
212 | if (end != NULL) | ||
213 | x = end - bp; | ||
214 | retval += x; | ||
215 | bp += x; | ||
216 | *bp = '\0'; | ||
217 | max -= x; | ||
218 | ctl->cget += x; | ||
219 | ctl->cavail -= x; | ||
220 | if (end != NULL) | ||
221 | { | ||
222 | bp -= 2; | ||
223 | if (strcmp(bp,"\r\n") == 0) | ||
224 | { | ||
225 | *bp++ = '\n'; | ||
226 | *bp++ = '\0'; | ||
227 | --retval; | ||
228 | } | ||
229 | break; | ||
230 | } | ||
231 | } | ||
232 | if (max == 1) | ||
233 | { | ||
234 | *buf = '\0'; | ||
235 | break; | ||
236 | } | ||
237 | if (ctl->cput == ctl->cget) | ||
238 | { | ||
239 | ctl->cput = ctl->cget = ctl->buf; | ||
240 | ctl->cavail = 0; | ||
241 | ctl->cleft = FTPLIB_BUFSIZ; | ||
242 | } | ||
243 | if (eof) | ||
244 | { | ||
245 | if (retval == 0) | ||
246 | retval = -1; | ||
247 | break; | ||
248 | } | ||
249 | if (!socket_wait(ctl)) | ||
250 | return retval; | ||
251 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) | ||
252 | { | ||
253 | perror("read"); | ||
254 | retval = -1; | ||
255 | break; | ||
256 | } | ||
257 | if (x == 0) | ||
258 | eof = 1; | ||
259 | ctl->cleft -= x; | ||
260 | ctl->cavail += x; | ||
261 | ctl->cput += x; | ||
224 | } | 262 | } |
225 | if (ctl->cput == ctl->cget) | ||
226 | { | ||
227 | ctl->cput = ctl->cget = ctl->buf; | ||
228 | ctl->cavail = 0; | ||
229 | ctl->cleft = FTPLIB_BUFSIZ; | ||
230 | } | ||
231 | if (eof) | ||
232 | { | ||
233 | if (retval == 0) | ||
234 | retval = -1; | ||
235 | break; | ||
236 | } | ||
237 | if (!socket_wait(ctl)) | ||
238 | return retval; | ||
239 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) | ||
240 | { | ||
241 | perror("read"); | ||
242 | retval = -1; | ||
243 | break; | ||
244 | } | ||
245 | if (x == 0) | ||
246 | eof = 1; | ||
247 | ctl->cleft -= x; | ||
248 | ctl->cavail += x; | ||
249 | ctl->cput += x; | ||
250 | } | ||
251 | while (1); | 263 | while (1); |
252 | return retval; | 264 | return retval; |
253 | } | 265 | } |
254 | 266 | ||
255 | /* | 267 | /* |
256 | * write lines of text | 268 | * write lines of text |
257 | * | 269 | * |
258 | * return -1 on error or bytecount | 270 | * return -1 on error or bytecount |
259 | */ | 271 | */ |
260 | static int writeline(char *buf, int len, netbuf *nData) | 272 | static int writeline(char *buf, int len, netbuf *nData) |
261 | { | 273 | { |
262 | int x, nb=0, w; | 274 | int x, nb=0, w; |
263 | char *ubp = buf, *nbp; | 275 | char *ubp = buf, *nbp; |
264 | char lc=0; | 276 | char lc=0; |
265 | 277 | ||
266 | if (nData->dir != FTPLIB_WRITE) | 278 | if (nData->dir != FTPLIB_WRITE) |
267 | return -1; | 279 | return -1; |
268 | nbp = nData->buf; | 280 | nbp = nData->buf; |
269 | for (x=0; x < len; x++) | 281 | for (x=0; x < len; x++) |
270 | { | ||
271 | if ((*ubp == '\n') && (lc != '\r')) | ||
272 | { | ||
273 | if (nb == FTPLIB_BUFSIZ) | ||
274 | { | 282 | { |
275 | if (!socket_wait(nData)) | 283 | if ((*ubp == '\n') && (lc != '\r')) |
276 | return x; | 284 | { |
277 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | 285 | if (nb == FTPLIB_BUFSIZ) |
278 | if (w != FTPLIB_BUFSIZ) | 286 | { |
279 | { | 287 | if (!socket_wait(nData)) |
280 | printf("net_write(1) returned %d, errno = %d\n", w, errno); | 288 | return x; |
281 | return(-1); | 289 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); |
282 | } | 290 | if (w != FTPLIB_BUFSIZ) |
283 | nb = 0; | 291 | { |
292 | printf("net_write(1) returned %d, errno = %d\n", w, errno); | ||
293 | return(-1); | ||
294 | } | ||
295 | nb = 0; | ||
296 | } | ||
297 | nbp[nb++] = '\r'; | ||
298 | } | ||
299 | if (nb == FTPLIB_BUFSIZ) | ||
300 | { | ||
301 | if (!socket_wait(nData)) | ||
302 | return x; | ||
303 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | ||
304 | if (w != FTPLIB_BUFSIZ) | ||
305 | { | ||
306 | printf("net_write(2) returned %d, errno = %d\n", w, errno); | ||
307 | return(-1); | ||
308 | } | ||
309 | nb = 0; | ||
310 | } | ||
311 | nbp[nb++] = lc = *ubp++; | ||
284 | } | 312 | } |
285 | nbp[nb++] = '\r'; | 313 | if (nb) |
286 | } | ||
287 | if (nb == FTPLIB_BUFSIZ) | ||
288 | { | ||
289 | if (!socket_wait(nData)) | ||
290 | return x; | ||
291 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | ||
292 | if (w != FTPLIB_BUFSIZ) | ||
293 | { | 314 | { |
294 | printf("net_write(2) returned %d, errno = %d\n", w, errno); | 315 | if (!socket_wait(nData)) |
295 | return(-1); | 316 | return x; |
317 | w = net_write(nData->handle, nbp, nb); | ||
318 | if (w != nb) | ||
319 | { | ||
320 | printf("net_write(3) returned %d, errno = %d\n", w, errno); | ||
321 | return(-1); | ||
322 | } | ||
296 | } | 323 | } |
297 | nb = 0; | ||
298 | } | ||
299 | nbp[nb++] = lc = *ubp++; | ||
300 | } | ||
301 | if (nb) | ||
302 | { | ||
303 | if (!socket_wait(nData)) | ||
304 | return x; | ||
305 | w = net_write(nData->handle, nbp, nb); | ||
306 | if (w != nb) | ||
307 | { | ||
308 | printf("net_write(3) returned %d, errno = %d\n", w, errno); | ||
309 | return(-1); | ||
310 | } | ||
311 | } | ||
312 | return len; | 324 | return len; |
313 | } | 325 | } |
314 | 326 | ||
315 | /* | 327 | /* |
316 | * read a response from the server | 328 | * read a response from the server |
317 | * | 329 | * |
318 | * return 0 if first char doesn't match | 330 | * return 0 if first char doesn't match |
319 | * return 1 if first char matches | 331 | * return 1 if first char matches |
320 | */ | 332 | */ |
321 | static int readresp(char c, netbuf *nControl) | 333 | static int readresp(char c, netbuf *nControl) |
322 | { | 334 | { |
323 | char match[5]; | 335 | char match[5]; |
324 | if (readline(nControl->response,256,nControl) == -1) | 336 | if (readline(nControl->response,256,nControl) == -1) |
325 | { | 337 | { |
326 | perror("Control socket read failed"); | 338 | perror("Control socket read failed"); |
327 | return 0; | 339 | return 0; |
328 | } | 340 | } |
329 | if (ftplib_debug > 1) | 341 | if (ftplib_debug > 1) |
330 | fprintf(stderr,"%s",nControl->response); | 342 | fprintf(stderr,"%s",nControl->response); |
331 | if (nControl->response[3] == '-') | 343 | if (nControl->response[3] == '-') |
332 | { | ||
333 | strncpy(match,nControl->response,3); | ||
334 | match[3] = ' '; | ||
335 | match[4] = '\0'; | ||
336 | do | ||
337 | { | ||
338 | if (readline(nControl->response,256,nControl) == -1) | ||
339 | { | 344 | { |
340 | perror("Control socket read failed"); | 345 | strncpy(match,nControl->response,3); |
341 | return 0; | 346 | match[3] = ' '; |
347 | match[4] = '\0'; | ||
348 | do | ||
349 | { | ||
350 | if (readline(nControl->response,256,nControl) == -1) | ||
351 | { | ||
352 | perror("Control socket read failed"); | ||
353 | return 0; | ||
354 | } | ||
355 | if (ftplib_debug > 1) | ||
356 | fprintf(stderr,"%s",nControl->response); | ||
357 | } | ||
358 | while (strncmp(nControl->response,match,4)); | ||
342 | } | 359 | } |
343 | if (ftplib_debug > 1) | ||
344 | fprintf(stderr,"%s",nControl->response); | ||
345 | } | ||
346 | while (strncmp(nControl->response,match,4)); | ||
347 | } | ||
348 | if (nControl->response[0] == c) | 360 | if (nControl->response[0] == c) |
349 | return 1; | 361 | return 1; |
350 | return 0; | 362 | return 0; |
351 | } | 363 | } |
352 | 364 | ||
353 | /* | 365 | /* |
354 | * FtpInit for stupid operating systems that require it (Windows NT) | 366 | * FtpInit for stupid operating systems that require it (Windows NT) |
355 | */ | 367 | */ |
356 | GLOBALDEF void FtpInit(void) | 368 | GLOBALDEF void FtpInit(void) |
357 | { | 369 | { |
358 | #if defined(_WIN32) | 370 | #if defined(_WIN32) |
359 | WORD wVersionRequested; | 371 | WORD wVersionRequested; |
360 | WSADATA wsadata; | 372 | WSADATA wsadata; |
361 | int err; | 373 | int err; |
362 | wVersionRequested = MAKEWORD(1,1); | 374 | wVersionRequested = MAKEWORD(1,1); |
363 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) | 375 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) |
364 | fprintf(stderr,"Network failed to start: %d\n",err); | 376 | fprintf(stderr,"Network failed to start: %d\n",err); |
365 | #endif | 377 | #endif |
366 | } | 378 | } |
367 | 379 | ||
368 | /* | 380 | /* |
369 | * FtpLastResponse - return a pointer to the last response received | 381 | * FtpLastResponse - return a pointer to the last response received |
370 | */ | 382 | */ |
371 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) | 383 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) |
372 | { | 384 | { |
373 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) | 385 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) |
374 | return nControl->response; | 386 | return nControl->response; |
375 | return NULL; | 387 | return NULL; |
376 | } | 388 | } |
377 | 389 | ||
378 | /* | 390 | /* |
379 | * FtpConnect - connect to remote server | 391 | * FtpConnect - connect to remote server |
380 | * | 392 | * |
381 | * return 1 if connected, 0 if not | 393 | * return 1 if connected, 0 if not |
382 | */ | 394 | */ |
383 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) | 395 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) |
384 | { | 396 | { |
385 | int sControl; | 397 | int sControl, stat, flags, oldflags; |
386 | struct sockaddr_in sin; | 398 | struct sockaddr_in sin; |
387 | struct hostent *phe; | 399 | struct hostent *phe; |
388 | struct servent *pse; | 400 | struct servent *pse; |
389 | int on=1; | 401 | int on=1; |
390 | netbuf *ctrl; | 402 | netbuf *ctrl; |
391 | char *lhost; | 403 | char *lhost; |
392 | char *pnum; | 404 | char *pnum; |
405 | struct timeval tv; | ||
406 | fd_set wr; | ||
393 | 407 | ||
394 | memset(&sin,0,sizeof(sin)); | 408 | memset(&sin,0,sizeof(sin)); |
395 | sin.sin_family = AF_INET; | 409 | sin.sin_family = AF_INET; |
396 | lhost = strdup(host); | 410 | lhost = strdup(host); |
397 | pnum = strchr(lhost,':'); | 411 | pnum = strchr(lhost,':'); |
398 | if (pnum == NULL) | 412 | if (pnum == NULL) |
399 | { | 413 | { |
400 | #if defined(VMS) | 414 | #if defined(VMS) |
401 | sin.sin_port = htons(21); | 415 | sin.sin_port = htons(21); |
402 | #else | 416 | #else |
403 | if ((pse = getservbyname("ftp","tcp")) == NULL) | 417 | if ((pse = getservbyname("ftp","tcp")) == NULL) |
404 | { | 418 | { |
405 | perror("getservbyname"); | 419 | perror("getservbyname"); |
406 | return 0; | 420 | return 0; |
407 | } | 421 | } |
408 | sin.sin_port = pse->s_port; | 422 | sin.sin_port = pse->s_port; |
409 | #endif | 423 | #endif |
410 | } | 424 | } |
411 | else | 425 | else |
412 | { | 426 | { |
413 | *pnum++ = '\0'; | 427 | *pnum++ = '\0'; |
414 | if (isdigit(*pnum)) | 428 | if (isdigit(*pnum)) |
415 | sin.sin_port = htons(atoi(pnum)); | 429 | sin.sin_port = htons(atoi(pnum)); |
416 | else | 430 | else |
417 | { | 431 | { |
418 | pse = getservbyname(pnum,"tcp"); | 432 | pse = getservbyname(pnum,"tcp"); |
419 | sin.sin_port = pse->s_port; | 433 | sin.sin_port = pse->s_port; |
420 | } | 434 | } |
421 | } | 435 | } |
422 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) | 436 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) |
423 | { | ||
424 | if ((phe = gethostbyname(lhost)) == NULL) | ||
425 | { | 437 | { |
426 | perror("gethostbyname"); | 438 | if ((phe = gethostbyname(lhost)) == NULL) |
427 | return 0; | 439 | { |
440 | perror("gethostbyname"); | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); | ||
445 | |||
428 | } | 446 | } |
429 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); | ||
430 | } | ||
431 | free(lhost); | 447 | free(lhost); |
448 | |||
432 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); | 449 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
433 | if (sControl == -1) | 450 | if (sControl == -1) |
434 | { | 451 | { |
435 | perror("socket"); | 452 | perror("socket"); |
436 | return 0; | 453 | return 0; |
437 | } | 454 | } |
438 | if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, | 455 | |
439 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) | 456 | if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, |
440 | { | 457 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) |
441 | perror("setsockopt"); | 458 | { |
442 | net_close(sControl); | 459 | perror("setsockopt"); |
443 | return 0; | 460 | net_close(sControl); |
444 | } | 461 | return 0; |
445 | if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1) | 462 | } |
446 | { | 463 | |
447 | perror("connect"); | 464 | //set nonblocking for connection timeout |
448 | net_close(sControl); | 465 | flags = fcntl( sControl, F_GETFL,0); |
449 | return 0; | 466 | oldflags=flags; |
450 | } | 467 | fcntl( sControl, F_SETFL, O_NONBLOCK|flags); |
468 | |||
469 | stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin)); | ||
470 | if (stat < 0) | ||
471 | { | ||
472 | if (errno != EWOULDBLOCK && errno != EINPROGRESS) | ||
473 | { | ||
474 | perror("connect"); | ||
475 | net_close(sControl); | ||
476 | return 0; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | FD_ZERO(&wr); | ||
481 | FD_SET( sControl, &wr); | ||
482 | |||
483 | tv.tv_sec = ACCEPT_TIMEOUT; | ||
484 | tv.tv_usec = 0; | ||
485 | |||
486 | stat = select(sControl+1, 0, &wr, 0, &tv); | ||
487 | |||
488 | if (stat < 1) | ||
489 | { | ||
490 | // time out has expired, | ||
491 | // or an error has ocurred | ||
492 | perror("timeout"); | ||
493 | net_close(sControl); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | printf("connected\n"); | ||
498 | |||
499 | //set original flags | ||
500 | fcntl( sControl, F_SETFL, oldflags); | ||
501 | |||
451 | ctrl = calloc(1,sizeof(netbuf)); | 502 | ctrl = calloc(1,sizeof(netbuf)); |
452 | if (ctrl == NULL) | 503 | if (ctrl == NULL) |
453 | { | 504 | { |
454 | perror("calloc"); | 505 | perror("calloc"); |
455 | net_close(sControl); | 506 | net_close(sControl); |
456 | return 0; | 507 | return 0; |
457 | } | 508 | } |
458 | ctrl->buf = malloc(FTPLIB_BUFSIZ); | 509 | ctrl->buf = malloc(FTPLIB_BUFSIZ); |
459 | if (ctrl->buf == NULL) | 510 | if (ctrl->buf == NULL) |
460 | { | 511 | { |
461 | perror("calloc"); | 512 | perror("calloc"); |
462 | net_close(sControl); | 513 | net_close(sControl); |
463 | free(ctrl); | 514 | free(ctrl); |
464 | return 0; | 515 | return 0; |
465 | } | 516 | } |
466 | ctrl->handle = sControl; | 517 | ctrl->handle = sControl; |
467 | ctrl->dir = FTPLIB_CONTROL; | 518 | ctrl->dir = FTPLIB_CONTROL; |
468 | ctrl->ctrl = NULL; | 519 | ctrl->ctrl = NULL; |
469 | ctrl->cmode = FTPLIB_DEFMODE; | 520 | ctrl->cmode = FTPLIB_DEFMODE; |
470 | ctrl->idlecb = NULL; | 521 | ctrl->idlecb = NULL; |
471 | ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; | 522 | ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; |
472 | ctrl->idlearg = NULL; | 523 | ctrl->idlearg = NULL; |
473 | ctrl->xfered = 0; | 524 | ctrl->xfered = 0; |
474 | ctrl->xfered1 = 0; | 525 | ctrl->xfered1 = 0; |
475 | ctrl->cbbytes = 0; | 526 | ctrl->cbbytes = 0; |
476 | if (readresp('2', ctrl) == 0) | 527 | if (readresp('2', ctrl) == 0) |
477 | { | 528 | { |
478 | net_close(sControl); | 529 | net_close(sControl); |
479 | free(ctrl->buf); | 530 | free(ctrl->buf); |
480 | free(ctrl); | 531 | free(ctrl); |
481 | return 0; | 532 | return 0; |
482 | } | 533 | } |
483 | *nControl = ctrl; | 534 | *nControl = ctrl; |
484 | return 1; | 535 | return 1; |
485 | } | 536 | } |
486 | 537 | ||
487 | /* | 538 | /* |
488 | * FtpOptions - change connection options | 539 | * FtpOptions - change connection options |
489 | * | 540 | * |
490 | * returns 1 if successful, 0 on error | 541 | * returns 1 if successful, 0 on error |
491 | */ | 542 | */ |
492 | GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) | 543 | GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) |
493 | { | 544 | { |
494 | int v,rv=0; | 545 | int v,rv=0; |
495 | switch (opt) | 546 | switch (opt) |
496 | { | 547 | { |
497 | case FTPLIB_CONNMODE: | 548 | case FTPLIB_CONNMODE: |
498 | v = (int) val; | 549 | v = (int) val; |
499 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) | 550 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) |
500 | { | 551 | { |
501 | nControl->cmode = v; | 552 | nControl->cmode = v; |
502 | rv = 1; | 553 | rv = 1; |
503 | } | 554 | } |
504 | break; | 555 | break; |
505 | case FTPLIB_CALLBACK: | 556 | case FTPLIB_CALLBACK: |
506 | nControl->idlecb = (FtpCallback) val; | 557 | nControl->idlecb = (FtpCallback) val; |
507 | rv = 1; | 558 | rv = 1; |
508 | break; | 559 | break; |
509 | case FTPLIB_IDLETIME: | 560 | case FTPLIB_IDLETIME: |
510 | v = (int) val; | 561 | v = (int) val; |
511 | rv = 1; | 562 | rv = 1; |
512 | nControl->idletime.tv_sec = v / 1000; | 563 | nControl->idletime.tv_sec = v / 1000; |
513 | nControl->idletime.tv_usec = (v % 1000) * 1000; | 564 | nControl->idletime.tv_usec = (v % 1000) * 1000; |
514 | break; | 565 | break; |
515 | case FTPLIB_CALLBACKARG: | 566 | case FTPLIB_CALLBACKARG: |
516 | rv = 1; | 567 | rv = 1; |
517 | nControl->idlearg = (void *) val; | 568 | nControl->idlearg = (void *) val; |
518 | break; | 569 | break; |
519 | case FTPLIB_CALLBACKBYTES: | 570 | case FTPLIB_CALLBACKBYTES: |
520 | rv = 1; | 571 | rv = 1; |
521 | nControl->cbbytes = (int) val; | 572 | nControl->cbbytes = (int) val; |
522 | break; | 573 | break; |
523 | } | 574 | } |
524 | return rv; | 575 | return rv; |
525 | } | 576 | } |
526 | 577 | ||
527 | /* | 578 | /* |
528 | * FtpSendCmd - send a command and wait for expected response | 579 | * FtpSendCmd - send a command and wait for expected response |
529 | * | 580 | * |
530 | * return 1 if proper response received, 0 otherwise | 581 | * return 1 if proper response received, 0 otherwise |
531 | */ | 582 | */ |
532 | static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) | 583 | static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) |
533 | { | 584 | { |
534 | char buf[256]; | 585 | char buf[256]; |
535 | if (nControl->dir != FTPLIB_CONTROL) | 586 | if (nControl->dir != FTPLIB_CONTROL) |
536 | return 0; | 587 | return 0; |
537 | if (ftplib_debug > 2) | 588 | if (ftplib_debug > 2) |
538 | fprintf(stderr,"%s\n",cmd); | 589 | fprintf(stderr,"%s\n",cmd); |
539 | if ((strlen(cmd) + 3) > sizeof(buf)) | 590 | if ((strlen(cmd) + 3) > sizeof(buf)) |
540 | return 0; | 591 | return 0; |
541 | sprintf(buf,"%s\r\n",cmd); | 592 | sprintf(buf,"%s\r\n",cmd); |
542 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) | 593 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) |
543 | { | 594 | { |
544 | perror("write"); | 595 | perror("write"); |
545 | return 0; | 596 | return 0; |
546 | } | 597 | } |
547 | return readresp(expresp, nControl); | 598 | return readresp(expresp, nControl); |
548 | } | 599 | } |
549 | 600 | ||
550 | /* | 601 | /* |
551 | * FtpLogin - log in to remote server | 602 | * FtpLogin - log in to remote server |
552 | * | 603 | * |
553 | * return 1 if logged in, 0 otherwise | 604 | * return 1 if logged in, 0 otherwise |
554 | */ | 605 | */ |
555 | GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) | 606 | GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) |
556 | { | 607 | { |
557 | char tempbuf[64]; | 608 | char tempbuf[64]; |
558 | 609 | ||
559 | if (((strlen(user) + 7) > sizeof(tempbuf)) || | 610 | if (((strlen(user) + 7) > sizeof(tempbuf)) || |
560 | ((strlen(pass) + 7) > sizeof(tempbuf))) | 611 | ((strlen(pass) + 7) > sizeof(tempbuf))) |
561 | return 0; | 612 | return 0; |
562 | sprintf(tempbuf,"USER %s",user); | 613 | sprintf(tempbuf,"USER %s",user); |
563 | if (!FtpSendCmd(tempbuf,'3',nControl)) | 614 | if (!FtpSendCmd(tempbuf,'3',nControl)) |
564 | { | 615 | { |
565 | if (nControl->response[0] == '2') | 616 | if (nControl->response[0] == '2') |
566 | return 1; | 617 | return 1; |
567 | return 0; | 618 | return 0; |
568 | } | 619 | } |
569 | sprintf(tempbuf,"PASS %s",pass); | 620 | sprintf(tempbuf,"PASS %s",pass); |
570 | return FtpSendCmd(tempbuf,'2',nControl); | 621 | return FtpSendCmd(tempbuf,'2',nControl); |
571 | } | 622 | } |
572 | 623 | ||
573 | /* | 624 | /* |
574 | * FtpOpenPort - set up data connection | 625 | * FtpOpenPort - set up data connection |
575 | * | 626 | * |
576 | * return 1 if successful, 0 otherwise | 627 | * return 1 if successful, 0 otherwise |
577 | */ | 628 | */ |
578 | static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) | 629 | static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) |
579 | { | 630 | { |
580 | int sData; | 631 | int sData; |
581 | union { | 632 | union { |
582 | struct sockaddr sa; | 633 | struct sockaddr sa; |
583 | struct sockaddr_in in; | 634 | struct sockaddr_in in; |
584 | } sin; | 635 | } sin; |
585 | struct linger lng = { 0, 0 }; | 636 | struct linger lng = { 0, 0 }; |
586 | unsigned int l; | 637 | unsigned int l; |
587 | int on=1; | 638 | int on=1; |
588 | netbuf *ctrl; | 639 | netbuf *ctrl; |
589 | char *cp; | 640 | char *cp; |
590 | unsigned int v[6]; | 641 | unsigned int v[6]; |
591 | char buf[256]; | 642 | char buf[256]; |
592 | 643 | ||
593 | if (nControl->dir != FTPLIB_CONTROL) | 644 | if (nControl->dir != FTPLIB_CONTROL) |
594 | return -1; | 645 | return -1; |
595 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) | 646 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) |
596 | { | 647 | { |
597 | sprintf(nControl->response, "Invalid direction %d\n", dir); | 648 | sprintf(nControl->response, "Invalid direction %d\n", dir); |
598 | return -1; | 649 | return -1; |
599 | } | 650 | } |
600 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) | 651 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) |
601 | { | 652 | { |
602 | sprintf(nControl->response, "Invalid mode %c\n", mode); | 653 | sprintf(nControl->response, "Invalid mode %c\n", mode); |
603 | return -1; | 654 | return -1; |
604 | } | 655 | } |
605 | l = sizeof(sin); | 656 | l = sizeof(sin); |
606 | if (nControl->cmode == FTPLIB_PASSIVE) | 657 | if (nControl->cmode == FTPLIB_PASSIVE) |
607 | { | 658 | { |
608 | memset(&sin, 0, l); | 659 | memset(&sin, 0, l); |
609 | sin.in.sin_family = AF_INET; | 660 | sin.in.sin_family = AF_INET; |
610 | if (!FtpSendCmd("PASV",'2',nControl)) | 661 | if (!FtpSendCmd("PASV",'2',nControl)) |
611 | return -1; | 662 | return -1; |
612 | cp = strchr(nControl->response,'('); | 663 | cp = strchr(nControl->response,'('); |
613 | if (cp == NULL) | 664 | if (cp == NULL) |
614 | return -1; | 665 | return -1; |
615 | cp++; | 666 | cp++; |
616 | sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); | 667 | 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]; | 668 | sin.sa.sa_data[2] = v[2]; |
618 | sin.sa.sa_data[3] = v[3]; | 669 | sin.sa.sa_data[3] = v[3]; |
619 | sin.sa.sa_data[4] = v[4]; | 670 | sin.sa.sa_data[4] = v[4]; |
620 | sin.sa.sa_data[5] = v[5]; | 671 | sin.sa.sa_data[5] = v[5]; |
621 | sin.sa.sa_data[0] = v[0]; | 672 | sin.sa.sa_data[0] = v[0]; |
622 | sin.sa.sa_data[1] = v[1]; | 673 | sin.sa.sa_data[1] = v[1]; |
623 | } | 674 | } |
624 | else | 675 | else |
625 | { | 676 | { |
626 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) | 677 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) |
627 | { | 678 | { |
628 | perror("getsockname"); | 679 | perror("getsockname"); |
629 | return 0; | 680 | return 0; |
630 | } | 681 | } |
631 | } | 682 | } |
632 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); | 683 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); |
633 | if (sData == -1) | 684 | if (sData == -1) |
634 | { | 685 | { |
635 | perror("socket"); | 686 | perror("socket"); |
636 | return -1; | 687 | return -1; |
637 | } | 688 | } |
638 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, | 689 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, |
639 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) | 690 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) |
640 | { | 691 | { |
641 | perror("setsockopt"); | 692 | perror("setsockopt"); |
642 | net_close(sData); | 693 | net_close(sData); |
643 | return -1; | 694 | return -1; |
644 | } | 695 | } |
645 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, | 696 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, |
646 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) | 697 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) |
647 | { | 698 | { |
648 | perror("setsockopt"); | 699 | perror("setsockopt"); |
649 | net_close(sData); | 700 | net_close(sData); |
650 | return -1; | 701 | return -1; |
651 | } | 702 | } |
652 | if (nControl->cmode == FTPLIB_PASSIVE) | 703 | if (nControl->cmode == FTPLIB_PASSIVE) |
653 | { | 704 | { |
654 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) | 705 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) |
655 | { | 706 | { |
656 | perror("connect"); | 707 | perror("connect"); |
657 | net_close(sData); | 708 | net_close(sData); |
658 | return -1; | 709 | return -1; |
659 | } | 710 | } |
660 | } | 711 | } |
661 | else | 712 | else |
662 | { | 713 | { |
663 | sin.in.sin_port = 0; | 714 | sin.in.sin_port = 0; |
664 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) | 715 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) |
665 | { | 716 | { |
666 | perror("bind"); | 717 | perror("bind"); |
667 | net_close(sData); | 718 | net_close(sData); |
668 | return 0; | 719 | return 0; |
669 | } | 720 | } |
670 | if (listen(sData, 1) < 0) | 721 | if (listen(sData, 1) < 0) |
671 | { | 722 | { |
672 | perror("listen"); | 723 | perror("listen"); |
673 | net_close(sData); | 724 | net_close(sData); |
674 | return 0; | 725 | return 0; |
675 | } | 726 | } |
676 | if (getsockname(sData, &sin.sa, &l) < 0) | 727 | if (getsockname(sData, &sin.sa, &l) < 0) |
677 | return 0; | 728 | return 0; |
678 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", | 729 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", |
679 | (unsigned char) sin.sa.sa_data[2], | 730 | (unsigned char) sin.sa.sa_data[2], |
680 | (unsigned char) sin.sa.sa_data[3], | 731 | (unsigned char) sin.sa.sa_data[3], |
681 | (unsigned char) sin.sa.sa_data[4], | 732 | (unsigned char) sin.sa.sa_data[4], |
682 | (unsigned char) sin.sa.sa_data[5], | 733 | (unsigned char) sin.sa.sa_data[5], |
683 | (unsigned char) sin.sa.sa_data[0], | 734 | (unsigned char) sin.sa.sa_data[0], |
684 | (unsigned char) sin.sa.sa_data[1]); | 735 | (unsigned char) sin.sa.sa_data[1]); |
685 | if (!FtpSendCmd(buf,'2',nControl)) | 736 | if (!FtpSendCmd(buf,'2',nControl)) |
686 | { | 737 | { |
687 | net_close(sData); | 738 | net_close(sData); |
688 | return 0; | 739 | return 0; |
689 | } | 740 | } |
690 | } | 741 | } |
691 | ctrl = calloc(1,sizeof(netbuf)); | 742 | ctrl = calloc(1,sizeof(netbuf)); |
692 | if (ctrl == NULL) | 743 | if (ctrl == NULL) |
693 | { | 744 | { |
694 | perror("calloc"); | 745 | perror("calloc"); |
695 | net_close(sData); | 746 | net_close(sData); |
696 | return -1; | 747 | return -1; |
697 | } | 748 | } |
698 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) | 749 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) |
699 | { | 750 | { |
700 | perror("calloc"); | 751 | perror("calloc"); |
701 | net_close(sData); | 752 | net_close(sData); |
702 | free(ctrl); | 753 | free(ctrl); |
703 | return -1; | 754 | return -1; |
704 | } | 755 | } |
705 | ctrl->handle = sData; | 756 | ctrl->handle = sData; |
706 | ctrl->dir = dir; | 757 | ctrl->dir = dir; |
707 | ctrl->idletime = nControl->idletime; | 758 | ctrl->idletime = nControl->idletime; |
708 | ctrl->idlearg = nControl->idlearg; | 759 | ctrl->idlearg = nControl->idlearg; |
709 | ctrl->xfered = 0; | 760 | ctrl->xfered = 0; |
710 | ctrl->xfered1 = 0; | 761 | ctrl->xfered1 = 0; |
711 | ctrl->cbbytes = nControl->cbbytes; | 762 | ctrl->cbbytes = nControl->cbbytes; |
712 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) | 763 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) |
713 | ctrl->idlecb = nControl->idlecb; | 764 | ctrl->idlecb = nControl->idlecb; |
714 | else | 765 | else |
715 | ctrl->idlecb = NULL; | 766 | ctrl->idlecb = NULL; |
716 | *nData = ctrl; | 767 | *nData = ctrl; |
717 | return 1; | 768 | return 1; |
718 | } | 769 | } |
719 | 770 | ||
720 | /* | 771 | /* |
721 | * FtpAcceptConnection - accept connection from server | 772 | * FtpAcceptConnection - accept connection from server |
722 | * | 773 | * |
723 | * return 1 if successful, 0 otherwise | 774 | * return 1 if successful, 0 otherwise |
724 | */ | 775 | */ |
725 | static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) | 776 | static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) |
726 | { | 777 | { |
727 | int sData; | 778 | int sData; |
728 | struct sockaddr addr; | 779 | struct sockaddr addr; |
729 | unsigned int l; | 780 | unsigned int l; |
730 | int i; | 781 | int i; |
731 | struct timeval tv; | 782 | struct timeval tv; |
732 | fd_set mask; | 783 | fd_set mask; |
733 | int rv; | 784 | int rv; |
734 | 785 | ||
735 | FD_ZERO(&mask); | 786 | FD_ZERO(&mask); |
736 | FD_SET(nControl->handle, &mask); | 787 | FD_SET(nControl->handle, &mask); |
737 | FD_SET(nData->handle, &mask); | 788 | FD_SET(nData->handle, &mask); |
738 | tv.tv_usec = 0; | 789 | tv.tv_usec = 0; |
739 | tv.tv_sec = ACCEPT_TIMEOUT; | 790 | tv.tv_sec = ACCEPT_TIMEOUT; |
791 | printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); | ||
740 | i = nControl->handle; | 792 | i = nControl->handle; |
741 | if (i < nData->handle) | 793 | if (i < nData->handle) |
742 | i = nData->handle; | 794 | i = nData->handle; |
743 | i = select(i+1, &mask, NULL, NULL, &tv); | 795 | i = select(i+1, &mask, NULL, NULL, &tv); |
744 | if (i == -1) | 796 | if (i == -1) |
745 | { | 797 | { |
746 | strncpy(nControl->response, strerror(errno), | 798 | strncpy(nControl->response, strerror(errno), |
747 | sizeof(nControl->response)); | 799 | sizeof(nControl->response)); |
748 | net_close(nData->handle); | 800 | net_close(nData->handle); |
749 | nData->handle = 0; | 801 | nData->handle = 0; |
750 | rv = 0; | 802 | rv = 0; |
751 | } | 803 | } |
752 | else if (i == 0) | 804 | else if (i == 0) |
753 | { | ||
754 | strcpy(nControl->response, "timed out waiting for connection"); | ||
755 | net_close(nData->handle); | ||
756 | nData->handle = 0; | ||
757 | rv = 0; | ||
758 | } | ||
759 | else | ||
760 | { | ||
761 | if (FD_ISSET(nData->handle, &mask)) | ||
762 | { | ||
763 | l = sizeof(addr); | ||
764 | sData = accept(nData->handle, &addr, &l); | ||
765 | i = errno; | ||
766 | net_close(nData->handle); | ||
767 | if (sData > 0) | ||
768 | { | 805 | { |
769 | rv = 1; | 806 | strcpy(nControl->response, "timed out waiting for connection"); |
770 | nData->handle = sData; | 807 | net_close(nData->handle); |
808 | nData->handle = 0; | ||
809 | rv = 0; | ||
771 | } | 810 | } |
772 | else | 811 | else |
773 | { | 812 | { |
774 | strncpy(nControl->response, strerror(i), | 813 | if (FD_ISSET(nData->handle, &mask)) |
775 | sizeof(nControl->response)); | 814 | { |
776 | nData->handle = 0; | 815 | l = sizeof(addr); |
777 | rv = 0; | 816 | sData = accept(nData->handle, &addr, &l); |
817 | i = errno; | ||
818 | net_close(nData->handle); | ||
819 | if (sData > 0) | ||
820 | { | ||
821 | rv = 1; | ||
822 | nData->handle = sData; | ||
823 | } | ||
824 | else | ||
825 | { | ||
826 | strncpy(nControl->response, strerror(i), | ||
827 | sizeof(nControl->response)); | ||
828 | nData->handle = 0; | ||
829 | rv = 0; | ||
830 | } | ||
831 | } | ||
832 | else if (FD_ISSET(nControl->handle, &mask)) | ||
833 | { | ||
834 | net_close(nData->handle); | ||
835 | nData->handle = 0; | ||
836 | readresp('2', nControl); | ||
837 | rv = 0; | ||
838 | } | ||
778 | } | 839 | } |
779 | } | ||
780 | else if (FD_ISSET(nControl->handle, &mask)) | ||
781 | { | ||
782 | net_close(nData->handle); | ||
783 | nData->handle = 0; | ||
784 | readresp('2', nControl); | ||
785 | rv = 0; | ||
786 | } | ||
787 | } | ||
788 | return rv; | 840 | return rv; |
789 | } | 841 | } |
790 | 842 | ||
791 | /* | 843 | /* |
792 | * FtpAccess - return a handle for a data stream | 844 | * FtpAccess - return a handle for a data stream |
793 | * | 845 | * |
794 | * return 1 if successful, 0 otherwise | 846 | * return 1 if successful, 0 otherwise |
795 | */ | 847 | */ |
796 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, | 848 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, |
797 | netbuf **nData) | 849 | netbuf **nData) |
798 | { | 850 | { |
799 | char buf[256]; | 851 | char buf[256]; |
800 | int dir; | 852 | int dir; |
801 | if ((path == NULL) && | 853 | if ((path == NULL) && |
802 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) | 854 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) |
803 | { | 855 | { |
804 | sprintf(nControl->response, | 856 | sprintf(nControl->response, |
805 | "Missing path argument for file transfer\n"); | 857 | "Missing path argument for file transfer\n"); |
806 | return 0; | 858 | return 0; |
807 | } | 859 | } |
808 | sprintf(buf, "TYPE %c", mode); | 860 | sprintf(buf, "TYPE %c", mode); |
809 | if (!FtpSendCmd(buf, '2', nControl)) | 861 | if (!FtpSendCmd(buf, '2', nControl)) |
810 | return 0; | 862 | return 0; |
811 | switch (typ) | 863 | switch (typ) |
812 | { | 864 | { |
813 | case FTPLIB_DIR: | 865 | case FTPLIB_DIR: |
814 | strcpy(buf,"NLST"); | 866 | strcpy(buf,"NLST"); |
815 | dir = FTPLIB_READ; | 867 | dir = FTPLIB_READ; |
816 | break; | 868 | break; |
817 | case FTPLIB_DIR_VERBOSE: | 869 | case FTPLIB_DIR_VERBOSE: |
818 | strcpy(buf,"LIST"); | 870 | strcpy(buf,"LIST"); |
819 | dir = FTPLIB_READ; | 871 | dir = FTPLIB_READ; |
820 | break; | 872 | break; |
821 | case FTPLIB_FILE_READ: | 873 | case FTPLIB_FILE_READ: |
822 | strcpy(buf,"RETR"); | 874 | strcpy(buf,"RETR"); |
823 | dir = FTPLIB_READ; | 875 | dir = FTPLIB_READ; |
824 | break; | 876 | break; |
825 | case FTPLIB_FILE_WRITE: | 877 | case FTPLIB_FILE_WRITE: |
826 | strcpy(buf,"STOR"); | 878 | strcpy(buf,"STOR"); |
827 | dir = FTPLIB_WRITE; | 879 | dir = FTPLIB_WRITE; |
828 | break; | 880 | break; |
829 | default: | 881 | default: |
830 | sprintf(nControl->response, "Invalid open type %d\n", typ); | 882 | sprintf(nControl->response, "Invalid open type %d\n", typ); |
831 | return 0; | ||
832 | } | ||
833 | if (path != NULL) | ||
834 | { | ||
835 | int i = strlen(buf); | ||
836 | buf[i++] = ' '; | ||
837 | if ((strlen(path) + i) >= sizeof(buf)) | ||
838 | return 0; | 883 | return 0; |
839 | strcpy(&buf[i],path); | 884 | } |
840 | } | 885 | if (path != NULL) |
886 | { | ||
887 | int i = strlen(buf); | ||
888 | buf[i++] = ' '; | ||
889 | if ((strlen(path) + i) >= sizeof(buf)) | ||
890 | return 0; | ||
891 | strcpy(&buf[i],path); | ||
892 | } | ||
841 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) | 893 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) |
842 | return 0; | 894 | return 0; |
843 | if (!FtpSendCmd(buf, '1', nControl)) | 895 | if (!FtpSendCmd(buf, '1', nControl)) |
844 | { | 896 | { |
845 | FtpClose(*nData); | 897 | FtpClose(*nData); |
846 | *nData = NULL; | 898 | *nData = NULL; |
847 | return 0; | 899 | return 0; |
848 | } | 900 | } |
849 | (*nData)->ctrl = nControl; | 901 | (*nData)->ctrl = nControl; |
850 | nControl->data = *nData; | 902 | nControl->data = *nData; |
851 | if (nControl->cmode == FTPLIB_PORT) | 903 | if (nControl->cmode == FTPLIB_PORT) |
852 | { | 904 | { |
853 | if (!FtpAcceptConnection(*nData,nControl)) | 905 | if (!FtpAcceptConnection(*nData,nControl)) |
854 | { | 906 | { |
855 | FtpClose(*nData); | 907 | FtpClose(*nData); |
856 | *nData = NULL; | 908 | *nData = NULL; |
857 | nControl->data = NULL; | 909 | nControl->data = NULL; |
858 | return 0; | 910 | return 0; |
859 | } | 911 | } |
860 | } | 912 | } |
861 | return 1; | 913 | return 1; |
862 | } | 914 | } |
863 | 915 | ||
864 | /* | 916 | /* |
865 | * FtpRead - read from a data connection | 917 | * FtpRead - read from a data connection |
866 | */ | 918 | */ |
867 | GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) | 919 | GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) |
868 | { | 920 | { |
869 | int i; | 921 | int i; |
870 | if (nData->dir != FTPLIB_READ) | 922 | if (nData->dir != FTPLIB_READ) |
871 | return 0; | 923 | return 0; |
872 | if (nData->buf) | 924 | if (nData->buf) |
873 | i = readline(buf, max, nData); | 925 | i = readline(buf, max, nData); |
874 | else | 926 | else |
875 | { | 927 | { |
876 | i = socket_wait(nData); | 928 | i = socket_wait(nData); |
877 | if (i != 1) | 929 | if (i != 1) |
878 | return 0; | 930 | return 0; |
879 | i = net_read(nData->handle, buf, max); | 931 | i = net_read(nData->handle, buf, max); |
880 | } | 932 | } |
881 | if (i == -1) | 933 | if (i == -1) |
882 | return 0; | 934 | return 0; |
883 | nData->xfered += i; | 935 | nData->xfered += i; |
884 | if (nData->idlecb && nData->cbbytes) | 936 | if (nData->idlecb && nData->cbbytes) |
885 | { | 937 | { |
886 | nData->xfered1 += i; | 938 | nData->xfered1 += i; |
887 | if (nData->xfered1 > nData->cbbytes) | 939 | if (nData->xfered1 > nData->cbbytes) |
888 | { | 940 | { |
889 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) | 941 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) |
890 | return 0; | 942 | return 0; |
891 | nData->xfered1 = 0; | 943 | nData->xfered1 = 0; |
892 | } | 944 | } |
893 | } | 945 | } |
894 | return i; | 946 | return i; |
895 | } | 947 | } |
896 | 948 | ||
897 | /* | 949 | /* |
898 | * FtpWrite - write to a data connection | 950 | * FtpWrite - write to a data connection |
899 | */ | 951 | */ |
900 | GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) | 952 | GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) |
901 | { | 953 | { |
902 | int i; | 954 | int i; |
903 | if (nData->dir != FTPLIB_WRITE) | 955 | if (nData->dir != FTPLIB_WRITE) |
904 | return 0; | 956 | return 0; |
905 | if (nData->buf) | 957 | if (nData->buf) |
906 | i = writeline(buf, len, nData); | 958 | i = writeline(buf, len, nData); |
907 | else | 959 | else |
908 | { | 960 | { |
909 | socket_wait(nData); | 961 | socket_wait(nData); |
910 | i = net_write(nData->handle, buf, len); | 962 | i = net_write(nData->handle, buf, len); |
911 | } | 963 | } |
912 | if (i == -1) | 964 | if (i == -1) |
913 | return 0; | 965 | return 0; |
914 | nData->xfered += i; | 966 | nData->xfered += i; |
915 | if (nData->idlecb && nData->cbbytes) | 967 | if (nData->idlecb && nData->cbbytes) |
916 | { | 968 | { |
917 | nData->xfered1 += i; | 969 | nData->xfered1 += i; |
918 | if (nData->xfered1 > nData->cbbytes) | 970 | if (nData->xfered1 > nData->cbbytes) |
919 | { | 971 | { |
920 | nData->idlecb(nData, nData->xfered, nData->idlearg); | 972 | nData->idlecb(nData, nData->xfered, nData->idlearg); |
921 | nData->xfered1 = 0; | 973 | nData->xfered1 = 0; |
922 | } | 974 | } |
923 | } | 975 | } |
924 | return i; | 976 | return i; |
925 | } | 977 | } |
926 | 978 | ||
927 | /* | 979 | /* |
928 | * FtpClose - close a data connection | 980 | * FtpClose - close a data connection |
929 | */ | 981 | */ |
930 | GLOBALDEF int FtpClose(netbuf *nData) | 982 | GLOBALDEF int FtpClose(netbuf *nData) |
931 | { | 983 | { |
932 | netbuf *ctrl; | 984 | netbuf *ctrl; |
933 | switch (nData->dir) | 985 | switch (nData->dir) |
934 | { | 986 | { |
935 | case FTPLIB_WRITE: | 987 | case FTPLIB_WRITE: |
936 | /* potential problem - if buffer flush fails, how to notify user? */ | 988 | /* potential problem - if buffer flush fails, how to notify user? */ |
937 | if (nData->buf != NULL) | 989 | if (nData->buf != NULL) |
938 | writeline(NULL, 0, nData); | 990 | writeline(NULL, 0, nData); |
939 | case FTPLIB_READ: | 991 | case FTPLIB_READ: |
940 | if (nData->buf) | 992 | if (nData->buf) |
941 | free(nData->buf); | 993 | free(nData->buf); |
942 | shutdown(nData->handle,2); | 994 | shutdown(nData->handle,2); |
943 | net_close(nData->handle); | 995 | net_close(nData->handle); |
944 | ctrl = nData->ctrl; | 996 | ctrl = nData->ctrl; |
945 | free(nData); | 997 | free(nData); |
946 | if (ctrl) | 998 | if (ctrl) |
947 | { | 999 | { |
948 | ctrl->data = NULL; | 1000 | ctrl->data = NULL; |
949 | return(readresp('2', ctrl)); | 1001 | return(readresp('2', ctrl)); |
950 | } | 1002 | } |
951 | return 1; | 1003 | return 1; |
952 | case FTPLIB_CONTROL: | 1004 | case FTPLIB_CONTROL: |
953 | if (nData->data) | 1005 | if (nData->data) |
954 | { | 1006 | { |
955 | nData->ctrl = NULL; | 1007 | nData->ctrl = NULL; |
956 | FtpClose(nData); | 1008 | FtpClose(nData); |
957 | } | 1009 | } |
958 | net_close(nData->handle); | 1010 | net_close(nData->handle); |
959 | free(nData); | 1011 | free(nData); |
960 | return 0; | 1012 | return 0; |
961 | } | 1013 | } |
962 | return 1; | 1014 | return 1; |
963 | } | 1015 | } |
964 | 1016 | ||
965 | /* | 1017 | /* |
966 | * FtpSite - send a SITE command | 1018 | * FtpSite - send a SITE command |
967 | * | 1019 | * |
968 | * return 1 if command successful, 0 otherwise | 1020 | * return 1 if command successful, 0 otherwise |
969 | */ | 1021 | */ |
970 | GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) | 1022 | GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) |
971 | { | 1023 | { |
972 | char buf[256]; | 1024 | char buf[256]; |
973 | 1025 | ||
974 | if ((strlen(cmd) + 7) > sizeof(buf)) | 1026 | if ((strlen(cmd) + 7) > sizeof(buf)) |
975 | return 0; | 1027 | return 0; |
976 | sprintf(buf,"SITE %s",cmd); | 1028 | sprintf(buf,"SITE %s",cmd); |
977 | if (!FtpSendCmd(buf,'2',nControl)) | 1029 | if (!FtpSendCmd(buf,'2',nControl)) |
978 | return 0; | 1030 | return 0; |
979 | return 1; | 1031 | return 1; |
980 | } | 1032 | } |
981 | 1033 | ||
982 | /* | 1034 | /* |
983 | * FtpSysType - send a SYST command | 1035 | * FtpSysType - send a SYST command |
984 | * | 1036 | * |
985 | * Fills in the user buffer with the remote system type. If more | 1037 | * Fills in the user buffer with the remote system type. If more |
986 | * information from the response is required, the user can parse | 1038 | * information from the response is required, the user can parse |
987 | * it out of the response buffer returned by FtpLastResponse(). | 1039 | * it out of the response buffer returned by FtpLastResponse(). |
988 | * | 1040 | * |
989 | * return 1 if command successful, 0 otherwise | 1041 | * return 1 if command successful, 0 otherwise |
990 | */ | 1042 | */ |
991 | GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) | 1043 | GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) |
992 | { | 1044 | { |
993 | int l = max; | 1045 | int l = max; |
994 | char *b = buf; | 1046 | char *b = buf; |
995 | char *s; | 1047 | char *s; |
996 | if (!FtpSendCmd("SYST",'2',nControl)) | 1048 | if (!FtpSendCmd("SYST",'2',nControl)) |
997 | return 0; | 1049 | return 0; |
998 | s = &nControl->response[4]; | 1050 | s = &nControl->response[4]; |
999 | while ((--l) && (*s != ' ')) | 1051 | while ((--l) && (*s != ' ')) |
1000 | *b++ = *s++; | 1052 | *b++ = *s++; |
1001 | *b++ = '\0'; | 1053 | *b++ = '\0'; |
1002 | return 1; | 1054 | return 1; |
1003 | } | 1055 | } |
1004 | 1056 | ||
1005 | /* | 1057 | /* |
1006 | * FtpMkdir - create a directory at server | 1058 | * FtpMkdir - create a directory at server |
1007 | * | 1059 | * |
1008 | * return 1 if successful, 0 otherwise | 1060 | * return 1 if successful, 0 otherwise |
1009 | */ | 1061 | */ |
1010 | GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) | 1062 | GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) |
1011 | { | 1063 | { |
1012 | char buf[256]; | 1064 | char buf[256]; |
1013 | 1065 | ||
1014 | if ((strlen(path) + 6) > sizeof(buf)) | 1066 | if ((strlen(path) + 6) > sizeof(buf)) |
1015 | return 0; | 1067 | return 0; |
1016 | sprintf(buf,"MKD %s",path); | 1068 | sprintf(buf,"MKD %s",path); |
1017 | if (!FtpSendCmd(buf,'2', nControl)) | 1069 | if (!FtpSendCmd(buf,'2', nControl)) |
1018 | return 0; | 1070 | return 0; |
1019 | return 1; | 1071 | return 1; |
1020 | } | 1072 | } |
1021 | 1073 | ||
1022 | /* | 1074 | /* |
1023 | * FtpChdir - change path at remote | 1075 | * FtpChdir - change path at remote |
1024 | * | 1076 | * |
1025 | * return 1 if successful, 0 otherwise | 1077 | * return 1 if successful, 0 otherwise |
1026 | */ | 1078 | */ |
1027 | GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) | 1079 | GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) |
1028 | { | 1080 | { |
1029 | char buf[256]; | 1081 | char buf[256]; |
1030 | 1082 | ||
1031 | if ((strlen(path) + 6) > sizeof(buf)) | 1083 | if ((strlen(path) + 6) > sizeof(buf)) |
1032 | return 0; | 1084 | return 0; |
1033 | sprintf(buf,"CWD %s",path); | 1085 | sprintf(buf,"CWD %s",path); |
1034 | if (!FtpSendCmd(buf,'2',nControl)) | 1086 | if (!FtpSendCmd(buf,'2',nControl)) |
1035 | return 0; | 1087 | return 0; |
1036 | return 1; | 1088 | return 1; |
1037 | } | 1089 | } |
1038 | 1090 | ||
1039 | /* | 1091 | /* |
1040 | * FtpCDUp - move to parent directory at remote | 1092 | * FtpCDUp - move to parent directory at remote |
1041 | * | 1093 | * |
1042 | * return 1 if successful, 0 otherwise | 1094 | * return 1 if successful, 0 otherwise |
1043 | */ | 1095 | */ |
1044 | GLOBALDEF int FtpCDUp(netbuf *nControl) | 1096 | GLOBALDEF int FtpCDUp(netbuf *nControl) |
1045 | { | 1097 | { |
1046 | if (!FtpSendCmd("CDUP",'2',nControl)) | 1098 | if (!FtpSendCmd("CDUP",'2',nControl)) |
1047 | return 0; | 1099 | return 0; |
1048 | return 1; | 1100 | return 1; |
1049 | } | 1101 | } |
1050 | 1102 | ||
1051 | /* | 1103 | /* |
1052 | * FtpRmdir - remove directory at remote | 1104 | * FtpRmdir - remove directory at remote |
1053 | * | 1105 | * |
1054 | * return 1 if successful, 0 otherwise | 1106 | * return 1 if successful, 0 otherwise |
1055 | */ | 1107 | */ |
1056 | GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) | 1108 | GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) |
1057 | { | 1109 | { |
1058 | char buf[256]; | 1110 | char buf[256]; |
1059 | 1111 | ||
1060 | if ((strlen(path) + 6) > sizeof(buf)) | 1112 | if ((strlen(path) + 6) > sizeof(buf)) |
1061 | return 0; | 1113 | return 0; |
1062 | sprintf(buf,"RMD %s",path); | 1114 | sprintf(buf,"RMD %s",path); |
1063 | if (!FtpSendCmd(buf,'2',nControl)) | 1115 | if (!FtpSendCmd(buf,'2',nControl)) |
1064 | return 0; | 1116 | return 0; |
1065 | return 1; | 1117 | return 1; |
1066 | } | 1118 | } |
1067 | 1119 | ||
1068 | /* | 1120 | /* |
1069 | * FtpPwd - get working directory at remote | 1121 | * FtpPwd - get working directory at remote |
1070 | * | 1122 | * |
1071 | * return 1 if successful, 0 otherwise | 1123 | * return 1 if successful, 0 otherwise |
1072 | */ | 1124 | */ |
1073 | GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) | 1125 | GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) |
1074 | { | 1126 | { |
1075 | int l = max; | 1127 | int l = max; |
1076 | char *b = path; | 1128 | char *b = path; |
1077 | char *s; | 1129 | char *s; |
1078 | if (!FtpSendCmd("PWD",'2',nControl)) | 1130 | if (!FtpSendCmd("PWD",'2',nControl)) |
1079 | return 0; | 1131 | return 0; |
1080 | s = strchr(nControl->response, '"'); | 1132 | s = strchr(nControl->response, '"'); |
1081 | if (s == NULL) | 1133 | if (s == NULL) |
1082 | return 0; | 1134 | return 0; |
1083 | s++; | 1135 | s++; |
1084 | while ((--l) && (*s) && (*s != '"')) | 1136 | while ((--l) && (*s) && (*s != '"')) |
1085 | *b++ = *s++; | 1137 | *b++ = *s++; |
1086 | *b++ = '\0'; | 1138 | *b++ = '\0'; |
1087 | return 1; | 1139 | return 1; |
1088 | } | 1140 | } |
1089 | 1141 | ||
1090 | /* | 1142 | /* |
1091 | * FtpXfer - issue a command and transfer data | 1143 | * FtpXfer - issue a command and transfer data |
1092 | * | 1144 | * |
1093 | * return 1 if successful, 0 otherwise | 1145 | * return 1 if successful, 0 otherwise |
1094 | */ | 1146 | */ |
1095 | static int FtpXfer(const char *localfile, const char *path, | 1147 | static int FtpXfer(const char *localfile, const char *path, |
1096 | netbuf *nControl, int typ, int mode) | 1148 | netbuf *nControl, int typ, int mode) |
1097 | { | 1149 | { |
1098 | int l,c; | 1150 | int l,c; |
1099 | char *dbuf; | 1151 | char *dbuf; |
1100 | FILE *local = NULL; | 1152 | FILE *local = NULL; |
1101 | netbuf *nData; | 1153 | netbuf *nData; |
1102 | int rv=1; | 1154 | int rv=1; |
1103 | 1155 | ||
1104 | if (localfile != NULL) | 1156 | if (localfile != NULL) |
1105 | { | 1157 | { |
1106 | char ac[4] = "w"; | 1158 | char ac[4] = "w"; |
1107 | if (typ == FTPLIB_FILE_WRITE) | 1159 | if (typ == FTPLIB_FILE_WRITE) |
1108 | ac[0] = 'r'; | 1160 | ac[0] = 'r'; |
1109 | if (mode == FTPLIB_IMAGE) | 1161 | if (mode == FTPLIB_IMAGE) |
1110 | ac[1] = 'b'; | 1162 | ac[1] = 'b'; |
1111 | local = fopen(localfile, ac); | 1163 | local = fopen(localfile, ac); |
1112 | if (local == NULL) | 1164 | if (local == NULL) |
1113 | { | 1165 | { |
1114 | strncpy(nControl->response, strerror(errno), | 1166 | strncpy(nControl->response, strerror(errno), |
1115 | sizeof(nControl->response)); | 1167 | sizeof(nControl->response)); |
1116 | return 0; | 1168 | return 0; |
1117 | } | 1169 | } |
1118 | } | 1170 | } |
1119 | if (local == NULL) | 1171 | if (local == NULL) |
1120 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; | 1172 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; |
1121 | if (!FtpAccess(path, typ, mode, nControl, &nData)) | 1173 | if (!FtpAccess(path, typ, mode, nControl, &nData)) |
1122 | return 0; | 1174 | return 0; |
1123 | dbuf = malloc(FTPLIB_BUFSIZ); | 1175 | dbuf = malloc(FTPLIB_BUFSIZ); |
1124 | if (typ == FTPLIB_FILE_WRITE) | 1176 | if (typ == FTPLIB_FILE_WRITE) |
1125 | { | ||
1126 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) | ||
1127 | if ((c = FtpWrite(dbuf, l, nData)) < l) | ||
1128 | { | 1177 | { |
1129 | printf("short write: passed %d, wrote %d\n", l, c); | 1178 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) |
1130 | rv = 0; | 1179 | if ((c = FtpWrite(dbuf, l, nData)) < l) |
1131 | break; | 1180 | { |
1181 | printf("short write: passed %d, wrote %d\n", l, c); | ||
1182 | rv = 0; | ||
1183 | break; | ||
1184 | } | ||
1132 | } | 1185 | } |
1133 | } | ||
1134 | else | 1186 | else |
1135 | { | ||
1136 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) | ||
1137 | if (fwrite(dbuf, 1, l, local) <= 0) | ||
1138 | { | 1187 | { |
1139 | perror("localfile write"); | 1188 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) |
1140 | rv = 0; | 1189 | if (fwrite(dbuf, 1, l, local) <= 0) |
1141 | break; | 1190 | { |
1191 | perror("localfile write"); | ||
1192 | rv = 0; | ||
1193 | break; | ||
1194 | } | ||
1142 | } | 1195 | } |
1143 | } | ||
1144 | free(dbuf); | 1196 | free(dbuf); |
1145 | fflush(local); | 1197 | fflush(local); |
1146 | if (localfile != NULL) | 1198 | if (localfile != NULL) |
1147 | fclose(local); | 1199 | fclose(local); |
1148 | FtpClose(nData); | 1200 | FtpClose(nData); |
1149 | return rv; | 1201 | return rv; |
1150 | } | 1202 | } |
1151 | 1203 | ||
1152 | /* | 1204 | /* |
1153 | * FtpNlst - issue an NLST command and write response to output | 1205 | * FtpNlst - issue an NLST command and write response to output |
1154 | * | 1206 | * |
1155 | * return 1 if successful, 0 otherwise | 1207 | * return 1 if successful, 0 otherwise |
1156 | */ | 1208 | */ |
1157 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, | 1209 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, |
1158 | netbuf *nControl) | 1210 | netbuf *nControl) |
1159 | { | 1211 | { |
1160 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); | 1212 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); |
1161 | } | 1213 | } |
1162 | 1214 | ||
1163 | /* | 1215 | /* |
1164 | * FtpDir - issue a LIST command and write response to output | 1216 | * FtpDir - issue a LIST command and write response to output |
1165 | * | 1217 | * |
1166 | * return 1 if successful, 0 otherwise | 1218 | * return 1 if successful, 0 otherwise |
1167 | */ | 1219 | */ |
1168 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) | 1220 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) |
1169 | { | 1221 | { |
1170 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); | 1222 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); |
1171 | } | 1223 | } |
1172 | 1224 | ||
1173 | /* | 1225 | /* |
1174 | * FtpSize - determine the size of a remote file | 1226 | * FtpSize - determine the size of a remote file |
1175 | * | 1227 | * |
1176 | * return 1 if successful, 0 otherwise | 1228 | * return 1 if successful, 0 otherwise |
1177 | */ | 1229 | */ |
1178 | GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) | 1230 | GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) |
1179 | { | 1231 | { |
1180 | char cmd[256]; | 1232 | char cmd[256]; |
1181 | int resp,sz,rv=1; | 1233 | int resp,sz,rv=1; |
1182 | 1234 | ||
1183 | if ((strlen(path) + 7) > sizeof(cmd)) | 1235 | if ((strlen(path) + 7) > sizeof(cmd)) |
1184 | return 0; | 1236 | return 0; |
1185 | sprintf(cmd, "TYPE %c", mode); | 1237 | sprintf(cmd, "TYPE %c", mode); |
1186 | if (!FtpSendCmd(cmd, '2', nControl)) | 1238 | if (!FtpSendCmd(cmd, '2', nControl)) |
1187 | return 0; | 1239 | return 0; |
1188 | sprintf(cmd,"SIZE %s",path); | 1240 | sprintf(cmd,"SIZE %s",path); |
1189 | if (!FtpSendCmd(cmd,'2',nControl)) | 1241 | if (!FtpSendCmd(cmd,'2',nControl)) |
1190 | rv = 0; | 1242 | rv = 0; |
1191 | else | 1243 | else |
1192 | { | 1244 | { |
1193 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) | 1245 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) |
1194 | *size = sz; | 1246 | *size = sz; |
1195 | else | 1247 | else |
1196 | rv = 0; | 1248 | rv = 0; |
1197 | } | 1249 | } |
1198 | return rv; | 1250 | return rv; |
1199 | } | 1251 | } |
1200 | 1252 | ||
1201 | /* | 1253 | /* |
1202 | * FtpModDate - determine the modification date of a remote file | 1254 | * FtpModDate - determine the modification date of a remote file |
1203 | * | 1255 | * |
1204 | * return 1 if successful, 0 otherwise | 1256 | * return 1 if successful, 0 otherwise |
1205 | */ | 1257 | */ |
1206 | GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) | 1258 | GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) |
1207 | { | 1259 | { |
1208 | char buf[256]; | 1260 | char buf[256]; |
1209 | int rv = 1; | 1261 | int rv = 1; |
1210 | 1262 | ||
1211 | if ((strlen(path) + 7) > sizeof(buf)) | 1263 | if ((strlen(path) + 7) > sizeof(buf)) |
1212 | return 0; | 1264 | return 0; |
1213 | sprintf(buf,"MDTM %s",path); | 1265 | sprintf(buf,"MDTM %s",path); |
1214 | if (!FtpSendCmd(buf,'2',nControl)) | 1266 | if (!FtpSendCmd(buf,'2',nControl)) |
1215 | rv = 0; | 1267 | rv = 0; |
1216 | else | 1268 | else |
1217 | strncpy(dt, &nControl->response[4], max); | 1269 | strncpy(dt, &nControl->response[4], max); |
1218 | return rv; | 1270 | return rv; |
1219 | } | 1271 | } |
1220 | 1272 | ||
1221 | /* | 1273 | /* |
1222 | * FtpGet - issue a GET command and write received data to output | 1274 | * FtpGet - issue a GET command and write received data to output |
1223 | * | 1275 | * |
1224 | * return 1 if successful, 0 otherwise | 1276 | * return 1 if successful, 0 otherwise |
1225 | */ | 1277 | */ |
1226 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, | 1278 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, |
1227 | char mode, netbuf *nControl) | 1279 | char mode, netbuf *nControl) |
1228 | { | 1280 | { |
1229 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); | 1281 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); |
1230 | } | 1282 | } |
1231 | 1283 | ||
1232 | /* | 1284 | /* |
1233 | * FtpPut - issue a PUT command and send data from input | 1285 | * FtpPut - issue a PUT command and send data from input |
1234 | * | 1286 | * |
1235 | * return 1 if successful, 0 otherwise | 1287 | * return 1 if successful, 0 otherwise |
1236 | */ | 1288 | */ |
1237 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, | 1289 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, |
1238 | netbuf *nControl) | 1290 | netbuf *nControl) |
1239 | { | 1291 | { |
1240 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); | 1292 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); |
1241 | } | 1293 | } |
1242 | 1294 | ||
1243 | /* | 1295 | /* |
1244 | * FtpRename - rename a file at remote | 1296 | * FtpRename - rename a file at remote |
1245 | * | 1297 | * |
1246 | * return 1 if successful, 0 otherwise | 1298 | * return 1 if successful, 0 otherwise |
1247 | */ | 1299 | */ |
1248 | GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) | 1300 | GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) |
1249 | { | 1301 | { |
1250 | char cmd[256]; | 1302 | char cmd[256]; |
1251 | 1303 | ||
1252 | if (((strlen(src) + 7) > sizeof(cmd)) || | 1304 | if (((strlen(src) + 7) > sizeof(cmd)) || |
1253 | ((strlen(dst) + 7) > sizeof(cmd))) | 1305 | ((strlen(dst) + 7) > sizeof(cmd))) |
1254 | return 0; | 1306 | return 0; |
1255 | sprintf(cmd,"RNFR %s",src); | 1307 | sprintf(cmd,"RNFR %s",src); |
1256 | if (!FtpSendCmd(cmd,'3',nControl)) | 1308 | if (!FtpSendCmd(cmd,'3',nControl)) |
1257 | return 0; | 1309 | return 0; |
1258 | sprintf(cmd,"RNTO %s",dst); | 1310 | sprintf(cmd,"RNTO %s",dst); |
1259 | if (!FtpSendCmd(cmd,'2',nControl)) | 1311 | if (!FtpSendCmd(cmd,'2',nControl)) |
1260 | return 0; | 1312 | return 0; |
1261 | return 1; | 1313 | return 1; |
1262 | } | 1314 | } |
1263 | 1315 | ||
1264 | /* | 1316 | /* |
1265 | * FtpDelete - delete a file at remote | 1317 | * FtpDelete - delete a file at remote |
1266 | * | 1318 | * |
1267 | * return 1 if successful, 0 otherwise | 1319 | * return 1 if successful, 0 otherwise |
1268 | */ | 1320 | */ |
1269 | GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) | 1321 | GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) |
1270 | { | 1322 | { |
1271 | char cmd[256]; | 1323 | char cmd[256]; |
1272 | 1324 | ||
1273 | if ((strlen(fnm) + 7) > sizeof(cmd)) | 1325 | if ((strlen(fnm) + 7) > sizeof(cmd)) |
1274 | return 0; | 1326 | return 0; |
1275 | sprintf(cmd,"DELE %s",fnm); | 1327 | sprintf(cmd,"DELE %s",fnm); |
1276 | if (!FtpSendCmd(cmd,'2', nControl)) | 1328 | if (!FtpSendCmd(cmd,'2', nControl)) |
1277 | return 0; | 1329 | return 0; |
1278 | return 1; | 1330 | return 1; |
1279 | } | 1331 | } |
1280 | 1332 | ||
1281 | /* | 1333 | /* |
1282 | * FtpQuit - disconnect from remote | 1334 | * FtpQuit - disconnect from remote |
1283 | * | 1335 | * |
1284 | * return 1 if successful, 0 otherwise | 1336 | * return 1 if successful, 0 otherwise |
1285 | */ | 1337 | */ |
1286 | GLOBALDEF void FtpQuit(netbuf *nControl) | 1338 | GLOBALDEF void FtpQuit(netbuf *nControl) |
1287 | { | 1339 | { |
1288 | if (nControl->dir != FTPLIB_CONTROL) | 1340 | if (nControl->dir != FTPLIB_CONTROL) |
1289 | return; | 1341 | return; |
1290 | FtpSendCmd("QUIT",'2',nControl); | 1342 | FtpSendCmd("QUIT",'2',nControl); |
1291 | net_close(nControl->handle); | 1343 | net_close(nControl->handle); |
1292 | free(nControl->buf); | 1344 | free(nControl->buf); |
1293 | free(nControl); | 1345 | free(nControl); |
1294 | } | 1346 | } |
diff --git a/noncore/net/ftplib/ftplib.control b/noncore/net/ftplib/ftplib.control new file mode 100644 index 0000000..67765ad --- a/dev/null +++ b/noncore/net/ftplib/ftplib.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: $QTDIR/lib/libftplib.* | ||
2 | Priority: optional | ||
3 | Section: Communications | ||
4 | Maintainer: L.J. Potter <ljp@llornkcor.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-$SUB_VERSION | ||
7 | Depends: opie-base ($QPE_VERSION) | ||
8 | Description: Libftp | ||
9 | The ftp library for the Opie environment. | ||
diff --git a/noncore/net/opieftp/ftplib.h b/noncore/net/ftplib/ftplib.h index 75a90ae..75a90ae 100644 --- a/noncore/net/opieftp/ftplib.h +++ b/noncore/net/ftplib/ftplib.h | |||
diff --git a/noncore/net/ftplib/ftplib.pro b/noncore/net/ftplib/ftplib.pro new file mode 100644 index 0000000..9ee3605 --- a/dev/null +++ b/noncore/net/ftplib/ftplib.pro | |||
@@ -0,0 +1,6 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG = qt warn_on release | ||
3 | HEADERS = ftplib.h | ||
4 | SOURCES = ftplib.c | ||
5 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | ||
6 | INTERFACES = | ||
diff --git a/noncore/net/opieftp/opieftp.control b/noncore/net/opieftp/opieftp.control index 18ec80f..42590bd 100644 --- a/noncore/net/opieftp/opieftp.control +++ b/noncore/net/opieftp/opieftp.control | |||
@@ -1,9 +1,9 @@ | |||
1 | Files: bin/opieftp pics/opieftp apps/Applications/opieftp.desktop | 1 | Files: bin/opieftp pics/opieftp apps/Applications/opieftp.desktop |
2 | Priority: optional | 2 | Priority: optional |
3 | Section: Communications | 3 | Section: Communications |
4 | Maintainer: L.J. Potter <ljp@llornkcor.com> | 4 | Maintainer: L.J. Potter <ljp@llornkcor.com> |
5 | Architecture: arm | 5 | Architecture: arm |
6 | Version: $QPE_VERSION-$SUB_VERSION | 6 | Version: $QPE_VERSION-$SUB_VERSION |
7 | Depends: opie-base ($QPE_VERSION) | 7 | Depends: opie-base ($QPE_VERSION), ftplib |
8 | Description: OpieFtp | 8 | Description: OpieFtp |
9 | The ftp client for the Opie environment. | 9 | The ftp client for the Opie environment. |
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 292cc9d..7c83223 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp | |||
@@ -1,1512 +1,1516 @@ | |||
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 DEVELOPERS_VERSION | 12 | //#define DEVELOPERS_VERSION |
13 | 13 | ||
14 | #include "opieftp.h" | 14 | #include "opieftp.h" |
15 | 15 | ||
16 | extern "C" { | 16 | extern "C" { |
17 | #include "ftplib.h" | 17 | #include "../ftplib/ftplib.h" |
18 | } | 18 | } |
19 | 19 | ||
20 | #include "inputDialog.h" | 20 | #include "inputDialog.h" |
21 | 21 | ||
22 | #include <qpe/qpemenubar.h> | 22 | #include <qpe/qpemenubar.h> |
23 | #include <qpe/qpetoolbar.h> | 23 | #include <qpe/qpetoolbar.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/mimetype.h> | 28 | #include <qpe/mimetype.h> |
29 | #include <qpe/qpemessagebox.h> | 29 | #include <qpe/qpemessagebox.h> |
30 | 30 | ||
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
34 | #include <qtoolbutton.h> | 34 | #include <qtoolbutton.h> |
35 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qcombobox.h> | 39 | #include <qcombobox.h> |
40 | #include <qpopupmenu.h> | 40 | #include <qpopupmenu.h> |
41 | #include <qlistview.h> | 41 | #include <qlistview.h> |
42 | #include <qmainwindow.h> | 42 | #include <qmainwindow.h> |
43 | #include <qlabel.h> | 43 | #include <qlabel.h> |
44 | #include <qprogressbar.h> | 44 | #include <qprogressbar.h> |
45 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
46 | #include <qtabwidget.h> | 46 | #include <qtabwidget.h> |
47 | #include <qwidget.h> | 47 | #include <qwidget.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qimage.h> | 49 | #include <qimage.h> |
50 | #include <qpixmap.h> | 50 | #include <qpixmap.h> |
51 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
52 | #include <qlineedit.h> | 52 | #include <qlineedit.h> |
53 | #include <qregexp.h> | 53 | #include <qregexp.h> |
54 | #include <qlistbox.h> | 54 | #include <qlistbox.h> |
55 | 55 | ||
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | #include <stdlib.h> | 57 | #include <stdlib.h> |
58 | 58 | ||
59 | 59 | ||
60 | QProgressBar *ProgressBar; | 60 | QProgressBar *ProgressBar; |
61 | static netbuf *conn=NULL; | 61 | static netbuf *conn=NULL; |
62 | 62 | ||
63 | static int log_progress(netbuf *, int xfered, void *) | 63 | static int log_progress(netbuf *, int xfered, void *) |
64 | { | 64 | { |
65 | // int fsz = *(int *)arg; | 65 | // int fsz = *(int *)arg; |
66 | // int pct = (xfered * 100) / fsz; | 66 | // int pct = (xfered * 100) / fsz; |
67 | // printf("%3d%%\r", pct); | 67 | // printf("%3d%%\r", pct); |
68 | // fflush(stdout); | 68 | // fflush(stdout); |
69 | ProgressBar->setProgress(xfered); | 69 | ProgressBar->setProgress(xfered); |
70 | qApp->processEvents(); | 70 | qApp->processEvents(); |
71 | return 1; | 71 | return 1; |
72 | } | 72 | } |
73 | 73 | ||
74 | OpieFtp::OpieFtp( ) | 74 | OpieFtp::OpieFtp( ) |
75 | : QMainWindow( ) | 75 | : QMainWindow( ) |
76 | { | 76 | { |
77 | setCaption( tr( "OpieFtp" ) ); | 77 | setCaption( tr( "OpieFtp" ) ); |
78 | fuckeduphack=FALSE; | 78 | fuckeduphack=FALSE; |
79 | QGridLayout *layout = new QGridLayout( this ); | 79 | QGridLayout *layout = new QGridLayout( this ); |
80 | layout->setSpacing( 2); | 80 | layout->setSpacing( 2); |
81 | layout->setMargin( 2); | 81 | layout->setMargin( 2); |
82 | 82 | ||
83 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 83 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
84 | 84 | ||
85 | QPEMenuBar *menuBar = new QPEMenuBar(this); | 85 | QPEMenuBar *menuBar = new QPEMenuBar(this); |
86 | // QPEToolBar *menuBar = new QPEToolBar(this); | 86 | // QPEToolBar *menuBar = new QPEToolBar(this); |
87 | // menuBar->setHorizontalStretchable( TRUE ); | 87 | // menuBar->setHorizontalStretchable( TRUE ); |
88 | 88 | ||
89 | connectionMenu = new QPopupMenu( this ); | 89 | connectionMenu = new QPopupMenu( this ); |
90 | localMenu = new QPopupMenu( this ); | 90 | localMenu = new QPopupMenu( this ); |
91 | remoteMenu = new QPopupMenu( this ); | 91 | remoteMenu = new QPopupMenu( this ); |
92 | tabMenu = new QPopupMenu( this ); | 92 | tabMenu = new QPopupMenu( this ); |
93 | 93 | ||
94 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 ); | 94 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 ); |
95 | 95 | ||
96 | menuBar->insertItem( tr( "Connection" ), connectionMenu); | 96 | menuBar->insertItem( tr( "Connection" ), connectionMenu); |
97 | menuBar->insertItem( tr( "Local" ), localMenu); | 97 | menuBar->insertItem( tr( "Local" ), localMenu); |
98 | menuBar->insertItem( tr( "Remote" ), remoteMenu); | 98 | menuBar->insertItem( tr( "Remote" ), remoteMenu); |
99 | menuBar->insertItem( tr( "View" ), tabMenu); | 99 | menuBar->insertItem( tr( "View" ), tabMenu); |
100 | 100 | ||
101 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); | 101 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); |
102 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); | 102 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); |
103 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); | 103 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); |
104 | 104 | ||
105 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 105 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
106 | localMenu->insertSeparator(); | 106 | localMenu->insertSeparator(); |
107 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 107 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
108 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 108 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
109 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 109 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
110 | localMenu->insertSeparator(); | 110 | localMenu->insertSeparator(); |
111 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 111 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
112 | localMenu->setCheckable(TRUE); | 112 | localMenu->setCheckable(TRUE); |
113 | 113 | ||
114 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 114 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
115 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 115 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
116 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 116 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
117 | remoteMenu->insertSeparator(); | 117 | remoteMenu->insertSeparator(); |
118 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 118 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
119 | 119 | ||
120 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); | 120 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); |
121 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); | 121 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); |
122 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); | 122 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); |
123 | tabMenu->insertSeparator(); | 123 | tabMenu->insertSeparator(); |
124 | tabMenu->insertItem( tr( "About" ), this, SLOT( doAbout() )); | 124 | tabMenu->insertItem( tr( "About" ), this, SLOT( doAbout() )); |
125 | tabMenu->setCheckable(TRUE); | 125 | tabMenu->setCheckable(TRUE); |
126 | 126 | ||
127 | 127 | ||
128 | 128 | ||
129 | cdUpButton = new QToolButton( this,"cdUpButton"); | 129 | cdUpButton = new QToolButton( this,"cdUpButton"); |
130 | cdUpButton->setPixmap(Resource::loadPixmap("up")); | 130 | cdUpButton->setPixmap(Resource::loadPixmap("up")); |
131 | cdUpButton ->setFixedSize( QSize( 20, 20 ) ); | 131 | cdUpButton ->setFixedSize( QSize( 20, 20 ) ); |
132 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); | 132 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); |
133 | layout->addMultiCellWidget( cdUpButton, 0, 0, 3, 3 ); | 133 | layout->addMultiCellWidget( cdUpButton, 0, 0, 3, 3 ); |
134 | cdUpButton->hide(); | 134 | cdUpButton->hide(); |
135 | 135 | ||
136 | // docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | 136 | // docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); |
137 | // docButton->setFixedSize( QSize( 20, 20 ) ); | 137 | // docButton->setFixedSize( QSize( 20, 20 ) ); |
138 | // connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | 138 | // connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); |
139 | // docButton->setFlat(TRUE); | 139 | // docButton->setFlat(TRUE); |
140 | // layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); | 140 | // layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); |
141 | 141 | ||
142 | homeButton = new QToolButton(this,"homeButton"); | 142 | homeButton = new QToolButton(this,"homeButton"); |
143 | homeButton->setPixmap( Resource::loadPixmap("home")); | 143 | homeButton->setPixmap( Resource::loadPixmap("home")); |
144 | homeButton->setFixedSize( QSize( 20, 20 ) ); | 144 | homeButton->setFixedSize( QSize( 20, 20 ) ); |
145 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 145 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
146 | layout->addMultiCellWidget( homeButton, 0, 0, 4, 4); | 146 | layout->addMultiCellWidget( homeButton, 0, 0, 4, 4); |
147 | homeButton->hide(); | 147 | homeButton->hide(); |
148 | 148 | ||
149 | TabWidget = new QTabWidget( this, "TabWidget" ); | 149 | TabWidget = new QTabWidget( this, "TabWidget" ); |
150 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 4 ); | 150 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 4 ); |
151 | 151 | ||
152 | // TabWidget->setTabShape(QTabWidget::Triangular); | 152 | // TabWidget->setTabShape(QTabWidget::Triangular); |
153 | 153 | ||
154 | tab = new QWidget( TabWidget, "tab" ); | 154 | tab = new QWidget( TabWidget, "tab" ); |
155 | tabLayout = new QGridLayout( tab ); | 155 | tabLayout = new QGridLayout( tab ); |
156 | tabLayout->setSpacing( 2); | 156 | tabLayout->setSpacing( 2); |
157 | tabLayout->setMargin( 2); | 157 | tabLayout->setMargin( 2); |
158 | 158 | ||
159 | Local_View = new QListView( tab, "Local_View" ); | 159 | Local_View = new QListView( tab, "Local_View" ); |
160 | // Local_View->setResizePolicy( QListView::AutoOneFit ); | 160 | // Local_View->setResizePolicy( QListView::AutoOneFit ); |
161 | Local_View->addColumn( tr("File"),150); | 161 | Local_View->addColumn( tr("File"),150); |
162 | Local_View->addColumn( tr("Date"),-1); | 162 | Local_View->addColumn( tr("Date"),-1); |
163 | Local_View->setColumnAlignment(1,QListView::AlignRight); | 163 | Local_View->setColumnAlignment(1,QListView::AlignRight); |
164 | Local_View->addColumn( tr("Size"),-1); | 164 | Local_View->addColumn( tr("Size"),-1); |
165 | Local_View->setColumnAlignment(2,QListView::AlignRight); | 165 | Local_View->setColumnAlignment(2,QListView::AlignRight); |
166 | Local_View->setAllColumnsShowFocus(TRUE); | 166 | Local_View->setAllColumnsShowFocus(TRUE); |
167 | 167 | ||
168 | Local_View->setMultiSelection( TRUE); | 168 | Local_View->setMultiSelection( TRUE); |
169 | Local_View->setSelectionMode(QListView::Extended); | 169 | Local_View->setSelectionMode(QListView::Extended); |
170 | Local_View->setFocusPolicy(QWidget::ClickFocus); | 170 | Local_View->setFocusPolicy(QWidget::ClickFocus); |
171 | 171 | ||
172 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); | 172 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); |
173 | 173 | ||
174 | tabLayout->addWidget( Local_View, 0, 0 ); | 174 | tabLayout->addWidget( Local_View, 0, 0 ); |
175 | 175 | ||
176 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), | 176 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), |
177 | this,SLOT( localListClicked(QListViewItem *)) ); | 177 | this,SLOT( localListClicked(QListViewItem *)) ); |
178 | // connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), | 178 | // connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), |
179 | // this,SLOT( localListClicked(QListViewItem *)) ); | 179 | // this,SLOT( localListClicked(QListViewItem *)) ); |
180 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 180 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
181 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | 181 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); |
182 | 182 | ||
183 | TabWidget->insertTab( tab, tr( "Local" ) ); | 183 | TabWidget->insertTab( tab, tr( "Local" ) ); |
184 | 184 | ||
185 | tab_2 = new QWidget( TabWidget, "tab_2" ); | 185 | tab_2 = new QWidget( TabWidget, "tab_2" ); |
186 | tabLayout_2 = new QGridLayout( tab_2 ); | 186 | tabLayout_2 = new QGridLayout( tab_2 ); |
187 | tabLayout_2->setSpacing( 2); | 187 | tabLayout_2->setSpacing( 2); |
188 | tabLayout_2->setMargin( 2); | 188 | tabLayout_2->setMargin( 2); |
189 | 189 | ||
190 | Remote_View = new QListView( tab_2, "Remote_View" ); | 190 | Remote_View = new QListView( tab_2, "Remote_View" ); |
191 | Remote_View->addColumn( tr("File"),150); | 191 | Remote_View->addColumn( tr("File"),150); |
192 | Remote_View->addColumn( tr("Date"),-1); | 192 | Remote_View->addColumn( tr("Date"),-1); |
193 | // Remote_View->setColumnAlignment(1,QListView::AlignRight); | 193 | // Remote_View->setColumnAlignment(1,QListView::AlignRight); |
194 | Remote_View->addColumn( tr("Size"),-1); | 194 | Remote_View->addColumn( tr("Size"),-1); |
195 | Remote_View->setColumnAlignment(2,QListView::AlignRight); | 195 | Remote_View->setColumnAlignment(2,QListView::AlignRight); |
196 | Remote_View->setColumnAlignment(3,QListView::AlignCenter); | 196 | Remote_View->setColumnAlignment(3,QListView::AlignCenter); |
197 | Remote_View->addColumn( tr("Dir"),-1); | 197 | Remote_View->addColumn( tr("Dir"),-1); |
198 | Remote_View->setColumnAlignment(4,QListView::AlignRight); | 198 | Remote_View->setColumnAlignment(4,QListView::AlignRight); |
199 | Remote_View->setAllColumnsShowFocus(TRUE); | 199 | Remote_View->setAllColumnsShowFocus(TRUE); |
200 | 200 | ||
201 | Remote_View->setMultiSelection( FALSE); | 201 | Remote_View->setMultiSelection( FALSE); |
202 | Remote_View->setSelectionMode(QListView::Extended); | 202 | Remote_View->setSelectionMode(QListView::Extended); |
203 | Remote_View->setFocusPolicy(QWidget::ClickFocus); | 203 | Remote_View->setFocusPolicy(QWidget::ClickFocus); |
204 | 204 | ||
205 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); | 205 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); |
206 | 206 | ||
207 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), | 207 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), |
208 | this,SLOT( remoteListClicked(QListViewItem *)) ); | 208 | this,SLOT( remoteListClicked(QListViewItem *)) ); |
209 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 209 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
210 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); | 210 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); |
211 | 211 | ||
212 | tabLayout_2->addWidget( Remote_View, 0, 0 ); | 212 | tabLayout_2->addWidget( Remote_View, 0, 0 ); |
213 | 213 | ||
214 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); | 214 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); |
215 | 215 | ||
216 | tab_3 = new QWidget( TabWidget, "tab_3" ); | 216 | tab_3 = new QWidget( TabWidget, "tab_3" ); |
217 | tabLayout_3 = new QGridLayout( tab_3 ); | 217 | tabLayout_3 = new QGridLayout( tab_3 ); |
218 | tabLayout_3->setSpacing( 2); | 218 | tabLayout_3->setSpacing( 2); |
219 | tabLayout_3->setMargin( 2); | 219 | tabLayout_3->setMargin( 2); |
220 | 220 | ||
221 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); | 221 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); |
222 | TextLabel1->setText( tr( "Username" ) ); | 222 | TextLabel1->setText( tr( "Username" ) ); |
223 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); | 223 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); |
224 | 224 | ||
225 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); | 225 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); |
226 | UsernameComboBox->setEditable(TRUE); | 226 | UsernameComboBox->setEditable(TRUE); |
227 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); | 227 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); |
228 | 228 | ||
229 | connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this, | 229 | connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this, |
230 | SLOT( UsernameComboBoxEdited(const QString & ) )); | 230 | SLOT( UsernameComboBoxEdited(const QString & ) )); |
231 | 231 | ||
232 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); | 232 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); |
233 | TextLabel2->setText( tr( "Password" ) ); | 233 | TextLabel2->setText( tr( "Password" ) ); |
234 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); | 234 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); |
235 | 235 | ||
236 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); | 236 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); |
237 | PasswordEdit->setEchoMode(QLineEdit::Password); | 237 | PasswordEdit->setEchoMode(QLineEdit::Password); |
238 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); | 238 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); |
239 | 239 | ||
240 | connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this, | 240 | connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this, |
241 | SLOT( PasswordEditEdited(const QString & ) )); | 241 | SLOT( PasswordEditEdited(const QString & ) )); |
242 | 242 | ||
243 | //PasswordEdit->setFixedWidth(85); | 243 | //PasswordEdit->setFixedWidth(85); |
244 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); | 244 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); |
245 | TextLabel3->setText( tr( "Remote server" ) ); | 245 | TextLabel3->setText( tr( "Remote server" ) ); |
246 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); | 246 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); |
247 | 247 | ||
248 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); | 248 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); |
249 | ServerComboBox->setEditable(TRUE); | 249 | ServerComboBox->setEditable(TRUE); |
250 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); | 250 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); |
251 | 251 | ||
252 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); | 252 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); |
253 | connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this, | 253 | connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this, |
254 | SLOT(serverComboEdited(const QString & ) )); | 254 | SLOT(serverComboEdited(const QString & ) )); |
255 | 255 | ||
256 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); | 256 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); |
257 | TextLabel5->setText( tr( "Remote path" ) ); | 257 | TextLabel5->setText( tr( "Remote path" ) ); |
258 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); | 258 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); |
259 | 259 | ||
260 | 260 | ||
261 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); | 261 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); |
262 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); | 262 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); |
263 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); | 263 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); |
264 | TextLabel4->setText( tr( "Port" ) ); | 264 | TextLabel4->setText( tr( "Port" ) ); |
265 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); | 265 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); |
266 | 266 | ||
267 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); | 267 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); |
268 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); | 268 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); |
269 | PortSpinBox->setMaxValue(32786); | 269 | PortSpinBox->setMaxValue(32786); |
270 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); | 270 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); |
271 | 271 | ||
272 | serverListView = new QListBox( tab_3, "ServerListView" ); | 272 | serverListView = new QListBox( tab_3, "ServerListView" ); |
273 | tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5); | 273 | tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5); |
274 | 274 | ||
275 | connect( serverListView, SIGNAL( highlighted( const QString &)), | 275 | connect( serverListView, SIGNAL( highlighted( const QString &)), |
276 | this,SLOT( serverListClicked( const QString &) ) ); | 276 | this,SLOT( serverListClicked( const QString &) ) ); |
277 | 277 | ||
278 | connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); | 278 | connectServerBtn = new QPushButton( "Connect", tab_3 , "ConnectButton" ); |
279 | tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1); | 279 | tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1); |
280 | connectServerBtn->setToggleButton(TRUE); | 280 | connectServerBtn->setToggleButton(TRUE); |
281 | connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); | 281 | connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); |
282 | 282 | ||
283 | newServerButton= new QPushButton( "Add", tab_3 , "NewServerButton" ); | 283 | newServerButton= new QPushButton( "Add", tab_3 , "NewServerButton" ); |
284 | tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2); | 284 | tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2); |
285 | connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() )); | 285 | connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() )); |
286 | 286 | ||
287 | QPushButton *deleteServerBtn; | 287 | QPushButton *deleteServerBtn; |
288 | deleteServerBtn = new QPushButton( "Delete", tab_3 , "OpenButton" ); | 288 | deleteServerBtn = new QPushButton( "Delete", tab_3 , "OpenButton" ); |
289 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3); | 289 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3); |
290 | 290 | ||
291 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); | 291 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); |
292 | 292 | ||
293 | 293 | ||
294 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 294 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
295 | tabLayout_3->addItem( spacer, 5, 0 ); | 295 | tabLayout_3->addItem( spacer, 5, 0 ); |
296 | 296 | ||
297 | TabWidget->insertTab( tab_3, tr( "Config" ) ); | 297 | TabWidget->insertTab( tab_3, tr( "Config" ) ); |
298 | 298 | ||
299 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), | 299 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), |
300 | this,SLOT(tabChanged(QWidget*))); | 300 | this,SLOT(tabChanged(QWidget*))); |
301 | 301 | ||
302 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 302 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
303 | currentDir.setPath( QDir::currentDirPath()); | 303 | currentDir.setPath( QDir::currentDirPath()); |
304 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 304 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
305 | 305 | ||
306 | currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); | 306 | currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); |
307 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 4); | 307 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 4); |
308 | currentPathCombo ->setFixedWidth(220); | 308 | currentPathCombo ->setFixedWidth(220); |
309 | currentPathCombo->setEditable(TRUE); | 309 | currentPathCombo->setEditable(TRUE); |
310 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | 310 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); |
311 | 311 | ||
312 | connect( currentPathCombo, SIGNAL( activated( const QString & ) ), | 312 | connect( currentPathCombo, SIGNAL( activated( const QString & ) ), |
313 | this, SLOT( currentPathComboActivated( const QString & ) ) ); | 313 | this, SLOT( currentPathComboActivated( const QString & ) ) ); |
314 | 314 | ||
315 | connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), | 315 | connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), |
316 | this,SLOT(currentPathComboChanged())); | 316 | this,SLOT(currentPathComboChanged())); |
317 | 317 | ||
318 | ProgressBar = new QProgressBar( this, "ProgressBar" ); | 318 | ProgressBar = new QProgressBar( this, "ProgressBar" ); |
319 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4); | 319 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4); |
320 | ProgressBar->setMaximumHeight(10); | 320 | ProgressBar->setMaximumHeight(10); |
321 | filterStr="*"; | 321 | filterStr="*"; |
322 | b=FALSE; | 322 | b=FALSE; |
323 | populateLocalView(); | 323 | populateLocalView(); |
324 | readConfig(); | 324 | readConfig(); |
325 | 325 | ||
326 | // ServerComboBox->setCurrentItem(currentServerConfig); | 326 | // ServerComboBox->setCurrentItem(currentServerConfig); |
327 | 327 | ||
328 | TabWidget->setCurrentPage(2); | 328 | TabWidget->setCurrentPage(2); |
329 | } | 329 | } |
330 | 330 | ||
331 | OpieFtp::~OpieFtp() | 331 | OpieFtp::~OpieFtp() |
332 | { | 332 | { |
333 | } | 333 | } |
334 | 334 | ||
335 | void OpieFtp::cleanUp() | 335 | void OpieFtp::cleanUp() |
336 | { | 336 | { |
337 | if(conn) | 337 | if(conn) |
338 | FtpQuit(conn); | 338 | FtpQuit(conn); |
339 | QString sfile=QDir::homeDirPath(); | 339 | QString sfile=QDir::homeDirPath(); |
340 | if(sfile.right(1) != "/") | 340 | if(sfile.right(1) != "/") |
341 | sfile+="/._temp"; | 341 | sfile+="/._temp"; |
342 | else | 342 | else |
343 | sfile+="._temp"; | 343 | sfile+="._temp"; |
344 | QFile file( sfile); | 344 | QFile file( sfile); |
345 | if(file.exists()) | 345 | if(file.exists()) |
346 | file.remove(); | 346 | file.remove(); |
347 | Config cfg("opieftp"); | 347 | Config cfg("opieftp"); |
348 | cfg.setGroup("Server"); | 348 | cfg.setGroup("Server"); |
349 | cfg.writeEntry("currentServer", currentServerConfig); | 349 | cfg.writeEntry("currentServer", currentServerConfig); |
350 | 350 | ||
351 | exit(0); | 351 | exit(0); |
352 | } | 352 | } |
353 | 353 | ||
354 | void OpieFtp::tabChanged(QWidget *) | 354 | void OpieFtp::tabChanged(QWidget *) |
355 | { | 355 | { |
356 | if (TabWidget->currentPageIndex() == 0) { | 356 | if (TabWidget->currentPageIndex() == 0) { |
357 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | 357 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); |
358 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); | 358 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); |
359 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 359 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
360 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 360 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
361 | if(cdUpButton->isHidden()) | 361 | if(cdUpButton->isHidden()) |
362 | cdUpButton->show(); | 362 | cdUpButton->show(); |
363 | if(homeButton->isHidden()) | 363 | if(homeButton->isHidden()) |
364 | homeButton->show(); | 364 | homeButton->show(); |
365 | 365 | ||
366 | } | 366 | } |
367 | if (TabWidget->currentPageIndex() == 1) { | 367 | if (TabWidget->currentPageIndex() == 1) { |
368 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 368 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
369 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); | 369 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); |
370 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 370 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
371 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 371 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
372 | if(cdUpButton->isHidden()) | 372 | if(cdUpButton->isHidden()) |
373 | cdUpButton->show(); | 373 | cdUpButton->show(); |
374 | homeButton->hide(); | 374 | homeButton->hide(); |
375 | 375 | ||
376 | } | 376 | } |
377 | if (TabWidget->currentPageIndex() == 2) { | 377 | if (TabWidget->currentPageIndex() == 2) { |
378 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); | 378 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); |
379 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 379 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
380 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 380 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
381 | cdUpButton->hide(); | 381 | cdUpButton->hide(); |
382 | homeButton->hide(); | 382 | homeButton->hide(); |
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
386 | void OpieFtp::newConnection() | 386 | void OpieFtp::newConnection() |
387 | { | 387 | { |
388 | UsernameComboBox->lineEdit()->setText(""); | 388 | UsernameComboBox->lineEdit()->setText(""); |
389 | PasswordEdit->setText( "" ); | 389 | PasswordEdit->setText( "" ); |
390 | ServerComboBox->lineEdit()->setText( ""); | 390 | ServerComboBox->lineEdit()->setText( ""); |
391 | remotePath->setText( currentRemoteDir = "/"); | 391 | remotePath->setText( currentRemoteDir = "/"); |
392 | PortSpinBox->setValue( 21); | 392 | PortSpinBox->setValue( 21); |
393 | TabWidget->setCurrentPage(2); | 393 | TabWidget->setCurrentPage(2); |
394 | } | 394 | } |
395 | 395 | ||
396 | void OpieFtp::serverComboEdited(const QString & ) | 396 | void OpieFtp::serverComboEdited(const QString & ) |
397 | { | 397 | { |
398 | // if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { | 398 | // if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { |
399 | // qDebug("ServerComboEdited"); | 399 | // qDebug("ServerComboEdited"); |
400 | // // currentServerConfig = -1; | 400 | // // currentServerConfig = -1; |
401 | // } | 401 | // } |
402 | } | 402 | } |
403 | 403 | ||
404 | void OpieFtp::UsernameComboBoxEdited(const QString &) { | 404 | void OpieFtp::UsernameComboBoxEdited(const QString &) { |
405 | // currentServerConfig = -1; | 405 | // currentServerConfig = -1; |
406 | } | 406 | } |
407 | 407 | ||
408 | void OpieFtp::PasswordEditEdited(const QString & ) { | 408 | void OpieFtp::PasswordEditEdited(const QString & ) { |
409 | // currentServerConfig = -1; | 409 | // currentServerConfig = -1; |
410 | } | 410 | } |
411 | 411 | ||
412 | void OpieFtp::connectorBtnToggled(bool On) | 412 | void OpieFtp::connectorBtnToggled(bool On) |
413 | { | 413 | { |
414 | if(On) { | 414 | if(On) { |
415 | connector(); | 415 | connector(); |
416 | } else { | 416 | } else { |
417 | disConnector(); | 417 | disConnector(); |
418 | } | 418 | } |
419 | 419 | ||
420 | } | 420 | } |
421 | 421 | ||
422 | void OpieFtp::connector() | 422 | void OpieFtp::connector() |
423 | { | 423 | { |
424 | // QCopEnvelope ( "QPE/System", "busy()" ); | 424 | // QCopEnvelope ( "QPE/System", "busy()" ); |
425 | // qApp->processEvents(); | 425 | // qApp->processEvents(); |
426 | currentRemoteDir=remotePath->text(); | 426 | currentRemoteDir=remotePath->text(); |
427 | 427 | ||
428 | if( ServerComboBox->currentText().isEmpty()) { | 428 | if( ServerComboBox->currentText().isEmpty()) { |
429 | 429 | ||
430 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); | 430 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); |
431 | TabWidget->setCurrentPage(2); | 431 | TabWidget->setCurrentPage(2); |
432 | ServerComboBox->setFocus(); | 432 | ServerComboBox->setFocus(); |
433 | connectServerBtn->setOn(FALSE); | 433 | connectServerBtn->setOn(FALSE); |
434 | connectServerBtn->setText( tr("Connect")); | 434 | connectServerBtn->setText( tr("Connect")); |
435 | return; | 435 | return; |
436 | } | 436 | } |
437 | 437 | ||
438 | FtpInit(); | 438 | FtpInit(); |
439 | 439 | ||
440 | TabWidget->setCurrentPage(1); | 440 | TabWidget->setCurrentPage(1); |
441 | QString ftp_host = ServerComboBox->currentText(); | 441 | QString ftp_host = ServerComboBox->currentText(); |
442 | QString ftp_user = UsernameComboBox->currentText(); | 442 | QString ftp_user = UsernameComboBox->currentText(); |
443 | QString ftp_pass = PasswordEdit->text(); | 443 | QString ftp_pass = PasswordEdit->text(); |
444 | QString port=PortSpinBox->cleanText(); | 444 | QString port=PortSpinBox->cleanText(); |
445 | port.stripWhiteSpace(); | 445 | port.stripWhiteSpace(); |
446 | 446 | ||
447 | Config cfg("opieftp"); | 447 | Config cfg("opieftp"); |
448 | cfg.setGroup("Server"); | 448 | cfg.setGroup("Server"); |
449 | // int current=cfg.readNumEntry("currentServer", 1); | 449 | // int current=cfg.readNumEntry("currentServer", 1); |
450 | 450 | ||
451 | // if(ftp_host!= cfg.readEntry(QString::number( current))) | 451 | // if(ftp_host!= cfg.readEntry(QString::number( current))) |
452 | // currentServerConfig=-1; | 452 | // currentServerConfig=-1; |
453 | // cfg.setGroup(QString::number(current)); | 453 | // cfg.setGroup(QString::number(current)); |
454 | // if( ftp_user != cfg.readEntry("Username")) | 454 | // if( ftp_user != cfg.readEntry("Username")) |
455 | // currentServerConfig=-1; | 455 | // currentServerConfig=-1; |
456 | // if(ftp_pass != cfg.readEntry(cfg.readEntry("Username"))) | 456 | // if(ftp_pass != cfg.readEntry(cfg.readEntry("Username"))) |
457 | // currentServerConfig=-1; | 457 | // currentServerConfig=-1; |
458 | 458 | ||
459 | 459 | ||
460 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) | 460 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) |
461 | ftp_host=ftp_host.right(ftp_host.length()-6); | 461 | ftp_host=ftp_host.right(ftp_host.length()-6); |
462 | ftp_host+=":"+port; | 462 | ftp_host+=":"+port; |
463 | 463 | ||
464 | if (!FtpConnect( ftp_host.latin1(), &conn)) { | 464 | if (!FtpConnect( ftp_host.latin1(), &conn)) { |
465 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); | 465 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); |
466 | connectServerBtn->setOn(FALSE); | 466 | connectServerBtn->setOn(FALSE); |
467 | connectServerBtn->setText( tr("Connect")); | 467 | connectServerBtn->setText( tr("Connect")); |
468 | return ; | 468 | return ; |
469 | } | 469 | } |
470 | 470 | ||
471 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { | 471 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { |
472 | QString msg; | 472 | QString msg; |
473 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); | 473 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); |
474 | msg.replace(QRegExp(":"),"\n"); | 474 | msg.replace(QRegExp(":"),"\n"); |
475 | QMessageBox::message(tr("Note"),msg); | 475 | QMessageBox::message(tr("Note"),msg); |
476 | if(conn) | 476 | if(conn) |
477 | FtpQuit(conn); | 477 | FtpQuit(conn); |
478 | connectServerBtn->setOn(FALSE); | 478 | connectServerBtn->setOn(FALSE); |
479 | connectServerBtn->setText( tr("Connect")); | 479 | connectServerBtn->setText( tr("Connect")); |
480 | return ; | 480 | return ; |
481 | } | 481 | } |
482 | 482 | ||
483 | remoteDirList("/") ; | 483 | remoteDirList("/") ; |
484 | setCaption(ftp_host); | 484 | setCaption(ftp_host); |
485 | if( currentServerConfig == -1) | 485 | if( currentServerConfig == -1) |
486 | writeConfig(); | 486 | writeConfig(); |
487 | connectServerBtn->setText( tr("Disconnect")); | 487 | connectServerBtn->setText( tr("Disconnect")); |
488 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 488 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
489 | } | 489 | } |
490 | 490 | ||
491 | void OpieFtp::disConnector() | 491 | void OpieFtp::disConnector() |
492 | { | 492 | { |
493 | if(conn) | 493 | if(conn) |
494 | FtpQuit(conn); | 494 | FtpQuit(conn); |
495 | setCaption("OpieFtp"); | 495 | setCaption("OpieFtp"); |
496 | currentRemoteDir="/"; | 496 | currentRemoteDir="/"; |
497 | Remote_View->clear(); | 497 | Remote_View->clear(); |
498 | connectServerBtn->setText( tr("Connect")); | 498 | connectServerBtn->setText( tr("Connect")); |
499 | connectServerBtn->setOn(FALSE); | 499 | connectServerBtn->setOn(FALSE); |
500 | setCaption("OpieFtp"); | 500 | setCaption("OpieFtp"); |
501 | } | 501 | } |
502 | 502 | ||
503 | void OpieFtp::localUpload() | 503 | void OpieFtp::localUpload() |
504 | { | 504 | { |
505 | int fsz; | 505 | int fsz; |
506 | // QCopEnvelope ( "QPE/System", "busy()" ); | 506 | // QCopEnvelope ( "QPE/System", "busy()" ); |
507 | // qApp->processEvents(); | 507 | // qApp->processEvents(); |
508 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | 508 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); |
509 | QListViewItemIterator it( Local_View ); | 509 | QListViewItemIterator it( Local_View ); |
510 | for ( ; it.current(); ++it ) { | 510 | for ( ; it.current(); ++it ) { |
511 | if ( it.current()->isSelected() ) { | 511 | if ( it.current()->isSelected() ) { |
512 | QString strItem = it.current()->text(0); | 512 | QString strItem = it.current()->text(0); |
513 | QString localFile = currentDir.canonicalPath()+"/"+strItem; | 513 | QString localFile = currentDir.canonicalPath()+"/"+strItem; |
514 | QString remoteFile= currentRemoteDir+strItem; | 514 | QString remoteFile= currentRemoteDir+strItem; |
515 | QFileInfo fi(localFile); | 515 | QFileInfo fi(localFile); |
516 | if( !fi.isDir()) { | 516 | if( !fi.isDir()) { |
517 | fsz=fi.size(); | 517 | fsz=fi.size(); |
518 | ProgressBar->setTotalSteps(fsz); | 518 | ProgressBar->setTotalSteps(fsz); |
519 | 519 | ||
520 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 520 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
521 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 521 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
522 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 522 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
523 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 523 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
524 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); | 524 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); |
525 | 525 | ||
526 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 526 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
527 | QString msg; | 527 | QString msg; |
528 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); | 528 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); |
529 | msg.replace(QRegExp(":"),"\n"); | 529 | msg.replace(QRegExp(":"),"\n"); |
530 | QMessageBox::message(tr("Note"),msg); | 530 | QMessageBox::message(tr("Note"),msg); |
531 | } | 531 | } |
532 | } else { | 532 | } else { |
533 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); | 533 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); |
534 | } | 534 | } |
535 | ProgressBar->reset(); | 535 | ProgressBar->reset(); |
536 | nullifyCallBack(); | 536 | nullifyCallBack(); |
537 | it.current()->setSelected(FALSE); | 537 | it.current()->setSelected(FALSE); |
538 | } //end currentSelected | 538 | } //end currentSelected |
539 | } | 539 | } |
540 | for ( ; it.current(); ++it ) { | 540 | for ( ; it.current(); ++it ) { |
541 | Local_View->clearSelection(); | 541 | Local_View->clearSelection(); |
542 | } | 542 | } |
543 | Local_View->clearFocus(); | 543 | Local_View->clearFocus(); |
544 | TabWidget->setCurrentPage(1); | 544 | TabWidget->setCurrentPage(1); |
545 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 545 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
546 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 546 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
547 | } | 547 | } |
548 | 548 | ||
549 | void OpieFtp::nullifyCallBack() | 549 | void OpieFtp::nullifyCallBack() |
550 | { | 550 | { |
551 | FtpOptions(FTPLIB_CALLBACK, 0, conn); | 551 | FtpOptions(FTPLIB_CALLBACK, 0, conn); |
552 | FtpOptions(FTPLIB_IDLETIME, 0, conn); | 552 | FtpOptions(FTPLIB_IDLETIME, 0, conn); |
553 | FtpOptions(FTPLIB_CALLBACKARG, 0, conn); | 553 | FtpOptions(FTPLIB_CALLBACKARG, 0, conn); |
554 | FtpOptions(FTPLIB_CALLBACKBYTES, 0, conn); | 554 | FtpOptions(FTPLIB_CALLBACKBYTES, 0, conn); |
555 | } | 555 | } |
556 | 556 | ||
557 | void OpieFtp::remoteDownload() | 557 | void OpieFtp::remoteDownload() |
558 | { | 558 | { |
559 | // qApp->processEvents(); | 559 | // qApp->processEvents(); |
560 | int fsz; | 560 | int fsz; |
561 | // QCopEnvelope ( "QPE/System", "busy()" ); | 561 | // QCopEnvelope ( "QPE/System", "busy()" ); |
562 | 562 | ||
563 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); | 563 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); |
564 | QListViewItemIterator it( Remote_View ); | 564 | QListViewItemIterator it( Remote_View ); |
565 | for ( ; it.current(); ++it ) { | 565 | for ( ; it.current(); ++it ) { |
566 | if ( it.current()->isSelected() ) { | 566 | if ( it.current()->isSelected() ) { |
567 | QString strItem = it.current()->text(0); | 567 | QString strItem = it.current()->text(0); |
568 | // strItem=strItem.right(strItem.length()-1); | 568 | // strItem=strItem.right(strItem.length()-1); |
569 | QString localFile = currentDir.canonicalPath(); | 569 | QString localFile = currentDir.canonicalPath(); |
570 | if(localFile.right(1).find("/",0,TRUE) == -1) | 570 | if(localFile.right(1).find("/",0,TRUE) == -1) |
571 | localFile += "/"; | 571 | localFile += "/"; |
572 | localFile += strItem; | 572 | localFile += strItem; |
573 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; | 573 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; |
574 | QString remoteFile= currentRemoteDir+strItem; | 574 | QString remoteFile= currentRemoteDir+strItem; |
575 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) | 575 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) |
576 | fsz = 0; | 576 | fsz = 0; |
577 | QString temp; | 577 | QString temp; |
578 | temp.sprintf( remoteFile+" "+" %dkb", fsz); | 578 | temp.sprintf( remoteFile+" "+" %dkb", fsz); |
579 | 579 | ||
580 | ProgressBar->setTotalSteps(fsz); | 580 | ProgressBar->setTotalSteps(fsz); |
581 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 581 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
582 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 582 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
583 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 583 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
584 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 584 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
585 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); | 585 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); |
586 | 586 | ||
587 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 587 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
588 | QString msg; | 588 | QString msg; |
589 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); | 589 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); |
590 | msg.replace(QRegExp(":"),"\n"); | 590 | msg.replace(QRegExp(":"),"\n"); |
591 | QMessageBox::message(tr("Note"),msg); | 591 | QMessageBox::message(tr("Note"),msg); |
592 | } | 592 | } |
593 | ProgressBar->reset(); | 593 | ProgressBar->reset(); |
594 | nullifyCallBack(); | 594 | nullifyCallBack(); |
595 | it.current()->setSelected(FALSE); | 595 | it.current()->setSelected(FALSE); |
596 | } | 596 | } |
597 | } | 597 | } |
598 | for ( ; it.current(); ++it ) { | 598 | for ( ; it.current(); ++it ) { |
599 | Remote_View->clearSelection(); | 599 | Remote_View->clearSelection(); |
600 | } | 600 | } |
601 | Remote_View->setFocus(); | 601 | Remote_View->setFocus(); |
602 | TabWidget->setCurrentPage(0); | 602 | TabWidget->setCurrentPage(0); |
603 | populateLocalView(); | 603 | populateLocalView(); |
604 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 604 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
605 | } | 605 | } |
606 | 606 | ||
607 | bool OpieFtp::remoteDirList(const QString &dir) | 607 | bool OpieFtp::remoteDirList(const QString &dir) |
608 | { | 608 | { |
609 | QString tmp = QDir::homeDirPath(); | 609 | QString tmp = QDir::homeDirPath(); |
610 | if(tmp.right(1) != "/") | 610 | if(tmp.right(1) != "/") |
611 | tmp+="/._temp"; | 611 | tmp+="/._temp"; |
612 | else | 612 | else |
613 | tmp+="._temp"; | 613 | tmp+="._temp"; |
614 | // qDebug("Listing remote dir "+tmp); | 614 | // qDebug("Listing remote dir "+tmp); |
615 | // QCopEnvelope ( "QPE/System", "busy()" ); | 615 | // QCopEnvelope ( "QPE/System", "busy()" ); |
616 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { | 616 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { |
617 | QString msg; | 617 | QString msg; |
618 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); | 618 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); |
619 | msg.replace(QRegExp(":"),"\n"); | 619 | msg.replace(QRegExp(":"),"\n"); |
620 | QMessageBox::message(tr("Note"),msg); | 620 | QMessageBox::message(tr("Note"),msg); |
621 | return false; | 621 | return false; |
622 | } | 622 | } |
623 | populateRemoteView() ; | 623 | populateRemoteView() ; |
624 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 624 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
625 | return true; | 625 | return true; |
626 | } | 626 | } |
627 | 627 | ||
628 | bool OpieFtp::remoteChDir(const QString &dir) | 628 | bool OpieFtp::remoteChDir(const QString &dir) |
629 | { | 629 | { |
630 | // QCopEnvelope ( "QPE/System", "busy()" ); | 630 | // QCopEnvelope ( "QPE/System", "busy()" ); |
631 | if (!FtpChdir( dir.latin1(), conn )) { | 631 | if (!FtpChdir( dir.latin1(), conn )) { |
632 | QString msg; | 632 | QString msg; |
633 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); | 633 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); |
634 | msg.replace(QRegExp(":"),"\n"); | 634 | msg.replace(QRegExp(":"),"\n"); |
635 | QMessageBox::message(tr("Note"),msg); | 635 | QMessageBox::message(tr("Note"),msg); |
636 | // qDebug(msg); | 636 | // qDebug(msg); |
637 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 637 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
638 | return FALSE; | 638 | return FALSE; |
639 | } | 639 | } |
640 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 640 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
641 | return TRUE; | 641 | return TRUE; |
642 | } | 642 | } |
643 | 643 | ||
644 | void OpieFtp::populateLocalView() | 644 | void OpieFtp::populateLocalView() |
645 | { | 645 | { |
646 | Local_View->clear(); | 646 | Local_View->clear(); |
647 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 647 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
648 | currentDir.setMatchAllDirs(TRUE); | 648 | currentDir.setMatchAllDirs(TRUE); |
649 | currentDir.setNameFilter(filterStr); | 649 | currentDir.setNameFilter(filterStr); |
650 | QString fileL, fileS, fileDate; | 650 | QString fileL, fileS, fileDate; |
651 | bool isDir=FALSE; | 651 | bool isDir=FALSE; |
652 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 652 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
653 | QFileInfoListIterator it(*list); | 653 | QFileInfoListIterator it(*list); |
654 | QFileInfo *fi; | 654 | QFileInfo *fi; |
655 | while ( (fi=it.current()) ) { | 655 | while ( (fi=it.current()) ) { |
656 | if (fi->isSymLink() ){ | 656 | if (fi->isSymLink() ){ |
657 | QString symLink=fi->readLink(); | 657 | QString symLink=fi->readLink(); |
658 | // qDebug("Symlink detected "+symLink); | 658 | // qDebug("Symlink detected "+symLink); |
659 | QFileInfo sym( symLink); | 659 | QFileInfo sym( symLink); |
660 | fileS.sprintf( "%10i", sym.size() ); | 660 | fileS.sprintf( "%10i", sym.size() ); |
661 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); | 661 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); |
662 | fileDate = sym.lastModified().toString(); | 662 | fileDate = sym.lastModified().toString(); |
663 | } else { | 663 | } else { |
664 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 664 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
665 | fileS.sprintf( "%10i", fi->size() ); | 665 | fileS.sprintf( "%10i", fi->size() ); |
666 | fileL.sprintf( "%s",fi->fileName().data() ); | 666 | fileL.sprintf( "%s",fi->fileName().data() ); |
667 | fileDate= fi->lastModified().toString(); | 667 | fileDate= fi->lastModified().toString(); |
668 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 668 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
669 | fileL+="/"; | 669 | fileL+="/"; |
670 | isDir=TRUE; | 670 | isDir=TRUE; |
671 | // qDebug( fileL); | 671 | // qDebug( fileL); |
672 | } | 672 | } |
673 | } | 673 | } |
674 | if(fileL !="./" && fi->exists()) { | 674 | if(fileL !="./" && fi->exists()) { |
675 | item = new QListViewItem( Local_View,fileL, fileDate, fileS ); | 675 | item = new QListViewItem( Local_View,fileL, fileDate, fileS ); |
676 | QPixmap pm; | 676 | QPixmap pm; |
677 | 677 | ||
678 | if(isDir || fileL.find("/",0,TRUE) != -1) { | 678 | if(isDir || fileL.find("/",0,TRUE) != -1) { |
679 | if( !QDir( fi->filePath() ).isReadable()) | 679 | if( !QDir( fi->filePath() ).isReadable()) |
680 | pm = Resource::loadPixmap( "lockedfolder" ); | 680 | pm = Resource::loadPixmap( "lockedfolder" ); |
681 | else | 681 | else |
682 | pm= Resource::loadPixmap( "folder" ); | 682 | pm= Resource::loadPixmap( "folder" ); |
683 | item->setPixmap( 0,pm ); | 683 | item->setPixmap( 0,pm ); |
684 | } else { | 684 | } else { |
685 | if( !fi->isReadable() ) | 685 | if( !fi->isReadable() ) |
686 | pm = Resource::loadPixmap( "locked" ); | 686 | pm = Resource::loadPixmap( "locked" ); |
687 | else { | 687 | else { |
688 | MimeType mt(fi->filePath()); | 688 | MimeType mt(fi->filePath()); |
689 | pm=mt.pixmap(); //sets the correct pixmap for mimetype | 689 | pm=mt.pixmap(); //sets the correct pixmap for mimetype |
690 | if(pm.isNull()) | 690 | if(pm.isNull()) |
691 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | 691 | pm = Resource::loadPixmap( "UnknownDocument-14" ); |
692 | item->setPixmap( 0,pm); | 692 | item->setPixmap( 0,pm); |
693 | } | 693 | } |
694 | } | 694 | } |
695 | if( fileL.find("->",0,TRUE) != -1) { | 695 | if( fileL.find("->",0,TRUE) != -1) { |
696 | // overlay link image | 696 | // overlay link image |
697 | pm= Resource::loadPixmap( "folder" ); | 697 | pm= Resource::loadPixmap( "folder" ); |
698 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); | 698 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); |
699 | QPainter painter( &pm ); | 699 | QPainter painter( &pm ); |
700 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 700 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
701 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 701 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
702 | item->setPixmap( 0, pm); | 702 | item->setPixmap( 0, pm); |
703 | } | 703 | } |
704 | } | 704 | } |
705 | isDir=FALSE; | 705 | isDir=FALSE; |
706 | ++it; | 706 | ++it; |
707 | } | 707 | } |
708 | Local_View->setSorting( 3,FALSE); | 708 | Local_View->setSorting( 3,FALSE); |
709 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() ); | 709 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() ); |
710 | fillCombo( (const QString &)currentDir); | 710 | fillCombo( (const QString &)currentDir); |
711 | } | 711 | } |
712 | 712 | ||
713 | bool OpieFtp::populateRemoteView( ) | 713 | bool OpieFtp::populateRemoteView( ) |
714 | { | 714 | { |
715 | // qDebug("populate remoteview"); | 715 | // qDebug("populate remoteview"); |
716 | QString sfile=QDir::homeDirPath(); | 716 | QString sfile=QDir::homeDirPath(); |
717 | if(sfile.right(1) != "/") | 717 | if(sfile.right(1) != "/") |
718 | sfile+="/._temp"; | 718 | sfile+="/._temp"; |
719 | else | 719 | else |
720 | sfile+="._temp"; | 720 | sfile+="._temp"; |
721 | QFile file( sfile); | 721 | QFile file( sfile); |
722 | Remote_View->clear(); | 722 | Remote_View->clear(); |
723 | QString s, File_Name; | 723 | QString s, File_Name; |
724 | QListViewItem *itemDir=NULL, *itemFile=NULL; | 724 | QListViewItem *itemDir=NULL, *itemFile=NULL; |
725 | QRegExp monthRe(" [JFMASOND][eapuecoe][brynlgptvc] [ 0-9][0-9] [ 0-9][0-9][:0-9][0-9][0-9] "); | 725 | QRegExp monthRe(" [JFMASOND][eapuecoe][brynlgptvc] [ 0-9][0-9] [ 0-9][0-9][:0-9][0-9][0-9] "); |
726 | QString fileL, fileS, fileDate; | 726 | QString fileL, fileS, fileDate; |
727 | if ( file.open(IO_ReadOnly)) { | 727 | if ( file.open(IO_ReadOnly)) { |
728 | QTextStream t( &file ); // use a text stream | 728 | QTextStream t( &file ); // use a text stream |
729 | while ( !t.eof()) { | 729 | while ( !t.eof()) { |
730 | s = t.readLine(); | 730 | s = t.readLine(); |
731 | 731 | ||
732 | if(s.find("total",0,TRUE) == 0) | 732 | if(s.find("total",0,TRUE) == 0) |
733 | continue; | 733 | continue; |
734 | 734 | ||
735 | int len, month = monthRe.match(s, 0, &len); | 735 | int len, month = monthRe.match(s, 0, &len); |
736 | fileDate = s.mid(month + 1, len - 2); // minus spaces | 736 | fileDate = s.mid(month + 1, len - 2); // minus spaces |
737 | fileL = s.right(s.length() - month - len); | 737 | fileL = s.right(s.length() - month - len); |
738 | if(s.left(1) == "d") | 738 | if(s.left(1) == "d") |
739 | fileL = fileL+"/"; | 739 | fileL = fileL+"/"; |
740 | fileS = s.mid(month - 8, 8); // FIXME | 740 | fileS = s.mid(month - 8, 8); // FIXME |
741 | fileS = fileS.stripWhiteSpace(); | 741 | fileS = fileS.stripWhiteSpace(); |
742 | 742 | ||
743 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { | 743 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { |
744 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"d"); | 744 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"d"); |
745 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); | 745 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); |
746 | // if(itemDir) | 746 | // if(itemDir) |
747 | item->moveItem(itemDir); | 747 | item->moveItem(itemDir); |
748 | itemDir=item; | 748 | itemDir=item; |
749 | } else { | 749 | } else { |
750 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"f"); | 750 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"f"); |
751 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); | 751 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); |
752 | // if(itemFile) | 752 | // if(itemFile) |
753 | item->moveItem(itemDir); | 753 | item->moveItem(itemDir); |
754 | item->moveItem(itemFile); | 754 | item->moveItem(itemFile); |
755 | itemFile=item; | 755 | itemFile=item; |
756 | } | 756 | } |
757 | } | 757 | } |
758 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); | 758 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); |
759 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); | 759 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); |
760 | file.close(); | 760 | file.close(); |
761 | if( file.exists()) | 761 | if( file.exists()) |
762 | file. remove(); | 762 | file. remove(); |
763 | } else | 763 | } else |
764 | qDebug("temp file not opened successfullly "+sfile); | 764 | qDebug("temp file not opened successfullly "+sfile); |
765 | Remote_View->setSorting( 4,TRUE); | 765 | Remote_View->setSorting( 4,TRUE); |
766 | return true; | 766 | return true; |
767 | } | 767 | } |
768 | 768 | ||
769 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) | 769 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) |
770 | { | 770 | { |
771 | if( selectedItem) { | 771 | if( selectedItem) { |
772 | // QCopEnvelope ( "QPE/System", "busy()" ); | 772 | // QCopEnvelope ( "QPE/System", "busy()" ); |
773 | QString oldRemoteCurrentDir = currentRemoteDir; | 773 | QString oldRemoteCurrentDir = currentRemoteDir; |
774 | QString strItem=selectedItem->text(0); | 774 | QString strItem=selectedItem->text(0); |
775 | strItem=strItem.simplifyWhiteSpace(); | 775 | strItem=strItem.simplifyWhiteSpace(); |
776 | if(strItem == "../") { // the user wants to go ^ | 776 | if(strItem == "../") { // the user wants to go ^ |
777 | if( FtpCDUp( conn) == 0) { | 777 | if( FtpCDUp( conn) == 0) { |
778 | QString msg; | 778 | QString msg; |
779 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); | 779 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); |
780 | msg.replace(QRegExp(":"),"\n"); | 780 | msg.replace(QRegExp(":"),"\n"); |
781 | QMessageBox::message(tr("Note"),msg); | 781 | QMessageBox::message(tr("Note"),msg); |
782 | // qDebug(msg); | 782 | // qDebug(msg); |
783 | } | 783 | } |
784 | char path[256]; | 784 | char path[256]; |
785 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string | 785 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string |
786 | QString msg; | 786 | QString msg; |
787 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); | 787 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); |
788 | msg.replace(QRegExp(":"),"\n"); | 788 | msg.replace(QRegExp(":"),"\n"); |
789 | QMessageBox::message(tr("Note"),msg); | 789 | QMessageBox::message(tr("Note"),msg); |
790 | // qDebug(msg); | 790 | // qDebug(msg); |
791 | } | 791 | } |
792 | currentRemoteDir=path; | 792 | currentRemoteDir=path; |
793 | } else { | 793 | } else { |
794 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers | 794 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers |
795 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); | 795 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); |
796 | strItem = strItem.stripWhiteSpace(); | 796 | strItem = strItem.stripWhiteSpace(); |
797 | currentRemoteDir = strItem; | 797 | currentRemoteDir = strItem; |
798 | if( !remoteChDir( (const QString &)strItem)) { | 798 | if( !remoteChDir( (const QString &)strItem)) { |
799 | currentRemoteDir = oldRemoteCurrentDir; | 799 | currentRemoteDir = oldRemoteCurrentDir; |
800 | strItem=""; | 800 | strItem=""; |
801 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 801 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
802 | } | 802 | } |
803 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory | 803 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory |
804 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { | 804 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { |
805 | currentRemoteDir = oldRemoteCurrentDir; | 805 | currentRemoteDir = oldRemoteCurrentDir; |
806 | strItem=""; | 806 | strItem=""; |
807 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 807 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
808 | 808 | ||
809 | } else { | 809 | } else { |
810 | currentRemoteDir = currentRemoteDir+strItem; | 810 | currentRemoteDir = currentRemoteDir+strItem; |
811 | } | 811 | } |
812 | } else { | 812 | } else { |
813 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 813 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
814 | return; | 814 | return; |
815 | } | 815 | } |
816 | } | 816 | } |
817 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 817 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
818 | if(currentRemoteDir.right(1) !="/") | 818 | if(currentRemoteDir.right(1) !="/") |
819 | currentRemoteDir +="/"; | 819 | currentRemoteDir +="/"; |
820 | currentPathCombo->lineEdit()->setText( currentRemoteDir); | 820 | currentPathCombo->lineEdit()->setText( currentRemoteDir); |
821 | fillRemoteCombo( (const QString &)currentRemoteDir); | 821 | fillRemoteCombo( (const QString &)currentRemoteDir); |
822 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 822 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
823 | Remote_View->ensureItemVisible(Remote_View->firstChild()); | 823 | Remote_View->ensureItemVisible(Remote_View->firstChild()); |
824 | 824 | ||
825 | } | 825 | } |
826 | } | 826 | } |
827 | 827 | ||
828 | void OpieFtp::localListClicked(QListViewItem *selectedItem) | 828 | void OpieFtp::localListClicked(QListViewItem *selectedItem) |
829 | { | 829 | { |
830 | if(selectedItem!= NULL) { | 830 | if(selectedItem!= NULL) { |
831 | 831 | ||
832 | QString strItem=selectedItem->text(0); | 832 | QString strItem=selectedItem->text(0); |
833 | QString strSize=selectedItem->text(1); | 833 | QString strSize=selectedItem->text(1); |
834 | strSize=strSize.stripWhiteSpace(); | 834 | strSize=strSize.stripWhiteSpace(); |
835 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 835 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
836 | // is symlink | 836 | // is symlink |
837 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | 837 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); |
838 | if(QDir(strItem2).exists() ) { | 838 | if(QDir(strItem2).exists() ) { |
839 | currentDir.cd(strItem2, TRUE); | 839 | currentDir.cd(strItem2, TRUE); |
840 | populateLocalView(); | 840 | populateLocalView(); |
841 | } | 841 | } |
842 | } else { // not a symlink | 842 | } else { // not a symlink |
843 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 843 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
844 | 844 | ||
845 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 845 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
846 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 846 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
847 | currentDir.cd(strItem,FALSE); | 847 | currentDir.cd(strItem,FALSE); |
848 | populateLocalView(); | 848 | populateLocalView(); |
849 | } else { | 849 | } else { |
850 | currentDir.cdUp(); | 850 | currentDir.cdUp(); |
851 | populateLocalView(); | 851 | populateLocalView(); |
852 | } | 852 | } |
853 | if(QDir(strItem).exists()){ | 853 | if(QDir(strItem).exists()){ |
854 | currentDir.cd(strItem, TRUE); | 854 | currentDir.cd(strItem, TRUE); |
855 | populateLocalView(); | 855 | populateLocalView(); |
856 | } | 856 | } |
857 | } else { | 857 | } else { |
858 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 858 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
859 | if( QFile::exists(strItem ) ) { | 859 | if( QFile::exists(strItem ) ) { |
860 | // qDebug("upload "+strItem); | 860 | // qDebug("upload "+strItem); |
861 | return; | 861 | return; |
862 | } | 862 | } |
863 | } //end not symlink | 863 | } //end not symlink |
864 | chdir(strItem.latin1()); | 864 | chdir(strItem.latin1()); |
865 | } | 865 | } |
866 | Local_View->ensureItemVisible(Local_View->firstChild()); | 866 | Local_View->ensureItemVisible(Local_View->firstChild()); |
867 | } | 867 | } |
868 | } | 868 | } |
869 | 869 | ||
870 | void OpieFtp::doLocalCd() | 870 | void OpieFtp::doLocalCd() |
871 | { | 871 | { |
872 | localListClicked( Local_View->currentItem()); | 872 | localListClicked( Local_View->currentItem()); |
873 | } | 873 | } |
874 | 874 | ||
875 | void OpieFtp:: doRemoteCd() | 875 | void OpieFtp:: doRemoteCd() |
876 | { | 876 | { |
877 | remoteListClicked( Remote_View->currentItem()); | 877 | remoteListClicked( Remote_View->currentItem()); |
878 | 878 | ||
879 | } | 879 | } |
880 | 880 | ||
881 | void OpieFtp::showHidden() | 881 | void OpieFtp::showHidden() |
882 | { | 882 | { |
883 | if (!b) { | 883 | if (!b) { |
884 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 884 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
885 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); | 885 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); |
886 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 886 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
887 | b=TRUE; | 887 | b=TRUE; |
888 | 888 | ||
889 | } else { | 889 | } else { |
890 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 890 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
891 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); | 891 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); |
892 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 892 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
893 | b=FALSE; | 893 | b=FALSE; |
894 | } | 894 | } |
895 | populateLocalView(); | 895 | populateLocalView(); |
896 | } | 896 | } |
897 | 897 | ||
898 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &, int) | 898 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &, int) |
899 | { | 899 | { |
900 | // if(item) | 900 | // if(item) |
901 | if (mouse == 2) { | 901 | if (mouse == 2) { |
902 | showLocalMenu(item); | 902 | showLocalMenu(item); |
903 | } | 903 | } |
904 | } | 904 | } |
905 | 905 | ||
906 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &, int ) | 906 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &, int ) |
907 | { | 907 | { |
908 | if(mouse == 2) { | 908 | if(mouse == 2) { |
909 | showRemoteMenu(item); | 909 | showRemoteMenu(item); |
910 | } | 910 | } |
911 | } | 911 | } |
912 | 912 | ||
913 | void OpieFtp::showRemoteMenu(QListViewItem * item) | 913 | void OpieFtp::showRemoteMenu(QListViewItem * item) |
914 | { | 914 | { |
915 | QPopupMenu * m;// = new QPopupMenu( Local_View ); | 915 | QPopupMenu * m;// = new QPopupMenu( Local_View ); |
916 | m = new QPopupMenu(this); | 916 | m = new QPopupMenu(this); |
917 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) != -1) | 917 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) != -1) |
918 | m->insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); | 918 | m->insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); |
919 | else | 919 | else |
920 | m->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 920 | m->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
921 | m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 921 | m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
922 | m->insertItem( tr("Rescan"), this, SLOT( populateLocalView() )); | 922 | m->insertItem( tr("Rescan"), this, SLOT( populateLocalView() )); |
923 | m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 923 | m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
924 | m->insertSeparator(); | 924 | m->insertSeparator(); |
925 | m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 925 | m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
926 | m->exec( QCursor::pos() ); | 926 | m->exec( QCursor::pos() ); |
927 | delete m; | 927 | delete m; |
928 | } | 928 | } |
929 | 929 | ||
930 | void OpieFtp::showLocalMenu(QListViewItem * item) | 930 | void OpieFtp::showLocalMenu(QListViewItem * item) |
931 | { | 931 | { |
932 | 932 | ||
933 | QPopupMenu *m; | 933 | QPopupMenu *m; |
934 | m = new QPopupMenu( this); | 934 | m = new QPopupMenu( this); |
935 | m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 935 | m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
936 | m->insertSeparator(); | 936 | m->insertSeparator(); |
937 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) | 937 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) |
938 | m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); | 938 | m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); |
939 | else | 939 | else |
940 | m->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 940 | m->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
941 | m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 941 | m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
942 | m->insertItem( tr("Rescan"), this, SLOT( populateRemoteView() )); | 942 | m->insertItem( tr("Rescan"), this, SLOT( populateRemoteView() )); |
943 | m->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 943 | m->insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
944 | m->insertSeparator(); | 944 | m->insertSeparator(); |
945 | m->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 945 | m->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
946 | m->setCheckable(TRUE); | 946 | m->setCheckable(TRUE); |
947 | if (b) | 947 | if (b) |
948 | m->setItemChecked(m->idAt(0),TRUE); | 948 | m->setItemChecked(m->idAt(0),TRUE); |
949 | else | 949 | else |
950 | m->setItemChecked(m->idAt(0),FALSE); | 950 | m->setItemChecked(m->idAt(0),FALSE); |
951 | 951 | ||
952 | m->exec( QCursor::pos() ); | 952 | m->exec( QCursor::pos() ); |
953 | delete m; | 953 | delete m; |
954 | } | 954 | } |
955 | 955 | ||
956 | void OpieFtp::localMakDir() | 956 | void OpieFtp::localMakDir() |
957 | { | 957 | { |
958 | InputDialog *fileDlg; | 958 | InputDialog *fileDlg; |
959 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 959 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
960 | fileDlg->exec(); | 960 | fileDlg->exec(); |
961 | if( fileDlg->result() == 1 ) { | 961 | if( fileDlg->result() == 1 ) { |
962 | QString filename = fileDlg->LineEdit1->text(); | 962 | QString filename = fileDlg->LineEdit1->text(); |
963 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | 963 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); |
964 | } | 964 | } |
965 | populateLocalView(); | 965 | populateLocalView(); |
966 | } | 966 | } |
967 | 967 | ||
968 | void OpieFtp::localDelete() | 968 | void OpieFtp::localDelete() |
969 | { | 969 | { |
970 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | 970 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); |
971 | QListViewItemIterator it( Local_View ); | 971 | QListViewItemIterator it( Local_View ); |
972 | for ( ; it.current(); ++it ) { | 972 | for ( ; it.current(); ++it ) { |
973 | if ( it.current()->isSelected() ) { | 973 | if ( it.current()->isSelected() ) { |
974 | QString f = it.current()->text(0); | 974 | QString f = it.current()->text(0); |
975 | it.current()->setSelected(FALSE); | 975 | it.current()->setSelected(FALSE); |
976 | 976 | ||
977 | // QString f = Local_View->currentItem()->text(0); | 977 | // QString f = Local_View->currentItem()->text(0); |
978 | if(QDir(f).exists() ) { | 978 | if(QDir(f).exists() ) { |
979 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ | 979 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ |
980 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { | 980 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { |
981 | case 0: { | 981 | case 0: { |
982 | f=currentDir.canonicalPath()+"/"+f; | 982 | f=currentDir.canonicalPath()+"/"+f; |
983 | QString cmd="rmdir "+f; | 983 | QString cmd="rmdir "+f; |
984 | system( cmd.latin1()); | 984 | system( cmd.latin1()); |
985 | } | 985 | } |
986 | break; | 986 | break; |
987 | case 1: | 987 | case 1: |
988 | // exit | 988 | // exit |
989 | break; | 989 | break; |
990 | }; | 990 | }; |
991 | 991 | ||
992 | } else { | 992 | } else { |
993 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f | 993 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f |
994 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | 994 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { |
995 | case 0: { | 995 | case 0: { |
996 | f=currentDir.canonicalPath()+"/"+f; | 996 | f=currentDir.canonicalPath()+"/"+f; |
997 | QString cmd="rm "+f; | 997 | QString cmd="rm "+f; |
998 | system( cmd.latin1()); | 998 | system( cmd.latin1()); |
999 | } | 999 | } |
1000 | break; | 1000 | break; |
1001 | case 1: | 1001 | case 1: |
1002 | // exit | 1002 | // exit |
1003 | break; | 1003 | break; |
1004 | }; | 1004 | }; |
1005 | } | 1005 | } |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | populateLocalView(); | 1008 | populateLocalView(); |
1009 | 1009 | ||
1010 | } | 1010 | } |
1011 | 1011 | ||
1012 | void OpieFtp::remoteMakDir() | 1012 | void OpieFtp::remoteMakDir() |
1013 | { | 1013 | { |
1014 | InputDialog *fileDlg; | 1014 | InputDialog *fileDlg; |
1015 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 1015 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
1016 | fileDlg->exec(); | 1016 | fileDlg->exec(); |
1017 | if( fileDlg->result() == 1 ) { | 1017 | if( fileDlg->result() == 1 ) { |
1018 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; | 1018 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; |
1019 | QString tmp=currentRemoteDir+filename; | 1019 | QString tmp=currentRemoteDir+filename; |
1020 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1020 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1021 | if(FtpMkdir( tmp.latin1(), conn) == 0) { | 1021 | if(FtpMkdir( tmp.latin1(), conn) == 0) { |
1022 | QString msg; | 1022 | QString msg; |
1023 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); | 1023 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); |
1024 | msg.replace(QRegExp(":"),"\n"); | 1024 | msg.replace(QRegExp(":"),"\n"); |
1025 | QMessageBox::message(tr("Note"),msg); | 1025 | QMessageBox::message(tr("Note"),msg); |
1026 | } | 1026 | } |
1027 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1027 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1028 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1028 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1029 | } | 1029 | } |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | void OpieFtp::remoteDelete() | 1032 | void OpieFtp::remoteDelete() |
1033 | { | 1033 | { |
1034 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); | 1034 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); |
1035 | QListViewItemIterator it( Remote_View ); | 1035 | QListViewItemIterator it( Remote_View ); |
1036 | for ( ; it.current(); ++it ) { | 1036 | for ( ; it.current(); ++it ) { |
1037 | if ( it.current()->isSelected() ) { | 1037 | if ( it.current()->isSelected() ) { |
1038 | QString f = it.current()->text(0); | 1038 | QString f = it.current()->text(0); |
1039 | // QString f = Remote_View->currentItem()->text(0); | 1039 | // QString f = Remote_View->currentItem()->text(0); |
1040 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1040 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1041 | if( f.right(1) =="/") { | 1041 | if( f.right(1) =="/") { |
1042 | QString path= currentRemoteDir+f; | 1042 | QString path= currentRemoteDir+f; |
1043 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 1043 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
1044 | ,tr("Yes"),tr("No"),0,0,1) ) { | 1044 | ,tr("Yes"),tr("No"),0,0,1) ) { |
1045 | case 0: { | 1045 | case 0: { |
1046 | f=currentDir.canonicalPath()+"/"+f; | 1046 | f=currentDir.canonicalPath()+"/"+f; |
1047 | if(FtpRmdir( path.latin1(), conn) ==0) { | 1047 | if(FtpRmdir( path.latin1(), conn) ==0) { |
1048 | QString msg; | 1048 | QString msg; |
1049 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); | 1049 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); |
1050 | msg.replace(QRegExp(":"),"\n"); | 1050 | msg.replace(QRegExp(":"),"\n"); |
1051 | QMessageBox::message(tr("Note"),msg); | 1051 | QMessageBox::message(tr("Note"),msg); |
1052 | } | 1052 | } |
1053 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1053 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1054 | } | 1054 | } |
1055 | break; | 1055 | break; |
1056 | }; | 1056 | }; |
1057 | } else { | 1057 | } else { |
1058 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 1058 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
1059 | ,tr("Yes"),tr("No"),0,0,1) ) { | 1059 | ,tr("Yes"),tr("No"),0,0,1) ) { |
1060 | case 0: { | 1060 | case 0: { |
1061 | QString path= currentRemoteDir+f; | 1061 | QString path= currentRemoteDir+f; |
1062 | if(FtpDelete( path.latin1(), conn)==0) { | 1062 | if(FtpDelete( path.latin1(), conn)==0) { |
1063 | QString msg; | 1063 | QString msg; |
1064 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); | 1064 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); |
1065 | msg.replace(QRegExp(":"),"\n"); | 1065 | msg.replace(QRegExp(":"),"\n"); |
1066 | QMessageBox::message(tr("Note"),msg); | 1066 | QMessageBox::message(tr("Note"),msg); |
1067 | } | 1067 | } |
1068 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1068 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1069 | } | 1069 | } |
1070 | break; | 1070 | break; |
1071 | }; | 1071 | }; |
1072 | } | 1072 | } |
1073 | } | 1073 | } |
1074 | } | 1074 | } |
1075 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1075 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void OpieFtp::remoteRename() | 1078 | void OpieFtp::remoteRename() |
1079 | { | 1079 | { |
1080 | QString curFile = Remote_View->currentItem()->text(0); | 1080 | QString curFile = Remote_View->currentItem()->text(0); |
1081 | InputDialog *fileDlg; | 1081 | InputDialog *fileDlg; |
1082 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 1082 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
1083 | fileDlg->setTextEdit((const QString &)curFile); | 1083 | fileDlg->setTextEdit((const QString &)curFile); |
1084 | fileDlg->exec(); | 1084 | fileDlg->exec(); |
1085 | if( fileDlg->result() == 1 ) { | 1085 | if( fileDlg->result() == 1 ) { |
1086 | QString oldName = currentRemoteDir +"/"+ curFile; | 1086 | QString oldName = currentRemoteDir +"/"+ curFile; |
1087 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; | 1087 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; |
1088 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1088 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1089 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { | 1089 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { |
1090 | QString msg; | 1090 | QString msg; |
1091 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); | 1091 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); |
1092 | msg.replace(QRegExp(":"),"\n"); | 1092 | msg.replace(QRegExp(":"),"\n"); |
1093 | QMessageBox::message(tr("Note"),msg); | 1093 | QMessageBox::message(tr("Note"),msg); |
1094 | } | 1094 | } |
1095 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1095 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1096 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1096 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1097 | } | 1097 | } |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | void OpieFtp::localRename() | 1100 | void OpieFtp::localRename() |
1101 | { | 1101 | { |
1102 | QString curFile = Local_View->currentItem()->text(0); | 1102 | QString curFile = Local_View->currentItem()->text(0); |
1103 | InputDialog *fileDlg; | 1103 | InputDialog *fileDlg; |
1104 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 1104 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
1105 | fileDlg->setTextEdit((const QString &)curFile); | 1105 | fileDlg->setTextEdit((const QString &)curFile); |
1106 | fileDlg->exec(); | 1106 | fileDlg->exec(); |
1107 | if( fileDlg->result() == 1 ) { | 1107 | if( fileDlg->result() == 1 ) { |
1108 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | 1108 | QString oldname = currentDir.canonicalPath() + "/" + curFile; |
1109 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | 1109 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; |
1110 | if( rename(oldname.latin1(), newName.latin1())== -1) | 1110 | if( rename(oldname.latin1(), newName.latin1())== -1) |
1111 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 1111 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
1112 | } | 1112 | } |
1113 | populateLocalView(); | 1113 | populateLocalView(); |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | void OpieFtp::currentPathComboActivated(const QString & currentPath) { | 1116 | void OpieFtp::currentPathComboActivated(const QString & currentPath) { |
1117 | if (TabWidget->currentPageIndex() == 0) { | 1117 | if (TabWidget->currentPageIndex() == 0) { |
1118 | chdir( currentPath.latin1() ); | 1118 | chdir( currentPath.latin1() ); |
1119 | currentDir.cd( currentPath, TRUE); | 1119 | currentDir.cd( currentPath, TRUE); |
1120 | populateLocalView(); | 1120 | populateLocalView(); |
1121 | update(); | 1121 | update(); |
1122 | } else { | 1122 | } else { |
1123 | // chdir( currentPath.latin1() ); | 1123 | // chdir( currentPath.latin1() ); |
1124 | // currentDir.cd( currentPath, TRUE); | 1124 | // currentDir.cd( currentPath, TRUE); |
1125 | // populateList(); | 1125 | // populateList(); |
1126 | // update(); | 1126 | // update(); |
1127 | 1127 | ||
1128 | } | 1128 | } |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | void OpieFtp::fillCombo(const QString ¤tPath) { | 1131 | void OpieFtp::fillCombo(const QString ¤tPath) { |
1132 | 1132 | ||
1133 | currentPathCombo->lineEdit()->setText(currentPath); | 1133 | currentPathCombo->lineEdit()->setText(currentPath); |
1134 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1134 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1135 | currentPathCombo->clear(); | 1135 | currentPathCombo->clear(); |
1136 | localDirPathStringList.prepend(currentPath ); | 1136 | localDirPathStringList.prepend(currentPath ); |
1137 | currentPathCombo->insertStringList( localDirPathStringList,-1); | 1137 | currentPathCombo->insertStringList( localDirPathStringList,-1); |
1138 | } | 1138 | } |
1139 | currentPathCombo->lineEdit()->setText(currentPath); | 1139 | currentPathCombo->lineEdit()->setText(currentPath); |
1140 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1140 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1141 | currentPathCombo->clear(); | 1141 | currentPathCombo->clear(); |
1142 | remoteDirPathStringList.prepend(currentPath ); | 1142 | remoteDirPathStringList.prepend(currentPath ); |
1143 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); | 1143 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); |
1144 | } | 1144 | } |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | void OpieFtp::fillRemoteCombo(const QString ¤tPath) { | 1147 | void OpieFtp::fillRemoteCombo(const QString ¤tPath) { |
1148 | 1148 | ||
1149 | currentPathCombo->lineEdit()->setText(currentPath); | 1149 | currentPathCombo->lineEdit()->setText(currentPath); |
1150 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1150 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1151 | currentPathCombo->clear(); | 1151 | currentPathCombo->clear(); |
1152 | remoteDirPathStringList.prepend(currentPath ); | 1152 | remoteDirPathStringList.prepend(currentPath ); |
1153 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); | 1153 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); |
1154 | } | 1154 | } |
1155 | } | 1155 | } |
1156 | 1156 | ||
1157 | void OpieFtp::currentPathComboChanged() | 1157 | void OpieFtp::currentPathComboChanged() |
1158 | { | 1158 | { |
1159 | QString oldRemoteCurrentDir = currentRemoteDir; | 1159 | QString oldRemoteCurrentDir = currentRemoteDir; |
1160 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); | 1160 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); |
1161 | if (TabWidget->currentPageIndex() == 0) { | 1161 | if (TabWidget->currentPageIndex() == 0) { |
1162 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { | 1162 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { |
1163 | currentDir.setPath( currentPathCombo->lineEdit()->text() ); | 1163 | currentDir.setPath( currentPathCombo->lineEdit()->text() ); |
1164 | populateLocalView(); | 1164 | populateLocalView(); |
1165 | } else { | 1165 | } else { |
1166 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | 1166 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); |
1167 | } | 1167 | } |
1168 | } | 1168 | } |
1169 | if (TabWidget->currentPageIndex() == 1) { | 1169 | if (TabWidget->currentPageIndex() == 1) { |
1170 | currentRemoteDir = currentPathCombo->lineEdit()->text(); | 1170 | currentRemoteDir = currentPathCombo->lineEdit()->text(); |
1171 | if(currentRemoteDir.right(1) !="/") { | 1171 | if(currentRemoteDir.right(1) !="/") { |
1172 | currentRemoteDir = currentRemoteDir +"/"; | 1172 | currentRemoteDir = currentRemoteDir +"/"; |
1173 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 1173 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
1174 | } | 1174 | } |
1175 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { | 1175 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { |
1176 | currentRemoteDir = oldRemoteCurrentDir; | 1176 | currentRemoteDir = oldRemoteCurrentDir; |
1177 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 1177 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | remoteDirList( (const QString &)currentRemoteDir); | 1180 | remoteDirList( (const QString &)currentRemoteDir); |
1181 | } | 1181 | } |
1182 | } | 1182 | } |
1183 | 1183 | ||
1184 | void OpieFtp::switchToLocalTab() | 1184 | void OpieFtp::switchToLocalTab() |
1185 | { | 1185 | { |
1186 | TabWidget->setCurrentPage(0); | 1186 | TabWidget->setCurrentPage(0); |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | void OpieFtp::switchToRemoteTab() | 1189 | void OpieFtp::switchToRemoteTab() |
1190 | { | 1190 | { |
1191 | TabWidget->setCurrentPage(1); | 1191 | TabWidget->setCurrentPage(1); |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | void OpieFtp::switchToConfigTab() | 1194 | void OpieFtp::switchToConfigTab() |
1195 | { | 1195 | { |
1196 | TabWidget->setCurrentPage(2); | 1196 | TabWidget->setCurrentPage(2); |
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | void OpieFtp::readConfig() | 1199 | void OpieFtp::readConfig() |
1200 | { | 1200 | { |
1201 | fillCombos(); | 1201 | fillCombos(); |
1202 | Config cfg("opieftp"); | 1202 | Config cfg("opieftp"); |
1203 | cfg.setGroup("Server"); | 1203 | cfg.setGroup("Server"); |
1204 | currentServerConfig = cfg.readNumEntry("currentServer", -1); | 1204 | currentServerConfig = cfg.readNumEntry("currentServer", -1); |
1205 | 1205 | ||
1206 | // qDebug("Reading %d", currentServerConfig); | 1206 | // qDebug("Reading %d", currentServerConfig); |
1207 | serverComboSelected( currentServerConfig-1); | 1207 | serverComboSelected( currentServerConfig-1); |
1208 | 1208 | ||
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | void OpieFtp::writeConfig() | 1211 | void OpieFtp::writeConfig() |
1212 | { | 1212 | { |
1213 | qDebug("write config"); | 1213 | qDebug("write config"); |
1214 | Config cfg("opieftp"); | 1214 | Config cfg("opieftp"); |
1215 | cfg.setGroup("Server"); | 1215 | cfg.setGroup("Server"); |
1216 | 1216 | ||
1217 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1217 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1218 | 1218 | ||
1219 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1219 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1220 | 1220 | ||
1221 | if( currentServerConfig == -1) { | 1221 | if( currentServerConfig == -1) { |
1222 | 1222 | ||
1223 | for (int i = 1; i <= numberOfEntries; i++) { | 1223 | for (int i = 1; i <= numberOfEntries; i++) { |
1224 | temp.setNum(i); | 1224 | temp.setNum(i); |
1225 | cfg.setGroup("Server"); | 1225 | cfg.setGroup("Server"); |
1226 | QString tempStr = cfg.readEntry( temp,""); | 1226 | QString tempStr = cfg.readEntry( temp,""); |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | temp.setNum( numberOfEntries + 1); | 1229 | temp.setNum( numberOfEntries + 1); |
1230 | cfg.setGroup("Server"); | 1230 | cfg.setGroup("Server"); |
1231 | 1231 | ||
1232 | remoteServerStr = cfg.readEntry( temp,""); | 1232 | remoteServerStr = cfg.readEntry( temp,""); |
1233 | 1233 | ||
1234 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1234 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1235 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | 1235 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); |
1236 | 1236 | ||
1237 | temp.setNum(numberOfEntries+1); | 1237 | temp.setNum(numberOfEntries+1); |
1238 | cfg.setGroup("Server"); | 1238 | cfg.setGroup("Server"); |
1239 | 1239 | ||
1240 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); | 1240 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); |
1241 | cfg.writeEntry("currentServer", numberOfEntries+1); | 1241 | cfg.writeEntry("currentServer", numberOfEntries+1); |
1242 | 1242 | ||
1243 | currentServerConfig = numberOfEntries+1; | 1243 | currentServerConfig = numberOfEntries+1; |
1244 | qDebug("setting currentserverconfig to %d", currentServerConfig); | 1244 | qDebug("setting currentserverconfig to %d", currentServerConfig); |
1245 | 1245 | ||
1246 | cfg.setGroup(temp); | 1246 | cfg.setGroup(temp); |
1247 | if(!newServerName.isEmpty()) | 1247 | if(!newServerName.isEmpty()) |
1248 | cfg.writeEntry("ServerName", newServerName); | 1248 | cfg.writeEntry("ServerName", newServerName); |
1249 | 1249 | ||
1250 | cfg.writeEntry("RemotePath", remotePath->text()); | 1250 | cfg.writeEntry("RemotePath", remotePath->text()); |
1251 | 1251 | ||
1252 | cfg.writeEntry("Username", UsernameComboBox->currentText()); | 1252 | cfg.writeEntry("Username", UsernameComboBox->currentText()); |
1253 | 1253 | ||
1254 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); | 1254 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); |
1255 | cfg.setGroup("Server"); | 1255 | cfg.setGroup("Server"); |
1256 | 1256 | ||
1257 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); | 1257 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); |
1258 | 1258 | ||
1259 | } | 1259 | } |
1260 | } | 1260 | } |
1261 | 1261 | ||
1262 | void OpieFtp::clearCombos() { | 1262 | void OpieFtp::clearCombos() { |
1263 | qDebug("clearing"); | 1263 | qDebug("clearing"); |
1264 | ServerComboBox->clear(); | 1264 | ServerComboBox->clear(); |
1265 | UsernameComboBox->clear(); | 1265 | UsernameComboBox->clear(); |
1266 | PasswordEdit->clear(); | 1266 | PasswordEdit->clear(); |
1267 | serverListView->clear(); | 1267 | serverListView->clear(); |
1268 | } | 1268 | } |
1269 | 1269 | ||
1270 | 1270 | ||
1271 | void OpieFtp::fillCombos() | 1271 | void OpieFtp::fillCombos() |
1272 | { | 1272 | { |
1273 | clearCombos(); | 1273 | clearCombos(); |
1274 | 1274 | ||
1275 | Config cfg("opieftp"); | 1275 | Config cfg("opieftp"); |
1276 | cfg.setGroup("Server"); | 1276 | cfg.setGroup("Server"); |
1277 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1277 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1278 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1278 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1279 | 1279 | ||
1280 | for (int i = 1; i <= numberOfEntries; i++) { | 1280 | for (int i = 1; i <= numberOfEntries; i++) { |
1281 | temp.setNum(i); | 1281 | temp.setNum(i); |
1282 | qDebug(temp); | 1282 | qDebug(temp); |
1283 | cfg.setGroup("Server"); | 1283 | cfg.setGroup("Server"); |
1284 | remoteServerStr = cfg.readEntry( temp,""); | 1284 | remoteServerStr = cfg.readEntry( temp,""); |
1285 | qDebug( remoteServerStr); | 1285 | qDebug( remoteServerStr); |
1286 | 1286 | ||
1287 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1287 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1288 | port = remoteServerStr.right( divider - 1); | 1288 | port = remoteServerStr.right( divider - 1); |
1289 | bool ok; | 1289 | bool ok; |
1290 | PortSpinBox->setValue( port.toInt(&ok,10)); | 1290 | PortSpinBox->setValue( port.toInt(&ok,10)); |
1291 | 1291 | ||
1292 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | 1292 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); |
1293 | qDebug( "remote server string "+remoteServerStr); | 1293 | qDebug( "remote server string "+remoteServerStr); |
1294 | ServerComboBox->insertItem( remoteServerStr ); | 1294 | ServerComboBox->insertItem( remoteServerStr ); |
1295 | 1295 | ||
1296 | cfg.setGroup(temp); | 1296 | cfg.setGroup(temp); |
1297 | 1297 | ||
1298 | username = cfg.readEntry(temp); | 1298 | username = cfg.readEntry(temp); |
1299 | UsernameComboBox->insertItem(username); | 1299 | UsernameComboBox->insertItem(username); |
1300 | password = cfg.readEntryCrypt(username,""); | 1300 | password = cfg.readEntryCrypt(username,""); |
1301 | PasswordEdit->setText(password); | 1301 | PasswordEdit->setText(password); |
1302 | 1302 | ||
1303 | serverListView->insertItem( cfg.readEntry("ServerName")); | 1303 | serverListView->insertItem( cfg.readEntry("ServerName")); |
1304 | } | 1304 | } |
1305 | } | 1305 | } |
1306 | 1306 | ||
1307 | 1307 | ||
1308 | void OpieFtp::serverComboSelected(int index) | 1308 | void OpieFtp::serverComboSelected(int index) |
1309 | { | 1309 | { |
1310 | currentServerConfig = index+1; | 1310 | currentServerConfig = index+1; |
1311 | qDebug("server combo selected %d", index+1); | 1311 | qDebug("server combo selected %d", index+1); |
1312 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1312 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1313 | // remoteServerStr = ServerComboBox->text(index); | 1313 | // remoteServerStr = ServerComboBox->text(index); |
1314 | 1314 | ||
1315 | Config cfg("opieftp"); | 1315 | Config cfg("opieftp"); |
1316 | cfg.setGroup("Server"); | 1316 | cfg.setGroup("Server"); |
1317 | // int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1317 | // int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1318 | 1318 | ||
1319 | temp.setNum(index+1); | 1319 | temp.setNum(index+1); |
1320 | remoteServerStr = cfg.readEntry( temp,""); | 1320 | remoteServerStr = cfg.readEntry( temp,""); |
1321 | 1321 | ||
1322 | qDebug("Group" +temp); | 1322 | qDebug("Group" +temp); |
1323 | cfg.setGroup(temp); | 1323 | cfg.setGroup(temp); |
1324 | // qDebug(temp); | 1324 | // qDebug(temp); |
1325 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1325 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1326 | port = remoteServerStr.right( divider - 1); | 1326 | port = remoteServerStr.right( divider - 1); |
1327 | bool ok; | 1327 | bool ok; |
1328 | int portInt = port.toInt(&ok,10); | 1328 | int portInt = port.toInt(&ok,10); |
1329 | if( portInt == 0) portInt = 21; | 1329 | if( portInt == 0) portInt = 21; |
1330 | 1330 | ||
1331 | ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); | 1331 | ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); |
1332 | 1332 | ||
1333 | PortSpinBox->setValue( portInt); | 1333 | PortSpinBox->setValue( portInt); |
1334 | 1334 | ||
1335 | remotePath->setText(cfg.readEntry("RemotePath", "/")); | 1335 | remotePath->setText(cfg.readEntry("RemotePath", "/")); |
1336 | 1336 | ||
1337 | username = cfg.readEntry("Username", "anonymous"); | 1337 | username = cfg.readEntry("Username", "anonymous"); |
1338 | UsernameComboBox->lineEdit()->setText(username); | 1338 | UsernameComboBox->lineEdit()->setText(username); |
1339 | qDebug(username); | 1339 | qDebug(username); |
1340 | // qDebug("Password is "+cfg.readEntryCrypt(username, "me@opieftp.org")); | 1340 | // qDebug("Password is "+cfg.readEntryCrypt(username, "me@opieftp.org")); |
1341 | PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); | 1341 | PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); |
1342 | // UsernameComboBox | 1342 | // UsernameComboBox |
1343 | // PasswordEdit | 1343 | // PasswordEdit |
1344 | 1344 | ||
1345 | cfg.setGroup("Server"); | 1345 | cfg.setGroup("Server"); |
1346 | temp.sprintf("%d",currentServerConfig); | 1346 | temp.sprintf("%d",currentServerConfig); |
1347 | cfg.writeEntry("currentServer", temp); | 1347 | cfg.writeEntry("currentServer", temp); |
1348 | 1348 | ||
1349 | fuckeduphack = TRUE; | 1349 | fuckeduphack = TRUE; |
1350 | serverListView->setCurrentItem( index); | 1350 | serverListView->setCurrentItem( index); |
1351 | fuckeduphack=FALSE; | 1351 | fuckeduphack=FALSE; |
1352 | qDebug("server list set selected %d",index); | 1352 | qDebug("server list set selected %d",index); |
1353 | update(); | 1353 | update(); |
1354 | } | 1354 | } |
1355 | 1355 | ||
1356 | void OpieFtp::deleteServer() | 1356 | void OpieFtp::deleteServer() |
1357 | { | 1357 | { |
1358 | QString username, remoteServerStr, remotePathStr, password, port, temp, servername; | 1358 | QString username, remoteServerStr, remotePathStr, password, port, temp, servername; |
1359 | remoteServerStr = ServerComboBox->currentText( ); | 1359 | remoteServerStr = ServerComboBox->currentText( ); |
1360 | username = UsernameComboBox->currentText(); | 1360 | username = UsernameComboBox->currentText(); |
1361 | servername=serverListView->currentText(); | 1361 | servername=serverListView->currentText(); |
1362 | 1362 | ||
1363 | Config cfg("opieftp"); | 1363 | Config cfg("opieftp"); |
1364 | cfg.setGroup("Server"); | 1364 | cfg.setGroup("Server"); |
1365 | QString tempname; | 1365 | QString tempname; |
1366 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1366 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1367 | 1367 | ||
1368 | for (int i = 1; i <= numberOfEntries; i++) { | 1368 | for (int i = 1; i <= numberOfEntries; i++) { |
1369 | temp.setNum(i); | 1369 | temp.setNum(i); |
1370 | // cfg.setGroup("Server"); | 1370 | // cfg.setGroup("Server"); |
1371 | cfg.setGroup(QString::number(i)); | 1371 | cfg.setGroup(QString::number(i)); |
1372 | tempname=cfg.readEntry( "ServerName",""); | 1372 | tempname=cfg.readEntry( "ServerName",""); |
1373 | 1373 | ||
1374 | if( tempname.find( servername,0,TRUE) != -1 ) { | 1374 | if( tempname.find( servername,0,TRUE) != -1 ) { |
1375 | // servername.find( cfg.readEntry("ServerName")) != -1 && | 1375 | // servername.find( cfg.readEntry("ServerName")) != -1 && |
1376 | // remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 && | 1376 | // remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 && |
1377 | // username.find( cfg.readEntry("Username")) != -1) { | 1377 | // username.find( cfg.readEntry("Username")) != -1) { |
1378 | 1378 | ||
1379 | serverListView->removeItem(i); | 1379 | serverListView->removeItem(i); |
1380 | 1380 | ||
1381 | qDebug("OK DELETE "+tempname); | 1381 | qDebug("OK DELETE "+tempname); |
1382 | cfg.removeEntry(QString::number(i)); | 1382 | cfg.removeEntry(QString::number(i)); |
1383 | for ( ; i <= numberOfEntries; i++) { | 1383 | for ( ; i <= numberOfEntries; i++) { |
1384 | cfg.setGroup("Server"); | 1384 | cfg.setGroup("Server"); |
1385 | cfg.writeEntry("Server", QString::number(numberOfEntries + 1 )); | 1385 | cfg.writeEntry("Server", QString::number(numberOfEntries + 1 )); |
1386 | 1386 | ||
1387 | cfg.setGroup(QString::number(i+1)); //get next server config | 1387 | cfg.setGroup(QString::number(i+1)); //get next server config |
1388 | servername=cfg.readEntry("ServerName"); | 1388 | servername=cfg.readEntry("ServerName"); |
1389 | remoteServerStr=cfg.readEntry("RemotePath"); | 1389 | remoteServerStr=cfg.readEntry("RemotePath"); |
1390 | username=cfg.readEntry("Username"); | 1390 | username=cfg.readEntry("Username"); |
1391 | password=cfg.readEntryCrypt( username); | 1391 | password=cfg.readEntryCrypt( username); |
1392 | 1392 | ||
1393 | cfg.setGroup(QString::number(i)); | 1393 | cfg.setGroup(QString::number(i)); |
1394 | 1394 | ||
1395 | cfg.writeEntry("RemotePath", remoteServerStr); | 1395 | cfg.writeEntry("RemotePath", remoteServerStr); |
1396 | cfg.writeEntry("ServerName", servername); | 1396 | cfg.writeEntry("ServerName", servername); |
1397 | cfg.writeEntry("Username", username); | 1397 | cfg.writeEntry("Username", username); |
1398 | cfg.writeEntryCrypt( username, password); | 1398 | cfg.writeEntryCrypt( username, password); |
1399 | 1399 | ||
1400 | } | 1400 | } |
1401 | cfg.setGroup("Server"); | 1401 | cfg.setGroup("Server"); |
1402 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 )); | 1402 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 )); |
1403 | } | 1403 | } |
1404 | } | 1404 | } |
1405 | cfg.setGroup(QString::number(numberOfEntries)); | 1405 | cfg.setGroup(QString::number(numberOfEntries)); |
1406 | cfg.removeEntry("Server"); | 1406 | cfg.removeEntry("Server"); |
1407 | cfg.removeEntry("RemotePath"); | 1407 | cfg.removeEntry("RemotePath"); |
1408 | cfg.removeEntry("ServerName"); | 1408 | cfg.removeEntry("ServerName"); |
1409 | username=cfg.readEntry("Username"); | 1409 | username=cfg.readEntry("Username"); |
1410 | cfg.removeEntry("Username"); | 1410 | cfg.removeEntry("Username"); |
1411 | cfg.removeEntry(username); | 1411 | cfg.removeEntry(username); |
1412 | 1412 | ||
1413 | currentServerConfig=currentServerConfig-1; | 1413 | currentServerConfig=currentServerConfig-1; |
1414 | 1414 | ||
1415 | fillCombos(); | 1415 | fillCombos(); |
1416 | update(); | 1416 | update(); |
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | void OpieFtp::upDir() | 1419 | void OpieFtp::upDir() |
1420 | { | 1420 | { |
1421 | if (TabWidget->currentPageIndex() == 0) { | 1421 | if (TabWidget->currentPageIndex() == 0) { |
1422 | QString current = currentDir.canonicalPath(); | 1422 | QString current = currentDir.canonicalPath(); |
1423 | QDir dir(current); | 1423 | QDir dir(current); |
1424 | dir.cdUp(); | 1424 | dir.cdUp(); |
1425 | current = dir.canonicalPath(); | 1425 | current = dir.canonicalPath(); |
1426 | chdir( current.latin1() ); | 1426 | chdir( current.latin1() ); |
1427 | currentDir.cd( current, TRUE); | 1427 | currentDir.cd( current, TRUE); |
1428 | populateLocalView(); | 1428 | populateLocalView(); |
1429 | update(); | 1429 | update(); |
1430 | } else { | 1430 | } else { |
1431 | if( FtpCDUp( conn) == 0) { | 1431 | if( FtpCDUp( conn) == 0) { |
1432 | QString msg; | 1432 | QString msg; |
1433 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); | 1433 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); |
1434 | msg.replace(QRegExp(":"),"\n"); | 1434 | msg.replace(QRegExp(":"),"\n"); |
1435 | QMessageBox::message(tr("Note"),msg); | 1435 | QMessageBox::message(tr("Note"),msg); |
1436 | // qDebug(msg); | 1436 | // qDebug(msg); |
1437 | } | 1437 | } |
1438 | char path[256]; | 1438 | char path[256]; |
1439 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string | 1439 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string |
1440 | QString msg; | 1440 | QString msg; |
1441 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); | 1441 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); |
1442 | msg.replace(QRegExp(":"),"\n"); | 1442 | msg.replace(QRegExp(":"),"\n"); |
1443 | QMessageBox::message(tr("Note"),msg); | 1443 | QMessageBox::message(tr("Note"),msg); |
1444 | // qDebug(msg); | 1444 | // qDebug(msg); |
1445 | } | 1445 | } |
1446 | currentRemoteDir=path; | 1446 | currentRemoteDir=path; |
1447 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1447 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1448 | if(currentRemoteDir.right(1) !="/") | 1448 | if(currentRemoteDir.right(1) !="/") |
1449 | currentRemoteDir +="/"; | 1449 | currentRemoteDir +="/"; |
1450 | currentPathCombo->lineEdit()->setText( currentRemoteDir); | 1450 | currentPathCombo->lineEdit()->setText( currentRemoteDir); |
1451 | fillRemoteCombo( (const QString &)currentRemoteDir); | 1451 | fillRemoteCombo( (const QString &)currentRemoteDir); |
1452 | 1452 | ||
1453 | } | 1453 | } |
1454 | } | 1454 | } |
1455 | 1455 | ||
1456 | void OpieFtp::docButtonPushed() { | 1456 | void OpieFtp::docButtonPushed() { |
1457 | QString current = QPEApplication::documentDir(); | 1457 | QString current = QPEApplication::documentDir(); |
1458 | chdir( current.latin1() ); | 1458 | chdir( current.latin1() ); |
1459 | currentDir.cd( current, TRUE); | 1459 | currentDir.cd( current, TRUE); |
1460 | populateLocalView(); | 1460 | populateLocalView(); |
1461 | update(); | 1461 | update(); |
1462 | 1462 | ||
1463 | } | 1463 | } |
1464 | 1464 | ||
1465 | void OpieFtp::homeButtonPushed() { | 1465 | void OpieFtp::homeButtonPushed() { |
1466 | QString current = QDir::homeDirPath(); | 1466 | QString current = QDir::homeDirPath(); |
1467 | chdir( current.latin1() ); | 1467 | chdir( current.latin1() ); |
1468 | currentDir.cd( current, TRUE); | 1468 | currentDir.cd( current, TRUE); |
1469 | populateLocalView(); | 1469 | populateLocalView(); |
1470 | update(); | 1470 | update(); |
1471 | } | 1471 | } |
1472 | 1472 | ||
1473 | void OpieFtp::doAbout() { | 1473 | void OpieFtp::doAbout() { |
1474 | QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n" | 1474 | QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n" |
1475 | "L.J.Potter<llornkcor@handhelds.org>\n" | 1475 | "L.J.Potter<llornkcor@handhelds.org>\n" |
1476 | "and uses ftplib copyright 1996-2000\n" | 1476 | "and uses ftplib copyright 1996-2000\n" |
1477 | "by Thomas Pfau, pfau@cnj.digex.net\n\n" | 1477 | "by Thomas Pfau, pfau@cnj.digex.net\n\n" |
1478 | "and is licensed by the GPL"); | 1478 | "and is licensed by the GPL"); |
1479 | } | 1479 | } |
1480 | 1480 | ||
1481 | void OpieFtp::NewServer() { | 1481 | void OpieFtp::NewServer() { |
1482 | InputDialog *fileDlg; | 1482 | InputDialog *fileDlg; |
1483 | fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0); | 1483 | fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0); |
1484 | fileDlg->exec(); | 1484 | fileDlg->exec(); |
1485 | Config cfg("opieftp"); | 1485 | Config cfg("opieftp"); |
1486 | if( fileDlg->result() == 1 ) { | 1486 | if( fileDlg->result() == 1 ) { |
1487 | newServerName = fileDlg->LineEdit1->text(); | 1487 | newServerName = fileDlg->LineEdit1->text(); |
1488 | for(int i=1;i<serverListView->count();i++) { | 1488 | for(int i=1;i<serverListView->count();i++) { |
1489 | cfg.setGroup( QString::number(i)); | 1489 | cfg.setGroup( QString::number(i)); |
1490 | if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) { | 1490 | if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) { |
1491 | QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken")); | 1491 | QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken")); |
1492 | return; | 1492 | return; |
1493 | } | 1493 | } |
1494 | } | 1494 | } |
1495 | currentServerConfig =-1; | 1495 | currentServerConfig =-1; |
1496 | writeConfig(); | 1496 | writeConfig(); |
1497 | serverListView->insertItem( newServerName ); | 1497 | serverListView->insertItem( newServerName ); |
1498 | serverListView->setCurrentItem( serverListView->count()); | 1498 | serverListView->setCurrentItem( serverListView->count()); |
1499 | } | 1499 | } |
1500 | } | 1500 | } |
1501 | 1501 | ||
1502 | void OpieFtp::serverListClicked( const QString &item) { | 1502 | void OpieFtp::serverListClicked( const QString &item) { |
1503 | if(item.isEmpty()) return; | 1503 | if(item.isEmpty()) return; |
1504 | Config cfg("opieftp"); | 1504 | Config cfg("opieftp"); |
1505 | qDebug("highltined "+item); | 1505 | qDebug("highltined "+item); |
1506 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1506 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1507 | for (int i = 1; i <= numberOfEntries; i++) { | 1507 | for (int i = 1; i <= numberOfEntries; i++) { |
1508 | cfg.setGroup(QString::number(i)); | 1508 | cfg.setGroup(QString::number(i)); |
1509 | if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) | 1509 | if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) |
1510 | serverComboSelected(i-1); | 1510 | serverComboSelected(i-1); |
1511 | } | 1511 | } |
1512 | } | 1512 | } |
1513 | |||
1514 | void OpieFtp::timerOut() { | ||
1515 | |||
1516 | } | ||
diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index 2aa691a..109b5f8 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h | |||
@@ -1,138 +1,140 @@ | |||
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 QLineEdit; | 37 | class QLineEdit; |
38 | class QPushButton; | 38 | class QPushButton; |
39 | class QToolButton; | 39 | class QToolButton; |
40 | class QStringList; | 40 | class QStringList; |
41 | class QListBox; | 41 | class QListBox; |
42 | class QTimer; | ||
42 | 43 | ||
43 | class OpieFtp : public QMainWindow | 44 | class OpieFtp : public QMainWindow |
44 | { | 45 | { |
45 | Q_OBJECT | 46 | Q_OBJECT |
46 | 47 | ||
47 | public: | 48 | public: |
48 | OpieFtp( ); | 49 | OpieFtp( ); |
49 | ~OpieFtp(); | 50 | ~OpieFtp(); |
50 | 51 | ||
51 | QTabWidget *TabWidget; | 52 | QTabWidget *TabWidget; |
52 | QWidget *tab, *tab_2, *tab_3; | 53 | QWidget *tab, *tab_2, *tab_3; |
53 | QListView *Local_View, *Remote_View; | 54 | QListView *Local_View, *Remote_View; |
54 | QListBox *serverListView; | 55 | QListBox *serverListView; |
55 | 56 | ||
56 | QComboBox *UsernameComboBox, *ServerComboBox, *currentPathCombo; | 57 | QComboBox *UsernameComboBox, *ServerComboBox, *currentPathCombo; |
57 | QLineEdit *PasswordEdit, *remotePath; | 58 | QLineEdit *PasswordEdit, *remotePath; |
58 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; | 59 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; |
59 | QSpinBox* PortSpinBox; | 60 | QSpinBox* PortSpinBox; |
60 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu, *aboutMenu; | 61 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu, *aboutMenu; |
61 | QDir currentDir; | 62 | QDir currentDir; |
62 | QString currentRemoteDir; | 63 | QString currentRemoteDir; |
63 | QString filterStr; | 64 | QString filterStr; |
64 | QListViewItem * item; | 65 | QListViewItem * item; |
65 | QPushButton *connectServerBtn, *newServerButton;// | 66 | QPushButton *connectServerBtn, *newServerButton;// |
66 | QToolButton *cdUpButton, *homeButton, *docButton; | 67 | QToolButton *cdUpButton, *homeButton, *docButton; |
67 | bool b; | 68 | bool b; |
68 | int currentServerConfig; | 69 | int currentServerConfig; |
69 | protected slots: | 70 | protected slots: |
71 | void timerOut(); | ||
70 | void upDir(); | 72 | void upDir(); |
71 | void homeButtonPushed(); | 73 | void homeButtonPushed(); |
72 | void docButtonPushed(); | 74 | void docButtonPushed(); |
73 | void doAbout(); | 75 | void doAbout(); |
74 | 76 | ||
75 | void serverComboEdited(const QString & ); | 77 | void serverComboEdited(const QString & ); |
76 | void UsernameComboBoxEdited(const QString & ); | 78 | void UsernameComboBoxEdited(const QString & ); |
77 | void PasswordEditEdited(const QString & ); | 79 | void PasswordEditEdited(const QString & ); |
78 | 80 | ||
79 | void showLocalMenu( QListViewItem *); | 81 | void showLocalMenu( QListViewItem *); |
80 | void showRemoteMenu( QListViewItem *); | 82 | void showRemoteMenu( QListViewItem *); |
81 | void doLocalCd(); | 83 | void doLocalCd(); |
82 | void doRemoteCd(); | 84 | void doRemoteCd(); |
83 | void localUpload(); | 85 | void localUpload(); |
84 | void remoteDownload(); | 86 | void remoteDownload(); |
85 | void newConnection(); | 87 | void newConnection(); |
86 | void connector(); | 88 | void connector(); |
87 | void disConnector(); | 89 | void disConnector(); |
88 | void populateLocalView(); | 90 | void populateLocalView(); |
89 | bool populateRemoteView(); | 91 | bool populateRemoteView(); |
90 | void showHidden(); | 92 | void showHidden(); |
91 | void writeConfig(); | 93 | void writeConfig(); |
92 | void readConfig(); | 94 | void readConfig(); |
93 | void localListClicked(QListViewItem *); | 95 | void localListClicked(QListViewItem *); |
94 | void remoteListClicked(QListViewItem *); | 96 | void remoteListClicked(QListViewItem *); |
95 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 97 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
96 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); | 98 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); |
97 | void localMakDir(); | 99 | void localMakDir(); |
98 | void localDelete(); | 100 | void localDelete(); |
99 | void remoteMakDir(); | 101 | void remoteMakDir(); |
100 | void remoteDelete(); | 102 | void remoteDelete(); |
101 | 103 | ||
102 | bool remoteDirList(const QString &); | 104 | bool remoteDirList(const QString &); |
103 | bool remoteChDir(const QString &); | 105 | bool remoteChDir(const QString &); |
104 | 106 | ||
105 | void tabChanged(QWidget*); | 107 | void tabChanged(QWidget*); |
106 | void cleanUp(); | 108 | void cleanUp(); |
107 | 109 | ||
108 | void remoteRename(); | 110 | void remoteRename(); |
109 | void localRename(); | 111 | void localRename(); |
110 | 112 | ||
111 | void currentPathComboChanged(); | 113 | void currentPathComboChanged(); |
112 | void currentPathComboActivated(const QString &); | 114 | void currentPathComboActivated(const QString &); |
113 | void switchToLocalTab(); | 115 | void switchToLocalTab(); |
114 | void switchToRemoteTab(); | 116 | void switchToRemoteTab(); |
115 | void switchToConfigTab(); | 117 | void switchToConfigTab(); |
116 | 118 | ||
117 | void fillCombos(); | 119 | void fillCombos(); |
118 | void clearCombos(); | 120 | void clearCombos(); |
119 | void fillRemoteCombo(const QString&); | 121 | void fillRemoteCombo(const QString&); |
120 | void fillCombo(const QString &); | 122 | void fillCombo(const QString &); |
121 | void serverComboSelected(int); | 123 | void serverComboSelected(int); |
122 | void deleteServer(); | 124 | void deleteServer(); |
123 | void connectorBtnToggled(bool); | 125 | void connectorBtnToggled(bool); |
124 | void NewServer(); | 126 | void NewServer(); |
125 | void serverListClicked( const QString &); | 127 | void serverListClicked( const QString &); |
126 | 128 | ||
127 | protected: | 129 | protected: |
128 | bool fuckeduphack; | 130 | bool fuckeduphack; |
129 | QStringList remoteDirPathStringList, localDirPathStringList; | 131 | QStringList remoteDirPathStringList, localDirPathStringList; |
130 | QString newServerName; | 132 | QString newServerName; |
131 | void nullifyCallBack(); | 133 | void nullifyCallBack(); |
132 | QGridLayout* tabLayout; | 134 | QGridLayout* tabLayout; |
133 | QGridLayout* tabLayout_2; | 135 | QGridLayout* tabLayout_2; |
134 | QGridLayout* tabLayout_3; | 136 | QGridLayout* tabLayout_3; |
135 | 137 | ||
136 | }; | 138 | }; |
137 | 139 | ||
138 | #endif // OPIEFTP_H | 140 | #endif // OPIEFTP_H |
diff --git a/noncore/net/opieftp/opieftp.pro b/noncore/net/opieftp/opieftp.pro index 6d88530..ae72ff3 100644 --- a/noncore/net/opieftp/opieftp.pro +++ b/noncore/net/opieftp/opieftp.pro | |||
@@ -1,24 +1,24 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS = opieftp.h inputDialog.h ftplib.h | 3 | HEADERS = opieftp.h inputDialog.h ftplib.h |
4 | SOURCES = opieftp.cpp inputDialog.cpp ftplib.c main.cpp | 4 | SOURCES = opieftp.cpp inputDialog.cpp main.cpp |
5 | TARGET = opieftp | 5 | TARGET = opieftp |
6 | DESTDIR = $(OPIEDIR)/bin | 6 | DESTDIR = $(OPIEDIR)/bin |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include | 8 | DEPENDPATH += $(OPIEDIR)/include |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe -lftplib |
10 | 10 | ||
11 | TRANSLATIONS = ../../../i18n/de/opieftp.ts \ | 11 | TRANSLATIONS = ../../../i18n/de/opieftp.ts \ |
12 | ../../../i18n/en/opieftp.ts \ | 12 | ../../../i18n/en/opieftp.ts \ |
13 | ../../../i18n/es/opieftp.ts \ | 13 | ../../../i18n/es/opieftp.ts \ |
14 | ../../../i18n/fr/opieftp.ts \ | 14 | ../../../i18n/fr/opieftp.ts \ |
15 | ../../../i18n/hu/opieftp.ts \ | 15 | ../../../i18n/hu/opieftp.ts \ |
16 | ../../../i18n/ja/opieftp.ts \ | 16 | ../../../i18n/ja/opieftp.ts \ |
17 | ../../../i18n/ko/opieftp.ts \ | 17 | ../../../i18n/ko/opieftp.ts \ |
18 | ../../../i18n/no/opieftp.ts \ | 18 | ../../../i18n/no/opieftp.ts \ |
19 | ../../../i18n/pl/opieftp.ts \ | 19 | ../../../i18n/pl/opieftp.ts \ |
20 | ../../../i18n/pt/opieftp.ts \ | 20 | ../../../i18n/pt/opieftp.ts \ |
21 | ../../../i18n/pt_BR/opieftp.ts \ | 21 | ../../../i18n/pt_BR/opieftp.ts \ |
22 | ../../../i18n/sl/opieftp.ts \ | 22 | ../../../i18n/sl/opieftp.ts \ |
23 | ../../../i18n/zh_CN/opieftp.ts \ | 23 | ../../../i18n/zh_CN/opieftp.ts \ |
24 | ../../../i18n/zh_TW/opieftp.ts | 24 | ../../../i18n/zh_TW/opieftp.ts |