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

          Line data    Source code
       1             : #include "http_minipot_config.h"
       2             : #include <minipot_argp.h>
       3             : #include <minipot_config_load.h>
       4             : #include <minipot_log.h>
       5             : #include <minipot_utils.h>
       6             : #include <logc_argp.h>
       7             : #include <logc_config.h>
       8             : #include "log.h"
       9             : 
      10             : const char *argp_program_version = "sentinel_minipot_http 0.1";
      11             : const char *argp_program_bug_address = PACKAGE_BUGREPORT;
      12             : 
      13             : static const char doc[] = "Turris Sentinel HTTP Minipot - minimal HTTP honeypot\n"
      14             : "It collects authentication data by emulating HTTP server.";
      15             : 
      16             : static const struct argp http_minipot_argp = {
      17             :         .doc = doc,
      18             :         .children = (struct argp_child[]){
      19             :                 {&minipot_argp, 0, NULL, 0},
      20             :                 {&logc_argp_parser, 0, "Logging", 2},
      21             :                 {NULL}
      22             :         },
      23             : };
      24             : 
      25           0 : void http_minipot_config_load(int argc, char **argv, struct http_minipot_config *cfg) {
      26             :         // bind the library log to ours to get logs form the library
      27           0 :         log_bind(log_sentinel_minipot_http, log_libsentinel_minipot);
      28             :         // bind logc_config log to ours log to get logs from configuration parsing
      29           0 :         log_bind(log_sentinel_minipot_http, log_logc_config);
      30             : 
      31             :         // set our log to be configured by logc_argp
      32           0 :         logc_argp_log = log_sentinel_minipot_http;
      33             :         // parse CLI options
      34           0 :         argp_parse(&http_minipot_argp, argc, argv, 0 , NULL, cfg);
      35             :         
      36             :         // parse configuration file
      37           0 :         if (cfg->parent.config_file) {
      38           0 :                 config_t conf;
      39           0 :                 if (minipot_config_load_from_file(&conf, cfg->parent.config_file)) {
      40             :                         // parse our log settings from log group
      41           0 :                         logc_config_load_setting(log_sentinel_minipot_http,
      42             :                                 config_lookup(&conf, "http_minipot.log"));
      43             :                         // parse minipot setting
      44           0 :                         minipot_config_parse_setting(&cfg->parent,
      45             :                                 config_lookup(&conf, "http_minipot"));
      46             :                 }
      47           0 :                 config_destroy(&conf);
      48             :         }
      49           0 : }
      50             : 
      51           0 : void http_minipot_config_init(struct http_minipot_config *cfg) {
      52           0 :         cfg->parent = (struct minipot_config){};
      53           0 :         minipot_config_init(&cfg->parent);
      54           0 : }
      55             : 
      56           0 : void http_minipot_config_destroy(struct http_minipot_config *cfg){
      57           0 :         minipot_config_destroy(&cfg->parent);
      58           0 : }
      59             : 
      60           0 : void http_minipot_config_check(struct http_minipot_config *cfg) {
      61           0 :         minipot_config_check(&cfg->parent);
      62           0 : }
      63             : 
      64           0 : void http_minipot_config_print(struct http_minipot_config *cfg) {
      65           0 :         char * str = minipot_config_2str(&cfg->parent);
      66           0 :         info("Using following configuration:\n%s", str);
      67           0 :         free(str);
      68           0 : }

Generated by: LCOV version 1.16