Ejemplo n.º 1
0
int ConfigInt(int config_id)
{
   config_node *c;
   int ret_val;

   c = GetConfigByID(config_id);
   if (c == NULL)
   {
      StartupPrintf("ConfigInt can't find id %i\n",config_id);
      return 0;
   }
   if (c->config_type != CONFIG_INT)
   {
      StartupPrintf("ConfigInt found id %i is not int\n",config_id);
      return 0;
   }

   if (c->is_dynamic)
      LockDynamicConfig();

   ret_val = c->config_int_value;

   if (c->is_dynamic)
      UnlockDynamicConfig();

   return ret_val;
}
Ejemplo n.º 2
0
Bool ConfigBool(int config_id)
{
   config_node *c;
   Bool ret_val;
   
   c = GetConfigByID(config_id);
   if (c == NULL)
   {
      StartupPrintf("ConfigBool can't find id %i\n",config_id);
      return 0;
   }
   if (c->config_type != CONFIG_BOOL)
   {
      StartupPrintf("ConfigBool found id %i is not bool\n",config_id);
      return 0;
   }

   if (c->is_dynamic)
      LockDynamicConfig();

   ret_val = c->config_int_value;

   if (c->is_dynamic)
      UnlockDynamicConfig();

   return ret_val;
}
Ejemplo n.º 3
0
char * ConfigStr(int config_id)
{
   config_node *c;

   /* this should be changed to NOT call startupprintf */
   
   c = GetConfigByID(config_id);
   if (c == NULL)
   {
      StartupPrintf("ConfigStr can't find id %i\n",config_id);
      return NULL;
   }
   if (c->config_type != CONFIG_STR && c->config_type != CONFIG_PATH)
   {
      StartupPrintf("ConfigStr found id %i is not str\n",config_id);
      return NULL;
   }

   if (c->is_dynamic)
   {
      StartupPrintf("ConfigStr found id %i is dynamic\n",config_id);
      return NULL;
   }

   return c->config_str_value;
}
Ejemplo n.º 4
0
void LoadConfig(void)
{
   FILE *configfile;
   char line[MAX_CONFIG_LINE+1];
   int lineno,current_group,i,config_id;   

   if ((configfile = fopen(CONFIG_FILE,"rt")) == NULL)
      StartupPrintf("LoadConfig can't open %s, using default configuration\n",CONFIG_FILE);
   else
   {
      lineno = 1;
      current_group = -1;
      while (fgets(line,MAX_CONFIG_LINE,configfile))
      {
	 current_group = LoadConfigLine(line,lineno,CONFIG_FILE,current_group);
	 lineno++;
      }
      fclose(configfile);
   }

   for (i=0;i<LEN_CONFIG_TABLE;i++)
   {
      config_id = config_table[i].config_id;
      if (GetConfigByID(config_id) == NULL)
	 AddConfig(config_id,config_table[i].default_str,
		   config_table[i].config_type,config_table[i].is_dynamic);
   }
}
Ejemplo n.º 5
0
void StartupComplete()
{
	char str[200];
	connection_node conn;
	session_node *s;
	
	len_admin_response_buf = 0;
	
	conn.type = CONN_CONSOLE;
	s = CreateSession(conn);
	if (s == NULL)
		FatalError("Interface can't make session for console");
	s->account = GetConsoleAccount();
	InitSessionState(s,STATE_ADMIN);
	console_session_id = s->session_id;
	
	
	if (Edit_GetText(GetDlgItem(HWND_STATUS,IDC_STARTUP_TEXT),str,sizeof(str)) == 0)
		StartupPrintf("No errors on startup\n");
	
	SendDlgItemMessage(hwndMain,IDC_TOOLBAR,TB_ENABLEBUTTON,IDM_FILE_EXIT,MAKELPARAM(TRUE,0));
	SendDlgItemMessage(hwndMain,IDC_TOOLBAR,TB_ENABLEBUTTON,IDM_FILE_SAVE,MAKELPARAM(TRUE,0));
	SendDlgItemMessage(hwndMain,IDC_TOOLBAR,TB_ENABLEBUTTON,IDM_FILE_RELOADSYSTEM,
		      MAKELPARAM(TRUE,0));
	SendDlgItemMessage(hwndMain,IDC_TOOLBAR,TB_ENABLEBUTTON,IDM_MESSAGES_MESSAGEOFTHEDAY,
		      MAKELPARAM(TRUE,0));
	
}
Ejemplo n.º 6
0
config_node * GetConfigByID(int config_id)
{
   if (config_id < 0 || config_id >= NUM_CONFIG_VALUES)
   {
      StartupPrintf("GetConfigByID got invalid request for id %i\n",config_id);
      return NULL;
   }

   if (configs[config_id].config_type == CONFIG_NONE)
      return NULL;
   else
      return &configs[config_id];
}
Ejemplo n.º 7
0
void InitMemory(void)
{
	int i;
	
	/* verify that memory_stat_names has a name for every malloc_id */
	i = 0;
	while (memory_stat_names[i] != NULL)
		i++;
	
	if (i != MALLOC_ID_NUM)
		StartupPrintf("InitMemory FATAL there aren't names for every malloc id\n");
	
	for (i=0;i<MALLOC_ID_NUM;i++)
		memory_stat.allocated[i] = 0;
}
Ejemplo n.º 8
0
void OpenDefaultChannels()
{
   int i;
   for (i=0;i<NUM_CHANNELS;i++)
   {
      if (ConfigBool(channel_table[i].disk_config_id))
      {
         channel[i].file = CreateFileChannel(i);
         if (channel[i].file == NULL)
            StartupPrintf("OpenDefaultChannels couldn't open file %s\n",
                          channel_table[i].file_name);
      }
      else
         channel[i].file = NULL;
   }
}
Ejemplo n.º 9
0
int LoadConfigLine(char *line,int lineno,const char *filename,int current_group)
{
   char *first_str,*t1;
   int i;

   first_str = strtok(line,"= \t\n");
   if (first_str == NULL)
      return current_group;

   if (*first_str == '#')
      return current_group;
   
   if (*first_str == '[')
   {
      if (strchr(first_str,']') == NULL)
      {
	 StartupPrintf("LoadConfigLine found invalid grouping (no ]) %s (%i)\n",
		filename,lineno);
	 return current_group;
      }
      t1 = strtok(NULL,"= \t\n");
      if (t1 != NULL)
      {
	 StartupPrintf("LoadConfigLine found extra stuff after grouping %s (%i)\n",
		filename,lineno);
	 return current_group;
      }

      for (i=0;i<LEN_CONFIG_TABLE;i++)
	 if (config_table[i].config_type == CONFIG_GROUP &&
	     !stricmp(first_str,config_table[i].config_name))
	    return i;
      
      StartupPrintf("LoadConfig found nonexistent group %s %s (%i)\n",
	     first_str,filename,lineno);
      
      return current_group;
   }
   
   
   if (current_group < 0 || current_group >= LEN_CONFIG_TABLE)
   {
      StartupPrintf("LoadConfig found data before a group declared %s (%i)\n",
	     filename,lineno);
      return current_group;
   }

   t1 = strtok(NULL,"\n");	/* rest of the line */
   if (t1 == NULL)
   {
      StartupPrintf("LoadConfig error %s (%i): no data value\n",filename,lineno);
      return current_group;
   }

   while (*t1 != 0 && (*t1 == ' ' || *t1 == '\t'))
      t1++;			/* skip whitespace */

   if (*t1 == '<' && *(t1+strlen(t1)-1) == '>')
   {
      *(t1+strlen(t1)-1) = 0;
      t1++;
   }
   else
      t1 = strtok(t1," \t\n");

   for (i=current_group+1;i<LEN_CONFIG_TABLE;i++)
   {
      if (config_table[i].config_type == CONFIG_GROUP)
	 break;

      if (!stricmp(first_str,config_table[i].config_name))
      {
         const char *s = AddConfig(config_table[i].config_id,t1,config_table[i].config_type,
		       config_table[i].is_dynamic);
	 if (s != NULL)
	    StartupPrintf("LoadConfig error %s (%i): `%s' is %s\n",
		   filename,lineno,t1,s);
	 break;
      }
   }
   
   if (i == LEN_CONFIG_TABLE || config_table[i].config_type == CONFIG_GROUP)
      StartupPrintf("LoadConfig can't match value %s (%i)\n",filename,lineno);

   return current_group;
}
Ejemplo n.º 10
0
/* returns error string, NULL if ok */
const char * AddConfig(int config_id,const char *config_data,int config_type,int is_dynamic)
{
   config_node *c;
   int len,num;
   struct stat file_stat;
   char s[MAX_CONFIG_LINE];

   c = GetConfigByID(config_id);
   if (c != NULL)
      return "config option listed more than once";

   c = &configs[config_id];

   c->is_dynamic = is_dynamic;

   strcpy(s,config_data);

   switch (config_type)
   {
   case CONFIG_GROUP :
      break;

   case CONFIG_PATH :
      len = strlen(s);
      
      if (s[len-1] == '\\')
	 s[len-1] = 0;
      
      if (stat(s,&file_stat) != 0 || !(file_stat.st_mode & S_IFDIR))
	 return "invalid path--not found";
      
      if (s[len-1] != ':')
	 strcat(s,"\\");
      c->config_str_value = (char *)AllocateMemory(MALLOC_ID_CONFIG,strlen(s)+1);
      strcpy(c->config_str_value,s);
      break;

   case CONFIG_INT :
      if (sscanf(s,"%i",&num) != 1)
	 return "invalid int";
      c->config_int_value = num;
      break;

   case CONFIG_BOOL :
      if (stricmp(s,"YES") != 0 && stricmp(s,"NO") != 0)
	 return "invalid bool";
      c->config_int_value = (stricmp(s,"YES") == 0);
      break;

   case CONFIG_STR :
      if (s && *s == '@')
      {
	 // If blakserv.cfg has line "Setting   <@setting.txt>",
	 // then Setting is set to the *contents* of the first line
	 // of the setting.txt file.  The config becomes non-dynamic,
	 // since SetConfigStr would need to either ignore settings.txt
	 // or write to it.

	 FILE* f = fopen(s+1, "rt");
	 if (f)
	 {
	    fgets(s, sizeof(s)-1, f);
	    strtok(s, "\r\n\x1A");
	    fclose(f);
	    c->is_dynamic = false;
	 }
      }
      c->config_str_value = (char *)AllocateMemory(MALLOC_ID_CONFIG,strlen(s)+1);
      strcpy(c->config_str_value,s);
      break;

   default :
      StartupPrintf("AddConfig can't handle type %i\n",config_type);
      break;
   }

   c->config_id = config_id;
   c->config_type = config_type;

   return NULL; /* no error string, everything is fine */
}