diff --git a/debian/libwiretap0.symbols b/debian/libwiretap0.symbols index 7cf7df8eeed..24f083c0e50 100644 --- a/debian/libwiretap0.symbols +++ b/debian/libwiretap0.symbols @@ -9,6 +9,7 @@ libwiretap.so.0 libwiretap0 #MINVER# file_read@Base 1.9.1 file_seek@Base 1.9.1 file_tell@Base 1.9.1 + get_backwards_compatibility_lua_table@Base 3.5.0 init_open_routines@Base 1.12.0~rc1 merge_files@Base 1.99.9 merge_files_to_stdout@Base 2.3.0 @@ -119,8 +120,8 @@ libwiretap.so.0 libwiretap0 #MINVER# wtap_get_next_interface_description@Base 3.3.2 wtap_get_num_encap_types@Base 1.9.1 wtap_get_num_file_type_extensions@Base 1.12.0~rc1 - wtap_get_num_file_types_subtypes@Base 1.12.0~rc1 - wtap_get_savable_file_types_subtypes@Base 1.12.0~rc1 + wtap_get_savable_file_types_subtypes_for_file@Base 3.5.0 + wtap_get_writable_file_types_subtypes@Base 3.5.0 wtap_has_open_info@Base 1.12.0~rc1 wtap_init@Base 2.3.0 wtap_name_to_encap@Base 2.9.1 @@ -137,6 +138,7 @@ libwiretap.so.0 libwiretap0 #MINVER# wtap_read_so_far@Base 1.9.1 wtap_rec_cleanup@Base 2.5.1 wtap_rec_init@Base 2.5.1 + wtap_register_backwards_compatibility_lua_name@Base 3.5.0 wtap_register_encap_type@Base 1.9.1 wtap_register_file_type_extension@Base 1.12.0~rc1 wtap_register_file_type_subtypes@Base 1.12.0~rc1 diff --git a/editcap.c b/editcap.c index cc90d33a2aa..0fc4c150018 100644 --- a/editcap.c +++ b/editcap.c @@ -871,13 +871,6 @@ struct string_elem { const char *lstr; /* The long string */ }; -static gint -string_compare(gconstpointer a, gconstpointer b) -{ - return strcmp(((const struct string_elem *)a)->sstr, - ((const struct string_elem *)b)->sstr); -} - static gint string_nat_compare(gconstpointer a, gconstpointer b) { @@ -895,22 +888,16 @@ string_elem_print(gpointer data, gpointer stream_ptr) static void list_capture_types(FILE *stream) { - int i; - struct string_elem *captypes; - GSList *list = NULL; + GArray *writable_type_subtypes; - captypes = g_new(struct string_elem,WTAP_NUM_FILE_TYPES_SUBTYPES); 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_name(i); - captypes[i].lstr = wtap_file_type_subtype_description(i); - list = g_slist_insert_sorted(list, &captypes[i], string_compare); - } + writable_type_subtypes = wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME); + for (guint i = 0; i < writable_type_subtypes->len; i++) { + int ft = g_array_index(writable_type_subtypes, int, i); + fprintf(stderr, " %s - %s\n", wtap_file_type_subtype_name(ft), + wtap_file_type_subtype_description(ft)); } - g_slist_foreach(list, string_elem_print, stream); - g_slist_free(list); - g_free(captypes); + g_array_free(writable_type_subtypes, TRUE); } static void diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl index 650502ec36a..77eedbf3327 100755 --- a/epan/wslua/make-init-lua.pl +++ b/epan/wslua/make-init-lua.pl @@ -19,7 +19,6 @@ die "'$WSROOT' is not a directory" unless -d $WSROOT; my $wtap_encaps_table = ''; -my $wtap_filetypes_table = ''; my $wtap_tsprecs_table = ''; my $wtap_commenttypes_table = ''; my $ft_types_table = ''; @@ -36,7 +35,6 @@ my %replacements = %{{ WTAP_ENCAPS => \$wtap_encaps_table, - WTAP_FILETYPES => \$wtap_filetypes_table, WTAP_TSPRECS => \$wtap_tsprecs_table, WTAP_COMMENTTYPES => \$wtap_commenttypes_table, FT_TYPES => \$ft_types_table, @@ -70,7 +68,6 @@ # $wtap_encaps_table = "-- Wiretap encapsulations XXX\nwtap_encaps = {\n"; -$wtap_filetypes_table = "-- Wiretap file types\nwtap_filetypes = {\n"; $wtap_tsprecs_table = "-- Wiretap timestamp precision types\nwtap_tsprecs = {\n"; $wtap_commenttypes_table = "-- Wiretap file comment types\nwtap_comments = {\n"; $wtap_rec_types_table = "-- Wiretap record_types\nwtap_rec_types = {\n"; @@ -85,8 +82,6 @@ if ( /^#define WTAP_TSPREC_([A-Z0-9_]+)\s+(\d+)/ ) { $wtap_tsprecs_table .= "\t[\"$1\"] = $2,\n"; - # for backwards compatibility we need to add them to the filetypes table too - $wtap_filetypes_table .= "\t[\"TSPREC_$1\"] = $2,\n"; } if ( /^#define WTAP_COMMENT_([A-Z0-9_]+)\s+(0x\d+)/ ) { @@ -104,7 +99,6 @@ } $wtap_encaps_table =~ s/,\n$/\n}\nwtap = wtap_encaps -- for bw compatibility\n/msi; -$wtap_filetypes_table =~ s/,\n$/\n}\n/msi; $wtap_tsprecs_table =~ s/,\n$/\n}\n/msi; $wtap_commenttypes_table =~ s/,\n$/\n}\n/msi; # wtap_rec_types_table has comments at the end (not a comma), diff --git a/epan/wslua/make-reg.pl b/epan/wslua/make-reg.pl index d0cc9d00d44..549b440daff 100755 --- a/epan/wslua/make-reg.pl +++ b/epan/wslua/make-reg.pl @@ -16,6 +16,7 @@ my @classes = (); my @functions = (); +my @internal_functions = (); my $source_dir = ""; GetOptions('dir=s' => \$source_dir); @@ -33,6 +34,7 @@ while () { push @classes, $1 if /WSLUA_CLASS_DEFINE(?:_BASE)?\050\s*([A-Za-z0-9]+)/; push @functions, $1 if /WSLUA_FUNCTION\s+wslua_([a-z_0-9]+)/; + push @internal_functions, $1 if /WSLUA_INTERNAL_FUNCTION\s+wslua_([a-z_0-9]+)/; } } @@ -52,6 +54,9 @@ for (@functions) { print H "\tWSLUA_FUNCTION wslua_$_(lua_State* L);\\\n" } +for (@internal_functions) { + print H "\tWSLUA_INTERNAL_FUNCTION wslua_$_(lua_State* L);\\\n" +} print H "\n\n"; print H "extern void wslua_register_classes(lua_State* L);\n"; print H "extern void wslua_register_functions(lua_State* L);\n"; @@ -83,6 +88,9 @@ for (@functions) { print C "\tWSLUA_REGISTER_FUNCTION($_); \n" } +for (@internal_functions) { + print C "\tWSLUA_REGISTER_FUNCTION($_); \n" +} print C "}\n\n"; close H; diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index f4aec8a0a2c..796bd8eb776 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -78,12 +78,6 @@ end %WTAP_ENCAPS% --- --- This pulls in the WTAP_TSPREC_ values that are included in --- wtap_filetypes for backwards compatibility. --- -%WTAP_FILETYPES% - -- -- Generate the wtap_filetypes items for file types, for backwards -- compatibility. @@ -94,120 +88,7 @@ end -- New code should use wtap_name_to_file_type_subtype to -- look up file types by name. -- --- "UNKNOWN" is a special case; it has no name. --- -wtap_filetypes["UNKNOWN"] = 0 -for filetype = 1, wtap_get_num_file_types_subtypes() - 1 do - local typename = wtap_file_type_subtype_name(filetype) - -- - -- In most cases, the old #define was just a capitalized - -- version of the file type name. - -- - -- We process the exceptions here. - -- - if typename == "nsecpcap" then - wtap_filetypes["PCAP_NSEC"] = filetype - elseif typename == "aixpcap" then - wtap_filetypes["PCAP_AIX"] = filetype - elseif typename == "modpcap" then - wtap_filetypes["PCAP_SS991029"] = filetype - elseif typename == "nokiapcap" then - wtap_filetypes["PCAP_NOKIA"] = filetype - elseif typename == "rh6_1pcap" then - wtap_filetypes["PCAP_SS990417"] = filetype - elseif typename == "suse6_3pcap" then - wtap_filetypes["PCAP_SS990915"] = filetype - elseif typename == "iptrace_1" then - wtap_filetypes["IPTRACE_1_0"] = filetype - elseif typename == "iptrace_2" then - wtap_filetypes["IPTRACE_2_0"] = filetype - elseif typename == "dct2000" then - wtap_filetypes["CATAPULT_DCT2000"] = filetype - elseif typename == "netxray1" then - wtap_filetypes["NETXRAY_OLD"] = filetype - elseif typename == "netxray2" then - -- This is correct; the #define was wrong - wtap_filetypes["NETXRAY_1_0"] = filetype - elseif typename == "etherwatch" then - wtap_filetypes["DBS_ETHERWATCH"] = filetype - elseif typename == "iseries_ascii" then - wtap_filetypes["ISERIES"] = filetype - elseif typename == "iseries_unicode" then - wtap_filetypes["ISERIES_UNICODE"] = filetype - elseif typename == "netmon1" then - wtap_filetypes["NETMON_1_x"] = filetype - elseif typename == "netmon2" then - wtap_filetypes["NETMON_2_x"] = filetype - elseif typename == "ngsniffer" then - wtap_filetypes["NGSNIFFER_UNCOMPRESSED"] = filetype - elseif typename == "ngsniffer_comp" then - wtap_filetypes["NGSNIFFER_COMPRESSED"] = filetype - elseif typename == "ngwsniffer_1_1" then - wtap_filetypes["NETXRAY_1_1"] = filetype - elseif typename == "ngwsniffer_2_0" then - wtap_filetypes["NETXRAY_2_00x"] = filetype - elseif typename == "niobserver" then - wtap_filetypes["NETWORK_INSTRUMENTS"] = filetype - elseif typename == "pppd" then - wtap_filetypes["PPPDUMP"] = filetype - elseif typename == "tcpiptrace" then - wtap_filetypes["VMS"] = filetype - elseif typename == "rf5" then - wtap_filetypes["K12"] = filetype - elseif typename == "visual" then - wtap_filetypes["VISUAL_NETWORKS"] = filetype - elseif typename == "peekclassic56" then - wtap_filetypes["PEEKCLASSIC_V56"] = filetype - elseif typename == "peekclassic7" then - wtap_filetypes["PEEKCLASSIC_V7"] = filetype - elseif typename == "pklg" then - wtap_filetypes["PACKETLOGGER"] = filetype - elseif typename == "dsna" then - wtap_filetypes["DAINTREE_SNA"] = filetype - elseif typename == "nstrace10" then - wtap_filetypes["NETSCALER_1_0"] = filetype - elseif typename == "nstrace20" then - wtap_filetypes["NETSCALER_2_0"] = filetype - elseif typename == "nstrace30" then - wtap_filetypes["NETSCALER_3_0"] = filetype - elseif typename == "nstrace35" then - wtap_filetypes["NETSCALER_3_5"] = filetype - elseif typename == "jpeg" then - wtap_filetypes["JPEG_JFIF"] = filetype - elseif typename == "mp2t" then - wtap_filetypes["MPEG_2_TS"] = filetype - elseif typename == "vwr80211" then - wtap_filetypes["VWR_80211"] = filetype - elseif typename == "vwreth" then - wtap_filetypes["VWR_ETH"] = filetype - elseif typename == "stanag4607" then - wtap_filetypes["STANAG_4607"] = filetype - elseif typename == "logcat-brief" then - wtap_filetypes["LOGCAT_BRIEF"] = filetype - elseif typename == "logcat-process" then - wtap_filetypes["LOGCAT_PROCESS"] = filetype - elseif typename == "logcat-tag" then - wtap_filetypes["LOGCAT_TAG"] = filetype - elseif typename == "logcat-thread" then - wtap_filetypes["LOGCAT_THREAD"] = filetype - elseif typename == "logcat-time" then - wtap_filetypes["LOGCAT_TIME"] = filetype - elseif typename == "logcat-threadtime" then - wtap_filetypes["LOGCAT_THREADTIME"] = filetype - elseif typename == "logcat-long" then - wtap_filetypes["LOGCAT_LONG"] = filetype - elseif typename == "colasoft-pb" then - wtap_filetypes["PACKET_BUILDER"] = filetype - elseif typename == "3gpp32423" then - wtap_filetypes["NETTRACE_3GPP_32_423"] = filetype - elseif typename == "3gpp_log" then - wtap_filetypes["LOG_3GPP"] = filetype - elseif typename == "jpeg" then - wtap_filetypes["JPEG_JFIF"] = filetype - else - wtap_filetypes[string.upper(typename)] = filetype - end -end +wtap_filetypes = get_wtap_filetypes() %WTAP_TSPRECS% diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index fe5ebd29695..e7acbe2ec8f 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -462,6 +462,8 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb #endif #define WSLUA_FUNCTION extern int +/* This is for functions intended only to be used in init.lua */ +#define WSLUA_INTERNAL_FUNCTION extern int #define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); } diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index 0737ab17370..49602878a83 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -719,16 +719,6 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) { if (!verify_filehandler_complete(fh)) return luaL_error(L,"this FileHandler is not complete enough to register"); - /* If a Lua file handler is reloaded, try to reuse the previous subtype. - * 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_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; - } - if (fh->is_writer) { if (fh->extensions && fh->extensions[0]) { char *extension = g_strdup(fh->extensions); @@ -747,7 +737,7 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) { fh->finfo.dump_open = wslua_filehandler_dump_open; } - fh->file_type = wtap_register_file_type_subtypes(&(fh->finfo), file_type); + fh->file_type = wtap_register_file_type_subtypes(&(fh->finfo)); if (fh->is_reader) { struct open_info oi = { NULL, OPEN_INFO_HEURISTIC, NULL, NULL, NULL, NULL }; diff --git a/epan/wslua/wslua_wtap.c b/epan/wslua/wslua_wtap.c index bbd3108025f..4644430d422 100644 --- a/epan/wslua/wslua_wtap.c +++ b/epan/wslua/wslua_wtap.c @@ -20,6 +20,12 @@ #include "wslua.h" #include +/* + * Solely for the function that gets the table of backwards-compatibility + * Lua names for file types/subtypes. + */ +#include + WSLUA_FUNCTION wslua_wtap_file_type_subtype_description(lua_State* LS) { /* Get a string describing a capture file type, given a filetype @@ -84,15 +90,39 @@ WSLUA_FUNCTION wslua_wtap_name_to_file_type_subtype(lua_State* LS) { WSLUA_RETURN(1); /* The filetype value for the file type with that name, or nil if there is no such file type. */ } -WSLUA_FUNCTION wslua_wtap_get_num_file_types_subtypes(lua_State* LS) { - /* - Get the total number of filetype values. +/* + * init.wslua-only function to return a table to assign to + * wtap_filetypes. + */ +WSLUA_INTERNAL_FUNCTION wslua_get_wtap_filetypes(lua_State* LS) { + /* Get the GArray from which we initialize this. */ + const GArray *table = get_backwards_compatibility_lua_table(); - Note: as filetype values begin with 0, this is one *greater* - than the largest filetype value. + /* + * Create the table; it's indexted by strings, not numbers, + * so none of the entries will be in a sequence. + */ + lua_createtable(LS,0,table->len); + for (guint i = 0; i < table->len; i++) { + struct backwards_compatibiliity_lua_name *entry; - @since 3.5.0 - */ - lua_pushnumber(LS,wtap_get_num_file_types_subtypes()); - WSLUA_RETURN(1); /* The total number of registered file types. */ + entry = &g_array_index(table, + struct backwards_compatibiliity_lua_name, i); + /* + * Push the name and the ft, in order, so that the ft, + * which should be the value at the top of the stack, + * is at the top of the stack, and the name, which should + * be the value just below that, is the value just below + * it. + */ + lua_pushstring(LS, entry->name); + lua_pushnumber(LS, entry->ft); + /* + * The -3 is the index, relative to the top of the stack, of + * the table; the two elements on top of it are the ft and + * the name, so it's -3. + */ + lua_settable(LS, -3); + } + WSLUA_RETURN(1); /* The table. */ } diff --git a/mergecap.c b/mergecap.c index 96856b533fa..de1dc965bff 100644 --- a/mergecap.c +++ b/mergecap.c @@ -101,25 +101,6 @@ mergecap_cmdarg_err_cont(const char *fmt, va_list ap) fprintf(stderr, "\n"); } -struct string_elem { - const char *sstr; /* The short string */ - const char *lstr; /* The long string */ -}; - -static gint -string_compare(gconstpointer a, gconstpointer b) -{ - return strcmp(((const struct string_elem *)a)->sstr, - ((const struct string_elem *)b)->sstr); -} - -static void -string_elem_print(gpointer data, gpointer not_used _U_) -{ - fprintf(stderr, " %s - %s\n", ((struct string_elem *)data)->sstr, - ((struct string_elem *)data)->lstr); -} - /* * General errors and warnings are reported with an console message * in mergecap. @@ -134,23 +115,16 @@ failure_warning_message(const char *msg_format, va_list ap) static void list_capture_types(void) { - int i; - struct string_elem *captypes; - GSList *list = NULL; - - captypes = g_new(struct string_elem,WTAP_NUM_FILE_TYPES_SUBTYPES); + GArray *writable_type_subtypes; 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_name(i); - captypes[i].lstr = wtap_file_type_subtype_description(i); - list = g_slist_insert_sorted(list, &captypes[i], string_compare); - } + writable_type_subtypes = wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME); + for (guint i = 0; i < writable_type_subtypes->len; i++) { + int ft = g_array_index(writable_type_subtypes, int, i); + fprintf(stderr, " %s - %s\n", wtap_file_type_subtype_name(ft), + wtap_file_type_subtype_description(ft)); } - g_slist_foreach(list, string_elem_print, NULL); - g_slist_free(list); - g_free(captypes); + g_array_free(writable_type_subtypes, TRUE); } static void diff --git a/plugins/wiretap/usbdump/usbdump.c b/plugins/wiretap/usbdump/usbdump.c index 3412ad1c3be..21db48aa04a 100644 --- a/plugins/wiretap/usbdump/usbdump.c +++ b/plugins/wiretap/usbdump/usbdump.c @@ -334,8 +334,7 @@ wtap_register_usbdump(void) NULL }; - usbdump_file_type_subtype = - wtap_register_file_type_subtypes(&fi, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + usbdump_file_type_subtype = wtap_register_file_type_subtypes(&fi); } /* diff --git a/tools/make-regs.py b/tools/make-regs.py index 3ab5d1ed03d..8e468e037ff 100755 --- a/tools/make-regs.py +++ b/tools/make-regs.py @@ -90,7 +90,7 @@ def make_wtap_modules(outfile, infiles): output += """\ #include "wtap_modules.h" -const gulong wtap_module_count = {0}; +const guint wtap_module_count = {0}; """.format(len(wtap_modules)) diff --git a/tshark.c b/tshark.c index 0239c04f9bd..15d1563f775 100644 --- a/tshark.c +++ b/tshark.c @@ -272,6 +272,20 @@ static void failure_message_cont(const char *msg_format, va_list ap); static GHashTable *output_only_tables = NULL; +static void +list_capture_types(void) { + GArray *writable_type_subtypes; + + fprintf(stderr, "tshark: The available capture file types for the \"-F\" flag are:\n"); + writable_type_subtypes = wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME); + for (guint i = 0; i < writable_type_subtypes->len; i++) { + int ft = g_array_index(writable_type_subtypes, int, i); + fprintf(stderr, " %s - %s\n", wtap_file_type_subtype_name(ft), + wtap_file_type_subtype_description(ft)); + } + g_array_free(writable_type_subtypes, TRUE); +} + struct string_elem { const char *sstr; /* The short string */ const char *lstr; /* The long string */ @@ -292,39 +306,23 @@ string_elem_print(gpointer data) ((struct string_elem *)data)->lstr); } -static void -list_capture_types(void) { - int i; - struct string_elem *captypes; - GSList *list = NULL; - - captypes = g_new(struct string_elem, WTAP_NUM_FILE_TYPES_SUBTYPES); - - 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_name(i); - captypes[i].lstr = wtap_file_type_subtype_description(i); - list = g_slist_insert_sorted(list, &captypes[i], string_compare); - } - } - g_slist_free_full(list, string_elem_print); - g_free(captypes); -} - static void list_read_capture_types(void) { - int i; + guint i; + size_t num_file_types; struct string_elem *captypes; GSList *list = NULL; const char *magic = "Magic-value-based"; const char *heuristic = "Heuristics-based"; - /* this is a hack, but WTAP_NUM_FILE_TYPES_SUBTYPES is always >= number of open routines so we're safe */ - captypes = g_new(struct string_elem, WTAP_NUM_FILE_TYPES_SUBTYPES); + /* How many readable file types are there? */ + num_file_types = 0; + for (i = 0; open_routines[i].name != NULL; i++) + num_file_types++; + captypes = g_new(struct string_elem, num_file_types); fprintf(stderr, "tshark: The available read file types for the \"-X read_format:\" option are:\n"); - for (i = 0; open_routines[i].name != NULL; i++) { + for (i = 0; i < num_file_types && open_routines[i].name != NULL; i++) { captypes[i].sstr = open_routines[i].name; captypes[i].lstr = (open_routines[i].type == OPEN_INFO_MAGIC) ? magic : heuristic; list = g_slist_insert_sorted(list, &captypes[i], string_compare); diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index edd2d1882ec..afea3b8d717 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -813,9 +813,10 @@ QStringList CaptureFileDialog::buildFileSaveAsTypeList(bool must_support_all_com required_comment_types = 0; /* none of them */ /* What types of file can we save this file as? */ - savable_file_types_subtypes = wtap_get_savable_file_types_subtypes(cap_file_->cd_t, + savable_file_types_subtypes = wtap_get_savable_file_types_subtypes_for_file(cap_file_->cd_t, cap_file_->linktypes, - required_comment_types); + required_comment_types, + FT_SORT_BY_DESCRIPTION); if (savable_file_types_subtypes != NULL) { int ft; diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 924e1ef63cc..4196d903fe9 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -250,9 +250,10 @@ win32_save_as_file(HWND h_wnd, const wchar_t *title, capture_file *cf, GString * else required_comment_types = 0; /* none of them */ - savable_file_types = wtap_get_savable_file_types_subtypes(cf->cd_t, + savable_file_types = wtap_get_savable_file_types_subtypes_for_file(cf->cd_t, cf->linktypes, - required_comment_types); + required_comment_types, + FT_SORT_BY_DESCRIPTION); if (savable_file_types == NULL) return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */ g_compressed = FALSE; @@ -328,8 +329,9 @@ win32_export_specified_packets_file(HWND h_wnd, const wchar_t *title, StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str)); } - savable_file_types = wtap_get_savable_file_types_subtypes(cf->cd_t, - cf->linktypes, 0); + savable_file_types = wtap_get_savable_file_types_subtypes_for_file(cf->cd_t, + cf->linktypes, 0, + FT_SORT_BY_DESCRIPTION); if (savable_file_types == NULL) return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */ diff --git a/wiretap/5views.c b/wiretap/5views.c index 810ef44ce5b..8c74b61e96a 100644 --- a/wiretap/5views.c +++ b/wiretap/5views.c @@ -461,9 +461,14 @@ static const struct file_type_subtype_info _5views_info = { void register_5views(void) { - _5views_file_type_subtype = - wtap_register_file_type_subtypes(&_5views_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + _5views_file_type_subtype = wtap_register_file_type_subtypes(&_5views_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("5VIEWS", + _5views_file_type_subtype); } /* diff --git a/wiretap/aethra.c b/wiretap/aethra.c index 36633d97f47..00c13e9c752 100644 --- a/wiretap/aethra.c +++ b/wiretap/aethra.c @@ -349,9 +349,14 @@ static const struct file_type_subtype_info aethra_info = { void register_aethra(void) { - aethra_file_type_subtype = - wtap_register_file_type_subtypes(&aethra_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + aethra_file_type_subtype = wtap_register_file_type_subtypes(&aethra_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("AETHRA", + aethra_file_type_subtype); } /* diff --git a/wiretap/ascendtext.c b/wiretap/ascendtext.c index 420999b1497..233503b3220 100644 --- a/wiretap/ascendtext.c +++ b/wiretap/ascendtext.c @@ -465,6 +465,12 @@ static const struct file_type_subtype_info ascend_info = { void register_ascend(void) { - ascend_file_type_subtype = wtap_register_file_type_subtypes(&ascend_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + ascend_file_type_subtype = wtap_register_file_type_subtypes(&ascend_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("ASCEND", + ascend_file_type_subtype); } diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c index 7ac50171533..6448437fd00 100644 --- a/wiretap/btsnoop.c +++ b/wiretap/btsnoop.c @@ -434,8 +434,14 @@ static const struct file_type_subtype_info btsnoop_info = { void register_btsnoop(void) { - btsnoop_file_type_subtype = wtap_register_file_type_subtypes(&btsnoop_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + btsnoop_file_type_subtype = wtap_register_file_type_subtypes(&btsnoop_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("BTSNOOP", + btsnoop_file_type_subtype); } /* diff --git a/wiretap/camins.c b/wiretap/camins.c index 407d5f4976b..eecaa79d5f6 100644 --- a/wiretap/camins.c +++ b/wiretap/camins.c @@ -460,8 +460,14 @@ static const struct file_type_subtype_info camins_info = { void register_camins(void) { - camins_file_type_subtype = wtap_register_file_type_subtypes(&camins_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + camins_file_type_subtype = wtap_register_file_type_subtypes(&camins_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("CAMINS", + camins_file_type_subtype); } /* diff --git a/wiretap/capsa.c b/wiretap/capsa.c index 181bd4ad6b3..2b2b4037735 100644 --- a/wiretap/capsa.c +++ b/wiretap/capsa.c @@ -448,12 +448,17 @@ static const struct file_type_subtype_info packet_builder_info = { void register_capsa(void) { - capsa_file_type_subtype = - wtap_register_file_type_subtypes(&capsa_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - packet_builder_file_type_subtype = - wtap_register_file_type_subtypes(&packet_builder_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + capsa_file_type_subtype = wtap_register_file_type_subtypes(&capsa_info); + packet_builder_file_type_subtype = wtap_register_file_type_subtypes(&packet_builder_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("COLASOFT_CAPSA", + capsa_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("COLASOFT_PACKET_BUILDER", + packet_builder_file_type_subtype); } /* diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index d6d4d064646..7a506b56b37 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -1652,17 +1652,21 @@ free_line_prefix_info(gpointer key, gpointer value, } static const struct file_type_subtype_info dct2000_info = { - "Catapult DCT2000 trace (.out format)", "dct2000", "out", NULL, - FALSE, FALSE, 0, - catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open, NULL - + "Catapult DCT2000 trace (.out format)", "dct2000", "out", NULL, + FALSE, FALSE, 0, + catapult_dct2000_dump_can_write_encap, catapult_dct2000_dump_open, NULL }; void register_dct2000(void) { - dct2000_file_type_subtype = - wtap_register_file_type_subtypes(&dct2000_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + dct2000_file_type_subtype = wtap_register_file_type_subtypes(&dct2000_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("CATAPULT_DCT2000", + dct2000_file_type_subtype); } /* diff --git a/wiretap/commview.c b/wiretap/commview.c index 68d04ef76a1..1be532604fe 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -608,9 +608,14 @@ static const struct file_type_subtype_info commview_info = { void register_commview(void) { - commview_file_type_subtype = - wtap_register_file_type_subtypes(&commview_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + commview_file_type_subtype = wtap_register_file_type_subtypes(&commview_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("COMMVIEW", + commview_file_type_subtype); } /* diff --git a/wiretap/cosine.c b/wiretap/cosine.c index c5c03d92b58..1ca9b16d698 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -496,9 +496,14 @@ static const struct file_type_subtype_info cosine_info = { void register_cosine(void) { - cosine_file_type_subtype = - wtap_register_file_type_subtypes(&cosine_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + cosine_file_type_subtype = wtap_register_file_type_subtypes(&cosine_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("COSINE", + cosine_file_type_subtype); } /* diff --git a/wiretap/csids.c b/wiretap/csids.c index 5e8322980ad..d144524851e 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -217,8 +217,14 @@ static const struct file_type_subtype_info csids_info = { void register_csids(void) { - csids_file_type_subtype = wtap_register_file_type_subtypes(&csids_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + csids_file_type_subtype = wtap_register_file_type_subtypes(&csids_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("CSIDS", + csids_file_type_subtype); } /* diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index 285be7b1dae..97a6479117a 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -262,9 +262,14 @@ static const struct file_type_subtype_info daintree_sna_info = { void register_daintree_sna(void) { - daintree_sna_file_type_subtype = - wtap_register_file_type_subtypes(&daintree_sna_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + daintree_sna_file_type_subtype = wtap_register_file_type_subtypes(&daintree_sna_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("DAINTREE_SNA", + daintree_sna_file_type_subtype); } /* diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index c2b6b180975..d2adcfdf842 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -638,8 +638,14 @@ static const struct file_type_subtype_info dbs_etherwatch_info = { void register_dbs_etherwatch(void) { - dbs_etherwatch_file_type_subtype = wtap_register_file_type_subtypes(&dbs_etherwatch_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + dbs_etherwatch_file_type_subtype = wtap_register_file_type_subtypes(&dbs_etherwatch_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("DBS_ETHERWATCH", + dbs_etherwatch_file_type_subtype); } /* diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c index cdfcc3794e8..89b8988571d 100644 --- a/wiretap/dct3trace.c +++ b/wiretap/dct3trace.c @@ -410,9 +410,14 @@ static const struct file_type_subtype_info dct3trace_info = { void register_dct3trace(void) { - dct3trace_file_type_subtype = - wtap_register_file_type_subtypes(&dct3trace_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + dct3trace_file_type_subtype = wtap_register_file_type_subtypes(&dct3trace_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("DCT3TRACE", + dct3trace_file_type_subtype); } /* diff --git a/wiretap/dpa400.c b/wiretap/dpa400.c index 95885597ff6..aa4ee490f15 100644 --- a/wiretap/dpa400.c +++ b/wiretap/dpa400.c @@ -254,9 +254,14 @@ static const struct file_type_subtype_info dpa400_info = { void register_dpa400(void) { - dpa400_file_type_subtype = - wtap_register_file_type_subtypes(&dpa400_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + dpa400_file_type_subtype = wtap_register_file_type_subtypes(&dpa400_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("DPA400", + dpa400_file_type_subtype); } /* diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 6023a045a34..622085ac095 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -484,9 +484,14 @@ static const struct file_type_subtype_info eyesdn_info = { void register_eyesdn(void) { - eyesdn_file_type_subtype = - wtap_register_file_type_subtypes(&eyesdn_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + eyesdn_file_type_subtype = wtap_register_file_type_subtypes(&eyesdn_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("EYESDN", + eyesdn_file_type_subtype); } /* diff --git a/wiretap/file_access.c b/wiretap/file_access.c index e4c5ec734ca..25a3b7500a2 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -15,8 +15,12 @@ #include #include +#ifdef HAVE_PLUGINS +#include +#endif #include "wtap-int.h" +#include "wtap_modules.h" #include "file_wrappers.h" #include #include "lanalyzer.h" @@ -1220,7 +1224,7 @@ wtap_fdreopen(wtap *wth, const char *filename, int *err) If we need to modify it, we allocate a GArray, copy the entries in the above table to that GArray, use the copy as the table, and make all changes to the copy. */ -static const struct file_type_subtype_info dump_open_table_base[] = { +static const struct file_type_subtype_info file_type_subtype_table_base[] = { /* WTAP_FILE_TYPE_SUBTYPE_UNKNOWN (only used internally for initialization) */ { NULL, NULL, NULL, NULL, FALSE, FALSE, 0, @@ -1293,108 +1297,125 @@ static const struct file_type_subtype_info dump_open_table_base[] = { NULL, NULL, NULL } }; +#define N_DUMP_OPEN_TABLE_BASE_ENTRIES (sizeof(file_type_subtype_table_base) / sizeof(struct file_type_subtype_info)) + /* - * Pointer to the table we're currently using. It's initialized to point - * to the static table, but, if we have to allocate the GArray, it's - * changed to point to the data in the GArray. + * Pointer to the GArray holding the registered file types. */ -static const struct file_type_subtype_info* dump_open_table = dump_open_table_base; +static GArray* file_type_subtype_table_arr; /* - * Number of elements in the table we're currently using. It's initialized - * to the number of elements in the static table, but, if we have to - * allocate the GArray, it's changed to have the size of the GArray. + * Pointer to the table of registered file types in that GArray. */ -static gint wtap_num_file_types_subtypes = sizeof(dump_open_table_base) / sizeof(struct file_type_subtype_info); +static const struct file_type_subtype_info* file_type_subtype_table; /* - * Pointer to the GArray; NULL until it's needed. + * Number of elements in the table for builtin file types/subtypes. */ -static GArray* dump_open_table_arr = NULL; +static guint wtap_num_builtin_file_types_subtypes; /* - * Create the GArray from the static table if it hasn't already been created. + * Initialize the table of file types/subtypes with all the builtin + * types/subtypes. */ -static void -init_file_types_subtypes_garray(void) +void +wtap_init_file_type_subtypes(void) { - if (dump_open_table_arr) return; + /* Don't do this twice. */ + g_assert(file_type_subtype_table_arr == NULL); - dump_open_table_arr = g_array_new(FALSE,TRUE,sizeof(struct file_type_subtype_info)); + /* + * Estimate the number of file types/subtypes as twice the + * number of modules; that's probably an overestimate, as + * the average number of file types/subtypes registered by + * a module is > 1 but probably < 2, but that shouldn't + * waste too much memory. + */ + file_type_subtype_table_arr = g_array_sized_new(FALSE, TRUE, + sizeof(struct file_type_subtype_info), wtap_module_count*2); + + /* Copy over the fixed builtin entries. */ + g_array_append_vals(file_type_subtype_table_arr, file_type_subtype_table_base, + N_DUMP_OPEN_TABLE_BASE_ENTRIES); - g_array_append_vals(dump_open_table_arr,dump_open_table_base,wtap_num_file_types_subtypes); + file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data; - dump_open_table = (const struct file_type_subtype_info*)(void *)dump_open_table_arr->data; + /* Load the builtin plugins that aren't in the table. */ + for (guint i = 0; i < wtap_module_count; i++) + wtap_module_reg[i].cb_func(); + + /* Remember which entries are builtin. */ + wtap_num_builtin_file_types_subtypes = file_type_subtype_table_arr->len; } -/* if subtype is WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, then create a new subtype as well as register it, else replace the - existing entry in that spot */ +/* + * Attempt to register a new file type/subtype; fails if a type/subtype + * with that name is already registered. + */ int -wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const int subtype) +wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi) { struct file_type_subtype_info* finfo; /* - * Check for required fields (description and name). If an existing - * file type is overridden (as opposed as creating a new registration), - * prevent internal subtypes from being overridden by Lua plugins. + * Check for required fields (description and name). */ - if (!fi || !fi->description || !fi->name || - (subtype != WTAP_FILE_TYPE_SUBTYPE_UNKNOWN && - (subtype <= (int)G_N_ELEMENTS(dump_open_table_base) || - subtype > wtap_num_file_types_subtypes))) { - g_error("no file type info or invalid file type to register"); - return subtype; - } - - /* do we want a new registration? */ - if (subtype == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN) { - /* register a new one; first verify there isn't one named this already */ - if (wtap_name_to_file_type_subtype(fi->name) > -1 ) { - g_error("file type short name \"%s\" already exists", fi->name); - return subtype; - } + if (!fi || !fi->description || !fi->name) { + g_error("no file type info"); + return -1; + } + /* + * Is this type already registered? + */ + if (wtap_name_to_file_type_subtype(fi->name) != -1) { /* - * Create the GArray if it hasn't already been created. + * Yes. You don't get to replace an existing handler. */ - init_file_types_subtypes_garray(); - - g_array_append_val(dump_open_table_arr,*fi); - - dump_open_table = (const struct file_type_subtype_info*)(void *)dump_open_table_arr->data; - - return wtap_num_file_types_subtypes++; - } - - /* re-register an existing one - verify the names do match (sanity check really) */ - if (!dump_open_table[subtype].name || strcmp(dump_open_table[subtype].name,fi->name) != 0) { - g_error("invalid file type name given to register"); - return subtype; + g_error("file type \"%s\" is already registered", fi->name); + return -1; } /* - * Create the GArray if it hasn't already been created. + * Is there a freed entry in the array, due to a file type + * being de-registered? + * + * Skip the built-in entries, as they're never deregistered + * (and because entry 0, for WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, + * has a null name pointer). */ - init_file_types_subtypes_garray(); + for (guint i = wtap_num_builtin_file_types_subtypes; + i < file_type_subtype_table_arr->len; i++) { + if (file_type_subtype_table[i].name == NULL) { + /* + * We found such an entry. + * + * Get the pointer from the GArray, so that we get a + * non-const pointer. + */ + finfo = &g_array_index(file_type_subtype_table_arr, struct file_type_subtype_info, i); + + /* + * Fill in the entry with the new values. + */ + *finfo = *fi; + + return (gint)i; + } + } /* - * Get the pointer from the GArray, so that we get a non-const - * pointer. + * There aren't any free slots, so add a new entry. + * Append this entry to the end of the array, change + * file_type_subtype_table in case the array had to get reallocated, + * increment the number of entries (XXX - just use the array + * length!), and return subtype, which is now set to the + * old number of entries, which is now the index of the new + * entry. */ - finfo = &g_array_index(dump_open_table_arr, struct file_type_subtype_info, subtype); - /*finfo->description = fi->description;*/ - /*finfo->name = fi->name;*/ - finfo->default_file_extension = fi->default_file_extension; - finfo->additional_file_extensions = fi->additional_file_extensions; - finfo->writing_must_seek = fi->writing_must_seek; - finfo->has_name_resolution = fi->has_name_resolution; - finfo->supported_comment_types = fi->supported_comment_types; - finfo->can_write_encap = fi->can_write_encap; - finfo->dump_open = fi->dump_open; - finfo->wslua_info = fi->wslua_info; - - return subtype; + g_array_append_val(file_type_subtype_table_arr,*fi); + file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data; + return file_type_subtype_table_arr->len; } /* De-registers a file writer - they can never be removed from the GArray, but we can "clear" an entry. @@ -1404,24 +1425,25 @@ wtap_deregister_file_type_subtype(const int subtype) { struct file_type_subtype_info* finfo; - if (subtype < 0 || subtype >= wtap_num_file_types_subtypes) { + if (subtype < 0 || subtype >= (int)file_type_subtype_table_arr->len) { g_error("invalid file type to de-register"); return; } - - /* - * Create the GArray if it hasn't already been created. - */ - init_file_types_subtypes_garray(); + if ((guint)subtype >= wtap_num_builtin_file_types_subtypes) { + g_error("built-in file types cannot be de-registered"); + return; + } /* * Get the pointer from the GArray, so that we get a non-const * pointer. */ - finfo = &g_array_index(dump_open_table_arr, struct file_type_subtype_info, subtype); - /* unfortunately, it's not safe to null-out the description or name; bunch of other code doesn't guard aainst that, afaict */ - /*finfo->description = NULL;*/ - /*finfo->name = NULL;*/ + finfo = &g_array_index(file_type_subtype_table_arr, struct file_type_subtype_info, subtype); + /* + * Clear out this entry. + */ + finfo->description = NULL; + finfo->name = NULL; finfo->default_file_extension = NULL; finfo->additional_file_extensions = NULL; finfo->writing_must_seek = FALSE; @@ -1432,12 +1454,6 @@ wtap_deregister_file_type_subtype(const int subtype) finfo->wslua_info = NULL; } -int -wtap_get_num_file_types_subtypes(void) -{ - return wtap_num_file_types_subtypes; -} - /* * Given a GArray of WTAP_ENCAP_ types, return the per-file encapsulation * type that would be needed to write out a file with those types. If @@ -1462,19 +1478,19 @@ wtap_dump_can_write_encap(int filetype, int encap) { int result = 0; - if (filetype < 0 || filetype >= wtap_num_file_types_subtypes - || dump_open_table[filetype].can_write_encap == NULL) + if (filetype < 0 || filetype >= (int)file_type_subtype_table_arr->len || + file_type_subtype_table[filetype].can_write_encap == NULL) return FALSE; - result = (*dump_open_table[filetype].can_write_encap)(encap); + result = (*file_type_subtype_table[filetype].can_write_encap)(encap); if (result != 0) { /* if the err said to check wslua's can_write_encap, try that */ if (result == WTAP_ERR_CHECK_WSLUA - && dump_open_table[filetype].wslua_info != NULL - && dump_open_table[filetype].wslua_info->wslua_can_write_encap != NULL) { + && file_type_subtype_table[filetype].wslua_info != NULL + && file_type_subtype_table[filetype].wslua_info->wslua_can_write_encap != NULL) { - result = (*dump_open_table[filetype].wslua_info->wslua_can_write_encap)(encap, dump_open_table[filetype].wslua_info->wslua_data); + result = (*file_type_subtype_table[filetype].wslua_info->wslua_can_write_encap)(encap, file_type_subtype_table[filetype].wslua_info->wslua_data); } @@ -1546,7 +1562,7 @@ wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types) { int ft; - for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) { + for (ft = 0; ft < (int)file_type_subtype_table_arr->len; ft++) { /* To save a file with Wiretap, Wiretap has to handle that format, * and its code to handle that format must be able to write a file * with this file's encapsulation types. @@ -1561,16 +1577,45 @@ wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types) return FALSE; } +/* + * Sort by file type/subtype name. + */ +static int +compare_file_type_subtypes_by_name(gconstpointer a, gconstpointer b) +{ + int file_type_subtype_a = *(const int *)a; + int file_type_subtype_b = *(const int *)b; + + return strcmp(wtap_file_type_subtype_name(file_type_subtype_a), + wtap_file_type_subtype_name(file_type_subtype_b)); +} + +/* + * Sort by file type/subtype description. + */ +static int +compare_file_type_subtypes_by_description(gconstpointer a, gconstpointer b) +{ + int file_type_subtype_a = *(const int *)a; + int file_type_subtype_b = *(const int *)b; + + return strcmp(wtap_file_type_subtype_description(file_type_subtype_a), + wtap_file_type_subtype_description(file_type_subtype_b)); +} + /** - * Get a GArray of WTAP_FILE_TYPE_SUBTYPE_ values for file types/subtypes + * Get a GArray of file type/subtype values for file types/subtypes * that can be used to save a file of a given type/subtype with a given * GArray of encapsulation types and the given bitmask of comment types. */ GArray * -wtap_get_savable_file_types_subtypes(int file_type_subtype, - const GArray *file_encaps, guint32 required_comment_types) +wtap_get_savable_file_types_subtypes_for_file(int file_type_subtype, + const GArray *file_encaps, guint32 required_comment_types, + ft_sort_order sort_order) { GArray *savable_file_types_subtypes; + int pcap_file_type_subtype = wtap_name_to_file_type_subtype("pcap"); + int pcapng_file_type_subtype = wtap_name_to_file_type_subtype("pcapng"); int ft; int default_file_type_subtype = -1; int other_file_type_subtype = -1; @@ -1583,7 +1628,7 @@ wtap_get_savable_file_types_subtypes(int file_type_subtype, } else { /* OK, find the first file type/subtype we *can* save it as. */ default_file_type_subtype = -1; - for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) { + for (ft = 0; ft < (int)file_type_subtype_table_arr->len; ft++) { if (wtap_dump_can_write_format(ft, file_encaps, required_comment_types)) { /* OK, got it. */ @@ -1598,34 +1643,38 @@ wtap_get_savable_file_types_subtypes(int file_type_subtype, return NULL; } - /* Allocate the array. */ - savable_file_types_subtypes = g_array_new(FALSE, FALSE, (guint)sizeof (int)); - - /* Put the default file type/subtype first in the list. */ - g_array_append_val(savable_file_types_subtypes, default_file_type_subtype); - - /* If the default is pcap, put pcapng right after it if we can - also write it in pcapng format; otherwise, if the default is - pcapng, put pcap right after it if we can also write it in - pcap format. */ - if (default_file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP) { - if (wtap_dump_can_write_format(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, file_encaps, - required_comment_types)) - other_file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAPNG; - } else if (default_file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) { - if (wtap_dump_can_write_format(WTAP_FILE_TYPE_SUBTYPE_PCAP, file_encaps, + /* + * If the default is pcap, put pcapng right after it if we can + * also write it in pcapng format; otherwise, if the default is + * pcapng, put pcap right after it if we can also write it in + * pcap format. + */ + if (default_file_type_subtype == pcap_file_type_subtype) { + if (wtap_dump_can_write_format(pcapng_file_type_subtype, + file_encaps, + required_comment_types)) + other_file_type_subtype = pcapng_file_type_subtype; + } else if (default_file_type_subtype == pcapng_file_type_subtype) { + if (wtap_dump_can_write_format(pcap_file_type_subtype, + file_encaps, required_comment_types)) - other_file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAP; + other_file_type_subtype = pcap_file_type_subtype; } - if (other_file_type_subtype != -1) - g_array_append_val(savable_file_types_subtypes, other_file_type_subtype); - /* Add all the other file types/subtypes that work. */ - for (ft = 0; ft < WTAP_NUM_FILE_TYPES_SUBTYPES; ft++) { + /* Allocate the array. */ + savable_file_types_subtypes = g_array_new(FALSE, FALSE, + sizeof (int)); + + /* + * First, add the types we don't want to force to the + * beginning of the list. + */ + for (ft = 0; ft < (int)file_type_subtype_table_arr->len; ft++) { if (ft == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN) continue; /* not a real file type */ - if (ft == default_file_type_subtype || ft == other_file_type_subtype) - continue; /* we've already done this one */ + if (ft == default_file_type_subtype || + ft == other_file_type_subtype) + continue; /* we will done this one later */ if (wtap_dump_can_write_format(ft, file_encaps, required_comment_types)) { /* OK, we can write it out in this type. */ @@ -1633,9 +1682,97 @@ wtap_get_savable_file_types_subtypes(int file_type_subtype, } } + /* Now, sort the list. */ + g_array_sort(savable_file_types_subtypes, + (sort_order == FT_SORT_BY_NAME) ? compare_file_type_subtypes_by_name : + compare_file_type_subtypes_by_description); + + /* + * If we have a type/subtype to put above the default one, + * do so. + * + * We put this type at the beginning before putting the + * default there, so the default is at the top. + */ + if (other_file_type_subtype != -1) + g_array_prepend_val(savable_file_types_subtypes, + other_file_type_subtype); + + /* Put the default file type/subtype first in the list. */ + g_array_prepend_val(savable_file_types_subtypes, + default_file_type_subtype); + return savable_file_types_subtypes; } +/** + * Get a GArray of all writable file type/subtype values. + */ +GArray * +wtap_get_writable_file_types_subtypes(ft_sort_order sort_order) +{ + GArray *writable_file_types_subtypes; + int pcap_file_type_subtype = wtap_name_to_file_type_subtype("pcap"); + int pcapng_file_type_subtype = wtap_name_to_file_type_subtype("pcapng"); + int ft; + + /* + * Allocate the array. + * Pre-allocate room enough for all types. + * XXX - that's overkill; just scan the table to find all the + * writable types and count them. + */ + writable_file_types_subtypes = g_array_sized_new(FALSE, FALSE, + sizeof (int), file_type_subtype_table_arr->len); + + /* + * First, add the types we don't want to force to the + * beginning of the list. + */ + for (ft = 0; ft < (int)file_type_subtype_table_arr->len; ft++) { + if (ft == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN) + continue; /* not a real file type */ + if (ft == pcap_file_type_subtype || + ft == pcapng_file_type_subtype) + continue; /* we've already done these two */ + if (wtap_dump_can_open(ft)) { + /* OK, we can write this type. */ + g_array_append_val(writable_file_types_subtypes, ft); + } + } + + /* Now, sort the list. */ + g_array_sort(writable_file_types_subtypes, + (sort_order == FT_SORT_BY_NAME) ? compare_file_type_subtypes_by_name : + compare_file_type_subtypes_by_description); + + /* + * Now, put pcap and pcapng at the beginning, as they're + * our "native" formats. Put pcapng there first, and + * pcap before it. + */ + if (pcapng_file_type_subtype != -1 && + wtap_dump_can_open(pcapng_file_type_subtype)) { + /* + * We can write pcapng. (If we can't, that's a huge + * mistake.) + */ + g_array_prepend_val(writable_file_types_subtypes, + pcapng_file_type_subtype); + } + if (pcap_file_type_subtype != -1 && + wtap_dump_can_open(pcap_file_type_subtype)) { + /* + * We can write pcap. (If we can't, that's a huge + * mistake.) + */ + g_array_prepend_val(writable_file_types_subtypes, + pcap_file_type_subtype); + } + + return writable_file_types_subtypes; +} + /** * Return TRUE if files of this file type/subtype use interface IDs * to associate records with an interface. @@ -1658,22 +1795,22 @@ wtap_uses_interface_ids(int file_type) const char * wtap_file_type_subtype_description(int file_type_subtype) { - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) { - g_error("Unknown capture file type %d", file_type_subtype); - /** g_error() does an abort() and thus never returns **/ - return ""; - } else - return dump_open_table[file_type_subtype].description; + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len) + return NULL; + else + return file_type_subtype_table[file_type_subtype].description; } /* Name to use in, say, a command-line flag specifying the type/subtype. */ const char * wtap_file_type_subtype_name(int file_type_subtype) { - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len) return NULL; else - return dump_open_table[file_type_subtype].name; + return file_type_subtype_table[file_type_subtype].name; } /* Translate a name to a capture file type/subtype. */ @@ -1682,32 +1819,39 @@ wtap_name_to_file_type_subtype(const char *name) { int file_type_subtype; - for (file_type_subtype = 0; file_type_subtype < wtap_num_file_types_subtypes; file_type_subtype++) { - if (dump_open_table[file_type_subtype].name != NULL && - strcmp(name, dump_open_table[file_type_subtype].name) == 0) - return file_type_subtype; - } - /* * We now call the libpcap file format just pcap, but we allow * the various variants of it to be specified using names * containing "libpcap" as well as "pcap", for backwards * compatibility. */ - if (strcmp(name, "libpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP; - else if (strcmp(name, "nseclibpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC; - else if (strcmp(name, "aixlibpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX; - else if (strcmp(name, "modlibpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029; - else if (strcmp(name, "nokialibpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA; - else if (strcmp(name, "rh6_1libpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417; - else if (strcmp(name, "suse6_3libpcap") == 0) - return WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915; + static const struct name_map { + const char *oldname; + const char *name; + } name_map[] = { + { "libpcap", "pcap" }, + { "nseclibpcap", "nsecpcap" }, + { "aixlibpcap", "aixpcap" }, + { "modlibpcap", "modpcap" }, + { "nokialibpcap", "nokiapcap" }, + { "rh6_1libpcap", "rh6_1pcap" }, + { "suse6_3libpcap", "suse6_3pcap" } + }; +#define N_NAME_MAP_ENTRIES (sizeof name_map / sizeof name_map[0]) + + for (size_t i = 0; i < N_NAME_MAP_ENTRIES; i++) { + if (strcmp(name_map[i].oldname, name) == 0) { + name = name_map[i].name; + break; + } + } + for (file_type_subtype = 0; + file_type_subtype < (int)file_type_subtype_table_arr->len; + file_type_subtype++) { + if (file_type_subtype_table[file_type_subtype].name != NULL && + strcmp(name, file_type_subtype_table[file_type_subtype].name) == 0) + return file_type_subtype; + } return -1; /* no such file type, or we can't write it */ } @@ -1724,20 +1868,20 @@ add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions, * from the list of compressed-file extensions, if there is a * default extension. */ - if (dump_open_table[file_type_subtype].default_file_extension != NULL) { + if (file_type_subtype_table[file_type_subtype].default_file_extension != NULL) { extensions = add_extensions(extensions, - dump_open_table[file_type_subtype].default_file_extension, + file_type_subtype_table[file_type_subtype].default_file_extension, compression_type_extensions); } - if (dump_open_table[file_type_subtype].additional_file_extensions != NULL) { + if (file_type_subtype_table[file_type_subtype].additional_file_extensions != NULL) { /* * We have additional extensions; add them. * * First, split the extension-list string into a set of * extensions. */ - extensions_set = g_strsplit(dump_open_table[file_type_subtype].additional_file_extensions, + extensions_set = g_strsplit(file_type_subtype_table[file_type_subtype].additional_file_extensions, ";", 0); /* @@ -1773,10 +1917,11 @@ wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed { GSList *extensions, *compression_type_extensions; - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len) return NULL; /* not a valid file type */ - if (dump_open_table[file_type_subtype].default_file_extension == NULL) + if (file_type_subtype_table[file_type_subtype].default_file_extension == NULL) return NULL; /* valid, but no extensions known */ extensions = NULL; /* empty list, to start with */ @@ -1819,7 +1964,6 @@ GSList * wtap_get_all_file_extensions_list(void) { GSList *extensions, *compression_type_extensions; - int i; extensions = NULL; /* empty list, to start with */ @@ -1828,8 +1972,8 @@ wtap_get_all_file_extensions_list(void) */ compression_type_extensions = wtap_get_all_compression_type_extensions_list(); - for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) { - extensions = add_extensions_for_file_type_subtype(i, extensions, + for (int ft = 0; ft < (int)file_type_subtype_table_arr->len; ft++) { + extensions = add_extensions_for_file_type_subtype(ft, extensions, compression_type_extensions); } @@ -1860,17 +2004,19 @@ wtap_free_extensions_list(GSList *extensions) const char * wtap_default_file_extension(int file_type_subtype) { - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len) return NULL; else - return dump_open_table[file_type_subtype].default_file_extension; + return file_type_subtype_table[file_type_subtype].default_file_extension; } gboolean wtap_dump_can_open(int file_type_subtype) { - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes - || dump_open_table[file_type_subtype].dump_open == NULL) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len || + file_type_subtype_table[file_type_subtype].dump_open == NULL) return FALSE; return TRUE; @@ -1885,8 +2031,9 @@ wtap_dump_can_compress(int file_type_subtype) * seek when writing out a file with this file type, * return FALSE. */ - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes - || dump_open_table[file_type_subtype].writing_must_seek) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len || + file_type_subtype_table[file_type_subtype].writing_must_seek) return FALSE; return TRUE; @@ -1902,8 +2049,9 @@ wtap_dump_can_compress(int file_type_subtype _U_) gboolean wtap_dump_has_name_resolution(int file_type_subtype) { - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes - || dump_open_table[file_type_subtype].has_name_resolution == FALSE) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len || + file_type_subtype_table[file_type_subtype].has_name_resolution == FALSE) return FALSE; return TRUE; @@ -1914,10 +2062,11 @@ wtap_dump_supports_comment_types(int file_type_subtype, guint32 comment_types) { guint32 supported_comment_types; - if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes) + if (file_type_subtype < 0 || + file_type_subtype >= (int)file_type_subtype_table_arr->len) return FALSE; - supported_comment_types = dump_open_table[file_type_subtype].supported_comment_types; + supported_comment_types = file_type_subtype_table[file_type_subtype].supported_comment_types; if ((comment_types & supported_comment_types) == comment_types) return TRUE; @@ -2242,13 +2391,13 @@ wtap_dump_open_check(int file_type_subtype, int encap, gboolean compressed, int /* OK, we know how to write that type; can we write the specified encapsulation type? */ - *err = (*dump_open_table[file_type_subtype].can_write_encap)(encap); + *err = (*file_type_subtype_table[file_type_subtype].can_write_encap)(encap); /* if the err said to check wslua's can_write_encap, try that */ if (*err == WTAP_ERR_CHECK_WSLUA - && dump_open_table[file_type_subtype].wslua_info != NULL - && dump_open_table[file_type_subtype].wslua_info->wslua_can_write_encap != NULL) { + && file_type_subtype_table[file_type_subtype].wslua_info != NULL + && file_type_subtype_table[file_type_subtype].wslua_info->wslua_can_write_encap != NULL) { - *err = (*dump_open_table[file_type_subtype].wslua_info->wslua_can_write_encap)(encap, dump_open_table[file_type_subtype].wslua_info->wslua_data); + *err = (*file_type_subtype_table[file_type_subtype].wslua_info->wslua_can_write_encap)(encap, file_type_subtype_table[file_type_subtype].wslua_info->wslua_data); } @@ -2309,7 +2458,7 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err, } /* If this file type requires seeking, and we can't seek, fail. */ - if (dump_open_table[file_type_subtype].writing_must_seek && cant_seek) { + if (file_type_subtype_table[file_type_subtype].writing_must_seek && cant_seek) { *err = WTAP_ERR_CANT_WRITE_TO_PIPE; return FALSE; } @@ -2317,11 +2466,11 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, int *err, /* Set wdh with wslua data if any - this is how we pass the data * to the file writer. */ - if (dump_open_table[file_type_subtype].wslua_info) - wdh->wslua_data = dump_open_table[file_type_subtype].wslua_info->wslua_data; + if (file_type_subtype_table[file_type_subtype].wslua_info) + wdh->wslua_data = file_type_subtype_table[file_type_subtype].wslua_info->wslua_data; /* Now try to open the file for writing. */ - if (!(*dump_open_table[file_type_subtype].dump_open)(wdh, err, + if (!(*file_type_subtype_table[file_type_subtype].dump_open)(wdh, err, err_info)) { return FALSE; } @@ -2432,9 +2581,10 @@ wtap_addrinfo_list_empty(addrinfo_lists_t *addrinfo_lists) gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists) { - if (!wdh || wdh->file_type_subtype < 0 || wdh->file_type_subtype >= wtap_num_file_types_subtypes - || dump_open_table[wdh->file_type_subtype].has_name_resolution == FALSE) - return FALSE; + if (!wdh || wdh->file_type_subtype < 0 || + wdh->file_type_subtype >= (int)file_type_subtype_table_arr->len || + file_type_subtype_table[wdh->file_type_subtype].has_name_resolution == FALSE) + return FALSE; wdh->addrinfo_lists = addrinfo_lists; return TRUE; } @@ -2609,6 +2759,99 @@ cleanup_open_routines(void) } } +/* + * Allow built-in file handlers (but *not* plugin file handlers!) to + * register a "backwards-compatibility" name and file type value, to + * put in the Lua wtap_filetypes table. + * + * This is only to be used as long as we have that table; new Lua + * code should use wtap_name_to_file_type_subtype() to look up + * file types by their name, just as C code should. + * + * The backwards-ccmpatibility names are the old WTAP_FILE_TYPE_SUBTYPE_ + * #define name, with WTAP_FILE_TYPE_SUBTYPE_ removed. + */ + +static GArray *backwards_compatibility_lua_names; + +void +wtap_register_backwards_compatibility_lua_name(const char *name, int ft) +{ + struct backwards_compatibiliity_lua_name entry; + + /* + * Create the table if it doesn't already exist. + * Use the same size as we do for the file type/subtype table. + */ + if (backwards_compatibility_lua_names == NULL) { + backwards_compatibility_lua_names = g_array_sized_new(FALSE, + TRUE, sizeof(struct backwards_compatibiliity_lua_name), + wtap_module_count*2); + + /* + * Extra backwards compatibility hack - add entries + * for time stamp precision values(!), as well as + * for "UNKNOWN" and types that don't yet register + * themselves. + * + * If new WS_TSPREC_ value are added, don't bother + * adding them to this table; any Lua program that + * would use them should use the wtap_tsprecs type. + * + * (Recursion: see "recursion".) + */ + wtap_register_backwards_compatibility_lua_name("TSPREC_SEC", + WTAP_TSPREC_SEC); + wtap_register_backwards_compatibility_lua_name("TSPREC_DSEC", + WTAP_TSPREC_DSEC); + wtap_register_backwards_compatibility_lua_name("TSPREC_CSEC", + WTAP_TSPREC_CSEC); + wtap_register_backwards_compatibility_lua_name("TSPREC_MSEC", + WTAP_TSPREC_MSEC); + wtap_register_backwards_compatibility_lua_name("TSPREC_USEC", + WTAP_TSPREC_USEC); + wtap_register_backwards_compatibility_lua_name("TSPREC_NSEC", + WTAP_TSPREC_NSEC); + wtap_register_backwards_compatibility_lua_name("UNKNOWN", + WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + wtap_register_backwards_compatibility_lua_name("PCAP", + WTAP_FILE_TYPE_SUBTYPE_PCAP); + wtap_register_backwards_compatibility_lua_name("PCAPNG", + WTAP_FILE_TYPE_SUBTYPE_PCAPNG); + wtap_register_backwards_compatibility_lua_name("PCAP_NSEC", + WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC); + wtap_register_backwards_compatibility_lua_name("PCAP_AIX", + WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX); + wtap_register_backwards_compatibility_lua_name("PCAP_SS991029", + WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029); + wtap_register_backwards_compatibility_lua_name("PCAP_NOKIA", + WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA); + wtap_register_backwards_compatibility_lua_name("PCAP_SS990417", + WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417); + wtap_register_backwards_compatibility_lua_name("PCAP_SS990915", + WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915); + wtap_register_backwards_compatibility_lua_name("IPTRACE_1_0", + WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0); + wtap_register_backwards_compatibility_lua_name("IPTRACE_2_0", + WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0); + wtap_register_backwards_compatibility_lua_name("BER", + WTAP_FILE_TYPE_SUBTYPE_BER); + wtap_register_backwards_compatibility_lua_name("ERF", + WTAP_FILE_TYPE_SUBTYPE_ERF); + wtap_register_backwards_compatibility_lua_name("SYSTEMD_JOURNAL", + WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL); + } + entry.name = name; + entry.ft = ft; + g_array_append_val(backwards_compatibility_lua_names, entry); +} + +const GArray * +get_backwards_compatibility_lua_table(void) +{ + return backwards_compatibility_lua_names; +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c index 2f912bae7ae..902f8df5cf1 100644 --- a/wiretap/hcidump.c +++ b/wiretap/hcidump.c @@ -130,9 +130,14 @@ static const struct file_type_subtype_info hcidump_info = { void register_hcidump(void) { - hcidump_file_type_subtype = - wtap_register_file_type_subtypes(&hcidump_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + hcidump_file_type_subtype = wtap_register_file_type_subtypes(&hcidump_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("HCIDUMP", + hcidump_file_type_subtype); } /* diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index cbfd775cf54..439e8e1a202 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -305,9 +305,14 @@ static const struct file_type_subtype_info i4btrace_info = { void register_i4btrace(void) { - i4btrace_file_type_subtype = - wtap_register_file_type_subtypes(&i4btrace_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + i4btrace_file_type_subtype = wtap_register_file_type_subtypes(&i4btrace_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("I4BTRACE", + i4btrace_file_type_subtype); } /* diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 5eb2e7a53ed..120f7521793 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -336,8 +336,14 @@ static const struct file_type_subtype_info ipfix_info = { void register_ipfix(void) { - ipfix_file_type_subtype = wtap_register_file_type_subtypes(&ipfix_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + ipfix_file_type_subtype = wtap_register_file_type_subtypes(&ipfix_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("IPFIX", + ipfix_file_type_subtype); } /* diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 56a046a9ba2..d9fce389e8f 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -1066,10 +1066,17 @@ static const struct file_type_subtype_info iseries_unicode_info = { void register_iseries(void) { - iseries_file_type_subtype = wtap_register_file_type_subtypes(&iseries_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - iseries_unicode_file_type_subtype = wtap_register_file_type_subtypes(&iseries_unicode_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + iseries_file_type_subtype = wtap_register_file_type_subtypes(&iseries_info); + iseries_unicode_file_type_subtype = wtap_register_file_type_subtypes(&iseries_unicode_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("ISERIES", + iseries_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("ISERIES_UNICODE", + iseries_unicode_file_type_subtype); } /* diff --git a/wiretap/json.c b/wiretap/json.c index 589fc06e20c..064cca584be 100644 --- a/wiretap/json.c +++ b/wiretap/json.c @@ -68,7 +68,6 @@ wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info) } static const struct file_type_subtype_info json_info = { - /* WTAP_FILE_TYPE_SUBTYPE_JSON */ "JavaScript Object Notation", "json", "json", NULL, FALSE, FALSE, 0, NULL, NULL, NULL @@ -76,8 +75,14 @@ static const struct file_type_subtype_info json_info = { void register_json(void) { - json_file_type_subtype = wtap_register_file_type_subtypes(&json_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + json_file_type_subtype = wtap_register_file_type_subtypes(&json_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("JSON", + json_file_type_subtype); } /* diff --git a/wiretap/k12.c b/wiretap/k12.c index ce65b9c86dc..2a76990fcd5 100644 --- a/wiretap/k12.c +++ b/wiretap/k12.c @@ -1401,8 +1401,14 @@ static const struct file_type_subtype_info k12_info = { void register_k12(void) { - k12_file_type_subtype = wtap_register_file_type_subtypes(&k12_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + k12_file_type_subtype = wtap_register_file_type_subtypes(&k12_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("K12", + k12_file_type_subtype); } /* diff --git a/wiretap/k12text.l b/wiretap/k12text.l index ff07a34a005..32aef082057 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -584,6 +584,12 @@ static const struct file_type_subtype_info k12text_info = { void register_k12text(void) { - k12text_file_type_subtype = wtap_register_file_type_subtypes(&k12text_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + k12text_file_type_subtype = wtap_register_file_type_subtypes(&k12text_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("K12TEXT", + k12text_file_type_subtype); } diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c index fdcffb37520..85ae5538bcd 100644 --- a/wiretap/lanalyzer.c +++ b/wiretap/lanalyzer.c @@ -972,8 +972,14 @@ static const struct file_type_subtype_info lanalyzer_info = { void register_lanalyzer(void) { - lanalyzer_file_type_subtype = wtap_register_file_type_subtypes(&lanalyzer_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + lanalyzer_file_type_subtype = wtap_register_file_type_subtypes(&lanalyzer_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("LANALYZER", + lanalyzer_file_type_subtype); } /* diff --git a/wiretap/log3gpp.c b/wiretap/log3gpp.c index aab0cc1cc1e..ba48a966a24 100644 --- a/wiretap/log3gpp.c +++ b/wiretap/log3gpp.c @@ -887,16 +887,21 @@ gboolean get_file_time_stamp(gchar* linebuff, time_t *secs, guint32 *usecs) } static const struct file_type_subtype_info log3gpp_info = { - "3GPP Log", "3gpp_log", "*.log", NULL, - TRUE, FALSE, 0, - NULL, NULL, NULL + "3GPP Log", "3gpp_log", "*.log", NULL, + TRUE, FALSE, 0, + NULL, NULL, NULL }; void register_log3gpp(void) { - log3gpp_file_type_subtype = - wtap_register_file_type_subtypes(&log3gpp_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + log3gpp_file_type_subtype = wtap_register_file_type_subtypes(&log3gpp_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("LOG_3GPP", + log3gpp_file_type_subtype); } #if 0 @@ -914,6 +919,7 @@ void wtap_register_phonelog(void) { wf_3gpp_log = wtap_register_file_type_subtypes(&fi, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); } #endif + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/wiretap/logcat.c b/wiretap/logcat.c index 66327bd0e4a..5181b9124ae 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -372,8 +372,14 @@ static const struct file_type_subtype_info logcat_info = { void register_logcat(void) { - logcat_file_type_subtype = wtap_register_file_type_subtypes(&logcat_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + logcat_file_type_subtype = wtap_register_file_type_subtypes(&logcat_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("LOGCAT", + logcat_file_type_subtype); } /* diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index de3cf22c8c8..b49eed49f8a 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -672,20 +672,32 @@ static const struct file_type_subtype_info logcat_text_long_info = { void register_logcat_text(void) { - logcat_text_brief_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_brief_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_process_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_process_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_tag_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_tag_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_thread_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_thread_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_time_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_time_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_threadtime_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_threadtime_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - logcat_text_long_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_long_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + logcat_text_brief_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_brief_info); + logcat_text_process_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_process_info); + logcat_text_tag_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_tag_info); + logcat_text_thread_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_thread_info); + logcat_text_time_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_time_info); + logcat_text_threadtime_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_threadtime_info); + logcat_text_long_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_long_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("LOGCAT_BRIEF", + logcat_text_brief_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_PROCESS", + logcat_text_process_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_TAG", + logcat_text_tag_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_THREAD", + logcat_text_thread_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_TIME", + logcat_text_time_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_THREADTIME", + logcat_text_threadtime_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("LOGCAT_LONG", + logcat_text_long_file_type_subtype); } /* diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c index 171cd3706e5..2fb42955334 100644 --- a/wiretap/mime_file.c +++ b/wiretap/mime_file.c @@ -168,16 +168,24 @@ static const struct file_type_subtype_info jpeg_jfif_info = { void register_mime(void) { - mime_file_type_subtype = - wtap_register_file_type_subtypes(&mime_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + int jpeg_jfif_file_type_subtype; + + mime_file_type_subtype = wtap_register_file_type_subtypes(&mime_info); + + /* + * Obsoleted by "mime", but we want it for the backwards- + * compatibility table for Lua. + */ + jpeg_jfif_file_type_subtype = wtap_register_file_type_subtypes(&jpeg_jfif_info); /* - * Obsoleted by "mime", so just register it; we don't - * need its return value. + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. */ - wtap_register_file_type_subtypes(&jpeg_jfif_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + wtap_register_backwards_compatibility_lua_name("MIME", + mime_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("JPEG_JFIF", + jpeg_jfif_file_type_subtype); } /* diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c index b43370bb686..c05bb684c8e 100644 --- a/wiretap/mp2t.c +++ b/wiretap/mp2t.c @@ -403,8 +403,14 @@ static const struct file_type_subtype_info mp2t_info = { void register_mp2t(void) { - mp2t_file_type_subtype = wtap_register_file_type_subtypes(&mp2t_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + mp2t_file_type_subtype = wtap_register_file_type_subtypes(&mp2t_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("MPEG_2_TS", + mp2t_file_type_subtype); } /* diff --git a/wiretap/mp4.c b/wiretap/mp4.c index 92d9e91914f..3f7e1efb517 100644 --- a/wiretap/mp4.c +++ b/wiretap/mp4.c @@ -53,7 +53,6 @@ mp4_open(wtap *wth, int *err, gchar **err_info) } static const struct file_type_subtype_info mp4_info = { - /* WTAP_FILE_TYPE_SUBTYPE_MP4 */ "MP4 media", "mp4", "mp4", NULL, FALSE, FALSE, 0, NULL, NULL, NULL @@ -61,9 +60,14 @@ static const struct file_type_subtype_info mp4_info = { void register_mp4(void) { - mp4_file_type_subtype = - wtap_register_file_type_subtypes(&mp4_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + mp4_file_type_subtype = wtap_register_file_type_subtypes(&mp4_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("MP4", + mp4_file_type_subtype); } /* diff --git a/wiretap/mpeg.c b/wiretap/mpeg.c index 366358cf4ec..f5ce370a229 100644 --- a/wiretap/mpeg.c +++ b/wiretap/mpeg.c @@ -273,9 +273,14 @@ static const struct file_type_subtype_info mpeg_info = { void register_mpeg(void) { - mpeg_file_type_subtype = - wtap_register_file_type_subtypes(&mpeg_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + mpeg_file_type_subtype = wtap_register_file_type_subtypes(&mpeg_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("MPEG", + mpeg_file_type_subtype); } /* diff --git a/wiretap/mplog.c b/wiretap/mplog.c index 08e9bf939ca..0c31c964bd5 100644 --- a/wiretap/mplog.c +++ b/wiretap/mplog.c @@ -262,8 +262,14 @@ static const struct file_type_subtype_info mplog_info = { void register_mplog(void) { - mplog_file_type_subtype = wtap_register_file_type_subtypes(&mplog_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + mplog_file_type_subtype = wtap_register_file_type_subtypes(&mplog_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("MPLOG", + mplog_file_type_subtype); } /* diff --git a/wiretap/netmon.c b/wiretap/netmon.c index 8f1c0e8652e..0b7c9d5bfde 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -1993,12 +1993,17 @@ static const struct file_type_subtype_info netmon_2_x_info = { void register_netmon(void) { - netmon_1_x_file_type_subtype = - wtap_register_file_type_subtypes(&netmon_1_x_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - netmon_2_x_file_type_subtype = - wtap_register_file_type_subtypes(&netmon_2_x_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + netmon_1_x_file_type_subtype = wtap_register_file_type_subtypes(&netmon_1_x_info); + netmon_2_x_file_type_subtype = wtap_register_file_type_subtypes(&netmon_2_x_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETMON_1_x", + netmon_1_x_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETMON_2_x", + netmon_2_x_file_type_subtype); } /* diff --git a/wiretap/netscaler.c b/wiretap/netscaler.c index 47f6a428210..4755da4a20a 100644 --- a/wiretap/netscaler.c +++ b/wiretap/netscaler.c @@ -2441,14 +2441,23 @@ static const struct file_type_subtype_info nstrace_3_5_info = { void register_netscaler(void) { - nstrace_1_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_1_0_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - nstrace_2_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_2_0_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - nstrace_3_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_3_0_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - nstrace_3_5_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_3_5_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + nstrace_1_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_1_0_info); + nstrace_2_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_2_0_info); + nstrace_3_0_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_3_0_info); + nstrace_3_5_file_type_subtype = wtap_register_file_type_subtypes(&nstrace_3_5_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETSCALER_1_0", + nstrace_1_0_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETSCALER_2_0", + nstrace_2_0_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETSCALER_3_0", + nstrace_3_0_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETSCALER_3_5", + nstrace_3_5_file_type_subtype); } /* diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index 82c74c9a0d7..597267164a5 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -458,9 +458,14 @@ static const struct file_type_subtype_info netscreen_info = { void register_netscreen(void) { - netscreen_file_type_subtype = - wtap_register_file_type_subtypes(&netscreen_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + netscreen_file_type_subtype = wtap_register_file_type_subtypes(&netscreen_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETSCREEN", + netscreen_file_type_subtype); } /* diff --git a/wiretap/nettl.c b/wiretap/nettl.c index e698b5b3b79..c9e8f6c1ed8 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -805,8 +805,14 @@ static const struct file_type_subtype_info nettl_info = { void register_nettl(void) { - nettl_file_type_subtype = wtap_register_file_type_subtypes(&nettl_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + nettl_file_type_subtype = wtap_register_file_type_subtypes(&nettl_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETTL", + nettl_file_type_subtype); } /* diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index a64162e6cdb..28312b19c79 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -832,7 +832,6 @@ nettrace_3gpp_32_423_file_open(wtap *wth, int *err, gchar **err_info) } static const struct file_type_subtype_info nettrace_3gpp_32_423_info = { - /* WTAP_FILE_TYPE_SUBTYPE_NETTRACE_3GPP_32_423 */ "3GPP TS 32.423 Trace", "3gpp32423", NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL @@ -840,9 +839,14 @@ static const struct file_type_subtype_info nettrace_3gpp_32_423_info = { void register_nettrace_3gpp_32_423(void) { - nettrace_3gpp_32_423_file_type_subtype = - wtap_register_file_type_subtypes(&nettrace_3gpp_32_423_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + nettrace_3gpp_32_423_file_type_subtype = wtap_register_file_type_subtypes(&nettrace_3gpp_32_423_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETTRACE_3GPP_32_423", + nettrace_3gpp_32_423_file_type_subtype); } /* diff --git a/wiretap/network_instruments.c b/wiretap/network_instruments.c index 21067543277..41947c2b9b3 100644 --- a/wiretap/network_instruments.c +++ b/wiretap/network_instruments.c @@ -888,8 +888,14 @@ static const struct file_type_subtype_info network_instruments_info = { void register_network_instruments(void) { - network_instruments_file_type_subtype = wtap_register_file_type_subtypes(&network_instruments_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + network_instruments_file_type_subtype = wtap_register_file_type_subtypes(&network_instruments_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETWORK_INSTRUMENTS", + network_instruments_file_type_subtype); } /* diff --git a/wiretap/netxray.c b/wiretap/netxray.c index 447698d7b40..ff3b094379c 100644 --- a/wiretap/netxray.c +++ b/wiretap/netxray.c @@ -2121,18 +2121,23 @@ static const struct file_type_subtype_info netxray_2_00x_info = { void register_netxray(void) { - netxray_old_file_type_subtype = - wtap_register_file_type_subtypes(&netxray_old_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - netxray_1_0_file_type_subtype = - wtap_register_file_type_subtypes(&netxray_1_0_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - netxray_1_1_file_type_subtype = - wtap_register_file_type_subtypes(&netxray_1_1_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - netxray_2_00x_file_type_subtype = - wtap_register_file_type_subtypes(&netxray_2_00x_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + netxray_old_file_type_subtype = wtap_register_file_type_subtypes(&netxray_old_info); + netxray_1_0_file_type_subtype = wtap_register_file_type_subtypes(&netxray_1_0_info); + netxray_1_1_file_type_subtype = wtap_register_file_type_subtypes(&netxray_1_1_info); + netxray_2_00x_file_type_subtype = wtap_register_file_type_subtypes(&netxray_2_00x_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NETXRAY_OLD", + netxray_old_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETXRAY_1_0", + netxray_1_0_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETXRAY_1_1", + netxray_1_1_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NETXRAY_2_00x", + netxray_2_00x_file_type_subtype); } /* diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index efb3dbfb06e..ae1602089fe 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -2856,12 +2856,17 @@ static const struct file_type_subtype_info ngsniffer_compressed_info = { void register_ngsniffer(void) { - ngsniffer_uncompressed_file_type_subtype = - wtap_register_file_type_subtypes(&ngsniffer_uncompressed_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - ngsniffer_compressed_file_type_subtype = - wtap_register_file_type_subtypes(&ngsniffer_compressed_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + ngsniffer_uncompressed_file_type_subtype = wtap_register_file_type_subtypes(&ngsniffer_uncompressed_info); + ngsniffer_compressed_file_type_subtype = wtap_register_file_type_subtypes(&ngsniffer_compressed_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("NGSNIFFER_UNCOMPRESSED", + ngsniffer_uncompressed_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("NGSNIFFER_COMPRESSED", + ngsniffer_compressed_file_type_subtype); } /* diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c index 43c35e97d32..d9cad3d2521 100644 --- a/wiretap/packetlogger.c +++ b/wiretap/packetlogger.c @@ -385,9 +385,14 @@ static const struct file_type_subtype_info packetlogger_info = { void register_packetlogger(void) { - packetlogger_file_type_subtype = - wtap_register_file_type_subtypes(&packetlogger_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + packetlogger_file_type_subtype = wtap_register_file_type_subtypes(&packetlogger_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("PACKETLOGGER", + packetlogger_file_type_subtype); } /* diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 4e6fa88dc91..c1642646121 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -676,12 +676,17 @@ static const struct file_type_subtype_info peekclassic_v7_info = { void register_peekclassic(void) { - peekclassic_v56_file_type_subtype = - wtap_register_file_type_subtypes(&peekclassic_v56_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - peekclassic_v7_file_type_subtype = - wtap_register_file_type_subtypes(&peekclassic_v7_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + peekclassic_v56_file_type_subtype = wtap_register_file_type_subtypes(&peekclassic_v56_info); + peekclassic_v7_file_type_subtype = wtap_register_file_type_subtypes(&peekclassic_v7_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("PEEKCLASSIC_V56", + peekclassic_v56_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("PEEKCLASSIC_V7", + peekclassic_v7_file_type_subtype); } /* diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c index 68ad7f1d97b..99de82ddd02 100644 --- a/wiretap/peektagged.c +++ b/wiretap/peektagged.c @@ -893,8 +893,14 @@ static const struct file_type_subtype_info peektagged_info = { void register_peektagged(void) { - peektagged_file_type_subtype = wtap_register_file_type_subtypes(&peektagged_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + peektagged_file_type_subtype = wtap_register_file_type_subtypes(&peektagged_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("PEEKTAGGED", + peektagged_file_type_subtype); } /* diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 3f1e5268c9a..aaf7f7e4be7 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -804,9 +804,14 @@ static const struct file_type_subtype_info pppdump_info = { void register_pppdump(void) { - pppdump_file_type_subtype = - wtap_register_file_type_subtypes(&pppdump_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + pppdump_file_type_subtype = wtap_register_file_type_subtypes(&pppdump_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("PPPDUMP", + pppdump_file_type_subtype); } /* diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 655ecc53810..8ad81e66e69 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -380,9 +380,14 @@ static const struct file_type_subtype_info radcom_info = { void register_radcom(void) { - radcom_file_type_subtype = - wtap_register_file_type_subtypes(&radcom_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + radcom_file_type_subtype = wtap_register_file_type_subtypes(&radcom_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("RADCOM", + radcom_file_type_subtype); } /* diff --git a/wiretap/rfc7468.c b/wiretap/rfc7468.c index 78df9c5af05..54355878894 100644 --- a/wiretap/rfc7468.c +++ b/wiretap/rfc7468.c @@ -107,8 +107,14 @@ static const struct file_type_subtype_info rfc7468_info = { void register_rfc7468(void) { - rfc7468_file_type_subtype = wtap_register_file_type_subtypes(&rfc7468_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + rfc7468_file_type_subtype = wtap_register_file_type_subtypes(&rfc7468_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("RFC7468", + rfc7468_file_type_subtype); } /* diff --git a/wiretap/ruby_marshal.c b/wiretap/ruby_marshal.c index 72e661a1f87..a57eb2b2d07 100644 --- a/wiretap/ruby_marshal.c +++ b/wiretap/ruby_marshal.c @@ -92,8 +92,14 @@ static const struct file_type_subtype_info ruby_marshal_info = { void register_ruby_marshal(void) { - ruby_marshal_file_type_subtype = wtap_register_file_type_subtypes(&ruby_marshal_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + ruby_marshal_file_type_subtype = wtap_register_file_type_subtypes(&ruby_marshal_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("RUBY_MARSHAL", + ruby_marshal_file_type_subtype); } /* diff --git a/wiretap/snoop.c b/wiretap/snoop.c index e1a33ba9f7f..6fa7ac9cd7f 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -931,12 +931,17 @@ static const struct file_type_subtype_info shomiti_info = { void register_snoop(void) { - snoop_file_type_subtype = - wtap_register_file_type_subtypes(&snoop_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - shomiti_file_type_subtype = - wtap_register_file_type_subtypes(&shomiti_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + snoop_file_type_subtype = wtap_register_file_type_subtypes(&snoop_info); + shomiti_file_type_subtype = wtap_register_file_type_subtypes(&shomiti_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("SNOOP", + snoop_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("SHOMITI", + shomiti_file_type_subtype); } /* diff --git a/wiretap/stanag4607.c b/wiretap/stanag4607.c index 7766c33f9cf..f1662680ce2 100644 --- a/wiretap/stanag4607.c +++ b/wiretap/stanag4607.c @@ -216,8 +216,14 @@ static const struct file_type_subtype_info stanag4607_info = { void register_stanag4607(void) { - stanag4607_file_type_subtype = wtap_register_file_type_subtypes(&stanag4607_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + stanag4607_file_type_subtype = wtap_register_file_type_subtypes(&stanag4607_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("STANAG_4607", + stanag4607_file_type_subtype); } /* diff --git a/wiretap/tnef.c b/wiretap/tnef.c index c69e669852c..593fe09ced7 100644 --- a/wiretap/tnef.c +++ b/wiretap/tnef.c @@ -52,8 +52,14 @@ static const struct file_type_subtype_info tnef_info = { void register_tnef(void) { - tnef_file_type_subtype = wtap_register_file_type_subtypes(&tnef_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + tnef_file_type_subtype = wtap_register_file_type_subtypes(&tnef_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("TNEF", + tnef_file_type_subtype); } /* diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index abdaec9ba8d..844457286c6 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -437,9 +437,14 @@ static const struct file_type_subtype_info toshiba_info = { void register_toshiba(void) { - toshiba_file_type_subtype = - wtap_register_file_type_subtypes(&toshiba_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + toshiba_file_type_subtype = wtap_register_file_type_subtypes(&toshiba_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("TOSHIBA", + toshiba_file_type_subtype); } /* diff --git a/wiretap/visual.c b/wiretap/visual.c index 9440a52a0e8..9dfaab7bedd 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -869,8 +869,14 @@ static const struct file_type_subtype_info visual_info = { void register_visual(void) { - visual_file_type_subtype = wtap_register_file_type_subtypes(&visual_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + visual_file_type_subtype = wtap_register_file_type_subtypes(&visual_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("VISUAL_NETWORKS", + visual_file_type_subtype); } /* diff --git a/wiretap/vms.c b/wiretap/vms.c index b77aa8e467b..b1b157f5390 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -536,8 +536,14 @@ static const struct file_type_subtype_info vms_info = { void register_vms(void) { - vms_file_type_subtype = wtap_register_file_type_subtypes(&vms_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + vms_file_type_subtype = wtap_register_file_type_subtypes(&vms_info); + + /* + * Register name for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("VMS", + vms_file_type_subtype); } /* diff --git a/wiretap/vwr.c b/wiretap/vwr.c index aec1f7c3c83..9744a8c5eb3 100644 --- a/wiretap/vwr.c +++ b/wiretap/vwr.c @@ -3384,10 +3384,17 @@ static const struct file_type_subtype_info vwr_eth_info = { void register_vwr(void) { - vwr_80211_file_type_subtype = wtap_register_file_type_subtypes(&vwr_80211_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); - vwr_eth_file_type_subtype = wtap_register_file_type_subtypes(&vwr_eth_info, - WTAP_FILE_TYPE_SUBTYPE_UNKNOWN); + vwr_80211_file_type_subtype = wtap_register_file_type_subtypes(&vwr_80211_info); + vwr_eth_file_type_subtype = wtap_register_file_type_subtypes(&vwr_eth_info); + + /* + * Register names for backwards compatibility with the + * wtap_filetypes table in Lua. + */ + wtap_register_backwards_compatibility_lua_name("VWR_80211", + vwr_80211_file_type_subtype); + wtap_register_backwards_compatibility_lua_name("VWR_ETH", + vwr_eth_file_type_subtype); } /* diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 51006647398..8af29422b2a 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -23,6 +23,8 @@ #define wtap_warn(...) g_warning(__VA_ARGS__) +void wtap_init_file_type_subtypes(void); + WS_DLL_PUBLIC int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err); @@ -345,6 +347,18 @@ wtap_add_idb(wtap *wth, wtap_block_t idb); */ void wtapng_process_dsb(wtap *wth, wtap_block_t dsb); + +void +wtap_register_backwards_compatibility_lua_name(const char *name, int ft); + +struct backwards_compatibiliity_lua_name { + const char *name; + int ft; +}; + +WS_DLL_PUBLIC +const GArray *get_backwards_compatibility_lua_table(void); + #endif /* __WTAP_INT_H__ */ /* diff --git a/wiretap/wtap.c b/wiretap/wtap.c index cac93c29782..f1d8868bf7a 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -15,7 +15,6 @@ #include "wtap-int.h" #include "wtap_opttypes.h" -#include "wtap_modules.h" #include "pcapng.h" #include "file_wrappers.h" @@ -1807,8 +1806,7 @@ wtap_init(gboolean load_wiretap_plugins) init_open_routines(); wtap_opttypes_initialize(); wtap_init_encap_types(); - for (gulong i = 0; i < wtap_module_count; i++) - wtap_module_reg[i].cb_func(); + wtap_init_file_type_subtypes(); if (load_wiretap_plugins) { #ifdef HAVE_PLUGINS libwiretap_plugins = plugins_init(WS_PLUGIN_WIRETAP); diff --git a/wiretap/wtap.h b/wiretap/wtap.h index b9ea9bc944e..2a0ecfb4f89 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -315,8 +315,6 @@ extern "C" { #define WTAP_FILE_TYPE_SUBTYPE_ERF 12 #define WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL 13 -#define WTAP_NUM_FILE_TYPES_SUBTYPES wtap_get_num_file_types_subtypes() - /* timestamp precision (currently only these values are supported) */ #define WTAP_TSPREC_UNKNOWN -2 #define WTAP_TSPREC_PER_PACKET -1 /* as a per-file value, means per-packet */ @@ -2134,14 +2132,29 @@ gboolean wtap_dump_close(wtap_dumper *wdh, int *err, gchar **err_info); WS_DLL_PUBLIC gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types); +/* + * Sort the file types by name or by description? + */ +typedef enum { + FT_SORT_BY_NAME, + FT_SORT_BY_DESCRIPTION +} ft_sort_order; + /** - * Get a GArray of WTAP_FILE_TYPE_SUBTYPE_ values for file types/subtypes + * Get a GArray of file type/subtype values for file types/subtypes * that can be used to save a file of a given type with a given GArray of * WTAP_ENCAP_ types and the given bitmask of comment types. */ WS_DLL_PUBLIC -GArray *wtap_get_savable_file_types_subtypes(int file_type, - const GArray *file_encaps, guint32 required_comment_types); +GArray *wtap_get_savable_file_types_subtypes_for_file(int file_type, + const GArray *file_encaps, guint32 required_comment_types, + ft_sort_order sort_order); + +/** + * Get a GArray of all writable file type/subtype values. + */ +WS_DLL_PUBLIC +GArray *wtap_get_writable_file_types_subtypes(ft_sort_order sort_order); /** * Return TRUE if files of this file type/subtype use interface IDs @@ -2188,8 +2201,6 @@ WS_DLL_PUBLIC int wtap_get_num_file_type_extensions(void); WS_DLL_PUBLIC int wtap_get_num_encap_types(void); -WS_DLL_PUBLIC -int wtap_get_num_file_types_subtypes(void); /*** get information for file type extension ***/ WS_DLL_PUBLIC @@ -2226,7 +2237,7 @@ void wtap_deregister_open_info(const gchar *name); WS_DLL_PUBLIC unsigned int open_info_name_to_type(const char *name); WS_DLL_PUBLIC -int wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const int subtype); +int wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi); WS_DLL_PUBLIC void wtap_deregister_file_type_subtype(const int file_type_subtype); diff --git a/wiretap/wtap_modules.h b/wiretap/wtap_modules.h index 80bb7f36723..38114debcbf 100644 --- a/wiretap/wtap_modules.h +++ b/wiretap/wtap_modules.h @@ -28,7 +28,7 @@ typedef struct _wtap_module_reg { extern wtap_module_reg_t wtap_module_reg[]; -extern const gulong wtap_module_count; +extern const guint wtap_module_count; #ifdef __cplusplus }