📄 cms_cfg.cc
字号:
default_ptr += strlen(bufname); strcpy(default_ptr, buf2); strncpy(search.proc_line, buf, CMS_CONFIG_LINELEN); } strcat(search.proc_line, " defaultproc defaultbuf"); } } if (CONFIG_SEARCH_OK == search.error_type) { return (cms_create(cms, search.buffer_line, search.proc_line, search.buffer_type, search.proc_type, set_to_server, set_to_master)); } switch (search.error_type) { case NO_BUFFER_LINE: rcs_print_error ("No buffer-line entry found for buffer %s in config file %s.\n", bufname, filename); break; case NO_PROCESS_LINE: rcs_print_error ("No process-line entry found for process %s connecting to buffer %s in config file %s and no applicable defaults were found.\n", procname, bufname, filename); break; default: break; } return (-1);}int hostname_matches_bufferline(char *bufline){ char my_hostname[256]; struct hostent *my_hostent_ptr = 0; struct hostent *buffer_hostent_ptr = 0; struct hostent my_hostent; char my_hostent_addresses[16][16]; int num_my_hostent_addresses = 0; struct in_addr myaddress; int j, k; char *buffer_host = 0; char *word[4]; /* array of pointers to words from line */ if (0 == bufline) { return 0; } /* Separate out the first four strings in the line. */ if (separate_words(word, 4, bufline) != 4) { return 0; } buffer_host = word[3]; if (buffer_host == 0) { return 0; } if (!strncmp(buffer_host, "localhost", 9)) { return 1; } gethostname(my_hostname, 256); if (!strcmp(buffer_host, my_hostname)) { return 1; } my_hostent_ptr = gethostbyname(my_hostname); if (0 == my_hostent_ptr) { return 0; } myaddress.s_addr = *((int *) my_hostent_ptr->h_addr_list[0]); if (!strcmp(buffer_host, inet_ntoa(myaddress))) { return 1; } if (my_hostent_ptr->h_length < 1 || my_hostent_ptr->h_length > 16) { rcs_print_error("Bad hostentry length.\n"); return 0; } /* We need to make a copy of my_hostent and all its addresses in case they are clobbered when we try to get the hostentry for buffer_host */ my_hostent = *my_hostent_ptr; memset(my_hostent_addresses, 0, 256); for (j = 0; j < 16 && 0 != my_hostent.h_addr_list[j]; j++) { memcpy(my_hostent_addresses[j], my_hostent.h_addr_list[j], my_hostent.h_length); } num_my_hostent_addresses = j; if (num_my_hostent_addresses < 1) { return 0; } buffer_hostent_ptr = gethostbyname(buffer_host); if (0 == buffer_hostent_ptr) { return 0; } j = 0; k = 0; if (buffer_hostent_ptr->h_length != my_hostent.h_length) { rcs_print_error("Mismatched hostentry lengths.\n"); return 0; } while (j < num_my_hostent_addresses && j < 16) { k = 0; while (buffer_hostent_ptr->h_addr_list[k] != 0 && k < 16) { if (!memcmp (my_hostent_addresses[j], buffer_hostent_ptr->h_addr_list[k], my_hostent.h_length)) { return 1; } k++; } j++; } return 0;}void find_proc_and_buffer_lines(CONFIG_SEARCH_STRUCT * s){ if (s == 0) { return; } loading_config_file = 1; FILE *fp = NULL; /* FILE ptr to config file. */ char linebuf[CMS_CONFIG_LINELEN]; /* Temporary buffer for line from file. */ char *line = linebuf; int line_len, line_number; char *word[4]; /* array of pointers to words from line */ int first_line = 1; /* Open the configuration file. */ LinkedList *lines_list = NULL; CONFIG_FILE_INFO *info = get_loaded_nml_config_file(s->filename); if (NULL != info) { lines_list = info->lines_list; line = (char *) lines_list->get_head(); } if (NULL == lines_list) { fp = fopen(s->filename, "r"); if (fp == NULL) { rcs_print_error("cms_config: can't open '%s'. Error = %d -- %s\n", s->filename, errno, strerror(errno)); loading_config_file = 0; s->error_type = BAD_CONFIG_FILE; return; } } /* Read the configuration file line by line until the lines matching */ /* bufname and procname are found. */ line_number = 0; while (1) { if (NULL != lines_list) { if (!first_line) { line = (char *) lines_list->get_next(); } first_line = 0; if (NULL == line) { break; } } else { if (feof(fp)) { break; } if ((fgets(line, CMS_CONFIG_LINELEN, fp)) == NULL) { break; } } line_number++; line_len = strlen(line); if (line_len < 3) { continue; } while (line[line_len - 1] == '\\') { int pos = line_len - 2; if ((fgets(line + pos, CMS_CONFIG_LINELEN - pos, fp)) == NULL) { break; } line_len = strlen(line); if (line_len > CMS_CONFIG_LINELEN) { break; } line_number++; } if (line_len > CMS_CONFIG_LINELEN) { rcs_print_error ("cms_cfg: Line length of line number %d in %s exceeds max length of %d", line_number, s->filename, CMS_CONFIG_LINELEN); } /* Skip comment lines and lines starting with white space. */ if (line[0] == CMS_CONFIG_COMMENTCHAR || strchr(" \t\n\r\0", line[0]) != NULL) { continue; } /* Separate out the first four strings in the line. */ if (separate_words(word, 4, line) != 4) { continue; } if (!s->bufline_found && !strcmp(word[1], s->bufname) && line[0] == 'B') { /* Buffer line found, store the line and type. */ strncpy(s->buffer_line, line, CMS_CONFIG_LINELEN); convert2upper(s->buffer_type, word[2], CMS_CONFIG_LINELEN); s->bufline_found = 1; s->bufline_number = line_number; rcs_print_debug(PRINT_CMS_CONFIG_INFO, "cms_config found buffer line on line %d\n", line_number); } else if (!s->procline_found && !strcmp(word[1], s->procname) && line[0] == 'P' && !strcmp(word[2], s->bufname_for_procline)) { /* Procedure line found, store the line and type. */ strncpy(s->proc_line, line, CMS_CONFIG_LINELEN); switch (cms_connection_mode) { case CMS_NORMAL_CONNECTION_MODE: convert2upper(s->proc_type, word[3], CMS_CONFIG_LINELEN); if (!strncmp(s->proc_type, "AUTO", 4)) { if (!s->bufline_found) { rcs_print_error ("Can't use process type AUTO unless the buffer line for %s is found earlier in the config file.\n", s->bufname); rcs_print_error("Bad line:\n%s:%d %s\n", s->filename, line_number, line); s->error_type = MISC_CONFIG_SEARCH_ERROR; return; } if (hostname_matches_bufferline(s->buffer_line)) { strcpy(s->proc_type, "LOCAL"); } else { strcpy(s->proc_type, "REMOTE"); } } break; case CMS_FORCE_LOCAL_CONNECTION_MODE: strcpy(s->proc_type, "LOCAL"); break; case CMS_FORCE_REMOTE_CONNECTION_MODE: strcpy(s->proc_type, "REMOTE"); break; } s->procline_found = 1; s->procline_number = line_number; rcs_print_debug(PRINT_CMS_CONFIG_INFO, "cms_config found process line on line %d\n", line_number); } if (s->procline_found && s->bufline_found) { /* Close the configuration file. */ if (NULL != fp) { fclose(fp); fp = NULL; } loading_config_file = 0; s->error_type = CONFIG_SEARCH_OK; return; } } /* Close the configuration file. */ if (NULL != fp) { fclose(fp); fp = NULL; } loading_config_file = 0; /* Missing either procname or bufname or both. */ if (!s->bufline_found) { s->error_type = NO_BUFFER_LINE; return; } if (!s->procline_found) { s->error_type = NO_PROCESS_LINE; return; } return;}intcms_create_from_lines(CMS ** cms, char *buffer_line, char *proc_line, int set_to_server, int set_to_master){ char proc_type[CMS_CONFIG_LINELEN]; char buffer_type[CMS_CONFIG_LINELEN]; char *word[4]; /* array of pointers to words from line */ if (4 != separate_words(word, 4, proc_line)) { rcs_print_error("cms_config: invalid proc_line=(%s)\n", proc_line); return -1; } convert2upper(proc_type, word[3], CMS_CONFIG_LINELEN); if (4 != separate_words(word, 4, buffer_line)) { rcs_print_error("cms_config: invalid buffer_line=(%s)\n", buffer_line); return -1; } convert2upper(buffer_type, word[2], CMS_CONFIG_LINELEN); return (cms_create(cms, buffer_line, proc_line, buffer_type, proc_type, set_to_server, 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){ if (NULL == cms || NULL == buffer_line || NULL == proc_line || NULL == buffer_type || NULL == proc_type) { rcs_print_error("cms_create passed NULL argument.\n"); return -1; } /* Both lines have been found, select the appropriate class from */ /* CMS's derived classes and call its constructor. */ if (!strcmp(buffer_type, "PHANTOM") || !strcmp(proc_type, "PHANTOM")) { *cms = new PHANTOMMEM(buffer_line, proc_line); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new PHANTOMEM(%s,%s)\n", *cms, buffer_line, proc_line); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create PHANTOMMEM object.\n"); } return (-1); } else { return (0); } } if (!strcmp(proc_type, "REMOTE")) { if (NULL != strstr(proc_line, "serialPortDevName=")) {/*! \todo Another #if 0 */#if 0 *cms = new TTYMEM(buffer_line, proc_line); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new TTYMEM(%s,%s)\n", *cms, buffer_line, proc_line); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create new TTYMEM object.\n"); } return (-1); } else if ((*cms)->status < 0) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Error %d(%s) occured during TTYMEM create.\n", (*cms)->status, (*cms)->status_string((*cms)->status)); } return (-1); }#else rcs_print_error("TTYMEM not supported on this platform.\n"); return (-1);#endif } else if (NULL != strstr(buffer_line, "STCP=")) {/*! \todo Another #if 0 */#if 0 *cms = new STCPMEM(buffer_line, proc_line); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new STCPMEM(%s,%s)\n", *cms, buffer_line, proc_line); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create new STPCMEM object.\n"); } return (-1); } else if ((*cms)->status < 0) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Error %d(%s) occured during STPCMEM create.\n", (*cms)->status, (*cms)->status_string((*cms)->status)); } return (-1); }#endif } else if (NULL != strstr(buffer_line, "TCP=")) { *cms = new TCPMEM(buffer_line, proc_line); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new TCPMEM(%s,%s)\n", *cms, buffer_line, proc_line); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create new TPCMEM object.\n"); } return (-1); } else if ((*cms)->status < 0) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Error %d(%s) occured during TPCMEM create.\n", (*cms)->status, (*cms)->status_string((*cms)->status)); } return (-1); } } else if (NULL != strstr(buffer_line, "UDP=")) { rcs_print_error("UPDMEM not supported.\n"); return (-1); } else { rcs_print_error("No remote connection configured.\n"); return (-1); } } else if (!strcmp(proc_type, "LOCAL")) { if (!strcmp(buffer_type, "SHMEM")) { *cms = new SHMEM(buffer_line, proc_line, set_to_server, set_to_master); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new SHMEM(%s,%s,%d,%d)\n", *cms, buffer_line, proc_line, set_to_server, set_to_master); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create new SHMEM object.\n"); } return (-1); } else if ((*cms)->status < 0) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: %d(%s) Error occured during SHMEM create.\n", (*cms)->status, (*cms)->status_string((*cms)->status)); } return (-1); } else { return (0); } } if (!strcmp(buffer_type, "RTLMEM")) { rcs_print_error("RTLMEM not supported.\n"); return (-1); } if (!strcmp(buffer_type, "LOCMEM")) { *cms = new LOCMEM(buffer_line, proc_line, set_to_server, set_to_master); rcs_print_debug(PRINT_CMS_CONFIG_INFO, "%X = new LOCMEM(%s,%s,%d,%d)\n", *cms, buffer_line, proc_line, set_to_server, set_to_master); if (NULL == *cms) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: Can't create new LOCMEM object.\n"); } return (-1); } if ((*cms)->status < 0) { if (verbose_nml_error_messages) { rcs_print_error ("cms_config: %d(%s) Error occured during LOCMEM create.\n", (*cms)->status, (*cms)->status_string((*cms)->status)); } return (-1); } return (0); } rcs_print_error("cms_config: invalid buffer_type (%s)\n", buffer_type); rcs_print_error("cms_config: buffer_line = (%s)\n", buffer_line); return (-1); } else { rcs_print_error("cms_config: invalid proc_type (%s)\n", proc_type); rcs_print_error("cms_config: proc_line = (%s)\n", proc_line); return (-1); } return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -