From: Richard Kettlewell Date: Sat, 5 Jun 2010 17:17:30 +0000 (+0100) Subject: Eliminate string_login(). X-Git-Tag: branchpoint-5.1~22^2~18 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/f4522fa75592b9508589a62dc6a503e8eed52432 Eliminate string_login(). --- diff --git a/lib/client-stubs.h b/lib/client-stubs.h index f6c32c8..19649ac 100644 --- a/lib/client-stubs.h +++ b/lib/client-stubs.h @@ -57,18 +57,22 @@ int disorder_allfiles(disorder_client *c, const char *dir, const char *re, char * * The confirmation string must have been created with 'register'. The username is returned so the caller knows who they are. * + * @param c Client * @param confirmation Confirmation string * @return 0 on success, non-0 on error */ int disorder_confirm(disorder_client *c, const char *confirmation); + /** @brief 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. * + * @param c Client * @param cookie Cookie string * @return 0 on success, non-0 on error */ int disorder_cookie(disorder_client *c, const char *cookie); + /** @brief Delete user * * Requires the 'admin' right. diff --git a/scripts/protocol b/scripts/protocol index 118fda3..7d4bbad 100755 --- a/scripts/protocol +++ b/scripts/protocol @@ -69,6 +69,8 @@ sub c_out_decl { "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"; } @@ -104,6 +106,8 @@ sub c_return_docs { " * \@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"; } @@ -182,6 +186,15 @@ 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), @@ -203,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 ---------------------------------------------------------------- @@ -304,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"]]); - -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("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"]); + +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",