зеркало из https://github.com/mozilla/gecko-dev.git
NOT PART OF THE BUILD
This commit is contained in:
Родитель
4e3ceb93f9
Коммит
23815bca90
|
@ -28,7 +28,7 @@
|
|||
#include "prmem.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbSyncDriver, nsIAbSyncDriver)
|
||||
// NS_IMPL_ISUPPORTS1(nsAbSyncDriver, nsIAbSyncDriver)
|
||||
//NS_IMPL_ISUPPORTS1(nsAbSyncDriver, nsIAbSyncDriver)
|
||||
|
||||
static NS_DEFINE_CID(kAbSync, NS_ABSYNC_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
|
|
@ -90,6 +90,9 @@ nsAbSync::InternalInit()
|
|||
mDeletedRecordValues = nsnull;
|
||||
mNewRecordTags = nsnull;
|
||||
mNewRecordValues = nsnull;
|
||||
|
||||
mPhoneTypes = nsnull;
|
||||
mPhoneValues = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -141,6 +144,11 @@ nsAbSync::InternalCleanup()
|
|||
if (mNewRecordValues)
|
||||
delete mNewRecordValues;
|
||||
|
||||
if (mPhoneTypes)
|
||||
delete mPhoneTypes;
|
||||
if (mPhoneValues)
|
||||
delete mPhoneValues;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -442,6 +450,10 @@ NS_IMETHODIMP nsAbSync::PerformAbSync(PRInt32 *aTransactionID)
|
|||
goto EarlyExit;
|
||||
}
|
||||
|
||||
// Get the string arrays setup for the phone numbers...
|
||||
mPhoneTypes = new nsStringArray();
|
||||
mPhoneValues = new nsStringArray();
|
||||
|
||||
#ifdef DEBUG_rhp
|
||||
printf("ABSYNC: PerformAbSync: Server = %s\n", mAbSyncServer);
|
||||
#endif
|
||||
|
@ -564,6 +576,9 @@ nsAbSync::GenerateProtocolForCard(nsIAbCard *aCard, PRBool aAddId, nsString &pro
|
|||
{
|
||||
PRUnichar *aName = nsnull;
|
||||
nsString tProtLine;
|
||||
PRInt32 phoneCount = 1;
|
||||
PRBool foundPhone = PR_FALSE;
|
||||
char *phoneType;
|
||||
|
||||
protLine = NS_ConvertASCIItoUCS2("");
|
||||
|
||||
|
@ -586,7 +601,58 @@ nsAbSync::GenerateProtocolForCard(nsIAbCard *aCard, PRBool aAddId, nsString &pro
|
|||
{
|
||||
if (NS_SUCCEEDED(aCard->GetCardValue(mSchemaMappingList[i].abField, &aName)) && (aName) && (*aName))
|
||||
{
|
||||
if (nsCRT::strncasecmp(mSchemaMappingList[i].serverField, "OMIT:", 5))
|
||||
// These are unknown tags we are omitting...
|
||||
if (!nsCRT::strncasecmp(mSchemaMappingList[i].serverField, "OMIT:", 5))
|
||||
continue;
|
||||
|
||||
// If this is a phone number, we have to special case this because
|
||||
// phone #'s are handled differently than all other tags...sigh!
|
||||
//
|
||||
foundPhone = PR_FALSE;
|
||||
if (!nsCRT::strncasecmp(mSchemaMappingList[i].abField, kWorkPhoneColumn, nsCRT::strlen(kWorkPhoneColumn)))
|
||||
{
|
||||
foundPhone = PR_TRUE;
|
||||
phoneType = ABSYNC_WORK_PHONE_TYPE;
|
||||
}
|
||||
else if (!nsCRT::strncasecmp(mSchemaMappingList[i].abField, kHomePhoneColumn, nsCRT::strlen(kHomePhoneColumn)))
|
||||
{
|
||||
foundPhone = PR_TRUE;
|
||||
phoneType = ABSYNC_HOME_PHONE_TYPE;
|
||||
}
|
||||
else if (!nsCRT::strncasecmp(mSchemaMappingList[i].abField, kFaxColumn, nsCRT::strlen(kFaxColumn)))
|
||||
{
|
||||
foundPhone = PR_TRUE;
|
||||
phoneType = ABSYNC_FAX_PHONE_TYPE;
|
||||
}
|
||||
else if (!nsCRT::strncasecmp(mSchemaMappingList[i].abField, kPagerColumn, nsCRT::strlen(kPagerColumn)))
|
||||
{
|
||||
foundPhone = PR_TRUE;
|
||||
phoneType = ABSYNC_PAGER_PHONE_TYPE;
|
||||
}
|
||||
else if (!nsCRT::strncasecmp(mSchemaMappingList[i].abField, kCellularColumn, nsCRT::strlen(kCellularColumn)))
|
||||
{
|
||||
foundPhone = PR_TRUE;
|
||||
phoneType = ABSYNC_CELL_PHONE_TYPE;
|
||||
}
|
||||
|
||||
if (foundPhone)
|
||||
{
|
||||
char *pVal = PR_smprintf("phone%d", phoneCount);
|
||||
if (pVal)
|
||||
{
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2("&"));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2(pVal));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2("="));
|
||||
tProtLine.Append(aName);
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2("&"));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2(pVal));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2("_type="));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2(phoneType));
|
||||
PR_FREEIF(pVal);
|
||||
phoneCount++;
|
||||
}
|
||||
}
|
||||
else // Good ole' normal tag...
|
||||
{
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2("&"));
|
||||
tProtLine.Append(NS_ConvertASCIItoUCS2(mSchemaMappingList[i].serverField));
|
||||
|
@ -2004,40 +2070,109 @@ EarlyExit:
|
|||
return rv;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsAbSync::GetTypeOfPhoneNumber(nsString tagName)
|
||||
{
|
||||
nsString compValue = tagName;
|
||||
compValue.Append(NS_ConvertASCIItoUCS2("_type"));
|
||||
|
||||
for (PRInt32 i=0; i<mPhoneTypes->Count(); i++)
|
||||
{
|
||||
nsString *val = mPhoneTypes->StringAt(i);
|
||||
if ( (!val) || val->IsEmpty() )
|
||||
continue;
|
||||
|
||||
if (!compValue.CompareWithConversion(ABSYNC_HOME_PHONE_TYPE, PR_TRUE, nsCRT::strlen(ABSYNC_HOME_PHONE_TYPE)))
|
||||
return ABSYNC_HOME_PHONE_ID;
|
||||
else if (!compValue.CompareWithConversion(ABSYNC_WORK_PHONE_TYPE, PR_TRUE, nsCRT::strlen(ABSYNC_WORK_PHONE_TYPE)))
|
||||
return ABSYNC_WORK_PHONE_ID;
|
||||
else if (!compValue.CompareWithConversion(ABSYNC_FAX_PHONE_TYPE, PR_TRUE, nsCRT::strlen(ABSYNC_FAX_PHONE_TYPE)))
|
||||
return ABSYNC_FAX_PHONE_ID;
|
||||
else if (!compValue.CompareWithConversion(ABSYNC_PAGER_PHONE_TYPE, PR_TRUE, nsCRT::strlen(ABSYNC_PAGER_PHONE_TYPE)))
|
||||
return ABSYNC_PAGER_PHONE_ID;
|
||||
else if (!compValue.CompareWithConversion(ABSYNC_CELL_PHONE_TYPE, PR_TRUE, nsCRT::strlen(ABSYNC_CELL_PHONE_TYPE)))
|
||||
return ABSYNC_CELL_PHONE_ID;
|
||||
}
|
||||
|
||||
// If we get here...drop back to the defaults...why, oh why is it this way?
|
||||
//
|
||||
if (!tagName.CompareWithConversion("phone1"))
|
||||
return ABSYNC_HOME_PHONE_ID;
|
||||
else if (!tagName.CompareWithConversion("phone2"))
|
||||
return ABSYNC_WORK_PHONE_ID;
|
||||
else if (!tagName.CompareWithConversion("phone3"))
|
||||
return ABSYNC_FAX_PHONE_ID;
|
||||
else if (!tagName.CompareWithConversion("phone4"))
|
||||
return ABSYNC_PAGER_PHONE_ID;
|
||||
else if (!tagName.CompareWithConversion("phone5"))
|
||||
return ABSYNC_CELL_PHONE_ID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAbSync::ProcessPhoneNumbersTheyAreSpecial(nsIAbCard *aCard)
|
||||
{
|
||||
PRInt32 i;
|
||||
nsString tagName;
|
||||
nsString phoneNumber;
|
||||
PRInt32 loc;
|
||||
|
||||
for (i=0; i<mPhoneValues->Count(); i++)
|
||||
{
|
||||
nsString *val = mPhoneValues->StringAt(i);
|
||||
if ( (!val) || val->IsEmpty() )
|
||||
continue;
|
||||
|
||||
tagName.Assign(*val);
|
||||
phoneNumber.Assign(*val);
|
||||
loc = tagName.FindChar('=');
|
||||
if (loc == -1)
|
||||
continue;
|
||||
|
||||
tagName.Cut(loc, (tagName.Length() - loc));
|
||||
phoneNumber.Cut(0, loc);
|
||||
|
||||
PRInt32 pType = GetTypeOfPhoneNumber(tagName);
|
||||
if (pType == 0)
|
||||
continue;
|
||||
|
||||
if (pType == ABSYNC_PAGER_PHONE_ID)
|
||||
aCard->SetPagerNumber(phoneNumber.GetUnicode());
|
||||
else if (pType == ABSYNC_HOME_PHONE_ID)
|
||||
aCard->SetHomePhone(phoneNumber.GetUnicode());
|
||||
else if (pType == ABSYNC_WORK_PHONE_ID)
|
||||
aCard->SetWorkPhone(phoneNumber.GetUnicode());
|
||||
else if (pType == ABSYNC_FAX_PHONE_ID)
|
||||
aCard->SetFaxNumber(phoneNumber.GetUnicode());
|
||||
else if (pType == ABSYNC_CELL_PHONE_ID)
|
||||
aCard->SetCellularNumber(phoneNumber.GetUnicode());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAbSync::AddValueToNewCard(nsIAbCard *aCard, nsString *aTagName, nsString *aTagValue)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
//
|
||||
// RICHIE_TODO: First, we are going to special case the phone entries because they seem to
|
||||
//
|
||||
/**
|
||||
#define ABSYNC_PAGER_PHONE_TYPE "Pager:"
|
||||
#define ABSYNC_HOME_PHONE_TYPE "Home:"
|
||||
#define ABSYNC_WORK_PHONE_TYPE "Work:"
|
||||
#define ABSYNC_FAX_PHONE_TYPE "Fax:"
|
||||
#define ABSYNC_CELL_PHONE_TYPE "Cellular:"
|
||||
|
||||
if (!aTagName->CompareWithConversion(kServerWorkPhoneColumn))
|
||||
aCard->SetWorkPhone(aTagValue->GetUnicode());
|
||||
|
||||
if (!aTagName->CompareWithConversion(kServerHomePhoneColumn))
|
||||
aCard->SetHomePhone(aTagValue->GetUnicode());
|
||||
|
||||
if (!aTagName->CompareWithConversion(kServerFaxColumn))
|
||||
aCard->SetFaxNumber(aTagValue->GetUnicode());
|
||||
|
||||
if (!aTagName->CompareWithConversion(kServerPagerColumn))
|
||||
aCard->SetPagerNumber(aTagValue->GetUnicode());
|
||||
|
||||
if (!aTagName->CompareWithConversion(kServerCellularColumn))
|
||||
aCard->SetCellularNumber(aTagValue->GetUnicode());
|
||||
|
||||
|
||||
******************************/
|
||||
// First, we are going to special case the phone entries because they seem to
|
||||
// be handled differently than all other tags. All other tags are unique with no specifiers
|
||||
// as to their type...this is not the case with phone numbers.
|
||||
//
|
||||
PRUnichar aChar = '_';
|
||||
|
||||
if (!aTagName->CompareWithConversion("phone", 5))
|
||||
{
|
||||
if (aTagName->FindChar(aChar) != -1)
|
||||
mPhoneTypes->AppendString(NS_ConvertASCIItoUCS2(aTagValue->ToNewCString()));
|
||||
else
|
||||
mPhoneValues->AppendString(NS_ConvertASCIItoUCS2(aTagValue->ToNewCString()));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Ok, we need to figure out what the tag name from the server maps to and assign
|
||||
// this value the new nsIAbCard
|
||||
|
|
|
@ -86,11 +86,16 @@ typedef struct {
|
|||
#define ABSYNC_PROTOCOL 3
|
||||
#define ABSYNC_VERSION "Demo"
|
||||
|
||||
#define ABSYNC_PAGER_PHONE_TYPE "Pager:"
|
||||
#define ABSYNC_HOME_PHONE_TYPE "Home:"
|
||||
#define ABSYNC_WORK_PHONE_TYPE "Work:"
|
||||
#define ABSYNC_FAX_PHONE_TYPE "Fax:"
|
||||
#define ABSYNC_CELL_PHONE_TYPE "Cellular:"
|
||||
#define ABSYNC_HOME_PHONE_TYPE "Home"
|
||||
#define ABSYNC_WORK_PHONE_TYPE "Work"
|
||||
#define ABSYNC_FAX_PHONE_TYPE "Fax"
|
||||
#define ABSYNC_PAGER_PHONE_TYPE "Pager"
|
||||
#define ABSYNC_CELL_PHONE_TYPE "Cellular"
|
||||
#define ABSYNC_HOME_PHONE_ID 1
|
||||
#define ABSYNC_WORK_PHONE_ID 2
|
||||
#define ABSYNC_FAX_PHONE_ID 3
|
||||
#define ABSYNC_PAGER_PHONE_ID 4
|
||||
#define ABSYNC_CELL_PHONE_ID 5
|
||||
|
||||
#define SYNC_ESCAPE_ADDUSER "op%3Dadd"
|
||||
#define SYNC_ESCAPE_MOD "op%3Dmod"
|
||||
|
@ -215,6 +220,8 @@ private:
|
|||
nsresult ProcessNewRecords();
|
||||
nsresult ProcessDeletedRecords();
|
||||
nsresult ProcessLastChange();
|
||||
nsresult ProcessPhoneNumbersTheyAreSpecial(nsIAbCard *aCard);
|
||||
PRInt32 GetTypeOfPhoneNumber(nsString tagName);
|
||||
|
||||
nsString mLocale; // Charset of returned data!
|
||||
nsStringArray *mDeletedRecordTags; // The deleted record tags from the server...
|
||||
|
@ -222,6 +229,9 @@ private:
|
|||
|
||||
nsStringArray *mNewRecordTags; // The new record tags from the server...
|
||||
nsStringArray *mNewRecordValues; // The new record values from the server...
|
||||
|
||||
nsStringArray *mPhoneTypes; // Phone number types...
|
||||
nsStringArray *mPhoneValues; // Phone number values...
|
||||
};
|
||||
|
||||
#endif /* __nsIAbSync_h__ */
|
||||
|
|
|
@ -299,58 +299,6 @@ nsAbSyncPostEngine::Initialize(nsOutputFileStream *fOut,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAbSyncPostEngine::FireURLRequest(nsIURI *aURL, nsPostCompletionCallback cb,
|
||||
void *tagData, const char *postData)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> postStream;
|
||||
|
||||
if (!postData)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(channel), aURL, nsnull), NS_ERROR_FAILURE);
|
||||
|
||||
/***
|
||||
// RICHIE
|
||||
// Tag the post stream onto the channel...but never seemed to work...so putting it
|
||||
// directly on the URL spec
|
||||
//
|
||||
|
||||
// Mark the channel as being a document URI...
|
||||
nsLoadFlags loadAttribs = 0;
|
||||
channel->GetLoadAttributes(&loadAttribs);
|
||||
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
|
||||
channel->SetLoadAttributes(loadAttribs);
|
||||
|
||||
nsCOMPtr<nsIAtom> method = NS_NewAtom ("POST");
|
||||
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
|
||||
if (!httpChannel)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
httpChannel->SetRequestMethod(method);
|
||||
if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postStream), PR_FALSE, postData, 0)))
|
||||
{
|
||||
httpChannel->SetUploadStream(postStream);
|
||||
}
|
||||
|
||||
*****/
|
||||
|
||||
// let's try uri dispatching...
|
||||
nsCOMPtr<nsIURILoader> pURILoader (do_GetService(NS_URI_LOADER_PROGID));
|
||||
NS_ENSURE_TRUE(pURILoader, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsISupports> openContext;
|
||||
nsCOMPtr<nsISupports> cntListener (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, this)));
|
||||
rv = pURILoader->OpenURI(channel, nsIURILoader::viewNormal, nsnull, cntListener);
|
||||
|
||||
mURL = dont_QueryInterface(aURL);
|
||||
mCallback = cb;
|
||||
mTagData = tagData;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void AddSyncListener (in nsIAbSyncPostListener aListener); */
|
||||
NS_IMETHODIMP nsAbSyncPostEngine::AddPostListener(nsIAbSyncPostListener *aListener)
|
||||
{
|
||||
|
@ -505,7 +453,6 @@ NS_IMETHODIMP nsAbSyncPostEngine::GetCurrentState(PRInt32 *_retval)
|
|||
// This is the implementation of the actual post driver.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsAbSyncPostEngine::SendAbRequest(const char *aSpec, PRInt32 aPort, const char *aProtocolRequest, PRInt32 aTransactionID)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -519,26 +466,62 @@ NS_IMETHODIMP nsAbSyncPostEngine::SendAbRequest(const char *aSpec, PRInt32 aPort
|
|||
mProtocolResponse = NS_ConvertASCIItoUCS2("");
|
||||
mTotalWritten = 0;
|
||||
|
||||
char *postHeader = "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s";
|
||||
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 */
|
||||
|
||||
char *tCommand = PR_smprintf(postHeader, mMessageSize, aProtocolRequest);
|
||||
if (!tCommand)
|
||||
return NS_ERROR_OUT_OF_MEMORY; // we couldn't allocate the string
|
||||
|
||||
printf("POST: %s\n", aProtocolRequest);
|
||||
|
||||
rv = nsEngineNewURI(&workURI, tSpec, nsnull);
|
||||
rv = nsEngineNewURI(&workURI, aSpec, nsnull);
|
||||
if (NS_FAILED(rv) || (!workURI))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PR_FREEIF(tSpec);
|
||||
if (aPort > 0)
|
||||
workURI->SetPort(aPort);
|
||||
|
||||
rv = FireURLRequest(workURI, PostDoneCallback, this, aProtocolRequest);
|
||||
rv = FireURLRequest(workURI, PostDoneCallback, this, tCommand);
|
||||
|
||||
PR_FREEIF(tCommand);
|
||||
mPostEngineState = nsIAbSyncPostEngineState::nsIAbSyncPostRunning;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAbSyncPostEngine::FireURLRequest(nsIURI *aURL, nsPostCompletionCallback cb,
|
||||
void *tagData, const char *postData)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> postStream;
|
||||
|
||||
if (!postData)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(channel), aURL, nsnull), NS_ERROR_FAILURE);
|
||||
|
||||
// Tag the post stream onto the channel...but never seemed to work...so putting it
|
||||
// directly on the URL spec
|
||||
//
|
||||
nsCOMPtr<nsIAtom> method = NS_NewAtom ("POST");
|
||||
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
|
||||
if (!httpChannel)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
httpChannel->SetRequestMethod(method);
|
||||
if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postStream), PR_FALSE, postData, 0)))
|
||||
httpChannel->SetUploadStream(postStream);
|
||||
|
||||
httpChannel->AsyncRead(this, nsnull);
|
||||
|
||||
mURL = dont_QueryInterface(aURL);
|
||||
mCallback = cb;
|
||||
mTagData = tagData;
|
||||
NS_ADDREF(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче