kio Library: ktelnetservice.cpp Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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 311366 2004-05-14 12:38:58Z waba $
    00023
    00024 #include <kapplication.h>
    00025 #include <kmessagebox.h>
    00026 #include <kcmdlineargs.h>
    00027 #include <kdebug.h>
    00028 #include <klocale.h>
    00029 #include <kprocess.h>
    00030
    00031 static const KCmdLineOptions options[] =
    00032 {
    00033     {"+url", 0, 0},
    00034     KCmdLineLastOption
    00035 };
    00036
    00037 int main(int argc, char **argv)
    00038 {
    00039     KLocale::setMainCatalogue("kdelibs");
    00040     KCmdLineArgs::init(argc, argv, "ktelnetservice", I18N_NOOP("telnet service"),
    00041                I18N_NOOP("telnet protocol handler"), "unknown");
    00042     KCmdLineArgs::addCmdLineOptions(options);
    00043
    00044     KApplication app;
    00045
    00046     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    00047
    00048     if (args->count() != 1)
    00049         return 1;
    00050
    00051     KURL url(args->arg(0));
    00052     QStringList cmd;
    00053     cmd << "--noclose";
    00054
    00055     cmd << "-e";
    00056         if ( url.protocol() == "telnet" )
    00057             cmd << "telnet";
    00058         else if ( url.protocol() == "ssh" )
    00059             cmd << "ssh";
    00060         else if ( url.protocol() == "rlogin" )
    00061             cmd << "rlogin";
    00062         else {
    00063             kdError() << "Invalid protocol " << url.protocol() << endl;
    00064             return 2;
    00065         }
    00066
    00067         if (!app.authorize("shell_access"))
    00068         {
    00069             KMessageBox::sorry(0,
    00070                 i18n("You do not have permission to access the %1 protocol.").arg(url.protocol()));
    00071             return 3;
    00072         }
    00073
    00074     if (!url.user().isEmpty())
    00075     {
    00076         cmd << "-l";
    00077         cmd << url.user();
    00078     }
    00079
    00080         QString host;
    00081         if (!url.host().isEmpty())
    00082            host = url.host(); // telnet://host
    00083         else if (!url.path().isEmpty())
    00084            host = url.path(); // telnet:host
    00085
    00086         if (host.isEmpty() || host.startsWith("-"))
    00087         {
    00088             kdError() << "Invalid hostname " << host << endl;
    00089             return 2;
    00090         }
    00091
    00092         cmd << host;
    00093
    00094     if (url.port()){
    00095             if ( url.protocol() == "ssh" )
    00096         cmd << "-p" << QString::number(url.port());
    00097         else
    00098         cmd << QString::number(url.port());
    00099     }
    00100
    00101     app.kdeinitExec("konsole", cmd);
    00102
    00103     return 0;
    00104 }
    00105
    00106 // vim: ts=4 sw=4 noet

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:24:04 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003