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

📄 rilsimtkittext.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            delete[] pbFileData;
            pbFileData = NULL;

            // Check for a separating comma unless this is the last file to parse.
            if (dwCurrentFile != (dwNumFiles - 1))
            {
                if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
                {
                    hr = E_FAIL;
                    goto Exit;
                }
            }
        }

    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Parsing successful, set proper values for build command functions

    *pbFifthByte = (BYTE)dwRefMode;
    
    if (pdwFileList)
    {
        m_pdwFiles = pdwFileList;
        m_dwNumFiles = dwNumFiles;
    }

Exit:
    if (FAILED(hr))
    {
        delete[] pbFileData;
        delete[] pdwFileList;
    }
    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseRefresh\r\n")));
    return hr;
}


HRESULT CRilSimToolkitCommand::ParseEventList(void)
{
    BYTE* pbParse;
    LPBYTE pbEventList = NULL;
    size_t cbEventListSize = 0;
    DWORD dwLength;
    HRESULT hr = S_OK;

    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseEventList\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the Event List notification should be in the form of:
    //
    // ,<eventList>
    //
    //The event list is encoded as a string of hex bytes.
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Get the string encoded hex for the event list and convert it to bytes
    // Memory allocated: We must manage the memory returned in pbFileData.
    if (!ParseBytes(pbParse, pbEventList, cbEventListSize, pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Parsing successful, set proper values for build command functions
    m_lpbEventList = pbEventList;
    m_dwEventListLen = cbEventListSize;

Exit:
    if (FAILED(hr))
    {
        delete[] pbEventList;
    }

    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseEventList\r\n")));
    return hr;
}

HRESULT CRilSimToolkitCommand::ParseLaunchBrowser(BYTE* pbFifthByte)
{
    BYTE* pbParse;
    BYTE* pbBearerData = NULL;
    DWORD dwLength;
    DWORD dwDCS;
    DWORD dwCmdQualifier;
    LPWSTR wszURL = NULL;
    LPWSTR wszGateway = NULL;
    LPWSTR wszAlphaId = NULL;
    size_t cbURLSize = 0;
    size_t cbBearerSize = 0;
    size_t cbGatewaySize = 0;
    size_t cbAlphaIdSize = 0;
    DWORD dwBrowserId;
    DWORD dwIconID = SIMTKIT_INVALID_VALUE;
    DWORD dwDispMode = SIMTKIT_INVALID_VALUE;
    BOOL fBrowserId = FALSE;
    BOOL fDCS = FALSE;
    DWORD dwNumFiles = 0;
    UINT uCurFile;
    HRESULT hr = S_OK;
    BOOL fKeepParsing = TRUE;
    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseLaunchBrowser\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the Launch Browser notification should be in the form of:
    //
    // ,<comQual>,<url>
    // [,<browserId>
    // [,<bearer>
    // [,<numFiles>,<provFiles>
    // [,<dcs>,<gateway>
    // [,<alphaId>
    // [,<iconId>,<dispMode>]]]]]]

    // Parse the command qualifier.
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseHexDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_LEADINGZERO, dwCmdQualifier, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        hr = E_FAIL;
        goto Exit;
    }
        
    // Parse the mandatory URL. The URL may be blank, signifying the use of the
    // default URL.
    ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_UNPACKED, wszURL, cbURLSize, pbParse);

    // Optional: ,
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        fKeepParsing = FALSE;        
    }
    
    //  Optional: <browserId>
    if (fKeepParsing)
    {
        fBrowserId = ParseHexDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_LEADINGZERO, dwBrowserId, (LPCSTR&)pbParse);
    }

    if (fKeepParsing)
    {
        // Optional: ,
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }    
    }

    if (fKeepParsing)
    {
        // <bearer>
        // Get the string encoded hex for the file and convert it to bytes
        // Memory allocated: We must manage the memory returned in pbFileData.
        ParseBytes(pbParse, pbBearerData, cbBearerSize, pbParse);
    }
    
    if (fKeepParsing)
    {
        // Optional: ,
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }    
    }

    if (fKeepParsing)
    {
        // Optional: <numFiles>
        ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwNumFiles, (LPCSTR&)pbParse);
    }

    if (fKeepParsing &&  (0 < dwNumFiles))
    {
        // if there are files listed, a comma here is required.
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }

        // Loop through parsing all files.
        // Create space for a list of pointers to files
        m_rgpsfr = new LPSIMFILEREFERENCE[dwNumFiles];
        if (!m_rgpsfr)
        {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        // Parse through and add files.
        // ---------------------------------
        // The list of files we receive from the radio is indexed
        // starting at 1.
        for (uCurFile = 1; uCurFile <= dwNumFiles ; uCurFile++)
        {
            if ( FAILED(ParseProvisionFile(pbParse)) )
            {
                hr = E_FAIL;
                goto Exit;
            }
            if (uCurFile != dwNumFiles)
            {
                // Check for comma on all except last.
                if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
                {
                    hr = E_FAIL;
                    goto Exit;
                }
            }
        }
    }
    else if (fKeepParsing)
    {
        // Optional: , (after numFiles)
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }    
    }

    if (fKeepParsing)
    {
        // Optional: , (after Provisioning files)
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }    
    }

    if (fKeepParsing)
    {
        // Optional: <dcs>
        fDCS = ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDCS, (LPCSTR&)pbParse);
    }
    
    if (fKeepParsing && fDCS)
    {
        // If DCS is set, comma is required.
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }
        
        // If DCS is set, <gateway> is required.
        if (!ParseEncodedText(pbParse, dwDCS, wszGateway, cbGatewaySize, pbParse)) 
        {
            hr = E_FAIL;
            goto Exit;
        }
    }
    else if (fKeepParsing)
    {
        // Optional: , (after DCS)
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }            
    }

    if (fKeepParsing)
    {
        // Optional: , (after Gateway)
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            fKeepParsing = FALSE;        
        }    
    }

    if (fKeepParsing)
    {
        // Optional: <alphaId>
        ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszAlphaId, cbAlphaIdSize, pbParse);
    }

    if (fKeepParsing)
    {
        // Optional:
        //[,<iconId>,<dispMode>]
        if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            // <iconID>
            if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwIconID, (LPCSTR&)pbParse)) 
            {
                hr = E_FAIL;
                goto Exit;
            }
            
            // ,<dispMode>
            if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
                !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDispMode, (LPCSTR&)pbParse)) 
            {
                hr = E_FAIL;
                goto Exit;
            }        
        }
    }
    
    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }
    // Parsing successful, set proper values for build command functions
    *pbFifthByte = (BYTE)dwCmdQualifier;
    m_pwszURL = wszURL;
    m_dwURLLen = cbURLSize;
    if(fBrowserId)
    {
        m_dwBrowserId = dwBrowserId;
    }
    m_lpbBearer = pbBearerData;
    m_dwBearerLen = cbBearerSize;
    m_numpsfr = dwNumFiles;
    m_pwszText = wszGateway;
    m_dwTextLen = cbGatewaySize;
    m_pwszAlphaId = wszAlphaId;
    m_dwAlphaIdLen = cbAlphaIdSize;

    if (SIMTKIT_INVALID_VALUE != dwIconID)
    {
        m_dwIconIdentifier = dwIconID;
    }

    if (SIMTKIT_INVALID_VALUE != dwDispMode)
    {
        m_dwIconQualifier = dwDispMode;
    }

Exit:
    if (FAILED(hr))
    {
        delete[] wszURL;
        delete[] pbBearerData;
        delete[] wszGateway;
        delete[] wszAlphaId;

        if (NULL != m_rgpsfr)
        {
            // Free memory
            for (UINT i = 0; i < m_numpsfr; i++)
            {
                delete m_rgpsfr[i];
            }
            delete m_rgpsfr;
            m_rgpsfr = NULL;
        }
        m_numpsfr = 0;
    }

    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseLaunchBrowser\r\n")));
    return hr;
}

HRESULT CRilSimToolkitCommand::ParseProvisionFile(LPBYTE& rpbParse)
{
    HRESULT hr = S_OK;
    BYTE* pbFileData = NULL;
    size_t cbFileSize = 0;
    DWORD dwSize;    
    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseProvisionFile\r\n")));

    // A Provision file is a list of bytes.
    if (!ParseBytes(rpbParse, pbFileData, cbFileSize, rpbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    dwSize = ROUNDTODWORD(sizeof(SIMFILEREFERENCE)) + ROUNDTODWORD(cbFileSize);
    m_rgpsfr[m_numpsfr] = NULL;
    m_rgpsfr[m_numpsfr] = (SIMFILEREFERENCE *) new BYTE[dwSize];

    if (NULL != m_rgpsfr[m_numpsfr])
    {
        memset(m_rgpsfr[m_numpsfr], 0, dwSize);
        m_rgpsfr[m_numpsfr]->cbSize = dwSize;
        m_rgpsfr[m_numpsfr]->dwParams = SIM_PARAM_SIMFILEREFERENCE_ALL;
        m_rgpsfr[m_numpsfr]->dwFileSize = cbFileSize;
        m_rgpsfr[m_numpsfr]->dwFileOffset = ROUNDTODWORD(sizeof(SIMFILEREFERENCE));
        memcpy(((LPBYTE) m_rgpsfr[m_numpsfr] + m_rgpsfr[m_numpsfr]->dwFileOffset), pbFileData, cbFileSize);

        // Great, we added this file, so increase the count
        m_numpsfr++;
    }
    else
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

Exit:
    delete[] pbFileData;        

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseProvisionFile\r\n")));

    return hr;
}

⌨️ 快捷键说明

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