LLProxy - HTTP Proxy Service written in C++
I eventually found the Proxy server by Sam King on the University of Illinois/NCSA web-site which had support for tunneling. I ported the code to Windows and tried to leave support for Unix. I did various code clean-up, such as porting C to C++ and removing #defines and using smart pointers to mamange memory.
After I got the basic proxy working I added a shared memory portal so an external agent could monitor the proxy traffic. Next I added a front end to allow the proxy to run as a windows service. Lastly, I created a simple Windows Monitor UI to display the shared memory portal information.
http://www.cs.uiuc.edu/homes/kingst/Research.html
The POSIX Threads Library for Win32 is provided by:
Contact Email: rpj@callisto.canberra.edu.au
The current list of contributors is contained
in the file CONTRIBUTORS included with the source
code distribution. The list can also be seen at the
following World Wide Web location:
http://sources.redhat.com/pthreads-win32/contributors.html
** (See full copyright notice in the pthread files).
Next you want to enable the Proxy server. From Chrome go to Settings by first clicking on the top right icon.
If you don't use Chrome click Control Panel to see alternate approach.
An alternate approach is to use the Window's Control Panel and select the Internet Options and LAN settings to get to the same place.
Licensing and Copyright Information
The body of the proxy server is from code found on:
Developed by the University of Illinois/NCSA in
the Research Group of Professor Sam King in the Department of Computer
Science The University of Illinois at Urbana-Champaign
** (See full copyright notice in proxy files).
Copyright(C) 1998 John E. Bossom
Copyright(C) 1999,2005 Pthreads-win32 contributors
Install
To Install the Proxy server you can either run it via the command line, which is ideal for testing, or as a window service.
Use -? to see the help banner (see image below).
Enable the Proxy server by checking the toggle box and click on Advance to set the ports.
|
The LLProxy server uses port 8000, set both HTTP and Secure to use this port.
|
To disable the proxy, just uncheck the proxy box, you don't have to clear or erase the port configuration.
LLProxyMon uses a shared memory region and an event handler to handle the communication of the HTTP url traffic across the shared memory.
This logic is similar to how the OutputDebugString message is handled.
The shared memory has a small header of 4 unsigned integers
As the Proxy Services posts messages it copies it into the shared memory at the postOff position.
Once the copy has completed the postOff value is moved to the end of the new message and the postSeq
is incremented and the event handler is set.
Running LLProxyMon to Monitor proxy traffic
LLProxyMon is a simple C# windows program to display the HTTP URL traffic.
Currently there is very little error handling and if you start it before starting the Proxy server it will fail to connect and will not retry.
public static void MonitorThread()
{
const string sLLProxyMemName = "Global\\llproxy";
const int sMemSize = 8192;
SharedMemory m_sharedMemory;
IntPtr m_MsgEvent = IntPtr.Zero;
try
{
m_sharedMemory = new SharedMemory(sLLProxyMemName, sMemSize);
}
catch (Exception ex)
{
SetStatus(MonitorStatus.eExit, ex.Message);
return;
}
// Create the event for slot 'DBWIN_BUFFER_READY'
const string sEventName1 = "llproxyEvent1";
WinEvent.SECURITY_ATTRIBUTES sa = new WinEvent.SECURITY_ATTRIBUTES();
m_MsgEvent = WinEvent.CreateEvent(ref sa, false, false, sEventName1);
if (m_MsgEvent == IntPtr.Zero)
{
SetStatus(MonitorStatus.eExit, "Failed to create event 'llproxyEvent1'");
return;
}
The memSize is initialized with the size of the shared memory region and the hdrSize with the size of the MemHeader structure.
struct MemHeader
{
uint memSize;
uint hdrSize;
uint postOff; // end of current message.
uint postSeq;
};
As the messages fill the shared memory region, they wrap around and over write previous messages.
The share memory is not locked by any critical sections or mutexes and has no performance impact on the Proxy Server.
If the Monitor program is running too slowly or does not use a separate thread to monitor the shared memory it
could get behind and produce garbled messages. The sequence number is one way for the monitor to detect that
it lost a message by comparing its sequence number with that in the shared memory.
bool ShareMsg::PostMsg(uint threadId, const std::string& host, const HTTP& http, int respondsLen)
{
bool status = false;
// WinSharedMem m_sharedMem;
std::ostringstream sout;
const char sSep[] = "|";
sout << GetTimeString() << sSep << threadId << sSep << host << sSep << http.GetUrl() << sSep << respondsLen << "\n";
std::string msg = sout.str();
uint msgLen = msg.length();
if (msgLen < sMemMsgSize)
{
status = true;
uint cpyLen = min(sMemMsgSize - m_memHdrPtr->postOff, msgLen);
memcpy(m_memPtr + m_memHdrPtr->postOff, msg.c_str(), cpyLen);
m_memHdrPtr->postOff = (m_memHdrPtr->postOff + cpyLen) % sMemMsgSize;
msgLen -= cpyLen;
if (msgLen != 0)
{
memcpy(m_memPtr + m_memHdrPtr->postOff, msg.c_str() + cpyLen, msgLen);
m_memHdrPtr->postOff += msgLen;
}
m_memHdrPtr->postSeq++;
SetEvent(m_eventHnd);
}
return status;
}
There are also some new features we are currently working on: Check the API reference manual for information about how does Fhscan HTTP API works.
Web Links to other HTTP Proxy examples
C/C++ Proxy Servers
Cross-Platform and small C++ HTTP api. This library currently supports:
The C++ TCP Proxy server is a simple and high performance utility using the
ASIO
networking library, for proxying (tunneling or redirecting) connections from external clients to a
designated server. The TCP Proxy server can be used to easily and efficiently:
This is a very basic HTTP proxy. Currently it will create a new
thread for each new client connection and use blocking I/O calls to
get the request from the browser and then get a reply from the server.
Non-C++ Proxy servers
Features
Code: Written in Pascal
Date: 3/17/2004 Commerical Proxy Servers