2018-12-07 06:47:47 +08:00
|
|
|
/* Copyright 2018, UCAR/Unidata and OPeNDAP, Inc.
|
2012-08-01 04:34:13 +08:00
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-09-29 07:02:35 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <unistd.h>
|
2012-09-29 07:02:35 +08:00
|
|
|
#endif
|
2012-12-19 05:08:23 +08:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <sys/types.h>
|
2012-12-19 05:08:23 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
#include "ocinternal.h"
|
|
|
|
#include "ocdebug.h"
|
|
|
|
#include "ocdump.h"
|
|
|
|
|
2013-03-16 05:44:59 +08:00
|
|
|
/* Mnemonic */
|
|
|
|
#define TOPLEVEL 1
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Forward */
|
2015-01-16 05:19:51 +08:00
|
|
|
static OCdata* newocdata(OCnode* pattern);
|
2024-03-16 01:25:09 +08:00
|
|
|
static off_t ocxdrsize(OCtype etype,int isscalar);
|
2012-08-01 04:34:13 +08:00
|
|
|
static OCerror occompile1(OCstate*, OCnode*, XXDR*, OCdata**);
|
|
|
|
static OCerror occompilerecord(OCstate*, OCnode*, XXDR*, OCdata**);
|
2013-03-16 05:44:59 +08:00
|
|
|
static OCerror occompilefields(OCstate*, OCdata*, XXDR*, int istoplevel);
|
2012-08-01 04:34:13 +08:00
|
|
|
static OCerror occompileatomic(OCstate*, OCdata*, XXDR*);
|
|
|
|
static int ocerrorstring(XXDR* xdrs);
|
2013-03-16 05:44:59 +08:00
|
|
|
static int istoplevel(OCnode* node);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Sequence tag constant */
|
2013-03-25 01:33:17 +08:00
|
|
|
static const char StartOfSequence = '\x5A';
|
|
|
|
static const char EndOfSequence = '\xA5';
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/*
|
2014-11-22 07:20:44 +08:00
|
|
|
Provide an option that makes a single pass over
|
2012-08-01 04:34:13 +08:00
|
|
|
the data packet and record pointers into it
|
|
|
|
to speed up access.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Assume we are operating on the datadds tree */
|
|
|
|
OCerror
|
|
|
|
occompile(OCstate* state, OCnode* xroot)
|
|
|
|
{
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
XXDR* xxdrs;
|
|
|
|
OCtree* xtree;
|
|
|
|
OCdata* data;
|
|
|
|
|
|
|
|
OCASSERT(state != NULL);
|
|
|
|
OCASSERT(xroot != NULL);
|
|
|
|
OCASSERT(xroot->tree != NULL);
|
|
|
|
OCASSERT(xroot->tree->dxdclass == OCDATADDS);
|
|
|
|
OCASSERT(xroot->tree->data.data == NULL);
|
|
|
|
|
|
|
|
xtree = xroot->tree;
|
|
|
|
|
|
|
|
xxdrs = xtree->data.xdrs;
|
|
|
|
if(xxdrs == NULL) return OCTHROW(OC_EXDR);
|
|
|
|
|
|
|
|
ocstat = occompile1(state,xroot,xxdrs,&data);
|
|
|
|
if(ocstat == OC_NOERR)
|
|
|
|
xtree->data.data = data;
|
|
|
|
|
|
|
|
#ifdef OCDEBUG
|
|
|
|
{
|
2017-03-18 07:20:02 +08:00
|
|
|
Ncbytes* buffer = ncbytesnew();
|
2012-08-01 04:34:13 +08:00
|
|
|
ocdumpdatatree(state,data,buffer,0);
|
2017-03-18 07:20:02 +08:00
|
|
|
fprintf(stderr,"datatree:\n%s",ncbytescontents(buffer));
|
|
|
|
ncbytesfree(buffer);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return OCTHROW(ocstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
|
|
|
occompile1(OCstate* state, OCnode* xnode, XXDR* xxdrs, OCdata** datap)
|
|
|
|
{
|
|
|
|
OCerror ocstat = OC_NOERR;
|
2014-03-09 11:41:30 +08:00
|
|
|
size_t i;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCdata* data = NULL;
|
|
|
|
size_t nelements = 0;
|
2017-03-09 08:01:10 +08:00
|
|
|
NClist* records = NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Allocate instance for this node */
|
|
|
|
data = newocdata(xnode);
|
|
|
|
MEMFAIL(data);
|
|
|
|
|
|
|
|
/* Capture position(s) */
|
|
|
|
data->xdroffset = xxdr_getpos(xxdrs);
|
|
|
|
|
|
|
|
switch (xnode->octype) {
|
|
|
|
|
|
|
|
case OC_Dataset:
|
|
|
|
case OC_Grid: /* Always scalars */
|
2013-03-16 05:44:59 +08:00
|
|
|
ocstat = occompilefields(state,data,xxdrs,istoplevel(xnode));
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR) goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Structure:
|
|
|
|
if(xnode->array.rank == 0) {/* scalar */
|
2013-03-16 05:44:59 +08:00
|
|
|
ocstat = occompilefields(state,data,xxdrs,istoplevel(xnode));
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR) goto fail;
|
|
|
|
} else { /* dimensioned structure */
|
|
|
|
unsigned int xdrcount;
|
|
|
|
fset(data->datamode,OCDT_ARRAY);
|
|
|
|
/* Determine # of instances */
|
|
|
|
nelements = octotaldimsize(xnode->array.rank,xnode->array.sizes);
|
2012-08-03 02:43:21 +08:00
|
|
|
if(nelements == 0) {ocstat = OCTHROW(OC_ENODATA); goto fail;}
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Validate and skip the leading count field */
|
|
|
|
if(!xxdr_uint(xxdrs,&xdrcount))
|
|
|
|
{ocstat = OC_EXDR; goto fail;}
|
|
|
|
if(xdrcount != nelements)
|
2019-02-01 12:13:06 +08:00
|
|
|
{ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* allocate space to capture all the element instances */
|
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
|
|
|
data->instances = (OCdata**)calloc(nelements,sizeof(OCdata*));
|
2014-11-22 07:20:44 +08:00
|
|
|
MEMGOTO(data->instances,ocstat,fail);
|
2012-08-01 04:34:13 +08:00
|
|
|
data->ninstances = 0;
|
|
|
|
|
|
|
|
/* create and fill the element instances */
|
|
|
|
for(i=0;i<nelements;i++) {
|
|
|
|
OCdata* instance = newocdata(xnode);
|
2014-11-22 07:20:44 +08:00
|
|
|
MEMGOTO(instance,ocstat,fail);
|
|
|
|
fset(instance->datamode,OCDT_ELEMENT);
|
2012-08-01 04:34:13 +08:00
|
|
|
data->instances[i] = instance;
|
|
|
|
data->ninstances++;
|
|
|
|
/* Capture the back link */
|
|
|
|
instance->container = data;
|
|
|
|
instance->index = i;
|
|
|
|
/* capture the current instance position */
|
|
|
|
instance->xdroffset = xxdr_getpos(xxdrs);
|
|
|
|
/* Now compile the fields of this instance */
|
2013-03-16 05:44:59 +08:00
|
|
|
ocstat = occompilefields(state,instance,xxdrs,!TOPLEVEL);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR) {goto fail;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Sequence:
|
|
|
|
/* Since we do not know the # records beforehand,
|
2017-03-09 08:01:10 +08:00
|
|
|
use a list to collect the record instances.
|
2012-08-01 04:34:13 +08:00
|
|
|
*/
|
|
|
|
fset(data->datamode,OCDT_SEQUENCE);
|
2017-03-09 08:01:10 +08:00
|
|
|
records = nclistnew();
|
2012-08-01 04:34:13 +08:00
|
|
|
for(nelements=0;;nelements++) {
|
|
|
|
/* pick up the sequence record begin marker*/
|
|
|
|
char tmp[sizeof(unsigned int)];
|
|
|
|
/* extract the tag byte*/
|
2014-03-09 11:41:30 +08:00
|
|
|
if(!xxdr_opaque(xxdrs,tmp,(off_t)sizeof(tmp)))
|
2012-08-01 04:34:13 +08:00
|
|
|
{ocstat = OC_EXDR; goto fail;}
|
|
|
|
if(tmp[0] == StartOfSequence) {
|
|
|
|
/* Allocate a record instance */
|
2014-04-19 07:02:58 +08:00
|
|
|
OCdata* record = NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
ocstat = occompilerecord(state,xnode,xxdrs,&record);
|
2014-04-19 09:13:34 +08:00
|
|
|
if(ocstat != OC_NOERR || !record) goto fail;
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Capture the back link */
|
|
|
|
record->container = data;
|
|
|
|
record->index = nelements;
|
2017-03-09 08:01:10 +08:00
|
|
|
nclistpush(records,(void*)record);
|
2012-08-01 04:34:13 +08:00
|
|
|
record = NULL;
|
|
|
|
} else if(tmp[0] == EndOfSequence) {
|
|
|
|
break; /* we are done with the this sequence instance*/
|
|
|
|
} else {
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGERR,"missing/invalid begin/end record marker\n");
|
2019-02-01 12:13:06 +08:00
|
|
|
ocstat = OCTHROW(OC_EINVALCOORDS);
|
2012-08-01 04:34:13 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
OCASSERT(nelements == nclistlength(records));
|
2012-08-01 04:34:13 +08:00
|
|
|
/* extract the content */
|
|
|
|
data->ninstances = nelements;
|
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
|
|
|
data->instances = nclistextract(records);
|
2014-11-22 07:20:44 +08:00
|
|
|
MEMGOTO(data,ocstat,fail);
|
2017-03-09 08:01:10 +08:00
|
|
|
nclistfree(records);
|
2012-08-01 04:34:13 +08:00
|
|
|
records = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Atomic:
|
|
|
|
fset(data->datamode,OCDT_ATOMIC);
|
|
|
|
ocstat = occompileatomic(state,data,xxdrs);
|
|
|
|
if(ocstat != OC_NOERR) goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OCPANIC1("occompile: encountered unexpected node type: %x",xnode->octype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ok:*/
|
2014-11-22 07:20:44 +08:00
|
|
|
if(datap) {
|
|
|
|
*datap = data;
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data != NULL)
|
|
|
|
ocdata_free(state,data);
|
|
|
|
|
|
|
|
return OCTHROW(ocstat);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
/* See if we can extract error info from the response */
|
|
|
|
ocerrorstring(xxdrs);
|
|
|
|
|
|
|
|
if(records != NULL) {
|
2017-03-09 08:01:10 +08:00
|
|
|
for(i=0;i<nclistlength(records);i++)
|
|
|
|
ocdata_free(state,(OCdata*)nclistget(records,i));
|
|
|
|
nclistfree(records);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
2014-11-22 07:20:44 +08:00
|
|
|
|
|
|
|
if(data != NULL)
|
2012-08-03 02:43:21 +08:00
|
|
|
ocdata_free(state,data);
|
2014-11-22 07:20:44 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
return OCTHROW(ocstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
|
|
|
occompilerecord(OCstate* state, OCnode* xnode, XXDR* xxdrs, OCdata** recordp)
|
|
|
|
{
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
OCdata* record = newocdata(xnode);/* create record record */
|
|
|
|
MEMFAIL(record);
|
|
|
|
fset(record->datamode,OCDT_RECORD);
|
2015-01-16 05:19:51 +08:00
|
|
|
record->pattern = xnode;
|
2012-08-01 04:34:13 +08:00
|
|
|
/* capture the current record position */
|
|
|
|
record->xdroffset = xxdr_getpos(xxdrs);
|
|
|
|
/* Compile the fields of this record */
|
2013-03-16 05:44:59 +08:00
|
|
|
ocstat = OCTHROW(occompilefields(state,record,xxdrs,!TOPLEVEL));
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat == OC_NOERR) {
|
2014-11-22 07:20:44 +08:00
|
|
|
if(recordp) {
|
|
|
|
*recordp = record;
|
|
|
|
record = NULL;
|
|
|
|
}
|
|
|
|
if(record != NULL)
|
|
|
|
ocdata_free(state,record);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
2014-11-22 07:20:44 +08:00
|
|
|
return OCTHROW(ocstat);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
2013-03-16 05:44:59 +08:00
|
|
|
occompilefields(OCstate* state, OCdata* data, XXDR* xxdrs, int istoplevel)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
2014-03-09 11:41:30 +08:00
|
|
|
size_t i;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
size_t nelements;
|
2015-01-16 05:19:51 +08:00
|
|
|
OCnode* xnode = data->pattern;
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2012-08-03 02:43:21 +08:00
|
|
|
assert(data != NULL);
|
2017-03-09 08:01:10 +08:00
|
|
|
nelements = nclistlength(xnode->subnodes);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(nelements == 0)
|
|
|
|
goto done;
|
|
|
|
data->instances = (OCdata**)malloc(nelements*sizeof(OCdata*));
|
|
|
|
MEMFAIL(data->instances);
|
|
|
|
for(i=0;i<nelements;i++) {
|
|
|
|
OCnode* fieldnode;
|
|
|
|
OCdata* fieldinstance;
|
2017-03-09 08:01:10 +08:00
|
|
|
fieldnode = (OCnode*)nclistget(xnode->subnodes,i);
|
2012-08-01 04:34:13 +08:00
|
|
|
ocstat = occompile1(state,fieldnode,xxdrs,&fieldinstance);
|
|
|
|
if(ocstat != OC_NOERR)
|
|
|
|
goto fail;
|
|
|
|
fset(fieldinstance->datamode,OCDT_FIELD);
|
|
|
|
data->instances[i] = fieldinstance;
|
|
|
|
data->ninstances++;
|
|
|
|
/* Capture the back link */
|
|
|
|
fieldinstance->container = data;
|
|
|
|
fieldinstance->index = i;
|
|
|
|
}
|
|
|
|
|
2013-03-16 05:44:59 +08:00
|
|
|
/* If top-level, then link the OCnode to the OCdata directly */
|
|
|
|
if(istoplevel) {
|
|
|
|
for(i=0;i<nelements;i++) {
|
2017-03-09 08:01:10 +08:00
|
|
|
OCnode* fieldnode = (OCnode*)nclistget(xnode->subnodes,i);
|
2013-03-16 05:44:59 +08:00
|
|
|
OCdata* fieldinstance = data->instances[i];
|
|
|
|
fieldnode->data = fieldinstance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
done:
|
|
|
|
return OCTHROW(ocstat);
|
|
|
|
|
|
|
|
fail:
|
2012-08-03 02:43:21 +08:00
|
|
|
if(data->instances != NULL) {
|
2012-08-01 04:34:13 +08:00
|
|
|
for(i=0;i<data->ninstances;i++)
|
|
|
|
ocdata_free(state,data->instances[i]);
|
2012-08-03 02:43:21 +08:00
|
|
|
data->ninstances = 0;
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
return OCTHROW(ocstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
|
|
|
occompileatomic(OCstate* state, OCdata* data, XXDR* xxdrs)
|
|
|
|
{
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
int i;
|
2024-03-16 01:25:09 +08:00
|
|
|
off_t xdrsize;
|
2012-08-01 04:34:13 +08:00
|
|
|
unsigned int xxdrcount;
|
2015-01-16 05:19:51 +08:00
|
|
|
OCnode* xnode = data->pattern;
|
2012-08-01 04:34:13 +08:00
|
|
|
int scalar = (xnode->array.rank == 0);
|
2014-11-22 07:20:44 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCASSERT((xnode->octype == OC_Atomic));
|
|
|
|
|
|
|
|
if(!scalar) {
|
|
|
|
/* Use the count from the datadds */
|
2024-03-16 01:25:09 +08:00
|
|
|
size_t nelements = octotaldimsize(xnode->array.rank,xnode->array.sizes);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Get first copy of the dimension count */
|
|
|
|
if(!xxdr_uint(xxdrs,&xxdrcount)) {ocstat = OC_EXDR; goto fail;}
|
2019-02-01 12:13:06 +08:00
|
|
|
if(xxdrcount != nelements) {ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
|
2012-08-01 04:34:13 +08:00
|
|
|
if(xnode->etype != OC_String && xnode->etype != OC_URL) {
|
|
|
|
/* Get second copy of the dimension count */
|
|
|
|
if(!xxdr_uint(xxdrs,&xxdrcount)) {ocstat = OC_EXDR; goto fail;}
|
2019-02-01 12:13:06 +08:00
|
|
|
if(xxdrcount != nelements) {ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
} else { /*scalar*/
|
|
|
|
xxdrcount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->xdroffset = xxdr_getpos(xxdrs);
|
|
|
|
data->ninstances = xxdrcount;
|
|
|
|
data->xdrsize = ocxdrsize(xnode->etype,scalar);
|
|
|
|
|
|
|
|
switch (xnode->etype) {
|
|
|
|
|
|
|
|
/* Do the fixed sized, non-packed cases */
|
|
|
|
case OC_Int16: case OC_UInt16:
|
|
|
|
case OC_Int32: case OC_UInt32:
|
|
|
|
case OC_Int64: case OC_UInt64:
|
|
|
|
case OC_Float32: case OC_Float64:
|
|
|
|
/* Skip the data */
|
2024-03-16 01:25:09 +08:00
|
|
|
xxdr_skip(xxdrs,(off_t)data->ninstances*data->xdrsize);
|
2012-08-01 04:34:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Do the fixed sized, possibly packed cases */
|
|
|
|
case OC_Byte:
|
|
|
|
case OC_UByte:
|
|
|
|
case OC_Char:
|
|
|
|
/* Get the totalsize and round up to multiple of XDRUNIT */
|
2024-03-16 01:25:09 +08:00
|
|
|
xdrsize = (off_t)data->ninstances*data->xdrsize;
|
2012-08-01 04:34:13 +08:00
|
|
|
xdrsize = RNDUP(xdrsize);
|
|
|
|
/* Skip the data */
|
|
|
|
xxdr_skip(xxdrs,xdrsize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Hard case, because strings are variable length */
|
|
|
|
case OC_String: case OC_URL:
|
|
|
|
/* Start by allocating a set of pointers for each string */
|
|
|
|
data->nstrings = xxdrcount;
|
|
|
|
data->strings = (off_t*)malloc(sizeof(off_t)*data->nstrings);
|
|
|
|
/* We need to walk each string, get size, then skip */
|
|
|
|
for(i=0;i<data->nstrings;i++) {
|
|
|
|
unsigned int len;
|
2014-03-09 11:41:30 +08:00
|
|
|
off_t lenz;
|
2012-08-01 04:34:13 +08:00
|
|
|
data->strings[i] = xxdr_getpos(xxdrs);
|
|
|
|
/* get exact string length */
|
|
|
|
if(!xxdr_uint(xxdrs,&len)) {ocstat = OC_EXDR; goto fail;}
|
2014-03-09 11:41:30 +08:00
|
|
|
lenz = (off_t)len;
|
|
|
|
lenz = RNDUP(lenz);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Skip the data */
|
2014-03-09 11:41:30 +08:00
|
|
|
xxdr_skip(xxdrs,lenz);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OCPANIC1("unexpected etype: %d",xnode->etype);
|
|
|
|
|
|
|
|
} /* switch */
|
|
|
|
|
|
|
|
/*ok:*/
|
|
|
|
return OCTHROW(ocstat);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if(data->strings != NULL)
|
|
|
|
free(data->strings);
|
|
|
|
data->strings = NULL;
|
|
|
|
data->ninstances = 0;
|
|
|
|
return OCTHROW(ocstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ocdata_free(OCstate* state, OCdata* data)
|
|
|
|
{
|
|
|
|
if(data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(data->instances != NULL) {
|
|
|
|
int i;
|
|
|
|
for(i=0;i<data->ninstances;i++)
|
|
|
|
ocdata_free(state,data->instances[i]);
|
|
|
|
free(data->instances);
|
|
|
|
}
|
|
|
|
if(data->strings != NULL)
|
|
|
|
free(data->strings);
|
2012-08-03 02:43:21 +08:00
|
|
|
free(data);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static OCdata*
|
2015-01-16 05:19:51 +08:00
|
|
|
newocdata(OCnode* pattern)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
OCdata* data = (OCdata*)calloc(1,sizeof(OCdata));
|
|
|
|
MEMCHECK(data,NULL);
|
|
|
|
data->header.magic = OCMAGIC;
|
|
|
|
data->header.occlass = OC_Data;
|
2015-01-16 05:19:51 +08:00
|
|
|
data->pattern = pattern;
|
2012-08-01 04:34:13 +08:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2013-03-16 05:44:59 +08:00
|
|
|
static int
|
|
|
|
istoplevel(OCnode* node)
|
|
|
|
{
|
|
|
|
if(node == NULL)
|
|
|
|
return 1; /* base case */
|
|
|
|
if(!istoplevel(node->container))
|
|
|
|
return 0;
|
|
|
|
switch (node->octype) {
|
|
|
|
case OC_Dataset: case OC_Grid: case OC_Atomic: return 1;
|
|
|
|
case OC_Structure:
|
2014-11-22 07:20:44 +08:00
|
|
|
return (node->array.rank == 0 ? 1 : 0); /* Toplevel if scalar */
|
2013-03-16 05:44:59 +08:00
|
|
|
case OC_Sequence: default: return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* XDR representation size depends on if this is scalar or not */
|
2024-03-16 01:25:09 +08:00
|
|
|
static off_t
|
2012-08-01 04:34:13 +08:00
|
|
|
ocxdrsize(OCtype etype, int isscalar)
|
|
|
|
{
|
|
|
|
switch (etype) {
|
|
|
|
case OC_Char:
|
|
|
|
case OC_Byte:
|
|
|
|
case OC_UByte:
|
|
|
|
return (isscalar? XDRUNIT : 1);
|
|
|
|
case OC_Int16:
|
|
|
|
case OC_UInt16:
|
|
|
|
case OC_Int32:
|
|
|
|
case OC_UInt32:
|
|
|
|
case OC_Float32:
|
|
|
|
return XDRUNIT;
|
|
|
|
case OC_Float64:
|
|
|
|
case OC_Int64:
|
|
|
|
case OC_UInt64:
|
|
|
|
return 2*XDRUNIT;
|
|
|
|
default:
|
|
|
|
break; /* no simple size */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define tag "Error {\n"
|
|
|
|
|
|
|
|
static int
|
|
|
|
ocerrorstring(XXDR* xdrs)
|
|
|
|
{
|
|
|
|
/* Check to see if the xdrs contains "Error {\n'; assume it is at the beginning of data */
|
|
|
|
off_t avail = xxdr_getavail(xdrs);
|
2014-11-22 07:20:44 +08:00
|
|
|
char* data;
|
|
|
|
if(!xxdr_setpos(xdrs,(off_t)0)) return 0;
|
|
|
|
data = (char*)malloc((size_t)avail);
|
|
|
|
MEMCHECK(data,0);
|
|
|
|
if(!xxdr_opaque(xdrs,data,avail)) {free(data); return 0;}
|
2012-08-01 04:34:13 +08:00
|
|
|
/* check for error tag at front */
|
|
|
|
if(ocstrncmp(data,tag,sizeof(tag))==0) {
|
|
|
|
char* p;
|
|
|
|
if((p=strchr(data,'}')) != NULL) *(++p)='\0';
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGERR,"Server error: %s",data);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Since important, report to stderr as well */
|
|
|
|
fprintf(stderr,"Server error: %s",data);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|