コード例 #1
0
ファイル: nsquery.c プロジェクト: RareHare/reactos
DWORD
WSAAPI
WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
                       IN LPWSAQUERYSETW Restrictions,
                       IN DWORD ControlFlags,
                       IN PNSCATALOG Catalog)
{
    WSASERVICECLASSINFOW ClassInfo;
    PNSQUERY_PROVIDER Provider;
    LPWSASERVICECLASSINFOW pClassInfo = NULL;
    PNSQUERY_PROVIDER NextProvider;
    PLIST_ENTRY Entry;
    INT ErrorCode;
    DWORD ClassInfoSize;
    PNSCATALOG_ENTRY CatalogEntry;
    ENUM_CONTEXT EnumContext;
    BOOLEAN TryAgain;

    /* Check for RAS Auto-dial attempt */
    if (NsQuery->TryAgain)
    {
        /* Make a copy of the query set */
        ErrorCode = CopyQuerySetW(Restrictions, &NsQuery->QuerySet);
        TryAgain = (ErrorCode == ERROR_SUCCESS);

        /* Check if we'll try again */
        if (!TryAgain)
        {
            /* We won't, fail */
            SetLastError(ErrorCode);
            ErrorCode = SOCKET_ERROR;
            NsQuery->TryAgain = FALSE;
            goto error;
        }

        /* Cache the information for a restart */
        NsQuery->ControlFlags = ControlFlags;
        NsQuery->Catalog = Catalog;
    }
    
    /* Check if we have a specific ID */
    if (Restrictions->lpNSProviderId)
    {
        /* Get the provider */
        ErrorCode = WsNcGetCatalogFromProviderId(Catalog,
                                                 Restrictions->lpNSProviderId,
                                                 &CatalogEntry);
        /* Check for success */
        if (ErrorCode != ERROR_SUCCESS)
        {
            /* Fail */
            SetLastError(WSAEINVAL);
            ErrorCode = SOCKET_ERROR;
            goto error;
        }
        else
        {
            /* Add this provider */
            WsNqAddProvider(NsQuery, CatalogEntry->Provider);
        }
    }
    else
    {
        /* Setup the lookup context */
        EnumContext.lpqsRestrictions = Restrictions;
        EnumContext.ErrorCode = ERROR_SUCCESS;
        EnumContext.NsQuery = NsQuery;
        EnumContext.Catalog = Catalog;

        /* Do a lookup for every entry */
        WsNcEnumerateCatalogItems(Catalog,
                                  WsNqBeginEnumerationProc,
                                  &EnumContext);
        ErrorCode = EnumContext.ErrorCode;
        
        /* Check for success */
        if (ErrorCode != ERROR_SUCCESS)
        {
            /* Fail */
            SetLastError(WSAEINVAL);
            ErrorCode = SOCKET_ERROR;
            goto error;
        }
    }

    /* Get the class information */
    ClassInfo.lpServiceClassId = Restrictions->lpServiceClassId;
    ErrorCode = WsNcGetServiceClassInfo(Catalog, &ClassInfoSize, &ClassInfo);

    /* Check if more buffer space is needed */
    if ((ErrorCode == SOCKET_ERROR) && (GetLastError() == WSAEFAULT))
    {
        /* FIXME: The WS 2.2 spec hasn't been finalized yet on this... */
    }
    else
    {
        /* Assume sucess */
        ErrorCode = ERROR_SUCCESS;
    }

    /* Check if the provider list is empty */
    if (IsListEmpty(&NsQuery->ProviderList))
    {
        /* We don't have any providers to handle this! */
        ErrorCode = SOCKET_ERROR;
        SetLastError(WSASERVICE_NOT_FOUND);
        goto error;
    }

    /* Get the first provider and loop */
    Entry = NsQuery->ProviderList.Flink;
    NextProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
    while (NextProvider)
    {
        /* Call it */
        ErrorCode = WsNqProvLookupServiceBegin(NextProvider,
                                               Restrictions,
                                               pClassInfo,
                                               ControlFlags);
        /* Check for error */
        if (ErrorCode == SOCKET_ERROR)
        {
            /* Remove this provider, get the next one, delete the old one */
            Provider = NextProvider;
            NextProvider = WsNqNextProvider(NsQuery, NextProvider);
            RemoveEntryList(&Provider->QueryLink);
            WsNqProvDelete(Provider);
        }
        else
        {
            /* Get the next provider */
            NextProvider = WsNqNextProvider(NsQuery, NextProvider);
        }
    }

error:
    /* Check if we had an error somewhere */
    if (ErrorCode == SOCKET_ERROR)
    {
        /* Loop the list */
        while (!IsListEmpty(&NsQuery->ProviderList))
        {
            /* Remove this provider */
            Entry = RemoveHeadList(&NsQuery->ProviderList);

            /* Get the failed provider and delete it */
            Provider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
            WsNqProvDelete(Provider);
        }
    }
    else
    {
        /* Set the active provider */
        Entry = NsQuery->ProviderList.Flink;
        NsQuery->ActiveProvider = CONTAINING_RECORD(Entry,
                                                    NSQUERY_PROVIDER,
                                                    QueryLink);
    }

    /* Return */
    return ErrorCode;
}
コード例 #2
0
ファイル: dprocess.c プロジェクト: Moteesh/reactos
VOID
WSAAPI
WsProcDelete(IN PWSPROCESS Process)
{
    /* Check if we didn't even initialize yet */
    if (!Process->LockReady) return;

    /* No more current process */
    CurrentWsProcess = NULL;

    /* If we have a socket table */
    if (WsSockHandleTable)
    {
        /* Enumerate the sockets with a delete callback */
        WahEnumerateHandleContexts(WsSockHandleTable,
                                   WsSockDeleteSockets,
                                   Process);
    }

    /* Close APC Helper */
    if (Process->ApcHelper) WahCloseApcHelper(Process->ApcHelper);

    /* Close handle helper */
    if (Process->HandleHelper) WahCloseHandleHelper(Process->HandleHelper);

    /* Check for notification helper */
    if (Process->NotificationHelper)
    {
        /* Close notification helper */
        WahCloseNotificationHandleHelper(Process->NotificationHelper);
    }

    /* Check if we have a protocol catalog*/
    if (Process->ProtocolCatalog)
    {
        /* Enumerate it to clean it up */
        WsTcEnumerateCatalogItems(Process->ProtocolCatalog,
                                  CleanupProtocolProviders,
                                  NULL);

        /* Delete it */
        WsTcDelete(Process->ProtocolCatalog);
        Process->ProtocolCatalog = NULL;
    }

    /* Check if we have a namespace catalog*/
    if (Process->NamespaceCatalog)
    {
        /* Enumerate it to clean it up */
        WsNcEnumerateCatalogItems(Process->NamespaceCatalog,
                                  CleanupNamespaceProviders,
                                  NULL);

        /* Delete it */
        WsNcDelete(Process->NamespaceCatalog);
        Process->NamespaceCatalog = NULL;
    }

    /* Delete the thread lock */
    DeleteCriticalSection(&Process->ThreadLock);

    /* Delete us */
    HeapFree(WsSockHeap, 0, Process);
}