29 #include <sys/types.h>
31 #include <QtCore/QByteArray>
32 #include <QtCore/QDir>
33 #include <QtCore/QFile>
34 #include <QtDBus/QDBusArgument>
35 #include <QtDBus/QDBusMetaType>
41 #define NETRC_READ_BUF_SIZE 4096
55 ExtraField(
const ExtraField& other)
56 : customTitle(other.customTitle),
62 ExtraField& operator=(
const ExtraField& other)
64 customTitle = other.customTitle;
76 QDataStream& operator<< (QDataStream& s, const ExtraField& extraField)
78 s << extraField.customTitle;
79 s << (int)extraField.flags;
80 s << extraField.value;
84 QDataStream&
operator>> (QDataStream& s, ExtraField& extraField)
86 s >> extraField.customTitle ;
90 s >> extraField.value ;
94 QDBusArgument &
operator<<(QDBusArgument &argument,
const ExtraField &extraField)
96 argument.beginStructure();
97 argument << extraField.customTitle << (int)extraField.flags
98 << QDBusVariant(extraField.value);
99 argument.endStructure();
103 const QDBusArgument &
operator>>(
const QDBusArgument &argument, ExtraField &extraField)
108 argument.beginStructure();
109 argument >> extraField.customTitle >> flag >> value;
110 argument.endStructure();
112 extraField.value = value.variant();
117 class KIO::AuthInfoPrivate
161 d->extraFields = info.d->extraFields;
179 d->extraFields[fieldName].value = value;
184 d->extraFields[fieldName].flags = flags;
189 if (!d->extraFields.contains(fieldName))
return QVariant();
190 return d->extraFields[fieldName].value;
196 return d->extraFields[fieldName].flags;
201 qRegisterMetaType<ExtraField>();
202 qRegisterMetaType<KIO::AuthInfo>();
203 qDBusRegisterMetaType<ExtraField>();
204 qDBusRegisterMetaType<KIO::AuthInfo>();
232 argument.beginStructure();
233 argument << (quint8)1
238 argument.endStructure();
247 argument.beginStructure();
253 argument.endStructure();
262 class NetRC::NetRCPrivate
272 NetRC* NetRC::instance = 0L;
275 : d( new NetRCPrivate )
289 instance =
new NetRC;
294 const QString &_type, LookUpMode mode )
297 if ( !url.isValid() )
301 if ( type.isEmpty() )
304 if ( d->loginMap.isEmpty() || d->isDirty )
313 filename = QDir::homePath() + QLatin1String(
"/.netrc");
321 if ( !d->loginMap.contains( type ) )
328 for (LoginList::ConstIterator it = l.begin(); it != l.end(); ++it)
333 log.
machine == QLatin1String(
"default") &&
344 log.
machine == QLatin1String(
"preset") &&
377 KDE_struct_stat sbuff;
382 if ( sbuff.st_mode != (S_IFREG|S_IRUSR|S_IWUSR) ||
383 sbuff.st_uid != geteuid() )
392 int m_len = strlen(key);
393 int b_len = strlen(buf);
397 while( buf[idx] ==
' ' || buf[idx] ==
'\t' )
400 if ( strncasecmp( buf+idx, key, m_len ) != 0 )
405 while( buf[idx] ==
' ' || buf[idx] ==
'\t' )
409 while( buf[idx] !=
' ' && buf[idx] !=
'\t' &&
410 buf[idx] !=
'\n' && buf[idx] !=
'\r' )
416 return QString::fromLatin1( buf+start, idx-start);
433 bool isMacro =
false;
435 FILE* fstream = KDE_fdopen( fd,
"rb" );
441 while ( buf[pos] ==
' ' || buf[pos] ==
'\t' )
444 if ( buf[pos] ==
'#' || buf[pos] ==
'\n' ||
445 buf[pos] ==
'\r' || buf[pos] ==
'\0' )
447 if ( buf[pos] !=
'#' && isMacro )
455 int tail = strlen(buf);
456 while( buf[tail-1] ==
'\n' || buf[tail-1] ==
'\r' )
459 QString mac = QString::fromLatin1(buf, tail).trimmed();
460 if ( !mac.isEmpty() )
461 d->loginMap[type][index].macdef[macro].append( mac );
470 if (strncasecmp(buf+pos,
"default", 7) == 0 )
473 l.
machine = QLatin1String(
"default");
475 else if (strncasecmp(buf+pos,
"preset", 6) == 0 )
478 l.
machine = QLatin1String(
"preset");
493 type = l.
type = QLatin1String(
"ftp");
496 macro =
extract( buf,
"macdef", pos );
497 isMacro = !macro.isEmpty();
500 d->loginMap[l.
type].append(l);
501 index = d->loginMap[l.
type].count()-1;