Example #1
0
gboolean
resolve_column (gint col, capture_file *cf)
{
    header_field_info *hfi;
    gboolean resolve = FALSE;

    if (!cf) return FALSE;

    switch (cf->cinfo.col_fmt[col]) {

    case COL_CUSTOM:
        hfi = proto_registrar_get_byname(cf->cinfo.col_custom_field[col]);
        /* Check if this is a valid field */
        if (hfi != NULL) {
            /* Check if we have an OID or a strings table with integer values */
            if ((hfi->type == FT_OID) ||
                    ((hfi->strings != NULL) &&
                     ((hfi->type == FT_BOOLEAN) || (hfi->type == FT_FRAMENUM) ||
                      IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)))) {
                resolve = TRUE;
            }
        }
        break;

    default:
        break;
    }

    return resolve;
}
Example #2
0
gboolean
right_justify_column (gint col, capture_file *cf)
{
    header_field_info *hfi;
    gboolean right_justify = FALSE;

    if (!cf) return FALSE;

    switch (cf->cinfo.col_fmt[col]) {

    case COL_NUMBER:
    case COL_PACKET_LENGTH:
    case COL_CUMULATIVE_BYTES:
    case COL_DCE_CALL:
    case COL_DSCP_VALUE:
    case COL_UNRES_DST_PORT:
    case COL_UNRES_SRC_PORT:
    case COL_DEF_DST_PORT:
    case COL_DEF_SRC_PORT:
    case COL_DELTA_TIME:
    case COL_DELTA_TIME_DIS:
        right_justify = TRUE;
        break;

    case COL_CUSTOM:
        hfi = proto_registrar_get_byname(cf->cinfo.col_custom_field[col]);
        /* Check if this is a valid field and we have no strings lookup table */
        if ((hfi != NULL) && ((hfi->strings == NULL) || !get_column_resolved(col))) {
            /* Check for bool, framenum and decimal/octal integer types */
            if ((hfi->type == FT_BOOLEAN) || (hfi->type == FT_FRAMENUM) ||
                    (((hfi->display == BASE_DEC) || (hfi->display == BASE_OCT)) &&
                     (IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)))) {
                right_justify = TRUE;
            }
        }
        break;

    default:
        break;
    }

    return right_justify;
}
bool PacketListModel::recordLessThan(PacketListRecord *r1, PacketListRecord *r2)
{
    int cmp_val = 0;

    // Wherein we try to cram the logic of packet_list_compare_records,
    // _packet_list_compare_records, and packet_list_compare_custom from
    // gtk/packet_list_store.c into one function

    if (sort_column_ < 0) {
        // No column.
        cmp_val = frame_data_compare(sort_cap_file_->epan, r1->frameData(), r2->frameData(), COL_NUMBER);
    } else if (text_sort_column_ < 0) {
        // Column comes directly from frame data
        cmp_val = frame_data_compare(sort_cap_file_->epan, r1->frameData(), r2->frameData(), sort_cap_file_->cinfo.col_fmt[sort_column_]);
    } else  {
        if (r1->columnString(sort_cap_file_, sort_column_).toByteArray().data() == r2->columnString(sort_cap_file_, sort_column_).toByteArray().data()) {
            cmp_val = 0;
        } else if (sort_cap_file_->cinfo.col_fmt[sort_column_] == COL_CUSTOM) {
            header_field_info *hfi;

            // Column comes from custom data
            hfi = proto_registrar_get_byname(sort_cap_file_->cinfo.col_custom_field[sort_column_]);

            if (hfi == NULL) {
                cmp_val = frame_data_compare(sort_cap_file_->epan, r1->frameData(), r2->frameData(), COL_NUMBER);
            } else if ((hfi->strings == NULL) &&
                       (((IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)) &&
                         ((hfi->display == BASE_DEC) || (hfi->display == BASE_DEC_HEX) ||
                          (hfi->display == BASE_OCT))) ||
                        (hfi->type == FT_DOUBLE) || (hfi->type == FT_FLOAT) ||
                        (hfi->type == FT_BOOLEAN) || (hfi->type == FT_FRAMENUM) ||
                        (hfi->type == FT_RELATIVE_TIME)))
            {
                /* Attempt to convert to numbers */
                bool ok_r1, ok_r2;
                double num_r1 = r1->columnString(sort_cap_file_, sort_column_).toDouble(&ok_r1);
                double num_r2 = r2->columnString(sort_cap_file_, sort_column_).toDouble(&ok_r2);

                if (!ok_r1 && !ok_r2) {
                    cmp_val = 0;
                } else if (!ok_r1 || num_r1 < num_r2) {
                    cmp_val = -1;
                } else if (!ok_r2 || num_r1 > num_r2) {
                    cmp_val = 1;
                }
            } else {
                cmp_val = strcmp(r1->columnString(sort_cap_file_, sort_column_).toByteArray().data(), r2->columnString(sort_cap_file_, sort_column_).toByteArray().data());
            }
        } else {
            cmp_val = strcmp(r1->columnString(sort_cap_file_, sort_column_).toByteArray().data(), r2->columnString(sort_cap_file_, sort_column_).toByteArray().data());
        }

        if (cmp_val == 0) {
            // Last resort. Compare column numbers.
            cmp_val = frame_data_compare(sort_cap_file_->epan, r1->frameData(), r2->frameData(), COL_NUMBER);
        }
    }

    if (sort_order_ == Qt::AscendingOrder) {
        return cmp_val < 0;
    } else {
        return cmp_val > 0;
    }
}