pref_DeleteItem(PLDHashTable *table, PLDHashEntryHdr *heh, PRUint32 i, void *arg) { PrefHashEntry* he = static_cast<PrefHashEntry*>(heh); const char *to_delete = (const char *) arg; int len = PL_strlen(to_delete); /* note if we're deleting "ldap" then we want to delete "ldap.xxx" and "ldap" (if such a leaf node exists) but not "ldap_1.xxx" */ if (to_delete && (PL_strncmp(he->key, to_delete, (PRUint32) len) == 0 || (len-1 == (int)PL_strlen(he->key) && PL_strncmp(he->key, to_delete, (PRUint32)(len-1)) == 0))) return PL_DHASH_REMOVE; return PL_DHASH_NEXT; }
// Verify that nsCRT versions of string comparison routines get the // same answers as the native non-unicode versions. We only pass in // iso-latin-1 strings, so the comparison must be valid. static void Check(const char* s1, const char* s2, PRIntn n) { #ifdef DEBUG PRIntn clib = #endif PL_strcmp(s1, s2); #ifdef DEBUG PRIntn clib_n = #endif PL_strncmp(s1, s2, n); nsAutoString t1,t2; t1.AssignWithConversion(s1); t2.AssignWithConversion(s2); const PRUnichar* us1 = t1.get(); const PRUnichar* us2 = t2.get(); #ifdef DEBUG PRIntn u2 = #endif nsCRT::strcmp(us1, us2); #ifdef DEBUG PRIntn u2_n = #endif nsCRT::strncmp(us1, us2, n); NS_ASSERTION(sign(clib) == sign(u2), "strcmp"); NS_ASSERTION(sign(clib_n) == sign(u2_n), "strncmp"); }
PRBool nsHttpConnection::SupportsPipelining(nsHttpResponseHead *responseHead) { // XXX there should be a strict mode available that disables this // blacklisting. // assuming connection is HTTP/1.1 with keep-alive enabled if (mConnInfo->UsingHttpProxy() && !mConnInfo->UsingSSL()) { // XXX check for bad proxy servers... return PR_TRUE; } // XXX what about checking for a Via header? (transparent proxies) // check for bad origin servers const char *val = responseHead->PeekHeader(nsHttp::Server); if (!val) return PR_FALSE; // no header, no love // The blacklist is indexed by the first character. All of these servers are // known to return their identifier as the first thing in the server string, // so we can do a leading match. static const char *bad_servers[26][5] = { { nsnull }, { nsnull }, { nsnull }, { nsnull }, // a - d { "EFAServer/", nsnull }, // e { nsnull }, { nsnull }, { nsnull }, { nsnull }, // f - i { nsnull }, { nsnull }, { nsnull }, // j - l { "Microsoft-IIS/4.", "Microsoft-IIS/5.", nsnull }, // m { "Netscape-Enterprise/3.", "Netscape-Enterprise/4.", "Netscape-Enterprise/5.", "Netscape-Enterprise/6.", nsnull }, // n { nsnull }, { nsnull }, { nsnull }, { nsnull }, // o - r { nsnull }, { nsnull }, { nsnull }, { nsnull }, // s - v { "WebLogic 3.", "WebLogic 4.","WebLogic 5.", "WebLogic 6.", nsnull }, // w { nsnull }, { nsnull }, { nsnull } // x - z }; int index = val[0] - 'A'; // the whole table begins with capital letters if ((index >= 0) && (index <= 25)) { for (int i = 0; bad_servers[index][i] != nsnull; i++) { if (!PL_strncmp (val, bad_servers[index][i], strlen (bad_servers[index][i]))) { LOG(("looks like this server does not support pipelining")); return PR_FALSE; } } } // ok, let's allow pipelining to this server return PR_TRUE; }
static nsresult pref_DoCallback(const char* changed_pref) { nsresult rv = NS_OK; struct CallbackNode* node; bool reentered = gCallbacksInProgress; gCallbacksInProgress = true; // Nodes must not be deleted while gCallbacksInProgress is true. // Nodes that need to be deleted are marked for deletion by nulling // out the |func| pointer. We release them at the end of this function // if we haven't reentered. for (node = gCallbacks; node != NULL; node = node->next) { if ( node->func && PL_strncmp(changed_pref, node->domain, PL_strlen(node->domain)) == 0 ) { nsresult rv2 = (*node->func) (changed_pref, node->data); if (NS_FAILED(rv2)) rv = rv2; } } gCallbacksInProgress = reentered; if (gShouldCleanupDeadNodes && !gCallbacksInProgress) { struct CallbackNode* prev_node = NULL; node = gCallbacks; while (node != NULL) { if (!node->func) { node = pref_RemoveCallbackNode(node, prev_node); } else { prev_node = node; node = node->next; } } gShouldCleanupDeadNodes = false; } return rv; }
PL_strstr(const char *big, const char *little) { PRUint32 ll; if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; ll = PL_strlen(little); for( ; *big; big++ ) if( *little == *big ) if( 0 == PL_strncmp(big, little, ll) ) return (char *)big; return (char *)0; }
static char * mkoutput(const char *input) { int in_len = strlen(input); char *output = PR_Malloc(in_len+sizeof(SGN_SUFFIX)); int index = in_len + 1 - sizeof("."SHLIB_SUFFIX); if ((index > 0) && (PL_strncmp(&input[index], "."SHLIB_SUFFIX,sizeof("."SHLIB_SUFFIX)) == 0)) { in_len = index; } memcpy(output,input,in_len); memcpy(&output[in_len],SGN_SUFFIX,sizeof(SGN_SUFFIX)); return output; }
PL_strnstr(const char *big, const char *little, PRUint32 max) { PRUint32 ll; if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; ll = PL_strlen(little); if( ll > max ) return (char *)0; max -= ll; max++; for( ; *big && max; big++, max-- ) if( *little == *big ) if( 0 == PL_strncmp(big, little, ll) ) return (char *)big; return (char *)0; }
PL_strrstr(const char *big, const char *little) { const char *p; PRUint32 ll; if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; ll = PL_strlen(little); p = &big[ PL_strlen(big) - ll ]; if( p < big ) return (char *)0; for( ; p >= big; p-- ) if( *little == *p ) if( 0 == PL_strncmp(p, little, ll) ) return (char *)p; return (char *)0; }
COMclass COMfindComponent (const char *className) { const char *prefix = "urn:"; const char *modulePrefix = "swarm/"; size_t prefixLen = PL_strlen (prefix); size_t modulePrefixLen = PL_strlen (modulePrefix); nsCID *cClass = new nsCID (); size_t classNameLen = PL_strlen (className); char *buf = (char *) malloc (prefixLen + classNameLen + 1); if (!buf) abort (); nsresult rv; PL_strcpy (buf, prefix); PL_strcat (buf, className); if (PL_strncmp (className, modulePrefix, modulePrefixLen) == 0) { unsigned i; buf[prefixLen + 5] = ':'; for (i = modulePrefixLen; i < classNameLen; i++) { unsigned pos = prefixLen + i; if (buf[pos] == '/') buf[pos] = '.'; } } nsCOMPtr<nsIComponentManager> compMgr; NS_GetComponentManager (getter_AddRefs (compMgr)); if (!compMgr) abort (); nsCOMPtr<nsIComponentManagerObsolete> compMgrO = do_QueryInterface (compMgr); rv = compMgrO->ContractIDToClassID (buf, cClass); free (buf); if (NS_FAILED (rv)) abort (); return (COMclass) cClass; }
PL_strnrstr(const char *big, const char *little, PRUint32 max) { const char *p; PRUint32 ll; if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; ll = PL_strlen(little); for( p = big; *p && max; p++, max-- ) ; p -= ll; if( p < big ) return (char *)0; for( ; p >= big; p-- ) if( *little == *p ) if( 0 == PL_strncmp(p, little, ll) ) return (char *)p; return (char *)0; }
static void SearchForSoname(const char* name, char** soname) { if (!(name && soname)) return; PRDir *fdDir = PR_OpenDir(DEFAULT_X11_PATH); if (!fdDir) return; int n = PL_strlen(name); PRDirEntry *dirEntry; while ((dirEntry = PR_ReadDir(fdDir, PR_SKIP_BOTH))) { if (!PL_strncmp(dirEntry->name, name, n)) { if (dirEntry->name[n] == '.' && dirEntry->name[n+1] && !dirEntry->name[n+2]) { // name.N, wild guess this is what we need char out[PLUGIN_MAX_LEN_OF_TMP_ARR] = DEFAULT_X11_PATH; PL_strcat(out, dirEntry->name); *soname = PL_strdup(out); break; } } } PR_CloseDir(fdDir); }
// |decode_mime_part2_str| taken from comi18n.c // Decode RFC2047-encoded words in the input and convert the result to UTF-8. // If aOverrideCharset is true, charset in RFC2047-encoded words is // ignored and aDefaultCharset is assumed, instead. aDefaultCharset // is also used to convert raw octets (without RFC 2047 encoding) to UTF-8. //static nsresult DecodeRFC2047Str(const char *aHeader, const char *aDefaultCharset, PRBool aOverrideCharset, nsACString &aResult) { const char *p, *q, *r; char *decodedText; const char *begin; // tracking pointer for where we are in the input buffer PRInt32 isLastEncodedWord = 0; const char *charsetStart, *charsetEnd; char charset[80]; // initialize charset name to an empty string charset[0] = '\0'; begin = aHeader; // To avoid buffer realloc, if possible, set capacity in advance. No // matter what, more than 3x expansion can never happen for all charsets // supported by Mozilla. SCSU/BCSU with the sliding window set to a // non-BMP block may be exceptions, but Mozilla does not support them. // Neither any known mail/news program use them. Even if there's, we're // safe because we don't use a raw *char any more. aResult.SetCapacity(3 * strlen(aHeader)); while ((p = PL_strstr(begin, "=?")) != 0) { if (isLastEncodedWord) { // See if it's all whitespace. for (q = begin; q < p; ++q) { if (!PL_strchr(" \t\r\n", *q)) break; } } if (!isLastEncodedWord || q < p) { // copy the part before the encoded-word CopyRawHeader(begin, p - begin, aDefaultCharset, aResult); begin = p; } p += 2; // Get charset info charsetStart = p; charsetEnd = 0; for (q = p; *q != '?'; q++) { if (*q <= ' ' || PL_strchr(especials, *q)) { goto badsyntax; } // RFC 2231 section 5 if (!charsetEnd && *q == '*') { charsetEnd = q; } } if (!charsetEnd) { charsetEnd = q; } // Check for too-long charset name if (PRUint32(charsetEnd - charsetStart) >= sizeof(charset)) goto badsyntax; memcpy(charset, charsetStart, charsetEnd - charsetStart); charset[charsetEnd - charsetStart] = 0; q++; if (*q != 'Q' && *q != 'q' && *q != 'B' && *q != 'b') goto badsyntax; if (q[1] != '?') goto badsyntax; r = q; for (r = q + 2; *r != '?'; r++) { if (*r < ' ') goto badsyntax; } if (r[1] != '=') goto badsyntax; else if (r == q + 2) { // it's empty, skip begin = r + 2; isLastEncodedWord = 1; continue; } if(*q == 'Q' || *q == 'q') decodedText = DecodeQ(q + 2, r - (q + 2)); else { // bug 227290. ignore an extraneous '=' at the end. // (# of characters in B-encoded part has to be a multiple of 4) PRInt32 n = r - (q + 2); n -= (n % 4 == 1 && !PL_strncmp(r - 3, "===", 3)) ? 1 : 0; decodedText = PL_Base64Decode(q + 2, n, nsnull); } if (decodedText == nsnull) goto badsyntax; // Override charset if requested. Never override labeled UTF-8. // Use default charset instead of UNKNOWN-8BIT if ((aOverrideCharset && 0 != nsCRT::strcasecmp(charset, "UTF-8")) || (aDefaultCharset && 0 == nsCRT::strcasecmp(charset, "UNKNOWN-8BIT"))) { PL_strncpy(charset, aDefaultCharset, sizeof(charset) - 1); charset[sizeof(charset) - 1] = '\0'; } { nsCOMPtr<nsIUTF8ConverterService> cvtUTF8(do_GetService(NS_UTF8CONVERTERSERVICE_CONTRACTID)); nsCAutoString utf8Text; // skip ASCIIness/UTF8ness test if aCharset is 7bit non-ascii charset. if (cvtUTF8 && NS_SUCCEEDED( cvtUTF8->ConvertStringToUTF8(nsDependentCString(decodedText), charset, IS_7BIT_NON_ASCII_CHARSET(charset), utf8Text))) { aResult.Append(utf8Text); } else { aResult.Append(REPLACEMENT_CHAR); } } PR_Free(decodedText); begin = r + 2; isLastEncodedWord = 1; continue; badsyntax: // copy the part before the encoded-word aResult.Append(begin, p - begin); begin = p; isLastEncodedWord = 0; } // put the tail back CopyRawHeader(begin, strlen(begin), aDefaultCharset, aResult); nsCAutoString tempStr(aResult); tempStr.ReplaceChar('\t', ' '); aResult = tempStr; return NS_OK; }
nsresult nsReadConfig::readConfigFile() { nsresult rv = NS_OK; nsXPIDLCString lockFileName; nsXPIDLCString lockVendor; PRUint32 fileNameLen = 0; nsCOMPtr<nsIPrefBranch> defaultPrefBranch; nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = prefService->GetDefaultBranch(nsnull, getter_AddRefs(defaultPrefBranch)); if (NS_FAILED(rv)) return rv; // This preference is set in the all.js or all-ns.js (depending whether // running mozilla or netscp6) rv = defaultPrefBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName)); PR_LOG(MCD, PR_LOG_DEBUG, ("general.config.filename = %s\n", lockFileName.get())); if (NS_FAILED(rv)) return rv; // This needs to be read only once. // if (!mRead) { // Initiate the new JS Context for Preference management rv = CentralizedAdminPrefManagerInit(); if (NS_FAILED(rv)) return rv; // Open and evaluate function calls to set/lock/unlock prefs rv = openAndEvaluateJSFile("prefcalls.js", 0, false, false); if (NS_FAILED(rv)) return rv; // Evaluate platform specific directives rv = openAndEvaluateJSFile("platform.js", 0, false, false); if (NS_FAILED(rv)) return rv; mRead = true; } // If the lockFileName is NULL return ok, because no lockFile will be used // Once the config file is read, we should check that the vendor name // is consistent By checking for the vendor name after reading the config // file we allow for the preference to be set (and locked) by the creator // of the cfg file meaning the file can not be renamed (successfully). nsCOMPtr<nsIPrefBranch> prefBranch; rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch)); NS_ENSURE_SUCCESS(rv, rv); PRInt32 obscureValue = 0; (void) defaultPrefBranch->GetIntPref("general.config.obscure_value", &obscureValue); PR_LOG(MCD, PR_LOG_DEBUG, ("evaluating .cfg file %s with obscureValue %d\n", lockFileName.get(), obscureValue)); rv = openAndEvaluateJSFile(lockFileName.get(), obscureValue, true, true); if (NS_FAILED(rv)) { PR_LOG(MCD, PR_LOG_DEBUG, ("error evaluating .cfg file %s %x\n", lockFileName.get(), rv)); return rv; } rv = prefBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName)); if (NS_FAILED(rv)) // There is NO REASON we should ever get here. This is POST reading // of the config file. return NS_ERROR_FAILURE; rv = prefBranch->GetCharPref("general.config.vendor", getter_Copies(lockVendor)); // If vendor is not NULL, do this check if (NS_SUCCEEDED(rv)) { fileNameLen = PL_strlen(lockFileName); // lockVendor and lockFileName should be the same with the addtion of // .cfg to the filename by checking this post reading of the cfg file // this value can be set within the cfg file adding a level of security. if (PL_strncmp(lockFileName, lockVendor, fileNameLen - 4) != 0) return NS_ERROR_FAILURE; } // get the value of the autoconfig url nsXPIDLCString urlName; rv = prefBranch->GetCharPref("autoadmin.global_config_url", getter_Copies(urlName)); if (NS_SUCCEEDED(rv) && !urlName.IsEmpty()) { // Instantiating nsAutoConfig object if the pref is present mAutoConfig = do_CreateInstance(NS_AUTOCONFIG_CONTRACTID, &rv); if (NS_FAILED(rv)) return NS_ERROR_OUT_OF_MEMORY; rv = mAutoConfig->SetConfigURL(urlName); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; } return NS_OK; } // ReadConfigFile
NS_IMETHODIMP nsMsgSaveAsListener::OnDataAvailable(nsIRequest* request, nsISupports* aSupport, nsIInputStream* inStream, uint64_t srcOffset, uint32_t count) { nsresult rv; uint64_t available; rv = inStream->Available(&available); if (!m_writtenData) { m_writtenData = true; rv = SetupMsgWriteStream(m_outputFile, m_addDummyEnvelope); NS_ENSURE_SUCCESS(rv, rv); } bool useCanonicalEnding = false; nsCOMPtr <nsIMsgMessageUrl> msgUrl = do_QueryInterface(aSupport); if (msgUrl) msgUrl->GetCanonicalLineEnding(&useCanonicalEnding); const char *lineEnding = (useCanonicalEnding) ? CRLF : MSG_LINEBREAK; uint32_t lineEndingLength = (useCanonicalEnding) ? 2 : MSG_LINEBREAK_LEN; uint32_t readCount, maxReadCount = SAVE_BUF_SIZE - m_leftOver; uint32_t writeCount; char *start, *end, lastCharInPrevBuf = '\0'; uint32_t linebreak_len = 0; while (count > 0) { if (count < maxReadCount) maxReadCount = count; rv = inStream->Read(m_dataBuffer + m_leftOver, maxReadCount, &readCount); if (NS_FAILED(rv)) return rv; m_leftOver += readCount; m_dataBuffer[m_leftOver] = '\0'; start = m_dataBuffer; // make sure we don't insert another LF, accidentally, by ignoring // second half of CRLF spanning blocks. if (lastCharInPrevBuf == '\r' && *start == '\n') start++; end = PL_strchr(start, '\r'); if (!end) end = PL_strchr(start, '\n'); else if (*(end+1) == '\n' && linebreak_len == 0) linebreak_len = 2; if (linebreak_len == 0) // not initialize yet linebreak_len = 1; count -= readCount; maxReadCount = SAVE_BUF_SIZE - m_leftOver; if (!end && count > maxReadCount) // must be a very very long line; sorry cannot handle it return NS_ERROR_FAILURE; while (start && end) { if (m_outputStream && PL_strncasecmp(start, "X-Mozilla-Status:", 17) && PL_strncasecmp(start, "X-Mozilla-Status2:", 18) && PL_strncmp(start, "From - ", 7)) { rv = m_outputStream->Write(start, end-start, &writeCount); nsresult tmp = m_outputStream->Write(lineEnding, lineEndingLength, &writeCount); if (NS_FAILED(tmp)) { rv = tmp; } } start = end+linebreak_len; if (start >= m_dataBuffer + m_leftOver) { maxReadCount = SAVE_BUF_SIZE; m_leftOver = 0; break; } end = PL_strchr(start, '\r'); if (!end) end = PL_strchr(start, '\n'); if (start && !end) { m_leftOver -= (start - m_dataBuffer); memcpy(m_dataBuffer, start, m_leftOver+1); // including null maxReadCount = SAVE_BUF_SIZE - m_leftOver; } } if (NS_FAILED(rv)) return rv; if (end) lastCharInPrevBuf = *end; } return rv; // rv = m_outputStream->WriteFrom(inStream, std::min(available, count), &bytesWritten); }
NS_IMETHODIMP nsMsgSaveAsListener::OnDataAvailable(nsIRequest* request, nsISupports* aSupport, nsIInputStream* inStream, PRUint32 srcOffset, PRUint32 count) { nsresult rv; PRUint32 available; rv = inStream->Available(&available); if (!m_writtenData) { m_writtenData = PR_TRUE; rv = SetupMsgWriteStream(m_outputFile, m_addDummyEnvelope); NS_ENSURE_SUCCESS(rv, rv); } PRBool useCanonicalEnding = PR_FALSE; nsCOMPtr <nsIMsgMessageUrl> msgUrl = do_QueryInterface(aSupport); if (msgUrl) msgUrl->GetCanonicalLineEnding(&useCanonicalEnding); const char *lineEnding = (useCanonicalEnding) ? CRLF : MSG_LINEBREAK; PRUint32 lineEndingLength = (useCanonicalEnding) ? 2 : MSG_LINEBREAK_LEN; PRUint32 readCount, maxReadCount = SAVE_BUF_SIZE - m_leftOver; PRUint32 writeCount; char *start, *end; PRUint32 linebreak_len = 0; while (count > 0) { if (count < maxReadCount) maxReadCount = count; rv = inStream->Read(m_dataBuffer + m_leftOver, maxReadCount, &readCount); if (NS_FAILED(rv)) return rv; m_leftOver += readCount; m_dataBuffer[m_leftOver] = '\0'; start = m_dataBuffer; end = PL_strchr(start, '\r'); if (!end) end = PL_strchr(start, '\n'); else if (*(end+1) == '\n' && linebreak_len == 0) linebreak_len = 2; if (linebreak_len == 0) // not initialize yet linebreak_len = 1; count -= readCount; maxReadCount = SAVE_BUF_SIZE - m_leftOver; if (!end && count > maxReadCount) // must be a very very long line; sorry cannot handle it return NS_ERROR_FAILURE; while (start && end) { if (PL_strncasecmp(start, "X-Mozilla-Status:", 17) && PL_strncasecmp(start, "X-Mozilla-Status2:", 18) && PL_strncmp(start, "From - ", 7)) { rv = m_outputStream->Write(start, end-start, &writeCount); rv = m_outputStream->Write(lineEnding, lineEndingLength, &writeCount); } start = end+linebreak_len; if (start >= m_dataBuffer + m_leftOver) { maxReadCount = SAVE_BUF_SIZE; m_leftOver = 0; break; } end = PL_strchr(start, '\r'); if (!end) end = PL_strchr(start, '\n'); if (start && !end) { m_leftOver -= (start - m_dataBuffer); memcpy(m_dataBuffer, start, m_leftOver+1); // including null maxReadCount = SAVE_BUF_SIZE - m_leftOver; } } if (NS_FAILED(rv)) return rv; } return rv; // rv = m_outputStream->WriteFrom(inStream, PR_MIN(available, count), &bytesWritten); }
PRBool nsFrameUtil::CompareTrees(Node* tree1, Node* tree2) { PRBool result = PR_TRUE; for (;; tree1 = tree1->next, tree2 = tree2->next) { // Make sure both nodes are non-null, or at least agree with each other if (nsnull == tree1) { if (nsnull == tree2) { break; } printf("first tree prematurely ends\n"); return PR_FALSE; } else if (nsnull == tree2) { printf("second tree prematurely ends\n"); return PR_FALSE; } // Check the attributes that we care about if (0 != PL_strcmp(tree1->type, tree2->type)) { printf("frame type mismatch: %s vs. %s\n", tree1->type, tree2->type); printf("Node 1:\n"); DumpNode(tree1, stdout, 1); printf("Node 2:\n"); DumpNode(tree2, stdout, 1); return PR_FALSE; } // Ignore the XUL scrollbar frames static const char kScrollbarFrame[] = "ScrollbarFrame"; if (0 == PL_strncmp(tree1->type, kScrollbarFrame, sizeof(kScrollbarFrame) - 1)) continue; if (tree1->state != tree2->state) { printf("frame state mismatch: 0x%x vs. 0x%x\n", tree1->state, tree2->state); printf("Node 1:\n"); DumpNode(tree1, stdout, 1); printf("Node 2:\n"); DumpNode(tree2, stdout, 1); result = PR_FALSE; // we have a non-critical failure, so remember that but continue } if (tree1->bbox != tree2->bbox) { printf("frame bbox mismatch: %d,%d,%d,%d vs. %d,%d,%d,%d\n", tree1->bbox.x, tree1->bbox.y, tree1->bbox.width, tree1->bbox.height, tree2->bbox.x, tree2->bbox.y, tree2->bbox.width, tree2->bbox.height); printf("Node 1:\n"); DumpNode(tree1, stdout, 1); printf("Node 2:\n"); DumpNode(tree2, stdout, 1); result = PR_FALSE; // we have a non-critical failure, so remember that but continue } if (tree1->styleData != tree2->styleData) { printf("frame style data mismatch: %s vs. %s\n", tree1->styleData.get(), tree2->styleData.get()); } // Check child lists too NodeList* list1 = tree1->lists; NodeList* list2 = tree2->lists; for (;;) { if (nsnull == list1) { if (nsnull != list2) { printf("first tree prematurely ends (no child lists)\n"); printf("Node 1:\n"); DumpNode(tree1, stdout, 1); printf("Node 2:\n"); DumpNode(tree2, stdout, 1); return PR_FALSE; } else { break; } } if (nsnull == list2) { printf("second tree prematurely ends (no child lists)\n"); printf("Node 1:\n"); DumpNode(tree1, stdout, 1); printf("Node 2:\n"); DumpNode(tree2, stdout, 1); return PR_FALSE; } if (0 != PL_strcmp(list1->name, list2->name)) { printf("child-list name mismatch: %s vs. %s\n", list1->name ? list1->name : "(null)", list2->name ? list2->name : "(null)"); result = PR_FALSE; // we have a non-critical failure, so remember that but continue } else { PRBool equiv = CompareTrees(list1->node, list2->node); if (!equiv) { return equiv; } } list1 = list1->next; list2 = list2->next; } } return result; }
SKERR SKIndex::ConfigureItem(char* pszSection, char* pszToken, char* pszValue) { SKERR err = err_not_handled; if(!pszToken) return noErr; if(!PL_strcmp(pszSection, "WORDTABLE")) { if(!PL_strcmp(pszToken, "DOCLINKFIELD")) { if(m_pWordRecordSet) { skPtr<SKIFldCollection> pCol; err = m_pWordRecordSet->GetFldCollection( pCol.already_AddRefed()); if(err == noErr) err = pCol->GetField(pszValue, m_pDocLinkField.already_AddRefed()); } else { err = err_config; } } else if(!PL_strcmp(pszToken, "DOCIDFIELD")) { if(m_pDocLinkField) { skPtr<SKIRecordSet> pLinkRS; err = m_pDocLinkField->GetLinkSubRecordSet( pLinkRS.already_AddRefed()); if(err == noErr) { skPtr<SKIFldCollection> pCol; err = pLinkRS->GetFldCollection( pCol.already_AddRefed()); if(err == noErr) err = pCol->GetField(pszValue, m_pDocIdField.already_AddRefed()); } } else { err = err_config; } } else if(!PL_strcmp(pszToken, "STRUCTUREFIELD")) { if(!*pszValue) err = noErr; else if(m_pDocLinkField) { skPtr<SKIRecordSet> pLinkRS; err = m_pDocLinkField->GetLinkSubRecordSet( pLinkRS.already_AddRefed()); if(err == noErr) { skPtr<SKIFldCollection> pCol; err = pLinkRS->GetFldCollection( pCol.already_AddRefed()); if(err == noErr) err = pCol->GetField(pszValue, m_pStructureField.already_AddRefed()); } } else { err = err_config; } } else if(!PL_strcmp(pszToken, "OCCLINKFIELD")) { if(!*pszValue) err = noErr; else if(m_pDocLinkField) { skPtr<SKIRecordSet> pLinkRS; err = m_pDocLinkField->GetLinkSubRecordSet( pLinkRS.already_AddRefed()); if(err == noErr) { skPtr<SKIFldCollection> pCol; err = pLinkRS->GetFldCollection( pCol.already_AddRefed()); if(err == noErr) err = pCol->GetField(pszValue, m_pOccLinkField.already_AddRefed()); } } else { err = err_config; } } else if(!PL_strcmp(pszToken, "OCCFIELD")) { if(!*pszValue) err = noErr; else if(m_pOccLinkField) { skPtr<SKIRecordSet> pLinkRS; err = m_pOccLinkField->GetLinkSubRecordSet( pLinkRS.already_AddRefed()); if(err == noErr) { skPtr<SKIFldCollection> pCol; err = pLinkRS->GetFldCollection( pCol.already_AddRefed()); if(err == noErr) err = pCol->GetField(pszValue, m_pOccField.already_AddRefed()); } } else { err = err_config; } } } // [WILDCARDWORDLIST] else if(!PL_strcmp(pszSection, "WILDCARDWORDLIST")) { if(!PL_strcmp(pszToken, "PATH")) { *m_pWordList.already_AddRefed() = sk_CreateInstance(SKWildCardWordList)(); if(m_pWordList) { err = m_pWordList->SetFileName(pszValue); if(err == noErr) err = m_pWordList->GetWordRecordSet( m_pWordRecordSet.already_AddRefed()); } else { err = err_memory; } } } // [SEPARATORS] else if (!PL_strcmp(pszSection, "SEPARATORS")) { if(!PL_strcmp(pszToken, "HARD")) { *m_pHardSepList.already_AddRefed() = sk_CreateInstance(SKIntegerList)(); if (m_pHardSepList) err = m_pHardSepList->SetListFromAsciiString(pszValue); else err = err_memory; } else if(!PL_strcmp(pszToken, "SOFT")) { *m_pSoftSepList.already_AddRefed() = sk_CreateInstance(SKIntegerList)(); if (m_pSoftSepList) err = m_pSoftSepList->SetListFromAsciiString(pszValue); else err = err_memory; } else if (!PL_strcmp(pszToken, "EXCEPTIONS")) { *m_pSoftSepExcList.already_AddRefed() = sk_CreateInstance(SKStringList)(); if (m_pSoftSepExcList) err = m_pSoftSepExcList->SetFileName(pszValue); else err = err_memory; } else err = err_config; } // [STOPWORDLIST] else if (!PL_strcmp(pszSection, "STOPWORDLIST")) { if(!PL_strcmp(pszToken, "PATH")) { *m_pStopWordList.already_AddRefed() = sk_CreateInstance(SKStringList)(); if (m_pStopWordList) err = m_pStopWordList->SetFileName(pszValue); else err = err_memory; } else err = err_config; } // [LINKS] else if (!PL_strcmp(pszSection, "LINKS")) { PRUint32 lLink = 0; if (!PL_strcmp(pszToken, "COUNT")) { PRUint32 i; m_lLinkCount = atoi(pszValue); __CleanPpsz(m_ppszLinkNames); err = noErr; m_ppszLinkNames = (char **)PR_Malloc(sizeof(char *) * m_lLinkCount); if (m_ppszLinkNames == NULL) err = SKError(err_idx_malloc, "[SKIndex::SetFileName] " "Can not allocate memory"); __CleanPpsz(m_ppszSubLinkNames); m_ppszSubLinkNames = (char **)PR_Malloc(sizeof(char *) * m_lLinkCount); if (m_ppszSubLinkNames == NULL) err = SKError(err_idx_malloc, "[SKIndex::SetFileName] " "Can not allocate memory"); m_pbMerge = (PRBool*) PR_Malloc(sizeof(PRBool) * m_lLinkCount); if (m_pbMerge == NULL) err = SKError(err_idx_malloc, "[SKIndex::SetFileName] " "Can not allocate memory"); for(i = 0 ; i < m_lLinkCount ; i++) { m_ppszLinkNames[i] = NULL; m_ppszSubLinkNames[i] = NULL; m_pbMerge[i] = PR_FALSE; } } else if(!PL_strncmp(pszToken, "FIELD", 5)) { err = noErr; if (pszToken[5] != ',') { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Missing comma after FIELD"); } lLink = atoi(pszToken + 6)-1; if (lLink >= m_lLinkCount) { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Bad link number value for FIELD: %d", lLink); } __CleanPsz(m_ppszLinkNames[lLink]); m_ppszLinkNames[lLink] = PL_strdup(pszValue); } else if(!PL_strncmp(pszToken, "SUBFIELD", 8)) { err = noErr; if (pszToken[8] != ',') { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Missing comma after SUBFIELD"); } lLink = atoi(pszToken + 9)-1; if (lLink >= m_lLinkCount) { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Bad link number value for SUBFIELD: %d", lLink); } __CleanPsz(m_ppszSubLinkNames[lLink]); m_ppszSubLinkNames[lLink] = PL_strdup(pszValue); } else if(!PL_strncmp(pszToken, "MERGE", 5)) { err = noErr; if (pszToken[5] != ',') { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Missing comma after MERGE"); } lLink = atoi(pszToken + 6)-1; if (lLink >= m_lLinkCount) { err = SKError(err_idx_invalid, "[SKIndex::SetFileName] " "Bad link number value for MERGE: %d", lLink); } m_pbMerge[lLink] = MAKE_BOOL(pszValue); } } return err; }
PRStatus FcgiParser::parseHttpHeader(CircularBuffer& to) { if(!waitingForDataParse) return PR_SUCCESS; const char *data = httpHeader.data(); int len = httpHeader.length(); PRUint8 flag = 0; while(len-- && flag < 2) { switch(*data) { case '\r': break; case '\n': flag++; break; default: flag = 0; break; } data++; } /* * Return (to be called later when we have more data) */ if(flag < 2) return PR_SUCCESS; waitingForDataParse = PR_FALSE; Request *rq = request->getOrigRequest(); pblock *authpb = NULL; if(fcgiRole == FCGI_AUTHORIZER) { authpb = pblock_create(rq->srvhdrs->hsize); } register int x ,y; register char c; int nh; char t[REQ_MAX_LINE]; PRBool headerEnd = PR_FALSE; char* statusHeader = pblock_findval("status", rq->srvhdrs); char *next = const_cast<char *>(httpHeader.data()); nh = 0; x = 0; y = -1; for(; !headerEnd;) { c = *(next++); switch(c) { case CR: // Silently ignore CRs break; case LF: if (x == 0) { headerEnd = PR_TRUE; break; } t[x] = '\0'; if(y == -1) { request->log(LOG_FAILURE, "name without value: got line \"%s\"", t); return PR_FAILURE; } while(t[y] && isspace(t[y])) ++y; // Do not change the status header to 200 if it was already set // This would happen only if it were a cgi error handler // and so the status had been already set on the request // originally if (!statusHeader || // If we don't already have a Status: header PL_strcmp(t, "status") || // or this isn't a Status: header PL_strncmp(&t[y], "200", 3)) // or this isn't "Status: 200" { if(!PL_strcmp(t, "content-type")) { pb_param* pParam = pblock_remove ( "content-type", rq->srvhdrs ); if ( pParam ) param_free ( pParam ); } if(fcgiRole == FCGI_AUTHORIZER) { pblock_nvinsert(t, &t[y], authpb); } else { pblock_nvinsert(t, &t[y], rq->srvhdrs); } // !FCGI_AUTHORIZER } x = 0; y = -1; ++nh; break; case ':': if(y == -1) { y = x+1; c = '\0'; } default: t[x++] = ((y == -1) && isupper(c) ? tolower(c) : c); } } // for if(fcgiRole == FCGI_AUTHORIZER) { if(parseAuthHeaders(authpb) != PR_SUCCESS) { pblock_free(authpb); return PR_FAILURE; } pblock_copy(authpb, rq->srvhdrs); pblock_free(authpb); } else { /* * We're done scanning the FCGI script's header output. Now * we have to write to the client: status, FCGI header, and * any over-read FCGI output. */ char *s; char *l = pblock_findval("location", rq->srvhdrs); if((s = pblock_findval("status", rq->srvhdrs))) { if((strlen(s) < 3) || (!isdigit(s[0]) || (!isdigit(s[1])) || (!isdigit(s[2])))) { s = NULL; } else { char ch = s[3]; s[3] = '\0'; int statusNum = atoi(s); s[3] = ch; rq->status_num = statusNum; } } if(!s) { if (l) pblock_nvinsert("url", l, rq->vars); protocol_status(request->getOrigSession(), request->getOrigRequest(), (l ? PROTOCOL_REDIRECT : PROTOCOL_OK), NULL); } } len = next - httpHeader.data(); len = httpHeader.length() - len; if(len < 0) return PR_FAILURE; /* * Only send the body for methods other than HEAD. */ if(!request->isHead()) { if(len > 0) { if(to.addData(next, len) != len) return PR_FAILURE; } } next = NULL; return PR_SUCCESS; }
static nsresult SplitURL(nsIURI *aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCString& aFile, PRBool *aModified = nsnull) { // Splits a "chrome:" URL into its package, provider, and file parts. // Here are the current portions of a // chrome: url that make up the chrome- // // chrome://global/skin/foo?bar // \------/ \----/\---/ \-----/ // | | | | // | | | `-- RemainingPortion // | | | // | | `-- Provider // | | // | `-- Package // | // `-- Always "chrome://" // // nsresult rv; nsCAutoString str; rv = aChromeURI->GetSpec(str); if (NS_FAILED(rv)) return rv; // We only want to deal with "chrome:" URLs here. We could return // an error code if the URL isn't properly prefixed here... if (PL_strncmp(str.get(), kChromePrefix, sizeof(kChromePrefix) - 1) != 0) return NS_ERROR_INVALID_ARG; // Cull out the "package" string; e.g., "navigator" aPackage = str.get() + sizeof(kChromePrefix) - 1; PRInt32 idx; idx = aPackage.FindChar('/'); if (idx < 0) return NS_OK; // Cull out the "provider" string; e.g., "content" aPackage.Right(aProvider, aPackage.Length() - (idx + 1)); aPackage.Truncate(idx); idx = aProvider.FindChar('/'); if (idx < 0) { // Force the provider to end with a '/' idx = aProvider.Length(); aProvider.Append('/'); } // Cull out the "file"; e.g., "navigator.xul" aProvider.Right(aFile, aProvider.Length() - (idx + 1)); aProvider.Truncate(idx); PRBool nofile = aFile.IsEmpty(); if (nofile) { // If there is no file, then construct the default file aFile = aPackage; if (aProvider.Equals("content")) { aFile += ".xul"; } else if (aProvider.Equals("skin")) { aFile += ".css"; } else if (aProvider.Equals("locale")) { aFile += ".dtd"; } else { NS_ERROR("unknown provider"); return NS_ERROR_FAILURE; } } else { // Protect against URIs containing .. that reach up out of the // chrome directory to grant chrome privileges to non-chrome files. int depth = 0; PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. for (const char* p=aFile.get(); *p; p++) { if (sawSlash) { if (p[0] == '.' && p[1] == '.'){ depth--; // we have /.., decrement depth. } else { static const char escape[] = "%2E%2E"; if (PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) depth--; // we have the HTML-escaped form of /.., decrement depth. } } else if (p[0] != '/') { depth++; // we have /x for some x that is not / } sawSlash = (p[0] == '/'); if (depth < 0) { return NS_ERROR_FAILURE; } } } if (aModified) *aModified = nofile; return NS_OK; }