static uint16_t read_byte(void) { uint8_t t1, t2; char c; c = cli_getc_cecho(); if (c == '-') { return 0x0500; } t1 = char2nibble(c); if (t1 == 0xff) { return 0x0100; } c = cli_getc_cecho(); t2 = char2nibble(c); if (t2 == 0xff) { return 0x0200|t1; } return (t1 << 4)|t2; }
/* Parse a tag value pair. tag1=value1&tag2=value2 */ static char *httpd_parse_msgbody(char *data_p, const char *tag, char *val, unsigned val_len, short *found) { int i, c1, c2; char *ptr; const char *tag_p; *found = 0; if (data_p == NULL || *data_p == '\0') return NULL; ptr = data_p; tag_p = tag; while (1) { if (*ptr == 0) { httpd_d("End of string reached"); return NULL; } if (*ptr == '=') { /* End of tag */ if (*tag_p != 0) goto next_token; else break; } /* perform url decode */ if (*ptr == '%') { ptr++; c1 = char2nibble(*ptr++); c2 = char2nibble(*ptr++); if (c1 == -1 || c2 == -1) { httpd_d("Invalid URL-encoded" " string. Ignoring."); return NULL; } if (*tag_p != ((c1 << 4) | c2)) goto next_token; tag_p++; } else if (*ptr == '+') { if (*tag_p != ' ') goto next_token; tag_p++; ptr++; } else { if (*tag_p != *ptr) goto next_token; ptr++; tag_p++; } } /* We come here only if tag was found */ *found = 1; ptr = strchr(ptr, '='); /* skip to next token */ if (ptr == NULL) { httpd_d("No = after tag"); return NULL; } ptr++; for (i = 0; i < val_len; i++) { if ((*ptr == '&') || (*ptr == 0)) { val[i] = 0; break; } /* perform url decode */ if (*ptr == '%') { ptr++; c1 = char2nibble(*ptr++); c2 = char2nibble(*ptr++); if (c1 == -1 || c2 == -1) { httpd_d("Invalid URL-encoded" " string. Ignoring."); return NULL; } val[i] = (c1 << 4) | c2; } else if (*ptr == '+') { val[i] = ' '; ptr++; } else { val[i] = *ptr++; } } if (i == val_len) { val[val_len] = 0; if ((*ptr != '&') && (*ptr != 0)) httpd_d("Max val length exceeded. " "Truncating value "); } next_token: ptr = strchr(ptr, '&'); /* skip to next token */ if (ptr == NULL) { return NULL; } return ptr + 1; }