/* sample-event.c - A sample UBS event. */ #include "ubs.h" int main(int argc, char *argv[]) { /* Table for variables specific to this event context. */ ubs_table sample; /* Initialize tables. */ ubs_table_init(&GLOBAL); ubs_table_init(&sample); /* Initialize program. */ ubs_init(argv[0]); /* Read ubs.conf for global context. */ if(read_config(DEF_CONFIG, "global", &GLOBAL)) { /* If the configuration file can't be read for whatever reason, print out an error and bail. */ console_error("Could not read global context in configuration file", FAIL); } /* Read ubs.conf for the "sample" context. In this case, users can define extra variables that will only be read by this program, in the form of sample.variable = value. These variables will be safely ignored by the rest of the UBS. */ if(read_config(DEF_CONFIG, "sample", &sample)) { console_error("Could not read sample context in configuration file", FAIL); } /* This module will only have one recognized context, which will be sample.text, and will contain a message that will be printed out to the UBS debug log. If this is not defined, then print out an error warning, but otherwise continue program execution. */ if(ubs_table_exists(&sample, "text")) { log_error_msg(LOG_DEBUG, "Message from sample event: '%s'", ubs_table_data(&sample, "text")); } else { ubs_error_msg(LOG_ERROR, "'text' variable undefined""); } return OK; }In this example program, a specific configuration variable is read from the ubs.conf file, and printed out to the UBS system logs. In order for a module to define its own context, all it needs to do is call read_config, with the second parameter being the name of the context to parse (which is "sample", in this case). This data is stored in a ubs_table structure, which must be initialized before the call to read_config.