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"
10 #include "ace/INet/INet_Log.h"
11 #include "ace/INet/String_IOStream.h"
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 const int Response::eof_
= std::char_traits
<char>::eof ();
23 : status_ (NORESPONSE
)
31 void Response::write(ostream
& str
) const
33 ACE_Array
<ACE_CString
>::size_type n
= 0;
35 if (this->response_
.size () > 0)
37 n
= this->response_
.size () - 1;
38 str
<< (n
> 0 ? '-' : ' ') << this->response_
[0].c_str ();
41 for (ACE_Array
<ACE_CString
>::size_type i
= 1;
45 str
<< this->response_
[i
].c_str () << "\r\n";
49 str
<< this->status_
<< ' '
50 << this->response_
[n
].c_str () << "\r\n";
54 bool Response::read(istream
& str
)
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
]);
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 ()));
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 ()))
96 if (str
.bad () || (nxt_stat
== this->status_
&& ch
!= ' '))
98 this->status_
= NORESPONSE
;
104 ch
= this->read_line (str
, nxt_sos
);
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_
)
118 this->status_
= NORESPONSE
;
129 ACE_END_VERSIONED_NAMESPACE_DECL