kio Library API Documentation

ktelnetservice.cpp

00001 /*
00002    Copyright (c) 2001 Malte Starostik <malte@kde.org>
00003    based on kmailservice.cpp,
00004    Copyright (c) 2000 Simon Hausmann <hausmann@kde.org>
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 // $Id: ktelnetservice.cpp,v 1.3.2.2 2003/03/31 09:13:55 waba Exp $
00023 
00024 #include <kapplication.h>
00025 #include <kcmdlineargs.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kprocess.h>
00029 
00030 static const KCmdLineOptions options[] =
00031 {
00032     {"+url", 0, 0},
00033     {0, 0, 0}
00034 };
00035 
00036 int main(int argc, char **argv)
00037 {
00038     KLocale::setMainCatalogue("kdelibs");
00039     KCmdLineArgs::init(argc, argv, "ktelnetservice", I18N_NOOP("telnet service"), I18N_NOOP("telnet protocol handler"));
00040     KCmdLineArgs::addCmdLineOptions(options);
00041 
00042     KApplication app;
00043     
00044     if (!app.authorize("shell_access"))
00045         return 3;
00046 
00047     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00048 
00049     if (args->count() != 1)
00050         return 1;
00051 
00052     KURL url(args->arg(0));
00053     QStringList cmd;
00054     cmd << "--noclose";
00055 
00056     cmd << "-e";
00057         if ( url.protocol() == "telnet" )
00058             cmd << "telnet";
00059         else if ( url.protocol() == "rlogin" )
00060             cmd << "rlogin";
00061         else {
00062             kdError() << "Invalid protocol " << url.protocol() << endl;
00063             return 2;
00064         }
00065     if (!url.user().isEmpty())
00066     {
00067         cmd << "-l";
00068         cmd << url.user();
00069     }
00070 
00071         QString host;
00072         if (!url.host().isEmpty())
00073            host = url.host(); // telnet://host
00074         else if (!url.path().isEmpty())
00075            host = url.path(); // telnet:host
00076 
00077         if (host.isEmpty() || host.startsWith("-"))
00078         {
00079             kdError() << "Invalid hostname " << host << endl;
00080             return 2;
00081         }
00082 
00083         cmd << host;
00084         
00085     if (url.port())
00086         cmd << QString::number(url.port());
00087 
00088     app.kdeinitExec("konsole", cmd);
00089 
00090     return 0;
00091 }
00092 
00093 // vim: ts=4 sw=4 noet
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:15:32 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001