aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-10-17 23:34:59 +0200
committerPřemysl Janouch <p@janouch.name>2018-10-17 23:34:59 +0200
commit253e35e1e43b8c7f8ea8de7b94556a4ef6cf0d95 (patch)
treebcdafdfe8356ac70d63ec8e58131bb19689803e0
parentcf56921c4e1959bb3962b4f99ee4a1e7665c57d4 (diff)
downloadjson-rpc-shell-253e35e1e43b8c7f8ea8de7b94556a4ef6cf0d95.tar.gz
json-rpc-shell-253e35e1e43b8c7f8ea8de7b94556a4ef6cf0d95.tar.xz
json-rpc-shell-253e35e1e43b8c7f8ea8de7b94556a4ef6cf0d95.zip
Wrap request::write_cb in a function
-rw-r--r--demo-json-rpc-server.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/demo-json-rpc-server.c b/demo-json-rpc-server.c
index 2b99419..9552146 100644
--- a/demo-json-rpc-server.c
+++ b/demo-json-rpc-server.c
@@ -1563,6 +1563,13 @@ request_free (struct request *self)
self->handler->finalize_cb (self);
}
+/// Write request CGI response data, intended for use by request handlers
+static void
+request_write (struct request *self, const void *data, size_t len)
+{
+ self->write_cb (self, data, len);
+}
+
/// This function is only intended to be run from asynchronous event handlers
/// such as timers, not as a direct result of starting the request or receiving
/// request data. CALLING THIS MAY CAUSE THE REQUEST TO BE DESTROYED.
@@ -1599,7 +1606,7 @@ request_start (struct request *self, struct str_map *headers)
struct str response = str_make ();
str_append (&response, "Status: 404 Not Found\n");
str_append (&response, "Content-Type: text/plain\n\n");
- self->write_cb (self, response.str, response.len);
+ request_write (self, response.str, response.len);
str_free (&response);
return false;
}
@@ -1654,7 +1661,7 @@ request_handler_json_rpc_push
str_append (&response, "Status: 200 OK\n");
str_append_printf (&response, "Content-Type: %s\n\n", "application/json");
process_json_rpc (request->ctx, buf->str, buf->len, &response);
- request->write_cb (request, response.str, response.len);
+ request_write (request, response.str, response.len);
str_free (&response);
return false;
}
@@ -1770,7 +1777,7 @@ request_handler_static_try_handle
str_append (&response, "Content-Type: text/plain\n\n");
str_append_printf (&response,
"File %s was not found on this server\n", suffix);
- request->write_cb (request, response.str, response.len);
+ request_write (request, response.str, response.len);
str_free (&response);
free (suffix);
@@ -1794,17 +1801,17 @@ request_handler_static_try_handle
struct str response = str_make ();
str_append (&response, "Status: 200 OK\n");
str_append_printf (&response, "Content-Type: %s\n\n", mime_type);
- request->write_cb (request, response.str, response.len);
+ request_write (request, response.str, response.len);
str_free (&response);
free (mime_type);
// Write the chunk we've used to help us with magic detection;
// obviously we have to do it after we've written the headers
if (len)
- request->write_cb (request, buf, len);
+ request_write (request, buf, len);
while ((len = fread (buf, 1, sizeof buf, fp)))
- request->write_cb (request, buf, len);
+ request_write (request, buf, len);
fclose (fp);
// TODO: this should rather not be returned all at once but in chunks;