void string_copy_value(void* csound, void* dest, void* src) { STRINGDAT* sDest = (STRINGDAT*)dest; STRINGDAT* sSrc = (STRINGDAT*)src; CSOUND* cs = (CSOUND*)csound; if (UNLIKELY(src == NULL)) return; if (UNLIKELY(dest == NULL)) return; if (sSrc->size > sDest->size) { if (sDest->data != NULL) { cs->Free(cs, sDest->data); } sDest->data = cs_strdup(csound, sSrc->data); } else { if (sDest->data == NULL) { sDest->data = cs_strdup(csound, sSrc->data); } else {//breaks here //fprintf(stderr, " in:src %p size=%d >>>%s<<<dstsize=%d dst->data=%p\n", // sSrc, sSrc->size, sSrc->data, sDest->size, sDest->data); //memcpy(sDest->data, sSrc->data, sDest->size); strcpy(sDest->data, sSrc->data); //cs->Free(cs, sDest->data); sDest->data = cs_strdup(csound, sSrc->data); } } sDest->size = sSrc->size; //fprintf(stderr, "out:srcsize=%d >>>%s<<<dstsize=%d dst->data=%p\n", // sSrc->size, sSrc->data, sDest->size, sDest->data); }
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); } }
int printksset_S(CSOUND *csound, PRINTKS *p){ char *sarg; sarg = ((STRINGDAT*)p->ifilcod)->data; if(sarg == NULL) return csoundInitError(csound, Str("null string\n")); p->old = cs_strdup(csound, sarg); return printksset_(csound, p, sarg); }
static int32_t ghttp_send_ecm(struct s_client *client, ECM_REQUEST *er, uchar *UNUSED(buf)) { uint32_t hash; s_ghttp *context = (s_ghttp *)client->ghttp; if(_is_pid_ignored(er)) { cs_debug_mask(D_CLIENT, "%s: ca context found in ignore list, ecm blocked: %x-%x-%x pid %x", client->reader->label, er->onid, er->tsid, er->srvid, er->pid); return -1; } if(!context->host_id) { context->host_id = (uchar *)cs_strdup(client->reader->device); } ll_append(context->ecm_q, er); if(ll_count(context->ecm_q) > 1) { cs_debug_mask(D_CLIENT, "%s: %d simultaneous ecms...", client->reader->label, ll_count(context->ecm_q)); } if(_is_post_context(context->post_contexts, er, false)) { _ghttp_post_ecmdata(client, er); } else { hash = javastring_hashcode(er->ecm + 3, er->ecmlen - 3); _ghttp_http_get(client, hash, er->ecm[0] == 0x81); } return 0; }
static void write_to_log_int(char *txt, int8_t header_len) { #if !defined(WEBIF) && !defined(MODULE_MONITOR) if(cfg.disablelog) { return; } #endif char *newtxt = cs_strdup(txt); if(!newtxt) { return; } struct s_log *log; if(!cs_malloc(&log, sizeof(struct s_log))) { NULLFREE(newtxt); return; } log->txt = newtxt; log->header_len = header_len; log->direct_log = 0; struct s_client *cl = cur_client(); log->cl_usr = ""; if(!cl) { log->cl_text = "undef"; log->cl_typ = ' '; } else { switch(cl->typ) { case 'c': case 'm': if(cl->account) { log->cl_text = cl->account->usr; log->cl_usr = cl->account->usr; } else { log->cl_text = ""; } break; case 'p': case 'r': log->cl_text = cl->reader ? cl->reader->label : ""; break; default: log->cl_text = "server"; break; } log->cl_typ = cl->typ; } if(exit_oscam == 1 || cfg.disablelog) //Exit or log disabled. if disabled, just display on webif/monitor { char buf[LOG_BUF_SIZE]; cs_strncpy(buf, log->txt, LOG_BUF_SIZE); write_to_log(buf, log, 1); NULLFREE(log->txt); NULLFREE(log); } else { log_list_add(log); } }
/* Creates the master client of OSCam and inits some global variables/mutexes. */ void init_first_client(void) { // get username OScam is running under struct passwd pwd; struct passwd *pwdbuf; #ifdef __ANDROID__ pwdbuf = getpwuid(getuid()); // This is safe if(pwdbuf) { memcpy(&pwd, pwdbuf, sizeof(pwd)); processUsername = cs_strdup(pwd.pw_name); } #else char buf[256]; if(getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &pwdbuf) == 0) { processUsername = cs_strdup(pwd.pw_name); } #endif if(!cs_malloc(&first_client, sizeof(struct s_client))) { fprintf(stderr, "Could not allocate memory for master client, exiting..."); exit(1); } memset(first_client_hashed, 0, sizeof(first_client_hashed)); int32_t bucket = (uintptr_t)first_client / 16 % CS_CLIENT_HASHBUCKETS; first_client_hashed[bucket] = first_client; first_client->next = NULL; //terminate clients list with NULL first_client->login = time(NULL); first_client->typ = 's'; first_client->thread = pthread_self(); set_localhost_ip(&first_client->ip); struct s_auth *null_account; if(!cs_malloc(&null_account, sizeof(struct s_auth))) { fprintf(stderr, "Could not allocate memory for master account, exiting..."); exit(1); } first_client->account = null_account; if(pthread_setspecific(getclient, first_client)) { fprintf(stderr, "Could not setspecific getclient in master process, exiting..."); exit(1); } }
void config_list_set_defaults(const struct config_list *clist, void *config_data) { const struct config_list *c; for (c = clist; c->opt_type != OPT_UNKNOWN; c++) { void *var = config_data + c->var_offset; switch (c->opt_type) { case OPT_INT8: { *(int8_t *)var = c->def.d_int8; break; } case OPT_UINT8: { *(uint8_t *)var = c->def.d_uint8; break; } case OPT_INT32: { *(int32_t *)var = c->def.d_int32; break; } case OPT_UINT32: { *(uint32_t *)var = c->def.d_uint32; break; } case OPT_STRING: { char **scfg = var; NULLFREE(*scfg); if (c->def.d_char) *scfg = cs_strdup(c->def.d_char); break; } case OPT_SSTRING: { char *scfg = var; scfg[0] = '\0'; if (c->def.d_char && strlen(c->def.d_char)) cs_strncpy(scfg, c->def.d_char, c->str_size); break; } case OPT_HEX_ARRAY: { uint8_t *hex_array = var; memset(hex_array, 0, c->def.array_size); break; } case OPT_FUNC: { c->ops.process_fn((const char *)c->config_name, "", var, NULL); break; } case OPT_FUNC_EXTRA: { c->ops.process_fn_extra((const char *)c->config_name, "", var, c->def.d_extra, NULL); break; } case OPT_SAVE_FUNC: case OPT_FIXUP_FUNC: case OPT_UNKNOWN: continue; } } return; }
void Mips_printInst(MCInst *MI, SStream *O, void *info) { switch (MCInst_getOpcode(MI)) { default: break; case Mips_RDHWR: case Mips_RDHWR64: SStream_concat(O, ".set\tpush\n"); SStream_concat(O, ".set\tmips32r2\n"); break; case Mips_Save16: SStream_concat(O, "\tsave\t"); printSaveRestore(MI, O); SStream_concat(O, " # 16 bit inst\n"); return; case Mips_SaveX16: SStream_concat(O, "\tsave\t"); printSaveRestore(MI, O); SStream_concat(O, "\n"); return; case Mips_Restore16: SStream_concat(O, "\trestore\t"); printSaveRestore(MI, O); SStream_concat(O, " # 16 bit inst\n"); return; case Mips_RestoreX16: SStream_concat(O, "\trestore\t"); printSaveRestore(MI, O); SStream_concat(O, "\n"); return; } // Try to print any aliases first. if (!printAliasInstr(MI, O, info) && !printAlias(MI, O)) printInstruction(MI, O, NULL); else { // fixup instruction id due to the change in alias instruction char *mnem = cs_strdup(O->buffer); char *tab = strchr(mnem, '\t'); if (tab) *tab = '\0'; // reflect the new insn name (alias) in the opcode unsigned id = Mips_map_insn(mnem); MCInst_setOpcode(MI, Mips_get_insn_id2(id)); MCInst_setOpcodePub(MI, id); cs_mem_free(mnem); } switch (MCInst_getOpcode(MI)) { default: break; case Mips_RDHWR: case Mips_RDHWR64: SStream_concat(O, "\n.set\tpop"); break; } }
static char *_get_header_substr(uchar *buf, const char *start, const char *end) { char *data = strstr((char *)buf, start); if(!data) { return NULL; } data += strlen(start); int len = strstr(data, end) - data; if(len <= 0) { return NULL; } char tmp = data[len]; data[len] = '\0'; char *value = cs_strdup(data); data[len] = tmp; return value; }
void string_copy_value(void* csound, void* dest, void* src) { STRINGDAT* sDest = (STRINGDAT*)dest; STRINGDAT* sSrc = (STRINGDAT*)src; CSOUND* cs = (CSOUND*)csound; if(src == NULL) return; if(dest == NULL) return; if (sSrc->size >= sDest->size) { sDest->size = sSrc->size; if (sDest->data != NULL) { cs->Free(cs, sDest->data); } sDest->data = cs_strdup(csound, sSrc->data); } else { memcpy(sDest->data, sSrc->data, sDest->size); } }
static void cs_write_log_int(char *txt) { if(exit_oscam == 1) { cs_write_log(txt, 1); } else { char *newtxt = cs_strdup(txt); if (!newtxt) return; struct s_log *log; if (!cs_malloc(&log, sizeof(struct s_log))) { free(newtxt); return; } log->txt = newtxt; log->header_len = 0; log->direct_log = 1; ll_append(log_list, log); } }
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info) { //if (TSFlags & X86II::LOCK) // O << "\tlock\n"; if (printAliasInstr(MI, O)) { char *mnem = cs_strdup(O->buffer); char *tab = strchr(mnem, '\t'); if (tab) *tab = '\0'; // reflect the new insn name (alias) in the opcode MCInst_setOpcode(MI, X86_get_insn_id2(X86_map_insn(mnem))); cs_mem_free(mnem); } else printInstruction(MI, O, NULL); if (MI->csh->detail) { char tmp[64]; if (get_first_op(O->buffer, tmp)) { int post; char *acc_regs[] = { "al", "ax", "eax", "rax", NULL }; unsigned int acc_regs_id[] = { X86_REG_AL, X86_REG_AX, X86_REG_EAX, X86_REG_RAX }; if (tmp[0] != 0 && ((post = str_in_list(acc_regs, tmp)) != -1)) { // first op is register, so set operand size following register size MI->flat_insn.x86.op_size = 1 << post; // tmp is a register if ((MI->flat_insn.x86.operands[0].type != X86_OP_INVALID) && ((MI->flat_insn.x86.operands[0].type != X86_OP_REG) || (MI->flat_insn.x86.operands[0].reg != acc_regs_id[post]))) { // first op is register, so insert its detail to position 0 int i; for (i = MI->flat_insn.x86.op_count; i > 0; i--) { memcpy(&(MI->flat_insn.x86.operands[i]), &(MI->flat_insn.x86.operands[i - 1]), sizeof(MI->flat_insn.x86.operands[0])); } MI->flat_insn.x86.operands[0].type = X86_OP_REG; MI->flat_insn.x86.operands[0].reg = x86_map_regname(tmp); MI->flat_insn.x86.op_count++; } } } } }
int32_t pinit(CSOUND *csound, PINIT *p) { int32_t n; int32_t x = 1; int32_t nargs = p->OUTOCOUNT; int32_t pargs = csound->init_event->pcnt; int32_t start = (int32_t)(*p->start); /* Should check that inits exist> */ if (UNLIKELY(nargs>pargs)) csound->Warning(csound, Str("More arguments than p fields")); for (n=0; (n<nargs) && (n<=pargs-start); n++) { if (csound->ISSTRCOD(csound->init_event->p[n+start])) { ((STRINGDAT *)p->inits[n])->data = cs_strdup(csound, get_arg_string(csound, csound->init_event->p[n+start])); ((STRINGDAT *)p->inits[n])->size = strlen(((STRINGDAT *)p->inits[n])->data)+1; } else *p->inits[n] = csound->init_event->p[n+start]; x <<= 1; } return OK; }
/* printks is called on every k cycle * It must decide when to do a * print operation. */ int printks(CSOUND *csound, PRINTKS *p) { MYFLT timel; int32 cycles; char string[8192]; /* matt ingals replacement */ if (ISSTRCOD(*p->ifilcod) == 0) { char *sarg; sarg = ((STRINGDAT*)p->ifilcod)->data; if (sarg == NULL) return csoundPerfError(csound, p->h.insdshead, Str("null string\n")); if (strcmp(sarg, p->old) != 0) { printksset_(csound, p, sarg); csound->Free(csound, p->old); p->old = cs_strdup(csound, sarg); } } /*-----------------------------------*/ if (UNLIKELY(p->initialised != -1)) csound->PerfError(csound, p->h.insdshead, Str("printks not initialised")); timel = ((MYFLT) CS_KCNT * CS_ONEDKR) - p->initime; /* Divide the current elapsed time by the cycle time and round down to * an integer. */ cycles = (int32)(timel / p->ctime); /* Now test if the cycle number we are in is higher than the one in which * we last printed. If so, update cysofar and print. */ if (p->cysofar < cycles) { p->cysofar = cycles; /* Do the print cycle. */ string[0]='\0'; /* incase of empty string */ sprints(string, p->txtstring, p->kvals, p->INOCOUNT-2); csound->MessageS(csound, CSOUNDMSG_ORCH, string); } return OK; }
static void cs_write_log_int(char *txt) { if(exit_oscam == 1) { cs_write_log(txt, 1, 0, 0); } else { char *newtxt = cs_strdup(txt); if(!newtxt) { return; } struct s_log *log; if(!cs_malloc(&log, sizeof(struct s_log))) { NULLFREE(newtxt); return; } log->txt = newtxt; log->header_len = 0; log->direct_log = 1; log_list_add(log); } }
static void run_parser_test(struct test_type *t) { memset(t->data, 0, t->data_sz); memset(t->data_c, 0, t->data_sz); printf("%s\n", t->desc); const struct test_vec *vec = t->test_vec; while (vec->in) { bool ok; printf(" Testing \"%s\"", vec->in); char *input_setting = cs_strdup(vec->in); t->chk_fn(input_setting, t->data); t->clone_fn(t->data, t->data_c); // Check if 'clone' works t->clear_fn(t->data); // Check if 'clear' works char *generated = t->mk_t_fn(t->data_c); // Use cloned data if (vec->out) ok = strcmp(vec->out, generated) == 0; else ok = strcmp(vec->in, generated) == 0; if (ok) { printf(" [OK]\n"); } else { printf("\n"); printf(" === ERROR ===\n"); printf(" Input data: \"%s\"\n", vec->in); printf(" Got result: \"%s\"\n", generated); printf(" Expected out: \"%s\"\n", vec->out ? vec->out : vec->in); printf("\n"); } free_mk_t(generated); free(input_setting); fflush(stdout); vec++; } t->clear_fn(t->data_c); }
static int32_t ghttp_capmt_notify(struct s_client *client, struct demux_s *demux) { uchar req[640], lenhdr[64] = ""; uchar *pids = NULL; uchar *end; char *encauth = NULL; int32_t ret; int8_t i, pids_len = 0, offs = 0; s_ghttp *context = (s_ghttp *)client->ghttp; if(!context) { return -1; } cs_debug_mask(D_CLIENT, "%s: capmt %x-%x-%x %d pids on adapter %d mask %x dmx index %d", client->reader->label, demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->adapter_index, demux->ca_mask, demux->demux_index); if(demux->ECMpidcount > 0) { if(cs_malloc(&pids, demux->ECMpidcount * 8)) { pids_len = demux->ECMpidcount * 8; for(i = 0; i < demux->ECMpidcount; i++) { i2b_buf(2, demux->ECMpids[i].ECM_PID, pids + offs); i2b_buf(2, demux->ECMpids[i].CAID, pids + (offs += 2)); i2b_buf(4, demux->ECMpids[i].PROVID, pids + (offs += 2)); offs += 4; } snprintf((char *)lenhdr, sizeof(lenhdr), "\r\nContent-Length: %d", pids_len); } else { return -1; } } if(!context->host_id) { context->host_id = (uchar *)cs_strdup(client->reader->device); } encauth = _ghttp_basic_auth(client); if(encauth) // basic auth login { ret = snprintf((char *)req, sizeof(req), "%s /api/p/%x/%x/%x/%x/%x HTTP/1.1\r\nHost: %s\r\nAuthorization: Basic %s%s\r\n\r\n", ((pids_len > 0) ? "POST" : "GET"), demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->enigma_namespace, context->host_id, encauth, lenhdr); free(encauth); } else { if(context->session_id) // session exists { ret = snprintf((char *)req, sizeof(req), "%s /api/p/%s/%x/%x/%x/%x/%x HTTP/1.1\r\nHost: %s%s\r\n\r\n", ((pids_len > 0) ? "POST" : "GET"), context->session_id, demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->enigma_namespace, context->host_id, lenhdr); } else // no credentials configured, assume no session required { ret = snprintf((char *)req, sizeof(req), "%s /api/p/%x/%x/%x/%x/%x HTTP/1.1\r\nHost: %s%s\r\n\r\n", ((pids_len > 0) ? "POST" : "GET"), demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->enigma_namespace, context->host_id, lenhdr); } } end = req + ret; if(pids_len > 0) { memcpy(end, pids, pids_len); cs_debug_mask(D_CLIENT, "%s: new unscrambling detected, switching to post", client->reader->label); _set_pid_status(context->post_contexts, demux->onid, demux->tsid, demux->program_number, 0); } cs_ddump_mask(D_CLIENT, pids, pids_len, "%s: sending capmt ecm pids - %s /api/p/%x/%x/%x/%x/%x", client->reader->label, (pids_len > 0) ? "POST" : "GET", demux->onid, demux->tsid, demux->program_number, demux->ECMpidcount, demux->enigma_namespace); ret = ghttp_send(client, req, ret + pids_len); if(pids_len > 0) { free(pids); } return 0; }
static char *printAliasInstrEx(MCInst *MI, SStream *OS, void *info) { #define GETREGCLASS_CONTAIN(_class, _reg) MCRegisterClass_contains(MCRegisterInfo_getRegClass(MRI, _class), MCOperand_getReg(MCInst_getOperand(MI, _reg))) SStream ss; const char *opCode; char *tmp, *AsmMnem, *AsmOps, *c; int OpIdx, PrintMethodIdx; int decCtr = false, needComma = false; MCRegisterInfo *MRI = (MCRegisterInfo *)info; SStream_Init(&ss); switch (MCInst_getOpcode(MI)) { default: return NULL; case PPC_gBC: opCode = "b%s"; break; case PPC_gBCA: opCode = "b%sa"; break; case PPC_gBCCTR: opCode = "b%sctr"; break; case PPC_gBCCTRL: opCode = "b%sctrl"; break; case PPC_gBCL: opCode = "b%sl"; break; case PPC_gBCLA: opCode = "b%sla"; break; case PPC_gBCLR: opCode = "b%slr"; break; case PPC_gBCLRL: opCode = "b%slrl"; break; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 0) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 1)) { SStream_concat(&ss, opCode, "dnzf"); decCtr = true; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 2) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 3)) { SStream_concat(&ss, opCode, "dzf"); decCtr = true; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 4) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 7) && MCOperand_isReg(MCInst_getOperand(MI, 1)) && GETREGCLASS_CONTAIN(PPC_CRBITRCRegClassID, 1)) { int cr = getBICRCond(MCOperand_getReg(MCInst_getOperand(MI, 1))); switch(cr) { case CREQ: SStream_concat(&ss, opCode, "ne"); break; case CRGT: SStream_concat(&ss, opCode, "le"); break; case CRLT: SStream_concat(&ss, opCode, "ge"); break; case CRUN: SStream_concat(&ss, opCode, "ns"); break; } if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 6) SStream_concat0(&ss, "-"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 7) SStream_concat0(&ss, "+"); decCtr = false; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 8) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 9)) { SStream_concat(&ss, opCode, "dnzt"); decCtr = true; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 10) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 11)) { SStream_concat(&ss, opCode, "dzt"); decCtr = true; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) >= 12) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) <= 15) && MCOperand_isReg(MCInst_getOperand(MI, 1)) && GETREGCLASS_CONTAIN(PPC_CRBITRCRegClassID, 1)) { int cr = getBICRCond(MCOperand_getReg(MCInst_getOperand(MI, 1))); switch(cr) { case CREQ: SStream_concat(&ss, opCode, "eq"); break; case CRGT: SStream_concat(&ss, opCode, "gt"); break; case CRLT: SStream_concat(&ss, opCode, "lt"); break; case CRUN: SStream_concat(&ss, opCode, "so"); break; } if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 14) SStream_concat0(&ss, "-"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 15) SStream_concat0(&ss, "+"); decCtr = false; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && ((MCOperand_getImm(MCInst_getOperand(MI, 0)) & 0x12)== 16)) { SStream_concat(&ss, opCode, "dnz"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 24) SStream_concat0(&ss, "-"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 25) SStream_concat0(&ss, "+"); needComma = false; } if (MCInst_getNumOperands(MI) == 3 && MCOperand_isImm(MCInst_getOperand(MI, 0)) && ((MCOperand_getImm(MCInst_getOperand(MI, 0)) & 0x12)== 18)) { SStream_concat(&ss, opCode, "dz"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 26) SStream_concat0(&ss, "-"); if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 27) SStream_concat0(&ss, "+"); needComma = false; } if (MCOperand_isReg(MCInst_getOperand(MI, 1)) && GETREGCLASS_CONTAIN(PPC_CRBITRCRegClassID, 1) && MCOperand_isImm(MCInst_getOperand(MI, 0)) && (MCOperand_getImm(MCInst_getOperand(MI, 0)) < 16)) { int cr = getBICR(MCOperand_getReg(MCInst_getOperand(MI, 1))); if (decCtr) { needComma = true; SStream_concat0(&ss, " "); if (cr > PPC_CR0) { SStream_concat(&ss, "4*cr%d+", cr - PPC_CR0); } cr = getBICRCond(MCOperand_getReg(MCInst_getOperand(MI, 1))); switch(cr) { case CREQ: SStream_concat0(&ss, "eq"); op_addBC(MI, PPC_BC_EQ); break; case CRGT: SStream_concat0(&ss, "gt"); op_addBC(MI, PPC_BC_GT); break; case CRLT: SStream_concat0(&ss, "lt"); op_addBC(MI, PPC_BC_LT); break; case CRUN: SStream_concat0(&ss, "so"); op_addBC(MI, PPC_BC_SO); break; } cr = getBICR(MCOperand_getReg(MCInst_getOperand(MI, 1))); if (cr > PPC_CR0) { if (MI->csh->detail) { MI->flat_insn->detail->ppc.operands[MI->flat_insn->detail->ppc.op_count].type = PPC_OP_CRX; MI->flat_insn->detail->ppc.operands[MI->flat_insn->detail->ppc.op_count].crx.scale = 4; MI->flat_insn->detail->ppc.operands[MI->flat_insn->detail->ppc.op_count].crx.reg = PPC_REG_CR0 + cr - PPC_CR0; MI->flat_insn->detail->ppc.operands[MI->flat_insn->detail->ppc.op_count].crx.cond = MI->flat_insn->detail->ppc.bc; MI->flat_insn->detail->ppc.op_count++; } } } else { if (cr > PPC_CR0) { needComma = true; SStream_concat(&ss, " cr%d", cr - PPC_CR0); op_addReg(MI, PPC_REG_CR0 + cr - PPC_CR0); } } } if (MCOperand_isImm(MCInst_getOperand(MI, 2)) && MCOperand_getImm(MCInst_getOperand(MI, 2)) != 0) { if (needComma) SStream_concat0(&ss, ","); SStream_concat0(&ss, " $\xFF\x03\x01"); } tmp = cs_strdup(ss.buffer); AsmMnem = tmp; for(AsmOps = tmp; *AsmOps; AsmOps++) { if (*AsmOps == ' ' || *AsmOps == '\t') { *AsmOps = '\0'; AsmOps++; break; } } SStream_concat0(OS, AsmMnem); if (*AsmOps) { SStream_concat0(OS, "\t"); for (c = AsmOps; *c; c++) { if (*c == '$') { c += 1; if (*c == (char)0xff) { c += 1; OpIdx = *c - 1; c += 1; PrintMethodIdx = *c - 1; printCustomAliasOperand(MI, OpIdx, PrintMethodIdx, OS); } else printOperand(MI, *c - 1, OS); } else { SStream_concat(OS, "%c", *c); } } } return tmp; }
int32_t init_config(void) { FILE *fp; if(config_enabled(WEBIF)) { fp = open_config_file(cs_conf); } else { fp = open_config_file_or_die(cs_conf); } const struct config_sections *cur_section = oscam_conf; // Global char *token; config_sections_set_defaults(oscam_conf, &cfg); if(!fp) { // no oscam.conf but webif is included in build, set it up for lan access and tweak defaults #ifdef WEBIF cfg.http_port = DEFAULT_HTTP_PORT; chk_iprange(cs_strdup(DEFAULT_HTTP_ALLOW), &cfg.http_allowed); #endif NULLFREE(cfg.logfile); cfg.logtostdout = 1; #ifdef HAVE_DVBAPI cfg.dvbapi_enabled = 1; #endif return 0; } if(!cs_malloc(&token, MAXLINESIZE)) { return 1; } int line = 0; int valid_section = 1; while(fgets(token, MAXLINESIZE, fp)) { ++line; int len = strlen(trim(token)); if(len < 3) // a=b or [a] are at least 3 chars { continue; } if(token[0] == '#') // Skip comments { continue; } if(token[0] == '[' && token[len - 1] == ']') { token[len - 1] = '\0'; valid_section = 0; const struct config_sections *newconf = config_find_section(oscam_conf, token + 1); if(config_section_is_active(newconf) && cur_section) { config_list_apply_fixups(cur_section->config, &cfg); cur_section = newconf; valid_section = 1; } if(!newconf) { fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n", cs_conf, line, token + 1); continue; } if(!config_section_is_active(newconf)) { fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n", cs_conf, line, newconf->section); } continue; } if(!valid_section) { continue; } char *value = strchr(token, '='); if(!value) // No = found, well go on { continue; } *value++ = '\0'; char *tvalue = trim(value); char *ttoken = trim(strtolower(token)); if(cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg)) { fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n", cs_conf, line, cur_section->section, ttoken, tvalue); } } free(token); fclose(fp); if(cur_section) { config_list_apply_fixups(cur_section->config, &cfg); } return 0; }
/** Adds a UDO definition as an T_OPCODE or T_OPCODE0 type to the symbol table * used at parse time. An OENTRY is also added at this time so that at * verification time the opcode can be looked up to get its signature. */ int add_udo_definition(CSOUND *csound, char *opname, char *outtypes, char *intypes) { OENTRY tmpEntry, *opc, *newopc; OPCODINFO *inm; if (UNLIKELY(!check_instr_name(opname))) { synterr(csound, Str("invalid name for opcode")); return -1; } /* check if opcode is already defined */ opc = find_opcode_new(csound, opname, outtypes, intypes); if (opc != NULL) { /* IV - Oct 31 2002: redefine old opcode if possible */ if (UNLIKELY( !strcmp(opname, "instr") || !strcmp(opname, "endin") || !strcmp(opname, "opcode") || !strcmp(opname, "endop") || !strcmp(opname, "$label") || !strcmp(opname, "pset") || !strcmp(opname, "xin") || !strcmp(opname, "xout") || !strcmp(opname, "subinstr"))) { synterr(csound, Str("cannot redefine %s"), opname); return -2; } csound->Message(csound, Str("WARNING: redefined opcode: %s\n"), opname); } /* IV - Oct 31 2002 */ /* store the name in a linked list (note: must use csound->Calloc) */ inm = (OPCODINFO *) csound->Calloc(csound, sizeof(OPCODINFO)); inm->name = cs_strdup(csound, opname); inm->intypes = intypes; inm->outtypes = outtypes; inm->in_arg_pool = csoundCreateVarPool(csound); inm->out_arg_pool = csoundCreateVarPool(csound); inm->prv = csound->opcodeInfo; csound->opcodeInfo = inm; /* IV - Oct 31 2002: */ /* create a fake opcode so we can call it as such */ opc = find_opcode(csound, "##userOpcode"); memcpy(&tmpEntry, opc, sizeof(OENTRY)); tmpEntry.opname = cs_strdup(csound, opname); csound->AppendOpcodes(csound, &tmpEntry, 1); newopc = csound_find_internal_oentry(csound, &tmpEntry); newopc->useropinfo = (void*) inm; /* ptr to opcode parameters */ /* check in/out types and copy to the opcode's */ /* IV - Sep 8 2002: opcodes have an optional arg for ksmps */ newopc->outypes = csound->Malloc(csound, strlen(outtypes) + 1 + strlen(intypes) + 2); newopc->intypes = &(newopc->outypes[strlen(outtypes) + 1]); if (UNLIKELY(parse_opcode_args(csound, newopc) != 0)) return -3; if (strcmp(outtypes, "0")==0) { add_token(csound, opname, T_OPCODE0); } else { add_token(csound, opname, T_OPCODE); } return 0; }
static int parse_opcode_args(CSOUND *csound, OENTRY *opc) { OPCODINFO *inm = (OPCODINFO*) opc->useropinfo; char** in_args; char** out_args; char intypes[256]; char typeSpecifier[2]; char tempName[20]; int i = 0, err = 0; ARRAY_VAR_INIT varInit; typeSpecifier[1] = '\0'; // The following handles adding of extra 'o' type for optional // ksmps arg for all UDO's if (*inm->intypes == '0') { intypes[0] = 'o'; intypes[1] = '\0'; } else { snprintf(intypes, 256, "%so", inm->intypes); } in_args = splitArgs(csound, intypes); out_args = splitArgs(csound, inm->outtypes); if (*in_args[0] != '0') { while (in_args[i] != NULL) { char* in_arg = in_args[i]; snprintf(tempName, 20, "in%d", i); if (*in_arg == '[') { int dimensions = 0; while (*in_arg == '[') { dimensions += 1; in_arg += 1; } typeSpecifier[0] = *in_arg; // printf("Dimensions: %d SubArgType: %s\n", dimensions, typeSpecifier); CS_TYPE* type = csoundGetTypeWithVarTypeName(csound->typePool, typeSpecifier); if (type == NULL) { synterr(csound, Str("invalid input type for opcode %s"), in_arg); err++; continue; } varInit.dimensions = dimensions; varInit.type = type; CS_VARIABLE* var = csoundCreateVariable(csound, csound->typePool, (CS_TYPE*)&CS_VAR_TYPE_ARRAY, tempName, &varInit); var->dimensions = dimensions; csoundAddVariable(csound, inm->in_arg_pool, var); } else { char c = map_udo_in_arg_type(*in_arg); // printf("found arg type %s -> %c\n", in_arg, c); typeSpecifier[0] = c; CS_TYPE* type = csoundGetTypeWithVarTypeName(csound->typePool, typeSpecifier); if (type == NULL) { synterr(csound, Str("invalid input type for opcode %s"), in_arg); err++; continue; } CS_VARIABLE* var = csoundCreateVariable(csound, csound->typePool, type, tempName, NULL); csoundAddVariable(csound, inm->in_arg_pool, var); } i++; } } // inm->inchns = i + 1; /* Add one for optional local ksmps */ inm->inchns = i - 1; i = 0; if (*out_args[0] != '0') { while(out_args[i] != NULL) { char* out_arg = out_args[i]; snprintf(tempName, 20, "out%d", i); if (*out_arg == '[') { int dimensions = 0; while (*out_arg == '[') { dimensions += 1; out_arg += 1; } typeSpecifier[0] = *out_arg; //printf("Dimensions: %d SubArgType: %s\n", dimensions, typeSpecifier); CS_TYPE* type = csoundGetTypeWithVarTypeName(csound->typePool, typeSpecifier); if (type == NULL) { synterr(csound, Str("invalid output type for opcode %s"), out_arg); err++; continue; } varInit.dimensions = dimensions; varInit.type = type; CS_VARIABLE* var = csoundCreateVariable(csound, csound->typePool, (CS_TYPE*)&CS_VAR_TYPE_ARRAY, tempName, &varInit); var->dimensions = dimensions; csoundAddVariable(csound, inm->out_arg_pool, var); } else { char c = map_udo_out_arg_type(*out_arg); // printf("found arg type %s -> %c\n", out_arg, c); typeSpecifier[0] = c; CS_TYPE* type = csoundGetTypeWithVarTypeName(csound->typePool, typeSpecifier); if (type == NULL) { synterr(csound, Str("invalid output type for opcode %s"), out_arg); err++; continue; } CS_VARIABLE* var = csoundCreateVariable(csound, csound->typePool, type, tempName, NULL); csoundAddVariable(csound, inm->out_arg_pool, var); } i++; } } inm->outchns = i; opc->dsblksiz = (uint16) (sizeof(UOPCODE) + sizeof(MYFLT*) * (inm->inchns + inm->outchns)); opc->dsblksiz = ((opc->dsblksiz + (uint16) 15) & (~((uint16) 15))); /* align (needed ?) */ opc->intypes = cs_strdup(csound, intypes); opc->outypes = cs_strdup(csound, (inm->outtypes[0] == '0') ? "" : inm->outtypes); map_args(opc->intypes); map_args(opc->outypes); // /* count the number of arguments, and check types */ // default: // synterr(csound, Str("invalid input type for opcode %s"), inm->name); // err++; i--; // } // i++; types++; // if (UNLIKELY(i > OPCODENUMOUTS_MAX)) { // synterr(csound, Str("too many input args for opcode %s"), inm->name); // csound->LongJmp(csound, 1); // } // } // default: // synterr(csound, Str("invalid output type for opcode %s"), inm->name); // err++; i--; // } // i++; types++; // } int n=0; while(in_args[n] != NULL) { // printf("delete %p \n", argsFound[n]); csound->Free(csound, in_args[n]); n++; } csound->Free(csound, in_args); n = 0; while(out_args[n] != NULL) { // printf("delete %p \n", argsFound[n]); csound->Free(csound, out_args[n]); n++; } csound->Free(csound, out_args); return err; }
int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data) { const struct config_list *c; for (c = clist; c->opt_type != OPT_UNKNOWN; c++) { if (c->opt_type == OPT_SAVE_FUNC || c->opt_type == OPT_FIXUP_FUNC) continue; if (strcasecmp(token, c->config_name) != 0) continue; void *var = config_data + c->var_offset; switch (c->opt_type) { case OPT_INT8: { *(int8_t *)var = (int8_t)strToIntVal(value, c->def.d_int8); return 1; } case OPT_UINT8: { uint32_t tmp = strToUIntVal(value, c->def.d_uint8); *(uint8_t *)var = (uint8_t)(tmp <= 0xff ? tmp : 0xff); return 1; } case OPT_INT32: { *(int32_t *)var = strToIntVal(value, c->def.d_int32); return 1; } case OPT_UINT32: { *(uint32_t *)var = strToUIntVal(value, c->def.d_uint32); return 1; } case OPT_STRING: { char **scfg = var; if (c->def.d_char && strlen(value) == 0) // Set default value = c->def.d_char; NULLFREE(*scfg); if (strlen(value)) *scfg = cs_strdup(value); return 1; } case OPT_SSTRING: { char *scfg = var; if (c->def.d_char && strlen(value) == 0) // Set default value = c->def.d_char; scfg[0] = '\0'; unsigned int len = strlen(value); if (len) { strncpy(scfg, value, c->str_size - 1); if (len > c->str_size) { fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%u) exceeds max length: %d (%s)\n", token, value, len, c->str_size - 1, scfg); } } return 1; } case OPT_FUNC: { c->ops.process_fn(token, value, var, NULL); return 1; } case OPT_FIXUP_FUNC: case OPT_SAVE_FUNC: return 1; case OPT_UNKNOWN: { fprintf(stderr, "Unknown config type (%s = %s).", token, value); break; } } } return 0; }
static int32_t cs_check_v(IN_ADDR_T ip, int32_t port, int32_t add, char *info, int32_t acosc_penalty_duration) { int32_t result = 0; bool acosc_enabled = false; #ifdef CS_ANTICASC if(cfg.acosc_enabled) acosc_enabled = true; #endif if(!(cfg.failbantime || acosc_enabled)) { return 0; } if(!cfg.v_list) { cfg.v_list = ll_create("v_list"); } struct timeb (now); cs_ftime(&now); LL_ITER itr = ll_iter_create(cfg.v_list); V_BAN *v_ban_entry; int32_t ftime = cfg.failbantime * 60 * 1000; //run over all banned entries to do housekeeping: while((v_ban_entry = ll_iter_next(&itr))) { // housekeeping: int32_t gone = comp_timeb(&now, &v_ban_entry->v_time); if(((gone >= ftime) && !v_ban_entry->acosc_entry) || (v_ban_entry->acosc_entry && ((gone/1000) >= v_ban_entry->acosc_penalty_dur))) // entry out of time->remove { NULLFREE(v_ban_entry->info); ll_iter_remove_data(&itr); continue; } if(IP_EQUAL(ip, v_ban_entry->v_ip) && port == v_ban_entry->v_port) { result = 1; if(!info) { info = v_ban_entry->info; } else if(!v_ban_entry->info) { v_ban_entry->info = cs_strdup(info); } if(!add) { if(v_ban_entry->v_count >= cfg.failbancount) { if(!v_ban_entry->acosc_entry) { cs_debug_mask(D_TRACE, "failban: banned ip %s:%d - %d seconds left%s%s", cs_inet_ntoa(v_ban_entry->v_ip), v_ban_entry->v_port, (ftime - gone)/1000, info ? ", info: " : "", info ? info : ""); } else { cs_debug_mask(D_TRACE, "failban: banned ip %s:%d - %d seconds left%s%s", cs_inet_ntoa(v_ban_entry->v_ip), v_ban_entry->v_port, (v_ban_entry->acosc_penalty_dur - (gone/1000)), info?", info: ":"", info?info:""); } } else { cs_debug_mask(D_TRACE, "failban: ip %s:%d chance %d of %d%s%s", cs_inet_ntoa(v_ban_entry->v_ip), v_ban_entry->v_port, v_ban_entry->v_count, cfg.failbancount, info ? ", info: " : "", info ? info : ""); v_ban_entry->v_count++; } } else { cs_debug_mask(D_TRACE, "failban: banned ip %s:%d - already exist in list%s%s", cs_inet_ntoa(v_ban_entry->v_ip), v_ban_entry->v_port, info ? ", info: " : "", info ? info : ""); } } } if(add && !result) { if(cs_malloc(&v_ban_entry, sizeof(V_BAN))) { cs_ftime(&v_ban_entry->v_time); v_ban_entry->v_ip = ip; v_ban_entry->v_port = port; v_ban_entry->v_count = 1; v_ban_entry->acosc_entry = false; v_ban_entry->acosc_penalty_dur = 0; if(acosc_penalty_duration > 0) { v_ban_entry->v_count = cfg.failbancount +1; // set it to a higher level v_ban_entry->acosc_entry = true; v_ban_entry->acosc_penalty_dur = acosc_penalty_duration; } if(info) { v_ban_entry->info = cs_strdup(info); } ll_iter_insert(&itr, v_ban_entry); cs_debug_mask(D_TRACE, "failban: ban ip %s:%d with timestamp %ld%s%s", cs_inet_ntoa(v_ban_entry->v_ip), v_ban_entry->v_port, v_ban_entry->v_time.time, info ? ", info: " : "", info ? info : ""); } } return result; }
int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data) { const struct config_list *c; for(c = clist; c->opt_type != OPT_UNKNOWN; c++) { if(c->opt_type == OPT_SAVE_FUNC || c->opt_type == OPT_FIXUP_FUNC) { continue; } if(strcasecmp(token, c->config_name) != 0) { continue; } void *var = config_data + c->var_offset; switch(c->opt_type) { case OPT_INT8: { *(int8_t *)var = (int8_t)strToIntVal(value, c->def.d_int8); return 1; } case OPT_UINT8: { uint32_t tmp = strToUIntVal(value, c->def.d_uint8); *(uint8_t *)var = (uint8_t)(tmp <= 0xff ? tmp : 0xff); return 1; } case OPT_INT32: { int32_t tmp = strToIntVal(value, c->def.d_int32); memcpy(var, &tmp, sizeof(int32_t)); return 1; } case OPT_UINT32: { uint32_t tmp = strToUIntVal(value, c->def.d_uint32); memcpy(var, &tmp, sizeof(uint32_t)); return 1; } case OPT_STRING: { char **scfg = var; if(c->def.d_char && strlen(value) == 0) // Set default { value = c->def.d_char; } NULLFREE(*scfg); if(strlen(value)) { *scfg = cs_strdup(value); } return 1; } case OPT_SSTRING: { char *scfg = var; if(c->def.d_char && strlen(value) == 0) // Set default { value = c->def.d_char; } scfg[0] = '\0'; unsigned int len = strlen(value); if(len) { strncpy(scfg, value, c->str_size - 1); if(len > c->str_size) { fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%u) exceeds max length: %d (%s)\n", token, value, len, c->str_size - 1, scfg); } } return 1; } case OPT_HEX_ARRAY: { uint8_t *hex_array = var; if(!strlen(value)) { memset(hex_array, 0, c->def.array_size); } else if(key_atob_l(value, hex_array, c->def.array_size * 2)) { memset(hex_array, 0, c->def.array_size); fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%zu) requires %d chars.\n", token, value, strlen(value), c->def.array_size * 2); } return 1; } case OPT_FUNC: { c->ops.process_fn(token, value, var, NULL); return 1; } case OPT_FUNC_EXTRA: { c->ops.process_fn_extra(token, value, var, c->def.d_extra, NULL); return 1; } case OPT_FIXUP_FUNC: case OPT_SAVE_FUNC: return 1; case OPT_UNKNOWN: { fprintf(stderr, "Unknown config type (%s = %s).", token, value); break; } } } return 0; }
TREE* constant_fold(CSOUND *csound, TREE* root) { extern MYFLT MOD(MYFLT, MYFLT); TREE* current = root; while (current) { switch (current->type) { case '+': case '-': case '*': case '/': case '^': case '%': case '|': case '&': case '#': case S_BITSHIFT_LEFT: case S_BITSHIFT_RIGHT: current->left = constant_fold(csound, current->left); current->right = constant_fold(csound, current->right); //print_tree(csound, "Folding case??\n", current); if ((current->left->type == INTEGER_TOKEN || current->left->type == NUMBER_TOKEN) && (current->right->type == INTEGER_TOKEN || current->right->type == NUMBER_TOKEN)) { MYFLT lval, rval; char buf[64]; lval = (current->left->type == INTEGER_TOKEN ? (double)current->left->value->value : current->left->value->fvalue); rval = (current->right->type == INTEGER_TOKEN ? (double)current->right->value->value : current->right->value->fvalue); //printf("lval = %g rval = %g\n", lval, rval); switch (current->type) { case '+': lval = lval + rval; break; case '-': lval = lval - rval; break; case '*': lval = lval * rval; break; case '/': lval = lval / rval; break; case '^': lval = POWER(lval,rval); break; case '%': lval = MOD(lval,rval); break; case '|': lval = (MYFLT)(((int)lval)|((int)rval)); break; case '&': lval = (MYFLT)(((int)lval)&((int)rval)); break; case '#': lval = (MYFLT)(((int)lval)^((int)rval)); break; case S_BITSHIFT_LEFT: lval = (MYFLT)(((int)lval)<<((int)rval)); break; case S_BITSHIFT_RIGHT: lval = (MYFLT)(((int)lval)>>((int)rval)); break; } //printf("ans = %g\n", lval); current->value = current->left->value; current->type = NUMBER_TOKEN; current->value->fvalue = lval; snprintf(buf, 60, "%.20g", lval); csound->Free(csound, current->value->lexeme); current->value->lexeme = cs_strdup(csound, buf); csound->Free(csound, current->left); csound->Free(csound, current->right->value); csound->Free(csound, current->right); current->right = current->left = NULL; } break; case S_UMINUS: case '~': //print_tree(csound, "Folding case?\n", current); current->right = constant_fold(csound, current->right); //print_tree(csound, "Folding case??\n", current); if (current->right->type == INTEGER_TOKEN || current->right->type == NUMBER_TOKEN) { MYFLT lval; char buf[64]; lval = (current->right->type == INTEGER_TOKEN ? (double)current->right->value->value : current->right->value->fvalue); switch (current->type) { case S_UMINUS: lval = -lval; break; case '~': lval = (MYFLT)(~(int)lval); break; } current->value = current->right->value; current->type = NUMBER_TOKEN; current->value->fvalue = lval; snprintf(buf, 60, "%.20g", lval); csound->Free(csound, current->value->lexeme); current->value->lexeme = cs_strdup(csound, buf); csound->Free(csound, current->right); current->right = NULL; } break; default: current->left = constant_fold(csound, current->left); current->right = constant_fold(csound, current->right); } current = current->next; }
static void init_machine_info(void) { struct utsname buffer; if (uname(&buffer) == 0) { cs_log("System name = %s", buffer.sysname); cs_log("Host name = %s", buffer.nodename); cs_log("Release = %s", buffer.release); cs_log("Version = %s", buffer.version); cs_log("Machine = %s", buffer.machine); } else { cs_log("ERROR: uname call failed: %s", strerror(errno)); } #if !defined(__linux__) return; #endif // Linux only functionality char boxtype[128]; boxtype[0] = 0; char model[128]; model[0] = 0; char vumodel[128]; vumodel[0] = 0; int8_t azmodel = 0; FILE *f; if ((f = fopen("/proc/stb/info/azmodel", "r"))){ azmodel = 1; fclose(f);} read_line_from_file("/proc/stb/info/model", model, sizeof(model)); read_line_from_file("/proc/stb/info/boxtype", boxtype, sizeof(boxtype)); read_line_from_file("/proc/stb/info/vumodel", vumodel, sizeof(vumodel)); if (vumodel[0] && !boxtype[0] && !azmodel) snprintf(boxtype, sizeof(boxtype), "vu%s", vumodel); if (!boxtype[0] && azmodel) snprintf(boxtype, sizeof(boxtype), "Azbox-%s", model); // Detect dreambox type if (strcasecmp(buffer.machine, "ppc") == 0 && !model[0] && !boxtype[0]) { char line[128], *p; int have_dreambox = 0; if ((f = fopen("/proc/cpuinfo", "r"))) { while (fgets(line, sizeof(line), f)) { if (strstr(line, "STBx25xx")) have_dreambox++; if (strstr(line, "pvr" )) have_dreambox++; if (strstr(line, "Dreambox")) have_dreambox++; if (strstr(line, "9.80" )) have_dreambox++; if (strstr(line, "63MHz" )) have_dreambox++; } fclose(f); have_dreambox = have_dreambox == 5 ? 1 : 0; // Need to find all 5 strings } if (have_dreambox) { if (read_line_from_file("/proc/meminfo", line, sizeof(line)) && (p = strchr(line, ' '))) { unsigned long memtotal = strtoul(p, NULL, 10); if (memtotal > 40000) snprintf(boxtype, sizeof(boxtype), "%s", "dm600pvr"); else snprintf(boxtype, sizeof(boxtype), "%s", "dm500"); } } } if (!boxtype[0] && !strcasecmp(model, "dm800") && !strcasecmp(buffer.machine, "armv7l")) snprintf(boxtype, sizeof(boxtype), "%s", "su980"); if (!boxtype[0]) { uchar *pos; pos = (uchar*) memchr(buffer.release, 'd', sizeof(buffer.release)); if(pos) { if((!memcmp(pos, "dbox2", sizeof("dbox2"))) && !strcasecmp(buffer.machine, "ppc")) { snprintf(boxtype, sizeof(boxtype), "%s", "dbox2"); } } } if (model[0]) cs_log("Stb model = %s", model); if (vumodel[0]) cs_log("Stb vumodel = vu%s", vumodel); if (boxtype[0]) { char boxname[128]; if(!strcasecmp(boxtype,"ini-8000am")){snprintf(boxname, sizeof(boxname), "%s", "Atemio Nemesis");} else if(!strcasecmp(boxtype,"ini-9000ru")){snprintf(boxname, sizeof(boxname), "%s", "Sezam Marvel");} else if(!strcasecmp(boxtype,"ini-8000sv")){snprintf(boxname, sizeof(boxname), "%s", "Miraclebox Ultra");} else if(!strcasecmp(boxtype,"ini-9000de")){snprintf(boxname, sizeof(boxname), "%s", "Xpeed LX3");} else boxname[0] = 0; if(boxname[0]){cs_log("Stb boxname = %s", boxname); stb_boxname = cs_strdup(boxname);} cs_log("Stb boxtype = %s", boxtype); } if (boxtype[0]) stb_boxtype = cs_strdup(boxtype); else if (model[0]) stb_boxtype = cs_strdup(model); }