static int get_xml_time_t(
    xmlTextReaderPtr reader,
    time_t *value)
{    
    xmlChar *text;
    time_t temp;    
    if ((text = get_xml_text(reader)) != NULL){
        errno = 0;        
#if SIZEOF_TIME_T == 4
        temp = strtol((char *)text,NULL, 0);
#elif SIZEOF_TIME_T == 8
        temp = strtoll((char *)text,NULL, 0);        
#else
#error "Don't know how to deal with TIME_T other than 4 or 8 bytes"
#endif    
        if (errno>0){
            rrd_set_error("ling %d: get_xml_time_t from '%s' %s",
                          xmlTextReaderGetParserLineNumber(reader),
                          text,rrd_strerror(errno));
            xmlFree(text);            
            return -1;
        }
        xmlFree(text);            
        *value = temp;
        return 0;
    }
    return -1;
} /* get_xml_time_t */
Exemple #2
0
static int get_xml_string(
    xmlTextReaderPtr reader,
    char *value,
    int max_len)
{
    xmlChar *str;
    str = get_xml_text(reader);
    if (str != NULL){
        strncpy(value,(char *)str,max_len);
        xmlFree(str);
        return 0;        
    }
    else
        return -1;    
}
/*
 * Parse the <cdp_prep> block within an RRA definition
 */
static int parse_tag_rra_cdp_prep_ds_history(
    xmlTextReaderPtr reader,
    cdp_prep_t *cdp_prep)
{
    /* Make `history_buffer' the same size as the scratch area, plus the
     * terminating NULL byte. */
    xmlChar  *history;    
    char     *history_ptr;
    int       i;
    if ((history = get_xml_text(reader)) != NULL){
        history_ptr = (char *) (&cdp_prep->scratch[0]);
        for (i = 0; history[i] != '\0' && i < MAX_CDP_PAR_EN; i++)
            history_ptr[i] = (history[i] == '1') ? 1 : 0;
        xmlFree(history);        
        return 0;        
    }    
    return -1;    
}  /* int parse_tag_rra_cdp_prep_ds_history */
static int get_xml_string(
    xmlTextReaderPtr reader,
    char *value,
    unsigned int max_len)
{
    xmlChar *str;
    str = get_xml_text(reader);
    if (str != NULL){
        if (strlen((char *)str) >= max_len){
            rrd_set_error("'%s' is longer than %i",str,max_len);
            return -1;
        }            
        strncpy(value,(char *)str,max_len);
        xmlFree(str);
        return 0;        
    }
    else
        return -1;    
}
/*
 * Parse a DS definition
 */
static int parse_tag_ds_cdef(
    xmlTextReaderPtr reader,
    rrd_t *rrd)
{
    xmlChar *cdef;

    cdef = get_xml_text(reader);
    if (cdef != NULL){
        /* We're always working on the last DS that has been added to the structure
         * when we get here */
        parseCDEF_DS((char *)cdef, rrd->ds_def + rrd->stat_head->ds_cnt - 1,
		     rrd, lookup_DS);
        xmlFree(cdef);
        if (rrd_test_error())
            return -1;
        else            
            return 0;        
    }
    return -1;
}                       /* int parse_tag_ds_cdef */
static int parse_tag_ds_type(
    xmlTextReaderPtr reader,
    ds_def_t *ds_def)
{
    char *dst;
    dst = (char *)get_xml_text(reader);
    if (dst != NULL){
        int status;
        status = dst_conv(dst);
        if (status == -1) {
            rrd_set_error("parse_tag_ds_type: Unknown data source type: %s",
                          dst);
            return -1;
        }
        strncpy(ds_def->dst,dst,sizeof(ds_def->dst)-1);
        ds_def->dst[sizeof(ds_def->dst)-1] = '\0';
        xmlFree(dst);
        return 0;        
    }
    return -1;
}                       /* int parse_tag_ds_type */
static int get_xml_ulong(
    xmlTextReaderPtr reader,
    unsigned long *value)
{
    
    xmlChar *text;
    unsigned long temp;    
    if ((text = get_xml_text(reader)) != NULL){
        errno = 0;        
        temp = strtoul((char *)text,NULL, 0);        
        if (errno>0){
            rrd_set_error("ling %d: get_xml_ulong from '%s' %s",
                          xmlTextReaderGetParserLineNumber(reader),
                          text,rrd_strerror(errno));
            xmlFree(text);            
            return -1;
        }
        xmlFree(text);
        *value = temp;        
        return 0;
    }
    return -1;
} /* get_xml_ulong */
static int get_xml_double(
    xmlTextReaderPtr reader,
    double *value)
{
    
    xmlChar *text;
    double temp;    
    if ((text = get_xml_text(reader))!= NULL){
        if (xmlStrcasestr(text,(xmlChar *)"nan")){
            *value = DNAN;
            xmlFree(text);
            return 0;            
        }
        else if (xmlStrcasestr(text,(xmlChar *)"-inf")){
            *value = -DINF;
            xmlFree(text);
            return 0;            
        }
        else if (xmlStrcasestr(text,(xmlChar *)"+inf")
                 || xmlStrcasestr(text,(xmlChar *)"inf")){
            *value = DINF;
            xmlFree(text);
            return 0;            
        }        
        if ( rrd_strtodbl((char *)text,NULL, &temp, NULL) != 2 ){
            rrd_set_error("ling %d: get_xml_double from '%s' %s",
                          xmlTextReaderGetParserLineNumber(reader),
                          text,rrd_strerror(errno));
            xmlFree(text);
            return -1;
        }
        xmlFree(text);        
        *value = temp;
        return 0;
    }
    return -1;
} /* get_xml_double */