static void
dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    proto_tree   *cups_tree = NULL;
    proto_tree   *ptype_subtree = NULL;
    proto_item   *ti = NULL;
    gint          offset = 0;
    gint          next_offset;
    guint         len;
    const guint8 *str;
    cups_ptype_t  ptype;
    unsigned int  state;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG_CUPS);
    col_clear(pinfo->cinfo, COL_INFO);

    ti = proto_tree_add_item(tree, proto_cups, tvb, offset, -1, ENC_NA);
    cups_tree = proto_item_add_subtree(ti, ett_cups);

    /* Format (1450 bytes max.):  */
    /* type state uri ["location" ["info" ["make-and-model"]]]\n */

    ptype = get_hex_uint(tvb, offset, &next_offset);
    len = next_offset - offset;
    if (len != 0) {
        ti = proto_tree_add_uint(cups_tree, hf_cups_ptype, tvb, offset, len, ptype);
        ptype_subtree = proto_item_add_subtree(ti, ett_cups_ptype);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_default, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_implicit, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_variable, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_large, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_medium, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_small, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_sort, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_bind, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_cover, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_punch, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_collate, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_copies, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_staple, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_duplex, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_color, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_bw, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_remote, tvb, offset, len, ENC_BIG_ENDIAN);
        proto_tree_add_item(ptype_subtree, hf_cups_ptype_class, tvb, offset, len, ENC_BIG_ENDIAN);
    }
    offset = next_offset;

    if (!skip_space(tvb, offset, &next_offset))
        return;    /* end of packet */
    offset = next_offset;

    state = get_hex_uint(tvb, offset, &next_offset);
    len = next_offset - offset;
    if (len != 0) {
        proto_tree_add_uint(cups_tree, hf_cups_state, tvb, offset, len, state);
    }
    offset = next_offset;

    if (!skip_space(tvb, offset, &next_offset))
        return;    /* end of packet */
    offset = next_offset;

    str = get_unquoted_string(tvb, offset, &next_offset, &len);
    if (str == NULL)
        return;    /* separator/terminator not found */

    proto_tree_add_text(cups_tree, tvb, offset, len,
            "URI: %.*s", (guint16) len, str);
    col_add_fstr(pinfo->cinfo, COL_INFO, "%.*s (%s)",
            (guint16) len, str, val_to_str(state, cups_state_values, "0x%x"));
    offset = next_offset;

    if (!cups_tree)
        return;

    if (!skip_space(tvb, offset, &next_offset))
        return;    /* end of packet */
    offset = next_offset;

    str = get_quoted_string(tvb, offset, &next_offset, &len);
    if (str == NULL)
        return;    /* separator/terminator not found */
    proto_tree_add_text(cups_tree, tvb, offset+1, len,
        "Location: \"%.*s\"", (guint16) len, str);
    offset = next_offset;

    if (!skip_space(tvb, offset, &next_offset))
        return;    /* end of packet */
    offset = next_offset;

    str = get_quoted_string(tvb, offset, &next_offset, &len);
    if (str == NULL)
        return;    /* separator/terminator not found */
    proto_tree_add_text(cups_tree, tvb, offset+1, len,
        "Information: \"%.*s\"", (guint16) len, str);
    offset = next_offset;

    if (!skip_space(tvb, offset, &next_offset))
        return;    /* end of packet */
    offset = next_offset;

    str = get_quoted_string(tvb, offset, &next_offset, &len);
    if (str == NULL)
        return;    /* separator/terminator not found */
    proto_tree_add_text(cups_tree, tvb, offset+1, len,
            "Make and model: \"%.*s\"", (guint16) len, str);
}
Esempio n. 2
0
static void
dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_tree	*cups_tree = 0;
	proto_tree	*ptype_subtree = 0;
	proto_item	*ti = 0;
	gint		offset = 0;
	gint		next_offset;
	guint		len;
	unsigned int	u;
	const guint8	*str;
	cups_ptype_t	ptype;
	unsigned int	state;

	if (check_col(pinfo->cinfo, COL_PROTOCOL))
		col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG_CUPS);
	col_clear(pinfo->cinfo, COL_INFO);

	if (tree) {
		ti = proto_tree_add_item(tree, proto_cups, tvb, offset, -1,
		    FALSE);
		cups_tree = proto_item_add_subtree(ti, ett_cups);
	}

	/* Format (1450 bytes max.):  */
	/* type state uri ["location" ["info" ["make-and-model"]]]\n */

	ptype = get_hex_uint(tvb, offset, &next_offset);
	len = next_offset - offset;
	if (len != 0) {
		if (cups_tree) {
			ti = proto_tree_add_uint(cups_tree, hf_cups_ptype,
			    tvb, offset, len, ptype);
			ptype_subtree = proto_item_add_subtree(ti,
			    ett_cups_ptype);
			for (u = 0; u < N_CUPS_PTYPE_BITS; u++) {
				proto_tree_add_text(ptype_subtree, tvb,
				    offset, len, "%s",
				    decode_boolean_bitfield(ptype,
				      cups_ptype_bits[u].bit, sizeof (ptype)*8,
				      cups_ptype_bits[u].on_string,
				      cups_ptype_bits[u].off_string));
			}
		}
	}
	offset = next_offset;

	if (!skip_space(tvb, offset, &next_offset))
		return;	/* end of packet */
	offset = next_offset;

	state = get_hex_uint(tvb, offset, &next_offset);
	len = next_offset - offset;
	if (len != 0) {
		if (cups_tree)
			proto_tree_add_uint(cups_tree, hf_cups_state,
			    tvb, offset, len, state);
	}
	offset = next_offset;

	if (!skip_space(tvb, offset, &next_offset))
		return;	/* end of packet */
	offset = next_offset;

	str = get_unquoted_string(tvb, offset, &next_offset, &len);
	if (str == NULL)
		return;	/* separator/terminator not found */
	if (cups_tree)
		proto_tree_add_text(cups_tree, tvb, offset, len,
		    "URI: %.*s",
		    (guint16) len, str);
	if (check_col(pinfo->cinfo, COL_INFO))
		col_add_fstr(pinfo->cinfo, COL_INFO,
		    "%.*s (%s)",
		    (guint16) len, str,
		    val_to_str(state, cups_state_values, "0x%x"));
	offset = next_offset;

	if (!cups_tree)
		return;

	if (!skip_space(tvb, offset, &next_offset))
		return;	/* end of packet */
	offset = next_offset;

	str = get_quoted_string(tvb, offset, &next_offset, &len);
	if (str == NULL)
		return;	/* separator/terminator not found */
	proto_tree_add_text(cups_tree, tvb, offset+1, len,
	    "Location: \"%.*s\"",
	    (guint16) len, str);
	offset = next_offset;

	if (!skip_space(tvb, offset, &next_offset))
		return;	/* end of packet */
	offset = next_offset;

	str = get_quoted_string(tvb, offset, &next_offset, &len);
	if (str == NULL)
		return;	/* separator/terminator not found */
	proto_tree_add_text(cups_tree, tvb, offset+1, len,
	    "Information: \"%.*s\"",
	    (guint16) len, str);
	offset = next_offset;

	if (!skip_space(tvb, offset, &next_offset))
		return;	/* end of packet */
	offset = next_offset;

	str = get_quoted_string(tvb, offset, &next_offset, &len);
	if (str == NULL)
		return;	/* separator/terminator not found */
	proto_tree_add_text(cups_tree, tvb, offset+1, len,
	    "Make and model: \"%.*s\"",
	    (guint16) len, str);
	offset = next_offset;

	return;
}