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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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

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

43
   if(nothing_attached) {
159✔
44
      m_write_queue += std::make_pair(input, length);
×
45
   } else {
46
      m_write_queue.clear();
159✔
47
   }
48
}
49

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

62
/*
63
* End the current message
64
*/
65
void Filter::finish_msg() {
207✔
66
   end_msg();
207✔
67
   for(size_t j = 0; j != total_ports(); ++j) {
349✔
68
      if(m_next[j]) {
142✔
69
         m_next[j]->finish_msg();
142✔
70
      }
71
   }
72
}
207✔
73

74
/*
75
* Attach a filter to the current port
76
*/
77
void Filter::attach(Filter* new_filter) {
20✔
78
   if(new_filter) {
20✔
79
      Filter* last = this;
80
      while(last->get_next()) {
24✔
81
         last = last->get_next();
4✔
82
      }
83
      last->m_next[last->current_port()] = new_filter;
20✔
84
   }
85
}
20✔
86

87
/*
88
* Set the active port on a filter
89
*/
90
void Filter::set_port(size_t new_port) {
×
91
   if(new_port >= total_ports()) {
×
92
      throw Invalid_Argument("Filter: Invalid port number");
×
93
   }
94
   m_port_num = new_port;
×
95
}
×
96

97
/*
98
* Return the next Filter in the logical chain
99
*/
100
Filter* Filter::get_next() const {
28✔
101
   if(m_port_num < m_next.size()) {
28✔
102
      return m_next[m_port_num];
28✔
103
   }
104
   return nullptr;
105
}
106

107
/*
108
* Set the next Filters
109
*/
110
void Filter::set_next(Filter* filters[], size_t size) {
81✔
111
   m_next.clear();
81✔
112

113
   m_port_num = 0;
81✔
114
   m_filter_owns = 0;
81✔
115

116
   while(size && filters && (filters[size - 1] == nullptr)) {
87✔
117
      --size;
6✔
118
   }
119

120
   if(filters && size) {
81✔
121
      m_next.assign(filters, filters + size);
4✔
122
   }
123
}
81✔
124

125
/*
126
* Return the total number of ports
127
*/
128
size_t Filter::total_ports() const { return m_next.size(); }
9,041✔
129

130
}  // namespace Botan
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