source: trunk/oscam-conf-chk.c@ 8358

Last change on this file since 8358 was 8358, checked in by TNe-TWo, 9 years ago

cleanup/move cache settings
http://www.streamboard.tv/wbb2/thread.php?threadid=37089

cacheex mode 1 same dyn wait time as mode2/3/csp.
(one for all mode/csp)

fix that not only fallback rdr ask on stage 4
fix reader stat, to add only real rdr time to stat, when have wait_time
add real rdr time to log, when have wait_time

parameter change overview

[global] cachedelay -> [cache] delay
[global] max_cache_time -> [cache] max_time
[global] max_cache_count -> [cache] max_count
[global] cacheexenablestats -> [cache] cacheexenablestats
[csp] wait_time -> [cache] wait_time
[csp] port -> [cache] csp_port
[csp] serverip -> [cache] csp_serverip
[csp] csp_ecm_filter -> [cache] csp_ecm_filter
[csp] csp_allow_request -> [cache] csp_allow_request

File size: 10.8 KB
Line 
1#include "globals.h"
2#include "oscam-conf-chk.h"
3#include "oscam-garbage.h"
4#include "oscam-net.h"
5#include "oscam-string.h"
6
7void chk_iprange(char *value, struct s_ip **base)
8{
9 int32_t i = 0;
10 char *ptr1, *ptr2, *saveptr1 = NULL;
11 struct s_ip *fip, *lip, *cip;
12
13 if (!cs_malloc(&cip, sizeof(struct s_ip)))
14 return;
15 fip = cip;
16
17 for (ptr1=strtok_r(value, ",", &saveptr1); ptr1; ptr1=strtok_r(NULL, ",", &saveptr1)) {
18 if (i == 0)
19 ++i;
20 else {
21 if (!cs_malloc(&cip, sizeof(struct s_ip)))
22 break;
23 lip->next = cip;
24 }
25
26 if( (ptr2=strchr(trim(ptr1), '-')) ) {
27 *ptr2++ ='\0';
28 cs_inet_addr(trim(ptr1), &cip->ip[0]);
29 cs_inet_addr(trim(ptr2), &cip->ip[1]);
30 } else {
31 cs_inet_addr(ptr1, &cip->ip[0]);
32 IP_ASSIGN(cip->ip[1], cip->ip[0]);
33 }
34 lip = cip;
35 }
36 lip = *base;
37 *base = fip;
38 clear_sip(&lip);
39}
40
41void chk_caidtab(char *caidasc, CAIDTAB *ctab)
42{
43 int32_t i;
44 char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL;
45 CAIDTAB newctab;
46 memset(&newctab, 0, sizeof(CAIDTAB));
47 for (i = 1; i < CS_MAXCAIDTAB; newctab.mask[i++] = 0xffff);
48
49 for (i = 0, ptr1 = strtok_r(caidasc, ",", &saveptr1); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) {
50 uint32_t caid, mask, cmap;
51 if( (ptr3 = strchr(trim(ptr1), ':')) )
52 *ptr3++ = '\0';
53 else
54 ptr3 = "";
55
56 if( (ptr2 = strchr(trim(ptr1), '&')) )
57 *ptr2++ = '\0';
58 else
59 ptr2 = "";
60
61 if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
62 newctab.caid[i] = caid;
63 newctab.mask[i] = mask;
64 newctab.cmap[i++] = cmap;
65 }
66 }
67 memcpy(ctab, &newctab, sizeof(CAIDTAB));
68}
69
70void chk_caidvaluetab(char *lbrlt, CAIDVALUETAB *tab, int32_t minvalue)
71{
72 int32_t i;
73 char *ptr1, *ptr2, *saveptr1 = NULL;
74 CAIDVALUETAB newtab;
75 memset(&newtab, 0, sizeof(CAIDVALUETAB));
76
77 for (i = 0, ptr1 = strtok_r(lbrlt, ",", &saveptr1); (i < CS_MAX_CAIDVALUETAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) {
78 int32_t caid, value;
79
80 if( (ptr2 = strchr(trim(ptr1), ':')) )
81 *ptr2++ = '\0';
82 else
83 ptr2 = "";
84
85 if (((caid = a2i(ptr1, 2)) < 0xFFFF) | ((value = atoi(ptr2)) < 10000)) {
86 newtab.caid[i] = caid;
87 if (value < minvalue) value = minvalue;
88 newtab.value[i] = value;
89 newtab.n = ++i;
90 }
91 }
92 memcpy(tab, &newtab, sizeof(CAIDVALUETAB));
93}
94
95#ifdef CS_CACHEEX
96void chk_cacheex_valuetab(char *lbrlt, CECSPVALUETAB *tab) {
97 //[caid][&mask][@provid][$servid][:awtime][:]dwtime
98 int32_t i;
99 char *ptr = NULL, *saveptr1 = NULL;
100 CECSPVALUETAB newtab;
101 memset(&newtab, 0, sizeof(CECSPVALUETAB));
102
103 for (i = 0, ptr = strtok_r(lbrlt, ",", &saveptr1); (i < CS_MAXCAIDTAB) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1),i++) {
104 int32_t caid=-1, cmask=-1, srvid = -1;
105 int32_t j,provid = -1;
106 int16_t awtime=-1, dwtime = -1;
107 char *ptr1 = NULL, *ptr2 = NULL, *ptr3 = NULL, *ptr4 = NULL, *ptr5 = NULL, *saveptr2 = NULL;
108
109 if( (ptr4 = strchr(trim(ptr), ':')) ) {
110 //awtime & dwtime
111 *ptr4++ = '\0';
112 for (j = 0, ptr5 = strtok_r(ptr4, ":", &saveptr2); (j < 2) && ptr5; ptr5 = strtok_r(NULL, ":", &saveptr2), j++) {
113 if (!j) {
114 dwtime = atoi(ptr5);
115 }
116 if (j){
117 awtime = dwtime;
118 dwtime = atoi(ptr5);
119 }
120 }
121 }
122 if( (ptr3 = strchr(trim(ptr), '$')) ) {
123 *ptr3++ = '\0';
124 srvid = a2i(ptr3, 4);
125 }
126 if( (ptr2 = strchr(trim(ptr), '@')) ) {
127 *ptr2++ = '\0';
128 provid = a2i(ptr2, 6);
129 }
130 if ( (ptr1 = strchr(ptr, '&')) ) {
131 *ptr1++ = '\0';
132 cmask = a2i(ptr1,-2);
133 }
134 if (!ptr1 && !ptr2 && !ptr3 && !ptr4) //only dwtime
135 dwtime = atoi(ptr);
136 else
137 caid = a2i(ptr, 2);
138 if ((i==0 && (caid <= 0)) || (caid > 0)) {
139 newtab.caid[i] = caid;
140 newtab.cmask[i] = cmask;
141 newtab.prid[i] = provid;
142 newtab.srvid[i] = srvid;
143 newtab.awtime[i] = awtime;
144 newtab.dwtime[i] = dwtime;
145 newtab.n = i + 1;
146 }
147
148 }
149 memcpy(tab, &newtab, sizeof(CECSPVALUETAB));
150 }
151
152void chk_cacheex_hitvaluetab(char *lbrlt, CECSPVALUETAB *tab) {
153 //[caid][&mask][@provid][$servid]
154 int32_t i;
155 char *ptr = NULL, *saveptr1 = NULL;
156 CECSPVALUETAB newtab;
157 memset(&newtab, 0, sizeof(CECSPVALUETAB));
158
159 for (i = 0, ptr = strtok_r(lbrlt, ",", &saveptr1); (i < CS_MAXCAIDTAB) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1),i++) {
160 int32_t caid=-1, cmask=-1, srvid = -1;
161 int32_t provid = -1;
162 char *ptr1 = NULL, *ptr2 = NULL, *ptr3 = NULL;
163
164 if( (ptr3 = strchr(trim(ptr), '$')) ) {
165 *ptr3++ = '\0';
166 srvid = a2i(ptr3, 4);
167 }
168 if( (ptr2 = strchr(trim(ptr), '@')) ) {
169 *ptr2++ = '\0';
170 provid = a2i(ptr2, 6);
171 }
172 if ( (ptr1 = strchr(ptr, '&')) ) {
173 *ptr1++ = '\0';
174 cmask = a2i(ptr1,-2);
175 }
176 caid = a2i(ptr, 2);
177 if (caid > 0) {
178 newtab.caid[i] = caid;
179 newtab.cmask[i] = cmask;
180 newtab.prid[i] = provid;
181 newtab.srvid[i] = srvid;
182 newtab.n = i + 1;
183 }
184
185 }
186 memcpy(tab, &newtab, sizeof(CECSPVALUETAB));
187 }
188#endif
189
190void chk_tuntab(char *tunasc, TUNTAB *ttab)
191{
192 int32_t i;
193 char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL;
194 TUNTAB newttab;
195 memset(&newttab, 0 , sizeof(TUNTAB));
196
197 for (i = 0, ptr1 = strtok_r(tunasc, ",", &saveptr1); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) {
198 uint32_t bt_caidfrom, bt_caidto, bt_srvid;
199 if( (ptr3 = strchr(trim(ptr1), ':')) )
200 *ptr3++ = '\0';
201 else
202 ptr3 = "";
203
204 if( (ptr2 = strchr(trim(ptr1), '.')) )
205 *ptr2++ = '\0';
206 else
207 ptr2 = "";
208
209 if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
210 newttab.bt_caidfrom[i] = bt_caidfrom;
211 newttab.bt_caidto[i] = bt_caidto;
212 newttab.bt_srvid[i++] = bt_srvid;
213 newttab.n = i;
214 }
215 }
216 memcpy(ttab, &newttab, sizeof(TUNTAB));
217}
218
219void chk_services(char *labels, SIDTABS *sidtabs)
220{
221 int32_t i;
222 char *ptr, *saveptr1 = NULL;
223 SIDTAB *sidtab;
224 SIDTABBITS newsidok, newsidno;
225 newsidok = newsidno = 0;
226 for (ptr=strtok_r(labels, ",", &saveptr1); ptr; ptr=strtok_r(NULL, ",", &saveptr1)) {
227 for (trim(ptr), i = 0, sidtab = cfg.sidtab; sidtab; sidtab = sidtab->next, i++) {
228 if (!strcmp(sidtab->label, ptr)) newsidok|=((SIDTABBITS)1<<i);
229 if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) newsidno|=((SIDTABBITS)1<<i);
230 }
231 }
232 sidtabs->ok = newsidok;
233 sidtabs->no = newsidno;
234}
235
236void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
237{
238 int32_t i, j;
239 char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL;
240 char *ptr[CS_MAXFILTERS] = {0};
241 FTAB newftab;
242 memset(&newftab, 0, sizeof(FTAB));
243
244 for( i = 0, ptr1 = strtok_r(zFilterAsc, ";", &saveptr1); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1), i++ ) {
245 ptr[i] = ptr1;
246 if( (ptr2 = strchr(trim(ptr1), ':')) ) {
247 *ptr2++ ='\0';
248 newftab.filts[i].caid = (uint16_t)a2i(ptr1, 4);
249 ptr[i] = ptr2;
250 }
251 else if (zFiltName && zFiltName[0] == 'c') {
252 cs_log("PANIC: CAID field not found in CHID parameter!");
253 return;
254 }
255 newftab.nfilts++;
256 }
257
258 if( newftab.nfilts ) {
259 cs_debug_mask(D_CLIENT, "%s '%s' %s filter(s):", zType, zName, zFiltName);
260 }
261 for( i = 0; i < newftab.nfilts; i++ ) {
262 cs_debug_mask(D_CLIENT, "CAID #%d: %04X", i, newftab.filts[i].caid);
263 for( j = 0, ptr3 = strtok_r(ptr[i], ",", &saveptr1); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok_r(NULL, ",", &saveptr1), j++ ) {
264 newftab.filts[i].prids[j] = a2i(ptr3,6);
265 newftab.filts[i].nprids++;
266 cs_debug_mask(D_CLIENT, "%s #%d: %06X", zFiltName, j, newftab.filts[i].prids[j]);
267 }
268 }
269 memcpy(ftab, &newftab, sizeof(FTAB));
270}
271
272void chk_cltab(char *classasc, CLASSTAB *clstab)
273{
274 int32_t i;
275 char *ptr1, *saveptr1 = NULL;
276 CLASSTAB newclstab;
277 memset(&newclstab, 0, sizeof(newclstab));
278 newclstab.an = newclstab.bn = 0;
279 for( i = 0, ptr1 = strtok_r(classasc, ",", &saveptr1); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1) ) {
280 ptr1 = trim(ptr1);
281 if( ptr1[0] == '!' )
282 newclstab.bclass[newclstab.bn++] = (uchar)a2i(ptr1+1, 2);
283 else
284 newclstab.aclass[newclstab.an++] = (uchar)a2i(ptr1, 2);
285 }
286 memcpy(clstab, &newclstab, sizeof(CLASSTAB));
287}
288
289void chk_port_tab(char *portasc, PTAB *ptab)
290{
291 int32_t i, j, nfilts, ifilt, iport;
292 PTAB *newptab;
293 char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL;
294 char *ptr[CS_MAXPORTS] = {0};
295 int32_t port[CS_MAXPORTS] = {0};
296 if (!cs_malloc(&newptab, sizeof(PTAB)))
297 return;
298
299 for (nfilts = i = 0, ptr1 = strtok_r(portasc, ";", &saveptr1); (i < CS_MAXPORTS) && (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1), i++) {
300 ptr[i] = ptr1;
301 if( (ptr2=strchr(trim(ptr1), '@')) ) {
302 *ptr2++ ='\0';
303 newptab->ports[i].s_port = atoi(ptr1);
304
305 //checking for des key for port
306 newptab->ports[i].ncd_key_is_set = 0; //default to 0
307 if( (ptr3=strchr(trim(ptr1), '{')) ) {
308 *ptr3++='\0';
309 if (key_atob_l(ptr3, newptab->ports[i].ncd_key, sizeof(newptab->ports[i].ncd_key) * 2))
310 fprintf(stderr, "newcamd: error in DES Key for port %s -> ignored\n", ptr1);
311 else
312 newptab->ports[i].ncd_key_is_set = 1;
313 }
314
315 ptr[i] = ptr2;
316 port[i] = newptab->ports[i].s_port;
317 newptab->nports++;
318 }
319 nfilts++;
320 }
321
322 if( nfilts == 1 && strlen(portasc) < 6 && newptab->ports[0].s_port == 0 ) {
323 newptab->ports[0].s_port = atoi(portasc);
324 newptab->nports = 1;
325 }
326
327 iport = ifilt = 0;
328 for (i=0; i<nfilts; i++) {
329 if( port[i] != 0 )
330 iport = i;
331 for (j = 0, ptr3 = strtok_r(ptr[i], ",", &saveptr1); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok_r(NULL, ",", &saveptr1), j++) {
332 if( (ptr2=strchr(trim(ptr3), ':')) ) {
333 *ptr2++='\0';
334 newptab->ports[iport].ftab.nfilts++;
335 ifilt = newptab->ports[iport].ftab.nfilts-1;
336 newptab->ports[iport].ftab.filts[ifilt].caid = (uint16_t)a2i(ptr3, 4);
337 newptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
338 } else {
339 newptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
340 }
341 newptab->ports[iport].ftab.filts[ifilt].nprids++;
342 }
343 }
344 memcpy(ptab, newptab, sizeof(PTAB));
345 free(newptab);
346}
347
348/* Clears the s_ip structure provided. The pointer will be set to NULL so everything is cleared.*/
349void clear_sip(struct s_ip **sip) {
350 struct s_ip *cip = *sip;
351 for (*sip = NULL; cip != NULL; cip = cip->next){
352 add_garbage(cip);
353 }
354}
355
356/* Clears the s_ftab struct provided by setting nfilts and nprids to zero. */
357void clear_ftab(struct s_ftab *ftab) {
358 int32_t i, j;
359 for (i = 0; i < CS_MAXFILTERS; i++) {
360 ftab->filts[i].caid = 0;
361 for (j = 0; j < CS_MAXPROV; j++)
362 ftab->filts[i].prids[j] = 0;
363 ftab->filts[i].nprids = 0;
364 }
365 ftab->nfilts = 0;
366}
367
368/* Clears the s_ptab struct provided by setting nfilts and nprids to zero. */
369void clear_ptab(struct s_ptab *ptab) {
370 int32_t i = ptab->nports;
371 ptab->nports = 0;
372 for (; i >= 0; --i) {
373 ptab->ports[i].ftab.nfilts = 0;
374 ptab->ports[i].ftab.filts[0].nprids = 0;
375 }
376}
377
378/* Clears given caidtab */
379void clear_caidtab(struct s_caidtab *ctab) {
380 memset(ctab, 0, sizeof(struct s_caidtab));
381 int32_t i;
382 for (i = 1; i < CS_MAXCAIDTAB; ctab->mask[i++] = 0xffff);
383}
384
385#ifdef CS_CACHEEX
386/* Clears given csptab */
387void clear_cacheextab(CECSPVALUETAB *ctab) {
388 memset(ctab, -1, sizeof(CECSPVALUETAB));
389 ctab->n = 0;
390}
391#endif
392
393/* Clears given tuntab */
394void clear_tuntab(struct s_tuntab *ttab) {
395 memset(ttab, 0, sizeof(struct s_tuntab));
396}
Note: See TracBrowser for help on using the repository browser.