[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2159: Add support for registering for, parsing, and dispatching To (in trunk: . src/control)



Author: edmanm
Date: 2007-12-02 04:30:18 -0500 (Sun, 02 Dec 2007)
New Revision: 2159

Modified:
   trunk/
   trunk/src/control/eventtype.h
   trunk/src/control/torevents.cpp
   trunk/src/control/torevents.h
Log:
 r2197@lysithea:  edmanm | 2007-12-02 04:29:40 -0500
 Add support for registering for, parsing, and dispatching Tor status events.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /local/vidalia/trunk [r2197] on 0108964c-5b0b-4c9e-969f-e2288315d100

Modified: trunk/src/control/eventtype.h
===================================================================
--- trunk/src/control/eventtype.h	2007-12-02 09:30:10 UTC (rev 2158)
+++ trunk/src/control/eventtype.h	2007-12-02 09:30:18 UTC (rev 2159)
@@ -49,6 +49,12 @@
   const int SendCommandEvent   = QEvent::User+6;
   /** New address mapping event. */
   const int AddressMapEvent = QEvent::User+7;
+  /** Tor client status events. */
+  const int ClientStatusEvent = QEvent::User+8;
+  /** Tor server status events. */
+  const int ServerStatusEvent = QEvent::User+9;
+  /** General Tor status events. */
+  const int GeneralStatusEvent = QEvent::User+10;
 }
 
 #endif

Modified: trunk/src/control/torevents.cpp
===================================================================
--- trunk/src/control/torevents.cpp	2007-12-02 09:30:10 UTC (rev 2158)
+++ trunk/src/control/torevents.cpp	2007-12-02 09:30:18 UTC (rev 2159)
@@ -26,13 +26,18 @@
  */
 
 #include <QApplication>
-
+#include <stringutil.h>
 #include <vidalia.h>
 
 #include "circuit.h"
 #include "stream.h"
 #include "torevents.h"
+#include "unrecognizedserverstatusevent.h"
+#include "unrecognizedclientstatusevent.h"
+#include "unrecognizedgeneralstatusevent.h"
+#include "circuitestablishedevent.h"
 
+
 /** Format of expiry times in address map events. */
 #define DATE_FMT "\"yyyy-MM-dd HH:mm:ss\""
 
@@ -108,6 +113,9 @@
     case OrConnStatus:    event = "ORCONN"; break;
     case NewDescriptor:   event = "NEWDESC"; break;
     case AddressMap:      event = "ADDRMAP"; break;
+    case GeneralStatus:   event = "STATUS_GENERAL"; break;
+    case ClientStatus:    event = "STATUS_CLIENT"; break;
+    case ServerStatus:    event = "STATUS_SERVER"; break;
     default: event = "UNKNOWN"; break;
   }
   return event;
@@ -151,12 +159,18 @@
     e = LogWarn;
   } else if (event == "ERR") {
     e = LogError;
-  } else if (event == "ORCONN") {
-    e = OrConnStatus;
   } else if (event == "NEWDESC") {
     e = NewDescriptor;
   } else if (event == "ADDRMAP") {
     e = AddressMap;
+  } else if (event == "STATUS_GENERAL") {
+    e = GeneralStatus;
+  } else if (event == "STATUS_CLIENT") {
+    e = ClientStatus;
+  } else if (event == "STATUS_SERVER") {
+    e = ServerStatus;
+  } else if (event == "ORCONN") {
+    e = OrConnStatus;
   } else {
     e = Unknown;
   }
@@ -188,6 +202,13 @@
       case NewDescriptor:  handleNewDescriptor(line); break;
       case AddressMap:     handleAddressMap(line); break;
 
+      case GeneralStatus:
+        handleStatusEvent(GeneralStatus, line); break;
+      case ClientStatus:
+        handleStatusEvent(ClientStatus, line); break;
+      case ServerStatus:
+        handleStatusEvent(ServerStatus, line); break;
+
       case LogDebug: 
       case LogInfo:
       case LogNotice:
@@ -347,3 +368,90 @@
   }
 }
 
+/** Handles a Tor status event. The format for event messages of this type is:
+ *
+ *  "650" SP StatusType SP StatusSeverity SP StatusAction
+ *                                           [SP StatusArguments] CRLF
+ *
+ *  StatusType = "STATUS_GENERAL" / "STATUS_CLIENT" / "STATUS_SERVER"
+ *  StatusSeverity = "NOTICE" / "WARN" / "ERR"
+ *  StatusAction = 1*ALPHA
+ *  StatusArguments = StatusArgument *(SP StatusArgument)
+ *  StatusArgument = StatusKeyword '=' StatusValue
+ *  StatusKeyword = 1*(ALNUM / "_")
+ *  StatusValue = 1*(ALNUM / '_')  / QuotedString
+ */
+void
+TorEvents::handleStatusEvent(TorEvent type, ReplyLine line)
+{
+  QString status;
+  StatusEvent::Severity severity;
+  QHash<QString,QString> args;
+  QString msg = line.getMessage();
+  
+  severity = StatusEvent::severityFromString(msg.section(' ', 1, 1));
+  status   = msg.section(' ', 2, 2);
+  args     = string_parse_keyvals(msg.section(' ', 3));
+  switch (type) {
+    case ClientStatus:
+      dispatchClientStatusEvent(severity, status, args); break;
+    case ServerStatus:
+      dispatchServerStatusEvent(severity, status, args); break;
+    default:
+      dispatchGeneralStatusEvent(severity, status, args);
+  }
+}
+
+/** Parses and posts a Tor client status event. */
+void
+TorEvents::dispatchClientStatusEvent(StatusEvent::Severity severity,
+                                     const QString &action,
+                                     const QHash<QString,QString> &args)
+{
+  ClientStatusEvent *event;
+  ClientStatusEvent::Status status 
+    = ClientStatusEvent::statusFromString(action);
+
+  switch (status) {
+    case ClientStatusEvent::CircuitEstablished:
+      event = new CircuitEstablishedEvent(severity); break;
+    default:
+      event = new UnrecognizedClientStatusEvent(severity, action, args);
+  }
+  dispatch(ClientStatus, event);
+}
+
+/** Parses and posts a Tor server status event. */
+void
+TorEvents::dispatchServerStatusEvent(StatusEvent::Severity severity,
+                                     const QString &action,
+                                     const QHash<QString,QString> &args)
+{
+  ServerStatusEvent *event;
+  ServerStatusEvent::Status status
+    = ServerStatusEvent::statusFromString(action);
+
+  switch (status) {
+    default:
+      event = new UnrecognizedServerStatusEvent(severity, action, args);
+  }
+  dispatch(ServerStatus, event);
+}
+
+/** Parses and posts a general Tor status event. */
+void
+TorEvents::dispatchGeneralStatusEvent(StatusEvent::Severity severity,
+                                      const QString &action,
+                                      const QHash<QString,QString> &args)
+{
+  GeneralStatusEvent *event;
+  GeneralStatusEvent::Status status
+    = GeneralStatusEvent::statusFromString(action);
+
+  switch (status) {
+    default:
+      event = new UnrecognizedGeneralStatusEvent(severity, action, args);
+  }
+  dispatch(GeneralStatus, event);
+}
+

Modified: trunk/src/control/torevents.h
===================================================================
--- trunk/src/control/torevents.h	2007-12-02 09:30:10 UTC (rev 2158)
+++ trunk/src/control/torevents.h	2007-12-02 09:30:18 UTC (rev 2159)
@@ -40,6 +40,7 @@
 #include "orconnevent.h"
 #include "newdescriptorevent.h"
 #include "addressmapevent.h"
+#include "statusevent.h"
 #include "controlreply.h"
 
 
@@ -57,7 +58,10 @@
     StreamStatus,
     OrConnStatus,
     NewDescriptor,
-    AddressMap
+    AddressMap,
+    GeneralStatus,
+    ClientStatus,
+    ServerStatus
   };
  
   /** Default Constructor */
@@ -109,6 +113,22 @@
   void handleNewDescriptor(ReplyLine line);
   /** Handles a new or updated address map event. */
   void handleAddressMap(ReplyLine line);
+  /** Handles a Tor status event. */
+  void handleStatusEvent(TorEvent type, ReplyLine line);
+  
+  /** Parses and posts a Tor client status event. */
+  void dispatchClientStatusEvent(StatusEvent::Severity severity,
+                                 const QString &action,
+                                 const QHash<QString,QString> &args);
+  /** Parses and posts a Tor server status event. */
+  void dispatchServerStatusEvent(StatusEvent::Severity severity,
+                                 const QString &action,
+                                 const QHash<QString,QString> &args);
+  /** Parses and posts a general Tor status event. */
+  void dispatchGeneralStatusEvent(StatusEvent::Severity severity,
+                                  const QString &action,
+                                  const QHash<QString,QString> &args);
+
 };
 
 #endif