static enum frame_event_status textarea_op(struct form_state *fs, struct form_control *fc, int utf8, int (*do_op)(struct form_state *, struct line_info *, int, int)) { struct line_info *line; int current, state; int state_cell; assert(fs && fs->value && fc); if_assert_failed return FRAME_EVENT_OK; if (utf8) line = format_textutf8(fs->value, fc->cols, fc->wrap, 0); else line = format_text(fs->value, fc->cols, fc->wrap, 0); if (!line) return FRAME_EVENT_OK; current = get_textarea_line_number(line, fs->state); state = fs->state; state_cell = fs->state_cell; if (do_op(fs, line, current, utf8)) { mem_free(line); return FRAME_EVENT_IGNORED; } mem_free(line); return (fs->state == state && fs->state_cell == state_cell) ? FRAME_EVENT_OK : FRAME_EVENT_REFRESH; }
static int dissect_aim_msg_outgoing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree) { int offset = 0; const aim_tlv *aim_ch_tlvs = NULL; guint16 channel_id; guchar buddyname[MAX_BUDDYNAME_LENGTH+1]; int buddyname_length; /* ICBM Cookie */ proto_tree_add_item(msg_tree, hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA); offset += 8; /* Message Channel ID */ channel_id = tvb_get_ntohs(tvb, offset); proto_tree_add_item(msg_tree, hf_aim_message_channel_id, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2; /* Add the outgoing username to the info column */ buddyname_length = aim_get_buddyname(buddyname, tvb, offset, offset + 1); col_append_fstr(pinfo->cinfo, COL_INFO, " to: %s", format_text(buddyname, buddyname_length)); offset = dissect_aim_buddyname(tvb, pinfo, offset, msg_tree); switch(channel_id) { case ICBM_CHANNEL_IM: aim_ch_tlvs = aim_messaging_incoming_ch1_tlvs; break; case ICBM_CHANNEL_RENDEZVOUS: aim_ch_tlvs = aim_messaging_incoming_ch2_tlvs; break; default: return offset; } return dissect_aim_tlv_sequence(tvb, pinfo, offset, msg_tree, aim_ch_tlvs); }
static int dissect_aim_snac_signon_signon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { guint8 buddyname_length = 0; int offset = 0; guchar buddyname[MAX_BUDDYNAME_LENGTH + 1]; /* Info Type */ proto_tree_add_item(tree, hf_aim_infotype, tvb, offset, 2, FALSE); offset += 2; /* Unknown */ offset += 1; /* Buddy Name */ buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 ); if (check_col(pinfo->cinfo, COL_INFO)) { col_append_fstr(pinfo->cinfo, COL_INFO, " Username: %s", format_text(buddyname, buddyname_length)); } if(tree) { offset+=dissect_aim_buddyname(tvb, pinfo, offset, tree); } return offset; }
void __cdecl H3DString::format(const TCHAR* text, va_list arg_list) { const int TEXT_BUFFERSIZE = 2048; TCHAR text_buffer[TEXT_BUFFERSIZE]; format_text(text_buffer, text, arg_list); (*this) = text_buffer; }
int area_cursor(struct form_control *fc, struct form_state *fs) { struct line_info *line; int x, y; assert(fc && fs); if_assert_failed return 0; line = format_text(fs->value, fc->cols, fc->wrap, 0); if (!line) return 0; y = get_textarea_line_number(line, fs->state); if (y == -1) { mem_free(line); return 0; } x = fs->state - line[y].start; mem_free(line); if (fc->wrap && x == fc->cols) x--; int_bounds(&fs->vpos, x - fc->cols + 1, x); int_bounds(&fs->vypos, y - fc->rows + 1, y); x -= fs->vpos; y -= fs->vypos; return y * fc->cols + x; }
WlanNetworkTreeWidgetItem(QTreeWidget *parent, wlan_hdr_t *wlan_hdr) : QTreeWidgetItem (parent, wlan_network_row_type_), beacon_(0), data_packet_(0), probe_req_(0), probe_resp_(0), auth_(0), deauth_(0), other_(0), packets_(0) { updateBssid(wlan_hdr); channel_ = wlan_hdr->stats.channel; ssid_ = QByteArray::fromRawData((const char *)wlan_hdr->stats.ssid, wlan_hdr->stats.ssid_len); QString ssid_text; if (wlan_hdr->stats.ssid_len == 0) { ssid_text = QObject::tr("<Broadcast>"); } else if (wlan_hdr->stats.ssid_len == 1 && wlan_hdr->stats.ssid[0] == 0) { ssid_text = QObject::tr("<Hidden>"); } else { ssid_text = format_text(wlan_hdr->stats.ssid, wlan_hdr->stats.ssid_len); } setText(col_ssid_, ssid_text); }
static void dissect_msnms(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *msnms_tree; proto_item *ti; gint offset = 0; const guchar *line; gint next_offset; int linelen; /* int tokenlen; */ /* const guchar *next_token; */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSNMS"); /* * Find the end of the first line. * * Note that "tvb_find_line_end()" will return a value that is * not longer than what's in the buffer, so the "tvb_get_ptr()" * call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); if (check_col(pinfo->cinfo, COL_INFO)) { /* * Put the first line from the buffer into the summary. */ col_add_str(pinfo->cinfo, COL_INFO, format_text(line, linelen)); } if (tree) { ti = proto_tree_add_item(tree, proto_msnms, tvb, offset, -1, FALSE); msnms_tree = proto_item_add_subtree(ti, ett_msnms); /* * Show the rest of the packet as text, * a line at a time. */ while (tvb_offset_exists(tvb, offset)) { /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); /* * Put this line. */ proto_tree_add_text(msnms_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset)); offset = next_offset; } } }
/** * Processes all the widget files in the given dir. * * @see format_text * * @param *dir */ void generator_process_widgets(Dir *dir) { int i; for (i=0; i < dir->files_count; i++) { if (strcmp(dir->files[i]->extension, "widget") == 0) { format_text(&dir->files[i]->content); } } }
static void dissect_jabber(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { gboolean is_request; proto_tree *jabber_tree = NULL; proto_item *ti, *hidden_item; gint offset = 0; const guchar *line; gint next_offset; int linelen; tvbuff_t *xmltvb; col_set_str(pinfo->cinfo, COL_PROTOCOL, "Jabber"); /* * Find the end of the first line. * * Note that "tvb_find_line_end()" will return a value that is * not longer than what's in the buffer, so the "tvb_get_ptr()" * call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); if (pinfo->match_uint == pinfo->destport) is_request = TRUE; else is_request = FALSE; if (check_col(pinfo->cinfo, COL_INFO)) { /* * Put the first line from the buffer into the summary * (but leave out the line terminator). */ col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", is_request ? "Request" : "Response", format_text(line, linelen)); } if (tree) { ti = proto_tree_add_item(tree, proto_jabber, tvb, offset, -1, FALSE); jabber_tree = proto_item_add_subtree(ti, ett_jabber); if (is_request) { hidden_item = proto_tree_add_boolean(jabber_tree, hf_jabber_request, tvb, 0, 0, TRUE); } else { hidden_item = proto_tree_add_boolean(jabber_tree, hf_jabber_response, tvb, 0, 0, TRUE); } PROTO_ITEM_SET_HIDDEN(hidden_item); } xmltvb = tvb_new_subset_remaining(tvb, offset); call_dissector(xml_handle, xmltvb, pinfo, jabber_tree); }
/* * formatted text-only file prompt */ int CVmConsole::askfile(VMG_ const char *prompt, size_t prompt_len, char *reply, size_t replen, int /*dialog_type*/, os_filetype_t /*file_type*/, int bypass_script) { /* show the prompt */ format_text(vmg_ prompt, prompt_len); format_text(vmg_ " >"); /* ask for the filename */ if (read_line(vmg_ reply, replen)) return OS_AFE_FAILURE; /* * if they entered an empty line, return "cancel"; otherwise, return * success */ return (reply[0] == '\0' ? OS_AFE_CANCEL : OS_AFE_SUCCESS); }
static void swan_show_picture(const char *state, int reset) { unsigned int i; struct cavan_input_service service; close_console(); if (cavan_fb_bmp_view2(format_text(BMP_PATH "/%s.bmp", state), NULL) < 0) { cavan_fb_bmp_view2(format_text(BACKUP_BMP_PATH "/%s.bmp", state), NULL); } if (reset == 0) { sleep(5); return; } print_string("Press \"Power\" reset the system"); cavan_input_service_init(&service, swan_keypad_match); service.handler = swan_keypad_handler; cavan_input_service_start(&service, NULL); print_string("Press \"Enter\" into command line"); for (i = REBOOT_TIMEOUT; i > 0; i--) { int c; print("Reboot remain time %d(s) \r", i); c = cavan_getchar_timed(1, 0); if (c == '\n') { cavan_input_service_stop(&service); return; } } println("\nSystem Rebooting ..."); sync(); reboot(RB_AUTOBOOT); }
FrmTarifas::FrmTarifas(QWidget *parent) : QDialog(parent), ui(new Ui::FrmTarifas) { ui->setupUi(this); ui->tabWidget->setCurrentIndex(0); QSqlQueryModel *modelo = new QSqlQueryModel(this); modelo->setQuery("Select descripcion from codigotarifa",Configuracion_global->groupDB); ui->listaTarifa->setModel(modelo); modelVolumenes = new QSqlQueryModel(this); ui->tabla_volumenes->setModel(modelVolumenes); this->id_volumen =0; this->id_tarifa =0; modelVolumenes->setQuery(QString("select id,desde,hasta,precio from articulos_volumen where id_tarifa = %1").arg(this->id_tarifa), Configuracion_global->groupDB); QStringList headers; QVariantList sizes; headers << "id" <<tr("Desde") << tr("Hasta") << tr("Precio"); sizes << 0 << 60 << 60 <<100; for(int i=0;i<headers.size();i++) { ui->tabla_volumenes->setColumnWidth(i,sizes.at(i).toInt()); modelVolumenes->setHeaderData(i,Qt::Horizontal,headers.at(i)); if(i>0) ui->tabla_volumenes->setItemDelegateForColumn(i,new MonetaryDelegate(this)); } //----------- // CONEXIONES //----------- connect(ui->listaTarifa,SIGNAL(clicked(QModelIndex)),this,SLOT(cargarDatosTarifa(QModelIndex))); connect(ui->txtPVPDivisa,SIGNAL(editingFinished()),Configuracion_global,SLOT(format_text())); connect(ui->txtPVPDivisa,SIGNAL(editingFinished()),this,SLOT(cambiar_precio_editingfinished())); connect(ui->btnAceptar,SIGNAL(clicked()),this,SLOT(aceptar())); connect(ui->spinMargen,SIGNAL(valueChanged(double)),this,SLOT(calcular_precio(double))); //------------------------------- // CAMBIO DIVISA //------------------------------- connect(Configuracion_global,SIGNAL(cambioReady(float)),this,SLOT(asignarcambiodivisa(float))); // Configuracion_global->getCambio("EUR","USD",1); ui->spinMargen->setValue(Configuracion_global->margen); ui->spinmargen_minimo->setValue(Configuracion_global->margen_minimo); }
string Converter::info() const { std::stringstream s; s << std::boolalpha << std::fixed << std::setprecision(1); s << "Output format: " << format_text(format) << nl; s << "Channel order:"; for (int ch = 0; ch < NCHANNELS; ch++) if (order[ch] != CH_NONE) s << " " << ch_name_short(order[ch]); s << nl; s << "Buffer size: " << nsamples << " samples" << nl; return s.str(); }
int area_cursor(struct form_control *fc, struct form_state *fs, int utf8) { struct line_info *line; int x, y; assert(fc && fs); if_assert_failed return 0; if (utf8) line = format_textutf8(fs->value, fc->cols, fc->wrap, 0); else line = format_text(fs->value, fc->cols, fc->wrap, 0); if (!line) return 0; if (fs->state_cell) y = get_textarea_line_number(line, fs->state_cell); else y = get_textarea_line_number(line, fs->state); if (y == -1) { mem_free(line); return 0; } if (utf8) { if (fs->state_cell) { x = utf8_ptr2cells(fs->value + line[y].start, fs->value + fs->state_cell); x += line[y].last_char_width; } else x = utf8_ptr2cells(fs->value + line[y].start, fs->value + fs->state); } else { x = fs->state - line[y].start; if (fc->wrap && x == fc->cols) x--; } mem_free(line); int_bounds(&fs->vpos, x - fc->cols + 1, x); int_bounds(&fs->vypos, y - fc->rows + 1, y); x -= fs->vpos; y -= fs->vypos; return y * fc->cols + x; }
static void display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, socks_hash_entry_t *hash_info) { /* Display the ping/trace_route conversation */ const guchar *data, *dataend; const guchar *lineend, *eol; int linelen; /* handle the end command */ if ( pinfo->destport == TCP_PORT_SOCKS){ col_append_str(pinfo->cinfo, COL_INFO, ", Terminate Request"); if ( tree) proto_tree_add_text(tree, tvb, offset, 1, (hash_info->command == PING_COMMAND) ? "Ping: End command" : "Traceroute: End command"); } else{ /* display the PING or Traceroute results */ col_append_str(pinfo->cinfo, COL_INFO, ", Results"); if ( tree){ proto_tree_add_text(tree, tvb, offset, -1, (hash_info->command == PING_COMMAND) ? "Ping Results:" : "Traceroute Results"); data = tvb_get_ptr(tvb, offset, -1); dataend = data + tvb_length_remaining(tvb, offset); while (data < dataend) { lineend = find_line_end(data, dataend, &eol); linelen = (int)(lineend - data); proto_tree_add_text( tree, tvb, offset, linelen, "%s", format_text(data, linelen)); offset += linelen; data = lineend; } } } }
unsigned char * encode_textarea(struct submitted_value *sv) { struct form_control *fc; void *blabla; assert(sv && sv->value); if_assert_failed return NULL; fc = sv->form_control; /* We need to reformat text now if it has to be wrapped hard, just * before encoding it. */ /* TODO: Do we need here UTF-8 format or not? --scrool */ blabla = format_text(sv->value, fc->cols, fc->wrap, 1); mem_free_if(blabla); return encode_crlf(sv); }
static int dissect_aim_buddylist_offgoing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *buddy_tree) { guchar buddyname[MAX_BUDDYNAME_LENGTH+1]; int offset = 0; int buddyname_length = aim_get_buddyname( buddyname, tvb, offset, offset + 1 ); col_set_str(pinfo->cinfo, COL_INFO, "Offgoing Buddy"); col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", format_text(buddyname, buddyname_length)); offset += dissect_aim_buddyname(tvb, pinfo, offset, buddy_tree); /* Warning level */ proto_tree_add_item(buddy_tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2; return dissect_aim_tlv_list(tvb, pinfo, offset, buddy_tree, aim_onlinebuddy_tlvs); }
/* If name_val is !NULL then return the pointer to an emem allocated string in * this variable. */ static int add_value_head(const gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb, int offset, int name_length, int value_length, char **name_val) { proto_tree_add_string(tree, hf_ipp_tag, tvb, offset, 1, tag_desc); offset += 1; proto_tree_add_uint(tree, hf_ipp_name_length, tvb, offset, 2, name_length); offset += 2; if (name_length != 0) { guint8 *nv; nv = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, name_length, ENC_ASCII); proto_tree_add_string(tree, hf_ipp_name, tvb, offset, name_length, format_text(nv, name_length)); if (name_val) { *name_val=nv; } } offset += name_length; proto_tree_add_uint(tree, hf_ipp_value_length, tvb, offset, 2, value_length); offset += 2; return offset; }
/** * Processes all the pages in the given directory * * @see format text * @see embed_into_layout * * @param *dir Directory to process */ void generator_process_pages(Dir *dir) { int i; char *layout = NULL; if (has_layout(dir) != 0) { layout = dir->files[dir->layout_index]->content; } for (i=0; i < dir->files_count; i++) { if ( strcmp(dir->files[i]->extension, "page") == 0) { /*format*/ format_text(&(dir->files[i])->content); /*embed into layout*/ if (layout != NULL) { embed_into_layout( &(dir->files[i])->content, layout ); } } } }
/* If name_val is !NULL then return the pointer to an emem allocated string in * this variable. */ static int add_value_head(const gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb, int offset, int name_length, int value_length, char **name_val) { proto_tree_add_text(tree, tvb, offset, 1, "Tag: %s", tag_desc); offset += 1; proto_tree_add_text(tree, tvb, offset, 2, "Name length: %u", name_length); offset += 2; if (name_length != 0) { guint8 *nv; nv = tvb_get_string(wmem_packet_scope(), tvb, offset, name_length); proto_tree_add_text(tree, tvb, offset, name_length, "Name: %s", format_text(nv, name_length)); if (name_val) { *name_val=nv; } } offset += name_length; proto_tree_add_text(tree, tvb, offset, 2, "Value length: %u", value_length); offset += 2; return offset; }
void GrowAxis::export_javabean(GlowTransform* t, void* node, glow_eExportPass pass, int* shape_cnt, int node_cnt, int in_nc, std::ofstream& fp) { int i; int draw_text = (fabs(increment) > DBL_EPSILON); double x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y; double rotation; int bold; char text[20]; int line_length; int z_height, z_width, z_descent; int max_z_width = 0; int idx = int( ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (text_size + 4) - 4); double tsize = ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor * (8 + 2 * text_size); idx = MIN(idx, DRAW_TYPE_SIZE - 1); bold = (text_drawtype == glow_eDrawType_TextHelveticaBold); if (!t) { x1 = trf.x(ll.x, ll.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x; y1 = trf.y(ll.x, ll.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y; x2 = trf.x(ur.x, ur.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x; y2 = trf.y(ur.x, ur.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y; } else { x1 = trf.x(t, ll.x, ll.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x; y1 = trf.y(t, ll.x, ll.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y; x2 = trf.x(t, ur.x, ur.y) * ctx->mw.zoom_factor_x - ctx->mw.offset_x; y2 = trf.y(t, ur.x, ur.y) * ctx->mw.zoom_factor_y - ctx->mw.offset_y; } ll_x = MIN(x1, x2); ur_x = MAX(x1, x2); ll_y = MIN(y1, y2); ur_y = MAX(y1, y2); if (t) rotation = (trf.rot(t) / 360 - floor(trf.rot(t) / 360)) * 360; else rotation = (trf.rot() / 360 - floor(trf.rot() / 360)) * 360; // Calculate max value line width if (45 >= rotation || rotation > 315) { if (draw_text) { for (i = 0; i < lines; i++) { if (i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (max_z_width < z_width) max_z_width = z_width; } } line_length = int(ur_x - ll_x) - max_z_width; } else line_length = int(ur_x - ll_x); } else if (45 < rotation && rotation <= 135) { if (draw_text) { ctx->gdraw->get_text_extent("0", 1, text_drawtype, MAX(0, idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); line_length = int(ur_y - ll_y) - (z_height - z_descent); } else line_length = int(ur_y - ll_y); } else if (135 < rotation && rotation <= 225) { if (draw_text) { for (i = 0; i < lines; i++) { if (i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (max_z_width < z_width) max_z_width = z_width; } } line_length = int(ur_x - ll_x) - max_z_width; } else line_length = int(ur_x - ll_x); } else // if ( 225 < rotation && rotation <= 315) { if (draw_text) { ctx->gdraw->get_text_extent("0", 1, text_drawtype, MAX(0, idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); line_length = int(ur_y - ll_y) - (z_height - z_descent); } else line_length = int(ur_y - ll_y); } if (line_length < 3) line_length = 3; ((GrowCtx*)ctx) ->export_jbean->axis(ll_x, ll_y, ur_x, ur_y, draw_type, text_color_drawtype, min_value, max_value, lines, longquotient, valuequotient, line_length, line_width, rotation, bold, idx, format, pass, shape_cnt, node_cnt, fp); }
void GrowAxis::draw(GlowWind* w, GlowTransform* t, int highlight, int hot, void* node, void* colornode) { if (ctx->nodraw) return; if (w == &ctx->navw) { if (ctx->no_nav) return; hot = 0; } int i; int draw_text = (fabs(increment) > DBL_EPSILON); int idx; int x, y; char text[20]; int line_length; int x_text, y_text; int z_height = 0, z_width, z_descent = 0; int max_z_width = 0; double rotation; glow_eDrawType drawtype; int text_idx = int(w->zoom_factor_y / w->base_zoom_factor * (text_size + 4) - 4); double tsize = w->zoom_factor_y / w->base_zoom_factor * (8 + 2 * text_size); text_idx = MIN(text_idx, DRAW_TYPE_SIZE - 1); if (fix_line_width) { idx = line_width; idx += hot; if (idx < 0) { erase(w, t, hot, node); return; } } else { if (node && ((GrowNode*)node)->line_width) idx = int( w->zoom_factor_y / w->base_zoom_factor * ((GrowNode*)node)->line_width - 1); else idx = int(w->zoom_factor_y / w->base_zoom_factor * line_width - 1); idx += hot; } if ((node && ((GrowNode*)node)->invisible) || invisible) return; idx = MAX(0, idx); idx = MIN(idx, DRAW_TYPE_SIZE - 1); int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y; if (!t) { x1 = int(trf.x(ll.x, ll.y) * w->zoom_factor_x) - w->offset_x; y1 = int(trf.y(ll.x, ll.y) * w->zoom_factor_y) - w->offset_y; x2 = int(trf.x(ur.x, ur.y) * w->zoom_factor_x) - w->offset_x; y2 = int(trf.y(ur.x, ur.y) * w->zoom_factor_y) - w->offset_y; rotation = (trf.rot() / 360 - floor(trf.rot() / 360)) * 360; } else { x1 = int(trf.x(t, ll.x, ll.y) * w->zoom_factor_x) - w->offset_x; y1 = int(trf.y(t, ll.x, ll.y) * w->zoom_factor_y) - w->offset_y; x2 = int(trf.x(t, ur.x, ur.y) * w->zoom_factor_x) - w->offset_x; y2 = int(trf.y(t, ur.x, ur.y) * w->zoom_factor_y) - w->offset_y; rotation = (trf.rot(t) / 360 - floor(trf.rot(t) / 360)) * 360; } ll_x = MIN(x1, x2); ur_x = MAX(x1, x2); ll_y = MIN(y1, y2); ur_y = MAX(y1, y2); drawtype = ctx->get_drawtype(draw_type, glow_eDrawType_LineHighlight, highlight, (GrowNode*)colornode, 0); if (45 >= rotation || rotation > 315) { // Vertical line to the right and values to the left ctx->gdraw->line(w, ur_x, ll_y, ur_x, ur_y, drawtype, idx, 0); // Calculate max value text width if (draw_text) { for (i = 0; i < lines; i++) { if (i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (max_z_width < z_width) max_z_width = z_width; } } x_text = ll_x + max_z_width; line_length = ur_x - ll_x - max_z_width; if (line_length < 3) line_length = 3; } else { x_text = ll_x; line_length = ur_x - ll_x; } for (i = 0; i < lines; i++) { y = int(ll_y + double(ur_y - ll_y) / (lines - 1) * i); if (i % longquotient == 0) ctx->gdraw->line(w, ur_x - line_length, y, ur_x, y, drawtype, idx, 0); else ctx->gdraw->line( w, ur_x - int(2.0 / 3 * line_length), y, ur_x, y, drawtype, idx, 0); if (draw_text) { format_text(text, format, max_value - i * increment); if (text_idx >= 0 && max_z_width < ur_x - ll_x && i % valuequotient == 0) { if (i == lines - 1) y_text = y; else if (i == 0) y_text = y + z_height - z_descent - 3; else y_text = y + (z_height - z_descent) / 2; ctx->gdraw->text(w, ll_x, y_text, text, strlen(text), text_drawtype, text_color_drawtype, text_idx, highlight, 0, glow_eFont_Helvetica, tsize, 0); } } } } else if (45 < rotation && rotation <= 135) { // Horizontal line at bottom and values to the top ctx->gdraw->line(w, ll_x, ur_y, ur_x, ur_y, drawtype, idx, 0); // Calculate max value text height if (draw_text) { ctx->gdraw->get_text_extent("0", 1, text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); line_length = ur_y - ll_y - z_height; if (line_length < 3) line_length = 3; } else { line_length = ur_y - ll_y; } for (i = 0; i < lines; i++) { x = int(ll_x + double(ur_x - ll_x) / (lines - 1) * (lines - 1 - i)); if (i % longquotient == 0) ctx->gdraw->line(w, x, ur_y - line_length, x, ur_y, drawtype, idx, 0); else ctx->gdraw->line( w, x, ur_y - int(2.0 / 3 * line_length), x, ur_y, drawtype, idx, 0); if (draw_text && i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (text_idx >= 0 && z_height < ur_y - ll_y) { if (i == lines - 1) x_text = x; else if (i == 0) x_text = x - z_width; else x_text = x - (z_width) / 2; ctx->gdraw->text(w, x_text, ll_y + z_height - z_descent, text, strlen(text), text_drawtype, text_color_drawtype, text_idx, highlight, 0, glow_eFont_Helvetica, tsize, 0); } } } } else if (135 < rotation && rotation <= 225) { // Vertical line to the left and values to the right ctx->gdraw->line(w, ll_x, ll_y, ll_x, ur_y, drawtype, idx, 0); // Calculate max value text width if (draw_text) { for (i = 0; i < lines; i++) { if (i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (max_z_width < z_width) max_z_width = z_width; } } x_text = ur_x - max_z_width; line_length = ur_x - ll_x - max_z_width; if (line_length < 3) line_length = 3; } else { x_text = ur_x; line_length = ur_x - ll_x; } for (i = 0; i < lines; i++) { y = int(ll_y + double(ur_y - ll_y) / (lines - 1) * (lines - 1 - i)); if (i % longquotient == 0) ctx->gdraw->line(w, ll_x, y, ll_x + line_length, y, drawtype, idx, 0); else ctx->gdraw->line( w, ll_x, y, ll_x + int(2.0 / 3 * line_length), y, drawtype, idx, 0); format_text(text, format, max_value - i * increment); if (draw_text && text_idx >= 0 && max_z_width < ur_x - ll_x && i % valuequotient == 0) { if (i == lines - 1) y_text = y + z_height - z_descent - 3; else if (i == 0) y_text = y; else y_text = y + (z_height - z_descent) / 2; ctx->gdraw->text(w, x_text, y_text, text, strlen(text), text_drawtype, text_color_drawtype, text_idx, highlight, 0, glow_eFont_Helvetica, tsize, 0); } } } else { // if ( 225 < rotation && rotation <= 315) // Horizontal line at top and values at the bottom ctx->gdraw->line(w, ll_x, ll_y, ur_x, ll_y, drawtype, idx, 0); // Calculate max value text height if (draw_text) { ctx->gdraw->get_text_extent("0", 1, text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); line_length = ur_y - ll_y - (z_height - z_descent); if (line_length < 3) line_length = 3; } else { line_length = ur_y - ll_y; } for (i = 0; i < lines; i++) { x = int(ll_x + double(ur_x - ll_x) / (lines - 1) * i); if (i % longquotient == 0) ctx->gdraw->line(w, x, ll_y, x, ll_y + line_length, drawtype, idx, 0); else ctx->gdraw->line( w, x, ll_y, x, ll_y + int(2.0 / 3 * line_length), drawtype, idx, 0); if (draw_text && i % valuequotient == 0) { format_text(text, format, max_value - i * increment); ctx->gdraw->get_text_extent(text, strlen(text), text_drawtype, MAX(0, text_idx), glow_eFont_Helvetica, &z_width, &z_height, &z_descent, tsize, 0); if (text_idx >= 0 && z_height - z_descent < ur_y - ll_y) { if (i == lines - 1) x_text = x - z_width; else if (i == 0) x_text = x; else x_text = x - (z_width) / 2; ctx->gdraw->text(w, x_text, ur_y, text, strlen(text), text_drawtype, text_color_drawtype, text_idx, highlight, 0, glow_eFont_Helvetica, tsize, 0); } } } } }
static void dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { struct pop_proto_data *frame_data_p; gboolean is_request; gboolean is_continuation; proto_tree *pop_tree, *reqresp_tree; proto_item *ti; gint offset = 0; const guchar *line; gint next_offset; int linelen; int tokenlen; const guchar *next_token; fragment_data *frag_msg = NULL; tvbuff_t *next_tvb = NULL; conversation_t *conversation = NULL; struct pop_data_val *data_val = NULL; gint length_remaining; col_set_str(pinfo->cinfo, COL_PROTOCOL, "POP"); /* * Find the end of the first line. * * Note that "tvb_find_line_end()" will return a value that is * not longer than what's in the buffer, so the "tvb_get_ptr()" * call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); if (pinfo->match_port == pinfo->destport) { is_request = TRUE; is_continuation = FALSE; } else { is_request = FALSE; is_continuation = response_is_continuation(line); } frame_data_p = p_get_proto_data(pinfo->fd, proto_pop); if (!frame_data_p) { conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0); if (conversation == NULL) { /* No conversation, create one */ conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0); } data_val = conversation_get_proto_data(conversation, proto_pop); if (!data_val) { /* * No - create one and attach it. */ data_val = se_alloc0(sizeof(struct pop_data_val)); conversation_add_proto_data(conversation, proto_pop, data_val); } } if (check_col(pinfo->cinfo, COL_INFO)) { /* * Put the first line from the buffer into the summary * if it's a POP request or reply (but leave out the * line terminator). * Otherwise, just call it a continuation. */ if (is_continuation) { length_remaining = tvb_length_remaining(tvb, offset); col_add_fstr(pinfo->cinfo, COL_INFO, "S: DATA fragment, %d byte%s", length_remaining, plurality (length_remaining, "", "s")); } else col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", is_request ? "C" : "S", format_text(line, linelen)); } ti = proto_tree_add_item(tree, proto_pop, tvb, offset, -1, FALSE); pop_tree = proto_item_add_subtree(ti, ett_pop); if (is_continuation) { if (pop_data_desegment) { if (!frame_data_p) { data_val->msg_read_len += tvb_length(tvb); frame_data_p = se_alloc(sizeof(struct pop_proto_data)); frame_data_p->conversation_id = conversation->index; frame_data_p->more_frags = data_val->msg_read_len < data_val->msg_tot_len; p_add_proto_data(pinfo->fd, proto_pop, frame_data_p); } frag_msg = fragment_add_seq_next(tvb, 0, pinfo, frame_data_p->conversation_id, pop_data_segment_table, pop_data_reassembled_table, tvb_length(tvb), frame_data_p->more_frags); next_tvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled DATA", frag_msg, &pop_data_frag_items, NULL, pop_tree); if (next_tvb) { if (imf_handle) call_dissector(imf_handle, next_tvb, pinfo, tree); if (data_val) { /* we have read everything - reset */ data_val->msg_read_len = 0; data_val->msg_tot_len = 0; } pinfo->fragmented = FALSE; } else { pinfo->fragmented = TRUE; } } else { /* * Put the whole packet into the tree as data. */ call_dissector(data_handle,tvb, pinfo, pop_tree); } return; } /* * Put the line into the protocol tree. */ ti = proto_tree_add_string_format(pop_tree, (is_request) ? hf_pop_request : hf_pop_response, tvb, offset, next_offset - offset, "", "%s", tvb_format_text(tvb, offset, next_offset - offset)); reqresp_tree = proto_item_add_subtree(ti, ett_pop_reqresp); /* * Extract the first token, and, if there is a first * token, add it as the request or reply code. */ tokenlen = get_token_len(line, line + linelen, &next_token); if (tokenlen != 0) { proto_tree_add_item(reqresp_tree, (is_request) ? hf_pop_request_command : hf_pop_response_indicator, tvb, offset, tokenlen, FALSE); if (data_val) { if (is_request) { /* see if this is RETR or TOP command */ if (g_ascii_strncasecmp(line, "RETR", 4) == 0 || g_ascii_strncasecmp(line, "TOP", 3) == 0) /* the next response will tell us how many bytes */ data_val->msg_request = TRUE; } else { if (data_val->msg_request) { /* this is a response to a RETR or TOP command */ if (g_ascii_strncasecmp(line, "+OK ", 4) == 0) { /* the message will be sent - work out how many bytes */ data_val->msg_read_len = 0; data_val->msg_tot_len = atoi(line + 4); } data_val->msg_request = FALSE; } } } offset += (gint) (next_token - line); linelen -= (int) (next_token - line); } if (tree) { /* * Add the rest of the first line as request or * reply param/description. */ if (linelen != 0) { proto_tree_add_item(reqresp_tree, (is_request) ? hf_pop_request_parameter : hf_pop_response_description, tvb, offset, linelen, FALSE); } offset = next_offset; /* * Show the rest of the request or response as text, * a line at a time. */ while (tvb_offset_exists(tvb, offset)) { /* * Find the end of the line. */ tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); /* * Put this line. */ proto_tree_add_string_format(pop_tree, (is_request) ? hf_pop_request_data : hf_pop_response_data, tvb, offset, next_offset - offset, "", "%s", tvb_format_text(tvb, offset, next_offset - offset)); offset = next_offset; } } }
bool isMatch(wlan_hdr_t *wlan_hdr) { bool is_bssid_match = false; bool is_ssid_match = false; bool update_bssid = false; bool update_ssid = false; // We want (but might not have) a unicast BSSID and a named SSID. Try // to match the current packet and update our information if possible. if (addresses_equal(&bssid_, &wlan_hdr->bssid)) { is_bssid_match = true; } if ((wlan_hdr->stats.ssid_len > 0) && (wlan_hdr->stats.ssid[0] != 0)) { QByteArray hdr_ssid = QByteArray::fromRawData((const char *)wlan_hdr->stats.ssid, wlan_hdr->stats.ssid_len); if (ssid_ == hdr_ssid) { is_ssid_match = true; } } if (is_bssid_match && is_ssid_match) return true; // Probe requests. if (wlan_hdr->type == MGT_PROBE_REQ) { // Probes with visible SSIDs. Unicast or broadcast. if (is_ssid_match) { if (is_broadcast_ && !is_broadcast_bssid(&wlan_hdr->bssid)) { update_bssid = true; } // Probes with hidden SSIDs. Unicast. } else if ((wlan_hdr->stats.ssid_len == 1) && (wlan_hdr->stats.ssid[0] == 0)) { if (!is_broadcast_ && addresses_equal(&bssid_, &wlan_hdr->bssid)) { is_bssid_match = true; update_ssid = true; } // Probes with no SSID. Broadcast. } else if (ssid_.isEmpty() && wlan_hdr->stats.ssid_len < 1) { if (is_broadcast_ && is_broadcast_bssid(&wlan_hdr->bssid)) { return true; } } // Non-probe requests (responses, beacons, etc) } else { if (is_ssid_match) { if (is_broadcast_ && !is_broadcast_bssid(&wlan_hdr->bssid)) { update_bssid = true; } } else if (wlan_hdr->stats.ssid_len < 1) { // No SSID. is_ssid_match = true; } if (is_bssid_match) { if ((ssid_.isEmpty() || ssid_[0] == '\0') && (wlan_hdr->stats.ssid_len > 0) && (wlan_hdr->stats.ssid[0] != 0) ) { update_ssid = true; } } } if (update_bssid) { updateBssid(wlan_hdr); is_bssid_match = true; } if (update_ssid) { ssid_ = QByteArray::fromRawData((const char *)wlan_hdr->stats.ssid, wlan_hdr->stats.ssid_len); setText(col_ssid_, format_text(wlan_hdr->stats.ssid, wlan_hdr->stats.ssid_len)); is_ssid_match = true; } return is_bssid_match && is_ssid_match; }
int main(int argc, char *argv[]) { int ret; const char *target_device; const char *img_path; if (argv[1][0] != '-') { printf("Unknown Option\n"); return -1; } if (argc >= 4) { target_device = get_device(argv[2][0] - '0'); img_path = argv[3]; } else { target_device = get_device(0); if (argc >= 3) { img_path = argv[2]; } else { img_path = NULL; } } switch (argv[1][1]) { case 'u': case 'U': if (img_path == NULL) { return cavan_dd("u-boot-no-padding.bin", target_device, 0, UBOOT_OFFSET, 0); } else if (strcmp(text_basename(img_path), "u-boot.bin") == 0) { return cavan_dd(img_path, target_device, UBOOT_PADDING_SIZE, UBOOT_OFFSET, 0); } else { return cavan_dd(img_path, target_device, 0, UBOOT_OFFSET, 0); } case 'k': case 'K': return copy_to_emmc("uImage", img_path, target_device, UIMAGE_OFFSET); case 'l': case 'L': return copy_to_emmc("logo.bmp", img_path, target_device, LOGO_OFFSET); case 'b': case 'B': return copy_to_emmc("busybox.img", img_path, target_device, BUSYBOX_OFFSET); case 'c': case 'C': return copy_to_emmc("charge.bmps", img_path, target_device, CARTOON_OFFSET); case 's': case 'S': target_device = format_text("%sp2", target_device); ret = copy_to_emmc("system.img", img_path, target_device, 0); if (ret < 0) { error_msg("copy_to_emmc"); return ret; } break; case 'd': case 'D': target_device = format_text("%sp5", target_device); ret = copy_to_emmc("userdata.img", img_path, target_device, 0); if (ret < 0) { error_msg("copy_to_emmc"); return ret; } break; case 'r': case 'R': switch (argv[1][2]) { case 'a': case 'A': return copy_to_emmc("uramdisk.img", img_path, target_device, RAMDISK_OFFSET); case 'e': case 'E': target_device = format_text("%sp4", target_device); ret = copy_to_emmc("recovery.img", img_path, target_device, 0); if (ret < 0) { error_msg("copy_to_emmc"); return ret; } break; default: printf("Unknown Option\n"); return -1; } break; default: printf("Unknown Option\n"); return -1; } return extend_partition(target_device); }
static void dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { struct smtp_proto_data *spd_frame_data; proto_tree *smtp_tree = NULL; proto_tree *cmdresp_tree; proto_item *ti, *hidden_item; int offset = 0; int request = 0; conversation_t *conversation; struct smtp_session_state *session_state; const guchar *line, *linep, *lineend; guint32 code; int linelen = 0; gint length_remaining; gboolean eom_seen = FALSE; gint next_offset; gint loffset = 0; int cmdlen; fragment_data *frag_msg = NULL; tvbuff_t *next_tvb; /* As there is no guarantee that we will only see frames in the * the SMTP conversation once, and that we will see them in * order - in Wireshark, the user could randomly click on frames * in the conversation in any order in which they choose - we * have to store information with each frame indicating whether * it contains commands or data or an EOM indication. * * XXX - what about frames that contain *both*? TCP is a * byte-stream protocol, and there are no guarantees that * TCP segment boundaries will correspond to SMTP commands * or EOM indications. * * We only need that for the client->server stream; responses * are easy to manage. * * If we have per frame data, use that, else, we must be on the first * pass, so we figure it out on the first pass. */ /* * Find or create the conversation for this. */ conversation = find_or_create_conversation(pinfo); /* * Is there a request structure attached to this conversation? */ session_state = conversation_get_proto_data(conversation, proto_smtp); if (!session_state) { /* * No - create one and attach it. */ session_state = se_alloc(sizeof(struct smtp_session_state)); session_state->smtp_state = SMTP_STATE_READING_CMDS; session_state->crlf_seen = FALSE; session_state->data_seen = FALSE; session_state->msg_read_len = 0; session_state->msg_tot_len = 0; session_state->msg_last = TRUE; session_state->last_nontls_frame = 0; conversation_add_proto_data(conversation, proto_smtp, session_state); } /* Are we doing TLS? * FIXME In my understanding of RFC 2487 client and server can send SMTP cmds * after a rejected TLS negotiation */ if (session_state->last_nontls_frame != 0 && pinfo->fd->num > session_state->last_nontls_frame) { guint16 save_can_desegment; guint32 save_last_nontls_frame; /* This is TLS, not raw SMTP. TLS can desegment */ save_can_desegment = pinfo->can_desegment; pinfo->can_desegment = pinfo->saved_can_desegment; /* Make sure the SSL dissector will not be called again after decryption */ save_last_nontls_frame = session_state->last_nontls_frame; session_state->last_nontls_frame = 0; call_dissector(ssl_handle, tvb, pinfo, tree); pinfo->can_desegment = save_can_desegment; session_state->last_nontls_frame = save_last_nontls_frame; return; } /* Is this a request or a response? */ request = pinfo->destport == pinfo->match_uint; /* * Is there any data attached to this frame? */ spd_frame_data = p_get_proto_data(pinfo->fd, proto_smtp); if (!spd_frame_data) { /* * No frame data. */ if(request) { /* * Create a frame data structure and attach it to the packet. */ spd_frame_data = se_alloc0(sizeof(struct smtp_proto_data)); spd_frame_data->conversation_id = conversation->index; spd_frame_data->more_frags = TRUE; p_add_proto_data(pinfo->fd, proto_smtp, spd_frame_data); } /* * Get the first line from the buffer. * * Note that "tvb_find_line_end()" will, if it doesn't return * -1, return a value that is not longer than what's in the buffer, * and "tvb_find_line_end()" will always return a value that is not * longer than what's in the buffer, so the "tvb_get_ptr()" call * won't throw an exception. */ loffset = offset; while (tvb_offset_exists(tvb, loffset)) { linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, smtp_desegment && pinfo->can_desegment); if (linelen == -1) { if (offset == loffset) { /* * We didn't find a line ending, and we're doing desegmentation; * tell the TCP dissector where the data for this message starts * in the data it handed us, and tell it we need more bytes */ pinfo->desegment_offset = loffset; pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT; return; } else { linelen = tvb_length_remaining(tvb, loffset); next_offset = loffset + linelen; } } line = tvb_get_ptr(tvb, loffset, linelen); /* * Check whether or not this packet is an end of message packet * We should look for CRLF.CRLF and they may be split. * We have to keep in mind that we may see what we want on * two passes through here ... */ if (session_state->smtp_state == SMTP_STATE_READING_DATA) { /* * The order of these is important ... We want to avoid * cases where there is a CRLF at the end of a packet and a * .CRLF at the begining of the same packet. */ if ((session_state->crlf_seen && tvb_strneql(tvb, loffset, ".\r\n", 3) == 0) || tvb_strneql(tvb, loffset, "\r\n.\r\n", 5) == 0) eom_seen = TRUE; length_remaining = tvb_length_remaining(tvb, loffset); if (length_remaining == tvb_reported_length_remaining(tvb, loffset) && tvb_strneql(tvb, loffset + length_remaining - 2, "\r\n", 2) == 0) session_state->crlf_seen = TRUE; else session_state->crlf_seen = FALSE; } /* * OK, Check if we have seen a DATA request. We do it here for * simplicity, but we have to be careful below. */ if (request) { if (session_state->smtp_state == SMTP_STATE_READING_DATA) { /* * This is message data. */ if (eom_seen) { /* Seen the EOM */ /* * EOM. * Everything that comes after it is commands. */ spd_frame_data->pdu_type = SMTP_PDU_EOM; session_state->smtp_state = SMTP_STATE_READING_CMDS; break; } else { /* * Message data with no EOM. */ spd_frame_data->pdu_type = SMTP_PDU_MESSAGE; if (session_state->msg_tot_len > 0) { /* * We are handling a BDAT message. * Check if we have reached end of the data chunk. */ session_state->msg_read_len += tvb_length_remaining(tvb, loffset); if (session_state->msg_read_len == session_state->msg_tot_len) { /* * We have reached end of BDAT data chunk. * Everything that comes after this is commands. */ session_state->smtp_state = SMTP_STATE_READING_CMDS; if (session_state->msg_last) { /* * We have found the LAST data chunk. * The message can now be reassembled. */ spd_frame_data->more_frags = FALSE; } break; /* no need to go through the remaining lines */ } } } } else { /* * This is commands - unless the capture started in the * middle of a session, and we're in the middle of data. * * Commands are not necessarily 4 characters; look * for a space or the end of the line to see where * the putative command ends. */ linep = line; lineend = line + linelen; while (linep < lineend && *linep != ' ') linep++; cmdlen = (int)(linep - line); if (line_is_smtp_command(line, cmdlen)) { if (g_ascii_strncasecmp(line, "DATA", 4) == 0) { /* * DATA command. * This is a command, but everything that comes after it, * until an EOM, is data. */ spd_frame_data->pdu_type = SMTP_PDU_CMD; session_state->smtp_state = SMTP_STATE_READING_DATA; session_state->data_seen = TRUE; } else if (g_ascii_strncasecmp(line, "BDAT", 4) == 0) { /* * BDAT command. * This is a command, but everything that comes after it, * until given length is received, is data. */ guint32 msg_len; msg_len = strtoul (line+5, NULL, 10); spd_frame_data->pdu_type = SMTP_PDU_CMD; session_state->data_seen = TRUE; session_state->msg_tot_len += msg_len; if (msg_len == 0) { /* No data to read, next will be a command */ session_state->smtp_state = SMTP_STATE_READING_CMDS; } else { session_state->smtp_state = SMTP_STATE_READING_DATA; } if (g_ascii_strncasecmp(line+linelen-4, "LAST", 4) == 0) { /* * This is the last data chunk. */ session_state->msg_last = TRUE; if (msg_len == 0) { /* * No more data to expect. * The message can now be reassembled. */ spd_frame_data->more_frags = FALSE; } } else { session_state->msg_last = FALSE; } } else if (g_ascii_strncasecmp(line, "STARTTLS", 8) == 0) { /* * STARTTLS command. * This is a command, but if the response is 220, * everything after the response is TLS. */ session_state->smtp_state = SMTP_STATE_AWAITING_STARTTLS_RESPONSE; spd_frame_data->pdu_type = SMTP_PDU_CMD; } else { /* * Regular command. */ spd_frame_data->pdu_type = SMTP_PDU_CMD; } } else { /* * Assume it's message data. */ spd_frame_data->pdu_type = session_state->data_seen ? SMTP_PDU_MESSAGE : SMTP_PDU_CMD; } } } /* * Step past this line. */ loffset = next_offset; } } /* * From here, we simply add items to the tree and info to the info * fields ... */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMTP"); if (check_col(pinfo->cinfo, COL_INFO)) { /* Add the appropriate type here */ col_clear(pinfo->cinfo, COL_INFO); /* * If it is a request, we have to look things up, otherwise, just * display the right things */ if (request) { /* We must have frame_data here ... */ switch (spd_frame_data->pdu_type) { case SMTP_PDU_MESSAGE: length_remaining = tvb_length_remaining(tvb, offset); col_set_str(pinfo->cinfo, COL_INFO, smtp_data_desegment ? "C: DATA fragment" : "C: Message Body"); col_append_fstr(pinfo->cinfo, COL_INFO, ", %d byte%s", length_remaining, plurality (length_remaining, "", "s")); break; case SMTP_PDU_EOM: col_set_str(pinfo->cinfo, COL_INFO, "C: ."); break; case SMTP_PDU_CMD: loffset = offset; while (tvb_offset_exists(tvb, loffset)) { /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, loffset, linelen); if(loffset == offset) col_append_fstr(pinfo->cinfo, COL_INFO, "C: %s", format_text(line, linelen)); else { col_append_fstr(pinfo->cinfo, COL_INFO, " | %s", format_text(line, linelen)); } loffset = next_offset; } break; } } else { loffset = offset; while (tvb_offset_exists(tvb, loffset)) { /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, loffset, linelen); if (loffset == offset) col_append_fstr(pinfo->cinfo, COL_INFO, "S: %s", format_text(line, linelen)); else { col_append_fstr(pinfo->cinfo, COL_INFO, " | %s", format_text(line, linelen)); } loffset = next_offset; } } } if (tree) { /* Build the tree info ... */ ti = proto_tree_add_item(tree, proto_smtp, tvb, offset, -1, ENC_NA); smtp_tree = proto_item_add_subtree(ti, ett_smtp); } if (request) { /* * Check out whether or not we can see a command in there ... * What we are looking for is not data_seen and the word DATA * and not eom_seen. * * We will see DATA and session_state->data_seen when we process the * tree view after we have seen a DATA packet when processing * the packet list pane. * * On the first pass, we will not have any info on the packets * On second and subsequent passes, we will. */ switch (spd_frame_data->pdu_type) { case SMTP_PDU_MESSAGE: if (smtp_data_desegment) { frag_msg = fragment_add_seq_next(tvb, 0, pinfo, spd_frame_data->conversation_id, smtp_data_segment_table, smtp_data_reassembled_table, tvb_length(tvb), spd_frame_data->more_frags); } else { /* * Message body. * Put its lines into the protocol tree, a line at a time. */ dissect_smtp_data(tvb, offset, smtp_tree); } break; case SMTP_PDU_EOM: /* * End-of-message-body indicator. * * XXX - what about stuff after the first line? * Unlikely, as the client should wait for a response to the * DATA command this terminates before sending another * request, but we should probably handle it. */ proto_tree_add_text(smtp_tree, tvb, offset, linelen, "C: ."); if (smtp_data_desegment) { /* add final data segment */ if (loffset) fragment_add_seq_next(tvb, 0, pinfo, spd_frame_data->conversation_id, smtp_data_segment_table, smtp_data_reassembled_table, loffset, spd_frame_data->more_frags); /* terminate the desegmentation */ frag_msg = fragment_end_seq_next (pinfo, spd_frame_data->conversation_id, smtp_data_segment_table, smtp_data_reassembled_table); } break; case SMTP_PDU_CMD: /* * Command. * * XXX - what about stuff after the first line? * Unlikely, as the client should wait for a response to the * previous command before sending another request, but we * should probably handle it. */ loffset = offset; while (tvb_offset_exists(tvb, loffset)) { /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE); if (linelen >= 4) cmdlen = 4; else cmdlen = linelen; hidden_item = proto_tree_add_boolean(smtp_tree, hf_smtp_req, tvb, 0, 0, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); /* * Put the command line into the protocol tree. */ ti = proto_tree_add_item(smtp_tree, hf_smtp_command_line, tvb, loffset, next_offset - loffset, ENC_ASCII|ENC_NA); cmdresp_tree = proto_item_add_subtree(ti, ett_smtp_cmdresp); proto_tree_add_item(cmdresp_tree, hf_smtp_req_command, tvb, loffset, cmdlen, ENC_ASCII|ENC_NA); if (linelen > 5) { proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb, loffset + 5, linelen - 5, ENC_ASCII|ENC_NA); } if (smtp_data_desegment && !spd_frame_data->more_frags) { /* terminate the desegmentation */ frag_msg = fragment_end_seq_next (pinfo, spd_frame_data->conversation_id, smtp_data_segment_table, smtp_data_reassembled_table); } /* * Step past this line. */ loffset = next_offset; } } if (smtp_data_desegment) { next_tvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled SMTP", frag_msg, &smtp_data_frag_items, NULL, smtp_tree); if (next_tvb) { /* XXX: this is presumptious - we may have negotiated something else */ if (imf_handle) { call_dissector(imf_handle, next_tvb, pinfo, tree); } else { /* * Message body. * Put its lines into the protocol tree, a line at a time. */ dissect_smtp_data(tvb, offset, smtp_tree); } pinfo->fragmented = FALSE; } else { pinfo->fragmented = TRUE; } } } else { /* * Process the response, a line at a time, until we hit a line * that doesn't have a continuation indication on it. */ if (tree) { hidden_item = proto_tree_add_boolean(smtp_tree, hf_smtp_rsp, tvb, 0, 0, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); } while (tvb_offset_exists(tvb, offset)) { /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); if (tree) { /* * Put it into the protocol tree. */ ti = proto_tree_add_item(smtp_tree, hf_smtp_response, tvb, offset, next_offset - offset, ENC_ASCII|ENC_NA); cmdresp_tree = proto_item_add_subtree(ti, ett_smtp_cmdresp); } else cmdresp_tree = NULL; line = tvb_get_ptr(tvb, offset, linelen); if (linelen >= 3 && isdigit(line[0]) && isdigit(line[1]) && isdigit(line[2])) { /* * We have a 3-digit response code. */ code = (line[0] - '0')*100 + (line[1] - '0')*10 + (line[2] - '0'); /* * If we're awaiting the response to a STARTTLS code, this * is it - if it's 220, all subsequent traffic will * be TLS, otherwise we're back to boring old SMTP. */ if (session_state->smtp_state == SMTP_STATE_AWAITING_STARTTLS_RESPONSE) { if (code == 220) { /* This is the last non-TLS frame. */ session_state->last_nontls_frame = pinfo->fd->num; } session_state->smtp_state = SMTP_STATE_READING_CMDS; } if (tree) { /* * Put the response code and parameters into the protocol tree. */ proto_tree_add_uint(cmdresp_tree, hf_smtp_rsp_code, tvb, offset, 3, code); if (linelen >= 4) { proto_tree_add_item(cmdresp_tree, hf_smtp_rsp_parameter, tvb, offset + 4, linelen - 4, ENC_ASCII|ENC_NA); } } } /* * Step past this line. */ offset = next_offset; } } }
static void dissect_ftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { gboolean is_request; proto_tree *ftp_tree = NULL; proto_tree *reqresp_tree = NULL; proto_item *ti, *hidden_item; gint offset = 0; const guchar *line; guint32 code; gchar code_str[4]; gboolean is_port_request = FALSE; gboolean is_pasv_response = FALSE; gboolean is_epasv_response = FALSE; gint next_offset; int linelen; int tokenlen; const guchar *next_token; guint32 pasv_ip; guint32 ftp_ip; guint16 ftp_port; address ftp_ip_address; gboolean ftp_nat; conversation_t *conversation; ftp_ip_address = pinfo->src; if (pinfo->match_uint == pinfo->destport) is_request = TRUE; else is_request = FALSE; col_set_str(pinfo->cinfo, COL_PROTOCOL, "FTP"); /* * Find the end of the first line. * * Note that "tvb_find_line_end()" will return a value that is * not longer than what's in the buffer, so the "tvb_get_ptr()" * call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); /* * Put the first line from the buffer into the summary * (but leave out the line terminator). */ col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", is_request ? "Request" : "Response", format_text(line, linelen)); if (tree) { ti = proto_tree_add_item(tree, proto_ftp, tvb, offset, -1, ENC_NA); ftp_tree = proto_item_add_subtree(ti, ett_ftp); if (is_request) { hidden_item = proto_tree_add_boolean(ftp_tree, hf_ftp_request, tvb, 0, 0, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); hidden_item = proto_tree_add_boolean(ftp_tree, hf_ftp_response, tvb, 0, 0, FALSE); PROTO_ITEM_SET_HIDDEN(hidden_item); } else { hidden_item = proto_tree_add_boolean(ftp_tree, hf_ftp_request, tvb, 0, 0, FALSE); PROTO_ITEM_SET_HIDDEN(hidden_item); hidden_item = proto_tree_add_boolean(ftp_tree, hf_ftp_response, tvb, 0, 0, TRUE); PROTO_ITEM_SET_HIDDEN(hidden_item); } /* * Put the line into the protocol tree. */ ti = proto_tree_add_text(ftp_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset)); reqresp_tree = proto_item_add_subtree(ti, ett_ftp_reqresp); } if (is_request) { /* * Extract the first token, and, if there is a first * token, add it as the request. */ tokenlen = get_token_len(line, line + linelen, &next_token); if (tokenlen != 0) { if (tree) { proto_tree_add_item(reqresp_tree, hf_ftp_request_command, tvb, offset, tokenlen, ENC_ASCII|ENC_NA); } if (strncmp(line, "PORT", tokenlen) == 0) is_port_request = TRUE; } } else { /* * This is a response; the response code is 3 digits, * followed by a space or hyphen, possibly followed by * text. * * If the line doesn't start with 3 digits, it's part of * a continuation. * * XXX - keep track of state in the first pass, and * treat non-continuation lines not beginning with digits * as errors? */ if (linelen >= 3 && isdigit(line[0]) && isdigit(line[1]) && isdigit(line[2])) { /* * One-line reply, or first or last line * of a multi-line reply. */ tvb_get_nstringz0(tvb, offset, sizeof(code_str), code_str); code = strtoul(code_str, NULL, 10); if (tree) { proto_tree_add_uint(reqresp_tree, hf_ftp_response_code, tvb, offset, 3, code); } /* * See if it's a passive-mode response. * * XXX - does anybody do FOOBAR, as per RFC * 1639, or has that been supplanted by RFC 2428? */ if (code == 227) is_pasv_response = TRUE; /* * Responses to EPSV command, as per RFC 2428 * XXX - handle IPv6? */ if (code == 229) is_epasv_response = TRUE; /* * Skip the 3 digits and, if present, the * space or hyphen. */ if (linelen >= 4) next_token = line + 4; else next_token = line + linelen; } else { /* * Line doesn't start with 3 digits; assume it's * a line in the middle of a multi-line reply. */ next_token = line; } } offset += (gint) (next_token - line); linelen -= (int) (next_token - line); line = next_token; if (tree) { /* * Add the rest of the first line as request or * reply data. */ if (linelen != 0) { if (is_request) { proto_tree_add_item(reqresp_tree, hf_ftp_request_arg, tvb, offset, linelen, ENC_ASCII|ENC_NA); } else { proto_tree_add_item(reqresp_tree, hf_ftp_response_arg, tvb, offset, linelen, ENC_ASCII|ENC_NA); } } offset = next_offset; } /* * If this is a PORT request or a PASV response, handle it. */ if (is_port_request) { if (parse_port_pasv(line, linelen, &ftp_ip, &ftp_port)) { if (tree) { proto_tree_add_ipv4(reqresp_tree, hf_ftp_active_ip, tvb, 0, 0, ftp_ip); proto_tree_add_uint(reqresp_tree, hf_ftp_active_port, tvb, 0, 0, ftp_port); } SET_ADDRESS(&ftp_ip_address, AT_IPv4, 4, (const guint8 *)&ftp_ip); ftp_nat = !ADDRESSES_EQUAL(&pinfo->src, &ftp_ip_address); if (ftp_nat) { if (tree) { proto_tree_add_boolean( reqresp_tree, hf_ftp_active_nat, tvb, 0, 0, ftp_nat); } } } } if (is_pasv_response) { if (linelen != 0) { /* * This frame contains a PASV response; set up a * conversation for the data. */ if (parse_port_pasv(line, linelen, &pasv_ip, &ftp_port)) { if (tree) { proto_tree_add_ipv4(reqresp_tree, hf_ftp_pasv_ip, tvb, 0, 0, pasv_ip); proto_tree_add_uint(reqresp_tree, hf_ftp_pasv_port, tvb, 0, 0, ftp_port); } SET_ADDRESS(&ftp_ip_address, AT_IPv4, 4, (const guint8 *)&pasv_ip); ftp_nat = !ADDRESSES_EQUAL(&pinfo->src, &ftp_ip_address); if (ftp_nat) { if (tree) { proto_tree_add_boolean(reqresp_tree, hf_ftp_pasv_nat, tvb, 0, 0, ftp_nat); } } /* * We use "ftp_ip_address", so that if * we're NAT'd we look for the un-NAT'd * connection. * * XXX - should this call to * "find_conversation()" just use * "ftp_ip_address" and "server_port", and * wildcard everything else? */ conversation = find_conversation(pinfo->fd->num, &ftp_ip_address, &pinfo->dst, PT_TCP, ftp_port, 0, NO_PORT_B); if (conversation == NULL) { /* * XXX - should this call to "conversation_new()" * just use "ftp_ip_address" and "server_port", * and wildcard everything else? * * XXX - what if we did find a conversation? As * we create it only on the first pass through the * packets, if we find one, it's presumably an * unrelated conversation. Should we remove the * old one from the hash table and put this one in * its place? Can the conversation code handle * conversations not in the hash table? Or should * we make conversations support start and end * frames, as circuits do, and treat this as an * indication that one conversation was closed and * a new one was opened? */ conversation = conversation_new( pinfo->fd->num, &ftp_ip_address, &pinfo->dst, PT_TCP, ftp_port, 0, NO_PORT2); conversation_set_dissector(conversation, ftpdata_handle); } } } } if (is_epasv_response) { if (linelen != 0) { /* * This frame contains an EPSV response; set up a * conversation for the data. */ if (parse_extended_pasv_response(line, linelen, &ftp_port)) { /* Add port number to tree */ if (tree) { proto_tree_add_uint(reqresp_tree, hf_ftp_pasv_port, tvb, 0, 0, ftp_port); } /* Find/create conversation for data */ conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_TCP, ftp_port, 0, NO_PORT_B); if (conversation == NULL) { conversation = conversation_new( pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_TCP, ftp_port, 0, NO_PORT2); conversation_set_dissector(conversation, ftpdata_handle); } } } } if (tree) { /* * Show the rest of the request or response as text, * a line at a time. * XXX - only if there's a continuation indicator? */ while (tvb_offset_exists(tvb, offset)) { /* * Find the end of the line. */ tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); /* * Put this line. */ proto_tree_add_text(ftp_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset)); offset = next_offset; } } }
static void dissect_gift(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_item *ti, *hidden_item; proto_tree *gift_tree, *cmd_tree; gboolean is_request; gint offset = 0; const guchar *line; gint next_offset; int linelen; int tokenlen; const guchar *next_token; /* set "Protocol" column text */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "giFT"); /* determine whether it is a request to or response from the server */ if (pinfo->match_uint == pinfo->destport) is_request = TRUE; else is_request = FALSE; linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); /* set "Info" column text */ if (check_col(pinfo->cinfo, COL_INFO)) col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", is_request ? "Request" : "Response", format_text(line, linelen)); /* if tree != NULL, build protocol tree */ if (tree) { ti = proto_tree_add_item(tree, proto_gift, tvb, 0, -1, ENC_NA); gift_tree = proto_item_add_subtree(ti, ett_gift); if (is_request) { hidden_item = proto_tree_add_boolean(gift_tree, hf_gift_request, tvb, 0, 0, TRUE); } else { hidden_item = proto_tree_add_boolean(gift_tree, hf_gift_response, tvb, 0, 0, TRUE); } PROTO_ITEM_SET_HIDDEN(hidden_item); ti = proto_tree_add_text(gift_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset)); cmd_tree = proto_item_add_subtree(ti, ett_gift_cmd); tokenlen = get_token_len(line, line + linelen, &next_token); if (tokenlen != 0) { if (is_request) { proto_tree_add_text(cmd_tree, tvb, offset, tokenlen, "Request Command: %s", format_text(line, tokenlen)); } else { proto_tree_add_text(cmd_tree, tvb, offset, tokenlen, "Response Command: %s", format_text(line, tokenlen)); } offset += (gint) (next_token - line); linelen -= (int) (next_token - line); line = next_token; } if (linelen != 0) { if (is_request) { proto_tree_add_text(cmd_tree, tvb, offset, linelen, "Request Arg: %s", format_text(line, linelen)); } else { proto_tree_add_text(cmd_tree, tvb, offset, linelen, "Response Arg: %s", format_text(line, linelen)); } } } }
static void dissect_imap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { gboolean is_request; proto_tree *imap_tree, *reqresp_tree; proto_item *ti, *hidden_item; gint offset = 0; const guchar *line; gint next_offset; int linelen; int tokenlen; const guchar *next_token; col_set_str(pinfo->cinfo, COL_PROTOCOL, "IMAP"); if (pinfo->match_uint == pinfo->destport) is_request = TRUE; else is_request = FALSE; if (check_col(pinfo->cinfo, COL_INFO)) { /* * Put the first line from the buffer into the summary * (but leave out the line terminator). */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", is_request ? "Request" : "Response", format_text(line, linelen)); } if (tree) { ti = proto_tree_add_item(tree, proto_imap, tvb, offset, -1, ENC_NA); imap_tree = proto_item_add_subtree(ti, ett_imap); hidden_item = proto_tree_add_boolean(imap_tree, hf_imap_isrequest, tvb, 0, 0, is_request); PROTO_ITEM_SET_HIDDEN(hidden_item); while(tvb_length_remaining(tvb, offset) > 2) { /* * Find the end of each line * * Note that "tvb_find_line_end()" will return a value that is * not longer than what's in the buffer, so the "tvb_get_ptr()" * call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); /* * Put the line into the protocol tree. */ ti = proto_tree_add_item(imap_tree, hf_imap_line, tvb, offset, next_offset - offset, ENC_ASCII|ENC_NA); reqresp_tree = proto_item_add_subtree(ti, ett_imap_reqresp); /* * Show each line as tags + requests or replies. */ /* * Extract the first token, and, if there is a first * token, add it as the request or reply tag. */ tokenlen = get_token_len(line, line + linelen, &next_token); if (tokenlen != 0) { proto_tree_add_item(reqresp_tree, (is_request) ? hf_imap_request_tag : hf_imap_response_tag, tvb, offset, tokenlen, ENC_ASCII|ENC_NA); offset += (gint) (next_token - line); linelen -= (int) (next_token - line); line = next_token; } /* * Add the rest of the line as request or reply data. */ if (linelen != 0) { proto_tree_add_item(reqresp_tree, (is_request) ? hf_imap_request : hf_imap_response, tvb, offset, linelen, ENC_ASCII|ENC_NA); } offset += linelen+2; /* Skip over last line and \r\n at the end of it */ } } }
static void dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *icap_tree = NULL; proto_item *ti = NULL; proto_item *hidden_item; gint offset = 0; const guchar *line; gint next_offset; const guchar *linep, *lineend; int linelen; guchar c; icap_type_t icap_type; int datalen; col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP"); /* * Put the first line from the buffer into the summary * if it's an ICAP header (but leave out the * line terminator). * Otherwise, just call it a continuation. * * Note that "tvb_find_line_end()" will return a value that * is not longer than what's in the buffer, so the * "tvb_get_ptr()" call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); icap_type = ICAP_OTHER; /* type not known yet */ if (is_icap_message(line, linelen, &icap_type)) col_add_str(pinfo->cinfo, COL_INFO, format_text(line, linelen)); else col_set_str(pinfo->cinfo, COL_INFO, "Continuation"); if (tree) { ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1, ENC_NA); icap_tree = proto_item_add_subtree(ti, ett_icap); } /* * Process the packet data, a line at a time. */ icap_type = ICAP_OTHER; /* type not known yet */ while (tvb_offset_exists(tvb, offset)) { gboolean is_icap = FALSE; gboolean loop_done = FALSE; /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); /* * Get a buffer that refers to the line. */ line = tvb_get_ptr(tvb, offset, linelen); lineend = line + linelen; /* * find header format */ if (is_icap_message(line, linelen, &icap_type)) { goto is_icap_header; } /* * if it looks like a blank line, end of header perhaps? */ if (linelen == 0) { goto is_icap_header; } /* * No. Does it look like a header? */ linep = line; loop_done = FALSE; while (linep < lineend && (!loop_done)) { c = *linep++; /* * This must be a CHAR to be part of a token; that * means it must be ASCII. */ if (!isascii(c)) { is_icap = FALSE; break; /* not ASCII, thus not a CHAR */ } /* * This mustn't be a CTL to be part of a token. * * XXX - what about leading LWS on continuation * lines of a header? */ if (iscntrl(c)) { is_icap = FALSE; break; /* CTL, not part of a header */ } switch (c) { case '(': case ')': case '<': case '>': case '@': case ',': case ';': case '\\': case '"': case '/': case '[': case ']': case '?': case '=': case '{': case '}': /* * It's a separator, so it's not part of a * token, so it's not a field name for the * beginning of a header. * * (We don't have to check for HT; that's * already been ruled out by "iscntrl()".) * * XXX - what about ' '? HTTP's checks * check for that. */ is_icap = FALSE; loop_done = TRUE; break; case ':': /* * This ends the token; we consider this * to be a header. */ goto is_icap_header; } } /* * We don't consider this part of an ICAP message, * so we don't display it. * (Yeah, that means we don't display, say, a text/icap * page, but you can get that from the data pane.) */ if (!is_icap) break; is_icap_header: if (tree) { proto_tree_add_text(icap_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset) ); } offset = next_offset; } if (tree) { switch (icap_type) { case ICAP_OPTIONS: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_options, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_REQMOD: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_reqmod, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_RESPMOD: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_respmod, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_RESPONSE: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_response, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_OTHER: default: break; } } datalen = tvb_length_remaining(tvb, offset); if (datalen > 0) { call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo, icap_tree); } }