/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2008 Richard Kettlewell
+ * Copyright (C) 2004-2009 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
char *v;
if(disorder_version(getclient(), &v)) exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(v)));
+ v = nullcheck(utf82mb_f(v));
+ xprintf("%s\n", v);
+ xfree(v);
}
static void print_queue_entry(const struct queue_entry *q) {
char *value;
if(disorder_get(getclient(), argv[0], argv[1], &value)) exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(value)));
+ xprintf("%s\n", nullcheck(utf82mb_f(value)));
}
static void cf_length(char **argv) {
char *s;
if(disorder_part(getclient(), &s, argv[0], argv[1], argv[2])) exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(s)));
+ xprintf("%s\n", nullcheck(utf82mb_f(s)));
}
static int isarg_filename(const char *s) {
char *track;
if(disorder_resolve(getclient(), &track, argv[0])) exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(track)));
+ xprintf("%s\n", nullcheck(utf82mb_f(track)));
}
static void cf_pause(char attribute((unused)) **argv) {
char *value;
if(disorder_get_global(getclient(), argv[0], &value)) exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(value)));
+ xprintf("%s\n", nullcheck(utf82mb_f(value)));
}
static void cf_set_global(char **argv) {
if(disorder_userinfo(getclient(), argv[0], argv[1], &s))
exit(EXIT_FAILURE);
- xprintf("%s\n", nullcheck(utf82mb(s)));
+ xprintf("%s\n", nullcheck(utf82mb_f(s)));
}
static int isarg_option(const char *arg) {
TRACKDB=trackdb-stub.c
endif
-libdisorder_a_SOURCES=charset.c charset.h \
+libdisorder_a_SOURCES=charset.c charsetf.c charset.h \
addr.c addr.h \
arcfour.c arcfour.h \
authhash.c authhash.h \
/*
* This file is part of DisOrder
- * Copyright (C) 2004-2008 Richard Kettlewell
+ * Copyright (C) 2004-2009 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
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2006, 2007 Richard Kettlewell
+ * Copyright (C) 2004, 2006, 2007, 2009 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
* Computes H(challenge|password) and returns it as a newly allocated hex
* string, or returns NULL on error.
*/
-const char *authhash(const void *challenge, size_t nchallenge,
- const char *password, const char *algo) {
+char *authhash(const void *challenge, size_t nchallenge,
+ const char *password, const char *algo) {
gcrypt_hash_handle h;
- const char *res;
+ char *res;
size_t n;
int id;
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2006, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2006-2009 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
#ifndef AUTHHASH_H
#define AUTHHASH_H
-const char *authhash(const void *challenge, size_t nchallenge,
- const char *user, const char *algo);
+char *authhash(const void *challenge, size_t nchallenge,
+ const char *user, const char *algo);
int valid_authhash(const char *algo);
#endif /* AUTHHASH_H */
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-2009 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
* that iconv knows. If FROM and TO are both 0 then ANY is returned
* unchanged. */
+char *mb2utf8_f(char *mb);
+char *utf82mb_f(char *utf8);
+char *any2utf8_f(const char *from/*encoding*/,
+ char *any/*string*/);
+char *any2mb_f(const char *from/*encoding or 0*/,
+ char *any/*string*/);
+char *any2any_f(const char *from/*encoding or 0*/,
+ const char *to/*encoding to 0*/,
+ char *any/*string*/);
+
/** @brief Insist that @p s is not null
* @param s Pointer to check
* @return @p s
--- /dev/null
+/*
+ * This file is part of DisOrder.
+ * Copyright (C) 2004, 2005, 2007, 2008 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+/** @file lib/charsetf.c @brief Character set conversion with free() */
+
+#include "common.h"
+
+#include "charset.h"
+#include "mem.h"
+
+char *mb2utf8_f(char *mb) {
+ char *s = mb2utf8(mb);
+ xfree(mb);
+ return s;
+}
+
+char *utf82mb_f(char *utf8) {
+ char *s = utf82mb(utf8);
+ xfree(utf8);
+ return s;
+}
+
+char *any2utf8_f(const char *from,
+ char *any) {
+ char *s = any2utf8(from, any);
+ xfree(any);
+ return s;
+}
+
+char *any2mb_f(const char *from,
+ char *any) {
+ char *s = any2mb(from, any);
+ xfree(any);
+ return s;
+}
+
+char *any2any_f(const char *from,
+ const char *to,
+ char *any) {
+ char *s = any2any(from, to, any);
+ xfree(any);
+ return s;
+}
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2006, 2007, 2009 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
strcpy(su.sun_path, name);
sa = (struct sockaddr *)&su;
len = sizeof su;
+ xfree(name);
}
*sap = xmalloc_noptr(len);
memcpy(*sap, sa, len);
/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2008 Richard Kettlewell
+ * Copyright (C) 2004-2009 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
else if(rc / 100 == 2) {
if(rp)
*rp = (rc % 10 == 9) ? 0 : xstrdup(r + 4);
+ xfree(r);
return 0;
} else {
if(c->verbose)
disorder_error(0, "from %s: %s", c->ident, utf82mb(r));
+ xfree(r);
return rc;
}
}
D(("command: %s", d.vec));
if(fputs(d.vec, c->fpout) < 0)
goto write_error;
+ xfree(d.vec);
if(body) {
if(nbody < 0)
for(nbody = 0; body[nbody]; ++nbody)
if(!rc) {
if((rr = split(*rp, 0, SPLIT_QUOTES, 0, 0)) && *rr) {
+ xfree(*rp);
*rp = *rr;
+ xfree(rr);
return 0;
}
disorder_error(0, "invalid reply: %s", *rp);
const char *username,
const char *password,
const char *cookie) {
- int fd = -1, fd2 = -1, nrvec, rc;
- unsigned char *nonce;
+ int fd = -1, fd2 = -1, nrvec = 0, rc;
+ unsigned char *nonce = NULL;
size_t nl;
- const char *res;
- char *r, **rvec;
+ char *res = NULL;
+ char *r = NULL, **rvec = NULL;
const char *protocol, *algorithm, *challenge;
- struct sockaddr *sa;
+ struct sockaddr *sa = NULL;
socklen_t salen;
if((salen = find_server(conf, &sa, &c->ident)) == (socklen_t)-1)
disorder_error(0, "cannot parse server greeting %s", r);
goto error;
}
- protocol = *rvec++;
+ protocol = rvec[0];
if(strcmp(protocol, "2")) {
c->last = "unknown protocol version";
disorder_error(0, "unknown protocol version: %s", protocol);
goto error;
}
- algorithm = *rvec++;
- challenge = *rvec++;
+ algorithm = rvec[1];
+ challenge = rvec[2];
if(!(nonce = unhex(challenge, &nl)))
goto error;
if(cookie) {
if((rc = disorder_simple(c, 0, "user", username, res, (char *)0)))
goto error_rc;
c->user = xstrdup(username);
+ xfree(res);
+ free_strings(nrvec, rvec);
+ xfree(nonce);
+ xfree(sa);
+ xfree(r);
return 0;
error:
rc = -1;
}
c->fpout = 0;
}
+ xfree(c->ident);
c->ident = 0;
+ xfree(c->user);
c->user = 0;
return 0;
}
/*
* This file is part of DisOrder
- * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2007-2009 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
#include "printf.h"
#include "sink.h"
+#include "mem.h"
/** @brief vfprintf() workalike that always accepts UTF-8
* @param fp Stream to write to
* @return -1 on error or bytes written on success
*/
int byte_vfprintf(FILE *fp, const char *fmt, va_list ap) {
- return byte_vsinkprintf(sink_stdio(0, fp), fmt, ap);
+ struct sink *s = sink_stdio(0, fp);
+ int rc = byte_vsinkprintf(s, fmt, ap);
+ xfree(s);
+ return rc;
}
/** @brief fprintf() workalike that always accepts UTF-8
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2007-2009 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
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-2009 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