Пример #1
0
QVariant PacketListRecord::data(int col_num, column_info *cinfo) const
{
    g_assert(fdata);

    if (!cinfo)
        return QVariant();

    if (col_based_on_frame_data(cinfo, col_num)) //{
        col_fill_in_frame_data(fdata, cinfo, col_num, FALSE);
        return cinfo->col_data[col_num];
//    } else {
//        QString unknown;
//        return unknown.sprintf("Unknown: frame %d col %d", fdata->num, col_num);
//    }
}
Пример #2
0
static void
packet_list_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column,
			  GValue *value)
{
	PacketListRecord *record;
	PacketList *packet_list;

	g_return_if_fail(PACKETLIST_IS_LIST(tree_model));
	packet_list = (PacketList *) tree_model;

	g_return_if_fail(iter != NULL);
	g_return_if_fail(iter->stamp == packet_list->stamp);
	g_return_if_fail(iter->user_data != NULL);

	/* Note: We use one extra column to store the entire frame_data */
	g_return_if_fail(column >= 0 && column < packet_list->n_cols + 1);

	record = (PacketListRecord*) iter->user_data;

#ifdef PACKET_PARANOID_CHECKS
	g_return_if_fail(PACKET_LIST_RECORD_INDEX_VALID(packet_list->physical_rows, record->physical_pos));
#endif
	g_return_if_fail(PACKET_LIST_RECORD_INDEX_VALID(packet_list->visible_rows, record->visible_pos));

	if (column >= 0 && column < packet_list->n_cols) {
		int text_column;

		g_value_init(value, G_TYPE_STRING);

		if (record->col_text == NULL || !record->colorized)
			packet_list_dissect_and_cache_record(packet_list, record, !record->colorized);

		text_column = packet_list->col_to_text[column];
		if (text_column == -1) { /* column based on frame_data */
			col_fill_in_frame_data(record->fdata, &cfile.cinfo, column, FALSE);
			g_value_set_string(value, cfile.cinfo.col_data[column]);
		} else {
			g_return_if_fail(record->col_text);
			g_value_set_string(value, record->col_text[text_column]);
		}

	} else if (column == packet_list->n_cols) {
		g_value_init(value, G_TYPE_POINTER);
		g_value_set_pointer(value, record->fdata);
	}
}
Пример #3
0
//#define MINIMIZE_STRING_COPYING 1
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
{
    // packet_list_store.c:packet_list_change_record(PacketList *packet_list, PacketListRecord *record, gint col, column_info *cinfo)
    if (!cinfo) {
        return;
    }

    col_text_.clear();
    lines_ = 1;
    line_count_changed_ = false;

    for (int column = 0; column < cinfo->num_cols; ++column) {
        int col_lines = 1;

#ifdef MINIMIZE_STRING_COPYING
        int text_col = cinfo_column_.value(column, -1);

        /* Column based on frame_data or it already contains a value */
        if (text_col < 0) {
            col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
            col_text_.append(cinfo->columns[column].col_data);
            continue;
        }

        switch (cinfo->col_fmt[column]) {
        case COL_PROTOCOL:
        case COL_INFO:
        case COL_IF_DIR:
        case COL_DCE_CALL:
        case COL_8021Q_VLAN_ID:
        case COL_EXPERT:
        case COL_FREQ_CHAN:
            if (cinfo->columns[column].col_data && cinfo->columns[column].col_data != cinfo->columns[column].col_buf) {
                /* This is a constant string, so we don't have to copy it */
                // XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8
                // truncation in either case.
                int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN);
                col_text_.append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
                break;
            }
            /* !! FALL-THROUGH!! */

        case COL_DEF_SRC:
        case COL_RES_SRC:        /* COL_DEF_SRC is currently just like COL_RES_SRC */
        case COL_UNRES_SRC:
        case COL_DEF_DL_SRC:
        case COL_RES_DL_SRC:
        case COL_UNRES_DL_SRC:
        case COL_DEF_NET_SRC:
        case COL_RES_NET_SRC:
        case COL_UNRES_NET_SRC:
        case COL_DEF_DST:
        case COL_RES_DST:        /* COL_DEF_DST is currently just like COL_RES_DST */
        case COL_UNRES_DST:
        case COL_DEF_DL_DST:
        case COL_RES_DL_DST:
        case COL_UNRES_DL_DST:
        case COL_DEF_NET_DST:
        case COL_RES_NET_DST:
        case COL_UNRES_NET_DST:
        default:
            if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
                /* Use the unresolved value in col_expr_val */
                // XXX Use QContiguousCache?
                col_text_.append(cinfo->col_expr.col_expr_val[column]);
            } else {
                col_text_.append(cinfo->columns[column].col_data);
            }
            break;
        }
#else // MINIMIZE_STRING_COPYING
        const char *col_str;
        if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
            /* Use the unresolved value in col_expr_val */
            col_str = cinfo->col_expr.col_expr_val[column];
        } else {
            int text_col = cinfo_column_.value(column, -1);

            if (text_col < 0) {
                col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
            }
            col_str = cinfo->columns[column].col_data;
        }
        // g_string_chunk_insert_const manages a hash table of pointers to
        // strings:
        // https://git.gnome.org/browse/glib/tree/glib/gstringchunk.c
        // We might be better off adding the equivalent functionality to
        // wmem_tree.
        col_text_.append(g_string_chunk_insert_const(string_pool_, col_str));
        for (int i = 0; col_str[i]; i++) {
            if (col_str[i] == '\n') col_lines++;
        }
        if (col_lines > lines_) {
            lines_ = col_lines;
            line_count_changed_ = true;
        }
#endif // MINIMIZE_STRING_COPYING
    }
}