ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ubase64.C
Revision: 1.5
Committed: Sun Sep 16 18:54:45 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +7 -2 lines
Log Message:
#defines to enum

File Contents

# Content
1 /*
2 * ubase64.C: ircu base64 routines.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Rights to this code are documented in doc/pod/license.pod.
10 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 */
12
13 static char const rcsid[] = "$Id: ubase64.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
14
15 #include "atheme.h"
16
17 /*
18 * base64touint() written 01/20/06 by jilles, for getting IP addresses.
19 */
20
21 static const char ub64_alphabet[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[]";
22 #define __ '\377'
23 static const char ub64_lookuptab[256] = {
24 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, /* 0-15 */
25 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, /* 16-31 */
26 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, /* 32-47 */
27 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, __, __, __, __, __, __, /* 48-63 */
28 __, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 64-79 */
29 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 62, __, 63, __, __, /* 80-95 */
30 __, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 96-111 */
31 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, __, __, __, __, __, /* 112-127 */
32 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
33 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
34 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
35 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
36 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
37 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
38 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
39 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
40 };
41
42 #undef __
43
44 char const * const
45 uinttobase64 (char *buf, uint64_t v, int64_t count)
46 {
47 buf[count] = '\0';
48
49 while (count >= 0)
50 {
51 buf[--count] = ub64_alphabet[v & 63];
52 v >>= 6;
53 }
54
55 return buf;
56 }
57
58 unsigned int
59 base64touint (char *buf)
60 {
61 int bits;
62 unsigned int v = 0;
63 int count = 6;
64
65 while (--count >= 0 && (bits = ub64_lookuptab[255 & *buf++]) != '\377')
66 v = v << 6 | bits;
67 return v;
68 }
69
70 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
71 * vim:ts=8
72 * vim:sw=8
73 * vim:noexpandtab
74 */