int main(int argc, char *argv[]) { app_startup(); if (argc > 1) verbose = TRUE; msg_init(TRUE); configuration = cfg_new(0x0302); plugin_load_module("basicfuncs", configuration, NULL); plugin_load_module("syslogformat", configuration, NULL); pattern_db_global_init(); test_patterndb_rule(); test_patterndb_parsers(); test_patterndb_message_property_inheritance(); test_patterndb_context_length(); test_patterndb_tags_outside_of_rule(); app_shutdown(); return (fail ? 1 : 0); }
void test_config(void) { CfgFile* cfg = NULL; const char* file = NULL; const char* cfgname = NULL; file = "test.cfg"; cfgname = "Test1"; g_print("\n\rLoading '%s' configuration...\n\r", cfgname); cfg = cfg_load(file, cfgname); test_config_print_cfg(cfg); cfgname = "Test2"; g_print("Loading '%s' configuration...\n\r", cfgname); cfg = cfg_load(file, cfgname); test_config_print_cfg(cfg); cfgname = "Test3"; g_print("Creating a test configuration...\n\r"); cfg = cfg_new(file, cfgname); cfg_add_item(cfg, "KeyT3_1", "Value1"); cfg_add_item(cfg, "KeyT3_2", "Value2"); cfg_add_item(cfg, "KeyT3_3", "Value3"); g_print("Add the '%s' configuration\n\r", cfgname); cfg_store(cfg); g_print("The configuration size is %u...\n\r", cfg_get_size(cfg)); g_print("Free up configuration resources...\n\r"); cfg_free(cfg); }
int main(int argc, char *argv[]) { app_startup(); msg_init(TRUE); configuration = cfg_new(0x0302); plugin_load_module("basicfuncs", configuration, NULL); plugin_load_module("syslogformat", configuration, NULL); pattern_db_global_init(); test_conflicting_rules_with_different_parsers(); test_conflicting_rules_with_the_same_parsers(); test_patterndb_rule(); test_patterndb_parsers(); test_patterndb_message_property_inheritance(); test_patterndb_context_length(); test_patterndb_tags_outside_of_rule(); app_shutdown(); return 0; }
/* initiate configuration reload */ void main_loop_reload_config_initiate(void) { if (main_loop_is_terminating()) return; service_management_publish_status("Reloading configuration"); if (main_loop_new_config) { /* This block is entered only if this function is reentered before * main_loop_reload_config_apply() would be called. In that case we * drop the previously parsed configuration and start over again to * ensure that the contents of the running configuration matches the * contents of the file at the time the SIGHUP signal was received. */ cfg_free(main_loop_new_config); main_loop_new_config = NULL; } main_loop_old_config = current_configuration; app_pre_config_loaded(); main_loop_new_config = cfg_new(0); if (!cfg_read_config(main_loop_new_config, resolvedConfigurablePaths.cfgfilename, FALSE, NULL)) { cfg_free(main_loop_new_config); main_loop_new_config = NULL; main_loop_old_config = NULL; msg_error("Error parsing configuration", evt_tag_str(EVT_TAG_FILENAME, resolvedConfigurablePaths.cfgfilename)); service_management_publish_status("Error parsing new configuration, using the old config"); return; } main_loop_worker_sync_call(main_loop_reload_config_apply); }
static struct cfg *cfg_parse(const struct cfg_string *str, size_t *current, enum cfg_status *status) { struct cfg *cfg=NULL; //int beg_found=0; struct cfg_field *field=NULL; size_t end=0; if (!str) { *status = CFG_READ_ERROR; goto _cfg_parse_bail; } // beginning { is optional for overall config, but not sub-configs if (CFG_CFG_BEG == str->data[*current]) { (*current) += 1; } cfg = cfg_new(); while (1) { *current = find_nonwhite(str, *current, status); if (*status) { // EOF OK here *status=CFG_SUCCESS; break; } if (str->data[*current] == CFG_CFG_END) { break; } field=cfg_get_field(str, (*current), &end, status); if (CFG_FOUND_END == (*status)) { // just found end of config, break out *status=CFG_SUCCESS; break; } if (*status) { // an error occured break; } if (!field) { // probably natural end of file found break; } cfg_append(cfg,field); if (str->data[end] == CFG_CFG_END) { *current = end; break; } // skip past either the last letter, end quote, end array delim, etc. (*current) = end+1; } _cfg_parse_bail: if (*status) { cfg=cfg_free(cfg); } return cfg; };
int main(int argc, char *argv[]) { GPtrArray *transformers; app_startup(); putenv("TZ=MET-1METDST"); tzset(); configuration = cfg_new(0x0302); plugin_load_module("syslogformat", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); parse_options.flags |= LP_SYSLOG_PROTOCOL; testcase("rfc3164", NULL, "DATE,FACILITY,HOST,MESSAGE,PID,PRIORITY,PROGRAM", NULL); testcase("core", NULL, "DATE,FACILITY,HOST,MESSAGE,PID,PRIORITY,PROGRAM", NULL); testcase("base", NULL, "DATE,FACILITY,HOST,MESSAGE,PID,PRIORITY,PROGRAM", NULL); testcase("rfc5424", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip,DATE,FACILITY,HOST,MESSAGE,MSGID,PID,PRIORITY,PROGRAM", NULL); testcase("syslog-proto", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip,DATE,FACILITY,HOST,MESSAGE,MSGID,PID,PRIORITY,PROGRAM", NULL); testcase("selected-macros", NULL, "DATE,FACILITY,HOST,MESSAGE,PID,PRIORITY,PROGRAM,SEQNUM,SOURCEIP,TAGS", NULL); testcase("nv-pairs", NULL, "HOST,MESSAGE,MSGID,PID,PROGRAM", NULL); testcase("dot-nv-pairs", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip", NULL); testcase("sdata", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip", NULL); testcase("all-nv-pairs", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip,HOST,MESSAGE,MSGID,PID,PROGRAM", NULL); testcase("everything", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip,AMPM,BSDTAG,C_DATE,C_DAY,C_FULLDATE,C_HOUR,C_ISODATE,C_MIN,C_MONTH,C_MONTH_ABBREV,C_MONTH_NAME,C_MONTH_WEEK,C_SEC,C_STAMP,C_TZ,C_TZOFFSET,C_UNIXTIME,C_WEEK,C_WEEKDAY,C_WEEK_DAY,C_WEEK_DAY_ABBREV,C_WEEK_DAY_NAME,C_YEAR,C_YEAR_DAY,DATE,DAY,FACILITY,FACILITY_NUM,FULLDATE,HOST,HOUR,HOUR12,ISODATE,LEVEL,LEVEL_NUM,LOGHOST,MESSAGE,MIN,MONTH,MONTH_ABBREV,MONTH_NAME,MONTH_WEEK,MSEC,MSG,MSGHDR,MSGID,PID,PRI,PRIORITY,PROGRAM,R_AMPM,R_DATE,R_DAY,R_FULLDATE,R_HOUR,R_HOUR12,R_ISODATE,R_MIN,R_MONTH,R_MONTH_ABBREV,R_MONTH_NAME,R_MONTH_WEEK,R_MSEC,R_SEC,R_STAMP,R_TZ,R_TZOFFSET,R_UNIXTIME,R_USEC,R_WEEK,R_WEEKDAY,R_WEEK_DAY,R_WEEK_DAY_ABBREV,R_WEEK_DAY_NAME,R_YEAR,R_YEAR_DAY,SDATA,SEC,SEQNUM,SOURCEIP,STAMP,SYSUPTIME,S_AMPM,S_DATE,S_DAY,S_FULLDATE,S_HOUR,S_HOUR12,S_ISODATE,S_MIN,S_MONTH,S_MONTH_ABBREV,S_MONTH_NAME,S_MONTH_WEEK,S_MSEC,S_SEC,S_STAMP,S_TZ,S_TZOFFSET,S_UNIXTIME,S_USEC,S_WEEK,S_WEEKDAY,S_WEEK_DAY,S_WEEK_DAY_ABBREV,S_WEEK_DAY_NAME,S_YEAR,S_YEAR_DAY,TAG,TAGS,TZ,TZOFFSET,UNIXTIME,USEC,WEEK,WEEKDAY,WEEK_DAY,WEEK_DAY_ABBREV,WEEK_DAY_NAME,YEAR,YEAR_DAY", NULL); testcase("nv-pairs", ".SDATA.*", "HOST,MESSAGE,MSGID,PID,PROGRAM", NULL); /* tests that the exclude patterns do not affect explicitly added * keys. The testcase function adds a "test.key" and then checks if * it is indeed present. Even if it would be excluded it still has * to be in the result set. */ testcase("rfc3164", "test.*", "DATE,FACILITY,HOST,MESSAGE,PID,PRIORITY,PROGRAM", NULL); /* tests that excluding works even when the key would be in the * default set. */ testcase("nv-pairs", "MESSAGE", "HOST,MSGID,PID,PROGRAM", NULL); /* test the value-pair transformators */ transformers = g_ptr_array_new(); g_ptr_array_add(transformers, value_pairs_new_transform_add_prefix("__")); g_ptr_array_add(transformers, value_pairs_new_transform_shift(2)); g_ptr_array_add(transformers, value_pairs_new_transform_replace("C_", "CC_")); testcase("everything", NULL, "[email protected],[email protected],.SDATA.meta.sequenceId,.SDATA.meta.sysUpTime,.SDATA.origin.ip,AMPM,BSDTAG,CC_DATE,CC_DAY,CC_FULLDATE,CC_HOUR,CC_ISODATE,CC_MIN,CC_MONTH,CC_MONTH_ABBREV,CC_MONTH_NAME,CC_MONTH_WEEK,CC_SEC,CC_STAMP,CC_TZ,CC_TZOFFSET,CC_UNIXTIME,CC_WEEK,CC_WEEKDAY,CC_WEEK_DAY,CC_WEEK_DAY_ABBREV,CC_WEEK_DAY_NAME,CC_YEAR,CC_YEAR_DAY,DATE,DAY,FACILITY,FACILITY_NUM,FULLDATE,HOST,HOUR,HOUR12,ISODATE,LEVEL,LEVEL_NUM,LOGHOST,MESSAGE,MIN,MONTH,MONTH_ABBREV,MONTH_NAME,MONTH_WEEK,MSEC,MSG,MSGHDR,MSGID,PID,PRI,PRIORITY,PROGRAM,R_AMPM,R_DATE,R_DAY,R_FULLDATE,R_HOUR,R_HOUR12,R_ISODATE,R_MIN,R_MONTH,R_MONTH_ABBREV,R_MONTH_NAME,R_MONTH_WEEK,R_MSEC,R_SEC,R_STAMP,R_TZ,R_TZOFFSET,R_UNIXTIME,R_USEC,R_WEEK,R_WEEKDAY,R_WEEK_DAY,R_WEEK_DAY_ABBREV,R_WEEK_DAY_NAME,R_YEAR,R_YEAR_DAY,SDATA,SEC,SEQNUM,SOURCEIP,STAMP,SYSUPTIME,S_AMPM,S_DATE,S_DAY,S_FULLDATE,S_HOUR,S_HOUR12,S_ISODATE,S_MIN,S_MONTH,S_MONTH_ABBREV,S_MONTH_NAME,S_MONTH_WEEK,S_MSEC,S_SEC,S_STAMP,S_TZ,S_TZOFFSET,S_UNIXTIME,S_USEC,S_WEEK,S_WEEKDAY,S_WEEK_DAY,S_WEEK_DAY_ABBREV,S_WEEK_DAY_NAME,S_YEAR,S_YEAR_DAY,TAG,TAGS,TZ,TZOFFSET,UNIXTIME,USEC,WEEK,WEEKDAY,WEEK_DAY,WEEK_DAY_ABBREV,WEEK_DAY_NAME,YEAR,YEAR_DAY", transformers); g_ptr_array_free(transformers, TRUE); app_shutdown(); if (success) return 0; return 1; }
void init_and_load_syslogformat_module() { configuration = cfg_new(0x0302); plugin_load_module("syslogformat", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); }
Config cfg_new_from_stream(FILE* f) { Config cfg = cfg_new(); if(cfg_read(cfg, f) != CFG_OKAY) { cfg_destroy(cfg); cfg = NULL; } return cfg; }
Config cfg_new_from_file(const char* filename) { Config cfg = cfg_new(); if(cfg_read_file(cfg, filename) != CFG_OKAY) { cfg_destroy(cfg); cfg = NULL; } return cfg; }
Cell* ReadCells(MPI_Comm comm, const char* cellfile, int &Ncells) { int nprocs, myid, root; Cell* cells; MPI_Comm_size(comm, &nprocs); MPI_Comm_rank(comm, &myid); root = 0; /* Have root process read in cells */ if(myid == root) { size_t n, size; char endian; char fmt[ABN_MAX_FORMAT_LENGTH]; Config cellopts = cfg_new(); /* Read basis cells from file */ FILE* fcells = fopen(cellfile, "r"); if(fcells == NULL) { fprintf(stderr, "ReadCells: could not read cells from '%s'\n", cellfile); MPI_Abort(comm, 1); } if(abn_read(fcells, (void**) &cells, &n, &size, &endian, fmt, cellopts) != 0) { report_memory_usage(); fprintf(stderr, "ReadCells: error reading cells from '%s'\n", cellfile); MPI_Abort(comm, 1); } fclose(fcells); Ncells = cfg_get_int(cellopts, "Ncells"); if((int)n != Ncells) fprintf(stderr, "Warning: consistency check fail for Ncells: %d != %d\n", Ncells, (int)n); if(size != sizeof(Cell)) fprintf(stderr, "Warning: consistency check fail for sizeof(Cell): %d != %d\n", (int)sizeof(Cell), (int)size); /* Debugging... */ printf("Read %d basis cells from '%s'\n", Ncells, cellfile); } MPI_Bcast(&Ncells, 1, MPI_INT, root, comm); /* Define MPI datatype for cells (this must be updated if struct Cell changes!) */ MPI_Datatype cell_datatype; int blocklengths[2] = { 2, 8 }; MPI_Aint displacements[2] = { 0, 8 }; MPI_Datatype types[2] = { MPI_INT, MPI_DOUBLE }; MPI_Type_create_struct(2, blocklengths, displacements, types, &cell_datatype); MPI_Type_commit(&cell_datatype); /* Broadcast cell data to all other processes */ if(myid != root) { cells = (Cell*) malloc(Ncells*sizeof(Cell)); if(cells == NULL) { fprintf(stderr, "ReadCells: could not allocate memory for cells on process %d\n", myid); MPI_Abort(comm, 1); } } MPI_Bcast(cells, Ncells, cell_datatype, root, comm); return cells; }
static GlobalConfig * create_cfg() { GlobalConfig *cfg; cfg = cfg_new(0x0302); return cfg; }
void init_and_load_kmsgformat_module() { configuration = cfg_new(VERSION_VALUE); plugin_load_module("linux-kmsg-format", configuration, NULL); parse_options.format = "linux-kmsg"; msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); }
void expect_config_parse_failure(const char *raw_rewrite_rule) { char raw_config[1024]; configuration = cfg_new(VERSION_VALUE); snprintf(raw_config, sizeof(raw_config), "rewrite s_test{ %s };", raw_rewrite_rule); assert_false(parse_config(raw_config, LL_CONTEXT_ROOT, NULL, NULL), ASSERTION_ERROR("Parsing the given configuration failed")); cfg_free(configuration); };
Config cfg_new_copy(Config orig) { ConfigEntry entry; Config cfg = cfg_new(); cfg->strip_quotes = orig->strip_quotes; entry = orig->first; while(entry != NULL) { cfg_insert_entry(cfg, strdup(entry->key), strdup(entry->value)); entry = entry->next; } return cfg; }
int main() { app_startup(); configuration = cfg_new(0x0303); plugin_load_module("syslogformat", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); test_value_pairs_walk_prefix_data(configuration); app_shutdown(); };
int main(int argc, char *argv[]) { app_startup(); configuration = cfg_new(VERSION_VALUE); test_resolve_hostname_to_hostname(); test_resolve_hostname_to_sockaddr(); test_resolve_sockaddr_to_hostname(); cfg_free(configuration); return 0; }
int main() { app_startup(); setlocale (LC_ALL, "C"); putenv("TZ=CET-1"); tzset(); configuration = cfg_new(0x0302); /* Various ISO8601 formats */ testcase("2015-01-26T16:14:49+0300", NULL, NULL, "2015-01-26T16:14:49+03:00"); testcase("2015-01-26T16:14:49+0330", NULL, NULL, "2015-01-26T16:14:49+03:30"); testcase("2015-01-26T16:14:49+0200", NULL, NULL, "2015-01-26T16:14:49+02:00"); testcase("2015-01-26T16:14:49+03:00", NULL, NULL, "2015-01-26T16:14:49+03:00"); testcase("2015-01-26T16:14:49+03:30", NULL, NULL, "2015-01-26T16:14:49+03:30"); testcase("2015-01-26T16:14:49+02:00", NULL, NULL, "2015-01-26T16:14:49+02:00"); testcase("2015-01-26T16:14:49Z", NULL, NULL, "2015-01-26T16:14:49+00:00"); testcase("2015-01-26T16:14:49A", NULL, NULL, "2015-01-26T16:14:49-01:00"); testcase("2015-01-26T16:14:49B", NULL, NULL, "2015-01-26T16:14:49-02:00"); testcase("2015-01-26T16:14:49N", NULL, NULL, "2015-01-26T16:14:49+01:00"); testcase("2015-01-26T16:14:49O", NULL, NULL, "2015-01-26T16:14:49+02:00"); testcase("2015-01-26T16:14:49GMT", NULL, NULL, "2015-01-26T16:14:49+00:00"); testcase("2015-01-26T16:14:49PDT", NULL, NULL, "2015-01-26T16:14:49-07:00"); /* RFC 2822 */ testcase("Tue, 27 Jan 2015 11:48:46 +0200", NULL, "%a, %d %b %Y %T %z", "2015-01-27T11:48:46+02:00"); /* Apache-like */ testcase("21/Jan/2015:14:40:07 +0500", NULL, "%d/%b/%Y:%T %z", "2015-01-21T14:40:07+05:00"); /* Try with additional text at the end, should fail */ testcase("2015-01-26T16:14:49+0300 Disappointing log file", NULL, NULL, NULL); /* Dates without timezones. America/Phoenix has no DST */ testcase("Tue, 27 Jan 2015 11:48:46", NULL, "%a, %d %b %Y %T", "2015-01-27T11:48:46+01:00"); testcase("Tue, 27 Jan 2015 11:48:46", "America/Phoenix", "%a, %d %b %Y %T", "2015-01-27T11:48:46-07:00"); testcase("Tue, 27 Jan 2015 11:48:46", "+05:00", "%a, %d %b %Y %T", "2015-01-27T11:48:46+05:00"); /* Try without the year. */ testcase("01/Jan:00:40:07 +0500", NULL, "%d/%b:%T %z", "2016-01-01T00:40:07+05:00"); testcase("01/Aug:00:40:07 +0500", NULL, "%d/%b:%T %z", "2015-08-01T00:40:07+05:00"); testcase("01/Sep:00:40:07 +0500", NULL, "%d/%b:%T %z", "2015-09-01T00:40:07+05:00"); testcase("01/Oct:00:40:07 +0500", NULL, "%d/%b:%T %z", "2015-10-01T00:40:07+05:00"); testcase("01/Nov:00:40:07 +0500", NULL, "%d/%b:%T %z", "2015-11-01T00:40:07+05:00"); testcase("1446128356 +01:00", NULL, "%s %z", "2015-10-29T15:19:16+01:00"); testcase("1446128356", "Europe/Budapest", "%s", "2015-10-29T15:19:16+01:00"); app_shutdown(); return 0; };
LogRewrite * create_rewrite_rule(const char *raw_rewrite_rule) { char raw_config[1024]; configuration = cfg_new(VERSION_VALUE); snprintf(raw_config, sizeof(raw_config), "rewrite s_test{ %s }; log{ rewrite(s_test); };", raw_rewrite_rule); assert_true(parse_config(raw_config, LL_CONTEXT_ROOT, NULL, NULL), ASSERTION_ERROR("Parsing the given configuration failed")); assert_true(cfg_init(configuration), ASSERTION_ERROR("Config initialization failed")); LogExprNode *expr_node = cfg_tree_get_object(&configuration->tree, ENC_REWRITE, "s_test"); return (LogRewrite *)expr_node->children->object; }
Config cfg_new_sub(Config cfg, const char* prefix) { int prefixlen = strlen(prefix); ConfigEntry entry; Config subcfg = cfg_new(); subcfg->strip_quotes = cfg->strip_quotes; entry = cfg->first; while(entry != NULL) { if(strncmp(entry->key, prefix, prefixlen) == 0) { cfg_insert_entry(subcfg, strdup(entry->key + prefixlen), strdup(entry->value)); } entry = entry->next; } return subcfg; }
/*! \brief Firmware specific function that backs up the ECU to a filename passed \param filename is the filename to backup the ECU to */ G_MODULE_EXPORT void backup_all_ecu_settings(gchar *filename) { ConfigFile *cfgfile; gchar * section = NULL; gchar * tmpbuf = NULL; gint i = 0; gint locID = 0; gint x = 0; gint canID = 0; DataSize size = MTX_U08; /* <<<<< BAD BAD BAD >>>>> */ GString *string = NULL; extern gconstpointer *global_data; Firmware_Details *firmware = NULL; firmware = DATA_GET(global_data,"firmware"); g_return_if_fail(filename); g_return_if_fail(firmware); cfgfile = cfg_open_file(filename); if(!cfgfile) cfgfile = cfg_new(); set_file_api_f(cfgfile,BACKUP_MAJOR_API,BACKUP_MINOR_API); update_logbar_f("tools_view",NULL,g_strdup_printf("%s %s\n",_("Full Backup Commencing to file:\n\t"),filename),FALSE,FALSE,TRUE); cfg_write_string(cfgfile,"Firmware","name",firmware->name); for(i=0;i<firmware->total_pages;i++) { if (firmware->page_params[i]->read_only) continue; string = g_string_sized_new(64); section = g_strdup_printf("page_%i",i); cfg_write_int(cfgfile,section,"num_variables",firmware->page_params[i]->length); for(x=0;x<firmware->page_params[i]->length;x++) { locID = firmware->page_params[i]->phys_ecu_page; g_string_append_printf(string,"%i",freeems_get_ecu_data(canID,locID,x,size)); if (x < (firmware->page_params[i]->length-1)) string = g_string_append(string,","); } cfg_write_string(cfgfile,section,"data",string->str); g_free(section); g_string_free(string,TRUE); } update_logbar_f("tools_view",NULL,_("Full Backup Complete...\n"),FALSE,FALSE,FALSE); cfg_write_file(cfgfile,filename); cfg_free(cfgfile); }
int main() { app_startup(); configuration = cfg_new(0x0201); plugin_load_module("syslogformat", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); frequent_words_tests(); find_clusters_slct_tests(); log_tags_global_deinit(); return (fail ? 1 : 0); }
int main() { app_startup(); setlocale (LC_ALL, "C"); putenv("TZ=CET-1"); tzset(); configuration = cfg_new(0x0302); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); /* Various ISO8601 formats */ testcase("2015-01-26T16:14:49+03:00", 0, NULL, NULL, "2015-01-26T16:14:49+03:00"); // testcase("2015-01-26T16:14:49+03:30", 0, NULL, NULL, "2015-01-26T16:14:49+03:30"); testcase("2015-01-26T16:14:49+0200", 0, NULL, NULL, "2015-01-26T16:14:49+02:00"); // testcase("2015-01-26T16:14:49Z", 0, NULL, NULL, "2015-01-26T16:14:49+00:00"); /* RFC 2822 */ testcase("Tue, 27 Jan 2015 11:48:46 +0200", 0, NULL, "%a, %d %b %Y %T %z", "2015-01-27T11:48:46+02:00"); /* Apache-like */ testcase("21/Jan/2015:14:40:07 +0500", 0, NULL, "%d/%b/%Y:%T %z", "2015-01-21T14:40:07+05:00"); /* Try with additional text at the end */ testcase("2015-01-26T16:14:49+03:00 Disappointing log file", 0, NULL, NULL, "2015-01-26T16:14:49+03:00"); /* Try with offset */ testcase("<34> 2015-01-26T16:14:49+03:00 Disappointing log file", 5, NULL, NULL, "2015-01-26T16:14:49+03:00"); /* Dates without timezones. America/Phoenix has no DST */ testcase("Tue, 27 Jan 2015 11:48:46", 0, NULL, "%a, %d %b %Y %T", "2015-01-27T11:48:46+00:00"); testcase("Tue, 27 Jan 2015 11:48:46", 0, "America/Phoenix", "%a, %d %b %Y %T", "2015-01-27T11:48:46-07:00"); testcase("Tue, 27 Jan 2015 11:48:46", 0, "+05:00", "%a, %d %b %Y %T", "2015-01-27T11:48:46+05:00"); /* Try without the year. */ testcase("01/Jul:00:40:07 +0500", 0, NULL, "%d/%b:%T %z", "2015-07-01T00:40:07+05:00"); testcase("01/Aug:00:40:07 +0500", 0, NULL, "%d/%b:%T %z", "2015-08-01T00:40:07+05:00"); testcase("01/Sep:00:40:07 +0500", 0, NULL, "%d/%b:%T %z", "2015-09-01T00:40:07+05:00"); testcase("01/Oct:00:40:07 +0500", 0, NULL, "%d/%b:%T %z", "2014-10-01T00:40:07+05:00"); testcase("01/Nov:00:40:07 +0500", 0, NULL, "%d/%b:%T %z", "2014-11-01T00:40:07+05:00"); app_shutdown(); return 0; };
int main(int argc, char **argv) { app_startup(); main_thread_handle = get_thread_id(); configuration = cfg_new(0x306); configuration->threaded = FALSE; configuration->state = persist_state_new("test_systemd_journal.persist"); configuration->keep_hostname = TRUE; persist_state_start(configuration->state); JOURNALD_TESTCASE(test_journald_mock); JOURNALD_TESTCASE(test_journald_helper); JOURNALD_TESTCASE(test_journal_reader); persist_state_cancel(configuration->state); unlink("test_systemd_journal.persist"); app_shutdown(); return 0; }
static void testcase(gchar *msg, goffset offset, gchar *timezone, gchar *format, gchar *expected) { LogTemplate *templ; LogMessage *logmsg; NVTable *nvtable; GlobalConfig *cfg = cfg_new (0x302); LogParser *parser = date_parser_new (cfg); gboolean success; const gchar *context_id = "test-context-id"; GString *res = g_string_sized_new(128); date_parser_set_offset(parser, offset); if (format != NULL) date_parser_set_format(parser, format); if (timezone != NULL) date_parser_set_timezone(parser, timezone); parse_options.flags = 0; logmsg = log_msg_new_empty(); logmsg->timestamps[LM_TS_RECVD].tv_sec = 1438793384; /* Wed Aug 5 2015 */ log_msg_set_value(logmsg, log_msg_get_value_handle("MESSAGE"), msg, -1); nvtable = nv_table_ref(logmsg->payload); success = log_parser_process(parser, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1); nv_table_unref(nvtable); if (!success) { fprintf(stderr, "unable to parse offset=%d format=%s msg=%s\n", offset, format, msg); exit(1); } /* Convert to ISODATE */ templ = compile_template("${ISODATE}", FALSE); log_template_format(templ, logmsg, NULL, LTZ_LOCAL, 999, context_id, res); assert_nstring(res->str, res->len, expected, strlen(expected), "incorrect date parsed msg=%s offset=%d format=%s", msg, offset, format); log_template_unref(templ); g_string_free(res, TRUE); log_pipe_unref(&parser->super); log_msg_unref(logmsg); return; }
static void _setup(void) { msg_init(FALSE); g_thread_init(NULL); syntax_only = FALSE; debug_flag = TRUE; verbose_flag = TRUE; trace_flag = TRUE; log_msg_registry_init(); test_cfg = cfg_new(0x0308); g_assert(test_cfg); const gchar *persist_filename = ""; test_cfg->state = persist_state_new(persist_filename); _before_test(); }
/* * Returns: exit code to be returned to the calling process, 0 on success. */ int main_loop_read_and_init_config(void) { current_configuration = cfg_new(0); if (!cfg_read_config(current_configuration, resolvedConfigurablePaths.cfgfilename, syntax_only, preprocess_into)) { return 1; } if (syntax_only || preprocess_into) { return 0; } if (!main_loop_initialize_state(current_configuration, resolvedConfigurablePaths.persist_file)) { return 2; } return 0; }
gint main(gint argc, gchar **argv) { app_startup(); putenv("TZ=MET-1METDST"); tzset(); configuration = cfg_new(0x0308); plugin_load_module("syslogformat", configuration, NULL); plugin_load_module("disk-buffer", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); set_mark_message_serialized_size(); test_over_EOF(); test_rewind_backlog(); cfg_free(configuration); app_shutdown(); return 0; }
int main() { app_startup(); putenv("TZ=MET-1METDST"); tzset(); configuration = cfg_new(0x0302); plugin_load_module("syslogformat", configuration, NULL); msg_format_options_defaults(&parse_options); msg_format_options_init(&parse_options, configuration); fprintf(stderr,"Start testcase_with_threads\n"); testcase_with_threads(); #if 1 fprintf(stderr,"Start testcase_zero_diskbuf_alternating_send_acks\n"); testcase_zero_diskbuf_alternating_send_acks(); fprintf(stderr,"Start testcase_zero_diskbuf_and_normal_acks\n"); testcase_zero_diskbuf_and_normal_acks(); #endif return 0; }
double* ReadSpectrum(const char* specfile, int* n_, int* nev_) { int n, nev; double* modes = NULL; Config opts = cfg_new(); FILE* fspec = fopen(specfile, "r"); if(fspec == NULL) { fprintf(stderr, "ReadSpectrum: could not open file '%s'\n", specfile); return NULL; } int err = abn_read(fspec, (void**) &modes, NULL, NULL, NULL, NULL, opts); fclose(fspec); if(!err && !cfg_has_keys(opts, "n,nev", ",")) { fprintf(stderr, "ReadSpectrum: missing options\n"); err = 1; } else { n = cfg_get_int(opts, "n"); nev = cfg_get_int(opts, "nev"); } cfg_destroy(opts); if(err) { fprintf(stderr, "ReadSpectrum: error reading from '%s'\n", specfile); perror("system error"); free(modes); return NULL; } else { if(n_) *n_ = n; if(nev_) *nev_ = nev; return modes; } }
void save_config(GtkWidget *widget) { gchar *filename; ConfigFile *cfgfile; gint x; gint y; filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL); cfgfile = cfg_open_file(filename); if (!cfgfile) cfgfile = cfg_new(); cfg_write_int(cfgfile, "Global", "major_ver", _MAJOR_); cfg_write_int(cfgfile, "Global", "minor_ver", _MINOR_); cfg_write_int(cfgfile, "Global", "micro_ver", _MICRO_); if (Color_map.filename) cfg_write_string(cfgfile, "Global", "last_colormap", Color_map.filename); else cfg_write_string(cfgfile, "Global", "last_colormap",g_strconcat(g_get_home_dir(),"/.eXtace/ColorMaps/","Default",NULL)); cfg_write_int(cfgfile, "Global", "mode", mode); cfg_write_int(cfgfile, "Global", "data_source", data_source); cfg_write_int(cfgfile, "Global", "decimation_factor", decimation_factor); cfg_write_int(cfgfile, "Global", "fft_signal_source", fft_signal_source); cfg_write_float(cfgfile, "Global", "scope_zoom", scope_zoom); cfg_write_int(cfgfile, "Global", "refresh_rate", refresh_rate); cfg_write_int(cfgfile, "Global", "landflip", landflip); cfg_write_int(cfgfile, "Global", "spikeflip", spikeflip); cfg_write_boolean(cfgfile, "Global", "outlined", outlined); cfg_write_int(cfgfile, "Global", "sub_mode_3D", sub_mode_3D); cfg_write_int(cfgfile, "Global", "scope_sub_mode", scope_sub_mode); cfg_write_boolean(cfgfile, "Global", "dir_win_present", dir_win_present); cfg_write_int(cfgfile, "Global", "nsamp", nsamp); cfg_write_int(cfgfile, "Global", "window_func", window_func); cfg_write_int(cfgfile, "Global", "win_width", win_width); cfg_write_int(cfgfile, "Global", "axis_type", axis_type); cfg_write_int(cfgfile, "Global", "bands", bands); cfg_write_int(cfgfile, "Global", "lag", lag); cfg_write_float(cfgfile, "Global", "noise_floor", noise_floor); cfg_write_int(cfgfile, "Global", "seg_height", seg_height); cfg_write_int(cfgfile, "Global", "seg_space", seg_space); cfg_write_boolean(cfgfile, "Global", "bar_decay", bar_decay); cfg_write_boolean(cfgfile, "Global", "peak_decay", peak_decay); cfg_write_boolean(cfgfile, "Global", "stabilized", stabilized); cfg_write_boolean(cfgfile, "Global", "show_graticule", show_graticule); cfg_write_int(cfgfile, "Global", "decay_speed", bar_decay_speed); cfg_write_int(cfgfile, "Global", "peak_decay_speed", peak_decay_speed); cfg_write_int(cfgfile, "Global", "peak_hold_time", peak_hold_time); cfg_write_int(cfgfile, "Global", "tape_scroll", tape_scroll); cfg_write_int(cfgfile, "Global", "xdet_scroll", xdet_scroll); cfg_write_int(cfgfile, "Global", "zdet_scroll", zdet_scroll); cfg_write_float(cfgfile, "Global", "xdet_start", xdet_start); cfg_write_float(cfgfile, "Global", "xdet_end", xdet_end); cfg_write_float(cfgfile, "Global", "ydet_start", ydet_start); cfg_write_float(cfgfile, "Global", "ydet_end", ydet_end); cfg_write_float(cfgfile, "Global", "x3d_start", x3d_start); cfg_write_float(cfgfile, "Global", "x3d_end", x3d_end); cfg_write_float(cfgfile, "Global", "y3d_start", y3d_start); cfg_write_float(cfgfile, "Global", "y3d_end", y3d_end); cfg_write_float(cfgfile, "Global", "multiplier", multiplier); cfg_write_int(cfgfile, "Global", "horiz_spec_start", horiz_spec_start); cfg_write_int(cfgfile, "Global", "vert_spec_start", vert_spec_start); cfg_write_int(cfgfile, "Global", "x3d_scroll", x3d_scroll); cfg_write_int(cfgfile, "Global", "z3d_scroll", z3d_scroll); cfg_write_boolean(cfgfile, "Global", "show_leader", show_leader); cfg_write_int(cfgfile, "Global", "scope_sync_source", scope_sync_source); cfg_write_boolean(cfgfile, "Global", "landtilt",landtilt); cfg_write_boolean(cfgfile, "Global", "spiketilt", spiketilt); cfg_write_float(cfgfile, "Global", "low_freq", low_freq); cfg_write_float(cfgfile, "Global", "high_freq", high_freq); cfg_write_int(cfgfile, "Window", "width", width); cfg_write_int(cfgfile, "Window", "height", height+22); gdk_window_get_root_origin(widget->window, &x, &y); cfg_write_int(cfgfile, "Window", "main_x_origin", x); cfg_write_int(cfgfile, "Window", "main_y_origin", y); // cfg_write_boolean(cfgfile, "Window", "grad_win_present", grad_win_present); if (grad_win_present) { gdk_window_get_root_origin((gpointer) grad_win_ptr->window, &x, &y); cfg_write_int(cfgfile, "Window", "grad_x_origin", x); cfg_write_int(cfgfile, "Window", "grad_y_origin", y); } if (dir_win_present) { gdk_window_get_root_origin((gpointer) dir_win_ptr->window, &x, &y); cfg_write_int(cfgfile, "Window", "dir_x_origin", x); cfg_write_int(cfgfile, "Window", "dir_y_origin", y); } cfg_write_file(cfgfile, filename); cfg_free(cfgfile); g_free(filename); }