示例#1
0
EXPORT string make_packet_string(LogInfo *l)
{
    string m;
    if (l->packet_id){
        PacketType *type = getContacts()->getPacketType(l->packet_id);
        if (type == NULL)
            return m;
        Buffer *b = (Buffer*)(l->log_info);
        unsigned start = b->packetStartPos();
        time_t now;
        time(&now);
        struct tm *tm = localtime(&now);
        string name = type->name();
        if (l->add_info && *l->add_info){
            name += ".";
            name += l->add_info;
        }
        format(m, "%02u:%02u:%02u [%s] %s %u bytes\n", tm->tm_hour, tm->tm_min, tm->tm_sec,
               name.c_str(),
               (l->log_level & L_PACKET_IN) ? "Read" : "Write",
               b->size() - start);
        if (type->isText()){
            m.append(b->data(start), b->size() - start);
        }else{
            char line[81];
            char *p1 = line;
            char *p2 = line;
            unsigned n = 20;
            unsigned offs = 0;
            for (unsigned i = start; i < b->size(); i++, n++){
                char buf[32];
                if (n == 16){
                    m += line;
                    m += "\n";
                }
                if (n >= 16){
                    memset(line, ' ', 80);
                    line[80] = 0;
                    snprintf(buf, sizeof(buf), "%04X: ", offs);
                    memcpy(line, buf, strlen(buf));
                    p1 = line + strlen(buf);
                    p2 = p1 + 52;
                    n = 0;
                    offs += 0x10;
                }
                if (n == 8) p1++;
                unsigned char c = (unsigned char)*(b->data(i));
                *(p2++) = ((c >= ' ') && (c != 0x7F)) ? c : '.';
                snprintf(buf, sizeof(buf), "%02X ", c);
                memcpy(p1, buf, 3);
                p1 += 3;
            }
            if (n <= 16) m += line;
        }
    }else{
        m = (const char*)(l->log_info);
    }
    return m;
}
示例#2
0
void PacketTypeList::RegisterType(PacketType type)
{
	BlockLockMutex lock(this);

	assert(find(type.GetType()) == end());
	pf_log[W_DEBUG] << "Register " << type.GetName() << "(" << type.GetType() << ")";
	insert(value_type(type.GetType(), type));
}
示例#3
0
void LogConfig::fill()
{
    lstLevel->clear();
    addItem(I18N_NOOP("Error"), (m_plugin->getLogLevel() & L_ERROR) != 0, L_ERROR, 0);
    addItem(I18N_NOOP("Warning"), (m_plugin->getLogLevel() & L_WARN) != 0, L_WARN, 0);
    addItem(I18N_NOOP("Debug"), (m_plugin->getLogLevel() & L_DEBUG) != 0, L_DEBUG, 0);
    PacketType *type;
    ContactList::PacketIterator it;
    while ((type = ++it) != NULL){
        addItem(type->name(), m_plugin->isLogType(type->id()), 0, type->id());
    }
}
示例#4
0
void MonitorWindow::adjustLog()
{
    menuLog->clear();
    PacketType *packet;
    ContactList::PacketIterator it;
    while ((packet = ++it) != NULL){
        menuLog->insertItem(i18n(packet->name()), packet->id());
        menuLog->setItemChecked(packet->id(), m_plugin->isLogType(packet->id()));
    }
    menuLog->insertSeparator();
    for (const level_def *d = levels; d->name; d++){
        menuLog->insertItem(i18n(d->name), d->level);
        menuLog->setItemChecked(d->level, (m_plugin->getLogLevel() & d->level) != 0);
    }
}
示例#5
0
void LogConfig::fill()
{
    for (BOX_MAP::iterator it = m_boxes.begin(); it != m_boxes.end(); ++it)
        delete (*it).second;
    m_boxes.clear();
    QVBoxLayout *lay = static_cast<QVBoxLayout*>(layout());
    PacketType *packet;
    ContactList::PacketIterator it_packet;
    unsigned pos = 4;
    while ((packet = ++it_packet) != NULL){
        QCheckBox *box = new QCheckBox(i18n(packet->name()), this);
        lay->insertWidget(pos++, box);
        box->setChecked(m_plugin->isLogType(packet->id()));
        m_boxes.insert(BOX_MAP::value_type(packet->id(), box));
    }
	setMinimumSize(sizeHint());
}
bool LocalSocketConnection::send(const PacketType &packet,
                                 const EndpointIdType &endpoint)
{
  Q_UNUSED(endpoint);

  // Because of a possible bug with Qt 5.8 and 5.9 on Windows,
  // (*m_dataStream) << packet
  // sends two packets instead of one. The packets will fail to get read
  // correctly on the other side of the message. To fix this, we write the
  // message to a byte array and send it in all together as a single raw data
  // packet. If this bug gets fixed in the future, we will not need the
  // Windows section...
  // See https://bugreports.qt.io/browse/QTBUG-61097 for the bug report.
#ifdef _WIN32
  PacketType byteArray;
  QDataStream tmpStream(&byteArray, QIODevice::WriteOnly);
  tmpStream << packet;
  m_dataStream->writeRawData(byteArray, byteArray.size());
#else
  (*m_dataStream) << packet;
#endif

  return true;
}