chiark / gitweb /
Eliminate string_login().
[disorder] / scripts / protocol
index dbb6ad11ee5be4d2f6a8d10e40e574a3446fc78e..7d4bbad1e7204978fb7f2bc4b5a84d78a17e29a3 100755 (executable)
@@ -44,6 +44,9 @@ sub c_in_decl {
        return "const char *$name";
     } elsif($type eq 'integer') {
        return "long $name";
+    } elsif($type eq 'list' or $type eq 'body') {
+       return ("char **$name",
+               "int n$name");
     } else {
        die "$0: unknown type '$type'\n";
     }
@@ -64,6 +67,10 @@ sub c_out_decl {
     } elsif($type eq 'list') {
        return ("char ***${name}p",
                "int *n${name}p");
+    } elsif($type eq 'queue') {
+       return ("struct queue_entry **${name}p");
+    } elsif($type eq 'user') {
+       return ();
     } else {
        die "$0: unknown type '$type'\n";
     }
@@ -71,7 +78,17 @@ sub c_out_decl {
 
 sub c_param_docs {
     my $args = shift;
-    return map(" * \@param $_->[1] $_->[2]\n", @$args);
+    my @d = ();
+    for my $arg (@$args) {
+       if($arg->[0] eq 'body' or $arg->[0] eq 'list') {
+           push(@d,
+                " * \@param $arg->[1] $arg->[2]\n",
+                " * \@param n$arg->[1] Length of $arg->[1]\n");
+       } else {
+           push(@d, " * \@param $arg->[1] $arg->[2]\n");
+       }
+    }
+    return @d;
 }
 
 sub c_return_docs {
@@ -87,6 +104,10 @@ sub c_return_docs {
     } elsif($type eq 'list') {
        return (" * \@param ${name}p $descr\n",
                " * \@param n${name}p Number of elements in ${name}p\n");
+    } elsif($type eq 'queue') {
+       return (" * \@param ${name}p $descr\n");
+    } elsif($type eq 'user') {
+       return ();
     } else {
        die "$0: unknown return type '$type'\n";
     }
@@ -94,7 +115,7 @@ sub c_return_docs {
 
 # simple(CMD, SUMMARY, DETAIL,
 #        [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...],
-#        [RETURN-TYPE, RETURN-NAME, RETURN_DESCR)
+#        [RETURN-TYPE, RETURN-NAME, RETURN_DESCR])
 sub simple {
     my $cmd = shift;
     my $summary = shift;
@@ -109,6 +130,7 @@ sub simple {
          " *\n",
          " * $detail\n",
          " *\n",
+        " * \@param c Client\n",
          c_param_docs($args),
         c_return_docs($return),
          " * \@return 0 on success, non-0 on error\n",
@@ -124,10 +146,23 @@ sub simple {
                    c_out_decl($return)),
         ") {\n");
     if(!defined $return) {
-       push(@c, "  return disorder_simple(c, 0, \"$cmd\"",
-            map(", $_->[1]", @$args),
-            ", (char *)0);\n",
-           );
+       my @cargs = ();
+       for my $arg (@$args) {
+           if($arg->[0] eq 'body' or $arg->[0] eq 'list') {
+               push(@cargs, "disorder_$arg->[0]", $arg->[1], "n$arg->[1]");
+           } elsif($arg->[0] eq 'string') {
+               push(@cargs, $arg->[1]);
+           } elsif($arg->[0] eq 'integer') {
+               push(@cargs, "buf_$arg->[1]");
+               push(@c, "  char buf_$arg->[1]\[16];\n",
+                    "  byte_snprintf(buf_$arg->[1], sizeof buf_$arg->[1], \"%ld\", $arg->[1]);\n");
+           } else {
+               die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n";
+           }
+       }
+       push(@c, "  return disorder_simple(",
+            join(", ", "c", 0, "\"$cmd\"", @cargs, "(char *)0"),
+            ");\n");
     } elsif($return->[0] eq 'string') {
        push(@c, "  return dequote(disorder_simple(c, $return->[1]p, \"$cmd\"",
             map(", $_->[1]", @$args),
@@ -151,10 +186,21 @@ sub simple {
             "  *$return->[1]p = atol(v);\n",
             "  xfree(v);\n",
             "  return 0;\n");
+    } elsif($return->[0] eq 'user') {
+       push(@c, "  char *u;\n",
+            "  int rc;\n",
+            "  if((rc = disorder_simple(c, &u, \"$cmd\"",
+            map(", $_->[1]", @$args),
+            "  )))\n",
+            "    return rc;\n",
+            "  c->user = u;\n",
+            "  return 0;\n");
     } elsif($return->[0] eq 'list') {
        push(@c, "  return disorder_simple_list(c, $return->[1]p, n$return->[1]p, \"$cmd\"",
             map(", $_->[1]", @$args),
             ", (char *)0);\n");
+    } elsif($return->[0] eq 'queue') {
+       push(@c, "  return disorder_somequeue(c, \"$cmd\", $return->[1]p);\n");
     } else {
        die "$0: unknown return type '$return->[0]' for '$cmd'\n";
     }
@@ -170,55 +216,6 @@ sub simple {
     # TODO
 }
 
-# string_login(CMD, SUMMARY, DETAIL, [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...])
-#
-# Like string(), but the server returns a username, which we squirrel
-# away rather than returning to the caller.
-sub string_login {
-    my $cmd = shift;
-    my $summary = shift;
-    my $detail = shift;
-    my $args = shift;
-    my $return = shift;
-
-    my $cmdc = $cmd;
-    $cmdc =~ s/-/_/g;
-    # Synchronous C API
-    push(@h, "/** \@brief $summary\n",
-         " *\n",
-         " * $detail\n",
-         " *\n",
-        c_param_docs($args),
-         " * \@return 0 on success, non-0 on error\n",
-         " */\n",
-         "int disorder_$cmdc(",
-        join(", ", "disorder_client *c",
-                   map(c_in_decl($_), @$args)),
-         ");\n");
-    push(@c, "int disorder_$cmdc(",
-        join(", ", "disorder_client *c",
-                   map(c_in_decl($_), @$args)),
-        ") {\n",
-        "  char *u;\n",
-        "  int rc;\n",
-         "  if((rc = disorder_simple(c, &u, \"$cmd\"",
-         map(", $_->[1]", @$args),
-        "  )))\n",
-        "    return rc;\n",
-        "  c->user = u;\n",
-        "  return 0;\n",
-         "}\n\n");
-
-    # Asynchronous C API
-    # TODO
-
-    # Python API
-    # TODO
-
-    # Java API
-    # TODO
-}
-
 # TODO other command classes
 
 # Front matter ----------------------------------------------------------------
@@ -271,15 +268,17 @@ simple("allfiles",
        ["string", "re", "Regexp that results must match (optional)"]],
        ["list", "files", "List of matching files and directories"]);
 
-string_login("confirm",
-            "Confirm registration",
-            "The confirmation string must have been created with 'register'.  The username is returned so the caller knows who they are.",
-            [["string", "confirmation", "Confirmation string"]]);
+simple("confirm",
+       "Confirm registration",
+       "The confirmation string must have been created with 'register'.  The username is returned so the caller knows who they are.",
+       [["string", "confirmation", "Confirmation string"]],
+       ["user"]);
 
-string_login("cookie",
-            "Log in with a cookie",
-            "The cookie must have been created with 'make-cookie'.  The username is returned so the caller knows who they are.",
-            [["string", "cookie", "Cookie string"]]);
+simple("cookie",
+       "Log in with a cookie",
+       "The cookie must have been created with 'make-cookie'.  The username is returned so the caller knows who they are.",
+       [["string", "cookie", "Cookie string"]],
+       ["user"]);
 
 simple("deluser",
        "Delete user",
@@ -356,9 +355,17 @@ simple("make-cookie",
        [],
        ["string", "cookie", "Newly created cookie"]);
 
-# TODO move
+simple("move",
+       "Move a track",
+       "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
+       [["string", "track", "Track ID or name"],
+       ["integer", "delta", "How far to move the track towards the head of the queue"]]);
 
-# TODO moveafter
+simple("moveafter",
+       "Move multiple tracks",
+       "Requires one of the 'move mine', 'move random' or 'move any' rights depending on how the track came to be added to the queue.",
+       [["string", "target", "Move after this track, or to head if \"\""],
+       ["list", "ids", "List of tracks to move by ID"]]);
 
 # TODO new
 
@@ -386,7 +393,11 @@ simple("play",
        [["string", "track", "Track to play"]],
        ["string", "id", "Queue ID of new track"]);
 
-# TODO playafter
+simple("playafter",
+       "Play multiple tracks",
+       "Requires the 'play' right.",
+       [["string", "target", "Insert into queue after this track, or at head if \"\""],
+       ["list", "tracks", "List of track names to play"]]);
 
 # TODO playing
 
@@ -412,6 +423,12 @@ simple("playlist-lock",
        "Requires the 'play' right and permission to modify the playlist.  A given connection may lock at most one playlist.",
        [["string", "playlist", "Playlist to delete"]]);
 
+simple("playlist-set",
+       "Set the contents of a playlist",
+       "Requires the 'play' right and permission to modify the playlist, which must be locked.",
+       [["string", "playlist", "Playlist to modify"],
+       ["body", "tracks", "New list of tracks for playlist"]]);
+
 simple("playlist-set-share",
        "Set a playlist's sharing status",
        "Requires the 'play' right and permission to modify the playlist.",
@@ -431,7 +448,11 @@ simple("playlists",
 
 # TODO prefs
 
-# TODO queue
+simple("queue",
+       "List the queue",
+       "",
+       [],
+       ["queue", "queue", "Current queue contents"]);
 
 simple("random-disable",
        "Disable random play",
@@ -449,7 +470,11 @@ simple("random-enabled",
        [],
        ["boolean", "enabled", "1 if random play is enabled and 0 otherwise"]);
 
-# TODO recent
+simple("recent",
+       "List recently played tracks",
+       "",
+       [],
+       ["queue", "recent", "Recently played tracks"]);
 
 simple("reconfigure",
        "Re-read configuraiton file.",
@@ -493,7 +518,7 @@ simple("resume",
 simple("revoke",
        "Revoke a cookie.",
        "It will not subsequently be possible to log in with the cookie.",
-       []);                     # TODO fix docs!
+       []);
 
 # TODO rtp-address