Beispiel #1
0
void
ll_clean( struct linked_list **list )
{
	struct linked_list *iter = *list;
	struct linked_list_element *tmp;

	if( !ll_is_valid( iter ))
		return;

	while(( tmp = ll_get_head( iter )) != NULL )
	{
		ll_remove_head( iter );
		ll_free_element( ll_get_addr( tmp ));
	}

	free( iter );
}
Beispiel #2
0
/* retrieve a matching connection from the address information provided */
struct xbee_con *xbee_conFromAddress(struct xbee *xbee, struct xbee_conType *conType, struct xbee_conAddress *address) {
	struct xbee_con *con, *scon;
	
	/* check parameters */
	if (!xbee) {
		if (!xbee_default) return NULL;
		xbee = xbee_default;
	}
	if (!xbee_validate(xbee)) return NULL;
	if (!address) return NULL;
	if (!conType || !conType->initialized) return NULL;
	
	/* get the first connection, and return if there isn't one! */
	con = ll_get_head(&conType->conList);
	if (!con) return NULL;
	
	/* if both addresses are completely blank, just return the first connection (probably a local AT connection) */
	if ((!address->addr64_enabled && !address->addr16_enabled) &&
	    (!con->address.addr64_enabled && !con->address.addr16_enabled)) {
		return con;
	}
	
	scon = NULL;
	do {
		/* if both addresses have no 16 or 64-bit addressing information, match! */
		if ((!address->addr16_enabled && !con->address.addr16_enabled) &&
		    (!address->addr64_enabled && !con->address.addr64_enabled)) {
			goto got1;
		}

		/* check 64-bit addressing */
		if (address->addr64_enabled && con->address.addr64_enabled) {
			xbee_log(10,"Testing 64-bit address: 0x%02X%02X%02X%02X 0x%02X%02X%02X%02X", con->address.addr64[0],
			                                                                             con->address.addr64[1],
			                                                                             con->address.addr64[2],
			                                                                             con->address.addr64[3],
			                                                                             con->address.addr64[4],
			                                                                             con->address.addr64[5],
			                                                                             con->address.addr64[6],
			                                                                             con->address.addr64[7]);

			/* if 64-bit address matches, accept, else decline (don't even accept matching 16-bit address */
			if (!memcmp(address->addr64, con->address.addr64, 8)) {
				xbee_log(10,"    Success!");
				goto got1;
			}
		}

		/* check 16-bit addressing */
		if (address->addr16_enabled && con->address.addr16_enabled) {
			xbee_log(10,"Testing 16-bit address: 0x%02X%02X",  con->address.addr16[0], con->address.addr16[1]);
			/* if 16-bit address matches accept */
			if (!memcmp(address->addr16, con->address.addr16, 2)) {
				xbee_log(10,"    Success!");
				goto got1;
			}
		}

		/* nothing caused an 'accept', so try the next connection */
		continue; /* ############################################ */
		/* ###################################################### */

got1:
		/* if both connections have endpoints disabled, match! */
		if (!address->endpoints_enabled && !con->address.endpoints_enabled) goto got2;
		/* if both local endpoints match, match! */
		if (address->local_endpoint == con->address.local_endpoint) goto got2;

		/* nothing caused an 'accept', so try the next connection */
		continue; /* ############################################ */
		/* ###################################################### */

got2:
		/* if the connection is not sleeping, then we have our target!, otherwise continue the search */
		if (!con->sleeping) break;
		/* hold on to the last sleeping connection, just incase */
		scon = con;
	} while ((con = ll_get_next(&conType->conList, con)) != NULL);
	
	/* if we couldn't find a connection, return a sleeping connection (if any) */
	if (!con) return scon;
	return con;
}