?? syncmltransport.cpp
字號:
// [ Assumed to return hr ]
break;
default:
break;
}
}
if(hr == E_OUTOFMEMORY)
{
LogErrorEvent(E_OUTOFMEMORY, TRUE);
}
if(FAILED(hr) &&(pRqst == NULL || pRqst->ffFlags == SYNC_NORMAL))
{
//Get the body fetch thread to close now
m_fShutDown = TRUE;
// to disconnect after sync
//SendProgressMessage(SYNCPROGRESSITEM_DISCONNECTED);
}
ASSERT(m_pszProfile);
return hr;
}
//Simply get the value of the HKLM\Software\Funambol\SyncclientPIM
//put it in a buffer and cancel the value in the registry
wchar_t* CTransportSyncHandler::getValueFromReg(wchar_t* regval){
HKEY key = NULL;
DWORD res;
long err = 0;
wchar_t* buf = NULL;
ULONG dim = 0;
RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("Software\\") ROOT_CONTEXT_W,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key,
&res
);
if (key == 0) {
goto finally;
}
// Get value length
err = RegQueryValueEx(
key,
regval,
NULL,
NULL, // we currently support only strings
NULL,
&dim
);
if (err == ERROR_SUCCESS) {
if (dim > 0) {
buf = new wchar_t[dim + 1];
err = RegQueryValueEx(
key,
regval,
NULL,
NULL, // we currently support only strings
(UCHAR*)buf,
&dim
);
}
RegDeleteValue(key, regval);
}
finally:
if (key != 0) {
RegCloseKey(key);
}
return buf;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::ShutDown()
//
// Description:
// This DLL entry point is used by the Inbox to shut down the transport
// object. Perform any clean-up or thread signalling here. After this
// function returns, Inbox will likely Release() the IMailSyncHandler*.
//
// Parameters:
// dwReserved IN Reserved.
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::ShutDown(
DWORD dwReserved
)
{
HRESULT hr = S_OK;
//HWND wnd = FindWindow(NULL, _T("Funambol plug-in"));
HWND wnd = HwndFunctions::getWindowHandle();
Sleep(1000);
if(wnd == NULL){
startcmd(PROVIDER_W _T(".exe"), TEXT(""));
};
if(wnd != NULL) {
SetForegroundWindow(wnd);
}
m_fShutDown = TRUE;
SetEvent(m_hEventShutdown);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Install()
//
// Description:
// This DLL entry point is used by the Inbox to create a new service
// using this transport.
//
// Parameters:
// pszProfileName IN Name of the new service
// pszIncomingServer IN Name of the incoming server
// pszOutgoingServer IN Name of the outgoing server
// pidNetwork IN GUID that identifies the connection manager
// network to use to connect to these servers
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::Install
(
LPCWSTR pszProfileName,
LPCWSTR pszIncomingServer,
LPCWSTR pszOutgoingServer,
GUID * pidNetwork
)
{
HRESULT hr = S_OK;
//MessageBox(NULL, L"Install", L"TransportDemo", MB_SETFOREGROUND|MB_OK);
//MessageBox(NULL, pszProfileName, L"TransportDemo", MB_OK);
//MessageBox(NULL, pszIncomingServer, L"TransportDemo", MB_OK);
//MessageBox(NULL, pszOutgoingServer, L"TransportDemo", MB_OK);
// Most transports create a profile key in the registry and
// store these settings under that key.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::UnInstall()
//
// Description:
// This DLL entry point is used by the Inbox to remove a service that
// uses this transport.
//
//
// *** NOTE ***
// This is currently not used by Inbox.
//
//
// Parameters:
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::UnInstall()
{
HRESULT hr = S_OK;
//MessageBox(NULL, L"Uninstall", L"TransportDemo", MB_OK);
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Connect()
//
// Description:
// This DLL entry point is used by the Inbox to connect to the
// network identified by the pidNetwork parameter passed to
// the Install() method when the service was created.
//
// Parameters:
// dwReserved IN Reserved
// pCredentials IN Account credentials specified by the user
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::Connect(
DWORD dwReserved,
SYNCCREDENTIALS* pCredentials
)
{
HRESULT hr = S_OK;
SYNCCREDENTIALS * pCurrentCreds = pCredentials;
ULONG cTries = 0;
//MessageBox(NULL, L"Connect", L"SyncMLTransport", MB_OK);
// The transport is no longer shut down
// ASSERT(m_hEventShutdown != NULL);
m_fShutDown = FALSE;
// ResetEvent(m_hEventShutdown);
#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;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -