2 #include "oscam-string.h"
4 static void cl_set_last_providptr(struct s_client
*cl
, uint32_t provid
, uint16_t caid
)
7 struct s_provid
*this = cfg
.provid
;
8 struct s_provid
*zero_match
= NULL
;
10 cl
->last_providptr
= NULL
;
17 for(; this; this = this->next
)
19 if(this->caid
== caid
)
21 if(this->nprovid
== 0 )
26 for(i
= 0; i
< this->nprovid
; i
++)
28 if(this->provid
[i
] == 0 )
33 if(this->provid
[i
] == provid
)
35 cl
->last_providptr
= this;
42 if(zero_match
!= NULL
)
44 cl
->last_providptr
= zero_match
;
48 /* Gets the servicename. */
49 static char *__get_servicename(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
, bool return_unknown
)
52 struct s_srvid
*this, *provid_zero_match
= NULL
, *provid_any_match
= NULL
;
55 if(!srvid
|| (srvid
>> 12) >= 16) // cfg.srvid[16]
60 if(cl
&& cl
->last_srvidptr
&& cl
->last_srvidptr
->srvid
== srvid
)
62 for(i
= 0; i
< cl
->last_srvidptr
->ncaid
; i
++)
64 if(cl
->last_srvidptr
->caid
[i
].caid
== caid
&& cl
->last_srvidptr_search_provid
== provid
&& cl
->last_srvidptr
->name
)
66 if(cl
->last_providptr
== NULL
)
68 cl_set_last_providptr(cl
, provid
, caid
);
70 cs_strncpy(buf
, cl
->last_srvidptr
->name
, buflen
);
76 for(this = cfg
.srvid
[srvid
>> 12]; this; this = this->next
)
78 if(this->srvid
== srvid
)
80 for(i
= 0; i
< this->ncaid
; i
++)
82 if(this->caid
[i
].caid
== caid
&& this->name
)
84 provid_any_match
= this;
85 if(this->caid
[i
].nprovid
== 0)
87 provid_zero_match
= this;
93 cl_set_last_providptr(cl
, provid
, caid
);
94 cl
->last_srvidptr
= this;
95 cl
->last_srvidptr_search_provid
= provid
;
97 cs_strncpy(buf
, this->name
, buflen
);
102 for(j
= 0; j
< this->caid
[i
].nprovid
; j
++)
104 if(this->caid
[i
].provid
[j
] == 0)
105 { provid_zero_match
= this; }
107 if(this->caid
[i
].provid
[j
] == provid
)
111 cl_set_last_providptr(cl
, provid
, caid
);
112 cl
->last_srvidptr
= this;
113 cl
->last_srvidptr_search_provid
= provid
;
115 cs_strncpy(buf
, this->name
, buflen
);
126 if(provid
!= 0 && provid_zero_match
!= NULL
)
130 cl_set_last_providptr(cl
, provid
, caid
);
131 cl
->last_srvidptr
= provid_zero_match
;
132 cl
->last_srvidptr_search_provid
= provid
;
134 cs_strncpy(buf
, provid_zero_match
->name
, buflen
);
137 else if(provid
== 0 && provid_any_match
!= NULL
)
141 cl_set_last_providptr(cl
, provid
, caid
);
142 cl
->last_srvidptr
= provid_any_match
;
143 cl
->last_srvidptr_search_provid
= provid
;
145 cs_strncpy(buf
, provid_any_match
->name
, buflen
);
151 snprintf(buf
, buflen
, "%04X@%06X:%04X unknown", caid
, provid
, srvid
);
156 cl
->last_providptr
= NULL
;
157 cl
->last_srvidptr
= NULL
;
158 cl
->last_srvidptr_search_provid
= provid
;
164 char *get_servicename(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
166 return __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, true);
169 char *get_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
171 return __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, false);
174 char *get_picon_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
177 __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, false);
182 if(!cs_malloc(&tmp_buf
, buflen
))
189 for(i
= 0; i
< buflen
&& buf
[i
] && j
+ 4 < buflen
; i
++)
191 if(isalnum((int)buf
[i
]))
193 tmp_buf
[j
] = (char)tolower((int)buf
[i
]);
196 else if(buf
[i
] == '*')
199 tmp_buf
[j
+ 1] = 't';
200 tmp_buf
[j
+ 2] = 'a';
201 tmp_buf
[j
+ 3] = 'r';
204 else if(buf
[i
] == '+')
207 tmp_buf
[j
+ 1] = 'l';
208 tmp_buf
[j
+ 2] = 'u';
209 tmp_buf
[j
+ 3] = 's';
212 else if(buf
[i
] == '&')
215 tmp_buf
[j
+ 1] = 'n';
216 tmp_buf
[j
+ 2] = 'd';
221 tmp_buf
[buflen
- 1] = '\0';
222 cs_strncpy(buf
, tmp_buf
, buflen
);
229 int32_t picon_servicename_remve_hd(char *buf
, uint32_t UNUSED(buflen
))
231 int32_t l
= cs_strlen(buf
);
238 if(buf
[l
- 2] == 'h' && buf
[l
- 1] == 'd')
248 /* Gets the tier name. Make sure that buf is at least 83 bytes long. */
249 char *get_tiername(uint16_t tierid
, uint16_t caid
, char *buf
)
253 struct s_tierid
*this = cfg
.tierid
;
255 for(buf
[0] = 0; this && !found
; this = this->next
)
257 if(this->tierid
== tierid
)
259 for(i
= 0; i
< this->ncaid
&& !found
; i
++)
261 if(this->caid
[i
] == caid
)
263 cs_strncpy(buf
, this->name
, 32); found
= 1;
277 /* Gets the tier name. Make sure that buf is at least 83 bytes long. */
278 char *get_tiername_defaultid(uint16_t tierid
, uint16_t caid
, char *buf
)
282 struct s_tierid
*this = cfg
.tierid
;
284 for(buf
[0] = 0; this && !found
; this = this->next
)
286 if(this->tierid
== tierid
)
288 for(i
= 0; i
< this->ncaid
&& !found
; i
++)
290 if(this->caid
[i
] == caid
)
292 cs_strncpy(buf
, this->name
, 32); found
= 1;
300 snprintf(buf
, 82, "%04X", tierid
);
306 /* Gets the provider name. */
307 char *get_provider(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
311 struct s_provid
*this = cfg
.provid
;
319 for(buf
[0] = 0; this && !found
; this = this->next
)
321 if(this->caid
== caid
)
323 for(i
= 0; i
< this->nprovid
&& !found
; i
++)
325 if(this->provid
[i
] == provid
)
327 snprintf(buf
, buflen
, "%s%s%s%s%s",
329 *this->sat
&& this->sat
[0] ? " / " : "",
330 this->sat
, this->lang
[0] ? " / " : "",
340 snprintf(buf
, buflen
, "%04X@%06X unknown", caid
, provid
);
345 char *__get_providername(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
, bool return_unknown
)
349 struct s_provid
*this = cfg
.provid
;
350 struct s_provid
*zero_match
= NULL
;
358 for(buf
[0] = 0; this && !found
; this = this->next
)
360 if(this->caid
== caid
)
362 if(this->nprovid
== 0 )
367 for(i
= 0; i
< this->nprovid
&& !found
; i
++)
369 if(this->provid
[i
] == 0 )
374 if(this->provid
[i
] == provid
)
376 cs_strncpy(buf
, this->prov
, buflen
);
383 if(!found
&& zero_match
!= NULL
)
385 cs_strncpy(buf
, zero_match
->prov
, buflen
);
388 if(!buf
[0] && return_unknown
)
390 snprintf(buf
, buflen
, "%04X@%06X unknown", caid
, provid
);
396 char *get_providername(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
398 return __get_providername(provid
, caid
, buf
, buflen
, true);
401 char *get_providername_or_null(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
403 return __get_providername(provid
, caid
, buf
, buflen
, false);
406 const char *get_cl_lastprovidername(struct s_client
*cl
)
408 if(!cl
->last_srvidptr
|| !cl
->last_srvidptr
->prov
|| cl
->last_srvidptr
->prov
[0] == '\0' || !strcmp(cl
->last_srvidptr
->prov
, " "))
410 if(!cl
->last_providptr
)
416 return cl
->last_providptr
->prov
;
419 return cl
->last_srvidptr
->prov
;
422 // Add provider description. If provider was already present, do nothing.
423 void add_provider(uint16_t caid
, uint32_t provid
, const char *name
, const char *sat
, const char *lang
)
426 struct s_provid
**ptr
;
428 for(ptr
= &cfg
.provid
; *ptr
; ptr
= &(*ptr
)->next
)
430 if((*ptr
)->caid
== caid
)
432 for(i
= 0; i
< (*ptr
)->nprovid
; i
++)
434 if((*ptr
)->provid
[i
] == provid
)
442 struct s_provid
*prov
;
443 if(!cs_malloc(&prov
, sizeof(struct s_provid
)))
448 if(!cs_malloc(&prov
->provid
, sizeof(uint32_t)))
455 prov
->provid
[0] = provid
;
457 cs_strncpy(prov
->prov
, name
, sizeof(prov
->prov
));
458 cs_strncpy(prov
->sat
, sat
, sizeof(prov
->sat
));
459 cs_strncpy(prov
->lang
, lang
, sizeof(prov
->lang
));
463 // Get a cardsystem name based on caid
464 // used in webif/CCcam share and in dvbapi/ecminfo
465 const char *get_cardsystem_desc_by_caid(uint16_t caid
)
467 if(caid_is_seca(caid
)) { return "seca"; }
468 if(caid_is_viaccess(caid
)) { return "viaccess"; }
469 if(caid_is_irdeto(caid
)) { return "irdeto"; }
470 if(caid_is_videoguard(caid
)) { return "videoguard"; }
471 if(caid_is_powervu(caid
)) { return "powervu"; }
472 if(caid_is_director(caid
)) { return "director"; }
473 if(caid_is_conax(caid
)) { return "conax"; }
474 if(caid_is_cryptoworks(caid
)) { return "cryptoworks"; }
475 if(caid_is_betacrypt(caid
)) { return "betacrypt"; }
476 if(caid_is_nagra(caid
)) { return "nagra"; }
477 if(caid
>= 0x4B00 && caid
<= 0x4BFF) { return "tongfang"; }
478 if(caid
>= 0x5501 && caid
<= 0x551A) { return "griffin"; }
479 if(caid_is_dre(caid
)) { return "drecrypt"; }
480 if(caid_is_bulcrypt(caid
)) { return "bulcrypt"; }
481 if(caid_is_biss(caid
)) { return "biss"; }
482 if(caid
== 0x4ABF) { return "dgcrypt"; }