|
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 #include "StdAfx.h" 00029 #ifdef DYNAMIC_MIX 00030 #include "CAInfoServiceAware.hpp" 00031 #include "CASocket.hpp" 00032 #include "CASocketAddrINet.hpp" 00033 #include "CAHttpClient.hpp" 00034 #include "CACmdLnOptions.hpp" 00035 00047 SINT32 CAInfoServiceAware::sendInfoserviceRequest(CASocketAddrINet* a_addr, UINT8 *a_strRequest, DOM_Element *r_elemRoot, UINT8* a_postData, UINT32 a_postLen) 00048 { 00049 CASocket socket; 00050 CAHttpClient httpClient; 00051 UINT32 status, contentLength; 00052 UINT8 *content = NULL; 00053 SINT32 ret = E_UNKNOWN; 00054 DOM_Document doc; 00055 DOMParser oParser; 00056 MemBufInputSource *oInput = NULL; 00057 00058 if(socket.connect(*a_addr)!=E_SUCCESS) 00059 return E_UNKNOWN; 00060 00061 #ifdef DEBUG 00062 // CAMsg::printMsg(LOG_DEBUG, "CAInfoServiceAware::sendInfoserviceRequest - connected to InfoService\n"); 00063 #endif 00064 //Send request 00065 httpClient.setSocket(&socket); 00066 if( a_postData != NULL ) 00067 httpClient.sendPostRequest(a_strRequest, a_postData, a_postLen); 00068 else 00069 httpClient.sendGetRequest(a_strRequest); 00070 httpClient.parseHTTPHeader(&contentLength, &status); 00071 #ifdef DEBUG 00072 // CAMsg::printMsg(LOG_DEBUG, "CAInfoServiceAware::sendInfoserviceRequest - Request sent, HTTP status: %i, content length: %i\n", status, 00073 // contentLength); 00074 #endif 00075 if(status!=200|| contentLength>MAX_CONTENT_LENGTH) 00076 { 00077 return E_UNKNOWN; 00078 } 00079 content = new UINT8[contentLength]; 00080 00081 if(httpClient.getContent(content, &contentLength)!=E_SUCCESS) 00082 { 00083 delete []content; 00084 content = NULL; 00085 return E_UNKNOWN; 00086 } 00087 #ifdef DEBUG 00088 // CAMsg::printMsg(LOG_DEBUG, "CAInfoServiceAware::sendInfoserviceRequest - Answer was %s\n", (char*)content); 00089 #endif 00090 socket.close(); 00091 //Parse XML 00092 oInput = new MemBufInputSource( content, contentLength, "tmp" ); 00093 oParser.parse( *oInput ); 00094 delete[] content; 00095 content = NULL; 00096 delete oInput; 00097 oInput = NULL; 00098 doc = oParser.getDocument(); 00099 if(doc==NULL) 00100 return E_UNKNOWN; 00101 *r_elemRoot=doc.getDocumentElement(); 00102 return E_SUCCESS; 00103 } 00104 00115 SINT32 CAInfoServiceAware::sendInfoserviceGetRequest(CASocketAddrINet* a_addr, UINT8 *a_strRequest, DOM_Element *r_elemRoot) 00116 { 00117 return sendInfoserviceRequest(a_addr, a_strRequest, r_elemRoot, NULL, 0); 00118 } 00119 00129 SINT32 CAInfoServiceAware::sendRandomInfoserviceGetRequest(UINT8 *a_strRequest, DOM_Element *r_elemRoot) 00130 { 00131 return sendRandomInfoserviceRequest(a_strRequest, r_elemRoot, NULL, 0); 00132 } 00133 00145 SINT32 CAInfoServiceAware::sendRandomInfoserviceRequest(UINT8 *a_strRequest, DOM_Element *r_elemRoot, UINT8* a_postData, UINT32 a_postLen) 00146 { 00147 CASocketAddrINet *address; 00148 if( pglobalOptions->getRandomInfoService(address) != E_SUCCESS) 00149 { 00150 // CAMsg::printMsg( LOG_ERR, "CAInfoServiceAware::sendInfoserviceRequest - Unable to get a random InfoService - This will cause problems! Check your configuration!\n"); 00151 return E_UNKNOWN; 00152 } 00153 00154 return sendInfoserviceRequest(address, a_strRequest, r_elemRoot, a_postData, a_postLen); 00155 } 00156 00157 #endif // DYNAMIC_MIX
1.7.6.1