tdf#106359: use SvFileStream to read iqy; fixes *nix compatibility
Change-Id: I42dc6559a57eaedcc64d2a4e59e16677b9dfeb1c Reviewed-on: https://gerrit.libreoffice.org/39862 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
#include <svl/documentlockfile.hxx>
|
#include <svl/documentlockfile.hxx>
|
||||||
|
|
||||||
#include <ucbhelper/content.hxx>
|
|
||||||
#include <rtl/strbuf.hxx>
|
#include <rtl/strbuf.hxx>
|
||||||
#include <osl/file.hxx>
|
#include <osl/file.hxx>
|
||||||
|
|
||||||
@@ -170,14 +169,14 @@ CommandLineEvent CheckOfficeURI(/* in,out */ OUString& arg, CommandLineEvent cur
|
|||||||
|
|
||||||
// Skip single newline (be it *NIX LF, MacOS CR, of Win CRLF)
|
// Skip single newline (be it *NIX LF, MacOS CR, of Win CRLF)
|
||||||
// Changes the offset, and returns true if moved
|
// Changes the offset, and returns true if moved
|
||||||
bool SkipNewline(const char* pStr, sal_Int32& rOffset)
|
bool SkipNewline(const char* & pStr)
|
||||||
{
|
{
|
||||||
if ((pStr[rOffset] != '\r') && (pStr[rOffset] != '\n'))
|
if ((*pStr != '\r') && (*pStr != '\n'))
|
||||||
return false;
|
return false;
|
||||||
if (pStr[rOffset] == '\r')
|
if (*pStr == '\r')
|
||||||
++rOffset;
|
++pStr;
|
||||||
if (pStr[rOffset] == '\n')
|
if (*pStr == '\n')
|
||||||
++rOffset;
|
++pStr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,52 +193,43 @@ CommandLineEvent CheckWebQuery(/* in,out */ OUString& arg, CommandLineEvent curE
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
OUString sFileURL;
|
OUString sFileURL;
|
||||||
|
// Cannot use translateExternalUris yet, because process service factory is not yet available
|
||||||
if (osl::FileBase::getFileURLFromSystemPath(arg, sFileURL) != osl::FileBase::RC::E_None)
|
if (osl::FileBase::getFileURLFromSystemPath(arg, sFileURL) != osl::FileBase::RC::E_None)
|
||||||
return curEvt;
|
return curEvt;
|
||||||
css::uno::Reference < css::ucb::XCommandEnvironment > xEnv;
|
SvFileStream stream(sFileURL, StreamMode::READ);
|
||||||
ucbhelper::Content aSourceContent(sFileURL, xEnv, comphelper::getProcessComponentContext());
|
|
||||||
|
|
||||||
// the file can be opened readonly, no locking will be done
|
|
||||||
css::uno::Reference< css::io::XInputStream > xInput = aSourceContent.openStream();
|
|
||||||
if (!xInput.is())
|
|
||||||
return curEvt;
|
|
||||||
|
|
||||||
const sal_Int32 nBufLen = 32000;
|
const sal_Int32 nBufLen = 32000;
|
||||||
css::uno::Sequence< sal_Int8 > aBuffer(nBufLen);
|
char sBuffer[nBufLen];
|
||||||
sal_Int32 nRead = xInput->readBytes(aBuffer, nBufLen);
|
size_t nRead = stream.ReadBytes(sBuffer, nBufLen);
|
||||||
if (nRead < 8) // WEB\n1\n...
|
if (nRead < 8) // WEB\n1\n...
|
||||||
return curEvt;
|
return curEvt;
|
||||||
|
|
||||||
const char* sBuf = reinterpret_cast<const char*>(aBuffer.getConstArray());
|
const char* pPos = sBuffer;
|
||||||
sal_Int32 nOffset = 0;
|
if (strncmp(pPos, "WEB", 3) != 0)
|
||||||
if (strncmp(sBuf+nOffset, "WEB", 3) != 0)
|
|
||||||
return curEvt;
|
return curEvt;
|
||||||
nOffset += 3;
|
pPos += 3;
|
||||||
if (!SkipNewline(sBuf, nOffset))
|
if (!SkipNewline(pPos))
|
||||||
return curEvt;
|
return curEvt;
|
||||||
if (sBuf[nOffset] != '1')
|
if (*pPos != '1')
|
||||||
return curEvt;
|
return curEvt;
|
||||||
++nOffset;
|
++pPos;
|
||||||
if (!SkipNewline(sBuf, nOffset))
|
if (!SkipNewline(pPos))
|
||||||
return curEvt;
|
return curEvt;
|
||||||
|
|
||||||
rtl::OStringBuffer aResult(nRead);
|
rtl::OStringBuffer aResult(static_cast<unsigned int>(nRead));
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// xInput->readBytes() can relocate buffer
|
const char* pPos1 = pPos;
|
||||||
sBuf = reinterpret_cast<const char*>(aBuffer.getConstArray());
|
const char* pEnd = sBuffer + nRead;
|
||||||
const char* sPos = sBuf + nOffset;
|
while ((pPos1 < pEnd) && (*pPos1 != '\r') && (*pPos1 != '\n'))
|
||||||
const char* sPos1 = sPos;
|
++pPos1;
|
||||||
const char* sEnd = sBuf + nRead;
|
aResult.append(pPos, pPos1 - pPos);
|
||||||
while ((sPos1 < sEnd) && (*sPos1 != '\r') && (*sPos1 != '\n'))
|
if (pPos1 < pEnd) // newline
|
||||||
++sPos1;
|
|
||||||
aResult.append(sPos, sPos1 - sPos);
|
|
||||||
if (sPos1 < sEnd) // newline
|
|
||||||
break;
|
break;
|
||||||
nOffset = 0;
|
pPos = sBuffer;
|
||||||
} while ((nRead = xInput->readBytes(aBuffer, nBufLen)) > 0);
|
} while ((nRead = stream.ReadBytes(sBuffer, nBufLen)) > 0);
|
||||||
|
|
||||||
xInput->closeInput();
|
stream.Close();
|
||||||
|
|
||||||
arg = OUString::createFromAscii(aResult.getStr());
|
arg = OUString::createFromAscii(aResult.getStr());
|
||||||
return CommandLineEvent::ForceNew;
|
return CommandLineEvent::ForceNew;
|
||||||
|
Reference in New Issue
Block a user