Go to the documentation of this file.00001
00002
00003 #include "ace/OS_NS_stdlib.h"
00004 #include "ace/OS_NS_ctype.h"
00005 #include "ace/String_Base.h"
00006 #include "ace/INet/FTP_Response.h"
00007
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/INet/FTP_Response.inl"
00010 #endif
00011
00012 #include "ace/INet/INet_Log.h"
00013 #include "ace/INet/String_IOStream.h"
00014
00015 ACE_RCSID(NET_CLIENT,ACE_FTP_Response,"$Id: FTP_Response.cpp 90891 2010-06-28 09:55:39Z mcorino $")
00016
00017 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 namespace ACE
00020 {
00021 namespace FTP
00022 {
00023 const int Response::eof_ = std::char_traits<char>::eof ();
00024
00025 Response::Response()
00026 : status_ (NORESPONSE)
00027 {
00028 }
00029
00030 Response::~Response()
00031 {
00032 }
00033
00034 void Response::write(ostream& str) const
00035 {
00036 ACE_Array<ACE_CString>::size_type n = 0;
00037 str << this->status_;
00038 if (this->response_.size () > 0)
00039 {
00040 n = this->response_.size () - 1;
00041 str << (n > 0 ? '-' : ' ') << this->response_[0].c_str ();
00042 }
00043 str << "\r\n";
00044 for (ACE_Array<ACE_CString>::size_type i = 1;
00045 i < n;
00046 ++i)
00047 {
00048 str << this->response_[i].c_str () << "\r\n";
00049 }
00050 if (n > 0)
00051 {
00052 str << this->status_ << ' '
00053 << this->response_[n].c_str () << "\r\n";
00054 }
00055 }
00056
00057 bool Response::read(istream& str)
00058 {
00059 int ch;
00060 str >> this->status_;
00061 ch = str.get ();
00062 if (str.bad () || this->status_type () == NOSTATE || (ch != ' ' && ch != '-'))
00063 {
00064 return false;
00065 }
00066
00067 bool multi_line = (ch == '-');
00068
00069 ACE_Array<ACE_CString>::size_type n =
00070 this->response_.size ();
00071 this->response_.size (n+1);
00072 this->response_[n].clear ();
00073 ACE::IOS::CString_OStream sos (this->response_[n]);
00074 sos << this->status_;
00075 sos.put (ch);
00076 ch = this->read_line (str, sos);
00077 if (ch == '\r') ch = str.get ();
00078 sos.close ();
00079
00080 INET_DEBUG (6, (LM_DEBUG, DLINFO
00081 ACE_TEXT ("ACE_INet_FTP: <-- %C\n"),
00082 this->response_[n].c_str ()));
00083
00084 if (multi_line)
00085 {
00086 while (ch != eof_)
00087 {
00088 int nxt_stat = 0;
00089
00090 n = this->response_.size ();
00091 this->response_.size (n+1);
00092 this->response_[n].clear ();
00093 ACE::IOS::CString_OStream nxt_sos (this->response_[n]);
00094
00095 if (ACE_OS::ace_isdigit (str.peek ()))
00096 {
00097 str >> nxt_stat;
00098 ch = str.get ();
00099 if (str.bad () || (nxt_stat == this->status_ && ch != ' '))
00100 {
00101 this->status_ = NORESPONSE;
00102 return false;
00103 }
00104 nxt_sos << nxt_stat;
00105 nxt_sos.put(ch);
00106 }
00107 ch = this->read_line (str, nxt_sos);
00108
00109 nxt_sos.close ();
00110
00111 INET_DEBUG (9, (LM_DEBUG, DLINFO
00112 ACE_TEXT ("ACE_INet_FTP: <-+ %C\n"),
00113 this->response_[n].c_str ()));
00114
00115 if (nxt_stat == this->status_)
00116 {
00117 return true;
00118 }
00119 }
00120
00121 this->status_ = NORESPONSE;
00122 return false;
00123 }
00124 else
00125 {
00126 return true;
00127 }
00128 }
00129 }
00130 }
00131
00132 ACE_END_VERSIONED_NAMESPACE_DECL