Ejemplo n.º 1
0
static int geo_parse_range(geo_t *g, char *range, char *value) {
    uint32_t ip_addr;
    struct in_addr in;
    uint32_t start, end;

    if (strcmp(range, "default") == 0) {
        if (inet_aton(value, &in) == 0) {
            return -1;
        }
        ip_addr = ntohl(in.s_addr);
        range_set_def(g->u.range, ip_addr);
    } else if (strcmp(range, "delete") == 0) {
        if (parse_range(value, &start, &end) != 0) {
            return -1;
        }
        range_delete(g->u.range, start, end);
        return 0;
    } else {
        if (inet_aton(value, &in) == 0) {
            return -1;
        }
        ip_addr = ntohl(in.s_addr);

        if (parse_range(range, &start, &end) != 0) {
            return -1;
        }

        return range_insert(g->u.range, start, end, ip_addr);
    }
    return 0;
}
/**
 * Write the enqueued ranges to disk, free them
 * @param df the dest file object
 * @return 1 if it worked, else 0
 */
static int dest_file_dequeue( dest_file *df )
{
    int i,res = 1;
    int len = 0;
    range **array = ranges_to_array( df->queue, &len );
    if ( array != NULL )
    {
        range *r = df->queue;
        dest_file_set_first( df, 1 );
        for ( i=0;i<len;i++ )
        {
            r = array[i];
            res = df->f->rfunc( 
                range_get_name(r),
                range_get_atts(r),
                range_removed(r),
                dest_file_reloff(df,range_get_start(r)),
                range_get_len(r),
                range_get_content(r),
                range_get_content_len(r),
                dest_file_first(df), 
                dest_file_dst(df) );
            dest_file_set_first( df, 0 );
            range_delete( r );
            if ( !res )
            {
                fprintf(stderr, "stripper: failed to write range" );
                res = 0;
                break;
            }
            if ( !res )
                break;
        }
        free( array );
    }
    if ( res )
        df->queue = NULL;
    return res;
}
/**
 * Dispose of a destination file
 * @param df the dest file to dispose
 * @return NULL
 */
dest_file *dest_file_dispose( dest_file *df )
{
    if ( df->name != NULL )
        free( df->name );
    if ( df->next != NULL )
        dest_file_dispose( df->next );
    if ( df->queue != NULL )
    {
        range *r = df->queue;
        while ( r != NULL )
        {
            range *next = range_get_next(r);
            range_delete( r );
            r = next;
        }
    }
#ifdef JNI
    if ( df->dst != NULL )
        ramfile_dispose( df->dst );
#endif
    free( df );
    return NULL;
}
Ejemplo n.º 4
0
void
mn_delete(cml_node *mn)
{
    strdelete(mn->name);
    strdelete(mn->banner);
    listclear(mn->rules_using);
    if (mn->visibility_expr != 0)
    	expr_destroy(mn->visibility_expr);
    if (mn->saveability_expr != 0)
    	expr_destroy(mn->saveability_expr);
    /* only remove the list structure, all nodes are deleted seperately */
    listclear(mn->children);
    if (mn->expr != 0)
    	expr_destroy(mn->expr);
    atom_dtor(&mn->value);
    listclear(mn->transactions_guarded);
    listclear(mn->bindings);
    range_delete(mn->range);
    listdelete(mn->enumdefs, cml_enumdef, cml_enumdef_delete);
    listclear(mn->dependants);
    listclear(mn->dependees);
    strdelete(mn->help_text);
    g_free(mn);
}