-
Notifications
You must be signed in to change notification settings - Fork 1
/
channel_list.c
127 lines (102 loc) · 2.83 KB
/
channel_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "channel_list.h"
char codecs[13][12] = {
"CELP 5.1",
"CELP 6.3",
"GSM 14.8",
"GSM 16.4",
"CELPWin 5.2",
"Speex 3.4",
"Speex 5.2",
"Speex 7.2",
"Speex 9.3",
"Speex 12.3",
"Speex 16.3",
"Speex 19.6",
"Speex 25.9"
};
static void print_channel(struct channel * ch) {
printf(" id: %i\n", ch->id);
printf(" name: %s\n", ch->name);
printf(" flags: ");
if(ch->flags & CHANNEL_FLAG_UNREGISTERED)
printf("U");
else
printf("R");
if(ch->flags & CHANNEL_FLAG_MODERATED)
printf("M");
if(ch->flags & CHANNEL_FLAG_PASSWORD)
printf("P");
if(ch->flags & CHANNEL_FLAG_SUBCHANNELS)
printf("S");
if(ch->flags & CHANNEL_FLAG_DEFAULT)
printf("D");
printf("\n");
printf(" codec: %s\n", codecs[ch->codec]);
printf(" max users : %i\n", ch->max_users);
printf(" topic: %s\n", ch->topic);
printf(" desc: %s\n", ch->desc);
}
void print_channel_list(struct channel_list * chl) {
int i;
printf("Channel list : (%i channels)\n", chl->size);
for(i = 0 ; i<chl->size ; i++) {
print_channel(& (chl->channels[i]));
}
}
static void destroy_channel(struct channel * ch) {
free(ch->name);
free(ch->topic);
free(ch->desc);
free(ch);
}
void destroy_channel_list(struct channel_list * ch) {
int i;
for(i=0 ; i < ch->size ; i++) {
destroy_channel(& ch->channels[i]);
}
free(ch);
}
void * decode_channel(void * data, struct channel * ch) {
void * ptr = (char *)data;
int len;
ch->id = GUINT32_FROM_LE(* (uint32_t *)ptr);
ptr = (uint32_t *)ptr +1;
ch->flags = GUINT16_FROM_LE(* (uint16_t *)ptr);
ptr = (uint16_t *)ptr +1;
ch->codec = GUINT16_FROM_LE(* (uint16_t *)ptr);
ptr = (uint16_t *)ptr +1;
ptr = (uint32_t *)ptr +1; /* jump over ffffffff */
ch->sort_order = GUINT16_FROM_LE(* (uint16_t *)ptr);
ptr = (uint16_t *)ptr +1;
ch->max_users = GUINT16_FROM_LE(* (uint16_t *)ptr);
ptr = (uint16_t *)ptr +1;
len = strlen((char *)ptr);
ch->name = (char *)calloc(len+1, 1);
strcpy(ch->name, (char *)ptr);
ptr = (char *)ptr + len+1;
len = strlen((char *)ptr);
ch->topic = (char *)calloc(len+1, 1);
strcpy(ch->topic, (char *)ptr);
ptr = (char *)ptr + len+1;
len = strlen((char *)ptr);
ch->desc = (char *)calloc(len+1, 1);
strcpy(ch->desc, (char *)ptr);
ptr = (char *)ptr + len+1;
return ptr;
}
struct channel_list * decode_channel_list(void * data) {
void * ptr = data;
struct channel_list * chl;
int i;
chl = (struct channel_list *)calloc(sizeof(struct channel_list), 1);
/* skip the header */
ptr = (uint32_t *) ptr + 6;
chl->size = GUINT32_FROM_LE(* ((uint32_t *) ptr));
ptr = (uint32_t *) ptr +1;
chl->channels = (struct channel *)calloc(sizeof(struct channel), chl->size);
for(i=0 ; i < chl->size ; i++) {
ptr = decode_channel(ptr, chl->channels+i);
}
/* print_channel_list(chl);*/
return chl;
}