• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.79
/src/lib/filters/filter.cpp
1
/*
2
* Filter
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/filter.h>
9

10
#include <botan/exceptn.h>
11

12
namespace Botan {
13

14
/*
15
* Filter Constructor
16
*/
17
Filter::Filter() {
136✔
18
   m_next.resize(1);
136✔
19
   m_port_num = 0;
136✔
20
   m_filter_owns = 0;
136✔
21
   m_owned = false;
136✔
22
}
136✔
23

24
/*
25
* Send data to all ports
26
*/
27
void Filter::send(const uint8_t input[], size_t length) {
187✔
28
   if(!length)
187✔
29
      return;
30

31
   bool nothing_attached = true;
32
   for(size_t j = 0; j != total_ports(); ++j)
320✔
33
      if(m_next[j]) {
161✔
34
         if(!m_write_queue.empty())
161✔
35
            m_next[j]->write(m_write_queue.data(), m_write_queue.size());
×
36
         m_next[j]->write(input, length);
161✔
37
         nothing_attached = false;
161✔
38
      }
39

40
   if(nothing_attached)
159✔
41
      m_write_queue += std::make_pair(input, length);
×
42
   else
43
      m_write_queue.clear();
159✔
44
}
45

46
/*
47
* Start a new message
48
*/
49
void Filter::new_msg() {
207✔
50
   start_msg();
207✔
51
   for(size_t j = 0; j != total_ports(); ++j)
349✔
52
      if(m_next[j])
142✔
53
         m_next[j]->new_msg();
142✔
54
}
207✔
55

56
/*
57
* End the current message
58
*/
59
void Filter::finish_msg() {
207✔
60
   end_msg();
207✔
61
   for(size_t j = 0; j != total_ports(); ++j)
349✔
62
      if(m_next[j])
142✔
63
         m_next[j]->finish_msg();
142✔
64
}
207✔
65

66
/*
67
* Attach a filter to the current port
68
*/
69
void Filter::attach(Filter* new_filter) {
20✔
70
   if(new_filter) {
20✔
71
      Filter* last = this;
72
      while(last->get_next())
24✔
73
         last = last->get_next();
4✔
74
      last->m_next[last->current_port()] = new_filter;
20✔
75
   }
76
}
20✔
77

78
/*
79
* Set the active port on a filter
80
*/
81
void Filter::set_port(size_t new_port) {
×
82
   if(new_port >= total_ports())
×
83
      throw Invalid_Argument("Filter: Invalid port number");
×
84
   m_port_num = new_port;
×
85
}
×
86

87
/*
88
* Return the next Filter in the logical chain
89
*/
90
Filter* Filter::get_next() const {
28✔
91
   if(m_port_num < m_next.size())
28✔
92
      return m_next[m_port_num];
28✔
93
   return nullptr;
94
}
95

96
/*
97
* Set the next Filters
98
*/
99
void Filter::set_next(Filter* filters[], size_t size) {
81✔
100
   m_next.clear();
81✔
101

102
   m_port_num = 0;
81✔
103
   m_filter_owns = 0;
81✔
104

105
   while(size && filters && (filters[size - 1] == nullptr))
87✔
106
      --size;
6✔
107

108
   if(filters && size)
81✔
109
      m_next.assign(filters, filters + size);
4✔
110
}
81✔
111

112
/*
113
* Return the total number of ports
114
*/
115
size_t Filter::total_ports() const { return m_next.size(); }
9,041✔
116

117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc