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

          Line data    Source code
       1             : #ifndef _SENTINEL_MINIPOT_SENTINEL_MSG_PACKER_H_
       2             : #define _SENTINEL_MINIPOT_SENTINEL_MSG_PACKER_H_
       3             : 
       4             : #include <stdint.h>
       5             : #include <stddef.h>
       6             : 
       7             : struct minipot_uint8_t_pair {
       8             :         const uint8_t *key;
       9             :         size_t key_len;
      10             :         const uint8_t *val;
      11             :         size_t val_len;
      12             : };
      13             : 
      14             : struct minipot_sentinel_msg {
      15             :         // these fields are mandatory
      16             :         uint32_t ts;
      17             :         // MUST be NULL terminated strings
      18             :         const char *type;
      19             :         const char *ip;
      20             :         const char *action;
      21             :         // optional data from an attacker
      22             :         const struct minipot_uint8_t_pair *data;
      23             :         size_t data_len;
      24             : };
      25             : 
      26             : struct minipot_sentinel_msg_packer;
      27             : typedef struct minipot_sentinel_msg_packer* minipot_sentinel_msg_packer_t;
      28             : 
      29             : // Frees an instance.
      30           0 : void minipot_sentinel_msg_packer_free(minipot_sentinel_msg_packer_t)
      31             :         __attribute__((nonnull));
      32             : 
      33             : // Allocates an instance.
      34           0 : minipot_sentinel_msg_packer_t minipot_sentinel_msg_packer_new()
      35             :         __attribute__((malloc, returns_nonnull));
      36             : 
      37             : // Checks a given message for data validity. Returns 0 if OK otherwise -1.
      38             : // This is good to call before `minipot_sentinel_msg_packer_pack`.
      39           0 : int minipot_check_sentinel_msg(const struct minipot_sentinel_msg *)
      40             :         __attribute__((nonnull));
      41             : 
      42             : // Serializes a Sentinel message struct. A caller should check
      43             : // sentinel messsage before packing by `minipot_sentinel_msg_packer_check`.
      44             : // The packed data and their length can be retreived by
      45             : // `minipot_sentinel_msg_packer_retreive_data` and
      46             : // `minipot_sentinel_msg_packer_retreive_dlen`.
      47           0 : void minipot_sentinel_msg_packer_pack(minipot_sentinel_msg_packer_t,
      48             :         const struct minipot_sentinel_msg *) __attribute__((nonnull));
      49             : 
      50             : // Returns pointer to a packed data. The data must be first packed by
      51             : // `minipot_sentinel_msg_packer_pack`. Caller MUST NOT free it.
      52           0 : char *minipot_sentinel_msg_packer_retreive_data(minipot_sentinel_msg_packer_t)
      53             :         __attribute__((nonnull));
      54             : 
      55             : // Returns length of a packed data. The data must be first packed by
      56             : // `minipot_sentinel_msg_packer_pack`.
      57           0 : size_t minipot_sentinel_msg_packer_retreive_dlen(minipot_sentinel_msg_packer_t)
      58             :         __attribute__((nonnull));
      59             : 
      60             : 
      61             : #endif

Generated by: LCOV version 1.16