chiark / gitweb /
The Login page now includes a form to request a password reminder
[disorder] / lib / client.c
index d3ea6c38b3700d269ec65be8fd4d0d4f1341ba90..08d325a669276bbbc32478a669ab0205107b4f5d 100644 (file)
@@ -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.
  */
 
@@ -64,6 +64,7 @@ struct disorder_client {
   char *ident;
   char *user;
   int verbose;
+  char *last;                          /* last error string */
 };
 
 /** @brief Create a new client
@@ -97,14 +98,23 @@ static int response(disorder_client *c, char **rp) {
   if(r[0] >= '0' && r[0] <= '9'
      && r[1] >= '0' && r[1] <= '9'
      && r[2] >= '0' && r[2] <= '9'
-     && r[3] == ' ')
+     && r[3] == ' ') {
+    c->last = r + 4;
     return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0';
-  else {
+  else {
     error(0, "invalid reply format from %s", c->ident);
     return -1;
   }
 }
 
+/** @brief Return last response string
+ * @param c Client
+ * @return Last response string (UTF-8, English) or NULL
+ */
+const char *disorder_last(disorder_client *c) {
+  return c->last;
+}
+
 /** @brief Read and partially parse a response
  * @param c Client
  * @param rp Where to store response text (or NULL) (UTF-8)
@@ -155,6 +165,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);
@@ -725,7 +739,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
@@ -849,7 +863,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) {
@@ -939,7 +953,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
  */
@@ -1108,7 +1122,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
  */
@@ -1126,7 +1139,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
@@ -1139,6 +1158,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