revert breaks some stupid old compilers
[oscam.git] / oscam-simples.c
blobe73595294db7539da0170fce3784e651df610809
1 #include "globals.h"
2 #include "oscam-string.h"
4 static void cl_set_last_providptr(struct s_client *cl, uint32_t provid, uint16_t caid)
6 int32_t i;
7 struct s_provid *this = cfg.provid;
8 struct s_provid *zero_match = NULL;
10 cl->last_providptr = NULL;
12 if(!caid) {
13 return;
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;
31 return;
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)
44 int32_t i, j;
45 struct s_srvid *this, *provid_zero_match = NULL, *provid_any_match = NULL;
46 buf[0] = '\0';
48 if(!srvid || (srvid >> 12) >= 16) //cfg.srvid[16]
49 { return (buf); }
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);
60 return (buf);
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;
75 if(0 == provid)
77 if(cl)
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);
84 return (buf);
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)
95 if(cl)
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);
102 return (buf);
108 if(!buf[0])
110 if(provid != 0 && provid_zero_match != NULL)
112 if(cl)
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);
119 return (buf);
121 else if(provid == 0 && provid_any_match != NULL)
123 if(cl)
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);
130 return (buf);
133 if(return_unknown)
134 { snprintf(buf, buflen, "%04X@%06X:%04X unknown", caid, provid, srvid); }
135 if(cl)
137 cl->last_providptr = NULL;
138 cl->last_srvidptr = NULL;
139 cl->last_srvidptr_search_provid = provid;
142 return (buf);
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)
157 uint32_t i, j;
159 __get_servicename(cl, srvid, provid, caid, buf, buflen, false);
161 char *tmp_buf;
163 if(buf[0])
165 if(!cs_malloc(&tmp_buf, buflen))
167 buf[0] = '\0';
168 return (buf);
171 j = 0;
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]);
178 j++;
180 else if(buf[i] == '*')
182 tmp_buf[j] = 's';
183 tmp_buf[j+1] = 't';
184 tmp_buf[j+2] = 'a';
185 tmp_buf[j+3] = 'r';
186 j += 4;
188 else if(buf[i] == '+')
190 tmp_buf[j] = 'p';
191 tmp_buf[j+1] = 'l';
192 tmp_buf[j+2] = 'u';
193 tmp_buf[j+3] = 's';
194 j += 4;
196 else if(buf[i] == '&')
198 tmp_buf[j] = 'a';
199 tmp_buf[j+1] = 'n';
200 tmp_buf[j+2] = 'd';
201 j += 3;
205 tmp_buf[buflen-1] = '\0';
206 cs_strncpy(buf, tmp_buf, buflen);
208 NULLFREE(tmp_buf);
211 return (buf);
214 int32_t picon_servicename_remve_hd(char *buf, uint32_t UNUSED(buflen))
216 int32_t l = strlen(buf);
218 if(l < 3)
220 return 0;
223 if(buf[l-2] == 'h' && buf[l-1] == 'd')
225 buf[l-2] = '\0';
226 buf[l-1] = '\0';
227 return 1;
230 return 0;
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)
236 uint8_t found = 0;
237 int32_t i;
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'; }
247 return (buf);
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)
253 uint8_t found = 0;
254 int32_t i;
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; }
263 if(!tierid)
265 snprintf(buf, 82, "%04X", tierid);
268 return (buf);
271 /* Gets the provider name. */
272 char *get_provider(uint32_t provid, uint16_t caid, char *buf, uint32_t buflen)
274 uint8_t found = 0;
275 int32_t i;
276 struct s_provid *this = cfg.provid;
278 if(!caid) {
279 buf[0] = '\0';
280 return (buf);
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);
294 found = 1;
300 if(!buf[0]) { snprintf(buf, buflen, "%04X@%06X unknown", caid, provid); }
302 return (buf);
305 char *__get_providername(uint32_t provid, uint16_t caid, char *buf, uint32_t buflen, bool return_unknown)
307 uint8_t found = 0;
308 int32_t i;
309 struct s_provid *this = cfg.provid;
310 struct s_provid *zero_match = NULL;
312 if(!caid) {
313 buf[0] = '\0';
314 return (buf);
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);
332 found = 1;
338 if(!found && zero_match != NULL)
340 cs_strncpy(buf, zero_match->prov, buflen);
341 found = 1;
344 if(!buf[0] && return_unknown) { snprintf(buf, buflen, "%04X@%06X unknown", caid, provid); }
346 return (buf);
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)
366 return "";
368 else
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)
380 int32_t i;
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)
391 return;
397 struct s_provid *prov;
398 if(!cs_malloc(&prov, sizeof(struct s_provid)))
399 { return; }
401 if(!cs_malloc(&prov->provid, sizeof(uint32_t)))
402 { NULLFREE(prov); return; }
404 prov->nprovid = 1;
405 prov->provid[0] = provid;
406 prov->caid = caid;
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));
410 *ptr = prov;
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"; }
432 return "???";