summaryrefslogtreecommitdiffstats
path: root/tdeioslave/filter
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslave/filter')
-rw-r--r--tdeioslave/filter/CMakeLists.txt36
-rw-r--r--tdeioslave/filter/Makefile.am21
-rw-r--r--tdeioslave/filter/bzip.protocol10
-rw-r--r--tdeioslave/filter/bzip2.protocol10
-rw-r--r--tdeioslave/filter/configure.in.in1
-rw-r--r--tdeioslave/filter/filter.cc167
-rw-r--r--tdeioslave/filter/filter.h46
-rw-r--r--tdeioslave/filter/gzip.protocol10
8 files changed, 301 insertions, 0 deletions
diff --git a/tdeioslave/filter/CMakeLists.txt b/tdeioslave/filter/CMakeLists.txt
new file mode 100644
index 000000000..4b0c3d36c
--- /dev/null
+++ b/tdeioslave/filter/CMakeLists.txt
@@ -0,0 +1,36 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### other data ################################
+
+install( FILES gzip.protocol bzip.protocol bzip2.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
+
+
+##### kio_filter (module) #######################
+
+set( target kio_filter )
+
+tde_add_kpart( ${target} AUTOMOC
+ SOURCES filter.cc
+ LINK tdeio-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeioslave/filter/Makefile.am b/tdeioslave/filter/Makefile.am
new file mode 100644
index 000000000..f315064c8
--- /dev/null
+++ b/tdeioslave/filter/Makefile.am
@@ -0,0 +1,21 @@
+KDE_CPPFLAGS = -DQT_NO_CAST_ASCII
+
+INCLUDES = $(all_includes)
+
+kde_module_LTLIBRARIES = kio_filter.la
+
+kio_filter_la_SOURCES = filter.cc
+kio_filter_la_LIBADD = $(LIB_KSYCOCA)
+kio_filter_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+noinst_HEADERS = filter.h
+
+METASOURCES = AUTO
+
+protocoldir = $(kde_servicesdir)
+
+if include_BZIP2
+BZIP2FILES=bzip.protocol bzip2.protocol
+endif
+
+protocol_DATA = gzip.protocol $(BZIP2FILES)
+
diff --git a/tdeioslave/filter/bzip.protocol b/tdeioslave/filter/bzip.protocol
new file mode 100644
index 000000000..4d729f5ea
--- /dev/null
+++ b/tdeioslave/filter/bzip.protocol
@@ -0,0 +1,10 @@
+[Protocol]
+exec=kio_filter
+protocol=bzip
+mimetype=application/x-bzip
+input=stream
+output=stream
+reading=true
+source=false
+DocPath=tdeioslave/bzip.html
+Icon=ark
diff --git a/tdeioslave/filter/bzip2.protocol b/tdeioslave/filter/bzip2.protocol
new file mode 100644
index 000000000..c2b8d2c51
--- /dev/null
+++ b/tdeioslave/filter/bzip2.protocol
@@ -0,0 +1,10 @@
+[Protocol]
+exec=kio_filter
+protocol=bzip2
+mimetype=application/x-bzip2
+input=stream
+output=stream
+reading=true
+source=false
+DocPath=tdeioslave/bzip2.html
+Icon=ark
diff --git a/tdeioslave/filter/configure.in.in b/tdeioslave/filter/configure.in.in
new file mode 100644
index 000000000..5ef522b6f
--- /dev/null
+++ b/tdeioslave/filter/configure.in.in
@@ -0,0 +1 @@
+AC_FIND_BZIP2
diff --git a/tdeioslave/filter/filter.cc b/tdeioslave/filter/filter.cc
new file mode 100644
index 000000000..793921c6c
--- /dev/null
+++ b/tdeioslave/filter/filter.cc
@@ -0,0 +1,167 @@
+/*
+This file is part of KDE
+
+ Copyright (C) 1999-2000 Waldo Bastian (bastian@kde.org)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <kinstance.h>
+#include <kdebug.h>
+#include <kmimemagic.h>
+#include <kfilterbase.h>
+
+#include "filter.h"
+
+extern "C" { KDE_EXPORT int kdemain(int argc, char **argv); }
+
+int kdemain( int argc, char ** argv)
+{
+ TDEInstance instance( "kio_filter" );
+
+ kdDebug(7110) << "Starting " << getpid() << endl;
+
+ if (argc != 4)
+ {
+ fprintf(stderr, "Usage: kio_filter protocol domain-socket1 domain-socket2\n");
+ exit(-1);
+ }
+
+ FilterProtocol slave(argv[1], argv[2], argv[3]);
+ slave.dispatchLoop();
+
+ kdDebug(7110) << "Done" << endl;
+ return 0;
+}
+
+FilterProtocol::FilterProtocol( const TQCString & protocol, const TQCString &pool, const TQCString &app )
+ : TDEIO::SlaveBase( protocol, pool, app )
+{
+ TQString mimetype = TQString::fromLatin1("application/x-") + TQString::fromLatin1(protocol);
+ filter = KFilterBase::findFilterByMimeType( mimetype );
+ Q_ASSERT(filter);
+}
+
+void FilterProtocol::get( const KURL & )
+{
+ if (subURL.isEmpty())
+ {
+ error( TDEIO::ERR_NO_SOURCE_PROTOCOL, mProtocol );
+ return;
+ }
+ if (!filter)
+ {
+ error( TDEIO::ERR_INTERNAL, mProtocol );
+ return;
+ }
+ needSubURLData();
+
+ filter->init(IO_ReadOnly);
+
+ bool bNeedHeader = true;
+ bool bNeedMimetype = true;
+ bool bError = true;
+ int result;
+
+ TQByteArray inputBuffer;
+ TQByteArray outputBuffer(8*1024); // Start with a modest buffer
+ filter->setOutBuffer( outputBuffer.data(), outputBuffer.size() );
+ while(true)
+ {
+ if (filter->inBufferEmpty())
+ {
+ dataReq(); // Request data
+ result = readData( inputBuffer);
+ kdDebug(7110) << "requestData: got " << result << endl;
+ if (result <= 0)
+ {
+ bError = true;
+ break; // Unexpected EOF.
+ }
+ filter->setInBuffer( inputBuffer.data(), inputBuffer.size() );
+ }
+ if (bNeedHeader)
+ {
+ bError = !filter->readHeader();
+ if (bError)
+ break;
+ bNeedHeader = false;
+ }
+ result = filter->uncompress();
+ if ((filter->outBufferAvailable() == 0) || (result == KFilterBase::END))
+ {
+ kdDebug(7110) << "avail_out = " << filter->outBufferAvailable() << endl;
+ if (filter->outBufferAvailable() != 0)
+ {
+ // Discard unused space :-)
+ outputBuffer.resize(outputBuffer.size() - filter->outBufferAvailable());
+ }
+ if (bNeedMimetype)
+ {
+ KMimeMagicResult * result = KMimeMagic::self()->findBufferFileType( outputBuffer, subURL.fileName() );
+ kdDebug(7110) << "Emitting mimetype " << result->mimeType() << endl;
+ mimeType( result->mimeType() );
+ bNeedMimetype = false;
+ }
+ data( outputBuffer ); // Send data
+ filter->setOutBuffer( outputBuffer.data(), outputBuffer.size() );
+ if (result == KFilterBase::END)
+ break; // Finished.
+ }
+ if (result != KFilterBase::OK)
+ {
+ bError = true;
+ break; // Error
+ }
+ }
+
+ if (!bError)
+ {
+ dataReq(); // Request data
+ result = readData( inputBuffer);
+ kdDebug(7110) << "requestData: got " << result << "(expecting 0)" << endl;
+ data( TQByteArray() ); // Send EOF
+ }
+
+ filter->terminate();
+
+ if (bError)
+ {
+ error(TDEIO::ERR_COULD_NOT_READ, subURL.url());
+ subURL = KURL(); // Clear subURL
+ return;
+ }
+
+ subURL = KURL(); // Clear subURL
+ finished();
+}
+
+void FilterProtocol::put( const KURL &/*url*/, int, bool /*_overwrite*/, bool /*_resume*/ )
+{
+ error( TDEIO::ERR_UNSUPPORTED_ACTION, TQString::fromLatin1("put"));
+}
+
+void FilterProtocol::setSubURL(const KURL &url)
+{
+ subURL = url;
+}
+
diff --git a/tdeioslave/filter/filter.h b/tdeioslave/filter/filter.h
new file mode 100644
index 000000000..9457f0b73
--- /dev/null
+++ b/tdeioslave/filter/filter.h
@@ -0,0 +1,46 @@
+/*
+This file is part of KDE
+
+ Copyright (C) 2000 Waldo Bastian (bastian@kde.org)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef __filter_h__
+#define __filter_h__
+
+#include <tqobject.h>
+#include <tdeio/global.h>
+#include <tdeio/slavebase.h>
+
+class FilterProtocol : public TQObject, public TDEIO::SlaveBase
+{
+public:
+ FilterProtocol( const TQCString & protocol, const TQCString &pool, const TQCString &app );
+
+ virtual void get( const KURL &url );
+ virtual void put( const KURL &url, int _mode, bool _overwrite,
+ bool _resume );
+ virtual void setSubURL(const KURL &url);
+
+private:
+ KURL subURL;
+ KFilterBase * filter;
+};
+
+#endif
diff --git a/tdeioslave/filter/gzip.protocol b/tdeioslave/filter/gzip.protocol
new file mode 100644
index 000000000..f0f57911c
--- /dev/null
+++ b/tdeioslave/filter/gzip.protocol
@@ -0,0 +1,10 @@
+[Protocol]
+exec=kio_filter
+protocol=gzip
+mimetype=application/gzip
+input=stream
+output=stream
+reading=true
+source=false
+DocPath=tdeioslave/gzip.html
+Icon=ark