|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 00029 #ifndef _CASYNCCONTROLCHANNEL_ 00030 #define _CASYNCCONTROLCHANNEL_ 00031 #ifndef ONLY_LOCAL_PROXY 00032 #include "CAAbstractControlChannel.hpp" 00033 00036 class CASyncControlChannel : public CAAbstractControlChannel 00037 { 00038 public: 00043 CASyncControlChannel(UINT8 id, bool bIsEncrypted): 00044 CAAbstractControlChannel(id,bIsEncrypted) 00045 { 00046 m_MsgBuff=new UINT8[0xFFFF+32]; 00047 m_aktIndex=0; 00048 m_MsgBytesLeft=0; 00049 } 00050 virtual ~CASyncControlChannel(); 00056 virtual SINT32 processXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument* docMsg)=0; 00057 00058 protected: 00059 SINT32 proccessMessage(const UINT8* msg, UINT32 msglen) 00060 { 00061 #ifdef DEBUG 00062 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessage - msglen=%u\n",msglen); 00063 #endif 00064 if(m_MsgBytesLeft==0)//start of new XML Msg 00065 { 00066 if(msglen<2)//this should never happen... 00067 return E_UNKNOWN; 00068 m_MsgBytesLeft=(msg[0]<<8)|msg[1]; 00069 if(m_bIsEncrypted && m_pDispatcher->isKeySet()) // note: the second check is just a workaround for the time the encryption is not support by all JAPs/Mixes 00070 { 00071 m_MsgBytesLeft+=16;//auth tag 00072 } 00073 #ifdef DEBUG 00074 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessage - start of a new msg of len=%u\n",m_MsgBytesLeft); 00075 #endif 00076 msglen-=2; 00077 m_aktIndex=msglen; 00078 m_MsgBytesLeft-=msglen; 00079 memcpy(m_MsgBuff,msg+2,msglen); 00080 } 00081 else//received some part... 00082 { 00083 msglen=min(m_MsgBytesLeft,msglen); 00084 memcpy(m_MsgBuff+m_aktIndex,msg,msglen); 00085 m_aktIndex+=msglen; 00086 m_MsgBytesLeft-=msglen; 00087 } 00088 if(m_MsgBytesLeft==0) 00089 {//whole msg receveid 00090 if(m_bIsEncrypted) 00091 { 00092 UINT8* buff=new UINT8[m_aktIndex]; 00093 memcpy(buff,m_MsgBuff,m_aktIndex); 00094 m_pDispatcher->decryptMessage(buff,m_aktIndex,m_MsgBuff,&m_aktIndex); 00095 delete[]buff; 00096 } 00097 return proccessMessageComplete(); 00098 } 00099 return E_SUCCESS; 00100 } 00101 00103 SINT32 proccessMessageComplete() 00104 { 00105 #ifdef DEBUG 00106 if(m_aktIndex<0xFFFF) 00107 { 00108 m_MsgBuff[m_aktIndex]=0; 00109 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() - msg=%s\n",m_MsgBuff); 00110 } 00111 else 00112 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() \n"); 00113 #endif 00114 00115 XERCES_CPP_NAMESPACE::DOMDocument* doc=parseDOMDocument(m_MsgBuff,m_aktIndex); 00116 m_aktIndex=0; 00117 m_MsgBytesLeft=0; 00118 if(doc==NULL) 00119 { 00120 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel:: received XML document could not be parsed\n"); 00121 return E_UNKNOWN; 00122 } 00123 #ifdef DEBUG 00124 CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() call processXMLMessage()\n"); 00125 #endif 00126 SINT32 ret=processXMLMessage(doc); 00127 if (doc != NULL) 00128 { 00129 doc->release(); 00130 doc = NULL; 00131 } 00132 return ret; 00133 } 00134 00136 UINT8* m_MsgBuff; 00138 UINT32 m_aktIndex; 00140 UINT32 m_MsgBytesLeft; 00141 }; 00142 #endif 00143 #endif //ONLY_LOCAL_PROXY
1.7.6.1