chiark / gitweb /
Split base64 code into a separate .c so that the server doesn't pull
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 22 Dec 2007 12:39:44 +0000 (12:39 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 22 Dec 2007 12:39:44 +0000 (12:39 +0000)
in rest of the MIME code.

Correct computation of legacy user rights.

doc/disorder_protocol.5.in
lib/Makefile.am
lib/base64.c [new file with mode: 0644]
lib/base64.h [new file with mode: 0644]
lib/cookies.c
lib/mime.c
lib/mime.h
lib/test.c
lib/trackdb.c
server/server.c

index cd3a20a6f8732592639287214ef15ac50cf20c7f..15c83967c52e5a64a79aa76747bf7148bc4b4cba 100644 (file)
@@ -172,7 +172,7 @@ or
 .BR title .
 .TP
 .B pause
-Pause the current track.  Requires the \fBpause\R right.
+Pause the current track.  Requires the \fBpause\fR right.
 .TP
 .B play \fITRACK\fR
 Add a track to the queue.  The response contains the queue ID of the track.
index 1cbb7bf144e9b89c49dba021cd9f936d2079a1c6..a7ddf48bfe1a644a0fa5b933765f26e17c676ab9 100644 (file)
@@ -26,6 +26,7 @@ libdisorder_a_SOURCES=charset.c charset.h             \
        addr.c addr.h                                   \
        authhash.c authhash.h                           \
        basen.c basen.h                                 \
+       base64.c base64.h                               \
        cache.c cache.h                                 \
        client.c client.h                               \
        client-common.c client-common.h                 \
diff --git a/lib/base64.c b/lib/base64.c
new file mode 100644 (file)
index 0000000..8015b1a
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * This file is part of DisOrder
+ * Copyright (C) 2005, 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
+ * the Free Software Foundation; either version 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+/** @file lib/base64.c
+ * @brief Support for MIME base64
+ */
+
+#include <config.h>
+#include "types.h"
+
+#include <string.h>
+
+#include <stdio.h>
+
+#include "mem.h"
+#include "base64.h"
+#include "vector.h"
+
+static const char mime_base64_table[] =
+  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+/** @brief Convert MIME base64
+ * @param s base64 data
+ * @return Decoded data
+ */
+char *mime_base64(const char *s, size_t *nsp) {
+  struct dynstr d;
+  const char *t;
+  int b[4], n, c;
+
+  dynstr_init(&d);
+  n = 0;
+  while((c = (unsigned char)*s++)) {
+    if((t = strchr(mime_base64_table, c))) {
+      b[n++] = t - mime_base64_table;
+      if(n == 4) {
+       dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
+       dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
+       dynstr_append(&d, (b[2] << 6) + b[3]);
+       n = 0;
+      }
+    } else if(c == '=') {
+      if(n >= 2) {
+       dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
+       if(n == 3)
+         dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
+      }
+      break;
+    }
+  }
+  if(nsp)
+    *nsp = d.nvec;
+  dynstr_terminate(&d);
+  return d.vec;
+}
+
+/** @brief Convert a binary string to base64
+ * @param s Bytes to convert
+ * @param ns Number of bytes to convert
+ * @return Encoded data
+ *
+ * This function does not attempt to split up lines.
+ */
+char *mime_to_base64(const uint8_t *s, size_t ns) {
+  struct dynstr d[1];
+
+  dynstr_init(d);
+  while(ns >= 3) {
+    /* Input bytes with output bits: AAAAAABB BBBBCCCC CCDDDDDD */
+    /* Output bytes with input bits: 000000 001111 111122 222222 */
+    dynstr_append(d, mime_base64_table[s[0] >> 2]);
+    dynstr_append(d, mime_base64_table[((s[0] & 3) << 4)
+                                      + (s[1] >> 4)]);
+    dynstr_append(d, mime_base64_table[((s[1] & 15) << 2)
+                                      + (s[2] >> 6)]);
+    dynstr_append(d, mime_base64_table[s[2] & 63]);
+    ns -= 3;
+    s += 3;
+  }
+  if(ns > 0) {
+    dynstr_append(d, mime_base64_table[s[0] >> 2]);
+    switch(ns) {
+    case 1:
+      dynstr_append(d, mime_base64_table[(s[0] & 3) << 4]);
+      dynstr_append(d, '=');
+      dynstr_append(d, '=');
+      break;
+    case 2:
+      dynstr_append(d, mime_base64_table[((s[0] & 3) << 4)
+                                        + (s[1] >> 4)]);
+      dynstr_append(d, mime_base64_table[(s[1] & 15) << 2]);
+      dynstr_append(d, '=');
+      break;
+    }
+  }
+  dynstr_terminate(d);
+  return d->vec;
+}
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+End:
+*/
diff --git a/lib/base64.h b/lib/base64.h
new file mode 100644 (file)
index 0000000..a2c20e6
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * This file is part of DisOrder
+ * Copyright (C) 2005, 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
+ * the Free Software Foundation; either version 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+/** @file lib/base64.h
+ * @brief Support for MIME base64
+ */
+
+#ifndef BASE64_H
+#define BASE64_H
+
+char *mime_base64(const char *s, size_t *nsp);
+char *mime_to_base64(const uint8_t *s, size_t ns);
+
+#endif /* BASE64_H */
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+End:
+*/
index 425b84c8b91c3ea24508a59296c861ca1f1b30a3..bc8e9b087a3021388c420e0666aff60909f75d85 100644 (file)
@@ -38,7 +38,7 @@
 #include "mem.h"
 #include "log.h"
 #include "printf.h"
-#include "mime.h"
+#include "base64.h"
 #include "configuration.h"
 #include "kvp.h"
 #include "rights.h"
index 87fc43a9db8bec63570b3acfe5fafd3e3e72840b..7575b7bbf324ab23a20b690ff389e74261736ab2 100644 (file)
@@ -34,6 +34,7 @@
 #include "vector.h"
 #include "hex.h"
 #include "log.h"
+#include "base64.h"
 
 /** @brief Match whitespace characters */
 static int whitespace(int c) {
@@ -431,87 +432,6 @@ char *mime_qp(const char *s) {
   return d.vec;
 }
 
-static const char mime_base64_table[] =
-  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-/** @brief Convert MIME base64
- * @param s base64 data
- * @return Decoded data
- */
-char *mime_base64(const char *s, size_t *nsp) {
-  struct dynstr d;
-  const char *t;
-  int b[4], n, c;
-
-  dynstr_init(&d);
-  n = 0;
-  while((c = (unsigned char)*s++)) {
-    if((t = strchr(mime_base64_table, c))) {
-      b[n++] = t - mime_base64_table;
-      if(n == 4) {
-       dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
-       dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
-       dynstr_append(&d, (b[2] << 6) + b[3]);
-       n = 0;
-      }
-    } else if(c == '=') {
-      if(n >= 2) {
-       dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
-       if(n == 3)
-         dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
-      }
-      break;
-    }
-  }
-  if(nsp)
-    *nsp = d.nvec;
-  dynstr_terminate(&d);
-  return d.vec;
-}
-
-/** @brief Convert a binary string to base64
- * @param s Bytes to convert
- * @param ns Number of bytes to convert
- * @return Encoded data
- *
- * This function does not attempt to split up lines.
- */
-char *mime_to_base64(const uint8_t *s, size_t ns) {
-  struct dynstr d[1];
-
-  dynstr_init(d);
-  while(ns >= 3) {
-    /* Input bytes with output bits: AAAAAABB BBBBCCCC CCDDDDDD */
-    /* Output bytes with input bits: 000000 001111 111122 222222 */
-    dynstr_append(d, mime_base64_table[s[0] >> 2]);
-    dynstr_append(d, mime_base64_table[((s[0] & 3) << 4)
-                                      + (s[1] >> 4)]);
-    dynstr_append(d, mime_base64_table[((s[1] & 15) << 2)
-                                      + (s[2] >> 6)]);
-    dynstr_append(d, mime_base64_table[s[2] & 63]);
-    ns -= 3;
-    s += 3;
-  }
-  if(ns > 0) {
-    dynstr_append(d, mime_base64_table[s[0] >> 2]);
-    switch(ns) {
-    case 1:
-      dynstr_append(d, mime_base64_table[(s[0] & 3) << 4]);
-      dynstr_append(d, '=');
-      dynstr_append(d, '=');
-      break;
-    case 2:
-      dynstr_append(d, mime_base64_table[((s[0] & 3) << 4)
-                                        + (s[1] >> 4)]);
-      dynstr_append(d, mime_base64_table[(s[1] & 15) << 2]);
-      dynstr_append(d, '=');
-      break;
-    }
-  }
-  dynstr_terminate(d);
-  return d->vec;
-}
-
 /** @brief Parse a RFC2109 Cookie: header
  * @param s Header field value
  * @param cd Where to store result
index b6d21ce3b34d3aa379c7410912f6c72da9063c8a..b2286be89f0e34ade5375f5032cdb2411b20035c 100644 (file)
@@ -54,9 +54,6 @@ int mime_rfc2388_content_disposition(const char *s,
 /* Parse an RFC2388-style content-disposition field */
 
 char *mime_qp(const char *s);
-char *mime_base64(const char *s, size_t *nsp);
-char *mime_to_base64(const uint8_t *s, size_t ns);
-/* convert quoted-printable or base64 data */
 
 /** @brief Parsed form of an HTTP Cookie: header field */
 struct cookiedata {
index c3e4c345b508c3199559b311107c665d7c2cf783..0f38fc368547382786e558678295c4c45b304d32 100644 (file)
@@ -61,6 +61,7 @@
 #include "split.h"
 #include "configuration.h"
 #include "addr.h"
+#include "base64.h"
 
 static int tests, errors;
 static int fail_first;
index dc4cd4eda49009de2a41cd90426e5dd56bdcc309..e030665116e6ffb380ef20c14679e5d0d99a15b3 100644 (file)
@@ -64,7 +64,7 @@
 #include "hash.h"
 #include "unicode.h"
 #include "unidata.h"
-#include "mime.h"
+#include "base64.h"
 
 #define RESCAN "disorder-rescan"
 #define DEADLOCK "disorder-deadlock"
@@ -2493,7 +2493,7 @@ static int one_old_user(const char *user, const char *password,
     rights_type r;
 
     parse_rights(config->default_rights, &r, 1);
-    r &= (RIGHT_SCRATCH__MASK|RIGHT_MOVE__MASK|RIGHT_REMOVE__MASK);
+    r &= ~(rights_type)(RIGHT_SCRATCH__MASK|RIGHT_MOVE__MASK|RIGHT_REMOVE__MASK);
     r |= (RIGHT_ADMIN|RIGHT_RESCAN
           |RIGHT_SCRATCH_ANY|RIGHT_MOVE_ANY|RIGHT_REMOVE_ANY);
     rights = rights_string(r);
index a69c45194a285815a7184de59d69d5ab3739c77c..54dfe556e9f8d38b01ab69cd4e09856bba3604d3 100644 (file)
@@ -66,7 +66,7 @@
 #include "cache.h"
 #include "unicode.h"
 #include "cookies.h"
-#include "mime.h"
+#include "base64.h"
 
 #ifndef NONCE_SIZE
 # define NONCE_SIZE 16