bitcoin, gif: pass header_field_info to proto_tree_*.

svn path=/trunk/; revision=51606
This commit is contained in:
Jakub Zawadzki 2013-08-30 21:31:42 +00:00
parent f871fa054b
commit 17cbb2c36e
2 changed files with 714 additions and 712 deletions

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,8 @@
/* Edit this file with 4-space indentation */
#define NEW_PROTO_TREE_API
#include "config.h"
#include <string.h>
@ -80,42 +82,215 @@ enum {
GIF_89a = 0x89
};
/* Initialize the protocol and registered fields */
static int proto_gif = -1;
static dissector_handle_t gif_handle;
/* Protocol and registered fields */
static header_field_info *hfi_gif = NULL;
#define GIF_HFI_INIT HFI_INIT(proto_gif)
/* header fields */
/* GIF signature */
static gint hf_version = -1;
static header_field_info hfi_version GIF_HFI_INIT =
{ "Version",
IMG_GIF ".version",
FT_STRING, BASE_NONE, NULL, 0x00,
"GIF Version",
HFILL
};
/* Screen descriptor */
static gint hf_screen_width = -1;
static gint hf_screen_height = -1;
static gint hf_global_color_map_present = -1;
static gint hf_global_color_resolution = -1;
static gint hf_global_color_map_ordered = -1; /* GIF89a */
static gint hf_global_image_bpp = -1;
static header_field_info hfi_screen_width GIF_HFI_INIT =
{ "Screen width",
IMG_GIF ".screen.width",
FT_UINT16, BASE_DEC, NULL, 0x00,
NULL,
HFILL
};
static header_field_info hfi_screen_height GIF_HFI_INIT =
{ "Screen height",
IMG_GIF ".screen.height",
FT_UINT16, BASE_DEC, NULL, 0x00,
NULL,
HFILL
};
static header_field_info hfi_global_color_map_present GIF_HFI_INIT =
{ "Global color map is present",
IMG_GIF ".global.color_map.present",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
"Indicates if the global color map is present",
HFILL
};
static header_field_info hfi_global_color_resolution GIF_HFI_INIT =
{ "Bits per color minus 1",
IMG_GIF ".global.color_bpp",
FT_UINT8, BASE_DEC, NULL, 0x70,
"The number of bits per color is one plus the field value.",
HFILL
};
static header_field_info hfi_global_color_map_ordered/* GIF89a */ GIF_HFI_INIT =
{ "Global color map is ordered",
IMG_GIF ".global.color_map.ordered",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
"Indicates whether the global color map is ordered.",
HFILL
};
static header_field_info hfi_global_image_bpp GIF_HFI_INIT =
{ "Image bits per pixel minus 1",
IMG_GIF ".global.bpp",
FT_UINT8, BASE_DEC, NULL, 0x07,
"The number of bits per pixel is one plus the field value.",
HFILL
};
/* Only makes sense if the global color map is present: */
static gint hf_background_color = -1;
static gint hf_pixel_aspect_ratio = -1; /* GIF89a */
static gint hf_global_color_map = -1;
static header_field_info hfi_background_color GIF_HFI_INIT =
{ "Background color index",
IMG_GIF ".image_background_index",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Index of the background color in the color map.",
HFILL
};
static header_field_info hfi_pixel_aspect_ratio/* GIF89a */ GIF_HFI_INIT =
{ "Global pixel aspect ratio",
IMG_GIF ".global.pixel_aspect_ratio",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Gives an approximate value of the aspect ratio of the pixels.",
HFILL
};
static header_field_info hfi_global_color_map GIF_HFI_INIT =
{ "Global color map",
IMG_GIF ".global.color_map",
FT_BYTES, BASE_NONE, NULL, 0x00,
"Global color map.",
HFILL
};
/* Image descriptor */
static gint hf_image_left = -1;
static gint hf_image_top = -1;
static gint hf_image_width = -1;
static gint hf_image_height = -1;
static gint hf_local_color_map_present = -1;
static gint hf_local_color_resolution = -1;
static gint hf_local_color_map_ordered = -1; /* GIF89a */
/* static gint hf_local_image_bpp = -1; */
static gint hf_local_color_map = -1;
static header_field_info hfi_image_left GIF_HFI_INIT =
{ "Image left position",
IMG_GIF ".image.left",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Offset between left of Screen and left of Image.",
HFILL
};
static gint hf_extension = -1;
static gint hf_extension_label = -1;
static gint hf_image = -1;
static gint hf_image_code_size = -1;
static header_field_info hfi_image_top GIF_HFI_INIT =
{ "Image top position",
IMG_GIF ".image.top",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Offset between top of Screen and top of Image.",
HFILL
};
static header_field_info hfi_image_width GIF_HFI_INIT =
{ "Image width",
IMG_GIF ".image.width",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Image width.",
HFILL
};
static header_field_info hfi_image_height GIF_HFI_INIT =
{ "Image height",
IMG_GIF ".image.height",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Image height.",
HFILL
};
static header_field_info hfi_local_color_map_present GIF_HFI_INIT =
{ "Local color map is present",
IMG_GIF ".local.color_map.present",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
"Indicates if the local color map is present",
HFILL
};
static header_field_info hfi_local_color_resolution GIF_HFI_INIT =
{ "Bits per color minus 1",
IMG_GIF ".local.color_bpp",
FT_UINT8, BASE_DEC, NULL, 0x70,
"The number of bits per color is one plus the field value.",
HFILL
};
static header_field_info hfi_local_color_map_ordered/* GIF89a */ GIF_HFI_INIT =
{ "Local color map is ordered",
IMG_GIF ".local.color_map.ordered",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
"Indicates whether the local color map is ordered.",
HFILL
};
#if 0
static header_field_info hfi_local_image_bpp GIF_HFI_INIT =
{ "Image bits per pixel minus 1",
IMG_GIF ".local.bpp",
FT_UINT8, BASE_DEC, NULL, 0x07,
"The number of bits per pixel is one plus the field value.",
HFILL
};
#endif
static header_field_info hfi_local_color_map GIF_HFI_INIT =
{ "Local color map",
IMG_GIF ".local.color_map",
FT_BYTES, BASE_NONE, NULL, 0x00,
"Local color map.",
HFILL
};
/* Extension */
static header_field_info hfi_extension GIF_HFI_INIT =
{ "Extension",
IMG_GIF ".extension",
FT_NONE, BASE_NONE, NULL, 0x00,
"Extension.",
HFILL
};
static header_field_info hfi_extension_label GIF_HFI_INIT =
{ "Extension label",
IMG_GIF ".extension.label",
FT_UINT8, BASE_HEX, VALS(vals_extensions), 0x00,
"Extension label.",
HFILL
};
static header_field_info hfi_image GIF_HFI_INIT =
{ "Image",
IMG_GIF ".image",
FT_NONE, BASE_NONE, NULL, 0x00,
"Image.",
HFILL
};
static header_field_info hfi_image_code_size GIF_HFI_INIT =
{ "LZW minimum code size",
IMG_GIF ".image.code_size",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Minimum code size for the LZW compression.",
HFILL
};
/* Trailer (end of GIF data stream) */
static gint hf_trailer = -1;
static header_field_info hfi_trailer GIF_HFI_INIT =
{ "Trailer (End of the GIF stream)",
IMG_GIF ".end",
FT_NONE, BASE_NONE, NULL, 0x00,
"This byte tells the decoder that the data stream is finished.",
HFILL
};
/* Initialize the subtree pointers */
static gint ett_gif = -1;
@ -174,14 +349,14 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
* items to the protocol tree.
*/
if (tree) {
ti = proto_tree_add_item(tree, proto_gif, tvb, 0, -1, ENC_NA);
ti = proto_tree_add_item(tree, hfi_gif, tvb, 0, -1, ENC_NA);
proto_item_append_text(ti, ", Version: %s", str);
gif_tree = proto_item_add_subtree(ti, ett_gif);
/* GIF signature */
proto_tree_add_item(gif_tree, hf_version, tvb, 0, 6, ENC_ASCII|ENC_NA);
proto_tree_add_item(gif_tree, &hfi_version, tvb, 0, 6, ENC_ASCII|ENC_NA);
/* Screen descriptor */
proto_tree_add_item(gif_tree, hf_screen_width, tvb, 6, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(gif_tree, hf_screen_height, tvb, 8, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(gif_tree, &hfi_screen_width, tvb, 6, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(gif_tree, &hfi_screen_height, tvb, 8, 2, ENC_LITTLE_ENDIAN);
peek = tvb_get_guint8(tvb, 10);
/* Bitfield gccc 0ppp
@ -204,19 +379,19 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
color_resolution, plurality(color_resolution, "", "s"),
image_bpp, plurality(image_bpp, "", "s"));
subtree = proto_item_add_subtree(ti, ett_global_flags);
proto_tree_add_item(subtree, hf_global_color_map_present,
proto_tree_add_item(subtree, &hfi_global_color_map_present,
tvb, 10, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(subtree, hf_global_color_resolution,
proto_tree_add_item(subtree, &hfi_global_color_resolution,
tvb, 10, 1, ENC_LITTLE_ENDIAN);
if (version == GIF_89a) {
proto_tree_add_item(subtree, hf_global_color_map_ordered,
proto_tree_add_item(subtree, &hfi_global_color_map_ordered,
tvb, 10, 1, ENC_LITTLE_ENDIAN);
}
proto_tree_add_item(subtree, hf_global_image_bpp,
proto_tree_add_item(subtree, &hfi_global_image_bpp,
tvb, 10, 1, ENC_LITTLE_ENDIAN);
/* Background color */
proto_tree_add_item(gif_tree, hf_background_color,
proto_tree_add_item(gif_tree, &hfi_background_color,
tvb, 11, 1, ENC_LITTLE_ENDIAN);
/* byte at offset 12 is 0x00 - reserved in GIF87a but encodes the
@ -228,7 +403,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
peek = tvb_get_guint8(tvb, 12);
if (peek) {
/* Only display if different from 0 */
proto_tree_add_uint_format(gif_tree, hf_pixel_aspect_ratio,
proto_tree_add_uint_format(gif_tree, hfi_pixel_aspect_ratio.id,
tvb, 12, 1, peek,
"%u, yields an aspect ratio of (15 + %u) / 64 = %.2f",
peek, peek, (float)(15 + peek) / 64.0);
@ -241,7 +416,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
* in the Global Color Map */
if (color_map_present) {
len = 3 * (1 << image_bpp);
proto_tree_add_item(gif_tree, hf_global_color_map,
proto_tree_add_item(gif_tree, &hfi_global_color_map,
tvb, 13, len, ENC_NA);
} else {
len = 0;
@ -307,11 +482,11 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
* 1 byte : extension_label
*/
ti = proto_tree_add_item(gif_tree, hf_extension,
ti = proto_tree_add_item(gif_tree, &hfi_extension,
tvb, offset, 1, ENC_NA);
subtree = proto_item_add_subtree(ti, ett_extension);
offset++;
proto_tree_add_item(subtree, hf_extension_label,
proto_tree_add_item(subtree, &hfi_extension_label,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
peek = tvb_get_guint8(tvb, offset);
proto_item_append_text(ti, ": %s",
@ -341,18 +516,18 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
* 1 byte : image code size
*/
ti = proto_tree_add_item(gif_tree, hf_image,
ti = proto_tree_add_item(gif_tree, &hfi_image,
tvb, offset, 1, ENC_NA);
subtree = proto_item_add_subtree(ti, ett_image);
offset++;
/* Screen descriptor */
proto_tree_add_item(subtree, hf_image_left,
proto_tree_add_item(subtree, &hfi_image_left,
tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2;
proto_tree_add_item(subtree, hf_image_top,
proto_tree_add_item(subtree, &hfi_image_top,
tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2;
proto_tree_add_item(subtree, hf_image_width,
proto_tree_add_item(subtree, &hfi_image_width,
tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2;
proto_tree_add_item(subtree, hf_image_height,
proto_tree_add_item(subtree, &hfi_image_height,
tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2;
/* bit field */
peek = tvb_get_guint8(tvb, offset);
@ -369,15 +544,15 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
color_resolution, plurality(color_resolution, "", "s"),
image_bpp, plurality(image_bpp, "", "s"));
subtree2 = proto_item_add_subtree(ti2, ett_local_flags);
proto_tree_add_item(subtree2, hf_local_color_map_present,
proto_tree_add_item(subtree2, &hfi_local_color_map_present,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(subtree2, hf_local_color_resolution,
proto_tree_add_item(subtree2, &hfi_local_color_resolution,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
if (version == GIF_89a) {
proto_tree_add_item(subtree2, hf_local_color_map_ordered,
proto_tree_add_item(subtree2, &hfi_local_color_map_ordered,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
}
proto_tree_add_item(subtree2, hf_global_image_bpp,
proto_tree_add_item(subtree2, &hfi_global_image_bpp,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset++;
@ -387,7 +562,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
* in the Local Color Map */
if (color_map_present) {
len = 3 * (1 << image_bpp);
proto_tree_add_item(subtree, hf_local_color_map,
proto_tree_add_item(subtree, &hfi_local_color_map,
tvb, offset, len, ENC_NA);
} else {
len = 0;
@ -395,7 +570,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
offset += len;
item_len += len;
proto_tree_add_item(subtree, hf_image_code_size,
proto_tree_add_item(subtree, &hfi_image_code_size,
tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset++;
do {
@ -410,7 +585,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
proto_item_set_len(ti, item_len);
} else {
/* GIF processing stops at this very byte */
proto_tree_add_item(gif_tree, hf_trailer,
proto_tree_add_item(gif_tree, &hfi_trailer,
tvb, offset, 1, ENC_NA);
break;
}
@ -438,223 +613,53 @@ proto_register_gif(void)
/*
* Setup list of header fields.
*/
static hf_register_info hf[] = {
static header_field_info *hfi[] = {
/*
* GIF signature and version
*/
{ &hf_version,
{ "Version",
IMG_GIF ".version",
FT_STRING, BASE_NONE, NULL, 0x00,
"GIF Version",
HFILL
}
},
&hfi_version,
/*
* Logical screen descriptor
*/
{ &hf_screen_width,
{ "Screen width",
IMG_GIF ".screen.width",
FT_UINT16, BASE_DEC, NULL, 0x00,
NULL,
HFILL
}
},
{ &hf_screen_height,
{ "Screen height",
IMG_GIF ".screen.height",
FT_UINT16, BASE_DEC, NULL, 0x00,
NULL,
HFILL
}
},
{ &hf_global_color_map_present,
{ "Global color map is present",
IMG_GIF ".global.color_map.present",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
"Indicates if the global color map is present",
HFILL
}
},
{ &hf_global_color_resolution,
{ "Bits per color minus 1",
IMG_GIF ".global.color_bpp",
FT_UINT8, BASE_DEC, NULL, 0x70,
"The number of bits per color is one plus the field value.",
HFILL
}
},
{ &hf_global_color_map_ordered,
{ "Global color map is ordered",
IMG_GIF ".global.color_map.ordered",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
"Indicates whether the global color map is ordered.",
HFILL
}
},
{ &hf_global_image_bpp,
{ "Image bits per pixel minus 1",
IMG_GIF ".global.bpp",
FT_UINT8, BASE_DEC, NULL, 0x07,
"The number of bits per pixel is one plus the field value.",
HFILL
}
},
{ &hf_background_color,
{ "Background color index",
IMG_GIF ".image_background_index",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Index of the background color in the color map.",
HFILL
}
},
{ &hf_pixel_aspect_ratio,
{ "Global pixel aspect ratio",
IMG_GIF ".global.pixel_aspect_ratio",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Gives an approximate value of the aspect ratio of the pixels.",
HFILL
}
},
{ &hf_global_color_map,
{ "Global color map",
IMG_GIF ".global.color_map",
FT_BYTES, BASE_NONE, NULL, 0x00,
"Global color map.",
HFILL
}
},
&hfi_screen_width,
&hfi_screen_height,
&hfi_global_color_map_present,
&hfi_global_color_resolution,
&hfi_global_color_map_ordered,
&hfi_global_image_bpp,
&hfi_background_color,
&hfi_pixel_aspect_ratio,
&hfi_global_color_map,
/*
* Local color map (part of image)
*/
{ &hf_local_color_map_present,
{ "Local color map is present",
IMG_GIF ".local.color_map.present",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
"Indicates if the local color map is present",
HFILL
}
},
{ &hf_local_color_resolution,
{ "Bits per color minus 1",
IMG_GIF ".local.color_bpp",
FT_UINT8, BASE_DEC, NULL, 0x70,
"The number of bits per color is one plus the field value.",
HFILL
}
},
{ &hf_local_color_map_ordered,
{ "Local color map is ordered",
IMG_GIF ".local.color_map.ordered",
FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
"Indicates whether the local color map is ordered.",
HFILL
}
},
#if 0
{ &hf_local_image_bpp,
{ "Image bits per pixel minus 1",
IMG_GIF ".local.bpp",
FT_UINT8, BASE_DEC, NULL, 0x07,
"The number of bits per pixel is one plus the field value.",
HFILL
}
},
#endif
{ &hf_local_color_map,
{ "Local color map",
IMG_GIF ".local.color_map",
FT_BYTES, BASE_NONE, NULL, 0x00,
"Local color map.",
HFILL
}
},
&hfi_local_color_map_present,
&hfi_local_color_resolution,
&hfi_local_color_map_ordered,
/* &hfi_local_image_bpp, */
&hfi_local_color_map,
/*
* Extension
*/
{ &hf_extension,
{ "Extension",
IMG_GIF ".extension",
FT_NONE, BASE_NONE, NULL, 0x00,
"Extension.",
HFILL
}
},
{ &hf_extension_label,
{ "Extension label",
IMG_GIF ".extension.label",
FT_UINT8, BASE_HEX, VALS(vals_extensions), 0x00,
"Extension label.",
HFILL
}
},
&hfi_extension,
&hfi_extension_label,
/*
* Image
*/
{ &hf_image,
{ "Image",
IMG_GIF ".image",
FT_NONE, BASE_NONE, NULL, 0x00,
"Image.",
HFILL
}
},
{ &hf_image_left,
{ "Image left position",
IMG_GIF ".image.left",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Offset between left of Screen and left of Image.",
HFILL
}
},
{ &hf_image_top,
{ "Image top position",
IMG_GIF ".image.top",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Offset between top of Screen and top of Image.",
HFILL
}
},
{ &hf_image_width,
{ "Image width",
IMG_GIF ".image.width",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Image width.",
HFILL
}
},
{ &hf_image_height,
{ "Image height",
IMG_GIF ".image.height",
FT_UINT16, BASE_DEC, NULL, 0x00,
"Image height.",
HFILL
}
},
{ &hf_image_code_size,
{ "LZW minimum code size",
IMG_GIF ".image.code_size",
FT_UINT8, BASE_DEC, NULL, 0x00,
"Minimum code size for the LZW compression.",
HFILL
}
},
&hfi_image,
&hfi_image_left,
&hfi_image_top,
&hfi_image_width,
&hfi_image_height,
&hfi_image_code_size,
/*
* Trailer
*/
{ &hf_trailer,
{ "Trailer (End of the GIF stream)",
IMG_GIF ".end",
FT_NONE, BASE_NONE, NULL, 0x00,
"This byte tells the decoder that the data stream is finished.",
HFILL
}
},
&hfi_trailer,
};
/* Setup protocol subtree array */
@ -666,6 +671,8 @@ proto_register_gif(void)
&ett_image,
};
int proto_gif;
/* Register the protocol name and description */
proto_gif = proto_register_protocol(
"Compuserve GIF",
@ -673,21 +680,22 @@ proto_register_gif(void)
IMG_GIF
);
hfi_gif = proto_registrar_get_nth(proto_gif);
/* Required function calls to register the header fields
* and subtrees used */
proto_register_field_array(proto_gif, hf, array_length(hf));
proto_register_fields(proto_gif, hfi, array_length(hfi));
proto_register_subtree_array(ett, array_length(ett));
new_register_dissector(IMG_GIF, dissect_gif, proto_gif);
gif_handle = new_register_dissector(IMG_GIF, dissect_gif, proto_gif);
}
void
proto_reg_handoff_gif(void)
{
dissector_handle_t gif_handle = find_dissector(IMG_GIF);
/* Register the GIF media type */
dissector_add_string("media_type", "image/gif", gif_handle);
heur_dissector_add("http", dissect_gif_heur, proto_gif);
heur_dissector_add("wtap_file", dissect_gif_heur, proto_gif);
heur_dissector_add("http", dissect_gif_heur, hfi_gif->id);
heur_dissector_add("wtap_file", dissect_gif_heur, hfi_gif->id);
}