00001
00002 static char program_id[] = __FILE__ "version 1.2 compiled on" __DATE__;
00003
00004 #include "cms_cfg.hh"
00005 #include "nml.hh"
00006 #include "nmlmsg.hh"
00007 #include "cms.hh"
00008 #include "linklist.hh"
00009 #include "rcs_prnt.hh"
00010
00011 extern "C"
00012 {
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 }
00017
00018 enum LOCAL_CONNECT
00019 {
00020 LC_NOT_ATTEMPTED = 0,
00021 LC_FAILED,
00022 LC_SUCCEEDED,
00023 };
00024
00025 char LC_ARRAY[3][3] = { "NA", "F", "S" };
00026
00027 enum REMOTE_CONNECT
00028 {
00029 RC_NOT_ATTEMPTED = 0,
00030 RC_FAILED,
00031 RC_SUCCEEDED,
00032 };
00033
00034 char RC_ARRAY[3][3] = { "NA", "F", "S" };
00035
00036 #ifdef VXWORKS
00037 extern "C" void nmlclean (char *config_file, char *host_name);
00038
00039 void
00040 nmltest (char *config_file, char *host_name)
00041 #else
00042 int
00043 main (int argc, char **argv)
00044 #endif
00045 {
00046 FILE *fp;
00047 LOCAL_CONNECT local_connect_status = LC_NOT_ATTEMPTED;
00048 REMOTE_CONNECT remote_connect_status = RC_NOT_ATTEMPTED;
00049 char proc_line[CMS_CONFIG_LINELEN];
00050 char line[CMS_CONFIG_LINELEN];
00051 int line_len, line_number = 0;
00052 char output_line[80];
00053 char buffer_name[CMS_CONFIG_LINELEN];
00054 char buffer_host[CMS_CONFIG_LINELEN];
00055 RCS_LINKED_LIST *output_list;
00056 puts (program_id);
00057
00058 output_list = new RCS_LINKED_LIST;
00059 if (NULL == output_list)
00060 {
00061 printf ("Couldn`t malloc output list.\n");
00062 exit (-1);
00063 }
00064
00065 set_rcs_print_destination (RCS_PRINT_TO_STDOUT);
00066 #ifndef VXWORKS
00067 char config_file[80];
00068 char host_name[80];
00069 if (argc > 2)
00070 {
00071
00072 strcpy (config_file, argv[1]);
00073 strcpy (host_name, argv[2]);
00074 }
00075 else
00076 {
00077
00078 printf ("Configuration File? ");
00079 gets (config_file);
00080
00081 printf ("Host Name? ");
00082 gets (host_name);
00083 }
00084 #endif
00085
00086
00087 if ((fp = fopen (config_file, "r")) == NULL)
00088 {
00089 rcs_print_error ("nmltest: can't open '%s'\n", config_file);
00090 exit (-1);
00091 }
00092
00093
00094
00095 while (!feof (fp))
00096 {
00097 NML *lc_nml = (NML *) NULL;
00098 NML *rc_nml = (NML *) NULL;
00099
00100 if ((fgets (line, CMS_CONFIG_LINELEN, fp)) == NULL)
00101 {
00102 break;
00103 }
00104
00105 line_number++;
00106 line_len = strlen (line);
00107 if (line_len > CMS_CONFIG_LINELEN)
00108 {
00109 rcs_print_error
00110 ("cms_cfg: Line length of line number %d in %s exceeds max length of %d",
00111 line_number, config_file, CMS_CONFIG_LINELEN);
00112 }
00113
00114 if (line_len > 1)
00115 {
00116 if (line[line_len - 2] == '\\')
00117 {
00118 if (
00119 (fgets
00120 (line + line_len - 2, CMS_CONFIG_LINELEN - line_len,
00121 fp)) == NULL)
00122 {
00123 break;
00124 }
00125 line_number++;
00126 }
00127 }
00128
00129 if (line[0] != 'B')
00130 {
00131 continue;
00132 }
00133
00134 sscanf (line + 1, "%s %*s %s", buffer_name, buffer_host);
00135
00136
00137
00138 if (!strcmp (buffer_host, host_name))
00139 {
00140 printf ("\nAttempting to connect to %s locally . . .\n",
00141 buffer_name);
00142 sprintf (proc_line, "P nmltest %s LOCAL %s R 0 5 0 0\n",
00143 buffer_name, buffer_host);
00144 lc_nml = new NML (line, proc_line);
00145 if (NULL != lc_nml)
00146 {
00147 lc_nml->ignore_format_chain = 1;
00148 if (NULL != lc_nml->cms)
00149 {
00150 lc_nml->cms->delete_totally = 1;
00151 delete lc_nml;
00152 lc_nml = (NML *) NULL;
00153 local_connect_status = LC_SUCCEEDED;
00154 }
00155 else
00156 {
00157 local_connect_status = LC_FAILED;
00158 }
00159 }
00160 else
00161 {
00162 local_connect_status = LC_FAILED;
00163 }
00164 }
00165 printf ("\nAttempting to connect to %s remotely . . .\n", buffer_name);
00166 sprintf (proc_line, "P nmltest %s REMOTE %s R 0 5 0 0\n",
00167 buffer_name, host_name);
00168 rc_nml = new NML (line, proc_line);
00169 if (NULL != rc_nml)
00170 {
00171 rc_nml->ignore_format_chain = 1;
00172 if (NULL != rc_nml->cms)
00173 {
00174 rc_nml->cms->delete_totally = 1;
00175 delete rc_nml;
00176 rc_nml = (NML *) NULL;
00177 remote_connect_status = RC_SUCCEEDED;
00178 }
00179 else
00180 {
00181 remote_connect_status = RC_FAILED;
00182 }
00183 }
00184 else
00185 {
00186 remote_connect_status = RC_FAILED;
00187 }
00188 sprintf (output_line, "%s\t%s\t%s",
00189 buffer_name,
00190 LC_ARRAY[local_connect_status],
00191 RC_ARRAY[remote_connect_status]);
00192 output_list->store_at_tail (output_line, strlen (output_line) + 1, 1);
00193 }
00194
00195
00196
00197 printf ("NMLCLEAN: terminology\n");
00198 printf
00199 ("LCS - Local Connect Status S(Success)|F(Fail)|NA(Not Attempted)\n");
00200 printf
00201 ("RCS - Remote Connect Status (What did you think RCS stood for?)\n");
00202 printf ("NMLTEST: Summary\n");
00203 printf ("BufferName\tLCS\tRCS\n");
00204
00205
00206
00207 if (NULL != output_list)
00208 {
00209 char *next_line;
00210 next_line = (char *) output_list->get_head ();
00211 while (NULL != next_line)
00212 {
00213 puts (next_line);
00214 next_line = (char *) output_list->get_next ();
00215 }
00216 delete output_list;
00217 }
00218
00219 }