int main(int argc, char** argv) { settings* setting; g_set_prgname(argv[0]); setting = parse_cmdline(argc, argv); if (find_missing(&setting)) { fprintf(stderr, "missing required information\n"); fprintf(stdout, "%s", usage[0]); settings_free(&setting); return 1; } run_tests(setting); settings_free(&setting); return 0; }
int settings_read(struct settings *settings) { int retval; struct settings tmp_settings; memset(&tmp_settings, 0, sizeof(struct settings)); if ((retval = read_filter_duration(&tmp_settings)) != 0) goto err; if ((retval = read_filter_name(&tmp_settings)) != 0) goto err; if ((retval = read_monitor_name(&tmp_settings)) != 0) goto err; if ((retval = read_clone_name(&tmp_settings)) != 0) goto err; if ((retval = read_clone_id(&tmp_settings.clone_id)) != 0) goto err; if ((retval = read_monitor_keys(tmp_settings.monitor_key_valuev)) != 0) goto err; if ((retval = read_monitor_rels(tmp_settings.monitor_rel_valuev)) != 0) goto err; if ((retval = read_filter_keys(tmp_settings.filter_key_valuev)) != 0) goto err; if ((retval = read_filter_rels(tmp_settings.filter_rel_valuev)) != 0) goto err; /* Safe to copy fresh settings because no error was detected.*/ memcpy(settings, &tmp_settings, sizeof(struct settings)); return 0; err: settings_free(&tmp_settings); return retval; }
gboolean find_missing(settings** setting) { settings* s = *setting; const char* env; gboolean error = FALSE; if (! s) return TRUE; if (! s->uid) { if ((env = getenv("LIBCALDAV_UID")) == NULL) { env = get_setting_from_file(UID); if (env == NULL) error = TRUE; } s->uid = g_strdup(env); } if (! s->pwd) { if ((env = getenv("LIBCALDAV_PWD")) == NULL) { env = get_setting_from_file(PWD); if (env == NULL) error = TRUE; } s->pwd = g_strdup(env); } if (! s->url) { if ((env = getenv("LIBCALDAV_URL")) == NULL) { env = get_setting_from_file(URL); if (env == NULL) error = TRUE; } s->url = g_strdup(env); } settings_free(&SETTING); return error; }
int settings_get_sequence_number() { Settings *s = settings_load(); int ret = s->odl0_seq_num; settings_free(s); return ret; }
int settings_write_defaults(const char *path) { int r = 0; settings_init(path); if(conf_write_config(path)) { r = 1; } settings_free(); return r; }
const char *settings_get_station_code() { static char *station_code=NULL; if (!station_code) { Settings *s = settings_load(); station_code = STRDUP(s->station_code); settings_free(s); } return station_code; }
int widget_roms_finish( widget_finish_state finished ) { if( finished == WIDGET_FINISHED_OK ) { settings_copy( &settings_current, widget_settings ); } settings_free( widget_settings ); free( widget_settings ); return 0; }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); mcs_free(rdp->mcs); xfree(rdp); } }
int settings_get_next_req_id(int request_type, const char *drf) { Settings *s = settings_load(); int id; switch (request_type) { case OBSERVATION_REQUEST: { const char *stn = settings_get_aadn_or_tdrs(); if (strncmp_case(stn, "AADN", 4)==0) { id = s->obs_req_id_aadn; } else if (strncmp_case(stn, "TDRS", 4)==0) { id = s->obs_req_id_tdrs; } else { printf("[ID] Unexpected STN: %s\n", stn); id = s->obs_req_id_aadn; } break; } case ACQUISITION_REQUEST: { int found=FALSE, i; id = 1; for (i=0; i<MAX_STATIONS; ++i) { if (strncmp_case(drf, s->acq_req_stn_codes[i], strlen(s->acq_req_stn_codes[i])) == 0) { id = s->acq_req_ids[i]; found = TRUE; break; } } if (!found) { printf("Unknown station code '%s' - using request id = 1.\n", drf); } break; } case ON_DEMAND_LEVEL_0: id = s->odl0_req_id; break; case UNSELECTED_REQUEST_TYPE: id = 0; break; } settings_free(s); return id; }
/** * Free the memory allocated for all the settings. */ void settings_free_all(void) { struct zen_settings *setp, *tmp_setp; setp = settings; while(setp) { tmp_setp = setp; setp = tmp_setp->next; settings_free(tmp_setp); free(tmp_setp); } settings = NULL; }
void test_args(void) { char* argv_c[] = { "freerdp", "-a", "8", "-u", "testuser", "-d", "testdomain", "-g", "640x480", "address1:3389", "freerdp", "-a", "16", "-u", "testuser", "-d", "testdomain", "-g", "1280x960", "address2:3390" }; char** argv = argv_c; int argc = ARRAY_SIZE(argv_c); int i; int c; rdpSettings* settings; i = 0; while (argc > 0) { settings = settings_new(NULL); i++; c = freerdp_parse_args(settings, argc, argv, process_plugin_args, NULL, process_ui_args, NULL); CU_ASSERT(c > 0); if (c == 0) { settings_free(settings); break; } CU_ASSERT(settings->color_depth == i * 8); CU_ASSERT(settings->width == i * 640); CU_ASSERT(settings->height == i * 480); CU_ASSERT(settings->port == i + 3388); settings_free(settings); argc -= c; argv += c; } CU_ASSERT(i == 2); }
int save_settings() { Settings *s = settings_new_from_gui(); if (!is_dir(s->csv_dir)) { message_box("CSV Directory doesn't exist."); return FALSE; } if (!is_dir(s->output_dir)) { message_box("Output Directory doesn't exist."); return FALSE; } settings_save(s); settings_free(s); return TRUE; }
/** * Generic function to set a settings value. * * @param setting The name of the setting. * @param value A void pointer containing the value of the setting. This * @param value must have been casted properly by the caller, but we trust * @param value the caller, do we not? * @param type The type of the setting to set. If the setting has already * @param type been set at least once, it must be the same type as it * @param type already is. Otherwise this function returns with an error. * * @return a non-zero value if an error occurred. */ int settings_set(char *setting, void *value, enum zen_settings_type type) { struct zen_settings *setp; setp = find_or_init_setting(setting); /* If the type of the currently set value is not the same as the * type the caller wishes to set this time, we should return an * error here. */ if(setp->type != SETTING_UNASSIGNED && setp->type != type) { return 1; } /* If there already was a setting with the same name, we just delete * the contents of that here, before we put in the new content. */ settings_free(setp); setp->setting = (char *)malloc(strlen(setting) + 1); if(setp->setting == NULL) { return 1; } strcpy(setp->setting, setting); setp->type = type; switch(type) { case SETTING_NUMBER: case SETTING_BOOLEAN: setp->value = value; break; case SETTING_STRING: setp->value = malloc(strlen((char *)value) + 1); if(setp->value == NULL) { return 1; } strcpy((char *)setp->value, (char *)value); break; default: return 1; } return 0; }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); input_free(rdp->input); update_free(rdp->update); fastpath_free(rdp->fastpath); nego_free(rdp->nego); mcs_free(rdp->mcs); redirection_free(rdp->redirection); mppc_free(rdp); xfree(rdp); } }
void cleanup(void) { msg_log(MSG_MESSAGE, "Cleanup...\n"); session_cleanup(); dish_file_state_cleanup(); midi_stop(); driver_stop(); patch_shutdown(); mixer_shutdown(); settings_write(); settings_free(); free_instance_name(); mod_src_destroy(); msg_log(MSG_MESSAGE, "Goodbye!\n"); exit(0); }
/* init and read settings */ void settings_init() { if (gbl_settings) settings_free(); gbl_settings = malloc(sizeof(global_settings)); gbl_settings->last_sample_dir = strdup(getenv("HOME")); gbl_settings->last_bank_dir = strdup(getenv("HOME")); gbl_settings->filename = (char*) g_build_filename( g_get_user_config_dir(), g_get_prgname(), SETTINGS_BASENAME, NULL); gbl_settings->log_lines = DEFAULT_LOG_LINES; /* gbl_settings->abs_max_sample_size = DEFAULT_ABS_MAX_SAMPLE; gbl_settings->max_sample_size = DEFAULT_MAX_SAMPLE; */ settings_read((char*) gbl_settings->filename); }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { crypto_rc4_free(rdp->rc4_decrypt_key); crypto_rc4_free(rdp->rc4_encrypt_key); crypto_des3_free(rdp->fips_encrypt); crypto_des3_free(rdp->fips_decrypt); crypto_hmac_free(rdp->fips_hmac); settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); // input_free(rdp->input); // update_free(rdp->update); fastpath_free(rdp->fastpath); nego_free(rdp->nego); mcs_free(rdp->mcs); redirection_free(rdp->redirection); mppc_free(rdp); xfree(rdp); } }
settings* parse_cmdline(int argc, char** argv) { char c; settings* setting; setting = g_new0(settings, 1); while ((c = getopt(argc, argv, "ha:dlp:u:?")) != -1) { switch (c) { case 'h': case '?': fprintf(stdout, "%s", usage[0]); return 0; case 'a': setting->url = g_strdup(optarg); break; case 'd': DEBUG = TRUE; break; case 'l': DEBUG_LIB = TRUE; break; case 'p': setting->pwd = g_strdup(optarg); break; case 'u': setting->uid = g_strdup(optarg); break; } } if (argv[optind]) { fprintf(stderr, "No arguments after options expected\n"); fprintf(stderr, "%s", usage[0]); settings_free(&setting); return NULL; } return setting; }
int main(int argc, char *argv[]) { // Get path char *ip = NULL; unsigned short connect_port = 0; unsigned short listen_port = 0; int net_mode = NET_MODE_NONE; int ret = 0; // Path manager if(pm_init() != 0) { err_msgbox(pm_get_errormsg()); return 1; } // Check arguments if(argc >= 2) { if(strcmp(argv[1], "-v") == 0) { printf("OpenOMF v%d.%d.%d\n", V_MAJOR, V_MINOR, V_PATCH); printf("Source available at https://github.com/omf2097/ under MIT License\n"); printf("(C) 2097 Tuomas Virtanen, Andrew Thompson, Hunter and others\n"); goto exit_0; } else if(strcmp(argv[1], "-h") == 0) { printf("Arguments:\n"); printf("-h Prints this help\n"); printf("-c [ip] [port] Connect to server\n"); printf("-l [port] Start server\n"); goto exit_0; } else if(strcmp(argv[1], "-c") == 0) { if(argc >= 3) { ip = strcpy(malloc(strlen(argv[2])+1), argv[2]); } if(argc >= 4) { connect_port = atoi(argv[3]); } net_mode = NET_MODE_CLIENT; } else if(strcmp(argv[1], "-l") == 0) { if(argc >= 3) { listen_port = atoi(argv[2]); } net_mode = NET_MODE_SERVER; } } // Init log #if defined(DEBUGMODE) || defined(STANDALONE_SERVER) if(log_init(0)) { err_msgbox("Error while initializing log!"); goto exit_0; } #else if(log_init(pm_get_local_path(LOG_PATH))) { err_msgbox("Error while initializing log '%s'!", pm_get_local_path(LOG_PATH)); goto exit_0; } #endif // Simple header INFO("Starting OpenOMF v%d.%d.%d", V_MAJOR, V_MINOR, V_PATCH); // Dump pathmanager log pm_log(); // Random seed rand_seed(time(NULL)); // Init stringparser sd_stringparser_lib_init(); // Init config if(settings_init(pm_get_local_path(CONFIG_PATH))) { err_msgbox("Failed to initialize settings file"); goto exit_1; } settings_load(); // Find plugins and make sure they are valid plugins_init(); // Network game override stuff if(ip) { DEBUG("Connect IP overridden to %s", ip); settings_get()->net.net_connect_ip = ip; } if(connect_port > 0 && connect_port < 0xFFFF) { DEBUG("Connect Port overridden to %u", connect_port&0xFFFF); settings_get()->net.net_connect_port = connect_port; } if(listen_port > 0 && listen_port < 0xFFFF) { DEBUG("Listen Port overridden to %u", listen_port&0xFFFF); settings_get()->net.net_listen_port = listen_port; } // Init SDL2 unsigned int sdl_flags = SDL_INIT_TIMER; #ifndef STANDALONE_SERVER sdl_flags |= SDL_INIT_VIDEO; #endif if(SDL_Init(sdl_flags)) { err_msgbox("SDL2 Initialization failed: %s", SDL_GetError()); goto exit_2; } SDL_version sdl_linked; SDL_GetVersion(&sdl_linked); INFO("Found SDL v%d.%d.%d", sdl_linked.major, sdl_linked.minor, sdl_linked.patch); INFO("Running on platform: %s", SDL_GetPlatform()); #ifndef STANDALONE_SERVER if(SDL_InitSubSystem(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER|SDL_INIT_HAPTIC)) { err_msgbox("SDL2 Initialization failed: %s", SDL_GetError()); goto exit_2; } // Attempt to find gamecontrollerdb.txt, either from resources or from // built-in header SDL_RWops *rw = SDL_RWFromConstMem(gamecontrollerdb, strlen(gamecontrollerdb)); SDL_GameControllerAddMappingsFromRW(rw, 1); char *gamecontrollerdbpath = malloc(128); snprintf(gamecontrollerdbpath, 128, "%s/gamecontrollerdb.txt", pm_get_local_path(RESOURCE_PATH)); int mappings_loaded = SDL_GameControllerAddMappingsFromFile(gamecontrollerdbpath); if (mappings_loaded > 0) { DEBUG("loaded %d mappings from %s", mappings_loaded, gamecontrollerdbpath); } free(gamecontrollerdbpath); // Load up joysticks INFO("Found %d joysticks attached", SDL_NumJoysticks()); SDL_Joystick *joy; char guidstr[33]; for (int i = 0; i < SDL_NumJoysticks(); i++) { joy = SDL_JoystickOpen(i); if (joy) { SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy); SDL_JoystickGetGUIDString(guid, guidstr, 33); INFO("Opened Joystick %d", i); INFO(" * Name: %s", SDL_JoystickNameForIndex(i)); INFO(" * Number of Axes: %d", SDL_JoystickNumAxes(joy)); INFO(" * Number of Buttons: %d", SDL_JoystickNumButtons(joy)); INFO(" * Number of Balls: %d", SDL_JoystickNumBalls(joy)); INFO(" * Number of Hats: %d", SDL_JoystickNumHats(joy)); INFO(" * GUID : %s", guidstr); } else { INFO("Joystick %d is unsupported", i); } if (SDL_JoystickGetAttached(joy)) { SDL_JoystickClose(joy); } } // Init libDumb dumb_register_stdfiles(); #endif // Init enet if(enet_initialize() != 0) { err_msgbox("Failed to initialize enet"); goto exit_3; } // Initialize engine if(engine_init()) { err_msgbox("Failed to initialize game engine."); goto exit_4; } // Run engine_run(net_mode); // Close everything engine_close(); exit_4: enet_deinitialize(); exit_3: SDL_Quit(); exit_2: dumb_exit(); settings_save(); settings_free(); exit_1: sd_stringparser_lib_deinit(); INFO("Exit."); log_close(); exit_0: if (ip) { free(ip); } plugins_close(); pm_free(); return ret; }
int main(int argc, char **argv) { struct timespec timeout = {SELECT_TIMEOUT_SECONDS, 0}; struct sigaction sigact; sigset_t select_sigset; int exitval = EXIT_FAILURE; int syslog_options = LOG_ODELAY | LOG_PERROR; int settings_retval; parse_args(argc, argv); openlog(program_invocation_short_name, syslog_options, LOG_DAEMON); syslog(LOG_INFO, "starting"); memset(&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler = &sigterm_handler; if (sigfillset(&sigact.sa_mask) == -1) { syslog(LOG_ERR, "sigfillset: %s", strerror(errno)); goto out; } if (sigaction(SIGTERM, &sigact, NULL) == -1) { syslog(LOG_ERR, "sigaction SIGTERM: %s", strerror(errno)); goto out; } if (!is_daemon && sigaction(SIGINT, &sigact, NULL) == -1) { syslog(LOG_ERR, "sigaction SIGINT: %s", strerror(errno)); goto out; } if (sigemptyset(&select_sigset) == -1) { syslog(LOG_ERR, "sigemptyset: %s", strerror(errno)); goto out; } if (sigaddset(&select_sigset, SIGTERM) == -1) { syslog(LOG_ERR, "sigaddset SIGTERM: %s", strerror(errno)); goto out; } if (!is_daemon && sigaddset(&select_sigset, SIGINT) == -1) { syslog(LOG_ERR, "sigaddset SIGINT: %s", strerror(errno)); goto out; } settings_retval = settings_read(&settings); switch (settings_retval) { case 0: break; case -1: syslog(LOG_ERR, "settings_read: %s", strerror(errno)); goto out; default: syslog(LOG_ERR, "settings_read: %s", settings_strerror(settings_retval)); goto out; } if ((monitor_fd = open_evdev_by_name(settings.monitor_name)) == -1) { syslog(LOG_ERR, "open monitor %s: %s", settings.monitor_name, strerror(errno)); goto out; } if ((filter_fd = open_evdev_by_name(settings.filter_name)) == -1) { syslog(LOG_ERR, "open filter %s: %s", settings.filter_name, strerror(errno)); goto out; } if (ioctl(filter_fd, EVIOCGRAB, 1) == -1) { syslog(LOG_ERR, "grab filter: %s", strerror(errno)); goto out; } if ((clone_fd = clone_evdev(filter_fd, &settings.clone_id, settings.clone_name)) == -1) { syslog(LOG_ERR, "clone_evdev: %s", strerror(errno)); goto out; } if (is_daemon && daemonize() == -1) { syslog(LOG_ERR, "daemonize: %s", strerror(errno)); goto out; } syslog(LOG_INFO, "started"); while (is_running) { fd_set rfds; FD_ZERO(&rfds); FD_SET(monitor_fd, &rfds); FD_SET(filter_fd, &rfds); switch (pselect(filter_fd + 1, &rfds, NULL, NULL, &timeout, &select_sigset)) { case 0: break; case -1: syslog(LOG_ERR, "select: %s", strerror(errno)); goto out; default: if (FD_ISSET(filter_fd, &rfds)) { if (handle_filter() == -1) { goto out; } } else if (FD_ISSET(monitor_fd, &rfds)) { if (handle_monitor() == -1) { goto out; } } break; } } syslog(LOG_INFO, "stopped"); syslog(LOG_INFO, "terminating"); exitval = EXIT_SUCCESS; out: settings_free(&settings); if (clone_fd != -1) { if (ioctl(clone_fd, UI_DEV_DESTROY) == -1) { syslog(LOG_ERR, "destroy clone: %s", strerror(errno)); exitval = EXIT_FAILURE; } if (close(clone_fd) == -1) { syslog(LOG_ERR, "close clone: %s", strerror(errno)); exitval = EXIT_FAILURE; } } if (filter_fd != -1) { if (ioctl(filter_fd, EVIOCGRAB, 0) == -1) { syslog(LOG_ERR, "release filter: %s", strerror(errno)); exitval = EXIT_FAILURE; } if (close(filter_fd) == -1) { syslog(LOG_ERR, "close filter: %s", strerror(errno)); exitval = EXIT_FAILURE; } } if (monitor_fd != -1) { if (close(monitor_fd) == -1) { syslog(LOG_ERR, "close monitor: %s", strerror(errno)); exitval = EXIT_FAILURE; } } syslog(LOG_INFO, "terminated"); return exitval; }
void apply_saved_settings() { Settings *s = settings_load(); apply_settings_to_gui(s); settings_free(s); }
void settings_set_next_req_id_and_incr_req_num(int req_id, int request_type, const char *drf) { Settings *s = settings_load(); switch (request_type) { case OBSERVATION_REQUEST: { const char *stn = settings_get_aadn_or_tdrs(); if (strncmp_case(stn, "AADN", 4)==0) { if (req_id <= s->obs_req_id_aadn) printf("*** New observation request id is smaller!?\n"); s->obs_req_id_aadn = req_id; ++s->obs_req_num; } else if (strncmp_case(stn, "TDRS", 4)==0) { if (req_id <= s->obs_req_id_tdrs) printf("*** New observation request id is smaller!?\n"); s->obs_req_id_tdrs = req_id; ++s->obs_req_num; } else { printf("[NUM] Unexpected STN: %s\n", stn); } break; } case ACQUISITION_REQUEST: { int found=FALSE, i; for (i=0; i<MAX_STATIONS; ++i) { if (strncmp_case(drf, s->acq_req_stn_codes[i], strlen(s->acq_req_stn_codes[i])) == 0) { if (req_id <= s->acq_req_ids[i]) printf("*** New acquisition request id for %s is smaller!?\n", drf); s->acq_req_ids[i] = req_id; found = TRUE; break; } } if (!found) { printf("Unknown station code '%s' - can't increment request id.\n", drf); } ++s->acq_req_num; break; } case ON_DEMAND_LEVEL_0: if (req_id <= s->odl0_req_id) printf("*** New on-demand level 0 request id is smaller!?\n"); s->odl0_req_id = req_id; break; case UNSELECTED_REQUEST_TYPE: printf("This should never happen!!\n"); break; } settings_save(s); apply_settings_to_gui(s); settings_free(s); update_output_file(); }