Skip to content

Commit

Permalink
wiretap: file types have a name and a description.
Browse files Browse the repository at this point in the history
The "short name" is really just the name, used to look it up.  The
"name" is really a description intended solely for human consumption.
Rename the fields, and the functions that access them, to match.

The "description" maintained by Lua for file type handlers is used
*only* for one debugging message; we should probably just eliminate it.
Call it an "internal description" for now.
  • Loading branch information
guyharris committed Feb 13, 2021
1 parent 28dbff3 commit 24acef0
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 110 deletions.
4 changes: 2 additions & 2 deletions capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ print_stats(const gchar *filename, capture_info *cf_info)
gchar *size_string;

/* Build printable strings for various stats */
file_type_string = wtap_file_type_subtype_string(cf_info->file_type);
file_type_string = wtap_file_type_subtype_description(cf_info->file_type);
file_encap_string = wtap_encap_description(cf_info->file_encap);

if (filename) printf ("File name: %s\n", filename);
Expand Down Expand Up @@ -873,7 +873,7 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
const gchar *file_type_string, *file_encap_string;

/* Build printable strings for various stats */
file_type_string = wtap_file_type_subtype_string(cf_info->file_type);
file_type_string = wtap_file_type_subtype_description(cf_info->file_type);
file_encap_string = wtap_encap_description(cf_info->file_encap);

if (filename) {
Expand Down
2 changes: 1 addition & 1 deletion captype.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ main(int argc, char *argv[])
wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);

if(wth) {
printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
printf("%s: %s\n", argv[i], wtap_file_type_subtype_name(wtap_file_type_subtype(wth)));
wtap_close(wth);
} else {
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
Expand Down
6 changes: 3 additions & 3 deletions debian/libwiretap0.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_file_size@Base 1.9.1
wtap_file_tsprec@Base 1.99.0
wtap_file_type_subtype@Base 1.12.0~rc1
wtap_file_type_subtype_short_string@Base 1.12.0~rc1
wtap_file_type_subtype_string@Base 1.12.0~rc1
wtap_file_type_subtype_description@Base 3.5.0
wtap_file_type_subtype_name@Base 3.5.0
wtap_free_extensions_list@Base 1.9.1
wtap_free_idb_info@Base 1.99.9
wtap_fstat@Base 1.9.1
Expand All @@ -124,6 +124,7 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_has_open_info@Base 1.12.0~rc1
wtap_init@Base 2.3.0
wtap_name_to_encap@Base 2.9.1
wtap_name_to_file_type_subtype@Base 3.5.0
wtap_open_offline@Base 1.9.1
wtap_opttypes_initialize@Base 2.1.2
wtap_opttypes_cleanup@Base 2.3.0
Expand All @@ -147,7 +148,6 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_set_cb_new_secrets@Base 2.9.0
wtap_set_cb_new_ipv4@Base 1.9.1
wtap_set_cb_new_ipv6@Base 1.9.1
wtap_short_string_to_file_type_subtype@Base 1.9.1
wtap_snapshot_length@Base 1.9.1
wtap_strerror@Base 1.9.1
wtap_tsprec_string@Base 1.99.9
Expand Down
8 changes: 4 additions & 4 deletions editcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ list_capture_types(FILE *stream) {
fprintf(stream, "editcap: The available capture file types for the \"-F\" flag are:\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
if (wtap_dump_can_open(i)) {
captypes[i].sstr = wtap_file_type_subtype_short_string(i);
captypes[i].lstr = wtap_file_type_subtype_string(i);
captypes[i].sstr = wtap_file_type_subtype_name(i);
captypes[i].lstr = wtap_file_type_subtype_description(i);
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
}
Expand Down Expand Up @@ -1373,7 +1373,7 @@ main(int argc, char *argv[])
break;

case 'F':
out_file_type_subtype = wtap_short_string_to_file_type_subtype(optarg);
out_file_type_subtype = wtap_name_to_file_type_subtype(optarg);
if (out_file_type_subtype < 0) {
fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
optarg);
Expand Down Expand Up @@ -1550,7 +1550,7 @@ main(int argc, char *argv[])

if (verbose) {
fprintf(stderr, "File %s is a %s capture file.\n", argv[optind],
wtap_file_type_subtype_string(wtap_file_type_subtype(wth)));
wtap_file_type_subtype_description(wtap_file_type_subtype(wth)));
}

if (skip_radiotap) {
Expand Down
2 changes: 1 addition & 1 deletion epan/wslua/wslua.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct _wslua_filehandler {
struct file_type_subtype_info finfo;
gboolean is_reader;
gboolean is_writer;
gchar* description;
gchar* internal_description; /* XXX - this is redundant; finfo.description should suffice */
gchar* type;
gchar* extensions;
lua_State* L;
Expand Down
20 changes: 10 additions & 10 deletions epan/wslua/wslua_dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,23 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {

case WTAP_ERR_CANT_WRITE_TO_PIPE:
luaL_error(L,"The file \"%s\" is a pipe, and %s capture files can't be written to a pipe",
filename, wtap_file_type_subtype_string(filetype));
filename, wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_UNWRITABLE_FILE_TYPE:
luaL_error(L,"Files of file type %s cannot be written",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_UNWRITABLE_ENCAP:
luaL_error(L,"Files of file type %s don't support encapsulation %s",
wtap_file_type_subtype_string(filetype),
wtap_file_type_subtype_description(filetype),
wtap_encap_name(encap));
break;

case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
luaL_error(L,"Files of file type %s don't support per-packet encapsulation",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_CANT_OPEN:
Expand All @@ -253,7 +253,7 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {

case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
luaL_error(L,"Files of file type %s cannot be written as a compressed file",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_INTERNAL:
Expand Down Expand Up @@ -435,23 +435,23 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {

case WTAP_ERR_CANT_WRITE_TO_PIPE:
luaL_error(L,"The file \"%s\" is a pipe, and %s capture files can't be written to a pipe",
filename, wtap_file_type_subtype_string(filetype));
filename, wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_UNWRITABLE_FILE_TYPE:
luaL_error(L,"Files of file type %s cannot be written",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_UNWRITABLE_ENCAP:
luaL_error(L,"Files of file type %s don't support encapsulation %s",
wtap_file_type_subtype_string(filetype),
wtap_file_type_subtype_description(filetype),
wtap_encap_name(encap));
break;

case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
luaL_error(L,"Files of file type %s don't support per-packet encapsulation",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_CANT_OPEN:
Expand All @@ -466,7 +466,7 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {

case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
luaL_error(L,"Files of file type %s cannot be written as a compressed file",
wtap_file_type_subtype_string(filetype));
wtap_file_type_subtype_description(filetype));
break;

case WTAP_ERR_INTERNAL:
Expand Down
34 changes: 17 additions & 17 deletions epan/wslua/wslua_file_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,34 +609,34 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info)

WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) {
/* Creates a new FileHandler */
#define WSLUA_ARG_FileHandler_new_NAME 1 /* The name of the file type, for display purposes only. E.g., "Wireshark - pcapng" */
#define WSLUA_ARG_FileHandler_new_SHORTNAME 2 /* The file type short name, used as a shortcut in various places. E.g., "pcapng". Note: The name cannot already be in use. */
#define WSLUA_ARG_FileHandler_new_DESCRIPTION 3 /* Descriptive text about this file format, for display purposes only */
#define WSLUA_ARG_FileHandler_new_DESCRIPTION 1 /* A description of the file type, for display purposes only. E.g., "Wireshark - pcapng" */
#define WSLUA_ARG_FileHandler_new_NAME 2 /* The file type name, used to look up the file type in various places. E.g., "pcapng". Note: The name cannot already be in use. */
#define WSLUA_ARG_FileHandler_new_INTERNAL_DESCRIPTION 3 /* Descriptive text about this file format, for internal display purposes only */
#define WSLUA_ARG_FileHandler_new_TYPE 4 /* The type of FileHandler, "r"/"w"/"rw" for reader/writer/both, include "m" for magic, "s" for strong heuristic */

const gchar* description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_DESCRIPTION);
const gchar* name = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_NAME);
const gchar* short_name = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_SHORTNAME);
const gchar* desc = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_DESCRIPTION);
const gchar* internal_description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_INTERNAL_DESCRIPTION);
const gchar* type = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_TYPE);
FileHandler fh = (FileHandler) g_malloc0(sizeof(struct _wslua_filehandler));

fh->is_reader = (strchr(type,'r') != NULL) ? TRUE : FALSE;
fh->is_writer = (strchr(type,'w') != NULL) ? TRUE : FALSE;

if (fh->is_reader && wtap_has_open_info(short_name)) {
if (fh->is_reader && wtap_has_open_info(name)) {
g_free(fh);
return luaL_error(L, "FileHandler.new: '%s' short name already exists for a reader!", short_name);
return luaL_error(L, "FileHandler.new: '%s' name already exists for a reader!", name);
}

if (fh->is_writer && wtap_short_string_to_file_type_subtype(short_name) > -1) {
if (fh->is_writer && wtap_name_to_file_type_subtype(name) > -1) {
g_free(fh);
return luaL_error(L, "FileHandler.new: '%s' short name already exists for a writer!", short_name);
return luaL_error(L, "FileHandler.new: '%s' name already exists for a writer!", name);
}

fh->type = g_strdup(type);
fh->extensions = NULL;
fh->finfo.description = g_strdup(description);
fh->finfo.name = g_strdup(name);
fh->finfo.short_name = g_strdup(short_name);
fh->finfo.default_file_extension = NULL;
fh->finfo.additional_file_extensions = NULL;
fh->finfo.writing_must_seek = FALSE;
Expand All @@ -646,7 +646,7 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) {
/* this will be set to a new file_type when registered */
fh->file_type = WTAP_FILE_TYPE_SUBTYPE_UNKNOWN;

fh->description = g_strdup(desc);
fh->internal_description = g_strdup(internal_description);
fh->L = L;
fh->read_open_ref = LUA_NOREF;
fh->read_ref = LUA_NOREF;
Expand All @@ -671,8 +671,8 @@ WSLUA_METAMETHOD FileHandler__tostring(lua_State* L) {
if (!fh) {
lua_pushstring(L,"FileHandler pointer is NULL!");
} else {
lua_pushfstring(L, "FileHandler(%s): short-name='%s', description='%s', read_open=%d, read=%d, write=%d",
fh->finfo.name, fh->finfo.short_name, fh->description, fh->read_open_ref, fh->read_ref, fh->write_ref);
lua_pushfstring(L, "FileHandler(%s): description='%s', internal description='%s', read_open=%d, read=%d, write=%d",
fh->finfo.name, fh->finfo.description, fh->internal_description, fh->read_open_ref, fh->read_ref, fh->write_ref);
}

WSLUA_RETURN(1); /* String of debug information. */
Expand Down Expand Up @@ -723,7 +723,7 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) {
* XXX wtap_register_file_type_subtypes will abort the program if a builtin
* file handler is overridden, so plugin authors should not try that.
*/
int file_type = wtap_short_string_to_file_type_subtype(fh->finfo.short_name);
int file_type = wtap_name_to_file_type_subtype(fh->finfo.name);
if (file_type == -1) {
/* File type was not registered before, create a new one. */
file_type = WTAP_FILE_TYPE_SUBTYPE_UNKNOWN;
Expand Down Expand Up @@ -751,7 +751,7 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) {

if (fh->is_reader) {
struct open_info oi = { NULL, OPEN_INFO_HEURISTIC, NULL, NULL, NULL, NULL };
oi.name = fh->finfo.short_name;
oi.name = fh->finfo.name;
oi.open_routine = wslua_filehandler_open;
oi.extensions = fh->extensions;
oi.wslua_data = (void*)(fh);
Expand Down Expand Up @@ -787,8 +787,8 @@ wslua_deregister_filehandler_work(FileHandler fh)
if (fh->file_type != WTAP_FILE_TYPE_SUBTYPE_UNKNOWN)
wtap_deregister_file_type_subtype(fh->file_type);

if (fh->is_reader && wtap_has_open_info(fh->finfo.short_name)) {
wtap_deregister_open_info(fh->finfo.short_name);
if (fh->is_reader && wtap_has_open_info(fh->finfo.name)) {
wtap_deregister_open_info(fh->finfo.name);
}

fh->registered = FALSE;
Expand Down
12 changes: 6 additions & 6 deletions epan/wslua/wslua_wtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_description(lua_State* LS) {
*/
#define WSLUA_ARG_file_type_subtype_description_FILETYPE 1 /* The type for which the description is to be fetched - a number entry from the `wtap_filetypes` table in `init.lua`. */
lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_file_type_subtype_description_FILETYPE);
/* wtap_file_type_subtype_string()'s name isn't really descriptive. */
/* wtap_file_type_subtype_description()'s name isn't really descriptive. */
if (filetype > INT_MAX) {
/* Too big. */
lua_pushnil(LS);
} else {
const gchar* str = wtap_file_type_subtype_string((int)filetype);
const gchar* str = wtap_file_type_subtype_description((int)filetype);
if (str == NULL)
lua_pushnil(LS);
else
Expand All @@ -52,12 +52,12 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_name(lua_State* LS) {
*/
#define WSLUA_ARG_file_type_subtype_name_FILETYPE 1 /* The type for which the name is to be fetched - a number entry from the `wtap_filetypes` table in `init.lua`. */
lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_file_type_subtype_name_FILETYPE);
/* wtap_file_type_subtype_string()'s name isn't really descriptive. */
/* wtap_file_type_subtype_description()'s name isn't really descriptive. */
if (filetype > INT_MAX) {
/* Too big. */
lua_pushnil(LS);
} else {
const gchar* str = wtap_file_type_subtype_short_string((int)filetype);
const gchar* str = wtap_file_type_subtype_name((int)filetype);
if (str == NULL)
lua_pushnil(LS);
else
Expand All @@ -75,8 +75,8 @@ WSLUA_FUNCTION wslua_wtap_name_to_file_type_subtype(lua_State* LS) {
*/
#define WSLUA_ARG_name_to_file_type_subtype_NAME 1 /* A timestamp value to convert. */
const char* name = luaL_checkstring(LS,WSLUA_ARG_name_to_file_type_subtype_NAME);
/* wtap_short_string_to_file_type_subtype()'s name isn't really descriptive. */
lua_Number filetype = wtap_short_string_to_file_type_subtype(name);
/* wtap_name_to_file_type_subtype()'s name isn't really descriptive. */
lua_Number filetype = wtap_name_to_file_type_subtype(name);
if (filetype == -1)
lua_pushnil(LS);
else
Expand Down
8 changes: 4 additions & 4 deletions mergecap.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ list_capture_types(void) {
fprintf(stderr, "mergecap: The available capture file types for the \"-F\" flag are:\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
if (wtap_dump_can_open(i)) {
captypes[i].sstr = wtap_file_type_subtype_short_string(i);
captypes[i].lstr = wtap_file_type_subtype_string(i);
captypes[i].sstr = wtap_file_type_subtype_name(i);
captypes[i].lstr = wtap_file_type_subtype_description(i);
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
}
Expand Down Expand Up @@ -170,7 +170,7 @@ merge_callback(merge_event event, int num,
case MERGE_EVENT_INPUT_FILES_OPENED:
for (i = 0; i < in_file_count; i++) {
fprintf(stderr, "mergecap: %s is type %s.\n", in_files[i].filename,
wtap_file_type_subtype_string(wtap_file_type_subtype(in_files[i].wth)));
wtap_file_type_subtype_description(wtap_file_type_subtype(in_files[i].wth)));
}
break;

Expand Down Expand Up @@ -287,7 +287,7 @@ main(int argc, char *argv[])
break;

case 'F':
file_type = wtap_short_string_to_file_type_subtype(optarg);
file_type = wtap_name_to_file_type_subtype(optarg);
if (file_type < 0) {
fprintf(stderr, "mergecap: \"%s\" isn't a valid capture file type\n",
optarg);
Expand Down
8 changes: 4 additions & 4 deletions tshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ list_capture_types(void) {
fprintf(stderr, "tshark: The available capture file types for the \"-F\" flag are:\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
if (wtap_dump_can_open(i)) {
captypes[i].sstr = wtap_file_type_subtype_short_string(i);
captypes[i].lstr = wtap_file_type_subtype_string(i);
captypes[i].sstr = wtap_file_type_subtype_name(i);
captypes[i].lstr = wtap_file_type_subtype_description(i);
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ main(int argc, char *argv[])
}
break;
case 'F':
out_file_type = wtap_short_string_to_file_type_subtype(optarg);
out_file_type = wtap_name_to_file_type_subtype(optarg);
if (out_file_type < 0) {
cmdarg_err("\"%s\" isn't a valid capture file type", optarg);
list_capture_types();
Expand Down Expand Up @@ -3743,7 +3743,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
if (pdh && out_file_name_res) {
if (!wtap_dump_set_addrinfo_list(pdh, get_addrinfo_list())) {
cmdarg_err("The file format \"%s\" doesn't support name resolution information.",
wtap_file_type_subtype_short_string(out_file_type));
wtap_file_type_subtype_name(out_file_type));
}
}
/* Now close the capture file. */
Expand Down
Loading

0 comments on commit 24acef0

Please sign in to comment.