replyline.cpp

Go to the documentation of this file.
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 2362 2008-02-29 04:30:11Z edmanm $
00014 ** \brief Reply from a previous control command sent to Tor
00015 */
00016 
00017 #include "replyline.h"
00018 
00019 /** Default constructor */
00020 ReplyLine::ReplyLine()
00021 {
00022 }
00023 
00024 /** Constructor */
00025 ReplyLine::ReplyLine(const QString &status, const QString &msg)
00026 {
00027   _status = status;
00028   setMessage(msg);
00029 }
00030 
00031 /** Constructor */
00032 ReplyLine::ReplyLine(const QString &status, const QString &msg, 
00033                      const QString &data)
00034 {
00035   _status = status;
00036   setMessage(msg);
00037   appendData(data);
00038 }
00039 
00040 /** Set the status code for this reply line. See Tor Control Protocol V1
00041  * specification for a description of status codes. */
00042 void
00043 ReplyLine::setStatus(const QString &status)
00044 {
00045   _status = status;
00046 }
00047 
00048 /** Returns the status code for this reply line. */
00049 QString
00050 ReplyLine::getStatus() const
00051 {
00052   return _status;
00053 }
00054 
00055 /** Sets the ReplyText message this reply line to <b>msg</b>. */
00056 void
00057 ReplyLine::setMessage(const QString &msg)
00058 {
00059   _message = unescape(msg);
00060 }
00061 
00062 /** Returns the ReplyText portion of this reply line. */
00063 QString
00064 ReplyLine::getMessage() const
00065 {
00066   return _message;
00067 }
00068 
00069 /** Appends <b>data</b> to this reply line. */
00070 void
00071 ReplyLine::appendData(const QString &data)
00072 {
00073   _data << unescape(data);
00074 }
00075 
00076 /** Returns a QStringList of all data lines for this reply line */
00077 QStringList
00078 ReplyLine::getData() const
00079 {
00080   return _data;
00081 }
00082 
00083 /** Unescapes special characters in <b>str</b> and returns the unescaped
00084  * result. */
00085 QString
00086 ReplyLine::unescape(const QString &escaped)
00087 {
00088   QString str = escaped;
00089   /* If the line starts with a "." and was escaped, then unescape it */
00090   if (str.startsWith("..")) {
00091     str.remove(0, 1);
00092   }
00093 
00094   /* Trim off trailing whitespace (including \r\n) */
00095   return str.trimmed();
00096 }
00097 
00098 QString
00099 ReplyLine::toString() const
00100 {
00101   QString str = _status + " " + _message;
00102   if (!_data.isEmpty()) {
00103     str.append("\n");
00104     str.append(_data.join("\n"));
00105   }
00106   return str;
00107 }
00108 

Generated on Tue Jul 7 16:58:26 2009 for Vidalia by  doxygen 1.4.7