зеркало из https://github.com/mozilla/pjs.git
Adding new files to tree - NOT PART OF THE BUILD
This commit is contained in:
Родитель
f007acd29d
Коммит
e776747d06
|
@ -0,0 +1,54 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 "nsIURI.idl"
|
||||
#include "nsIAbCard.idl"
|
||||
|
||||
[scriptable, uuid(6EB9D874-01AA-11d4-8FBE-000064657374)]
|
||||
|
||||
interface nsIAddbookUrlOperation
|
||||
{
|
||||
const long InvalidUrl = 0;
|
||||
const long PrintIndividual = 1;
|
||||
const long PrintAddressBook = 2;
|
||||
const long ImportCards = 3;
|
||||
const long ImportMailingLists = 4;
|
||||
const long ExportCards = 5;
|
||||
const long AddToAddressBook = 6;
|
||||
const long ExportTitle = 7;
|
||||
const long ImportTitle = 8;
|
||||
};
|
||||
|
||||
interface nsIAddbookUrl : nsIURI {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Addbook parse specific getters
|
||||
// Not sure if this will be used by the outside world, but if it is, at
|
||||
// least its here
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// So what does the user want to do with this particular URL
|
||||
long GetAddbookOperation();
|
||||
nsIAbCard GetAbCard();
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,605 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
#include "msgCore.h" // precompiled header...
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#include "nsIStreamObserver.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsAddbookProtocolHandler.h"
|
||||
|
||||
#include "nsAddbookUrl.h"
|
||||
#include "nsAddbookProtocolHandler.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMsgIdentity.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsIAddrBookSession.h"
|
||||
#include "nsIAbDirectory.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
/* The definition is nsAddrDatabase.cpp */
|
||||
extern const char *kWorkAddressBook;
|
||||
extern const char *kFirstNameColumn;
|
||||
extern const char *kLastNameColumn;
|
||||
extern const char *kDisplayNameColumn;
|
||||
extern const char *kNicknameColumn;
|
||||
extern const char *kPriEmailColumn;
|
||||
extern const char *k2ndEmailColumn;
|
||||
extern const char *kPlainTextColumn;
|
||||
extern const char *kWorkPhoneColumn;
|
||||
extern const char *kHomePhoneColumn;
|
||||
extern const char *kFaxColumn;
|
||||
extern const char *kPagerColumn;
|
||||
extern const char *kCellularColumn;
|
||||
extern const char *kHomeAddressColumn;
|
||||
extern const char *kHomeAddress2Column;
|
||||
extern const char *kHomeCityColumn;
|
||||
extern const char *kHomeStateColumn;
|
||||
extern const char *kHomeZipCodeColumn;
|
||||
extern const char *kHomeCountryColumn;
|
||||
extern const char *kWorkAddressColumn;
|
||||
extern const char *kWorkAddress2Column;
|
||||
extern const char *kWorkCityColumn;
|
||||
extern const char *kWorkStateColumn;
|
||||
extern const char *kWorkZipCodeColumn;
|
||||
extern const char *kWorkCountryColumn;
|
||||
extern const char *kJobTitleColumn;
|
||||
extern const char *kDepartmentColumn;
|
||||
extern const char *kCompanyColumn;
|
||||
extern const char *kWebPage1Column;
|
||||
extern const char *kWebPage2Column;
|
||||
extern const char *kBirthYearColumn;
|
||||
extern const char *kBirthMonthColumn;
|
||||
extern const char *kBirthDayColumn;
|
||||
extern const char *kCustom1Column;
|
||||
extern const char *kCustom2Column;
|
||||
extern const char *kCustom3Column;
|
||||
extern const char *kCustom4Column;
|
||||
extern const char *kNotesColumn;
|
||||
extern const char *kLastModifiedDateColumn;
|
||||
/* end */
|
||||
|
||||
static NS_DEFINE_CID(kCAddbookUrlCID, NS_ADDBOOKURL_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
|
||||
static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
nsAddbookProtocolHandler::nsAddbookProtocolHandler()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
}
|
||||
|
||||
nsAddbookProtocolHandler::~nsAddbookProtocolHandler()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAddbookProtocolHandler, NS_GET_IID(nsIProtocolHandler));
|
||||
|
||||
NS_METHOD
|
||||
nsAddbookProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsAddbookProtocolHandler* ph = new nsAddbookProtocolHandler();
|
||||
if (ph == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return ph->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookProtocolHandler::GetScheme(char * *aScheme)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (aScheme)
|
||||
*aScheme = PL_strdup("addbook");
|
||||
else
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookProtocolHandler::GetDefaultPort(PRInt32 *aDefaultPort)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval)
|
||||
{
|
||||
// get a new smtp url
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr <nsIURI> addbookUrl;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kCAddbookUrlCID, NULL, NS_GET_IID(nsIURI), getter_AddRefs(addbookUrl));
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = addbookUrl->SetSpec(aSpec);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = addbookUrl->QueryInterface(NS_GET_IID(nsIURI), (void **) _retval);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::GenerateHTMLOutputChannel( char *aHtmlOutput,
|
||||
PRInt32 aHtmlOutputSize,
|
||||
nsIAddbookUrl *addbookUrl,
|
||||
const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIChannel *channel;
|
||||
nsCOMPtr<nsIInputStream> inStr;
|
||||
nsCOMPtr<nsISupports> s;
|
||||
|
||||
if (!aHtmlOutput)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = NS_NewStringInputStream(getter_AddRefs(s), aHtmlOutput);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
inStr = do_QueryInterface(s, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = NS_NewInputStreamChannel(aURI, "text/html",
|
||||
aHtmlOutputSize, inStr, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, &channel);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
*_retval = channel;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::NewChannel( const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char *outBuf = nsnull;
|
||||
|
||||
//
|
||||
// Ok, now that we are here, we need to figure out what oprations we
|
||||
// are going to perform...create a stream of buffered data if necessary
|
||||
// or launch the UI dialog window and go from there.
|
||||
//
|
||||
mAddbookOperation = nsIAddbookUrlOperation::InvalidUrl;
|
||||
nsCOMPtr <nsIAddbookUrl> addbookUrl = do_QueryInterface(getter_AddRefs(aURI));
|
||||
if (!addbookUrl)
|
||||
return NS_ERROR_ABORT;
|
||||
|
||||
//
|
||||
// Ok, first, lets see what we need to do here and then call the appropriate
|
||||
// method to handle the operation
|
||||
//
|
||||
addbookUrl->GetAddbookOperation(&mAddbookOperation);
|
||||
switch (mAddbookOperation)
|
||||
{
|
||||
case nsIAddbookUrlOperation::PrintIndividual:
|
||||
case nsIAddbookUrlOperation::PrintAddressBook:
|
||||
rv = GeneratePrintOutput(addbookUrl, &outBuf);
|
||||
if ((NS_FAILED(rv) || (!outBuf)))
|
||||
{
|
||||
char *eMsg = "Unsupported format/operation requested for \"addbook:\" URL.";
|
||||
PRInt32 eSize = nsCRT::strlen(eMsg);
|
||||
rv = GenerateHTMLOutputChannel(eMsg, eSize, addbookUrl, verb, aURI, aLoadGroup,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, _retval);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = GenerateHTMLOutputChannel(outBuf, nsCRT::strlen(outBuf), addbookUrl, verb, aURI, aLoadGroup,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, _retval);
|
||||
PR_FREEIF(outBuf);
|
||||
}
|
||||
break;
|
||||
|
||||
case nsIAddbookUrlOperation::ImportCards:
|
||||
case nsIAddbookUrlOperation::ImportMailingLists:
|
||||
case nsIAddbookUrlOperation::ExportCards:
|
||||
case nsIAddbookUrlOperation::AddToAddressBook:
|
||||
case nsIAddbookUrlOperation::ExportTitle:
|
||||
case nsIAddbookUrlOperation::ImportTitle:
|
||||
case nsIAddbookUrlOperation::InvalidUrl:
|
||||
default:
|
||||
char *eMsg = "Unsupported format/operation requested for \"addbook:\" URL.";
|
||||
PRInt32 eSize = nsCRT::strlen(eMsg);
|
||||
|
||||
rv = GenerateHTMLOutputChannel(eMsg, eSize, addbookUrl, verb, aURI, aLoadGroup,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, _retval);
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::OpenAB(char *aAbName, nsIAddrDatabase **aDatabase)
|
||||
{
|
||||
if (!aDatabase)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
|
||||
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
|
||||
if (dbPath)
|
||||
{
|
||||
if (!aAbName)
|
||||
(*dbPath) += "abook.mab";
|
||||
else
|
||||
(*dbPath) += aAbName;
|
||||
|
||||
NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(aDatabase), PR_TRUE);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::AddIndividualUserAttribPair(nsString &aString, const char *aColumn, nsIAbCard *aCard)
|
||||
{
|
||||
PRUnichar *aName = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(aCard->GetCardValue(aColumn, &aName)) && (aName) && (*aName))
|
||||
{
|
||||
aString.Append("<tr>");
|
||||
|
||||
aString.Append("<td><b>");
|
||||
aString.Append(aColumn);
|
||||
aString.Append("</b></td>");
|
||||
|
||||
aString.Append("<td>");
|
||||
aString.Append(aName);
|
||||
aString.Append("</td>");
|
||||
|
||||
aString.Append("</tr>");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::FindPossibleAbName(nsIAbCard *aCard,
|
||||
PRUnichar **retName)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsVoidArray *attrlist = nsnull;
|
||||
nsVoidArray *valuelist = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(aCard->GetAnonymousStrAttrubutesList(&attrlist)) && attrlist)
|
||||
{
|
||||
if (NS_SUCCEEDED(aCard->GetAnonymousStrValuesList(&valuelist)) && valuelist)
|
||||
{
|
||||
char *attr = nsnull;
|
||||
|
||||
for (PRInt32 i = 0; i<attrlist->Count(); i++)
|
||||
{
|
||||
attr = (char *)attrlist->ElementAt(i);
|
||||
|
||||
if ((attr) && (!nsCRT::strcasecmp(kWorkAddressBook, attr)))
|
||||
{
|
||||
char *val = (char *)valuelist->ElementAt(i);
|
||||
if ( (val) && (*val) )
|
||||
{
|
||||
*retName = nsString(val).ToNewUnicode();
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::GeneratePrintOutput(nsIAddbookUrl *addbookUrl,
|
||||
char **outBuf)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsString workBuffer = "";
|
||||
nsIAddrDatabase *aDatabase = nsnull;
|
||||
|
||||
if (!outBuf)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Get the address book entry
|
||||
nsCOMPtr <nsIRDFResource> resource = nsnull;
|
||||
nsCOMPtr <nsIAbDirectory> directory = nsnull;
|
||||
nsIAbCard *urlArgCard;
|
||||
PRUnichar *workEmail = nsnull;
|
||||
char *charEmail = nsnull;
|
||||
PRUnichar *workAb = nsnull;
|
||||
char *charAb = nsnull;
|
||||
char *abFileName = nsnull;
|
||||
|
||||
rv = NS_OK;
|
||||
// Get the RDF service...
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
goto EarlyExit;
|
||||
|
||||
// Get the AB card that has all of the URL arguments
|
||||
rv = addbookUrl->GetAbCard(&urlArgCard);
|
||||
if (NS_FAILED(rv))
|
||||
goto EarlyExit;
|
||||
|
||||
// Get the email of interest if this is for a specific email message
|
||||
if (mAddbookOperation == nsIAddbookUrlOperation::PrintIndividual)
|
||||
{
|
||||
rv = urlArgCard->GetCardValue(kPriEmailColumn, &workEmail);
|
||||
if ( (NS_FAILED(rv)) || (!workEmail) || (!*workEmail))
|
||||
goto EarlyExit;
|
||||
|
||||
// Make it a char *
|
||||
charEmail = nsString(workEmail).ToNewCString();
|
||||
if (!charEmail)
|
||||
goto EarlyExit;
|
||||
}
|
||||
|
||||
// Ok, we need to see if a particular address book was passed in on the
|
||||
// URL string. If not, then we will use the default, but if there was one
|
||||
// specified, we need to do a prefs lookup and get the file name of interest
|
||||
// The pref format is: user_pref("ldap_2.servers.Richie.filename", "abook-1.mab");
|
||||
//
|
||||
rv = FindPossibleAbName(urlArgCard, &workAb);
|
||||
if ( (NS_SUCCEEDED(rv)) && (workAb) && (*workAb))
|
||||
{
|
||||
// Make it a char *
|
||||
charAb = nsString(workAb).ToNewCString();
|
||||
if (!charAb)
|
||||
goto EarlyExit;
|
||||
|
||||
NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv);
|
||||
if (NS_FAILED(rv) || !pPref)
|
||||
goto EarlyExit;
|
||||
|
||||
nsCString prefId = "ldap_2.servers.";
|
||||
prefId.Append(charAb);
|
||||
prefId.Append(".filename");
|
||||
|
||||
rv = pPref->CopyCharPref(prefId, &abFileName);
|
||||
if (NS_FAILED(rv))
|
||||
abFileName = nsnull;
|
||||
}
|
||||
|
||||
// Now, open the database...for now, make it the default
|
||||
rv = OpenAB(abFileName, &aDatabase);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// this should not be hardcoded to abook.mab
|
||||
// RICHIE - this works for any address book...not sure why
|
||||
rv = rdfService->GetResource("abdirectory://abook.mab", getter_AddRefs(resource));
|
||||
if (NS_FAILED(rv))
|
||||
goto EarlyExit;
|
||||
|
||||
// query interface
|
||||
directory = do_QueryInterface(resource, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
goto EarlyExit;
|
||||
|
||||
// Ok, this is the place where we need to generate output for either a single entry
|
||||
// or the entire table...
|
||||
//
|
||||
if (mAddbookOperation == nsIAddbookUrlOperation::PrintIndividual)
|
||||
rv = BuildSingleHTML(aDatabase, directory, charEmail, workBuffer);
|
||||
else
|
||||
rv = BuildAllHTML(aDatabase, directory, workBuffer);
|
||||
|
||||
*outBuf = workBuffer.ToNewCString();
|
||||
|
||||
EarlyExit:
|
||||
// Database is open...make sure to close it
|
||||
if (aDatabase)
|
||||
{
|
||||
aDatabase->Close(PR_TRUE);
|
||||
// aDatabase->RemoveListener(??? listeners are hanging...I think);
|
||||
}
|
||||
NS_IF_RELEASE(aDatabase);
|
||||
|
||||
NS_IF_RELEASE(urlArgCard);
|
||||
PR_FREEIF(charEmail);
|
||||
PR_FREEIF(charAb);
|
||||
PR_FREEIF(abFileName);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::BuildSingleHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory,
|
||||
char *charEmail, nsString &workBuffer)
|
||||
{
|
||||
PRUnichar *aName = nsnull;
|
||||
nsCOMPtr <nsIAbCard> workCard;
|
||||
|
||||
nsresult rv = aDatabase->GetCardForEmailAddress(directory, charEmail, getter_AddRefs(workCard));
|
||||
if (NS_FAILED(rv) || (!workCard))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Ok, build a little HTML for output...
|
||||
workBuffer.Append("<HTML><BODY>");
|
||||
workBuffer.Append("<CENTER>");
|
||||
workBuffer.Append("<TABLE BORDER>");
|
||||
|
||||
if (NS_SUCCEEDED(workCard->GetName(&aName)) && (aName))
|
||||
{
|
||||
workBuffer.Append("<caption><b>");
|
||||
workBuffer.Append(aName);
|
||||
workBuffer.Append("</b></caption>");
|
||||
}
|
||||
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkAddressBook, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kFirstNameColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kLastNameColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kDisplayNameColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kNicknameColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kPriEmailColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, k2ndEmailColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kPlainTextColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkPhoneColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomePhoneColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kFaxColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kPagerColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCellularColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeAddressColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeAddress2Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeCityColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeStateColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeZipCodeColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kHomeCountryColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkAddressColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkAddress2Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkCityColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkStateColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkZipCodeColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWorkCountryColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kJobTitleColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kDepartmentColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCompanyColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWebPage1Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kWebPage2Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kBirthYearColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kBirthMonthColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kBirthDayColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCustom1Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCustom2Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCustom3Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kCustom4Column, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kNotesColumn, workCard);
|
||||
AddIndividualUserAttribPair(workBuffer, kLastModifiedDateColumn, workCard);
|
||||
|
||||
workBuffer.Append("</TABLE>");
|
||||
workBuffer.Append("<CENTER>");
|
||||
workBuffer.Append("</BODY></HTML>");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookProtocolHandler::BuildAllHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory,
|
||||
nsString &workBuffer)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
reportColumnStruct *reportColumns[] = {
|
||||
(kFirstNameColumn, PR_FALSE)
|
||||
(kLastNameColumn, PR_FALSE)
|
||||
(kDisplayNameColumn, PR_FALSE)
|
||||
(kNicknameColumn, PR_FALSE)
|
||||
(kPriEmailColumn, PR_FALSE)
|
||||
(k2ndEmailColumn, PR_FALSE)
|
||||
(kPlainTextColumn, PR_FALSE)
|
||||
(kWorkPhoneColumn, PR_FALSE)
|
||||
(kHomePhoneColumn, PR_FALSE)
|
||||
(kFaxColumn, PR_FALSE)
|
||||
(kPagerColumn, PR_FALSE)
|
||||
(kCellularColumn, PR_FALSE)
|
||||
(kHomeAddressColumn, PR_FALSE)
|
||||
(kHomeAddress2Column, PR_FALSE)
|
||||
(kHomeCityColumn, PR_FALSE)
|
||||
(kHomeStateColumn, PR_FALSE)
|
||||
(kHomeZipCodeColumn, PR_FALSE)
|
||||
(kHomeCountryColumn, PR_FALSE)
|
||||
(kWorkAddressColumn, PR_FALSE)
|
||||
(kWorkAddress2Column, PR_FALSE)
|
||||
(kWorkCityColumn, PR_FALSE)
|
||||
(kWorkStateColumn, PR_FALSE)
|
||||
(kWorkZipCodeColumn, PR_FALSE)
|
||||
(kWorkCountryColumn, PR_FALSE)
|
||||
(kJobTitleColumn, PR_FALSE)
|
||||
(kDepartmentColumn, PR_FALSE)
|
||||
(kCompanyColumn, PR_FALSE)
|
||||
(kWebPage1Column, PR_FALSE)
|
||||
(kWebPage2Column, PR_FALSE)
|
||||
(kBirthYearColumn, PR_FALSE)
|
||||
(kBirthMonthColumn, PR_FALSE)
|
||||
(kBirthDayColumn, PR_FALSE)
|
||||
(kCustom1Column, PR_FALSE)
|
||||
(kCustom2Column, PR_FALSE)
|
||||
(kCustom3Column, PR_FALSE)
|
||||
(kCustom4Column, PR_FALSE)
|
||||
(kNotesColumn, PR_FALSE)
|
||||
(kLastModifiedDateColumn, PR_FALSE)
|
||||
(nsnull, PR_FALSE)
|
||||
};
|
||||
|
||||
PRUnichar *aName = nsnull;
|
||||
nsCOMPtr <nsIAbCard> workCard;
|
||||
|
||||
// Ok, build a little HTML for output...
|
||||
workBuffer.Append("<HTML><BODY>");
|
||||
workBuffer.Append("<CENTER>");
|
||||
workBuffer.Append("<TABLE BORDER>");
|
||||
|
||||
NS_IMETHODIMP nsAddrDatabase::EnumerateCards(nsIAbDirectory *directory, nsIEnumerator **result)
|
||||
|
||||
|
||||
if (NS_SUCCEEDED(workCard->GetName(&aName)) && (aName))
|
||||
{
|
||||
workBuffer.Append("<caption><b>");
|
||||
workBuffer.Append(aName);
|
||||
workBuffer.Append("</b></caption>");
|
||||
}
|
||||
|
||||
workBuffer.Append("</TABLE>");
|
||||
workBuffer.Append("<CENTER>");
|
||||
workBuffer.Append("</BODY></HTML>");
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsAddbookProtocolHandler_h___
|
||||
#define nsAddbookProtocolHandler_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsAddbookProtocolHandler.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIAddbookUrl.h"
|
||||
#include "nsIAddrDatabase.h"
|
||||
|
||||
typedef struct {
|
||||
char *abField;
|
||||
PRBool includeIt;
|
||||
} reportColumnStruct;
|
||||
|
||||
class nsAddbookProtocolHandler : public nsIProtocolHandler
|
||||
{
|
||||
public:
|
||||
nsAddbookProtocolHandler();
|
||||
virtual ~nsAddbookProtocolHandler();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// we suppport the nsIProtocolHandler interface
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
private:
|
||||
// Output Generation calls to create the HTML output
|
||||
NS_METHOD GenerateHTMLOutputChannel(char *aHtmlOutput,
|
||||
PRInt32 aHtmlOutputSize,
|
||||
nsIAddbookUrl *addbookUrl,
|
||||
const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **_retval);
|
||||
|
||||
NS_METHOD GeneratePrintOutput(nsIAddbookUrl *addbookUrl,
|
||||
char **outBuf);
|
||||
NS_METHOD BuildSingleHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory,
|
||||
char *charEmail, nsString &workBuffer);
|
||||
|
||||
NS_METHOD BuildAllHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory,
|
||||
nsString &workBuffer);
|
||||
|
||||
NS_METHOD AddIndividualUserAttribPair(nsString &aString, const char *aColumn, nsIAbCard *workCard);
|
||||
|
||||
// Database access calls...
|
||||
NS_METHOD OpenAB(char *aAbName, nsIAddrDatabase **aDatabase);
|
||||
NS_METHOD FindPossibleAbName(nsIAbCard *aCard,
|
||||
PRUnichar **retName);
|
||||
|
||||
// Member vars...
|
||||
PRInt32 mAddbookOperation;
|
||||
};
|
||||
|
||||
#endif /* nsAddbookProtocolHandler_h___ */
|
|
@ -0,0 +1,473 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsAddbookUrl.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
|
||||
const char *kWorkAddressBook = "AddbookWorkAddressBook";
|
||||
|
||||
/* The definition is nsAddrDatabase.cpp */
|
||||
extern const char *kFirstNameColumn;
|
||||
extern const char *kLastNameColumn;
|
||||
extern const char *kDisplayNameColumn;
|
||||
extern const char *kNicknameColumn;
|
||||
extern const char *kPriEmailColumn;
|
||||
extern const char *k2ndEmailColumn;
|
||||
extern const char *kPlainTextColumn;
|
||||
extern const char *kWorkPhoneColumn;
|
||||
extern const char *kHomePhoneColumn;
|
||||
extern const char *kFaxColumn;
|
||||
extern const char *kPagerColumn;
|
||||
extern const char *kCellularColumn;
|
||||
extern const char *kHomeAddressColumn;
|
||||
extern const char *kHomeAddress2Column;
|
||||
extern const char *kHomeCityColumn;
|
||||
extern const char *kHomeStateColumn;
|
||||
extern const char *kHomeZipCodeColumn;
|
||||
extern const char *kHomeCountryColumn;
|
||||
extern const char *kWorkAddressColumn;
|
||||
extern const char *kWorkAddress2Column;
|
||||
extern const char *kWorkCityColumn;
|
||||
extern const char *kWorkStateColumn;
|
||||
extern const char *kWorkZipCodeColumn;
|
||||
extern const char *kWorkCountryColumn;
|
||||
extern const char *kJobTitleColumn;
|
||||
extern const char *kDepartmentColumn;
|
||||
extern const char *kCompanyColumn;
|
||||
extern const char *kWebPage1Column;
|
||||
extern const char *kWebPage2Column;
|
||||
extern const char *kBirthYearColumn;
|
||||
extern const char *kBirthMonthColumn;
|
||||
extern const char *kBirthDayColumn;
|
||||
extern const char *kCustom1Column;
|
||||
extern const char *kCustom2Column;
|
||||
extern const char *kCustom3Column;
|
||||
extern const char *kCustom4Column;
|
||||
extern const char *kNotesColumn;
|
||||
extern const char *kLastModifiedDateColumn;
|
||||
/* end */
|
||||
|
||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
||||
static NS_DEFINE_CID(kAbCardProperty, NS_ABCARDPROPERTY_CID);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// addbook url definition
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
nsAddbookUrl::nsAddbookUrl()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
nsComponentManager::CreateInstance(kSimpleURICID, nsnull,
|
||||
NS_GET_IID(nsIURI),
|
||||
(void **) getter_AddRefs(m_baseURL));
|
||||
nsComponentManager::CreateInstance(kAbCardProperty, nsnull, NS_GET_IID(nsAbCardProperty),
|
||||
(void **) getter_AddRefs(mAbCardProperty));
|
||||
|
||||
mOperationType = nsIAddbookUrlOperation::InvalidUrl;
|
||||
}
|
||||
|
||||
nsAddbookUrl::~nsAddbookUrl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsAddbookUrl, nsIURI)
|
||||
|
||||
//
|
||||
// This will do the parsing for a single address book entry print operation.
|
||||
// In this case, you will have address book folder and email:
|
||||
//
|
||||
// addbook:add?vcard=begin%3Avcard%0Afn%3ARichard%20Pizzarro%0Aemail%3Binternet%3Arhp%40netscape.com%0Aend%3Avcard%0A
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsAddbookUrl::CrackAddURL(char *searchPart)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCString emailAddr = "";
|
||||
nsCString folderName = "";
|
||||
|
||||
char *rest = searchPart;
|
||||
|
||||
// okay, first, free up all of our old search part state.....
|
||||
CleanupAddbookState();
|
||||
|
||||
// Start past the '?'...
|
||||
if (rest && *rest == '?')
|
||||
rest++;
|
||||
|
||||
if (rest)
|
||||
{
|
||||
char *token = nsCRT::strtok(rest, "&", &rest);
|
||||
while (token && *token)
|
||||
{
|
||||
char *value = 0;
|
||||
char *eq = PL_strchr(token, '=');
|
||||
if (eq)
|
||||
{
|
||||
value = eq+1;
|
||||
*eq = 0;
|
||||
}
|
||||
|
||||
switch (nsCRT::ToUpper(*token))
|
||||
{
|
||||
case 'E':
|
||||
if (!nsCRT::strcasecmp (token, "email"))
|
||||
emailAddr = value;
|
||||
break;
|
||||
case 'F':
|
||||
if (!nsCRT::strcasecmp (token, "folder"))
|
||||
folderName = value;
|
||||
break;
|
||||
} // end of switch statement...
|
||||
|
||||
if (eq)
|
||||
*eq = '='; // put it back
|
||||
token = nsCRT::strtok(rest, "&", &rest);
|
||||
} // while we still have part of the url to parse...
|
||||
} // if rest && *rest
|
||||
|
||||
nsUnescape(emailAddr);
|
||||
mAbCardProperty->SetCardValue(kPriEmailColumn, nsString(emailAddr).GetUnicode());
|
||||
|
||||
if (!folderName.IsEmpty())
|
||||
{
|
||||
nsUnescape(folderName);
|
||||
mAbCardProperty->SetCardValue(kWorkAddressBook, nsString(folderName).GetUnicode());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// This will do the parsing for a single address book entry print operation.
|
||||
// In this case, you will have address book folder and email:
|
||||
//
|
||||
// addbook:printall?folder=Netscape%20Address%20Book
|
||||
// addbook:printall?email=rhp@netscape.com&folder=Netscape%20Address%20Book
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsAddbookUrl::CrackPrintURL(char *searchPart, PRInt32 aOperation)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCString emailAddr = "";
|
||||
nsCString folderName = "";
|
||||
|
||||
char *rest = searchPart;
|
||||
|
||||
// okay, first, free up all of our old search part state.....
|
||||
CleanupAddbookState();
|
||||
|
||||
// Start past the '?'...
|
||||
if (rest && *rest == '?')
|
||||
rest++;
|
||||
|
||||
if (rest)
|
||||
{
|
||||
char *token = nsCRT::strtok(rest, "&", &rest);
|
||||
while (token && *token)
|
||||
{
|
||||
char *value = 0;
|
||||
char *eq = PL_strchr(token, '=');
|
||||
if (eq)
|
||||
{
|
||||
value = eq+1;
|
||||
*eq = 0;
|
||||
}
|
||||
|
||||
switch (nsCRT::ToUpper(*token))
|
||||
{
|
||||
case 'E':
|
||||
if (!nsCRT::strcasecmp (token, "email"))
|
||||
emailAddr = value;
|
||||
break;
|
||||
case 'F':
|
||||
if (!nsCRT::strcasecmp (token, "folder"))
|
||||
folderName = value;
|
||||
break;
|
||||
} // end of switch statement...
|
||||
|
||||
if (eq)
|
||||
*eq = '='; // put it back
|
||||
token = nsCRT::strtok(rest, "&", &rest);
|
||||
} // while we still have part of the url to parse...
|
||||
} // if rest && *rest
|
||||
|
||||
// Now unescape any fields that need escaped...
|
||||
if (emailAddr.IsEmpty() && (aOperation == nsIAddbookUrlOperation::PrintIndividual))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsUnescape(emailAddr);
|
||||
mAbCardProperty->SetCardValue(kPriEmailColumn, nsString(emailAddr).GetUnicode());
|
||||
|
||||
if (!folderName.IsEmpty())
|
||||
{
|
||||
nsUnescape(folderName);
|
||||
mAbCardProperty->SetCardValue(kWorkAddressBook, nsString(folderName).GetUnicode());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookUrl::SetSpec(const char * aSpec)
|
||||
{
|
||||
m_baseURL->SetSpec(aSpec);
|
||||
return ParseUrl();
|
||||
}
|
||||
|
||||
nsresult nsAddbookUrl::CleanupAddbookState()
|
||||
{
|
||||
PRUnichar *tString = nsnull;
|
||||
|
||||
mAbCardProperty->SetCardValue(kFirstNameColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kLastNameColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kDisplayNameColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kNicknameColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kPriEmailColumn, tString);
|
||||
mAbCardProperty->SetCardValue(k2ndEmailColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kPlainTextColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkPhoneColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomePhoneColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kFaxColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kPagerColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kCellularColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeAddressColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeAddress2Column, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeCityColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeStateColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeZipCodeColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kHomeCountryColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkAddressColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkAddress2Column, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkCityColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkStateColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkZipCodeColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWorkCountryColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kJobTitleColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kDepartmentColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kCompanyColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kWebPage1Column, tString);
|
||||
mAbCardProperty->SetCardValue(kWebPage2Column, tString);
|
||||
mAbCardProperty->SetCardValue(kBirthYearColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kBirthMonthColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kBirthDayColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kCustom1Column, tString);
|
||||
mAbCardProperty->SetCardValue(kCustom2Column, tString);
|
||||
mAbCardProperty->SetCardValue(kCustom3Column, tString);
|
||||
mAbCardProperty->SetCardValue(kCustom4Column, tString);
|
||||
mAbCardProperty->SetCardValue(kNotesColumn, tString);
|
||||
mAbCardProperty->SetCardValue(kLastModifiedDateColumn, tString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsAddbookUrl::ParseUrl()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCAutoString searchPart;
|
||||
|
||||
// we can get the path from the simple url.....
|
||||
nsXPIDLCString aPath;
|
||||
m_baseURL->GetPath(getter_Copies(aPath));
|
||||
if (aPath)
|
||||
mOperationPart = aPath;
|
||||
|
||||
PRInt32 startOfSearchPart = mOperationPart.FindChar('?');
|
||||
if (startOfSearchPart > 0)
|
||||
{
|
||||
// now parse out the search field...
|
||||
PRUint32 numExtraChars = mOperationPart.Mid(searchPart, startOfSearchPart, -1);
|
||||
if (!searchPart.IsEmpty())
|
||||
{
|
||||
// now we need to strip off the search part from the
|
||||
// to part....
|
||||
mOperationPart.Cut(startOfSearchPart, numExtraChars);
|
||||
}
|
||||
}
|
||||
else if (!mOperationPart.IsEmpty())
|
||||
{
|
||||
nsUnescape(mOperationPart);
|
||||
}
|
||||
|
||||
mOperationPart.ToLowerCase();
|
||||
// Now, figure out what we are supposed to be doing?
|
||||
if (mOperationPart == "printone")
|
||||
{
|
||||
mOperationType = nsIAddbookUrlOperation::PrintIndividual;
|
||||
rv = CrackPrintURL(searchPart, mOperationType);
|
||||
}
|
||||
else if (mOperationPart == "printall")
|
||||
{
|
||||
mOperationType = nsIAddbookUrlOperation::PrintAddressBook;
|
||||
rv = CrackPrintURL(searchPart, mOperationType);
|
||||
}
|
||||
else if (mOperationPart == "add")
|
||||
{
|
||||
mOperationType = nsIAddbookUrlOperation::AddToAddressBook;
|
||||
rv = CrackAddURL(searchPart);
|
||||
}
|
||||
else
|
||||
mOperationType = nsIAddbookUrlOperation::InvalidUrl;
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
mOperationType = nsIAddbookUrlOperation::InvalidUrl;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// Begin nsIURI support
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetSpec(char * *aSpec)
|
||||
{
|
||||
return m_baseURL->GetSpec(aSpec);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetScheme(char * *aScheme)
|
||||
{
|
||||
return m_baseURL->GetScheme(aScheme);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetScheme(const char * aScheme)
|
||||
{
|
||||
return m_baseURL->SetScheme(aScheme);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetPreHost(char * *aPreHost)
|
||||
{
|
||||
return m_baseURL->GetPreHost(aPreHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetPreHost(const char * aPreHost)
|
||||
{
|
||||
return m_baseURL->SetPreHost(aPreHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetUsername(char * *aUsername)
|
||||
{
|
||||
return m_baseURL->GetUsername(aUsername);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetUsername(const char * aUsername)
|
||||
{
|
||||
return m_baseURL->SetUsername(aUsername);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetPassword(char * *aPassword)
|
||||
{
|
||||
return m_baseURL->GetPassword(aPassword);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetPassword(const char * aPassword)
|
||||
{
|
||||
return m_baseURL->SetPassword(aPassword);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetHost(char * *aHost)
|
||||
{
|
||||
return m_baseURL->GetHost(aHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetHost(const char * aHost)
|
||||
{
|
||||
return m_baseURL->SetHost(aHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetPort(PRInt32 *aPort)
|
||||
{
|
||||
return m_baseURL->GetPort(aPort);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetPort(PRInt32 aPort)
|
||||
{
|
||||
return m_baseURL->SetPort(aPort);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetPath(char * *aPath)
|
||||
{
|
||||
return m_baseURL->GetPath(aPath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetPath(const char * aPath)
|
||||
{
|
||||
return m_baseURL->SetPath(aPath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::Equals(nsIURI *other, PRBool *_retval)
|
||||
{
|
||||
return m_baseURL->Equals(other, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::GetURLParser(nsIURLParser * *aURLParser)
|
||||
{
|
||||
return m_baseURL->GetURLParser(aURLParser);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetURLParser(nsIURLParser * aURLParser)
|
||||
{
|
||||
return m_baseURL->SetURLParser(aURLParser);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::Clone(nsIURI **_retval)
|
||||
{
|
||||
return m_baseURL->Clone(_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::SetRelativePath(const char *i_RelativePath)
|
||||
{
|
||||
return m_baseURL->SetRelativePath(i_RelativePath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddbookUrl::Resolve(const char *relativePath, char **result)
|
||||
{
|
||||
return m_baseURL->Resolve(relativePath, result);
|
||||
}
|
||||
|
||||
//
|
||||
// Specific nsAddbookUrl operations
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsAddbookUrl::GetAddbookOperation(PRInt32 *_retval)
|
||||
{
|
||||
*_retval = mOperationType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAddbookUrl::GetAbCard(nsIAbCard **aAbCard)
|
||||
{
|
||||
if (!mAbCardProperty)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIAbCard> tCard = do_QueryInterface(mAbCardProperty);
|
||||
if (!tCard)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aAbCard = tCard;
|
||||
NS_ADDREF(*aAbCard);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsAddbookUrl_h__
|
||||
#define nsAddbookUrl_h__
|
||||
|
||||
#include "nsISmtpUrl.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsMsgMailNewsUrl.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIMsgIdentity.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsINetPrompt.h"
|
||||
#include "nsISmtpServer.h"
|
||||
#include "nsIAddbookUrl.h"
|
||||
#include "nsAbCardProperty.h"
|
||||
#include "nsIAbCard.h"
|
||||
|
||||
class nsAddbookUrl : public nsIAddbookUrl
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURI
|
||||
NS_DECL_NSIADDBOOKURL
|
||||
|
||||
nsAddbookUrl();
|
||||
virtual ~nsAddbookUrl();
|
||||
|
||||
protected:
|
||||
nsresult CleanupAddbookState();
|
||||
|
||||
nsresult ParseUrl(); // This gets the ball rolling...
|
||||
|
||||
NS_METHOD CrackAddURL(char *searchPart);
|
||||
NS_METHOD CrackPrintURL(char *searchPart, PRInt32 aOperation);
|
||||
NS_METHOD GetAbCardProperty(nsAbCardProperty **aAbCardProp);
|
||||
|
||||
nsCString mOperationPart; // string name of operation requested
|
||||
PRInt32 mOperationType; // the internal ID for the operation
|
||||
|
||||
nsCOMPtr<nsIURI> m_baseURL; // the base URL for the object
|
||||
nsCOMPtr<nsAbCardProperty> mAbCardProperty; // Hold all parsed user info here
|
||||
|
||||
};
|
||||
|
||||
#endif // nsAddbookUrl_h__
|
Загрузка…
Ссылка в новой задаче