]> git.sur5r.net Git - ngadmin/blob - lib/src/bitrate.c
50dfb769dd5dac7283476ca2d9c3db4b84bfbecd
[ngadmin] / lib / src / bitrate.c
1
2 #include <ngadmin.h>
3
4 #include <nsdp/attr.h>
5 #include <nsdp/protocol.h>
6
7 #include "lib.h"
8 #include "network.h"
9
10
11 int ngadmin_getStormFilterState (struct ngadmin *nga, int *s)
12 {
13         List *attr;
14         struct attr *at;
15         int ret = ERR_OK;
16         
17         
18         if (nga == NULL || s == NULL)
19                 return ERR_INVARG;
20         else if (nga->current == NULL)
21                 return ERR_NOTLOG;
22         
23         
24         attr = createEmptyList();
25         pushBackList(attr, newEmptyAttr(ATTR_STORM_ENABLE));
26         ret = readRequest(nga, attr);
27         if (ret != ERR_OK)
28                 goto end;
29         
30         filterAttributes(attr, ATTR_STORM_ENABLE, ATTR_END);
31         
32         *s = 0;
33         
34         if (attr->first != NULL) {
35                 at = attr->first->data;
36                 *s = *(char*)at->data;
37         }
38         
39         
40 end:
41         destroyList(attr, (void(*)(void*))freeAttr);
42         
43         
44         return ret;
45 }
46
47
48 int ngadmin_setStormFilterState (struct ngadmin *nga, int s)
49 {
50         List *attr;
51         
52         
53         attr = createEmptyList();
54         pushBackList(attr, newByteAttr(ATTR_STORM_ENABLE, s != 0));
55         
56         
57         return writeRequest(nga, attr);
58 }
59
60
61 int ngadmin_getStormFilterValues (struct ngadmin *nga, int *ports)
62 {
63         List *attr;
64         ListNode *ln;
65         struct attr *at;
66         int ret = ERR_OK, port;
67         struct attr_bitrate *sb;
68         
69         
70         if (nga == NULL || ports == NULL)
71                 return ERR_INVARG;
72         else if (nga->current == NULL)
73                 return ERR_NOTLOG;
74         
75         
76         attr = createEmptyList();
77         pushBackList(attr, newEmptyAttr(ATTR_STORM_BITRATE));
78         ret = readRequest(nga, attr);
79         if (ret != ERR_OK)
80                 goto end;
81         
82         filterAttributes(attr, ATTR_STORM_BITRATE, ATTR_END);
83         
84         for (port = 0; port < nga->current->ports; port++)
85                 ports[port] = BITRATE_UNSPEC;
86         
87         for (ln = attr->first; ln != NULL; ln = ln->next) {
88                 at = ln->data;
89                 sb = at->data;
90                 ports[sb->port - 1] = sb->bitrate;
91         }
92         
93         
94 end:
95         destroyList(attr, (void(*)(void*))freeAttr);
96         
97         
98         return ret;
99 }
100
101
102 int ngadmin_setStormFilterValues (struct ngadmin *nga, const int *ports)
103 {
104         List *attr;
105         int port;
106         struct attr_bitrate *sb;
107         
108         
109         if (nga == NULL || ports == NULL)
110                 return ERR_INVARG;
111         else if (nga->current == NULL)
112                 return ERR_NOTLOG;
113         
114         
115         attr = createEmptyList();
116         
117         for (port = 0; port < nga->current->ports; port++) {
118                 if (ports[port] != BITRATE_UNSPEC) {
119                         sb = malloc(sizeof(struct attr_bitrate));
120                         if (sb == NULL)
121                                 return ERR_MEM;
122                         sb->port = port + 1;
123                         sb->bitrate = ports[port];
124                         pushBackList(attr, newAttr(ATTR_STORM_BITRATE, sizeof(struct attr_bitrate), sb));
125                 }
126         }
127         
128         return writeRequest(nga, attr);
129 }
130
131
132 int ngadmin_getBitrateLimits (struct ngadmin *nga, int *ports)
133 {
134         List *attr;
135         ListNode *ln;
136         struct attr *at;
137         int ret = ERR_OK, port;
138         struct attr_bitrate *pb;
139         
140         
141         if (nga == NULL || ports == NULL)
142                 return ERR_INVARG;
143         else if (nga->current == NULL)
144                 return ERR_NOTLOG;
145         
146         
147         attr = createEmptyList();
148         pushBackList(attr, newEmptyAttr(ATTR_BITRATE_INPUT));
149         pushBackList(attr, newEmptyAttr(ATTR_BITRATE_OUTPUT));
150         ret = readRequest(nga, attr);
151         if (ret != ERR_OK)
152                 goto end;
153         
154         
155         for (port = 0; port < nga->current->ports; port++) {
156                 ports[2 * port + 0] = BITRATE_UNSPEC;
157                 ports[2 * port + 1] = BITRATE_UNSPEC;
158         }
159         
160         for (ln = attr->first; ln != NULL; ln = ln->next) {
161                 at = ln->data;
162                 pb = at->data;
163                 if (at->attr == ATTR_BITRATE_INPUT)
164                         ports[(pb->port - 1) * 2 + 0] = pb->bitrate;
165                 else if (at->attr == ATTR_BITRATE_OUTPUT)
166                         ports[(pb->port - 1) * 2 + 1] = pb->bitrate;
167         }
168         
169         
170 end:
171         destroyList(attr, (void(*)(void*))freeAttr);
172         
173         return ret;
174 }
175
176
177 int ngadmin_setBitrateLimits (struct ngadmin *nga, const int *ports)
178 {
179         List *attr;
180         int port;
181         struct attr_bitrate *pb;
182         
183         
184         if (nga == NULL || ports == NULL)
185                 return ERR_INVARG;
186         else if (nga->current == NULL)
187                 return ERR_NOTLOG;
188         
189         
190         attr = createEmptyList();
191         
192         for (port = 0; port < nga->current->ports; port++) {
193                 if (ports[2 * port + 0] >= BITRATE_NOLIMIT && ports[2 * port + 0] <= BITRATE_512M) {
194                         pb = malloc(sizeof(struct attr_bitrate));
195                         if (pb == NULL)
196                                 return ERR_MEM;
197                         pb->port = port + 1;
198                         pb->bitrate = ports[2 * port + 0];
199                         pushBackList(attr, newAttr(ATTR_BITRATE_INPUT, sizeof(struct attr_bitrate), pb));
200                 }
201                 if (ports[2 * port + 1] >= BITRATE_NOLIMIT && ports[2 * port + 1] <= BITRATE_512M) {
202                         pb = malloc(sizeof(struct attr_bitrate));
203                         if (pb == NULL)
204                                 return ERR_MEM;
205                         pb->port = port + 1;
206                         pb->bitrate = ports[2 * port + 1];
207                         pushBackList(attr, newAttr(ATTR_BITRATE_OUTPUT, sizeof(struct attr_bitrate), pb));
208                 }
209         }
210         
211         
212         return writeRequest(nga, attr);
213 }
214
215