⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profile.cpp

📁 WinCE5.0部分核心源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
// Copyright 2001, Cisco Systems, Inc.  All rights reserved.
// No part of this source, or the resulting binary files, may be reproduced,
// transmitted or redistributed in any form or by any means, electronic or
// mechanical, for any purpose, without the express written permission of Cisco.
//
//---------------------------------------------------------------------------
// profile.cpp
//---------------------------------------------------------------------------
// Description:
//
// Revision History:
//
// Date         
//---------------------------------------------------------------------------
// 11/10/00     jbeaujon        -Initial Revision
// 02/21/01     jbeaujon        -use default profile names if none specified.
//
//---------------------------------------------------------------------------

#include "profile.h"
#include "alloc.h"
#include "support.h"
#include "keywords.h"


//---------------------------------------------------------------------------
// Private function prototypes.
//---------------------------------------------------------------------------

BOOLEAN         allocateProfile     (STPROFILE          **profiles, 
                                     USHORT             count,
                                     STPROFILE          **newProf);

USHORT          decodeZFlags        (STPROFILE      *profile, 
                                     UCHAR          *zFlagsBuf);

BOOLEAN         readProfile          (NDIS_HANDLE    ConfigHandle, 
                                     STPROFILE      *profile, 
                                     USHORT         index,
                                     PUSHORT        checkSum);


//===========================================================================
    STPROFILE* addProfile (PCARD              card,
                           PROFILE_PROPERTIES *profileProps)
//===========================================================================
// 
// Description: Add a new profile specifying only the profile properties.
//              All config info (the zflags) are set to 0.
//    
//      Inputs: card            - pointer to card structure.
//              profileProps    - pointer to profile properties
//    
//     Returns: Pointer to new profile if successful, NULL otherwise.
//    
//      (02/22/01)
//---------------------------------------------------------------------------
{
    STPROFILE *newProfile = NULL;
    if (allocateProfile(&card->m_profiles, card->m_numProfiles, &newProfile)) {
        memcpy(&newProfile->properties, profileProps, sizeof(PROFILE_PROPERTIES));
        newProfile->isValid = TRUE;
        // 
        // fix active and current pointers.
        // 
        card->m_activeProfile = &card->m_profiles[card->m_activeProfileIndex];
        card->m_currentProfile = newProfile;
        card->m_numProfiles++;
        }
    return(newProfile);
}

//===========================================================================
    STPROFILE* addProfile (PCARD    card,
                           PROFILE  *profile)
//===========================================================================
// 
// Description: Add a new profile.
//    
//      Inputs: card    - pointer to card structure.
//              profile - pointer to profile data.
//    
//     Returns: Pointer to new profile if successful, NULL otherwise.
//    
//      (02/22/01)
//---------------------------------------------------------------------------
{
    STPROFILE *newProfile = NULL;
    if (allocateProfile(&card->m_profiles, card->m_numProfiles, &newProfile)) {
        memcpy(&newProfile->zFlags.cfg, profile, sizeof(PROFILE));
        newProfile->isValid = TRUE;
        // 
        // fix active and current pointers.
        // 
        card->m_activeProfile = &card->m_profiles[card->m_activeProfileIndex];
        card->m_currentProfile = newProfile;
        card->m_numProfiles++;
        }
    return(newProfile);
}

//===========================================================================
    BOOLEAN getProfiles (NDIS_HANDLE  ConfigHandle, 
                         STPROFILE    **profiles, 
                         PUSHORT      count)
//===========================================================================
// 
// Description: Read all profiles from the registry.
//    
//      Inputs: ConfigHandle    - opaque registry handle
//              zFlags          - pointer to pointer to array of profiles.
//              count           - point to USHORT in which to store the number
//                                of profiles read.
//    
//     Returns: TRUE if successful, FALSE otherwise.
//    
//      (10/27/00)
//---------------------------------------------------------------------------
{
    BOOLEAN retval  = TRUE;
    USHORT  cnt     = 0;

    STPROFILE pf;

    *profiles       = NULL;

    USHORT      checkSum;
    STPROFILE   *newProf;
    // 
    // Loop until we've read all profiles.
    // 
    while (readProfile(ConfigHandle, &pf, cnt, &checkSum)) {

        if (allocateProfile(profiles, cnt, &newProf)) {
            // 
            // copy new profile to array.  Set valid flag based on checksum.
            // 
            memcpy(newProf, &pf, sizeof(STPROFILE));
            newProf->isValid = (checkSum == pf.zFlags.sum);
            // 
            // bump profile count.
            // 
            cnt++;
            }
        else {
            retval = FALSE;
            break;
            }
        }

    *count = cnt;

    return(retval);
}

//===========================================================================
    BOOLEAN allocateProfile (STPROFILE **profiles, USHORT count, STPROFILE **newProf)
//===========================================================================
// 
// Description: Allocate an additional profile at the end of the array of profiles
//              pointed to by "profiles".  The array initially contains "count" 
//              elements.  Upon successful return, the array contains count+1 
//              elements and the contents of the old array have been copied to 
//              the new array.  *newProf will point to the new profile structure
//              at the end of the array.
//    
//      Inputs: profiles    - pointer to pointer to an array of count profile 
//                            structures.  This array is reallocated to 
//                            accomodate one additional profile structure.
//              count       - number of elements in the array.
//              newProf     - used to return a pointer to the new profile (the
//                            last element in the array).
//    
//     Returns: TRUE if successful, FALSE otherwise.
// 
//     Caveats: Since the array of profiles is deallocated and then reallocated, 
//              any pointers referencing individual array elements will be invalid 
//              upon successful return of this function.
//    
//      (02/21/01)
//---------------------------------------------------------------------------
{
    BOOLEAN retval = FALSE;
    if (profiles) {
        // 
        // Save pointer to previous profile array.
        // 
        STPROFILE *saveProfiles = *profiles;
        // 
        // Allocate new array with one additional element.
        // 
        *profiles = new STPROFILE[count + 1];
        if (*profiles) {
            NdisZeroMemory(*profiles, sizeof(STPROFILE) * (count + 1));
            // 
            // copy old array to new if necessary
            // 
            if (saveProfiles) {
                memcpy(*profiles, saveProfiles, sizeof(STPROFILE) * count);
                }
            if (newProf) {
                *newProf = &((*profiles)[count]);
                }
            delete [] saveProfiles;
            retval = TRUE;
            }
        else {
            *profiles   = saveProfiles;
            *newProf    = NULL;
            }
        }

    return(retval);
}

//===========================================================================
    STPROFILE* findProfileByName (char      *name,
                                  STPROFILE *profiles,
                                  USHORT    count,
                                  USHORT    *index)
//===========================================================================
// 
// Description: Find a profile with the specified name in the array of count
//              profiles pointed to by profiles.
//    
//      Inputs: name        - pointer to name of profile to find.
//              profiles    - pointer to array of profiles.
//              count       - number of profiles in array.
//              index       - pointer to USHORT in which the array index of 
//                            profile is returned.
//    
//     Returns: pointer to profile is successful, NULL otherwise.
//    
//      (11/10/00)
//---------------------------------------------------------------------------
{
    STPROFILE *retval = NULL;
    for (USHORT i = 0; i < count; i++) {
        if (strcmp(name, profiles[i].properties.name) == 0) {
            retval = (profiles + i);
            *index = i;
            break;
            }
        }
    return(retval);
}

//===========================================================================
    BOOLEAN readProfile (NDIS_HANDLE  ConfigHandle, 
                         STPROFILE    *profile, 
                         USHORT       index,
                         PUSHORT      checkSum)
//===========================================================================
// 
// Description: Read the specified profile from the registry and store it in
//              the buffer pointed to by profile.
//    
//      Inputs: ConfigHandle    - opaque registry handle
//              profile         - pointer to structure in which to store profile.
//              index           - index of which profile to read.  0 indicates 
//                                the default profile stored in the registry 
//                                under the keys zFlags1, zFlags2, zFlags3, 
//                                zFlags4, zFlags5.  Alternate profiles (index == N, 
//                                where N != 0) are stored under registry keys 
//                                NzFlags1, NzFlags2, NzFlags3, NzFlags4, NzFlags5. 
//              checkSum        - pointer to USHORT in which to store calculated
//                                checksum of zFlags portion of the profile.
//    
//     Returns: TRUE if successful, FALSE otherwise.
//    
//      (10/24/00)
//---------------------------------------------------------------------------
{

    int i;
    // 
    // Assume failure.
    // 
    BOOLEAN retval = FALSE;

    char prefix[33]; // should be plenty big enough.
    NdisZeroMemory(prefix, sizeof(prefix));
    // 
    // Index of 0 uses the default zFlag keys (i.e. no prefix).
    // For index > 0 we prefix the index on the default registry keys.
    // 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -