pike_mi.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pike_mi.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Header file for PIKE MI functions
00005  *
00006  * Copyright (C) 2006 Voice Sistem SRL
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2006-12-05  created (bogdan)
00027  */
00028 
00029 #include "ip_tree.h"
00030 #include "pike_mi.h"
00031 
00032 #define IPv6_LEN 16
00033 #define IPv4_LEN 4
00034 #define MAX_IP_LEN IPv6_LEN
00035 
00036 
00037 static struct ip_node *ip_stack[MAX_IP_LEN];
00038 
00039 
00040 static inline void print_ip_stack( int level, struct mi_node *node)
00041 {
00042    if (level==IPv6_LEN) {
00043       /* IPv6 */
00044       addf_mi_node_child( node, 0, 0, 0,
00045          "%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
00046          ip_stack[0]->byte,  ip_stack[1]->byte,
00047          ip_stack[2]->byte,  ip_stack[3]->byte,
00048          ip_stack[4]->byte,  ip_stack[5]->byte,
00049          ip_stack[6]->byte,  ip_stack[7]->byte,
00050          ip_stack[8]->byte,  ip_stack[9]->byte,
00051          ip_stack[10]->byte, ip_stack[11]->byte,
00052          ip_stack[12]->byte, ip_stack[13]->byte,
00053          ip_stack[14]->byte, ip_stack[15]->byte );
00054    } else if (level==IPv4_LEN) {
00055       /* IPv4 */
00056       addf_mi_node_child( node, 0, 0, 0, "%d.%d.%d.%d",
00057          ip_stack[0]->byte,
00058          ip_stack[1]->byte,
00059          ip_stack[2]->byte,
00060          ip_stack[3]->byte );
00061    } else {
00062       LM_CRIT("leaf node at depth %d!!!\n", level);
00063       return;
00064    }
00065 }
00066 
00067 
00068 static void print_red_ips( struct ip_node *ip, int level, struct mi_node *node)
00069 {
00070    struct ip_node *foo;
00071 
00072    if (level==MAX_IP_LEN) {
00073       LM_CRIT("tree deeper than %d!!!\n", MAX_IP_LEN);
00074       return;
00075    }
00076    ip_stack[level] = ip;
00077 
00078    /* is the node marked red? */
00079    if ( ip->flags&NODE_ISRED_FLAG)
00080       print_ip_stack(level+1,node);
00081 
00082    /* go through all kids */
00083    foo = ip->kids;
00084    while(foo){
00085       print_red_ips( foo, level+1, node);
00086       foo = foo->next;
00087    }
00088 
00089 }
00090 
00091 
00092 
00093 /*
00094   Syntax of "pike_list" :
00095     no nodes
00096 */
00097 struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param)
00098 {
00099    struct mi_root* rpl_tree;
00100    struct ip_node *ip;
00101    int i;
00102 
00103    rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
00104    if (rpl_tree==0)
00105       return 0;
00106 
00107    for( i=0 ; i<MAX_IP_BRANCHES ; i++ ) {
00108 
00109       if (get_tree_branch(i)==0)
00110          continue;
00111 
00112       lock_tree_branch(i);
00113 
00114       if ( (ip=get_tree_branch(i))!=NULL )
00115          print_red_ips( ip, 0, &rpl_tree->node );
00116 
00117       unlock_tree_branch(i);
00118    }
00119 
00120    return rpl_tree;
00121 }
00122 
00123 

Generated on Thu May 24 02:00:29 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6