⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.c

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <sys/stat.h>#include <dirent.h>#include <stdio.h>#include <fcntl.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#ifdef HAVE_CONFIG_H#  include <config.h>#endif#include <gtk/gtk.h>#include "callbacks.h"#include "interface.h"#include "support.h"#include "configuration.h"#include "../../../build/vocalconfig.h"extern GtkWidget *main_window;extern GtkWidget *messages_window;extern GtkWidget *basic_config_dialog;extern GtkWidget *advanced_config_dialog;extern int videoEnabled;/* set to TRUE when the Display Name is edited */int display_name_set_by_user = FALSE;#define GUA_HOME ".sipset";#define STRING_LEN 100char config_file_name[100];char  *basic_values[NUM_BASIC_VALUES];char  *advanced_values[NUM_ADVANCED_VALUES];char* basic_names[] = {"User_Name", "Proxy_Server", "Pass_Word"};char *basic_defaults[] = {"","",""};char *basic_hints[] =  {    "Your phone number",    "IP address of SIP Proxy",    "Your password",  };char* advanced_names[] = {"Display_Name",                          "SIP_Transport",                          "Register_From",                          "Register_To",                          "Register_Expires",                          "Device_Name",                          "Min_RTP_Port",                          "Max_RTP_Port",                          "NATAddress_IP",                          "LogFilename",                          "LogLevel",                          "Video",                         };char *advanced_defaults[] = {"",                             "UDP",                             "",                             "",                             "300",                             "/dev/dsp",                             "10000",                             "10999",                             "",                             "",                             "LOG_ERR",                             "0",                         };char *advanced_hints[] =  {    "Name to display instead of User Name",    "Transport can be either TCP or UDP",    "IP of machine this user agent is registering from",    "IP of registrar, if different from SIP Proxy",    "Time (in seconds) until registration expires",    "Name of sound card (ie /dev/dsp)",    "Lowest port number in range of RTP ports",    "Highest port number in range of RTP ports",    "If behind NAT/firewall, enter WAN address",    "Name of file for log messages (ie /home/logfiles)",    "Use LOG_ERR for normal operation, LOG_DEBUG_STACK for debugging",    "Use 1 to turn on the Video capability.",  };voidread_basic_config(void){  GtkWidget *widget, *password_entry, *repeat_password_entry;  int i;  for (i=0; i<NUM_BASIC_VALUES; i++)  {    if ( (basic_values[i] != NULL) && (strlen(basic_values[i]) > 0) )    {      widget = lookup_widget(basic_config_dialog, basic_names[i]);      gtk_entry_set_text(GTK_ENTRY(widget), basic_values[i]);    }  }  /* Make sure that repeat password has password in it */  password_entry = lookup_widget(basic_config_dialog, "Pass_Word");  repeat_password_entry = lookup_widget(basic_config_dialog, "repeat_password");  gtk_entry_set_text(GTK_ENTRY(repeat_password_entry),       gtk_editable_get_chars(GTK_EDITABLE(password_entry), 0, -1));}voidread_advanced_config(void){  GtkWidget *widget;  int i;/*  read_all_config();*/  /* make the Display Name default to User Name if it is blank */  if( (advanced_values[DISPLAY_NAME] == NULL)    ||(strlen(advanced_values[DISPLAY_NAME]) == 0) )  {    if( (basic_values[USER_NAME] != NULL)      &&(strlen(basic_values[USER_NAME]) > 0) )    {      advanced_values[DISPLAY_NAME] = strdup(basic_values[USER_NAME]);    }    display_name_set_by_user = FALSE;  }  for (i=0; i<NUM_ADVANCED_VALUES; i++)  {    if( (advanced_values[i] != NULL)      &&(strlen(advanced_values[i]) > 0) )    {      widget = lookup_widget(advanced_config_dialog, advanced_names[i]);      if(strcmp(advanced_names[i], "Video") == 0)      {          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),                       atoi(advanced_values[i]));      }      else      {          gtk_entry_set_text(GTK_ENTRY(widget), advanced_values[i]);      }    }  }}voidwrite_all_config(void){  int i;  FILE *config_file;        config_file = fopen(config_file_name, "w");  if (config_file == NULL)  {    printf("could not open %s for writing", config_file_name);    exit(1);  }  /* ensure that Display Name does not get written unless it was edited by user */  if (!display_name_set_by_user)  {    advanced_values[DISPLAY_NAME][0] = '\0';  }  /* write out config file */  fprintf(config_file,"# %s\n",    "Config file for VOCAL Graphical User Agent (SIPset)");  for (i=0; i<NUM_BASIC_VALUES; i++)  {    fprintf(config_file,"\n# %s\n",basic_hints[i]);    if (basic_values[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_values[i]);    }  }  for (i=0; i<NUM_ADVANCED_VALUES; i++)  {    fprintf(config_file,"\n# %s\n",advanced_hints[i]);    if (advanced_values[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_values[i]);    }  }  fclose(config_file);}intwrite_basic_config(void){  GtkWidget *widget, *password_entry, *repeat_password_entry;  gchar *data, *password_data, *repeat_password_data;  int i;  /* Check that the password matches the repeat password */  password_entry = lookup_widget(basic_config_dialog, "Pass_Word");  repeat_password_entry = lookup_widget(basic_config_dialog, "repeat_password");  password_data = gtk_editable_get_chars(GTK_EDITABLE(password_entry), 0, -1);  repeat_password_data = gtk_editable_get_chars(GTK_EDITABLE(repeat_password_entry), 0, -1);  if (strcmp(password_data, repeat_password_data) != 0)  {    /* pop up error message and clear password fields */    GtkWidget *error_dialog = create_error_dialog();    GtkWidget *error_label = lookup_widget (error_dialog, "error_label");        gtk_label_set_text(GTK_LABEL(error_label), "Passwords do not match");    gtk_window_set_modal(GTK_WINDOW(error_dialog), TRUE);    gtk_entry_set_text(GTK_ENTRY(password_entry), "");    gtk_entry_set_text(GTK_ENTRY(repeat_password_entry), "");    gtk_widget_grab_focus (password_entry);    gtk_widget_show(error_dialog);    return FALSE;  }  for (i = 0; i<NUM_BASIC_VALUES; i++)  {    widget = lookup_widget(basic_config_dialog, basic_names[i]);    data = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);    basic_values[i] = strdup(data);  }  write_all_config();  return TRUE;}voidwrite_advanced_config(void){  GtkWidget *widget;  gchar *data;  int i;  for (i = 0; i<NUM_ADVANCED_VALUES; i++)  {    widget = lookup_widget(advanced_config_dialog, advanced_names[i]);    if(strcmp(advanced_names[i], "Video") == 0)    {        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))        {            data = "1";            videoEnabled = 1;            gtk_widget_set_usize (main_window, 380, 350);        }        else        {            data = "0";            videoEnabled = 0;            gtk_widget_set_usize (main_window, 380, 170);        }    }    else    {        data = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);    }    advanced_values[i] = strdup(data);  }  write_all_config();}/* this function is used in the foreach loop of write_phone_history */void write_to_file(gpointer data, gpointer file){  fprintf(file, "%s\n", (char *)data);}void write_phone_history(GList *history_list, char *dial_history_path){  FILE *dial_history;  dial_history = fopen(dial_history_path, "w");  if (dial_history != NULL)  {    g_list_foreach(history_list, write_to_file, (gpointer)dial_history);    fclose(dial_history);  }  else  {    printf("could not open %s for writing\n", dial_history_path);  }}/* * Get a basic value from config file */char *get_basic_config_value(int key){  if (basic_values[key] == NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -