home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / security / winnt / sockauth / collect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-09  |  1.3 KB  |  85 lines

  1. /*++
  2.  
  3. Copyright 1996-1997 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     collect.c
  8.  
  9. Abstract:
  10.  
  11.     Implements a very simple collection for mapping DWORD key values
  12.     to a blob of data.
  13.  
  14. Revision History:
  15.  
  16. --*/
  17.  
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include "collect.h"
  21.  
  22. typedef struct _node_tag  {
  23.     DWORD dwKey;
  24.     PVOID *pData;
  25.     struct _node_tag *pNext;
  26. } NODE, *PNODE;
  27.  
  28. static NODE Head = {(DWORD)-1, NULL, NULL};
  29.  
  30. BOOL GetEntry (DWORD dwKey, PVOID *ppData)
  31. {
  32.     PNODE pCurrent;
  33.  
  34.     pCurrent = Head.pNext;
  35.     while (NULL != pCurrent) {
  36.         if (dwKey == pCurrent->dwKey)  {
  37.             *ppData = pCurrent->pData;
  38.             return(TRUE);
  39.         }
  40.         pCurrent = pCurrent->pNext;
  41.     }
  42.  
  43.     return(FALSE);
  44. }
  45.  
  46. BOOL AddEntry (DWORD dwKey, PVOID pData)
  47. {
  48.     PNODE pTemp;
  49.  
  50.     pTemp = (PNODE) malloc (sizeof (NODE));
  51.     if (NULL == pTemp)  {
  52.         return(FALSE);
  53.     }
  54.  
  55.     pTemp->dwKey = dwKey;
  56.     pTemp->pData = pData;
  57.     pTemp->pNext = Head.pNext;
  58.     Head.pNext = pTemp;
  59.  
  60.     return(TRUE);
  61. }    
  62.  
  63. BOOL DeleteEntry (DWORD dwKey, PVOID *ppData)
  64. {
  65.     PNODE pCurrent, pTemp;
  66.  
  67.     pTemp = &Head;
  68.     pCurrent = Head.pNext;
  69.  
  70.     while (NULL != pCurrent) {
  71.         if (dwKey == pCurrent->dwKey)  {
  72.             pTemp->pNext = pCurrent->pNext;
  73.             *ppData = pCurrent->pData;
  74.             free (pCurrent);
  75.             return(TRUE);
  76.         }
  77.         else {
  78.             pTemp = pCurrent;
  79.             pCurrent = pCurrent->pNext;
  80.         }
  81.     }
  82.  
  83.     return(FALSE);
  84. }    
  85.