00001 // $Id: FTP_Request.cpp 90891 2010-06-28 09:55:39Z mcorino $ 00002 00003 #include "ace/String_Base.h" 00004 #include "ace/OS_NS_ctype.h" 00005 #include "ace/INet/FTP_Request.h" 00006 00007 #if !defined (__ACE_INLINE__) 00008 #include "ace/INet/FTP_Request.inl" 00009 #endif 00010 00011 #include "ace/INet/INet_Log.h" 00012 #include "ace/INet/String_IOStream.h" 00013 00014 ACE_RCSID(NET_CLIENT,ACE_FTP_Request,"$Id: FTP_Request.cpp 90891 2010-06-28 09:55:39Z mcorino $") 00015 00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace ACE 00019 { 00020 namespace FTP 00021 { 00022 00023 const ACE_CString Request::FTP_USER = "USER"; 00024 const ACE_CString Request::FTP_PASS = "PASS"; 00025 const ACE_CString Request::FTP_QUIT = "QUIT"; 00026 const ACE_CString Request::FTP_TYPE = "TYPE"; 00027 const ACE_CString Request::FTP_SYST = "SYST"; 00028 const ACE_CString Request::FTP_PWD = "PWD"; 00029 const ACE_CString Request::FTP_CWD = "CWD"; 00030 const ACE_CString Request::FTP_CDUP = "CDUP"; 00031 const ACE_CString Request::FTP_RNFR = "RNFR"; 00032 const ACE_CString Request::FTP_RNTO = "RNTO"; 00033 const ACE_CString Request::FTP_DELE = "DELE"; 00034 const ACE_CString Request::FTP_MKD = "MKD"; 00035 const ACE_CString Request::FTP_RMD = "RMD"; 00036 const ACE_CString Request::FTP_RETR = "RETR"; 00037 const ACE_CString Request::FTP_STOR = "STOR"; 00038 const ACE_CString Request::FTP_LIST = "LIST"; 00039 const ACE_CString Request::FTP_NLST = "NLST"; 00040 const ACE_CString Request::FTP_ABOR = "ABOR"; 00041 const ACE_CString Request::FTP_EPRT = "EPRT"; 00042 const ACE_CString Request::FTP_PORT = "PORT"; 00043 const ACE_CString Request::FTP_EPSV = "EPSV"; 00044 const ACE_CString Request::FTP_PASV = "PASV"; 00045 const ACE_CString Request::FTP_STAT = "STAT"; 00046 00047 const int Request::eof_ = std::char_traits<char>::eof (); 00048 00049 Request::Request() 00050 { 00051 } 00052 00053 Request::~Request() 00054 { 00055 } 00056 00057 void Request::arguments (ACE_Array<ACE_CString> & args) const 00058 { 00059 ACE::IOS::CString_IStream sis (this->args_); 00060 00061 int ch = sis.get (); 00062 while (ch != eof_) 00063 { 00064 // skip whitespace 00065 while (ACE_OS::ace_isspace (ch)) ch = sis.get (); 00066 if (ch != eof_) 00067 { 00068 // get arg 00069 ACE_Array<ACE_CString>::size_type n = 00070 args.size (); 00071 args.size (n + 1); 00072 ACE_CString& arg = args[n]; 00073 while (ch != eof_ && !ACE_OS::ace_isspace (ch)) 00074 { 00075 arg += ch; 00076 ch = sis.get (); 00077 } 00078 } 00079 } 00080 } 00081 00082 void Request::write(std::ostream& str) const 00083 { 00084 str << this->command_.c_str (); 00085 if (!this->args_.empty ()) 00086 str << ' ' << this->args_.c_str (); 00087 str << "\r\n"; 00088 00089 INET_DEBUG (6, (LM_DEBUG, DLINFO 00090 ACE_TEXT ("ACE_INet_FTP: --> %C %C\n"), 00091 this->command_.c_str (), 00092 this->command_ == FTP_PASS ? 00093 "***" : this->args_.c_str ())); 00094 } 00095 00096 bool Request::read(std::istream& str) 00097 { 00098 ACE_CString cmd (4, '\0'); 00099 ACE_CString args (128, '\0'); 00100 00101 int ch = str.peek (); 00102 if (ch == eof_) 00103 { 00104 str.get (); // skip to eof 00105 return false; 00106 } 00107 // skip whitespace 00108 while (ACE_OS::ace_isspace (str.peek ())) 00109 { 00110 str.get (); 00111 } 00112 // get method 00113 ch = str.get (); 00114 while (!ACE_OS::ace_isspace (ch) && ch != eof_ && cmd.length () < MAX_CMD_LENGTH) 00115 { 00116 cmd += ch; 00117 ch = str.get (); 00118 } 00119 if (!ACE_OS::ace_isspace (ch)) 00120 return false; // invalid FTP command string 00121 if (ch != '\r' && ch != '\n') 00122 { 00123 // skip whitespace 00124 while (ACE_OS::ace_isspace (str.peek ())) 00125 { 00126 str.get (); 00127 } 00128 // get arguments 00129 ch = str.get (); 00130 while (ch != eof_ && ch != '\r' && ch != '\n' && args.length () < MAX_ARG_LENGTH) 00131 { 00132 args += ch; 00133 ch = str.get (); 00134 } 00135 if (ch != eof_ && ch != '\r' && ch != '\n') 00136 { 00137 return false; // args too long 00138 } 00139 } 00140 if (ch == '\r') 00141 { 00142 str.get (); 00143 } 00144 this->command (cmd); 00145 this->args_ = args; 00146 return true; 00147 } 00148 00149 } 00150 } 00151 00152 ACE_END_VERSIONED_NAMESPACE_DECL