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

wsautil.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 API
00004  * FILE:        wsautil.c
00005  * PURPOSE:     Winsock Utility Functions
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 /* DATA **********************************************************************/
00013 
00014 /* FUNCTIONS *****************************************************************/
00015 
00016 HKEY
00017 WSAAPI
00018 WsOpenRegistryRoot(VOID)
00019 {
00020     HKEY WinsockRootKey;
00021     INT ErrorCode;
00022     ULONG CreateDisposition;
00023 
00024     /* Open Registry Key */
00025     ErrorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00026                              WINSOCK_ROOT,
00027                              0,
00028                              MAXIMUM_ALLOWED,
00029                              &WinsockRootKey);
00030     
00031     /* Check if it wasn't found */
00032     if (ErrorCode == ERROR_FILE_NOT_FOUND)
00033     {
00034         /* Create it */
00035         RegCreateKeyEx(HKEY_LOCAL_MACHINE,
00036                        WINSOCK_ROOT,
00037                        0,
00038                        NULL,
00039                        REG_OPTION_NON_VOLATILE,
00040                        KEY_ALL_ACCESS,
00041                        NULL,
00042                        &WinsockRootKey,
00043                        &CreateDisposition);
00044     }
00045     else if (ErrorCode == ERROR_SUCCESS)
00046     {
00047         /* It already exists */
00048         CreateDisposition = REG_OPENED_EXISTING_KEY;
00049     }
00050 
00051     /* Check for failure */
00052     if (ErrorCode != ERROR_SUCCESS) return NULL;
00053 
00054     /* Check if we had to create a new key */
00055     if (CreateDisposition == REG_CREATED_NEW_KEY)
00056     {
00057         /* Write the Winsock Version */
00058         RegSetValueEx(WinsockRootKey,
00059                       "WinSock_Registry_Version",
00060                       0,
00061                       REG_SZ,
00062                       (BYTE*)"2.2",
00063                       4);
00064     }
00065     else
00066     {
00067         /* Read the Winsock Version */
00068     }
00069 
00070     /* Return the key */
00071     return WinsockRootKey;
00072 }
00073 
00074 BOOL
00075 WSAAPI
00076 WsCheckCatalogState(IN HANDLE Event)
00077 {
00078     DWORD Return;
00079 
00080     /* Wait for the object */
00081     Return = WaitForSingleObject(Event, 0);
00082 
00083     /* Check for the value */
00084     if (Return == WAIT_OBJECT_0) return TRUE;
00085 
00086     /* If it timedout or anything else, return false */
00087     return FALSE;
00088 }
00089 
00090 INT
00091 WSAAPI
00092 WsApiProlog(OUT PWSPROCESS *Process,
00093             OUT PWSTHREAD *Thread)
00094 {
00095     INT ErrorCode = WSANOTINITIALISED;
00096 
00097     /* Try to get the current process */
00098     if ((*Process = WsGetProcess()))
00099     {
00100         /* And the current thread */
00101         ErrorCode = WsThreadGetCurrentThread(*Process, Thread);
00102     }
00103 
00104     /* Return init status */
00105     return ErrorCode;
00106 }
00107 
00108 INT
00109 WSAAPI
00110 WsSlowProlog(VOID)
00111 {
00112     PWSPROCESS Process;
00113     PWSTHREAD Thread;
00114 
00115     /* Call the prolog */
00116     return WsApiProlog(&Process, &Thread);
00117 }
00118 
00119 INT
00120 WSAAPI
00121 WsSlowPrologTid(OUT LPWSATHREADID *ThreadId)
00122 {
00123     PWSPROCESS Process;
00124     PWSTHREAD Thread;
00125     INT ErrorCode;
00126 
00127     /* Call the prolog */
00128     ErrorCode = WsApiProlog(&Process, &Thread);
00129 
00130     /* Check for success */
00131     if (ErrorCode == ERROR_SUCCESS)
00132     {
00133         /* Return the Thread ID */
00134         *ThreadId = &Thread->WahThreadId;
00135     }
00136 
00137     /* Return status */
00138     return ErrorCode;
00139 }
00140 
00141 INT
00142 WSAAPI
00143 WsSetupCatalogProtection(IN HKEY CatalogKey,
00144                          IN HANDLE CatalogEvent,
00145                          OUT LPDWORD UniqueId)
00146 {
00147     INT ErrorCode;
00148     HKEY RegistryKey;
00149     DWORD NewUniqueId;
00150     CHAR KeyBuffer[32];
00151     DWORD RegType = REG_DWORD;
00152     DWORD RegSize = sizeof(DWORD);
00153 
00154     /* Start loop */
00155     do
00156     {
00157 #if 0
00158         /* Ask for notifications */
00159         ErrorCode = RegNotifyChangeKeyValue(CatalogKey,
00160                                             FALSE,
00161                                             REG_NOTIFY_CHANGE_NAME,
00162                                             CatalogEvent,
00163                                             TRUE);
00164         if (ErrorCode != ERROR_SUCCESS)
00165         {
00166             /* Normalize error code */
00167             ErrorCode = WSASYSCALLFAILURE;
00168             break;
00169         }
00170 #endif
00171 
00172         /* Read the current ID */
00173         ErrorCode = RegQueryValueEx(CatalogKey,
00174                                     "Serial_Access_Num",
00175                                     0,
00176                                     &RegType,
00177                                     (LPBYTE)&NewUniqueId,
00178                                     &RegSize);
00179         if (ErrorCode != ERROR_SUCCESS)
00180         {
00181             /* Critical failure */
00182             ErrorCode = WSASYSCALLFAILURE;
00183             break;
00184         }
00185 
00186         /* Try to open it for writing */
00187         sprintf(KeyBuffer, "%8.8lX", NewUniqueId);
00188         ErrorCode = RegOpenKeyEx(CatalogKey,
00189                                  KeyBuffer,
00190                                  0,
00191                                  MAXIMUM_ALLOWED,
00192                                  &RegistryKey);
00193 
00194         /* If the key doesn't exist or is being delete, that's ok for us */
00195         if ((ErrorCode == ERROR_FILE_NOT_FOUND) ||
00196             (ErrorCode == ERROR_KEY_DELETED))
00197         {
00198             /* Set success and return the new ID */
00199             ErrorCode = ERROR_SUCCESS;
00200             *UniqueId = NewUniqueId;
00201             break;
00202         }
00203         else if (ErrorCode != ERROR_SUCCESS)
00204         {
00205             /* Any other failure is bad */
00206             ErrorCode = WSASYSCALLFAILURE;
00207             break;
00208         }
00209 
00210         /* If we could actually open the key, someone is using it :/ */
00211         ErrorCode = RegCloseKey(RegistryKey);
00212 
00213         /* In case we break out prematurely */
00214         ErrorCode = WSANO_RECOVERY;
00215 
00216         /* Keep looping until they let go of the registry writing */
00217     } while (!WaitForSingleObject(CatalogEvent, 180 * 1000));
00218 
00219     /* Return error code */
00220     return ErrorCode;
00221 }
00222 
00223 INT
00224 WSAAPI
00225 MapUnicodeProtocolInfoToAnsi(IN LPWSAPROTOCOL_INFOW UnicodeInfo,
00226                              OUT LPWSAPROTOCOL_INFOA AnsiInfo)
00227 {
00228     INT ReturnValue;
00229 
00230     /* Copy all the data that doesn't need converting */
00231     RtlCopyMemory(AnsiInfo,
00232                   UnicodeInfo,
00233                   FIELD_OFFSET(WSAPROTOCOL_INFOA, szProtocol));
00234 
00235     /* Now convert the protocol string */
00236     ReturnValue = WideCharToMultiByte(CP_ACP,
00237                                       0,
00238                                       UnicodeInfo->szProtocol,
00239                                       -1,
00240                                       AnsiInfo->szProtocol,
00241                                       sizeof(AnsiInfo->szProtocol),
00242                                       NULL,
00243                                       NULL);
00244     if (!ReturnValue) return WSASYSCALLFAILURE;
00245 
00246     /* Return success */
00247     return ERROR_SUCCESS;
00248 }
00249 
00250 /*
00251  * @implemented
00252  */
00253 VOID
00254 WSAAPI
00255 WEP(VOID)
00256 {
00257     return;
00258 }

Generated on Sun May 27 2012 04:27:11 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.