Mixe for Privacy and Anonymity in the Internet
CAAbstractControlChannel.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 
29 #ifndef __CAABSTRACTCONTROLCHANNEL__
30 #define __CAABSTRACTCONTROLCHANNEL__
31 
32 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
34 #include "xml/DOM_Output.hpp"
35 
36 
42 {
43  public:
44  CAAbstractControlChannel(UINT8 id, bool bIsEncrypted)
45  {
46  m_bIsEncrypted=bIsEncrypted;
47  m_ID=id;
48  m_pDispatcher=NULL;
49  }
50 
52  {
53  }
54 
62  SINT32 sendXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument* pDocMsg) const
63  {
64  UINT32 tlen=0xFFFF;
65  UINT8* tmpB=new UINT8[tlen];
66  if(DOM_Output::dumpToMem(pDocMsg,tmpB,&tlen)!=E_SUCCESS || tlen>0xFFFF)
67  {
68  delete[]tmpB;
69  return E_SPACE;
70  }
71  SINT32 ret=sendXMLMessage(tmpB,tlen);
72  delete[] tmpB;
73  return ret;
74  }
75 
84  SINT32 sendXMLMessage(const UINT8* msgXML,UINT32 msgLen) const
85  {
86  //CAMsg::printMsg(LOG_DEBUG,"Will send xml msg over control channel\n");
87  if(msgLen>0xFFFF)
88  {
89  return E_SPACE;
90  }
91  UINT32 tmpBLen=msgLen+2+16; //2for msg len and 16 for auth tag
92  UINT8* tmpB=new UINT8[tmpBLen];
93  if(m_bIsEncrypted)
94  {
95  m_pDispatcher->encryptMessage(msgXML,msgLen,tmpB+2,&tmpBLen);
96  }
97  else
98  {
99  memcpy(tmpB+2,msgXML,msgLen);
100  tmpBLen=msgLen;
101  }
102  tmpB[0]=(UINT8)(msgLen>>8);
103  tmpB[1]=(UINT8)(msgLen&0xFF);
104  SINT32 ret=m_pDispatcher->sendMessages(m_ID,tmpB,tmpBLen+2);
105  delete[] tmpB;
106  return ret;
107  }
108 
112  UINT32 getID() const
113  {
114  return m_ID;
115  }
116 
117 // bool isEncrypted();
118 
119  protected:
123  virtual SINT32 proccessMessage(const UINT8* msg, UINT32 msglen)=0;
124 
128 
131  {
132  m_pDispatcher=pDispatcher;
133  return E_SUCCESS;
134  }
135 
140 };
141 
142 #endif
143 
144 #endif //ONLY_LOCAL_PROXY
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
The base of each control channel.
virtual SINT32 proccessMessageComplete()=0
Called if a whole messages was received, which should be delivered to the final recipient.
SINT32 sendXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument *pDocMsg) const
Call to send a XML message via this control channel.
CAControlChannelDispatcher * m_pDispatcher
virtual SINT32 proccessMessage(const UINT8 *msg, UINT32 msglen)=0
Processes some bytes of a message we got from the communication channel.
CAAbstractControlChannel(UINT8 id, bool bIsEncrypted)
UINT32 getID() const
Returns the id of this control channel.
SINT32 setDispatcher(CAControlChannelDispatcher *pDispatcher)
Sets the Dispatcher.
SINT32 sendXMLMessage(const UINT8 *msgXML, UINT32 msgLen) const
Call to send a XML message via this control channel.
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control ...
SINT32 sendMessages(UINT32 id, const UINT8 *msg, UINT32 msglen)
SINT32 encryptMessage(const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *outlen)
Encrypts a control channel message.
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_SPACE
Definition: errorcodes.hpp:7