/** * Get the number of repeats from the config file. * * The kv parameter should be the node->section parameter as it is being * handled inside of the handle_event function. * * This function checks the node->section to see if a delay_repeats keypair is * set, if not, it tries the root of the config to see if that same keypair is * set. Failing that, it returns 0 (infinite). * * A value of 0 returned from this function means it should keep looping * indefinetely. */ static int get_delay_repeats(struct keyval_node* kv) { struct keyval_node* val; if ((val = keyval_node_find(kv, "delay_repeats"))) return keyval_node_get_value_int(val); if ((val = keyval_node_find(config, "delay_repeats"))) return keyval_node_get_value_int(val); return 0; }
/** * Get the delay time (in seconds) from the config file. * * The kv parameter should be the node->section parameter as it is being * handled inside of the handle_event function. * * This function checks the node->section to see if a delay_time keypair is * set, if not, it tries the root of the config to see if that same keypair is * set. Failing that, it returns 300 (300 seconds, aka 5 minutes). */ static int get_delay_time(struct keyval_node* kv) { struct keyval_node* val; if ((val = keyval_node_find(kv, "delay_time"))) return keyval_node_get_value_int(val); if ((val = keyval_node_find(config, "delay_time"))) return keyval_node_get_value_int(val); /* 5 minute default */ return 300; }
/* set nest to the desired indentation level in the output. You probably want 0, this is mainly used internally when recursing */ void keyval_node_debug (struct keyval_node * node, int nest) { char prefix [23]; if (nest > 20) { fprintf (stderr, "Requested ridicously high nesting level %i", nest); exit(2); } char * p = prefix; int i; for (i=0; i <= nest; i++) { *p = '-'; p++; } *p = '>'; *(p+1) = '\0'; printf ("%s Node name: %s", prefix, keyval_node_get_name(node)); printf (", comment: %s", prefix, keyval_node_get_comment(node)); printf (", value: ", prefix); switch (keyval_node_get_value_type(node)) { case KEYVAL_TYPE_NONE: printf ("None"); break; case KEYVAL_TYPE_BOOL: printf ("Bool: %s", keyval_node_get_value_bool(node)); break; case KEYVAL_TYPE_STRING: printf ("String: %s", keyval_node_get_value_string(node)); break; case KEYVAL_TYPE_INT: printf ("Int: %i", keyval_node_get_value_int(node)); break; case KEYVAL_TYPE_DOUBLE: printf ("Double: %d", keyval_node_get_value_double(node)); break; case KEYVAL_TYPE_LIST: printf ("List"); break; } printf ("\n"); struct keyval_node * child = keyval_node_get_children(node); while (child) { keyval_node_debug (child, nest +1); child = child->next; } }