Beispiel #1
0
uint8_t *midcol_serialize(Lyst mids, uint32_t *size)
{
	uint8_t *result = NULL;
	Sdnv num_sdnv;
	LystElt elt;

	DTNMP_DEBUG_ENTRY("midcol_serialize","(%#llx, %#llx)",
			          (unsigned long) mids, (unsigned long) size);

	/* Step 0: Sanity Check */
	if((mids == NULL) || (size == NULL))
	{
		DTNMP_DEBUG_ERR("midcol_serialize","Bad args.", NULL);
		DTNMP_DEBUG_EXIT("midcol_serialize","->NULL",NULL);
		return NULL;
	}

	/* Step 1: Calculate the size. */

	/* Consider the size of the SDNV holding # MIDS.*/
	encodeSdnv(&num_sdnv, lyst_length(mids));

	*size = num_sdnv.length;

	/* Walk through each MID, make sure it is serialized, and look at size. */
    for(elt = lyst_first(mids); elt; elt = lyst_next(elt))
    {
    	mid_t *cur_mid = (mid_t *) lyst_data(elt);

    	if(cur_mid != NULL)
    	{
    		if((cur_mid->raw == NULL) || (cur_mid->raw_size == 0))
    		{
    			/* \todo check return code. */
    			mid_internal_serialize(cur_mid);
    		}
    		if((cur_mid->raw == NULL) || (cur_mid->raw_size == 0))
    		{
        		DTNMP_DEBUG_WARN("midcol_serialize","MID didn't serialize.", NULL);
    		}
    		else
    		{
    			*size += cur_mid->raw_size;
    		}
    	}
    	else
    	{
    		DTNMP_DEBUG_WARN("midcol_serialize","Found NULL MID?", NULL);
    	}
    }

    /* Step 3: Allocate the space for the serialized list. */
    if((result = (uint8_t*) MTAKE(*size)) == NULL)
    {
		DTNMP_DEBUG_ERR("midcol_serialize","Can't alloc %d bytes", *size);
		*size = 0;

		DTNMP_DEBUG_EXIT("midcol_serialize","->NULL",NULL);
		return NULL;
    }

    /* Step 4: Walk through list again copying as we go. */
    uint8_t *cursor = result;

    /* COpy over the number of MIDs in the collection. */
    memcpy(cursor, num_sdnv.text, num_sdnv.length);
    cursor += num_sdnv.length;

    for(elt = lyst_first(mids); elt; elt = lyst_next(elt))
    {
    	mid_t *cur_mid = (mid_t *) lyst_data(elt);

    	if(cur_mid != NULL)
    	{
    		if((cur_mid->raw != NULL) && (cur_mid->raw_size > 0))
    		{
    			memcpy(cursor,cur_mid->raw, cur_mid->raw_size);
    			cursor += cur_mid->raw_size;
    		}
    	}
    	else
    	{
    		DTNMP_DEBUG_WARN("midcol_serialize","Found NULL MID?", NULL);
    	}
    }

    /* Step 5: Final sanity check. */
    if((cursor - result) != *size)
    {
		DTNMP_DEBUG_ERR("midcol_serialize","Wrote %d bytes not %d bytes",
				        (cursor - result), *size);
		*size = 0;
		MRELEASE(result);
		DTNMP_DEBUG_EXIT("midcol_serialize","->NULL",NULL);
		return NULL;
    }

	DTNMP_DEBUG_EXIT("midcol_serialize","->%#llx",(unsigned long) result);
	return result;
}
Beispiel #2
0
char *midcol_to_string(Lyst mc)
{
	LystElt elt;
	char *result = NULL;
	char *cursor = NULL;
	int num_items = 0;
	int i = 0;

	char **mid_strs = NULL;
	int tot_size = 0;

	DTNMP_DEBUG_ENTRY("midcol_to_string","(%#llx)", (unsigned long) mc);

	/* Step 0: Sanity Check. */
	if(mc == NULL)
	{
		DTNMP_DEBUG_ERR("midcol_to_string","Bad Args.", NULL);
		DTNMP_DEBUG_EXIT("midcol_to_string","->NULL", NULL);
		return NULL;
	}

	/* Step 1: Grab the number of MIDs in the collection, and pre-allocate
	 *         space to store their printed information.
	 */
	num_items = (int) lyst_length(mc);

	mid_strs = (char**) MTAKE(num_items * sizeof(char*));
	if(mid_strs == NULL)
	{
		DTNMP_DEBUG_ERR("midcol_to_string","Can't alloc %d bytes.",
				        num_items * sizeof(char *));
		DTNMP_DEBUG_EXIT("midcol_to_string","->NULL",NULL);
		return NULL;
	}

	/* Step 2: Grab the pretty-print of individual MIDs. We need this anyway
	 *         and it will help us get the sizing right.
	 */
	for(elt = lyst_first(mc); (elt && (i < num_items)); elt=lyst_next(elt))
	{
		mid_t *cur_mid = (mid_t*) lyst_data(elt);
		mid_strs[i] = mid_to_string(cur_mid);
		tot_size += strlen(mid_strs[i]);
		i++;
	}

	/* Step 3: Calculate size of the MID collection print and allocate it. */
	tot_size += 5 +        /* "MC : " */
				2 +        /* trailer */
			    num_items; /* space between MIDs. */

	if((result = (char *) MTAKE(tot_size)) == NULL)
	{
		DTNMP_DEBUG_ERR("midcol_to_string","Can't alloc %d bytes.",
				        tot_size);
		for(i = 0; i < num_items; i++)
		{
			MRELEASE(mid_strs[i]);
		}
		MRELEASE(mid_strs);

		DTNMP_DEBUG_EXIT("midcol_to_string","->NULL",NULL);
		return NULL;
	}
	else
	{
		cursor = result;
	}

	/* Step 4: Fill in the MID collection string. */
	cursor += sprintf(cursor,"MC : ");
	for(i = 0; i < num_items; i++)
	{
		cursor += sprintf(cursor,"%s ",mid_strs[i]);
		MRELEASE(mid_strs[i]);
	}
	cursor += sprintf(cursor,".\n");
	MRELEASE(mid_strs);

	/* Step 5: Sanity check. */
	if((cursor - result) > tot_size)
	{
		DTNMP_DEBUG_ERR("midcol_to_string", "OVERWROTE! Alloc %d, wrote %llu.",
				tot_size, (cursor-result));
		MRELEASE(result);
		DTNMP_DEBUG_EXIT("mid_to_string","->NULL",NULL);
		return NULL;
	}

	DTNMP_DEBUG_INFO("midcol_to_string","Wrote %llu into %d string.",
					(cursor -result), tot_size);

	DTNMP_DEBUG_EXIT("midcol_to_string","->%#llx",result);

	return result;
}
Beispiel #3
0
void ui_print_reports(agent_t* agent)
{
	 LystElt report_elt;
	 LystElt entry_elt;
	 rpt_t *cur_report = NULL;
	 rpt_entry_t *cur_entry = NULL;

	 if(agent == NULL)
	 {
		 AMP_DEBUG_ENTRY("ui_print_reports","(NULL)", NULL);
		 AMP_DEBUG_ERR("ui_print_reports", "No agent specified", NULL);
		 AMP_DEBUG_EXIT("ui_print_reports", "->.", NULL);
		 return;

	 }
	 AMP_DEBUG_ENTRY("ui_print_reports","(%s)", agent->agent_eid.name);

	 if(lyst_length(agent->reports) == 0)
	 {
		 AMP_DEBUG_ALWAYS("ui_print_reports","[No reports received from this agent.]", NULL);
		 AMP_DEBUG_EXIT("ui_print_reports", "->.", NULL);
		 return;
	 }

	 /* Free any reports left in the reports list. */
	 for (report_elt = lyst_first(agent->reports); report_elt; report_elt = lyst_next(report_elt))
	 {
		 /* Grab the current report */
	     if((cur_report = (rpt_t*)lyst_data(report_elt)) == NULL)
	     {
	        AMP_DEBUG_ERR("ui_print_reports","Unable to get report from lyst!", NULL);
	     }
	     else
	     {
	    	 uvast mid_sizes = 0;
	    	 uvast data_sizes = 0;
	    	 int i = 1;

	    	 /* Print the Report Header */
	    	 printf("\n----------------------------------------");
	    	 printf("\n            DTNMP DATA REPORT           ");
	    	 printf("\n----------------------------------------");
	    	 printf("\nSent to   : %s", cur_report->recipient.name);
	    	 printf("\nTimestamp : %s", ctime(&(cur_report->time)));
	    	 printf("\n# Entries : %lu",
			 (unsigned long) lyst_length(cur_report->entries));
	    	 printf("\n----------------------------------------");

 	    	 /* For each MID in this report, print it. */
	    	 for(entry_elt = lyst_first(cur_report->entries); entry_elt; entry_elt = lyst_next(entry_elt))
	    	 {
	    		 printf("\nEntry %d ", i);
	    		 cur_entry = (rpt_entry_t*)lyst_data(entry_elt);
	    		 ui_print_entry(cur_entry, &mid_sizes, &data_sizes);
	    		 i++;
	    	 }

	    	 printf("\n----------------------------------------");
	    	 printf("\nSTATISTICS:");
	    	 printf("\nMIDs total "UVAST_FIELDSPEC" bytes", mid_sizes);
	    	 printf("\nData total: "UVAST_FIELDSPEC" bytes", data_sizes);
		 if ((mid_sizes + data_sizes) > 0)
		 {
	    	 	printf("\nEfficiency: %.2f%%", (double)(((double)data_sizes)/((double)mid_sizes + data_sizes)) * (double)100.0);
		 }

	    	 printf("\n----------------------------------------\n\n\n");
	     }
	 }
}
Beispiel #4
0
// THis is a DC of values? Generally, a typed data collection is a DC of values.
void ui_print_tdc(tdc_t *tdc, def_gen_t *cur_def)
{
	LystElt elt = NULL;
	LystElt def_elt = NULL;
	uint32_t i = 0;
	amp_type_e cur_type;
	blob_t *cur_entry = NULL;
	value_t *cur_val = NULL;

	if(tdc == NULL)
	{
		AMP_DEBUG_ERR("ui_print_tdc","Bad Args.", NULL);
		return;
	}

	if(cur_def != NULL)
	{
		if(lyst_length(cur_def->contents) != tdc->hdr.length)
		{
			AMP_DEBUG_WARN("ui_print_tdc","def and TDC length mismatch: %d != %d. Ignoring.",
					        lyst_length(cur_def->contents), tdc->hdr.length);
			cur_def = NULL;
		}
	}


	elt = lyst_first(tdc->datacol);
	if(cur_def != NULL)
	{
		def_elt = lyst_first(cur_def->contents);
	}

	for(i = 0; ((i < tdc->hdr.length) && elt); i++)
	{
		cur_type = (amp_type_e) tdc->hdr.data[i];

		printf("\n\t");
		if(cur_def != NULL)
		{
			printf("Value %d (", i);
			ui_print_mid((mid_t *) lyst_data(def_elt));
			printf(") ");
		}

		// \todo: Check return values.
		if((cur_entry = lyst_data(elt)) == NULL)
		{
			printf("NULL\n");
		}
		else
		{
			ui_print_val(cur_type, cur_entry->value, cur_entry->length);
		}


		elt = lyst_next(elt);

		if(cur_def != NULL)
		{
			def_elt = lyst_next(def_elt);
		}
	}

}
Beispiel #5
0
AmsMib	*loadMib(char *mibSource)
{
	AmsMib			*mib;
	int			result;
	int			i;
	TransSvc		*ts;
	AmsMibParameters	parms = { 0, NULL, NULL, NULL };

	lockMib();
	mib = _mib(NULL);
	if (mib)
	{
		mib->users += 1;
		unlockMib();
		return mib;	/*	MIB is already loaded.		*/
	}

	if (mibSource == NULL)
	{
		result = loadTestMib();
	}
	else
	{
#ifdef NOEXPAT
		result = loadMibFromRcSource(mibSource);
#else
		result = loadMibFromXmlSource(mibSource);
#endif
	}

	if (result < 0)
	{
		oK(_mib(&parms));	/*	Erase.			*/
		mib = NULL;
	}
	else
	{
		mib = _mib(NULL);
	}

	if (mib == NULL)
	{
		putErrmsg("Failed loading AMS MIB.", NULL);
		unlockMib();
		return NULL;
	}

	if (lyst_length(mib->amsEndpointSpecs) == 0)
	{
		for (i = 0, ts = mib->transportServices;
				i < mib->transportServiceCount; i++, ts++)
		{
			if (createAmsEpspec(ts->name, "@") == NULL)
			{
				putErrmsg("Can't load default AMS endpoint \
specs.", NULL);
				oK(_mib(&parms));	/*	Erase.	*/
				unlockMib();
				return NULL;
			}
		}
	}