1 /*------------------------------------------------------------------------------
2 *
3 * Copyright (c) 2011-2021, EURid vzw. All rights reserved.
4 * The YADIFA TM software product is provided under the BSD 3-clause license:
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of EURid nor the names of its contributors may be
16 * used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 *------------------------------------------------------------------------------
32 *
33 */
34
35 #include "dnscore/dnscore-config.h"
36 #include <dnscore/message-viewer.h>
37
38 static u8 message_viewer_requires_section_with_view_with_mode[4] =
39 {
40 MESSAGE_VIEWER_WITH_QUESTION,
41 MESSAGE_VIEWER_WITH_ANSWER,
42 MESSAGE_VIEWER_WITH_AUTHORITY,
43 MESSAGE_VIEWER_WITH_ADDITIONAL
44 };
45
message_viewer_requires_section(int section,int view_with_mode)46 bool message_viewer_requires_section(int section, int view_with_mode)
47 {
48 if((section >= 0) && (section <= 3))
49 {
50 return (message_viewer_requires_section_with_view_with_mode[section] & view_with_mode) != 0;
51 }
52
53 return FALSE;
54 }
55
56 static void
message_viewer_default_three(message_viewer * view,const u8 * buffer)57 message_viewer_default_three(message_viewer *view, const u8 *buffer)
58 {
59 printf("three!\n");
60 }
61
62 static void
message_viewer_default_four(message_viewer * view)63 message_viewer_default_four(message_viewer *view)
64 {
65 printf("four!\n");
66 }
67
68
69 static void
message_viewer_default_five(message_viewer * viewer,long time_duration)70 message_viewer_default_five(message_viewer *viewer, long time_duration)
71 {
72 printf("five!\n");
73 }
74
75
76 static void
message_viewer_default_six(message_viewer * viewer,u32 section_idx,u16 count)77 message_viewer_default_six(message_viewer *viewer, u32 section_idx, u16 count)
78 {
79 printf("six!\n");
80 }
81
82
83 static void
message_viewer_default_seven(message_viewer * viewer,u32 section_idx,u16 count)84 message_viewer_default_seven(message_viewer *viewer, u32 section_idx, u16 count)
85 {
86 printf("seven!\n");
87 }
88
89
90 static void
message_viewer_default_eight(message_viewer * viewer,const u8 * record_wire,u16 rclass,u16 rtype)91 message_viewer_default_eight(message_viewer *viewer, const u8 *record_wire, u16 rclass, u16 rtype)
92 {
93 printf("eight!\n");
94 }
95
96
97 static void
message_viewer_default_nine(message_viewer * viewer,const u8 * record_wire,u8 view_mode_with)98 message_viewer_default_nine(message_viewer *viewer, const u8 *record_wire, u8 view_mode_with)
99 {
100 printf("nine!\n");
101 }
102
message_viewer_default_pseudosection_record(message_viewer * mv,const u8 * record_wire)103 static ya_result message_viewer_default_pseudosection_record(message_viewer *mv, const u8 *record_wire)
104 {
105 (void)mv;
106 (void)record_wire;
107 return 0;
108 }
109
110 static const message_viewer_vtbl default_viewer_vtbl = {
111 message_viewer_default_three,
112 message_viewer_default_four,
113 message_viewer_default_five,
114 message_viewer_default_six,
115 message_viewer_default_seven,
116 message_viewer_default_eight,
117 message_viewer_default_nine,
118 message_viewer_default_pseudosection_record,
119 "message_viewer_default",
120 };
121
122 void
message_viewer_set_default(message_viewer * view)123 message_viewer_set_default(message_viewer *view)
124 {
125 view->data = NULL;
126 view->vtbl = &default_viewer_vtbl;
127 }
128
129 void
message_viewer_init(message_viewer * view)130 message_viewer_init(message_viewer *view)
131 {
132
133 view->bytes = 0;
134 view->data = NULL;
135 view->messages = 0;
136 view->os = NULL;
137 view->resource_records_total[0] = 0;
138 view->resource_records_total[1] = 0;
139 view->resource_records_total[2] = 0;
140 view->resource_records_total[3] = 0;
141 view->view_mode_with = 0;
142 view->host = NULL;
143
144 view->vtbl = &default_viewer_vtbl;
145 }
146