예제 #1
0
파일: adm.c 프로젝트: brnrc/ion-dtn
void adm_destroy()
{
   LystElt elt = 0;

   for (elt = lyst_first(gAdmData); elt; elt = lyst_next(elt))
   {
	   adm_datadef_t *cur = (adm_datadef_t *) lyst_data(elt);
	   mid_release(cur->mid);
	   MRELEASE(cur);
   }
   lyst_destroy(gAdmData);
   gAdmData = NULL;

   for (elt = lyst_first(gAdmCtrls); elt; elt = lyst_next(elt))
   {
	   adm_ctrl_t *cur = (adm_ctrl_t *) lyst_data(elt);
	   mid_release(cur->mid);
	   MRELEASE(cur);
   }
   lyst_destroy(gAdmCtrls);
   gAdmCtrls = NULL;

   lyst_destroy(gAdmLiterals);
   gAdmLiterals = NULL;

   lyst_destroy(gAdmOps);
   gAdmOps = NULL;

}
예제 #2
0
파일: mid.c 프로젝트: brnrc/ion-dtn
/******************************************************************************
 *
 * \par Function Name: midcol_destroy
 *
 * \par Purpose: Destroy MID collection in a Lyst.
 *
 * \retval  NULL - Failure
 *         !NULL - The copied MID collection
 *
 * \param[in,out] mids The lyst being destroyed.
 *
 * \par Notes:
 *		1. We pass a double pointer for the honor of making sure the lyst is set
 *         to NULL when finished.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  11/14/12  E. Birrane     Initial implementation,
 *****************************************************************************/
void midcol_destroy(Lyst *mids)
{
	LystElt elt;
	mid_t *cur_mid = NULL;

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

	/*
	 * Step 0: Make sure we even have a lyst. Not an error if not, since we
	 * are destroying anyway.
	 */
	if((mids == NULL) || (*mids == NULL))
	{
		DTNMP_DEBUG_ERR("midcol_destroy","Bad Args.",NULL);
		DTNMP_DEBUG_EXIT("midcol_destroy","->.", NULL);
		return;
	}

	/* Step 1: Walk through the MIDs releasing as you go. */
    for(elt = lyst_first(*mids); elt; elt = lyst_next(elt))
    {
    	cur_mid = (mid_t *) lyst_data(elt);

    	if(cur_mid != NULL)
    	{
    		mid_release(cur_mid);
    	}
    }

    /* Step 2: Destroy and zero out the lyst. */
    lyst_destroy(*mids);
    *mids = NULL;

    DTNMP_DEBUG_EXIT("midcol_destroy","->.", NULL);
}
예제 #3
0
void ctrl_release(ctrl_exec_t *ctrl)
{
	if(ctrl != NULL)
	{
		mid_release(ctrl->mid);
		SRELEASE(ctrl);
	}
}
예제 #4
0
파일: report.c 프로젝트: brnrc/ion-dtn
void rpt_release_data_entry(rpt_data_entry_t *entry)
{
	if(entry != NULL)
	{
		MRELEASE(entry->contents);
		mid_release(entry->id);
		MRELEASE(entry);
	}

}
예제 #5
0
void msg_release_stat_msg(adm_stat_msg_t *msg)
{
	AMP_DEBUG_ENTRY("msg_release_stat_msg","(0x%x)",
			          (unsigned long) msg);

	if(msg != NULL)
	{
		mid_release(msg->code);
		midcol_destroy(&(msg->generators));
		SRELEASE(msg);
	}

	AMP_DEBUG_EXIT("msg_release_stat_msg","->.",NULL);
}
예제 #6
0
void wframe::mouseReleaseEvent(QMouseEvent *event)
{
	emit release(event);

	if(event->button() == Qt::RightButton)
	{
		emit right_release();
	}
	else if(event->button() == Qt::LeftButton)
	{
		emit left_release(event);
	}
	else if(event->button() == Qt::MidButton)
	{
		emit mid_release();
	}
}
예제 #7
0
파일: adm.c 프로젝트: brnrc/ion-dtn
/******************************************************************************
 *
 * \par Function Name: adm_add_datadef_collect
 *
 * \par Registers a collection function to a data definition.
 *
 * \param[in] mid_str   serialized MID value
 * \param[in] collect   The data collection function.
 *
 * \par Notes:
 *		1. When working with parameterized OIDs, the given MID should
 *		   be all information excluding the parameterized portion of the OID.
 *		2. ADM names will be truncated after ADM_MAX_NAME bytes.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  11/25/12  E. Birrane     Initial implementation.
 *  07/27/13  E. BIrrane     Updated ADM to use Lysts.
 *****************************************************************************/
void adm_add_datadef_collect(uint8_t *mid_str, adm_data_collect_fn collect)
{
	uint32_t used = 0;
	mid_t *mid = NULL;
	adm_datadef_t *entry = NULL;

	DTNMP_DEBUG_ENTRY("adm_add_datadef_collect","(%lld, %lld)", mid_str, collect);

	if((mid_str == NULL) || (collect == NULL))
	{
		DTNMP_DEBUG_ERR("adm_add_datadef_collect","Bad Args.", NULL);
		DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL);
		return;
	}

	if((mid = mid_deserialize(mid_str, ADM_MID_ALLOC, &used)) == NULL)
	{
		char *tmp = utils_hex_to_string(mid_str, ADM_MID_ALLOC);
		DTNMP_DEBUG_ERR("adm_add_datadef_collect","Can't deserialize MID str %s.",tmp);
		MRELEASE(tmp);

		DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL);
		return;
	}

	if((entry = adm_find_datadef(mid)) == NULL)
	{
		char *tmp = mid_to_string(mid);
		DTNMP_DEBUG_ERR("adm_add_datadef_collect","Can't find data for MID %s.", tmp);
		MRELEASE(tmp);
	}
	else
	{
		entry->collect = collect;
	}

	mid_release(mid);

	DTNMP_DEBUG_EXIT("adm_add_datadef_collect","->.", NULL);
}
예제 #8
0
파일: adm.c 프로젝트: brnrc/ion-dtn
void adm_add_ctrl_run(uint8_t *mid_str, adm_ctrl_fn run)
{
	uint32_t used = 0;
	mid_t *mid = NULL;
	adm_ctrl_t *entry = NULL;

	DTNMP_DEBUG_ENTRY("adm_add_ctrl_run","(%lld, %lld)", mid_str, run);

	if((mid_str == NULL) || (run == NULL))
	{
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Bad Args.", NULL);
		DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
		return;
	}

	if((mid = mid_deserialize(mid_str, ADM_MID_ALLOC, &used)) == NULL)
	{
		char *tmp = utils_hex_to_string(mid_str, ADM_MID_ALLOC);
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't deserialized MID %s", tmp);
		MRELEASE(tmp);
		DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
		return;
	}

	if((entry = adm_find_ctrl(mid)) == NULL)
	{
		char *tmp = mid_to_string(mid);
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't find control for MID %s", tmp);
		MRELEASE(tmp);
	}
	else
	{
		entry->run = run;
	}

	mid_release(mid);

	DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
}
예제 #9
0
파일: mid.c 프로젝트: brnrc/ion-dtn
/******************************************************************************
 *
 * \par Function Name: mid_deserialize
 *
 * \par Extracts a MID from a byte buffer.
 *
 * \retval NULL - Failure
 *         !NULL - The created/deserialized MID.
 *
 * \param[in]  buffer       The byte buffer holding the MID data
 * \param[in]  buffer_size  The # bytes available in the buffer
 * \param[out] bytes_used   The # of bytes consumed in the deserialization.
 *
 * \par Notes:
 * \todo: Allow a NULL bytes_used for cases where we are not deserializing
 *        from a larger stream.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  10/22/12  E. Birrane     Initial implementation,
 *  06/25/13  E. Birrane     Removed references to priority field.
 *****************************************************************************/
mid_t *mid_deserialize(unsigned char *buffer,
		               uint32_t  buffer_size,
		               uint32_t *bytes_used)
{
    mid_t *result = NULL;
    unsigned char *cursor = NULL;
    int sdnv_len = 0;
    uint32_t cur_bytes = 0;
    uint32_t bytes_left=0;

    DTNMP_DEBUG_ENTRY("mid_deserialize","(%#llx, %d, %#llx)",
                     (unsigned long) buffer,
                     (unsigned long) buffer_size,
                     (unsigned long) bytes_used);

    *bytes_used = 0;

    /* Step 1: Sanity checks. */
    if((buffer == NULL) || (buffer_size == 0) || (bytes_used == NULL))
    {
        DTNMP_DEBUG_ERR("mid_deserialize","Bad params.",NULL);
        DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
        return NULL;
    }
    else
    {
    	*bytes_used = 0;
    	cursor = buffer;
    	bytes_left = buffer_size;
    }

    /* Step 2: Allocate/Zero the MID. */
    if((result = (mid_t *) MTAKE(sizeof(mid_t))) == NULL)
    {
        DTNMP_DEBUG_ERR("mid_deserialize","Cannot allocate MID of size %d",
        		        sizeof(mid_t));
        DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
        return NULL;
    }
    else
    {
        memset(result,0,sizeof(mid_t));
    }

    /* Step 3: Grab the MID flag */
    if(utils_grab_byte(cursor, bytes_left, &(result->flags)) != 1)
    {
    	DTNMP_DEBUG_ERR("mid_deserialize","Can't grab flag byte.", NULL);
    	mid_release(result);

        DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
        return NULL;
    }
    else
    {
    	cursor += 1;
    	bytes_left -= 1;
    	*bytes_used += 1;
    }

    /* Step 4: Break out flag...*/
    result->type = MID_GET_FLAG_TYPE(result->flags);
    result->category = MID_GET_FLAG_CAT(result->flags);

    /* Step 5: Grab issuer, if present. Issuers MUST exist for non-atomic.*/
    if(MID_GET_FLAG_ISS(result->flags))
    {
    	cur_bytes = utils_grab_sdnv(cursor, bytes_left, &(result->issuer));
        if( cur_bytes == 0)
        {
        	DTNMP_DEBUG_ERR("mid_deserialize","Can't grab issuer.", NULL);
        	mid_release(result);

            DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
            return NULL;
        }
        else
        {
        	cursor += cur_bytes;
        	bytes_left -= cur_bytes;
        	*bytes_used += cur_bytes;
        }
    }

    /* Step 6: Grab the OID. */
    switch(MID_GET_FLAG_OID(result->flags))
    {
    	case OID_TYPE_FULL:
    		result->oid = oid_deserialize_full(cursor, bytes_left, &cur_bytes);
    		break;
    	case OID_TYPE_PARAM:
    		result->oid = oid_deserialize_param(cursor, bytes_left, &cur_bytes);
    		break;
    	case OID_TYPE_COMP_FULL:
    		result->oid = oid_deserialize_comp(cursor, bytes_left, &cur_bytes);
    		break;
    	case OID_TYPE_COMP_PARAM:
    		result->oid = oid_deserialize_comp_param(cursor, bytes_left, &cur_bytes);
    		break;
    	default:
    		result->oid = NULL;
    		cur_bytes = 0;
    		break;
    }

    if(result->oid == NULL)
    {
    	DTNMP_DEBUG_ERR("mid_deserialize","Can't grab oid.", NULL);
    	mid_release(result);

        DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
        return NULL;
    }
    else
    {
    	cursor += cur_bytes;
    	bytes_left -= cur_bytes;
    	*bytes_used += cur_bytes;
    	result->oid->type = MID_GET_FLAG_OID(result->flags);
    }


    /* Step 7: Populate Tag if preset. */
    if(MID_GET_FLAG_TAG(result->flags))
    {
    	cur_bytes = utils_grab_sdnv(cursor, bytes_left, &(result->tag));
        if( cur_bytes == 0)
        {
        	DTNMP_DEBUG_ERR("mid_deserialize","Can't grab tag.", NULL);
        	mid_release(result);

            DTNMP_DEBUG_EXIT("mid_deserialize","-> NULL", NULL);
            return NULL;
        }
        else
        {
        	cursor += cur_bytes;
        	bytes_left -= cur_bytes;
        	*bytes_used += cur_bytes;
        }
    }

    /* Step 8: Is this a sane MID? */
    if(mid_sanity_check(result) == 0)
    {
    	DTNMP_DEBUG_ERR("mid_deserialize","Flags Sanity Check Failed.", NULL);
    	mid_release(result);

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

    /* Step 9: Copy MID into the raw value. */
    if((result->raw = (unsigned char *) MTAKE(*bytes_used)) == NULL)
    {
        DTNMP_DEBUG_ERR("mid_deserialize","Can't TAKE raw mid of size (%d)",
        		        *bytes_used);
        mid_release(result);

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

    memcpy(result->raw, buffer, *bytes_used);
    result->raw_size = *bytes_used;

    DTNMP_DEBUG_EXIT("mid_deserialize","-> %#llx", (unsigned long) result);
    return result;
}
예제 #10
0
파일: mid.c 프로젝트: brnrc/ion-dtn
mid_t *mid_construct(uint8_t type, uint8_t cat,
		             uvast *issuer, uvast *tag, oid_t *oid)
{
	mid_t *mid = NULL;
	DTNMP_DEBUG_ENTRY("mid_construct","(%#llx, %#llx, %#llx, %#llx, %#llx",
			         type, cat,
			         (unsigned long) issuer, (unsigned long) tag,
			         (unsigned long) oid);


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

	/* Step 1: Allocate the MID. */
	if((mid = (mid_t *)MTAKE(sizeof(mid_t))) == NULL)
	{
		DTNMP_DEBUG_ERR("mid_construct","Can't allocate %d bytes.",
				        sizeof(mid_t));
		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}

	/* Step 2: Populate the MID. */

	/* Flag */
	mid->flags =  (oid->type & 0x03) << 6;
	mid->flags |= (tag != NULL) ? 0x20 : 0x00;
	mid->flags |= (issuer != NULL) ? 0x10 : 0x00;
	mid->flags |= (cat & 0x03) << 2;
	mid->flags |= (type & 0x03);

	/* Shallow copies */
	mid->type     = type;
	mid->category = cat;
	mid->issuer   = (issuer != NULL) ? *issuer : 0;
	mid->tag      = (tag != NULL) ? *tag : 0;

	if((mid->oid = oid_copy(oid)) == NULL)
	{
		DTNMP_DEBUG_ERR("mid_construct","Failed to copy OID.",NULL);

		MRELEASE(mid);
		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}

	/* Step 3: Build the serialized MID. */
	if (mid_internal_serialize(mid) == 0)
	{
		DTNMP_DEBUG_ERR("mid_construct","Failed to serialize MID.",NULL);

		mid_release(mid);

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


	DTNMP_DEBUG_EXIT("mid_construct","->0x%x",(unsigned long)mid);
	return mid;
}
예제 #11
0
void ui_print_val(uint8_t type, uint8_t *data, uint32_t length)
{
	uint32_t bytes = 0;

	if(data == NULL)
	{
		printf("NULL");
		return;
	}



	switch(type)
	{
		case AMP_TYPE_VAR:
		{
			var_t *cd = var_deserialize(data, length, &bytes);
			char *str = var_to_string(cd);
			printf("%s", str);
			SRELEASE(str);
			var_release(cd);
		}
			break;

		case AMP_TYPE_INT:
			printf("%d", utils_deserialize_int(data, length, &bytes));
			break;

		case AMP_TYPE_TS:
		case AMP_TYPE_UINT:
			printf("%d", utils_deserialize_uint(data, length, &bytes));
			break;

		case AMP_TYPE_VAST:
			printf(VAST_FIELDSPEC, utils_deserialize_vast(data, length, &bytes));
			break;

		case AMP_TYPE_SDNV:
		case AMP_TYPE_UVAST:
			printf(UVAST_FIELDSPEC, utils_deserialize_uvast(data, length, &bytes));
			break;

		case AMP_TYPE_REAL32:
			printf("%f", utils_deserialize_real32(data, length, &bytes));
			break;

		case AMP_TYPE_REAL64:
			printf("%f", utils_deserialize_real64(data, length, &bytes));
			break;

		case AMP_TYPE_STRING:
			{
				char* tmp = NULL;
				tmp = utils_deserialize_string(data, length, &bytes);
				printf("%s", tmp);
				SRELEASE(tmp);
			}
			break;

		case AMP_TYPE_BLOB:
			{
				blob_t *blob = blob_deserialize(data, length, &bytes);
				char *str = blob_to_str(blob);
				printf("%s", str);
				SRELEASE(str);
				SRELEASE(blob);
			}
			break;

		case AMP_TYPE_DC:
			{
				uint32_t bytes = 0;
				Lyst dc = dc_deserialize(data, length, &bytes);
				ui_print_dc(dc);
				dc_destroy(&dc);
			}
			break;

		case AMP_TYPE_MID:
			{
				uint32_t bytes = 0;
				mid_t *mid = mid_deserialize(data, length, &bytes);
				ui_print_mid(mid);
				mid_release(mid);
			}
			break;

		case AMP_TYPE_MC:
			{
				uint32_t bytes = 0;
				Lyst mc = midcol_deserialize(data, length, &bytes);
				ui_print_mc(mc);
				midcol_destroy(&mc);
			}
			break;
			// \todo: Expression has no priority. Need to re-think priority.

		case AMP_TYPE_EXPR:
			{
				uint32_t bytes = 0;
				expr_t *expr = expr_deserialize(data, length, &bytes);
				ui_print_expr(expr);
				expr_release(expr);
			}
			break;

/*		case DTNMP_TYPE_DEF:
			{
				uint32_t bytes = 0;
				def_gen_t *def = def_deserialize_gen(data, length, &bytes);
				ui_print_def(def);
				def_release_gen(def);
			}
			break;
*/
		case AMP_TYPE_TRL:
			{
				uint32_t bytes = 0;
				trl_t *trl = trl_deserialize(data, length, &bytes);
				ui_print_trl(trl);
				trl_release(trl);
			}
			break;

		case AMP_TYPE_TABLE:
			{
				uint32_t bytes = 0;
				table_t *table = table_deserialize(data, length, &bytes);
				ui_print_table(table);
				table_destroy(table, 1);
			}
			break;

		case AMP_TYPE_SRL:
			{
				uint32_t bytes = 0;
				srl_t *srl = srl_deserialize(data, length, &bytes);
				ui_print_srl(srl);
				srl_release(srl);
			}
			break;

		default:
			printf("Unknown.");
	}
}