зеркало из https://github.com/mozilla/pjs.git
Bug 119051 duplicate symbol breaks win32 static build
create and use nsIIOService::getQueryAttributeValue r=dbradley sr=darin
This commit is contained in:
Родитель
7fd85fc3e4
Коммит
eef5c54aad
|
@ -29,8 +29,6 @@
|
|||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
#define DEFAULT_IMAGE_SIZE 16
|
||||
|
||||
static void extractAttributeValue(const char * searchString, const char * attributeName, char ** result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(inBitmapURI, inIBitmapURI, nsIURI)
|
||||
|
@ -76,39 +74,6 @@ inBitmapURI::GetSpec(char* *aSpec)
|
|||
return FormatSpec(aSpec);
|
||||
}
|
||||
|
||||
// takes a string like ?size=32&contentType=text/html and returns a new string
|
||||
// containing just the attribute value. i.e you could pass in this string with
|
||||
// an attribute name of size, this will return 32
|
||||
// Assumption: attribute pairs in the string are separated by '&'.
|
||||
static void extractAttributeValue(const char * searchString, const char * attributeName, char ** result)
|
||||
{
|
||||
//NS_ENSURE_ARG_POINTER(extractAttributeValue);
|
||||
|
||||
char * attributeValue = nsnull;
|
||||
if (searchString && attributeName)
|
||||
{
|
||||
// search the string for attributeName
|
||||
PRUint32 attributeNameSize = PL_strlen(attributeName);
|
||||
char * startOfAttribute = PL_strcasestr(searchString, attributeName);
|
||||
if (startOfAttribute)
|
||||
{
|
||||
startOfAttribute += attributeNameSize; // skip over the attributeName
|
||||
if (startOfAttribute) // is there something after the attribute name
|
||||
{
|
||||
char * endofAttribute = startOfAttribute ? PL_strchr(startOfAttribute, '&') : nsnull;
|
||||
if (startOfAttribute && endofAttribute) // is there text after attribute value
|
||||
attributeValue = PL_strndup(startOfAttribute, endofAttribute - startOfAttribute);
|
||||
else // there is nothing left so eat up rest of line.
|
||||
attributeValue = PL_strdup(startOfAttribute);
|
||||
} // if we have a attribute value
|
||||
|
||||
} // if we have a attribute name
|
||||
} // if we got non-null search string and attribute name values
|
||||
|
||||
*result = attributeValue; // passing ownership of attributeValue into result...no need to
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inBitmapURI::SetSpec(const char* aSpec)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,8 @@
|
|||
#include "nsMsgDBCID.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIMsgHdr.h"
|
||||
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "rdf.h"
|
||||
|
@ -113,7 +114,7 @@ static char *nsMailboxGetURI(const char *nativepath)
|
|||
nsFilePath serverPath(spec);
|
||||
|
||||
// check if filepath begins with serverPath
|
||||
PRInt32 len = PL_strlen(serverPath);
|
||||
PRInt32 len = strlen(serverPath);
|
||||
if (PL_strncasecmp(serverPath, filePath, len) == 0) {
|
||||
nsXPIDLCString serverURI;
|
||||
rv = server->GetServerURI(getter_Copies(serverURI));
|
||||
|
@ -138,10 +139,6 @@ static char *nsMailboxGetURI(const char *nativepath)
|
|||
return uri;
|
||||
}
|
||||
|
||||
|
||||
// helper function for parsing the search field of a url
|
||||
char * extractAttributeValue(const char * searchString, const char * attributeName);
|
||||
|
||||
nsMailboxUrl::nsMailboxUrl()
|
||||
{
|
||||
m_mailboxAction = nsIMailboxUrl::ActionParseMailbox;
|
||||
|
@ -373,31 +370,35 @@ NS_IMETHODIMP nsMailboxUrl::IsUrlType(PRUint32 type, PRBool *isType)
|
|||
|
||||
nsresult nsMailboxUrl::ParseSearchPart()
|
||||
{
|
||||
nsXPIDLCString searchPart;
|
||||
nsresult rv = GetQuery(getter_Copies(searchPart));
|
||||
// add code to this function to decompose everything past the '?'.....
|
||||
if (NS_SUCCEEDED(rv) && searchPart)
|
||||
{
|
||||
// the action for this mailbox must be a display message...
|
||||
char * msgPart = extractAttributeValue(searchPart, "part=");
|
||||
if (msgPart) // if we have a part in the url then we must be fetching just the part.
|
||||
m_mailboxAction = nsIMailboxUrl::ActionFetchPart;
|
||||
nsXPIDLCString searchPart;
|
||||
nsresult rv = GetQuery(getter_Copies(searchPart));
|
||||
// add code to this function to decompose everything past the '?'.....
|
||||
if (NS_SUCCEEDED(rv) && searchPart)
|
||||
{
|
||||
char * msgPart = nsnull;
|
||||
nsCOMPtr<nsIIOService> ioService (do_GetIOService(&rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
// the action for this mailbox must be a display message...
|
||||
rv = ioService->GetQueryAttributeValue(searchPart, "part", &msgPart);
|
||||
// if we have a part in the url then we must be fetching just the part.
|
||||
m_mailboxAction = NS_SUCCEEDED(rv)
|
||||
? nsIMailboxUrl::ActionFetchPart
|
||||
: nsIMailboxUrl::ActionFetchMessage;
|
||||
PR_FREEIF(msgPart);
|
||||
|
||||
char * messageKey = nsnull;
|
||||
rv = ioService->GetQueryAttributeValue(searchPart, "number", &messageKey);
|
||||
ioService->GetQueryAttributeValue(searchPart, "messageid", &m_messageID);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
m_messageKey = atol(messageKey); // convert to a long...
|
||||
PR_FREEIF(messageKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
m_mailboxAction = nsIMailboxUrl::ActionFetchMessage;
|
||||
m_mailboxAction = nsIMailboxUrl::ActionParseMailbox;
|
||||
|
||||
char * messageKey = extractAttributeValue(searchPart, "number=");
|
||||
m_messageID = extractAttributeValue(searchPart,"messageid=");
|
||||
if (messageKey)
|
||||
m_messageKey = atol(messageKey); // convert to a long...
|
||||
if (messageKey || m_messageID)
|
||||
|
||||
PR_FREEIF(msgPart);
|
||||
PR_FREEIF(messageKey);
|
||||
}
|
||||
else
|
||||
m_mailboxAction = nsIMailboxUrl::ActionParseMailbox;
|
||||
|
||||
return rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// warning: don't assume when parsing the url that the protocol part is "news"...
|
||||
|
@ -410,7 +411,7 @@ nsresult nsMailboxUrl::ParseUrl()
|
|||
// ### fix me.
|
||||
// this hack is to avoid asserting on every local message loaded because the security manager
|
||||
// is creating an empty "mailbox://" uri for every message.
|
||||
if (nsCRT::strlen(m_file) < 2)
|
||||
if (strlen(m_file) < 2)
|
||||
m_filePath = nsnull;
|
||||
else
|
||||
m_filePath = new nsFileSpec(nsFilePath(nsUnescape((char *) (const char *)m_file)));
|
||||
|
@ -433,43 +434,6 @@ NS_IMETHODIMP nsMailboxUrl::SetQuery(const char *aQuery)
|
|||
return rv;
|
||||
}
|
||||
|
||||
// takes a string like ?messageID=fooo&number=MsgKey and returns a new string
|
||||
// containing just the attribute value. i.e you could pass in this string with
|
||||
// an attribute name of messageID and I'll return fooo. Use PR_Free to delete
|
||||
// this string...
|
||||
|
||||
// Assumption: attribute pairs in the string are separated by '&'.
|
||||
char * extractAttributeValue(const char * searchString, const char * attributeName)
|
||||
{
|
||||
char * attributeValue = nsnull;
|
||||
|
||||
if (searchString && attributeName)
|
||||
{
|
||||
// search the string for attributeName
|
||||
PRUint32 attributeNameSize = PL_strlen(attributeName);
|
||||
char * startOfAttribute = PL_strcasestr(searchString, attributeName);
|
||||
if (startOfAttribute)
|
||||
{
|
||||
startOfAttribute += attributeNameSize; // skip over the attributeName
|
||||
if (startOfAttribute) // is there something after the attribute name
|
||||
{
|
||||
char * endofAttribute = startOfAttribute ? PL_strchr(startOfAttribute, '&') : nsnull;
|
||||
if (startOfAttribute && endofAttribute) // is there text after attribute value
|
||||
attributeValue = PL_strndup(startOfAttribute, endofAttribute - startOfAttribute);
|
||||
else // there is nothing left so eat up rest of line.
|
||||
attributeValue = PL_strdup(startOfAttribute);
|
||||
|
||||
// now unescape the string...
|
||||
if (attributeValue)
|
||||
attributeValue = nsUnescape(attributeValue); // unescape the string...
|
||||
} // if we have a attribute value
|
||||
|
||||
} // if we have a attribute name
|
||||
} // if we got non-null search string and attribute name values
|
||||
|
||||
return attributeValue;
|
||||
}
|
||||
|
||||
// nsIMsgI18NUrl support
|
||||
|
||||
nsresult nsMailboxUrl::GetMsgFolder(nsIMsgFolder **msgFolder)
|
||||
|
|
|
@ -62,6 +62,15 @@ interface nsIIOService : nsISupports
|
|||
*/
|
||||
unsigned long getProtocolFlags(in string scheme);
|
||||
|
||||
/**
|
||||
* Returns the value of an attribute of a query string.
|
||||
*
|
||||
* @param searchString (eg "?size=32&contentType=text/html")
|
||||
* @param attributeName (eg "size" or "contentType")
|
||||
* @return new string containing value (eg "32" or "text/html")
|
||||
*/
|
||||
string getQueryAttributeValue(in string searchString, in string attributeName);
|
||||
|
||||
/**
|
||||
* This method constructs a new URI by first determining the scheme
|
||||
* of the URI spec, and then delegating the construction of the URI
|
||||
|
|
|
@ -403,7 +403,7 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
|||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX_LENGTH
|
||||
== nsCRT::strlen(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX),
|
||||
== strlen(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX),
|
||||
"need to fix NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX_LENGTH");
|
||||
|
||||
NS_ENSURE_ARG_POINTER(scheme);
|
||||
|
@ -484,7 +484,7 @@ nsIOService::GetParserForScheme(const char *scheme, nsIURLParser **_retval)
|
|||
rv = entry->GetData(getter_Copies(entryString));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
if (nsCRT::strcmp(entryString, scheme) == 0) {
|
||||
if (strcmp(entryString, scheme) == 0) {
|
||||
nsXPIDLCString contractID;
|
||||
rv = catmgr->GetCategoryEntry(NS_IURLPARSER_KEY,(const char *)entryString, getter_Copies(contractID));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
@ -530,7 +530,7 @@ ExtractUrlPart_Helper(const char *src, PRUint32 pos, PRInt32 len,
|
|||
if (endPos)
|
||||
*endPos = pos + len;
|
||||
if (urlPart)
|
||||
*urlPart = PL_strndup(src + pos, len);
|
||||
*urlPart = nsCRT::strndup(src + pos, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,6 +699,57 @@ nsIOService::GetProtocolFlags(const char* scheme, PRUint32 *flags)
|
|||
return rv;
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
LocateStartOfAttribute(
|
||||
const char *searchString,
|
||||
char prefix,
|
||||
const char *attr,
|
||||
PRUint32 attrLen)
|
||||
{
|
||||
const char *p = strchr(searchString, prefix);
|
||||
if (p && !nsCRT::strncasecmp(p+1, attr, attrLen) && p[attrLen+2] == '=')
|
||||
return p + 1;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIOService::GetQueryAttributeValue(
|
||||
const char * searchString,
|
||||
const char * attrName,
|
||||
char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(searchString);
|
||||
NS_ENSURE_ARG_POINTER(attrName);
|
||||
|
||||
PRUint32 attrLen = strlen(attrName);
|
||||
|
||||
const char * attrStart;
|
||||
|
||||
attrStart = LocateStartOfAttribute(searchString, '?', attrName, attrLen);
|
||||
if (!attrStart) {
|
||||
attrStart = LocateStartOfAttribute(searchString, '&', attrName, attrLen);
|
||||
if (!attrStart)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
attrStart += attrLen + 1; // skip over the attrName
|
||||
// is there something after the attribute name?
|
||||
if (*attrStart) {
|
||||
const char *attrEnd = strchr(attrStart, '&');
|
||||
if (result) {
|
||||
*result = attrEnd
|
||||
? // is there text after attribute value
|
||||
nsCRT::strndup(attrStart, attrEnd - attrStart)
|
||||
: // there is nothing left so eat up rest of line
|
||||
nsCRT::strdup(attrStart);
|
||||
if (!*result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI, nsIURI* *result)
|
||||
|
@ -777,7 +828,7 @@ nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
|
|||
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
|
||||
if (pi && !nsCRT::strcmp(pi->Type(),"http")) {
|
||||
if (pi && !strcmp(pi->Type(),"http")) {
|
||||
// we are going to proxy this channel using an http proxy
|
||||
rv = GetProtocolHandler("http", getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -976,11 +1027,11 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|||
if (!prefs) return;
|
||||
|
||||
// Look for extra ports to block
|
||||
if (!pref || PL_strcmp(pref, PORT_PREF("banned")) == 0)
|
||||
if (!pref || strcmp(pref, PORT_PREF("banned")) == 0)
|
||||
ParsePortList(prefs, PORT_PREF("banned"), PR_FALSE);
|
||||
|
||||
// ...as well as previous blocks to remove.
|
||||
if (!pref || PL_strcmp(pref, PORT_PREF("banned.override")) == 0)
|
||||
if (!pref || strcmp(pref, PORT_PREF("banned.override")) == 0)
|
||||
ParsePortList(prefs, PORT_PREF("banned.override"), PR_TRUE);
|
||||
}
|
||||
|
||||
|
@ -1024,18 +1075,18 @@ nsIOService::Observe(nsISupports *subject,
|
|||
const char *topic,
|
||||
const PRUnichar *data)
|
||||
{
|
||||
if (!nsCRT::strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
|
||||
if (prefBranch)
|
||||
PrefsChanged(prefBranch, NS_ConvertUCS2toUTF8(data).get());
|
||||
}
|
||||
else if (!nsCRT::strcmp(topic, kProfileChangeNetTeardownTopic)) {
|
||||
else if (!strcmp(topic, kProfileChangeNetTeardownTopic)) {
|
||||
if (!mOffline) {
|
||||
SetOffline(PR_TRUE);
|
||||
mOfflineForProfileChange = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else if (!nsCRT::strcmp(topic, kProfileChangeNetRestoreTopic)) {
|
||||
else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) {
|
||||
if (mOfflineForProfileChange) {
|
||||
SetOffline(PR_FALSE);
|
||||
mOfflineForProfileChange = PR_FALSE;
|
||||
|
@ -1064,7 +1115,7 @@ nsIOService::ParseFileURL(const char* inURL,
|
|||
nsXPIDLCString scheme;
|
||||
rv = ExtractScheme(inURL, nsnull, nsnull, getter_Copies(scheme));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (nsCRT::strcmp(scheme.get(), "file") != 0) {
|
||||
if (strcmp(scheme.get(), "file") != 0) {
|
||||
NS_ERROR("must be a file:// url");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
@ -1101,11 +1152,11 @@ nsIOService::ParseFileURL(const char* inURL,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (directoryLen > 0)
|
||||
*outDirectory = PL_strndup(inURL + filepathPos + directoryPos, directoryLen);
|
||||
*outDirectory = nsCRT::strndup(inURL + filepathPos + directoryPos, directoryLen);
|
||||
if (basenameLen > 0)
|
||||
*outFileBaseName = PL_strndup(inURL + filepathPos + basenamePos, basenameLen);
|
||||
*outFileBaseName = nsCRT::strndup(inURL + filepathPos + basenamePos, basenameLen);
|
||||
if (extensionLen > 0)
|
||||
*outFileExtension = PL_strndup(inURL + filepathPos + extensionPos, extensionLen);
|
||||
*outFileExtension = nsCRT::strndup(inURL + filepathPos + extensionPos, extensionLen);
|
||||
// since we are using a no-auth url parser, there will never be a host
|
||||
|
||||
return NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче