source: trunk/oscam-conf-mk.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: 21.0 KB
Line 
1#include "globals.h"
2#include "oscam-conf-mk.h"
3#include "oscam-net.h"
4#include "oscam-string.h"
5
6/*
7 * Creates a string ready to write as a token into config or WebIf for CAIDs. You must free the returned value through free_mk_t().
8 */
9char *mk_t_caidtab(CAIDTAB *ctab) {
10 int32_t i = 0, needed = 1, pos = 0;
11 while(ctab->caid[i]) {
12 if(ctab->mask[i]) needed += 10;
13 else needed += 5;
14 if(ctab->cmap[i]) needed += 5;
15 ++i;
16 }
17 char *value;
18 if (needed == 1 || !cs_malloc(&value, needed)) return "";
19 char *saveptr = value;
20 i = 0;
21 while(ctab->caid[i]) {
22 if (ctab->caid[i] < 0x0100) { //for "ignore provider for" option, caid-shortcut, just first 2 bytes:
23 if(i == 0) {
24 snprintf(value + pos, needed-(value-saveptr), "%02X", ctab->caid[i]);
25 pos += 2;
26 } else {
27 snprintf(value + pos, needed-(value-saveptr), ",%02X", ctab->caid[i]);
28 pos += 3;
29 }
30 } else {
31 if(i == 0) {
32 snprintf(value + pos, needed-(value-saveptr), "%04X", ctab->caid[i]);
33 pos += 4;
34 } else {
35 snprintf(value + pos, needed-(value-saveptr), ",%04X", ctab->caid[i]);
36 pos += 5;
37 }
38 }
39
40 if((ctab->mask[i]) && (ctab->mask[i] != 0xFFFF)) {
41 snprintf(value + pos, needed-(value-saveptr), "&%04X", ctab->mask[i]);
42 pos += 5;
43 }
44 if(ctab->cmap[i]) {
45 snprintf(value + pos, needed-(value-saveptr), ":%04X", ctab->cmap[i]);
46 pos += 5;
47 }
48 ++i;
49 }
50 value[pos] = '\0';
51 return value;
52}
53
54/*
55 * Creates a string ready to write as a token into config or WebIf for TunTabs. You must free the returned value through free_mk_t().
56 */
57char *mk_t_tuntab(TUNTAB *ttab) {
58 int32_t i, needed = 1, pos = 0;
59 for (i=0; i<ttab->n; i++) {
60 if(ttab->bt_srvid[i]) needed += 10;
61 else needed += 5;
62 if(ttab->bt_caidto[i]) needed += 5;
63 }
64 char *value;
65 if (needed == 1 || !cs_malloc(&value, needed)) return "";
66 char *saveptr = value;
67 for (i=0; i<ttab->n; i++) {
68 if(i == 0) {
69 snprintf(value + pos, needed-(value-saveptr), "%04X", ttab->bt_caidfrom[i]);
70 pos += 4;
71 } else {
72 snprintf(value + pos, needed-(value-saveptr), ",%04X", ttab->bt_caidfrom[i]);
73 pos += 5;
74 }
75 if(ttab->bt_srvid[i]) {
76 snprintf(value + pos, needed-(value-saveptr), ".%04X", ttab->bt_srvid[i]);
77 pos += 5;
78 }
79 if(ttab->bt_caidto[i]) {
80 snprintf(value + pos, needed-(value-saveptr), ":%04X", ttab->bt_caidto[i]);
81 pos += 5;
82 }
83 }
84 value[pos] = '\0';
85 return value;
86}
87
88/*
89 * Creates a string ready to write as a token into config or WebIf for groups. You must free the returned value through free_mk_t().
90 */
91char *mk_t_group(uint64_t grp) {
92 int32_t i = 0, needed = 1, pos = 0, dot = 0;
93
94 for(i = 0; i < 64; i++) {
95 if (grp&((uint64_t)1<<i)) {
96 needed += 2;
97 if(i > 9) needed += 1;
98 }
99 }
100 char *value;
101 if (needed == 1 || !cs_malloc(&value, needed)) return "";
102 char * saveptr = value;
103 for(i = 0; i < 64; i++) {
104 if (grp&((uint64_t)1<<i)) {
105 if (dot == 0) {
106 snprintf(value + pos, needed-(value-saveptr), "%d", i+1);
107 if (i > 8)pos += 2;
108 else pos += 1;
109 dot = 1;
110 } else {
111 snprintf(value + pos, needed-(value-saveptr), ",%d", i+1);
112 if (i > 8)pos += 3;
113 else pos += 2;
114 }
115 }
116 }
117 value[pos] = '\0';
118 return value;
119}
120
121/*
122 * Creates a string ready to write as a token into config or WebIf for FTabs (CHID, Ident). You must free the returned value through free_mk_t().
123 */
124char *mk_t_ftab(FTAB *ftab) {
125 int32_t i = 0, j = 0, needed = 1, pos = 0;
126
127 if (ftab->nfilts != 0) {
128 needed = ftab->nfilts * 5;
129 for (i = 0; i < ftab->nfilts; ++i)
130 needed += ftab->filts[i].nprids * 7;
131 }
132
133 char *value;
134 if (needed == 1 || !cs_malloc(&value, needed)) return "";
135 char *saveptr = value;
136 char *dot="";
137 for (i = 0; i < ftab->nfilts; ++i) {
138 snprintf(value + pos, needed-(value-saveptr), "%s%04X", dot, ftab->filts[i].caid);
139 pos += 4;
140 if (i > 0) pos += 1;
141 dot=":";
142 for (j = 0; j < ftab->filts[i].nprids; ++j) {
143 snprintf(value + pos, needed-(value-saveptr), "%s%06X", dot, ftab->filts[i].prids[j]);
144 pos += 7;
145 dot=",";
146 }
147 dot=";";
148 }
149
150 value[pos] = '\0';
151 return value;
152}
153
154/*
155 * Creates a string ready to write as a token into config or WebIf for the camd35 tcp ports. You must free the returned value through free_mk_t().
156 */
157char *mk_t_camd35tcp_port(void) {
158 int32_t i, j, pos = 0, needed = 1;
159
160 /* Precheck to determine how long the resulting string will maximally be (might be a little bit smaller but that shouldn't hurt) */
161 for(i = 0; i < cfg.c35_tcp_ptab.nports; ++i) {
162 /* Port is maximally 5 chars long, plus the @caid, plus the ";" between ports */
163 needed += 11;
164 if (cfg.c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 1) {
165 needed += cfg.c35_tcp_ptab.ports[i].ftab.filts[0].nprids * 7;
166 }
167 }
168 char *value;
169 if (needed == 1 || !cs_malloc(&value, needed)) return "";
170 char *saveptr = value;
171 char *dot1 = "", *dot2;
172 for(i = 0; i < cfg.c35_tcp_ptab.nports; ++i) {
173
174 if (cfg.c35_tcp_ptab.ports[i].ftab.filts[0].caid) {
175 pos += snprintf(value + pos, needed-(value-saveptr), "%s%d@%04X", dot1,
176 cfg.c35_tcp_ptab.ports[i].s_port,
177 cfg.c35_tcp_ptab.ports[i].ftab.filts[0].caid);
178
179 if (cfg.c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 1) {
180 dot2 = ":";
181 for (j = 0; j < cfg.c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j) {
182 pos += snprintf(value + pos, needed-(value-saveptr), "%s%X", dot2, cfg.c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
183 dot2 = ",";
184 }
185 }
186 dot1=";";
187 } else {
188 pos += snprintf(value + pos, needed-(value-saveptr), "%d", cfg.c35_tcp_ptab.ports[i].s_port);
189 }
190 }
191 return value;
192}
193
194#ifdef MODULE_CCCAM
195/*
196 * Creates a string ready to write as a token into config or WebIf for the cccam tcp ports. You must free the returned value through free_mk_t().
197 */
198char *mk_t_cccam_port(void) {
199 int32_t i, pos = 0, needed = CS_MAXPORTS*6+8;
200
201 char *value;
202 if (!cs_malloc(&value, needed)) return "";
203 char *dot = "";
204 for(i = 0; i < CS_MAXPORTS; i++) {
205 if (!cfg.cc_port[i]) break;
206
207 pos += snprintf(value + pos, needed-pos, "%s%d", dot, cfg.cc_port[i]);
208 dot=",";
209 }
210 return value;
211}
212#endif
213
214
215/*
216 * Creates a string ready to write as a token into config or WebIf for AESKeys. You must free the returned value through free_mk_t().
217 */
218char *mk_t_aeskeys(struct s_reader *rdr) {
219 AES_ENTRY *current = rdr->aes_list;
220 int32_t i, pos = 0, needed = 1, prevKeyid = 0, prevCaid = 0;
221 uint32_t prevIdent = 0;
222
223 /* Precheck for the approximate size that we will need; it's a bit overestimated but we correct that at the end of the function */
224 while(current) {
225 /* The caid, ident, "@" and the trailing ";" need to be output when they are changing */
226 if(prevCaid != current->caid || prevIdent != current->ident) needed += 12 + (current->keyid * 2);
227 /* "0" keys are not saved so we need to check for gaps */
228 else if(prevKeyid != current->keyid + 1) needed += (current->keyid - prevKeyid - 1) * 2;
229 /* The 32 byte key plus either the (heading) ":" or "," */
230 needed += 33;
231 prevCaid = current->caid;
232 prevIdent = current->ident;
233 prevKeyid = current->keyid;
234 current = current->next;
235 }
236
237 /* Set everything back and now create the string */
238 current = rdr->aes_list;
239 prevCaid = 0;
240 prevIdent = 0;
241 prevKeyid = 0;
242 char tmp[needed];
243 char dot;
244 if(needed == 1) tmp[0] = '\0';
245 char tmpkey[33];
246 while(current) {
247 /* A change in the ident or caid means that we need to output caid and ident */
248 if(prevCaid != current->caid || prevIdent != current->ident) {
249 if(pos > 0) {
250 tmp[pos] = ';';
251 ++pos;
252 }
253 pos += snprintf(tmp+pos, sizeof(tmp)-pos, "%04X@%06X", current->caid, current->ident);
254 prevKeyid = -1;
255 dot = ':';
256 } else dot = ',';
257 /* "0" keys are not saved so we need to check for gaps and output them! */
258 for (i = prevKeyid + 1; i < current->keyid; ++i) {
259 pos += snprintf(tmp+pos, sizeof(tmp)-pos, "%c0", dot);
260 dot = ',';
261 }
262 tmp[pos] = dot;
263 ++pos;
264 for (i = 0; i < 16; ++i) snprintf(tmpkey + (i*2), sizeof(tmpkey) - (i*2), "%02X", current->plainkey[i]);
265 /* A key consisting of only FFs has a special meaning (just return what the card outputted) and can be specified more compact */
266 if(strcmp(tmpkey, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") == 0) pos += snprintf(tmp+pos, sizeof(tmp)-pos, "FF");
267 else pos += snprintf(tmp+pos, sizeof(tmp)-pos, "%s", tmpkey);
268 prevCaid = current->caid;
269 prevIdent = current->ident;
270 prevKeyid = current->keyid;
271 current = current->next;
272 }
273
274 /* copy to result array of correct size */
275 char *value;
276 if (pos == 0 || !cs_malloc(&value, pos + 1)) return "";
277 memcpy(value, tmp, pos + 1);
278 return(value);
279}
280
281/*
282 * Creates a string ready to write as a token into config or WebIf for the Newcamd Port. You must free the returned value through free_mk_t().
283 */
284char *mk_t_newcamd_port(void) {
285 int32_t i, j, k, pos = 0, needed = 1;
286
287 /* Precheck to determine how long the resulting string will maximally be (might be a little bit smaller but that shouldn't hurt) */
288 for(i = 0; i < cfg.ncd_ptab.nports; ++i) {
289 /* Port is maximally 5 chars long, plus the @caid, plus the ";" between ports */
290 needed += 11;
291 if(cfg.ncd_ptab.ports[i].ncd_key_is_set) needed += 30;
292 if (cfg.ncd_ptab.ports[i].ftab.filts[0].nprids > 0) {
293 needed += cfg.ncd_ptab.ports[i].ftab.filts[0].nprids * 7;
294 }
295 }
296 char *value;
297 if (needed == 1 || !cs_malloc(&value, needed)) return "";
298 char *dot1 = "", *dot2;
299
300 for(i = 0; i < cfg.ncd_ptab.nports; ++i) {
301 pos += snprintf(value + pos, needed-pos, "%s%d", dot1, cfg.ncd_ptab.ports[i].s_port);
302
303 // separate DES Key for this port
304 if(cfg.ncd_ptab.ports[i].ncd_key_is_set) {
305 pos += snprintf(value + pos, needed-pos, "{");
306 for (k = 0; k < (int32_t)sizeof(cfg.ncd_ptab.ports[i].ncd_key[k]); k++)
307 pos += snprintf(value + pos, needed-pos, "%02X", cfg.ncd_ptab.ports[i].ncd_key[k]);
308 pos += snprintf(value + pos, needed-pos, "}");
309 }
310
311 pos += snprintf(value + pos, needed-pos, "@%04X", cfg.ncd_ptab.ports[i].ftab.filts[0].caid);
312
313 if (cfg.ncd_ptab.ports[i].ftab.filts[0].nprids > 0) {
314 dot2 = ":";
315 for (j = 0; j < cfg.ncd_ptab.ports[i].ftab.filts[0].nprids; ++j) {
316 pos += snprintf(value + pos, needed-pos, "%s%06X", dot2, (int)cfg.ncd_ptab.ports[i].ftab.filts[0].prids[j]);
317 dot2 = ",";
318 }
319 }
320 dot1=";";
321 }
322 return value;
323}
324
325/*
326 * Creates a string ready to write as a token into config or WebIf for au readers. You must free the returned value through free_mk_t().
327 */
328char *mk_t_aureader(struct s_auth *account) {
329 int32_t pos = 0;
330 char *dot = "";
331
332 char *value;
333 if (ll_count(account->aureader_list) == 0 || !cs_malloc(&value, 256)) return "";
334 value[0] = '\0';
335
336 struct s_reader *rdr;
337 LL_ITER itr = ll_iter_create(account->aureader_list);
338 while ((rdr = ll_iter_next(&itr))) {
339 pos += snprintf(value + pos, 256-pos, "%s%s", dot, rdr->label);
340 dot = ",";
341 }
342
343 return value;
344}
345
346/*
347 * Creates a string ready to write as a token into config or WebIf for blocknano and savenano. You must free the returned value through free_mk_t().
348 */
349char *mk_t_nano(uint16_t nano) {
350 int32_t i, pos = 0, needed = 0;
351
352 for (i=0; i<16; i++)
353 if ((1 << i) & nano)
354 needed++;
355
356 char *value;
357 if (nano == 0xFFFF) {
358 if (!cs_malloc(&value, 4)) return "";
359 snprintf(value, 4, "all");
360 } else {
361 if (needed == 0 || !cs_malloc(&value, needed * 3 + 1)) return "";
362 value[0] = '\0';
363 for (i=0; i<16; i++) {
364 if ((1 << i) & nano)
365 pos += snprintf(value + pos, (needed*3)+1-pos, "%s%02x", pos ? "," : "", (i+0x80));
366 }
367 }
368 return value;
369}
370
371/*
372 * Creates a string ready to write as a token into config or WebIf for the sidtab. You must free the returned value through free_mk_t().
373 */
374char *mk_t_service(SIDTABS *sidtabs) {
375 int32_t i, pos;
376 char *dot;
377 char *value;
378 struct s_sidtab *sidtab = cfg.sidtab;
379 if (!sidtab || (!sidtabs->ok && !sidtabs->no) || !cs_malloc(&value, 1024)) return "";
380 value[0] = '\0';
381
382 for (i=pos=0,dot=""; sidtab; sidtab=sidtab->next,i++) {
383 if (sidtabs->ok&((SIDTABBITS)1<<i)) {
384 pos += snprintf(value + pos, 1024 - pos, "%s%s", dot, sidtab->label);
385 dot = ",";
386 }
387 if (sidtabs->no&((SIDTABBITS)1<<i)) {
388 pos += snprintf(value + pos, 1024 - pos, "%s!%s", dot, sidtab->label);
389 dot = ",";
390 }
391 }
392 return value;
393}
394
395/*
396 * Creates a string ready to write as a token into config or WebIf for the logfile parameter. You must free the returned value through free_mk_t().
397 */
398char *mk_t_logfile(void) {
399 int32_t pos = 0, needed = 1;
400 char *value, *dot = "";
401
402 if(cfg.logtostdout == 1) needed += 7;
403 if(cfg.logtosyslog == 1) needed += 7;
404 if(cfg.logfile) needed += strlen(cfg.logfile);
405 if (needed == 1 || !cs_malloc(&value, needed)) return "";
406
407 if(cfg.logtostdout == 1) {
408 pos += snprintf(value + pos, needed - pos, "stdout");
409 dot = ";";
410 }
411 if(cfg.logtosyslog == 1) {
412 pos += snprintf(value + pos, needed - pos, "%ssyslog", dot);
413 dot = ";";
414 }
415 if(cfg.logfile) {
416 pos += snprintf(value + pos, needed - pos, "%s%s", dot, cfg.logfile);
417 }
418 return value;
419}
420
421/*
422 * Creates a string ready to write as a token into config or WebIf for the ecm whitelist. You must free the returned value through free_mk_t().
423 */
424char *mk_t_ecmwhitelist(struct s_ecmWhitelist *whitelist) {
425 int32_t needed = 1, pos = 0;
426 struct s_ecmWhitelist *cip;
427 struct s_ecmWhitelistIdent *cip2;
428 struct s_ecmWhitelistLen *cip3;
429 char *value, *dot = "", *dot2 = "";
430 for (cip = whitelist; cip; cip = cip->next) {
431 needed += 7;
432 for (cip2 = cip->idents; cip2; cip2 = cip2->next) {
433 needed +=7;
434 for (cip3 = cip2->lengths; cip3; cip3 = cip3->next) needed +=3;
435 }
436 }
437
438 char tmp[needed];
439
440 for (cip = whitelist; cip; cip = cip->next) {
441 for (cip2 = cip->idents; cip2; cip2 = cip2->next) {
442 if(cip2->lengths != NULL) {
443 if(cip->caid != 0) {
444 if(cip2->ident == 0)
445 pos += snprintf(tmp + pos, needed - pos, "%s%04X:", dot, cip->caid);
446 else
447 pos += snprintf(tmp + pos, needed - pos, "%s%04X@%06X:", dot, cip->caid, cip2->ident);
448 } else pos += snprintf(tmp + pos, needed - pos, "%s", dot);
449 }
450 dot2="";
451 for (cip3 = cip2->lengths; cip3; cip3 = cip3->next) {
452 pos += snprintf(tmp + pos, needed - pos, "%s%02X", dot2, cip3->len);
453 dot2=",";
454 }
455 dot=";";
456 }
457 }
458 if (pos == 0 || !cs_malloc(&value, pos + 1)) return "";
459 memcpy(value, tmp, pos + 1);
460 return value;
461}
462
463/*
464 * Creates a string ready to write as a token into config or WebIf for the ECM Headerwhitelist. You must free the returned value through free_mk_t().
465 */
466char *mk_t_ecmheaderwhitelist(struct s_ecmHeaderwhitelist *headerlist){
467 int32_t needed = 1, pos = 0;
468 struct s_ecmHeaderwhitelist *cip;
469 for (cip = headerlist; cip; cip = cip->next) needed += 51;
470 char *value, *dot = "";
471 char tmp[needed];
472 int16_t i;
473 int16_t ccache = 0;
474 uint32_t pcache = 0;
475 tmp[0] = '\0';
476 for (cip = headerlist; cip; cip = cip->next){
477 dot = "";
478 if (ccache == cip->caid && pcache == cip->provid){
479 if (pos)
480 pos -= 1;
481 if (strlen(tmp))
482 pos += snprintf(tmp + pos, needed - pos, ",");
483 } else {
484 if (cip->header != NULL && cip->caid != 0 && cip->provid == 0) {
485 pos += snprintf(tmp + pos, needed - pos, "%s%04X:", dot, cip->caid);
486 ccache = cip->caid;
487 pcache = 0;
488 }
489
490 if (cip->header != NULL && cip->caid != 0 && cip->provid != 0) {
491 pos += snprintf(tmp + pos, needed - pos, "%s%04X@%06X:", dot, cip->caid, cip->provid);
492 ccache = cip->caid;
493 pcache = cip->provid;
494 }
495 }
496 if(cip->header != NULL) {
497 for (i=0; i < cip->len/2; i++) {
498 pos += snprintf(tmp + pos, needed - pos, "%s%02X", dot, cip->header[i]);
499 if (i == cip->len/2-1) pos += snprintf(tmp + pos, needed - pos, ",");
500 ccache = cip->caid;
501 pcache = cip->provid;
502 }
503 }
504 if (pos)
505 pos -= 1;
506 pos += snprintf(tmp + pos, needed - pos, ";");
507 }
508 if (pos == 0 || !cs_malloc(&value, pos + 1)) return "";
509 memcpy(value, tmp, pos-1);
510 return value;
511}
512
513/*
514 * Creates a string ready to write as a token into config or WebIf for an iprange. You must free the returned value through free_mk_t().
515 */
516char *mk_t_iprange(struct s_ip *range) {
517 struct s_ip *cip;
518 char *value, *dot = "";
519 int32_t needed = 1, pos = 0;
520 for (cip = range; cip; cip = cip->next) needed += 32;
521
522 char tmp[needed];
523
524 for (cip = range; cip; cip = cip->next) {
525 pos += snprintf(tmp + pos, needed - pos, "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
526 if (!IP_EQUAL(cip->ip[0], cip->ip[1])) pos += snprintf(tmp + pos, needed - pos, "-%s", cs_inet_ntoa(cip->ip[1]));
527 dot=",";
528 }
529 if (pos == 0 || !cs_malloc(&value, pos + 1)) return "";
530 memcpy(value, tmp, pos + 1);
531 return value;
532}
533
534/*
535 * Creates a string ready to write as a token into config or WebIf for the class attribute. You must free the returned value through free_mk_t().
536 */
537char *mk_t_cltab(CLASSTAB *clstab) {
538 char *value, *dot = "";
539 int32_t i, needed = 1, pos = 0;
540 for(i = 0; i < clstab->an; ++i) needed += 3;
541 for(i = 0; i < clstab->bn; ++i) needed += 4;
542
543 char tmp[needed];
544
545 for(i = 0; i < clstab->an; ++i) {
546 pos += snprintf(tmp + pos, needed - pos, "%s%02x", dot, (int32_t)clstab->aclass[i]);
547 dot=",";
548 }
549 for(i = 0; i < clstab->bn; ++i) {
550 pos += snprintf(tmp + pos, needed - pos, "%s!%02x", dot, (int32_t)clstab->bclass[i]);
551 dot=",";
552 }
553
554 if (pos == 0 || !cs_malloc(&value, pos + 1)) return "";
555 memcpy(value, tmp, pos + 1);
556 return value;
557}
558
559/*
560 * Creates a string ready to write as a token into config or WebIf. You must free the returned value through free_mk_t().
561 */
562char *mk_t_caidvaluetab(CAIDVALUETAB *tab)
563{
564 if (!tab->n) return "";
565 int32_t i, size = 2 + tab->n * (4 + 1 + 5 + 1); //caid + ":" + time + ","
566 char *buf;
567 if (!cs_malloc(&buf, size))
568 return "";
569 char *ptr = buf;
570
571 for (i = 0; i < tab->n; i++) {
572 if (tab->caid[i] < 0x0100) //Do not format 0D as 000D, its a shortcut for 0Dxx:
573 ptr += snprintf(ptr, size-(ptr-buf), "%s%02X:%d", i?",":"", tab->caid[i], tab->value[i]);
574 else
575 ptr += snprintf(ptr, size-(ptr-buf), "%s%04X:%d", i?",":"", tab->caid[i], tab->value[i]);
576 }
577 *ptr = 0;
578 return buf;
579}
580
581#ifdef CS_CACHEEX
582char *mk_t_cacheex_valuetab(CECSPVALUETAB *tab){
583 if (!tab->n) return "";
584 int32_t i, size = 2 + tab->n * (4 + 1 + 4 + 1 + 6 + 1 + 4 + 1 + 5 + 1 + 5 + 1); //caid&mask@provid$servid:awtime:dwtime","
585 char *buf;
586 if (!cs_malloc(&buf, size))
587 return "";
588 char *ptr = buf;
589
590 for (i = 0; i < tab->n; i++) {
591 if (i) ptr += snprintf(ptr, size-(ptr-buf), ",");
592 if (tab->caid[i]>=0) {
593 if (tab->caid[i] == 0) {
594 if (tab->awtime[i]>0)
595 ptr += snprintf(ptr, size-(ptr-buf), "%d", tab->caid[i]);
596 } else if(tab->caid[i] < 256) //Do not format 0D as 000D, its a shortcut for 0Dxx:
597 ptr += snprintf(ptr, size-(ptr-buf), "%02X", tab->caid[i]);
598 else
599 ptr += snprintf(ptr, size-(ptr-buf), "%04X", tab->caid[i]);
600 }
601 if (tab->cmask[i]>=0)
602 ptr += snprintf(ptr, size-(ptr-buf), "&%04X", tab->cmask[i]);
603 if (tab->prid[i]>=0)
604 ptr += snprintf(ptr, size-(ptr-buf), "@%06X", tab->prid[i]);
605 if (tab->srvid[i]>=0)
606 ptr += snprintf(ptr, size-(ptr-buf), "$%04X", tab->srvid[i]);
607 if (tab->awtime[i]>0)
608 ptr += snprintf(ptr, size-(ptr-buf), ":%d", tab->awtime[i]);
609 if (!tab->dwtime[i]>0)
610 ptr += snprintf(ptr, size-(ptr-buf), ":0");
611 if (tab->dwtime[i]>0) {
612 if ((tab->caid[i] <= 0) && (tab->prid[i] == -1) &&(tab->srvid[i] == -1) && (tab->srvid[i] == -1) && (tab->awtime[i] <= 0))
613 ptr += snprintf(ptr, size-(ptr-buf), "%d", tab->dwtime[i]);
614 else
615 ptr += snprintf(ptr, size-(ptr-buf), ":%d", tab->dwtime[i]);
616 }
617 }
618 *ptr = 0;
619 return buf;
620}
621
622char *mk_t_cacheex_hitvaluetab(CECSPVALUETAB *tab){
623 if (!tab->n) return "";
624 int32_t i, size = 2 + tab->n * (4 + 1 + 4 + 1 + 6 + 1 + 4 + 1); //caid&mask@provid$servid","
625 char *buf;
626 if (!cs_malloc(&buf, size))
627 return "";
628 char *ptr = buf;
629
630 for (i = 0; i < tab->n; i++) {
631 if (i) ptr += snprintf(ptr, size-(ptr-buf), ",");
632 if (tab->caid[i]>0) {
633 if(tab->caid[i] < 256) //Do not format 0D as 000D, its a shortcut for 0Dxx:
634 ptr += snprintf(ptr, size-(ptr-buf), "%02X", tab->caid[i]);
635 else
636 ptr += snprintf(ptr, size-(ptr-buf), "%04X", tab->caid[i]);
637 if (tab->cmask[i]>=0)
638 ptr += snprintf(ptr, size-(ptr-buf), "&%04X", tab->cmask[i]);
639 if (tab->prid[i]>=0)
640 ptr += snprintf(ptr, size-(ptr-buf), "@%06X", tab->prid[i]);
641 if (tab->srvid[i]>=0)
642 ptr += snprintf(ptr, size-(ptr-buf), "$%04X", tab->srvid[i]);
643 }
644 }
645 *ptr = 0;
646 return buf;
647}
648#endif
649
650/*
651 * returns string of comma separated values
652 */
653char *mk_t_emmbylen(struct s_reader *rdr) {
654
655 char *value, *dot = "";
656 int32_t pos = 0, needed = 0;
657 int8_t i;
658
659 needed = (CS_MAXEMMBLOCKBYLEN * 4) +1;
660
661 if (!cs_malloc(&value, needed)) return "";
662
663 for( i = 0; i < CS_MAXEMMBLOCKBYLEN; i++ ) {
664 if(rdr->blockemmbylen[i] != 0) {
665 pos += snprintf(value + pos, needed, "%s%d", dot, rdr->blockemmbylen[i]);
666 dot = ",";
667 }
668 }
669 return value;
670}
671
672/*
673 * makes string from binary structure
674 */
675char *mk_t_allowedprotocols(struct s_auth *account) {
676
677 if (!account->allowedprotocols)
678 return "";
679
680 int16_t i, tmp = 1, pos = 0, needed = 255, tagcnt;
681 char *tag[] = {"camd33", "camd35", "cs378x", "newcamd", "cccam", "gbox", "radegast", "dvbapi", "constcw", "serial"};
682 char *value, *dot = "";
683
684 if (!cs_malloc(&value, needed))
685 return "";
686
687 tagcnt = sizeof(tag)/sizeof(char *);
688 for (i = 0; i < tagcnt; i++) {
689 if ((account->allowedprotocols & tmp) == tmp) {
690 pos += snprintf(value + pos, needed, "%s%s", dot, tag[i]);
691 dot = ",";
692 }
693 tmp = tmp << 1;
694 }
695 return value;
696}
697
698/*
699 * mk_t-functions give back a constant empty string when allocation fails or when the result is an empty string.
700 * This function thus checks the stringlength and only frees if necessary.
701 */
702void free_mk_t(char *value) {
703 if(strlen(value) > 0) free(value);
704}
Note: See TracBrowser for help on using the repository browser.