X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/637fdea366a8a87024322d283eba89067a403493..f0feb22e80bfe438c16d212a7cc8be6d2282b6ac:/lib/client.c diff --git a/lib/client.c b/lib/client.c index 979e54a..e4e28e8 100644 --- a/lib/client.c +++ b/lib/client.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2004, 2005, 2006 Richard Kettlewell + * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell * * 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 @@ -31,6 +31,7 @@ #include #include #include +#include #include "log.h" #include "mem.h" @@ -49,6 +50,7 @@ #include "addr.h" #include "authhash.h" #include "client-common.h" +#include "trackdb.h" struct disorder_client { FILE *fpin, *fpout; @@ -154,22 +156,24 @@ static int connect_sock(void *vc, const char *ident) { const char *username, *password; disorder_client *c = vc; - int n; if(!(username = config->username)) { error(0, "no username configured"); return -1; } - if(!(password = config->password)) { - for(n = 0; (n < config->allow.n - && strcmp(config->allow.s[n].s[0], username)); ++n) - ; - if(n < config->allow.n) - password = config->allow.s[n].s[1]; - else { - error(0, "no password configured"); - return -1; - } + password = config->password; + if(!password) { + /* Maybe we can read the database */ + /* TODO failure to open the database should not be fatal */ + trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE); + trackdb_open(TRACKDB_READ_ONLY); + password = trackdb_get_password(username); + trackdb_close(); + } + if(!password) { + /* Oh well */ + error(0, "no password configured"); + return -1; } return disorder_connect_sock(c, sa, len, username, password, ident); } @@ -600,6 +604,22 @@ int disorder_tags(disorder_client *c, return disorder_simple_list(c, vecp, nvecp, "tags", (char *)0); } +/** @brief Get recentl added tracks + * @param c Client + * @param vecp Where to store pointer to list + * @param nvecp Where to store count + * @param max Maximum tracks to fetch, or 0 for all available + * @return 0 on success, non-0 on error + */ +int disorder_new_tracks(disorder_client *c, + char ***vecp, int *nvecp, + int max) { + char limit[32]; + + sprintf(limit, "%d", max); + return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0); +} + int disorder_set_global(disorder_client *c, const char *key, const char *value) { return disorder_simple(c, 0, "set-global", key, value, (char *)0); @@ -613,6 +633,32 @@ int disorder_get_global(disorder_client *c, const char *key, char **valuep) { return disorder_simple(c, valuep, "get-global", key, (char *)0); } +int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) { + char *r; + int rc, n; + char **vec; + + if((rc = disorder_simple(c, &r, "rtp-address", (char *)0))) + return rc; + vec = split(r, &n, SPLIT_QUOTES, 0, 0); + if(n != 2) { + error(0, "malformed rtp-address reply"); + return -1; + } + *addressp = vec[0]; + *portp = vec[1]; + return 0; +} + +int disorder_adduser(disorder_client *c, + const char *user, const char *password) { + return disorder_simple(c, 0, "adduser", user, password, (char *)0); +} + +int disorder_deluser(disorder_client *c, const char *user) { + return disorder_simple(c, 0, "deluser", user, (char *)0); +} + /* Local Variables: c-basic-offset:2