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 1 - (hide annotations) (download) (as text)
Wed Feb 18 08:06:53 2009 UTC (15 years, 1 month ago) by hirohitohigashi
Original Path: trunk/ftp_str.c
File MIME type: text/x-csrc
File size: 4557 byte(s)
Initial import. original is libOftp_1_0.tar.gz.
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     int i=0;
40     int same=0;
41    
42     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    
48    
49     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    
55    
56     while (big_str[i] != '\0') {
57    
58     if (i >= bytes)
59     break;
60    
61     if (needle[i] == big_str[i]) {
62    
63     same++;
64     } else {
65    
66     same=0;
67     break;
68     }
69    
70     i++;
71    
72     }
73    
74     if (same != 0)
75     return 0;
76     else
77     return -1;
78    
79     }
80    
81     /*
82     *
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    
91     int find_pasv (char *StrPasv, int verbose) {
92    
93     char p1[100];
94     char p2[100];
95    
96     int port1 = 0;
97     int port2 = 0;
98    
99     int len = strlen(StrPasv);
100    
101     len = len-2;
102     StrPasv[len] = '\0';
103    
104     int count = 0;
105     int i = 0;
106    
107    
108     if (strstr(StrPasv, ")") == NULL) { //mmh an error occur..
109     return 1;
110     }
111    
112     while (StrPasv[i] != '\0') {
113     if (StrPasv[i] == ')') {
114     break;
115     }
116    
117     i++;
118     }
119    
120     int temp = 0;
121    
122     temp = i;
123     i = 0;
124    
125     int tmp = 0;
126     int sum = 0;
127    
128    
129     extern int data_port1;
130     extern int data_port2;
131    
132     data_port1 = 0;
133     data_port2 = 0;
134    
135     count = temp;
136    
137     count = count - 1;
138    
139     memset(p1, 0x0, 100);
140     memset(p2, 0x0, 100);
141    
142     if (verbose == 1) {
143     printf("--[ Server: %s\n", StrPasv);
144     }
145    
146     while (StrPasv[count] != ',') {
147    
148     if (i >= 100)
149     return -1;
150    
151     p1[i] = StrPasv[count];
152    
153     count--;
154     i++;
155    
156     }
157    
158     p1[i] = '\0';
159    
160    
161     count--;
162     i = 0;
163    
164     while (StrPasv[count] != ',') {
165    
166     p2[i] = StrPasv[count];
167    
168    
169     count--;
170     i++;
171    
172     }
173    
174     p2[i] = '\0';
175    
176     i = 0;
177     count = 0;
178     tmp = 0;
179     sum = 0;
180    
181     while (p1[i] != '\0') {
182    
183     tmp = 0;
184     sum = 0;
185    
186     if (i == 1) {
187    
188     tmp = (int)p1[i] - 48;
189     sum = 10*tmp;
190    
191     port1 = port1 + sum;
192    
193     } else if (i == 2) {
194    
195     tmp = (int)p1[i] - 48;
196    
197     sum = 100*tmp;
198    
199     port1 = port1 + sum;
200    
201     } else if (i == 0) {
202    
203     tmp = (int)p1[i] - 48;
204    
205     port1 = port1 + tmp;
206    
207     } else if ( i > 2) {
208    
209     return -1;
210    
211     }
212    
213     i++;
214    
215     }
216    
217     i = 0;
218     count = 0;
219     tmp = 0;
220     sum = 0;
221    
222     while (p2[i] != '\0') {
223    
224     tmp = 0;
225     sum = 0;
226    
227     if (i == 1) {
228    
229     tmp = (int)p2[i] - 48;
230     sum = 10*tmp;
231    
232     port2 = port2 + sum;
233    
234     } else if (i == 2) {
235    
236     tmp = (int)p2[i] - 48;
237    
238     sum = 100*tmp;
239    
240     port2 = port2 + sum;
241    
242     } else if (i == 0) {
243    
244     tmp = (int)p2[i] - 48;
245    
246     port2 = port2 + tmp;
247    
248     } else if ( i > 2) {
249    
250     return -1;
251    
252     }
253    
254     i++;
255    
256     }
257    
258     data_port2 = port1;
259     data_port1 = port2;
260    
261    
262     return 0;
263    
264    
265     }
266    
267     /*
268     *
269     * ftp_DataPort: Make the right Data Port for transfer connections
270     * int PortOne: First port in the PASV reply
271     * int PortTwo: Second port in the PASV reply
272     *
273     */
274    
275     int ftp_DataPort (int PortOne, int PortTwo) {
276    
277     /*** HOWTO Data Transfer Connection:
278     ((port1 * 256) + port2)
279     ***/
280    
281     extern int data_port;
282    
283     data_port = 0;
284    
285     data_port = PortOne * 256;
286     data_port = data_port + PortTwo;
287    
288     return data_port;
289    
290     }
291    
292     /*
293     *
294     * ftp_path: Reply with the Current Directory
295     * char *PathCurDir: Reply of the FTPD from the PWD command
296     *
297     */
298    
299     int ftp_path (char *PathCurDir) {
300    
301     int i = 0;
302     int count = 0;
303    
304     if (strlen(PathCurDir) > 1024)
305     return -1;
306    
307     while (PathCurDir[i] != '"') {
308    
309     if (i >= 1024)
310     return -1;
311     i++;
312    
313     }
314    
315     i++;
316    
317     while (PathCurDir[i] != '"') {
318    
319     if (i >= 1024) {
320     path[i] = '\0';
321     break;
322     }
323    
324     path[count] = PathCurDir[i];
325     i++;
326     count++;
327     }
328    
329     if (i >= 1024) {
330     path[i] = '\0';
331     return 0;
332     }
333    
334     path[count] = '\0';
335    
336     return 0;
337    
338     }

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