コード例 #1
0
/**
 * De-allocates memory of the given hashtable buffer.
 * All remaining Buckets are exported, then destroyed
 */
void destroyHashtable(Hashtable* ht)
{
	int i;

	for (i = 0; i < HASHTABLE_SIZE; i++) if (ht->bucket[i] != NULL) {
		HashBucket* bucket = ht->bucket[i];

		while (bucket != 0) {
			HashBucket* nextBucket = (HashBucket*)bucket->next;
			exportBucket(ht, bucket);
			destroyBucket(ht, bucket);
			bucket = nextBucket;
		}
	}

	/* Inform Exporter of Data Template destruction */
	for (i = 0; i < ht->callbackCount; i++) {
		CallbackInfo* ci = &ht->callbackInfo[i];

		if (ci->dataTemplateDestructionCallbackFunction) {
			ci->dataTemplateDestructionCallbackFunction(ci->handle, 0, ht->dataTemplate);
		}
	}

	free(ht->dataTemplate->fieldInfo);
	free(ht->fieldModifier);
	free(ht->dataTemplate->dataInfo);
	free(ht->dataTemplate->data);
	free(ht->dataTemplate);
	free(ht);
}
コード例 #2
0
 void DisplayDeviceManager::callCallbackFunctions(DisplayDeviceDescriptor &descriptor, bool wasAdded)
 {
     for (CallbackInfoIterator it = callbackInfos.begin(); it != callbackInfos.end(); it++)
     {
         CallbackInfo callbackInfo = *it;
         callbackInfo.callbackFunc(callbackInfo.context, descriptor, wasAdded);
     }
 }
コード例 #3
0
/**
 * Exports the given @c bucket
 */
static void exportBucket(Hashtable* ht, HashBucket* bucket)
{
	/* Pass Data Record to exporter interface */
	int n;
	for (n = 0; n < ht->callbackCount; n++) {
		CallbackInfo* ci = &ht->callbackInfo[n];
		if (ci->dataDataRecordCallbackFunction) {
			ci->dataDataRecordCallbackFunction(ci->handle, 0, ht->dataTemplate, ht->fieldLength, bucket->data);
		}
	}
}
コード例 #4
0
static v8::Handle<v8::Value> getNamedItems(HTMLFormControlsCollection* collection, const AtomicString& name, const CallbackInfo& callbackInfo)
{
    Vector<RefPtr<Node> > namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size())
        return v8Undefined();

    if (namedItems.size() == 1)
        return toV8(namedItems.at(0).release(), callbackInfo.Holder(), callbackInfo.GetIsolate());

    return toV8(collection->ownerNode()->radioNodeList(name).get(), callbackInfo.Holder(), callbackInfo.GetIsolate());
}
コード例 #5
0
static v8::Local<v8::Value> getNamedItems(HTMLAllCollection* collection, AtomicString name, const CallbackInfo& info)
{
    WillBeHeapVector<RefPtrWillBeMember<Element>> namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size())
        return v8Undefined();

    if (namedItems.size() == 1)
        return toV8(namedItems.at(0).release(), info.Holder(), info.GetIsolate());

    // FIXME: HTML5 specification says this should be a HTMLCollection.
    // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlallcollection
    return toV8(StaticElementList::adopt(namedItems), info.Holder(), info.GetIsolate());
}
コード例 #6
0
static v8::Handle<v8::Value> getItem(HTMLAllCollection* collection, v8::Handle<v8::Value> argument, const CallbackInfo& info)
{
    v8::Local<v8::Uint32> index = argument->ToArrayIndex();
    if (index.IsEmpty()) {
        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, name, argument, v8::Undefined(info.GetIsolate()));
        v8::Handle<v8::Value> result = getNamedItems(collection, name, info);

        if (result.IsEmpty())
            return v8::Undefined(info.GetIsolate());

        return result;
    }

    RefPtr<Element> result = collection->item(index->Uint32Value());
    return toV8(result.release(), info.Holder(), info.GetIsolate());
}
コード例 #7
0
static v8::Local<v8::Value> getItem(HTMLAllCollection* collection, v8::Local<v8::Value> argument, const CallbackInfo& info)
{
    v8::Local<v8::Uint32> index;
    if (!argument->ToArrayIndex(info.GetIsolate()->GetCurrentContext()).ToLocal(&index)) {
        TOSTRING_DEFAULT(V8StringResource<>, name, argument, v8::Undefined(info.GetIsolate()));
        v8::Local<v8::Value> result = getNamedItems(collection, name, info);

        if (result.IsEmpty())
            return v8::Undefined(info.GetIsolate());

        return result;
    }

    RefPtrWillBeRawPtr<Element> result = collection->item(index->Value());
    return toV8(result.release(), info.Holder(), info.GetIsolate());
}
コード例 #8
0
/**
 * Processes an IPFIX template set.
 * Called by processMessage
 */
static void processTemplateSet(IpfixReceiver* ipfixReceiver, SourceID sourceId, IpfixSetHeader* set) {
	IpfixTemplateHeader* th = (IpfixTemplateHeader*)&set->data;
	byte* endOfSet = (byte*)set + ntohs(set->length);
	byte* record = (byte*)&th->data;
	/* TemplateSets are >= 4 byte, so we stop processing when only 3 bytes are left */
	while (record < endOfSet - 3) {
		BufferedTemplate* bt = (BufferedTemplate*)malloc(sizeof(BufferedTemplate));
		TemplateInfo* ti = (TemplateInfo*)malloc(sizeof(TemplateInfo));
		bt->sourceID = sourceId;
		bt->templateID = ntohs(th->templateId);
		bt->recordLength = 0;
		bt->setID = ntohs(set->id);
		bt->templateInfo = ti;
		ti->userData = 0;
		ti->fieldCount = ntohs(th->fieldCount);
		ti->fieldInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));
		int isLengthVarying = 0;
		uint16_t fieldNo;
		for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) {
			ti->fieldInfo[fieldNo].type.id = ntohs(*(uint16_t*)((byte*)record+0));
			ti->fieldInfo[fieldNo].type.length = ntohs(*(uint16_t*)((byte*)record+2));
			ti->fieldInfo[fieldNo].offset = bt->recordLength; bt->recordLength+=ti->fieldInfo[fieldNo].type.length;
			if (ti->fieldInfo[fieldNo].type.length == 65535) isLengthVarying=1;
			if (ti->fieldInfo[fieldNo].type.id & 0x80) {
				ti->fieldInfo[fieldNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
				record = (byte*)((byte*)record+8);
				} else {
				ti->fieldInfo[fieldNo].type.eid = 0;
				record = (byte*)((byte*)record+4);
				}
			}
		if (isLengthVarying) {
  			bt->recordLength = 65535;
			for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) ti->fieldInfo[fieldNo].offset = 65535;
  			}
			
		bufferTemplate(ipfixReceiver->templateBuffer, bt); 
		// FIXME: Template expiration disabled for debugging
		// bt->expires = time(0) + TEMPLATE_EXPIRE_SECS;

		int n;		
		for (n = 0; n < ipfixReceiver->callbackCount; n++) {
			CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
			if (ci->templateCallbackFunction) ci->templateCallbackFunction(ci->handle, sourceId, ti);
			}
  		}
	}
コード例 #9
0
/**
 * get all tableNames in database that matches with the wildcard "h%"
 **/
int dbReaderDestroyTemplate(IpfixDbReader* ipfixDbReader, DataTemplateInfo* dataTemplateInfo)
{
	int n;
	DbReader* dbReader = ipfixDbReader->dbReader;

	for (n = 0; n != dbReader->callbackCount; n++) {
		CallbackInfo* ci = &dbReader->callbackInfo[n];
		if (ci->dataTemplateDestructionCallbackFunction) {
			ci->dataTemplateDestructionCallbackFunction(ci->handle, &ipfixDbReader->srcId,
							 dataTemplateInfo);
			msg(MSG_DEBUG,"IpfixDbReader destroyed template");
		}
	}

	free(dataTemplateInfo->fieldInfo);
	return 0;
}
コード例 #10
0
/**
 * Constructs a template from the table data and sends it to all connected
 * modules.
 */
int dbReaderSendNewTemplate(IpfixDbReader* ipfixDbReader,DataTemplateInfo* dataTemplateInfo, int table_index)
{
	int i,n;
	int fieldLength  = 0;

	DbReader* dbReader = ipfixDbReader->dbReader;
	DbData* dbData = dbReader->dbData;
	
	dataTemplateInfo->id =0;
	dataTemplateInfo->preceding= 0;	
	dataTemplateInfo->fieldCount = 0;
	dataTemplateInfo->fieldInfo = NULL;
	dataTemplateInfo->dataCount = 0;
	dataTemplateInfo->dataInfo = NULL;
	dataTemplateInfo->data = NULL;
	dataTemplateInfo->userData = NULL;
		
	/**get columnsname of the table*/
	if(getColumns(ipfixDbReader, table_index) != 0) {
		msg(MSG_ERROR,"IpfixDbReader: Could not get columns for template");
		return 1;
	}

	for(i = 0; i < dbData->colCount; i++) {			
		dataTemplateInfo->fieldCount++;
		dataTemplateInfo->fieldInfo = realloc(dataTemplateInfo->fieldInfo,
						      sizeof(FieldInfo)*dataTemplateInfo->fieldCount);
		FieldInfo* fi = &dataTemplateInfo->fieldInfo[dataTemplateInfo->fieldCount - 1];	
		fi->type.id = dbData->columns[i]->ipfixId;
		fi->type.length = dbData->columns[i]->length;
		fi->type.eid = 0;
		fi->offset = fieldLength;
		fieldLength = fieldLength + fi->type.length; 
	}

	for (n = 0; n != dbReader->callbackCount; n++) {
		CallbackInfo* ci = &dbReader->callbackInfo[n];
		if (ci->dataTemplateCallbackFunction) {
			ci->dataTemplateCallbackFunction(ci->handle, &ipfixDbReader->srcId,
							 dataTemplateInfo);
			msg(MSG_DEBUG,"IpfixDbReader sent template for table %s", dbData->tableNames[table_index]);
		}
	}
	return 0;
}
コード例 #11
0
static v8::Handle<v8::Value> getNamedItems(HTMLAllCollection* collection, AtomicString name, const CallbackInfo& info)
{
    WillBeHeapVector<RefPtrWillBeMember<Element>> namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size())
        return v8Undefined();

    if (namedItems.size() == 1)
        return toV8(namedItems.at(0).release(), info.Holder(), info.GetIsolate());

    // FIXME: HTML5 specification says this should be a HTMLCollection.
    // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlallcollection
    //
    // FIXME: Oilpan: explicitly convert adopt()'s result so as to
    // disambiguate the (implicit) conversion of its
    // PassRefPtrWillBeRawPtr<StaticElementList> result -- the
    // other toV8() overload that introduces the ambiguity is
    // toV8(NodeList*, ...).
    //
    // When adopt() no longer uses transition types, the conversion
    // can be removed.
    return toV8(PassRefPtrWillBeRawPtr<NodeList>(StaticElementList::adopt(namedItems)), info.Holder(), info.GetIsolate());
}
コード例 #12
0
ファイル: Event.cpp プロジェクト: LucyScott/mdsplus
	void intCallbackC(char *c1, char *c2, int i1, void *ciPtr, bool b, int i2, char *c3, int i3)
	{
		CallbackInfo *ci = (CallbackInfo *)ciPtr;
		ci->callback(c1, c2, i1, ci->callbackArg, b, i2, c3, i3);
	}
コード例 #13
0
static bool TestInterfaceNamedConstructorCreateDataProperty(v8::Local<v8::Name> name, v8::Local<v8::Value> v8Value, const CallbackInfo& info)
{
    ASSERT(info.This()->IsObject());
    return v8CallBoolean(v8::Local<v8::Object>::Cast(info.This())->CreateDataProperty(info.GetIsolate()->GetCurrentContext(), name, v8Value));
}
コード例 #14
0
/**
 * Processes an IPFIX data set.
 * Called by processMessage
 */
static void processDataSet(IpfixReceiver* ipfixReceiver, SourceID sourceId, IpfixSetHeader* set) {
	BufferedTemplate* bt = getBufferedTemplate(ipfixReceiver->templateBuffer, sourceId, ntohs(set->id));

	if(bt == 0) {
                /* this error may come in rapid succession; I hope I don't regret it */
		msg(MSG_INFO, "Template %d unknown to collecting process", ntohs(set->id));
		return;
	}
	
	#ifdef SUPPORT_NETFLOWV9
	if ((bt->setID == IPFIX_SetId_Template) || (bt->setID == NetflowV9_SetId_Template)) {
	#else
	if (bt->setID == IPFIX_SetId_Template) {
	#endif

		TemplateInfo* ti = bt->templateInfo;

		uint16_t length = ntohs(set->length)-((byte*)(&set->data)-(byte*)set);

		byte* record = &set->data;
	
		if (bt->recordLength < 65535) {
			byte* recordX = record+length;

			if (record >= recordX - (bt->recordLength - 1)) {
				DPRINTF("Got a Data Set that contained not a single full record\n");
			}

			/* We stop processing when no full record is left */
			while (record < recordX - (bt->recordLength - 1)) {
				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->dataRecordCallbackFunction) ci->dataRecordCallbackFunction(ci->handle, sourceId, ti, bt->recordLength, record);
					}
				record = record + bt->recordLength;
				}
			} else {
			byte* recordX = record+length;

			if (record >= recordX - 3) {
				DPRINTF("Got a Data Set that contained not a single full record");
			}

			/* We assume that all variable-length records are >= 4 byte, so we stop processing when only 3 bytes are left */
			while (record < recordX - 3) {
				int recordLength=0;
				int i;
				for (i = 0; i < ti->fieldCount; i++) {
					int fieldLength = 0;
					if (ti->fieldInfo[i].type.length < 65535) {
						fieldLength = ti->fieldInfo[i].type.length;
						} else {
						if (*(byte*)record < 255) {
							fieldLength = *(byte*)record;
							} else {
							fieldLength = *(uint16_t*)(record+1);
							}
						}
					ti->fieldInfo[i].type.length = fieldLength;
					ti->fieldInfo[i].offset = recordLength;
					recordLength += fieldLength;
					}
				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->dataRecordCallbackFunction) ci->dataRecordCallbackFunction(ci->handle, sourceId, ti, recordLength, record);
					}
				record = record + recordLength;
				}
			}
		} else 
	if (bt->setID == IPFIX_SetId_OptionsTemplate) {
  	
		OptionsTemplateInfo* ti = bt->optionsTemplateInfo;

		uint16_t length = ntohs(set->length)-((byte*)(&set->data)-(byte*)set);
		byte* record = &set->data;
	
		if (bt->recordLength < 65535) {
			byte* recordX = record+length;
			while (record < recordX) {
				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->optionsRecordCallbackFunction) ci->optionsRecordCallbackFunction(ci->handle, sourceId, ti, bt->recordLength, record);
					}
				record = record + bt->recordLength;
				}
			} else {
			byte* recordX = record+length;
			while (record < recordX) {
				int recordLength=0;
				int i;
				for (i = 0; i < ti->scopeCount; i++) {
					int fieldLength = 0;
					if (ti->scopeInfo[i].type.length < 65535) {
						fieldLength = ti->scopeInfo[i].type.length;
						} else {
						if (*(byte*)record < 255) {
							fieldLength = *(byte*)record;
							} else {
							fieldLength = *(uint16_t*)(record+1);
							}
						}
					ti->scopeInfo[i].type.length = fieldLength;
					ti->scopeInfo[i].offset = recordLength;
					recordLength += fieldLength;
					}
				for (i = 0; i < ti->fieldCount; i++) {
					int fieldLength = 0;
					if (ti->fieldInfo[i].type.length < 65535) {
						fieldLength = ti->fieldInfo[i].type.length;
						} else {
						if (*(byte*)record < 255) {
							fieldLength = *(byte*)record;
							} else {
							fieldLength = *(uint16_t*)(record+1);
							}
						}
					ti->fieldInfo[i].type.length = fieldLength;
					ti->fieldInfo[i].offset = recordLength;
					recordLength += fieldLength;
					}

				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->optionsRecordCallbackFunction) ci->optionsRecordCallbackFunction(ci->handle, sourceId, ti, recordLength, record);
					}

				record = record + recordLength;
				}
			}
		} else 
  	if (bt->setID == IPFIX_SetId_DataTemplate) {
		DataTemplateInfo* ti = bt->dataTemplateInfo;

		uint16_t length = ntohs(set->length)-((byte*)(&set->data)-(byte*)set);
		byte* record = &set->data;

		if (bt->recordLength < 65535) {
			byte* recordX = record+length;
			while (record < recordX) {
				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->dataDataRecordCallbackFunction) ci->dataDataRecordCallbackFunction(ci->handle, sourceId, ti, bt->recordLength, record);
					}
				record = record + bt->recordLength;
				}
			} else {
			byte* recordX = record+length;
			while (record < recordX) {
				int recordLength=0;
				int i;
				for (i = 0; i < ti->fieldCount; i++) {
					int fieldLength = 0;
					if (ti->fieldInfo[i].type.length < 65535) {
						fieldLength = ti->fieldInfo[i].type.length;
						} else {
						if (*(byte*)record < 255) {
							fieldLength = *(byte*)record;
							} else {
							fieldLength = *(uint16_t*)(record+1);
							}
						}
					ti->fieldInfo[i].type.length = fieldLength;
					ti->fieldInfo[i].offset = recordLength;
					recordLength += fieldLength;
					}
				int n;		
				for (n = 0; n < ipfixReceiver->callbackCount; n++) {
					CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
					if (ci->dataDataRecordCallbackFunction) ci->dataDataRecordCallbackFunction(ci->handle, sourceId, ti, recordLength, record);
					}
				record = record + recordLength;
			}
			}
		} else {
		msg(MSG_FATAL, "Data Set based on known but unhandled template type %d", bt->setID);
		}
}
	

/**
 * Process a NetflowV9 Packet
 * @return 0 on success
 */	
static int processNetflowV9Packet(IpfixReceiver* ipfixReceiver, byte* message, uint16_t length) {
	NetflowV9Header* header = (NetflowV9Header*)message;
	
	/* pointer to first set */
	IpfixSetHeader* set = (IpfixSetHeader*)&header->data;

	int i;
	for (i = 0; i < ntohs(header->setCount); i++) {
		if (ntohs(set->id) == NetflowV9_SetId_Template) {
  			processTemplateSet(ipfixReceiver, ntohs(header->sourceId), set);
  			} else
		if (ntohs(set->id) >= IPFIX_SetId_Data_Start) {
  			processDataSet(ipfixReceiver, ntohs(header->sourceId), set);
  			} else {
			msg(MSG_ERROR, "processNetflowV9: Unsupported Set ID - expected 0/256+, got %d", ntohs(set->id));
  			}
		set = (IpfixSetHeader*)((byte*)set + ntohs(set->length));
		}

	return 0;
}
コード例 #15
0
/**
 * Processes an IPFIX DataTemplate set.
 * Called by processMessage
 */
static void processDataTemplateSet(IpfixReceiver* ipfixReceiver, SourceID sourceId, IpfixSetHeader* set) {
	IpfixDataTemplateHeader* th = (IpfixDataTemplateHeader*)&set->data;
	byte* endOfSet = (byte*)set + ntohs(set->length);
	byte* record = (byte*)&th->data;

	/* DataTemplateSets are >= 4 byte, so we stop processing when only 3 bytes are left */
	while (record < endOfSet - 3) {
		BufferedTemplate* bt = (BufferedTemplate*)malloc(sizeof(BufferedTemplate));
		DataTemplateInfo* ti = (DataTemplateInfo*)malloc(sizeof(DataTemplateInfo));
		bt->sourceID = sourceId;
		bt->templateID = ntohs(th->templateId);
		bt->recordLength = 0;
		bt->setID = ntohs(set->id);
		bt->dataTemplateInfo = ti;
		ti->userData = 0;
		ti->fieldCount = ntohs(th->fieldCount);
		ti->dataCount = ntohs(th->dataCount);
		ti->fieldInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));
		int isLengthVarying = 0;
		uint16_t fieldNo;
		for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) {
			ti->fieldInfo[fieldNo].type.id = ntohs(*(uint16_t*)((byte*)record+0));
			ti->fieldInfo[fieldNo].type.length = ntohs(*(uint16_t*)((byte*)record+2));
			ti->fieldInfo[fieldNo].offset = bt->recordLength; bt->recordLength+=ti->fieldInfo[fieldNo].type.length;
			if (ti->fieldInfo[fieldNo].type.length == 65535) isLengthVarying=1;
			if (ti->fieldInfo[fieldNo].type.id & 0x80) {
				ti->fieldInfo[fieldNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
				record = (byte*)((byte*)record+8);
				} else {
				ti->fieldInfo[fieldNo].type.eid = 0;
				record = (byte*)((byte*)record+4);
				}
			}
		if (isLengthVarying) {
			bt->recordLength = 65535;
			for (fieldNo = 0; fieldNo < ti->fieldCount; fieldNo++) ti->fieldInfo[fieldNo].offset = 65535;
			}

		ti->dataInfo = (FieldInfo*)malloc(ti->fieldCount * sizeof(FieldInfo));
		for (fieldNo = 0; fieldNo < ti->dataCount; fieldNo++) {
			ti->dataInfo[fieldNo].type.id = ntohs(*(uint16_t*)((byte*)record+0));
			ti->dataInfo[fieldNo].type.length = ntohs(*(uint16_t*)((byte*)record+2));
			if (ti->dataInfo[fieldNo].type.id & 0x80) {
				ti->dataInfo[fieldNo].type.eid = ntohl(*(uint32_t*)((byte*)record+4));
				record = (byte*)((byte*)record+8);
				} else {
				ti->dataInfo[fieldNo].type.eid = 0;
				record = (byte*)((byte*)record+4);
				}
			}
		
		/* done with reading dataInfo, @c record now points to the fixed data block */
		byte* dataStart = record;
		
		int dataLength = 0;
		for (fieldNo = 0; fieldNo < ti->dataCount; fieldNo++) {
			ti->dataInfo[fieldNo].offset = dataLength;
			if (ti->dataInfo[fieldNo].type.length == 65535) {
				/* This is a variable-length field, get length from first byte and advance offset */
				ti->dataInfo[fieldNo].type.length = *(uint8_t*)(dataStart + ti->dataInfo[fieldNo].offset);
				ti->dataInfo[fieldNo].offset += 1;
				if (ti->dataInfo[fieldNo].type.length == 255) {
					/* First byte did not suffice, length is stored in next two bytes. Advance offset */
					ti->dataInfo[fieldNo].type.length = *(uint16_t*)(dataStart + ti->dataInfo[fieldNo].offset);
					ti->dataInfo[fieldNo].offset += 2;
					}
				}
			dataLength += ti->dataInfo[fieldNo].type.length;
			}
			
		/* Copy fixed data block */
		ti->data = (byte*)malloc(dataLength);
		memcpy(ti->data,dataStart,dataLength);

		/* Advance record to end of fixed data block, i.e. start of next template*/
		record += dataLength;
		
		bufferTemplate(ipfixReceiver->templateBuffer, bt); 
		// FIXME: Template expiration disabled for debugging
		// bt->expires = time(0) + TEMPLATE_EXPIRE_SECS;

		int n;		
		for (n = 0; n < ipfixReceiver->callbackCount; n++) {
			CallbackInfo* ci = &ipfixReceiver->callbackInfo[n];
			if (ci->dataTemplateCallbackFunction) ci->dataTemplateCallbackFunction(ci->handle, sourceId, ti);
			}
  		}
	}
コード例 #16
0
inline void v8SetReturnValue(const CallbackInfo& info, bool value)
{
    info.GetReturnValue().Set(value);
}
コード例 #17
0
inline void v8SetReturnValue(const CallbackInfo& info, v8::MaybeLocal<S> maybe)
{
    if (LIKELY(!maybe.IsEmpty()))
        info.GetReturnValue().Set(maybe.ToLocalChecked());
}
コード例 #18
0
ファイル: JsonReader.hpp プロジェクト: aleksigron/kokko
	void Parse(const CallbackInfo& callback) const
	{
		enum class St : unsigned char
		{
			Root,
			Object,
			Array,
			String
		};

		unsigned int charIndex = 0;

		static const int maxDepth = 32;
		int currDepth = 0;

		St typeStack[maxDepth];
		typeStack[currDepth] = St::Root;

		StringRef keyStack[maxDepth];

		// Array of String should be value initialized already, but let's be safe
		keyStack[currDepth].str = nullptr;

		int scopeStart = 0;
		char prevChar = 0;

		while (charIndex < content.len)
		{
			char c = content.str[charIndex];

			switch (c)
			{
				case '"':
				{
					if (prevChar != '\\')
					{
						// Quotation mark wasn't escaped
						// This is a real quotation mark

						if (typeStack[currDepth] == St::String)
						{
							// End string literal
							--currDepth;

							// No key is needed in this scope
							if (typeStack[currDepth] == St::Array ||
								typeStack[currDepth] == St::Root)
							{
								StringRef value;
								value.str = content.str + scopeStart;
								value.len = charIndex - scopeStart;

								callback.readString(keyStack[currDepth], value,
									callback.userData);
							}
							// A key has been defined in this scope
							else if (keyStack[currDepth].str != nullptr)
							{
								StringRef value;
								value.str = content.str + scopeStart;
								value.len = charIndex - scopeStart;

								callback.readString(keyStack[currDepth],
									value, callback.userData);

								// Unset key
								keyStack[currDepth].Invalidate();
							}
							// Key has not been defined, use this as the key
							else
							{
								keyStack[currDepth].str = content.str + scopeStart;
								keyStack[currDepth].len = charIndex - scopeStart;
							}
						}
						else
						{
							// Start string literal
							typeStack[++currDepth] = St::String;
							scopeStart = charIndex + 1;
						}
					}
				}
					break;
/*
				case ':':
				{

				}
					break;

				case ',':

					break;
*/
				case '{':
				{
					// We're not within a string literal
					if (typeStack[currDepth] != St::String)
					{
						// If there's a key defined, the callee can detect it
						callback.openObject(keyStack[currDepth], callback.userData);

						// Start object scope
						typeStack[++currDepth] = St::Object;
					}
				}
					break;

				case '}':
				{
					if (typeStack[currDepth] == St::Object)
					{
						// End object scope
						--currDepth;

						// If there's a key defined, the callee can detect it
						callback.closeObject(keyStack[currDepth], callback.userData);

						// Unset key, if it existed anyway
						keyStack[currDepth].Invalidate();
					}
				}
					break;

				case '[':
				{
					// We're not within a string literal
					if (typeStack[currDepth] != St::String)
					{
						// If there's a key defined, the callee can detect it
						callback.openArray(keyStack[currDepth], callback.userData);

						// Start array scope
						typeStack[++currDepth] = St::Array;
					}
				}
					break;

				case ']':
				{
					if (typeStack[currDepth] == St::Array)
					{
						// End array scope
						--currDepth;

						// If there's a key defined, the callee can detect it
						callback.closeArray(keyStack[currDepth], callback.userData);

						// Unset key, if it existed anyway
						keyStack[currDepth].Invalidate(); // Unset key
					}
				}
					break;
			}

			prevChar = c;
			++charIndex;
		}
	}
コード例 #19
0
/**
 * Create a clone of this object, a new instance ID must be specified.
 * Do not use this function directly to create new instances, the
 * UAVObjectManager should be used instead.
 */
UAVDataObject *CallbackInfo::clone(quint32 instID)
{
    CallbackInfo *obj = new CallbackInfo();
    obj->initialize(instID, this->getMetaObject());
    return obj;
}
コード例 #20
0
int dbReaderSendTable(IpfixDbReader* ipfixDbReader, DataTemplateInfo* dataTemplateInfo, int table_index)
{
       	MYSQL_RES* dbResult = NULL;
	MYSQL_ROW dbRow = NULL;
	DbReader* dbReader = ipfixDbReader->dbReader;
	DbData* dbData = dbReader->dbData;
	int i;
	FieldData* data = (FieldData*)malloc(MAX_MSG_LEN);
	int dataLength = 0;
	unsigned delta = 0;
	unsigned flowTime = 0;
	unsigned lastFlowTime = 0;
	long long tmp;
	

	char select[STARTLEN] = "SELECT * FROM ";
	strncat(select, ipfixDbReader->dbReader->dbData->tableNames[table_index],TABLE_WIDTH);
	strcat(select," ORDER BY lastSwitched");
	/** get all data from database*/
	if(mysql_query(ipfixDbReader->conn, select) != 0) {
		msg(MSG_ERROR,"IpfixDbReader: Select on table failed. Error: %s",
		    mysql_error(ipfixDbReader->conn));
		free(data);
		return 1;
	}

	dbResult = mysql_store_result(ipfixDbReader->conn);
	msg(MSG_DEBUG,"IpfixDbReader starts sending records from table %s", dbData->tableNames[table_index]);
	while((dbRow = mysql_fetch_row(dbResult))) {
		if (delta == 0) {
			for (i = 0; i != dbData->colCount; ++i) {
				if (IPFIX_TYPEID_flowEndSeconds) {
					delta = time(NULL) - atoll(dbRow[i]);
					flowTime = lastFlowTime = atoll(dbRow[i]) + delta;
				}
			}
			if (delta == 0) {
				msg(MSG_FATAL, "IpfixDbReader: flowEndTime in first data base record missing!");
				mysql_free_result(dbResult);
				free(data);
				return 1;
			}
		}
		for(i = 0; i != dbData->colCount; ++i) {
			switch(dbData->columns[i]->ipfixId) {
			case IPFIX_TYPEID_flowEndSeconds:
			        flowTime = atoll(dbRow[i]) + delta;
			case IPFIX_TYPEID_flowStartSeconds:
				tmp = atoll(dbRow[i]) + delta;
				copyUintNetByteOrder(data + dataTemplateInfo->fieldInfo[i].offset,
						     (char*)&tmp,
						     dataTemplateInfo->fieldInfo[i].type);
				dataLength += dataTemplateInfo->fieldInfo[i].type.length;
				break;
			case IPFIX_TYPEID_octetDeltaCount:
			case IPFIX_TYPEID_packetDeltaCount:
			case IPFIX_TYPEID_destinationIPv4Address:
			case IPFIX_TYPEID_sourceIPv4Address:
			case IPFIX_TYPEID_sourceTransportPort:
			case IPFIX_TYPEID_destinationTransportPort:
			case IPFIX_TYPEID_protocolIdentifier:
			case IPFIX_TYPEID_classOfServiceIPv4:
				tmp = atoll(dbRow[i]);
				copyUintNetByteOrder(data + dataTemplateInfo->fieldInfo[i].offset,
						     (char*)&tmp,
						     dataTemplateInfo->fieldInfo[i].type);
				dataLength += dataTemplateInfo->fieldInfo[i].type.length;
				break;
			}
		}
	
		/** according to flowstarttime wait for sending the record*/
		if(flowTime != lastFlowTime) {
			time_t t = time(NULL);
			if (t > flowTime) {
				msg(MSG_ERROR, "IpfixDbReader: Sending flows too slowly");
			} else {
				sleep (flowTime - t);
			}
			lastFlowTime = flowTime;
		}
		for (i = 0; i != dbReader->callbackCount; ++i) {
			CallbackInfo* ci = &dbReader->callbackInfo[i];
			if (ci->dataDataRecordCallbackFunction) {
				ci->dataDataRecordCallbackFunction(ci->handle,
								   &ipfixDbReader->srcId,
								   dataTemplateInfo,
								   dataLength,
								   data);
				msg(MSG_INFO,"IpfixDbReader sent record");
			}
		}

	}
	mysql_free_result(dbResult);
	free(data);
	
	msg(MSG_DEBUG,"Sending from table %s done", dbData->tableNames[table_index]);

	return 0;
}
コード例 #21
0
inline void v8SetReturnValue(const CallbackInfo& info, const v8::Local<S> handle)
{
    info.GetReturnValue().Set(handle);
}
コード例 #22
0
static void TestTypedefsForceSetAttributeOnThis(v8::Local<v8::Name> name, v8::Local<v8::Value> v8Value, const CallbackInfo& info)
{
    ASSERT(info.This()->IsObject());
    v8::Local<v8::Object>::Cast(info.This())->ForceSet(info.GetIsolate()->GetCurrentContext(), name, v8Value);
}