Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

cms_cfg.cc File Reference

#include "rcs_defs.hh"
#include "inetfile.hh"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "cms.hh"
#include "cms_cfg.hh"
#include "tcpmem.hh"
#include "stcpmem.hh"
#include "udpmem.hh"
#include "phantom.hh"
#include "locmem.hh"
#include "shmem.hh"
#include "ttymem.hh"
#include "rcs_prnt.hh"
#include "linklist.hh"

Include dependency graph for cms_cfg.cc:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  CONFIG_FILE_INFO
struct  CONFIG_SEARCH_STRUCT

Defines

#define CMS_USE_INET_FILES

Enumerations

enum  CONFIG_SEARCH_ERROR_TYPE {
  CONFIG_SEARCH_ERROR_NOT_SET, CONFIG_SEARCH_OK, BAD_CONFIG_FILE, NO_PROCESS_LINE,
  NO_BUFFER_LINE, MISC_CONFIG_SEARCH_ERROR
}

Functions

int load_nml_config_file (const char *file)
int unload_nml_config_file (const char *file)
CONFIG_FILE_INFOget_loaded_nml_config_file (const char *file)
int print_loaded_nml_config_file (const char *file)
int print_loaded_nml_config_file_list ()
int unload_all_nml_config_file ()
int convert2upper (char *dest, char *src, int len)
int cms_copy (CMS **dest, CMS *src, int set_to_server, int set_to_master)
char * get_buffer_line (const char *bufname, const char *filename)
void find_proc_and_buffer_lines (CONFIG_SEARCH_STRUCT *s)
int cms_config (CMS **cms, char *bufname, char *procname, char *filename, int set_to_server, int set_to_master)
int hostname_matches_bufferline (char *bufline)
int cms_create_from_lines (CMS **cms, char *buffer_line, char *proc_line, int set_to_server, int set_to_master)
int cms_create (CMS **cms, char *buffer_line, char *proc_line, char *buffer_type, char *proc_type, int set_to_server, int set_to_master)

Variables

int verbose_nml_error_messages
RCS_LINKED_LISTconfig_file_list = NULL
int loading_config_file = 0


Define Documentation

#define CMS_USE_INET_FILES
 

Definition at line 14 of file cms_cfg.cc.


Enumeration Type Documentation

enum CONFIG_SEARCH_ERROR_TYPE
 

Enumeration values:
CONFIG_SEARCH_ERROR_NOT_SET 
CONFIG_SEARCH_OK 
BAD_CONFIG_FILE 
NO_PROCESS_LINE 
NO_BUFFER_LINE 
MISC_CONFIG_SEARCH_ERROR 

Definition at line 595 of file cms_cfg.cc.


Function Documentation

int load_nml_config_file const char *    file
 

Definition at line 122 of file cms_cfg.cc.

00123 {
00124   unload_nml_config_file (file);
00125   if (loading_config_file)
00126     {
00127       return -1;
00128     }
00129   loading_config_file = 1;
00130   if (NULL == file)
00131     {
00132       loading_config_file = 0;
00133       return -1;
00134     }
00135   if (NULL == config_file_list)
00136     {
00137       config_file_list = new RCS_LINKED_LIST ();
00138     }
00139   if (NULL == config_file_list)
00140     {
00141       loading_config_file = 0;
00142       return -1;
00143     }
00144   char line[CMS_CONFIG_LINELEN];        /* Temporary buffer for line from file. */
00145 
00146   CONFIG_FILE_INFO *info = new CONFIG_FILE_INFO ();
00147   info->lines_list = new RCS_LINKED_LIST ();
00148   strncpy (info->file_name, file, 80);
00149 #ifdef CMS_USE_INET_FILES
00150   INET_FILE *fp;
00151   fp = inet_file_open ((char *) file, "r");
00152 #else
00153   FILE *fp;
00154   fp = fopen (file, "r");
00155 #endif
00156   if (fp == NULL)
00157     {
00158 #ifndef UNDER_CE
00159       rcs_print_error ("cms_config: can't open '%s'. Error = %d -- %s\n",
00160                        file, errno, strerror (errno));
00161 #else
00162       rcs_print_error ("cms_config: can't open '%s'.\n", file);
00163 #endif
00164       if (NULL != info)
00165         {
00166           delete info;
00167         }
00168       loading_config_file = 0;
00169       return -1;
00170     }
00171 
00172 #ifdef CMS_USE_INET_FILES
00173   while (!inet_file_eof (fp))
00174 #else
00175   while (!feof (fp))
00176 #endif
00177     {
00178 #ifdef CMS_USE_INET_FILES
00179       if ((inet_file_gets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00180         {
00181           break;
00182         }
00183 #else
00184       if ((fgets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00185         {
00186           break;
00187         }
00188 #endif
00189       int linelen = strlen (line);
00190       if (linelen < 3)
00191         {
00192           continue;
00193         }
00194       while (line[linelen - 1] == '\\')
00195         {
00196           int pos = linelen - 2;
00197 #ifdef CMS_USE_INET_FILES
00198           if ((inet_file_gets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) ==
00199               NULL)
00200             {
00201               break;
00202             }
00203 #else
00204           if ((fgets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) == NULL)
00205             {
00206               break;
00207             }
00208 #endif
00209           linelen = strlen (line);
00210           if (linelen > CMS_CONFIG_LINELEN - 2)
00211             {
00212               break;
00213             }
00214         }
00215 
00216       if (line[0] == '#')
00217         {
00218           continue;
00219         }
00220       info->lines_list->store_at_tail (line, linelen + 1, 1);
00221     }
00222 
00223   if (NULL != fp)
00224     {
00225 #ifdef CMS_USE_INET_FILES
00226       inet_file_close (fp);
00227 #else
00228       fclose (fp);
00229 #endif
00230       fp = NULL;
00231     }
00232   config_file_list->store_at_tail (info, sizeof (info), 0);
00233   loading_config_file = 0;
00234   return 0;
00235 }

int unload_nml_config_file const char *    file
 

Definition at line 238 of file cms_cfg.cc.

00239 {
00240   if (loading_config_file)
00241     {
00242       return -1;
00243     }
00244   if (NULL == file)
00245     {
00246       return -1;
00247     }
00248   if (NULL == config_file_list)
00249     {
00250       return -1;
00251     }
00252   CONFIG_FILE_INFO *info = (CONFIG_FILE_INFO *) config_file_list->get_head ();
00253   while (NULL != info)
00254     {
00255       if (!strncmp (info->file_name, file, 80))
00256         {
00257           config_file_list->delete_current_node ();
00258           delete info;
00259           return 0;
00260         }
00261       info = (CONFIG_FILE_INFO *) config_file_list->get_next ();
00262     }
00263   return -1;
00264 }

CONFIG_FILE_INFO* get_loaded_nml_config_file const char *    file
 

Definition at line 269 of file cms_cfg.cc.

Referenced by find_proc_and_buffer_lines(), get_buffer_line(), and print_loaded_nml_config_file().

00270 {
00271   if (NULL == file)
00272     {
00273       return NULL;
00274     }
00275   if (NULL == config_file_list)
00276     {
00277       return NULL;
00278     }
00279   CONFIG_FILE_INFO *info = (CONFIG_FILE_INFO *) config_file_list->get_head ();
00280   while (NULL != info)
00281     {
00282       if (!strncmp (info->file_name, file, 80))
00283         {
00284           return info;
00285         }
00286       info = (CONFIG_FILE_INFO *) config_file_list->get_next ();
00287     }
00288   return NULL;
00289 }

int print_loaded_nml_config_file const char *    file
 

Definition at line 292 of file cms_cfg.cc.

00293 {
00294   CONFIG_FILE_INFO *info = get_loaded_nml_config_file (file);
00295   if (NULL == info)
00296     {
00297       rcs_print ("Config file %s not loaded.\n");
00298       return -1;
00299     }
00300   if (NULL == info->lines_list)
00301     {
00302       return -1;
00303     }
00304   char *line = (char *) info->lines_list->get_head ();
00305   while (NULL != line)
00306     {
00307       rcs_print ("%s", line);
00308       int linelen = strlen (line);
00309       if (linelen > 1)
00310         {
00311           char last_char = line[linelen - 1];
00312           if (last_char != '\n' && last_char != '\r')
00313             {
00314               rcs_print ("\n");
00315             }
00316         }
00317       line = (char *) info->lines_list->get_next ();
00318     }
00319   rcs_print ("\n");
00320   return 0;
00321 }

int print_loaded_nml_config_file_list  
 

Definition at line 324 of file cms_cfg.cc.

Referenced by CMS_CONFIG_COMMENTCHAR().

00325 {
00326   if (loading_config_file)
00327     {
00328       rcs_print
00329         ("In the process of loading a config file, please try again later.\n");
00330       return -1;
00331     }
00332   if (NULL == config_file_list)
00333     {
00334       rcs_print ("No Configuration files loaded.\n");
00335       return 0;
00336     }
00337   CONFIG_FILE_INFO *info = (CONFIG_FILE_INFO *) config_file_list->get_head ();
00338   while (NULL != info)
00339     {
00340       if (NULL != info->lines_list)
00341         {
00342           rcs_print ("%s \t- - \t%d lines\n", info->file_name,
00343                      info->lines_list->list_size);
00344         }
00345       else
00346         {
00347           rcs_print ("%s \t-1 lines", info->file_name);
00348         }
00349       info = (CONFIG_FILE_INFO *) config_file_list->get_next ();
00350     }
00351   return 0;
00352 }

int unload_all_nml_config_file  
 

Definition at line 356 of file cms_cfg.cc.

00357 {
00358   if (loading_config_file)
00359     {
00360       return -1;
00361     }
00362   if (NULL == config_file_list)
00363     {
00364       return -1;
00365     }
00366   CONFIG_FILE_INFO *info = (CONFIG_FILE_INFO *) config_file_list->get_head ();
00367   while (NULL != info)
00368     {
00369       config_file_list->delete_current_node ();
00370       delete info;
00371       info = (CONFIG_FILE_INFO *) config_file_list->get_next ();
00372     }
00373   if (config_file_list->list_size <= 0)
00374     {
00375       delete config_file_list;
00376       config_file_list = NULL;
00377     }
00378   return 0;
00379 }

int convert2upper char *    dest,
char *    src,
int    len
[static]
 

Definition at line 406 of file cms_cfg.cc.

00407 {
00408   int i;
00409   if (src == NULL || dest == NULL)
00410     {
00411       rcs_print_error ("convert2upper passed NULL argument.\n");
00412       return -1;
00413     }
00414 
00415   for (i = 0; i < len; i++)
00416     {
00417       if (src[i] == 0)
00418         {
00419           dest[i] = 0;
00420           return i;
00421         }
00422 #ifndef UNDER_CE
00423       dest[i] = toupper (src[i]);
00424 #else
00425       if (src[i] >= 'a' && src[i] <= 'z')
00426         {
00427           dest[i] = src[i] + ('A' - 'a');
00428         }
00429       else
00430         {
00431           dest[i] = src[i];
00432         }
00433 #endif
00434 
00435     }
00436   return i;
00437 }

int cms_copy CMS **    dest,
CMS   src,
int    set_to_server = 0,
int    set_to_master = 0
 

Definition at line 441 of file cms_cfg.cc.

00442 {
00443   if (NULL == dest || NULL == src)
00444     {
00445       return -1;
00446     }
00447   return cms_create_from_lines (dest, src->BufferLine, src->ProcessLine,
00448                                 set_to_server, set_to_master);
00449 }

char* get_buffer_line const char *    buf,
const char *    file
 

Definition at line 453 of file cms_cfg.cc.

00454 {
00455   int line_len, line_number;
00456   char linebuf[CMS_CONFIG_LINELEN];     /* Temporary buffer for line from file. */
00457   char *line = linebuf;
00458 #ifdef CMS_USE_INET_FILES
00459   INET_FILE *fp = NULL;
00460 #else
00461   FILE *fp = NULL;              /* FILE ptr to config file.  */
00462 #endif
00463   char *word[4];                /* array of pointers to words from line */
00464 
00465 
00466   /* Open the configuration file. */
00467   RCS_LINKED_LIST *lines_list = NULL;
00468   CONFIG_FILE_INFO *info = get_loaded_nml_config_file (filename);
00469   if (NULL != info)
00470     {
00471       lines_list = info->lines_list;
00472       line = (char *) lines_list->get_head ();
00473     }
00474 
00475   if (NULL == lines_list)
00476     {
00477 #ifdef CMS_USE_INET_FILES
00478       fp = inet_file_open (filename, "r");
00479 #else
00480       fp = fopen (filename, "r");
00481 #endif
00482       if (fp == NULL)
00483         {
00484 #ifndef UNDER_CE
00485           rcs_print_error ("cms_config: can't open '%s'. Error = %d -- %s\n",
00486                            filename, errno, strerror (errno));
00487 #else
00488           rcs_print_error ("cms_config: can't open '%s'.\n", filename);
00489 #endif
00490           loading_config_file = 0;
00491           return NULL;
00492         }
00493     }
00494 
00495 
00496   /* Read the configuration file line by line until the lines matching */
00497   /*     bufname and procname are found.  */
00498   line_number = 0;
00499   int first_line = 1;
00500 
00501 
00502   while (1)
00503     {
00504       if (NULL != lines_list)
00505         {
00506           if (!first_line)
00507             {
00508               line = (char *) lines_list->get_next ();
00509             }
00510           first_line = 0;
00511           if (NULL == line)
00512             {
00513               break;
00514             }
00515         }
00516       else
00517         {
00518 #ifdef CMS_USE_INET_FILES
00519           if (inet_file_eof (fp))
00520             {
00521               break;
00522             }
00523           if ((inet_file_gets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00524             {
00525               break;
00526             }
00527 #else
00528           if (feof (fp))
00529             {
00530               break;
00531             }
00532           if ((fgets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00533             {
00534               break;
00535             }
00536 #endif
00537         }
00538 
00539 
00540       line_number++;
00541       line_len = strlen (line);
00542       while (line[line_len - 1] == '\\')
00543         {
00544           int pos = line_len - 2;
00545 #ifdef CMS_USE_INET_FILES
00546           if ((inet_file_gets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) ==
00547               NULL)
00548             {
00549               break;
00550             }
00551 #else
00552           if ((fgets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) == NULL)
00553             {
00554               break;
00555             }
00556 #endif
00557           line_len = strlen (line);
00558           if (line_len > CMS_CONFIG_LINELEN - 2)
00559             {
00560               break;
00561             }
00562           line_number++;
00563         }
00564       if (line_len > CMS_CONFIG_LINELEN)
00565         {
00566           rcs_print_error
00567             ("cms_cfg: Line length of line number %d in %s exceeds max length of %d",
00568              line_number, filename, CMS_CONFIG_LINELEN);
00569         }
00570 
00571 
00572       /* Skip comment lines and lines starting with white space. */
00573       if (line[0] == CMS_CONFIG_COMMENTCHAR ||
00574           strchr (" \t\n\r\0", line[0]) != NULL)
00575         {
00576           continue;
00577         }
00578 
00579 
00580       /* Separate out the first four strings in the line. */
00581       if (separate_words (word, 4, line) != 4)
00582         {
00583           continue;
00584         }
00585 
00586       if (!strcmp (word[1], bufname) && line[0] == 'B')
00587         {
00588           /* Buffer line found, store the line and type. */
00589           return line;
00590         }
00591     }
00592   return NULL;
00593 }

void find_proc_and_buffer_lines CONFIG_SEARCH_STRUCT   s
 

Definition at line 847 of file cms_cfg.cc.

Referenced by cms_config().

00848 {
00849   if (s == 0)
00850     {
00851       return;
00852     }
00853 
00854   loading_config_file = 1;
00855 #ifdef CMS_USE_INET_FILES
00856   INET_FILE *fp = NULL;
00857 #else
00858   FILE *fp = NULL;              /* FILE ptr to config file.  */
00859 #endif
00860   char linebuf[CMS_CONFIG_LINELEN];     /* Temporary buffer for line from file. */
00861   char *line = linebuf;
00862   int line_len, line_number;
00863   char *word[4];                /* array of pointers to words from line */
00864 
00865   int first_line = 1;
00866 
00867   /* Open the configuration file. */
00868   RCS_LINKED_LIST *lines_list = NULL;
00869   CONFIG_FILE_INFO *info = get_loaded_nml_config_file (s->filename);
00870   if (NULL != info)
00871     {
00872       lines_list = info->lines_list;
00873       line = (char *) lines_list->get_head ();
00874     }
00875 
00876   if (NULL == lines_list)
00877     {
00878 #ifdef CMS_USE_INET_FILES
00879       fp = inet_file_open (s->filename, "r");
00880 #else
00881       fp = fopen (s->filename, "r");
00882 #endif
00883       if (fp == NULL)
00884         {
00885 #ifndef UNDER_CE
00886           rcs_print_error ("cms_config: can't open '%s'. Error = %d -- %s\n",
00887                            s->filename, errno, strerror (errno));
00888 #else
00889           rcs_print_error ("cms_config: can't open '%s'.\n", s->filename);
00890 #endif
00891           loading_config_file = 0;
00892           s->error_type = BAD_CONFIG_FILE;
00893           return;
00894         }
00895     }
00896 
00897 
00898   /* Read the configuration file line by line until the lines matching */
00899   /*     bufname and procname are found.  */
00900   line_number = 0;
00901 
00902   while (1)
00903     {
00904       if (NULL != lines_list)
00905         {
00906           if (!first_line)
00907             {
00908               line = (char *) lines_list->get_next ();
00909             }
00910           first_line = 0;
00911           if (NULL == line)
00912             {
00913               break;
00914             }
00915         }
00916       else
00917         {
00918 #ifdef CMS_USE_INET_FILES
00919           if (inet_file_eof (fp))
00920             {
00921               break;
00922             }
00923           if ((inet_file_gets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00924             {
00925               break;
00926             }
00927 #else
00928           if (feof (fp))
00929             {
00930               break;
00931             }
00932           if ((fgets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00933             {
00934               break;
00935             }
00936 #endif
00937         }
00938 
00939 
00940       line_number++;
00941       line_len = strlen (line);
00942       if (line_len < 3)
00943         {
00944           continue;
00945         }
00946       while (line[line_len - 1] == '\\')
00947         {
00948           int pos = line_len - 2;
00949 #ifdef CMS_USE_INET_FILES
00950           if ((inet_file_gets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) ==
00951               NULL)
00952             {
00953               break;
00954             }
00955 #else
00956           if ((fgets (line + pos, CMS_CONFIG_LINELEN - pos, fp)) == NULL)
00957             {
00958               break;
00959             }
00960 #endif
00961           line_len = strlen (line);
00962           if (line_len > CMS_CONFIG_LINELEN)
00963             {
00964               break;
00965             }
00966           line_number++;
00967         }
00968       if (line_len > CMS_CONFIG_LINELEN)
00969         {
00970           rcs_print_error
00971             ("cms_cfg: Line length of line number %d in %s exceeds max length of %d",
00972              line_number, s->filename, CMS_CONFIG_LINELEN);
00973         }
00974 
00975       /* Skip comment lines and lines starting with white space. */
00976       if (line[0] == CMS_CONFIG_COMMENTCHAR ||
00977           strchr (" \t\n\r\0", line[0]) != NULL)
00978         {
00979           continue;
00980         }
00981 
00982 
00983       /* Separate out the first four strings in the line. */
00984       if (separate_words (word, 4, line) != 4)
00985         {
00986           continue;
00987         }
00988 
00989       if (!s->bufline_found && !strcmp (word[1], s->bufname) &&
00990           line[0] == 'B')
00991         {
00992           /* Buffer line found, store the line and type. */
00993           strncpy (s->buffer_line, line, CMS_CONFIG_LINELEN);
00994           convert2upper (s->buffer_type, word[2], CMS_CONFIG_LINELEN);
00995           s->bufline_found = 1;
00996           s->bufline_number = line_number;
00997           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
00998                            "cms_config found buffer line on line %d\n",
00999                            line_number);
01000         }
01001       else if (!s->procline_found && !strcmp (word[1], s->procname) &&
01002                line[0] == 'P' && !strcmp (word[2], s->bufname_for_procline))
01003         {
01004           /* Procedure line found, store the line and type. */
01005           strncpy (s->proc_line, line, CMS_CONFIG_LINELEN);
01006           switch (cms_connection_mode)
01007             {
01008             case CMS_NORMAL_CONNECTION_MODE:
01009               convert2upper (s->proc_type, word[3], CMS_CONFIG_LINELEN);
01010               if (!strncmp (s->proc_type, "AUTO", 4))
01011                 {
01012                   if (!s->bufline_found)
01013                     {
01014                       rcs_print_error
01015                         ("Can't use process type AUTO unless the buffer line for %s is found earlier in the config file.\n",
01016                          s->bufname);
01017                       rcs_print_error ("Bad line:\n%s:%d %s\n", s->filename,
01018                                        line_number, line);
01019                       s->error_type = MISC_CONFIG_SEARCH_ERROR;
01020                       return;
01021                     }
01022                   if (hostname_matches_bufferline (s->buffer_line))
01023                     {
01024                       strcpy (s->proc_type, "LOCAL");
01025                     }
01026                   else
01027                     {
01028                       strcpy (s->proc_type, "REMOTE");
01029                     }
01030                 }
01031               break;
01032 
01033             case CMS_FORCE_LOCAL_CONNECTION_MODE:
01034               strcpy (s->proc_type, "LOCAL");
01035               break;
01036 
01037             case CMS_FORCE_REMOTE_CONNECTION_MODE:
01038               strcpy (s->proc_type, "REMOTE");
01039               break;
01040             }
01041           s->procline_found = 1;
01042           s->procline_number = line_number;
01043           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01044                            "cms_config found process line on line %d\n",
01045                            line_number);
01046         }
01047 
01048       if (s->procline_found && s->bufline_found)
01049         {
01050           /* Close the configuration file. */
01051           if (NULL != fp)
01052             {
01053 #ifdef CMS_USE_INET_FILES
01054               inet_file_close (fp);
01055 #else
01056               fclose (fp);
01057 #endif
01058               fp = NULL;
01059             }
01060           loading_config_file = 0;
01061           s->error_type = CONFIG_SEARCH_OK;
01062           return;
01063         }
01064     }
01065 
01066   /* Close the configuration file. */
01067   if (NULL != fp)
01068     {
01069 #ifdef CMS_USE_INET_FILES
01070       inet_file_close (fp);
01071 #else
01072       fclose (fp);
01073 #endif
01074       fp = NULL;
01075     }
01076   loading_config_file = 0;
01077 
01078   /* Missing either procname or bufname or both. */
01079   if (!s->bufline_found)
01080     {
01081       s->error_type = NO_BUFFER_LINE;
01082       return;
01083     }
01084   if (!s->procline_found)
01085     {
01086       s->error_type = NO_PROCESS_LINE;
01087       return;
01088     }
01089   return;
01090 }

int cms_config CMS **    c,
char *    b,
char *    p,
char *    f,
int    set_to_server = 0,
int    set_to_master = 0
 

Definition at line 628 of file cms_cfg.cc.

00630 {
00631   char *word[4];                /* array of pointers to words from line */
00632   CONFIG_SEARCH_STRUCT search;
00633   char buf[CMS_CONFIG_LINELEN];
00634   char buf2[CMS_CONFIG_LINELEN];
00635   char *default_ptr = 0;
00636 
00637   if (0 == bufname || 0 == procname || 0 == filename)
00638     {
00639       return -1;
00640     }
00641   rcs_print_debug (PRINT_CMS_CONFIG_INFO, "cms_config arguments:\n");
00642   rcs_print_debug (PRINT_CMS_CONFIG_INFO, "bufname = %s\n", bufname);
00643   rcs_print_debug (PRINT_CMS_CONFIG_INFO, "procname = %s\n", procname);
00644   rcs_print_debug (PRINT_CMS_CONFIG_INFO, "filename = %s\n", filename);
00645 
00646   search.error_type = CONFIG_SEARCH_ERROR_NOT_SET;
00647   search.bufline_found = 0;
00648   search.bufline_number = -1;
00649   search.procline_found = 0;
00650   search.procline_number = -1;
00651   search.bufname = bufname;
00652   search.bufname_for_procline = bufname;
00653   search.procname = procname;
00654   search.filename = filename;
00655   find_proc_and_buffer_lines (&search);
00656   if (NO_PROCESS_LINE == search.error_type)
00657     {
00658       search.bufname_for_procline = "default";
00659       find_proc_and_buffer_lines (&search);
00660       if (search.error_type == CONFIG_SEARCH_OK)
00661         {
00662           default_ptr = 0;
00663           strncpy (buf, search.proc_line, CMS_CONFIG_LINELEN);
00664           default_ptr = strstr (buf, "default");
00665           if (default_ptr)
00666             {
00667               strcpy (buf2, default_ptr + 7);
00668               strcpy (default_ptr, bufname);
00669               default_ptr += strlen (bufname);
00670               strcpy (default_ptr, buf2);
00671               strncpy (search.proc_line, buf, CMS_CONFIG_LINELEN);
00672             }
00673           strcat (search.proc_line, " defaultbuf");
00674         }
00675     }
00676   if (NO_PROCESS_LINE == search.error_type)
00677     {
00678       search.bufname_for_procline = "default";
00679       search.procname = "default";
00680       find_proc_and_buffer_lines (&search);
00681       if (search.error_type == CONFIG_SEARCH_OK)
00682         {
00683           strncpy (buf, search.proc_line, CMS_CONFIG_LINELEN);
00684           default_ptr = strstr (buf, "default");
00685           if (default_ptr)
00686             {
00687               strcpy (buf2, default_ptr + 7);
00688               strcpy (default_ptr, procname);
00689               default_ptr += strlen (procname);
00690               strcpy (default_ptr, buf2);
00691               default_ptr = strstr (buf, "default");
00692             }
00693           if (default_ptr)
00694             {
00695               strcpy (buf2, default_ptr + 7);
00696               strcpy (default_ptr, bufname);
00697               default_ptr += strlen (bufname);
00698               strcpy (default_ptr, buf2);
00699               strncpy (search.proc_line, buf, CMS_CONFIG_LINELEN);
00700             }
00701           strcat (search.proc_line, " defaultproc defaultbuf");
00702         }
00703     }
00704   if (CONFIG_SEARCH_OK == search.error_type)
00705     {
00706       return (cms_create (cms, search.buffer_line, search.proc_line,
00707                           search.buffer_type, search.proc_type,
00708                           set_to_server, set_to_master));
00709     }
00710   switch (search.error_type)
00711     {
00712     case NO_BUFFER_LINE:
00713       rcs_print_error
00714         ("No buffer-line entry found for buffer %s in config file %s.\n",
00715          bufname, filename);
00716       break;
00717 
00718     case NO_PROCESS_LINE:
00719       rcs_print_error
00720         ("No process-line entry found for process %s connecting to buffer %s in config file %s and no applicable defaults were found.\n",
00721          procname, bufname, filename);
00722       break;
00723 
00724     default:
00725       break;
00726     }
00727 
00728 
00729   return (-1);
00730 }

int hostname_matches_bufferline char *    bufline
 

Definition at line 733 of file cms_cfg.cc.

00734 {
00735   char my_hostname[256];
00736 #ifndef VXWORKS
00737   struct hostent *my_hostent_ptr = 0;
00738   struct hostent *buffer_hostent_ptr = 0;
00739   struct hostent my_hostent;
00740 #endif
00741   char my_hostent_addresses[16][16];
00742   int num_my_hostent_addresses = 0;
00743   struct in_addr myaddress;
00744   int j, k;
00745   char *buffer_host = 0;
00746   char *word[4];                /* array of pointers to words from line */
00747 
00748   if (0 == bufline)
00749     {
00750       return 0;
00751     }
00752 
00753   /* Separate out the first four strings in the line. */
00754   if (separate_words (word, 4, bufline) != 4)
00755     {
00756       return 0;
00757     }
00758   buffer_host = word[3];
00759   if (buffer_host == 0)
00760     {
00761       return 0;
00762     }
00763 
00764   if (!strncmp (buffer_host, "localhost", 9))
00765     {
00766       return 1;
00767     }
00768   dl_gethostname (my_hostname, 256);
00769   if (!strcmp (buffer_host, my_hostname))
00770     {
00771       return 1;
00772     }
00773 
00774 #ifdef VXWORKS
00775   if (hostGetByName (my_hostname) == hostGetByName (buffer_host))
00776     {
00777       return 1;
00778     }
00779   if (hostGetByName (my_hostname) == dl_inet_aton (buffer_host))
00780     {
00781       return 1;
00782     }
00783 #else
00784   dl_gethostbyname (my_hostname, &my_hostent_ptr);
00785   if (0 == my_hostent_ptr)
00786     {
00787       return 0;
00788     }
00789   myaddress.s_addr = *((int *) my_hostent_ptr->h_addr_list[0]);
00790   if (!strcmp (buffer_host, dl_inet_ntoa (myaddress)))
00791     {
00792       return 1;
00793     }
00794   if (my_hostent_ptr->h_length < 1 || my_hostent_ptr->h_length > 16)
00795     {
00796       rcs_print_error ("Bad hostentry length.\n");
00797       return 0;
00798     }
00799   /* We need to make a copy of my_hostent and all its addresses in case they 
00800      are clobbered when we try to get the hostentry for buffer_host */
00801   my_hostent = *my_hostent_ptr;
00802   memset (my_hostent_addresses, 0, 256);
00803   for (j = 0; j < 16 && 0 != my_hostent.h_addr_list[j]; j++)
00804     {
00805       memcpy (my_hostent_addresses[j], my_hostent.h_addr_list[j],
00806               my_hostent.h_length);
00807     }
00808   num_my_hostent_addresses = j;
00809   if (num_my_hostent_addresses < 1)
00810     {
00811       return 0;
00812     }
00813   dl_gethostbyname (buffer_host, &buffer_hostent_ptr);
00814   if (0 == buffer_hostent_ptr)
00815     {
00816       return 0;
00817     }
00818   j = 0;
00819   k = 0;
00820   if (buffer_hostent_ptr->h_length != my_hostent.h_length)
00821     {
00822       rcs_print_error ("Mismatched hostentry lengths.\n");
00823       return 0;
00824     }
00825   while (j < num_my_hostent_addresses && j < 16)
00826     {
00827       k = 0;
00828       while (buffer_hostent_ptr->h_addr_list[k] != 0 && k < 16)
00829         {
00830           if (!memcmp
00831               (my_hostent_addresses[j], buffer_hostent_ptr->h_addr_list[k],
00832                my_hostent.h_length))
00833             {
00834               return 1;
00835             }
00836           k++;
00837         }
00838       j++;
00839     }
00840 #endif
00841 
00842   return 0;
00843 }

int cms_create_from_lines CMS **    cms,
char *    buffer_line,
char *    proc_line,
int    set_to_server = 0,
int    set_to_master = 0
 

Definition at line 1094 of file cms_cfg.cc.

01096 {
01097   char proc_type[CMS_CONFIG_LINELEN];
01098   char buffer_type[CMS_CONFIG_LINELEN];
01099   char *word[4];                /* array of pointers to words from line */
01100 
01101   if (4 != separate_words (word, 4, proc_line))
01102     {
01103       rcs_print_error ("cms_config: invalid proc_line=(%s)\n", proc_line);
01104       return -1;
01105     }
01106 
01107   convert2upper (proc_type, word[3], CMS_CONFIG_LINELEN);
01108 
01109   if (4 != separate_words (word, 4, buffer_line))
01110     {
01111       rcs_print_error ("cms_config: invalid buffer_line=(%s)\n", buffer_line);
01112       return -1;
01113     }
01114 
01115   convert2upper (buffer_type, word[2], CMS_CONFIG_LINELEN);
01116 
01117   return (cms_create (cms, buffer_line, proc_line,
01118                       buffer_type, proc_type, set_to_server, set_to_master));
01119 }

int cms_create CMS **    cms,
char *    buf_line,
char *    proc_line,
char *    buffer_type,
char *    proc_type,
int    set_to_server = 0,
int    set_to_master = 0
 

Definition at line 1122 of file cms_cfg.cc.

01125 {
01126   if (NULL == cms || NULL == buffer_line || NULL == proc_line ||
01127       NULL == buffer_type || NULL == proc_type)
01128     {
01129       rcs_print_error ("cms_create passed NULL argument.\n");
01130       return -1;
01131     }
01132 
01133   /* Both lines have been found, select the appropriate class from */
01134   /* CMS's derived classes and call its constructor. */
01135   if (!strcmp (buffer_type, "PHANTOM") || !strcmp (proc_type, "PHANTOM"))
01136     {
01137       *cms = new PHANTOMMEM (buffer_line, proc_line);
01138       rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new PHANTOMEM(%s,%s)\n",
01139                        *cms, buffer_line, proc_line);
01140       if (NULL == *cms)
01141         {
01142           if (verbose_nml_error_messages)
01143             {
01144               rcs_print_error
01145                 ("cms_config: Can't create PHANTOMMEM object.\n");
01146             }
01147           return (-1);
01148         }
01149       else
01150         {
01151           return (0);
01152         }
01153     }
01154   if (!strcmp (proc_type, "REMOTE"))
01155     {
01156       if (NULL != strstr (proc_line, "serialPortDevName="))
01157         {
01158 #if !defined(VXWORKS) && (!defined(__MSDOS__) || defined(WIN32)) && !defined(UNDER_CE) && !defined(DARWIN) && !defined(qnx)
01159           *cms = new TTYMEM (buffer_line, proc_line);
01160           rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new TTYMEM(%s,%s)\n",
01161                            *cms, buffer_line, proc_line);
01162           if (NULL == *cms)
01163             {
01164               if (verbose_nml_error_messages)
01165                 {
01166                   rcs_print_error
01167                     ("cms_config: Can't create new TTYMEM object.\n");
01168                 }
01169               return (-1);
01170             }
01171           else if ((*cms)->status < 0)
01172             {
01173               if (verbose_nml_error_messages)
01174                 {
01175                   rcs_print_error
01176                     ("cms_config: Error  %d(%s) occured during TTYMEM create.\n",
01177                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01178                 }
01179               return (-1);
01180             }
01181 #else
01182           rcs_print_error ("TTYMEM not supported on this platform.\n");
01183           return (-1);
01184 #endif
01185         }
01186       else if (NULL != strstr (buffer_line, "STCP="))
01187         {
01188 #ifndef UNDER_CE
01189           *cms = new STCPMEM (buffer_line, proc_line);
01190           rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new STCPMEM(%s,%s)\n",
01191                            *cms, buffer_line, proc_line);
01192           if (NULL == *cms)
01193             {
01194               if (verbose_nml_error_messages)
01195                 {
01196                   rcs_print_error
01197                     ("cms_config: Can't create new STPCMEM object.\n");
01198                 }
01199               return (-1);
01200             }
01201           else if ((*cms)->status < 0)
01202             {
01203               if (verbose_nml_error_messages)
01204                 {
01205                   rcs_print_error
01206                     ("cms_config: Error  %d(%s) occured during STPCMEM create.\n",
01207                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01208                 }
01209               return (-1);
01210             }
01211 #else
01212           rcs_print_error ("STCPMEM not supported in Windows CE.\n");
01213           return (-1);
01214 #endif
01215         }
01216       else if (NULL != strstr (buffer_line, "TCP="))
01217         {
01218           *cms = new TCPMEM (buffer_line, proc_line);
01219           rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new TCPMEM(%s,%s)\n",
01220                            *cms, buffer_line, proc_line);
01221           if (NULL == *cms)
01222             {
01223               if (verbose_nml_error_messages)
01224                 {
01225                   rcs_print_error
01226                     ("cms_config: Can't create new TPCMEM object.\n");
01227                 }
01228               return (-1);
01229             }
01230           else if ((*cms)->status < 0)
01231             {
01232               if (verbose_nml_error_messages)
01233                 {
01234                   rcs_print_error
01235                     ("cms_config: Error  %d(%s) occured during TPCMEM create.\n",
01236                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01237                 }
01238               return (-1);
01239             }
01240         }
01241       else if (NULL != strstr (buffer_line, "UDP="))
01242         {
01243           *cms = new UDPMEM (buffer_line, proc_line);
01244           rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new UDPMEM(%s,%s)\n",
01245                            *cms, buffer_line, proc_line);
01246           if (NULL == *cms)
01247             {
01248               if (verbose_nml_error_messages)
01249                 {
01250                   rcs_print_error
01251                     ("cms_config: Can't create new UDPMEM object.\n");
01252                 }
01253               return (-1);
01254             }
01255           else if ((*cms)->status < 0)
01256             {
01257               if (verbose_nml_error_messages)
01258                 {
01259                   rcs_print_error
01260                     ("cms_config: Error %d(%s) occured during UDPMEM create.\n",
01261                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01262                 }
01263               return (-1);
01264             }
01265           return (0);
01266         }
01267       else
01268         {
01269 #ifndef NO_DCE_RPC
01270           *cms = new RPCMEM (buffer_line, proc_line);
01271           rcs_print_debug (PRINT_CMS_CONFIG_INFO, "%X = new RPCMEM(%s,%s)\n",
01272                            *cms, buffer_line, proc_line);
01273           if (NULL == *cms)
01274             {
01275               if (verbose_nml_error_messages)
01276                 {
01277                   rcs_print_error
01278                     ("cms_config: Can't create new RPCMEM object.\n");
01279                 }
01280               return (-1);
01281             }
01282           else if ((*cms)->status < 0)
01283             {
01284               if (verbose_nml_error_messages)
01285                 {
01286                   rcs_print_error
01287                     ("cms_config: %d: %s Error occured during RPCMEM create.\n",
01288                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01289                 }
01290               return (-1);
01291             }
01292 #else
01293           rcs_print_error ("No remote connection configured.\n");
01294           return (-1);
01295 #endif
01296         }
01297     }
01298   else if (!strcmp (proc_type, "LOCAL"))
01299     {
01300 #if defined(VXWORKS) || defined(USE_BIT3) || defined(LINUX_VME)
01301       if (!strcmp (buffer_type, "GLOBMEM"))
01302         {
01303           *cms = new GLOBMEM (buffer_line, proc_line, set_to_server,
01304                               set_to_master);
01305           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01306                            "%X = new GLOBMEM(%s,%s,%d,%d)\n", *cms,
01307                            buffer_line, proc_line, set_to_server,
01308                            set_to_master);
01309           if (NULL == *cms)
01310             {
01311               if (verbose_nml_error_messages)
01312                 {
01313                   rcs_print_error
01314                     ("cms_config: Can't create new GLOBMEM object.\n");
01315                 }
01316               return (-1);
01317             }
01318           else if ((*cms)->status < 0)
01319             {
01320               if (verbose_nml_error_messages)
01321                 {
01322                   rcs_print_error
01323                     ("cms_config: %d(%s) Error occured during GLOBMEM create.\n",
01324                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01325                 }
01326               return (-1);
01327             }
01328           else
01329             {
01330               return (0);
01331             }
01332         }
01333 #endif
01334 #ifdef VXWORKS
01335       if (!strcmp (buffer_type, "BBDMEM"))
01336         {
01337           *cms = new BBDMEM (buffer_line, proc_line, set_to_server,
01338                              set_to_master);
01339           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01340                            "%X = new BBDMEM(%s,%s,%d,%d)\n", *cms,
01341                            buffer_line, proc_line, set_to_server,
01342                            set_to_master);
01343           if (NULL == *cms)
01344             {
01345               if (verbose_nml_error_messages)
01346                 {
01347                   rcs_print_error
01348                     ("cms_config: Can't create new BBDMEM object.\n");
01349                 }
01350               return (-1);
01351             }
01352           else if ((*cms)->status < 0)
01353             {
01354               if (verbose_nml_error_messages)
01355                 {
01356                   rcs_print_error
01357                     ("cms_config: %d(%s) Error occured during BBDMEM create.\n",
01358                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01359                 }
01360               return (-1);
01361             }
01362           else
01363             {
01364               return (0);
01365             }
01366         }
01367 #endif
01368 #if !defined(__MSDOS__) || defined(WIN32)
01369       if (!strcmp (buffer_type, "SHMEM"))
01370         {
01371           *cms = new SHMEM (buffer_line, proc_line, set_to_server,
01372                             set_to_master);
01373           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01374                            "%X = new SHMEM(%s,%s,%d,%d)\n", *cms, buffer_line,
01375                            proc_line, set_to_server, set_to_master);
01376           if (NULL == *cms)
01377             {
01378               if (verbose_nml_error_messages)
01379                 {
01380                   rcs_print_error
01381                     ("cms_config: Can't create new SHMEM object.\n");
01382                 }
01383               return (-1);
01384             }
01385           else if ((*cms)->status < 0)
01386             {
01387               if (verbose_nml_error_messages)
01388                 {
01389                   rcs_print_error
01390                     ("cms_config: %d(%s) Error occured during SHMEM create.\n",
01391                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01392                 }
01393               return (-1);
01394             }
01395           else
01396             {
01397               return (0);
01398             }
01399         }
01400 #endif /* !__MSDOS__ */
01401 #ifdef LINUX
01402 #if defined(HAVE_RTL) || defined(linux_rtai)
01403 #ifndef linux_2_0_36
01404       if (!strcmp (buffer_type, "RTLMEM"))
01405         {
01406           *cms = new RTLMEM (buffer_line, proc_line, set_to_server,
01407                              set_to_master);
01408           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01409                            "%X = new RTLMEM(%s,%s,%d,%d)\n", *cms,
01410                            buffer_line, proc_line, set_to_server,
01411                            set_to_master);
01412           if (NULL == *cms)
01413             {
01414               if (verbose_nml_error_messages)
01415                 {
01416                   rcs_print_error
01417                     ("cms_config: Can't create new RTLMEM object.\n");
01418                 }
01419               return (-1);
01420             }
01421           else if ((*cms)->status < 0)
01422             {
01423               if (verbose_nml_error_messages)
01424                 {
01425                   rcs_print_error
01426                     ("cms_config: %d(%s) Error occured during RTLMEM create.\n",
01427                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01428                 }
01429               return (-1);
01430             }
01431           else
01432             {
01433               return (0);
01434             }
01435         }
01436 #endif
01437 #endif
01438 #endif
01439       if (!strcmp (buffer_type, "LOCMEM"))
01440         {
01441           *cms =
01442             new LOCMEM (buffer_line, proc_line, set_to_server, set_to_master);
01443           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01444                            "%X = new LOCMEM(%s,%s,%d,%d)\n", *cms,
01445                            buffer_line, proc_line, set_to_server,
01446                            set_to_master);
01447           if (NULL == *cms)
01448             {
01449               if (verbose_nml_error_messages)
01450                 {
01451                   rcs_print_error
01452                     ("cms_config: Can't create new LOCMEM object.\n");
01453                 }
01454               return (-1);
01455             }
01456           if ((*cms)->status < 0)
01457             {
01458               if (verbose_nml_error_messages)
01459                 {
01460                   rcs_print_error
01461                     ("cms_config: %d(%s) Error occured during LOCMEM create.\n",
01462                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01463                 }
01464               return (-1);
01465             }
01466           return (0);
01467         }
01468 #if 0
01469       if (!strcmp (buffer_type, "FILEMEM"))
01470         {
01471           *cms =
01472             new FILEMEM (buffer_line, proc_line, set_to_server,
01473                          set_to_master);
01474           rcs_print_debug (PRINT_CMS_CONFIG_INFO,
01475                            "%X = new FILMEM(%s,%s,%d,%d)\n", *cms,
01476                            buffer_line, proc_line, set_to_server,
01477                            set_to_master);
01478           if (NULL == *cms)
01479             {
01480               if (verbose_nml_error_messages)
01481                 {
01482                   rcs_print_error
01483                     ("cms_config: Can't create new FILEMEM object.\n");
01484                 }
01485               return (-1);
01486             }
01487           if ((*cms)->status < 0)
01488             {
01489               if (verbose_nml_error_messages)
01490                 {
01491                   rcs_print_error
01492                     ("cms_config: %d(%s) Error occured during FILEMEM create.\n",
01493                      (*cms)->status, (*cms)->status_string ((*cms)->status));
01494                 }
01495               return (-1);
01496             }
01497           return (0);
01498         }
01499 #endif
01500       rcs_print_error ("cms_config: invalid buffer_type (%s)\n", buffer_type);
01501       rcs_print_error ("cms_config: buffer_line = (%s)\n", buffer_line);
01502       return (-1);
01503     }
01504   else
01505     {
01506       rcs_print_error ("cms_config: invalid proc_type (%s)\n", proc_type);
01507       rcs_print_error ("cms_config: proc_line = (%s)\n", proc_line);
01508       return (-1);
01509     }
01510   return (0);
01511 }


Variable Documentation

int verbose_nml_error_messages
 

Definition at line 20 of file cms_cfg.cc.

RCS_LINKED_LIST* config_file_list = NULL [static]
 

Definition at line 118 of file cms_cfg.cc.

int loading_config_file = 0 [static]
 

Definition at line 119 of file cms_cfg.cc.


Generated on Sun Dec 2 15:57:00 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001