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

enumprot.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:        enumprot.c
00005  * PURPOSE:     Protocol Enumeration
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 //#define NDEBUG
00013 #include <debug.h>
00014 
00015 /* DATA **********************************************************************/
00016 
00017 /* FUNCTIONS *****************************************************************/
00018 
00019 BOOL
00020 WSAAPI
00021 CheckProtocolMatch(IN LPINT ProtocolSet,
00022                    IN LPWSAPROTOCOL_INFOW ProtocolInfo)
00023 {
00024     BOOL Return = FALSE;
00025     DWORD i = 0;
00026     INT ProtocolId = 0;
00027 
00028     /* Make sure we have a set */
00029     if (ProtocolSet)
00030     {
00031         /* Get the first ID */
00032         ProtocolId = ProtocolSet[i];
00033 
00034         /* Loop the list */
00035         while (ProtocolId != 0)
00036         {
00037             /* Check if it's within ranges */
00038             if ((ProtocolId >= ProtocolInfo->iProtocol) &&
00039                 (ProtocolId <= (ProtocolInfo->iProtocol +
00040                                 ProtocolInfo->iProtocolMaxOffset)))
00041             {
00042                 /* Found it */
00043                 Return = TRUE;
00044                 break;
00045             }
00046 
00047             /* Move on */
00048             i++;
00049             ProtocolId = ProtocolSet[i];
00050         }
00051     }
00052     else
00053     {
00054         /* Assume match */
00055         Return = TRUE;
00056     }
00057 
00058     /* Return result */
00059     return Return;
00060 }
00061 
00062 VOID
00063 WSAAPI
00064 ProtocolInfoFromContext(IN LPWSAPROTOCOL_INFOW ProtocolInfo,
00065                         IN PPROTOCOL_ENUM_CONTEXT Context)
00066 {
00067     /* Check if we'll have space */
00068     if ((Context->BufferUsed + sizeof(*ProtocolInfo)) <=
00069         (Context->BufferLength))
00070     {
00071         /* Copy the data */
00072         RtlMoveMemory((PVOID)((ULONG_PTR)Context->ProtocolBuffer +
00073                               Context->BufferUsed),
00074                       ProtocolInfo,
00075                       sizeof(*ProtocolInfo));
00076 
00077         /* Increase the count */
00078         Context->Count++;
00079     }
00080 }
00081 
00082 BOOL
00083 WSAAPI
00084 ProtocolEnumerationProc(PVOID EnumContext,
00085                         PTCATALOG_ENTRY Entry)
00086 {
00087     PPROTOCOL_ENUM_CONTEXT Context = (PPROTOCOL_ENUM_CONTEXT)EnumContext;
00088     LPWSAPROTOCOL_INFOW ProtocolInfo = &Entry->ProtocolInfo;
00089 
00090     /* Check if this protocol matches */
00091     if (CheckProtocolMatch(Context->Protocols, ProtocolInfo))
00092     {
00093         /* Copy the information */
00094         ProtocolInfoFromContext(ProtocolInfo, Context);
00095         Context->BufferUsed += sizeof(*ProtocolInfo);
00096     }
00097 
00098     /* Continue enumeration */
00099     return TRUE;
00100 }
00101 
00102 PTCATALOG
00103 WSAAPI
00104 OpenInitializedCatalog(VOID)
00105 {
00106     PTCATALOG Catalog;
00107     HKEY WsKey;
00108 
00109     /* Allocate the catalog */
00110     Catalog = WsTcAllocate();
00111     if (Catalog)
00112     {
00113         /* Open the WS Key */
00114         WsKey = WsOpenRegistryRoot();
00115 
00116         /* Initialize the catalog */
00117         WsTcInitializeFromRegistry(Catalog, WsKey, NULL);
00118 
00119         /* Close the key */
00120         RegCloseKey(WsKey);
00121     }
00122 
00123     /* Return it */
00124     return Catalog;
00125 }
00126 
00127 /*
00128  * @implemented
00129  */
00130 INT
00131 WSPAPI
00132 WSCEnumProtocols(IN LPINT lpiProtocols,
00133                  OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer,
00134                  IN OUT LPDWORD lpdwBufferLength,
00135                  OUT LPINT lpErrno)
00136 {
00137     INT Status;
00138     PTCATALOG Catalog;
00139     PROTOCOL_ENUM_CONTEXT Context;
00140     DPRINT("WSCEnumProtocols: %p\n", lpiProtocols);
00141 
00142     /* Create a catalog object from the current one */
00143     Catalog = OpenInitializedCatalog();
00144     if (!Catalog)
00145     {
00146         /* Fail if we couldn't */
00147         *lpErrno = WSAENOBUFS;
00148         return SOCKET_ERROR;
00149     }
00150 
00151     /* Setup the context */
00152     Context.Protocols = lpiProtocols;
00153     Context.ProtocolBuffer = lpProtocolBuffer;
00154     Context.BufferLength = lpProtocolBuffer ? *lpdwBufferLength : 0;
00155     Context.BufferUsed = 0;
00156     Context.Count = 0;
00157     Context.ErrorCode = ERROR_SUCCESS;
00158 
00159     /* Enumerate the catalog */
00160     WsTcEnumerateCatalogItems(Catalog, ProtocolEnumerationProc, &Context);
00161 
00162     /* Get status */
00163     Status = Context.Count;
00164 
00165     /* Check the error code */
00166     if (Context.ErrorCode == ERROR_SUCCESS)
00167     {
00168         /* Check if enough space was available */
00169         if (Context.BufferLength < Context.BufferUsed)
00170         {
00171             /* Fail and tell them how much we need */
00172             *lpdwBufferLength = Context.BufferUsed;
00173             *lpErrno = WSAENOBUFS;
00174             Status = SOCKET_ERROR;
00175         }
00176     }
00177     else
00178     {
00179         /* Failure, normalize error */
00180         Status = SOCKET_ERROR;
00181         *lpErrno = Context.ErrorCode;
00182     }
00183 
00184     /* Delete the catalog object */
00185     WsTcDelete(Catalog);
00186 
00187     /* Return */
00188     return Status;
00189 }
00190 
00191 /*
00192  * @unimplemented
00193  */
00194 INT
00195 WSAAPI
00196 WSAEnumProtocolsA(IN LPINT lpiProtocols,
00197                   OUT LPWSAPROTOCOL_INFOA lpProtocolBuffer,
00198                   IN OUT LPDWORD lpdwBufferLength)
00199 {
00200     DPRINT("WSAEnumProtocolsA: %p\n", lpiProtocols);
00201     UNIMPLEMENTED;
00202     SetLastError(WSAEINVAL);
00203     return SOCKET_ERROR;
00204 }
00205 
00206 /*
00207  * @unimplemented
00208  */
00209 INT
00210 WSAAPI
00211 WSAEnumProtocolsW(IN LPINT lpiProtocols,
00212                   OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer,
00213                   IN OUT  LPDWORD lpdwBufferLength)
00214 {
00215     DPRINT("WSAEnumProtocolsW: %p\n", lpiProtocols);
00216     UNIMPLEMENTED;
00217     SetLastError(WSAEINVAL);
00218     return SOCKET_ERROR;
00219 }
00220 
00221 /*
00222  * @unimplemented
00223  */
00224 INT
00225 WSPAPI
00226 WPUGetProviderPath(IN LPGUID lpProviderId,
00227                    OUT LPWSTR lpszProviderDllPath,
00228                    IN OUT LPINT lpProviderDllPathLen,
00229                    OUT LPINT lpErrno)
00230 {
00231     DPRINT("WPUGetProviderPath: %p\n", lpProviderId);
00232     UNIMPLEMENTED;
00233     return 0;
00234 }
00235 
00236 /*
00237  * @unimplemented
00238  */
00239 INT
00240 WSAAPI
00241 WSAProviderConfigChange(IN OUT LPHANDLE lpNotificationHandle,
00242                         IN LPWSAOVERLAPPED lpOverlapped,
00243                         IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
00244 {
00245     DPRINT("WSAProviderConfigChange: %p\n", lpNotificationHandle);
00246     UNIMPLEMENTED;
00247     SetLastError(WSAEINVAL);
00248     return SOCKET_ERROR;
00249 }
00250 
00251 /*
00252  * @unimplemented
00253  */
00254 INT
00255 WSPAPI
00256 WSCGetProviderPath(IN LPGUID lpProviderId,
00257                    OUT LPWSTR lpszProviderDllPath,
00258                    IN OUT LPINT lpProviderDllPathLen,
00259                    OUT LPINT lpErrno)
00260 {
00261     DPRINT("WSCGetProviderPath: %p\n", lpProviderId);
00262     UNIMPLEMENTED;
00263     SetLastError(WSAEINVAL);
00264     return SOCKET_ERROR;
00265 }

Generated on Sat May 26 2012 04:25:39 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.