зеркало из https://github.com/mozilla/pjs.git
bug 47437, nscookie.cpp is duplicationg URL parsing logic, c=andreas.otte, r=morse, sr=alecf
This commit is contained in:
Родитель
934d942dca
Коммит
6ea1d428ef
|
@ -50,8 +50,10 @@
|
|||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -76,9 +78,10 @@ nsCookieService::~nsCookieService(void)
|
|||
nsresult nsCookieService::Init()
|
||||
{
|
||||
COOKIE_RegisterPrefCallbacks();
|
||||
nsresult rv;
|
||||
mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
||||
COOKIE_Read();
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (observerService) {
|
||||
|
@ -156,7 +159,7 @@ nsCookieService::GetCookieString(nsIURI *aURL, char ** aCookie) {
|
|||
nsXPIDLCString spec;
|
||||
nsresult rv = aURL->GetSpec(getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aCookie = COOKIE_GetCookie((char *)(const char *)spec);
|
||||
*aCookie = COOKIE_GetCookie((char *)(const char *)spec, mIOService);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -172,9 +175,9 @@ nsCookieService::GetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, char *
|
|||
nsXPIDLCString firstSpec;
|
||||
rv = aFirstURL->GetSpec(getter_Copies(firstSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aCookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, (char *)(const char *)firstSpec);
|
||||
*aCookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, (char *)(const char *)firstSpec, mIOService);
|
||||
} else {
|
||||
*aCookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, nsnull);
|
||||
*aCookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, nsnull, mIOService);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -185,7 +188,7 @@ nsCookieService::SetCookieString(nsIURI *aURL, nsIPrompt* aPrompt, const char *
|
|||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
|
||||
COOKIE_SetCookieString(spec, aPrompt, aCookie);
|
||||
COOKIE_SetCookieString(spec, aPrompt, aCookie, mIOService);
|
||||
nsCRT::free(spec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -201,7 +204,7 @@ nsCookieService::SetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, nsIPro
|
|||
char *firstSpec = NULL;
|
||||
rv = aFirstURL->GetSpec(&firstSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
COOKIE_SetCookieStringFromHttp(spec, firstSpec, aPrompter, aCookie, (char *)aExpires);
|
||||
COOKIE_SetCookieStringFromHttp(spec, firstSpec, aPrompter, aCookie, (char *)aExpires, mIOService);
|
||||
nsCRT::free(firstSpec);
|
||||
}
|
||||
nsCRT::free(spec);
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsIObserver.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -61,7 +62,10 @@ public:
|
|||
nsCookieService();
|
||||
virtual ~nsCookieService(void);
|
||||
nsresult Init();
|
||||
|
||||
|
||||
protected:
|
||||
// cached IOService
|
||||
nsCOMPtr<nsIIOService> mIOService;
|
||||
};
|
||||
|
||||
#endif /* nsCookieService_h__ */
|
||||
|
|
|
@ -584,7 +584,7 @@ cookie_IsInDomain(char* domain, char* host, int hostLength) {
|
|||
** to the caller to free any returned string
|
||||
*/
|
||||
PUBLIC char *
|
||||
COOKIE_GetCookie(char * address) {
|
||||
COOKIE_GetCookie(char * address, nsIIOService* ioService) {
|
||||
char *name=0;
|
||||
cookie_CookieStruct * cookie_s;
|
||||
PRBool isSecure = PR_FALSE;
|
||||
|
@ -607,8 +607,17 @@ COOKIE_GetCookie(char * address) {
|
|||
if (cookie_list == nsnull) {
|
||||
return nsnull;
|
||||
}
|
||||
char *host = CKutil_ParseURL(address, GET_HOST_PART);
|
||||
char *path = CKutil_ParseURL(address, GET_PATH_PART);
|
||||
char *host = nsnull;
|
||||
char *path = nsnull;
|
||||
PRUint32 start, end;
|
||||
// Get host and path
|
||||
nsresult result;
|
||||
NS_ASSERTION(ioService, "IOService not available");
|
||||
result = ioService->ExtractUrlPart(address, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end,
|
||||
&host);
|
||||
result = ioService->ExtractUrlPart(address, nsIIOService::url_Path,
|
||||
&start, &end, &path);
|
||||
for (PRInt32 i = 0; i <cookie_list->Count(); i++) {
|
||||
cookie_s = NS_STATIC_CAST(cookie_CookieStruct*, cookie_list->ElementAt(i));
|
||||
NS_ASSERTION(cookie_s, "corrupt cookie list");
|
||||
|
@ -727,12 +736,22 @@ cookie_SameDomain(char * currentHost, char * firstHost) {
|
|||
}
|
||||
|
||||
PRBool
|
||||
cookie_isForeign (char * curURL, char * firstURL) {
|
||||
cookie_isForeign (char * curURL, char * firstURL, nsIIOService* ioService) {
|
||||
if (!firstURL) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
char * curHost = CKutil_ParseURL(curURL, GET_HOST_PART);
|
||||
char * firstHost = CKutil_ParseURL(firstURL, GET_HOST_PART);
|
||||
char *curHost = nsnull;
|
||||
char *firstHost = nsnull;
|
||||
PRUint32 start,end;
|
||||
nsresult rv;
|
||||
NS_ASSERTION(ioService, "IOService not available");
|
||||
// Get hosts
|
||||
rv = ioService->ExtractUrlPart(curURL, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end,
|
||||
&curHost);
|
||||
rv = ioService->ExtractUrlPart(firstURL, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end,
|
||||
&firstHost);
|
||||
char * curHostColon = 0;
|
||||
char * firstHostColon = 0;
|
||||
|
||||
|
@ -798,8 +817,9 @@ cookie_P3PUserPref(PRInt32 policy, PRBool foreign) {
|
|||
* returns P3P_Accept, P3P_Downgrade, or P3P_Reject based on user's preferences
|
||||
*/
|
||||
int
|
||||
cookie_P3PDecision (char * curURL, char * firstURL) {
|
||||
return cookie_P3PUserPref(P3P_SitePolicy(curURL), cookie_isForeign(curURL, firstURL));
|
||||
cookie_P3PDecision (char * curURL, char * firstURL, nsIIOService* ioService) {
|
||||
return cookie_P3PUserPref(P3P_SitePolicy(curURL),
|
||||
cookie_isForeign(curURL, firstURL, ioService));
|
||||
}
|
||||
|
||||
/* returns PR_TRUE if authorization is required
|
||||
|
@ -809,15 +829,16 @@ cookie_P3PDecision (char * curURL, char * firstURL) {
|
|||
** to the caller to free any returned string
|
||||
*/
|
||||
PUBLIC char *
|
||||
COOKIE_GetCookieFromHttp(char * address, char * firstAddress) {
|
||||
COOKIE_GetCookieFromHttp(char * address, char * firstAddress,
|
||||
nsIIOService* ioService) {
|
||||
|
||||
if ((cookie_GetBehaviorPref() == PERMISSION_P3P) &&
|
||||
(cookie_P3PDecision(address, firstAddress) == P3P_Reject)) {
|
||||
(cookie_P3PDecision(address, firstAddress, ioService) == P3P_Reject)) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
if ((cookie_GetBehaviorPref() == PERMISSION_DontAcceptForeign) &&
|
||||
(!firstAddress || cookie_isForeign(address, firstAddress))) {
|
||||
(!firstAddress || cookie_isForeign(address, firstAddress, ioService))) {
|
||||
|
||||
/*
|
||||
* WARNING!!! This is a different behavior than 4.x. In 4.x we used this pref to
|
||||
|
@ -830,7 +851,7 @@ COOKIE_GetCookieFromHttp(char * address, char * firstAddress) {
|
|||
|
||||
return nsnull;
|
||||
}
|
||||
return COOKIE_GetCookie(address);
|
||||
return COOKIE_GetCookie(address, ioService);
|
||||
}
|
||||
|
||||
MODULE_PRIVATE PRBool
|
||||
|
@ -878,12 +899,21 @@ cookie_Count(char * host) {
|
|||
* this via COOKIE_SetCookieStringFromHttp.
|
||||
*/
|
||||
PRIVATE void
|
||||
cookie_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCookieHeader, time_t timeToExpire) {
|
||||
cookie_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCookieHeader, time_t timeToExpire, nsIIOService* ioService) {
|
||||
cookie_CookieStruct * prev_cookie;
|
||||
char *path_from_header=nsnull, *host_from_header=nsnull;
|
||||
char *name_from_header=nsnull, *cookie_from_header=nsnull;
|
||||
char *cur_path = CKutil_ParseURL(curURL, GET_PATH_PART);
|
||||
char *cur_host = CKutil_ParseURL(curURL, GET_HOST_PART);
|
||||
char *cur_host = nsnull;
|
||||
char *cur_path = nsnull;
|
||||
PRUint32 start,end;
|
||||
nsresult rv;
|
||||
NS_ASSERTION(ioService, "IOService not available");
|
||||
// Get host and path
|
||||
rv = ioService->ExtractUrlPart(curURL, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end,
|
||||
&cur_host);
|
||||
rv = ioService->ExtractUrlPart(curURL, nsIIOService::url_Path,
|
||||
&start, &end, &cur_path);
|
||||
char *semi_colon, *ptr, *equal;
|
||||
char *setCookieHeaderInternal = (char *) setCookieHeader;
|
||||
PRBool isSecure=PR_FALSE, isDomain=PR_FALSE;
|
||||
|
@ -1228,8 +1258,8 @@ cookie_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCook
|
|||
}
|
||||
|
||||
PUBLIC void
|
||||
COOKIE_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCookieHeader) {
|
||||
COOKIE_SetCookieStringFromHttp(curURL, nsnull, aPrompter, setCookieHeader, 0);
|
||||
COOKIE_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCookieHeader, nsIIOService* ioService) {
|
||||
COOKIE_SetCookieStringFromHttp(curURL, nsnull, aPrompter, setCookieHeader, 0, ioService);
|
||||
}
|
||||
|
||||
/* This function wrapper wraps COOKIE_SetCookieString for the purposes of
|
||||
|
@ -1241,15 +1271,15 @@ COOKIE_SetCookieString(char * curURL, nsIPrompt *aPrompter, const char * setCook
|
|||
*/
|
||||
|
||||
PUBLIC void
|
||||
COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPrompter, const char * setCookieHeader, char * server_date) {
|
||||
COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPrompter, const char * setCookieHeader, char * server_date, nsIIOService* ioService) {
|
||||
|
||||
/* allow for multiple cookies separated by newlines */
|
||||
char *newline = PL_strchr(setCookieHeader, '\n');
|
||||
if(newline) {
|
||||
*newline = '\0';
|
||||
COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, setCookieHeader, server_date);
|
||||
COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, setCookieHeader, server_date, ioService);
|
||||
*newline = '\n';
|
||||
COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, newline+1, server_date);
|
||||
COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, newline+1, server_date, ioService);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1266,7 +1296,7 @@ COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPromp
|
|||
|
||||
/* check to see if P3P pref is satisfied */
|
||||
if (cookie_GetBehaviorPref() == PERMISSION_P3P) {
|
||||
PRInt32 decision = cookie_P3PDecision(curURL, firstURL);
|
||||
PRInt32 decision = cookie_P3PDecision(curURL, firstURL, ioService);
|
||||
if (decision == P3P_Reject) {
|
||||
return;
|
||||
}
|
||||
|
@ -1277,7 +1307,7 @@ COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPromp
|
|||
|
||||
/* check for foreign cookie if pref says to reject such */
|
||||
if ((cookie_GetBehaviorPref() == PERMISSION_DontAcceptForeign) &&
|
||||
cookie_isForeign(curURL, firstURL)) {
|
||||
cookie_isForeign(curURL, firstURL, ioService)) {
|
||||
/* it's a foreign cookie so don't set the cookie */
|
||||
return;
|
||||
}
|
||||
|
@ -1329,7 +1359,7 @@ COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPromp
|
|||
gmtCookieExpires = get_current_time() + atoi(ptr);
|
||||
}
|
||||
|
||||
cookie_SetCookieString(curURL, aPrompter, setCookieHeader, gmtCookieExpires);
|
||||
cookie_SetCookieString(curURL, aPrompter, setCookieHeader, gmtCookieExpires, ioService);
|
||||
}
|
||||
|
||||
/* saves out the HTTP cookies to disk */
|
||||
|
|
|
@ -47,15 +47,16 @@
|
|||
#define NS_COOKIE NS_IMPORT
|
||||
#endif
|
||||
|
||||
#include "nsIIOService.h"
|
||||
|
||||
class nsIPrompt;
|
||||
|
||||
extern nsresult COOKIE_Read();
|
||||
extern nsresult COOKIE_Write();
|
||||
extern char * COOKIE_GetCookie(char * address);
|
||||
extern char * COOKIE_GetCookieFromHttp(char * address, char * firstAddress);
|
||||
extern void COOKIE_SetCookieString(char * cur_url, nsIPrompt *aPrompter, const char * set_cookie_header);
|
||||
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * first_url, nsIPrompt *aPRompter, const char * set_cookie_header, char * server_date);
|
||||
extern char * COOKIE_GetCookie(char * address, nsIIOService* ioService);
|
||||
extern char * COOKIE_GetCookieFromHttp(char * address, char * firstAddress, nsIIOService* ioService);
|
||||
extern void COOKIE_SetCookieString(char * cur_url, nsIPrompt *aPrompter, const char * set_cookie_header, nsIIOService* ioService);
|
||||
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * first_url, nsIPrompt *aPRompter, const char * set_cookie_header, char * server_date, nsIIOService* ioService);
|
||||
extern void COOKIE_RegisterPrefCallbacks(void);
|
||||
|
||||
extern void COOKIE_RemoveAll(void);
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsIPref.h"
|
||||
#include "nsTextFormatter.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#define image_behaviorPref "network.image.imageBehavior"
|
||||
#define image_warningPref "network.image.warnAboutImages"
|
||||
|
@ -197,11 +198,17 @@ IMAGE_CheckForPermission
|
|||
}
|
||||
|
||||
PUBLIC nsresult
|
||||
IMAGE_Block(const char* imageURL) {
|
||||
IMAGE_Block(const char* imageURL,
|
||||
nsIIOService* ioService) {
|
||||
if (!imageURL || !(*imageURL)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
char *host = CKutil_ParseURL(imageURL, GET_HOST_PART);
|
||||
nsresult rv = NS_OK;
|
||||
char *host = nsnull;
|
||||
PRUint32 start,end;
|
||||
NS_ASSERTION(ioService, "IOService not available");
|
||||
rv = ioService->ExtractUrlPart(imageURL, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end, &host);
|
||||
Permission_AddHost(host, PR_FALSE, IMAGEPERMISSION, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
extern nsresult IMAGE_CheckForPermission
|
||||
(const char * hostname, const char * firstHostname, PRBool *permission);
|
||||
extern nsresult IMAGE_Block(const char * imageURL);
|
||||
extern nsresult IMAGE_Block(const char * imageURL, nsIIOService *ioService);
|
||||
extern void IMAGE_RegisterPrefCallbacks(void);
|
||||
|
||||
#endif /* IMAGES_H */
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -66,13 +70,15 @@ nsImgManager::~nsImgManager(void)
|
|||
nsresult nsImgManager::Init()
|
||||
{
|
||||
IMAGE_RegisterPrefCallbacks();
|
||||
return NS_OK;
|
||||
nsresult rv;
|
||||
mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImgManager::Block(const char * imageURL)
|
||||
{
|
||||
::IMAGE_Block(imageURL);
|
||||
::IMAGE_Block(imageURL,mIOService);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
|
||||
#include "nsIImgManager.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -57,7 +59,11 @@ public:
|
|||
nsImgManager();
|
||||
virtual ~nsImgManager(void);
|
||||
nsresult Init();
|
||||
|
||||
|
||||
protected:
|
||||
// cached IOService
|
||||
nsCOMPtr<nsIIOService> mIOService;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsImgManager_h__ */
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#include "nsIPrompt.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -126,13 +129,13 @@ nsresult nsPermissionManager::Init()
|
|||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
|
||||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::Add
|
||||
(const char * objectURL, PRBool permission, PRInt32 type) {
|
||||
::PERMISSION_Add(objectURL, permission, type);
|
||||
::PERMISSION_Add(objectURL, permission, type, mIOService);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include "nsIPermissionManager.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -58,6 +60,10 @@ public:
|
|||
nsPermissionManager();
|
||||
virtual ~nsPermissionManager(void);
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
// cached IOService
|
||||
nsCOMPtr<nsIIOService> mIOService;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
#include "xp_core.h"
|
||||
#include "prmem.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
static const char *kCookiesPermFileName = "cookperm.txt";
|
||||
|
||||
|
@ -684,11 +686,17 @@ PERMISSION_DeletePersistentUserData(void)
|
|||
}
|
||||
|
||||
PUBLIC void
|
||||
PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type) {
|
||||
PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type,
|
||||
nsIIOService* ioService) {
|
||||
if (!objectURL) {
|
||||
return;
|
||||
}
|
||||
char *host = CKutil_ParseURL(objectURL, GET_HOST_PART);
|
||||
nsresult rv = NS_OK;
|
||||
char *host = nsnull;
|
||||
PRUint32 start,end;
|
||||
NS_ASSERTION(ioService, "IOService not available");
|
||||
rv = ioService->ExtractUrlPart(objectURL, nsIIOService::url_Host |
|
||||
nsIIOService::url_Port, &start, &end, &host);
|
||||
|
||||
/*
|
||||
* if permission is false, it will be added to the permission list
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#define PERMISSIONS_H
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#define COOKIEPERMISSION 0
|
||||
#define IMAGEPERMISSION 1
|
||||
|
@ -55,7 +56,7 @@ typedef enum {
|
|||
class nsIPrompt;
|
||||
|
||||
extern nsresult PERMISSION_Read();
|
||||
extern void PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type);
|
||||
extern void PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type, nsIIOService* ioService);
|
||||
extern void PERMISSION_RemoveAll();
|
||||
extern void PERMISSION_DeletePersistentUserData(void);
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
#define MAX_HOST_NAME_LEN 64
|
||||
#define BUFSIZE 128
|
||||
#define LOCALIZATION "chrome://communicator/locale/wallet/cookie.properties"
|
||||
|
||||
|
@ -100,184 +99,6 @@ CKutil_GetLine(nsInputFileStream& strm, nsString& aLine) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
PUBLIC char *
|
||||
CKutil_ParseURL (const char *url, int parts_requested) {
|
||||
char *rv=0,*colon, *slash, *ques_mark, *hash_mark;
|
||||
char *atSign, *host, *passwordColon, *gtThan;
|
||||
assert(url);
|
||||
if(!url) {
|
||||
return(CKutil_StrAllocCat(rv, ""));
|
||||
}
|
||||
colon = PL_strchr(url, ':'); /* returns a const char */
|
||||
/* Get the protocol part, not including anything beyond the colon */
|
||||
if (parts_requested & GET_PROTOCOL_PART) {
|
||||
if(colon) {
|
||||
char val = *(colon+1);
|
||||
*(colon+1) = '\0';
|
||||
CKutil_StrAllocCopy(rv, url);
|
||||
*(colon+1) = val;
|
||||
/* If the user wants more url info, tack on extra slashes. */
|
||||
if( (parts_requested & GET_HOST_PART)
|
||||
|| (parts_requested & GET_USERNAME_PART)
|
||||
|| (parts_requested & GET_PASSWORD_PART)) {
|
||||
if( *(colon+1) == '/' && *(colon+2) == '/') {
|
||||
CKutil_StrAllocCat(rv, "//");
|
||||
}
|
||||
/* If there's a third slash consider it file:/// and tack on the last slash. */
|
||||
if( *(colon+3) == '/' ) {
|
||||
CKutil_StrAllocCat(rv, "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the username if one exists */
|
||||
if (parts_requested & GET_USERNAME_PART) {
|
||||
if (colon && (*(colon+1) == '/') && (*(colon+2) == '/') && (*(colon+3) != '\0')) {
|
||||
if ( (slash = PL_strchr(colon+3, '/')) != NULL) {
|
||||
*slash = '\0';
|
||||
}
|
||||
if ( (atSign = PL_strchr(colon+3, '@')) != NULL) {
|
||||
*atSign = '\0';
|
||||
if ( (passwordColon = PL_strchr(colon+3, ':')) != NULL) {
|
||||
*passwordColon = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, colon+3);
|
||||
|
||||
/* Get the password if one exists */
|
||||
if (parts_requested & GET_PASSWORD_PART) {
|
||||
if (passwordColon) {
|
||||
CKutil_StrAllocCat(rv, ":");
|
||||
CKutil_StrAllocCat(rv, passwordColon+1);
|
||||
}
|
||||
}
|
||||
if (parts_requested & GET_HOST_PART) {
|
||||
CKutil_StrAllocCat(rv, "@");
|
||||
}
|
||||
if (passwordColon) {
|
||||
*passwordColon = ':';
|
||||
}
|
||||
*atSign = '@';
|
||||
}
|
||||
if (slash) {
|
||||
*slash = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the host part */
|
||||
if (parts_requested & GET_HOST_PART) {
|
||||
if(colon) {
|
||||
if(*(colon+1) == '/' && *(colon+2) == '/') {
|
||||
slash = PL_strchr(colon+3, '/');
|
||||
if(slash) {
|
||||
*slash = '\0';
|
||||
}
|
||||
if( (atSign = PL_strchr(colon+3, '@')) != NULL) {
|
||||
host = atSign+1;
|
||||
} else {
|
||||
host = colon+3;
|
||||
}
|
||||
ques_mark = PL_strchr(host, '?');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
gtThan = PL_strchr(host, '>');
|
||||
if (gtThan) {
|
||||
*gtThan = '\0';
|
||||
}
|
||||
|
||||
/* limit hostnames to within MAX_HOST_NAME_LEN characters to keep from crashing */
|
||||
if(PL_strlen(host) > MAX_HOST_NAME_LEN) {
|
||||
char * cp;
|
||||
char old_char;
|
||||
cp = host+MAX_HOST_NAME_LEN;
|
||||
old_char = *cp;
|
||||
*cp = '\0';
|
||||
CKutil_StrAllocCat(rv, host);
|
||||
*cp = old_char;
|
||||
} else {
|
||||
CKutil_StrAllocCat(rv, host);
|
||||
}
|
||||
if(slash) {
|
||||
*slash = '/';
|
||||
}
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
if (gtThan) {
|
||||
*gtThan = '>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the path part */
|
||||
if (parts_requested & GET_PATH_PART) {
|
||||
if(colon) {
|
||||
if(*(colon+1) == '/' && *(colon+2) == '/') {
|
||||
/* skip host part */
|
||||
slash = PL_strchr(colon+3, '/');
|
||||
} else {
|
||||
/* path is right after the colon */
|
||||
slash = colon+1;
|
||||
}
|
||||
if(slash) {
|
||||
ques_mark = PL_strchr(slash, '?');
|
||||
hash_mark = PL_strchr(slash, '#');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
if(hash_mark) {
|
||||
*hash_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, slash);
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
if(hash_mark) {
|
||||
*hash_mark = '#';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(parts_requested & GET_HASH_PART) {
|
||||
hash_mark = PL_strchr(url, '#'); /* returns a const char * */
|
||||
if(hash_mark) {
|
||||
ques_mark = PL_strchr(hash_mark, '?');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, hash_mark);
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(parts_requested & GET_SEARCH_PART) {
|
||||
ques_mark = PL_strchr(url, '?'); /* returns a const char * */
|
||||
if(ques_mark) {
|
||||
hash_mark = PL_strchr(ques_mark, '#');
|
||||
if(hash_mark) {
|
||||
*hash_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, ques_mark);
|
||||
if(hash_mark) {
|
||||
*hash_mark = '#';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy in a null string if nothing was copied in */
|
||||
if(!rv) {
|
||||
CKutil_StrAllocCopy(rv, "");
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUnichar *
|
||||
CKutil_Localize(const PRUnichar *genericString) {
|
||||
nsresult ret;
|
||||
|
|
|
@ -42,17 +42,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsFileStream.h"
|
||||
|
||||
//#define GET_ALL_PARTS 127
|
||||
#define GET_PASSWORD_PART 64
|
||||
#define GET_USERNAME_PART 32
|
||||
#define GET_PROTOCOL_PART 16
|
||||
#define GET_HOST_PART 8
|
||||
#define GET_PATH_PART 4
|
||||
#define GET_HASH_PART 2
|
||||
#define GET_SEARCH_PART 1
|
||||
|
||||
extern PRInt32 CKutil_GetLine(nsInputFileStream& strm, nsString& aLine);
|
||||
extern char * CKutil_ParseURL (const char *url, int parts_requested);
|
||||
extern PRUnichar* CKutil_Localize(const PRUnichar *genericString);
|
||||
extern nsresult CKutil_ProfileDirectory(nsFileSpec& dirSpec);
|
||||
extern char * CKutil_StrAllocCopy(char *&destination, const char *source);
|
||||
|
|
|
@ -183,6 +183,7 @@ interface nsIIOService : nsISupports
|
|||
const short url_Query = (1<<8);
|
||||
const short url_Ref = (1<<9);
|
||||
const short url_Path = (1<<10);
|
||||
const short url_Port = (1<<11);
|
||||
|
||||
/**
|
||||
* Get port from string.
|
||||
|
|
|
@ -534,8 +534,9 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
|||
rv = GetParserForScheme(scheme, getter_AddRefs(parser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 port;
|
||||
PRInt32 port = -1;
|
||||
nsXPIDLCString dummyScheme, username, password, host, path;
|
||||
char* portstr = nsnull;
|
||||
|
||||
rv = parser->ParseAtScheme(urlString,
|
||||
getter_Copies(dummyScheme),
|
||||
|
@ -568,6 +569,33 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Port) {
|
||||
if (port != -1) {
|
||||
portstr = PR_smprintf("%d", port);
|
||||
CalculateStartEndPos(urlString, portstr, startPos, endPos);
|
||||
} else {
|
||||
startPos = 0;
|
||||
endPos = 0;
|
||||
}
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(portstr);
|
||||
PR_smprintf_free(portstr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == (url_Host | url_Port)) {
|
||||
nsCAutoString hostport(host);
|
||||
if (port != -1) {
|
||||
portstr = PR_smprintf(":%d", port);
|
||||
hostport += portstr;
|
||||
}
|
||||
if (urlPart)
|
||||
*urlPart = ToNewCString(hostport);
|
||||
CalculateStartEndPos(urlString, *urlPart, startPos, endPos);
|
||||
PR_smprintf_free(portstr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Path) {
|
||||
CalculateStartEndPos(urlString, path, startPos, endPos);
|
||||
if (urlPart)
|
||||
|
@ -575,7 +603,6 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString directory, fileBaseName, fileExtension, param, query, ref;
|
||||
|
||||
rv = parser->ParseAtDirectory(path,
|
||||
|
@ -588,7 +615,6 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
|||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
if (flag == url_Directory) {
|
||||
CalculateStartEndPos(urlString, directory, startPos, endPos);
|
||||
if (urlPart)
|
||||
|
@ -631,7 +657,6 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -846,8 +871,7 @@ nsIOService::AllowPort(PRInt32 inPort, const char *scheme, PRBool *_retval)
|
|||
NS_IMETHODIMP
|
||||
nsIOService::ExtractPort(const char *str, PRInt32 *result)
|
||||
{
|
||||
PRInt32 returnValue = -1;
|
||||
*result = (0 < PR_sscanf(str, "%d", &returnValue)) ? returnValue : -1;
|
||||
*result = ExtractPortFrom(str);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче