/** * @internal * * Free the NCPROVENANCE object * @param prov Pointer to provenance object * * @return ::NC_NOERR No error. * @author Dennis Heimbigner */ int NC4_free_provenance(struct NCPROVENANCE* prov) { LOG((3, "%s", __func__)); if(prov == NULL) return NC_NOERR; if(prov->propattr.properties != NULL) nclistfreeall(prov->propattr.properties); prov->propattr.properties = NULL; free(prov); return NC_NOERR; }
int nc_http_open(const char* objecturl, void** curlp, long long* filelenp) { int stat = NC_NOERR; CURL* curl = NULL; int i; NClist* list = NULL; Trace("open"); /* initialize curl*/ curl = curl_easy_init(); if (curl == NULL) stat = NC_ECURL; if(curlp && curl) *curlp = (void*)curl; if(filelenp) { *filelenp = -1; /* Attempt to get the file length using HEAD */ list = nclistnew(); if((stat = setupconn(curl,objecturl,NULL))) goto done; if((stat = headerson(curl,list))) goto done; if((stat = execute(curl,HEADCMD,NULL))) goto done; headersoff(curl); for(i=0;i<nclistlength(list);i+=2) { char* s = nclistget(list,i); if(strcasecmp(s,"content-length")==0) { s = nclistget(list,i+1); sscanf(s,"%lld",filelenp); break; } /* Also check for the Accept-Ranges header */ if(strcasecmp(s,"accept-ranges")==0) { s = nclistget(list,i+1); if(strcasecmp(s,"bytes")!=0) /* oops! */ {stat = NC_EACCESS; goto done;} } } } done: nclistfreeall(list); dbgflush(); return stat; }
int NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void* params, NCmodel* model, char** newpathp) { int stat = NC_NOERR; char* newpath = NULL; NCURI* uri = NULL; int omode = *omodep; int isuri = 0; NClist* modeargs = nclistnew(); if((stat = processuri(path, &uri, &newpath, modeargs))) goto done; isuri = (uri != NULL); /* Phase 1: compute the IOSP */ if((stat = extractiosp(modeargs,omode,model))) goto done; assert(model->iosp != 0); /* Phase 2: Process the non-iosp mode arguments */ if(!modelcomplete(model) && isuri) { int i; for(i=0;i<nclistlength(modeargs);i++) { const char* arg = nclistget(modeargs,i); if((stat=processmodearg(arg,model))) goto done; } } /* Phase 3: See if we can infer DAP */ if(!modelcomplete(model) && isuri) { if((stat = NC_dapinfer(modeargs,model))) goto done; } /* Phase 4: mode inference */ if(!modelcomplete(model)) { if((stat = NC_omodeinfer(omode,model))) goto done; } /* Phase 5: Infer from file content, if possible; this has highest precedence, so it may override previous decisions. */ if(!iscreate && isreadable(model->iosp)) { /* Ok, we need to try to read the file */ if((stat = check_file_type(path, omode, useparallel, params, model, uri))) goto done; } /* Phase 6: Infer impl from format */ if(!modelcomplete(model)) { if((stat = NC_implinfer(useparallel, model))) goto done; } assert(modelcomplete(model)); /* Force flag consistency */ switch (model->impl) { case NC_FORMATX_NC4: case NC_FORMATX_NC_HDF4: case NC_FORMATX_DAP4: case NC_FORMATX_UDF0: case NC_FORMATX_UDF1: omode |= NC_NETCDF4; if(model->format == NC_FORMAT_NETCDF4_CLASSIC) omode |= NC_CLASSIC_MODEL; break; case NC_FORMATX_DAP2: omode &= ~(NC_NETCDF4|NC_64BIT_OFFSET|NC_64BIT_DATA); break; case NC_FORMATX_NC3: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; case NC_FORMATX_PNETCDF: omode &= ~NC_NETCDF4; /* must be netcdf-3 (CDF-1, CDF-2, CDF-5) */ if(model->format == NC_FORMAT_64BIT_OFFSET) omode |= NC_64BIT_OFFSET; else if(model->format == NC_FORMAT_64BIT_DATA) omode |= NC_64BIT_DATA; break; default: {stat = NC_ENOTNC; goto done;} } done: if(uri) ncurifree(uri); nclistfreeall(modeargs); if(stat == NC_NOERR && newpathp) {*newpathp = newpath; newpath = NULL;} nullfree(newpath); *omodep = omode; /* in/out */ return check(stat); }
/** * @internal Initialize default provenance info * This will only be used for newly created files * or for opened files that do not contain an _NCProperties * attribute. * * @return ::NC_NOERR No error. * @author Dennis Heimbigner */ int NC4_provenance_init(void) { int stat = NC_NOERR; int i; NClist* other = NULL; char* name = NULL; char* value = NULL; unsigned major,minor,release; if(globalpropinitialized) return stat; /* Build _NCProperties info */ /* Initialize globalpropinfo */ memset((void*)&globalpropinfo,0,sizeof(globalpropinfo)); globalpropinfo.version = NCPROPS_VERSION; globalpropinfo.properties = nclistnew(); if(globalpropinfo.properties == NULL) {stat = NC_ENOMEM; goto done;} /* Insert primary library version as first entry */ if((name = strdup(NCPNCLIB2)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,name); name = NULL; /* Avoid multiple free() */ if((value = strdup(PACKAGE_VERSION)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,value); value = NULL; /* Insert the HDF5 as underlying storage format library */ if((name = strdup(NCPHDF5LIB2)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,name); name = NULL; stat = NC4_hdf5get_libversion(&major,&minor,&release); if(stat) goto done; { char sversion[64]; snprintf(sversion,sizeof(sversion),"%1u.%1u.%1u",major,minor,release); if((value = strdup(sversion)) == NULL) {stat = NC_ENOMEM; goto done;} } nclistpush(globalpropinfo.properties,value); value = NULL; /* Add any extra fields */ /*Parse them into an NClist */ other = nclistnew(); if(other == NULL) {stat = NC_ENOMEM; goto done;} #ifdef NCPROPERTIES stat = properties_parse(NCPROPERTIES_EXTRA,other); if(stat) goto done; #endif /* merge into the properties list */ for(i=0;i<nclistlength(other);i++) nclistpush(globalpropinfo.properties,strdup(nclistget(other,i))); nclistfreeall(other); other = NULL; done: if(name != NULL) free(name); if(value != NULL) free(value); if(other != NULL) nclistfreeall(other); if(stat && globalpropinfo.properties != NULL) { nclistfreeall(globalpropinfo.properties); globalpropinfo.properties = NULL; } if(stat == NC_NOERR) globalpropinitialized = 1; /* avoid repeating it */ return stat; }
/** * @internal finalize default provenance info * * @return ::NC_NOERR No error. * @author Dennis Heimbigner */ int NC4_provenance_finalize(void) { nclistfreeall(globalpropinfo.properties); return NC_NOERR; }