/* compile the rc file, if any */ static OCerror ocreadrc(void) { OCerror stat = OC_NOERR; char* path = NULL; /* locate the configuration files: first if specified, then '.', then $HOME */ if(ocglobalstate.rc.rcfile != NULL) { /* always use this */ path = ocglobalstate.rc.rcfile; } else { char** rcname; int found = 0; for(rcname=rcfilenames;!found && *rcname;rcname++) { stat = rc_search(".",*rcname,&path); if(stat == OC_NOERR && path == NULL) /* try $HOME */ stat = rc_search(ocglobalstate.home,*rcname,&path); if(stat != OC_NOERR) goto done; if(path != NULL) found = 1; } } if(path == NULL) { oclog(OCLOGDBG,"Cannot find runtime configuration file; continuing"); } else { if(ocdebug > 0) fprintf(stderr, "DODS RC file: %s\n", path); if(ocdodsrc_read(path) == 0) { oclog(OCLOGERR, "Error parsing %s\n",path); stat = OC_ERCFILE; } } done: if(path != NULL) free(path); return stat; }
int ocinternalinitialize(void) { int stat = OC_NOERR; /* Compute some xdr related flags */ xxdr_init(); oc_loginit(); /* Determine if this version of curl supports "file://..." &/or "https://..." urls. */ { const char* const* proto; /*weird*/ curl_version_info_data* curldata; curldata = curl_version_info(CURLVERSION_NOW); oc_curl_file_supported = 0; oc_curl_https_supported = 0; for(proto=curldata->protocols;*proto;proto++) { if(strcmp("file",*proto)==0) {oc_curl_file_supported=1;break;} if(strcmp("https",*proto)==0) {oc_curl_https_supported=1;break;} } if(ocdebug > 0) { oc_log(LOGNOTE,"Curl file:// support = %d",oc_curl_file_supported); oc_log(LOGNOTE,"Curl https:// support = %d",oc_curl_file_supported); } } /* compile the .dodsrc, if any */ { char* path = NULL; char* homepath = NULL; char** alias; FILE* f = NULL; /* locate the configuration files: . first in '.', then $HOME */ for(alias=rcfilenames;*alias;alias++) { path = (char*)malloc(strlen("./")+strlen(*alias)+1); if(path == NULL) return OC_ENOMEM; strcpy(path,"./"); strcat(path,*alias); /* see if file is readable */ f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path = NULL;} /* cleanup */ } if(f == NULL) { /* try $HOME */ OCASSERT(path == NULL); homepath = getenv("HOME"); if (homepath!= NULL) { for(alias=rcfilenames;*alias;alias++) { path = (char*)malloc(strlen(homepath)+1+strlen(*alias)+1); if(path == NULL) return OC_ENOMEM; strcpy(path,homepath); strcat(path,"/"); strcat(path,*alias); f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path=NULL;} } } } if(f == NULL) { oc_log(LOGDBG,"Cannot find runtime configuration file"); } else { OCASSERT(path != NULL); fclose(f); if(ocdebug > 1) fprintf(stderr, "DODS RC file: %s\n", path); if(ocdodsrc_read(*alias,path) == 0) oc_log(LOGERR, "Error parsing %s\n",path); } if(path != NULL) free(path); } return OCTHROW(stat); }
int ocinternalinitialize(void) { int stat = OC_NOERR; if(!ocglobalstate.initialized) { memset((void*)&ocglobalstate,0,sizeof(ocglobalstate)); ocglobalstate.initialized = 1; } /* Capture $HOME */ { char* p; char* q; char* home = getenv("HOME"); char cwd[4096]; if(ocglobalstate.home == NULL) { #if defined(_WIN32) || defined(_WIN64) home = getenv("TEMP"); #else home = "/tmp"; #endif } if(home == NULL) { home = getcwd(cwd,sizeof(cwd)); if(home == NULL || *home == '\0') home = "."; } /* Convert '\' to '/' */ ocglobalstate.home = (char*)malloc(strlen(home) + 1); for(p=home,q=ocglobalstate.home;*p;p++,q++) { if(*p == '\\') {*q = '/'; } else {*q = *p;} } *q = '\0'; } /* Compute some xdr related flags */ xxdr_init(); ocloginit(); oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */ /* compile the .dodsrc, if any */ { char* path = NULL; char** alias; FILE* f = NULL; /* locate the configuration files: . first in '.', then $HOME */ for(alias=rcfilenames;*alias;alias++) { size_t pathlen = strlen("./")+strlen(*alias)+1; path = (char*)malloc(pathlen); if(path == NULL) return OC_ENOMEM; if(!occopycat(path,pathlen,2,"./",*alias)) { if(path) free(path); return OC_EOVERRUN; } /* see if file is readable */ f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path = NULL;} /* cleanup */ } if(f == NULL) { /* try $HOME */ OCASSERT(path == NULL); for(alias=rcfilenames;*alias;alias++) { size_t pathlen = strlen(ocglobalstate.home)+1+strlen(*alias)+1; path = (char*)malloc(pathlen); if(path == NULL) return OC_ENOMEM; if(!occopycat(path,pathlen,3,ocglobalstate.home,"/",*alias)) { if(path) free(path); return OC_EOVERRUN; } f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path=NULL;} } } if(f == NULL) { oclog(OCLOGDBG,"Cannot find runtime configuration file"); } else { OCASSERT(path != NULL); fclose(f); if(ocdebug > 1) fprintf(stderr, "DODS RC file: %s\n", path); if(ocdodsrc_read(*alias,path) == 0) oclog(OCLOGERR, "Error parsing %s\n",path); } if(path != NULL) free(path); } return OCTHROW(stat); }
int ocinternalinitialize(void) { int stat = OC_NOERR; /* Compute if we are same as network order v-a-v xdr */ #ifdef XDRBYTEORDER { XDR xdrs; union { char tmp[sizeof(unsigned int)]; unsigned int i; } u; int testint = 1; xrmem_create(&xdrs, (caddr_t)&u.tmp,sizeof(u.tmp), XDR_ENCODE); xdr_int(&xdrs, &testint); oc_network_order = (udub.i == testint?1:0); oc_big_endian = oc_network_order; } #else { int testint = 0x00000001; char *byte = (char *)&testint; oc_big_endian = (byte[0] == 0 ? 1 : 0); oc_network_order = oc_big_endian; } #endif /*XDRBYTEORDER*/ { /* It turns out that various machines store double in different formats. This affects the conversion code ocdata.c when reconstructing; probably could deduce this from oc_big_endian, but not sure. */ XDR xdrs; union { double dv; unsigned int i; unsigned int iv[2]; char tmp[sizeof(double)]; } udub; double testdub = 18000; /* verify double vs int size */ if(sizeof(double) != (2 * sizeof(unsigned int))) ocpanic("|double| != 2*|int|"); if(sizeof(udub) != sizeof(double)) ocpanic("|double| != |udub|"); memset((void*)&udub,0,sizeof(udub)); xdrmem_create(&xdrs, (caddr_t)&udub.tmp,sizeof(udub.tmp), XDR_ENCODE); xdr_double(&xdrs, &testdub); udub.iv[0] = ocntoh(udub.iv[0]); udub.iv[1] = ocntoh(udub.iv[1]); if (udub.dv == testdub) oc_invert_xdr_double = 0; else { /* swap and try again */ unsigned int temp = udub.iv[0]; udub.iv[0] = udub.iv[1]; udub.iv[1] = temp; if (udub.dv != testdub) ocpanic("cannot unpack xdr_double"); oc_invert_xdr_double = 1; } } oc_loginit(); /* Determine if this version of curl supports "file://..." &/or "https://..." urls. */ { const char* const* proto; /*weird*/ curl_version_info_data* curldata; curldata = curl_version_info(CURLVERSION_NOW); oc_curl_file_supported = 0; oc_curl_https_supported = 0; for(proto=curldata->protocols;*proto;proto++) { if(strcmp("file",*proto)==0) {oc_curl_file_supported=1;break;} if(strcmp("https",*proto)==0) {oc_curl_https_supported=1;break;} } if(ocdebug > 0) { oc_log(LOGNOTE,"Curl file:// support = %d",oc_curl_file_supported); oc_log(LOGNOTE,"Curl https:// support = %d",oc_curl_file_supported); } } /* compile the .dodsrc, if any */ { char* path = NULL; char* homepath = NULL; FILE* f = NULL; /* locate the configuration files: . first, then $HOME */ path = (char*)malloc(strlen("./")+strlen(DODSRC)+1); if(path == NULL) return OC_ENOMEM; strcpy(path,"./"); strcat(path,DODSRC); /* see if file is readable */ f = fopen(path,"r"); if(f == NULL) { /* try $HOME */ homepath = getenv("HOME"); if (homepath!= NULL) { if(path != NULL) free(path); path = (char*)malloc(strlen(homepath)+1+strlen(DODSRC)+1); if(path == NULL) return OC_ENOMEM; strcpy(path,homepath); strcat(path,"/"); strcat(path,DODSRC); f = fopen(path,"r"); } } if(f == NULL) { oc_log(LOGWARN,"Cannot find runtime .dodsrc configuration file"); } else { fclose(f); if(ocdebug > 1) fprintf(stderr, "DODS RC file: %s\n", path); if(ocdodsrc_read(path) == 0) oc_log(LOGERR, "Error parsing %s\n",path); } if(path != NULL) {free(path) ; path = NULL;} } return THROW(stat); }
int ocinternalinitialize(void) { int stat = OC_NOERR; if(!ocglobalstate.initialized) { memset((void*)&ocglobalstate,0,sizeof(ocglobalstate)); ocglobalstate.initialized = 1; } /* Compute some xdr related flags */ xxdr_init(); ocloginit(); oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */ /* compile the .dodsrc, if any */ { char* path = NULL; char* homepath = NULL; char** alias; FILE* f = NULL; /* locate the configuration files: . first in '.', then $HOME */ for(alias=rcfilenames;*alias;alias++) { size_t pathlen = strlen("./")+strlen(*alias)+1; path = (char*)malloc(pathlen); if(path == NULL) return OC_ENOMEM; if(!occopycat(path,pathlen,2,"./",*alias)) { if(path) free(path); return OC_EOVERRUN; } /* see if file is readable */ f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path = NULL;} /* cleanup */ } if(f == NULL) { /* try $HOME */ OCASSERT(path == NULL); homepath = getenv("HOME"); if (homepath!= NULL) { for(alias=rcfilenames;*alias;alias++) { size_t pathlen = strlen(homepath)+1+strlen(*alias)+1; path = (char*)malloc(pathlen); if(path == NULL) return OC_ENOMEM; if(!occopycat(path,pathlen,3,homepath,"/",*alias)) { if(path) {free(path);} return OC_EOVERRUN; } f = fopen(path,"r"); if(f != NULL) break; if(path != NULL) {free(path); path=NULL;} } } } if(f == NULL) { oclog(OCLOGDBG,"Cannot find runtime configuration file"); } else { OCASSERT(path != NULL); fclose(f); if(ocdebug > 1) fprintf(stderr, "DODS RC file: %s\n", path); if(ocdodsrc_read(*alias,path) == 0) oclog(OCLOGERR, "Error parsing %s\n",path); } if(path != NULL) free(path); } return OCTHROW(stat); }