int confload_toplevel(struct ConfParse *parse, void *data, const struct CF_Child *node) { struct Configuration *cfg = (struct Configuration *)data; if (node->token_count == 0) return 0; switch (lookup_name(node)) { case S_ACL: load_acl(cfg, parse, node); break; case S_INCLUDE: { struct CF_Token token = confparse_node_gettoken(parse, node, 1); char *filename; if (filename_is_absolute(token.name)) filename = filename_combine("", token.name); else filename = filename_combine(cfg->options.directory, token.name); token.name = filename; token.name_length = (unsigned)strlen(filename); confload_configuration(cfg, filename, &token); free(filename); } break; case S_KEY: conf_load_key(cfg, parse, node); break; case S_OPTIONS: load_options(cfg, parse, node); break; case S_ZONE: conf_load_zone(cfg, parse, node); break; default: //print_node(parse, stdout, node, 0); { struct CF_Token value = confparse_node_gettoken(parse, node, 0); CONF_OPTION_UNKNOWN(parse, &value); } break; } return 0; }
gmx_bool get_libdir(char *libdir) { #define GMX_BINNAME_MAX 512 char bin_name[GMX_BINNAME_MAX]; char buf[GMX_BINNAME_MAX]; char full_path[GMX_PATH_MAX+GMX_BINNAME_MAX]; char system_path[GMX_PATH_MAX]; char *dir,*ptr,*s,*pdum; gmx_bool found=FALSE; int i; if (Program() != NULL) { /* First - detect binary name */ if (strlen(Program()) >= GMX_BINNAME_MAX) { gmx_fatal(FARGS,"The name of the binary is longer than the allowed buffer size (%d):\n'%s'",GMX_BINNAME_MAX,Program()); } strncpy(bin_name,Program(),GMX_BINNAME_MAX-1); /* On windows & cygwin we need to add the .exe extension * too, or we wont be able to detect that the file exists */ #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __CYGWIN__ || defined __CYGWIN32__) if(strlen(bin_name)<3 || gmx_strncasecmp(bin_name+strlen(bin_name)-4,".exe",4)) strcat(bin_name,".exe"); #endif /* Only do the smart search part if we got a real name */ if (NULL!=bin_name && strncmp(bin_name,"GROMACS",GMX_BINNAME_MAX)) { if (!strchr(bin_name,DIR_SEPARATOR)) { /* No slash or backslash in name means it must be in the path - search it! */ /* Add the local dir since it is not in the path on windows */ #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__) pdum=_getcwd(system_path,sizeof(system_path)-1); #else pdum=getcwd(system_path,sizeof(system_path)-1); #endif sprintf(full_path,"%s%c%s",system_path,DIR_SEPARATOR,bin_name); found = gmx_fexist(full_path); if (!found && (s=getenv("PATH")) != NULL) { char *dupped; dupped=gmx_strdup(s); s=dupped; while(!found && (dir=gmx_strsep(&s, PATH_SEPARATOR)) != NULL) { sprintf(full_path,"%s%c%s",dir,DIR_SEPARATOR,bin_name); found = gmx_fexist(full_path); } sfree(dupped); } if (!found) { return FALSE; } } else if (!filename_is_absolute(bin_name)) { /* name contains directory separators, but * it does not start at the root, i.e. * name is relative to the current dir */ #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__) pdum=_getcwd(buf,sizeof(buf)-1); #else pdum=getcwd(buf,sizeof(buf)-1); #endif sprintf(full_path,"%s%c%s",buf,DIR_SEPARATOR,bin_name); } else { strncpy(full_path,bin_name,GMX_PATH_MAX); } /* Now we should have a full path and name in full_path, * but on unix it might be a link, or a link to a link to a link.. */ #if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64) while( (i=readlink(full_path,buf,sizeof(buf)-1)) > 0 ) { buf[i]='\0'; /* If it doesn't start with "/" it is relative */ if (buf[0]!=DIR_SEPARATOR) { strncpy(strrchr(full_path,DIR_SEPARATOR)+1,buf,GMX_PATH_MAX); } else strncpy(full_path,buf,GMX_PATH_MAX); } #endif /* Remove the executable name - it always contains at least one slash */ *(strrchr(full_path,DIR_SEPARATOR)+1)='\0'; /* Now we have the full path to the gromacs executable. * Use it to find the library dir. */ found=FALSE; while(!found && ( (ptr=strrchr(full_path,DIR_SEPARATOR)) != NULL ) ) { *ptr='\0'; found=search_subdirs(full_path,libdir); } } } /* End of smart searching. If we didn't find it in our parent tree, * or if the program name wasn't set, at least try some standard * locations before giving up, in case we are running from e.g. * a users home directory. This only works on unix or cygwin... */ #if ((!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64) || defined __CYGWIN__ || defined __CYGWIN32__) if(!found) found=search_subdirs("/usr/local",libdir); if(!found) found=search_subdirs("/usr",libdir); if(!found) found=search_subdirs("/opt",libdir); #endif return found; }
bool get_libdir(char *libdir) { char bin_name[512]; char buf[512]; char full_path[512]; char test_file[512]; char system_path[512]; char *dir,*ptr,*s,*pdum; bool found=FALSE; int i; /* First - detect binary name */ strcpy(bin_name,Program()); /* On windows & cygwin we need to add the .exe extension * too, or we wont be able to detect that the file exists */ #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __CYGWIN__ || defined __CYGWIN32__) if(strlen(bin_name)<3 || strncasecmp(bin_name+strlen(bin_name)-4,".exe",4)) strcat(bin_name,".exe"); #endif /* Only do the smart search part if we got a real name */ if (NULL!=bin_name && strcmp(bin_name,"GROMACS")) { if (!strchr(bin_name,DIR_SEPARATOR)) { /* No slash or backslash in name means it must be in the path - search it! */ s=getenv("PATH"); /* Add the local dir since it is not in the path on windows */ pdum=getcwd(system_path,sizeof(system_path)-1); strcat(system_path,PATH_SEPARATOR); if (s != NULL) strcat(system_path,s); s=system_path; found=FALSE; while (!found && (dir=strtok(s,PATH_SEPARATOR))!=NULL) { sprintf(full_path,"%s%c%s",dir,DIR_SEPARATOR,bin_name); found=fexist(full_path); s=NULL; /* pointer should be null for subseq. calls to strtok */ } if (!found) return FALSE; } else if (!filename_is_absolute(bin_name)) { /* name contains directory separators, but * it does not start at the root, i.e. * name is relative to the current dir */ pdum=getcwd(buf,sizeof(buf)-1); strcpy(full_path,buf); strcat(full_path,"/"); strcat(full_path,bin_name); } else { strcpy(full_path,bin_name); } /* Now we should have a full path and name in full_path, * but on unix it might be a link, or a link to a link to a link.. */ #if (!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64) while( (i=readlink(full_path,buf,sizeof(buf)-1)) > 0 ) { buf[i]='\0'; /* If it doesn't start with "/" it is relative */ if (buf[0]!=DIR_SEPARATOR) { strcpy(strrchr(full_path,DIR_SEPARATOR)+1,buf); } else strcpy(full_path,buf); } #endif /* Remove the executable name - it always contains at least one slash */ *(strrchr(full_path,DIR_SEPARATOR)+1)='\0'; /* Now we have the full path to the gromacs executable. * Use it to find the library dir. */ found=FALSE; while(!found && ( (ptr=strrchr(full_path,DIR_SEPARATOR)) != NULL ) ) { *ptr='\0'; found=search_subdirs(full_path,libdir); } } /* End of smart searching. If we didn't find it in our parent tree, * or if the program name wasn't set, at least try some standard * locations before giving up, in case we are running from e.g. * a users home directory. This only works on unix or cygwin... */ #if ((!defined WIN32 && !defined _WIN32 && !defined WIN64 && !defined _WIN64) || defined __CYGWIN__ || defined __CYGWIN32__) if(!found) found=search_subdirs("/usr/local",libdir); if(!found) found=search_subdirs("/usr",libdir); if(!found) found=search_subdirs("/opt",libdir); #endif return found; }
static void load_options(struct Configuration *cfg, const struct ConfParse *parse, const struct CF_Child *parent) { struct ConfigurationOptions *options = &cfg->options; size_t i; for (i=0; i<parent->child_count; i++) { struct CF_Child child = confparse_node_getchild(parse, parent, i); struct CF_Token name; struct CF_Token value; name = confparse_node_gettoken(parse, &child, 0); value = confparse_node_gettoken(parse, &child, 1); switch (lookup_token(&name)) { case S_DIRECTORY: if (options->directory) free(options->directory); if (filename_is_absolute(value.name)) { options->directory = filename_combine(value.name, ""); } else { char dir[2048]; if (getcwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); exit(1); } options->directory = filename_combine(dir, value.name); } break; case S_PID_FILE: if (options->pid_file) free(options->pid_file); if (filename_is_absolute(value.name)) { options->pid_file = filename_combine(value.name, ""); if (*options->pid_file && options->pid_file[strlen(options->pid_file)-1] == '/') options->pid_file[strlen(options->pid_file)-1] = '\0'; } else if (options->directory == NULL || strcmp(options->directory, ".") == 0) { char dir[2048]; if (getcwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); exit(1); } options->pid_file = filename_combine(dir, value.name); } else options->pid_file = filename_combine(options->directory, value.name); break; case S_PORT: if (!is_number(&value)) CONF_VALUE_BAD(parse, &value); else { unsigned n = to_number(&value); if (n > 65535) CONF_VALUE_BAD(parse, &value); else cfg->data_plane.port = n; } break; case S_LISTEN_ON: case S_LISTEN_ON_V6: break; case S_TRANSFER_SOURCE: case S_TRANSFER_SOURCE_V6: case S_ALT_TRANSFER_SOURCE: case S_ALT_TRANSFER_SOURCE_V6: break; case S_INTERFACE_INTERVAL: if (!is_number(&value)) CONF_VALUE_BAD(parse, &value); else { unsigned n = to_number(&value); if (n > 40320) CONF_VALUE_BAD(parse, &value); else cfg->data_plane.interface_interval = n; } break; case S_VERSION: switch (lookup_token(&value)) { case S_NONE: if (options->version) free(options->version); options->version = NULL; options->version_length = 0; break; default: if (options->version) free(options->version); options->version = malloc(value.name_length + 1); memcpy(options->version, value.name, value.name_length + 1); options->version_length = value.name_length; break; } break; case S_HOSTNAME: switch (lookup_token(&value)) { case S_NONE: if (options->hostname) free(options->hostname); options->hostname = NULL; break; case S_HOSTNAME: if (options->hostname) free(options->hostname); options->hostname = malloc(130); if (gethostname(options->hostname, 130) != 0) { perror("gethostname()"); free(options->hostname); options->hostname = 0; } break; default: if (options->hostname) free(options->hostname); options->hostname = malloc(value.name_length + 1); memcpy(options->hostname, value.name, value.name_length + 1); break; } break; case S_SERVER_ID: switch (lookup_token(&value)) { case S_NONE: if (options->server_id) free(options->server_id); options->server_id = NULL; options->server_id_length = 0; break; case S_HOSTNAME: if (options->server_id) free(options->server_id); options->server_id = malloc(130); if (gethostname(options->server_id, 130) != 0) { perror("gethostname()"); free(options->server_id); options->server_id = 0; options->server_id_length = 0; } else options->server_id_length = strlen(options->server_id); break; default: if (options->server_id) free(options->server_id); options->server_id = malloc(value.name_length + 1); memcpy(options->server_id, value.name, value.name_length + 1); options->server_id_length = value.name_length; break; } break; case S_ALLOW_NEW_ZONES: switch (lookup_token(&value)) { case S_YES: break; case S_NO: CONF_FEATURE_UNSUPPORTED(parse, &value); break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_RECURSION: switch (lookup_token(&value)) { case S_YES: CONF_FEATURE_UNSUPPORTED(parse, &value); break; case S_NO: //CONF_RECURSION_UNSUPPORTED(parse, &value); break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_AUTH_NXDOMAIN: switch (lookup_token(&value)) { case S_YES: CONF_FEATURE_UNSUPPORTED(parse, &value); break; case S_NO: break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_FORWARDERS: CONF_RECURSION_UNSUPPORTED(parse, &name); break; case S_DNSSEC_VALIDATION: CONF_FEATURE_UNSUPPORTED(parse, &name); break; default: CONF_OPTION_UNKNOWN(parse, &name); break; } } }