2017-03-09 08:01:10 +08:00
|
|
|
/*********************************************************************
|
2018-12-07 05:24:28 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2017-03-09 08:01:10 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "ncdispatch.h"
|
|
|
|
#include "ncd4dispatch.h"
|
|
|
|
#include "d4includes.h"
|
|
|
|
#include "d4read.h"
|
|
|
|
#include "d4curlfunctions.h"
|
|
|
|
|
2017-07-06 00:03:48 +08:00
|
|
|
#ifdef _MSC_VER
|
2017-03-09 08:01:10 +08:00
|
|
|
#include <process.h>
|
|
|
|
#include <direct.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* Forward */
|
|
|
|
|
|
|
|
static void applyclientmetacontrols(NCD4meta* meta);
|
|
|
|
static int constrainable(NCURI*);
|
|
|
|
static void freeCurl(NCD4curl*);
|
|
|
|
static void freeInfo(NCD4INFO*);
|
|
|
|
static int paramcheck(NCD4INFO*, const char* key, const char* subkey);
|
|
|
|
static const char* getparam(NCD4INFO* info, const char* key);
|
|
|
|
static int set_curl_properties(NCD4INFO*);
|
2021-01-15 12:39:08 +08:00
|
|
|
static int makesubstrate(NCD4INFO* d4info);
|
|
|
|
static void resetInfoforRead(NCD4INFO* d4info);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* Constants */
|
|
|
|
|
|
|
|
static const char* checkseps = "+,:;";
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
int
|
|
|
|
NCD4_open(const char * path, int mode,
|
2018-09-23 09:22:34 +08:00
|
|
|
int basepe, size_t *chunksizehintp,
|
2019-08-02 04:30:20 +08:00
|
|
|
void *mpidata, const NC_Dispatch *dispatch, int ncid)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
NCD4INFO* d4info = NULL;
|
|
|
|
const char* value;
|
2019-08-02 02:46:12 +08:00
|
|
|
NC* nc;
|
2021-01-15 12:39:08 +08:00
|
|
|
NCD4meta* meta = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
void* contents = NULL;
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
if(path == NULL)
|
|
|
|
return THROW(NC_EDAPURL);
|
|
|
|
|
|
|
|
assert(dispatch != NULL);
|
|
|
|
|
2019-08-02 02:46:12 +08:00
|
|
|
/* Find pointer to NC struct for this file. */
|
2019-08-02 04:30:20 +08:00
|
|
|
ret = NC_check_id(ncid,&nc);
|
2019-08-02 02:46:12 +08:00
|
|
|
if(ret != NC_NOERR) {goto done;}
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
/* Setup our NC and NCDAPCOMMON state*/
|
|
|
|
|
|
|
|
d4info = (NCD4INFO*)calloc(1,sizeof(NCD4INFO));
|
|
|
|
if(d4info == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
|
|
|
|
nc->dispatchdata = d4info;
|
|
|
|
nc->int_ncid = nc__pseudofd(); /* create a unique id */
|
|
|
|
d4info->controller = (NC*)nc;
|
|
|
|
|
|
|
|
/* Parse url and params */
|
2019-09-30 02:59:28 +08:00
|
|
|
if(ncuriparse(nc->path,&d4info->uri))
|
2017-03-09 08:01:10 +08:00
|
|
|
{ret = NC_EDAPURL; goto done;}
|
|
|
|
|
2017-09-01 04:19:56 +08:00
|
|
|
/* Load auth info from rc file */
|
|
|
|
if((ret = NC_authsetup(&d4info->auth, d4info->uri)))
|
|
|
|
goto done;
|
|
|
|
NCD4_curl_protocols(d4info);
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
if(!constrainable(d4info->uri))
|
|
|
|
SETFLAG(d4info->controls.flags,NCF_UNCONSTRAINABLE);
|
|
|
|
|
|
|
|
/* fail if we are unconstrainable but have constraints */
|
|
|
|
if(FLAGSET(d4info->controls.flags,NCF_UNCONSTRAINABLE)) {
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
if(d4info->uri != NULL && d4info->uri->query != NULL) {
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGWARN,"Attempt to constrain an unconstrainable data source: %s",
|
|
|
|
d4info->uri->query);
|
|
|
|
ret = THROW(NC_EDAPCONSTRAINT);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process control client parameters */
|
2018-10-31 10:48:12 +08:00
|
|
|
NCD4_applyclientparamcontrols(d4info);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/* Use libsrc4 code (netcdf-4) for storing metadata */
|
|
|
|
{
|
|
|
|
char tmpname[NC_MAX_NAME];
|
|
|
|
|
|
|
|
/* Create fake file name: exact name must be unique,
|
|
|
|
but is otherwise irrelevant because we are using NC_DISKLESS
|
|
|
|
*/
|
|
|
|
if(strlen(d4info->controls.substratename) > 0)
|
|
|
|
snprintf(tmpname,sizeof(tmpname),"%s",d4info->controls.substratename);
|
|
|
|
else
|
|
|
|
snprintf(tmpname,sizeof(tmpname),"tmp_%d",nc->int_ncid);
|
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Compute the relevant names for the substrate file */
|
|
|
|
d4info->substrate.filename = strdup(tmpname);
|
|
|
|
if(d4info->substrate.filename == NULL)
|
|
|
|
{ret = NC_ENOMEM; goto done;}
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn on logging; only do this after oc_open*/
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
if((value = ncurifragmentlookup(d4info->uri,"log")) != NULL) {
|
2017-03-09 08:01:10 +08:00
|
|
|
ncloginit();
|
2021-01-07 04:35:59 +08:00
|
|
|
ncsetlogging(1);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2021-05-30 11:30:33 +08:00
|
|
|
/* Check env values */
|
|
|
|
if(getenv("CURLOPT_VERBOSE") != NULL)
|
|
|
|
d4info->auth->curlflags.verbose = 1;
|
|
|
|
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
/* Setup a curl connection */
|
|
|
|
{
|
|
|
|
CURL* curl = NULL; /* curl handle*/
|
|
|
|
d4info->curl = (NCD4curl*)calloc(1,sizeof(NCD4curl));
|
|
|
|
if(d4info->curl == NULL)
|
|
|
|
{ret = NC_ENOMEM; goto done;}
|
|
|
|
/* create the connection */
|
|
|
|
if((ret=NCD4_curlopen(&curl))!= NC_NOERR) goto done;
|
|
|
|
d4info->curl->curl = curl;
|
2018-08-27 07:04:46 +08:00
|
|
|
/* Load misc rc properties */
|
|
|
|
NCD4_get_rcproperties(d4info);
|
2019-03-06 05:18:22 +08:00
|
|
|
if((ret=set_curl_properties(d4info))!= NC_NOERR) goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
/* Set the one-time curl flags */
|
|
|
|
if((ret=NCD4_set_flags_perlink(d4info))!= NC_NOERR) goto done;
|
|
|
|
#if 1 /* temporarily make per-link */
|
|
|
|
if((ret=NCD4_set_flags_perfetch(d4info))!= NC_NOERR) goto done;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
d4info->curl->packet = ncbytesnew();
|
|
|
|
ncbytessetalloc(d4info->curl->packet,DFALTPACKETSIZE); /*initial reasonable size*/
|
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Reset the substrate */
|
|
|
|
if((ret=makesubstrate(d4info))) goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Always start by reading the DMR only */
|
|
|
|
/* reclaim substrate.metadata */
|
|
|
|
resetInfoforRead(d4info);
|
2021-05-22 10:46:56 +08:00
|
|
|
/* Rebuild metadata */
|
|
|
|
if((d4info->substrate.metadata=NCD4_newmeta(d4info))==NULL)
|
|
|
|
{ret = NC_ENOMEM; goto done;}
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
if((ret=NCD4_readDMR(d4info, d4info->controls.flags.flags))) goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2021-05-22 10:46:56 +08:00
|
|
|
/* set serial.rawdata */
|
2021-01-15 12:39:08 +08:00
|
|
|
len = ncbyteslength(d4info->curl->packet);
|
|
|
|
contents = ncbytesextract(d4info->curl->packet);
|
2021-05-22 10:46:56 +08:00
|
|
|
NCD4_attachraw(d4info->substrate.metadata, len, contents);
|
2021-01-15 12:39:08 +08:00
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
meta = d4info->substrate.metadata;
|
|
|
|
|
|
|
|
/* process meta control parameters */
|
|
|
|
applyclientmetacontrols(meta);
|
|
|
|
|
|
|
|
/* Infer the mode */
|
|
|
|
if((ret=NCD4_infermode(meta))) goto done;
|
|
|
|
|
|
|
|
#ifdef D4DUMPDMR
|
|
|
|
{
|
|
|
|
fprintf(stderr,"=============\n");
|
|
|
|
fputs(d4info->substrate.metadata->serial.dmr,stderr);
|
|
|
|
fprintf(stderr,"\n=============\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Process the dmr part */
|
|
|
|
if((ret=NCD4_dechunk(meta))) goto done;
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
if((ret = NCD4_parse(d4info->substrate.metadata))) goto done;
|
2021-01-15 12:39:08 +08:00
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
#ifdef D4DEBUGMETA
|
|
|
|
{
|
|
|
|
fprintf(stderr,"\n/////////////\n");
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
NCD4_print(d4info->substrate.metadata,buf);
|
|
|
|
ncbytesnull(buf);
|
|
|
|
fputs(ncbytescontents(buf),stderr);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
fprintf(stderr,"\n/////////////\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Build the substrate metadata */
|
2020-05-31 07:36:25 +08:00
|
|
|
ret = NCD4_metabuild(d4info->substrate.metadata,d4info->substrate.metadata->ncid);
|
|
|
|
if(ret != NC_NOERR && ret != NC_EVARSIZE) goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
if(ret) {
|
|
|
|
freeInfo(d4info);
|
|
|
|
nc->dispatchdata = NULL;
|
|
|
|
}
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-02-26 12:45:31 +08:00
|
|
|
NCD4_close(int ncid, void* ignore)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
NC* nc;
|
|
|
|
NCD4INFO* d4info;
|
|
|
|
int substrateid;
|
|
|
|
|
|
|
|
ret = NC_check_id(ncid, (NC**)&nc);
|
|
|
|
if(ret != NC_NOERR) goto done;
|
|
|
|
d4info = (NCD4INFO*)nc->dispatchdata;
|
|
|
|
substrateid = makenc4id(nc,ncid);
|
|
|
|
|
|
|
|
/* We call abort rather than close to avoid trying to write anything,
|
|
|
|
except if we are debugging
|
|
|
|
*/
|
|
|
|
if(FLAGSET(d4info->controls.debugflags,NCF_DEBUG_COPY)) {
|
|
|
|
/* Dump the data into the substrate */
|
|
|
|
if((ret = NCD4_debugcopy(d4info)))
|
|
|
|
goto done;
|
|
|
|
ret = nc_close(substrateid);
|
|
|
|
} else {
|
|
|
|
ret = nc_abort(substrateid);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeInfo(d4info);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
NCD4_abort(int ncid)
|
|
|
|
{
|
2018-02-26 12:45:31 +08:00
|
|
|
return NCD4_close(ncid,NULL);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
|
2018-10-31 10:48:12 +08:00
|
|
|
/* Reclaim an NCD4INFO instance */
|
2017-03-09 08:01:10 +08:00
|
|
|
static void
|
|
|
|
freeInfo(NCD4INFO* d4info)
|
|
|
|
{
|
|
|
|
if(d4info == NULL) return;
|
|
|
|
d4info->controller = NULL; /* break link */
|
|
|
|
nullfree(d4info->rawurltext);
|
|
|
|
nullfree(d4info->urltext);
|
|
|
|
ncurifree(d4info->uri);
|
|
|
|
freeCurl(d4info->curl);
|
|
|
|
nullfree(d4info->data.memory);
|
|
|
|
nullfree(d4info->data.ondiskfilename);
|
|
|
|
if(d4info->data.ondiskfile != NULL)
|
|
|
|
fclose(d4info->data.ondiskfile);
|
2018-10-31 10:48:12 +08:00
|
|
|
nullfree(d4info->fileproto.filename);
|
2017-08-06 12:41:31 +08:00
|
|
|
if(d4info->substrate.realfile
|
|
|
|
&& !FLAGSET(d4info->controls.debugflags,NCF_DEBUG_COPY)) {
|
|
|
|
/* We used real file, so we need to delete the temp file
|
|
|
|
unless we are debugging.
|
|
|
|
Assume caller has done nc_close|nc_abort on the ncid.
|
|
|
|
Note that in theory, this should not be necessary since
|
|
|
|
AFAIK the substrate file is still in def mode, and
|
|
|
|
when aborted, it should be deleted. But that is not working
|
|
|
|
for some reason, so we delete it ourselves.
|
|
|
|
*/
|
2018-10-31 10:48:12 +08:00
|
|
|
#if 0
|
2017-08-06 12:41:31 +08:00
|
|
|
if(d4info->substrate.filename != NULL) {
|
2018-10-31 10:48:12 +08:00
|
|
|
unlink(d4info->substrate.filename);
|
2017-08-06 12:41:31 +08:00
|
|
|
}
|
2018-10-31 10:48:12 +08:00
|
|
|
#endif
|
2017-08-06 12:41:31 +08:00
|
|
|
}
|
|
|
|
nullfree(d4info->substrate.filename); /* always reclaim */
|
2017-03-09 08:01:10 +08:00
|
|
|
NCD4_reclaimMeta(d4info->substrate.metadata);
|
2020-11-20 08:01:04 +08:00
|
|
|
NC_authfree(d4info->auth);
|
2018-10-31 10:48:12 +08:00
|
|
|
nclistfree(d4info->blobs);
|
2019-03-06 05:18:22 +08:00
|
|
|
free(d4info);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2021-01-15 12:39:08 +08:00
|
|
|
/* Reset NCD4INFO instance for new read request */
|
|
|
|
static void
|
|
|
|
resetInfoforRead(NCD4INFO* d4info)
|
|
|
|
{
|
|
|
|
if(d4info == NULL) return;
|
|
|
|
if(d4info->substrate.realfile
|
|
|
|
&& !FLAGSET(d4info->controls.debugflags,NCF_DEBUG_COPY)) {
|
|
|
|
/* We used real file, so we need to delete the temp file
|
|
|
|
unless we are debugging.
|
|
|
|
Assume caller has done nc_close|nc_abort on the ncid.
|
|
|
|
Note that in theory, this should not be necessary since
|
|
|
|
AFAIK the substrate file is still in def mode, and
|
|
|
|
when aborted, it should be deleted. But that is not working
|
|
|
|
for some reason, so we delete it ourselves.
|
|
|
|
*/
|
|
|
|
if(d4info->substrate.filename != NULL) {
|
|
|
|
unlink(d4info->substrate.filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NCD4_resetMeta(d4info->substrate.metadata);
|
|
|
|
nullfree(d4info->substrate.metadata);
|
|
|
|
d4info->substrate.metadata = NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
static void
|
|
|
|
freeCurl(NCD4curl* curl)
|
|
|
|
{
|
|
|
|
if(curl == NULL) return;
|
|
|
|
NCD4_curlclose(curl->curl);
|
|
|
|
ncbytesfree(curl->packet);
|
|
|
|
nullfree(curl->errdata.code);
|
|
|
|
nullfree(curl->errdata.message);
|
2018-10-31 10:48:12 +08:00
|
|
|
free(curl);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Define the set of protocols known to be constrainable */
|
2018-10-02 05:51:43 +08:00
|
|
|
static const char* constrainableprotocols[] = {"http", "https",NULL};
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
constrainable(NCURI* durl)
|
|
|
|
{
|
2018-10-02 05:51:43 +08:00
|
|
|
const char** protocol = constrainableprotocols;
|
2017-03-09 08:01:10 +08:00
|
|
|
for(;*protocol;protocol++) {
|
|
|
|
if(strcmp(durl->protocol,*protocol)==0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set curl properties for link based on rc files etc.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
set_curl_properties(NCD4INFO* d4info)
|
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
|
2020-11-20 08:01:04 +08:00
|
|
|
if(d4info->auth->curlflags.useragent == NULL) {
|
2017-11-24 01:55:24 +08:00
|
|
|
char* agent;
|
|
|
|
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION);
|
|
|
|
len++; /*strlcat nul*/
|
|
|
|
agent = (char*)malloc(len+1);
|
2017-03-09 08:01:10 +08:00
|
|
|
strncpy(agent,DFALTUSERAGENT,len);
|
2017-11-24 01:55:24 +08:00
|
|
|
strlcat(agent,VERSION,len);
|
2020-11-20 08:01:04 +08:00
|
|
|
d4info->auth->curlflags.useragent = agent;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Some servers (e.g. thredds and columbia) appear to require a place
|
|
|
|
to put cookies in order for some security functions to work
|
|
|
|
*/
|
2020-11-20 08:01:04 +08:00
|
|
|
if(d4info->auth->curlflags.cookiejar != NULL
|
|
|
|
&& strlen(d4info->auth->curlflags.cookiejar) == 0) {
|
|
|
|
free(d4info->auth->curlflags.cookiejar);
|
|
|
|
d4info->auth->curlflags.cookiejar = NULL;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-20 08:01:04 +08:00
|
|
|
if(d4info->auth->curlflags.cookiejar == NULL) {
|
2017-03-09 08:01:10 +08:00
|
|
|
/* If no cookie file was defined, define a default */
|
2017-07-06 00:03:48 +08:00
|
|
|
char* path = NULL;
|
2017-09-04 05:09:10 +08:00
|
|
|
char* newpath = NULL;
|
2017-07-06 00:03:48 +08:00
|
|
|
int len;
|
2017-03-09 08:01:10 +08:00
|
|
|
errno = 0;
|
2019-03-31 04:06:20 +08:00
|
|
|
NCRCglobalstate* globalstate = ncrc_getglobalstate();
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
/* Create the unique cookie file name */
|
2017-07-06 00:03:48 +08:00
|
|
|
len =
|
2019-03-31 04:06:20 +08:00
|
|
|
strlen(globalstate->tempdir)
|
2017-07-06 00:03:48 +08:00
|
|
|
+ 1 /* '/' */
|
|
|
|
+ strlen("ncd4cookies");
|
|
|
|
path = (char*)malloc(len+1);
|
|
|
|
if(path == NULL) return NC_ENOMEM;
|
2019-03-31 04:06:20 +08:00
|
|
|
snprintf(path,len,"%s/nc4cookies",globalstate->tempdir);
|
2017-07-06 00:03:48 +08:00
|
|
|
/* Create the unique cookie file name */
|
2017-09-04 05:09:10 +08:00
|
|
|
newpath = NC_mktmp(path);
|
2017-07-06 00:03:48 +08:00
|
|
|
free(path);
|
2017-09-04 05:09:10 +08:00
|
|
|
if(newpath == NULL) {
|
2017-03-09 08:01:10 +08:00
|
|
|
fprintf(stderr,"Cannot create cookie file\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-11-20 08:01:04 +08:00
|
|
|
d4info->auth->curlflags.cookiejar = newpath;
|
|
|
|
d4info->auth->curlflags.cookiejarcreated = 1;
|
2017-03-09 08:01:10 +08:00
|
|
|
errno = 0;
|
|
|
|
}
|
2020-11-20 08:01:04 +08:00
|
|
|
assert(d4info->auth->curlflags.cookiejar != NULL);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/* Make sure the cookie jar exists and can be read and written */
|
|
|
|
{
|
|
|
|
FILE* f = NULL;
|
2020-11-20 08:01:04 +08:00
|
|
|
char* fname = d4info->auth->curlflags.cookiejar;
|
2017-03-09 08:01:10 +08:00
|
|
|
/* See if the file exists already */
|
|
|
|
f = fopen(fname,"r");
|
|
|
|
if(f == NULL) {
|
|
|
|
/* Ok, create it */
|
|
|
|
f = fopen(fname,"w+");
|
|
|
|
if(f == NULL) {
|
|
|
|
fprintf(stderr,"Cookie file cannot be read and written: %s\n",fname);
|
|
|
|
{ret= NC_EPERM; goto fail;}
|
|
|
|
}
|
|
|
|
} else { /* test if file can be written */
|
|
|
|
fclose(f);
|
|
|
|
f = fopen(fname,"r+");
|
|
|
|
if(f == NULL) {
|
|
|
|
fprintf(stderr,"Cookie file is cannot be written: %s\n",fname);
|
|
|
|
{ret = NC_EPERM; goto fail;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(f != NULL) fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return THROW(ret);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|
2018-10-31 10:48:12 +08:00
|
|
|
void
|
|
|
|
NCD4_applyclientparamcontrols(NCD4INFO* info)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
const char* value;
|
|
|
|
|
|
|
|
/* clear the flags */
|
|
|
|
CLRFLAG(info->controls.flags,NCF_CACHE);
|
|
|
|
CLRFLAG(info->controls.flags,NCF_SHOWFETCH);
|
|
|
|
CLRFLAG(info->controls.flags,NCF_NC4);
|
|
|
|
CLRFLAG(info->controls.flags,NCF_NCDAP);
|
2018-10-02 05:51:43 +08:00
|
|
|
CLRFLAG(info->controls.flags,NCF_FILLMISMATCH);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/* Turn on any default on flags */
|
|
|
|
SETFLAG(info->controls.flags,DFALT_ON_FLAGS);
|
|
|
|
SETFLAG(info->controls.flags,(NCF_NC4|NCF_NCDAP));
|
|
|
|
|
|
|
|
if(paramcheck(info,"show","fetch"))
|
|
|
|
SETFLAG(info->controls.flags,NCF_SHOWFETCH);
|
|
|
|
|
|
|
|
if(paramcheck(info,"translate","nc4"))
|
|
|
|
info->controls.translation = NCD4_TRANSNC4;
|
|
|
|
|
|
|
|
/* Look at the debug flags */
|
|
|
|
if(paramcheck(info,"debug","copy"))
|
|
|
|
SETFLAG(info->controls.debugflags,NCF_DEBUG_COPY); /* => close */
|
|
|
|
|
|
|
|
value = getparam(info,"substratename");
|
|
|
|
if(value != NULL)
|
2019-03-06 05:18:22 +08:00
|
|
|
strncpy(info->controls.substratename,value,(NC_MAX_NAME-1));
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2018-10-31 10:48:12 +08:00
|
|
|
info->controls.opaquesize = DFALTOPAQUESIZE;
|
|
|
|
value = getparam(info,"opaquesize");
|
|
|
|
if(value != NULL) {
|
|
|
|
long long len = 0;
|
|
|
|
if(sscanf(value,"%lld",&len) != 1 || len == 0)
|
|
|
|
nclog(NCLOGWARN,"bad [opaquesize] tag: %s",value);
|
|
|
|
else
|
2019-03-06 05:18:22 +08:00
|
|
|
info->controls.opaquesize = (size_t)len;
|
2018-10-31 10:48:12 +08:00
|
|
|
}
|
2019-03-06 05:18:22 +08:00
|
|
|
|
2018-10-02 05:51:43 +08:00
|
|
|
value = getparam(info,"fillmismatch");
|
|
|
|
if(value != NULL)
|
|
|
|
SETFLAG(info->controls.flags,NCF_FILLMISMATCH);
|
|
|
|
|
|
|
|
value = getparam(info,"nofillmismatch");
|
|
|
|
if(value != NULL)
|
|
|
|
CLRFLAG(info->controls.debugflags,NCF_FILLMISMATCH);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-06 05:18:22 +08:00
|
|
|
applyclientmetacontrols(NCD4meta* meta)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
NCD4INFO* info = meta->controller;
|
|
|
|
const char* value = getparam(info,"checksummode");
|
|
|
|
if(value != NULL) {
|
|
|
|
if(strcmp(value,"ignore")==0)
|
|
|
|
meta->ignorechecksums = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for substring in value of param. If substring == NULL; then just
|
|
|
|
check if param is defined.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
paramcheck(NCD4INFO* info, const char* key, const char* subkey)
|
|
|
|
{
|
|
|
|
const char* value;
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
value = getparam(info, key);
|
|
|
|
if(value == NULL)
|
|
|
|
return 0;
|
|
|
|
if(subkey == NULL) return 1;
|
|
|
|
p = strstr(value,subkey);
|
|
|
|
if(p == NULL) return 0;
|
|
|
|
p += strlen(subkey);
|
|
|
|
if(*p != '\0' && strchr(checkseps,*p) == NULL) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Given a parameter key, return its value or NULL if not defined.
|
|
|
|
*/
|
|
|
|
static const char*
|
|
|
|
getparam(NCD4INFO* info, const char* key)
|
|
|
|
{
|
|
|
|
const char* value;
|
|
|
|
|
|
|
|
if(info == NULL || key == NULL) return NULL;
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
if((value=ncurifragmentlookup(info->uri,key)) == NULL)
|
2017-03-09 08:01:10 +08:00
|
|
|
return NULL;
|
|
|
|
return value;
|
|
|
|
}
|
2021-01-15 12:39:08 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
makesubstrate(NCD4INFO* d4info)
|
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
int new = NC_NETCDF4;
|
|
|
|
int old = 0;
|
|
|
|
int ncid = 0;
|
|
|
|
int ncflags = NC_NETCDF4|NC_CLOBBER;
|
|
|
|
|
|
|
|
if(d4info->substrate.filename != NULL) {
|
|
|
|
/* reset the substrate */
|
|
|
|
nc_abort(d4info->substrate.nc4id);
|
|
|
|
d4info->substrate.nc4id = 0;
|
|
|
|
}
|
|
|
|
/* Create the hidden substrate netcdf file.
|
|
|
|
We want this hidden file to always be NC_NETCDF4, so we need to
|
|
|
|
force default format temporarily in case user changed it.
|
|
|
|
Since diskless is enabled, create file in-memory.
|
|
|
|
*/
|
|
|
|
ncflags |= NC_DISKLESS;
|
|
|
|
if(FLAGSET(d4info->controls.debugflags,NCF_DEBUG_COPY)) {
|
|
|
|
/* Cause data to be dumped to real file */
|
|
|
|
ncflags |= NC_WRITE;
|
|
|
|
ncflags &= ~(NC_DISKLESS); /* use real file */
|
|
|
|
}
|
|
|
|
nc_set_default_format(new,&old); /* save and change */
|
|
|
|
ret = nc_create(d4info->substrate.filename,ncflags,&ncid);
|
|
|
|
nc_set_default_format(old,&new); /* restore */
|
|
|
|
/* Avoid fill on the substrate */
|
|
|
|
nc_set_fill(ncid,NC_NOFILL,NULL);
|
|
|
|
d4info->substrate.nc4id = ncid;
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|