LCOV - code coverage report
Current view: top level - minipot/http - http_minipot.c (source / functions) Hit Total Coverage
Test: sentinel-minipot-2.3.0 Code Coverage Lines: 0 44 0.0 %
Date: 2022-11-27 17:36:11 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "http_minipot.h"
       2             : #include <minipot_utils.h>
       3             : #include <stdlib.h>
       4             : #include "log.h"
       5             : 
       6             : #define SESSIONS_PER_PORT 5
       7             : 
       8           0 : static void accept_cb(evutil_socket_t fd, short events, void *arg) {
       9           0 :         MINIPOT_TRACE_FUNC;
      10           0 :         struct http_minipot *minipot = arg;
      11           0 :         int no_available_session = 1;
      12           0 :         for (size_t i = 0; i < SESSIONS_PER_PORT * minipot->parent.ports_cnt; i++)
      13           0 :                 if (http_minipot_session_is_available(minipot->http_minipot_sessions + i)) {
      14           0 :                         http_minipot_session_accept(minipot->http_minipot_sessions + i, fd);
      15           0 :                         no_available_session = 0;
      16           0 :                         break;
      17             :                 }
      18           0 :         if (no_available_session)
      19           0 :                 http_minipot_stop_accept_new_conn(minipot);
      20           0 : }
      21             : 
      22           0 : void http_minipot_init(struct http_minipot *self, int pipe_write_fd,
      23             :                 const struct http_minipot_config *conf) {
      24           0 :         MINIPOT_TRACE_FUNC;
      25           0 :         minipot_init(&self->parent, &conf->parent, pipe_write_fd, accept_cb, self);
      26           0 :         self->http_minipot_sessions = malloc(sizeof(*self->http_minipot_sessions)
      27           0 :                 * SESSIONS_PER_PORT * self->parent.ports_cnt);
      28           0 :         for (size_t i = 0; i < SESSIONS_PER_PORT * self->parent.ports_cnt; i++)
      29           0 :                 http_minipot_session_init(self->http_minipot_sessions + i, self);
      30           0 :         self->tokens = malloc(sizeof(*self->tokens) * TOKENS_LEN);
      31           0 :         self->dcode_buff = malloc(sizeof(*self->dcode_buff) * DCODE_BUFF_LEN);
      32           0 : }
      33             : 
      34           0 : void http_minipot_destroy(struct http_minipot *self) {
      35           0 :         MINIPOT_TRACE_FUNC;
      36           0 :         for (size_t i = 0; i < SESSIONS_PER_PORT * self->parent.ports_cnt; i++)
      37           0 :                 http_minipot_session_destroy(self->http_minipot_sessions + i);
      38           0 :         free(self->http_minipot_sessions);
      39           0 :         free(self->tokens);
      40           0 :         free(self->dcode_buff);
      41           0 :         minipot_destroy(&self->parent);
      42           0 : }
      43             : 
      44           0 : int http_minipot_run(struct http_minipot *self) {
      45           0 :         MINIPOT_TRACE_FUNC;
      46           0 :         return (http_minipot_start_accept_new_conn(self)
      47           0 :                 || minipot_run(&self->parent));
      48             : }
      49             : 
      50           0 : int http_minipot_stop(struct http_minipot *self) {
      51           0 :         MINIPOT_TRACE_FUNC;
      52           0 :         return minipot_stop(&self->parent);
      53             : }
      54             : 
      55           0 : int http_minipot_start_accept_new_conn(struct http_minipot *self) {
      56           0 :         MINIPOT_TRACE_FUNC;
      57           0 :         return minipot_start_accept_new_conn(&self->parent);
      58             : }
      59             : 
      60           0 : int http_minipot_stop_accept_new_conn(struct http_minipot *self) {
      61           0 :         MINIPOT_TRACE_FUNC;
      62           0 :         return minipot_stop_accept_new_conn(&self->parent);
      63             : }

Generated by: LCOV version 1.16