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.

170 POP3 PROXY SERVER CLASS DEFINITION ANNOYANCE-FILTER §203<br />

203. Read the greeting from the server and forward it to the client. We do this prior to the dialogue<br />

loop to avoid tangled logic there when processing requests with multiple-line replies.<br />

〈 Read the greeting from the server and relay to the client 203 〉 ≡<br />

serverLength = recv (serverSocket , serverBuffer , POP_MAX_MESSAGE, 0);<br />

if (serverLength < 0) {<br />

perror ("POP3Proxy␣reading␣greeting␣from␣server");<br />

ok = false ;<br />

}<br />

else {<br />

clientLength = send (clientSocket , serverBuffer , serverLength , 0);<br />

if (clientLength < 0) {<br />

perror ("POP3Proxy␣forwarding␣greeting␣to␣client");<br />

ok = false ;<br />

}<br />

}<br />

This code is used in section 200.<br />

204. This is the main client/server dialogue loop. We read successive requests from the client, forward<br />

them to the server, then receive the reply from the server (which, depending on the request, may contain<br />

variable-length information after the obligatory status line). Before returning the reply to the client, we<br />

check whether this is a mail body we wish to pass through the filtering step and proceed accordingly.<br />

Finally, the results are written back to the client. If the command we’ve just completed is “QUIT”, we’re<br />

done with this client.<br />

〈 Conduct client/server dialogue 204 〉 ≡<br />

while (ok ) {<br />

〈 Read request from client 205 〉;<br />

〈 Check for blank request and discard 206 〉;<br />

〈 Forward request to server 207 〉;<br />

〈 Parse request and argument into canonical form 208 〉;<br />

〈 Read status line from server 209 〉;<br />

〈 Read multi-line reply from server if present 210 〉;<br />

〈 Fiddle with the reply from the server as required 211 〉;<br />

〈 Relay the status line from the server to the client 212 〉;<br />

〈 Relay multi-line reply, if any, to the client 213 〉;<br />

if (command ≡ "quit") {<br />

break;<br />

}<br />

}<br />

This code is used in section 200.

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

Saved successfully!

Ooh no, something went wrong!