aboutsummaryrefslogtreecommitdiff
path: root/gmid.h
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-02-01 22:04:51 +0000
committerOmar Polo <op@omarpolo.com>2021-02-01 22:04:51 +0000
commit35744950aa0953bee3035400e8035af844a675ba (patch)
treed80acba024c823266f6bf279ce1ca94115e829bc /gmid.h
parentb06f80cdf43be684bd57f9674917d2479bc0d317 (diff)
simplify handle_cgi
Now that I got rid of the enum+switch, adding more state is easier. Before, we used an hack to remember if we had read the CGI reply or not (c->code = -1). This introduces a new state, handle_cgi_reply that reads the CGI script reply, logs it, and only then switches to handle_cgi. handle_cgi itself is cleaner, now it only reads into c->sbuf and send what it had red. We even get, almost for free, the 42 error. If read exists with -1 or 0 from in handle_cgi_reply, we return a proper error to the client. We can extend this further in the future and also try to validate the CGI reply (for now we're only looking for a \n).
Diffstat (limited to 'gmid.h')
-rw-r--r--gmid.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/gmid.h b/gmid.h
index 4cf6266..1ba4a9e 100644
--- a/gmid.h
+++ b/gmid.h
@@ -42,6 +42,7 @@
#define SUCCESS 20
#define TEMP_REDIRECT 30
#define TEMP_FAILURE 40
+#define CGI_ERROR 42
#define NOT_FOUND 51
#define PROXY_REFUSED 53
#define BAD_REQUEST 59
@@ -134,10 +135,13 @@ typedef void (*statefn)(struct pollfd*, struct client*);
* handle_handshake -> handle_open_conn
* handle_handshake -> close_conn // on err
*
- * handle_open_conn -> handle_cgi // via open_file/dir/...
+ * handle_open_conn -> handle_cgi_reply // via open_file/dir/...
* handle_open_conn -> send_directory_listing // ...same
* handle_open_conn -> send_file // ...same
- * handle_open_conn -> close_conn // on error
+ * handle_open_conn -> start_reply // on error
+ *
+ * handle_cgi_reply -> handle_cgi // after logging the CGI reply
+ * handle_cgi_reply -> start_reply // on error
*
* handle_cgi -> close_conn
*
@@ -229,6 +233,7 @@ int read_next_dir_entry(struct client*);
void send_directory_listing(struct pollfd*, struct client*);
void cgi_poll_on_child(struct pollfd*, struct client*);
void cgi_poll_on_client(struct pollfd*, struct client*);
+void handle_cgi_reply(struct pollfd*, struct client*);
void handle_cgi(struct pollfd*, struct client*);
void close_conn(struct pollfd*, struct client*);
void do_accept(int, struct tls*, struct pollfd*, struct client*);