]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/statnode.cc
rec: Don't shadow variables
[thirdparty/pdns.git] / pdns / statnode.cc
1 #include "statnode.hh"
2
3 StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const
4 {
5 if(!silent) {
6 cout<<string(depth, ' ');
7 cout<<name<<": "<<endl;
8 }
9 Stat childstat;
10 childstat.queries += s.queries;
11 childstat.noerrors += s.noerrors;
12 childstat.nxdomains += s.nxdomains;
13 childstat.servfails += s.servfails;
14 childstat.drops += s.drops;
15 if(children.size()>1024 && !silent) {
16 cout<<string(depth, ' ')<<name<<": too many to print"<<endl;
17 }
18 for(const children_t::value_type& child : children) {
19 childstat=child.second.print(depth+8, childstat, silent || children.size()>1024);
20 }
21 if(!silent || children.size()>1)
22 cout<<string(depth, ' ')<<childstat.queries<<" queries, " <<
23 childstat.noerrors<<" noerrors, "<<
24 childstat.nxdomains<<" nxdomains, "<<
25 childstat.servfails<<" servfails, "<<
26 childstat.drops<<" drops"<<endl;
27
28 newstat+=childstat;
29
30 return newstat;
31 }
32
33
34 void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
35 {
36 Stat childstat;
37 childstat.queries += s.queries;
38 childstat.noerrors += s.noerrors;
39 childstat.nxdomains += s.nxdomains;
40 childstat.servfails += s.servfails;
41 childstat.drops += s.drops;
42 childstat.remotes = s.remotes;
43
44 Stat selfstat(childstat);
45
46
47 for(const children_t::value_type& child : children) {
48 child.second.visit(visitor, childstat, depth+8);
49 }
50
51 visitor(this, selfstat, childstat);
52
53 newstat+=childstat;
54 }
55
56
57 void StatNode::submit(const DNSName& domain, int rcode, const ComboAddress& remote)
58 {
59 // cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
60 vector<string> tmp = domain.getRawLabels();
61 if(tmp.empty())
62 return;
63
64 deque<string> parts;
65 for(auto const i : tmp) {
66 parts.push_back(i);
67 }
68 children[parts.back()].submit(parts, "", rcode, remote, 1);
69 }
70
71 /* www.powerdns.com. ->
72 . <- fullnames
73 com.
74 powerdns.com
75 www.powerdns.com.
76 */
77
78 void StatNode::submit(deque<string>& labels, const std::string& domain, int rcode, const ComboAddress& remote, unsigned int count)
79 {
80 if(labels.empty())
81 return;
82 // cerr<<"Submit called for domain='"<<domain<<"': ";
83 // for(const std::string& n : labels)
84 // cerr<<n<<".";
85 // cerr<<endl;
86 if(name.empty()) {
87
88 name=labels.back();
89 // cerr<<"Set short name to '"<<name<<"'"<<endl;
90 }
91 else {
92 // cerr<<"Short name was already set to '"<<name<<"'"<<endl;
93 }
94
95 if(labels.size()==1) {
96 if (fullname.empty()) {
97 fullname=name+"."+domain;
98 labelsCount = count;
99 }
100 // cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
101 s.queries++;
102 if(rcode<0)
103 s.drops++;
104 else if(rcode==0)
105 s.noerrors++;
106 else if(rcode==2)
107 s.servfails++;
108 else if(rcode==3)
109 s.nxdomains++;
110 s.remotes[remote]++;
111 }
112 else {
113 if (fullname.empty()) {
114 fullname=name+"."+domain;
115 labelsCount = count;
116 }
117 // cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
118 labels.pop_back();
119 children[labels.back()].submit(labels, fullname, rcode, remote, count+1);
120 }
121 }
122