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

INT WSAAPI MapUnicodeQuerySetToAnsi ( OUT LPWSAQUERYSETW  UnicodeSet,
IN OUT PSIZE_T  SetSize,
IN LPWSAQUERYSETA  AnsiSet 
)

Definition at line 930 of file qshelpr.c.

Referenced by WSALookupServiceNextA().

{
    INT ErrorCode = ERROR_SUCCESS;
    SIZE_T UnicodeSize, AnsiSize;
    LPWSAQUERYSETW UnicodeCopy = NULL;
    LPWSAQUERYSETA AnsiCopy;
    LPSTR ServiceCopy = NULL, CommentCopy = NULL;
    LPSTR ContextCopy = NULL, QueryCopy = NULL;

    /* Calculate the size of the Ansi version and allocate space for a copy */
    UnicodeSize = WSAComputeQuerySetSizeW(UnicodeSet);
    UnicodeCopy = HeapAlloc(WsSockHeap, 0, UnicodeSize);
    if (!UnicodeCopy)
    {
        /* Fail, couldn't allocate memory */
        ErrorCode = WSA_NOT_ENOUGH_MEMORY;
        goto error;
    }
    
    /* Build the relative buffer version */
    ErrorCode = WSABuildQuerySetBufferW(UnicodeSet, UnicodeSize, UnicodeCopy);
    if (ErrorCode != ERROR_SUCCESS) goto error;
        
    /* Re-use the Unicode version since the fields match */
    AnsiCopy = (LPWSAQUERYSETA)UnicodeCopy;

    /* Check if we have a service instance name */
    if (UnicodeCopy->lpszServiceInstanceName)
    {
        /* Duplicate it into unicode form */
        ServiceCopy = AnsiDupFromUnicode(UnicodeCopy->lpszServiceInstanceName);
        if (!ServiceCopy)
        {
            /* Fail */
            ErrorCode = WSA_NOT_ENOUGH_MEMORY;
            goto error;
        }

        /* Set the new string pointer */
        AnsiCopy->lpszServiceInstanceName = ServiceCopy;
    }

    /* Check if we have a service instance name */
    if (UnicodeCopy->lpszContext)
    {
        /* Duplicate it into unicode form */
        ContextCopy = AnsiDupFromUnicode(UnicodeCopy->lpszContext);
        if (!ContextCopy)
        {
            /* Fail */
            ErrorCode = WSA_NOT_ENOUGH_MEMORY;
            goto error;
        }

        /* Set the new string pointer */
        AnsiCopy->lpszContext = ContextCopy;
    }

    /* Check if we have a service instance name */
    if (UnicodeCopy->lpszComment)
    {
        /* Duplicate it into unicode form */
        CommentCopy = AnsiDupFromUnicode(UnicodeCopy->lpszComment);
        if (!CommentCopy)
        {
            /* Fail */
            ErrorCode = WSA_NOT_ENOUGH_MEMORY;
            goto error;
        }

        /* Set the new string pointer */
        AnsiCopy->lpszComment = CommentCopy;
    }

    /* Check if we have a query name */
    if (UnicodeCopy->lpszQueryString)
    {
        /* Duplicate it into unicode form */
        QueryCopy = AnsiDupFromUnicode(UnicodeCopy->lpszQueryString);
        if (!QueryCopy)
        {
            /* Fail */
            ErrorCode = WSA_NOT_ENOUGH_MEMORY;
            goto error;
        }

        /* Set the new string pointer */
        AnsiCopy->lpszQueryString = QueryCopy;
    }

    /* Now that we have the absolute unicode buffer, calculate its size */
    AnsiSize = WSAComputeQuerySetSizeA(AnsiCopy);
    if (AnsiSize > *SetSize)
    {
        /* The buffer wasn't large enough; return how much we need */
        *SetSize = AnsiSize;
        ErrorCode = WSAEFAULT;
        goto error;
    }

    /* Build the relative unicode buffer */
    ErrorCode = WSABuildQuerySetBufferA(AnsiCopy, *SetSize, AnsiSet);

error:
    /* Free the Ansi copy if we had one */
    if (UnicodeCopy) HeapFree(WsSockHeap, 0, UnicodeCopy);

    /* Free all the strings */
    if (ServiceCopy) HeapFree(WsSockHeap, 0, ServiceCopy);
    if (CommentCopy) HeapFree(WsSockHeap, 0, CommentCopy);
    if (ContextCopy) HeapFree(WsSockHeap, 0, ContextCopy);
    if (QueryCopy) HeapFree(WsSockHeap, 0, QueryCopy);

    /* Return error code */
    return ErrorCode;
}

Generated on Sat May 26 2012 05:20:14 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.