static void ins7E_fn(const char *token, char *value, void *setting, long var_size, FILE *f) { uint8_t *var = setting; var_size -= 1; // var_size contains sizeof(var) which is [X + 1] if(value) { int32_t len = strlen(value); if(len != var_size * 2 || key_atob_l(value, var, len)) { if(len > 0) { fprintf(stderr, "reader %s parse error, %s=%s\n", token, token, value); } memset(var, 0, var_size + 1); } else { var[var_size] = 1; // found and correct } return; } if(var[var_size]) { char tmp[var_size * 2 + 1]; fprintf_conf(f, token, "%s\n", cs_hexdump(0, var, var_size, tmp, sizeof(tmp))); } else if(cfg.http_full_cfg) { fprintf_conf(f, token, "\n"); } }
static void boxkey_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if(value) { int32_t len = strlen(value); if(len != 16 && len != 32) { memset(rdr->boxkey, 0, sizeof(rdr->boxkey)); } else { if(key_atob_l(value, rdr->boxkey, len)) { fprintf(stderr, "reader boxkey parse error, %s=%s\n", token, value); memset(rdr->boxkey, 0, sizeof(rdr->boxkey)); } } return; } int32_t len = check_filled(rdr->boxkey, sizeof(rdr->boxkey)); if(len > 0) { if(len > 8) { len = 16; } else { len = 8; } char tmp[len * 2 + 1]; fprintf_conf(f, "boxkey", "%s\n", cs_hexdump(0, rdr->boxkey, len, tmp, sizeof(tmp))); } else if(cfg.http_full_cfg) { fprintf_conf(f, "boxkey", "\n"); } }
static void account_allowedtimeframe_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if(value) { account->allowedtimeframe[0] = 0; account->allowedtimeframe[1] = 0; if(strlen(value)) { int32_t allowed[4]; if(sscanf(value, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4) { account->allowedtimeframe[0] = allowed[0] * 60 + allowed[1]; account->allowedtimeframe[1] = allowed[2] * 60 + allowed[3]; } else { fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value); } } return; } if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) { fprintf_conf(f, token, "%02d:%02d-%02d:%02d\n", account->allowedtimeframe[0] / 60, account->allowedtimeframe[0] % 60, account->allowedtimeframe[1] / 60, account->allowedtimeframe[1] % 60); } else if(cfg.http_full_cfg) { fprintf_conf(f, token, "%s\n", ""); } }
static void boxkey_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if(value) { int32_t len = strlen(value); if(((len % 8) != 0) || len == 0 || len > 32) { rdr->boxkey_length = 0; memset(rdr->boxkey, 0, sizeof(rdr->boxkey)); } else { if(key_atob_l(value, rdr->boxkey, len)) { fprintf(stderr, "reader boxkey parse error, %s=%s\n", token, value); rdr->boxkey_length = 0; memset(rdr->boxkey, 0, sizeof(rdr->boxkey)); } else { rdr->boxkey_length = len/2; } } return; } int32_t len = rdr->boxkey_length; if(len > 0) { char tmp[len * 2 + 1]; fprintf_conf(f, "boxkey", "%s\n", cs_hexdump(0, rdr->boxkey, len, tmp, sizeof(tmp))); } else if(cfg.http_full_cfg) { fprintf_conf(f, "boxkey", "\n"); } }
static void account_au_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { // set default values for usage during runtime from Webif account->autoau = 0; if (!account->aureader_list) account->aureader_list = ll_create("aureader_list"); if (streq(value, "1")) account->autoau = 1; strtolower(value); ll_clear(account->aureader_list); LL_ITER itr = ll_iter_create(configured_readers); struct s_reader *rdr; char *pch, *saveptr1 = NULL; for (pch = strtok_r(value, ",", &saveptr1); pch != NULL; pch = strtok_r(NULL, ",", &saveptr1)) { ll_iter_reset(&itr); while ((rdr = ll_iter_next(&itr))) { if (streq(rdr->label, pch) || account->autoau) { ll_append(account->aureader_list, rdr); } } } return; } if (account->autoau == 1) { fprintf_conf(f, token, "%d\n", account->autoau); } else if (account->aureader_list) { value = mk_t_aureader(account); if (strlen(value) > 0) fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } else if (cfg.http_full_cfg) { fprintf_conf(f, token, "%s\n", ""); } }
static void rsakey_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if(value) { int32_t len = strlen(value); if(len != 128 && len != 240) { rdr->rsa_mod_length = 0; memset(rdr->rsa_mod, 0, 120); } else { if(key_atob_l(value, rdr->rsa_mod, len)) { fprintf(stderr, "reader rsakey parse error, %s=%s\n", token, value); rdr->rsa_mod_length = 0; memset(rdr->rsa_mod, 0, sizeof(rdr->rsa_mod)); } else { rdr->rsa_mod_length = len/2; } } return; } int32_t len = rdr->rsa_mod_length; if(len > 0) { char tmp[len * 2 + 1]; fprintf_conf(f, "rsakey", "%s\n", cs_hexdump(0, rdr->rsa_mod, len, tmp, sizeof(tmp))); } else if(cfg.http_full_cfg) { fprintf_conf(f, "rsakey", "\n"); } }
static void gbox_my_cpu_api_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if(value) { const char *s; s=value; int32_t len = strlen(value); if ((s[strspn(s, "0123456789abcdefABCDEF")] != 0) || (len == 0) || (len > 2)) { cfg.gbox_my_cpu_api = GBOX_MY_CPU_API_DEF; } else { cfg.gbox_my_cpu_api = a2i(value,1); return; } } if(cfg.gbox_my_cpu_api != GBOX_MY_CPU_API_DEF) { fprintf_conf(f, token, "%02X\n", cfg.gbox_my_cpu_api); } else if(cfg.http_full_cfg) { fprintf_conf(f, token, "%02X\n", GBOX_MY_CPU_API_DEF); } }
static void boxid_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if (value) { rdr->boxid = strlen(value) ? a2i(value, 4) : 0; return; } if (rdr->boxid) fprintf_conf(f, token, "%08X\n", rdr->boxid); else if (cfg.http_full_cfg) fprintf_conf(f, token, "\n"); }
static void account_expdate_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { if (!value[0]) { account->expirationdate = (time_t)NULL; return; } int i; struct tm cstime; char *ptr1, *saveptr1 = NULL; memset(&cstime,0,sizeof(cstime)); for (i = 0, ptr1 = strtok_r(value, "-/", &saveptr1); i < 3 && ptr1; ptr1 = strtok_r(NULL, "-/", &saveptr1), i++) { switch(i) { case 0: cstime.tm_year = atoi(ptr1) - 1900; break; case 1: cstime.tm_mon = atoi(ptr1) - 1; break; case 2: cstime.tm_mday = atoi(ptr1); break; } } cstime.tm_hour = 23; cstime.tm_min = 59; cstime.tm_sec = 59; cstime.tm_isdst = -1; account->expirationdate = mktime(&cstime); return; } if (account->expirationdate || cfg.http_full_cfg) { char buf[16]; struct tm timeinfo; localtime_r(&account->expirationdate, &timeinfo); strftime(buf, 16, "%Y-%m-%d", &timeinfo); fprintf_conf(f, token, "%s\n", streq(buf, "1970-01-01") ? "" : buf); } }
static void http_dyndns_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { int i; if(value) { char *ptr, *saveptr1 = NULL; memset(cfg.http_dyndns, 0, sizeof(cfg.http_dyndns)); for(i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < MAX_HTTP_DYNDNS) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++) { trim(ptr); cs_strncpy((char *)cfg.http_dyndns[i], ptr, sizeof(cfg.http_dyndns[i])); } return; } if(strlen((const char *)(cfg.http_dyndns[0])) > 0 || cfg.http_full_cfg) { fprintf_conf(f, token, "%s", ""); // it should not have \n at the end for(i = 0; i < MAX_HTTP_DYNDNS; i++) { if(cfg.http_dyndns[i][0]) { fprintf(f, "%s%s", i > 0 ? "," : "", cfg.http_dyndns[i]); } } fprintf(f, "\n"); } }
static void http_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if(value) { cfg.http_port = 0; if(value[0]) { if(value[0] == '+') { if(config_enabled(WITH_SSL)) { cfg.http_use_ssl = 1; } else { fprintf(stderr, "Warning: OSCam compiled without SSL support.\n"); } cfg.http_port = strtoul(value + 1, NULL, 10); } else { cfg.http_port = strtoul(value, NULL, 10); } } return; } fprintf_conf(f, token, "%s%d\n", cfg.http_use_ssl ? "+" : "", cfg.http_port); }
static void gbox_proxy_card_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if (value) { char *ptr1, *saveptr1 = NULL; memset(cfg.gbox_proxy_card, 0, sizeof(cfg.gbox_proxy_card)); int n = 0, i; for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 8) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) { cfg.gbox_proxy_card[n++] = a2i(ptr1, 8); } cfg.gbox_proxy_cards_num = n; return; } if (cfg.gbox_proxy_cards_num > 0) { int i; char *dot = ""; fprintf_conf(f, token, " "); for (i = 0; i < cfg.gbox_proxy_cards_num; i++) { fprintf(f, "%s%08lX", dot, cfg.gbox_proxy_card[i]); dot = ","; } fprintf(f, "\n"); } }
void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f) { CAIDVALUETAB *caid_value_table = setting; if(value) { if (strlen(value)) { chk_caidvaluetab(value, caid_value_table); if (streq(token, "lb_retrylimits")) { int32_t i; for (i = 0; i < caid_value_table->cvnum; i++) { if (caid_value_table->cvdata[i].value < 50) caid_value_table->cvdata[i].value = 50; } } } else { caidvaluetab_clear(caid_value_table); } return; } if(caid_value_table->cvnum || cfg.http_full_cfg) { value = mk_t_caidvaluetab(caid_value_table); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void atr_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if(value) { memset(rdr->atr, 0, sizeof(rdr->atr)); rdr->atrlen = strlen(value); if(rdr->atrlen) { if(rdr->atrlen > (int32_t)sizeof(rdr->atr) * 2) { rdr->atrlen = (int32_t)sizeof(rdr->atr) * 2; } key_atob_l(value, rdr->atr, rdr->atrlen); } return; } if(rdr->atr[0] || cfg.http_full_cfg) { int j; fprintf_conf(f, token, "%s", ""); // it should not have \n at the end if(rdr->atr[0]) { for(j = 0; j < rdr->atrlen / 2; j++) { fprintf(f, "%02X", rdr->atr[j]); } } fprintf(f, "\n"); } }
static void reader_label_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; if(value) { int i, found = 0; if(!strlen(value)) { return; } for(i = 0; i < (int)strlen(value); i++) { if(value[i] == ' ') { value[i] = '_'; found++; } } if(found) { fprintf(stderr, "Configuration reader: corrected label to %s\n", value); } cs_strncpy(rdr->label, value, sizeof(rdr->label)); return; } fprintf_conf(f, token, "%s\n", rdr->label); }
static void device_fn(const char *token, char *value, void *setting, FILE *f) { struct s_reader *rdr = setting; int32_t isphysical = !is_network_reader(rdr); if(value) { int32_t i; char *ptr, *saveptr1 = NULL; for(i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < 3) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++) { trim(ptr); switch(i) { case 0: cs_strncpy(rdr->device, ptr, sizeof(rdr->device)); break; case 1: rdr->r_port = atoi(ptr); break; case 2: rdr->l_port = atoi(ptr); break; } } return; } fprintf_conf(f, token, "%s", rdr->device); // it should not have \n at the end if((rdr->r_port || cfg.http_full_cfg) && !isphysical) { fprintf(f, ",%d", rdr->r_port); } if((rdr->l_port || cfg.http_full_cfg) && !isphysical && strncmp(reader_get_type_desc(rdr, 0), "cccam", 5)) { fprintf(f, ",%d", rdr->l_port); } fprintf(f, "\n"); }
static void account_allowedprotocols_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { account->allowedprotocols = 0; if (strlen(value) > 3) { int i; char *ptr, *saveptr1 = NULL; for (i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr; ptr = strtok_r(NULL, ",", &saveptr1), i++) { if (streq(ptr, "camd33")) account->allowedprotocols |= LIS_CAMD33TCP; else if (streq(ptr, "camd35")) account->allowedprotocols |= LIS_CAMD35UDP; else if (streq(ptr, "cs357x")) account->allowedprotocols |= LIS_CAMD35UDP; else if (streq(ptr, "cs378x")) account->allowedprotocols |= LIS_CAMD35TCP; else if (streq(ptr, "newcamd")) account->allowedprotocols |= LIS_NEWCAMD; else if (streq(ptr, "cccam")) account->allowedprotocols |= LIS_CCCAM; else if (streq(ptr, "csp")) account->allowedprotocols |= LIS_CSPUDP; else if (streq(ptr, "gbox")) account->allowedprotocols |= LIS_GBOX; else if (streq(ptr, "radegast")) account->allowedprotocols |= LIS_RADEGAST; // these have no listener ports so it doesn't make sense else if (streq(ptr, "dvbapi")) account->allowedprotocols |= LIS_DVBAPI; else if (streq(ptr, "constcw")) account->allowedprotocols |= LIS_CONSTCW; else if (streq(ptr, "serial")) account->allowedprotocols |= LIS_SERIAL; } } return; } if (account->allowedprotocols || cfg.http_full_cfg ){ value = mk_t_allowedprotocols(account); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void logfile_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if (value) { char *saveptr1 = NULL; cfg.logtostdout = 0; cfg.logtosyslog = 0; NULLFREE(cfg.logfile); if (strlen(value) > 0) { char *pch; for(pch = strtok_r(value, ";", &saveptr1); pch != NULL; pch = strtok_r(NULL, ";", &saveptr1)){ pch=trim(pch); if(!strcmp(pch, "stdout")) cfg.logtostdout = 1; else if(!strcmp(pch, "syslog")) cfg.logtosyslog = 1; else { NULLFREE(cfg.logfile); if (!(cfg.logfile = cs_strdup(pch))) continue; } } } else { if (!(cfg.logfile = cs_strdup(CS_LOGFILE))) cfg.logtostdout = 1; } return; } if (cfg.logfile || cfg.logtostdout == 1 || cfg.logtosyslog == 1 || cfg.http_full_cfg) { value = mk_t_logfile(); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void gbox_proxy_card_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if (value) { char *ptr1, *saveptr1 = NULL; const char *s; memset(cfg.gbox_proxy_card, 0, sizeof(cfg.gbox_proxy_card)); int n = 0, i; for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < 8) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) { s=ptr1; if ((n < GBOX_MAX_PROXY_CARDS) && (s[strspn(s, "0123456789abcdefABCDEF")] == 0)) { cfg.gbox_proxy_card[n++] = a2i(ptr1, 8); } } cfg.gbox_proxy_cards_num = n; return; } if (cfg.gbox_proxy_cards_num > 0) { value = mk_t_gbox_proxy_card(); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void disablelog_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if (value) { cs_disable_log(strToIntVal(value, 0)); return; } if (cfg.disablelog || cfg.http_full_cfg) fprintf_conf(f, token, "%d\n", cfg.disablelog); }
static void account_ncd_keepalive_fn(const char *token, char *value, void *setting, FILE *f) { int8_t *ncd_keepalive = setting; if (value) { *ncd_keepalive = (int8_t)strToIntVal(value, cfg.ncd_keepalive); return; } if (*ncd_keepalive != cfg.ncd_keepalive || cfg.http_full_cfg) fprintf_conf(f, token, "%d\n", *ncd_keepalive); }
static void account_c35_suppresscmd08_fn(const char *token, char *value, void *setting, FILE *f) { int8_t *c35_suppresscmd08 = setting; if (value) { *c35_suppresscmd08 = (int8_t)strToIntVal(value, cfg.c35_suppresscmd08); return; } if (*c35_suppresscmd08 != cfg.c35_suppresscmd08 || cfg.http_full_cfg) fprintf_conf(f, token, "%d\n", *c35_suppresscmd08); }
static void account_tosleep_fn(const char *token, char *value, void *setting, FILE *f) { int32_t *tosleep = setting; if (value) { *tosleep = strToIntVal(value, cfg.tosleep); return; } if (*tosleep != cfg.tosleep || cfg.http_full_cfg) fprintf_conf(f, token, "%d\n", *tosleep); }
int32_t write_services(void) { int32_t i; struct s_sidtab *sidtab = cfg.sidtab; char *ptr; FILE *f = create_config_file(cs_sidt); if(!f) { return 1; } while(sidtab != NULL) { ptr = sidtab->label; while(*ptr) { if(*ptr == ' ') { *ptr = '_'; } ptr++; } fprintf(f, "[%s]\n", sidtab->label); fprintf_conf(f, "caid", "%s", ""); // it should not have \n at the end for(i = 0; i < sidtab->num_caid; i++) { if(i == 0) { fprintf(f, "%04X", sidtab->caid[i]); } else { fprintf(f, ",%04X", sidtab->caid[i]); } } fputc((int)'\n', f); fprintf_conf(f, "provid", "%s", ""); // it should not have \n at the end for(i = 0; i < sidtab->num_provid; i++) { if(i == 0) { fprintf(f, "%06X", sidtab->provid[i]); } else { fprintf(f, ",%06X", sidtab->provid[i]); } } fputc((int)'\n', f); fprintf_conf(f, "srvid", "%s", ""); // it should not have \n at the end for(i = 0; i < sidtab->num_srvid; i++) { if(i == 0) { fprintf(f, "%04X", sidtab->srvid[i]); } else { fprintf(f, ",%04X", sidtab->srvid[i]); } } fprintf(f, "\n\n"); sidtab = sidtab->next; } return flush_config_file(f, cs_sidt); }
static void account_services_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { strtolower(value); chk_services(value, &account->sidtabok, &account->sidtabno); return; } value = mk_t_service((uint64_t)account->sidtabok, (uint64_t)account->sidtabno); if (strlen(value) > 0 || cfg.http_full_cfg) fprintf_conf(f, token, "%s\n", value); free_mk_t(value); }
static void serverip_fn(const char *token, char *value, void *setting, FILE *f) { IN_ADDR_T srvip = *(IN_ADDR_T *)setting; if (value) { if (strlen(value) == 0) { set_null_ip((IN_ADDR_T *)setting); } else { cs_inet_addr(value, (IN_ADDR_T *)setting); } return; } if (IP_ISSET(srvip) || cfg.http_full_cfg) fprintf_conf(f, token, "%s\n", cs_inet_ntoa(srvip)); }
static void loghistorysize_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) { if (value) { uint32_t newsize = strToUIntVal(value, 4096); if (newsize < 1024 && newsize != 0) { fprintf(stderr, "WARNING: loghistorysize is too small, adjusted to 1024\n"); newsize = 1024; } cs_reinit_loghist(newsize); return; } if (cfg.loghistorysize != 4096 || cfg.http_full_cfg) fprintf_conf(f, token, "%u\n", cfg.loghistorysize); }
static void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f) { CAIDVALUETAB *caid_value_table = setting; int limit = streq(token, "lb_retrylimits") ? 50 : 1; if (value) { chk_caidvaluetab(value, caid_value_table, limit); return; } if (caid_value_table->n > 0 || cfg.http_full_cfg) { value = mk_t_caidvaluetab(caid_value_table); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void account_chid_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { strtolower(value); chk_ftab(value, &account->fchid, "user", account->usr, "chid"); return; } if (account->fchid.nfilts || cfg.http_full_cfg) { value = mk_t_ftab(&account->fchid); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }
static void account_class_fn(const char *token, char *value, void *setting, FILE *f) { struct s_auth *account = setting; if (value) { strtolower(value); chk_cltab(value, &account->cltab); return; } if ((account->cltab.bn > 0 || account->cltab.an > 0) || cfg.http_full_cfg) { value = mk_t_cltab(&account->cltab); fprintf_conf(f, token, "%s\n", value); free_mk_t(value); } }