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.

BOOL SpcConfirmationCreate(LPCTSTR lpszAddress, LPSTR *lpszID) {<br />

BYTE pbBuffer[16];<br />

if (!spc_rand(pbBuffer, sizeof(pbBuffer))) return FALSE;<br />

if (!(*lpszID = (LPSTR)spc_base64_encode(pbBuffer, sizeof(pbBuffer), 0)))<br />

return FALSE;<br />

if (!NewConfirmation(lpszAddress, *lpszID)) {<br />

LocalFree(*lpszID);<br />

return FALSE;<br />

}<br />

return TRUE;<br />

}<br />

BOOL SpcConfirmationReceive(LPCTSTR lpszAddress, LPCSTR lpszID) {<br />

DWORD dwIndex;<br />

LARGE_INTEGER liNow;<br />

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

* remove expired entries.<br />

*/<br />

GetSystemTimeAsFileTime((LPFILETIME)&liNow);<br />

for (dwIndex = 0; dwIndex < dwConfirmationCount; dwIndex++) {<br />

if (pConfirmations[dwIndex].liExpire.QuadPart 1 && dwIndex < dwConfirmationCount - 1)<br />

pConfirmations[dwIndex] = pConfirmations[dwConfirmationCount - 1];<br />

dwIndex--;<br />

dwConfirmationCount--;<br />

}<br />

}<br />

for (dwIndex = 0; dwIndex < dwConfirmationCount; dwIndex++) {<br />

if (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,<br />

pConfirmations[dwIndex].lpszAddress, -1,<br />

lpszAddress, -1) = = CSTR_EQUAL) {<br />

if (lstrcmpA(pConfirmations[dwIndex].lpszID, lpszID) != 0) return FALSE;<br />

LocalFree(pConfirmations[dwIndex].lpszAddress);<br />

LocalFree(pConfirmations[dwIndex].lpszID);<br />

if (dwConfirmationCount > 1 && dwIndex < dwConfirmationCount - 1)<br />

pConfirmations[dwIndex] = pConfirmations[dwConfirmationCount - 1];<br />

dwConfirmationCount--;<br />

return TRUE;<br />

}<br />

}<br />

return FALSE;<br />

}<br />

See Also<br />

Recipe 11.2<br />

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