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"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include <errno.h>
|
2012-08-01 04:34:13 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2013-11-15 06:13:20 +08:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2017-03-09 08:01:10 +08:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
2013-11-15 06:13:20 +08:00
|
|
|
|
2017-09-03 08:09:36 +08:00
|
|
|
#ifdef _MSC_VER
|
2017-03-09 08:01:10 +08:00
|
|
|
#include <io.h>
|
2013-11-16 06:41:17 +08:00
|
|
|
#define mode_t int
|
|
|
|
#endif
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#include "ocinternal.h"
|
|
|
|
#include "ocdebug.h"
|
|
|
|
|
|
|
|
/* Order is important: longest first */
|
2019-03-31 04:06:20 +08:00
|
|
|
static const char* DDSdatamarks[3] = {"Data:\r\n","Data:\n",(char*)NULL};
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Not all systems have strndup, so provide one*/
|
|
|
|
char*
|
|
|
|
ocstrndup(const char* s, size_t len)
|
|
|
|
{
|
|
|
|
char* dup;
|
|
|
|
if(s == NULL) return NULL;
|
|
|
|
dup = (char*)ocmalloc(len+1);
|
|
|
|
MEMCHECK(dup,NULL);
|
|
|
|
memcpy((void*)dup,s,len);
|
|
|
|
dup[len] = '\0';
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2013-02-08 06:14:57 +08:00
|
|
|
/* Do not trust strncmp semantics; this one
|
2019-09-18 10:27:43 +08:00
|
|
|
compares up to len chars or to null terminators */
|
2012-08-01 04:34:13 +08:00
|
|
|
int
|
|
|
|
ocstrncmp(const char* s1, const char* s2, size_t len)
|
|
|
|
{
|
|
|
|
const char *p,*q;
|
|
|
|
if(s1 == s2) return 0;
|
|
|
|
if(s1 == NULL) return -1;
|
|
|
|
if(s2 == NULL) return +1;
|
|
|
|
for(p=s1,q=s2;len > 0;p++,q++,len--) {
|
|
|
|
if(*p == 0 && *q == 0) return 0; /* *p == *q == 0 */
|
|
|
|
if(*p != *q)
|
|
|
|
return (*p - *q);
|
|
|
|
}
|
|
|
|
/* 1st len chars are same */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-22 07:20:44 +08:00
|
|
|
#if 0
|
2013-03-26 01:12:50 +08:00
|
|
|
void
|
2017-03-09 08:01:10 +08:00
|
|
|
makedimlist(Nclist* path, Nclist* dims)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
unsigned int i,j;
|
2017-03-09 08:01:10 +08:00
|
|
|
for(i=0;i<nclistlength(path);i++) {
|
|
|
|
OCnode* node = (OCnode*)nclistget(path,i);
|
2012-08-01 04:34:13 +08:00
|
|
|
unsigned int rank = node->array.rank;
|
|
|
|
for(j=0;j<rank;j++) {
|
2017-03-09 08:01:10 +08:00
|
|
|
OCnode* dim = (OCnode*)nclistget(node->array.dimensions,j);
|
|
|
|
nclistpush(dims,(void*)dim);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-26 01:12:50 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ocfreeprojectionclause(OCprojectionclause* clause)
|
|
|
|
{
|
|
|
|
if(clause->target != NULL) free(clause->target);
|
2017-03-09 08:01:10 +08:00
|
|
|
while(nclistlength(clause->indexsets) > 0) {
|
|
|
|
NClist* slices = (NClist*)nclistpop(clause->indexsets);
|
|
|
|
while(nclistlength(slices) > 0) {
|
|
|
|
OCslice* slice = (OCslice*)nclistpop(slices);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(slice != NULL) free(slice);
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
nclistfree(slices);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
nclistfree(clause->indexsets);
|
2012-08-01 04:34:13 +08:00
|
|
|
free(clause);
|
|
|
|
}
|
|
|
|
|
2014-11-22 07:20:44 +08:00
|
|
|
#if 0
|
2013-03-26 01:12:50 +08:00
|
|
|
void
|
2017-03-09 08:01:10 +08:00
|
|
|
freeAttributes(NClist* attset)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
unsigned int i,j;
|
2017-03-09 08:01:10 +08:00
|
|
|
for(i=0;i<nclistlength(attset);i++) {
|
|
|
|
OCattribute* att = (OCattribute*)nclistget(attset,i);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(att->name != NULL) free(att->name);
|
|
|
|
if(att->etype == OC_String || att->etype == OC_URL) {
|
|
|
|
for(j=0;j<att->nvalues;j++) {
|
|
|
|
char* s = ((char**)att->values)[j];
|
|
|
|
if(s != NULL) free(s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
free(att->values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-26 01:12:50 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2014-11-22 07:20:44 +08:00
|
|
|
#if 0
|
2013-03-26 01:12:50 +08:00
|
|
|
void
|
2012-08-01 04:34:13 +08:00
|
|
|
freeOCnode(OCnode* cdf, int deep)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if(cdf == NULL) return;
|
|
|
|
if(cdf->name != NULL) free(cdf->name);
|
|
|
|
if(cdf->fullname != NULL) free(cdf->fullname);
|
|
|
|
if(cdf->attributes != NULL) freeAttributes(cdf->attributes);
|
|
|
|
if(cdf->subnodes != NULL) {
|
|
|
|
if(deep) {
|
2017-03-09 08:01:10 +08:00
|
|
|
for(i=0;i<nclistlength(cdf->subnodes);i++) {
|
|
|
|
OCnode* node = (OCnode*)nclistget(cdf->subnodes,i);
|
2012-08-01 04:34:13 +08:00
|
|
|
freeOCnode(node,deep);
|
|
|
|
}
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
nclistfree(cdf->subnodes);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
free(cdf);
|
|
|
|
}
|
2013-03-26 01:12:50 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
int
|
2017-03-09 08:01:10 +08:00
|
|
|
ocfindbod(NCbytes* buffer, size_t* bodp, size_t* ddslenp)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
char* content;
|
2017-03-09 08:01:10 +08:00
|
|
|
size_t len = ncbyteslength(buffer);
|
2019-03-31 04:06:20 +08:00
|
|
|
const char** marks;
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
content = ncbytescontents(buffer);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
for(marks = DDSdatamarks;*marks;marks++) {
|
2019-03-31 04:06:20 +08:00
|
|
|
const char* mark = *marks;
|
2014-03-09 11:41:30 +08:00
|
|
|
size_t tlen = strlen(mark);
|
2012-08-01 04:34:13 +08:00
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
if((i+tlen) <= len
|
|
|
|
&& (ocstrncmp(content+i,mark,tlen)==0)) {
|
|
|
|
*ddslenp = i;
|
|
|
|
i += tlen;
|
|
|
|
*bodp = i;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ddslenp = 0;
|
|
|
|
*bodp = 0;
|
|
|
|
return 0; /* tag not found; not necessarily an error*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute total # of elements if dimensioned*/
|
|
|
|
size_t
|
|
|
|
octotaldimsize(size_t rank, size_t* sizes)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
size_t count = 1;
|
|
|
|
for(i=0;i<rank;i++) {
|
|
|
|
count *= sizes[i];
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
octypesize(OCtype etype)
|
|
|
|
{
|
|
|
|
switch (etype) {
|
|
|
|
case OC_Char: return sizeof(char);
|
|
|
|
case OC_Byte: return sizeof(signed char);
|
|
|
|
case OC_UByte: return sizeof(unsigned char);
|
|
|
|
case OC_Int16: return sizeof(short);
|
|
|
|
case OC_UInt16: return sizeof(unsigned short);
|
|
|
|
case OC_Int32: return sizeof(int);
|
|
|
|
case OC_UInt32: return sizeof(unsigned int);
|
|
|
|
case OC_Float32: return sizeof(float);
|
|
|
|
case OC_Float64: return sizeof(double);
|
|
|
|
#ifdef HAVE_LONG_LONG_INT
|
|
|
|
case OC_Int64: return sizeof(long long);
|
|
|
|
case OC_UInt64: return sizeof(unsigned long long);
|
|
|
|
#endif
|
|
|
|
case OC_String: return sizeof(char*);
|
|
|
|
case OC_URL: return sizeof(char*);
|
|
|
|
default: break; /* Ignore all others */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
octypetostring(OCtype octype)
|
|
|
|
{
|
|
|
|
switch (octype) {
|
|
|
|
case OC_NAT: return "OC_NAT";
|
|
|
|
case OC_Char: return "OC_Char";
|
|
|
|
case OC_Byte: return "OC_Byte";
|
|
|
|
case OC_UByte: return "OC_UByte";
|
|
|
|
case OC_Int16: return "OC_Int16";
|
|
|
|
case OC_UInt16: return "OC_UInt16";
|
|
|
|
case OC_Int32: return "OC_Int32";
|
|
|
|
case OC_UInt32: return "OC_UInt32";
|
|
|
|
case OC_Int64: return "OC_Int64";
|
|
|
|
case OC_UInt64: return "OC_UInt64";
|
|
|
|
case OC_Float32: return "OC_Float32";
|
|
|
|
case OC_Float64: return "OC_Float64";
|
|
|
|
case OC_String: return "OC_String";
|
|
|
|
case OC_URL: return "OC_URL";
|
|
|
|
/* Non-primitives*/
|
|
|
|
case OC_Dataset: return "OC_Dataset";
|
|
|
|
case OC_Sequence: return "OC_Sequence";
|
|
|
|
case OC_Grid: return "OC_Grid";
|
|
|
|
case OC_Structure: return "OC_Structure";
|
|
|
|
case OC_Dimension: return "OC_Dimension";
|
|
|
|
case OC_Attribute: return "OC_Attribute";
|
|
|
|
case OC_Attributeset: return "OC_Attributeset";
|
|
|
|
case OC_Atomic: return "OC_Atomic";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
octypetoddsstring(OCtype octype)
|
|
|
|
{
|
|
|
|
switch (octype) {
|
|
|
|
case OC_Byte: return "Byte";
|
|
|
|
case OC_Int16: return "Int16";
|
|
|
|
case OC_UInt16: return "UInt16";
|
|
|
|
case OC_Int32: return "Int32";
|
|
|
|
case OC_UInt32: return "UInt32";
|
|
|
|
case OC_Float32: return "Float32";
|
|
|
|
case OC_Float64: return "Float64";
|
|
|
|
case OC_String: return "String";
|
|
|
|
case OC_URL: return "Url";
|
|
|
|
/* Non-atomics*/
|
|
|
|
case OC_Dataset: return "Dataset";
|
|
|
|
case OC_Sequence: return "Sequence";
|
|
|
|
case OC_Grid: return "Grid";
|
|
|
|
case OC_Structure: return "Structure";
|
|
|
|
case OC_Dimension: return "Dimension";
|
|
|
|
case OC_Attribute: return "Attribute";
|
|
|
|
case OC_Attributeset: return "Attributeset";
|
|
|
|
case OC_Atomic: return "Atomic";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OCerror
|
|
|
|
octypeprint(OCtype etype, void* value, size_t bufsize, char* buf)
|
|
|
|
{
|
|
|
|
if(buf == NULL || bufsize == 0 || value == NULL) return OC_EINVAL;
|
|
|
|
buf[0] = '\0';
|
|
|
|
switch (etype) {
|
|
|
|
case OC_Char:
|
|
|
|
snprintf(buf,bufsize,"'%c'",*(char*)value);
|
|
|
|
break;
|
|
|
|
case OC_Byte:
|
|
|
|
snprintf(buf,bufsize,"%d",*(signed char*)value);
|
|
|
|
break;
|
|
|
|
case OC_UByte:
|
|
|
|
snprintf(buf,bufsize,"%u",*(unsigned char*)value);
|
|
|
|
break;
|
|
|
|
case OC_Int16:
|
|
|
|
snprintf(buf,bufsize,"%d",*(short*)value);
|
|
|
|
break;
|
|
|
|
case OC_UInt16:
|
|
|
|
snprintf(buf,bufsize,"%u",*(unsigned short*)value);
|
|
|
|
break;
|
|
|
|
case OC_Int32:
|
|
|
|
snprintf(buf,bufsize,"%d",*(int*)value);
|
|
|
|
break;
|
|
|
|
case OC_UInt32:
|
|
|
|
snprintf(buf,bufsize,"%u",*(unsigned int*)value);
|
|
|
|
break;
|
|
|
|
case OC_Float32:
|
|
|
|
snprintf(buf,bufsize,"%g",*(float*)value);
|
|
|
|
break;
|
|
|
|
case OC_Float64:
|
|
|
|
snprintf(buf,bufsize,"%g",*(double*)value);
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_LONG_LONG_INT
|
|
|
|
case OC_Int64:
|
|
|
|
snprintf(buf,bufsize,"%lld",*(long long*)value);
|
|
|
|
break;
|
|
|
|
case OC_UInt64:
|
|
|
|
snprintf(buf,bufsize,"%llu",*(unsigned long long*)value);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case OC_String:
|
|
|
|
case OC_URL: {
|
|
|
|
char* s = *(char**)value;
|
|
|
|
snprintf(buf,bufsize,"\"%s\"",s);
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return OC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
xxdrsize(OCtype etype)
|
|
|
|
{
|
|
|
|
switch (etype) {
|
|
|
|
case OC_Char:
|
|
|
|
case OC_Byte:
|
|
|
|
case OC_UByte:
|
|
|
|
case OC_Int16:
|
|
|
|
case OC_UInt16:
|
|
|
|
case OC_Int32:
|
|
|
|
case OC_UInt32:
|
|
|
|
return XDRUNIT;
|
|
|
|
case OC_Int64:
|
|
|
|
case OC_UInt64:
|
|
|
|
return (2*XDRUNIT);
|
|
|
|
case OC_Float32:
|
|
|
|
return XDRUNIT;
|
|
|
|
case OC_Float64:
|
|
|
|
return (2*XDRUNIT);
|
|
|
|
case OC_String:
|
|
|
|
case OC_URL:
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************/
|
|
|
|
|
|
|
|
char*
|
|
|
|
ocerrstring(int err)
|
|
|
|
{
|
|
|
|
if(err == 0) return "no error";
|
|
|
|
if(err > 0) return strerror(err);
|
|
|
|
switch (err) {
|
|
|
|
case OC_EBADID:
|
|
|
|
return "OC_EBADID: Not a valid ID";
|
|
|
|
case OC_EINVAL:
|
|
|
|
return "OC_EINVAL: Invalid argument";
|
|
|
|
case OC_EPERM:
|
|
|
|
return "OC_EPERM: Write to read only";
|
|
|
|
case OC_EINVALCOORDS:
|
|
|
|
return "OC_EINVALCOORDS: Index exceeds dimension bound";
|
|
|
|
case OC_ENOTVAR:
|
|
|
|
return "OC_ENOTVAR: Variable not found";
|
|
|
|
case OC_ECHAR:
|
|
|
|
return "OC_ECHAR: Attempt to convert between text & numbers";
|
|
|
|
case OC_EEDGE:
|
|
|
|
return "OC_EEDGE: Start+count exceeds dimension bound";
|
|
|
|
case OC_ESTRIDE:
|
|
|
|
return "OC_ESTRIDE: Illegal stride";
|
|
|
|
case OC_ENOMEM:
|
|
|
|
return "OC_ENOMEM: Memory allocation (malloc) failure";
|
|
|
|
case OC_EDIMSIZE:
|
|
|
|
return "OC_EDIMSIZE: Invalid dimension size";
|
|
|
|
case OC_EDAP:
|
2014-03-15 04:07:35 +08:00
|
|
|
return "OC_EDAP: unspecified DAP failure";
|
2012-08-01 04:34:13 +08:00
|
|
|
case OC_EXDR:
|
|
|
|
return "OC_EXDR: XDR failure";
|
|
|
|
case OC_ECURL:
|
2014-03-15 04:07:35 +08:00
|
|
|
return "OC_ECURL: unspecified libcurl failure";
|
2012-08-01 04:34:13 +08:00
|
|
|
case OC_EBADURL:
|
|
|
|
return "OC_EBADURL: malformed url";
|
|
|
|
case OC_EBADVAR:
|
|
|
|
return "OC_EBADVAR: no such variable";
|
|
|
|
case OC_EOPEN:
|
|
|
|
return "OC_EOPEN: temporary file open failed";
|
|
|
|
case OC_EIO:
|
|
|
|
return "OC_EIO: I/O failure";
|
|
|
|
case OC_ENODATA:
|
|
|
|
return "OC_ENODATA: Variable has no data in DAP request";
|
|
|
|
case OC_EDAPSVC:
|
|
|
|
return "OC_EDAPSVC: DAP Server error";
|
|
|
|
case OC_ENAMEINUSE:
|
|
|
|
return "OC_ENAMEINUSE: Duplicate name in DDS";
|
|
|
|
case OC_EDAS:
|
|
|
|
return "OC_EDAS: Malformed or unreadable DAS";
|
|
|
|
case OC_EDDS:
|
|
|
|
return "OC_EDDS: Malformed or unreadable DDS";
|
|
|
|
case OC_EDATADDS:
|
|
|
|
return "OC_EDATADDS: Malformed or unreadable DATADDS";
|
|
|
|
case OC_ERCFILE:
|
2014-12-25 01:22:47 +08:00
|
|
|
return "OC_ERCFILE: Malformed, unreadable, or bad value in the run-time configuration file";
|
2012-08-01 04:34:13 +08:00
|
|
|
case OC_ENOFILE:
|
|
|
|
return "OC_ENOFILE: cannot read content of URL";
|
|
|
|
|
|
|
|
/* oc_data related errors */
|
|
|
|
case OC_EINDEX:
|
|
|
|
return "OC_EINDEX: index argument too large";
|
|
|
|
case OC_EBADTYPE:
|
|
|
|
return "OC_EBADTYPE: argument of wrong OCtype";
|
2012-12-19 05:08:23 +08:00
|
|
|
|
|
|
|
/* String concatenation overrun */
|
|
|
|
case OC_EOVERRUN:
|
|
|
|
return "OC_EOVERRUN: internal concatenation failed";
|
2014-03-15 04:07:35 +08:00
|
|
|
|
|
|
|
/* Authorization Error */
|
|
|
|
case OC_EAUTH:
|
|
|
|
return "OC_EAUTH: authorization failure";
|
|
|
|
|
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
|
|
|
/* Access Error */
|
|
|
|
case OC_EACCESS:
|
|
|
|
return "OC_EACCESS: access failure";
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "<unknown error code>";
|
|
|
|
}
|
|
|
|
|
|
|
|
OCerror
|
|
|
|
ocsvcerrordata(OCstate* state, char** codep, char** msgp, long* httpp)
|
|
|
|
{
|
|
|
|
if(codep) *codep = state->error.code;
|
|
|
|
if(msgp) *msgp = state->error.message;
|
|
|
|
if(httpp) *httpp = state->error.httpcode;
|
|
|
|
return OC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we get OC_EDATADDS error, then try to capture any
|
|
|
|
error message and log it; assumes that in this case,
|
|
|
|
the datadds is not big.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ocdataddsmsg(OCstate* state, OCtree* tree)
|
|
|
|
{
|
|
|
|
#define ERRCHUNK 1024
|
|
|
|
#define ERRFILL ' '
|
|
|
|
#define ERRTAG "Error {"
|
2014-03-09 11:41:30 +08:00
|
|
|
int i,j;
|
|
|
|
size_t len;
|
2012-08-01 04:34:13 +08:00
|
|
|
XXDR* xdrs;
|
|
|
|
char* contents;
|
|
|
|
off_t ckp;
|
|
|
|
|
|
|
|
if(tree == NULL) return;
|
|
|
|
/* get available space */
|
|
|
|
xdrs = tree->data.xdrs;
|
|
|
|
len = xxdr_length(xdrs);
|
|
|
|
if(len < strlen(ERRTAG))
|
|
|
|
return; /* no room */
|
|
|
|
ckp = xxdr_getpos(xdrs);
|
2014-03-09 11:41:30 +08:00
|
|
|
xxdr_setpos(xdrs,(off_t)0);
|
2012-08-01 04:34:13 +08:00
|
|
|
/* read the whole thing */
|
|
|
|
contents = (char*)malloc(len+1);
|
2014-03-09 11:41:30 +08:00
|
|
|
(void)xxdr_getbytes(xdrs,contents,(off_t)len);
|
2012-08-01 04:34:13 +08:00
|
|
|
contents[len] = '\0';
|
|
|
|
/* Look for error tag */
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
if(ocstrncmp(contents+i,ERRTAG,strlen(ERRTAG))==0) {
|
|
|
|
/* log the error message */
|
|
|
|
/* Do a quick and dirty escape */
|
|
|
|
for(j=i;j<len;j++) {
|
|
|
|
int c = contents[i+j];
|
|
|
|
if(c > 0 && (c < ' ' || c >= '\177'))
|
|
|
|
contents[i+j] = ERRFILL;
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGERR,"DATADDS failure, possible message: '%s'\n",
|
2012-08-01 04:34:13 +08:00
|
|
|
contents+i);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xxdr_setpos(xdrs,ckp);
|
|
|
|
done:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given some set of indices [i0][i1]...[in] (where n == rank-1)
|
|
|
|
and the maximum sizes, compute the linear offset
|
|
|
|
for set of dimension indices.
|
|
|
|
*/
|
|
|
|
size_t
|
2019-03-31 04:06:20 +08:00
|
|
|
ocarrayoffset(size_t rank, size_t* sizes, const size_t* indices)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
size_t count = 0;
|
|
|
|
for(i=0;i<rank;i++) {
|
|
|
|
count *= sizes[i];
|
|
|
|
count += indices[i];
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inverse of ocarrayoffset: convert linear index to a set of indices */
|
|
|
|
void
|
2014-03-09 11:41:30 +08:00
|
|
|
ocarrayindices(size_t index, size_t rank, size_t* sizes, size_t* indices)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=rank-1;i>=0;i--) {
|
|
|
|
indices[i] = index % sizes[i];
|
|
|
|
index = (index - indices[i]) / sizes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given some set of edge counts [i0][i1]...[in] (where n == rank-1)
|
|
|
|
and the maximum sizes, compute the linear offset
|
|
|
|
for the last edge position
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
ocedgeoffset(size_t rank, size_t* sizes, size_t* edges)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
size_t count = 0;
|
|
|
|
for(i=0;i<rank;i++) {
|
|
|
|
count *= sizes[i];
|
|
|
|
count += (edges[i]-1);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ocvalidateindices(size_t rank, size_t* sizes, size_t* indices)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<rank;i++) {
|
|
|
|
if(indices[i] >= sizes[i]) return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
oc_ispacked(OCnode* node)
|
|
|
|
{
|
|
|
|
OCtype octype = node->octype;
|
|
|
|
OCtype etype = node->etype;
|
|
|
|
int isscalar = (node->array.rank == 0);
|
|
|
|
int packed;
|
|
|
|
|
|
|
|
if(isscalar || octype != OC_Atomic)
|
|
|
|
return 0; /* is not packed */
|
|
|
|
packed = (etype == OC_Byte
|
|
|
|
|| etype == OC_UByte
|
|
|
|
|| etype == OC_Char) ? 1 : 0;
|
|
|
|
return packed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be consistent with ocx.h.OCDT */
|
|
|
|
#define NMODES 6
|
|
|
|
#define MAXMODENAME 8 /*max (strlen(modestrings[i])) */
|
2019-03-31 04:06:20 +08:00
|
|
|
static const char* modestrings[NMODES+1] = {
|
2012-08-01 04:34:13 +08:00
|
|
|
"FIELD", /* ((OCDT)(1<<0)) field of a container */
|
|
|
|
"ELEMENT", /* ((OCDT)(1<<1)) element of a structure array */
|
|
|
|
"RECORD", /* ((OCDT)(1<<2)) record of a sequence */
|
|
|
|
"ARRAY", /* ((OCDT)(1<<3)) is structure array */
|
|
|
|
"SEQUENCE", /* ((OCDT)(1<<4)) is sequence */
|
|
|
|
"ATOMIC", /* ((OCDT)(1<<5)) is atomic leaf */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2019-03-31 04:06:20 +08:00
|
|
|
char*
|
2012-08-01 04:34:13 +08:00
|
|
|
ocdtmodestring(OCDT mode,int compact)
|
|
|
|
{
|
2019-03-31 04:06:20 +08:00
|
|
|
char* result = NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
int i;
|
2019-03-31 04:06:20 +08:00
|
|
|
char* p = NULL;
|
|
|
|
|
|
|
|
result = malloc(1+(NMODES*(MAXMODENAME+1)));
|
|
|
|
if(result == NULL) return NULL;
|
|
|
|
p = result;
|
2012-08-01 04:34:13 +08:00
|
|
|
result[0] = '\0';
|
|
|
|
if(mode == 0) {
|
|
|
|
if(compact) *p++ = '-';
|
2012-12-19 05:08:23 +08:00
|
|
|
else if(!occoncat(result,sizeof(result),1,"NONE"))
|
|
|
|
return NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
} else for(i=0;;i++) {
|
2019-03-31 04:06:20 +08:00
|
|
|
const char* ms = modestrings[i];
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ms == NULL) break;
|
2012-12-19 05:08:23 +08:00
|
|
|
if(!compact && i > 0)
|
|
|
|
if(!occoncat(result,sizeof(result),1,","))
|
|
|
|
return NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
if(fisset(mode,(1<<i))) {
|
|
|
|
if(compact) *p++ = ms[0];
|
2012-12-19 05:08:23 +08:00
|
|
|
else if(!occoncat(result,sizeof(result),1,ms))
|
|
|
|
return NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* pad compact list out to NMODES in length (+1 for null terminator) */
|
|
|
|
if(compact) {
|
|
|
|
while((p-result) < NMODES) *p++ = ' ';
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2012-12-07 05:17:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Instead of using snprintf to concatenate
|
|
|
|
multiple strings into a given target,
|
|
|
|
provide a direct concatenator.
|
2012-12-19 05:08:23 +08:00
|
|
|
So, this function concats the n argument strings
|
|
|
|
and overwrites the contents of dst.
|
|
|
|
Care is taken to never overrun the available
|
|
|
|
space (the size parameter).
|
2012-12-07 05:17:36 +08:00
|
|
|
Note that size is assumed to include the null
|
|
|
|
terminator and that in the event of overrun,
|
|
|
|
the string will have a null at dst[size-1].
|
2012-12-19 05:08:23 +08:00
|
|
|
Return 0 if overrun, 1 otherwise.
|
2012-12-07 05:17:36 +08:00
|
|
|
*/
|
|
|
|
int
|
2012-12-19 05:08:23 +08:00
|
|
|
occopycat(char* dst, size_t size, size_t n, ...)
|
2012-12-07 05:17:36 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
size_t avail = size - 1;
|
|
|
|
int i;
|
2014-08-27 01:19:32 +08:00
|
|
|
int status = 1; /* assume ok */
|
2012-12-07 05:17:36 +08:00
|
|
|
char* p = dst;
|
|
|
|
|
|
|
|
if(n == 0) {
|
|
|
|
if(size > 0)
|
|
|
|
dst[0] = '\0';
|
2012-12-19 05:08:23 +08:00
|
|
|
return (size > 0 ? 1: 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args,n);
|
|
|
|
for(i=0;i<n;i++) {
|
|
|
|
char* q = va_arg(args, char*);
|
|
|
|
for(;;) {
|
|
|
|
int c = *q++;
|
|
|
|
if(c == '\0') break;
|
|
|
|
if(avail == 0) {status = 0; goto done;}
|
|
|
|
*p++ = c;
|
|
|
|
avail--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* make sure we null terminate;
|
|
|
|
note that since avail was size-1, there
|
|
|
|
will always be room
|
|
|
|
*/
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(args);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Similar to occopycat, but
|
|
|
|
the n strings are, in effect,
|
|
|
|
concatenated and appended to the
|
|
|
|
current contents of dst.
|
|
|
|
The size parameter is the total size of dst,
|
|
|
|
including room for null terminator.
|
|
|
|
Return 0 if overrun, 1 otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
occoncat(char* dst, size_t size, size_t n, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2014-08-27 01:19:32 +08:00
|
|
|
int status = 1; /* assume ok */
|
|
|
|
size_t avail = 0;
|
2012-12-19 05:08:23 +08:00
|
|
|
int i;
|
|
|
|
char* p;
|
|
|
|
size_t dstused;
|
|
|
|
dstused = strlen(dst);
|
|
|
|
if(dstused >= size)
|
|
|
|
return 0; /* There is no room to append */
|
|
|
|
/* move to the end of the current contents of dst
|
|
|
|
and act like we are doing copycat
|
|
|
|
*/
|
|
|
|
p = dst + dstused;
|
|
|
|
size -= dstused;
|
|
|
|
avail = size - 1;
|
|
|
|
if(n == 0) {
|
|
|
|
if(size > 0)
|
|
|
|
p[0] = '\0';
|
|
|
|
return (size > 0 ? 1: 0);
|
2012-12-07 05:17:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args,n);
|
|
|
|
for(i=0;i<n;i++) {
|
|
|
|
char* q = va_arg(args, char*);
|
|
|
|
for(;;) {
|
|
|
|
int c = *q++;
|
|
|
|
if(c == '\0') break;
|
2012-12-19 05:08:23 +08:00
|
|
|
if(avail == 0) {status = 0; goto done;}
|
2012-12-07 05:17:36 +08:00
|
|
|
*p++ = c;
|
|
|
|
avail--;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 05:08:23 +08:00
|
|
|
/* make sure we null terminate;
|
|
|
|
note that since avail was size-1, there
|
|
|
|
will always be room
|
|
|
|
*/
|
|
|
|
*p = '\0';
|
2012-12-07 05:17:36 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(args);
|
|
|
|
return status;
|
|
|
|
}
|
2013-11-15 06:13:20 +08:00
|
|
|
|
2014-12-25 01:22:47 +08:00
|
|
|
/* merge two envv style lists */
|
|
|
|
char**
|
|
|
|
ocmerge(const char** list1, const char** list2)
|
|
|
|
{
|
|
|
|
int l1, l2;
|
|
|
|
char** merge;
|
|
|
|
const char** p;
|
|
|
|
for(l1=0,p=list1;*p;p++) {l1++;}
|
|
|
|
for(l2=0,p=list2;*p;p++) {l2++;}
|
|
|
|
merge = (char**)malloc(sizeof(char*)*(l1+l2+1));
|
|
|
|
if(merge == NULL)
|
|
|
|
return NULL;
|
|
|
|
memcpy(merge,list1,sizeof(char*)*l1);
|
|
|
|
memcpy(merge+l1,list2,sizeof(char*)*l2);
|
|
|
|
merge[l1+l2] = NULL;
|
|
|
|
return merge;
|
|
|
|
}
|