diff --git a/mozilla/extensions/pics/src/cslabel.c b/mozilla/extensions/pics/src/cslabel.c index 52af38d574b..6a63703e8f2 100644 --- a/mozilla/extensions/pics/src/cslabel.c +++ b/mozilla/extensions/pics/src/cslabel.c @@ -90,7 +90,7 @@ struct CSLabel_s { ServiceInfo_t * pCurrentServiceInfo; Label_t * pCurrentLabel; - int currentLabelNumber; + PRInt32 currentLabelNumber; HTList * pCurrentLabelTree; SingleLabel_t * pCurrentSingleLabel; LabelRating_t * pCurrentLabelRating; @@ -242,7 +242,7 @@ PRIVATE StateToken_t SingleLabel_stateTokens[] = { {"label extension", SubState_A, Punct_LPAREN, 0, "extension", 0, 0, &Extension_targetObject, SubState_N, Command_NONE, 0}, { "label option", SubState_A, Punct_WHITE, &getOption, 0, 0, 0, &SingleLabel_targetObject, SubState_B, Command_NONE, 0}, { "ratingword", SubState_A, Punct_LPAREN, 0, "r", "ratings", 0, &LabelRating_targetObject, SubState_N, Command_NONE, 0}, - { "option value", SubState_B, Punct_WHITE, &getOptionValue, 0, 0, 0, &SingleLabel_targetObject, SubState_A, Command_CLOSE, 0} + { "option value", SubState_B, Punct_WHITE, &getOptionValue, 0, 0, 0, &SingleLabel_targetObject, SubState_A, Command_CLOSE, 0} }; PRIVATE StateToken_t LabelRating_stateTokens[] = { @@ -346,7 +346,7 @@ PRIVATE StateToken_t ExtensionData_stateTokens[] = { }; -PRIVATE void init_target_obj(TargetObject_t *obj, char *note, Open_t *pOpen, Close_t *pClose, Destroy_t *pDestroy, StateToken_t *stateToken, int stateTokenCount, CSParseTC_t targetChange) +PRIVATE void init_target_obj(TargetObject_t *obj, char *note, Open_t *pOpen, Close_t *pClose, Destroy_t *pDestroy, StateToken_t *stateToken, PRInt32 stateTokenCount, CSParseTC_t targetChange) { obj->note = note; obj->pOpen = pOpen; @@ -359,11 +359,11 @@ PRIVATE void init_target_obj(TargetObject_t *obj, char *note, Open_t *pOpen, Clo PRIVATE void CSinitialize_global_data(void) { - static PRBool first_time=TRUE; + static PRBool first_time=PR_TRUE; if(first_time) { - first_time = FALSE; + first_time = PR_FALSE; init_target_obj(&LabelList_targetObject, "LabelList", &LabelList_open, &LabelList_close, &LabelList_destroy, LabelList_stateTokens, raysize(LabelList_stateTokens), CSLLTC_LIST); init_target_obj(&ServiceInfo_targetObject, "ServiceInfo", ServiceInfo_open, &ServiceInfo_close, &ServiceInfo_destroy, ServiceInfo_stateTokens, raysize(ServiceInfo_stateTokens), CSLLTC_SERVICE); @@ -657,7 +657,7 @@ PUBLIC char * CSLabel_getServiceName(CSLabel_t * pCSLabel) SVal_value(&pCSLabel->pCurrentServiceInfo->rating_service): 0;} PUBLIC Label_t * CSLabel_getLabel(CSLabel_t * pCSLabel) {return pCSLabel->pCurrentLabel;} -PUBLIC int CSLabel_getLabelNumber(CSLabel_t * pCSLabel) +PUBLIC PRInt32 CSLabel_getLabelNumber(CSLabel_t * pCSLabel) {return pCSLabel->currentLabelNumber;} PUBLIC SingleLabel_t * CSLabel_getSingleLabel(CSLabel_t * pCSLabel) {return pCSLabel->pCurrentSingleLabel;} @@ -674,7 +674,7 @@ PUBLIC char * CSLabel_getRatingStr(CSLabel_t * pCSLabel) HTList * ranges; Range_t * curRange; FVal_t fVal; - int count = 0; + PRInt32 count = 0; fVal = CSLabel_getLabelRating(pCSLabel)->value; if (FVal_initialized(&fVal)) return FVal_toStr(&fVal); @@ -746,7 +746,7 @@ PRIVATE StateRet_t parseErrorHandler(CSParse_t * pCSParse, const char * token, c PRIVATE PRBool charSetOK(CSParse_t * pCSParse, char * checkMe, CharSet_t set) { if(!checkMe) - return FALSE; + return PR_FALSE; for (;*checkMe;checkMe++) { if (set & CharSet_ALPHAS && @@ -790,9 +790,9 @@ PRIVATE PRBool charSetOK(CSParse_t * pCSParse, char * checkMe, CharSet_t set) *checkMe == '/' || *checkMe == '-')) continue; pCSParse->pParseContext->pTokenError = checkMe; - return FALSE; + return PR_FALSE; } - return TRUE; + return PR_TRUE; } #endif /* !NO_CHAR_TEST */ @@ -1454,7 +1454,7 @@ PUBLIC CSError_t CSLabel_iterateServices(CSLabel_t * pCSLabel, CSLabel_callback_ { HTList * serviceInfos; CSError_t ret = CSError_OK; - int count = 0; + PRInt32 count = 0; if (!pIteratorCB || !pCSLabel || !pCSLabel->pCSLLData->serviceInfos) @@ -1480,7 +1480,7 @@ PUBLIC CSError_t CSLabel_iterateLabels(CSLabel_t * pCSLabel, CSLabel_callback_t { HTList * labels; CSError_t ret= CSError_OK; - int count = 0; + PRInt32 count = 0; if (!pIteratorCB || !pCSLabel || !pCSLabel->pCurrentServiceInfo || @@ -1501,7 +1501,7 @@ PUBLIC CSError_t CSLabel_iterateLabels(CSLabel_t * pCSLabel, CSLabel_callback_t PUBLIC CSError_t CSLabel_iterateSingleLabels(CSLabel_t * pCSLabel, CSLabel_callback_t * pIteratorCB, State_Parms_t * pParms, const char * identifier, void * pVoid) { CSError_t ret= CSError_OK; - int count = 0; + PRInt32 count = 0; if (!pIteratorCB || !pCSLabel || !pCSLabel->pCurrentServiceInfo || @@ -1532,7 +1532,7 @@ PUBLIC CSError_t CSLabel_iterateLabelRatings(CSLabel_t * pCSLabel, CSLabel_callb { HTList * labelRatings; CSError_t ret = CSError_OK; - int count = 0; + PRInt32 count = 0; if (!pIteratorCB || !pCSLabel || !pCSLabel->pCurrentServiceInfo || @@ -1554,7 +1554,7 @@ PUBLIC CSError_t CSLabel_iterateLabelRatings(CSLabel_t * pCSLabel, CSLabel_callb /* R A N G E T E S T I N G - check that label values fall within acceptable user ranges */ /* CSLabel_ratingsIncludeFVal - find out if current rating in pCSLabel encompases userValue - * return: int stating how far it is from fitting. + * return: PRInt32 stating how far it is from fitting. */ PUBLIC FVal_t CSLabel_ratingsIncludeFVal(CSLabel_t * pCSLabel, FVal_t * userValue) { diff --git a/mozilla/extensions/pics/src/csll.h b/mozilla/extensions/pics/src/csll.h index dd3f566d51c..a44e2db66ba 100644 --- a/mozilla/extensions/pics/src/csll.h +++ b/mozilla/extensions/pics/src/csll.h @@ -122,7 +122,7 @@ extern CSLabel_t * CSLabel_copy(CSLabel_t * old); extern void CSLabel_free(CSLabel_t * me); extern char * CSLabel_getServiceName(CSLabel_t * pCSLabel); -extern int CSLabel_getLabelNumber(CSLabel_t * pCSLabel); +extern PRInt32 CSLabel_getLabelNumber(CSLabel_t * pCSLabel); extern char * CSLabel_getRatingName(CSLabel_t * pCSLabel); extern char * CSLabel_getRatingStr(CSLabel_t * pCSLabel); extern Range_t * CSLabel_getLabelRatingRange(CSLabel_t * pCSLabel); diff --git a/mozilla/extensions/pics/src/csllst.h b/mozilla/extensions/pics/src/csllst.h index a2ee168339c..373bfe2ad36 100644 --- a/mozilla/extensions/pics/src/csllst.h +++ b/mozilla/extensions/pics/src/csllst.h @@ -184,7 +184,7 @@ struct CSLLData_s { /* some usefull flags */ PRBool complete; PRBool hasTree; /* so it can't make a list of labels */ - int mandatoryExtensions; + PRInt32 mandatoryExtensions; }; /* diff --git a/mozilla/extensions/pics/src/cslutils.h b/mozilla/extensions/pics/src/cslutils.h index 9edbe0fa7d0..4ec2bbb2817 100644 --- a/mozilla/extensions/pics/src/cslutils.h +++ b/mozilla/extensions/pics/src/cslutils.h @@ -129,7 +129,7 @@ extern void FVal_clear(FVal_t * pFVal); PRBool isZero - see if value is zero - int isInfinite - -1 or 1 for negative or positive infinity + PRInt32 isInfinite - -1 or 1 for negative or positive infinity PRBool nearerZero - see if check is nearer zero than check @@ -141,7 +141,7 @@ extern void FVal_clear(FVal_t * pFVal); extern void FVal_set(FVal_t * pFVal, float value); extern void FVal_setInfinite(FVal_t * pFVal, PRBool negative); extern PRBool FVal_isZero(const FVal_t * pFVal); -extern int FVal_isInfinite(const FVal_t * pFVal); +extern PRInt32 FVal_isInfinite(const FVal_t * pFVal); extern PRBool FVal_nearerZero(const FVal_t * pRef, const FVal_t * pCheck); extern FVal_t FVal_minus(const FVal_t * pBig, const FVal_t * pSmall); extern char * FVal_toStr(FVal_t * pFVal); @@ -188,13 +188,13 @@ DVAL typedef struct { char * value; /* keep the string around for debugging and output */ PRBool initialized; - int year; - int month; - int day; - int hour; - int minute; - int timeZoneHours; - int timeZoneMinutes; + PRInt32 year; + PRInt32 month; + PRInt32 day; + PRInt32 hour; + PRInt32 minute; + PRInt32 timeZoneHours; + PRInt32 timeZoneMinutes; } DVal_t; extern PRBool DVal_readVal(DVal_t * pDVal, const char * valueStr); @@ -205,10 +205,10 @@ extern void DVal_clear(DVal_t * pDVal); additional methods - int compare - -1 or 1 for a before or after b, 0 for equivilence + PRInt32 compare - -1 or 1 for a before or after b, 0 for equivilence */ -extern int DVal_compare(const DVal_t * a, const DVal_t * b); +extern PRInt32 DVal_compare(const DVal_t * a, const DVal_t * b); /* RANGE @@ -254,7 +254,7 @@ CSPARSE_PARSECHUNK typedef struct CSParse_s CSParse_t; typedef enum {CSDoMore_more, CSDoMore_done, CSDoMore_error} CSDoMore_t; extern CSDoMore_t CSParse_parseChunk (CSParse_t * pCSParse, const char * ptr, - int len, void * pVoid); + PRInt32 len, void * pVoid); /* PARSE CALLBACKS @@ -268,7 +268,7 @@ CSPARSETC object. It is used in the TargetChangeCallback */ -typedef unsigned int CSParseTC_t; +typedef PRUint32 CSParseTC_t; /* diff --git a/mozilla/extensions/pics/src/csparse.c b/mozilla/extensions/pics/src/csparse.c index de295d9a3ca..3f408fb367b 100644 --- a/mozilla/extensions/pics/src/csparse.c +++ b/mozilla/extensions/pics/src/csparse.c @@ -52,7 +52,7 @@ with copyright holders. #include "cslutils.h" #include "csparse.h" -PUBLIC int ParseDebug = 0; /* For use with LablPars and RatPars */ +PUBLIC PRInt32 ParseDebug = 0; /* For use with LablPars and RatPars */ PUBLIC PRBool BVal_readVal(BVal_t * pBVal, const char * valueStr) { @@ -120,14 +120,14 @@ PUBLIC float FVal_value(const FVal_t * pFVal) PRIVATE PRBool FVal_lessThan(const FVal_t * pSmall, const FVal_t * pBig) { if (pBig->stat == FVal_UNINITIALIZED || pSmall->stat == FVal_UNINITIALIZED) - return FALSE; + return PR_FALSE; if (pBig->stat == FVal_POSITIVE_INF || pSmall->stat == FVal_NEGATIVE_INF) { if (pSmall->stat == FVal_POSITIVE_INF) - return FALSE; - return TRUE; + return PR_FALSE; + return PR_TRUE; } if (pBig->stat == FVal_NEGATIVE_INF || pSmall->stat == FVal_POSITIVE_INF) { - return FALSE; + return PR_FALSE; } return pSmall->value < pBig->value; } @@ -188,7 +188,7 @@ PUBLIC void FVal_setInfinite(FVal_t * pFVal, PRBool negative) pFVal->stat = negative ? FVal_NEGATIVE_INF : FVal_POSITIVE_INF; } -PUBLIC int FVal_isInfinite(const FVal_t * pFVal) +PUBLIC PRInt32 FVal_isInfinite(const FVal_t * pFVal) { return (pFVal->stat == FVal_POSITIVE_INF ? 1 : pFVal->stat == FVal_NEGATIVE_INF ? -1 : 0); } @@ -236,13 +236,13 @@ PUBLIC void SVal_clear(SVal_t * pSVal) } #if 0 - int year; - int month; - int day; - int hour; - int minute; - int timeZoneHours; - int timeZoneMinutes; + PRInt32 year; + PRInt32 month; + PRInt32 day; + PRInt32 hour; + PRInt32 minute; + PRInt32 timeZoneHours; + PRInt32 timeZoneMinutes; #endif PUBLIC PRBool DVal_readVal(DVal_t * pDVal, const char * valueStr) { @@ -277,7 +277,7 @@ PUBLIC PRBool DVal_initialized(const DVal_t * pDVal) return (pDVal->initialized != NO); } -PUBLIC int DVal_compare(const DVal_t * a, const DVal_t * b) +PUBLIC PRInt32 DVal_compare(const DVal_t * a, const DVal_t * b) { if (a->year > b->year) return 1; if (a->year < b->year) return -1; @@ -416,9 +416,9 @@ PRIVATE StateRet_t callErrorHandler(CSParse_t * pCSParse, * NowIn_END - expect no more text or parens * NowIn_ERROR - */ -PUBLIC CSDoMore_t CSParse_parseChunk (CSParse_t * pCSParse, const char * ptr, int len, void * pVoid) +PUBLIC CSDoMore_t CSParse_parseChunk (CSParse_t * pCSParse, const char * ptr, PRInt32 len, void * pVoid) { - int i; + PRInt32 i; if (!len || !ptr) return CSDoMore_error; for (i = 0; i < len; i++) { @@ -557,7 +557,7 @@ PRIVATE char * CSParse_subState2str(SubState_t subState) else if (subState == SubState_X) PL_strcpy(space, "X"); else { - int i; + PRInt32 i; SubState_t comp; char ch[] = "A"; for (i = 1, comp = SubState_A; i < (sizeof(SubState_t)*8 - 1); i++, (*ch)++, comp<<=1) @@ -567,7 +567,7 @@ PRIVATE char * CSParse_subState2str(SubState_t subState) return space; } -PRIVATE int ParseTrace(const char * fmt, ...) +PRIVATE PRInt32 ParseTrace(const char * fmt, ...) { va_list pArgs; @@ -585,7 +585,7 @@ PUBLIC NowIn_t CSParse_targetParser(CSParse_t * pCSParse, char demark, void * pV PRBool failedOnPunct = NO; char * token = 0; StateRet_t ret = StateRet_OK; - int i; + PRInt32 i; static NowIn_t lastRet = NowIn_END; /* changed by montulli@netscape.com 11/29/97 @@ -651,7 +651,7 @@ static NowIn_t lastRet = NowIn_END; return NowIn_ERROR; if (pStateToken->command & (Command_OPEN|Command_CLOSE) && pCSParse->pParseContext->pTargetChangeCallback) { - ParseTrace("%3d", pStateToken->command & Command_CLOSE ? -(int)pTargetObject->targetChange : pTargetObject->targetChange); + ParseTrace("%3d", pStateToken->command & Command_CLOSE ? -(PRInt32)pTargetObject->targetChange : pTargetObject->targetChange); if ((*pCSParse->pParseContext->pTargetChangeCallback)(pCSParse, pTargetObject, pTargetObject->targetChange, (PRBool)(pStateToken->command & Command_CLOSE), pVoid) == StateRet_ERROR) return NowIn_ERROR; diff --git a/mozilla/extensions/pics/src/csparse.h b/mozilla/extensions/pics/src/csparse.h index d4b9da0771b..ec1c9c33de2 100644 --- a/mozilla/extensions/pics/src/csparse.h +++ b/mozilla/extensions/pics/src/csparse.h @@ -259,7 +259,7 @@ struct TargetObject_s { Close_t * pClose; /* call this function to close structure */ Destroy_t * pDestroy; StateToken_t * stateTokens; /* array of sub states */ - int stateTokenCount; /* number of sub states */ + PRInt32 stateTokenCount; /* number of sub states */ CSParseTC_t targetChange; /* target change signal for opening this parse state */ }; /* @@ -305,7 +305,7 @@ typedef struct { PRBool observeQuotes; PRBool observedQuotes; char * legalChars; - int legalCharCount; + PRInt32 legalCharCount; } ParseContext_t; /* @@ -319,8 +319,8 @@ struct CSParse_s { NowIn_t nowIn; HTChunk * token; char demark; - int offset; - int depth; + PRInt32 offset; + PRInt32 depth; ParseContext_t * pParseContext; union { /* all the types this parse engine fills */ CSMachRead_t * pCSMachRead; /* defined in CSMacRed.c */ diff --git a/mozilla/extensions/pics/src/htchunk.c b/mozilla/extensions/pics/src/htchunk.c index e1bbd6a9ad0..6404fe82f8a 100644 --- a/mozilla/extensions/pics/src/htchunk.c +++ b/mozilla/extensions/pics/src/htchunk.c @@ -33,7 +33,7 @@ with copyright holders. ** ** (c) COPYRIGHT MIT 1995. ** Please first read the full copyright statement in the file COPYRIGH. -** @(#) $Id: htchunk.c,v 1.1 1999-03-18 22:32:48 neeti%netscape.com Exp $ +** @(#) $Id: htchunk.c,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $ ** ** history: AL, HF 28 Apr 94, Now chunk->data is filled by '\0' so ** that the string is terminated at any time. That makes @@ -52,7 +52,7 @@ with copyright holders. /* Create a chunk with a certain allocation unit ** -------------- */ -PUBLIC HTChunk * HTChunk_new (int grow) +PUBLIC HTChunk * HTChunk_new (PRInt32 grow) { HTChunk * ch; if ((ch = (HTChunk *) HT_CALLOC(1, sizeof(HTChunk))) == NULL) @@ -90,7 +90,7 @@ PUBLIC void HTChunk_delete (HTChunk * ch) /* Create a chunk from an allocated string ** --------------------------------------- */ -PUBLIC HTChunk * HTChunk_fromCString (char * str, int grow) +PUBLIC HTChunk * HTChunk_fromCString (char * str, PRInt32 grow) { HTChunk * ch; ch = HTChunk_new(grow); @@ -140,17 +140,17 @@ PUBLIC void HTChunk_putc (HTChunk * ch, char c) */ PUBLIC void HTChunk_puts (HTChunk * ch, const char * s) { - HTChunk_putb(ch, s, (int) PL_strlen(s)); + HTChunk_putb(ch, s, (PRInt32) PL_strlen(s)); } /* Append a block ** --------------- ** The string is always zero terminated */ -PUBLIC void HTChunk_putb (HTChunk * ch, const char * block, int len) +PUBLIC void HTChunk_putb (HTChunk * ch, const char * block, PRInt32 len) { if (ch && block && len) { - int needed = ch->size+len; + PRInt32 needed = ch->size+len; if (needed >= ch->allocated) { ch->allocated = needed - needed%ch->growby + ch->growby; if (ch->data) { @@ -171,10 +171,10 @@ PUBLIC void HTChunk_putb (HTChunk * ch, const char * block, int len) /* Ensure a certain size ** --------------------- */ -PUBLIC void HTChunk_ensure (HTChunk * ch, int len) +PUBLIC void HTChunk_ensure (HTChunk * ch, PRInt32 len) { if (ch && len) { - int needed = ch->size+len; + PRInt32 needed = ch->size+len; if (needed >= ch->allocated) { ch->allocated = needed - needed%ch->growby + ch->growby; if (ch->data) { diff --git a/mozilla/extensions/pics/src/htchunk.h b/mozilla/extensions/pics/src/htchunk.h index 73b4328fc9a..6c511077180 100644 --- a/mozilla/extensions/pics/src/htchunk.h +++ b/mozilla/extensions/pics/src/htchunk.h @@ -64,9 +64,9 @@ THE CHUNK CLASS */ typedef struct { - int size; /* In bytes */ - int growby; /* Allocation unit in bytes */ - int allocated; /* Current size of *data */ + PRInt32 size; /* In bytes */ + PRInt32 growby; /* Allocation unit in bytes */ + PRInt32 allocated; /* Current size of *data */ char * data; /* Pointer to malloced area or 0 */ } HTChunk; /* @@ -78,7 +78,7 @@ CREATE NEW CHUNK */ #define HTChunkCreate(growby) HTChunk_new(growby) -extern HTChunk * HTChunk_new (int growby); +extern HTChunk * HTChunk_new (PRInt32 growby); /* FREE A CHUNK @@ -107,7 +107,7 @@ ENSURE A CHUNK HAS A CERTAIN AMOUNT OF FREE SPACE */ #define HTChunkEnsure(ch, s) HTChunk_ensure(ch, s) -extern void HTChunk_ensure (HTChunk * ch, int s); +extern void HTChunk_ensure (HTChunk * ch, PRInt32 s); /* APPEND A CHARACTER TO A CHUNK @@ -134,7 +134,7 @@ APPEND A BLOCK TO A CHUNK Add the block and increment the size of the chunk by the len */ -extern void HTChunk_putb (HTChunk * ch, const char *block, int len); +extern void HTChunk_putb (HTChunk * ch, const char *block, PRInt32 len); /* @@ -167,7 +167,7 @@ CSTRING CONVERSIONS Once a string is built, the chunk may be destroyed and the string kept around. */ -extern HTChunk * HTChunk_fromCString (char * str, int grow); +extern HTChunk * HTChunk_fromCString (char * str, PRInt32 grow); extern char * HTChunk_toCString (HTChunk * ch); /* @@ -187,6 +187,6 @@ RETURN CURRENT SIZE ___________________________________ - @(#) $Id: htchunk.h,v 1.1 1999-03-18 22:32:48 neeti%netscape.com Exp $ + @(#) $Id: htchunk.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $ */ diff --git a/mozilla/extensions/pics/src/htlist.c b/mozilla/extensions/pics/src/htlist.c index c372f6fce11..276675af7c8 100644 --- a/mozilla/extensions/pics/src/htlist.c +++ b/mozilla/extensions/pics/src/htlist.c @@ -33,7 +33,7 @@ with copyright holders. ** ** (c) COPYRIGHT MIT 1995. ** Please first read the full copyright statement in the file COPYRIGH. -** @(#) $Id: htlist.c,v 1.1 1999-03-18 22:32:48 neeti%netscape.com Exp $ +** @(#) $Id: htlist.c,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $ ** ** A list is represented as a sequence of linked nodes of type HTList. ** The first node is a header which contains no object. @@ -155,19 +155,19 @@ PUBLIC void * HTList_firstObject (HTList * me) return NULL; } -PUBLIC int HTList_count (HTList * me) +PUBLIC PRInt32 HTList_count (HTList * me) { - int count = 0; + PRInt32 count = 0; if (me) while ((me = me->next) != NULL) count++; return count; } -PUBLIC int HTList_indexOf (HTList * me, void * object) +PUBLIC PRInt32 HTList_indexOf (HTList * me, void * object) { if (me) { - int position = 0; + PRInt32 position = 0; while ((me = me->next) != NULL) { if (me->object == object) return position; @@ -177,7 +177,7 @@ PUBLIC int HTList_indexOf (HTList * me, void * object) return -1; } -PUBLIC void * HTList_objectAt (HTList * me, int position) +PUBLIC void * HTList_objectAt (HTList * me, PRInt32 position) { if (position < 0) return NULL; @@ -191,7 +191,7 @@ PUBLIC void * HTList_objectAt (HTList * me, int position) return NULL; /* Reached the end of the list */ } -PRIVATE void * HTList_removeObjectAt (HTList * me, int position) +PRIVATE void * HTList_removeObjectAt (HTList * me, PRInt32 position) { if (position < 0) return NULL; diff --git a/mozilla/extensions/pics/src/htlist.h b/mozilla/extensions/pics/src/htlist.h index 75a227316a6..43f59298de7 100644 --- a/mozilla/extensions/pics/src/htlist.h +++ b/mozilla/extensions/pics/src/htlist.h @@ -106,7 +106,7 @@ SIZE OF A LIST */ #define HTList_isEmpty(me) (me ? me->next == NULL : YES) -extern int HTList_count (HTList *me); +extern PRInt32 HTList_count (HTList *me); /* REFERENCE LIST ELEMENTS BY INDEX @@ -115,8 +115,8 @@ REFERENCE LIST ELEMENTS BY INDEX This is for example the case if an element can be registered multiple times. */ -extern int HTList_indexOf (HTList *me, void *object); -extern void * HTList_objectAt (HTList *me, int position); +extern PRInt32 HTList_indexOf (HTList *me, void *object); +extern void * HTList_objectAt (HTList *me, PRInt32 position); /* FIND LIST ELEMENTS @@ -158,6 +158,6 @@ PR_END_EXTERN_C ___________________________________ - @(#) $Id: htlist.h,v 1.1 1999-03-18 22:32:49 neeti%netscape.com Exp $ + @(#) $Id: htlist.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $ */ diff --git a/mozilla/extensions/pics/src/htmemory.h b/mozilla/extensions/pics/src/htmemory.h index 49324d5aa7d..6258c93091e 100644 --- a/mozilla/extensions/pics/src/htmemory.h +++ b/mozilla/extensions/pics/src/htmemory.h @@ -61,6 +61,9 @@ with copyright holders. */ #ifndef HTMEMORY_H #define HTMEMORY_H + +PR_BEGIN_EXTERN_C + /* ALLOCATION, REALLOCATION AND DE-ALLOCATION @@ -169,12 +172,15 @@ extern void HTMemory_outofmem(char * name, char * file, unsigned long line); /* */ + +PR_END_EXTERN_C + #endif /* HTMEMORY_H */ /* ___________________________________ - @(#) $Id: htmemory.h,v 1.1 1999-03-18 22:32:49 neeti%netscape.com Exp $ + @(#) $Id: htmemory.h,v 1.2 1999-05-07 05:26:11 neeti%netscape.com Exp $ */ diff --git a/mozilla/extensions/pics/src/htstring.c b/mozilla/extensions/pics/src/htstring.c index 3c0cce6e2f0..786c146895d 100644 --- a/mozilla/extensions/pics/src/htstring.c +++ b/mozilla/extensions/pics/src/htstring.c @@ -33,7 +33,7 @@ with copyright holders. ** ** (c) COPYRIGHT MIT 1995. ** Please first read the full copyright statement in the file COPYRIGH. -** @(#) $Id: htstring.c,v 1.1 1999-03-18 22:32:50 neeti%netscape.com Exp $ +** @(#) $Id: htstring.c,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $ ** ** Original version came with listserv implementation. ** Version TBL Oct 91 replaces one which modified the strings. @@ -55,7 +55,7 @@ PUBLIC FILE *WWWTrace = NULL; #endif #ifndef WWW_WIN_DLL -PUBLIC int WWW_TraceFlag = 0; /* Global trace flag for ALL W3 code */ +PUBLIC PRInt32 WWW_TraceFlag = 0; /* Global trace flag for ALL W3 code */ #endif @@ -80,7 +80,7 @@ PUBLIC char * HTSACat (char ** dest, const char * src) { if (src && *src) { if (*dest) { - int length = PL_strlen (*dest); + PRInt32 length = PL_strlen (*dest); if ((*dest = (char *) HT_REALLOC(*dest, length + PL_strlen(src) + 1)) == NULL) HT_OUTOFMEM("HTSACat"); PL_strcpy (*dest + length, src); @@ -153,7 +153,7 @@ PUBLIC HTTraceCallback * HTTrace_getCallback(void) return PHTTraceCallback; } -PUBLIC int HTTrace(const char * fmt, ...) +PUBLIC PRInt32 HTTrace(const char * fmt, ...) { va_list pArgs; va_start(pArgs, fmt); diff --git a/mozilla/extensions/pics/src/htstring.h b/mozilla/extensions/pics/src/htstring.h index 5e8d156b394..2baaf6eb2a8 100644 --- a/mozilla/extensions/pics/src/htstring.h +++ b/mozilla/extensions/pics/src/htstring.h @@ -76,8 +76,8 @@ CASE-INSENSITIVE STRING COMPARISON The usual routines (comp instead of cmp) had some problem. */ -/* extern int strcasecomp (const char *a, const char *b); */ -/* extern int strncasecomp (const char *a, const char *b, int n); */ +/* extern PRInt32 strcasecomp (const char *a, const char *b); */ +/* extern PRInt32 strncasecomp (const char *a, const char *b, PRInt32 n); */ /* STRING COMPARISON WITH WILD CARD MATCH @@ -126,6 +126,6 @@ PR_END_EXTERN_C ___________________________________ - @(#) $Id: htstring.h,v 1.1 1999-03-18 22:32:50 neeti%netscape.com Exp $ + @(#) $Id: htstring.h,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $ */ diff --git a/mozilla/extensions/pics/src/htutils.h b/mozilla/extensions/pics/src/htutils.h index 438c2ab8b63..987707a9fe8 100644 --- a/mozilla/extensions/pics/src/htutils.h +++ b/mozilla/extensions/pics/src/htutils.h @@ -67,10 +67,10 @@ DEBUG MESSAGE CONTROL */ #ifdef DEBUG #ifdef WWW_WIN_DLL -extern int * WWW_TraceFlag; /* In DLLs, we need the indirection */ +extern PRInt32 * WWW_TraceFlag; /* In DLLs, we need the indirection */ #define WWWTRACE (*WWW_TraceFlag) #else -extern int WWW_TraceFlag; /* Global flag for all W3 trace */ +extern PRInt32 WWW_TraceFlag; /* Global flag for all W3 trace */ #define WWWTRACE (WWW_TraceFlag) #endif /* WWW_WIN_DLL */ #else @@ -132,13 +132,13 @@ typedef enum _HTTraceFlags { MyAppSpecificTrace */ -typedef int (*HTTraceCallback)(); /* jhines--7/9/97 */ -/* typedef int HTTraceCallback(const char * fmt, va_list pArgs); */ +typedef PRInt32 (*HTTraceCallback)(); /* jhines--7/9/97 */ +/* typedef PRInt32 HTTraceCallback(const char * fmt, va_list pArgs); */ extern void HTTrace_setCallback(HTTraceCallback * pCall); extern HTTraceCallback * HTTrace_getCallback(void); -extern int HTTrace(const char * fmt, ...); +extern PRInt32 HTTrace(const char * fmt, ...); /* MACROS FOR FUNCTION DECLARATIONS @@ -210,7 +210,7 @@ UPPER- AND LOWERCASE MACROS /* #ifndef TOLOWER */ /* #define TOLOWER(c) tolower(c) */ /* #define TOUPPER(c) toupper(c) */ -#define TOUPPER(x) ((((unsigned int) (x)) > 0x7f) ? x : toupper(x)) +#define TOUPPER(x) ((((PRUint32) (x)) > 0x7f) ? x : toupper(x)) /* #endif */ /* @@ -260,6 +260,6 @@ LIBRARY DYNAMIC MEMORY MAGEMENT ___________________________________ - @(#) $Id: htutils.h,v 1.1 1999-03-18 22:32:50 neeti%netscape.com Exp $ + @(#) $Id: htutils.h,v 1.2 1999-05-07 05:26:12 neeti%netscape.com Exp $ */ diff --git a/mozilla/extensions/pics/src/lablpars.c b/mozilla/extensions/pics/src/lablpars.c index 830b50a3e4b..46c6aa4d4a5 100644 --- a/mozilla/extensions/pics/src/lablpars.c +++ b/mozilla/extensions/pics/src/lablpars.c @@ -35,11 +35,11 @@ with copyright holders. #include "csll.h" /* to define states in stateChange */ #include "csparse.h" -int Total; +PRInt32 Total; -extern int ParseDebug; +extern PRInt32 ParseDebug; -extern int SEC_ERROR_NO_MEMORY; +extern PRInt32 SEC_ERROR_NO_MEMORY; PRIVATE @@ -52,7 +52,7 @@ CSError_t spit(char* text, CSLabel_t * pCSMR, PRBool closed) LabelTargetCallback_t targetCallback; StateRet_t targetCallback(CSLabel_t * pCSMR, CSParse_t * pCSParse, CSLLTC_t target, PRBool closed, void * pVoid) { - int change = closed ? -target : target; + PRInt32 change = closed ? -target : target; Total += change; if (!ParseDebug) @@ -113,7 +113,7 @@ StateRet_t parseErrorHandler(CSLabel_t * pCSLabel, CSParse_t * pCSParse, /* #if 1 */ #if 0 /* use this main to test input with a series of labels, each on a line. */ -int main(int argc, char** argv) +PRInt32 main(PRInt32 argc, char** argv) { char lineBuf[512]; CSParse_t * pCSParse = 0; @@ -132,7 +132,7 @@ int main(int argc, char** argv) ParseDebug = 1; pCSParse = CSParse_newLabel(&targetCallback, &parseErrorHandler); while (fgets(lineBuf, sizeof(lineBuf), input)){ - int len; + PRInt32 len; char * ptr; for (ptr = lineBuf; *ptr; ptr++) if (*ptr == ';') { @@ -156,7 +156,7 @@ int main(int argc, char** argv) last = CSDoMore_done; } else { printf("%s ", lineBuf); if (ParseDebug) printf("\n"); - switch (last = CSParse_parseChunk(pCSParse, lineBuf, (int) PL_strlen(lineBuf), 0)) { + switch (last = CSParse_parseChunk(pCSParse, lineBuf, (PRInt32) PL_strlen(lineBuf), 0)) { case CSDoMore_done: printf("= %d - parsing end\n", Total); break; @@ -181,7 +181,7 @@ int main(int argc, char** argv) #if 0 /* use this main to test input of a label list spread out over multiple lines*/ -int main(int argc, char** argv) +PRInt32 main(PRInt32 argc, char** argv) { char lineBuf[512]; while (gets(lineBuf)){ @@ -192,7 +192,7 @@ int main(int argc, char** argv) printf("%s", lineBuf); pCSParse = CSParse_newLabel(&targetCallback, &parseErrorHandler); if (CSParse_parseChunk(pCSParse, lineBuf, - (int)PL_strlen(lineBuf), 0) != CSDoMore_done) { + (PRInt32)PL_strlen(lineBuf), 0) != CSDoMore_done) { printf("parsing end error\n"); break; } @@ -204,7 +204,7 @@ int main(int argc, char** argv) #endif #if 0 /* a not-needed but often useful sample implementation of HTTrace */ -int HTTrace(const char * fmt, ...) +PRInt32 HTTrace(const char * fmt, ...) { va_list pArgs; va_start(pArgs, fmt); diff --git a/mozilla/extensions/pics/src/makefile.win b/mozilla/extensions/pics/src/makefile.win index 9c601d2d8ef..86c0ad5c9f5 100644 --- a/mozilla/extensions/pics/src/makefile.win +++ b/mozilla/extensions/pics/src/makefile.win @@ -18,7 +18,7 @@ DEPTH=..\..\.. IGNORE_MANIFEST=1 -DEFINES=-D_IMPL_NS_WEB -DWIN32_LEAN_AND_MEAN +DEFINES=-D_IMPL_NS_PICS -DWIN32_LEAN_AND_MEAN MODULE=pics CSRCS= \ @@ -32,6 +32,7 @@ CSRCS= \ CPPSRCS= \ nsPICS.cpp \ + nsPICSElementObserver.cpp \ $(NULL) C_OBJS= \ @@ -46,6 +47,7 @@ C_OBJS= \ CPP_OBJS= \ .\$(OBJDIR)\nspics.obj \ + .\$(OBJDIR)\nsPICSElementObserver.obj \ $(NULL) LINCS = -I$(PUBLIC)/js \ @@ -75,6 +77,7 @@ LLIBS = \ $(DIST)\lib\xpcom32.lib \ $(DIST)\lib\xppref32.lib \ $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\raptorhtmlpars.lib \ $(HASHLIBS) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/extensions/pics/src/nsPICS.cpp b/mozilla/extensions/pics/src/nsPICS.cpp index edef62b56dc..23e76fe1cd8 100644 --- a/mozilla/extensions/pics/src/nsPICS.cpp +++ b/mozilla/extensions/pics/src/nsPICS.cpp @@ -22,22 +22,52 @@ #include "nsIServiceManager.h" #include "nsRepository.h" #include "nsIPICS.h" +#include "nsIPref.h" +#include "nsIURL.h" +#include "nsIParser.h" +#include "nsParserCIID.h" +#include "nsIHTMLContentSink.h" +#include "nsIObserverService.h" +#include "nsPICSElementObserver.h" +#include "nsFileSpec.h" +#include "nsIDocumentViewer.h" +#include "nsIDocumentLoader.h" +#include "nsIDocumentLoaderObserver.h" +//#include "nsIWebShell.h" +#include "nsIWebShellServices.h" +#include "nsIContentViewerContainer.h" +#include "nsHashtable.h" +#include "nsVoidArray.h" #include "nscore.h" #include "cslutils.h" #include "csll.h" #include "csllst.h" +#include "csparse.h" #include "htstring.h" #include "prprf.h" #include "plstr.h" #include "prmem.h" #include "net.h" +#include "nsString.h" #include -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIPICSIID, NS_IPICS_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIPICSIID, NS_IPICS_IID); -static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); +static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + +static NS_DEFINE_IID(kIObserverServiceIID, NS_IOBSERVERSERVICE_IID); +static NS_DEFINE_IID(kObserverServiceCID, NS_OBSERVERSERVICE_CID); + +static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID); +static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); + +static NS_DEFINE_IID(kIWebShellServicesIID, NS_IWEB_SHELL_SERVICES_IID); +//static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); + +static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); +static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID); @@ -48,33 +78,33 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); #define PICS_REENABLE_FOR_SESSION PICS_DOMAIN"reenable_for_this_session" #define PICS_URL_PREFIX "about:pics" -#define PICS_TO_UPPER(x) ((((unsigned int) (x)) > 0x7f) ? x : toupper(x)) -#define PICS_TO_LOWER(x) ((((unsigned int) (x)) > 0x7f) ? x : tolower(x)) +#define PICS_TO_UPPER(x) ((((PRUint32) (x)) > 0x7f) ? x : toupper(x)) +#define PICS_TO_LOWER(x) ((((PRUint32) (x)) > 0x7f) ? x : tolower(x)) -#define PICS_IS_ALPHA(x) ((((unsigned int) (x)) > 0x7f) ? 0 : isalpha(x)) -#define PICS_IS_DIGIT(x) ((((unsigned int) (x)) > 0x7f) ? 0 : isdigit(x)) -#define PICS_IS_SPACE(x) ((((unsigned int) (x)) > 0x7f) ? 0 : isspace(x)) +#define PICS_IS_ALPHA(x) ((((PRUint32) (x)) > 0x7f) ? 0 : isalpha(x)) +#define PICS_IS_DIGIT(x) ((((PRUint32) (x)) > 0x7f) ? 0 : isdigit(x)) +#define PICS_IS_SPACE(x) ((((PRUint32) (x)) > 0x7f) ? 0 : isspace(x)) #define JAVA_SECURITY_PASSWORD "signed.applets.capabilitiesDB.password" typedef struct { - char *service; - PRBool generic; - char *fur; /* means 'for' */ - HTList *ratings; + char *service; + PRBool generic; + char *fur; /* means 'for' */ + HTList *ratings; } PICS_RatingsStruct; typedef struct { - char *name; - double value; + char *name; + double value; } PICS_RatingValue; typedef enum { - PICS_RATINGS_PASSED, - PICS_RATINGS_FAILED, - PICS_NO_RATINGS + PICS_RATINGS_PASSED, + PICS_RATINGS_FAILED, + PICS_NO_RATINGS } PICS_PassFailReturnVal; typedef struct { @@ -88,104 +118,151 @@ typedef struct { PRBool rs_invalid; } ClosureData; +typedef struct { + nsIURL* url; + PRBool notified; +} PICS_URLData; + //////////////////////////////////////////////////////////////////////////////// -class nsPICS : public nsIPICS { +class nsPICS : public nsIPICS, + public nsIDocumentLoaderObserver { public: - NS_IMETHOD - ProcessPICSLabel(char *label); - NS_IMETHOD Init(); + // nsISupports + NS_DECL_ISUPPORTS - nsPICS(); - ~nsPICS(void); + // nsIPICS + static nsresult GetPICS(nsIPICS** aPICS); + NS_IMETHOD + ProcessPICSLabel(char *label); + + NS_IMETHOD GetWebShell(PRUint32 key, nsIWebShellServices*& aResult); + + NS_IMETHOD SetNotified(nsIWebShellServices* aResult, nsIURL* aURL, PRBool notified); + + nsPICS(); + ~nsPICS(void); + + // nsIDocumentLoaderObserver + NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + const char* aCommand); + NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + PRInt32 aStatus); + NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, const char* aContentType, + nsIContentViewer* aViewer); + NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, PRUint32 aProgress, + PRUint32 aProgressMax); + NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, nsString& aMsg); + NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, PRInt32 aStatus); + NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader, + nsIURL* aURL, + const char *aContentType, + const char *aCommand ); +// NS_IMETHOD OnConnectionsComplete(); - NS_DECL_ISUPPORTS protected: - void GetUserPreferences(); + void GetUserPreferences(); private: - nsIPref* mPrefs; + nsIPref* mPrefs; - PRBool mPICSRatingsEnabled ; - PRBool mPICSPagesMustBeRatedPref; - PRBool mPICSDisabledForThisSession; - PRBool mPICSJavaCapabilitiesEnabled; +// nsPICSElementObserver* mPICSElementObserver; + nsIObserver* mPICSElementObserver; + nsIWebShellServices* mWebShellServices; - HTList* mPICSTreeRatings; + nsIDocumentLoader* mDocLoaderService; +// nsVoidArray* currentURLList; + nsHashtable* mWebShellServicesURLTable; - friend StateRet_t TargetCallback(CSLabel_t *pCSLabel, - CSParse_t * pCSParse, - CSLLTC_t target, PRBool closed, - void * pClosure); + PRBool mPICSRatingsEnabled ; + PRBool mPICSPagesMustBeRatedPref; + PRBool mPICSDisabledForThisSession; + PRBool mPICSJavaCapabilitiesEnabled; - friend StateRet_t ParseErrorHandlerCallback(CSLabel_t * pCSLabel, - CSParse_t * pCSParse, - const char * token, char demark, - StateRet_t errorCode); + HTList* mPICSTreeRatings; - friend int PrefChangedCallback(const char*, void*); + friend StateRet_t TargetCallback(CSLabel_t *pCSLabel, + CSParse_t * pCSParse, + CSLLTC_t target, PRBool closed, + void * pClosure); - void PreferenceChanged(const char* aPrefName); - - PICS_RatingsStruct * ParsePICSLabel(char * label); + friend StateRet_t ParseErrorHandlerCallback(CSLabel_t * pCSLabel, + CSParse_t * pCSParse, + const char * token, char demark, + StateRet_t errorCode); - PRBool IsPICSEnabledByUser(void); + friend PRInt32 PrefChangedCallback(const char*, void*); - PRBool AreRatingsRequired(void); + nsresult Init(); + void PreferenceChanged(const char* aPrefName); - char * GetURLFromRatingsStruct(PICS_RatingsStruct *rs, char *cur_page_url); + PICS_RatingsStruct * ParsePICSLabel(char * label); - void FreeRatingsStruct(PICS_RatingsStruct *rs); + PRBool IsPICSEnabledByUser(void); - PICS_RatingsStruct * CopyRatingsStruct(PICS_RatingsStruct *rs); + PRBool AreRatingsRequired(void); - PRBool CanUserEnableAdditionalJavaCapabilities(void); + char * GetURLFromRatingsStruct(PICS_RatingsStruct *rs, char *cur_page_url); - /* returns TRUE if page should be censored - * FALSE if page is allowed to be shown - */ - PICS_PassFailReturnVal CompareToUserSettings(PICS_RatingsStruct *rs, char *cur_page_url); + void FreeRatingsStruct(PICS_RatingsStruct *rs); - char * IllegalToUnderscore(char *string); + PICS_RatingsStruct * CopyRatingsStruct(PICS_RatingsStruct *rs); - char * LowercaseString(char *string); + PRBool CanUserEnableAdditionalJavaCapabilities(void); - void AddPICSRatingsStructToTreeRatings(PICS_RatingsStruct *rs, PRBool ratings_passed); + /* returns PR_TRUE if page should be censored + * PR_FALSE if page is allowed to be shown + */ + PICS_PassFailReturnVal CompareToUserSettings(PICS_RatingsStruct *rs, char *cur_page_url); - TreeRatingStruct * FindPICSGenericRatings(char *url_address); + char * IllegalToUnderscore(char *string); - void CheckForGenericRatings(char *url_address, PICS_RatingsStruct **rs, - PICS_PassFailReturnVal *status); + char * LowercaseString(char *string); + + void AddPICSRatingsStructToTreeRatings(PICS_RatingsStruct *rs, PRBool ratings_passed); + + TreeRatingStruct * FindPICSGenericRatings(char *url_address); + + void CheckForGenericRatings(char *url_address, PICS_RatingsStruct **rs, + PICS_PassFailReturnVal *status); + + nsresult GetRootURL(nsIURL* aURL); }; +static nsPICS* gPICS = nsnull; // The one-and-only PICSService + //////////////////////////////////////////////////////////////////////////////// class nsPICSFactory : public nsIFactory { public: - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS - // nsIFactory methods: + // nsIFactory methods: - NS_IMETHOD CreateInstance(nsISupports *aOuter, - REFNSIID aIID, - void **aResult); + NS_IMETHOD CreateInstance(nsISupports *aOuter, + REFNSIID aIID, + void **aResult); - NS_IMETHOD LockFactory(PRBool aLock); + NS_IMETHOD LockFactory(PRBool aLock); - // nsPICS methods: + // nsPICS methods: - nsPICSFactory(void); - virtual ~nsPICSFactory(void); + nsPICSFactory(void); + virtual ~nsPICSFactory(void); }; -static PRInt32 g_InstanceCount = 0; -static PRInt32 g_LockCount = 0; StateRet_t TargetCallback(CSLabel_t *pCSLabel, @@ -193,69 +270,69 @@ TargetCallback(CSLabel_t *pCSLabel, CSLLTC_t target, PRBool closed, void * pClosure) { - char * ratingname; - char * ratingstr; - ClosureData *cd = (ClosureData *)pClosure; - - /* closed signifies that the parsing is done for that label */ - if(!cd || !closed) - return StateRet_OK; + char * ratingname; + char * ratingstr; + ClosureData *cd = (ClosureData *)pClosure; - if(target == CSLLTC_SINGLE) - { - LabelOptions_t * lo = CSLabel_getLabelOptions(pCSLabel); + /* closed signifies that the parsing is done for that label */ + if(!cd || !closed) + return StateRet_OK; - if(lo) { - if(BVal_value(&lo->generic)) { - cd->rs->generic = TRUE; - } + if(target == CSLLTC_SINGLE) + { + LabelOptions_t * lo = CSLabel_getLabelOptions(pCSLabel); - if(lo->fur.value && !cd->rs->fur) { - StrAllocCopy(cd->rs->fur, lo->fur.value); - } - } - } else if(target == CSLLTC_RATING) { - PICS_RatingsStruct *rating_struct = cd->rs; - LabelOptions_t * lo = CSLabel_getLabelOptions(pCSLabel); + if(lo) { + if(BVal_value(&lo->generic)) { + cd->rs->generic = PR_TRUE; + } - ratingstr = CSLabel_getRatingStr(pCSLabel); - ratingname = CSLabel_getRatingName(pCSLabel); + if(lo->fur.value && !cd->rs->fur) { + StrAllocCopy(cd->rs->fur, lo->fur.value); + } + } + } else if(target == CSLLTC_RATING) { + PICS_RatingsStruct *rating_struct = cd->rs; + LabelOptions_t * lo = CSLabel_getLabelOptions(pCSLabel); - if(ratingname) { - LabelRating_t * label_rating; - ServiceInfo_t * service_info; + ratingstr = CSLabel_getRatingStr(pCSLabel); + ratingname = CSLabel_getRatingName(pCSLabel); - service_info = CSLabel_getServiceInfo(pCSLabel); + if(ratingname) { + LabelRating_t * label_rating; + ServiceInfo_t * service_info; - if(service_info && !rating_struct->service) { - rating_struct->service = PL_strdup(service_info->rating_service.value); - } + service_info = CSLabel_getServiceInfo(pCSLabel); - label_rating = CSLabel_getLabelRating(pCSLabel); + if(service_info && !rating_struct->service) { + rating_struct->service = PL_strdup(service_info->rating_service.value); + } - if(label_rating) { - double value; - PICS_RatingValue *rating_value = PR_NEWZAP(PICS_RatingValue); + label_rating = CSLabel_getLabelRating(pCSLabel); - value = label_rating->value.value; - - if(rating_value) { - rating_value->value = label_rating->value.value; - rating_value->name = PL_strdup(label_rating->identifier.value); + if(label_rating) { + double value; + PICS_RatingValue *rating_value = PR_NEWZAP(PICS_RatingValue); - if(rating_value->name) { - /* insert it into the list */ - HTList_addObject(rating_struct->ratings, rating_value); + value = label_rating->value.value; + + if(rating_value) { + rating_value->value = label_rating->value.value; + rating_value->name = PL_strdup(label_rating->identifier.value); + + if(rating_value->name) { + /* insert it into the list */ + HTList_addObject(rating_struct->ratings, rating_value); } else { - /* error, cleanup */ - PR_Free(rating_value); - } - } - } - } + /* error, cleanup */ + PR_Free(rating_value); + } + } + } + } - } - return StateRet_OK; + } + return StateRet_OK; } StateRet_t @@ -266,55 +343,131 @@ ParseErrorHandlerCallback(CSLabel_t * pCSLabel, CSParse_t * pCSParse, return errorCode; } -int +PRInt32 PrefChangedCallback(const char* aPrefName, void* instance_data) { - nsPICS* pics = (nsPICS*)instance_data; + nsPICS* pics = (nsPICS*)instance_data; - NS_ASSERTION(nsnull != pics, "bad instance data"); - if (nsnull != pics) { - pics->PreferenceChanged(aPrefName); - } - return 0; // PREF_OK + NS_ASSERTION(nsnull != pics, "bad instance data"); + if (nsnull != pics) { + pics->PreferenceChanged(aPrefName); + } + return 0; // PREF_OK } //////////////////////////////////////////////////////////////////////////////// // nsPICS Implementation -NS_IMPL_ISUPPORTS(nsPICS, kIPICSIID); +//NS_IMPL_ISUPPORTS(nsPICS, kIPICSIID); +NS_IMPL_ADDREF(nsPICS) \ +NS_IMPL_RELEASE(nsPICS) + +NS_EXPORT nsresult NS_NewPICS(nsIPICS** aPICS) +{ + return nsPICS::GetPICS(aPICS); +} nsPICS::nsPICS() { - PR_AtomicIncrement(&g_InstanceCount); - NS_INIT_REFCNT(); - - printf(" creating my service\n"); - mPICSRatingsEnabled = FALSE; - mPICSPagesMustBeRatedPref = FALSE; - mPICSDisabledForThisSession = FALSE; - mPICSJavaCapabilitiesEnabled = TRUE; + NS_INIT_REFCNT(); - mPICSTreeRatings = nsnull; + mPrefs = nsnull; + mPICSElementObserver = nsnull; + mWebShellServices = nsnull; + mWebShellServicesURLTable = nsnull; +// currentURLList = nsnull; + mDocLoaderService = nsnull; + + mPICSRatingsEnabled = PR_FALSE; + mPICSPagesMustBeRatedPref = PR_FALSE; + mPICSDisabledForThisSession = PR_FALSE; + mPICSJavaCapabilitiesEnabled = PR_TRUE; + + mPICSTreeRatings = nsnull; + + Init(); } nsPICS::~nsPICS(void) { - PR_AtomicDecrement(&g_InstanceCount); - printf(" destroying my service\n"); + if(mPICSTreeRatings) + HTList_free(mPICSTreeRatings); + if(mWebShellServicesURLTable) + delete mWebShellServicesURLTable; + gPICS = nsnull; } +NS_IMETHODIMP nsPICS::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + + if( NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + *aInstancePtr = NULL; + + if( aIID.Equals ( kIPICSIID )) { + *aInstancePtr = (void*) ((nsIPICS*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIDocumentLoaderObserverIID)) { + *aInstancePtr = (void*)(nsIDocumentLoaderObserver*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if( aIID.Equals ( kISupportsIID )) { + *aInstancePtr = (void*) (this); + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +nsresult nsPICS::GetPICS(nsIPICS** aPICS) +{ + if (! gPICS) { + nsPICS* it = new nsPICS(); + if (! it) + return NS_ERROR_OUT_OF_MEMORY; + gPICS = it; + } + + NS_ADDREF(gPICS); + *aPICS = gPICS; + return NS_OK; +} nsresult nsPICS::ProcessPICSLabel(char *label) { - PICS_PassFailReturnVal status = PICS_NO_RATINGS; - printf(" invoking my service\n"); - PICS_RatingsStruct *rs; -/* PICS_Init(); */ - rs = ParsePICSLabel(label); + PICS_PassFailReturnVal status = PICS_RATINGS_PASSED; + PICS_RatingsStruct *rs = nsnull; + if (mPICSRatingsEnabled) { + if (!label) { + status = PICS_NO_RATINGS; + return status; + } + while(label[0] == SQUOTE || label[0] == DQUOTE) { + nsString theLabel(label); + char* quoteValue = PL_strndup(label, 1); + // nsString value2(theValue2); + theLabel.Trim(quoteValue); + char *lab = theLabel.ToNewCString(); + PL_strcpy(label, lab); + } + // rv = GetRootURL(); + rs = ParsePICSLabel(label); status = CompareToUserSettings(rs, "http://www.w3.org/"); - printf("PICS_PassFailReturnVal %d", status); + if(status == PICS_NO_RATINGS) { + printf("PICS_PassFailReturnVal %d", status); + if(mPICSPagesMustBeRatedPref) + status = PICS_RATINGS_FAILED; + else + status = PICS_RATINGS_PASSED; + } + } + printf("\nPICS_PassFailReturnVal %d\n", status); FreeRatingsStruct(rs); return status; } @@ -322,35 +475,72 @@ nsPICS::ProcessPICSLabel(char *label) nsresult nsPICS::Init() { - nsresult rv = NS_OK; + nsresult rv; nsresult res; nsIPref* aPrefs; - - static PRBool first_time=TRUE; + nsString aTopic("htmlparser"); + nsIObserverService *anObserverService = nsnull; + // nsFileSpec mySpec("C:\\Program Files\\Netscape\\Users\\neeti\\prefs.js"); + + + static PRBool first_time=PR_TRUE; res = nsServiceManager::GetService(kPrefCID, nsIPref::GetIID(), (nsISupports **)&aPrefs); if (NS_OK != res) { - return res; + return res; } mPrefs = aPrefs; + if(!mPrefs) + return NS_ERROR_NULL_POINTER; + if(!first_time) { - return rv; + return NS_OK; } else { /* char *password=NULL; */ - first_time = FALSE; - + first_time = PR_FALSE; - mPrefs->Startup("C:\\Program Files\\Netscape\\Users\\neeti\\prefs.js"); + // mPrefs->StartUpWith(mySpec); + /* get the prefs */ PrefChangedCallback(PICS_DOMAIN, (void*)this); - mPrefs->RegisterCallback(PICS_DOMAIN, PrefChangedCallback, (void*)this); + mPrefs->RegisterCallback(PICS_DOMAIN, PrefChangedCallback, (void*)this); + + + + // Get the global document loader service... + rv = nsServiceManager::GetService(kDocLoaderServiceCID, + kIDocumentLoaderIID, + (nsISupports **)&mDocLoaderService); + if (NS_SUCCEEDED(rv)) { + //Register ourselves as an observer for the new doc loader + mDocLoaderService->AddObserver((nsIDocumentLoaderObserver*)this); + } + + if(mPICSRatingsEnabled) { + if (NS_FAILED(rv = NS_NewPICSElementObserver(&mPICSElementObserver))) + return rv; + + rv = nsServiceManager::GetService(kObserverServiceCID, + nsIObserverService::GetIID(), + (nsISupports **)&anObserverService); + + if(rv == NS_OK) { + rv = anObserverService->AddObserver(&mPICSElementObserver, &aTopic); + if (NS_FAILED(rv)) + return rv; + + } + + } + + /* check for security pref that password disables the enableing of java permissions */ @@ -384,11 +574,11 @@ prompt_again: if(!hashed_password) { - mPICSJavaCapabilitiesEnabled = FALSE; + mPICSJavaCapabilitiesEnabled = PR_FALSE; } else if(!PL_strcmp(hashed_password, password)) { - mPICSJavaCapabilitiesEnabled = TRUE; + mPICSJavaCapabilitiesEnabled = PR_TRUE; } else { @@ -413,39 +603,81 @@ prompt_again: void nsPICS::GetUserPreferences() { - PRBool bool_rv; + PRBool bool_rv; - if(!this->mPrefs->GetBoolPref(PICS_ENABLED_PREF, &bool_rv)) - mPICSRatingsEnabled = bool_rv; + if(mPrefs) { + if(!this->mPrefs->GetBoolPref(PICS_ENABLED_PREF, &bool_rv)) + mPICSRatingsEnabled = bool_rv; if(!mPrefs->GetBoolPref(PICS_MUST_BE_RATED_PREF, &bool_rv)) - mPICSPagesMustBeRatedPref = bool_rv; + mPICSPagesMustBeRatedPref = bool_rv; if(!mPrefs->GetBoolPref(PICS_DISABLED_FOR_SESSION, &bool_rv)) { - if(bool_rv) { - mPICSDisabledForThisSession = TRUE; - mPrefs->SetBoolPref(PICS_DISABLED_FOR_SESSION, FALSE); - } - } + if(bool_rv) { + mPICSDisabledForThisSession = PR_TRUE; + mPrefs->SetBoolPref(PICS_DISABLED_FOR_SESSION, PR_FALSE); + } + } if(!mPrefs->GetBoolPref(PICS_REENABLE_FOR_SESSION, &bool_rv)) { - if(bool_rv) { - mPICSDisabledForThisSession = FALSE; - mPrefs->SetBoolPref(PICS_REENABLE_FOR_SESSION, FALSE); - } - } + if(bool_rv) { + mPICSDisabledForThisSession = PR_FALSE; + mPrefs->SetBoolPref(PICS_REENABLE_FOR_SESSION, PR_FALSE); + } + } + } } +NS_IMETHODIMP +nsPICS::GetWebShell(PRUint32 key, nsIWebShellServices*& aResult) +{ + nsresult rv; + nsIContentViewerContainer* cont = nsnull; + rv = mDocLoaderService->GetContentViewerContainer(key, &cont); + if (NS_SUCCEEDED(rv) && nsnull != cont) { + rv = cont->QueryInterface(kIWebShellServicesIID, (void **)&aResult); + NS_RELEASE(cont); + } + return rv; +} + +NS_IMETHODIMP +nsPICS::SetNotified(nsIWebShellServices* ws, nsIURL* aURL, PRBool notified) +{ + nsVoidArray* currentURLList; + if(ws == nsnull) + return NS_ERROR_NULL_POINTER; + nsVoidKey key((void*)ws); + + if(mWebShellServicesURLTable == nsnull) { + return NS_ERROR_NULL_POINTER; + } + + if(mWebShellServicesURLTable->Exists(&key)) { + currentURLList = (nsVoidArray *) mWebShellServicesURLTable->Get(&key); + if (currentURLList != NULL) { + PRInt32 count = currentURLList->Count(); + for (PRInt32 i = 0; i < count; i++) { + PICS_URLData* urlData = (PICS_URLData*)currentURLList->ElementAt(i); + if(aURL == urlData->url) { + urlData->notified = notified; + } + } + } + } + return NS_OK; +} + /* return NULL or ratings struct */ PICS_RatingsStruct * nsPICS::ParsePICSLabel(char * label) { CSParse_t *CSParse_handle; - ClosureData *cd; + ClosureData *cd; PICS_RatingsStruct *rs; PICS_RatingsStruct *new_rs; - CSDoMore_t status; + CSDoMore_t status; HTList *list_ptr; - PICS_RatingValue *rating_value; + PICS_RatingValue *rating_value; if(!label) return NULL; @@ -462,7 +694,7 @@ nsPICS::ParsePICSLabel(char * label) return NULL; } - rs->ratings = HTList_new(); + rs->ratings = HTList_new(); cd->rs = rs; @@ -482,7 +714,7 @@ nsPICS::ParsePICSLabel(char * label) if(cd->rs_invalid) { FreeRatingsStruct(rs); rs = NULL; - } else { + } else { new_rs = CopyRatingsStruct(rs); FreeRatingsStruct(rs); rs = NULL; @@ -502,21 +734,214 @@ nsPICS::ParsePICSLabel(char * label) PR_Free(cd); - CSParse_deleteLabel(CSParse_handle); + CSParse_deleteLabel(CSParse_handle); return(new_rs); } +NS_IMETHODIMP +nsPICS::OnStartDocumentLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + const char* aCommand) +{ + nsresult rv = NS_ERROR_FAILURE; + mWebShellServices = nsnull; + + return rv; +} + + + +NS_IMETHODIMP +nsPICS::OnEndDocumentLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + PRInt32 aStatus) +{ + nsresult rv = NS_OK; + + return rv; + +} + +NS_IMETHODIMP +nsPICS::OnStartURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + const char* aContentType, + nsIContentViewer* aViewer) +{ + nsresult rv; + + nsIContentViewerContainer *cont; + + PICS_URLData* urlData; + nsVoidArray* currentURLList; + + if(0 == PL_strcmp("text/html", aContentType)) { + mWebShellServices = nsnull; + + rv = loader->GetContainer(&cont); + if (NS_OK == rv) { + nsIWebShellServices *ws; + + rv = cont->QueryInterface(kIWebShellServicesIID, (void **)&ws); + if (NS_OK == rv) { + mWebShellServices = ws; + } + } + + if (nsnull != aURL) { + urlData = PR_NEWZAP(PICS_URLData); + urlData->url = (nsIURL*)PR_Malloc(sizeof(aURL)); + // urlData->url = new nsIURL; + urlData->notified = PR_FALSE; + + } + + nsVoidKey key((void*)ws); + + if(mWebShellServicesURLTable == nsnull) { + mWebShellServicesURLTable = new nsHashtable(256, PR_TRUE); + if (mWebShellServicesURLTable == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + } + + if(mWebShellServicesURLTable->Exists(&key)) { + currentURLList = (nsVoidArray *) mWebShellServicesURLTable->Get(&key); + if (currentURLList != NULL) { + currentURLList->AppendElement(urlData); + mWebShellServicesURLTable->Put(&key, currentURLList); + } else { + currentURLList = new nsVoidArray(); + if(!currentURLList) + return NS_ERROR_OUT_OF_MEMORY; + mWebShellServicesURLTable->Put(&key, currentURLList); + } + } else { + currentURLList = new nsVoidArray(); + if(!currentURLList) + return NS_ERROR_OUT_OF_MEMORY; + mWebShellServicesURLTable->Put(&key, currentURLList); + } + + } + return NS_OK; +} + +NS_IMETHODIMP +nsPICS::OnProgressURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + PRUint32 aProgress, + PRUint32 aProgressMax) +{ + + return NS_OK; +} + +NS_IMETHODIMP +nsPICS::OnStatusURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + nsString& aMsg) +{ + + return NS_OK; +} + +NS_IMETHODIMP +nsPICS::OnEndURLLoad(nsIDocumentLoader* loader, + nsIURL* aURL, + PRInt32 aStatus) +{ + nsIContentViewerContainer *cont; + nsresult rv; + const char* uProtocol; + const char* uHost; + const char* uFile; + nsIURL* rootURL; + + nsVoidArray* currentURLList; + + + rv = loader->GetContainer(&cont); + if (NS_OK == rv) { + nsIWebShellServices *ws; + if(cont) { + rv = cont->QueryInterface(kIWebShellServicesIID, (void **)&ws); + if (NS_OK == rv) { + mWebShellServices = ws; + } + } + } + + if(ws == nsnull) + return NS_ERROR_NULL_POINTER; + nsVoidKey key((void*)ws); + + if(mWebShellServicesURLTable == nsnull) { + return NS_ERROR_NULL_POINTER; + } + + if(mWebShellServicesURLTable->Exists(&key)) { + currentURLList = (nsVoidArray *) mWebShellServicesURLTable->Get(&key); + if (currentURLList != NULL) { + PRInt32 count = currentURLList->Count(); + for (PRInt32 i = 0; i < count; i++) { + PICS_URLData* urlData = (PICS_URLData*)currentURLList->ElementAt(i); + const char* spec1; + const char* spec2; + aURL->GetSpec(&spec1); + aURL->GetSpec(&spec2); + + if(0 == PL_strcmp(spec1, spec2)) { + if(!urlData->notified) { + currentURLList->RemoveElementAt(i); + if (nsnull != aURL) { + aURL->GetProtocol(&uProtocol); + aURL->GetHost(&uHost); + aURL->GetFile(&uFile); + if ((0 != PL_strcmp("/", uFile)) && (0 != PL_strcmp("/index.html", uFile))) { + if (0 != PL_strcmp("file", uProtocol)) { + nsAutoString protocolStr(uProtocol); + nsAutoString hostStr(uHost); + + // Construct a chrome URL and use it to look up a resource. + nsAutoString rootStr = protocolStr + "://" + hostStr + "/"; + + rv = NS_NewURL(&rootURL, rootStr); + // rv = GetRootURL(rootURL); + } + } + } + } + } + } + } + } + + + return NS_OK; +} + +NS_IMETHODIMP +nsPICS::HandleUnknownContentType(nsIDocumentLoader* loader, + nsIURL* aURL, + const char *aContentType, + const char *aCommand ) { + // If we have a doc loader observer, let it respond to this. +// return mDocLoaderObserver ? mDocLoaderObserver->HandleUnknownContentType( mDocLoader, aURL, aContentType, aCommand ) + //: NS_ERROR_FAILURE; + return NS_OK; +} + void nsPICS::FreeRatingsStruct(PICS_RatingsStruct *rs) { if(rs) { - PICS_RatingValue *rv; - - while((rv = (PICS_RatingValue *)HTList_removeFirstObject(rs->ratings)) != NULL) { - PR_Free(rv->name); - PR_Free(rv); - } + PICS_RatingValue *rv; + + while((rv = (PICS_RatingValue *)HTList_removeFirstObject(rs->ratings)) != NULL) { + PR_Free(rv->name); + PR_Free(rv); + } PR_FREEIF(rs->fur); PR_FREEIF(rs->service); @@ -530,32 +955,32 @@ nsPICS::CopyRatingsStruct(PICS_RatingsStruct *rs) PICS_RatingsStruct *new_rs = NULL; if(rs) { - PICS_RatingValue *rv; - PICS_RatingValue *new_rv; - HTList *list_ptr; + PICS_RatingValue *rv; + PICS_RatingValue *new_rv; + HTList *list_ptr; new_rs = PR_NEWZAP(PICS_RatingsStruct); if(!new_rs) return NULL; - new_rs->ratings = HTList_new(); - - list_ptr = rs->ratings; - while((rv = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { - new_rv = (PICS_RatingValue*)PR_Malloc(sizeof(PICS_RatingValue)); - - if(new_rv) { - new_rv->name = PL_strdup(rv->name); - new_rv->value = rv->value; + new_rs->ratings = HTList_new(); + + list_ptr = rs->ratings; + while((rv = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { + new_rv = (PICS_RatingValue*)PR_Malloc(sizeof(PICS_RatingValue)); + + if(new_rv) { + new_rv->name = PL_strdup(rv->name); + new_rv->value = rv->value; - if(new_rv->name) { - HTList_addObject(new_rs->ratings, new_rv); - } else { - PR_Free(new_rv); - } - } - } + if(new_rv->name) { + HTList_addObject(new_rs->ratings, new_rv); + } else { + PR_Free(new_rv); + } + } + } new_rs->generic= rs->generic; new_rs->fur = PL_strdup(rs->fur); @@ -576,10 +1001,10 @@ PRBool nsPICS::IsPICSEnabledByUser(void) { - if(mPICSDisabledForThisSession) - return FALSE; + if(mPICSDisabledForThisSession) + return PR_FALSE; - return(mPICSRatingsEnabled); + return(mPICSRatingsEnabled); } PRBool @@ -594,233 +1019,240 @@ nsPICS::AreRatingsRequired(void) char * nsPICS::GetURLFromRatingsStruct(PICS_RatingsStruct *rs, char *cur_page_url) { - char *rv; - char *escaped_cur_page=NULL; + char *rv; + char *escaped_cur_page=NULL; - if(cur_page_url) { - /* HACK --Neeti fix this - escaped_cur_page = NET_Escape(cur_page_url, URL_PATH); */ - if(!escaped_cur_page) - return NULL; - } + if(cur_page_url) { + /* HACK --Neeti fix this + escaped_cur_page = NET_Escape(cur_page_url, URL_PATH); */ + if(!escaped_cur_page) + return NULL; + } - rv = PR_smprintf("%s?Destination=%s", - PICS_URL_PREFIX, - escaped_cur_page ? escaped_cur_page : "none"); + rv = PR_smprintf("%s?Destination=%s", + PICS_URL_PREFIX, + escaped_cur_page ? escaped_cur_page : "none"); - PR_Free(escaped_cur_page); + PR_Free(escaped_cur_page); - if(!rs || !rs->service) { - StrAllocCat(rv, "&NO_RATING"); - return(rv); - } else { + if(!rs || !rs->service) { + StrAllocCat(rv, "&NO_RATING"); + return(rv); + } else { HTList *list_ptr = rs->ratings; PICS_RatingValue *rating_value; - char *escaped_service = NULL; - /* HACK --Neeti fix this - escaped_service = NET_Escape(rs->service, URL_PATH); */ + char *escaped_service = NULL; + /* HACK --Neeti fix this + escaped_service = NET_Escape(rs->service, URL_PATH); */ - if(!escaped_service) - return NULL; + if(!escaped_service) + return NULL; - StrAllocCat(rv, "&Service="); - StrAllocCat(rv, escaped_service); + StrAllocCat(rv, "&Service="); + StrAllocCat(rv, escaped_service); - PR_Free(escaped_service); + PR_Free(escaped_service); - while((rating_value = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { + while((rating_value = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { - char *add; - char *escaped_name = NULL; - - /* HACK --Neeti fix this - escaped_name = NET_Escape( - IllegalToUnderscore(rating_value->name), - URL_PATH); */ - if(!escaped_name) { - PR_Free(rv); - return NULL; - } - - add = PR_smprintf("&%s=%f", escaped_name, rating_value->value); + char *add; + char *escaped_name = NULL; + + /* HACK --Neeti fix this + escaped_name = NET_Escape( + IllegalToUnderscore(rating_value->name), + URL_PATH); */ + if(!escaped_name) { + PR_Free(rv); + return NULL; + } + + add = PR_smprintf("&%s=%f", escaped_name, rating_value->value); - PR_Free(escaped_name); + PR_Free(escaped_name); - StrAllocCat(rv, add); + StrAllocCat(rv, add); - PR_Free(add); - } + PR_Free(add); + } - return rv; + return rv; } PR_ASSERT(0);// should never get here return NULL; } -/* returns TRUE if page should be censored - * FALSE if page is allowed to be shown +/* returns PR_TRUE if page should be censored + * PR_FALSE if page is allowed to be shown */ PICS_PassFailReturnVal nsPICS::CompareToUserSettings(PICS_RatingsStruct *rs, char *cur_page_url) { - int32 int_pref; - PRBool bool_pref; - char * pref_prefix; - char * pref_string=NULL; - char * escaped_service; - PICS_PassFailReturnVal rv = PICS_RATINGS_PASSED; - HTList *list_ptr; - PICS_RatingValue *rating_value; + PRInt32 int_pref; + PRBool bool_pref; + char * pref_prefix = NULL; + char * pref_string=NULL; + char * escaped_service = NULL; + PICS_PassFailReturnVal rv = PICS_RATINGS_PASSED; + HTList *list_ptr; + PICS_RatingValue *rating_value; - if(!rs || !rs->service) { - return PICS_NO_RATINGS; - } + if(!rs){ + return PICS_NO_RATINGS; + } -#define PICS_SERVICE_DOMAIN PICS_DOMAIN"service." -#define PICS_SERVICE_ENABLED "service_enabled" + if(!*rs->service) { + return PICS_NO_RATINGS; + } - /* cycle through list of ratings and compare to the users prefs */ - list_ptr = rs->ratings; - pref_prefix = PL_strdup(PICS_SERVICE_DOMAIN); + #define PICS_SERVICE_DOMAIN PICS_DOMAIN"service." + #define PICS_SERVICE_ENABLED "service_enabled" - /* need to deal with bad characters */ - escaped_service = PL_strdup(rs->service); - escaped_service = IllegalToUnderscore(escaped_service); - escaped_service = LowercaseString(escaped_service); + /* cycle through list of ratings and compare to the users prefs */ + list_ptr = rs->ratings; + pref_prefix = PL_strdup(PICS_SERVICE_DOMAIN); - if(!escaped_service) - return PICS_RATINGS_FAILED; + /* need to deal with bad characters */ + escaped_service = PL_strdup(rs->service); + escaped_service = IllegalToUnderscore(escaped_service); + escaped_service = LowercaseString(escaped_service); - StrAllocCat(pref_prefix, escaped_service); + if(!escaped_service) + return PICS_RATINGS_FAILED; - PR_Free(escaped_service); + StrAllocCat(pref_prefix, escaped_service); - if(!pref_prefix) - return PICS_RATINGS_FAILED; + PR_FREEIF(escaped_service); - /* verify that this type of rating system is enabled */ - pref_string = PR_smprintf("%s.%s", pref_prefix, PICS_SERVICE_ENABLED); - - if(!pref_string) - goto cleanup; + if(!pref_prefix) + return PICS_RATINGS_FAILED; - if(!mPrefs->GetBoolPref(pref_string, &bool_pref)) { - if(!bool_pref) { - /* this is an unenabled ratings service */ - rv = PICS_NO_RATINGS; - PR_Free(pref_string); - goto cleanup; - } - } else { - /* this is an unsupported ratings service */ - rv = PICS_NO_RATINGS; + /* verify that this type of rating system is enabled */ + pref_string = PR_smprintf("%s.%s", pref_prefix, PICS_SERVICE_ENABLED); + + if(!pref_string) + goto cleanup; + + if(mPrefs) { + if(!mPrefs->GetBoolPref(pref_string, &bool_pref)) { + if(!bool_pref) { + /* this is an unenabled ratings service */ + rv = PICS_NO_RATINGS; PR_Free(pref_string); - goto cleanup; - } + goto cleanup; + } + } else { + /* this is an unsupported ratings service */ + rv = PICS_NO_RATINGS; + PR_Free(pref_string); + goto cleanup; + } + } + PR_Free(pref_string); - PR_Free(pref_string); + while((rating_value = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { + /* compose pref lookup string */ + pref_string = PR_smprintf("%s.%s", + pref_prefix, + IllegalToUnderscore(rating_value->name)); - while((rating_value = (PICS_RatingValue *)HTList_nextObject(list_ptr)) != NULL) { - /* compose pref lookup string */ - pref_string = PR_smprintf("%s.%s", - pref_prefix, - IllegalToUnderscore(rating_value->name)); + if(!pref_string) + goto cleanup; - if(!pref_string) - goto cleanup; + /* find the value in the prefs if it exists + * if it does compare it to the value given and if + * less than, censer the page. + */ - /* find the value in the prefs if it exists - * if it does compare it to the value given and if - * less than, censer the page. - */ - - if(!mPrefs->GetIntPref(pref_string, &int_pref)) { - if(rating_value->value > int_pref) { - rv = PICS_RATINGS_FAILED; - PR_Free(pref_string); - goto cleanup; - } - } + if(mPrefs) { + if(!mPrefs->GetIntPref(pref_string, &int_pref)) { + if(rating_value->value > int_pref) { + rv = PICS_RATINGS_FAILED; + PR_Free(pref_string); + goto cleanup; + } + } + } - PR_Free(pref_string); - } + PR_Free(pref_string); +} cleanup: - PR_Free(pref_prefix); + PR_Free(pref_prefix); - /* make sure this rating applies to this page */ - if(rs->fur) { - char *new_url; - PL_strcpy(cur_page_url, rs->fur); /** HACK - remove this Neeti - new_url = NET_MakeAbsoluteURL(cur_page_url, rs->fur); - if(new_url) - { - PR_Free(rs->fur); - rs->fur = new_url; - } - **/ - - if(PL_strncasecmp(cur_page_url, rs->fur, PL_strlen(rs->fur))) { - /* HACK -Neeti fix this - if(MAILBOX_TYPE_URL == NET_URL_Type(cur_page_url)) - { - // if it's a mailbox URL ignore the "for" directive, - // and don't store the url in the tree rating - // - return rv; - } - */ - - rv = PICS_NO_RATINGS; - } - } + /* make sure this rating applies to this page */ + if(rs->fur) { + // char *new_url; + PL_strcpy(cur_page_url, rs->fur); /** HACK - remove this Neeti + new_url = NET_MakeAbsoluteURL(cur_page_url, rs->fur); + if(new_url) + { + PR_Free(rs->fur); + rs->fur = new_url; + } + **/ - if(rv != PICS_NO_RATINGS) { - PR_ASSERT(rv == PICS_RATINGS_PASSED || rv == PICS_RATINGS_FAILED); - /* if there is no URL make it the current one */ - if(!rs->fur) - rs->fur = PL_strdup(cur_page_url); + if(PL_strncasecmp(cur_page_url, rs->fur, PL_strlen(rs->fur))) { + /* HACK -Neeti fix this + if(MAILBOX_TYPE_URL == NET_URL_Type(cur_page_url)) + { + // if it's a mailbox URL ignore the "for" directive, + // and don't store the url in the tree rating + // + return rv; + } + */ - /* rating should apply to a whole tree, add to list */ - AddPICSRatingsStructToTreeRatings(rs, rv == PICS_RATINGS_PASSED); - } + rv = PICS_NO_RATINGS; + } +} - return rv; + if(rv != PICS_NO_RATINGS) { + PR_ASSERT(rv == PICS_RATINGS_PASSED || rv == PICS_RATINGS_FAILED); + /* if there is no URL make it the current one */ + if(!rs->fur) + rs->fur = PL_strdup(cur_page_url); + + /* rating should apply to a whole tree, add to list */ + AddPICSRatingsStructToTreeRatings(rs, rv == PICS_RATINGS_PASSED); + } + + return rv; } char * nsPICS::IllegalToUnderscore(char *string) { - char* ptr = string; + char* ptr = string; - if(!string) - return NULL; + if(!string) + return NULL; - if(!PICS_IS_ALPHA(*ptr)) - *ptr = '_'; + if(!PICS_IS_ALPHA(*ptr)) + *ptr = '_'; - for(ptr++; *ptr; ptr++) - if(!PICS_IS_ALPHA(*ptr) && !PICS_IS_DIGIT(*ptr)) - *ptr = '_'; + for(ptr++; *ptr; ptr++) + if(!PICS_IS_ALPHA(*ptr) && !PICS_IS_DIGIT(*ptr)) + *ptr = '_'; - return string; + return string; } char * nsPICS::LowercaseString(char *string) { - char *ptr = string; + char *ptr = string; - if(!string) - return NULL; + if(!string) + return NULL; - for(; *ptr; ptr++) - *ptr = PICS_TO_LOWER(*ptr); + for(; *ptr; ptr++) + *ptr = PICS_TO_LOWER(*ptr); - return string; + return string; } void @@ -883,7 +1315,7 @@ nsPICS::AddPICSRatingsStructToTreeRatings(PICS_RatingsStruct *rs, PRBool ratings trs->ratings_passed = ratings_passed; trs->rs = CopyRatingsStruct(rs); if(trs->rs) - HTList_addObject(mPICSTreeRatings, trs); + HTList_addObject(mPICSTreeRatings, trs); } return; @@ -918,12 +1350,12 @@ nsPICS::CheckForGenericRatings(char *url_address, PICS_RatingsStruct **rs, PICS_ TreeRatingStruct *trs = FindPICSGenericRatings(url_address); if(trs) { - if(trs->ratings_passed) - *status = PICS_RATINGS_PASSED; - else - *status = PICS_RATINGS_FAILED; + if(trs->ratings_passed) + *status = PICS_RATINGS_PASSED; + else + *status = PICS_RATINGS_FAILED; - *rs = trs->rs; + *rs = trs->rs; } } @@ -935,6 +1367,41 @@ nsPICS::PreferenceChanged(const char* aPrefName) GetUserPreferences(); } +//#define UA_CSS_URL "resource:/res/ua.css" +#define UA_CSS_URL "http://www.w3.org/" +nsresult +nsPICS::GetRootURL(nsIURL* aURL) +{ + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv; + nsIParser *mParser; + nsIContentSink* sink; + nsIStreamListener* lsnr = nsnull; + + + rv = nsComponentManager::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&mParser); + + if (NS_OK == rv) { + + NS_NewHTMLNullSink(&sink); + + if (sink) { + mParser->SetContentSink(sink); + if (NS_FAILED(rv = mParser->QueryInterface(kIStreamListenerIID, (void**) &lsnr))) + return rv; + mParser->Parse(aURL); + rv = NS_OpenURL(aURL, lsnr); + } + NS_RELEASE(sink); + } + return rv; + +} //////////////////////////////////////////////////////////////////////////////// @@ -945,51 +1412,46 @@ NS_IMPL_ISUPPORTS(nsPICSFactory, kIFactoryIID); nsPICSFactory::nsPICSFactory(void) { - NS_INIT_REFCNT(); - printf("initializing my service factory\n"); - PR_AtomicIncrement(&g_InstanceCount); + NS_INIT_REFCNT(); } nsPICSFactory::~nsPICSFactory(void) { - PR_AtomicDecrement(&g_InstanceCount); - printf("finalizing my service factory\n"); + } nsresult nsPICSFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aOuter) - return NS_ERROR_NO_AGGREGATION; + if (! aResult) + return NS_ERROR_NULL_POINTER; - *aResult = nsnull; + if (aOuter) + return NS_ERROR_NO_AGGREGATION; - nsresult rv; - nsPICS* inst = new nsPICS(); + *aResult = nsnull; - if (!inst) - return NS_ERROR_OUT_OF_MEMORY; + nsresult rv; + nsIPICS* inst = nsnull; - rv = inst->QueryInterface(aIID, aResult); - - if (NS_FAILED(rv)) { - *aResult = NULL; - } + if (NS_FAILED(rv = NS_NewPICS(&inst))) return rv; + + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + + rv = inst->QueryInterface(aIID, aResult); + + if (NS_FAILED(rv)) { + *aResult = NULL; + } + return rv; } nsresult nsPICSFactory::LockFactory(PRBool aLock) { - if (aLock) { - PR_AtomicIncrement(&g_LockCount); - } else { - PR_AtomicDecrement(&g_LockCount); - } - return NS_OK; + return NS_OK; } @@ -1006,48 +1468,48 @@ NSGetFactory(nsISupports* servMgr, const char *aProgID, nsIFactory **aFactory) { - if (! aFactory) - return NS_ERROR_NULL_POINTER; - - if (aClass.Equals(kPICSCID)) { - nsPICSFactory *factory = new nsPICSFactory(); + if (! aFactory) + return NS_ERROR_NULL_POINTER; - if (factory == nsnull) - return NS_ERROR_OUT_OF_MEMORY; + if (aClass.Equals(kPICSCID)) { + nsPICSFactory *factory = new nsPICSFactory(); - NS_ADDREF(factory); - *aFactory = factory; - return NS_OK; - } + if (factory == nsnull) + return NS_ERROR_OUT_OF_MEMORY; - return NS_NOINTERFACE; + NS_ADDREF(factory); + *aFactory = factory; + return NS_OK; + } + + return NS_NOINTERFACE; } extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* serviceMgr) { - return PRBool(g_InstanceCount == 0 && g_LockCount == 0); + return PR_FALSE; } extern "C" PR_IMPLEMENT(nsresult) NSRegisterSelf(nsISupports* serviceMgr, const char* aPath) { - return nsRepository::RegisterComponent(kPICSCID, - "PICS", - NS_PICS_PROGID, - aPath,PR_TRUE, PR_TRUE); - - return NS_OK; + return nsRepository::RegisterComponent(kPICSCID, + "PICS", + NS_PICS_PROGID, + aPath,PR_TRUE, PR_TRUE); + + return NS_OK; } extern "C" PR_IMPLEMENT(nsresult) NSUnregisterSelf(nsISupports* serviceMgr, const char* aPath) { - nsresult rv; + nsresult rv; - rv = nsRepository::UnregisterComponent(kPICSCID, aPath); - - return rv; + rv = nsRepository::UnregisterComponent(kPICSCID, aPath); + + return rv; } diff --git a/mozilla/extensions/pics/src/nsPICSElementObserver.cpp b/mozilla/extensions/pics/src/nsPICSElementObserver.cpp new file mode 100644 index 00000000000..f64462871cc --- /dev/null +++ b/mozilla/extensions/pics/src/nsPICSElementObserver.cpp @@ -0,0 +1,227 @@ +/* -*- 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.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#define NS_IMPL_IDS +#include "pratom.h" +#include "nsIFactory.h" +#include "nsIServiceManager.h" +#include "nsRepository.h" +//#include "nsIObserver.h" +#include "nsIURL.h" +#include "nsPICSElementObserver.h" +#include "nsString.h" +#include "nsIPICS.h" +#include "nspics.h" +#include "nsIWebShellServices.h" +#include "prenv.h" + +//static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID); +//static NS_DEFINE_IID(kObserverCID, NS_OBSERVER_CID); +static NS_DEFINE_IID(kIPICSElementObserverIID, NS_IPICSELEMENTOBSERVER_IID); +static NS_DEFINE_IID(kIElementObserverIID, NS_IELEMENTOBSERVER_IID); +static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +static NS_DEFINE_IID(kIPICSIID, NS_IPICS_IID); +static NS_DEFINE_IID(kPICSCID, NS_PICS_CID); + + + + +//////////////////////////////////////////////////////////////////////////////// +// nsPICSElementObserver Implementation + + +NS_IMPL_ADDREF(nsPICSElementObserver) \ +NS_IMPL_RELEASE(nsPICSElementObserver) + +NS_PICS nsresult NS_NewPICSElementObserver(nsIObserver** anObserver) +{ + if (anObserver == NULL) + { + return NS_ERROR_NULL_POINTER; + } + + nsPICSElementObserver* it = new nsPICSElementObserver(); + + if (it == 0) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return it->QueryInterface(kIPICSElementObserverIID, (void **) anObserver); +} + +nsPICSElementObserver::nsPICSElementObserver() +{ + NS_INIT_REFCNT(); +} + +nsPICSElementObserver::~nsPICSElementObserver(void) +{ + +} + +NS_IMETHODIMP nsPICSElementObserver::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + + if( NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + *aInstancePtr = NULL; + + if( aIID.Equals ( kIPICSElementObserverIID )) { + *aInstancePtr = (void*) ((nsIElementObserver*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + if( aIID.Equals ( kIElementObserverIID )) { + *aInstancePtr = (void*) ((nsIElementObserver*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + if( aIID.Equals ( kIObserverIID )) { + *aInstancePtr = (void*) ((nsIObserver*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if( aIID.Equals ( kISupportsIID )) { + *aInstancePtr = (void*) (this); + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +const char* nsPICSElementObserver::GetTagName() +{ + return "META"; + // return NS_OK; +} + +NS_IMETHODIMP nsPICSElementObserver::Notify(PRUint32 aDocumentID, eHTMLTags aTag, + PRUint32 numOfAttributes, const PRUnichar* nameArray[], + const PRUnichar* valueArray[]) +{ + nsresult rv; + int status; + nsIWebShellServices* ws; +// nsString theURL(aSpec); +// char* url = aSpec.ToNewCString(); + nsIURL* uaURL = nsnull; +// rv = NS_NewURL(&uaURL, nsString(aSpec)); + + if(numOfAttributes >= 2) { + const nsString& theValue1=valueArray[0]; + char *val1 = theValue1.ToNewCString(); + if(theValue1.EqualsIgnoreCase("\"PICS-LABEL\"")) { + printf("\nReceived notification for a PICS-LABEl\n"); + const nsString& theValue2=valueArray[1]; + char *label = theValue2.ToNewCString(); + if (valueArray[numOfAttributes]) { + const nsString& theURLValue=valueArray[numOfAttributes]; + rv = NS_NewURL(&uaURL, theURLValue); + } + nsIPICS *pics = NULL; + rv = nsRepository::CreateInstance(kPICSCID, + NULL, + kIPICSIID, + (void **) &pics); + if(rv == NS_OK) { + pics->GetWebShell(aDocumentID, ws); + if(ws) { + status = pics->ProcessPICSLabel(label); + if(uaURL) + pics->SetNotified(ws, uaURL, PR_TRUE); + + if(status) { + if(ws) { + char * text = PR_GetEnv("NGLAYOUT_HOME"); + nsString mtemplateURL = text ? text : "resource:/res/samples/picstest1.html"; + // ws->LoadURL(mtemplateURL, nsnull, nsnull); + nsCharsetSource s; + ws->StopDocumentLoad(); + ws->LoadDocument("resource:/res/samples/picstest1.html", nsnull, s); + } + } + } + } + } + } + return NS_OK; + +} + +NS_IMETHODIMP nsPICSElementObserver::Notify(nsISupports** result) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +//////////////////////////////////////////////////////////////////////////////// +// nsPICSElementObserverFactory Implementation + +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +NS_IMPL_ISUPPORTS(nsPICSElementObserverFactory, kIFactoryIID); + +nsPICSElementObserverFactory::nsPICSElementObserverFactory(void) +{ + NS_INIT_REFCNT(); +} + +nsPICSElementObserverFactory::~nsPICSElementObserverFactory(void) +{ + +} + +nsresult +nsPICSElementObserverFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + *aResult = nsnull; + + nsresult rv; + nsIObserver* inst = nsnull; + + if (NS_FAILED(rv = NS_NewPICSElementObserver(&inst))) + return rv; + + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + + rv = inst->QueryInterface(aIID, aResult); + + if (NS_FAILED(rv)) { + *aResult = NULL; + } + return rv; +} + +nsresult +nsPICSElementObserverFactory::LockFactory(PRBool aLock) +{ + return NS_OK; +} + + +////////////////////////////////////////////////////////////////////////////////