26#include <com/sun/star/beans/PropertyAttribute.hpp>
50#include <com/sun/star/lang/IllegalAccessException.hpp>
51#include <com/sun/star/lang/NoSupportException.hpp>
52#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
53#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
54#include <com/sun/star/beans/IllegalTypeException.hpp>
55#include <com/sun/star/beans/UnknownPropertyException.hpp>
56#include <com/sun/star/beans/Property.hpp>
57#include <com/sun/star/ucb/XCommandInfo.hpp>
58#include <com/sun/star/io/BufferSizeExceededException.hpp>
59#include <com/sun/star/io/IOException.hpp>
60#include <com/sun/star/io/NotConnectedException.hpp>
61#include <com/sun/star/io/XActiveDataSink.hpp>
62#include <com/sun/star/io/XOutputStream.hpp>
63#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
64#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
65#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
66#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
67#include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
68#include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
69#include <com/sun/star/ucb/InteractiveIOException.hpp>
70#include <com/sun/star/ucb/MissingPropertiesException.hpp>
71#include <com/sun/star/ucb/MissingInputStreamException.hpp>
72#include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
73#include <com/sun/star/ucb/OpenMode.hpp>
74#include <com/sun/star/ucb/IOErrorCode.hpp>
93 : ContentImplHelper(rxContext,pProvider,
Identifier)
105 : ContentImplHelper(rxContext,pProvider,
Identifier)
107 , m_aFTPURL(
Identifier->getContentIdentifier(), pProvider)
114FTPContent::~FTPContent()
123 OWeakObject::acquire();
129 OWeakObject::release();
135 static_cast< XTypeProvider*
>(
this),
136 static_cast< XServiceInfo*
>(
this),
137 static_cast< XContent*
>(
this),
138 static_cast< XCommandProcessor*
>(
this),
139 static_cast< XContentCreator*
>(
this),
140 static_cast< XChild*
>(
this)
142 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
149 return css::uno::Sequence<sal_Int8>();
171 return "com.sun.star.comp.FTPContent";
181 return {
"com.sun.star.ucb.FTPContent" };
204 std::vector<FTPDirentry>&& dirvec)
206 m_xProvider(xProvider),
208 m_dirvec(
std::move(dirvec))
226enum ACTION { NOACTION,
227 THROWAUTHENTICATIONREQUEST,
229 THROWINTERACTIVECONNECT,
242 XCommandEnvironment >& Environment)
251 if(
action == THROWAUTHENTICATIONREQUEST)
254 OUString aPassword,aAccount;
275 xInteractionHandler =
278 if( xInteractionHandler.is()) {
279 xInteractionHandler->handle(
p);
285 xSelection,UNO_QUERY).is())
288 xSelection,UNO_QUERY).is()) {
293 p->getAuthenticationSupplier()->getPassword(),
298 aRet =
p->getRequest();
321 case THROWAUTHENTICATIONREQUEST:
327 case THROWACCESSDENIED:
334 IOErrorCode_ACCESS_DENIED,
339 case THROWINTERACTIVECONNECT:
341 InteractiveNetworkConnectException excep;
351 IllegalIdentifierException
ex;
358 case THROWRESOLVENAME:
360 InteractiveNetworkResolveNameException excep;
389 if(
aCommand.Name ==
"getPropertyValues") {
393 aRet <<= IllegalArgumentException(
394 "Wrong argument type!",
402 else if(
aCommand.Name ==
"setPropertyValues")
406 if( ! (
aCommand.Argument >>= propertyValues ) ) {
407 aRet <<= IllegalArgumentException(
408 "Wrong argument type!",
416 else if(
aCommand.Name ==
"getCommandInfo") {
420 else if(
aCommand.Name ==
"getPropertySetInfo") {
426 InsertCommandArgument aInsertArgument;
427 if ( ! (
aCommand.Argument >>= aInsertArgument ) ) {
428 aRet <<= IllegalArgumentException(
429 "Wrong argument type!",
436 else if(
aCommand.Name ==
"delete") {
441 OpenCommandArgument2 aOpenCommand;
442 if ( !(
aCommand.Argument >>= aOpenCommand ) ) {
443 aRet <<= IllegalArgumentException(
444 "Wrong argument type!",
454 xActiveDataSink(aOpenCommand.Sink,UNO_QUERY);
456 xOutputStream(aOpenCommand.Sink,UNO_QUERY);
458 if(xActiveDataSink.is()) {
459 xActiveDataSink->setInputStream(
462 else if(xOutputStream.is()) {
467 sal_Int32
n =
xStream->readBytes(byte_seq, 4096);
472 if(byte_seq.getLength() !=
n)
474 xOutputStream->writeBytes(byte_seq);
475 }
catch(
const NotConnectedException&) {
477 }
catch(
const BufferSizeExceededException&) {
485 aRet <<= UnsupportedDataSinkException(
492 else if(aOpenCommand.Mode == OpenMode::ALL ||
493 aOpenCommand.Mode == OpenMode::DOCUMENTS ||
494 aOpenCommand.Mode == OpenMode::FOLDERS ) {
495 std::vector<FTPDirentry> resvec =
501 std::make_unique<ResultSetFactory>(
m_xContext,
503 aOpenCommand.Properties,
507 else if(aOpenCommand.Mode ==
508 OpenMode::DOCUMENT_SHARE_DENY_NONE ||
510 OpenMode::DOCUMENT_SHARE_DENY_WRITE) {
512 aRet <<= UnsupportedOpenModeException(
515 static_cast< sal_Int16
>(aOpenCommand.Mode));
519 aRet <<= IllegalArgumentException(
520 "Unexpected OpenMode!",
526 }
else if(
aCommand.Name ==
"createNewContent") {
528 if (!(
aCommand.Argument >>= aArg)) {
531 IllegalArgumentException(
532 "Wrong argument type!",
540 aRet <<= UnsupportedCommandException(
550 if(e.
code() == CURLE_COULDNT_CONNECT)
551 action = THROWINTERACTIVECONNECT;
552 else if (e.
code() == CURLE_URL_MALFORMAT)
556 else if(e.
code() == CURLE_COULDNT_RESOLVE_HOST )
557 action = THROWRESOLVENAME;
558 else if(e.
code() == CURLE_FTP_USER_PASSWORD_INCORRECT ||
559 e.
code() == CURLE_LOGIN_DENIED ||
560 e.
code() == CURLE_BAD_PASSWORD_ENTERED ||
561 e.
code() == CURLE_FTP_WEIRD_PASS_REPLY)
562 action = THROWAUTHENTICATIONREQUEST;
563 else if(e.
code() == CURLE_FTP_ACCESS_DENIED)
564 action = THROWACCESSDENIED;
565 else if(e.
code() == CURLE_FTP_QUOTE_ERROR)
567 else if(e.
code() == CURLE_FTP_COULDNT_RETR_FILE)
576constexpr OUStringLiteral
FTP_FILE =
u"application/vnd.sun.staroffice.ftp-file";
578constexpr OUStringLiteral
FTP_FOLDER =
u"application/vnd.sun.staroffice.ftp-folder";
594 PropertyAttribute::MAYBEVOID
595 | PropertyAttribute::BOUND ) };
598 {
FTP_FILE, ContentInfoAttribute::INSERT_WITH_INPUTSTREAM | ContentInfoAttribute::KIND_DOCUMENT,
props },
606 if(
Info.Type ==
"application/vnd.sun.staroffice.ftp-file" ||
Info.Type ==
"application/vnd.sun.staroffice.ftp-folder" )
627 throw NoSupportException();
644 : m_xInputStream(xInputStream) { }
645 virtual ~InsertData() {}
648 virtual sal_Int32 read(
sal_Int8 *dest,sal_Int32 nBytesRequested)
override;
657sal_Int32 InsertData::read(
sal_Int8 *dest,sal_Int32 nBytesRequested)
661 if(m_xInputStream.is()) {
663 m = m_xInputStream->readBytes(seq,nBytesRequested);
664 memcpy(dest,seq.getConstArray(),m);
676 MissingPropertiesException excep;
677 excep.Properties = {
"Title" };
683 !aInsertCommand.Data.is())
685 MissingInputStreamException excep;
689 bool bReplace(aInsertCommand.ReplaceExisting);
694 InsertData data(aInsertCommand.Data);
704 xInt =
Env->getInteractionHandler();
706 UnsupportedNameClashException excep;
743 for(
const auto& rProp : seqProp) {
744 const OUString&
Name = rProp.Name;
746 xRow->appendString(rProp,aDirEntry.
m_aName);
747 else if(
Name ==
"CreatableContentsInfo")
748 xRow->appendObject(rProp,
751 if(
Name ==
"ContentType")
752 xRow->appendString(rProp,
756 else if(
Name ==
"IsReadOnly")
757 xRow->appendBoolean(rProp,
760 else if(
Name ==
"IsDocument")
761 xRow->appendBoolean(rProp,
764 else if(
Name ==
"IsFolder")
765 xRow->appendBoolean(rProp,
768 else if(
Name ==
"Size")
769 xRow->appendLong(rProp,
771 else if(
Name ==
"DateCreated")
772 xRow->appendTimestamp(rProp,
775 xRow->appendVoid(rProp);
777 xRow->appendVoid(rProp);
788 auto retRange = asNonConstRange(ret);
792 for(sal_Int32
i = 0;
i < ret.getLength(); ++
i) {
793 if ( seqPropVal[
i].
Name ==
"Title" ) {
796 retRange[
i] <<= IllegalTypeException();
798 }
else if(
Title.isEmpty()) {
799 retRange[
i] <<= IllegalArgumentException();
818 InteractiveIOException excep;
821 excep.Code = IOErrorCode_ACCESS_DENIED;
822 retRange[
i] <<= excep;
829 retRange[
i] <<= UnknownPropertyException();
830 const auto& rName = seqPropVal[
i].Name;
831 auto pProp = std::find_if(
props.begin(),
props.end(),
832 [&rName](
const Property& rProp) { return rProp.Name == rName; });
833 if (pProp !=
props.end()) {
834 retRange[
i] <<= IllegalAccessException(
835 "Property is read-only!",
844 if(evt.hasElements()) {
Reference< XComponentContext > m_xContext
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
void forHost(std::u16string_view host, std::u16string_view port, std::u16string_view username, OUString &password, OUString &account)
host is in the form host:port.
bool setHost(const OUString &host, const OUString &port, const OUString &username, const OUString &password, const OUString &account)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &seqPropVal)
FTPContentProvider * m_pFCP
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL release() noexcept override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
css::ucb::ContentInfo m_aInfo
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
static css::uno::Sequence< css::ucb::ContentInfo > queryCreatableContentsInfo_Static()
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual OUString SAL_CALL getContentType() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
FTPContent(const css::uno::Reference< css::uno::XComponentContext > &rxContext, FTPContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, const FTPURL &FtpUrl)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
void insert(const css::ucb::InsertCommandArgument &, const css::uno::Reference< css::ucb::XCommandEnvironment > &)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &seqProp)
virtual OUString getParentURL() override
virtual void SAL_CALL abort(sal_Int32 CommandId) override
void insert(bool ReplaceExisting, void *stream) const
const OUString & port() const
OUString parent(bool internal=false) const
returns the parent url.
FTPDirentry direntry() const
std::vector< FTPDirentry > list(sal_Int16 nMode) const
const OUString & username() const
OUString ren(const OUString &NewTitle)
const OUString & host() const
OUString ident(bool withslash, bool internal) const
This returns the URL, but cleaned from unnecessary ellipses.
void mkdir(bool ReplaceExisting) const
void child(const OUString &title)
sets the unencoded title
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
ResultSetFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::ucb::XContentProvider > &xProvider, const css::uno::Sequence< css::beans::Property > &seq, std::vector< FTPDirentry > &&dirvec)
std::vector< FTPDirentry > m_dirvec
css::uno::Sequence< css::beans::Property > m_seq
rtl::Reference< ResultSetBase > createResultSet()
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::task::XInteractionRequest > const & getRequest() const
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
rtl::Reference< ContentProviderImplHelper > m_xProvider
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
css::uno::Reference< css::uno::XComponentContext > m_xContext
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
constexpr OUStringLiteral FTP_FOLDER
constexpr OUStringLiteral FTP_FILE
constexpr OUStringLiteral FTP_CONTENT_TYPE
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Definition of ftpcontentprovider.
@ FOLDER_MIGHT_EXIST_DURING_INSERT
@ FILE_MIGHT_EXIST_DURING_INSERT
@ INETCOREFTP_FILEMODE_ISDIR
@ INETCOREFTP_FILEMODE_UNKNOWN
@ INETCOREFTP_FILEMODE_WRITE
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)