// analyse the url given // The string passed to this function will look like this: // ?s=1 HTTP/1..... // We start after the first slash ("/" already removed) int8_t analyse_get_url(char *str) { // the first slash: if (*str == 'c'){ // alarm configpage: gPlen=print_alarm_config(); return(10); } if (*str == 'n'){ // network configpage: gPlen=print_net_config(); return(10); } if (*str == 'u'){ if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"pw")){ urldecode(gStrbuf); if (verify_password(gStrbuf)){ if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"n")){ urldecode(gStrbuf); gStrbuf[MYNAME_LEN]='\0'; strcpy(myname,gStrbuf); } if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"di")){ urldecode(gStrbuf); if (parse_ip(udpsrvip,gStrbuf)!=0){ return(-2); } // we've found destip, which means this is update from the // alarm conf page (this is a mandatory field) // Check alarm check box here if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"ae")){ alarmOn=1; }else{ alarmOn=0; } } if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"dp")){ gStrbuf[4]='\0'; udpsrvport=atoi(gStrbuf); } if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"hb")){ gStrbuf[4]='\0'; heartbeat_timeout_sec=atoi(gStrbuf); // we've found heartbeat, which means this is update from the // network conf page // Check dhcp check box here if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"dh")){ dhcpOn=1; }else{ dhcpOn=0; } } if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"gi")){ urldecode(gStrbuf); if (parse_ip(gwip,gStrbuf)!=0){ return(-2); } } if (find_key_val(str,gStrbuf,STR_BUFFER_SIZE,"ip")){ urldecode(gStrbuf); if (parse_ip(myip,gStrbuf)!=0){ return(-2); } } data2eeprom(); gPlen=http200ok(); gPlen=fill_tcp_data_p(buf,gPlen,PSTR("<a href=/>[home]</a>")); gPlen=fill_tcp_data_p(buf,gPlen,PSTR("<h2>OK</h2>")); return(10); } } return(-1); } return(0); }
/* Processes the current directive. * If the encoder returns an error, a message including current file and * line number together with the pt error string is printed on stderr. * * Returns 0 on success; a negative enum errcode otherwise. * Returns -err_internal if @p or @e is the NULL pointer. * Returns -err_parse_missing_directive if there was a pt directive marker, * but no directive. * Returns -stop_process if the .exp directive was encountered. * Returns -err_pt_lib if the pt encoder returned an error. * Returns -err_parse if a general parsing error was encountered. * Returns -err_parse_unknown_directive if there was an unknown pt directive. */ static int p_process(struct parser *p, struct pt_encoder *e) { int bytes_written; int errcode; char *directive, *payload, *pt_label_name, *tmp; struct pt_directive *pd; struct pt_packet packet; if (bug_on(!p)) return -err_internal; if (bug_on(!e)) return -err_internal; pd = p->pd; if (!pd) return -err_internal; directive = pd->name; payload = pd->payload; pt_label_name = NULL; bytes_written = 0; errcode = 0; /* find a label name. */ tmp = strchr(directive, ':'); if (tmp) { uint64_t x; pt_label_name = directive; directive = tmp+1; *tmp = '\0'; /* ignore whitespace between label and directive. */ while (isspace(*directive)) directive += 1; /* if we can lookup a yasm label with the same name, the * current pt directive label is invalid. */ errcode = yasm_lookup_label(p->y, &x, pt_label_name); if (errcode == 0) errcode = -err_label_not_unique; if (errcode != -err_no_label) return yasm_print_err(p->y, "label lookup", errcode); /* if we can lookup a pt directive label with the same * name, the current pt directive label is invalid. */ errcode = l_lookup(p->pt_labels, &x, pt_label_name); if (errcode == 0) errcode = -err_label_not_unique; if (errcode != -err_no_label) return yasm_print_err(p->y, "label lookup", -err_label_not_unique); } /* now try to match the directive string and call the * corresponding function that parses the payload and emits an * according packet. */ if (strcmp(directive, "") == 0) return yasm_print_err(p->y, "invalid syntax", -err_parse_missing_directive); else if (strcmp(directive, ".exp") == 0) { /* this is the end of processing pt directives, so we * add a p_last label to the pt directive labels. */ errcode = l_append(p->pt_labels, "eos", p->pt_bytes_written); if (errcode < 0) return yasm_print_err(p->y, "append label", errcode); return -stop_process; } if (strcmp(directive, "psb") == 0) { errcode = parse_empty(payload); if (errcode < 0) { yasm_print_err(p->y, "psb: parsing failed", errcode); goto error; } packet.type = ppt_psb; } else if (strcmp(directive, "psbend") == 0) { errcode = parse_empty(payload); if (errcode < 0) { yasm_print_err(p->y, "psbend: parsing failed", errcode); goto error; } packet.type = ppt_psbend; } else if (strcmp(directive, "pad") == 0) { errcode = parse_empty(payload); if (errcode < 0) { yasm_print_err(p->y, "pad: parsing failed", errcode); goto error; } packet.type = ppt_pad; } else if (strcmp(directive, "ovf") == 0) { errcode = parse_empty(payload); if (errcode < 0) { yasm_print_err(p->y, "ovf: parsing failed", errcode); goto error; } packet.type = ppt_ovf; } else if (strcmp(directive, "stop") == 0) { errcode = parse_empty(payload); if (errcode < 0) { yasm_print_err(p->y, "stop: parsing failed", errcode); goto error; } packet.type = ppt_stop; } else if (strcmp(directive, "tnt") == 0) { errcode = parse_tnt(&packet.payload.tnt.payload, &packet.payload.tnt.bit_size, payload); if (errcode < 0) { yasm_print_err(p->y, "tnt: parsing failed", errcode); goto error; } packet.type = ppt_tnt_8; } else if (strcmp(directive, "tnt64") == 0) { errcode = parse_tnt(&packet.payload.tnt.payload, &packet.payload.tnt.bit_size, payload); if (errcode < 0) { yasm_print_err(p->y, "tnt64: parsing failed", errcode); goto error; } packet.type = ppt_tnt_64; } else if (strcmp(directive, "tip") == 0) { errcode = parse_ip(p, &packet.payload.ip.ip, &packet.payload.ip.ipc, payload); if (errcode < 0) { yasm_print_err(p->y, "tip: parsing failed", errcode); goto error; } packet.type = ppt_tip; } else if (strcmp(directive, "tip.pge") == 0) { errcode = parse_ip(p, &packet.payload.ip.ip, &packet.payload.ip.ipc, payload); if (errcode < 0) { yasm_print_err(p->y, "tip.pge: parsing failed", errcode); goto error; } packet.type = ppt_tip_pge; } else if (strcmp(directive, "tip.pgd") == 0) { errcode = parse_ip(p, &packet.payload.ip.ip, &packet.payload.ip.ipc, payload); if (errcode < 0) { yasm_print_err(p->y, "tip.pgd: parsing failed", errcode); goto error; } packet.type = ppt_tip_pgd; } else if (strcmp(directive, "fup") == 0) { errcode = parse_ip(p, &packet.payload.ip.ip, &packet.payload.ip.ipc, payload); if (errcode < 0) { yasm_print_err(p->y, "fup: parsing failed", errcode); goto error; } packet.type = ppt_fup; } else if (strcmp(directive, "mode.exec") == 0) { if (strcmp(payload, "16bit") == 0) { packet.payload.mode.bits.exec.csl = 0; packet.payload.mode.bits.exec.csd = 0; } else if (strcmp(payload, "64bit") == 0) { packet.payload.mode.bits.exec.csl = 1; packet.payload.mode.bits.exec.csd = 0; } else if (strcmp(payload, "32bit") == 0) { packet.payload.mode.bits.exec.csl = 0; packet.payload.mode.bits.exec.csd = 1; } else { errcode = yasm_print_err(p->y, "mode.exec: argument must be one of \"16bit\", \"64bit\" or \"32bit\"", -err_parse); goto error; } packet.payload.mode.leaf = pt_mol_exec; packet.type = ppt_mode; } else if (strcmp(directive, "mode.tsx") == 0) { if (strcmp(payload, "begin") == 0) { packet.payload.mode.bits.tsx.intx = 1; packet.payload.mode.bits.tsx.abrt = 0; } else if (strcmp(payload, "abort") == 0) { packet.payload.mode.bits.tsx.intx = 0; packet.payload.mode.bits.tsx.abrt = 1; } else if (strcmp(payload, "commit") == 0) { packet.payload.mode.bits.tsx.intx = 0; packet.payload.mode.bits.tsx.abrt = 0; } else { errcode = yasm_print_err(p->y, "mode.tsx: argument must be one of \"begin\", \"abort\" or \"commit\"", -err_parse); goto error; } packet.payload.mode.leaf = pt_mol_tsx; packet.type = ppt_mode; } else if (strcmp(directive, "pip") == 0) { const char *modifier; errcode = parse_uint64(&packet.payload.pip.cr3, payload); if (errcode < 0) { yasm_print_err(p->y, "pip: parsing failed", errcode); goto error; } packet.type = ppt_pip; packet.payload.pip.nr = 0; modifier = strtok(NULL, " ,"); if (modifier) { if (strcmp(modifier, "nr") == 0) packet.payload.pip.nr = 1; else { yasm_print_err(p->y, "pip: parsing failed", -err_parse_trailing_tokens); goto error; } } } else if (strcmp(directive, "tsc") == 0) { errcode = parse_uint64(&packet.payload.tsc.tsc, payload); if (errcode < 0) { yasm_print_err(p->y, "tsc: parsing failed", errcode); goto error; } packet.type = ppt_tsc; } else if (strcmp(directive, "cbr") == 0) { errcode = parse_uint8(&packet.payload.cbr.ratio, payload); if (errcode < 0) { yasm_print_err(p->y, "cbr: parsing cbr failed", errcode); goto error; } packet.type = ppt_cbr; } else if (strcmp(directive, "tma") == 0) { errcode = parse_tma(&packet.payload.tma.ctc, &packet.payload.tma.fc, payload); if (errcode < 0) { yasm_print_err(p->y, "tma: parsing tma failed", errcode); goto error; } packet.type = ppt_tma; } else if (strcmp(directive, "mtc") == 0) { errcode = parse_uint8(&packet.payload.mtc.ctc, payload); if (errcode < 0) { yasm_print_err(p->y, "mtc: parsing mtc failed", errcode); goto error; } packet.type = ppt_mtc; } else if (strcmp(directive, "cyc") == 0) { errcode = parse_uint64(&packet.payload.cyc.value, payload); if (errcode < 0) { yasm_print_err(p->y, "cyc: parsing cyc failed", errcode); goto error; } packet.type = ppt_cyc; } else if (strcmp(directive, "vmcs") == 0) { errcode = parse_uint64(&packet.payload.vmcs.base, payload); if (errcode < 0) { yasm_print_err(p->y, "vmcs: parsing failed", errcode); goto error; } packet.type = ppt_vmcs; } else if (strcmp(directive, "mnt") == 0) { errcode = parse_uint64(&packet.payload.mnt.payload, payload); if (errcode < 0) { yasm_print_err(p->y, "mnt: parsing failed", errcode); goto error; } packet.type = ppt_mnt; } else { errcode = yasm_print_err(p->y, "invalid syntax", -err_parse_unknown_directive); goto error; } bytes_written = pt_enc_next(e, &packet); if (bytes_written < 0) { const char *errstr, *format; char *msg; size_t n; errstr = pt_errstr(pt_errcode(bytes_written)); format = "encoder error in directive %s (status %s)"; /* the length of format includes the "%s" (-2) * characters, we add errstr (+-0) and then we need * space for a terminating null-byte (+1). */ n = strlen(format)-4 + strlen(directive) + strlen(errstr) + 1; msg = malloc(n); if (!msg) errcode = yasm_print_err(p->y, "encoder error not enough memory to show error code", -err_pt_lib); else { sprintf(msg, format, directive, errstr); errcode = yasm_print_err(p->y, msg, -err_pt_lib); free(msg); } } else { if (pt_label_name) { errcode = l_append(p->pt_labels, pt_label_name, p->pt_bytes_written); if (errcode < 0) goto error; } p->pt_bytes_written += bytes_written; } error: if (errcode < 0) bytes_written = errcode; return bytes_written; }
static void parse_cmdline(int argc, char **argp) { unsigned int i = 1; if(argc < 2) { show_usage(1); } if (!strcmp(argp[i], "-h")) { show_usage(0); } else if (!strcmp(argp[i], "-srq")) { command = COM_SRQ; i++; if(argc != 5) show_usage(1); parse_port(argp[i++]); parse_q(argp[i++]); parse_pt(argp[i++]); } else if (!strcmp(argp[i], "-sq")) { command = COM_SQ; i++; if(argc != 6) show_usage(1); parse_port(argp[i++]); parse_q(argp[i++]); parse_mac(argp[i++], mac); } else if (!strcmp(argp[i], "-srp")) { command = COM_SRP; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_policy(argp[i++]); } else if (!strcmp(argp[i], "-srqw")) { command = COM_SRQW; i++; if(argc != 5) show_usage(1); parse_port(argp[i++]); parse_q(argp[i++]); parse_hex_val(argp[i++], &weight); } else if (!strcmp(argp[i], "-stp")) { command = COM_STP; i++; if(argc != 6) show_usage(1); parse_port(argp[i++]); parse_q(argp[i++]); parse_hex_val(argp[i++], &weight); parse_policy(argp[i++]); } else if (!strcmp(argp[i], "-fprs")) { command = COM_IP_RULE_SET; i++; if(argc != 8) show_usage(1); parse_dec_val(argp[i++], &inport); parse_dec_val(argp[i++], &outport); parse_ip(argp[i++], &dip); parse_ip(argp[i++], &sip); parse_mac(argp[i++], da); parse_mac(argp[i++], sa); } else if (!strcmp(argp[i], "-fprd")) { command = COM_IP_RULE_DEL; i++; if(argc != 4) show_usage(1); parse_ip(argp[i++], &dip); parse_ip(argp[i++], &sip); } else if (!strcmp(argp[i], "-fp_st")) { command = COM_NFP_STATUS; if(argc != 2) show_usage(1); } else if (!strcmp(argp[i], "-fp_print")) { command = COM_NFP_PRINT; i++; if (argc != 3) show_usage(1); parse_db_name(argp[i++]); } else if (!strcmp(argp[i], "-txdone")) { command = COM_TXDONE_Q; i++; if(argc != 3) show_usage(1); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-txen")) { command = COM_TX_EN; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-lro")) { command = COM_LRO; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-lro_desc")) { command = COM_LRO_DESC; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-reuse")) { command = COM_SKB_REUSE; i++; if(argc != 3) show_usage(1); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-recycle")) { command = COM_SKB_RECYCLE; i++; if(argc != 3) show_usage(1); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-nfp")) { command = COM_NFP; i++; if(argc != 3) show_usage(1); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-rxcoal")) { command = COM_RX_COAL; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-txcoal")) { command = COM_TX_COAL; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-ejp")) { command = COM_EJP_MODE; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-tos")) { command = COM_TOS_MAP; i++; if(argc != 5) show_usage(1); parse_port(argp[i++]); parse_q(argp[i++]); parse_hex_val(argp[i++], &value); } else if (!strcmp(argp[i], "-tx_noq")) { command = COM_TX_NOQUEUE; i++; if(argc != 4) show_usage(1); parse_port(argp[i++]); parse_dec_val(argp[i++], &value); } else if (!strcmp(argp[i], "-St")) { command = COM_STS; i++; if(argc < 4) show_usage(1); parse_status(argp[i++]); if( status == STS_PORT_Q ) { if(argc != 5) show_usage(1); parse_q(argp[i++]); } else if(argc != 4) show_usage(1); parse_port(argp[i++]); } else { show_usage(i++); } }
uint8_t EtherShield::ES_parse_ip(uint8_t *bytestr,char *str) { return parse_ip(bytestr,str); }