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
;
16 for(; this; this = this->next
)
18 if(this->caid
== caid
)
20 if(this->nprovid
== 0 )
21 { zero_match
= this; }
23 for(i
=0; i
< this->nprovid
; i
++)
25 if(this->provid
[i
] == 0 )
26 { zero_match
= this; }
28 if(this->provid
[i
] == provid
)
30 cl
->last_providptr
= this;
37 if(zero_match
!= NULL
)
38 { cl
->last_providptr
= zero_match
; }
41 /* Gets the servicename. */
42 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
)
45 struct s_srvid
*this, *provid_zero_match
= NULL
, *provid_any_match
= NULL
;
48 if(!srvid
|| (srvid
>> 12) >= 16) //cfg.srvid[16]
51 if(cl
&& cl
->last_srvidptr
&& cl
->last_srvidptr
->srvid
== srvid
)
52 for(i
= 0; i
< cl
->last_srvidptr
->ncaid
; i
++)
53 if(cl
->last_srvidptr
->caid
[i
].caid
== caid
54 && cl
->last_srvidptr_search_provid
== provid
55 && cl
->last_srvidptr
->name
)
57 if(cl
->last_providptr
== NULL
)
58 { cl_set_last_providptr(cl
, provid
, caid
); }
59 cs_strncpy(buf
, cl
->last_srvidptr
->name
, buflen
);
63 for(this = cfg
.srvid
[srvid
>> 12]; this; this = this->next
)
64 if(this->srvid
== srvid
)
65 for(i
= 0; i
< this->ncaid
; i
++)
67 if(this->caid
[i
].caid
== caid
&& this->name
)
69 provid_any_match
= this;
71 if(this->caid
[i
].nprovid
== 0)
73 provid_zero_match
= this;
79 cl_set_last_providptr(cl
, provid
, caid
);
80 cl
->last_srvidptr
= this;
81 cl
->last_srvidptr_search_provid
= provid
;
83 cs_strncpy(buf
, this->name
, buflen
);
88 for(j
= 0; j
< this->caid
[i
].nprovid
; j
++)
90 if(this->caid
[i
].provid
[j
] == 0)
91 { provid_zero_match
= this; }
93 if(this->caid
[i
].provid
[j
] == provid
)
97 cl_set_last_providptr(cl
, provid
, caid
);
98 cl
->last_srvidptr
= this;
99 cl
->last_srvidptr_search_provid
= provid
;
101 cs_strncpy(buf
, this->name
, buflen
);
110 if(provid
!= 0 && provid_zero_match
!= NULL
)
114 cl_set_last_providptr(cl
, provid
, caid
);
115 cl
->last_srvidptr
= provid_zero_match
;
116 cl
->last_srvidptr_search_provid
= provid
;
118 cs_strncpy(buf
, provid_zero_match
->name
, buflen
);
121 else if(provid
== 0 && provid_any_match
!= NULL
)
125 cl_set_last_providptr(cl
, provid
, caid
);
126 cl
->last_srvidptr
= provid_any_match
;
127 cl
->last_srvidptr_search_provid
= provid
;
129 cs_strncpy(buf
, provid_any_match
->name
, buflen
);
134 { snprintf(buf
, buflen
, "%04X@%06X:%04X unknown", caid
, provid
, srvid
); }
137 cl
->last_providptr
= NULL
;
138 cl
->last_srvidptr
= NULL
;
139 cl
->last_srvidptr_search_provid
= provid
;
145 char *get_servicename(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
147 return __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, true);
150 char *get_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
152 return __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, false);
155 char *get_picon_servicename_or_null(struct s_client
*cl
, uint16_t srvid
, uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
159 __get_servicename(cl
, srvid
, provid
, caid
, buf
, buflen
, false);
165 if(!cs_malloc(&tmp_buf
, buflen
))
173 for(i
=0; i
<buflen
&& buf
[i
] && j
+4<buflen
; i
++)
175 if(isalnum((int)buf
[i
]))
177 tmp_buf
[j
] = (char)tolower((int)buf
[i
]);
180 else if(buf
[i
] == '*')
188 else if(buf
[i
] == '+')
196 else if(buf
[i
] == '&')
205 tmp_buf
[buflen
-1] = '\0';
206 cs_strncpy(buf
, tmp_buf
, buflen
);
214 int32_t picon_servicename_remve_hd(char *buf
, uint32_t UNUSED(buflen
))
216 int32_t l
= strlen(buf
);
223 if(buf
[l
-2] == 'h' && buf
[l
-1] == 'd')
233 /* Gets the tier name. Make sure that buf is at least 83 bytes long. */
234 char *get_tiername(uint16_t tierid
, uint16_t caid
, char *buf
)
238 struct s_tierid
*this = cfg
.tierid
;
240 for(buf
[0] = 0; this && !found
; this = this->next
)
241 if(this->tierid
== tierid
)
242 for(i
= 0; i
< this->ncaid
&& !found
; i
++)
243 if(this->caid
[i
] == caid
)
244 { cs_strncpy(buf
, this->name
, 32); found
= 1; }
246 if(!tierid
) { buf
[0] = '\0'; }
250 /* Gets the tier name. Make sure that buf is at least 83 bytes long. */
251 char *get_tiername_defaultid(uint16_t tierid
, uint16_t caid
, char *buf
)
255 struct s_tierid
*this = cfg
.tierid
;
257 for(buf
[0] = 0; this && !found
; this = this->next
)
258 if(this->tierid
== tierid
)
259 for(i
= 0; i
< this->ncaid
&& !found
; i
++)
260 if(this->caid
[i
] == caid
)
261 { cs_strncpy(buf
, this->name
, 32); found
= 1; }
265 snprintf(buf
, 82, "%04X", tierid
);
271 /* Gets the provider name. */
272 char *get_provider(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
276 struct s_provid
*this = cfg
.provid
;
283 for(buf
[0] = 0; this && !found
; this = this->next
)
285 if(this->caid
== caid
)
287 for(i
=0; i
<this->nprovid
&& !found
; i
++)
289 if(this->provid
[i
] == provid
)
291 snprintf(buf
, buflen
, "%s%s%s%s%s", this->prov
,
292 *this->sat
&& this->sat
[0] ? " / " : "", this->sat
,
293 this->lang
[0] ? " / " : "", this->lang
);
300 if(!buf
[0]) { snprintf(buf
, buflen
, "%04X@%06X unknown", caid
, provid
); }
305 char *__get_providername(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
, bool return_unknown
)
309 struct s_provid
*this = cfg
.provid
;
310 struct s_provid
*zero_match
= NULL
;
317 for(buf
[0] = 0; this && !found
; this = this->next
)
319 if(this->caid
== caid
)
321 if(this->nprovid
== 0 )
322 { zero_match
= this; }
324 for(i
=0; i
<this->nprovid
&& !found
; i
++)
326 if(this->provid
[i
] == 0 )
327 { zero_match
= this; }
329 if(this->provid
[i
] == provid
)
331 cs_strncpy(buf
, this->prov
, buflen
);
338 if(!found
&& zero_match
!= NULL
)
340 cs_strncpy(buf
, zero_match
->prov
, buflen
);
344 if(!buf
[0] && return_unknown
) { snprintf(buf
, buflen
, "%04X@%06X unknown", caid
, provid
); }
349 char *get_providername(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
351 return __get_providername(provid
, caid
, buf
, buflen
, true);
354 char *get_providername_or_null(uint32_t provid
, uint16_t caid
, char *buf
, uint32_t buflen
)
356 return __get_providername(provid
, caid
, buf
, buflen
, false);
359 const char *get_cl_lastprovidername(struct s_client
*cl
)
361 if(!cl
->last_srvidptr
|| !cl
->last_srvidptr
->prov
362 || cl
->last_srvidptr
->prov
[0] == '\0' || !strcmp(cl
->last_srvidptr
->prov
, " "))
364 if(!cl
->last_providptr
)
370 return cl
->last_providptr
->prov
;
374 return cl
->last_srvidptr
->prov
;
377 // Add provider description. If provider was already present, do nothing.
378 void add_provider(uint16_t caid
, uint32_t provid
, const char *name
, const char *sat
, const char *lang
)
381 struct s_provid
**ptr
;
383 for(ptr
= &cfg
.provid
; *ptr
; ptr
= &(*ptr
)->next
)
385 if((*ptr
)->caid
== caid
)
387 for(i
=0; i
<(*ptr
)->nprovid
; i
++)
389 if((*ptr
)->provid
[i
] == provid
)
397 struct s_provid
*prov
;
398 if(!cs_malloc(&prov
, sizeof(struct s_provid
)))
401 if(!cs_malloc(&prov
->provid
, sizeof(uint32_t)))
402 { NULLFREE(prov
); return; }
405 prov
->provid
[0] = provid
;
407 cs_strncpy(prov
->prov
, name
, sizeof(prov
->prov
));
408 cs_strncpy(prov
->sat
, sat
, sizeof(prov
->sat
));
409 cs_strncpy(prov
->lang
, lang
, sizeof(prov
->lang
));
413 // Get a cardsystem name based on caid
414 // used in webif/CCcam share and in dvbapi/ecminfo
415 const char *get_cardsystem_desc_by_caid(uint16_t caid
)
417 if(caid_is_seca(caid
)) { return "seca"; }
418 if(caid_is_viaccess(caid
)) { return "viaccess"; }
419 if(caid_is_irdeto(caid
)) { return "irdeto"; }
420 if(caid_is_videoguard(caid
)) { return "videoguard"; }
421 if(caid
>= 0x0E00 && caid
<= 0x0EFF) { return "powervu"; }
422 if(caid
>= 0x0B00 && caid
<= 0x0BFF) { return "conax"; }
423 if(caid_is_cryptoworks(caid
)) { return "cryptoworks"; }
424 if(caid_is_betacrypt(caid
)) { return "betacrypt"; }
425 if(caid_is_nagra(caid
)) { return "nagra"; }
426 if(caid
>= 0x4B00 && caid
<= 0x4BFF) { return "tongfang"; }
427 if(caid
>= 0x5501 && caid
<= 0x551A) { return "griffin"; }
428 if(caid
== 0x4AE0 || caid
== 0x4AE1) { return "drecrypt"; }
429 if(caid_is_bulcrypt(caid
)) { return "bulcrypt"; }
430 if(caid_is_biss(caid
)) { return "biss"; }
431 if(caid
== 0x4ABF) { return "dgcrypt"; }