mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
httpd: make the /cmd answer usable when a command fails or floods
Three ways the answer could mislead the caller, all in the paths that matter most when something is wrong. The capture sat in write_char(), so anything printed through print_string_no_syslog() escaped it. That is exactly the replies of the syslog commands, which deliberately avoid the syslog path: "syslog on" answered with the bare address and no sentence around it, "syslog off" answered with nothing at all. Moving the capture one level down, into write_char_no_syslog(), catches both paths and costs nothing, since write_char() reaches it anyway. On a parse error send_bad_request() rewrote the buffer from the start, throwing away the very text that explains the error and replacing it with the 400 HTML page. Keeping the captured text and restating only the status keeps the parser's own message; "400 NO" is as long as "200 OK", so the header does not have to be rebuilt. An overlong listing was cut at the buffer end with nothing to show for it, so a clipped answer read as a short one. It now ends in a marker, and the reserved room is accounted for in the guard. While here: a command that configures something prints nothing, and an empty body reads the same as "nothing ran", so a successful silent command now answers "OK". No internal RAM and no xdata; 174 bytes of BANK1, which has 7356 left.
This commit is contained in:
1 parent
f46ef3a43c
commit
f23d840cee
3 files changed
+37
-8
No files matched your search
+11
-3
@@ -248,6 +248,17 @@ extern __xdata uint16_t slen;
|
||||
|
||||
void write_char_no_syslog(char c)
|
||||
{
|
||||
/* Capturing sits here rather than in write_char() so that the messages
|
||||
* printed through print_string_no_syslog() are captured too: those are
|
||||
* the replies of the syslog commands, which must not generate a syslog
|
||||
* packet but do belong in the answer to a command sent over HTTP. */
|
||||
if (cmd_capture) {
|
||||
if (slen < TCP_OUTBUF_SIZE - sizeof(CMD_TRUNCATED))
|
||||
outbuf[slen++] = c;
|
||||
else
|
||||
cmd_capture = 2; /* out of room, httpd says so */
|
||||
}
|
||||
|
||||
do {
|
||||
} while (tx_buf_empty == 0);
|
||||
if (c =='\n') {
|
||||
@@ -262,9 +273,6 @@ void write_char_no_syslog(char c)
|
||||
|
||||
void write_char(char c)
|
||||
{
|
||||
if (cmd_capture && slen < TCP_OUTBUF_SIZE - 1)
|
||||
outbuf[slen++] = c;
|
||||
|
||||
write_char_no_syslog(c);
|
||||
|
||||
if (syslog_state.enabled) {
|
||||
|
||||
Reference in new issue
Block a user