Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / utils / field_information.cpp
blob395bde2fa816d819c2b37cb8a6fceba25018adf9
1 /* field_information.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include <stdint.h>
12 #include <ui/qt/utils/field_information.h>
14 FieldInformation::FieldInformation(field_info *fi, QObject * parent)
15 :QObject(parent)
17 fi_ = fi;
18 parent_fi_ = NULL;
21 FieldInformation::FieldInformation(const ProtoNode *node, QObject * parent)
22 :QObject(parent)
24 fi_ = NULL;
25 if (node && node->isValid()) {
26 fi_ = node->protoNode()->finfo;
28 parent_fi_ = NULL;
31 bool FieldInformation::isValid() const
33 bool ret = false;
35 if (fi_ && fi_->hfinfo)
37 if (fi_->hfinfo->blurb != NULL && fi_->hfinfo->blurb[0] != '\0') {
38 ret = true;
39 } else {
40 ret = QString((fi_->hfinfo->name)).length() > 0;
44 return ret;
47 bool FieldInformation::isLink() const
49 if (fi_ && fi_->hfinfo) {
50 if ((fi_->hfinfo->type == FT_FRAMENUM) ||
51 (FI_GET_FLAG(fi_, FI_URL) && FT_IS_STRING(fi_->hfinfo->type))) {
52 return true;
55 return false;
58 void FieldInformation::setParentField(field_info * par_fi)
60 parent_fi_ = par_fi;
63 int FieldInformation::treeType()
65 if (fi_) {
66 Q_ASSERT(fi_->tree_type >= -1 && fi_->tree_type < num_tree_types);
67 return fi_->tree_type;
69 return -1;
72 field_info * FieldInformation::fieldInfo() const
74 return fi_;
77 FieldInformation::HeaderInfo FieldInformation::headerInfo() const
79 HeaderInfo header;
81 if (fi_ && fi_->hfinfo)
83 header.name = fi_->hfinfo->name;
84 header.description = fi_->hfinfo->blurb;
85 header.abbreviation = fi_->hfinfo->abbrev;
86 header.isValid = true;
87 header.type = fi_->hfinfo->type;
88 header.parent = fi_->hfinfo->parent;
89 header.id = fi_->hfinfo->id;
91 else
93 header.name = "";
94 header.description = "";
95 header.abbreviation = "";
96 header.isValid = false;
97 header.type = FT_NONE;
98 header.parent = 0;
99 header.id = 0;
102 return header;
105 FieldInformation * FieldInformation::parentField() const
107 return new FieldInformation(parent_fi_, parent());
110 bool FieldInformation::tvbContains(FieldInformation *child)
112 if (fi_ && child && fi_->ds_tvb == child->fieldInfo()->ds_tvb)
113 return true;
115 return false;
118 unsigned FieldInformation::flag(unsigned mask)
120 if (fi_) {
121 return FI_GET_FLAG(fi_, mask);
123 return 0;
126 const QString FieldInformation::moduleName()
128 QString module_name;
129 if (isValid()) {
130 if (headerInfo().parent == -1) {
131 module_name = fi_->hfinfo->abbrev;
132 } else {
133 module_name = proto_registrar_get_abbrev(headerInfo().parent);
136 return module_name;
139 QString FieldInformation::toString()
141 QByteArray display_label;
143 display_label.resize(80); // Arbitrary.
144 int label_len = proto_item_fill_display_label(fi_, display_label.data(), static_cast<int>(display_label.size())-1);
145 display_label.resize(label_len);
147 if (display_label.isEmpty()) {
148 return "[no value for field]";
150 return QString(display_label);
153 QString FieldInformation::url()
155 QString url;
156 if (flag(FI_URL) && headerInfo().isValid && FT_IS_STRING(fi_->hfinfo->type)) {
157 url = toString();
159 return url;
162 FieldInformation::Position FieldInformation::position() const
164 Position pos = {-1, -1};
165 if (fi_ && fi_->ds_tvb)
167 int len = (int) tvb_captured_length(fi_->ds_tvb);
169 pos.start = fi_->start;
170 pos.length = fi_->length;
172 if (pos.start < 0 || pos.length < 0 || pos.start >= len)
174 if (fi_->appendix_start >= 0 && fi_->appendix_length > 0 && fi_->appendix_start < len)
176 pos.start = fi_->appendix_start;
177 pos.length = fi_->appendix_length;
182 return pos;
185 FieldInformation::Position FieldInformation::appendix() const
187 Position pos = {-1, -1};
188 if (fi_ && fi_->ds_tvb)
190 pos.start = fi_->appendix_start;
191 pos.length = fi_->appendix_length;
194 return pos;
197 const QByteArray FieldInformation::printableData()
199 QByteArray data;
201 if (fi_ && fi_->ds_tvb)
203 FieldInformation::Position pos = position();
204 int rem_length = tvb_captured_length_remaining(fi_->ds_tvb, pos.start);
206 int length = pos.length;
207 if (length > rem_length)
208 length = rem_length;
209 uint8_t * dataSet = (uint8_t *)tvb_memdup(wmem_file_scope(), fi_->ds_tvb, pos.start, length);
210 data = QByteArray::fromRawData((char *)dataSet, length);
213 return data;