ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/uid.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 * uid.C: UID management.
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: uid.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
14
15 #include "atheme.h"
16
17 static char new_uid[9]; /* allow for \0 */
18 static unsigned int uindex = 0;
19
20 void
21 init_uid (void)
22 {
23 unsigned int i;
24 char buf[BUFSIZE];
25
26 if (ircd->uses_p10 == true)
27 {
28 me.numeric = sstrdup (uinttobase64 (buf, atoi (me.numeric), 2));
29 uindex = 5;
30 }
31 else
32 uindex = 9;
33
34
35 memset (new_uid, 0, sizeof (new_uid));
36
37 if (me.numeric != NULL)
38 memcpy (new_uid, me.numeric, strlen (me.numeric));
39 else
40 return;
41
42 for (i = 0; i < strlen (me.numeric); i++)
43 if (new_uid[i] == '\0')
44 new_uid[i] = 'A';
45
46 for (i = strlen (me.numeric); i < uindex; i++)
47 new_uid[i] = 'A';
48 }
49
50 static void
51 add_one_to_uid (unsigned int i)
52 {
53 if (i != strlen (me.numeric)) /* Not reached server SID portion yet? */
54 {
55 if (new_uid[i] == 'Z')
56 new_uid[i] = '0';
57 else if (new_uid[i] == '9')
58 {
59 new_uid[i] = 'A';
60 add_one_to_uid (i - 1);
61 }
62 else
63 new_uid[i] = new_uid[i] + 1;
64 }
65 else
66 {
67 if (new_uid[i] == 'Z')
68 for (i = strlen (me.numeric); i < 9; i++)
69 new_uid[i] = 'A';
70 else
71 new_uid[i] = new_uid[i] + 1;
72 }
73 }
74
75 char *
76 uid_get (void)
77 {
78 add_one_to_uid (uindex - 1); /* index from 0 */
79 return (new_uid);
80 }