void DDS_Dissector::dissect_transport_header (proto_tree* ltree, const DCPS::TransportHeader& header, gint& offset) { gint len; offset += sizeof(header.protocol_) - 2; // skip preamble // hf_version len = sizeof(header.protocol_) - offset; const guint8 *data_ptr = reinterpret_cast<const guint8*>(header.protocol_ + offset); proto_tree_add_bytes_format_value (ltree, hf_version, tvb_, offset, len, data_ptr, "%d.%d", header.protocol_[4], header.protocol_[5]); offset += len; // hf_flags len = sizeof(ACE_CDR::Octet); proto_tree_add_bitmask(ltree, tvb_, offset, hf_flags, ett_trans_flags, flags_fields, FALSE); offset += len; offset += sizeof(header.reserved_); // skip reserved // hf_length len = sizeof(header.length_); proto_tree_add_uint_format_value(ltree, hf_length, tvb_, offset, len, header.length_, "%d octets", header.length_); offset += len; // hf_sequence size_t size = 0, padding = 0; gen_find_size(header.sequence_, size, padding); len = static_cast<gint>(size); proto_tree_add_uint64(ltree, hf_sequence, tvb_, offset, len, gint64(header.sequence_.getValue())); offset += len; // hf_source len = sizeof(header.source_); proto_tree_add_uint(ltree, hf_source, tvb_, offset, len, guint32(header.source_)); offset += len; }
void ArticleView::AppendData(gchar *data, const gchar *oword, const gchar *real_oword) { std::string mark; guint32 sec_size=0; const guint32 data_size=get_uint32(data); data+=sizeof(guint32); const gchar *p=data; bool first_time = true; size_t iPlugin; size_t nPlugins = gpAppFrame->oStarDictPlugins->ParseDataPlugins.nplugins(); unsigned int parsed_size; ParseResult parse_result; while (guint32(p - data)<data_size) { if (first_time) first_time=false; else mark+= "\n"; for (iPlugin = 0; iPlugin < nPlugins; iPlugin++) { parse_result.clear(); if (gpAppFrame->oStarDictPlugins->ParseDataPlugins.parse(iPlugin, p, &parsed_size, parse_result, oword)) { p += parsed_size; break; } } if (iPlugin != nPlugins) { append_and_mark_orig_word(mark, real_oword, LinksPosList()); mark.clear(); append_data_parse_result(real_oword, parse_result); parse_result.clear(); continue; } switch (*p) { case 'm': //case 'l': //TODO: convert from local encoding to utf-8 p++; sec_size = strlen(p); if (sec_size) { gchar *m_str = g_markup_escape_text(p, sec_size); mark+=m_str; g_free(m_str); } sec_size++; break; case 'g': p++; sec_size=strlen(p); if (sec_size) { mark+=p; } sec_size++; break; case 'x': p++; sec_size = strlen(p) + 1; mark+= _("XDXF data parsing plug-in is not found!"); break; case 'k': p++; sec_size = strlen(p) + 1; mark+= _("PowerWord data parsing plug-in is not found!"); break; case 'w': p++; sec_size = strlen(p) + 1; mark+= _("Wiki data parsing plug-in is not found!"); break; case 'h': p++; sec_size = strlen(p) + 1; mark+= _("HTML data parsing plug-in is not found!"); break; case 'n': p++; sec_size = strlen(p) + 1; mark+= _("WordNet data parsing plug-in is not found!"); break; case 't': p++; sec_size = strlen(p); if (sec_size) { mark += "[<span foreground=\"blue\">"; gchar *m_str = g_markup_escape_text(p, sec_size); mark += m_str; g_free(m_str); mark += "</span>]"; } sec_size++; break; case 'y': p++; sec_size = strlen(p); if (sec_size) { mark += "[<span foreground=\"red\">"; gchar *m_str = g_markup_escape_text(p, sec_size); mark += m_str; g_free(m_str); mark += "</span>]"; } sec_size++; break; case 'r': p++; sec_size = strlen(p); if(sec_size) { append_and_mark_orig_word(mark, real_oword, LinksPosList()); mark.clear(); append_resource_file_list(p); } sec_size++; break; /*case 'W': { p++; sec_size=g_ntohl(get_uint32(p)); //TODO: sound button. sec_size += sizeof(guint32); } break;*/ case 'P': { p++; sec_size=g_ntohl(get_uint32(p)); if (sec_size) { if (for_float_win) { append_and_mark_orig_word(mark, real_oword, LinksPosList()); mark.clear(); append_pixbuf(NULL); } else { GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(loader, (const guchar *)(p+sizeof(guint32)), sec_size, NULL); gdk_pixbuf_loader_close(loader, NULL); GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); if (pixbuf) { append_and_mark_orig_word(mark, real_oword, LinksPosList()); mark.clear(); append_pixbuf(pixbuf); } else { mark += _("<span foreground=\"red\">[Load image error!]</span>"); } g_object_unref(loader); } } else { mark += _("<span foreground=\"red\">[Missing Image]</span>"); } sec_size += sizeof(guint32); } break; default: if (g_ascii_isupper(*p)) { p++; sec_size=g_ntohl(get_uint32(p)); sec_size += sizeof(guint32); } else { p++; sec_size = strlen(p)+1; } mark += _("Unknown data type, please upgrade StarDict!"); break; } p += sec_size; } append_and_mark_orig_word(mark, real_oword, LinksPosList()); }
bool DictBase::SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data) { int nWord = SearchWords.size(); std::vector<bool> WordFind(nWord, false); int nfound=0; if (dictfile) fseek(dictfile, idxitem_offset, SEEK_SET); if (dictfile) fread(origin_data, idxitem_size, 1, dictfile); else dictdzfile->read(origin_data, idxitem_offset, idxitem_size); gchar *p = origin_data; guint32 sec_size; int j; if (!sametypesequence.empty()) { gint sametypesequence_len = sametypesequence.length(); for (int i=0; i<sametypesequence_len-1; i++) { switch (sametypesequence[i]) { case 'm': case 't': case 'y': case 'l': case 'g': case 'x': case 'k': case 'w': case 'h': for (j=0; j<nWord; j++) // KMP() is faster than strstr() in theory. Really? Always be true? //if (!WordFind[j] && strstr(p, SearchWords[j].c_str())) { if (!WordFind[j] && KMP(p, strlen(p), SearchWords[j].c_str())!=-1) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; sec_size = strlen(p)+1; p+=sec_size; break; default: if (g_ascii_isupper(sametypesequence[i])) { sec_size = get_uint32(p); sec_size += sizeof(guint32); } else { sec_size = strlen(p)+1; } p+=sec_size; } } switch (sametypesequence[sametypesequence_len-1]) { case 'm': case 't': case 'y': case 'l': case 'g': case 'x': case 'k': case 'w': case 'h': sec_size = idxitem_size - (p-origin_data); for (j=0; j<nWord; j++) //if (!WordFind[j] && g_strstr_len(p, sec_size, SearchWords[j].c_str())) { if (!WordFind[j] && KMP(p, sec_size, SearchWords[j].c_str())!=-1) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; break; } } else { while (guint32(p - origin_data)<idxitem_size) { switch (*p) { case 'm': case 't': case 'y': case 'l': case 'g': case 'x': case 'k': case 'w': case 'h': for (j=0; j<nWord; j++) if (!WordFind[j] && strstr(p, SearchWords[j].c_str())) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; sec_size = strlen(p)+1; p+=sec_size; break; default: if (g_ascii_isupper(*p)) { sec_size = get_uint32(p); sec_size += sizeof(guint32); } else { sec_size = strlen(p)+1; } p+=sec_size; } } } return false; }
bool DictBase::SearchData(std::vector<std::string> &SearchWords, guint32 idxitem_offset, guint32 idxitem_size, gchar *origin_data) { const int nWord = SearchWords.size(); std::vector<bool> WordFind(nWord, false); int nfound=0; if (dictfile) fseek(dictfile, idxitem_offset, SEEK_SET); if (dictfile) { size_t fread_size; fread_size = fread(origin_data, idxitem_size, 1, dictfile); if (fread_size != 1) { g_print("fread error!\n"); } } else { dictdzfile->read(origin_data, idxitem_offset, idxitem_size); } gchar *p = origin_data; guint32 sec_size; int j; if (!sametypesequence.empty()) { const gint sametypesequence_len = sametypesequence.length(); for (int i=0; i<sametypesequence_len-1; i++) { if(is_dict_data_type_search_data(sametypesequence[i])) { sec_size = strlen(p); for (j=0; j<nWord; j++) // KMP() is faster than strstr() in theory. Really? Always be true? if (!WordFind[j] && KMP(p, sec_size, SearchWords[j].c_str())!=-1) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; sec_size += sizeof(gchar); p+=sec_size; } else { if (g_ascii_isupper(sametypesequence[i])) { sec_size = g_ntohl(get_uint32(p)); sec_size += sizeof(guint32); } else { sec_size = strlen(p)+1; } p+=sec_size; } } if(is_dict_data_type_search_data(sametypesequence[sametypesequence_len-1])) { sec_size = idxitem_size - (p-origin_data); for (j=0; j<nWord; j++) if (!WordFind[j] && KMP(p, sec_size, SearchWords[j].c_str())!=-1) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; } } else { while (guint32(p - origin_data)<idxitem_size) { if(is_dict_data_type_search_data(*p)) { for (j=0; j<nWord; j++) if (!WordFind[j] && strstr(p, SearchWords[j].c_str())) { WordFind[j] = true; ++nfound; } if (nfound==nWord) return true; sec_size = strlen(p)+1; p+=sec_size; } else { if (g_ascii_isupper(*p)) { sec_size = g_ntohl(get_uint32(p)); sec_size += sizeof(guint32); } else { sec_size = strlen(p)+1; } p+=sec_size; } } } return false; }
void convert_with_module(struct convert_module *mod, gchar *src, GString *dest) { size_t data_size, sec_size; data_size = get_uint32(src); src += sizeof(guint32); const gchar *p = src; while (guint32(p - src) < data_size) { switch (*p) { case 'm': case 'l': p++; sec_size = strlen(p); if (sec_size) { gchar *m_str = g_markup_escape_text(p, sec_size); mod->convert(m_str, dest); g_free(m_str); } sec_size++; break; case 'g': p++; sec_size = strlen(p); if (sec_size) { g_string_append(dest, "<pre>\n"); g_string_append(dest, p); g_string_append(dest, "\n</pre>"); } sec_size++; break; case 'x': case 'k': case 'w': case 'h': p++; sec_size = strlen(p) + 1; g_string_append(dest, "<p class=\"error\">Format not supported.</p>"); break; case 't': case 'y': p++; sec_size = strlen(p); if (sec_size) { g_string_append_printf(dest, "<div class=\"%c\">", *p); gchar *m_str = g_markup_escape_text(p, sec_size); g_string_append(dest, m_str); g_free(m_str); g_string_append(dest, "</div>\n"); } sec_size++; break; case 'W': p++; sec_size = ntohl(get_uint32(p)); // enable sound button. sec_size += sizeof(guint32); break; case 'P': p++; sec_size = ntohl(get_uint32(p)); if (sec_size) { // TODO: extract images from here g_string_append(dest, "<span foreground=\"red\">[Missing Image]</span>"); } else { g_string_append(dest, "<span foreground=\"red\">[Missing Image]</span>"); } sec_size += sizeof(guint32); break; default: if (g_ascii_isupper(*p)) { p++; sec_size = ntohl(get_uint32(p)); sec_size += sizeof(guint32); } else { p++; sec_size = strlen(p) + 1; } g_string_append(dest, "<p class=\"error\">Unknown data type.</p>"); break; } p += sec_size; } }
bool LaserdockDevice::version_minor_number(uint32_t *minor) { return guint32(d->devh_ctl, 0X8C, minor); }
bool LaserdockDevice::ringbuffer_empty_sample_count(uint32_t *count) { return guint32(d->devh_ctl, 0X8A, count); }
bool LaserdockDevice::bulk_packet_sample_count(uint32_t *count) { return guint32(d->devh_ctl, 0x8E, count); }
bool LaserdockDevice::sample_element_count(uint32_t *count) { return guint32(d->devh_ctl, 0X85, count); }
bool LaserdockDevice::max_dac_value(uint32_t *value) { return guint32(d->devh_ctl, 0x88, value); }
bool LaserdockDevice::max_dac_rate(uint32_t *rate) { return guint32(d->devh_ctl, 0X84, rate); }
static string parse_data(const gchar *data) { if (!data) return ""; string res; guint32 data_size, sec_size=0; gchar *m_str; const gchar *p=data; data_size=*((guint32 *)p); p+=sizeof(guint32); while (guint32(p - data)<data_size) { switch (*p++) { case 'm': case 'l': //need more work... case 'g': sec_size = strlen(p); if (sec_size) { res+="\n"; m_str = g_strndup(p, sec_size); res += m_str; g_free(m_str); } sec_size++; break; case 'x': sec_size = strlen(p); if (sec_size) { res+="\n"; m_str = g_strndup(p, sec_size); res += xdxf2text(m_str); g_free(m_str); } sec_size++; break; case 't': sec_size = strlen(p); if(sec_size){ res+="\n"; m_str = g_strndup(p, sec_size); res += "["+string(m_str)+"]"; g_free(m_str); } sec_size++; break; case 'y': sec_size = strlen(p); sec_size++; break; case 'W': case 'P': sec_size=*((guint32 *)p); sec_size+=sizeof(guint32); break; } p += sec_size; } return res; }