From 9703095ccd14dd591669f4c6830147a4028994a9 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 6 Oct 2016 17:03:27 +0200 Subject: [PATCH] pike: reformatted code for pike top rpc command --- modules/pike/pike_rpc.c | 28 +++++++++++++++++++--------- modules/pike/pike_top.c | 16 +++++++++++----- modules/pike/pike_top.h | 7 +++++-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/modules/pike/pike_rpc.c b/modules/pike/pike_rpc.c index ef2d171ceda..9c74e9e2927 100644 --- a/modules/pike/pike_rpc.c +++ b/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 ) { 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 */ switch (options) { case 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; 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; } } - 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 ) - 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 */ - 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; @@ -150,8 +158,10 @@ static void pike_top(rpc_t *rpc, void *c) } 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", + 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->array_add(list, "{", &item); diff --git a/modules/pike/pike_top.c b/modules/pike/pike_top.c index e187a0b91e6..2d49a550190 100644 --- a/modules/pike/pike_top.c +++ b/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; } -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; 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 { 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; @@ -65,9 +68,12 @@ static char *print_addr(unsigned char *ip, int iplen) 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); DBG("pike_top_add_enrty(ip: %s, leaf_hits[%d,%d], hits[%d,%d]," diff --git a/modules/pike/pike_top.h b/modules/pike/pike_top.h index 74bb8e30a3e..fc15bbe053a 100644 --- a/modules/pike/pike_top.h +++ b/modules/pike/pike_top.h @@ -38,13 +38,16 @@ struct TopListItem_t { }; // 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(); void pike_top_list_clear(); /* 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