fix 130080 [Signing Acrobat doesn't work] r=peterl, sr=darin

This commit is contained in:
serge%netscape.com 2002-04-25 21:28:06 +00:00
Родитель 8bf4676d16
Коммит e1f1159d4a
2 изменённых файлов: 72 добавлений и 31 удалений

Просмотреть файл

@ -147,7 +147,8 @@ NS_NewPluginPostDataStream(nsIInputStream **result,
file,
PR_RDONLY,
0600,
nsIFileInputStream::DELETE_ON_CLOSE))
nsIFileInputStream::DELETE_ON_CLOSE |
nsIFileInputStream::CLOSE_ON_EOF))
)
{
// wrap the file stream with a buffered input stream

Просмотреть файл

@ -5853,14 +5853,15 @@ nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURI* aURL,
nsIPluginInstanceOwner *aOwner,
nsIPluginInstance* aInstance)
{
if (!aURL)
return NS_OK;
nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
if (listener == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (!aURL)
return NS_OK;
// if we have an instance, everything has been set up
// if we only have an owner, then we need to pass it in
@ -5884,6 +5885,9 @@ nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURI* aURL,
}
}
rv = NS_OpenURI(listener, nsnull, aURL, nsnull, loadGroup);
// delete listener, don't leak it
if (NS_FAILED(rv))
delete listener;
}
//NS_RELEASE(aURL);
@ -6329,6 +6333,7 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders(
return NS_ERROR_FAILURE;
}
p += headersLen;
newBufferLen = headersLen + dataLen;
}
// at this point we've done with headers.
// there is a possibility that input buffer has only headers info in it
@ -6352,29 +6357,49 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
PRInt64 fileSize;
nsXPIDLCString filename;
// stat file == get size & convert file:///c:/ to c: if needed
nsCOMPtr<nsILocalFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
nsCOMPtr<nsILocalFile> inFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv) ||
(NS_FAILED(rv = NS_InitFileFromURLSpec(file, nsDependentCString(postDataURL))) &&
NS_FAILED(rv = file->InitWithPath(postDataURL))) ||
NS_FAILED(rv = file->GetFileSize(&fileSize)) ||
NS_FAILED(rv = file->GetPath(getter_Copies(filename)))
(NS_FAILED(rv = NS_InitFileFromURLSpec(inFile, nsDependentCString(postDataURL))) &&
NS_FAILED(rv = inFile->InitWithPath(postDataURL))) ||
NS_FAILED(rv = inFile->GetFileSize(&fileSize)) ||
NS_FAILED(rv = inFile->GetPath(getter_Copies(filename)))
)
return rv;
if (!LL_IS_ZERO(fileSize)) {
nsCOMPtr<nsIInputStream> inStream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream), file);
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream), inFile);
if (NS_FAILED(rv)) return rv;
// Create a temporary file to write the http Content-length: %ld\r\n\" header
// and "\r\n" == end of headers for post data to
nsCOMPtr<nsIFile> tempFile;
nsresult rv;
rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempFile));
if (tempFile) {
tempFile->Append("pluginpost");
// mode is 0600 so that it's not world-readable
rv = tempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
}
if (NS_FAILED(rv))
return rv;
rv = tempFile->Append(kPluginTmpDirName);
if (NS_FAILED(rv))
return rv;
PRBool dirExists;
tempFile->Exists(&dirExists);
if (!dirExists)
(void) tempFile->Create(nsIFile::DIRECTORY_TYPE, 0600);
nsXPIDLCString inFileName;
inFile->GetLeafName(getter_Copies(inFileName));
nsCAutoString tempFileName("post-");
tempFileName += inFileName;
rv = tempFile->Append(tempFileName.get());
if (NS_FAILED(rv))
return rv;
// make it unique, and mode == 0600, not world-readable
rv = tempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIOutputStream> outStream;
if (NS_SUCCEEDED(rv)) {
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStream),
@ -6383,32 +6408,47 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa
0600); // 600 so others can't read our form data
}
NS_ASSERTION(NS_SUCCEEDED(rv), "Post data file couldn't be created!");
if (NS_FAILED(rv)) return rv;
PRInt32 contentLen = nsInt64(fileSize);
char p[128];
sprintf(p, "Content-length: %ld\r\n\r\n",contentLen);
PRUint32 bw = 0, br= 0;
rv = outStream->Write(p, bw = PL_strlen(p), &br) ||
bw != br ? NS_ERROR_FAILURE : NS_OK;
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write Post data into tmp file!");
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv))
return rv;
char buf[1024];
PRUint32 br, bw;
PRBool firstRead = PR_TRUE;
while (1) {
// Read() mallocs if buffer is null
rv = inStream->Read(buf, 1024, &br);
if (NS_FAILED(rv) || (PRInt32)br <= 0) break;
if (NS_FAILED(rv) || (PRInt32)br <= 0)
break;
if (firstRead) {
// according to the 4.x spec
// http://developer.netscape.com/docs/manuals/communicator/plugin/pgfn2.htm#1007707
//"For protocols in which the headers must be distinguished from the body,
// such as HTTP, the buffer or file should contain the headers, followed by
// a blank line, then the body. If no custom headers are required, simply
// add a blank line ('\n') to the beginning of the file or buffer.
char *parsedBuf;
// assuming first 1K (or what we got) has all headers in,
// lets parse it through nsPluginHostImpl::ParsePostBufferToFixHeaders()
ParsePostBufferToFixHeaders((const char *)buf, br, &parsedBuf, &bw);
rv = outStream->Write(parsedBuf, bw, &br);
nsMemory::Free(parsedBuf);
if (NS_FAILED(rv) || (bw != br))
break;
firstRead = PR_FALSE;
continue;
}
bw = br;
rv = outStream->Write(buf, bw, &br);
if (NS_FAILED(rv) || (bw != br)) break;
if (NS_FAILED(rv) || (bw != br))
break;
}
inStream->Close();
outStream->Close();
if (NS_SUCCEEDED(rv)) {
nsXPIDLCString tempFileName;
tempFile->GetPath(getter_Copies(tempFileName));
*pTmpFileName = PL_strdup(tempFileName);
tempFile->GetPath(pTmpFileName);
}
}
return rv;