📄 reply.h
字号:
// reply.h// Reply class, holds FTP replies// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt#ifndef __REPLY_H#define __REPLY_H#include "str.h" // string#include "exc.h" // xBase#ifndef SAFETPC#include "socketd.h" // SOCKETclass StreamLineReader; // see lineread.h#endif// first digit of reply codesenum ReplyCodeFirst { RCF_POSITIVE_PRELIMINARY=100, RCF_POSITIVE_COMPLETION=200, RCF_POSITIVE_INTERMEDIATE=300, RCF_NEGATIVE_TRANSIENT=400, RCF_NEGATIVE_PERMANENT=500, RCF_ENCRYPTED=600};bool valid(ReplyCodeFirst f);// second digit of reply codesenum ReplyCodeSecond { RCS_SYNTAX=0, RCS_INFORMATION=10, RCS_CONNECTION=20, RCS_AUTHENTICATION=30, RCS_UNSPECIFIED=40, RCS_FILE_SYSTEM=50};bool valid(ReplyCodeSecond s);// third digit of reply codes (no orthogonal semantics)enum ReplyCodeThird { RCT_0, RCT_1, RCT_2, RCT_3, RCT_4, RCT_5, RCT_6, RCT_7, RCT_8, RCT_9,};bool valid(ReplyCodeThird t);// complete codes as defined by 959 and 2228enum ReplyCode { // code ranges RC_MINIMUM = 100, RC_MAXIMUM = 659, // 959 codes RC_RESTART_MARKER_REPLY=110, RC_SERVICE_READY_SOON=120, RC_DATA_CONN_ALREADY_OPEN=125, RC_FILE_STATUS_OK=150, RC_COMMAND_OK=200, RC_COMMAND_SUPERFLUOUS=202, RC_SYSTEM_STATUS=211, RC_DIRECTORY_STATUS=212, RC_FILE_STATUS=213, RC_HELP_MESSAGE=214, RC_NAME_SYSTEM_TYPE=215, RC_SERVICE_READY=220, RC_SERVICE_CLOSING=221, RC_DATA_CONN_OPEN=225, RC_CONN_ACTION_SUCCESSFUL=226, RC_ENTERING_PASSIVE=227, RC_USER_LOGGED_IN=230, RC_FILE_ACTION_SUCCESSFUL=250, RC_PATHNAME_CREATED=257, RC_NEED_PASSWORD=331, RC_NEED_ACCOUNT=332, RC_FILE_ACTION_NEED_INFO=350, RC_SERVICE_NOT_AVAILABLE=421, RC_FAILED_DATA_CONN_OPEN=425, RC_TRANSFER_ABORTED=426, RC_FILE_TEMPORARILY_UNAVAILABLE=450, RC_FILE_ACTION_ERROR=451, RC_FILE_ACTION_INSUFFICIENT_STORAGE=452, RC_UNRECOGNIZED_COMMAND=500, RC_PARAMETER_SYNTAX_ERROR=501, RC_COMMAND_NOT_IMPLEMENTED=502, RC_BAD_COMMAND_SEQUENCE=503, RC_PARAMETER_NOT_IMPLEMENTED=504, RC_NOT_LOGGED_IN=530, RC_FILE_NEED_ACCOUNT=532, RC_FILE_UNAVAILABLE=550, RC_FILE_PAGE_TYPE_UNKNOWN=551, RC_FILE_ACTION_QUOTA_EXCEEDED=552, RC_FILE_NAME_NOT_ALLOWED=553, // 2228 replies RC_AUTHORIZED_USER_LOGGED_IN=232, RC_SECURITY_DATA_EXCHANGE_COMPLETE=234, RC_LAST_ADAT=235, RC_FIRST_ADAT=334, RC_MIDDLE_ADAT=335, RC_PASSWORD_CHALLENGE=336, RC_SECURITY_RESOURCE_UNAVAILABLE=431, RC_PROTECTION_LEVEL_DENIED=533, RC_REQUEST_DENIED=534, RC_FAILED_SECURITY_CHECK=535, RC_UNSUPPORTED_PROT_LEVEL=536, RC_UNSUPPORTED_COMMAND_PROTECTION=537, RC_INTEGRITY=631, RC_PRIVATE_INTEGRITY=632, RC_PRIVATE=633, // reply codes that we added, as documented in our internet draft RC_PBSZ_TOO_SMALL=538, // replies I added RC_INTERNAL_ERROR=510, // ideally, we'll never send this.. if we do, // it is technically a violation of 959 // last one, so line doesn't end with a comma __last_one_dont_use};bool valid(ReplyCode c);// simple reply code extraction and composition,// guaranteed to only return valid values (exception otherwise)ReplyCodeFirst first(ReplyCode code);ReplyCodeSecond second(ReplyCode code);ReplyCodeThird third(ReplyCode code);// checks for valid argument ranges (exception otherwise)ReplyCode makeCode(ReplyCodeFirst f, ReplyCodeSecond s, ReplyCodeThird t);// returns true when s begins with a three-digit// reply code, and either legal separatorbool replyCodeStart(char const *s);// holds a complete (possibly multiline) reply from serverclass Reply {private: // types typedef string (*LineGetter)(void *&arg);public: // types // constants enum { ADATTagLen = 5 // length of "ADAT=" };private: // data // lines of text string **text; // array of string pointers int numLines; // # lines defined int arraySize; // allocated size of array ReplyCode code; // the (3-digit) reply code // note that this code is not necessarily among those defined above // TODO: Add something to store the complete reply as it came over the // wire, for correct DIGT calculation with non-canonical replies. private: // funcs static string socketLineGetter(void *&arg); static string bufferLineGetter(void *&arg);#ifndef SAFETPC static string streamLineGetter(void *&arg);#endif void parse(LineGetter getter, void *&arg); void init(); string **alloc(int size);public: // funcs // copy ctor Reply(Reply const &obj); // ----- composing ctors ------- // construct a one-line reply Reply(ReplyCode replyCode, char const *firstLine); // ----- parsing ctors ------ // read and parse next reply Reply(SOCKET s); // parse from in-memory buffer; this is actually fairly complicated, // see the comments near the code Reply(char const *&text); // parse from arbitrary stream source#ifndef SAFETPC Reply(StreamLineReader &reader);#endif // free mem ~Reply(); // append a line of text void append(char const *s); // send reply to a socket void send(SOCKET s) const; // get the reply code; note that ReplyCode only defines symbolic // constants for a subset of all possible 3-letter replies ReplyCode getCode() const { return code; } // get the entire reply as CRLF-separated lines, terminated by CRLF, // and with each line starting with the reply code string getAllText() const; // retrieve individual lines int getNumLines() const { return numLines; } string getNthLine(int n) const; // 0-based index // retrieve last line of text (no CRLF at end) string getLastText() const; // get the entire reply text as a single line, with no reply codes // or newlines anywhere in the string string getAllTextAsOneLine() const; // convenient test: true if the reply contains authentication data bool containsADAT() const;};// exception class to signal a negative replyclass xReply : public xBase {public: ReplyCode code; // numeric code string text; // server's text (does *not* include the code)public: xReply(ReplyCode code, char const *text); xReply(Reply const &reply); xReply(xReply const &obj); ~xReply();};#endif // __REPLY_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -