diff options
Diffstat (limited to 'shell/source/unix/exec')
-rw-r--r-- | shell/source/unix/exec/exports.map | 10 | ||||
-rw-r--r-- | shell/source/unix/exec/makefile.mk | 90 | ||||
-rw-r--r-- | shell/source/unix/exec/shellexec.cxx | 331 | ||||
-rw-r--r-- | shell/source/unix/exec/shellexec.hxx | 79 | ||||
-rw-r--r-- | shell/source/unix/exec/shellexecentry.cxx | 134 | ||||
-rw-r--r-- | shell/source/unix/exec/syssh.xml | 33 | ||||
-rw-r--r-- | shell/source/unix/exec/urltest.cxx | 151 | ||||
-rw-r--r-- | shell/source/unix/exec/urltest.sh | 2 | ||||
-rw-r--r-- | shell/source/unix/exec/urltest.txt | 11 |
9 files changed, 841 insertions, 0 deletions
diff --git a/shell/source/unix/exec/exports.map b/shell/source/unix/exec/exports.map new file mode 100644 index 000000000000..ba501f9ae076 --- /dev/null +++ b/shell/source/unix/exec/exports.map @@ -0,0 +1,10 @@ +UDK_3_0_0 { + global: + GetVersionInfo; + component_getImplementationEnvironment; + component_getFactory; + component_writeInfo; + + local: + *; +}; diff --git a/shell/source/unix/exec/makefile.mk b/shell/source/unix/exec/makefile.mk new file mode 100644 index 000000000000..2d9d5d250da4 --- /dev/null +++ b/shell/source/unix/exec/makefile.mk @@ -0,0 +1,90 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJNAME=shell +TARGET=exec + +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE + +COMP1TYPELIST=syssh + +TESTAPP1=urltest + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +DLLPRE= + +SLOFILES=$(SLO)$/shellexec.obj\ + $(SLO)$/shellexecentry.obj + +SHL1OBJS=$(SLOFILES) + +SHL1TARGET=syssh.uno +.IF "$(GUI)" == "OS2" +SHL1IMPLIB=i$(TARGET) +.ELSE +SHL1IMPLIB= +.ENDIF + +SHL1VERSIONMAP=exports.map +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) + +SHL1STDLIBS=$(CPPULIB)\ + $(CPPUHELPERLIB)\ + $(SALLIB) +SHL1LIBS= +SHL1DEPN= + +.IF "$(test)" != "" + +APP1TARGET=$(TESTAPP1) +APP1STDLIBS= $(SHL1STDLIBS) +APP1OBJS= \ + $(SLO)$/shellexec.obj \ + $(SLO)$/$(APP1TARGET).obj + +.ENDIF # "$(test)" != "" + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +run_test : $(BIN)$/$(TESTAPP1).sh + dmake test=t + $(BIN)$/$(TESTAPP1) urltest.txt + +$(BIN)$/$(TESTAPP1).sh : $$(@:f) + $(COPY) $< $@ + -chmod +x $@ diff --git a/shell/source/unix/exec/shellexec.cxx b/shell/source/unix/exec/shellexec.cxx new file mode 100644 index 000000000000..e6aca26922da --- /dev/null +++ b/shell/source/unix/exec/shellexec.cxx @@ -0,0 +1,331 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_shell.hxx" +#include <osl/diagnose.h> +#include <osl/thread.h> +#include <osl/process.h> +#include <osl/file.hxx> +#include <rtl/ustrbuf.hxx> + +#ifndef _RTL_URI_H_ +#include <rtl/uri.hxx> +#endif +#include "shellexec.hxx" +#include <com/sun/star/system/SystemShellExecuteFlags.hpp> + +#include <com/sun/star/util/XMacroExpander.hpp> +#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp> +#include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp> + +#include "uno/current_context.hxx" + +#include <string.h> +#include <errno.h> +#include <unistd.h> + +//------------------------------------------------------------------------ +// namespace directives +//------------------------------------------------------------------------ + +using com::sun::star::system::XSystemShellExecute; +using com::sun::star::system::SystemShellExecuteException; + +using rtl::OString; +using rtl::OUString; +using rtl::OStringBuffer; +using rtl::OUStringBuffer; +using osl::FileBase; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::system::SystemShellExecuteFlags; +using namespace cppu; + +//------------------------------------------------------------------------ +// defines +//------------------------------------------------------------------------ + +#define SHELLEXEC_IMPL_NAME "com.sun.star.comp.system.SystemShellExecute2" + +//------------------------------------------------------------------------ +// helper functions +//------------------------------------------------------------------------ + +namespace // private +{ + Sequence< OUString > SAL_CALL ShellExec_getSupportedServiceNames() + { + Sequence< OUString > aRet(1); + aRet[0] = OUString::createFromAscii("com.sun.star.sys.shell.SystemShellExecute"); + return aRet; + } +} + +void escapeForShell( rtl::OStringBuffer & rBuffer, const rtl::OString & rURL) +{ + sal_Int32 nmax = rURL.getLength(); + for(sal_Int32 n=0; n < nmax; ++n) + { + // escape every non alpha numeric characters (excluding a few "known good") by prepending a '\' + sal_Char c = rURL[n]; +#ifndef OS2 // YD shell does not support escaped chars + if( ( c < 'A' || c > 'Z' ) && ( c < 'a' || c > 'z' ) && ( c < '0' || c > '9' ) && c != '/' && c != '.' ) + rBuffer.append( '\\' ); +#endif + + rBuffer.append( c ); + } +} + +//----------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------- + +ShellExec::ShellExec( const Reference< XComponentContext >& xContext ) : + WeakImplHelper2< XSystemShellExecute, XServiceInfo >(), + m_xContext(xContext) +{ + try { + Reference< XCurrentContext > xCurrentContext(getCurrentContext()); + + if (xCurrentContext.is()) + { + Any aValue = xCurrentContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM( "system.desktop-environment" ) ) ); + + OUString aDesktopEnvironment; + if (aValue >>= aDesktopEnvironment) + { + m_aDesktopEnvironment = OUStringToOString(aDesktopEnvironment, RTL_TEXTENCODING_ASCII_US); + } + } + } catch (RuntimeException e) { + } +} + +//------------------------------------------------- +// +//------------------------------------------------- + +void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aParameter, sal_Int32 nFlags ) + throw (IllegalArgumentException, SystemShellExecuteException, RuntimeException) +{ + OStringBuffer aBuffer, aLaunchBuffer; + + // DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html + static const char *pDesktopLaunch = getenv( "DESKTOP_LAUNCH" ); + + // Check wether aCommand contains a document url or not + sal_Int32 nIndex = aCommand.indexOf( OUString( RTL_CONSTASCII_USTRINGPARAM(":/") ) ); + + if( nIndex > 0 || 0 == aCommand.compareToAscii("mailto:", 7) ) + { + // It seems to be a url .. + // We need to re-encode file urls because osl_getFileURLFromSystemPath converts + // to UTF-8 before encoding non ascii characters, which is not what other apps + // expect. + OUString aURL( + com::sun::star::uri::ExternalUriReferenceTranslator::create( + m_xContext)->translateToExternal(aCommand)); + if ( aURL.getLength() == 0 && aCommand.getLength() != 0 ) + { + throw RuntimeException( + (OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Cannot translate URI reference to external format: ")) + + aCommand), + static_cast< cppu::OWeakObject * >(this)); + } + +#ifdef MACOSX + aBuffer.append("open"); +#else + // The url launchers are expected to be in the $OOO_BASE_DIR/program + // directory: + com::sun::star::uno::Reference< com::sun::star::util::XMacroExpander > + exp; + if (!(m_xContext->getValueByName( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "/singletons/com.sun.star.util.theMacroExpander"))) + >>= exp) + || !exp.is()) + { + throw SystemShellExecuteException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "component context fails to supply singleton" + " com.sun.star.util.theMacroExpander of type" + " com.sun.star.util.XMacroExpander")), + static_cast< XSystemShellExecute * >(this), ENOENT); + } + OUString aProgramURL; + try { + aProgramURL = exp->expandMacros( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/"))); + } catch (com::sun::star::lang::IllegalArgumentException &) + { + throw SystemShellExecuteException( + OUString(RTL_CONSTASCII_USTRINGPARAM("Could not expand $OOO_BASE_DIR path")), + static_cast < XSystemShellExecute * > (this), ENOENT ); + } + + OUString aProgram; + if ( FileBase::E_None != FileBase::getSystemPathFromFileURL(aProgramURL, aProgram)) + { + throw SystemShellExecuteException( + OUString(RTL_CONSTASCII_USTRINGPARAM("Cound not convert executable path")), + static_cast < XSystemShellExecute * > (this), ENOENT ); + } + +#ifdef OS2 + OStringBuffer aProg = OUStringToOString(aProgram, osl_getThreadTextEncoding()); + aProg.append("open-url.exe"); + OString aUrl = OUStringToOString(aURL, osl_getThreadTextEncoding()); + if ( -1 == spawnl(P_NOWAIT, aProg.getStr(), aProg.getStr(), aUrl.getStr() , NULL) ) + { + int nerr = errno; + throw SystemShellExecuteException(OUString::createFromAscii( strerror( nerr ) ), + static_cast < XSystemShellExecute * > (this), nerr ); + } + return; +#endif + + OString aTmp = OUStringToOString(aProgram, osl_getThreadTextEncoding()); + escapeForShell(aBuffer, aTmp); + +#ifdef SOLARIS + if ( m_aDesktopEnvironment.getLength() == 0 ) + m_aDesktopEnvironment = OString("GNOME"); +#endif + + // Respect the desktop environment - if there is an executable named + // <desktop-environement-is>-open-url, pass the url to this one instead + // of the default "open-url" script. + if ( m_aDesktopEnvironment.getLength() > 0 ) + { + OString aDesktopEnvironment(m_aDesktopEnvironment.toAsciiLowerCase()); + OStringBuffer aCopy(aTmp); + + aCopy.append(aDesktopEnvironment); + aCopy.append("-open-url"); + + if ( 0 == access( aCopy.getStr(), X_OK) ) + { + aBuffer.append(aDesktopEnvironment); + aBuffer.append("-"); + + /* CDE requires file urls to be decoded */ + if ( m_aDesktopEnvironment.equals("CDE") && 0 == aURL.compareToAscii("file://", 7) ) + { + aURL = rtl::Uri::decode(aURL, rtl_UriDecodeWithCharset, osl_getThreadTextEncoding()); + } + } + } + + aBuffer.append("open-url"); +#endif + aBuffer.append(" "); + escapeForShell(aBuffer, OUStringToOString(aURL, osl_getThreadTextEncoding())); + + if ( pDesktopLaunch && *pDesktopLaunch ) + { + aLaunchBuffer.append( pDesktopLaunch ); + aLaunchBuffer.append(" "); + escapeForShell(aLaunchBuffer, OUStringToOString(aURL, osl_getThreadTextEncoding())); + } + } else { + escapeForShell(aBuffer, OUStringToOString(aCommand, osl_getThreadTextEncoding())); + aBuffer.append(" "); + if( nFlags != 42 ) + escapeForShell(aBuffer, OUStringToOString(aParameter, osl_getThreadTextEncoding())); + else + aBuffer.append(OUStringToOString(aParameter, osl_getThreadTextEncoding())); + } + + // Prefer DESKTOP_LAUNCH when available + if ( aLaunchBuffer.getLength() > 0 ) + { + FILE *pLaunch = popen( aLaunchBuffer.makeStringAndClear().getStr(), "w" ); + if ( pLaunch != NULL ) + { + if ( 0 == pclose( pLaunch ) ) + return; + } + // Failed, do not try DESKTOP_LAUNCH any more + pDesktopLaunch = NULL; + } + + OString cmd = aBuffer.makeStringAndClear(); + if ( 0 != pclose(popen(cmd.getStr(), "w")) ) + { + int nerr = errno; + throw SystemShellExecuteException(OUString::createFromAscii( strerror( nerr ) ), + static_cast < XSystemShellExecute * > (this), nerr ); + } +} + + +// ------------------------------------------------- +// XServiceInfo +// ------------------------------------------------- + +OUString SAL_CALL ShellExec::getImplementationName( ) + throw( RuntimeException ) +{ + return OUString::createFromAscii( SHELLEXEC_IMPL_NAME ); +} + +// ------------------------------------------------- +// XServiceInfo +// ------------------------------------------------- + +sal_Bool SAL_CALL ShellExec::supportsService( const OUString& ServiceName ) + throw( RuntimeException ) +{ + Sequence < OUString > SupportedServicesNames = ShellExec_getSupportedServiceNames(); + + for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; ) + if (SupportedServicesNames[n].compareTo(ServiceName) == 0) + return sal_True; + + return sal_False; +} + +// ------------------------------------------------- +// XServiceInfo +// ------------------------------------------------- + +Sequence< OUString > SAL_CALL ShellExec::getSupportedServiceNames( ) + throw( RuntimeException ) +{ + return ShellExec_getSupportedServiceNames(); +} + diff --git a/shell/source/unix/exec/shellexec.hxx b/shell/source/unix/exec/shellexec.hxx new file mode 100644 index 000000000000..d7955cc135fd --- /dev/null +++ b/shell/source/unix/exec/shellexec.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SHELLEXEC_HXX_ +#define _SHELLEXEC_HXX_ + +#include <cppuhelper/implbase2.hxx> +#include <osl/mutex.hxx> +#include <rtl/strbuf.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#ifndef _COM_SUN_STAR_SYS_SHELL_XSYSTEMSHELLEXECUTE_HPP_ +#include <com/sun/star/system/XSystemShellExecute.hpp> +#endif + +//---------------------------------------------------------- +// class declaration +//---------------------------------------------------------- + +class ShellExec : public ::cppu::WeakImplHelper2< com::sun::star::system::XSystemShellExecute, com::sun::star::lang::XServiceInfo > +{ + ::rtl::OString m_aDesktopEnvironment; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + +public: + ShellExec(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext); + + //------------------------------------------------ + // XSystemShellExecute + //------------------------------------------------ + + virtual void SAL_CALL execute( const ::rtl::OUString& aCommand, const ::rtl::OUString& aParameter, sal_Int32 nFlags ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::system::SystemShellExecuteException, ::com::sun::star::uno::RuntimeException); + + //------------------------------------------------ + // XServiceInfo + //------------------------------------------------ + + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw(::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw(::com::sun::star::uno::RuntimeException); +}; + + +// helper function - needed for urltest +void escapeForShell( rtl::OStringBuffer & rBuffer, const rtl::OString & rURL); + +#endif diff --git a/shell/source/unix/exec/shellexecentry.cxx b/shell/source/unix/exec/shellexecentry.cxx new file mode 100644 index 000000000000..da5e5613f955 --- /dev/null +++ b/shell/source/unix/exec/shellexecentry.cxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_shell.hxx" + +//----------------------------------------------------------------------- +// includes of other projects +//----------------------------------------------------------------------- +#include <cppuhelper/factory.hxx> +#include <osl/diagnose.h> +#include "shellexec.hxx" + +//----------------------------------------------------------------------- +// namespace directives +//----------------------------------------------------------------------- + +using namespace ::rtl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::cppu; +using com::sun::star::system::XSystemShellExecute; + +//----------------------------------------------------------------------- +// defines +//----------------------------------------------------------------------- + +#define SHELLEXEC_SERVICE_NAME "com.sun.star.system.SystemShellExecute" +#define SHELLEXEC_IMPL_NAME "com.sun.star.comp.system.SystemShellExecute" +#define SHELLEXEC_REGKEY_NAME "/com.sun.star.comp.system.SystemShellExecute/UNO/SERVICES/com.sun.star.system.SystemShellExecute" + +//----------------------------------------------------------------------- +// +//----------------------------------------------------------------------- + +namespace +{ + Reference< XInterface > SAL_CALL createInstance(const Reference< XComponentContext >& xContext) + { + return Reference< XInterface >( static_cast< XSystemShellExecute* >( new ShellExec(xContext) ) ); + } +} + +//----------------------------------------------------------------------- +// the 3 important functions which will be exported +//----------------------------------------------------------------------- + +extern "C" +{ + +//---------------------------------------------------------------------- +// component_getImplementationEnvironment +//---------------------------------------------------------------------- + +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//----------------------------------------------------------------------- +// component_writeInfo +//----------------------------------------------------------------------- + +sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > pXNewKey( static_cast< XRegistryKey* >( pRegistryKey ) ); + pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( SHELLEXEC_REGKEY_NAME ) ) ); + return sal_True; + } + catch( InvalidRegistryException& ) + { + OSL_ENSURE(sal_False, "InvalidRegistryException caught"); + } + } + + return sal_False; +} + +//---------------------------------------------------------------------- +// component_getFactory +//---------------------------------------------------------------------- + +void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface* /*pSrvManager*/, uno_Interface* /*pRegistryKey*/ ) +{ + Reference< XSingleComponentFactory > xFactory; + + if (0 == ::rtl_str_compare( pImplName, SHELLEXEC_IMPL_NAME )) + { + OUString serviceName( RTL_CONSTASCII_USTRINGPARAM(SHELLEXEC_SERVICE_NAME) ); + + xFactory = ::cppu::createSingleComponentFactory( + createInstance, + OUString( RTL_CONSTASCII_USTRINGPARAM(SHELLEXEC_IMPL_NAME) ), + Sequence< OUString >( &serviceName, 1 ) ); + + } + + if (xFactory.is()) + xFactory->acquire(); + + return xFactory.get(); +} + +} // extern "C" diff --git a/shell/source/unix/exec/syssh.xml b/shell/source/unix/exec/syssh.xml new file mode 100644 index 000000000000..5c72befa9141 --- /dev/null +++ b/shell/source/unix/exec/syssh.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + <module-name>syssh</module-name> + <component-description> + <author> Oliver Braun </author> + <name>com.sun.star.comp.system.SystemShellExecute</name> + <description> The unix implementation of a SystemShellExecute service. </description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="beta"/> + <supported-service>com.sun.star.system.SystemShellExecute</supported-service> + <service-dependency>...</service-dependency> + <type>com.sun.star.system.XSystemShellExecute</type> + <type>com.sun.star.system.SystemShellExecuteException</type> + <type>com.sun.star.system.SystemShellExecuteFlags</type> + <type>com.sun.star.lang.IllegalArgumentException</type> + <type>com.sun.star.lang.XServiceInfo</type> + <type>com.sun.star.lang.XSingleComponentFactory</type> + <type>com.sun.star.lang.XTypeProvider</type> + <type>com.sun.star.uno.TypeClass</type> + <type>com.sun.star.uno.XAggregation</type> + <type>com.sun.star.uno.XComponentContext</type> + <type>com.sun.star.uno.XWeak</type> + <type>com.sun.star.registry.XRegistryKey</type> + </component-description> + <project-build-dependency>cppuhelper</project-build-dependency> + <project-build-dependency>cppu</project-build-dependency> + <project-build-dependency>sal</project-build-dependency> + <runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency> + <runtime-module-dependency>cppu3</runtime-module-dependency> + <runtime-module-dependency>sal3</runtime-module-dependency> +</module-description> diff --git a/shell/source/unix/exec/urltest.cxx b/shell/source/unix/exec/urltest.cxx new file mode 100644 index 000000000000..1de12766e650 --- /dev/null +++ b/shell/source/unix/exec/urltest.cxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "shellexec.hxx" + +#include <osl/process.h> + +#include <stdio.h> +#include <limits.h> +#include <string.h> +#include <strings.h> + +// ----------------------------------------------------------------------- + +int main(int argc, const char *argv[]) +{ + int ret = 0; + + if( argc != 2 ) + { + fprintf(stderr, "Usage: urltest <urllist>\n"); + return -1; + } + + FILE * fp = fopen( argv[1], "r" ); + if( NULL == fp ) + { + perror( argv[1] ); + return -1; + } + + // expect urltest.sh beside this binary + char line[LINE_MAX]; + size_t len = strlen(argv[0]); + strcpy( line, argv[0] ); + strcpy( line + len, ".sh " ); + len += 4; + + unsigned int errors = 0; + + // read url(s) to test from file + char url[512]; + while( NULL != fgets(url, sizeof(url), fp)) + { + // remove trailing line break + strtok( url, "\r\n" ); + + printf( "Passing URL: %s\n", url ); + + // test the encoding functionality from shellexec.cxx + rtl::OString aURL( url ); + rtl::OStringBuffer aBuffer; + escapeForShell(aBuffer, aURL); + + // append encoded URL as (only) parameter to the script + strcpy( line + len, aBuffer.getStr() ); + + printf( "Command line: %s\n", line ); + + FILE * pipe = popen( line, "r" ); + if( NULL != pipe ) + { + char buffer[BUFSIZ]; + + // initialize buffer with '\0' + memset(buffer, '\0', BUFSIZ); + + // read the output of the script + if(NULL == fgets( buffer, BUFSIZ, pipe)) + { + perror("FAILED: output of script could not be read"); + printf( "\n"); + ++errors; + continue; + } + + // remove trailing line break again + strtok( buffer, "\r\n" ); + + int n = pclose(pipe); + if( 0 != n ) + { + printf("FAILED: fclose returned %d\n\n", n ); + ++errors; + continue; + } + + if( 0 == strcmp( url, buffer ) ) + { + // strings are identical: good ! + printf( "OK\n\n"); + } + else + { + // compare failed + printf( "FAILED: returned string is %s\n\n", buffer); + ++errors; + } + + } + else + { + perror( line ); + ret = -2; + break; + } + } + + if( ferror( fp ) ) + { + perror( argv[1] ); + ret = -1; + } + + fclose( fp ); + + if( errors ) + { + printf( "Number of tests failing: %d\n", errors); + ret = -3; + } + else + printf( "All tests passed OK.\n" ); + + + return ret; +} diff --git a/shell/source/unix/exec/urltest.sh b/shell/source/unix/exec/urltest.sh new file mode 100644 index 000000000000..ce55ee694114 --- /dev/null +++ b/shell/source/unix/exec/urltest.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "$1"
\ No newline at end of file diff --git a/shell/source/unix/exec/urltest.txt b/shell/source/unix/exec/urltest.txt new file mode 100644 index 000000000000..e69a8cfaf92b --- /dev/null +++ b/shell/source/unix/exec/urltest.txt @@ -0,0 +1,11 @@ +http://www.openoffice.org +http://en.wiktionary.org/wiki/harmless';CMD=lsx-lx$HOME;IFS=x;$CMD;#' +http://en.wikipedia.org/wiki/Shell_(computers) +http://www.google.com/search?hl=$100+bill +http://unix.t-a-y-l-o-r.com/;clear;ls +http://www.google.com/;exec mozilla; +http://www.yahoo.com/<> +http://www.yahoo.com/\ +http://www.yahoo.com/" +http://www.yahoo.com/' +http://www.yahoo.com/;echo 'this';
\ No newline at end of file |