26 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/lang/IllegalAccessException.hpp>
50 #include <com/sun/star/lang/NoSupportException.hpp>
51 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
52 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
53 #include <com/sun/star/beans/IllegalTypeException.hpp>
54 #include <com/sun/star/beans/UnknownPropertyException.hpp>
55 #include <com/sun/star/beans/Property.hpp>
56 #include <com/sun/star/ucb/XCommandInfo.hpp>
57 #include <com/sun/star/io/BufferSizeExceededException.hpp>
58 #include <com/sun/star/io/IOException.hpp>
59 #include <com/sun/star/io/NotConnectedException.hpp>
60 #include <com/sun/star/io/XActiveDataSink.hpp>
61 #include <com/sun/star/io/XOutputStream.hpp>
62 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
63 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
64 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
65 #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
66 #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
67 #include <com/sun/star/ucb/InteractiveIOException.hpp>
68 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
69 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
70 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
71 #include <com/sun/star/ucb/OpenMode.hpp>
72 #include <com/sun/star/ucb/IOErrorCode.hpp>
91 : ContentImplHelper(rxContext,pProvider,Identifier)
103 : ContentImplHelper(rxContext,pProvider,Identifier)
105 , m_aFTPURL(Identifier->getContentIdentifier(), pProvider)
121 OWeakObject::acquire();
127 OWeakObject::release();
133 static_cast< XTypeProvider* >(
this),
134 static_cast< XServiceInfo* >(
this),
135 static_cast< XContent* >(
this),
136 static_cast< XCommandProcessor* >(
this),
137 static_cast< XContentCreator* >(
this),
138 static_cast< XChild* >(
this)
140 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
147 return css::uno::Sequence<sal_Int8>();
169 return "com.sun.star.comp.FTPContent";
179 return {
"com.sun.star.ucb.FTPContent" };
202 std::vector<FTPDirentry>&& dirvec)
204 m_xProvider(xProvider),
206 m_dirvec(
std::move(dirvec))
225 THROWAUTHENTICATIONREQUEST,
227 THROWINTERACTIVECONNECT,
239 XCommandEnvironment >& Environment)
248 if(action == THROWAUTHENTICATIONREQUEST)
251 OUString aPassword,aAccount;
263 ucbhelper::SimpleAuthenticationRequest
266 ucbhelper::SimpleAuthenticationRequest
272 xInteractionHandler =
275 if( xInteractionHandler.is()) {
276 xInteractionHandler->handle(p);
282 xSelection,UNO_QUERY).is())
285 xSelection,UNO_QUERY).is()) {
290 p->getAuthenticationSupplier()->getPassword(),
295 aRet = p->getRequest();
318 case THROWAUTHENTICATIONREQUEST:
324 case THROWACCESSDENIED:
331 IOErrorCode_ACCESS_DENIED,
336 case THROWINTERACTIVECONNECT:
338 InteractiveNetworkConnectException excep;
346 case THROWRESOLVENAME:
348 InteractiveNetworkResolveNameException excep;
377 if(aCommand.Name ==
"getPropertyValues") {
379 if(!(aCommand.Argument >>= Properties))
381 aRet <<= IllegalArgumentException(
382 "Wrong argument type!",
383 static_cast< cppu::OWeakObject * >(
this),
390 else if(aCommand.Name ==
"setPropertyValues")
394 if( ! ( aCommand.Argument >>= propertyValues ) ) {
395 aRet <<= IllegalArgumentException(
396 "Wrong argument type!",
397 static_cast< cppu::OWeakObject * >(
this),
404 else if(aCommand.Name ==
"getCommandInfo") {
408 else if(aCommand.Name ==
"getPropertySetInfo") {
412 else if(aCommand.Name ==
"insert")
414 InsertCommandArgument aInsertArgument;
415 if ( ! ( aCommand.Argument >>= aInsertArgument ) ) {
416 aRet <<= IllegalArgumentException(
417 "Wrong argument type!",
418 static_cast< cppu::OWeakObject * >(
this),
424 else if(aCommand.Name ==
"delete") {
428 else if(aCommand.Name ==
"open") {
429 OpenCommandArgument2 aOpenCommand;
430 if ( !( aCommand.Argument >>= aOpenCommand ) ) {
431 aRet <<= IllegalArgumentException(
432 "Wrong argument type!",
433 static_cast< cppu::OWeakObject * >(
this),
442 xActiveDataSink(aOpenCommand.Sink,UNO_QUERY);
444 xOutputStream(aOpenCommand.Sink,UNO_QUERY);
446 if(xActiveDataSink.is()) {
447 xActiveDataSink->setInputStream(
450 else if(xOutputStream.is()) {
455 sal_Int32
n = xStream->readBytes(byte_seq, 4096);
460 if(byte_seq.getLength() != n)
462 xOutputStream->writeBytes(byte_seq);
463 }
catch(
const NotConnectedException&) {
465 }
catch(
const BufferSizeExceededException&) {
473 aRet <<= UnsupportedDataSinkException(
475 static_cast< cppu::OWeakObject * >(
this),
480 else if(aOpenCommand.Mode == OpenMode::ALL ||
481 aOpenCommand.Mode == OpenMode::DOCUMENTS ||
482 aOpenCommand.Mode == OpenMode::FOLDERS ) {
483 std::vector<FTPDirentry> resvec =
489 std::make_unique<ResultSetFactory>(
m_xContext,
491 aOpenCommand.Properties,
495 else if(aOpenCommand.Mode ==
496 OpenMode::DOCUMENT_SHARE_DENY_NONE ||
498 OpenMode::DOCUMENT_SHARE_DENY_WRITE) {
500 aRet <<= UnsupportedOpenModeException(
502 static_cast< cppu::OWeakObject * >(
this),
503 static_cast< sal_Int16 >(aOpenCommand.Mode));
507 aRet <<= IllegalArgumentException(
508 "Unexpected OpenMode!",
509 static_cast< cppu::OWeakObject * >(
this),
514 }
else if(aCommand.Name ==
"createNewContent") {
516 if (!(aCommand.Argument >>= aArg)) {
519 IllegalArgumentException(
520 "Wrong argument type!",
521 static_cast< cppu::OWeakObject * >(
this),
528 aRet <<= UnsupportedCommandException(
530 static_cast< cppu::OWeakObject * >(
this));
538 if(e.
code() == CURLE_COULDNT_CONNECT)
539 action = THROWINTERACTIVECONNECT;
540 else if(e.
code() == CURLE_COULDNT_RESOLVE_HOST )
541 action = THROWRESOLVENAME;
542 else if(e.
code() == CURLE_FTP_USER_PASSWORD_INCORRECT ||
543 e.
code() == CURLE_LOGIN_DENIED ||
544 e.
code() == CURLE_BAD_PASSWORD_ENTERED ||
545 e.
code() == CURLE_FTP_WEIRD_PASS_REPLY)
546 action = THROWAUTHENTICATIONREQUEST;
547 else if(e.
code() == CURLE_FTP_ACCESS_DENIED)
548 action = THROWACCESSDENIED;
549 else if(e.
code() == CURLE_FTP_QUOTE_ERROR)
551 else if(e.
code() == CURLE_FTP_COULDNT_RETR_FILE)
552 action = THROWNOFILE;
555 action = THROWGENERAL;
560 constexpr OUStringLiteral
FTP_FILE =
u"application/vnd.sun.staroffice.ftp-file";
562 constexpr OUStringLiteral
FTP_FOLDER =
u"application/vnd.sun.staroffice.ftp-folder";
578 PropertyAttribute::MAYBEVOID
579 | PropertyAttribute::BOUND ) };
582 {
FTP_FILE, ContentInfoAttribute::INSERT_WITH_INPUTSTREAM | ContentInfoAttribute::KIND_DOCUMENT,
props },
590 if( Info.Type ==
"application/vnd.sun.staroffice.ftp-file" || Info.Type ==
"application/vnd.sun.staroffice.ftp-folder" )
611 throw NoSupportException();
628 : m_xInputStream(xInputStream) { }
629 virtual ~InsertData() {}
632 virtual sal_Int32 read(
sal_Int8 *dest,sal_Int32 nBytesRequested)
override;
641 sal_Int32 InsertData::read(
sal_Int8 *dest,sal_Int32 nBytesRequested)
645 if(m_xInputStream.is()) {
647 m = m_xInputStream->readBytes(seq,nBytesRequested);
648 memcpy(dest,seq.getConstArray(),m);
660 MissingPropertiesException excep;
661 excep.Properties = {
"Title" };
667 !aInsertCommand.Data.is())
669 MissingInputStreamException excep;
673 bool bReplace(aInsertCommand.ReplaceExisting);
678 InsertData
data(aInsertCommand.Data);
680 }
else if(
m_aInfo.Type == FTP_FOLDER)
688 xInt = Env->getInteractionHandler();
690 UnsupportedNameClashException excep;
727 for(
const auto& rProp : seqProp) {
728 const OUString&
Name = rProp.Name;
730 xRow->appendString(rProp,aDirEntry.
m_aName);
731 else if(Name ==
"CreatableContentsInfo")
732 xRow->appendObject(rProp,
735 if(Name ==
"ContentType")
736 xRow->appendString(rProp,
738 ? OUString(FTP_FOLDER)
739 : OUString(FTP_FILE) );
740 else if(Name ==
"IsReadOnly")
741 xRow->appendBoolean(rProp,
744 else if(Name ==
"IsDocument")
745 xRow->appendBoolean(rProp,
748 else if(Name ==
"IsFolder")
749 xRow->appendBoolean(rProp,
752 else if(Name ==
"Size")
753 xRow->appendLong(rProp,
755 else if(Name ==
"DateCreated")
756 xRow->appendTimestamp(rProp,
759 xRow->appendVoid(rProp);
761 xRow->appendVoid(rProp);
772 auto retRange = asNonConstRange(ret);
776 for(sal_Int32
i = 0;
i < ret.getLength(); ++
i) {
777 if ( seqPropVal[
i].
Name ==
"Title" ) {
779 if(!(seqPropVal[
i].
Value >>= Title)) {
780 retRange[
i] <<= IllegalTypeException();
782 }
else if(Title.isEmpty()) {
783 retRange[
i] <<= IllegalArgumentException();
802 InteractiveIOException excep;
805 excep.Code = IOErrorCode_ACCESS_DENIED;
806 retRange[
i] <<= excep;
813 retRange[
i] <<= UnknownPropertyException();
814 const auto& rName = seqPropVal[
i].Name;
815 auto pProp = std::find_if(props.begin(), props.end(),
816 [&rName](
const Property& rProp) {
return rProp.Name == rName; });
817 if (pProp != props.end()) {
818 retRange[
i] <<= IllegalAccessException(
819 "Property is read-only!",
823 static_cast< cppu::OWeakObject * >(
this ));
828 if(evt.hasElements()) {
css::uno::Reference< css::uno::XComponentContext > m_xContext
const OUString & host() const
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.
constexpr OUStringLiteral FTP_FILE
rtl::Reference< ResultSetBase > createResultSet()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL acquire() noexcept override
virtual OUString getParentURL() override
bool setHost(const OUString &host, const OUString &port, const OUString &username, const OUString &password, const OUString &account)
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
const OUString & username() const
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
css::uno::Reference< css::task::XInteractionRequest > const & getRequest() const
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &seqPropVal)
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
void mkdir(bool ReplaceExisting) const
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
OUString parent(bool internal=false) const
returns the parent url.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::vector< FTPDirentry > list(sal_Int16 nMode) const
virtual void SAL_CALL release() noexcept override
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
FTPDirentry direntry() const
std::vector< FTPDirentry > m_dirvec
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr OUStringLiteral FTP_FOLDER
OUString ren(const OUString &NewTitle)
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
constexpr OUStringLiteral FTP_CONTENT_TYPE
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
void insert(bool ReplaceExisting, void *stream) const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void insert(const css::ucb::InsertCommandArgument &, const css::uno::Reference< css::ucb::XCommandEnvironment > &)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
void child(const OUString &title)
sets the unencoded title
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Sequence< css::beans::Property > m_seq
Definition of ftpcontentprovider.
static css::uno::Sequence< css::ucb::ContentInfo > queryCreatableContentsInfo_Static()
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< css::uno::Type > SAL_CALL getTypes() override
const OUString & port() const
exports com.sun.star.chart2. data
virtual ~FTPContent() override
rtl::Reference< ContentProviderImplHelper > m_xProvider
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() 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
virtual OUString SAL_CALL getContentType() override
css::ucb::ContentInfo m_aInfo
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &seqProp)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
Reference< XComponentContext > m_xContext
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
FTPContentProvider * m_pFCP
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
OUString ident(bool withslash, bool internal) const
This returns the URL, but cleaned from unnecessary ellipses.
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)
bool m_bDetectedRangeSegmentation false