From a36bf0f10ec63936325e1d5e02bc09a28c17c549 Mon Sep 17 00:00:00 2001 From: Kaian Date: Fri, 11 Oct 2019 12:20:27 +0200 Subject: [PATCH] parser: move all packet parser related files --- CMakeLists.txt | 20 ++++++++++---------- src/capture/capture_hep.c | 8 ++++---- src/capture/capture_pcap.c | 10 +--------- src/capture/capture_pcap.h | 6 ------ src/capture/capture_txt.c | 2 +- src/main.c | 2 +- src/ncurses/manager.c | 2 +- src/ncurses/windows/auth_validate_win.c | 2 +- src/ncurses/windows/call_flow_win.c | 4 ++-- src/ncurses/windows/call_raw_win.c | 2 +- src/ncurses/windows/filter_win.c | 2 +- src/ncurses/windows/save_win.c | 2 +- src/ncurses/windows/stats_win.c | 2 +- src/parser/packet.c | 14 ++++++++++---- src/parser/packet.h | 6 ++++++ src/parser/{dissectors => }/packet_hep.c | 0 src/parser/{dissectors => }/packet_hep.h | 0 src/parser/{dissectors => }/packet_ip.c | 0 src/parser/{dissectors => }/packet_ip.h | 0 src/parser/{dissectors => }/packet_link.c | 0 src/parser/{dissectors => }/packet_link.h | 0 src/parser/{dissectors => }/packet_rtcp.c | 0 src/parser/{dissectors => }/packet_rtcp.h | 0 src/parser/{dissectors => }/packet_rtp.c | 0 src/parser/{dissectors => }/packet_rtp.h | 0 src/parser/{dissectors => }/packet_sdp.c | 0 src/parser/{dissectors => }/packet_sdp.h | 0 src/parser/{dissectors => }/packet_sip.c | 0 src/parser/{dissectors => }/packet_sip.h | 0 src/parser/{dissectors => }/packet_tcp.c | 0 src/parser/{dissectors => }/packet_tcp.h | 0 src/parser/{dissectors => }/packet_tls.c | 0 src/parser/{dissectors => }/packet_tls.h | 0 src/parser/{dissectors => }/packet_udp.c | 0 src/parser/{dissectors => }/packet_udp.h | 0 src/parser/{dissectors => }/packet_ws.c | 0 src/parser/{dissectors => }/packet_ws.h | 0 src/parser/parser.c | 20 ++++++++++---------- src/storage/attribute.c | 2 +- src/storage/call.c | 2 +- src/storage/datetime.c | 6 ------ src/storage/datetime.h | 10 ---------- src/storage/message.c | 4 ++-- src/storage/message.h | 2 +- src/storage/storage.c | 2 +- src/storage/stream.h | 6 +++--- valgrind.supp | 12 ++++++++++++ 47 files changed, 72 insertions(+), 78 deletions(-) rename src/parser/{dissectors => }/packet_hep.c (100%) rename src/parser/{dissectors => }/packet_hep.h (100%) rename src/parser/{dissectors => }/packet_ip.c (100%) rename src/parser/{dissectors => }/packet_ip.h (100%) rename src/parser/{dissectors => }/packet_link.c (100%) rename src/parser/{dissectors => }/packet_link.h (100%) rename src/parser/{dissectors => }/packet_rtcp.c (100%) rename src/parser/{dissectors => }/packet_rtcp.h (100%) rename src/parser/{dissectors => }/packet_rtp.c (100%) rename src/parser/{dissectors => }/packet_rtp.h (100%) rename src/parser/{dissectors => }/packet_sdp.c (100%) rename src/parser/{dissectors => }/packet_sdp.h (100%) rename src/parser/{dissectors => }/packet_sip.c (100%) rename src/parser/{dissectors => }/packet_sip.h (100%) rename src/parser/{dissectors => }/packet_tcp.c (100%) rename src/parser/{dissectors => }/packet_tcp.h (100%) rename src/parser/{dissectors => }/packet_tls.c (100%) rename src/parser/{dissectors => }/packet_tls.h (100%) rename src/parser/{dissectors => }/packet_udp.c (100%) rename src/parser/{dissectors => }/packet_udp.h (100%) rename src/parser/{dissectors => }/packet_ws.c (100%) rename src/parser/{dissectors => }/packet_ws.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0333aaa..1e8d70d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,14 +50,14 @@ set(SOURCES src/parser/address.c src/parser/packet.c src/parser/parser.c - src/parser/dissectors/packet_link.c - src/parser/dissectors/packet_ip.c - src/parser/dissectors/packet_tcp.c - src/parser/dissectors/packet_udp.c - src/parser/dissectors/packet_sip.c - src/parser/dissectors/packet_sdp.c - src/parser/dissectors/packet_rtp.c - src/parser/dissectors/packet_rtcp.c + src/parser/packet_link.c + src/parser/packet_ip.c + src/parser/packet_tcp.c + src/parser/packet_udp.c + src/parser/packet_sip.c + src/parser/packet_sdp.c + src/parser/packet_rtp.c + src/parser/packet_rtcp.c src/storage/filter.c src/storage/group.c src/storage/stream.c @@ -75,7 +75,7 @@ set(SOURCES option(USE_HEP "Enable HEP/EEP Support" OFF) if (USE_HEP) set(SOURCES ${SOURCES} src/capture/capture_hep.c) - set(SOURCES ${SOURCES} src/parser/dissectors/packet_hep.c) + set(SOURCES ${SOURCES} src/parser/packet_hep.c) endif (USE_HEP) # IPv6 Support @@ -84,7 +84,7 @@ option(USE_IPV6 "Enable IPv6 Support" OFF) # GnuTLS Support option(WITH_SSL "Enable SSL Support (TLS SIP Transport)" OFF) if (WITH_SSL) - set(SOURCES ${SOURCES} src/parser/dissectors/packet_tls.c) + set(SOURCES ${SOURCES} src/parser/packet_tls.c) endif (WITH_SSL) # libsnd Support diff --git a/src/capture/capture_hep.c b/src/capture/capture_hep.c index 855a7fc..edcbafe 100644 --- a/src/capture/capture_hep.c +++ b/src/capture/capture_hep.c @@ -51,10 +51,10 @@ #include "storage/datetime.h" #include "setting.h" #include "glib/glib-extra.h" -#include "parser/dissectors/packet_hep.h" -#include "parser/dissectors/packet_ip.h" -#include "parser/dissectors/packet_udp.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_hep.h" +#include "parser/packet_ip.h" +#include "parser/packet_udp.h" +#include "parser/packet_sip.h" #include "parser/packet.h" #include "capture_hep.h" diff --git a/src/capture/capture_pcap.c b/src/capture/capture_pcap.c index d237f7e..2fca81f 100644 --- a/src/capture/capture_pcap.c +++ b/src/capture/capture_pcap.c @@ -34,13 +34,11 @@ #include #include #include -#include #include #include "glib/glib-extra.h" #include "capture.h" -#include "capture_hep.h" #include "capture_pcap.h" -#include "parser/dissectors/packet_link.h" +#include "parser/packet_link.h" #include "storage/storage.h" #include "storage/stream.h" #include "setting.h" @@ -451,12 +449,6 @@ capture_pcap_parse_packet(u_char *info, const struct pcap_pkthdr *header, const g_byte_array_unref(data); } -gint -capture_packet_time_sorter(const Packet **a, const Packet **b) -{ - return date_time_is_older(packet_time(*a), packet_time(*b)); -} - const gchar * capture_input_pcap_file(CaptureManager *manager) { diff --git a/src/capture/capture_pcap.h b/src/capture/capture_pcap.h index 352274b..72c48b2 100644 --- a/src/capture/capture_pcap.h +++ b/src/capture/capture_pcap.h @@ -178,12 +178,6 @@ capture_output_pcap(const gchar *filename, GError **error); void capture_pcap_parse_packet(u_char *input, const struct pcap_pkthdr *header, const guchar *content); -/** - * @brief Sorter by time for captured packets - */ -gint -capture_packet_time_sorter(const Packet **a, const Packet **b); - /** * @brief Get Input file from Offline mode * diff --git a/src/capture/capture_txt.c b/src/capture/capture_txt.c index e7cfa4c..39e9751 100644 --- a/src/capture/capture_txt.c +++ b/src/capture/capture_txt.c @@ -34,7 +34,7 @@ #include #include "storage/datetime.h" #include "parser/packet.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "capture/capture_txt.h" GQuark diff --git a/src/main.c b/src/main.c index 8ada0cb..7e03b1e 100644 --- a/src/main.c +++ b/src/main.c @@ -36,7 +36,7 @@ #include "capture/capture_hep.h" #endif #ifdef WITH_SSL -#include "parser/dissectors/packet_tls.h" +#include "parser/packet_tls.h" #endif void diff --git a/src/ncurses/manager.c b/src/ncurses/manager.c index 3dc6969..8b497f3 100644 --- a/src/ncurses/manager.c +++ b/src/ncurses/manager.c @@ -40,7 +40,7 @@ #include "setting.h" #include "manager.h" #include "capture/capture.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "ncurses/windows/auth_validate_win.h" #include "ncurses/windows/call_list_win.h" #include "ncurses/windows/call_flow_win.h" diff --git a/src/ncurses/windows/auth_validate_win.c b/src/ncurses/windows/auth_validate_win.c index 6f352e8..7184989 100644 --- a/src/ncurses/windows/auth_validate_win.c +++ b/src/ncurses/windows/auth_validate_win.c @@ -28,7 +28,7 @@ #include "config.h" #include #include -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "ncurses/dialog.h" #include "auth_validate_win.h" diff --git a/src/ncurses/windows/call_flow_win.c b/src/ncurses/windows/call_flow_win.c index 6324cc5..8e31c49 100644 --- a/src/ncurses/windows/call_flow_win.c +++ b/src/ncurses/windows/call_flow_win.c @@ -29,7 +29,7 @@ #include "config.h" #include #include -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "capture/capture_pcap.h" #include "ncurses/manager.h" #include "ncurses/dialog.h" @@ -150,7 +150,7 @@ call_flow_arrow_time(const CallFlowArrow *arrow) static gint call_flow_arrow_time_sorter(const CallFlowArrow **a, const CallFlowArrow **b) { - return date_time_is_older(call_flow_arrow_time(*a), call_flow_arrow_time(*b)); + return g_date_time_compare(call_flow_arrow_time(*a), call_flow_arrow_time(*b)); } /** diff --git a/src/ncurses/windows/call_raw_win.c b/src/ncurses/windows/call_raw_win.c index 83268d9..142afa3 100644 --- a/src/ncurses/windows/call_raw_win.c +++ b/src/ncurses/windows/call_raw_win.c @@ -33,7 +33,7 @@ #include "config.h" #include #include -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "ncurses/manager.h" #include "ncurses/dialog.h" #include "ncurses/windows/save_win.h" diff --git a/src/ncurses/windows/filter_win.c b/src/ncurses/windows/filter_win.c index 051fcaf..e2576e1 100644 --- a/src/ncurses/windows/filter_win.c +++ b/src/ncurses/windows/filter_win.c @@ -30,7 +30,7 @@ #include #include #include -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "ncurses/manager.h" #include "filter_win.h" #include "call_list_win.h" diff --git a/src/ncurses/windows/save_win.c b/src/ncurses/windows/save_win.c index aa25e20..909babe 100644 --- a/src/ncurses/windows/save_win.c +++ b/src/ncurses/windows/save_win.c @@ -399,7 +399,7 @@ save_to_file(Window *window) } } - g_ptr_array_sort(packets, (GCompareFunc) capture_packet_time_sorter); + g_ptr_array_sort(packets, (GCompareFunc) packet_time_sorter); g_ptr_array_foreach(packets, (GFunc) save_packet_cb, output); dialog_progress_destroy(progress); diff --git a/src/ncurses/windows/stats_win.c b/src/ncurses/windows/stats_win.c index 68ab5a3..e300b60 100644 --- a/src/ncurses/windows/stats_win.c +++ b/src/ncurses/windows/stats_win.c @@ -58,7 +58,7 @@ #include #include "glib/glib-extra.h" #include "storage/storage.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "stats_win.h" Window * diff --git a/src/parser/packet.c b/src/parser/packet.c index d811807..78da7a6 100644 --- a/src/parser/packet.c +++ b/src/parser/packet.c @@ -29,10 +29,10 @@ #include "config.h" #include #include "glib/glib-extra.h" -#include "parser/dissectors/packet_ip.h" -#include "parser/dissectors/packet_tcp.h" -#include "parser/dissectors/packet_udp.h" -#include "parser/dissectors/packet_sip.h" +#include "packet_ip.h" +#include "packet_tcp.h" +#include "packet_udp.h" +#include "packet_sip.h" #include "capture/capture_pcap.h" #include "packet.h" @@ -185,6 +185,12 @@ packet_time(const Packet *packet) return ts; } +gint +packet_time_sorter(const Packet **a, const Packet **b) +{ + return g_date_time_compare(packet_time(*a), packet_time(*b)); +} + void packet_frame_free(PacketFrame *frame) { diff --git a/src/parser/packet.h b/src/parser/packet.h index 019c1b4..1ce55fa 100644 --- a/src/parser/packet.h +++ b/src/parser/packet.h @@ -152,6 +152,12 @@ packet_transport(Packet *packet); GDateTime * packet_time(const Packet *packet); +/** + * @brief Sorter by time for captured packets + */ +gint +packet_time_sorter(const Packet **a, const Packet **b); + /** * @brief Free allocated memory in Packet frame * @param frame Frame pointer to be free'd diff --git a/src/parser/dissectors/packet_hep.c b/src/parser/packet_hep.c similarity index 100% rename from src/parser/dissectors/packet_hep.c rename to src/parser/packet_hep.c diff --git a/src/parser/dissectors/packet_hep.h b/src/parser/packet_hep.h similarity index 100% rename from src/parser/dissectors/packet_hep.h rename to src/parser/packet_hep.h diff --git a/src/parser/dissectors/packet_ip.c b/src/parser/packet_ip.c similarity index 100% rename from src/parser/dissectors/packet_ip.c rename to src/parser/packet_ip.c diff --git a/src/parser/dissectors/packet_ip.h b/src/parser/packet_ip.h similarity index 100% rename from src/parser/dissectors/packet_ip.h rename to src/parser/packet_ip.h diff --git a/src/parser/dissectors/packet_link.c b/src/parser/packet_link.c similarity index 100% rename from src/parser/dissectors/packet_link.c rename to src/parser/packet_link.c diff --git a/src/parser/dissectors/packet_link.h b/src/parser/packet_link.h similarity index 100% rename from src/parser/dissectors/packet_link.h rename to src/parser/packet_link.h diff --git a/src/parser/dissectors/packet_rtcp.c b/src/parser/packet_rtcp.c similarity index 100% rename from src/parser/dissectors/packet_rtcp.c rename to src/parser/packet_rtcp.c diff --git a/src/parser/dissectors/packet_rtcp.h b/src/parser/packet_rtcp.h similarity index 100% rename from src/parser/dissectors/packet_rtcp.h rename to src/parser/packet_rtcp.h diff --git a/src/parser/dissectors/packet_rtp.c b/src/parser/packet_rtp.c similarity index 100% rename from src/parser/dissectors/packet_rtp.c rename to src/parser/packet_rtp.c diff --git a/src/parser/dissectors/packet_rtp.h b/src/parser/packet_rtp.h similarity index 100% rename from src/parser/dissectors/packet_rtp.h rename to src/parser/packet_rtp.h diff --git a/src/parser/dissectors/packet_sdp.c b/src/parser/packet_sdp.c similarity index 100% rename from src/parser/dissectors/packet_sdp.c rename to src/parser/packet_sdp.c diff --git a/src/parser/dissectors/packet_sdp.h b/src/parser/packet_sdp.h similarity index 100% rename from src/parser/dissectors/packet_sdp.h rename to src/parser/packet_sdp.h diff --git a/src/parser/dissectors/packet_sip.c b/src/parser/packet_sip.c similarity index 100% rename from src/parser/dissectors/packet_sip.c rename to src/parser/packet_sip.c diff --git a/src/parser/dissectors/packet_sip.h b/src/parser/packet_sip.h similarity index 100% rename from src/parser/dissectors/packet_sip.h rename to src/parser/packet_sip.h diff --git a/src/parser/dissectors/packet_tcp.c b/src/parser/packet_tcp.c similarity index 100% rename from src/parser/dissectors/packet_tcp.c rename to src/parser/packet_tcp.c diff --git a/src/parser/dissectors/packet_tcp.h b/src/parser/packet_tcp.h similarity index 100% rename from src/parser/dissectors/packet_tcp.h rename to src/parser/packet_tcp.h diff --git a/src/parser/dissectors/packet_tls.c b/src/parser/packet_tls.c similarity index 100% rename from src/parser/dissectors/packet_tls.c rename to src/parser/packet_tls.c diff --git a/src/parser/dissectors/packet_tls.h b/src/parser/packet_tls.h similarity index 100% rename from src/parser/dissectors/packet_tls.h rename to src/parser/packet_tls.h diff --git a/src/parser/dissectors/packet_udp.c b/src/parser/packet_udp.c similarity index 100% rename from src/parser/dissectors/packet_udp.c rename to src/parser/packet_udp.c diff --git a/src/parser/dissectors/packet_udp.h b/src/parser/packet_udp.h similarity index 100% rename from src/parser/dissectors/packet_udp.h rename to src/parser/packet_udp.h diff --git a/src/parser/dissectors/packet_ws.c b/src/parser/packet_ws.c similarity index 100% rename from src/parser/dissectors/packet_ws.c rename to src/parser/packet_ws.c diff --git a/src/parser/dissectors/packet_ws.h b/src/parser/packet_ws.h similarity index 100% rename from src/parser/dissectors/packet_ws.h rename to src/parser/packet_ws.h diff --git a/src/parser/parser.c b/src/parser/parser.c index cb91aee..81ab9c2 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -31,19 +31,19 @@ #include #include "setting.h" #include "glib/glib-extra.h" -#include "parser/dissectors/packet_link.h" -#include "parser/dissectors/packet_ip.h" -#include "parser/dissectors/packet_udp.h" -#include "parser/dissectors/packet_tcp.h" -#include "parser/dissectors/packet_sip.h" -#include "parser/dissectors/packet_sdp.h" -#include "parser/dissectors/packet_rtp.h" -#include "parser/dissectors/packet_rtcp.h" +#include "packet_link.h" +#include "packet_ip.h" +#include "packet_udp.h" +#include "packet_tcp.h" +#include "packet_sip.h" +#include "packet_sdp.h" +#include "packet_rtp.h" +#include "packet_rtcp.h" #ifdef WITH_SSL -#include "parser/dissectors/packet_tls.h" +#include "packet_tls.h" #endif #ifdef USE_HEP -#include "parser/dissectors/packet_hep.h" +#include "packet_hep.h" #endif #include "parser.h" diff --git a/src/storage/attribute.c b/src/storage/attribute.c index 31c848e..93f2802 100644 --- a/src/storage/attribute.c +++ b/src/storage/attribute.c @@ -30,7 +30,7 @@ #include #include "glib/glib-extra.h" #include "attribute.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "ncurses/manager.h" static GPtrArray *attributes = NULL; diff --git a/src/storage/call.c b/src/storage/call.c index f15e109..84a9361 100644 --- a/src/storage/call.c +++ b/src/storage/call.c @@ -32,7 +32,7 @@ #include #include "glib/glib-extra.h" #include "call.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "storage/storage.h" #include "setting.h" #include "message.h" diff --git a/src/storage/datetime.c b/src/storage/datetime.c index 61a242f..b740b62 100644 --- a/src/storage/datetime.c +++ b/src/storage/datetime.c @@ -32,12 +32,6 @@ #include #include "datetime.h" -gint -date_time_is_older(GDateTime *t1, GDateTime *t2) -{ - return g_date_time_compare(t1, t2); -} - const gchar * date_time_date_to_str(GDateTime *time, gchar *out) { diff --git a/src/storage/datetime.h b/src/storage/datetime.h index b6c6671..39ef90f 100644 --- a/src/storage/datetime.h +++ b/src/storage/datetime.h @@ -31,16 +31,6 @@ #include -/** - * @brief Compare two timeval structures - * - * @param time1 First timeval structure - * @param t2 Second timval structure - * @return -1 if t1 > t2, 1 if t1 < t2, 0 if t1 == t2 - */ -gint -date_time_is_older(GDateTime *t1, GDateTime *t2); - /** * @brief Convert timeval to yyyy/mm/dd format */ diff --git a/src/storage/message.c b/src/storage/message.c index 08fb253..2f6ecaa 100644 --- a/src/storage/message.c +++ b/src/storage/message.c @@ -32,8 +32,8 @@ #include #include "glib/glib-extra.h" #include "message.h" -#include "parser/dissectors/packet_sip.h" -#include "parser/dissectors/packet_sdp.h" +#include "parser/packet_sip.h" +#include "parser/packet_sdp.h" #include "storage/storage.h" Message * diff --git a/src/storage/message.h b/src/storage/message.h index e83b5ed..fc2f27d 100644 --- a/src/storage/message.h +++ b/src/storage/message.h @@ -30,7 +30,7 @@ #define __SNGREP_MESSAGE_H #include -#include "parser/dissectors/packet_sdp.h" +#include "parser/packet_sdp.h" #include "parser/packet.h" #include "storage/attribute.h" #include "datetime.h" diff --git a/src/storage/storage.c b/src/storage/storage.c index 8f0d1bb..13db5a9 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -57,7 +57,7 @@ #include #include #include "glib/glib-extra.h" -#include "parser/dissectors/packet_sip.h" +#include "parser/packet_sip.h" #include "setting.h" #include "filter.h" #include "storage.h" diff --git a/src/storage/stream.h b/src/storage/stream.h index 22c1706..42f8c74 100644 --- a/src/storage/stream.h +++ b/src/storage/stream.h @@ -32,9 +32,9 @@ #include "config.h" #include "storage/message.h" #include "capture/capture_pcap.h" -#include "parser/dissectors/packet_sdp.h" -#include "parser/dissectors/packet_rtp.h" -#include "parser/dissectors/packet_rtcp.h" +#include "parser/packet_sdp.h" +#include "parser/packet_rtp.h" +#include "parser/packet_rtcp.h" //! Shorter declaration of rtp_stream structure typedef struct _Stream Stream; diff --git a/valgrind.supp b/valgrind.supp index efe5e99..d9032d8 100644 --- a/valgrind.supp +++ b/valgrind.supp @@ -322,3 +322,15 @@ fun:capture_input_pcap_read_packet fun:g_main_context_dispatch } + +{ + malloc + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:g_malloc + fun:parse_arg.isra.0 + fun:parse_short_option + fun:g_option_context_parse + fun:main +}