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
@@ -37,6 +37,10 @@ extern __xdata uint8_t sbuf[SBUF_SIZE];
|
||||
// Size of the TCP Output buffer
|
||||
#define TCP_OUTBUF_SIZE 2500
|
||||
|
||||
// Appended when a captured command wrote more than the output buffer holds,
|
||||
// so a clipped listing is visibly clipped instead of silently short.
|
||||
#define CMD_TRUNCATED "\n[output truncated]\n"
|
||||
|
||||
// Size of the port name, including the terminating null byte
|
||||
#define PORT_NAME_SIZE 32
|
||||
|
||||
|
||||
Reference in new issue
Block a user