21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Upon receipt of a response to a confirmation request, the address from which it was<br />

sent and the unique identified contained within it should be passed as arguments to<br />

spc_confirmation_receive( ) (SpcConfirmationReceive() on Windows). If the address<br />

and unique identifier are in the list of pending requests, the return from this function<br />

will be 1; otherwise, it will be 0. Before the list is checked, expired entries will<br />

automatically be removed.<br />

int spc_confirmation_receive(const char *address, const char *id) {<br />

time_t now;<br />

unsigned long i;<br />

/* Before we check the pending list of confirmations, prune the list to<br />

* remove expired entries.<br />

*/<br />

now = time(0);<br />

for (i = 0; i < confirmation_count; i++) {<br />

if (confirmations[i].expire 1 && i < confirmation_count - 1)<br />

confirmations[i] = confirmations[confirmation_count - 1];<br />

i--;<br />

confirmation_count--;<br />

}<br />

}<br />

for (i = 0; i < confirmation_count; i++) {<br />

if (!strcmp(confirmations[i].address, address)) {<br />

if (strcmp(confirmations[i].id, id) != 0) return 0;<br />

free(confirmations[i].address);<br />

free(confirmations[i].id);<br />

if (confirmation_count > 1 && i < confirmation_count - 1)<br />

confirmations[i] = confirmations[confirmation_count - 1];<br />

confirmation_count--;<br />

return 1;<br />

}<br />

}<br />

return 0;<br />

}<br />

The Windows versions of spc_confirmation_create( ) and spc_confirmation_<br />

receive( ) are named SpcConfirmationCreate( ) and SpcConfirmationReceive( ),<br />

respectively. The arguments and return values for each are the same; however, there<br />

are enough subtle differences in the underlying implementation that we present an<br />

entirely separate code listing for Windows instead of using the preprocessor to have<br />

a single version.<br />

#include <br />

/* Confirmation receipts must be received within one hour (3600 seconds) */<br />

#define SPC_CONFIRMATION_EXPIRE 3600<br />

Confirming Requests via Email | 451<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!