ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/uid.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

# User Rev Content
1 pippijn 1.1 /*
2     * uid.C: UID management.
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     static char new_uid[9]; /* allow for \0 */
13     static unsigned int uindex = 0;
14    
15     void
16     init_uid (void)
17     {
18     unsigned int i;
19     char buf[BUFSIZE];
20    
21     if (ircd->uses_p10 == true)
22     {
23     me.numeric = sstrdup (uinttobase64 (buf, (uint64_t) atoi (me.numeric), 2));
24     uindex = 5;
25     }
26     else
27     uindex = 9;
28    
29    
30     memset (new_uid, 0, sizeof (new_uid));
31    
32     if (me.numeric != NULL)
33     memcpy (new_uid, me.numeric, strlen (me.numeric));
34     else
35     return;
36    
37     for (i = 0; i < strlen (me.numeric); i++)
38     if (new_uid[i] == '\0')
39     new_uid[i] = 'A';
40    
41     for (i = strlen (me.numeric); i < uindex; i++)
42     new_uid[i] = 'A';
43     }
44    
45     static void
46     add_one_to_uid (unsigned int i)
47     {
48     if (i != strlen (me.numeric)) /* Not reached server SID portion yet? */
49     {
50     if (new_uid[i] == 'Z')
51     new_uid[i] = '0';
52     else if (new_uid[i] == '9')
53     {
54     new_uid[i] = 'A';
55     add_one_to_uid (i - 1);
56     }
57     else
58     new_uid[i] = new_uid[i] + 1;
59     }
60     else
61     {
62     if (new_uid[i] == 'Z')
63     for (i = strlen (me.numeric); i < 9; i++)
64     new_uid[i] = 'A';
65     else
66     new_uid[i] = new_uid[i] + 1;
67     }
68     }
69    
70     char *
71     uid_get (void)
72     {
73     add_one_to_uid (uindex - 1); /* index from 0 */
74     return (new_uid);
75     }
76    
77     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
78     * vim:ts=8
79     * vim:sw=8
80     * vim:noexpandtab
81     */