Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / FTP_Request.cpp
blobedddd1ef555e1ba638dc7df939ff0715fd575ef5
1 #include "ace/String_Base.h"
2 #include "ace/OS_NS_ctype.h"
3 #include "ace/INet/FTP_Request.h"
5 #if !defined (__ACE_INLINE__)
6 #include "ace/INet/FTP_Request.inl"
7 #endif
9 #include "ace/INet/INet_Log.h"
10 #include "ace/INet/String_IOStream.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 namespace ACE
17 namespace FTP
19 const ACE_CString Request::FTP_USER = "USER";
20 const ACE_CString Request::FTP_PASS = "PASS";
21 const ACE_CString Request::FTP_QUIT = "QUIT";
22 const ACE_CString Request::FTP_TYPE = "TYPE";
23 const ACE_CString Request::FTP_SYST = "SYST";
24 const ACE_CString Request::FTP_PWD = "PWD";
25 const ACE_CString Request::FTP_CWD = "CWD";
26 const ACE_CString Request::FTP_CDUP = "CDUP";
27 const ACE_CString Request::FTP_RNFR = "RNFR";
28 const ACE_CString Request::FTP_RNTO = "RNTO";
29 const ACE_CString Request::FTP_DELE = "DELE";
30 const ACE_CString Request::FTP_MKD = "MKD";
31 const ACE_CString Request::FTP_RMD = "RMD";
32 const ACE_CString Request::FTP_RETR = "RETR";
33 const ACE_CString Request::FTP_STOR = "STOR";
34 const ACE_CString Request::FTP_LIST = "LIST";
35 const ACE_CString Request::FTP_NLST = "NLST";
36 const ACE_CString Request::FTP_ABOR = "ABOR";
37 const ACE_CString Request::FTP_EPRT = "EPRT";
38 const ACE_CString Request::FTP_PORT = "PORT";
39 const ACE_CString Request::FTP_EPSV = "EPSV";
40 const ACE_CString Request::FTP_PASV = "PASV";
41 const ACE_CString Request::FTP_STAT = "STAT";
43 const int Request::eof_ = std::char_traits<char>::eof ();
45 Request::Request()
49 Request::~Request()
53 void Request::arguments (ACE_Array<ACE_CString> & args) const
55 ACE::IOS::CString_IStream sis (this->args_);
57 int ch = sis.get ();
58 while (ch != eof_)
60 // skip whitespace
61 while (ACE_OS::ace_isspace (ch)) ch = sis.get ();
62 if (ch != eof_)
64 // get arg
65 ACE_Array<ACE_CString>::size_type n =
66 args.size ();
67 args.size (n + 1);
68 ACE_CString& arg = args[n];
69 while (ch != eof_ && !ACE_OS::ace_isspace (ch))
71 arg += ch;
72 ch = sis.get ();
78 void Request::write(std::ostream& str) const
80 str << this->command_.c_str ();
81 if (!this->args_.empty ())
82 str << ' ' << this->args_.c_str ();
83 str << "\r\n";
85 INET_DEBUG (6, (LM_DEBUG, DLINFO
86 ACE_TEXT ("ACE_INet_FTP: --> %C %C\n"),
87 this->command_.c_str (),
88 this->command_ == FTP_PASS ?
89 "***" : this->args_.c_str ()));
92 bool Request::read(std::istream& str)
94 ACE_CString cmd (4, '\0');
95 ACE_CString args (128, '\0');
97 int ch = str.peek ();
98 if (ch == eof_)
100 str.get (); // skip to eof
101 return false;
103 // skip whitespace
104 while (ACE_OS::ace_isspace (str.peek ()))
106 str.get ();
108 // get method
109 ch = str.get ();
110 while (!ACE_OS::ace_isspace (ch) && ch != eof_ && cmd.length () < MAX_CMD_LENGTH)
112 cmd += ch;
113 ch = str.get ();
115 if (!ACE_OS::ace_isspace (ch))
116 return false; // invalid FTP command string
117 if (ch != '\r' && ch != '\n')
119 // skip whitespace
120 while (ACE_OS::ace_isspace (str.peek ()))
122 str.get ();
124 // get arguments
125 ch = str.get ();
126 while (ch != eof_ && ch != '\r' && ch != '\n' && args.length () < MAX_ARG_LENGTH)
128 args += ch;
129 ch = str.get ();
131 if (ch != eof_ && ch != '\r' && ch != '\n')
133 return false; // args too long
136 if (ch == '\r')
138 str.get ();
140 this->command (cmd);
141 this->args_ = args;
142 return true;
148 ACE_END_VERSIONED_NAMESPACE_DECL