12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

164 POP3 PROXY SERVER CLASS DEFINITION ANNOYANCE-FILTER §194<br />

194. POP3 proxy server class definition.<br />

We begin by defining the POP3Proxy class, which implements a general purpose POP3 proxy<br />

capability.<br />

#define POP_MAX_MESSAGE 512<br />

#define POP_BUFFER ((POP_MAX_MESSAGE) + 2)<br />

〈 Class definitions 10 〉 +≡<br />

#ifdef POP3_PROXY_SERVER<br />

〈 Declare signal handler function for broken pipes 216 〉<br />

typedef void(∗POP3Proxy<strong>Filter</strong>Function )(const string command , const string<br />

argument , char ∗replyBuffer , int ∗replyLength , string &reply );<br />

class POP3Proxy {<br />

protected:<br />

unsigned short popProxyPort ; /∗ Port on which POP proxy server listens ∗/<br />

string serverName ; /∗ Domain name or IP address of POP server ∗/<br />

unsigned short serverPort ; /∗ Port on which POP server listens ∗/<br />

bool opened ; /∗ Have we established connection ? ∗/<br />

private:<br />

set〈string〉 multiLine , cMultiLine ; /∗ POP3 multi-line command lists ∗/<br />

int listenSocket ; /∗ Socket on which we listen for connections ∗/<br />

POP3Proxy<strong>Filter</strong>Function filterFunction ; /∗ <strong>Filter</strong> function for replies from server ∗/<br />

public:<br />

POP3Proxy(unsigned short proxyPort = 9110, string serverN = "", unsigned short<br />

serverP = 110, POP3Proxy<strong>Filter</strong>Function filterF = Λ):<br />

popProxyPort (proxyPort ), serverName (serverN ), serverPort (serverP ), opened (false ),<br />

listenSocket (−1), filterFunction (filterF )<br />

{<br />

〈 Define multi-line and conditional multi-line commands 195 〉;<br />

}<br />

∼POP3Proxy( )<br />

{<br />

if (listenSocket ≠ −1) {<br />

close (listenSocket );<br />

signal (SIGPIPE, SIG_DFL);<br />

}<br />

}<br />

void setPopProxyPort (unsigned short p)<br />

{<br />

〈 Check for POP3 connection already opened 196 〉;<br />

popProxyPort = p;<br />

}<br />

void setServerName (string &s)<br />

{<br />

〈 Check for POP3 connection already opened 196 〉;<br />

serverName = s;<br />

}<br />

void setServerPort (unsigned short p)<br />

{<br />

〈 Check for POP3 connection already opened 196 〉;<br />

serverPort = p;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!