#ifndef BNCCREDENTIALS_H
#define BNCCREDENTIALS_H

#include <QString>
#include <QStringList>
#include <QUrl>

// Passwords from credentials files instead of the configuration file
// (option 'credentialsFile', default $NETRC or ~/.netrc). Two formats,
// detected per file:
//   netrc:  machine <host>[:<port>] login <user> password <password>
//   BNC:    <host> <port|*> <user|-> <password>      (one entry per line)
//           <host> <user> <password>                  (any port)
// Tokens are separated by white space, may be quoted ("..."), '#' starts a
// comment. An entry for the exact port is preferred, the netrc 'default'
// entry is never used.
class bncCredentials {
 public:
  // Password of user (empty: entry without user) at host:port
  static bool password(const QString& host, int port, const QString& user,
                       QString& password);

  // Stream URL: a user without password gets it from the credentials files;
  // a URL without user stays anonymous
  static void complete(QUrl& url);

  // Upload or sourcetable: an empty password is taken from the credentials
  // files (also for an empty user, e.g. Ntrip Version 1 upload if 'anyUser')
  static void complete(const QString& host, int port, const QString& user,
                       QString& password, bool anyUser, bool hint);

  static QStringList fileNames();
};

#endif
