ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

proplist.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2004-2006 Juan Lang
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 #include <assert.h>
00019 #include <stdarg.h>
00020 #include "windef.h"
00021 #include "winbase.h"
00022 #include "wincrypt.h"
00023 #include "wine/debug.h"
00024 #include "wine/list.h"
00025 #include "crypt32_private.h"
00026 
00027 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
00028 
00029 typedef struct _CONTEXT_PROPERTY_LIST
00030 {
00031     CRITICAL_SECTION cs;
00032     struct list      properties;
00033 } CONTEXT_PROPERTY_LIST;
00034 
00035 typedef struct _CONTEXT_PROPERTY
00036 {
00037     DWORD       propID;
00038     DWORD       cbData;
00039     LPBYTE      pbData;
00040     struct list entry;
00041 } CONTEXT_PROPERTY, *PCONTEXT_PROPERTY;
00042 
00043 PCONTEXT_PROPERTY_LIST ContextPropertyList_Create(void)
00044 {
00045     PCONTEXT_PROPERTY_LIST list = CryptMemAlloc(sizeof(CONTEXT_PROPERTY_LIST));
00046 
00047     if (list)
00048     {
00049         InitializeCriticalSection(&list->cs);
00050         list->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PCONTEXT_PROPERTY_LIST->cs");
00051         list_init(&list->properties);
00052     }
00053     return list;
00054 }
00055 
00056 void ContextPropertyList_Free(PCONTEXT_PROPERTY_LIST list)
00057 {
00058     PCONTEXT_PROPERTY prop, next;
00059 
00060     LIST_FOR_EACH_ENTRY_SAFE(prop, next, &list->properties, CONTEXT_PROPERTY,
00061      entry)
00062     {
00063         list_remove(&prop->entry);
00064         CryptMemFree(prop->pbData);
00065         CryptMemFree(prop);
00066     }
00067     list->cs.DebugInfo->Spare[0] = 0;
00068     DeleteCriticalSection(&list->cs);
00069     CryptMemFree(list);
00070 }
00071 
00072 BOOL ContextPropertyList_FindProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
00073  PCRYPT_DATA_BLOB blob)
00074 {
00075     PCONTEXT_PROPERTY prop;
00076     BOOL ret = FALSE;
00077 
00078     TRACE("(%p, %d, %p)\n", list, id, blob);
00079 
00080     EnterCriticalSection(&list->cs);
00081     LIST_FOR_EACH_ENTRY(prop, &list->properties, CONTEXT_PROPERTY, entry)
00082     {
00083         if (prop->propID == id)
00084         {
00085             blob->cbData = prop->cbData;
00086             blob->pbData = prop->pbData;
00087             ret = TRUE;
00088             break;
00089         }
00090     }
00091     LeaveCriticalSection(&list->cs);
00092     return ret;
00093 }
00094 
00095 BOOL ContextPropertyList_SetProperty(PCONTEXT_PROPERTY_LIST list, DWORD id,
00096  const BYTE *pbData, size_t cbData)
00097 {
00098     LPBYTE data;
00099     BOOL ret = FALSE;
00100 
00101     if (cbData)
00102     {
00103         data = CryptMemAlloc(cbData);
00104         if (data)
00105             memcpy(data, pbData, cbData);
00106     }
00107     else
00108         data = NULL;
00109     if (!cbData || data)
00110     {
00111         PCONTEXT_PROPERTY prop;
00112         BOOL found = FALSE;
00113 
00114         EnterCriticalSection(&list->cs);
00115         LIST_FOR_EACH_ENTRY(prop, &list->properties, CONTEXT_PROPERTY, entry)
00116         {
00117             if (prop->propID == id)
00118             {
00119                 found = TRUE;
00120                 break;
00121             }
00122         }
00123         if (found)
00124         {
00125             CryptMemFree(prop->pbData);
00126             prop->cbData = cbData;
00127             prop->pbData = data;
00128             ret = TRUE;
00129         }
00130         else
00131         {
00132             prop = CryptMemAlloc(sizeof(CONTEXT_PROPERTY));
00133             if (prop)
00134             {
00135                 prop->propID = id;
00136                 prop->cbData = cbData;
00137                 prop->pbData = data;
00138                 list_add_tail(&list->properties, &prop->entry);
00139                 ret = TRUE;
00140             }
00141             else
00142                 CryptMemFree(data);
00143         }
00144         LeaveCriticalSection(&list->cs);
00145     }
00146     return ret;
00147 }
00148 
00149 void ContextPropertyList_RemoveProperty(PCONTEXT_PROPERTY_LIST list, DWORD id)
00150 {
00151     PCONTEXT_PROPERTY prop, next;
00152 
00153     EnterCriticalSection(&list->cs);
00154     LIST_FOR_EACH_ENTRY_SAFE(prop, next, &list->properties, CONTEXT_PROPERTY,
00155      entry)
00156     {
00157         if (prop->propID == id)
00158         {
00159             list_remove(&prop->entry);
00160             CryptMemFree(prop->pbData);
00161             CryptMemFree(prop);
00162             break;
00163         }
00164     }
00165     LeaveCriticalSection(&list->cs);
00166 }
00167 
00168 /* Since the properties are stored in a list, this is a tad inefficient
00169  * (O(n^2)) since I have to find the previous position every time.
00170  */
00171 DWORD ContextPropertyList_EnumPropIDs(PCONTEXT_PROPERTY_LIST list, DWORD id)
00172 {
00173     DWORD ret;
00174 
00175     EnterCriticalSection(&list->cs);
00176     if (id)
00177     {
00178         PCONTEXT_PROPERTY cursor = NULL;
00179 
00180         LIST_FOR_EACH_ENTRY(cursor, &list->properties, CONTEXT_PROPERTY, entry)
00181         {
00182             if (cursor->propID == id)
00183                 break;
00184         }
00185         if (cursor)
00186         {
00187             if (cursor->entry.next != &list->properties)
00188                 ret = LIST_ENTRY(cursor->entry.next, CONTEXT_PROPERTY,
00189                  entry)->propID;
00190             else
00191                 ret = 0;
00192         }
00193         else
00194             ret = 0;
00195     }
00196     else if (!list_empty(&list->properties))
00197         ret = LIST_ENTRY(list->properties.next, CONTEXT_PROPERTY,
00198          entry)->propID;
00199     else
00200         ret = 0;
00201     LeaveCriticalSection(&list->cs);
00202     return ret;
00203 }
00204 
00205 void ContextPropertyList_Copy(PCONTEXT_PROPERTY_LIST to,
00206  PCONTEXT_PROPERTY_LIST from)
00207 {
00208     PCONTEXT_PROPERTY prop;
00209 
00210     EnterCriticalSection(&from->cs);
00211     LIST_FOR_EACH_ENTRY(prop, &from->properties, CONTEXT_PROPERTY, entry)
00212     {
00213         ContextPropertyList_SetProperty(to, prop->propID, prop->pbData,
00214          prop->cbData);
00215     }
00216     LeaveCriticalSection(&from->cs);
00217 }

Generated on Sun May 27 2012 04:23:18 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.