📄 configuration.c
字号:
{ return ""; } return(basic_values[key]);}/* * Get an advanced value from config file */char *get_advanced_config_value(int key){ if (advanced_values[key] == NULL) { return ""; } return(advanced_values[key]);}/* * set the bubble help for each basic config field. */voidset_basic_config_tooltips(GtkWidget *basic_config_dialog){ int i; for (i=0; i<NUM_BASIC_VALUES; i++) { GtkWidget *entry = lookup_widget(basic_config_dialog, basic_names[i]); GtkWidget *tooltips = lookup_widget(basic_config_dialog, "tooltips"); gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), entry, basic_hints[i], NULL); }}/* * set the bubble help for each advanced config field. */voidset_advanced_config_tooltips(GtkWidget *advanced_config_dialog){ int i; for (i=0; i<NUM_ADVANCED_VALUES; i++) { GtkWidget *entry = lookup_widget(advanced_config_dialog, advanced_names[i]); GtkWidget *tooltips = lookup_widget(advanced_config_dialog, "tooltips"); gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), entry, advanced_hints[i], NULL); }}/* * param config_file_path should look like $HOME/.sipset * * We have a set of defaults predefined in code. * These get over-written by the config file in INSTALL_DIR, * if that config file exists. * We look for a config file in HOME. * If that does not exist, we create one using defaults. * If config file does exist, we need to add any missing values * (in case software has been upgraded). */voidinit_config(char *config_file_path, char *config_name){ char install_file_path[100]; FILE *config_file, *install_config_file; char line[100]; char log_path[50]; char *key; char *value; struct stat stbuf; int config_file_needs_writing = FALSE; /* see if we can get default values from install dir */ sprintf(install_file_path, "%s/etc/gua.cfg", VOCAL_INSTALL_PATH); if( (stat(install_file_path, &stbuf) == 0) && S_ISREG(stbuf.st_mode)) { printf("default configuration from %s\n", install_file_path); install_config_file = fopen(install_file_path, "r"); if (install_config_file != NULL) { while (fgets(line, 100, install_config_file) != NULL) { int found = 0; int i; /* skip comments and blank lines*/ if (line[0] == '#' || isspace(line[0])) { continue; } key = strtok(line, " \t"); /* throw away the datatype specifier */ strtok(NULL, " \t"); value = strtok(NULL, " \t\n"); for (i=0; i<NUM_BASIC_VALUES; i++) { if (strcmp(basic_names[i], key) == 0) { basic_defaults[i] = strdup(value); found = 1; break; } } if (!found) { for (i=0; i<NUM_ADVANCED_VALUES; i++) { if (strcmp(advanced_names[i], key) == 0) { advanced_defaults[i] = strdup(value); break; } } } } fclose(install_config_file); } else { printf ("Error: cannot open default config %s for reading\n", install_file_path); } } else { printf("no default configuration at %s\n", install_file_path); } /* make the default log file be $HOME/.sipset/gua.log */ sprintf(log_path, "%s/gua.log", config_file_path); advanced_defaults[LOG_FILENAME] = strdup(log_path); /* see if there is already a user config directory */ if( (stat(config_file_path, &stbuf) == 0) && S_ISDIR(stbuf.st_mode)) { /* printf("config dir %s exists\n", config_file_path); */ } else { printf("config dir %s does not exist\n", config_file_path); if (mkdir(config_file_path, S_IRWXU) != 0) { printf ("error: cannot create directory %s\n", config_file_path); exit(1); } } /* now set global config_file_name to location of config file */ sprintf(config_file_name, "%s/%s", config_file_path, config_name); if( (stat(config_file_name, &stbuf) == 0) && S_ISREG(stbuf.st_mode)) { int basic_values_check[NUM_BASIC_VALUES]; int advanced_values_check[NUM_ADVANCED_VALUES]; int i; /* add any missing values */ config_file = fopen(config_file_name, "r"); /* initialize the arrays to FALSE */ for (i=0; i<NUM_BASIC_VALUES; i++) { basic_values_check[i] = FALSE; } for (i=0; i<NUM_ADVANCED_VALUES; i++) { advanced_values_check[i] = FALSE; } /* read config file and check off every value found */ while (fgets(line, 100, config_file) != NULL) { int found = 0; int i; /* skip comments and blank lines*/ if (line[0] == '#' || isspace(line[0])) { continue; } key = strtok(line, " \t"); /* throw away the datatype specifier */ strtok(NULL, " \t"); value = strtok(NULL, " \t\n"); for (i=0; i<NUM_BASIC_VALUES; i++) { if (strcmp(basic_names[i], key) == 0) { basic_values[i] = strdup(value); basic_values_check[i] = TRUE; found = 1; break; } } if (!found) { for (i=0; i<NUM_ADVANCED_VALUES; i++) { if (strcmp(advanced_names[i], key) == 0) { if(strcmp(advanced_names[i], "Video") == 0) { if(value && atoi(value)) videoEnabled = 1; } if(value) advanced_values[i] = strdup(value); else advanced_values[i] = strdup(""); advanced_values_check[i] = TRUE; break; } } } } /* Now look for any missing values */ for (i=0; i< NUM_BASIC_VALUES; i++) { if (!basic_values_check[i]) { basic_values[i] = strdup(basic_defaults[i]); config_file_needs_writing = TRUE; } } for (i=0; i< NUM_ADVANCED_VALUES; i++) { if (!advanced_values_check[i]) { advanced_values[i] = strdup(advanced_defaults[i]); config_file_needs_writing = TRUE; } } fclose(config_file); /* If Display Name was in file, then leave that field as is */ if (strlen(get_advanced_config_value(DISPLAY_NAME)) > 0) { display_name_set_by_user = TRUE; } /* If any values were missing, write the config file */ if (config_file_needs_writing) { write_all_config(); } } else { /* if config file does not exist, create it with defaults */ int i; printf ("creating config file in home directory %s\n", config_file_name); if (creat(config_file_name, 0666) != -1) { config_file = fopen(config_file_name, "w"); if (config_file == NULL) { printf("could not open %s for writing", config_file_name); exit(1); } /* write out config file */ fprintf(config_file,"# %s\n", "Config file for VOCAL Graphical User Agent (SIPset)"); /* copy defaults to values and print non-blanks to file */ for (i=0; i<NUM_BASIC_VALUES; i++) { basic_values[i] = strdup(basic_defaults[i]); fprintf(config_file,"\n# %s\n",basic_hints[i]); if (basic_defaults[i][0] == '\0') { fprintf(config_file,"# %s string <put value here>\n",basic_names[i]); } else { fprintf(config_file,"%s string %s\n",basic_names[i],basic_defaults[i]); } } /* copy defaults to values and print non-blanks to file */ for (i=0; i<NUM_ADVANCED_VALUES; i++) { advanced_values[i] = strdup(advanced_defaults[i]); fprintf(config_file,"\n# %s\n",advanced_hints[i]); if (advanced_defaults[i][0] == '\0') { fprintf(config_file,"# %s string <put value here>\n",advanced_names[i]); } else { fprintf(config_file,"%s string %s\n",advanced_names[i],advanced_defaults[i]); } } fclose(config_file); } else { printf("could not create config file %s", config_file_name); exit(1); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -