ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ubase64.C
Revision: 1.1
Committed: Thu Jul 19 08:24:59 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

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