Esempio n. 1
0
quint32 AbrStructParser::parseEntry(QDataStream &buf){
    quint32 nlen;
    buf >> nlen;
    if (nlen == 0){
        nlen = 4;
    }
    
    QString value = "";
   
    if (nlen == MAGIC_OBJC_LENGTH){
        value = p_objc(buf);
        qDebug() << ABR_PRESET_START  << ABR_OBJECT << value;
        // start to create the preset here
        m_translator.addEntry(ABR_PRESET_START, ABR_OBJECT, value);
    }else{
        // read char with nlen bytes and convert to String
        char * name = new char[ nlen+1 ];
        int status = buf.readRawData(name, nlen);
        if (status == -1){
            qDebug() << "Error, name can't be readed";
        }
        name[nlen] = '\0';

        char * type = new char[5];
        status = buf.readRawData(type, 4);
        type[4] = '\0';
        QString key = QString::fromLatin1(type);
        
        if (m_types.contains(key))
        {
            enumFuncNames enumName = m_types[key];
            
            switch (enumName){
                case P_PATT: value = p_patt(buf); break;
                case P_DESC: value = p_desc(buf); break;
                case P_VLLS: value = p_vlls(buf); break;
                case P_TEXT: value = p_text(buf); break;
                case P_OBJC: value = p_objc(buf); break;
                case P_UNTF: value = p_untf(buf); break;
                case P_BOOL: value = p_bool(buf); break;
                case P_LONG: value = p_long(buf); break; 
                case P_DOUB: value = p_doub(buf); break;
                case P_ENUM: value = p_enum(buf); break;
                case P_TDTA: value = p_tdta(buf); break;
                default: qDebug() << "Freak error occurred!"; break;
            }
            
            QString attributeName = QString::fromLatin1(name);
            //qDebug() << attributeName << key << value;
            m_translator.addEntry(attributeName, key, value);
            
            // airbrush is the last parsed attribute of the preset
            if (attributeName == ABR_AIRBRUSH)    {
                m_translator.finishPreset();
                qDebug() << m_translator.toString();
            }
                
        }else
        {
            qDebug() << "Unknown key:\t" << name << type;
            //qDebug() << p_unkn(buf);
            return -1;
        }
    
    }
    return 0;
}
Esempio n. 2
0
static PyObject *
PyFB_ifstats(PyObject *self)
{
	int mib_ifdata[6] = { CTL_NET, PF_LINK, NETLINK_GENERIC,
			      IFMIB_IFDATA, 0, IFDATA_GENERAL};
	struct ifmibdata ifmd;
	size_t len; 
	int value, i;
	PyObject *r, *d, *t;

	len = sizeof value;
	if (sysctlbyname("net.link.generic.system.ifcount", &value,
			 &len, NULL, 0) < 0)
		return OSERROR();

	r = PyDict_New();

	for (i = 1; i <= value; i++) {
		len = sizeof ifmd;
		mib_ifdata[4] = i;
		if (sysctl(mib_ifdata, 6, &ifmd, &len, NULL, 0) < 0) {
			Py_DECREF(r);
			PyErr_SetFromErrno(PyExc_OSError);
			return Py_None;
		}

		d = PyDict_New();

#define p_long(f)   p(PyLong_FromUnsignedLong, unsigned long, f)
#define p_str(f)    p(PyString_FromString, char *, f)
#define p_int(f)    p(PyInt_FromLong, long, f)

#define p(adoptor, castor, f) \
		t = adoptor((castor)ifmd.ifmd_##f); \
		PyDict_SetItemString(d, #f, t); \
		Py_DECREF(t);
		p_str(name);        p_int(pcount);
		p_int(flags);       p_int(snd_len);
		p_int(snd_maxlen);  p_int(snd_drops);
#undef p

#define p(adoptor, castor, f) \
		t = adoptor((castor)ifmd.ifmd_data.ifi_##f); \
		PyDict_SetItemString(d, #f, t); \
		Py_DECREF(t);
		p_int(type);        p_int(physical);
		p_int(addrlen);     p_int(hdrlen);
		p_int(recvquota);   p_int(xmitquota);
		p_long(mtu);        p_long(metric);
		p_long(baudrate);   p_long(ipackets);
		p_long(ierrors);    p_long(opackets);
		p_long(oerrors);    p_long(collisions);
		p_long(ibytes);     p_long(obytes);
		p_long(imcasts);    p_long(omcasts);
		p_long(iqdrops);    p_long(noproto);
		p_long(hwassist);
#undef p

		PyDict_SetItemString(r, ifmd.ifmd_name, d);
		Py_DECREF(d);
	}

	return r;
}