Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / FTP_Response.cpp
bloba08528b8e422063072d050487fb9ed954366e84e
1 #include "ace/OS_NS_stdlib.h"
2 #include "ace/OS_NS_ctype.h"
3 #include "ace/String_Base.h"
4 #include "ace/INet/FTP_Response.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/INet/FTP_Response.inl"
8 #endif
10 #include "ace/INet/INet_Log.h"
11 #include "ace/INet/String_IOStream.h"
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 namespace ACE
18 namespace FTP
20 const int Response::eof_ = std::char_traits<char>::eof ();
22 Response::Response()
23 : status_ (NORESPONSE)
27 Response::~Response()
31 void Response::write(ostream& str) const
33 ACE_Array<ACE_CString>::size_type n = 0;
34 str << this->status_;
35 if (this->response_.size () > 0)
37 n = this->response_.size () - 1;
38 str << (n > 0 ? '-' : ' ') << this->response_[0].c_str ();
40 str << "\r\n";
41 for (ACE_Array<ACE_CString>::size_type i = 1;
42 i < n;
43 ++i)
45 str << this->response_[i].c_str () << "\r\n";
47 if (n > 0)
49 str << this->status_ << ' '
50 << this->response_[n].c_str () << "\r\n";
54 bool Response::read(istream& str)
56 int ch;
57 str >> this->status_;
58 ch = str.get ();
59 if (str.bad () || this->status_type () == NOSTATE || (ch != ' ' && ch != '-'))
61 return false; // invalid status
64 bool multi_line = (ch == '-');
66 ACE_Array<ACE_CString>::size_type n =
67 this->response_.size ();
68 this->response_.size (n+1);
69 this->response_[n].clear ();
70 ACE::IOS::CString_OStream sos (this->response_[n]);
71 sos << this->status_;
72 sos.put (ch);
73 ch = this->read_line (str, sos);
74 if (ch == '\r') ch = str.get ();
75 sos.close (); // close the stream before resizing the array invalidates the string reference
77 INET_DEBUG (6, (LM_DEBUG, DLINFO
78 ACE_TEXT ("ACE_INet_FTP: <-- %C\n"),
79 this->response_[n].c_str ()));
81 if (multi_line)
83 while (ch != eof_)
85 int nxt_stat = 0;
87 n = this->response_.size ();
88 this->response_.size (n+1);
89 this->response_[n].clear ();
90 ACE::IOS::CString_OStream nxt_sos (this->response_[n]);
92 if (ACE_OS::ace_isdigit (str.peek ()))
94 str >> nxt_stat;
95 ch = str.get ();
96 if (str.bad () || (nxt_stat == this->status_ && ch != ' '))
98 this->status_ = NORESPONSE;
99 return false;
101 nxt_sos << nxt_stat;
102 nxt_sos.put(ch);
104 ch = this->read_line (str, nxt_sos);
106 nxt_sos.close ();
108 INET_DEBUG (9, (LM_DEBUG, DLINFO
109 ACE_TEXT ("ACE_INet_FTP: <-+ %C\n"),
110 this->response_[n].c_str ()));
112 if (nxt_stat == this->status_)
114 return true;
118 this->status_ = NORESPONSE;
119 return false;
121 else
123 return true;
129 ACE_END_VERSIONED_NAMESPACE_DECL