Browse Source

pike: reformatted code for pike top rpc command

Daniel-Constantin Mierla 9 years ago
parent
commit
9703095ccd
3 changed files with 35 additions and 16 deletions
  1. 19 9
      modules/pike/pike_rpc.c
  2. 11 5
      modules/pike/pike_top.c
  3. 5 2
      modules/pike/pike_top.h

+ 19 - 9
modules/pike/pike_rpc.c

@@ -53,25 +53,33 @@ static void traverse_subtree( struct ip_node *node, int depth, int options )
 
 
 	if ( node->flags & NODE_IPLEAF_FLAG ) {
 	if ( node->flags & NODE_IPLEAF_FLAG ) {
 		int ns = node_status(node);
 		int ns = node_status(node);
-		DBG("pike:traverse_subtree: options: 0x%02x, node status: 0x%02x", options, ns);
+		DBG("pike:traverse_subtree: options: 0x%02x, node status: 0x%02x",
+				options, ns);
 		/* add to the result list if it has requested status */
 		/* add to the result list if it has requested status */
 		switch (options) {
 		switch (options) {
 			case NODE_STATUS_HOT:
 			case NODE_STATUS_HOT:
 						if ( ns & NODE_STATUS_HOT )
 						if ( ns & NODE_STATUS_HOT )
-							pike_top_add_entry(ip_addr, depth+1, node->leaf_hits, node->hits, node->expires - get_ticks(), ns);
+							pike_top_add_entry(ip_addr, depth+1,
+									node->leaf_hits, node->hits,
+									node->expires - get_ticks(), ns);
 						break;
 						break;
 			case NODE_STATUS_ALL:
 			case NODE_STATUS_ALL:
-						pike_top_add_entry(ip_addr, depth+1, node->leaf_hits, node->hits, node->expires - get_ticks(), ns);
+						pike_top_add_entry(ip_addr, depth+1, node->leaf_hits,
+								node->hits, node->expires - get_ticks(), ns);
 						break;
 						break;
 		}
 		}
 	}
 	}
-	else if (! node->kids) {	/* TODO non IP leaf of ip_tree - it is possible to report WARM nodes here */
+	else if (! node->kids) {
+		/* TODO non IP leaf of ip_tree - it is possible to report WARM nodes here */
 /*		if ( options == ns )
 /*		if ( options == ns )
-			pike_top_add_entry(ip_addr, depth+1, node->leaf_hits, node->hits, node->expires - get_ticks(), ns);
+			pike_top_add_entry(ip_addr, depth+1, node->leaf_hits, node->hits,
+					node->expires - get_ticks(), ns);
 */	}
 */	}
 	else {	/* not a any kind of leaf - inner node */
 	else {	/* not a any kind of leaf - inner node */
-		DBG("pike:rpc traverse_subtree, not IP leaf, depth: %d, ip: %d.%d.%d.%d   hits[%d,%d], expires: %d",
-			depth, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], node->hits[0], node->hits[1], node->expires - get_ticks());
+		DBG("pike:rpc traverse_subtree, not IP leaf, depth: %d, ip: %d.%d.%d.%d"
+				"   hits[%d,%d], expires: %d",
+			depth, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3],
+			node->hits[0], node->hits[1], node->expires - get_ticks());
 	}
 	}
 
 
 	foo = node->kids;
 	foo = node->kids;
@@ -150,8 +158,10 @@ static void pike_top(rpc_t *rpc, void *c)
 	}
 	}
 	else {
 	else {
 		for( ti = top_list_root, i = 0; ti != 0; ti = ti->next, ++i ) {
 		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",
+			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],
 					i, addr_buff, ti->leaf_hits[0], ti->leaf_hits[1],
 					ti->hits[0], ti->hits[1], ti->expires, ti->status);
 					ti->hits[0], ti->hits[1], ti->expires, ti->status);
 			rpc->array_add(list, "{", &item);
 			rpc->array_add(list, "{", &item);

+ 11 - 5
modules/pike/pike_top.c

@@ -37,7 +37,8 @@ static char buff[PIKE_BUFF_SIZE];
 
 
 struct TopListItem_t *pike_top_get_root() { return top_list_root; }
 struct TopListItem_t *pike_top_get_root() { return top_list_root; }
 
 
-char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff, int buffsize )
+char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff,
+		int buffsize )
 {
 {
 	unsigned short *ipv6_ptr = (unsigned short *)ip;
 	unsigned short *ipv6_ptr = (unsigned short *)ip;
 	memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
 	memset(buff, 0, PIKE_BUFF_SIZE*sizeof(char));
@@ -52,8 +53,10 @@ char *pike_top_print_addr( unsigned char *ip, int iplen, char *buff, int buffsiz
 	}
 	}
 	else {
 	else {
 		sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
 		sprintf( buff, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
-				htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]), htons(ipv6_ptr[3]),
-				htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]), htons(ipv6_ptr[7]));
+				htons(ipv6_ptr[0]), htons(ipv6_ptr[1]), htons(ipv6_ptr[2]),
+				htons(ipv6_ptr[3]),
+				htons(ipv6_ptr[4]), htons(ipv6_ptr[5]), htons(ipv6_ptr[6]),
+				htons(ipv6_ptr[7]));
 	}
 	}
 
 
 	return buff;
 	return buff;
@@ -65,9 +68,12 @@ static char *print_addr(unsigned char *ip, int iplen)
 	return pike_top_print_addr(ip, iplen, buff, sizeof(buff));
 	return pike_top_print_addr(ip, iplen, buff, sizeof(buff));
 }
 }
 
 
-int pike_top_add_entry( unsigned char *ip_addr, int addr_len, unsigned short leaf_hits[2], unsigned short hits[2], unsigned int expires, node_status_t status )
+int pike_top_add_entry( unsigned char *ip_addr, int addr_len,
+		unsigned short leaf_hits[2], unsigned short hits[2],
+		unsigned int expires, node_status_t status )
 {
 {
-	struct TopListItem_t *new_item = (struct TopListItem_t *)malloc(sizeof(struct TopListItem_t));
+	struct TopListItem_t *new_item
+				= (struct TopListItem_t *)malloc(sizeof(struct TopListItem_t));
 
 
 	print_addr(ip_addr, addr_len);
 	print_addr(ip_addr, addr_len);
 	DBG("pike_top_add_enrty(ip: %s, leaf_hits[%d,%d], hits[%d,%d],"
 	DBG("pike_top_add_enrty(ip: %s, leaf_hits[%d,%d], hits[%d,%d],"

+ 5 - 2
modules/pike/pike_top.h

@@ -38,13 +38,16 @@ struct TopListItem_t {
 };
 };
 
 
 // returns 1 when OK and 0 when failed
 // returns 1 when OK and 0 when failed
-int pike_top_add_entry( unsigned char *ip_addr, int addr_len, unsigned short leaf_hits[2], unsigned short hits[2], unsigned int expires, node_status_t status );
+int pike_top_add_entry( unsigned char *ip_addr, int addr_len,
+		unsigned short leaf_hits[2], unsigned short hits[2],
+		unsigned int expires, node_status_t status );
 
 
 struct TopListItem_t *pike_top_get_root();
 struct TopListItem_t *pike_top_get_root();
 void pike_top_list_clear();
 void pike_top_list_clear();
 
 
 /* helpful functions */
 /* helpful functions */
-char *pike_top_print_addr( unsigned char *ip_addr, int addrlen, char *buff, int buffsize );
+char *pike_top_print_addr( unsigned char *ip_addr, int addrlen,
+		char *buff, int buffsize );
 
 
 
 
 #endif // PIKE_TOP_H
 #endif // PIKE_TOP_H