chore: integrate cppcheck into workflow
This commit is contained in:
parent
b053aa6c93
commit
6af3e6ad6d
17 changed files with 64 additions and 69 deletions
|
|
@ -13,14 +13,12 @@
|
|||
#include "event_loop.h"
|
||||
#include "log.h"
|
||||
|
||||
static int event_loop_fd_set_nb(int fd) {
|
||||
static void event_loop_fd_set_nb(int fd) {
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
|
||||
flags |= O_NONBLOCK;
|
||||
|
||||
fcntl(fd, F_SETFL, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
event_loop *event_loop_init() {
|
||||
|
|
@ -61,13 +59,7 @@ int event_loop_accept(event_loop *el, int fd) {
|
|||
}
|
||||
|
||||
// set the new connection fd to nonblocking mode
|
||||
int res = event_loop_fd_set_nb(connfd);
|
||||
|
||||
if (res < 0) {
|
||||
close(connfd);
|
||||
|
||||
return -2;
|
||||
}
|
||||
event_loop_fd_set_nb(connfd);
|
||||
|
||||
// creating the struct Conn
|
||||
event_loop_conn *conn = event_loop_conn_init(el);
|
||||
|
|
@ -82,7 +74,7 @@ int event_loop_accept(event_loop *el, int fd) {
|
|||
conn->fd = connfd;
|
||||
conn->state = event_loop_conn_state_req;
|
||||
|
||||
res = event_loop_put(el, conn);
|
||||
int res = event_loop_put(el, conn);
|
||||
|
||||
if (res != 0) {
|
||||
close(connfd);
|
||||
|
|
@ -126,16 +118,10 @@ void event_loop_run(event_loop *el, int port) {
|
|||
}
|
||||
|
||||
// The listening socket is always poll'ed in non-blocking mode as well
|
||||
res = event_loop_fd_set_nb(fd);
|
||||
|
||||
if (res != 0) {
|
||||
critical(1, "Failed to set listening socket to non-blocking, errno: %i",
|
||||
errno);
|
||||
}
|
||||
event_loop_fd_set_nb(fd);
|
||||
|
||||
// TODO don't hardcode the number 32
|
||||
struct pollfd *poll_args = calloc(sizeof(struct pollfd), 32);
|
||||
size_t poll_args_count;
|
||||
|
||||
// for convenience, the listening fd is put in the first position
|
||||
struct pollfd pfd = {fd, POLLIN, 0};
|
||||
|
|
@ -147,7 +133,7 @@ void event_loop_run(event_loop *el, int port) {
|
|||
info("Starting event loop on port %i", port);
|
||||
|
||||
while (1) {
|
||||
poll_args_count = 1;
|
||||
size_t poll_args_count = 1;
|
||||
|
||||
// connection fds
|
||||
for (size_t i = 0; i < el->connection_count; i++) {
|
||||
|
|
@ -160,7 +146,8 @@ void event_loop_run(event_loop *el, int port) {
|
|||
events = (conn->state == event_loop_conn_state_req) ? POLLIN : POLLOUT;
|
||||
events |= POLLERR;
|
||||
|
||||
struct pollfd pfd = {conn->fd, events, 0};
|
||||
pfd.fd = conn->fd;
|
||||
pfd.events = events;
|
||||
|
||||
poll_args[poll_args_count] = pfd;
|
||||
poll_args_count++;
|
||||
|
|
|
|||
|
|
@ -72,17 +72,17 @@ event_loop *http_loop_init(http_route *routes, size_t route_count,
|
|||
}
|
||||
|
||||
void http_loop_set_api_key(http_loop *hl, const char *api_key) {
|
||||
((http_loop_gctx *)hl->gctx)->api_key = api_key;
|
||||
http_loop_gctx *gctx = hl->gctx;
|
||||
gctx->api_key = api_key;
|
||||
}
|
||||
|
||||
void http_loop_run(event_loop *el, int port) {
|
||||
debug("Compiling RegEx routes");
|
||||
|
||||
http_loop_gctx *gctx = el->gctx;
|
||||
http_route *route;
|
||||
|
||||
for (size_t i = 0; i < gctx->route_count; i++) {
|
||||
route = &gctx->routes[i];
|
||||
http_route *route = &gctx->routes[i];
|
||||
|
||||
if (route->type == http_route_regex) {
|
||||
regex_t *r = calloc(sizeof(regex_t), 1);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ bool http_loop_step_parse_content_length(event_loop_conn *conn) {
|
|||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
for (size_t i = 0; i < ctx->req.num_headers; i++) {
|
||||
struct phr_header *header = &ctx->req.headers[i];
|
||||
const struct phr_header *header = &ctx->req.headers[i];
|
||||
|
||||
if (strncmp(header->name, "Content-Length", header->name_len) == 0) {
|
||||
// If the content length header is present but contains an invalid
|
||||
|
|
@ -65,7 +65,7 @@ bool try_parse_content_length(event_loop_conn *conn) {
|
|||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
for (size_t i = 0; i < ctx->req.num_headers; i++) {
|
||||
struct phr_header *header = &ctx->req.headers[i];
|
||||
const struct phr_header *header = &ctx->req.headers[i];
|
||||
|
||||
if (strncmp(header->name, "Content-Length", header->name_len) == 0) {
|
||||
// If the content length header is present but contains an invalid
|
||||
|
|
@ -145,7 +145,7 @@ bool http_loop_step_auth(event_loop_conn *conn) {
|
|||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
for (size_t i = 0; i < ctx->req.num_headers; i++) {
|
||||
struct phr_header *header = &ctx->req.headers[i];
|
||||
const struct phr_header *header = &ctx->req.headers[i];
|
||||
|
||||
if ((strncmp("X-Api-Key", header->name, header->name_len) == 0) &&
|
||||
(strncmp(header->value, ctx->g->api_key, header->value_len) == 0) &&
|
||||
|
|
|
|||
|
|
@ -72,12 +72,12 @@ void lander_ctx_reset(lander_ctx *ctx) {
|
|||
|
||||
void lander_ctx_free(lander_ctx *ctx) { free(ctx); }
|
||||
|
||||
void lander_header_to_attr(http_loop_ctx *ctx, char *header_name,
|
||||
void lander_header_to_attr(http_loop_ctx *ctx, const char *header_name,
|
||||
lander_attr_type attr_type) {
|
||||
lander_ctx *c_ctx = ctx->c;
|
||||
|
||||
for (size_t i = 0; i < ctx->req.num_headers; i++) {
|
||||
struct phr_header *header = &ctx->req.headers[i];
|
||||
const struct phr_header *header = &ctx->req.headers[i];
|
||||
|
||||
if (strncmp(header->name, header_name, header->name_len) == 0) {
|
||||
if (header->value_len > 0) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ bool lander_insert_entry(http_loop_ctx *ctx) {
|
|||
randomize_key(key_s, key_len);
|
||||
lsm_str_init(&key, key_s);
|
||||
} else {
|
||||
char *key_s = (char *)&ctx->req.path[ctx->req.regex_groups[2].rm_so];
|
||||
const char *key_s = &ctx->req.path[ctx->req.regex_groups[2].rm_so];
|
||||
key_len = ctx->req.regex_groups[2].rm_eo - ctx->req.regex_groups[2].rm_so;
|
||||
|
||||
lsm_str_init_copy_n(&key, key_s, key_len);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue