continued writing cache
[NeonServV5.git] / ChanNode.c
1 #include "ChanNode.h"
2
3 static struct ChanNode **chanList;
4
5 void init_ChanNode() {
6     /*
7      len pos chars 
8      26  0   a-z
9      10  26  0-9
10      10  36  {|}~[\]^_`
11      1   46  *everything else*
12      ---------------------------
13      = 47
14     */
15     userList = calloc(47, sizeof(*userList));
16 }
17
18 int is_valid_chan(const char *name) {
19     unsigned int ii;
20     if (*name !='#')
21         return 0;
22     for (ii=1; name[ii]; ++ii) {
23         if ((name[ii] > 0) && (name[ii] <= 32))
24             return 0;
25         if (name[ii] == ',')
26             return 0;
27         if (name[ii] == '\xa0')
28             return 0;
29     }
30     return 1;
31 }
32
33 static int get_chanlist_entry(int name) {
34     int i;
35     if((name > 0 && name <= 32) || name == ',' || name == '\xa0') return -1; //invalid name
36     if(tolower(name) >= 97 && tolower(name) <= 122) {
37         return (tolower(name) - 97);
38     }
39     if(tolower(name) >= 48 && tolower(name) <= 57) {
40         return (tolower(name) - 48 + 26);
41     }
42     /* {|}~[\]^_` */
43     if(name == '{') return 36;
44     if(name == '|') return 37;
45     if(name == '}') return 38;
46     if(name == '~') return 39;
47     if(name == '[') return 40;
48     if(name == '\\') return 41;
49     if(name == ']') return 42;
50     if(name == '^') return 43;
51     if(name == '_') return 44;
52     if(name == '`') return 45;
53     return 46;
54 }
55
56 struct ChanNode* getChanByName(const char *name) { //case insensitive
57     int chanListIndex = get_chanlist_entry(*name);
58     if(chanListIndex == -1 || chanList[chanListIndex] == NULL)
59         return NULL;
60     struct ChanNode *chan;
61     for(chan = chanList[chanListIndex]; chan; chan = chan->next) {
62         if(!stricmp(name, chan->name))
63             return chan;
64     }
65     return NULL;
66 }
67
68 struct ChanNode* addChannel(const char *chan) {
69     return NULL; //to be continued
70 }
71
72 void delChannel(struct ChanNode* chan, int freeChan) {
73     //to be continued
74 }