Replace similar code with a common routine.
svn path=/trunk/; revision=53519
This commit is contained in:
parent
11d8147ab5
commit
b3a24c5cc4
29
epan/proto.c
29
epan/proto.c
|
@ -4543,6 +4543,35 @@ proto_get_protocol_filter_name(const int proto_id)
|
|||
return protocol->filter_name;
|
||||
}
|
||||
|
||||
void
|
||||
proto_get_frame_protocols(const wmem_list_t *layers, gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp) {
|
||||
wmem_list_frame_t* protos = wmem_list_head(layers);
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
|
||||
/* Walk the list of a available protocols in the packet and
|
||||
find "major" ones. */
|
||||
/* It might make more sense to assemble and return a bitfield. */
|
||||
while (protos != NULL)
|
||||
{
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (is_ip && ((!strcmp(proto_name, "ip")) ||
|
||||
(!strcmp(proto_name, "ipv6")))) {
|
||||
*is_ip = TRUE;
|
||||
} else if (is_tcp && !strcmp(proto_name, "tcp")) {
|
||||
*is_tcp = TRUE;
|
||||
} else if (is_udp && !strcmp(proto_name, "udp")) {
|
||||
*is_udp = TRUE;
|
||||
} else if (is_sctp && !strcmp(proto_name, "sctp")) {
|
||||
*is_sctp = TRUE;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
proto_is_protocol_enabled(const protocol_t *protocol)
|
||||
{
|
||||
|
|
13
epan/proto.h
13
epan/proto.h
|
@ -1787,6 +1787,19 @@ WS_DLL_PUBLIC gboolean proto_is_protocol_enabled(const protocol_t *protocol);
|
|||
@return its filter name. */
|
||||
WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id);
|
||||
|
||||
/** Find commonly-used protocols in a layer list.
|
||||
* @param layers Protocol layer list
|
||||
* @param is_ip Set to TRUE if the layer list contains IPv4 or IPv6, otherwise
|
||||
* unchanged. May be NULL.
|
||||
* @param is_tcp Set to TRUE if the layer list contains TCP, otherwise
|
||||
* unchanged. May be NULL.
|
||||
* @param is_udp Set to TRUE if the layer list contains UDP, otherwise
|
||||
* unchanged. May be NULL.
|
||||
* @param is_sctp Set to TRUE if the layer list contains SCTP, otherwise
|
||||
* unchanged. May be NULL.
|
||||
*/
|
||||
WS_DLL_PUBLIC void proto_get_frame_protocols(const wmem_list_t *layers, gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp);
|
||||
|
||||
/** Enable / Disable protocol of the given item number.
|
||||
@param proto_id protocol id (0-indexed)
|
||||
@param enabled enable / disable the protocol */
|
||||
|
|
|
@ -105,25 +105,9 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_)
|
|||
size_t nchars;
|
||||
gchar *data_out_filename;
|
||||
char stream_window_title[256];
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
gboolean is_tcp = FALSE;
|
||||
|
||||
/* we got tcp so we can follow (should really be protected by menu sensitivity) */
|
||||
protos = wmem_list_head(cfile.edt->pi.layers);
|
||||
/* walk the list of a available protocols in the packet to see if we have TCP */
|
||||
while (protos != NULL) {
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(cfile.edt->pi.layers, NULL, &is_tcp, NULL, NULL);
|
||||
|
||||
if (!is_tcp) {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
||||
|
|
|
@ -94,25 +94,9 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_)
|
|||
follow_stats_t stats;
|
||||
follow_info_t *follow_info;
|
||||
GString *msg;
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
gboolean is_udp = FALSE;
|
||||
|
||||
/* we got udp so we can follow (should really be protected by menu sensitivity) */
|
||||
protos = wmem_list_head(cfile.edt->pi.layers);
|
||||
/* walk the list of a available protocols in the packet to see if we have UDP */
|
||||
while (protos != NULL) {
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(cfile.edt->pi.layers, NULL, NULL, &is_udp, NULL);
|
||||
|
||||
if (!is_udp) {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
||||
|
|
|
@ -189,30 +189,10 @@ static char *
|
|||
build_conversation_filter(int action, gboolean show_dialog)
|
||||
{
|
||||
packet_info *pi = &cfile.edt->pi;
|
||||
wmem_list_frame_t * protos = wmem_list_head(pi->layers);
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
char *buf;
|
||||
gboolean is_ip = FALSE, is_tcp = FALSE, is_udp = FALSE;
|
||||
|
||||
/* walk the list of a available protocols in the packet to
|
||||
figure out if any of them affect conversation filters */
|
||||
while (protos != NULL)
|
||||
{
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if ((!strcmp(proto_name, "ip")) ||
|
||||
(!strcmp(proto_name, "ipv6"))) {
|
||||
is_ip = TRUE;
|
||||
} else if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
} else if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(pi->layers, &is_ip, &is_tcp, &is_udp, NULL);
|
||||
|
||||
switch(action) {
|
||||
case(CONV_CBA):
|
||||
|
|
|
@ -807,9 +807,6 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_tcp_index)
|
|||
tcp_stream_chunk sc;
|
||||
size_t nchars;
|
||||
GString * msg;
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
gboolean is_tcp = FALSE, is_udp = FALSE;
|
||||
|
||||
resetStream();
|
||||
|
@ -826,21 +823,7 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_tcp_index)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* walk the list of a available protocols in the packet to see what we have
|
||||
Handles error conditions that should probably just be handled with menu sensitivity */
|
||||
protos = wmem_list_head(cap_file_->edt->pi.layers);
|
||||
while (protos != NULL) {
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
} else if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL);
|
||||
|
||||
switch (follow_type_)
|
||||
{
|
||||
|
|
|
@ -1366,9 +1366,6 @@ void MainWindow::setTitlebarForCaptureInProgress()
|
|||
|
||||
void MainWindow::setMenusForFollowStream()
|
||||
{
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
gboolean is_tcp = FALSE, is_udp = FALSE;
|
||||
|
||||
if (!cap_file_)
|
||||
|
@ -1381,24 +1378,8 @@ void MainWindow::setMenusForFollowStream()
|
|||
main_ui_->actionAnalyzeFollowUDPStream->setEnabled(false);
|
||||
main_ui_->actionAnalyzeFollowSSLStream->setEnabled(false);
|
||||
|
||||
protos = wmem_list_head(cap_file_->edt->pi.layers);
|
||||
|
||||
/* walk the list of a available protocols in the packet to
|
||||
figure out if any of them affect context sensitivity */
|
||||
while (protos != NULL)
|
||||
{
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
} else if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
|
||||
proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL);
|
||||
|
||||
if (is_tcp)
|
||||
{
|
||||
main_ui_->actionAnalyzeFollowTCPStream->setEnabled(true);
|
||||
|
|
|
@ -726,9 +726,6 @@ void MainWindow::setMenusForSelectedPacket()
|
|||
// gboolean properties = FALSE;
|
||||
// const char *abbrev = NULL;
|
||||
// char *prev_abbrev;
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
#if 0
|
||||
gboolean is_ip = FALSE, is_tcp = FALSE, is_udp = FALSE, is_sctp = FALSE;
|
||||
#else
|
||||
|
@ -776,34 +773,7 @@ void MainWindow::setMenusForSelectedPacket()
|
|||
|
||||
if (cap_file_->edt)
|
||||
{
|
||||
protos = wmem_list_head(cap_file_->edt->pi.layers);
|
||||
|
||||
/* walk the list of a available protocols in the packet to
|
||||
figure out if any of them affect context sensitivity */
|
||||
while (protos != NULL)
|
||||
{
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
#if 0
|
||||
if ((!strcmp(proto_name, "ip")) ||
|
||||
(!strcmp(proto_name, "ipv6"))) {
|
||||
is_ip = TRUE;
|
||||
} else if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
} else if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
} else if (!strcmp(proto_name, "sctp")) {
|
||||
is_sctp = TRUE;
|
||||
}
|
||||
#else
|
||||
if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, NULL, NULL);
|
||||
}
|
||||
}
|
||||
// if (cfile.edt && cfile.edt->tree) {
|
||||
|
|
|
@ -460,27 +460,12 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event)
|
|||
{
|
||||
bool fa_enabled = filter_actions_[0]->isEnabled();
|
||||
QAction *act;
|
||||
wmem_list_frame_t* protos;
|
||||
int proto_id;
|
||||
const char* proto_name;
|
||||
gboolean is_tcp = FALSE, is_udp = FALSE;
|
||||
|
||||
/* walk the list of a available protocols in the packet to see what we have */
|
||||
if ((cap_file_ != NULL) && (cap_file_->edt != NULL))
|
||||
{
|
||||
protos = wmem_list_head(cap_file_->edt->pi.layers);
|
||||
while (protos != NULL) {
|
||||
proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos));
|
||||
proto_name = proto_get_protocol_filter_name(proto_id);
|
||||
|
||||
if (!strcmp(proto_name, "tcp")) {
|
||||
is_tcp = TRUE;
|
||||
} else if (!strcmp(proto_name, "udp")) {
|
||||
is_udp = TRUE;
|
||||
}
|
||||
|
||||
protos = wmem_list_frame_next(protos);
|
||||
}
|
||||
proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL);
|
||||
}
|
||||
|
||||
foreach (act, filter_actions_)
|
||||
|
|
Loading…
Reference in New Issue