Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/ftp_pwd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (hide annotations) (download) (as text)
Wed Dec 2 15:13:30 2009 UTC (14 years, 4 months ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 2933 byte(s)
add error check
1 hirohitohigashi 19 /*
2     liboftp: this is an FTP library to simplify the work to a Developer
3     who want to work with FTP servers (RFC 959).
4    
5     Copyright (c) 2009 hirohito higashi. All rights reserved.
6     This file is distributed under BSD license.
7     */
8    
9    
10     /***** Feature test switches ************************************************/
11     /***** System headers *******************************************************/
12     #include <string.h>
13    
14    
15     /***** Local headers ********************************************************/
16     #include "liboftp.h"
17     #include "sub.h"
18    
19    
20     /***** Constat values *******************************************************/
21     /***** Macros ***************************************************************/
22     /***** Typedefs *************************************************************/
23     /***** Function prototypes **************************************************/
24     /***** Local variables ******************************************************/
25     /***** Global variables *****************************************************/
26     /***** Signal catching functions ********************************************/
27     /***** Local functions ******************************************************/
28     /***** Global functions *****************************************************/
29    
30     /****************************************************************************/
31     /*! PWD������������
32     *
33     *@param ftp LIBOFTP���������������������
34     *@param buf ���������������������������
35     *@param bufsiz ���������������������
36 hirohitohigashi 30 *@retval int ������������������
37 hirohitohigashi 19 *@note
38     */
39     int ftp_pwd( LIBOFTP *ftp, char *buf, int bufsiz )
40     {
41     char str1[512] = "PWD\r\n";
42 hirohitohigashi 29 int res;
43 hirohitohigashi 19 char *p1, *p2;
44    
45 hirohitohigashi 50 if( ftp->socket < 0 ) return LIBOFTP_ERROR;
46    
47 hirohitohigashi 19 /*
48     * send PWD command
49     */
50 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
51 hirohitohigashi 29 DEBUGPRINT1( "command sending error. %s\n", str1 );
52     return LIBOFTP_ERROR_OS;
53 hirohitohigashi 19 }
54    
55 hirohitohigashi 29 if( (res = ftp_receive_response( ftp, str1, sizeof(str1) )) != 257 ) { /* 257: "PATHNAME" created. */
56     DEBUGPRINT1( "command response error. %d\n", res );
57     strncpy( ftp->error_message, str1, sizeof(ftp->error_message) - 1 );
58     return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
59 hirohitohigashi 19 }
60    
61     /*
62     * parse response
63     */
64     p1 = strchr( str1, '"' );
65     if( p1 == NULL ) {
66 hirohitohigashi 29 DEBUGPRINT1( "reply string parse error. %s\n", str1 );
67     strncpy( ftp->error_message, "reply string parse error.", sizeof( ftp->error_message ) );
68     return LIBOFTP_ERROR_PROTOCOL;
69 hirohitohigashi 19 }
70    
71     p2 = strchr( p1+1, '"' );
72     if( p2 == NULL ) {
73 hirohitohigashi 29 DEBUGPRINT1( "reply string parse error. %s\n", str1 );
74     strncpy( ftp->error_message, "reply string parse error.", sizeof( ftp->error_message ) );
75     return LIBOFTP_ERROR_PROTOCOL;
76 hirohitohigashi 19 }
77     if( bufsiz < (p2-p1) ) {
78 hirohitohigashi 29 DEBUGPRINT1( "buffer too small.%s", "" );
79     strncpy( ftp->error_message, "buffer too small", sizeof( ftp->error_message ) );
80     return LIBOFTP_ERROR_BUFFER;
81 hirohitohigashi 19 }
82    
83     memcpy( buf, p1+1, p2 - p1 - 1 );
84     buf[ p2 - p1 - 1 ] = 0;
85    
86 hirohitohigashi 29 return LIBOFTP_NOERROR;
87 hirohitohigashi 19 }

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