X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/bb037be206aa8d904c310f722a971ed835588288..eb5f83f45eb2ff415ededbb30187fec8c3e71010:/lib/client.c diff --git a/lib/client.c b/lib/client.c index 8147c6d..c06bdf1 100644 --- a/lib/client.c +++ b/lib/client.c @@ -20,7 +20,7 @@ /** @file lib/client.c * @brief Simple C client * - * See @file lib/eclient.c for an asynchronous-capable client + * See @ref lib/eclient.c for an asynchronous-capable client * implementation. */ @@ -59,12 +59,20 @@ #include "rights.h" #include "trackdb.h" +/** @brief Client handle contents */ struct disorder_client { - FILE *fpin, *fpout; + /** @brief Stream to read from */ + FILE *fpin; + /** @brief Stream to write to */ + FILE *fpout; + /** @brief Peer description */ char *ident; + /** @brief Username */ char *user; + /** @brief Report errors to @c stderr */ int verbose; - char *last; /* last error string */ + /** @brief Last error string */ + char *last; }; /** @brief Create a new client @@ -165,6 +173,10 @@ static int disorder_simple_v(disorder_client *c, const char *arg; struct dynstr d; + if(!c->fpout) { + error(0, "not connected to server"); + return -1; + } if(cmd) { dynstr_init(&d); dynstr_append_string(&d, cmd); @@ -543,6 +555,7 @@ int disorder_playing(disorder_client *c, struct queue_entry **qp) { return 0; } +/** @brief Fetch the queue, recent list, etc */ static int disorder_somequeue(disorder_client *c, const char *cmd, struct queue_entry **qp) { struct queue_entry *qh, **qt = &qh, *q; @@ -735,7 +748,7 @@ static void pref_error_handler(const char *msg, error(0, "error handling 'prefs' reply: %s", msg); } -/** @param Get all preferences for a trcak +/** @brief Get all preferences for a trcak * @param c Client * @param track Track name * @param kp Where to store linked list of preferences @@ -859,7 +872,7 @@ int disorder_random_disable(disorder_client *c) { /** @brief Test whether random play is enabled * @param c Client - * @param existsp Where to store result (non-0 iff enabled) + * @param enabledp Where to store result (non-0 iff enabled) * @return 0 on success, non-0 on error */ int disorder_random_enabled(disorder_client *c, int *enabledp) { @@ -949,7 +962,7 @@ int disorder_part(disorder_client *c, char **partp, /** @brief Resolve aliases * @param c Client - * @param trackkp Where to store canonical name (UTF-8) + * @param trackp Where to store canonical name (UTF-8) * @param track Track name (UTF-8) * @return 0 on success, non-0 on error */ @@ -1118,7 +1131,6 @@ int disorder_edituser(disorder_client *c, const char *user, * @param user Username * @param password Password * @param email Email address (UTF-8) - * @param rights Initial rights or NULL to use default * @param confirmp Where to store confirmation string * @return 0 on success, non-0 on error */ @@ -1136,7 +1148,13 @@ int disorder_register(disorder_client *c, const char *user, * @return 0 on success, non-0 on error */ int disorder_confirm(disorder_client *c, const char *confirm) { - return disorder_simple(c, 0, "confirm", confirm, (char *)0); + char *u; + int rc; + + if(!(rc = dequote(disorder_simple(c, &u, "confirm", confirm, (char *)0), + &u))) + c->user = u; + return rc; } /** @brief Make a cookie for this login @@ -1149,6 +1167,23 @@ int disorder_make_cookie(disorder_client *c, char **cookiep) { cookiep); } +/** @brief Revoke the cookie used by this session + * @param c Client + * @return 0 on success, non-0 on error + */ +int disorder_revoke(disorder_client *c) { + return disorder_simple(c, 0, "revoke", (char *)0); +} + +/** @brief Request a password reminder email + * @param c Client + * @param user Username + * @return 0 on success, non-0 on error + */ +int disorder_reminder(disorder_client *c, const char *user) { + return disorder_simple(c, 0, "reminder", user, (char *)0); +} + /* Local Variables: c-basic-offset:2