Ejemplo n.º 1
0
static void
extract_orb2orb_orbargs( char *what, char *cmdline_fromorb, char *cmdline_toorb )
{
	char	*split_what;
	Tbl	*orb2orb_args;

	split_what = strdup( what );
	orb2orb_args = split( split_what, ' ' );

	shifttbl( orb2orb_args );
	strcpy( cmdline_fromorb, shifttbl( orb2orb_args ) );

	if( cmdline_fromorb[0] == '-' ) {

		/* Old style orb2orb command-line; 
		 * assume no start-time, period, 
		 * or end-time are specified:
		 */
		strcpy( cmdline_toorb, poptbl( orb2orb_args ) );
		strcpy( cmdline_fromorb, poptbl( orb2orb_args ) );
		
	} else {

		strcpy( cmdline_toorb, shifttbl( orb2orb_args ) );
	}

	free( split_what );
	freetbl( orb2orb_args, 0 );

	return;
}
Ejemplo n.º 2
0
int
sinfo_update ( Arr * sold, Arr * snew )
{
   int i;
   int n1, n2;
   int numfields;
   char * field;
   char * value;
   char * newval;
   char * oldval;
   int newp, oldp;
   Tbl * fields;

   fields = keysarr( getpf( snew, FIELDS ) );

   numfields = maxtbl( fields );
   for ( i = 0; i < numfields; i++ )
   {
       field = (char*) poptbl( fields );
       value = get_station_field( snew, field );
       oldval = get_station_field( sold, field );
       if ( strcmp( field, LATENCY ) == 0 )
       {
           newp = atoi( getpf( snew, LATENCY_ORDER ) );
           oldp = atoi( getpf( sold, LATENCY_ORDER ) );
           if ( ( !oldp  && newp ) || ( newp < oldp ) )
           {
               set_station_field( sold, field, strdup(value) );
               setarr( sold, LATENCY_ORDER, create_pf( itoa(newp), PFSTRING ) );
           }
           else if ( ( ( newp == oldp ) || ( !newp && !oldp ) ) && 
                     ( atoi( value ) < atoi( oldval ) ) )
           {
               set_station_field( sold, field, strdup(value) );
               setarr( sold, LATENCY_ORDER, create_pf( itoa(newp), PFSTRING ) );
           }
       }
       else
           /* If this is a channels value, we want to merge the values */
           if ( strcmp( field, NUMCHANS ) == 0 )
           {
               (!value)? (n1 = 0): (n1 = atoi( value ));
               (!oldval)? (n2 = 0): (n2 = atoi( oldval ));
               set_station_field( sold, field, itoa( n1 + n2 ) );
           }
           else
               if ( value != NULL )
                   set_station_field( sold, field, strdup(value) );
       
   }
   freetbl( fields, 0 );

   return 1;
}
Ejemplo n.º 3
0
int
clrarr( Arr * arr, void (*free_value )() )
{
    Tbl * tbl;
    char * key;
    void * oldval;
    int size;
    int i;

    tbl = keysarr( arr );
    size = maxtbl( tbl );
    for ( i = 0; i < size; i++ )
    {
        key = poptbl( tbl );
        oldval = delarr( arr, key );
        if ( oldval ) free_value( oldval );
    }
    freetbl( tbl, 0 );

    return 1;
}
Ejemplo n.º 4
0
int
get_priority( char * alert_name, orbinfo * oi )
{
    int i;
    int size;
    Arr * level;
    Tbl * alerttbl;

    alerttbl = valsarr( oi->alert_stages );
    size = maxtbl( alerttbl );
    for ( i = 0; i < size; i++ )
    {
        level = (Arr*) poptbl( alerttbl );
        if ( strcmp( getarr( level, NAME ), alert_name ) == 0 )
        {
            freetbl( alerttbl, 0 );
            return atoi( getarr( level, PRIORITY ));
        }
    }
    freetbl( alerttbl, 0 );
    return -1;
}
Ejemplo n.º 5
0
/* Recursively removes pf instances from the pf object and returns the
 * objects' contents in an entirely new structure so that no memory is reused.
 * Requires the caller have some knowledge about the structure of the data. */
void *
pf_collapse( Pf * pf )
{
    Arr * currarr;
    Tbl * currtbl;
    char * key;
    void * value;
    int i;
    int size;
    
    if ( pf == NULL ) return NULL;
    switch( pf->type )
    {
        case PFARR:     currtbl = keysarr( pf->value.arr );
                        size = maxtbl( currtbl );
                        /* currarr = newarr( pf->value.arr->rb_comp ); */
                        currarr = newarr( strcmp );
                        for ( i = 0; i < size; i++ )
                        {
                            key = poptbl( currtbl );
                            value = pf_collapse( getarr( pf->value.arr, key ) );
                            setarr( currarr, key, value );
                        }
                        freetbl( currtbl, 0 );
                        return currarr;

        case PFTBL:     size = maxtbl( pf->value.tbl );
                        currtbl = newtbl( size );
                        for ( i = 0; i < size; i++ )
                            settbl( currtbl, i,
                                    pf_collapse( gettbl( pf->value.tbl, i ) ) );
                        return currtbl;

        default:        return strdup( pf->value.s );
    }
}
Ejemplo n.º 6
0
static void
parse_orbname( char *orbname, char *orb_address, int *orb_port )
{
	char	*split_orbname;
	Tbl	*orbname_parts;
	char	orbname_port[STRSZ];
	Hook	*hook = 0;
	static Pf *pfnames = 0;
	int	len = 0;
		
	if( STREQ( orbname, ":" ) ) {
		
		strcpy( orb_address, "127.0.0.1" );
		strcpy( orbname_port, "" );

	} else {
		
		split_orbname = strdup( orbname );
		orbname_parts = split( split_orbname, ':' );

		if( maxtbl( orbname_parts ) == 1 && orbname[0] == ':' ) {

			strcpy( orb_address, "127.0.0.1" );
			strcpy( orbname_port, poptbl( orbname_parts ) );

		} else if( maxtbl( orbname_parts ) == 1 ) {

			strcpy( orb_address, shifttbl( orbname_parts ) );
			strcpy( orbname_port, "" );

		} else if( maxtbl( orbname_parts ) == 2 ) {

			strcpy( orb_address, shifttbl( orbname_parts ) );
			strcpy( orbname_port, poptbl( orbname_parts ) );

		} else {

			elog_complain( 0, "pforbstat: unexpected error translating orb2orb argument <%s>\n",
				  orbname );
			strcpy( orb_address, "" );
			strcpy( orbname_port, "" );
		}

		free( split_orbname );
		freetbl( orbname_parts, 0 );
	}

	if( ( len = strlen( orbname_port ) ) > 0 ) {

		if( orbname_port[len-1] == '@' ) {
			
			orbname_port[len-1] = '\0';
		}
	}

	if( STREQ( orbname_port, "" ) ) {
		
		*orb_port = ORB_TCP_PORT;

	} else if( strmatches( orbname_port, "^[0-9]+$", &hook ) ) {
		
		*orb_port = atoi( orbname_port );

	} else {

		if( pfnames == 0 ) {

			pfread( "orbserver_names", &pfnames );
		}

		if( pfget_string( pfnames, orbname_port ) == 0 ) {

			elog_complain( 0, "pforbstat: couldn't translate orb port \":%s\"\n", orbname_port );

			*orb_port = 0;

		} else {
		
			*orb_port = pfget_int( pfnames, orbname_port );
		}
	}

	return;
}
Ejemplo n.º 7
0
int
set_sinfo_limits( Arr * sinfo, orbinfo * oi, char * pkttype )
{
    int i, j;
    int size, size2;
    int numalerts;
    Arr * alert_ranges;
    Arr* ranges; 
    Arr * oldval;
    Pf * newfieldlist;
    Arr * field;
    Pf * thresholds;
    Pf * thresh;
    double high;
    double low;
    double * val;
    Tbl* levels;
    Tbl* byfield;
    Tbl* fields;
    char* level;
    char * name;
    int priority = 0;

    /* Find the alert thresholds applicable to this packet type. If packet
       type not mentioned by name, use the default values. */
       
    if ( !( ranges = getarr( oi->alert_ranges, pkttype) ) ) 
       if ( !( ranges = getarr( oi->alert_ranges, "all") ) ) return 0;

    thresholds = pfnew( PFARR );
    thresholds->value.arr = newarr( strcmp );
    oldval = setarr( sinfo, THRESHOLD, thresholds );
    /* if ( oldval ) freearr( oldval, recurse_free_pf ); */
    
    /* First grab the list of alert levels for this packet type. */
    levels = keysarr( ranges );
    numalerts = maxtbl( levels );
    for ( i =0; i < numalerts; i++ )
    {
        level = poptbl( levels );
        byfield = (Tbl*) getarr( ranges, level );
        
        newfieldlist = create_pf ( newarr( strcmp ), PFARR );
        setarr( thresholds->value.arr, level, newfieldlist );
        priority = get_priority( level, oi );

        /* Next, get the thresholds for this current alert level. */
        size = maxtbl( byfield );
        for ( j = 0; j < size; j++ )
        {
            /* From this, examine each field. */
            field = (Arr*) gettbl( byfield, j );

            thresh = create_pf( newarr( strcmp ), PFARR );

            setarr ( thresh->value.arr, HIGH, 
                     create_pf( strdup( getarr( field, HIGH ) ), PFSTRING) );
            setarr ( thresh->value.arr, LOW, 
                     create_pf( strdup( getarr( field, LOW ) ), PFSTRING) );
            setarr ( thresh->value.arr, PRIORITY, 
                     create_pf( itoa( priority ), PFSTRING));

            name = getarr( field, NAME );
            if ( name == NULL )
                continue;

            oldval = setarr( newfieldlist->value.arr, name, thresh );
            if ( oldval ) free( oldval );
        }
    }

    freetbl( levels, 0 );
    return 1; 
}