21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

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.

see the confirmation request and the unique identifier that it contains. Unfortunately,<br />

this is a much more difficult problem to solve, and it is one that cannot be<br />

easily solved in software, so we will not give it any further consideration.<br />

To implement such a scheme, the mailing list software must maintain some state<br />

information. In particular, upon receipt of a request for membership, the software<br />

needs to generate the unique identifier to include in the confirmation requests, and it<br />

must store that identifier along with the email address for which membership has<br />

been requested. In addition, it is a good idea to maintain some kind of a timestamp<br />

so that confirmation requests will eventually expire. Expiring confirmation requests<br />

significantly reduces the likelihood that Alice can guess the unique identifier; more<br />

importantly, it also helps to reduce the amount of information that must be remembered<br />

to be able to confirm requests.<br />

We define two functions in this recipe that provide the basic implementation for the<br />

confirmation request scheme we have just described. The first, spc_confirmation_<br />

create( ), creates a new confirmation request by generating a unique identifier and<br />

storing it with the email address for which confirmation is to be requested. It stores<br />

the confirmation request information in an in-memory list of pending confirmations,<br />

implemented simply as a dynamically allocated array. For use in a production environment,<br />

a hash table or binary tree might be a better solution for an in-memory<br />

data structure. Alternatively, the information could be stored in a database.<br />

The function spc_confirmation_create( ) (SpcConfirmationCreate() on Windows)<br />

will return 0 if some kind of error occurs. Possible errors include memory allocation<br />

failures and attempts to add an address to the list of pending confirmations that<br />

already exists in the list. If the operation is successful, the return value will be 1. Two<br />

arguments are required by spc_confirmation_create( ):<br />

address<br />

Email address that is to be confirmed.<br />

id<br />

Pointer to a buffer that will be allocated by spc_confirmation_create( ). If the<br />

function returns successfully, the buffer will contain the unique identifier to send<br />

as part of the confirmation request email. It is the responsibility of the caller to<br />

free the buffer using free( ) on Unix or LocalFree( ) on Windows.<br />

You may adjust the SPC_CONFIRMATION_EXPIRE macro from the default presented here.<br />

It controls how long pending confirmation requests will be honored and is specified<br />

in seconds.<br />

Note that the code we are presenting here does not send or receive email at all. Programmatically<br />

sending and receiving email is outside the scope of this book.<br />

#include <br />

#include <br />

#include <br />

Confirming Requests via Email | 449<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!