chiark / gitweb /
Doxygen-clean
[disorder] / cgi / actions.c
index 8bbce8787a97642a087c2900f73f5843917a2863..f63e51922cf3146c33df3983650c017538eb581a 100644 (file)
@@ -2,28 +2,28 @@
  * This file is part of DisOrder.
  * Copyright (C) 2004-2008 Richard Kettlewell
  *
  * This file is part of DisOrder.
  * Copyright (C) 2004-2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
  * You should have received a copy of the GNU General Public License
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
-/** @file server/actions.c
+/** @file cgi/actions.c
  * @brief DisOrder web actions
  *
  * Actions are anything that the web interface does beyond passive template
  * expansion and inspection of state recieved from the server.  This means
  * playing tracks, editing prefs etc but also setting extra headers e.g. to
  * auto-refresh the playing list.
  * @brief DisOrder web actions
  *
  * Actions are anything that the web interface does beyond passive template
  * expansion and inspection of state recieved from the server.  This means
  * playing tracks, editing prefs etc but also setting extra headers e.g. to
  * auto-refresh the playing list.
+ *
+ * See @ref lib/macros-builtin.c for docstring syntax.
  */
 
 #include "disorder-cgi.h"
  */
 
 #include "disorder-cgi.h"
@@ -47,14 +47,14 @@ static void redirect(const char *url) {
     fatal(errno, "error writing to stdout");
 }
 
     fatal(errno, "error writing to stdout");
 }
 
-/*! playing
+/*$ playing
  *
  * Expands \fIplaying.tmpl\fR as if there was no special 'playing' action, but
  * adds a Refresh: field to the HTTP header.  The maximum refresh interval is
  * defined by \fBrefresh\fR (see \fBdisorder_config\fR(5)) but may be less if
  * the end of the track is near.
  */
  *
  * Expands \fIplaying.tmpl\fR as if there was no special 'playing' action, but
  * adds a Refresh: field to the HTTP header.  The maximum refresh interval is
  * defined by \fBrefresh\fR (see \fBdisorder_config\fR(5)) but may be less if
  * the end of the track is near.
  */
-/*! manage
+/*$ manage
  *
  * Expands \fIplaying.tmpl\fR (NB not \fImanage.tmpl\fR) as if there was no
  * special 'playing' action, and adds a Refresh: field to the HTTP header.  The
  *
  * Expands \fIplaying.tmpl\fR (NB not \fImanage.tmpl\fR) as if there was no
  * special 'playing' action, and adds a Refresh: field to the HTTP header.  The
@@ -105,7 +105,7 @@ static void act_playing(void) {
   dcgi_expand("playing", 1);
 }
 
   dcgi_expand("playing", 1);
 }
 
-/*! disable
+/*$ disable
  *
  * Disables play.
  */
  *
  * Disables play.
  */
@@ -115,7 +115,7 @@ static void act_disable(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! enable
+/*$ enable
  *
  * Enables play.
  */
  *
  * Enables play.
  */
@@ -125,7 +125,7 @@ static void act_enable(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! random-disable
+/*$ random-disable
  *
  * Disables random play.
  */
  *
  * Disables random play.
  */
@@ -135,7 +135,7 @@ static void act_random_disable(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! random-enable
+/*$ random-enable
  *
  * Enables random play.
  */
  *
  * Enables random play.
  */
@@ -145,7 +145,7 @@ static void act_random_enable(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! pause
+/*$ pause
  *
  * Pauses the current track (if there is one and it's not paused already).
  */
  *
  * Pauses the current track (if there is one and it's not paused already).
  */
@@ -155,7 +155,7 @@ static void act_pause(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! resume
+/*$ resume
  *
  * Resumes the current track (if there is one and it's paused).
  */
  *
  * Resumes the current track (if there is one and it's paused).
  */
@@ -165,7 +165,7 @@ static void act_resume(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! remove
+/*$ remove
  *
  * Removes the track given by the \fBid\fR argument.  If this is the currently
  * playing track then it is scratched.
  *
  * Removes the track given by the \fBid\fR argument.  If this is the currently
  * playing track then it is scratched.
@@ -201,7 +201,7 @@ static void act_remove(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! move
+/*$ move
  *
  * Moves the track given by the \fBid\fR argument the distance given by the
  * \fBdelta\fR argument.  If this is positive the track is moved earlier in the
  *
  * Moves the track given by the \fBid\fR argument the distance given by the
  * \fBdelta\fR argument.  If this is positive the track is moved earlier in the
@@ -231,7 +231,7 @@ static void act_move(void) {
   redirect(0);
 }
 
   redirect(0);
 }
 
-/*! play
+/*$ play
  *
  * Play the track given by the \fBtrack\fR argument, or if that is not set all
  * the tracks in the directory given by the \fBdir\fR argument.
  *
  * Play the track given by the \fBtrack\fR argument, or if that is not set all
  * the tracks in the directory given by the \fBdir\fR argument.
@@ -240,7 +240,7 @@ static void act_play(void) {
   const char *track, *dir;
   char **tracks;
   int ntracks, n;
   const char *track, *dir;
   char **tracks;
   int ntracks, n;
-  struct dcgi_entry *e;
+  struct tracksort_data *tsd;
   
   if(dcgi_client) {
     if((track = cgi_get("track"))) {
   
   if(dcgi_client) {
     if((track = cgi_get("track"))) {
@@ -248,16 +248,9 @@ static void act_play(void) {
     } else if((dir = cgi_get("dir"))) {
       if(disorder_files(dcgi_client, dir, 0, &tracks, &ntracks))
         ntracks = 0;
     } else if((dir = cgi_get("dir"))) {
       if(disorder_files(dcgi_client, dir, 0, &tracks, &ntracks))
         ntracks = 0;
-      /* TODO use tracksort_init */
-      e = xmalloc(ntracks * sizeof (struct dcgi_entry));
-      for(n = 0; n < ntracks; ++n) {
-        e[n].track = tracks[n];
-        e[n].sort = trackname_transform("track", tracks[n], "sort");
-        e[n].display = trackname_transform("track", tracks[n], "display");
-      }
-      qsort(e, ntracks, sizeof (struct dcgi_entry), dcgi_compare_entry);
+      tsd = tracksort_init(ntracks, tracks, "track");
       for(n = 0; n < ntracks; ++n)
       for(n = 0; n < ntracks; ++n)
-        disorder_play(dcgi_client, e[n].track);
+        disorder_play(dcgi_client, tsd[n].track);
     }
   }
   redirect(0);
     }
   }
   redirect(0);
@@ -271,7 +264,7 @@ static int clamp(int n, int min, int max) {
   return n;
 }
 
   return n;
 }
 
-/*! volume
+/*$ volume
  *
  * If the \fBdelta\fR argument is set: adjust both channels by that amount (up
  * if positive, down if negative).
  *
  * If the \fBdelta\fR argument is set: adjust both channels by that amount (up
  * if positive, down if negative).
@@ -333,7 +326,7 @@ static int login_as(const char *username, const char *password) {
   return 0;                             /* OK */
 }
 
   return 0;                             /* OK */
 }
 
-/*! login
+/*$ login
  *
  * If \fBusername\fR and \fBpassword\fR are set (and the username isn't
  * "guest") then attempt to log in using those credentials.  On success,
  *
  * If \fBusername\fR and \fBpassword\fR are set (and the username isn't
  * "guest") then attempt to log in using those credentials.  On success,
@@ -368,7 +361,7 @@ static void act_login(void) {
   }
 }
 
   }
 }
 
-/*! logout
+/*$ logout
  *
  * Logs out the current user and expands \fIlogin.tmpl\fR with \fBstatus\fR or
  * \fB@error\fR set according to the result.
  *
  * Logs out the current user and expands \fIlogin.tmpl\fR with \fBstatus\fR or
  * \fB@error\fR set according to the result.
@@ -393,7 +386,7 @@ static void act_logout(void) {
   dcgi_expand("login", 1);
 }
 
   dcgi_expand("login", 1);
 }
 
-/*! register
+/*$ register
  *
  * Register a new user using \fBusername\fR, \fBpassword1\fR, \fBpassword2\fR
  * and \fBemail\fR and expands \fIlogin.tmpl\fR with \fBstatus\fR or
  *
  * Register a new user using \fBusername\fR, \fBpassword1\fR, \fBpassword2\fR
  * and \fBemail\fR and expands \fIlogin.tmpl\fR with \fBstatus\fR or
@@ -434,9 +427,8 @@ static void act_register(void) {
     return;
   }
   /* We could well do better address validation but for now we'll just do the
     return;
   }
   /* We could well do better address validation but for now we'll just do the
-   * minimum
-   /* TODO use email_valid() */
-  if(!strchr(email, '@')) {
+   * minimum */
+  if(!email_valid(email)) {
     login_error("bademail");
     return;
   }
     login_error("bademail");
     return;
   }
@@ -461,7 +453,7 @@ static void act_register(void) {
   dcgi_expand("login", 1);
 }
 
   dcgi_expand("login", 1);
 }
 
-/*! confirm
+/*$ confirm
  *
  * Confirm a user registration using the nonce supplied in \fBc\fR and expands
  * \fIlogin.tmpl\fR with \fBstatus\fR or \fB@error\fR set according to the
  *
  * Confirm a user registration using the nonce supplied in \fBc\fR and expands
  * \fIlogin.tmpl\fR with \fBstatus\fR or \fB@error\fR set according to the
@@ -497,7 +489,7 @@ static void act_confirm(void) {
   dcgi_expand("login", 1);
 }
 
   dcgi_expand("login", 1);
 }
 
-/*! edituser
+/*$ edituser
  *
  * Edit user details using \fBusername\fR, \fBchangepassword1\fR,
  * \fBchangepassword2\fR and \fBemail\fR and expands \fIlogin.tmpl\fR with
  *
  * Edit user details using \fBusername\fR, \fBchangepassword1\fR,
  * \fBchangepassword2\fR and \fBemail\fR and expands \fIlogin.tmpl\fR with
@@ -525,8 +517,7 @@ static void act_edituser(void) {
     }
   } else
     password = password2 = 0;
     }
   } else
     password = password2 = 0;
-  /* TODO use email_valid() */
-  if(email && !strchr(email, '@')) {
+  if(email && !email_valid(email)) {
     login_error("bademail");
     return;
   }
     login_error("bademail");
     return;
   }
@@ -559,7 +550,7 @@ static void act_edituser(void) {
   dcgi_expand("login", 1);
 }
 
   dcgi_expand("login", 1);
 }
 
-/*! reminder
+/*$ reminder
  *
  * Issue an email password reminder to \fBusername\fR and expands
  * \fIlogin.tmpl\fR with \fBstatus\fR or \fB@error\fR set according to the
  *
  * Issue an email password reminder to \fBusername\fR and expands
  * \fIlogin.tmpl\fR with \fBstatus\fR or \fB@error\fR set according to the
@@ -641,7 +632,7 @@ static int process_prefs(int numfile) {
   return 0;
 }
 
   return 0;
 }
 
-/*! prefs
+/*$ prefs
  *
  * Set preferences on a number of tracks.
  *
  *
  * Set preferences on a number of tracks.
  *
@@ -745,7 +736,7 @@ void dcgi_expand(const char *name, int header) {
   if(!(found = mx_find(p, 0/*report*/)))
     fatal(errno, "cannot find %s", p);
   if(header) {
   if(!(found = mx_find(p, 0/*report*/)))
     fatal(errno, "cannot find %s", p);
   if(header) {
-    if(printf("Content-Type: text/html\n"
+    if(printf("Content-Type: text/html; charset=UTF-8\n"
               "%s\n"
               "\n", dcgi_cookie_header()) < 0)
       fatal(errno, "error writing to stdout");
               "%s\n"
               "\n", dcgi_cookie_header()) < 0)
       fatal(errno, "error writing to stdout");