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

rnr.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:        rnr.c
00005  * PURPOSE:     Registration n' Resolution Support
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 /*
00020  * @implemented
00021  */
00022 INT
00023 WSAAPI
00024 WSAAddressToStringA(IN LPSOCKADDR lpsaAddress,
00025                     IN DWORD dwAddressLength,
00026                     IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
00027                     OUT LPSTR lpszAddressString,
00028                     IN OUT  LPDWORD lpdwAddressStringLength)
00029 {
00030     PWSPROCESS Process;
00031     PWSTHREAD Thread;
00032     INT ErrorCode, Status;
00033     DWORD CatalogEntryId;
00034     PTCATALOG Catalog;
00035     PTCATALOG_ENTRY CatalogEntry;
00036     LPWSTR UnicodeString;
00037     DWORD Length = *lpdwAddressStringLength;
00038     DPRINT("WSAAddressToStringA: %p\n", lpsaAddress);
00039 
00040     /* Enter prolog */
00041     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00042     {
00043         /* Leave now */
00044         SetLastError(ErrorCode);
00045         return SOCKET_ERROR;
00046     }
00047 
00048     /* Allocate the unicode string */
00049     UnicodeString = HeapAlloc(WsSockHeap, 0, Length * 2);
00050     if (!UnicodeString)
00051     {
00052         /* No memory; fail */
00053         SetLastError(WSAENOBUFS);
00054         return SOCKET_ERROR;
00055     }
00056 
00057     /* Get the catalog */
00058     Catalog = WsProcGetTCatalog(Process);
00059 
00060     /* Check if we got custom protocol info */
00061     if (lpProtocolInfo)
00062     {
00063         /* Get the entry ID */
00064         CatalogEntryId = lpProtocolInfo->dwCatalogEntryId;
00065 
00066         /* Get the entry associated with it */
00067         ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog,
00068                                                    CatalogEntryId,
00069                                                    &CatalogEntry);
00070     }
00071     else
00072     {
00073         /* Get it from the address family */
00074         ErrorCode = WsTcGetEntryFromAf(Catalog,
00075                                        lpsaAddress->sa_family,
00076                                        &CatalogEntry);
00077     }
00078     
00079     /* Check for success */
00080     if (ErrorCode == ERROR_SUCCESS)
00081     {
00082         /* Call the provider */
00083         Status = CatalogEntry->Provider->Service.lpWSPAddressToString(lpsaAddress,
00084                                                                       dwAddressLength,
00085                                                                       &CatalogEntry->
00086                                                                       ProtocolInfo,
00087                                                                       UnicodeString,
00088                                                                       lpdwAddressStringLength,
00089                                                                       &ErrorCode);
00090         if (Status == ERROR_SUCCESS)
00091         {
00092             /* Convert the string */
00093             WideCharToMultiByte(CP_ACP,
00094                                 0,
00095                                 UnicodeString,
00096                                 -1,
00097                                 lpszAddressString,
00098                                 Length,
00099                                 NULL,
00100                                 NULL);
00101         }
00102 
00103         /* Dereference the entry */
00104         WsTcEntryDereference(CatalogEntry);
00105 
00106         /* Free the unicode string */
00107         HeapFree(WsSockHeap, 0, UnicodeString);
00108 
00109         /* Check for success and return */
00110         if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
00111     }
00112     else
00113     {
00114         /* Free the unicode string */
00115         HeapFree(WsSockHeap, 0, UnicodeString);
00116     }
00117 
00118     /* Set the error and return */
00119     SetLastError(ErrorCode);
00120     return SOCKET_ERROR;
00121 }
00122 
00123 /*
00124  * @implemented
00125  */
00126 INT
00127 WSAAPI
00128 WSAAddressToStringW(IN LPSOCKADDR lpsaAddress,
00129                     IN DWORD dwAddressLength,
00130                     IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
00131                     OUT LPWSTR lpszAddressString,
00132                     IN OUT LPDWORD lpdwAddressStringLength)
00133 {
00134     PWSPROCESS Process;
00135     PWSTHREAD Thread;
00136     INT ErrorCode, Status;
00137     DWORD CatalogEntryId;
00138     PTCATALOG Catalog;
00139     PTCATALOG_ENTRY CatalogEntry;
00140     DPRINT("WSAAddressToStringW: %p\n", lpsaAddress);
00141 
00142     /* Enter prolog */
00143     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00144     {
00145         /* Leave now */
00146         SetLastError(ErrorCode);
00147         return SOCKET_ERROR;
00148     }
00149 
00150     /* Get the catalog */
00151     Catalog = WsProcGetTCatalog(Process);
00152 
00153     /* Check if we got custom protocol info */
00154     if (lpProtocolInfo)
00155     {
00156         /* Get the entry ID */
00157         CatalogEntryId = lpProtocolInfo->dwCatalogEntryId;
00158 
00159         /* Get the entry associated with it */
00160         ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog,
00161                                                    CatalogEntryId,
00162                                                    &CatalogEntry);
00163     }
00164     else
00165     {
00166         /* Get it from the address family */
00167         ErrorCode = WsTcGetEntryFromAf(Catalog,
00168                                        lpsaAddress->sa_family,
00169                                        &CatalogEntry);
00170     }
00171     
00172     /* Check for success */
00173     if (ErrorCode == ERROR_SUCCESS)
00174     {
00175         /* Call the provider */
00176         Status = CatalogEntry->Provider->Service.lpWSPAddressToString(lpsaAddress,
00177                                                                       dwAddressLength,
00178                                                                       &CatalogEntry->
00179                                                                       ProtocolInfo,
00180                                                                       lpszAddressString,
00181                                                                       lpdwAddressStringLength,
00182                                                                       &ErrorCode);
00183 
00184         /* Dereference the entry */
00185         WsTcEntryDereference(CatalogEntry);
00186 
00187         /* Check for success and return */
00188         if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
00189     }
00190 
00191     /* Set the error and return */
00192     SetLastError(ErrorCode);
00193     return SOCKET_ERROR;
00194 }
00195 
00196 /*
00197  * @implemented
00198  */
00199 INT
00200 WSAAPI
00201 WSALookupServiceEnd(IN HANDLE hLookup)
00202 {
00203     PWSPROCESS Process;
00204     PWSTHREAD Thread;
00205     INT ErrorCode;
00206     PNSQUERY Query = hLookup;
00207     DPRINT("WSALookupServiceEnd: %lx\n", hLookup);
00208 
00209     /* Enter prolog */
00210     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00211     {
00212         /* Leave now */
00213         SetLastError(ErrorCode);
00214         return SOCKET_ERROR;
00215     }
00216 
00217     /* Check for a valid handle, then validate and reference it */
00218     if (!(Query) || !(WsNqValidateAndReference(Query)))
00219     {
00220         /* Fail */
00221         SetLastError(WSA_INVALID_HANDLE);
00222         return SOCKET_ERROR;
00223     }
00224 
00225     /* Do the lookup */
00226     ErrorCode = WsNqLookupServiceEnd(Query);
00227 
00228     /* Remove the validation reference */
00229     WsNqDereference(Query);
00230 
00231     /* Remove the keep-alive */
00232     WsNqDereference(Query);
00233 
00234     /* Return */
00235     return ERROR_SUCCESS;
00236 }
00237 
00238 /*
00239  * @implemented
00240  */
00241 INT
00242 WSAAPI
00243 WSALookupServiceBeginA(IN LPWSAQUERYSETA lpqsRestrictions,
00244                        IN DWORD dwControlFlags,
00245                        OUT LPHANDLE lphLookup)
00246 {
00247     INT ErrorCode;
00248     LPWSAQUERYSETW UnicodeQuerySet = NULL;
00249     DWORD UnicodeQuerySetSize = 0;
00250     DPRINT("WSALookupServiceBeginA: %p\n", lpqsRestrictions);
00251 
00252     /* Verifiy pointer */
00253     if (IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)))
00254     {
00255         /* Invalid */
00256         SetLastError(WSAEFAULT);
00257         return SOCKET_ERROR;
00258     }
00259 
00260     /* Clear the reserved fields */
00261     lpqsRestrictions->dwOutputFlags = 0;
00262     lpqsRestrictions->lpszComment = NULL;
00263     lpqsRestrictions->dwNumberOfCsAddrs = 0;
00264 
00265     /* Find out the side we'll need */
00266     ErrorCode = MapAnsiQuerySetToUnicode(lpqsRestrictions,
00267                                          &UnicodeQuerySetSize,
00268                                          UnicodeQuerySet);
00269 
00270     /* We should've failed */
00271     if (ErrorCode == WSAEFAULT)
00272     {
00273         /* Allocate the buffer we'll need */
00274         UnicodeQuerySet = HeapAlloc(WsSockHeap, 0, UnicodeQuerySetSize);
00275         if (UnicodeQuerySet)
00276         {
00277             /* Do the conversion for real */
00278             ErrorCode = MapAnsiQuerySetToUnicode(lpqsRestrictions,
00279                                                  &UnicodeQuerySetSize,
00280                                                  UnicodeQuerySet);
00281             if (ErrorCode == ERROR_SUCCESS)
00282             {
00283                 /* Now call the Unicode function */
00284                 ErrorCode = WSALookupServiceBeginW(UnicodeQuerySet,
00285                                                    dwControlFlags,
00286                                                    lphLookup);
00287             }
00288             else
00289             {
00290                 /* Fail, conversion failed */
00291                 SetLastError(ErrorCode);
00292             }
00293 
00294             /* Free our buffer */
00295             HeapFree(WsSockHeap, 0, UnicodeQuerySet);
00296         }
00297         else
00298         {
00299             /* No memory to allocate */
00300             SetLastError(WSAEFAULT);
00301         }
00302     }
00303     else
00304     {
00305         /* We couldn't get the size for some reason */
00306         SetLastError(ErrorCode);
00307     }
00308 
00309     /* Return to caller */
00310     return ErrorCode == ERROR_SUCCESS ? ErrorCode : SOCKET_ERROR;
00311 }
00312 
00313 /*
00314  * @implemented
00315  */
00316 INT 
00317 WINAPI
00318 WSALookupServiceBeginW(IN LPWSAQUERYSETW lpqsRestrictions,
00319                        IN DWORD dwControlFlags,
00320                        OUT LPHANDLE lphLookup)
00321 {
00322     PWSPROCESS Process;
00323     PWSTHREAD Thread;
00324     INT ErrorCode;
00325     PNSQUERY Query;
00326     DPRINT("WSALookupServiceBeginW: %p\n", lpqsRestrictions);
00327 
00328     /* Enter prolog */
00329     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00330     {
00331         /* Leave now */
00332         SetLastError(ErrorCode);
00333         return SOCKET_ERROR;
00334     }
00335 
00336     /* Verify pointers */
00337     if (IsBadWritePtr(lphLookup, sizeof(*lphLookup)) ||
00338         IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)))
00339     {
00340         /* They are invalid; fail */
00341         SetLastError(WSAEFAULT);
00342         return SOCKET_ERROR;
00343     }
00344 
00345     /* Create a new query object */
00346     if ((Query = WsNqAllocate()))
00347     {
00348         /* Initialize it */
00349         WsNqInitialize(Query);
00350 
00351         /* Do the lookup */
00352         ErrorCode = WsNqLookupServiceBegin(Query,
00353                                            lpqsRestrictions,
00354                                            dwControlFlags,
00355                                            WsProcGetNsCatalog(Process));
00356 
00357         /* Check for success */
00358         if (ErrorCode == ERROR_SUCCESS)
00359         {
00360             /* Return the handle */
00361             *lphLookup = Query;
00362         }
00363         else
00364         {
00365             /* Fail */
00366             *lphLookup = NULL;
00367             WsNqDelete(Query);
00368         }
00369     }
00370     else
00371     {
00372         /* No memory */
00373         ErrorCode = SOCKET_ERROR;
00374         SetLastError(WSAENOBUFS);
00375     }
00376     
00377     /* Return */
00378     return ErrorCode;
00379 }
00380 
00381 /*
00382  * @implemented
00383  */
00384 INT
00385 WINAPI
00386 WSALookupServiceNextW(IN HANDLE hLookup,
00387                       IN DWORD dwControlFlags,
00388                       IN OUT LPDWORD lpdwBufferLength,
00389                       OUT LPWSAQUERYSETW lpqsResults)
00390 {
00391     PWSPROCESS Process;
00392     PWSTHREAD Thread;
00393     INT ErrorCode;
00394     PNSQUERY Query = hLookup;
00395     DPRINT("WSALookupServiceNextW: %lx\n", hLookup);
00396 
00397     /* Enter prolog */
00398     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00399     {
00400         /* Leave now */
00401         SetLastError(ErrorCode);
00402         return SOCKET_ERROR;
00403     }
00404 
00405     /* Check for a valid handle, then validate and reference it */
00406     if (!(Query) || !(WsNqValidateAndReference(Query)))
00407     {
00408         /* Fail */
00409         SetLastError(WSA_INVALID_HANDLE);
00410         return SOCKET_ERROR;
00411     }
00412 
00413     /* Do the lookup */
00414     ErrorCode = WsNqLookupServiceNext(Query,
00415                                       dwControlFlags,
00416                                       lpdwBufferLength,
00417                                       lpqsResults);
00418 
00419     /* Remove the validation reference */
00420     WsNqDereference(Query);
00421 
00422     /* Return */
00423     return ErrorCode;
00424 }
00425 
00426 /*
00427  * @implemented
00428  */
00429 INT
00430 WSAAPI
00431 WSALookupServiceNextA(IN HANDLE hLookup,
00432                       IN DWORD dwControlFlags,
00433                       IN OUT LPDWORD lpdwBufferLength,
00434                       OUT LPWSAQUERYSETA lpqsResults)
00435 {
00436     LPWSAQUERYSETW UnicodeQuerySet;
00437     DWORD UnicodeQuerySetSize = *lpdwBufferLength;
00438     INT ErrorCode;
00439     DPRINT("WSALookupServiceNextA: %lx\n", hLookup);
00440 
00441     /* Check how much the user is giving */
00442     if (UnicodeQuerySetSize >= sizeof(WSAQUERYSETW))
00443     {
00444         /* Allocate the buffer we'll use */
00445         UnicodeQuerySet = HeapAlloc(WsSockHeap, 0, UnicodeQuerySetSize);
00446         if (!UnicodeQuerySet) UnicodeQuerySetSize = 0;
00447     }
00448     else
00449     {
00450         /* His buffer is too small */
00451         UnicodeQuerySetSize = 0;
00452         UnicodeQuerySet = NULL;
00453     }
00454 
00455     /* Call the Unicode Function */
00456     ErrorCode = WSALookupServiceNextW(hLookup,
00457                                       dwControlFlags,
00458                                       &UnicodeQuerySetSize,
00459                                       UnicodeQuerySet);
00460     if (ErrorCode == ERROR_SUCCESS)
00461     {
00462         /* Not convert to ANSI */
00463         ErrorCode = MapUnicodeQuerySetToAnsi(UnicodeQuerySet,
00464                                              lpdwBufferLength,
00465                                              lpqsResults);
00466         if (ErrorCode != ERROR_SUCCESS) SetLastError(ErrorCode);
00467     }
00468     else
00469     {
00470         /* Check if we ran out of space */
00471         if (GetLastError() == WSAEFAULT)
00472         {
00473             /* Return how much space we'll need, including padding */
00474             *lpdwBufferLength = UnicodeQuerySetSize +
00475                                 ((sizeof(ULONG) * 6) - (6 * 1));
00476         }
00477     }
00478 
00479     /* If we had a local buffer, free it */
00480     if (UnicodeQuerySet) HeapFree(WsSockHeap, 0, UnicodeQuerySet);
00481 
00482     /* Return to caller */
00483     return ErrorCode == ERROR_SUCCESS ? ErrorCode : SOCKET_ERROR;
00484 }
00485 
00486 /*
00487  * @unimplemented
00488  */
00489 INT
00490 WSPAPI
00491 WSANSPIoctl(HANDLE hLookup,
00492             DWORD dwControlCode,
00493             LPVOID lpvInBuffer,
00494             DWORD cbInBuffer,
00495             LPVOID lpvOutBuffer,
00496             DWORD cbOutBuffer,
00497             LPDWORD lpcbBytesReturned,
00498             LPWSACOMPLETION lpCompletion)
00499 {
00500     DPRINT("WSANSPIoctl: %lx\n", hLookup);
00501     return 0;
00502 }
00503 
00504 /*
00505  * @unimplemented
00506  */
00507 INT
00508 WSAAPI
00509 WSARemoveServiceClass(IN LPGUID lpServiceClassId)
00510 {
00511     DPRINT("WSARemoveServiceClass: %lx\n", lpServiceClassId);
00512     SetLastError(WSAEINVAL);
00513     return SOCKET_ERROR;
00514 }
00515 
00516 /*
00517  * @unimplemented
00518  */
00519 INT
00520 WSAAPI
00521 WSASetServiceA(IN LPWSAQUERYSETA lpqsRegInfo,
00522                IN WSAESETSERVICEOP essOperation,
00523                IN DWORD dwControlFlags)
00524 {
00525     DPRINT("WSASetServiceA: %lx\n", lpqsRegInfo);
00526     SetLastError(WSAEINVAL);
00527     return SOCKET_ERROR;
00528 }
00529 
00530 /*
00531  * @unimplemented
00532  */
00533 INT
00534 WSAAPI
00535 WSASetServiceW(IN LPWSAQUERYSETW lpqsRegInfo,
00536                IN WSAESETSERVICEOP essOperation,
00537                IN DWORD dwControlFlags)
00538 {
00539     DPRINT("WSASetServiceW: %lx\n", lpqsRegInfo);
00540     SetLastError(WSAEINVAL);
00541     return SOCKET_ERROR;
00542 }
00543 
00544 /*
00545  * @unimplemented
00546  */
00547 INT
00548 WSAAPI
00549 WSAGetServiceClassInfoA(IN LPGUID lpProviderId,
00550                         IN LPGUID lpServiceClassId,
00551                         IN OUT LPDWORD lpdwBufferLength,
00552                         OUT LPWSASERVICECLASSINFOA lpServiceClassInfo)
00553 {
00554     DPRINT("WSAGetServiceClassInfoA: %lx\n", lpProviderId);
00555     SetLastError(WSAEINVAL);
00556     return SOCKET_ERROR;
00557 }
00558 
00559 /*
00560  * @unimplemented
00561  */
00562 INT
00563 WSAAPI
00564 WSAGetServiceClassInfoW(IN LPGUID lpProviderId,
00565                         IN LPGUID lpServiceClassId,
00566                         IN OUT LPDWORD lpdwBufferLength,
00567                         OUT LPWSASERVICECLASSINFOW lpServiceClassInfo)
00568 {
00569     DPRINT("WSAGetServiceClassInfoW: %lx\n", lpProviderId);
00570     SetLastError(WSAEINVAL);
00571     return SOCKET_ERROR;
00572 }
00573 
00574 /*
00575  * @unimplemented
00576  */
00577 INT
00578 WSAAPI
00579 WSAGetServiceClassNameByClassIdA(IN LPGUID lpServiceClassId,
00580                                  OUT LPSTR lpszServiceClassName,
00581                                  IN OUT LPDWORD lpdwBufferLength)
00582 {
00583     DPRINT("WSAGetServiceClassNameByClassIdA: %lx\n", lpServiceClassId);
00584     SetLastError(WSAEINVAL);
00585     return SOCKET_ERROR;
00586 }
00587 
00588 /*
00589  * @unimplemented
00590  */
00591 INT
00592 WSAAPI
00593 WSAGetServiceClassNameByClassIdW(IN LPGUID lpServiceClassId,
00594                                  OUT LPWSTR lpszServiceClassName,
00595                                  IN OUT LPDWORD lpdwBufferLength)
00596 {
00597     DPRINT("WSAGetServiceClassNameByClassIdW: %lx\n", lpServiceClassId);
00598     SetLastError(WSAEINVAL);
00599     return SOCKET_ERROR;
00600 }
00601 
00602 /*
00603  * @unimplemented
00604  */
00605 INT
00606 WSAAPI
00607 WSAInstallServiceClassA(IN LPWSASERVICECLASSINFOA lpServiceClassInfo)
00608 {
00609     DPRINT("WSAInstallServiceClassA: %lx\n", lpServiceClassInfo);
00610     SetLastError(WSAEINVAL);
00611     return SOCKET_ERROR;
00612 }
00613 
00614 /*
00615  * @unimplemented
00616  */
00617 INT
00618 WSAAPI
00619 WSAEnumNameSpaceProvidersA(IN OUT LPDWORD lpdwBufferLength,
00620                            OUT LPWSANAMESPACE_INFOA lpnspBuffer)
00621 {
00622     DPRINT("WSAEnumNameSpaceProvidersA: %lx\n", lpnspBuffer);
00623     SetLastError(WSAEINVAL);
00624     return SOCKET_ERROR;
00625 }
00626 
00627 /*
00628  * @unimplemented
00629  */
00630 INT
00631 WSAAPI
00632 WSAEnumNameSpaceProvidersW(IN OUT LPDWORD lpdwBufferLength,
00633                            OUT LPWSANAMESPACE_INFOW lpnspBuffer)
00634 {
00635     DPRINT("WSAEnumNameSpaceProvidersW: %lx\n", lpnspBuffer);
00636     SetLastError(WSAEINVAL);
00637     return SOCKET_ERROR;
00638 }
00639 
00640 /*
00641  * @unimplemented
00642  */
00643 INT
00644 WSAAPI
00645 WSAInstallServiceClassW(IN LPWSASERVICECLASSINFOW lpServiceClassInfo)
00646 {
00647     DPRINT("WSAInstallServiceClassW: %lx\n", lpServiceClassInfo);
00648     SetLastError(WSAEINVAL);
00649     return SOCKET_ERROR;
00650 }
00651 
00652 /*
00653  * @implemented
00654  */
00655 INT
00656 WSAAPI
00657 WSAStringToAddressA(IN LPSTR AddressString,
00658                     IN INT AddressFamily,
00659                     IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
00660                     OUT LPSOCKADDR lpAddress,
00661                     IN OUT  LPINT lpAddressLength)
00662 {
00663     PWSPROCESS Process;
00664     PWSTHREAD Thread;
00665     INT ErrorCode, Status;
00666     DWORD CatalogEntryId;
00667     PTCATALOG Catalog;
00668     PTCATALOG_ENTRY CatalogEntry;
00669     LPWSTR UnicodeString;
00670     DWORD Length = (DWORD)strlen(AddressString) + 1;
00671     DPRINT("WSAStringToAddressA: %s\n", AddressString);
00672 
00673     /* Enter prolog */
00674     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00675     {
00676         /* Leave now */
00677         SetLastError(ErrorCode);
00678         return SOCKET_ERROR;
00679     }
00680 
00681     /* Allocate the unicode string */
00682     UnicodeString = HeapAlloc(WsSockHeap, 0, Length * 2);
00683     if (!UnicodeString)
00684     {
00685         /* No memory; fail */
00686         SetLastError(WSAENOBUFS);
00687         return SOCKET_ERROR;
00688     }
00689 
00690     /* Convert the string */
00691     MultiByteToWideChar(CP_ACP, 0, AddressString, -1, UnicodeString, Length);
00692 
00693     /* Get the catalog */
00694     Catalog = WsProcGetTCatalog(Process);
00695 
00696     /* Check if we got custom protocol info */
00697     if (lpProtocolInfo)
00698     {
00699         /* Get the entry ID */
00700         CatalogEntryId = lpProtocolInfo->dwCatalogEntryId;
00701 
00702         /* Get the entry associated with it */
00703         ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog,
00704                                                    CatalogEntryId,
00705                                                    &CatalogEntry);
00706     }
00707     else
00708     {
00709         /* Get it from the address family */
00710         ErrorCode = WsTcGetEntryFromAf(Catalog, AddressFamily, &CatalogEntry);
00711     }
00712     
00713     /* Check for success */
00714     if (ErrorCode == ERROR_SUCCESS)
00715     {
00716         /* Call the provider */
00717         Status = CatalogEntry->Provider->Service.lpWSPStringToAddress(UnicodeString,
00718                                                               AddressFamily,
00719                                                               &CatalogEntry->
00720                                                               ProtocolInfo,
00721                                                               lpAddress,
00722                                                               lpAddressLength,
00723                                                               &ErrorCode);
00724 
00725         /* Dereference the entry */
00726         WsTcEntryDereference(CatalogEntry);
00727 
00728         /* Free the unicode string */
00729         HeapFree(WsSockHeap, 0, UnicodeString);
00730 
00731         /* Check for success and return */
00732         if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
00733     }
00734     else
00735     {
00736         /* Free the unicode string */
00737         HeapFree(WsSockHeap, 0, UnicodeString);
00738     }
00739 
00740     /* Set the error and return */
00741     SetLastError(ErrorCode);
00742     return SOCKET_ERROR;
00743 }
00744 
00745 /*
00746  * @implemented
00747  */
00748 INT
00749 WSAAPI
00750 WSAStringToAddressW(IN LPWSTR AddressString,
00751                     IN INT AddressFamily,
00752                     IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
00753                     OUT LPSOCKADDR lpAddress,
00754                     IN OUT LPINT lpAddressLength)
00755 {
00756     PWSPROCESS Process;
00757     PWSTHREAD Thread;
00758     INT ErrorCode, Status;
00759     DWORD CatalogEntryId;
00760     PTCATALOG Catalog;
00761     PTCATALOG_ENTRY CatalogEntry;
00762     DPRINT("WSAStringToAddressW: %S\n", AddressString);
00763 
00764     /* Enter prolog */
00765     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00766     {
00767         /* Leave now */
00768         SetLastError(ErrorCode);
00769         return SOCKET_ERROR;
00770     }
00771 
00772     /* Get the catalog */
00773     Catalog = WsProcGetTCatalog(Process);
00774 
00775     /* Check if we got custom protocol info */
00776     if (lpProtocolInfo)
00777     {
00778         /* Get the entry ID */
00779         CatalogEntryId = lpProtocolInfo->dwCatalogEntryId;
00780 
00781         /* Get the entry associated with it */
00782         ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog,
00783                                                    CatalogEntryId,
00784                                                    &CatalogEntry);
00785     }
00786     else
00787     {
00788         /* Get it from the address family */
00789         ErrorCode = WsTcGetEntryFromAf(Catalog, AddressFamily, &CatalogEntry);
00790     }
00791     
00792     /* Check for success */
00793     if (ErrorCode == ERROR_SUCCESS)
00794     {
00795         /* Call the provider */
00796         Status = CatalogEntry->Provider->Service.lpWSPStringToAddress(AddressString,
00797                                                                       AddressFamily,
00798                                                                       &CatalogEntry->
00799                                                                       ProtocolInfo,
00800                                                                       lpAddress,
00801                                                                       lpAddressLength,
00802                                                                       &ErrorCode);
00803 
00804         /* Dereference the entry */
00805         WsTcEntryDereference(CatalogEntry);
00806 
00807         /* Check for success and return */
00808         if (Status == ERROR_SUCCESS) return ERROR_SUCCESS;
00809     }
00810 
00811     /* Set the error and return */
00812     SetLastError(ErrorCode);
00813     return SOCKET_ERROR;
00814 }

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