You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
6.6 KiB
262 lines
6.6 KiB
15 years ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <sys/stat.h>
|
||
|
|
||
15 years ago
|
#include <tqdir.h>
|
||
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtextstream.h>
|
||
15 years ago
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kinstance.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
#include "info.h"
|
||
|
|
||
12 years ago
|
using namespace TDEIO;
|
||
15 years ago
|
|
||
15 years ago
|
InfoProtocol::InfoProtocol( const TQCString &pool, const TQCString &app )
|
||
15 years ago
|
: SlaveBase( "info", pool, app )
|
||
|
, m_page( "" )
|
||
|
, m_node( "" )
|
||
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::InfoProtocol" << endl;
|
||
|
|
||
12 years ago
|
m_perl = TDEGlobal::dirs()->findExe( "perl" );
|
||
12 years ago
|
m_infoScript = locate( "data", "tdeio_info/kde-info2html" );
|
||
|
m_infoConf = locate("data", "tdeio_info/kde-info2html.conf");
|
||
15 years ago
|
|
||
|
if( m_perl.isNull() || m_infoScript.isNull() || m_infoConf.isNull() ) {
|
||
|
kdError( 7108 ) << "Critical error: Cannot locate files for HTML-conversion" << endl;
|
||
15 years ago
|
TQString errorStr;
|
||
15 years ago
|
if ( m_perl.isNull() ) {
|
||
|
errorStr = "perl.";
|
||
|
} else {
|
||
12 years ago
|
TQString missing =m_infoScript.isNull() ? "tdeio_info/kde-info2html" : "tdeio_info/kde-info2html.conf";
|
||
15 years ago
|
errorStr = "kde-info2html" + i18n( "\nUnable to locate file %1 which is necessary to run this service. "
|
||
|
"Please check your software installation" ).arg( missing );
|
||
|
}
|
||
12 years ago
|
error( TDEIO::ERR_CANNOT_LAUNCH_PROCESS, errorStr );
|
||
15 years ago
|
exit();
|
||
|
}
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::InfoProtocol - done" << endl;
|
||
|
}
|
||
|
|
||
|
InfoProtocol::~InfoProtocol()
|
||
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::~InfoProtocol" << endl;
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::~InfoProtocol - done" << endl;
|
||
|
}
|
||
|
|
||
|
void InfoProtocol::get( const KURL& url )
|
||
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::get" << endl;
|
||
|
kdDebug( 7108 ) << "URL: " << url.prettyURL() << " , Path :" << url.path() << endl;
|
||
|
|
||
|
if (url.path()=="/")
|
||
|
{
|
||
|
KURL newUrl("info:/dir");
|
||
|
redirection(newUrl);
|
||
|
finished();
|
||
|
return;
|
||
|
};
|
||
|
|
||
|
// some people write info://autoconf instead of info:/autoconf
|
||
|
if (!url.host().isEmpty()) {
|
||
|
KURL newURl(url);
|
||
|
newURl.setPath(url.host()+url.path());
|
||
15 years ago
|
newURl.setHost(TQString::null);
|
||
15 years ago
|
redirection(newURl);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( url.path().right(1) == "/" )
|
||
|
{
|
||
|
// Trailing / are not supported, so we need to remove them.
|
||
|
KURL newUrl( url );
|
||
15 years ago
|
TQString newPath( url.path() );
|
||
15 years ago
|
newPath.truncate( newPath.length()-1 );
|
||
|
newUrl.setPath( newPath );
|
||
|
redirection( newUrl );
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
mimeType("text/html");
|
||
|
// extract the path and node from url
|
||
|
decodeURL( url );
|
||
|
|
||
10 years ago
|
TQString path = TDEGlobal::iconLoader()->iconPath("go-up", TDEIcon::Toolbar, true);
|
||
13 years ago
|
int revindex = path.findRev('/');
|
||
15 years ago
|
path = path.left(revindex);
|
||
|
|
||
12 years ago
|
TQString cmd = TDEProcess::quote(m_perl);
|
||
15 years ago
|
cmd += " ";
|
||
12 years ago
|
cmd += TDEProcess::quote(m_infoScript);
|
||
15 years ago
|
cmd += " ";
|
||
12 years ago
|
cmd += TDEProcess::quote(m_infoConf);
|
||
15 years ago
|
cmd += " ";
|
||
12 years ago
|
cmd += TDEProcess::quote(path);
|
||
15 years ago
|
cmd += " ";
|
||
12 years ago
|
cmd += TDEProcess::quote(m_page);
|
||
15 years ago
|
cmd += " ";
|
||
12 years ago
|
cmd += TDEProcess::quote(m_node);
|
||
15 years ago
|
|
||
|
kdDebug( 7108 ) << "cmd: " << cmd << endl;
|
||
|
|
||
15 years ago
|
FILE *file = popen( TQFile::encodeName(cmd), "r" );
|
||
15 years ago
|
if ( !file ) {
|
||
|
kdDebug( 7108 ) << "InfoProtocol::get popen failed" << endl;
|
||
|
error( ERR_CANNOT_LAUNCH_PROCESS, cmd );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
char buffer[ 4096 ];
|
||
15 years ago
|
TQByteArray array;
|
||
15 years ago
|
|
||
|
bool empty = true;
|
||
|
while ( !feof( file ) )
|
||
|
{
|
||
|
int n = fread( buffer, 1, sizeof( buffer ), file );
|
||
|
if ( !n && feof( file ) && empty ) {
|
||
|
error( ERR_CANNOT_LAUNCH_PROCESS, cmd );
|
||
|
return;
|
||
|
}
|
||
|
if ( n < 0 )
|
||
|
{
|
||
|
// ERROR
|
||
|
kdDebug( 7108 ) << "InfoProtocol::get ERROR!" << endl;
|
||
|
pclose( file );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
empty = false;
|
||
|
array.setRawData( buffer, n );
|
||
|
data( array );
|
||
|
array.resetRawData( buffer, n );
|
||
|
}
|
||
|
|
||
|
pclose( file );
|
||
|
|
||
|
finished();
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::get - done" << endl;
|
||
|
}
|
||
|
|
||
|
void InfoProtocol::mimetype( const KURL& /* url */ )
|
||
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::mimetype" << endl;
|
||
|
|
||
|
// to get rid of those "Open with" dialogs...
|
||
|
mimeType( "text/html" );
|
||
|
|
||
|
// finish action
|
||
|
finished();
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::mimetype - done" << endl;
|
||
|
}
|
||
|
|
||
|
void InfoProtocol::decodeURL( const KURL &url )
|
||
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::decodeURL" << endl;
|
||
|
|
||
|
/* Notes:
|
||
|
*
|
||
|
* I cleaned up the URL decoding and chose not to support URLs in the
|
||
|
* form "info:/usr/local/share/info/libc.info.gz" or similar which the
|
||
|
* older code attempted (and failed, maybe it had worked once) to do.
|
||
|
*
|
||
|
* The reason is that an obvious use such as viewing a info file off your
|
||
|
* infopath would work for the first page, but then all the links would be
|
||
|
* wrong. Of course, one could change kde-info2html to make it work, but I don't
|
||
|
* think it worthy, others are free to disagree and write the necessary code ;)
|
||
|
*
|
||
|
* luis pedro
|
||
|
*/
|
||
|
|
||
|
if ( url == KURL( "info:/browse_by_file?special=yes" ) ) {
|
||
|
m_page = "#special#";
|
||
|
m_node = "browse_by_file";
|
||
|
kdDebug( 7108 ) << "InfoProtocol::decodeURL - special - browse by file" << endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
decodePath( url.path() );
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::decodeURL - done" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void InfoProtocol::decodePath( TQString path )
|
||
15 years ago
|
{
|
||
|
kdDebug( 7108 ) << "InfoProtocol::decodePath(-" <<path<<"-)"<< endl;
|
||
|
|
||
|
m_page = "dir"; //default
|
||
|
m_node = "";
|
||
|
|
||
|
// remove leading slash
|
||
|
if ('/' == path[0]) {
|
||
|
path = path.mid( 1 );
|
||
|
}
|
||
|
//kdDebug( 7108 ) << "Path: " << path << endl;
|
||
|
|
||
13 years ago
|
int slashPos = path.find( "/" );
|
||
15 years ago
|
|
||
|
if( slashPos < 0 )
|
||
|
{
|
||
|
m_page = path;
|
||
|
m_node = "Top";
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
m_page = path.left( slashPos );
|
||
|
|
||
|
// remove leading+trailing whitespace
|
||
|
m_node = path.right( path.length() - slashPos - 1).stripWhiteSpace ();
|
||
|
|
||
|
kdDebug( 7108 ) << "InfoProtocol::decodePath - done" << endl;
|
||
|
}
|
||
|
|
||
|
// A minimalistic stat with only the file type
|
||
|
// This seems to be enough for konqueror
|
||
|
void InfoProtocol::stat( const KURL & )
|
||
|
{
|
||
|
UDSEntry uds_entry;
|
||
|
UDSAtom uds_atom;
|
||
|
|
||
|
// Regular file with rwx permission for all
|
||
12 years ago
|
uds_atom.m_uds = TDEIO::UDS_FILE_TYPE;
|
||
15 years ago
|
uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
|
||
|
|
||
|
uds_entry.append( uds_atom );
|
||
|
|
||
|
statEntry( uds_entry );
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
extern "C" { int KDE_EXPORT kdemain( int argc, char **argv ); }
|
||
|
|
||
|
int kdemain( int argc, char **argv )
|
||
|
{
|
||
12 years ago
|
TDEInstance instance( "tdeio_info" );
|
||
15 years ago
|
|
||
12 years ago
|
kdDebug() << "tdeio_info starting " << getpid() << endl;
|
||
15 years ago
|
|
||
|
if (argc != 4)
|
||
|
{
|
||
12 years ago
|
fprintf(stderr, "Usage: tdeio_info protocol domain-socket1 domain-socket2\n");
|
||
15 years ago
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
InfoProtocol slave( argv[2], argv[3] );
|
||
|
slave.dispatchLoop();
|
||
|
|
||
|
return 0;
|
||
|
}
|