|
reSIProcate/repro
9694
|
00001 00002 #if defined(HAVE_CONFIG_H) 00003 #include "config.h" 00004 #endif 00005 00006 #include <signal.h> 00007 #include "repro/ReproRunner.hxx" 00008 #include "rutil/Socket.hxx" 00009 00010 #include "rutil/WinLeakCheck.hxx" 00011 00012 using namespace repro; 00013 using namespace resip; 00014 using namespace std; 00015 00016 static bool finished = false; 00017 00018 static void 00019 signalHandler(int signo) 00020 { 00021 std::cerr << "Shutting down" << endl; 00022 finished = true; 00023 } 00024 00025 /* 00026 Extending Repro by adding custom processors to the chain is as easy as overriding the 00027 ReproRunner class virtual methods makeRequestProcessorChain, makeResponseProcessorChain 00028 and/or makeTargetProcessorChain and adding your Processor to the chain. Create 00029 an instance of your overridden ReproRunner class and call run to start everything 00030 up. 00031 00032 Example: 00033 00034 class MyCustomProcessor : public Processor 00035 { 00036 public: 00037 MyCustomProcessor(ProxyConfig& config) : Processor("MyCustomProcessor") {} 00038 virtual ~MyCustomProcessor() {} 00039 00040 virtual processor_action_t process(RequestContext &context) 00041 { 00042 DebugLog(<< "Monkey handling request: " << *this << "; reqcontext = " << context); 00043 00044 ...Do something interesting here.... 00045 00046 return Processor::Continue; 00047 } 00048 } 00049 }; 00050 00051 class MyReproRunner : public ReproRunner 00052 { 00053 public: 00054 MyReproRunner() {} 00055 virtual ~MyReproRunner() {} 00056 00057 protected: 00058 virtual void makeRequestProcessorChain(repro::ProcessorChain& chain) 00059 { 00060 ReproRunner::makeRequestProcessorChain(chain); 00061 chain.addProcessor(std::auto_ptr<Processor>(new MyCustomProcessor(*mProxyConfig))); 00062 } 00063 }; 00064 00065 There is also generic storage available for custom Processor at three different 00066 scope levels via a KeyValueStore: 00067 -Global Proxy Scope - Proxy::getKeyValueStore 00068 -Request Scope - RequestContext::getKeyValueStore 00069 -Target Scope - Target::getKeyValueStore 00070 Before this storage can be used you must statically allocate a storage key. 00071 See mFromTrustedNodeKey use in the IsTrustedNode class for an example. 00072 00073 */ 00074 00075 int 00076 main(int argc, char** argv) 00077 { 00078 // Install signal handlers 00079 #ifndef _WIN32 00080 if ( signal( SIGPIPE, SIG_IGN) == SIG_ERR) 00081 { 00082 cerr << "Couldn't install signal handler for SIGPIPE" << endl; 00083 exit(-1); 00084 } 00085 #endif 00086 00087 if ( signal( SIGINT, signalHandler ) == SIG_ERR ) 00088 { 00089 cerr << "Couldn't install signal handler for SIGINT" << endl; 00090 exit( -1 ); 00091 } 00092 00093 if ( signal( SIGTERM, signalHandler ) == SIG_ERR ) 00094 { 00095 cerr << "Couldn't install signal handler for SIGTERM" << endl; 00096 exit( -1 ); 00097 } 00098 00099 // Initialize network 00100 initNetwork(); 00101 00102 #if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 00103 { FindMemoryLeaks fml; 00104 #endif 00105 00106 ReproRunner repro; 00107 if(!repro.run(argc, argv)) 00108 { 00109 cerr << "Failed to start repro, exiting..." << endl; 00110 exit(-1); 00111 } 00112 00113 // Main program thread, just waits here for a signal to shutdown 00114 while (!finished) 00115 { 00116 #ifdef WIN32 00117 Sleep(1000); 00118 #else 00119 usleep(100000); 00120 #endif 00121 } 00122 00123 repro.shutdown(); 00124 00125 #if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 00126 } 00127 #endif 00128 return 0; 00129 } 00130 00131 00132 /* ==================================================================== 00133 * The Vovida Software License, Version 1.0 00134 * 00135 * Copyright (c) 2000-2005 00136 * 00137 * Redistribution and use in source and binary forms, with or without 00138 * modification, are permitted provided that the following conditions 00139 * are met: 00140 * 00141 * 1. Redistributions of source code must retain the above copyright 00142 * notice, this list of conditions and the following disclaimer. 00143 * 00144 * 2. Redistributions in binary form must reproduce the above copyright 00145 * notice, this list of conditions and the following disclaimer in 00146 * the documentation and/or other materials provided with the 00147 * distribution. 00148 * 00149 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00150 * and "Vovida Open Communication Application Library (VOCAL)" must 00151 * not be used to endorse or promote products derived from this 00152 * software without prior written permission. For written 00153 * permission, please contact vocal@vovida.org. 00154 * 00155 * 4. Products derived from this software may not be called "VOCAL", nor 00156 * may "VOCAL" appear in their name, without prior written 00157 * permission of Vovida Networks, Inc. 00158 * 00159 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00160 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00161 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00162 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00163 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00164 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00165 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00166 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00167 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00168 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00169 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00170 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00171 * DAMAGE. 00172 * 00173 * ==================================================================== 00174 * 00175 * This software consists of voluntary contributions made by Vovida 00176 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00177 * Inc. For more information on Vovida Networks, Inc., please see 00178 * <http://www.vovida.org/>. 00179 * 00180 */ 00181 /* 00182 * vi: set shiftwidth=3 expandtab: 00183 */
1.7.5.1