SolidSyslog coverage report
Current view: top level - Core/Source - SolidSyslogStreamSenderStatic.c (source / functions) Coverage Total Hit
Test: SolidSyslog Lines: 100.0 % 39 39
Test Date: 2026-11-12 23:14:35 Functions: 100.0 % 5 5
Branches: 100.0 % 22 22

             Branch data     Line data    Source code
       1                 :             : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
       2                 :             :  * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
       3                 :             :  */
       4                 :             : 
       5                 :             : #include "SolidSyslogStreamSender.h"
       6                 :             : 
       7                 :             : #include <stdbool.h>
       8                 :             : #include <stddef.h>
       9                 :             : #include <stdint.h>
      10                 :             : 
      11                 :             : #include "SolidSyslogError.h"
      12                 :             : #include "SolidSyslogErrorCategory.h"
      13                 :             : #include "SolidSyslogNullSender.h"
      14                 :             : #include "SolidSyslogPoolAllocator.h"
      15                 :             : #include "SolidSyslogPrival.h"
      16                 :             : #include "SolidSyslogStreamSenderErrors.h"
      17                 :             : #include "SolidSyslogStreamSenderPrivate.h"
      18                 :             : #include "SolidSyslogTunables.h"
      19                 :             : 
      20                 :             : struct SolidSyslogSender;
      21                 :             : 
      22                 :             : static bool StreamSender_IsValidConfig(const struct SolidSyslogStreamSenderConfig* config);
      23                 :             : static inline size_t StreamSender_IndexFromHandle(const struct SolidSyslogSender* base);
      24                 :             : static inline void StreamSender_CleanupAtIndex(size_t index, void* context);
      25                 :             : 
      26                 :             : static bool StreamSender_InUse[SOLIDSYSLOG_STREAM_SENDER_POOL_SIZE];
      27                 :             : static struct SolidSyslogStreamSender StreamSender_Pool[SOLIDSYSLOG_STREAM_SENDER_POOL_SIZE];
      28                 :             : static struct SolidSyslogPoolAllocator StreamSender_Allocator = {
      29                 :             :     StreamSender_InUse,
      30                 :             :     SOLIDSYSLOG_STREAM_SENDER_POOL_SIZE
      31                 :             : };
      32                 :             : 
      33                 :         227 : struct SolidSyslogSender* SolidSyslogStreamSender_Create(const struct SolidSyslogStreamSenderConfig* config)
      34                 :             : {
      35                 :         227 :     struct SolidSyslogSender* result = SolidSyslogNullSender_Get();
      36         [ +  + ]:         227 :     if (StreamSender_IsValidConfig(config))
      37                 :             :     {
      38                 :         221 :         size_t index = SolidSyslogPoolAllocator_AcquireFirstFree(&StreamSender_Allocator);
      39         [ +  + ]:         221 :         if (SolidSyslogPoolAllocator_IndexIsValid(&StreamSender_Allocator, index))
      40                 :             :         {
      41                 :         219 :             SolidSyslogStreamSender_Initialise(&StreamSender_Pool[index].Base, config);
      42                 :         219 :             result = &StreamSender_Pool[index].Base;
      43                 :             :         }
      44                 :             :         else
      45                 :             :         {
      46                 :           2 :             StreamSender_Report(
      47                 :             :                 SOLIDSYSLOG_POOL_EXHAUSTED_SEVERITY,
      48                 :             :                 SOLIDSYSLOG_CAT_POOL_EXHAUSTED,
      49                 :             :                 SOLIDSYSLOG_STREAM_SENDER_ERROR_POOL_EXHAUSTED
      50                 :             :             );
      51                 :             :         }
      52                 :             :     }
      53                 :         227 :     return result;
      54                 :             : }
      55                 :             : 
      56                 :         227 : static bool StreamSender_IsValidConfig(const struct SolidSyslogStreamSenderConfig* config)
      57                 :             : {
      58                 :         227 :     bool valid = false;
      59         [ +  + ]:         227 :     if (config == NULL)
      60                 :             :     {
      61                 :           3 :         StreamSender_Report(
      62                 :             :             SOLIDSYSLOG_BAD_CONFIG_FATAL_SEVERITY,
      63                 :             :             SOLIDSYSLOG_CAT_BAD_CONFIG,
      64                 :             :             SOLIDSYSLOG_STREAM_SENDER_ERROR_NULL_CONFIG
      65                 :             :         );
      66                 :             :     }
      67         [ +  + ]:         224 :     else if (config->Resolver == NULL)
      68                 :             :     {
      69                 :           1 :         StreamSender_Report(
      70                 :             :             SOLIDSYSLOG_BAD_CONFIG_FATAL_SEVERITY,
      71                 :             :             SOLIDSYSLOG_CAT_BAD_CONFIG,
      72                 :             :             SOLIDSYSLOG_STREAM_SENDER_ERROR_NULL_RESOLVER
      73                 :             :         );
      74                 :             :     }
      75         [ +  + ]:         223 :     else if (config->Stream == NULL)
      76                 :             :     {
      77                 :           1 :         StreamSender_Report(
      78                 :             :             SOLIDSYSLOG_BAD_CONFIG_FATAL_SEVERITY,
      79                 :             :             SOLIDSYSLOG_CAT_BAD_CONFIG,
      80                 :             :             SOLIDSYSLOG_STREAM_SENDER_ERROR_NULL_STREAM
      81                 :             :         );
      82                 :             :     }
      83         [ +  + ]:         222 :     else if (config->Address == NULL)
      84                 :             :     {
      85                 :           1 :         StreamSender_Report(
      86                 :             :             SOLIDSYSLOG_BAD_CONFIG_FATAL_SEVERITY,
      87                 :             :             SOLIDSYSLOG_CAT_BAD_CONFIG,
      88                 :             :             SOLIDSYSLOG_STREAM_SENDER_ERROR_NULL_ADDRESS
      89                 :             :         );
      90                 :             :     }
      91                 :             :     else
      92                 :             :     {
      93                 :         221 :         valid = true;
      94                 :             :     }
      95                 :         227 :     return valid;
      96                 :             : }
      97                 :             : 
      98                 :         228 : void SolidSyslogStreamSender_Destroy(struct SolidSyslogSender* base)
      99                 :             : {
     100                 :         228 :     size_t index = StreamSender_IndexFromHandle(base);
     101                 :         228 :     bool released =
     102   [ +  +  +  + ]:         448 :         SolidSyslogPoolAllocator_IndexIsValid(&StreamSender_Allocator, index) &&
     103                 :         220 :         SolidSyslogPoolAllocator_FreeIfInUse(&StreamSender_Allocator, index, StreamSender_CleanupAtIndex, NULL);
     104         [ +  + ]:         228 :     if (!released)
     105                 :             :     {
     106                 :           9 :         StreamSender_Report(
     107                 :             :             SOLIDSYSLOG_UNKNOWN_DESTROY_SEVERITY,
     108                 :             :             SOLIDSYSLOG_CAT_UNKNOWN_DESTROY,
     109                 :             :             SOLIDSYSLOG_STREAM_SENDER_ERROR_UNKNOWN_DESTROY
     110                 :             :         );
     111                 :             :     }
     112                 :         228 : }
     113                 :             : 
     114                 :         228 : static inline size_t StreamSender_IndexFromHandle(const struct SolidSyslogSender* base)
     115                 :             : {
     116                 :         228 :     size_t result = SOLIDSYSLOG_STREAM_SENDER_POOL_SIZE;
     117         [ +  + ]:         246 :     for (size_t poolIndex = 0U; poolIndex < SOLIDSYSLOG_STREAM_SENDER_POOL_SIZE; poolIndex++)
     118                 :             :     {
     119         [ +  + ]:         238 :         if (base == &StreamSender_Pool[poolIndex].Base)
     120                 :             :         {
     121                 :         220 :             result = poolIndex;
     122                 :         220 :             break;
     123                 :             :         }
     124                 :             :     }
     125                 :         228 :     return result;
     126                 :             : }
     127                 :             : 
     128                 :         219 : static inline void StreamSender_CleanupAtIndex(size_t index, void* context)
     129                 :             : {
     130                 :             :     (void) context;
     131                 :         219 :     SolidSyslogStreamSender_Cleanup(&StreamSender_Pool[index].Base);
     132                 :         219 : }
        

Generated by: LCOV version 2.0-1