00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file replyline.cpp 00024 * \version $Id: replyline.cpp 1238 2006-09-25 17:50:57Z edmanm $ 00025 * \brief Reply from a previous control command sent to Tor 00026 */ 00027 00028 #include "replyline.h" 00029 00030 /** Default constructor */ 00031 ReplyLine::ReplyLine() 00032 { 00033 } 00034 00035 /** Constructor */ 00036 ReplyLine::ReplyLine(QString status, QString msg) 00037 { 00038 _status = status; 00039 setMessage(msg); 00040 } 00041 00042 /** Constructor */ 00043 ReplyLine::ReplyLine(QString status, QString msg, QString data) 00044 { 00045 _status = status; 00046 setMessage(msg); 00047 appendData(data); 00048 } 00049 00050 /** Set the status code for this reply line. See Tor Control Protocol V1 00051 * specification for a description of status codes. */ 00052 void 00053 ReplyLine::setStatus(QString status) 00054 { 00055 _status = status; 00056 } 00057 00058 /** Get the status code for this reply line. */ 00059 QString 00060 ReplyLine::getStatus() 00061 { 00062 return _status; 00063 } 00064 00065 /** Set the message for this reply line */ 00066 void 00067 ReplyLine::setMessage(QString msg) 00068 { 00069 _message = unescape(msg); 00070 } 00071 00072 /** Get the message for this reply line */ 00073 QString 00074 ReplyLine::getMessage() 00075 { 00076 return _message; 00077 } 00078 00079 /** Add some data to this line */ 00080 void 00081 ReplyLine::appendData(QString data) 00082 { 00083 _data << unescape(data); 00084 } 00085 00086 /** Returns a QStringList of all data lines for this reply line */ 00087 QStringList 00088 ReplyLine::getData() 00089 { 00090 return _data; 00091 } 00092 00093 /** Unescapes characters in the given string */ 00094 QString 00095 ReplyLine::unescape(QString str) 00096 { 00097 /* If the line starts with a "." and was escaped, then unescape it */ 00098 if (str.startsWith("..")) { 00099 str.remove(0, 1); 00100 } 00101 00102 /* Trim off trailing whitespace (including \r\n) */ 00103 return str.trimmed(); 00104 } 00105