File: kionetrctest.cpp

package info (click to toggle)
kio 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,496 kB
  • sloc: cpp: 123,468; xml: 528; ansic: 466; ruby: 60; sh: 21; makefile: 13
file content (47 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <QApplication>
#include <QDebug>

#include "authinfo.h"

void output(const QUrl &u)
{
    qDebug() << "Looking up auto login for: " << u;
    KIO::NetRC::AutoLogin l;
    bool result = KIO::NetRC::self()->lookup(u, l, true);
    if (!result) {
        qDebug() << "Either no .netrc and/or .kionetrc file was "
                    "found or there was problem when attempting to "
                    "read from them!  Please make sure either or both "
                    "of the above files exist and have the correct "
                    "permission, i.e. a regular file owned by you with "
                    "with a read/write permission (0600)";
        return;
    }

    qDebug() << "Type: " << l.type << "\nMachine: " << l.machine << "\nLogin: " << l.login << "\nPassword: " << l.password;

    QMap<QString, QStringList>::ConstIterator it = l.macdef.constBegin();
    for (; it != l.macdef.constEnd(); ++it) {
        qDebug() << "Macro: " << it.key() << "= " << it.value().join(QLatin1String("   "));
    }
}

int main(int argc, char **argv)
{
    // KCmdLineOptions options;
    // options.add("+command", qi18n("[url1,url2 ,...]"));

    // KCmdLineArgs::init( argc, argv, "kionetrctest", 0, qi18n("KIO-netrc-test"), version, qi18n("Unit test for .netrc and kionetrc parser."));
    QApplication app(argc, argv);

    int count = QCoreApplication::arguments().count() - 1;
    for (int i = 0; i < count; i++) {
        QUrl u = QUrl::fromUserInput(QCoreApplication::arguments().at(i + 1));
        if (!u.isValid()) {
            qDebug() << u << "is invalid! Ignoring...";
            continue;
        }
        output(u);
    }
    return 0;
}