Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/REL-1.1/ftp_str.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (hide annotations) (download) (as text)
Mon Feb 23 02:24:24 2009 UTC (15 years, 1 month ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 4927 byte(s)
Tag release 1.1
1 hirohitohigashi 1 /*
2    
3     libftp 1.0 (stable): this is an FTP library to simplify the work to a Developer
4     who want to work with FTP servers (RFC 959).
5     Copyright (C) 2007/2008 omnipresent - omnipresent[at]email.it
6    
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
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program. If not, see <http://www.gnu.org/licenses/>.
19    
20     */
21     #include "ftp_main.h"
22     #include <stdio.h>
23     #include <string.h>
24     /* Path of the Current Work Directory */
25     char path[1050]={'\0'};
26    
27     /*
28     *
29     * strfnbytes: look for needle into big_str for n bytes
30     * char *big_str: big string (where to look for needle)
31     * char *needle: string that you need
32     * int bytes: first n bytes
33     *
34     */
35    
36    
37     int strfnbytes(char *big_str, char *needle, int bytes) {
38    
39 hirohitohigashi 7 int i=0;
40     int same=0;
41 hirohitohigashi 1
42 hirohitohigashi 7 if (strlen(big_str)-1 < bytes) {
43     printf("[-] Big String MUST BE major than %d\n", bytes);
44     printf("Aborting...\n");
45     return (-1);
46     }
47 hirohitohigashi 1
48    
49 hirohitohigashi 7 if (strlen(needle)-1 >= bytes) {
50     printf("[-] needle MUST BE the same as n bytes\n");
51     printf("Aborting...\n");
52     return (-1);
53     }
54 hirohitohigashi 1
55    
56 hirohitohigashi 7 while (big_str[i] != '\0') {
57 hirohitohigashi 1
58 hirohitohigashi 7 if (i >= bytes)
59     break;
60 hirohitohigashi 1
61 hirohitohigashi 7 if (needle[i] == big_str[i]) {
62 hirohitohigashi 1
63 hirohitohigashi 7 same++;
64     } else {
65 hirohitohigashi 1
66 hirohitohigashi 7 same=0;
67     break;
68     }
69 hirohitohigashi 1
70 hirohitohigashi 7 i++;
71 hirohitohigashi 1
72 hirohitohigashi 7 }
73 hirohitohigashi 1
74 hirohitohigashi 7 if (same != 0)
75     return 0;
76     else
77     return -1;
78 hirohitohigashi 1
79     }
80    
81     /*
82 hirohitohigashi 7 *
83     * find_pasv: find the ports in the PASV message reply
84     * char *StrPasv: the reply string to working on it
85     * int verbose: verbose mode
86     * - 1 Yes
87     * - 0 No
88     *
89     */
90 hirohitohigashi 1
91 hirohitohigashi 7 int find_pasv (char *StrPasv, int verbose)
92     {
93     char p1[100];
94     char p2[100];
95 hirohitohigashi 1
96 hirohitohigashi 7 int port1 = 0;
97     int port2 = 0;
98     int count = 0;
99     int i = 0;
100     int temp = 0;
101     int tmp = 0;
102     int sum = 0;
103 hirohitohigashi 1
104 hirohitohigashi 7 extern int data_port1;
105     extern int data_port2;
106 hirohitohigashi 1
107    
108 hirohitohigashi 7 int len = strlen(StrPasv);
109 hirohitohigashi 1
110 hirohitohigashi 7 len = len-2;
111     StrPasv[len] = '\0';
112 hirohitohigashi 1
113    
114 hirohitohigashi 7 if (strstr(StrPasv, ")") == NULL) { //mmh an error occur..
115     return 1;
116     }
117    
118     while (StrPasv[i] != '\0') {
119     if (StrPasv[i] == ')') {
120     break;
121 hirohitohigashi 1 }
122    
123 hirohitohigashi 7 i++;
124     }
125 hirohitohigashi 1
126    
127 hirohitohigashi 7 temp = i;
128     i = 0;
129 hirohitohigashi 1
130    
131    
132    
133 hirohitohigashi 7 data_port1 = 0;
134     data_port2 = 0;
135 hirohitohigashi 1
136 hirohitohigashi 7 count = temp;
137 hirohitohigashi 1
138 hirohitohigashi 7 count = count - 1;
139 hirohitohigashi 1
140 hirohitohigashi 7 memset(p1, 0x0, 100);
141     memset(p2, 0x0, 100);
142 hirohitohigashi 1
143 hirohitohigashi 7 if (verbose == 1) {
144 hirohitohigashi 1 printf("--[ Server: %s\n", StrPasv);
145 hirohitohigashi 7 }
146 hirohitohigashi 1
147 hirohitohigashi 7 while (StrPasv[count] != ',') {
148 hirohitohigashi 1
149     if (i >= 100)
150 hirohitohigashi 7 return -1;
151 hirohitohigashi 1
152     p1[i] = StrPasv[count];
153    
154     count--;
155     i++;
156    
157 hirohitohigashi 7 }
158 hirohitohigashi 1
159 hirohitohigashi 7 p1[i] = '\0';
160 hirohitohigashi 1
161    
162 hirohitohigashi 7 count--;
163     i = 0;
164 hirohitohigashi 1
165 hirohitohigashi 7 while (StrPasv[count] != ',') {
166 hirohitohigashi 1
167     p2[i] = StrPasv[count];
168    
169    
170     count--;
171     i++;
172    
173 hirohitohigashi 7 }
174 hirohitohigashi 1
175 hirohitohigashi 7 p2[i] = '\0';
176 hirohitohigashi 1
177 hirohitohigashi 7 i = 0;
178     count = 0;
179     tmp = 0;
180     sum = 0;
181 hirohitohigashi 1
182 hirohitohigashi 7 while (p1[i] != '\0') {
183 hirohitohigashi 1
184     tmp = 0;
185     sum = 0;
186    
187     if (i == 1) {
188    
189 hirohitohigashi 7 tmp = (int)p1[i] - 48;
190     sum = 10*tmp;
191 hirohitohigashi 1
192 hirohitohigashi 7 port1 = port1 + sum;
193 hirohitohigashi 1
194     } else if (i == 2) {
195    
196 hirohitohigashi 7 tmp = (int)p1[i] - 48;
197 hirohitohigashi 1
198 hirohitohigashi 7 sum = 100*tmp;
199 hirohitohigashi 1
200 hirohitohigashi 7 port1 = port1 + sum;
201 hirohitohigashi 1
202     } else if (i == 0) {
203    
204 hirohitohigashi 7 tmp = (int)p1[i] - 48;
205 hirohitohigashi 1
206 hirohitohigashi 7 port1 = port1 + tmp;
207 hirohitohigashi 1
208     } else if ( i > 2) {
209    
210 hirohitohigashi 7 return -1;
211 hirohitohigashi 1
212     }
213    
214     i++;
215    
216 hirohitohigashi 7 }
217 hirohitohigashi 1
218 hirohitohigashi 7 i = 0;
219     count = 0;
220     tmp = 0;
221     sum = 0;
222 hirohitohigashi 1
223 hirohitohigashi 7 while (p2[i] != '\0') {
224 hirohitohigashi 1
225     tmp = 0;
226     sum = 0;
227    
228     if (i == 1) {
229    
230 hirohitohigashi 7 tmp = (int)p2[i] - 48;
231     sum = 10*tmp;
232 hirohitohigashi 1
233 hirohitohigashi 7 port2 = port2 + sum;
234 hirohitohigashi 1
235     } else if (i == 2) {
236    
237 hirohitohigashi 7 tmp = (int)p2[i] - 48;
238 hirohitohigashi 1
239 hirohitohigashi 7 sum = 100*tmp;
240 hirohitohigashi 1
241 hirohitohigashi 7 port2 = port2 + sum;
242 hirohitohigashi 1
243     } else if (i == 0) {
244    
245 hirohitohigashi 7 tmp = (int)p2[i] - 48;
246 hirohitohigashi 1
247 hirohitohigashi 7 port2 = port2 + tmp;
248 hirohitohigashi 1
249     } else if ( i > 2) {
250    
251 hirohitohigashi 7 return -1;
252 hirohitohigashi 1
253     }
254    
255     i++;
256    
257 hirohitohigashi 7 }
258 hirohitohigashi 1
259 hirohitohigashi 7 data_port2 = port1;
260     data_port1 = port2;
261 hirohitohigashi 1
262    
263 hirohitohigashi 7 return 0;
264 hirohitohigashi 1
265    
266     }
267    
268     /*
269 hirohitohigashi 7 *
270     * ftp_DataPort: Make the right Data Port for transfer connections
271     * int PortOne: First port in the PASV reply
272     * int PortTwo: Second port in the PASV reply
273     *
274     */
275 hirohitohigashi 1
276     int ftp_DataPort (int PortOne, int PortTwo) {
277    
278     /*** HOWTO Data Transfer Connection:
279 hirohitohigashi 7 ((port1 * 256) + port2)
280 hirohitohigashi 1 ***/
281    
282 hirohitohigashi 7 extern int data_port;
283 hirohitohigashi 1
284 hirohitohigashi 7 data_port = 0;
285 hirohitohigashi 1
286 hirohitohigashi 7 data_port = PortOne * 256;
287     data_port = data_port + PortTwo;
288 hirohitohigashi 1
289 hirohitohigashi 7 return data_port;
290 hirohitohigashi 1
291     }
292    
293     /*
294 hirohitohigashi 7 *
295     * ftp_path: Reply with the Current Directory
296     * char *PathCurDir: Reply of the FTPD from the PWD command
297     *
298     */
299 hirohitohigashi 1
300     int ftp_path (char *PathCurDir) {
301    
302 hirohitohigashi 7 int i = 0;
303     int count = 0;
304 hirohitohigashi 1
305 hirohitohigashi 7 if (strlen(PathCurDir) > 1024)
306 hirohitohigashi 1 return -1;
307    
308 hirohitohigashi 7 while (PathCurDir[i] != '"') {
309 hirohitohigashi 1
310     if (i >= 1024)
311 hirohitohigashi 7 return -1;
312     i++;
313 hirohitohigashi 1
314 hirohitohigashi 7 }
315 hirohitohigashi 1
316 hirohitohigashi 7 i++;
317 hirohitohigashi 1
318 hirohitohigashi 7 while (PathCurDir[i] != '"') {
319 hirohitohigashi 1
320     if (i >= 1024) {
321 hirohitohigashi 7 path[i] = '\0';
322     break;
323 hirohitohigashi 1 }
324    
325 hirohitohigashi 7 path[count] = PathCurDir[i];
326     i++;
327     count++;
328     }
329 hirohitohigashi 1
330 hirohitohigashi 7 if (i >= 1024) {
331 hirohitohigashi 1 path[i] = '\0';
332     return 0;
333 hirohitohigashi 7 }
334 hirohitohigashi 1
335 hirohitohigashi 7 path[count] = '\0';
336 hirohitohigashi 1
337 hirohitohigashi 7 return 0;
338 hirohitohigashi 1
339     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26