Vidalia 0.2.10
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If 00004 ** you did not receive the LICENSE file with this file, you may obtain it 00005 ** from the Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to 00008 ** the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file ReplyLine.cpp 00013 ** \version $Id: ReplyLine.cpp 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Reply from a previous control command sent to Tor 00015 */ 00016 00017 #include "ReplyLine.h" 00018 00019 00020 /** Default constructor */ 00021 ReplyLine::ReplyLine() 00022 { 00023 } 00024 00025 /** Constructor */ 00026 ReplyLine::ReplyLine(const QString &status, const QString &msg) 00027 { 00028 _status = status; 00029 setMessage(msg); 00030 } 00031 00032 /** Constructor */ 00033 ReplyLine::ReplyLine(const QString &status, const QString &msg, 00034 const QString &data) 00035 { 00036 _status = status; 00037 setMessage(msg); 00038 appendData(data); 00039 } 00040 00041 /** Set the status code for this reply line. See Tor Control Protocol V1 00042 * specification for a description of status codes. */ 00043 void 00044 ReplyLine::setStatus(const QString &status) 00045 { 00046 _status = status; 00047 } 00048 00049 /** Returns the status code for this reply line. */ 00050 QString 00051 ReplyLine::getStatus() const 00052 { 00053 return _status; 00054 } 00055 00056 /** Sets the ReplyText message this reply line to <b>msg</b>. */ 00057 void 00058 ReplyLine::setMessage(const QString &msg) 00059 { 00060 _message = unescape(msg); 00061 } 00062 00063 /** Returns the ReplyText portion of this reply line. */ 00064 QString 00065 ReplyLine::getMessage() const 00066 { 00067 return _message; 00068 } 00069 00070 /** Appends <b>data</b> to this reply line. */ 00071 void 00072 ReplyLine::appendData(const QString &data) 00073 { 00074 _data << unescape(data); 00075 } 00076 00077 /** Returns a QStringList of all data lines for this reply line */ 00078 QStringList 00079 ReplyLine::getData() const 00080 { 00081 return _data; 00082 } 00083 00084 /** Unescapes special characters in <b>str</b> and returns the unescaped 00085 * result. */ 00086 QString 00087 ReplyLine::unescape(const QString &escaped) 00088 { 00089 QString str = escaped; 00090 /* If the line starts with a "." and was escaped, then unescape it */ 00091 if (str.startsWith("..")) { 00092 str.remove(0, 1); 00093 } 00094 00095 /* Trim off trailing whitespace (including \r\n) */ 00096 return str.trimmed(); 00097 } 00098 00099 QString 00100 ReplyLine::toString() const 00101 { 00102 QString str = _status + " " + _message; 00103 if (!_data.isEmpty()) { 00104 str.append("\n"); 00105 str.append(_data.join("\n")); 00106 } 00107 return str; 00108 } 00109