void lex (parser *p) { #if LDEBUG if (p->ch) fprintf(stderr, "lex: p->ch = '%c'\n", p->ch); else fprintf(stderr, "lex: p->ch = NUL\n"); #endif if (p->ch == 0) { p->sym = EOT; return; } while (p->ch != 0) { switch (p->ch) { case ' ': case '\t': case '\r': case '\n': parser_getc(p); break; case '+': p->sym = B_ADD; parser_getc(p); return; case '-': p->sym = B_SUB; parser_getc(p); return; case '*': if (p->targ == LIST) { /* treat '*' as wildcard */ getword(p); return; } parser_getc(p); if (p->ch == '*') { p->sym = B_KRON; parser_getc(p); } else { p->sym = B_MUL; } return; case '\'': p->sym = B_TRMUL; parser_getc(p); return; case '/': p->sym = B_DIV; parser_getc(p); return; case '\\': p->sym = B_LDIV; parser_getc(p); return; case '%': p->sym = B_MOD; parser_getc(p); return; case '^': p->sym = B_POW; parser_getc(p); return; case '&': parser_getc(p); if (p->ch == '&') { p->sym = B_AND; parser_getc(p); } else { p->sym = U_ADDR; } return; case '|': parser_getc(p); if (p->ch == '|') { p->sym = B_OR; parser_getc(p); } else { p->sym = B_VCAT; } return; case '!': parser_getc(p); if (p->ch == '=') { p->sym = B_NEQ; parser_getc(p); } else { p->sym = U_NOT; } return; case '=': parser_getc(p); if (p->ch == '=') { /* allow "==" as synonym for "=" */ parser_getc(p); } p->sym = B_EQ; return; case '>': parser_getc(p); if (p->ch == '=') { p->sym = B_GTE; parser_getc(p); } else { p->sym = B_GT; } return; case '<': parser_getc(p); if (p->ch == '=') { p->sym = B_LTE; parser_getc(p); } else if (p->ch == '>') { p->sym = B_NEQ; parser_getc(p); } else { p->sym = B_LT; } return; case '(': p->sym = G_LPR; parser_getc(p); return; case ')': p->sym = G_RPR; parser_getc(p); return; case '[': p->sym = G_LBR; parser_getc(p); return; case '{': p->sym = G_LCB; parser_getc(p); return; case '}': p->sym = G_RCB; parser_getc(p); return; case ']': p->sym = G_RBR; parser_getc(p); return; case '~': p->sym = B_HCAT; parser_getc(p); return; case ',': p->sym = P_COM; parser_getc(p); return; case ';': if (p->targ == LIST) { p->sym = B_JOIN; } else { /* used in matrix definition */ p->sym = P_SEMI; } parser_getc(p); return; case ':': p->sym = P_COL; parser_getc(p); return; case '?': p->sym = QUERY; parser_getc(p); return; case '.': if (*p->point == '$') { p->sym = P_DOT; parser_getc(p); return; } parser_getc(p); if (p->ch == '*') { p->sym = B_DOTMULT; parser_getc(p); return; } else if (p->ch == '/') { p->sym = B_DOTDIV; parser_getc(p); return; } else if (p->ch == '^') { p->sym = B_DOTPOW; parser_getc(p); return; } else if (p->ch == '+') { p->sym = B_DOTADD; parser_getc(p); return; } else if (p->ch == '-') { p->sym = B_DOTSUB; parser_getc(p); return; } else if (p->ch == '=') { p->sym = B_DOTEQ; parser_getc(p); return; } else if (p->ch == '>') { p->sym = B_DOTGT; parser_getc(p); if (p->ch == '=') { p->sym = B_DOTGTE; parser_getc(p); } return; } else if (p->ch == '<') { p->sym = B_DOTLT; parser_getc(p); if (p->ch == '=') { p->sym = B_DOTLTE; parser_getc(p); } return; } else if (p->ch == '.') { p->sym = B_ELLIP; parser_getc(p); return; } else { /* not a "dot operator", so back up */ parser_ungetc(p); } default: if (p->targ == LIST && lag_range_sym(p)) { p->sym = B_RANGE; parser_getc(p); parser_getc(p); return; } if (p->targ == LIST && *(p->point - 2) == ' ' && (bare_data_type(p->sym) || closing_sym(p->sym) || (p->sym == LAG))) { /* may be forming a list, but only if there are spaces between the terms */ p->sym = B_LCAT; return; } if (isdigit(p->ch) || (p->ch == '.' && isdigit(*p->point))) { parse_number(p); return; } else if (islower(p->ch) || isupper(p->ch) || word_start_special(p->ch)) { getword(p); return; } else if (p->ch == '"') { p->idstr = get_quoted_string(p); return; } else { parser_print_input(p); pprintf(p->prn, _("Invalid character '%c'\n"), p->ch); p->err = E_PARSE; return; } } /* end ch switch */ } /* end while ch != 0 */ }
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); }
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; }