syncmltransport.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,990 行 · 第 1/5 页

CPP
1,990
字号

#if 0
    if (ret == 0) {
        // MessageBox (NULL, TEXT("Sync succesfully done"), TEXT ("Debug"), MB_SETFOREGROUND |MB_OK);
    }
    else {
        //MessageBox (NULL, TEXT("Sync failed"), TEXT ("Debug"), MB_SETFOREGROUND |MB_OK);
    }
#endif
/*
    while(TRUE)
    {
        // Do we need to prompt for account info?
        if(cTries || *pCurrentCreds->pszPassword == L'\0')
        {
            SYNCCREDENTIALS * pNewCreds = NULL;



            // Make a request to the Inbox for logon credentials.
            hr = m_pCallback->RequestCredentials(m_pszProfile, pCurrentCreds, &pNewCreds);
            if(FAILED(hr))
            {
                // Log an error...
                if (!m_fShutDown)
                {
                    LogErrorEvent(CEMAPI_E_NO_ACCOUNT_INFO, 0);
                }

                break;
            }

            // pNewCreds now contains the new info from the user.
            ASSERT(pNewCreds != NULL);

            // Check to see if 'pCurrentCreds' is *not* the ones passed in.
            // If they are not, then we need to free them.  This will happen
            // if the user has been asked more than once for the password.
            if(pCurrentCreds != pCredentials)
            {
                m_pCallback->FreeMem(pCurrentCreds);
            }

            pCurrentCreds = pNewCreds;
        }

        // Now try to connect to the mail server
        // [ Omitted ]
        // [ Assumed to return hr ]
        if(FAILED(hr))
        {
            if (!m_fShutDown)
            {
                LogErrorEvent(hr, 0);
            }

            break;
        }

        if(m_fShutDown)
        {
            hr = E_FAIL;
            break;
        }

        // Log in to the mail server
        SetStatusText(0): //IDS_TRANSPORT_CONNECTING);     // TODO:  Use an appropriate string resource
        // [ Omitted ]
        // [ Assumed to return hr ]

        // If the logon succeeded, we're done
        if(SUCCEEDED(hr))
        {
            break;
        }

        // If we failed due to anything but authentication errors,
        // log the error and bail out
        if(hr != E_ACCESSDENIED)
        {
            // Log an error back to the application if user didn't himself ask for shutdown
            if (!m_fShutDown)
            {
                LogErrorEvent(hr, 0);
            }

            break;
        }

        // No success!  Need to hang up and ask the user for new
        // credentials.

        ++cTries;

        // Disconnect from the mail server
        // [ Omitted ]
        // [ Assumed to return hr ]

    }   // while(TRUE)

*/
    /*
    checkNetwork();
    getIPAddress(ipaddress);
    if (wcscmp(ipaddress, IP_ADDRESS_PPC) == 0 ||
        wcscmp(ipaddress, IP_ADDRESS_WM5) == 0   ) {

    int ret = MessageBox (NULL, ASK_PERFORM_SYNC, TEXT ("Funambol Sync"), MB_SETFOREGROUND | MB_YESNO | MB_ICONQUESTION);

        if (ret == IDNO)
            toSyncNow = FALSE;
            //hr = E_FAIL;
    }
    */

    if(FAILED(hr))
    {
        // Disconnect from the mail server
        // [ Omitted ]
        // [ Assumed to return hr ]
    }

    return hr;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::Disconnect()
//
//  Description:
//      This DLL entry point is used by the Inbox to disconnect the
//      transport from the network.
//
//  Parameters:
//      dwReserved          IN  Reserved
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::Disconnect(
    DWORD dwReserved
    )
{
    //MessageBox (NULL, TEXT("Disconnect"), TEXT ("debug"), MB_SETFOREGROUND |MB_OK);

    HRESULT hr = S_OK;
    /*
    // Set the Inbox status bar to display "Disconnecting..."
    SetStatusText(0);   //IDS_TRANSPORT_DISCONNECTING    // TODO:  Use an appropriate string resource

    // Shut down the connection watching thread
    SetEvent(m_hEventShutdown);

    // Clear the Wastebasket if the option is set
    if(m_nDeleteAction != DELACTION_MANUALLY)
    {
        // Call a utility function to empty the Deleted Items folder
        // [ Omitted ]
        // [ Assumed to return hr ]
    }

    // Disconnect from the mail server
    // [ Omitted ]
    // [ Assumed to return hr ]
    */
    return hr;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::DoProperties()
//
//  Description:
//      This DLL entry point is used by the Inbox to display a properties
//      dialog for the service.
//
//  *** NOTE ***  Pocket PC 2002 does not use this.
//
//  Parameters:
//      hwndParent  IN  Parent window
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::DoProperties(HWND hwndParent)
{
    //MessageBox(NULL, L"DoProperties", L"TransportDemo", MB_OK);

    return S_OK;
    //return S_FALSE;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::GetCapability()
//
//  Description:
//      This DLL entry point is used by the Inbox to query the transport
//      for various settings and limits.
//
//      cemapi.h defines these capabilities:
//
//      kszCapAmountToFetch         -   Number of bytes to fetch for each message
//      kszCapAttachAmount          -   Attachment fetch size limit(transport should
//                                      skip attachments greater than this size)
//      kszCapAgeFilter             -   Number of days of mail to sync(older mail
//                                      should age off device or not be retrieved)
//      kszCapFolders               -   Non-zero if the transport can sync folders.
//      kszSyncHierarchy            -   Non-zero if the transport can sync folders.
//      kszCapDeleteAction          -   DELACTION_MANUALLY or DELACTION_IMMEDIATELY.
//                                      If set to manual, deletes go to the trash folder
//                                      and the user is responsible for deleting them.
//                                      If set to immediately, deletes happen immediately.
//
//  Parameters:
//      pszName         IN      String identifying the capability being queried
//      pval            OUT     Value of the capability being queried
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::GetCapability(
    LPCWSTR pszName,
    LPSPropValue pval
    )
{
    HRESULT     hr      =   S_OK;

    if ((!pszName) ||(!pval))
    {
        return E_INVALIDARG;
    }
/*
if(_tcscmp(pszName,kszCapHTMLMail                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAmountToFetch                 ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAttachAmount                  ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAgeFilter                     ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSaveSent                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSMSUnicode                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSMTPAuthenticate              ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapIncludeOriginal               ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapIndentBody                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAddLeading                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapLeadChar                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSyncMsgClasses                ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSyncMsgClassDef               ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapPropDialog                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSyncHierarchy                 ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapDeleteAction                  ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapMoveToTrash                   ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapReturnAddress                 ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapCreateSpecialFldrs            ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolders                       ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolderNotifications           ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapClearAll                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapEmptyDeleteItem               ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapEditProperties                ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolderOptions                 ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapMgmtFolder                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSync                          ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapSyncOnDockEvent               ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapConnect                       ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapRequireRadio                  ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapMarkAttachments               ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapReplyAll                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAlwaysIncludeOriginal         ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapCompose                       ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapOfflineStatus                 ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapCallSender                    ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapLanguage                      ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapAttachments                   ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolderManagementAllowCreate   ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolderManagementAllowRename   ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
if(_tcscmp(pszName,kszCapFolderManagementAllowDelete   ) == 0) {LOG.debug("Property name: %S. Value: %ul", pszName,pval->Value.ul); }
*/
    // Test pszName against the specific capability strings that the
    // transport supports, and return the requested value when a match
    // is found.  If no match is found, return MAPI_E_NOT_FOUND.
    // [ Omitted ]
    //MessageBox(0, pszName, L"GetCapability", MB_OK);

    /*
    * This property allows to show the UI to modify the parameters
    * if the value is 0 the default appears, if the value is 1 the custom appears.
    * The custom must be implmented into DoProperties method
    * HRESULT CTransportSyncHandler::DoProperties(HWND hwndParent)
    */

    if(_tcscmp(pszName, kszCapPropDialog) == 0) {
        pval->Value.ul = 0;
        return S_OK;
    }


    //
    // Disable the sync on dock event. Default is TRUE. We set to FALSE
    //
    if(_tcscmp(pszName, kszCapSyncOnDockEvent) == 0) {
        pval->Value.ul = 0;
        return S_OK;
    }

    //
    // Allows to create new mail. Default is TRUE. Maybe changing the kszCapSyncOnDockEvent
    // we must reset it too
    //
    if(_tcscmp(pszName, kszCapCompose) == 0) {
        pval->Value.ul = 1;
        return S_OK;
    }
    
    //
    // Allows to reply all: default is TRUE. Maybe changing the kszCapSyncOnDockEvent
    // we must reset it too
    //
    if(_tcscmp(pszName, kszCapReplyAll) == 0) {
        pval->Value.ul = 1;
        return S_OK;
    }
// to make available the account into the meetting request accounts...
    /*
    if(_tcscmp(pszName, kszCapCannotSendMeetingRequests) == 0) {
        pval->Value.ul = 0;
        return S_OK;
    }
    */

#if _WIN32_WCE > 0x501    
    if(_tcscmp(pszName, kszCapConnectHomeNetwork) == 0) {
        pval->Value.ul = 1;
        return S_OK;
    }    
#endif
    //
    // It disables the capability to manage folders...
    //
    /*
    if(_tcscmp(pszName, kszCapMgmtFolder) == 0) {
        pval->Value.ul = 0;
        return S_OK;
    }


    if(_tcscmp(pszName, kszCapAmountToFetch) == 0) {
        LOG.debug("kszCapAmountToFetch %ul", pval->Value.ul);
        return S_OK;
    }

    if(_tcscmp(pszName, kszCapAttachAmount) == 0) {
        LOG.debug("kszCapAttachAmount %ul", pval->Value.ul);
        return S_OK;
    }

    if(_tcscmp(pszName, kszCapAttachAmount) == 0) {
        LOG.debug("kszCapAttachAmount %ul", pval->Value.ul);
        return S_OK;
    }
    */

    return hr;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::SetCapability()
//
//  Description:
//      This DLL entry point is used by the Inbox to set various settings
//      and limits in the transport.  This is called when the user makes an
//      alteration(e.g. via the wizard) to a service that uses this transport.
//
//      See GetCapability() for a list of capabilities.
//
//  Parameters:
//      pszName         IN      String identifying the capability being queried
//      pval            IN      Value of the capability being queried
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::SetCapability(
    LPCWSTR pszName,
    LPSPropValue pval
    )
{
    ULONG   *   pnVal   =   NULL;
    HRESULT     hr      =   S_OK;

    if ((pszName == NULL) ||(pval == NULL))
    {

⌨️ 快捷键说明

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