Exemple #1
0
static void pike_top(rpc_t *rpc, void *c)
{

	DBG("pike: top");

	int i;
	void *handle;
	struct TopListItem_t *top_list_root;
	struct TopListItem_t *ti = 0;
	char addr_buff[40];
	char *ip_addr = 0;
	char *leaf_hits_prev = 0;
	char *leaf_hits_curr = 0;
	char *expires = 0;
	char *status = 0;
	size_t ip_addr_size = 0;
	size_t leaf_hits_prev_size = 0;
	size_t leaf_hits_curr_size = 0;
	size_t expires_size = 0;
	size_t status_size = 0;
	
	char *stropts;
	int   options = 0;
	
	/* obtain params */
	if (rpc->scan(c, "s", &stropts) <= 0)
		stropts = "HOT";

	DBG("pike:top: string options: '%s'", stropts);
	if ( strstr(stropts, "ALL") ) { 
		options = NODE_STATUS_ALL;
	} else if ( strstr(stropts, "HOT") ) {
		options |= NODE_STATUS_HOT;
	} else if ( strstr(stropts, "WARM") ) {
		options |= NODE_STATUS_WARM;
	}
	DBG("pike:top: options: 0x%02x\n", options);
	
	
	print_tree( 0 );
	
	collect_data(options);
	top_list_root = pike_top_get_root();
	DBG("pike_top: top_list_root = %p", top_list_root);
	
	rpc->add(c, "{", &handle);
	rpc->struct_add(handle, "d", "max_hits", get_max_hits());
	i = 0; // it is passed as number of rows
	if ( top_list_root == 0 ) {
		DBG("pike_top: no data");
	}
	else {
		for( ti = top_list_root, i = 0; ti != 0; ti = ti->next, ++i ) {
			pike_top_print_addr(ti->ip_addr, ti->addr_len, addr_buff, sizeof(addr_buff));
			DBG("pike:top: result[%d]: %s leaf_hits[%d,%d] hits[%d,%d] expires: %d status: 0x%02x",
					i, addr_buff, ti->leaf_hits[0], ti->leaf_hits[1],
					ti->hits[0], ti->hits[1], ti->expires, ti->status); 
			rpc->struct_add(handle, "sddds",
							concat(ip_addr, ip_addr_size, "ip_addr", i), addr_buff,
							concat(leaf_hits_prev, leaf_hits_prev_size, "leaf_hits_prev", i), ti->leaf_hits[0],
							concat(leaf_hits_curr, leaf_hits_curr_size, "leaf_hits_curr", i), ti->leaf_hits[1],
							concat(expires, expires_size, "expires", i), ti->expires,
							concat(status, status_size, "status", i), node_status_array[ti->status]);
		}
	}
	rpc->struct_add(handle, "d", "number_of_rows", i);
	/* free buffers */
	free(ip_addr);
	free(leaf_hits_prev);
	free(leaf_hits_curr);
	free(expires);
	free(status);
	pike_top_list_clear();
	
	rpc->send(c);
}
Exemple #2
0
/* if you do not need global buffer, you can use this simpler call */
static char *print_addr(unsigned char *ip, int iplen)
{
	return pike_top_print_addr(ip, iplen, buff, sizeof(buff));
}