NS_IMETHODIMP nsCommandLine::Init(int32_t argc, const char* const* argv, nsIFile* aWorkingDir, uint32_t aState) { NS_ENSURE_ARG_MAX(aState, 2); int32_t i; mWorkingDir = aWorkingDir; // skip argv[0], we don't want it for (i = 1; i < argc; ++i) { const char* curarg = argv[i]; #ifdef DEBUG_COMMANDLINE printf("Testing native arg %i: '%s'\n", i, curarg); #endif #if defined(XP_WIN) if (*curarg == '/') { char* dup = PL_strdup(curarg); if (!dup) return NS_ERROR_OUT_OF_MEMORY; *dup = '-'; char* colon = PL_strchr(dup, ':'); if (colon) { *colon = '\0'; appendArg(dup); appendArg(colon+1); } else { appendArg(dup); } PL_strfree(dup); continue; } #endif if (*curarg == '-') { if (*(curarg+1) == '-') ++curarg; char* dup = PL_strdup(curarg); if (!dup) return NS_ERROR_OUT_OF_MEMORY; char* eq = PL_strchr(dup, '='); if (eq) { *eq = '\0'; appendArg(dup); appendArg(eq + 1); } else { appendArg(dup); } PL_strfree(dup); continue; } appendArg(curarg); } mState = aState; return NS_OK; }
/* str is the string which needs to be unserialized. If prefixes is NULL, simply returns the number of namespaces in str. (len is ignored) If prefixes is not NULL, it should be an array of length len which is to be filled in with newly-allocated string. Returns the number of strings filled in. */ int nsIMAPNamespaceList::UnserializeNamespaces(const char *str, char **prefixes, int len) { if (!str) return 0; if (!prefixes) { if (str[0] != '"') return 1; else { int count = 0; char *ourstr = PL_strdup(str); char *origOurStr = ourstr; if (ourstr) { char *token = NS_strtok(SERIALIZER_SEPARATORS, &ourstr ); while (token != nullptr) { token = NS_strtok(SERIALIZER_SEPARATORS, &ourstr ); count++; } PR_Free(origOurStr); } return count; } } else { if ((str[0] != '"') && (len >= 1)) { prefixes[0] = PL_strdup(str); return 1; } else { int count = 0; char *ourstr = PL_strdup(str); char *origOurStr = ourstr; if (ourstr) { char *token = NS_strtok(SERIALIZER_SEPARATORS, &ourstr ); while ((count < len) && (token != nullptr)) { char *current = PL_strdup(token), *where = current; if (where[0] == '"') where++; if (where[PL_strlen(where)-1] == '"') where[PL_strlen(where)-1] = 0; prefixes[count] = PL_strdup(where); PR_FREEIF(current); token = NS_strtok(SERIALIZER_SEPARATORS, &ourstr ); count++; } PR_Free(origOurStr); } return count; } } }
nsresult nsMsgAttachmentHandler::ConvertToZipFile(nsILocalFileMac *aSourceFile) { // append ".zip" to the real file name nsCAutoString zippedName; nsresult rv = aSourceFile->GetNativeLeafName(zippedName); NS_ENSURE_SUCCESS(rv, rv); zippedName.AppendLiteral(".zip"); // create a temporary file that we'll work on nsCOMPtr <nsIFile> tmpFile; rv = nsMsgCreateTempFile(zippedName.get(), getter_AddRefs(tmpFile)); NS_ENSURE_SUCCESS(rv, rv); mEncodedWorkingFile = do_QueryInterface(tmpFile); // point our URL at the zipped temp file NS_NewFileURI(getter_AddRefs(mURL), mEncodedWorkingFile); // zip it! rv = nsSimpleZipper::Zip(aSourceFile, mEncodedWorkingFile); NS_ENSURE_SUCCESS(rv, rv); // set some metadata for this attachment, that will affect the MIME headers. PR_Free(m_type); m_type = PL_strdup(APPLICATION_ZIP); PR_Free(m_real_name); m_real_name = PL_strdup(zippedName.get()); return NS_OK; }
/* readonly attribute string windowTitle; */ NS_IMETHODIMP nsNSSCertificate::GetWindowTitle(char * *aWindowTitle) { nsNSSShutDownPreventionLock locker; if (isAlreadyShutDown()) return NS_ERROR_NOT_AVAILABLE; NS_ENSURE_ARG(aWindowTitle); if (mCert) { if (mCert->nickname) { *aWindowTitle = PL_strdup(mCert->nickname); } else { *aWindowTitle = CERT_GetCommonName(&mCert->subject); if (!*aWindowTitle) { if (mCert->subjectName) { *aWindowTitle = PL_strdup(mCert->subjectName); } else if (mCert->emailAddr) { *aWindowTitle = PL_strdup(mCert->emailAddr); } else { *aWindowTitle = PL_strdup(""); } } } } else { NS_ERROR("Somehow got nullptr for mCertificate in nsNSSCertificate."); *aWindowTitle = nullptr; } return NS_OK; }
nsresult GConfProxy::GetCharPref(const char *aMozKey, char **retval) { NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); const gchar *gconfkey = MozKey2GConfKey(aMozKey); if (!strcmp (aMozKey, "network.proxy.no_proxies_on")) { GSList *s; nsCString noproxy; GSList *gslist = GConfClientGetList(mGConfClient, gconfkey, GCONF_VALUE_STRING, NULL); for (s = gslist; s; s = g_slist_next(s)) { noproxy += (char *)s->data; noproxy += ", "; g_free ((char *)s->data); } g_slist_free (gslist); *retval = PL_strdup(noproxy.get()); } else { gchar *str = GConfClientGetString(mGConfClient, gconfkey, NULL); if (str) { *retval = PL_strdup(str); g_free (str); } } return NS_OK; }
// static void Mark(PRUint32 aType, void * aItem, const char * aText, const char * aText2) { #ifdef MOZ_VISUAL_EVENT_TRACER if (!gInitialized) return; if (aType == eNone) return; if (!CheckEventFilters(aType, aItem, aText)) // Events use just aText return; RecordBatch * threadLogPrivate = static_cast<RecordBatch *>( PR_GetThreadPrivate(gThreadPrivateIndex)); if (!threadLogPrivate) { // Deletion is made by the flushing thread threadLogPrivate = new RecordBatch(); PR_SetThreadPrivate(gThreadPrivateIndex, threadLogPrivate); } Record * record = threadLogPrivate->mNextRecord; record->mType = aType; record->mTime = (mozilla::TimeStamp::Now() - gProfilerStart).ToMilliseconds(); record->mItem = aItem; record->mText = PL_strdup(aText); record->mText2 = aText2 ? PL_strdup(aText2) : nsnull; ++threadLogPrivate->mNextRecord; if (threadLogPrivate->mNextRecord == threadLogPrivate->mRecordsTail) { // This calls RecordBatch::FlushBatch(threadLogPrivate) PR_SetThreadPrivate(gThreadPrivateIndex, nsnull); } #endif }
// Obtains all of the information currently available for this plugin. nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info) { nsresult rv = NS_ERROR_FAILURE; HMODULE hPlug = 0; // Need a HMODULE to query resource statements char failure[ CCHMAXPATH] = ""; APIRET ret; nsCAutoString path; if (NS_FAILED(rv = mPlugin->GetNativePath(path))) return rv; nsCAutoString fileName; if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName))) return rv; ret = DosLoadModule( failure, CCHMAXPATH, path.get(), &hPlug); info.fVersion = nsnull; while( ret == NO_ERROR) { info.fName = LoadRCDATAString( hPlug, NS_INFO_ProductName); info.fVersion = LoadRCDATAVersion( hPlug, NS_INFO_ProductVersion); // get description (doesn't matter if it's missing)... info.fDescription = LoadRCDATAString( hPlug, NS_INFO_FileDescription); char * mimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType); if( nsnull == mimeType) break; char * mimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName); if( nsnull == mimeDescription) break; char * extensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents); if( nsnull == extensions) break; info.fVariantCount = CalculateVariantCount(mimeType); info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType); if( info.fMimeTypeArray == nsnull) break; info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription); if( nsnull == info.fMimeDescriptionArray) break; info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions); if( nsnull == info.fExtensionArray) break; info.fFullPath = PL_strdup(path.get()); info.fFileName = PL_strdup(fileName.get()); rv = NS_OK; break; } if( 0 != hPlug) DosFreeModule( hPlug); return rv; }
char * SECU_GetModulePassword(PK11SlotInfo *slot, PRBool retry, void *arg) { #if(0) char prompt[255]; #endif secuPWData *pwdata = (secuPWData *)arg; secuPWData pwnull = { PW_NONE, 0 }; secuPWData pwxtrn = { PW_EXTERNAL, "external" }; char *pw; if (pwdata == NULL) pwdata = &pwnull; if (PK11_ProtectedAuthenticationPath(slot)) { pwdata = &pwxtrn; } if (retry && pwdata->source != PW_NONE) { PR_fprintf(PR_STDERR, "Incorrect password/PIN entered.\n"); return NULL; } switch (pwdata->source) { #if(0) case PW_NONE: sprintf(prompt, "Enter Password or Pin for \"%s\":", PK11_GetTokenName(slot)); return SECU_GetPasswordString(NULL, prompt); #endif case PW_FROMFILE: /* Instead of opening and closing the file every time, get the pw * once, then keep it in memory (duh). */ pw = SECU_FilePasswd(slot, retry, pwdata->data); pwdata->source = PW_PLAINTEXT; pwdata->data = PL_strdup(pw); /* it's already been dup'ed */ return pw; #if(0) case PW_EXTERNAL: sprintf(prompt, "Press Enter, then enter PIN for \"%s\" on external device.\n", PK11_GetTokenName(slot)); (void) SECU_GetPasswordString(NULL, prompt); /* Fall Through */ #endif case PW_PLAINTEXT: return PL_strdup(pwdata->data); default: break; } PR_fprintf(PR_STDERR, "Password check failed: No password found.\n"); return NULL; }
int nsMsgSendPart::CopyString(char** dest, const char* src) { NS_ASSERTION(src, "src null"); PR_FREEIF(*dest); if (!src) *dest = PL_strdup(""); else *dest = PL_strdup(src); return *dest? 0 : NS_ERROR_OUT_OF_MEMORY; }
SKERR SetValue(const char* pKey, const char* pValue) { char * pOldValue; if((pOldValue = (char*) PL_HashTableLookup(m_pHash, pKey))) { PL_HashTableRemove(m_pHash, pKey); } char* pHashKey = PL_strdup(pKey); char* pHashValue = PL_strdup(pValue); PL_HashTableAdd(m_pHash, pHashKey, pHashValue); return noErr; }
SKERR GetValue(const char* pKey, char **pValue) { *pValue = (char *)PL_HashTableLookup(m_pHash, pKey); if(*pValue) { *pValue = PL_strdup(*pValue); } else *pValue = PL_strdup(""); return noErr; }
void ConfigStore::Add(const char *name, const char *value) { if (IsNameDefined(name)) { PR_Lock(m_lock); PL_HashTableRemove(m_root->getSet(), name); PL_HashTableAdd(m_root->getSet(), PL_strdup(name), PL_strdup(value)); PR_Unlock(m_lock); } else { PR_Lock(m_lock); PL_HashTableAdd(m_root->getSet(), PL_strdup(name), PL_strdup(value)); PR_Unlock(m_lock); } }
/** * Constructs a base class for HttpConnection */ TPS_PUBLIC HttpConnection::HttpConnection(const char *id, ConnectionInfo *cinfo, int retries, int timeout, bool isSSL, const char *nickname, bool keepAlive, NameValueSet *headers) { m_failoverList = cinfo; m_retries = retries; m_timeout = timeout; m_Id = PL_strdup(id); m_isSSL = isSSL; m_clientnickname = PL_strdup(nickname); m_keepAlive = keepAlive; m_headers = headers; m_curr = 0; m_lock = PR_NewLock(); }
/** * Called from PL_HashTableEnumerateEntries * A pointer to a PRCList (circular linked list) is passed in. * Once enumeration is complete, the PRCList will contain a lexically * ordered list of a copy of the keys in the hash. * The caller needs to free the copies */ static PRIntn OrderLoop(PLHashEntry *he, PRIntn index, void *arg) { PRCList *qp = (PRCList *)arg; OrderedEntry_t *entry; if (he != NULL) { entry = (OrderedEntry_t *) PR_Malloc(sizeof(OrderedEntry_t)); entry->key = PL_strdup((char *) he->key); if (index ==0) { PR_APPEND_LINK((PRCList *)entry, qp); return HT_ENUMERATE_NEXT; } PRCList *head = PR_LIST_HEAD(qp); PRCList *next; while (head != qp) { OrderedEntry_t *current = (OrderedEntry_t *) head; if (strcmp((char *) he->key, (char *) current->key) <=0) break; next = PR_NEXT_LINK(head); head = next; } PR_INSERT_BEFORE((PRCList*) entry, head); return HT_ENUMERATE_NEXT; } else { return HT_ENUMERATE_STOP; } }
/* GetFolderNameWithoutNamespace takes as input a folder name in canonical form, and the namespace for the given folder. It returns an allocated string of the folder's path with the namespace string stripped out. For instance, when passed the folder Folders/a/b where the namespace is "Folders/", it will return "a/b". Similarly, if the folder name is "#news/comp/mail/imap" in canonical form, with a real delimiter of "." and a namespace of "#news.", it will return "comp/mail/imap". The return value is always in canonical form. */ char* nsIMAPNamespaceList::GetFolderNameWithoutNamespace(nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName) { NS_ASSERTION(canonicalFolderName, "null folder name"); #ifdef DEBUG NS_ASSERTION(namespaceForFolder || !PL_strcasecmp(canonicalFolderName, "INBOX"), "need namespace or INBOX"); #endif char *retFolderName = nullptr; if (!PL_strcasecmp(canonicalFolderName, "INBOX")) return PL_strdup(canonicalFolderName); // convert the canonical path to the online path char *convertedFolderName = nsIMAPNamespaceList::AllocateServerFolderName(canonicalFolderName, namespaceForFolder->GetDelimiter()); if (convertedFolderName) { char *beginFolderPath = nullptr; if (strlen(convertedFolderName) <= strlen(namespaceForFolder->GetPrefix())) beginFolderPath = convertedFolderName; else beginFolderPath = convertedFolderName + strlen(namespaceForFolder->GetPrefix()); NS_ASSERTION(beginFolderPath, "empty folder path"); retFolderName = nsIMAPNamespaceList::AllocateCanonicalFolderName(beginFolderPath, namespaceForFolder->GetDelimiter()); PR_Free(convertedFolderName); } NS_ASSERTION(retFolderName, "returning null folder name"); return retFolderName; }
char *passwdcb(PK11SlotInfo *info, PRBool retry, void *arg) { if (!retry) return PL_strdup("test"); else return NULL; }
ConfigStore::ConfigStore(ConfigStoreRoot* root, const char *subStoreName) { m_substore_name = PL_strdup(subStoreName); m_root = root; root->addref(); m_lock = PR_NewLock(); }
void PoisonWrite() { // Quick sanity check that we don't poison twice. static bool WritesArePoisoned = false; MOZ_ASSERT(!WritesArePoisoned); if (WritesArePoisoned) return; WritesArePoisoned = true; if (PoisoningDisabled) return; nsCOMPtr<nsIFile> mozFile; NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile)); if (mozFile) { nsAutoCString nativePath; nsresult rv = mozFile->GetNativePath(nativePath); if (NS_SUCCEEDED(rv)) { sProfileDirectory = PL_strdup(nativePath.get()); } } OldCleanup = __cleanup; __cleanup = FinalCleanup; for (int i = 0; i < NumFunctions; ++i) { FuncData *d = Functions[i]; if (!d->Function) d->Function = dlsym(RTLD_DEFAULT, d->Name); if (!d->Function) continue; mach_error_t t = mach_override_ptr(d->Function, d->Wrapper, &d->Buffer); MOZ_ASSERT(t == err_none); } }
void nsIMAPGenericParser::AdvanceToNextToken() { if (!fCurrentLine || fAtEndOfLine) AdvanceToNextLine(); if (Connected()) { if (!fStartOfLineOfTokens) { // this is the first token of the line; setup tokenizer now fStartOfLineOfTokens = PL_strdup(fCurrentLine); if (!fStartOfLineOfTokens) { HandleMemoryFailure(); return; } fLineOfTokens = fStartOfLineOfTokens; fCurrentTokenPlaceHolder = fStartOfLineOfTokens; } fNextToken = NS_strtok(WHITESPACE, &fCurrentTokenPlaceHolder); if (!fNextToken) { fAtEndOfLine = true; fNextToken = CRLF; } } }
// Create an atom // This function does not advance the parser. // Call AdvanceToNextToken() to get the next token after the atom. // RFC3501: atom = 1*ATOM-CHAR // ASTRING-CHAR = ATOM-CHAR / resp-specials // ATOM-CHAR = <any CHAR except atom-specials> // atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / // quoted-specials / resp-specials // list-wildcards = "%" / "*" // quoted-specials = DQUOTE / "\" // resp-specials = "]" // "Characters are 7-bit US-ASCII unless otherwise specified." [RFC3501, 1.2.] char *nsIMAPGenericParser::CreateAtom(bool isAstring) { char *rv = PL_strdup(fNextToken); if (!rv) { HandleMemoryFailure(); return nsnull; } // We wish to stop at the following characters (in decimal ascii) // 1-31 (CTL), 32 (SP), 34 '"', 37 '%', 40-42 "()*", 92 '\\', 123 '{' // also, ']' is only allowed in astrings char *last = rv; char c = *last; while ((c > 42 || c == 33 || c == 35 || c == 36 || c == 38 || c == 39) && c != '\\' && c != '{' && (isAstring || c != ']')) c = *++last; if (rv == last) { SetSyntaxError(true, "no atom characters found"); PL_strfree(rv); return nsnull; } if (*last) { // not the whole token was consumed *last = '\0'; AdvanceTokenizerStartingPoint((fNextToken - fLineOfTokens) + (last-rv)); } return rv; }
BloatEntry(const char* className, uint32_t classSize) : mClassSize(classSize) { mClassName = PL_strdup(className); Clear(&mNewStats); Clear(&mAllStats); mTotalLeaked = 0; }
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner) : mTarget(PL_strdup(target)), mOwner(owner) { nsresult rv; nsCOMPtr<nsIFile> pluginTmp; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) return; mTempFile = do_QueryInterface(pluginTmp, &rv); if (NS_FAILED(rv)) return; // need to create a file with a unique name - use target as the basis rv = mTempFile->AppendNative(nsDependentCString(target)); if (NS_FAILED(rv)) return; // Yes, make it unique. rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0700); if (NS_FAILED(rv)) return; // create the file rv = NS_NewLocalFileOutputStream(getter_AddRefs(mOutputStream), mTempFile, -1, 00600); if (NS_FAILED(rv)) return; // construct the URL we'll use later in calls to GetURL() NS_GetURLSpecFromFile(mTempFile, mFileURL); #ifdef DEBUG printf("File URL = %s\n", mFileURL.get()); #endif }
// Caller is responsible for freeing returned buffer. static char* CFStringRefToUTF8Buffer(CFStringRef cfString) { const char* buffer = ::CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8); if (buffer) { return PL_strdup(buffer); } int bufferLength = ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString), kCFStringEncodingUTF8) + 1; char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength)); if (!newBuffer) { return nullptr; } if (!::CFStringGetCString(cfString, newBuffer, bufferLength, kCFStringEncodingUTF8)) { NS_Free(newBuffer); return nullptr; } newBuffer = static_cast<char*>(NS_Realloc(newBuffer, PL_strlen(newBuffer) + 1)); return newBuffer; }
// Assumption: attribute pairs in the string are separated by '&'. char * extractAttributeValue(const char * searchString, const char * attributeName) { char * attributeValue = nullptr; if (searchString && attributeName) { // search the string for attributeName uint32_t attributeNameSize = PL_strlen(attributeName); char * startOfAttribute = PL_strcasestr(searchString, attributeName); if (startOfAttribute) { startOfAttribute += attributeNameSize; // skip over the attributeName if (startOfAttribute) // is there something after the attribute name { char * endOfAttribute = startOfAttribute ? PL_strchr(startOfAttribute, '&') : nullptr; nsDependentCString attributeValueStr; if (startOfAttribute && endOfAttribute) // is there text after attribute value attributeValueStr.Assign(startOfAttribute, endOfAttribute - startOfAttribute); else // there is nothing left so eat up rest of line. attributeValueStr.Assign(startOfAttribute); // now unescape the string... nsCString unescapedValue; MsgUnescapeString(attributeValueStr, 0, unescapedValue); attributeValue = PL_strdup(unescapedValue.get()); } // if we have a attribute value } // if we have a attribute name } // if we got non-null search string and attribute name values return attributeValue; }
NS_METHOD LocalSearchDataSource::parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens) { const char *uri = nsnull; char *id, *token, *value, *newstr; int loop; nsresult rv; if (NS_FAILED(rv = u->GetValueConst(&uri))) return(rv); #ifdef DEBUG printf("Find: %s\n", (const char*) uri); #endif if (!(id = PL_strdup(uri + sizeof(kFindProtocol) - 1))) return(NS_ERROR_OUT_OF_MEMORY); /* parse ID, build up token list */ if ((token = nsCRT::strtok(id, "&", &newstr)) != NULL) { while (token != NULL) { if ((value = strstr(token, "=")) != NULL) { *value++ = '\0'; } for (loop=0; tokens[loop].token != NULL; loop++) { if (!strcmp(token, tokens[loop].token)) { if (!strcmp(token, "text")) { nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(kTextToSubURICID, &rv); if (NS_SUCCEEDED(rv) && (textToSubURI)) { PRUnichar *uni = nsnull; if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", value, &uni)) && (uni)) { tokens[loop].value = uni; Recycle(uni); } } } else { nsAutoString valueStr; valueStr.AssignWithConversion(value); tokens[loop].value = valueStr; } break; } } token = nsCRT::strtok(newstr, "&", &newstr); } } PL_strfree(id); return(NS_OK); }
BloatEntry(const char* aClassName, uint32_t aClassSize) : mClassSize(aClassSize) { MOZ_ASSERT(strlen(aClassName) > 0, "BloatEntry name must be non-empty"); mClassName = PL_strdup(aClassName); mStats.Clear(); mTotalLeaked = 0; }
void nsImapSearchResultSequence::AddSearchResultLine(const char *searchLine) { // The first add becomes node 2. Fix this. char *copiedSequence = PL_strdup(searchLine + 9); // 9 == "* SEARCH " if (copiedSequence) // if we can't allocate this then the search won't hit AppendElement(copiedSequence); }
char *getCString(VObject *vObj) { if (VALUE_TYPE(vObj) == VCVT_USTRINGZ) return fakeCString(vObjectUStringZValue(vObj)); if (VALUE_TYPE(vObj) == VCVT_STRINGZ) return PL_strdup(vObjectStringZValue(vObj)); return NULL; }
SKERR SKIndex::SetOperators(const char* pszOperators) { if(m_pszOperators) PL_strfree(m_pszOperators); m_pszOperators = PL_strdup(pszOperators); ::SetOperators(m_pszOperators); return noErr; }
nsresult nsNPAPIPluginStreamListener::OnStartBinding(nsPluginStreamListenerPeer* streamPeer) { if (!mInst || !mInst->CanFireNotifications() || mStreamCleanedUp) return NS_ERROR_FAILURE; PluginDestructionGuard guard(mInst); nsNPAPIPlugin* plugin = mInst->GetPlugin(); if (!plugin || !plugin->GetLibrary()) return NS_ERROR_FAILURE; NPPluginFuncs* pluginFunctions = plugin->PluginFuncs(); if (!pluginFunctions->newstream) return NS_ERROR_FAILURE; NPP npp; mInst->GetNPP(&npp); bool seekable; char* contentType; uint16_t streamType = NP_NORMAL; NPError error; streamPeer->GetURL(&mNPStreamWrapper->mNPStream.url); streamPeer->GetLength((uint32_t*)&(mNPStreamWrapper->mNPStream.end)); streamPeer->GetLastModified((uint32_t*)&(mNPStreamWrapper->mNPStream.lastmodified)); streamPeer->IsSeekable(&seekable); streamPeer->GetContentType(&contentType); if (!mResponseHeaders.IsEmpty()) { mResponseHeaderBuf = PL_strdup(mResponseHeaders.get()); mNPStreamWrapper->mNPStream.headers = mResponseHeaderBuf; } mStreamListenerPeer = streamPeer; NPPAutoPusher nppPusher(npp); NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->newstream)(npp, (char*)contentType, &mNPStreamWrapper->mNPStream, seekable, &streamType), mInst, NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO); NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPP NewStream called: this=%p, npp=%p, mime=%s, seek=%d, type=%d, return=%d, url=%s\n", this, npp, (char *)contentType, seekable, streamType, error, mNPStreamWrapper->mNPStream.url)); if (error != NPERR_NO_ERROR) return NS_ERROR_FAILURE; if (streamType == nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN) { SuspendRequest(); } else if (!SetStreamType(streamType, false)) { return NS_ERROR_FAILURE; } return NS_OK; }