+/** @brief Connect a client with a specified username and password
+ * @param c Client
+ * @param username Username to log in with
+ * @param password Password to log in with
+ * @return 0 on success, non-0 on error
+ */
+int disorder_connect_user(disorder_client *c,
+ const char *username,
+ const char *password) {
+ return disorder_connect_generic(c,
+ username,
+ password,
+ 0);
+}
+
+/** @brief Connect a client
+ * @param c Client
+ * @return 0 on success, non-0 on error
+ *
+ * The connection will use the username and password found in @ref
+ * config, or directly from the database if no password is found and
+ * the database is readable (usually only for root).
+ */
+int disorder_connect(disorder_client *c) {
+ const char *username, *password;
+
+ if(!(username = config->username)) {
+ c->last = "no username";
+ error(0, "no username configured");
+ return -1;
+ }
+ password = config->password;
+ if(!password) {
+ /* Maybe we can read the database */
+ /* TODO failure to open the database should not be fatal */
+ trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
+ trackdb_open(TRACKDB_READ_ONLY);
+ password = trackdb_get_password(username);
+ trackdb_close();
+ }
+ if(!password) {
+ /* Oh well */
+ c->last = "no password";
+ error(0, "no password configured");
+ return -1;
+ }
+ return disorder_connect_generic(c,
+ username,
+ password,
+ 0);
+}
+
+/** @brief Connect a client
+ * @param c Client
+ * @param cookie Cookie to log in with, or NULL
+ * @return 0 on success, non-0 on error
+ *
+ * If @p cookie is NULL or does not work then we attempt to log in as
+ * guest instead (so when the cookie expires only an extra round trip
+ * is needed rathre than a complete new login).
+ */
+int disorder_connect_cookie(disorder_client *c,
+ const char *cookie) {
+ return disorder_connect_generic(c,
+ "guest",
+ "",
+ cookie);
+}
+
+/** @brief Close a client
+ * @param c Client
+ * @return 0 on succcess, non-0 on errior
+ *
+ * The client is still closed even on error. It might well be
+ * appropriate to ignore the return value.
+ */