JUST ADDING CODE - NOT PART OF THE BUILD

This commit is contained in:
rhp%netscape.com 2000-05-09 04:11:11 +00:00
parent 7ec100ab59
commit dd7eebdfff
12 changed files with 331 additions and 20 deletions

View File

@ -72,5 +72,15 @@
#define NS_ABSYNC_POST_LISTENER_PROGID \
"component://netscape/absync/postlistener"
//
// Sync Driver
//
#define NS_ADDBOOK_SYNCDRIVER_PROGID \
"component://netscape/addressbook/services/syncdriver"
#define NS_ADDBOOK_SYNCDRIVER_CID \
{ /* 40D1D3DA-1637-11d4-8FE1-00A024A7D144 */ \
0x40d1d3da, 0x1637, 0x11d4, \
{ 0x8f, 0xe1, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 } \
}
#endif // nsAbSyncCID_h__

View File

@ -36,8 +36,10 @@
#include "nsAbSync.h"
#include "nsAbSyncPostEngine.h"
#include "nsABSyncDriver.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbSync);
// NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbSyncPostEngine);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbSyncDriver)
////////////////////////////////////////////////////////////
//
@ -52,7 +54,11 @@ static nsModuleComponentInfo components[] =
{ "Addressbook Sync Post Engine",
NS_ABSYNC_POST_ENGINE_CID,
NS_ABSYNC_POST_ENGINE_PROGID,
nsAbSyncPostEngine::Create }
nsAbSyncPostEngine::Create },
{ "The Address Book Sync Driver",
NS_ADDBOOK_SYNCDRIVER_CID,
NS_ADDBOOK_SYNCDRIVER_PROGID,
nsAbSyncDriverConstructor }
};
NS_IMPL_NSGETMODULE("nsAbSyncModule", components)

View File

@ -36,6 +36,7 @@ XPIDLSRCS = \
nsIAbSyncListener.idl \
nsIAbSyncPostEngine.idl \
nsIAbSyncPostListener.idl \
nsIAbSyncDriver.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -28,6 +28,7 @@ XPIDLSRCS=\
.\nsIAbSyncListener.idl \
.\nsIAbSyncPostEngine.idl \
.\nsIAbSyncPostListener.idl \
.\nsIAbSyncDriver.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsrootidl.idl"
#include "nsIAbSyncListener.idl"
#include "nsIMsgStatusFeedback.idl"
[scriptable, uuid(91FDFEE1-EFBC-11d3-8F97-000073757374)]
interface nsIAbSyncDriver : nsIAbSyncListener
{
void KickIt(in nsIMsgStatusFeedback aStatus);
};

View File

@ -33,12 +33,14 @@ CPPSRCS = \
nsAbSyncPostEngine.cpp \
nsAbSync.cpp \
nsAbSyncCRCModel.cpp \
nsABSyncDriver.cpp \
$(NULL)
EXPORTS = \
nsAbSyncPostEngine.h \
nsAbSync.h \
nsAbSyncCRCModel.h \
nsABSyncDriver.h \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

View File

@ -31,6 +31,7 @@ EXPORTS= nsAbSyncPostEngine.h \
nsAbSync.h \
nsAbSyncCRCModel.h \
nsSyncDecoderRing.h \
nsABSyncDriver.h \
$(NULL)
################################################################################
@ -42,6 +43,7 @@ CPP_OBJS= .\$(OBJDIR)\nsAbSyncPostEngine.obj \
.\$(OBJDIR)\nsAbSync.obj \
.\$(OBJDIR)\nsAbSyncCRCModel.obj \
.\$(OBJDIR)\nsSyncDecoderRing.obj \
.\$(OBJDIR)\nsABSyncDriver.obj \
$(NULL)

View File

@ -0,0 +1,162 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsABSyncDriver.h"
#include "nsIAbSync.h"
#include "nsAbSyncCID.h"
#include "nsIServiceManager.h"
#include "nsTextFormatter.h"
#include "nsIStringBundle.h"
#include "prmem.h"
NS_IMPL_ISUPPORTS1(nsAbSyncDriver, nsIAbSyncDriver)
static NS_DEFINE_CID(kAbSync, NS_ABSYNC_SERVICE_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
nsAbSyncDriver::nsAbSyncDriver()
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
mTransactionID = -1;
mStatus = nsnull;
}
nsAbSyncDriver::~nsAbSyncDriver()
{
/* destructor code */
}
/* void OnStartOperation (in PRInt32 aTransactionID, in PRUint32 aMsgSize); */
NS_IMETHODIMP nsAbSyncDriver::OnStartOperation(PRInt32 aTransactionID, PRUint32 aMsgSize)
{
if (mStatus)
{
PRUnichar *outValue = nsnull;
PRUnichar *msgValue = nsnull;
// Tweak the button...
mStatus->StartMeteors();
outValue = GetString(NS_ConvertASCIItoUCS2("syncStarting").GetUnicode());
msgValue = nsTextFormatter::smprintf(outValue, aMsgSize);
mStatus->ShowStatusString(msgValue);
PR_FREEIF(outValue);
PR_FREEIF(msgValue);
}
return NS_OK;
}
/* void OnProgress (in PRInt32 aTransactionID, in PRUint32 aProgress, in PRUint32 aProgressMax); */
NS_IMETHODIMP nsAbSyncDriver::OnProgress(PRInt32 aTransactionID, PRUint32 aProgress, PRUint32 aProgressMax)
{
if (mStatus)
{
PRUnichar *outValue = nsnull;
PRUnichar *msgValue = nsnull;
outValue = GetString(NS_ConvertASCIItoUCS2("syncProgress").GetUnicode());
msgValue = nsTextFormatter::smprintf(outValue, aProgress);
mStatus->ShowStatusString(msgValue);
PR_FREEIF(outValue);
PR_FREEIF(msgValue);
}
return NS_OK;
}
/* void OnStatus (in PRInt32 aTransactionID, in wstring aMsg); */
NS_IMETHODIMP nsAbSyncDriver::OnStatus(PRInt32 aTransactionID, const PRUnichar *aMsg)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void OnStopOperation (in PRInt32 aTransactionID, in nsresult aStatus, in wstring aMsg); */
NS_IMETHODIMP nsAbSyncDriver::OnStopOperation(PRInt32 aTransactionID, nsresult aStatus, const PRUnichar *aMsg)
{
if (mStatus)
{
PRUnichar *outValue = nsnull;
// Tweak the button...
mStatus->StopMeteors();
if (NS_SUCCEEDED(aStatus))
outValue = GetString(NS_ConvertASCIItoUCS2("syncDoneSuccess").GetUnicode());
else
outValue = GetString(NS_ConvertASCIItoUCS2("syncDoneFailed").GetUnicode());
mStatus->ShowStatusString(outValue);
PR_FREEIF(outValue);
}
return NS_OK;
}
/* void KickIt (); */
NS_IMETHODIMP nsAbSyncDriver::KickIt(nsIMsgStatusFeedback *aStatus)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIAbSync, sync, kAbSync, &rv);
if (NS_FAILED(rv) || !sync)
return rv;
mStatus = aStatus;
// Add ourselves to the party!
sync->AddSyncListener((nsIAbSyncListener *)this);
rv = sync->PerformAbSync(&mTransactionID);
return rv;
}
#define AB_STRING_URL "chrome://messenger/locale/addressbook/addressBook.properties"
PRUnichar *
nsAbSyncDriver::GetString(const PRUnichar *aStringName)
{
nsresult res = NS_OK;
PRUnichar *ptrv = nsnull;
if (!mStringBundle)
{
char *propertyURL = AB_STRING_URL;
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res);
if (NS_SUCCEEDED(res) && (nsnull != sBundleService))
{
nsILocale *locale = nsnull;
res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(mStringBundle));
}
}
if (mStringBundle)
res = mStringBundle->GetStringFromName(aStringName, &ptrv);
if ( NS_SUCCEEDED(res) && (ptrv) )
return ptrv;
else
return nsCRT::strdup(aStringName);
}

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __nsAbSyncDriver_h__
#define __nsAbSyncDriver_h__
#include "nsIAbSyncDriver.h"
#include "nsIMsgStatusFeedback.h"
#include "nsIStringBundle.h"
class nsAbSyncDriver : public nsIAbSyncDriver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIABSYNCDRIVER
NS_DECL_NSIABSYNCLISTENER
nsAbSyncDriver();
virtual ~nsAbSyncDriver();
/* additional members */
PRUnichar *GetString(const PRUnichar *aStringName);
private:
nsCOMPtr<nsIStringBundle> mStringBundle;
PRInt32 mTransactionID;
nsCOMPtr<nsIMsgStatusFeedback> mStatus;
};
#endif /* __nsAbSyncDriver_h__ */

View File

@ -37,6 +37,8 @@
#include "nsSyncDecoderRing.h"
#include "plstr.h"
#include "nsString.h"
#include "nsTextFormatter.h"
#include "nsIStringBundle.h"
static NS_DEFINE_CID(kCAbSyncPostEngineCID, NS_ABSYNC_POST_ENGINE_CID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
@ -45,6 +47,7 @@ static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
/* Implementation file */
NS_IMPL_ISUPPORTS1(nsAbSync, nsIAbSync)
@ -53,6 +56,11 @@ nsAbSync::nsAbSync()
{
NS_INIT_ISUPPORTS();
// For listener array stuff...
mListenerArrayCount = 0;
mListenerArray = nsnull;
mStringBundle = nsnull;
InternalInit();
InitSchemaColumns();
}
@ -61,8 +69,6 @@ void
nsAbSync::InternalInit()
{
/* member initializers and constructor code */
mListenerArray = nsnull;
mListenerArrayCount = 0;
mCurrentState = nsIAbSyncState::nsIAbSyncIdle;
mTransactionID = 100;
mPostEngine = nsnull;
@ -470,17 +476,6 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(PRInt32 *aTransactionID)
if (NS_FAILED(rv))
goto EarlyExit;
//
// if we have nothing in mPostString, then we can just return OK...no
// sync was needed
//
// if (mPostString.IsEmpty())
// {
// rv = NS_OK;
// OnStopOperation(mTransactionID, NS_OK, nsnull, nsnull);
// goto EarlyExit;
// }
// We can keep this object around for reuse...
if (!mPostEngine)
{
@ -492,15 +487,16 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(PRInt32 *aTransactionID)
}
// Ok, add the header to this protocol string information...
// prefixStr = PR_smprintf("last=%u&protocol=%d&client=seamonkey&ver=%s&", mLastChangeNum, ABSYNC_PROTOCOL, ABSYNC_VERSION);
if (mPostString.IsEmpty())
prefixStr = PR_smprintf("last=%u&protocol=%d&client=2&ver=Demo", mLastChangeNum, ABSYNC_PROTOCOL, ABSYNC_VERSION);
prefixStr = PR_smprintf("last=%u&protocol=%d&client=2&ver=Demo&user=%s",
mLastChangeNum, ABSYNC_PROTOCOL, ABSYNC_VERSION, mUserName);
else
prefixStr = PR_smprintf("last=%u&protocol=%d&client=2&ver=Demo&", mLastChangeNum, ABSYNC_PROTOCOL, ABSYNC_VERSION);
prefixStr = PR_smprintf("last=%u&protocol=%d&client=2&ver=Demo&user=%s&",
mLastChangeNum, ABSYNC_PROTOCOL, ABSYNC_VERSION, mUserName);
if (!prefixStr)
{
rv = NS_ERROR_OUT_OF_MEMORY;
OnStopOperation(mTransactionID, NS_OK, nsnull, nsnull);
OnStopOperation(mTransactionID, NS_ERROR_OUT_OF_MEMORY, nsnull, nsnull);
goto EarlyExit;
}
@ -515,9 +511,13 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(PRInt32 *aTransactionID)
rv = mPostEngine->SendAbRequest(postSpec, mAbSyncPort, protocolRequest, mTransactionID);
if (NS_SUCCEEDED(rv))
{
// RICHIE_TODO - need to kick the end of operation listener
mCurrentState = nsIAbSyncState::nsIAbSyncRunning;
}
else
{
OnStopOperation(mTransactionID, rv, nsnull, nsnull);
goto EarlyExit;
}
EarlyExit:
PR_FREEIF(protocolRequest);
@ -1666,6 +1666,7 @@ nsAbSync::ProcessServerResponse(const char *aProtocolResponse)
// If no response, then this is a problem...
if (!aProtocolResponse)
{
// RICHIE_TODO START HERE DUDE...NICE DIALOGS!
printf("\7RICHIE_GUI: Server returned invalid response!\n");
return NS_ERROR_FAILURE;
}
@ -2097,7 +2098,44 @@ nsAbSync::AddValueToNewCard(nsIAbCard *aCard, nsString *aTagName, nsString *aTag
return rv;
}
#define AB_STRING_URL "chrome://messenger/locale/addressbook/addressBook.properties"
PRUnichar *
nsAbSync::GetString(const PRUnichar *aStringName)
{
nsresult res = NS_OK;
PRUnichar *ptrv = nsnull;
if (!mStringBundle)
{
char *propertyURL = AB_STRING_URL;
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res);
if (NS_SUCCEEDED(res) && (nsnull != sBundleService))
{
nsILocale *locale = nsnull;
res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(mStringBundle));
}
}
if (mStringBundle)
res = mStringBundle->GetStringFromName(aStringName, &ptrv);
if ( NS_SUCCEEDED(res) && (ptrv) )
return ptrv;
else
return nsCRT::strdup(aStringName);
}
/*********** RICHIE_TODO
These are the types for the phone entries!
Pager:
Home:
Work:
Fax:
Cellular:
*****/
/************ UNUSED FOR NOW
aCard->SetDisplayName(aTagValue->GetUnicode());

View File

@ -31,6 +31,7 @@
#include "nsIAbDirectory.h"
#include "nsAbSyncCRCModel.h"
#include "nsVoidArray.h"
#include "nsIStringBundle.h"
//
// Basic Sync Logic
@ -147,6 +148,7 @@ private:
void InternalInit();
nsresult InternalCleanup();
nsresult CleanServerTable(nsVoidArray *aArray);
PRUnichar *GetString(const PRUnichar *aStringName);
nsCOMPtr<nsIAbSyncPostEngine> mPostEngine;
nsString mPostString;
@ -156,6 +158,7 @@ private:
PRInt32 mLastChangeNum;
char *mUserName;
nsCOMPtr<nsIStringBundle> mStringBundle;
// Setting for ABSync operations...
char *mAbSyncServer;

View File

@ -91,6 +91,7 @@ nsAbSyncPostEngine::nsAbSyncPostEngine()
mPostEngineState = nsIAbSyncPostEngineState::nsIAbSyncPostIdle;
mTransactionID = 0;
mMessageSize = 0;
}
nsAbSyncPostEngine::~nsAbSyncPostEngine()
@ -511,6 +512,10 @@ NS_IMETHODIMP nsAbSyncPostEngine::SendAbRequest(const char *aSpec, PRInt32 aPort
mProtocolResponse = NS_ConvertASCIItoUCS2("");
mTotalWritten = 0;
if (aProtocolRequest)
mMessageSize = nsCRT::strlen(aProtocolRequest);
else
mMessageSize = 0;
char *tSpec = PR_smprintf("%s?%s", aSpec, aProtocolRequest);
if (!tSpec)
return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the string */