Skip to content

Commit

Permalink
check the arguments like printf
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jan 6, 2021
1 parent e7f5ca1 commit d53a954
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions example/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ static void default_handler(struct uh_connection *conn, int event)
conn->send_head(conn, HTTP_STATUS_OK, -1, NULL);
conn->chunk_printf(conn, "I'm Libuhttpd: %s\n", UHTTPD_VERSION_STRING);
conn->chunk_printf(conn, "Method: %s\n", conn->get_method_str(conn));
conn->chunk_printf(conn, "Path: %.*s\n", path.len ,path.p);
conn->chunk_printf(conn, "Query: %.*s\n", query.len, query.p);
conn->chunk_printf(conn, "User-Agent: %.*s\n", ua.len, ua.p);
conn->chunk_printf(conn, "Body: %.*s\n", body.len, body.p);
conn->chunk_printf(conn, "Path: %.*s\n", (int)path.len ,path.p);
conn->chunk_printf(conn, "Query: %.*s\n", (int)query.len, query.p);
conn->chunk_printf(conn, "User-Agent: %.*s\n", (int)ua.len, ua.p);
conn->chunk_printf(conn, "Body: %.*s\n", (int)body.len, body.p);
conn->chunk_end(conn);
conn->done(conn);
} else {
Expand Down
2 changes: 1 addition & 1 deletion example/test_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void test_handler(struct uh_connection *conn, int event)
path = conn->get_path(conn);

conn->send_head(conn, 200, -1, NULL);
conn->chunk_printf(conn, "Path: %.*s\n", path.len, path.p);
conn->chunk_printf(conn, "Path: %.*s\n", (int)path.len, path.p);
conn->chunk_end(conn);
}

Expand Down
10 changes: 4 additions & 6 deletions src/uhttpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ struct uh_connection {
void (*done)(struct uh_connection *conn);
void (*send)(struct uh_connection *conn, const void *data, ssize_t len);
void (*send_file)(struct uh_connection *conn, const char *path, size_t offset, ssize_t len);
void (*printf)(struct uh_connection *conn, const char *format, ...);
void (*printf)(struct uh_connection *conn, const char *format, ...) __attribute__((format(printf, 2, 3)));
void (*vprintf)(struct uh_connection *conn, const char *format, va_list arg);
void (*send_status_line)(struct uh_connection *conn, int code, const char *extra_headers);
void (*send_head)(struct uh_connection *conn, int code, int content_length, const char *extra_headers);
void (*error)(struct uh_connection *conn, int code, const char *reason);
void (*redirect)(struct uh_connection *conn, int code, const char *location, ...);
void (*redirect)(struct uh_connection *conn, int code, const char *location, ...) __attribute__((format(printf, 3, 4)));
void (*serve_file)(struct uh_connection *conn);
void (*chunk_send)(struct uh_connection *conn, const void *data, ssize_t len);
void (*chunk_printf)(struct uh_connection *conn, const char *format, ...);
void (*chunk_printf)(struct uh_connection *conn, const char *format, ...) __attribute__((format(printf, 2, 3)));
void (*chunk_vprintf)(struct uh_connection *conn, const char *format, va_list arg);
void (*chunk_end)(struct uh_connection *conn);
const struct sockaddr *(*get_addr)(struct uh_connection *conn); /* peer address */
const struct sockaddr *(*get_addr)(struct uh_connection *conn); /* peer address */
enum http_method (*get_method)(struct uh_connection *conn);
const char *(*get_method_str)(struct uh_connection *conn);
struct uh_str (*get_path)(struct uh_connection *conn);
Expand Down Expand Up @@ -117,7 +117,6 @@ struct uh_path_handler {
char path[0];
};


/*
* uh_server_new - creat an uh_server struct and init it
* @loop: If NULL will use EV_DEFAULT
Expand All @@ -129,4 +128,3 @@ struct uh_server *uh_server_new(struct ev_loop *loop, const char *host, int port
int uh_server_init(struct uh_server *srv, struct ev_loop *loop, const char *host, int port);

#endif

0 comments on commit d53a954

Please sign in to comment.