Example #1
0
/** Parse /collector/address */
int conf_collector_address (const char *id, var *v, updatetype tp) {
    if (tp == UPDATE_REMOVE) exit (0);
    APP.collectoraddr = strdup (var_get_str (v));
    return 1;
}
Example #2
0
/** Extract the time out of a variable. There are two options here.
  * If the type is VAR_INT, the value is treated as a unix timestamp
  * and just typecast. If the type is VAR_STR, the value is parsed
  * as a UTC iso timestring.
  * \param self The var with the alleged time value
  * \return Timestamp, 0 if none could be extracted.
  */
time_t var_get_time (var *self) {
    if (self->type == VAR_INT) return (time_t) var_get_int (self);
    if (self->type == VAR_STR) return utcstr2time (var_get_str (self));
    return 0;
}
Example #3
0
/** Deep copy another var into one. The new structure will share no memory
  * with the original.
  * \param self The destination var
  * \param orig The original var
  */
void var_copy (var *self, var *orig) {
    if (self->type == VAR_STR) {
        free (self->value.sval);
        self->value.sval = NULL;
    }
    
    if (self->type == VAR_ARRAY || self->type == VAR_DICT) {
        var *c = self->value.arr.first;
        var *nc;
        
        while (c) {
            nc = c->next;
            var_free (c);
            c = nc;
        }
        self->value.arr.first = self->value.arr.last = NULL;
        self->value.arr.cachepos = -1;
        self->value.arr.cachenode = NULL;
        self->value.arr.count = 0;
    }

    self->type = VAR_NULL;
    var *crsr;
    
    switch (orig->type) {
        case VAR_NULL:
            break;
        
        case VAR_INT:
            var_set_int (self, var_get_int (orig));
            break;
        
        case VAR_DOUBLE:
            var_set_double (self, var_get_double (orig));
            break;
        
        case VAR_STR:
            var_set_str (self, var_get_str (orig));
            break;
        
        case VAR_ARRAY:
            self->type = VAR_ARRAY;
            self->value.arr.first = self->value.arr.last = NULL;
            self->value.arr.cachepos = -1;
            self->value.arr.cachenode = NULL;
            self->value.arr.count = 0;
            crsr = orig->value.arr.first;
            while (crsr) {
                var *nvar = var_alloc();
                nvar->id[0] = 0;
                nvar->hashcode = 0;
                var_copy (nvar, crsr);
                var_link (nvar, self);
                crsr = crsr->next;
            }
            break;
        
        case VAR_DICT:
            self->type = VAR_DICT;
            self->value.arr.first = self->value.arr.last = NULL;
            self->value.arr.cachepos = -1;
            self->value.arr.cachenode = NULL;
            self->value.arr.count = 0;
            crsr = orig->value.arr.first;
            while (crsr) {
                var *nvar = var_alloc();
                strcpy (nvar->id, crsr->id);
                nvar->hashcode = crsr->hashcode;
                var_copy (nvar, crsr);
                var_link (nvar, self);
                crsr = crsr->next;
            }
            break;
    }
}
Example #4
0
/** Parse the string value of a var object as a uuid */
uuid var_get_uuid (var *self) {
    return mkuuid (var_get_str (self));
}