root/honeyclient/branches/rel/1.0/Capture2/capture-client-xeno-mod/EventController.h

Revision 823, 3.3 kB (checked in by xkovah, 1 year ago)

adding the files finally

Line 
1 /*
2  *  PROJECT: Capture
3  *  FILE: EventController.h
4  *  AUTHORS: Ramon Steenson (rsteenson@gmail.com) & Christian Seifert (christian.seifert@gmail.com)
5  *
6  *  Developed by Victoria University of Wellington and the New Zealand Honeynet Alliance
7  *
8  *  This file is part of Capture.
9  *
10  *  Capture is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  Capture is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with Capture; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  */
24 #pragma once
25 //#include "CaptureGlobal.h"
26 #include <boost/signal.hpp>
27 #include <boost/bind.hpp>
28 #include <vector>
29 #include <expatpplib.h>
30 #include <hash_map>
31
32 using namespace std;
33
34 typedef struct _ATTRIBUTE
35 {
36     wstring name;
37     wstring value;
38 } Attribute, * pAttribute;
39
40 typedef struct _ELEMENT
41 {
42     wstring name;
43     vector<Attribute> attributes;
44     char * data;
45     size_t dataLength;
46 } Element, * pElement;
47
48 /*
49     Class: EventController
50
51     The EventController is responsible for passing events to various objects in the
52     client. It is a singleton and extends the expatpp SAX parser which allows the
53     controller to parse XML documents. Objects listen for a particular event by
54     calling connect_onServerEvent with a particular event type and a binding to
55     a method on that object. This uses the boost signal slot functionality. Events can
56     be sent to the controller in various ways. At the moment it is used to signal
57     events from the server. For example when an Visit XML document is sent from the server
58     the <Server> will receive it, and pass it to receiveServerEvent which will parse it
59     to various XML Elements and based on the element name pass it to the various
60     listeners.
61
62     This is very similar to an event pump which received all external events and passes
63     them to all of the internal objects. This can be extended very easy and was designed
64     for the intention of creating a command line interface which could easily communicate
65     with the internal object without knowing anything about them.
66 */
67 class EventController : public expatpp
68 {
69    
70 public:
71     typedef boost::signal<void (Element*)> signal_serverEvent;
72     typedef pair <wstring, signal_serverEvent*> OnServerEventPair;
73 public:
74     ~EventController(void);
75     static EventController* getInstance();
76
77     boost::signals::connection connect_onServerEvent(wstring eventType, const signal_serverEvent::slot_type& s);
78
79     void receiveServerEvent(const char* xmlDocument);
80 private:
81     static bool instanceCreated;
82     static EventController *pEventController;
83     EventController(void);
84
85     void notifyListeners();
86
87     stdext::hash_map<wstring, signal_serverEvent*> onServerEventMap;
88     Element* pCurrentElement;
89    
90 public:
91     virtual void startElement(const XML_Char *name, const XML_Char **atts);
92     virtual void endElement(const XML_Char* name);
93     virtual void charData(const XML_Char *s, int len);
94 };
Note: See TracBrowser for help on using the browser.