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"
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2012-12-19 05:08:23 +08:00
|
|
|
#ifdef HAVE_FCNTL_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <fcntl.h>
|
2012-12-19 05:08:23 +08:00
|
|
|
#endif
|
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
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
2017-09-03 08:09:36 +08:00
|
|
|
#ifdef _MSC_VER
|
2012-11-22 07:57:42 +08:00
|
|
|
#include <io.h>
|
2017-07-19 02:44:39 +08:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY _O_BINARY
|
|
|
|
#endif
|
2012-11-22 07:57:42 +08:00
|
|
|
#endif
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "ncrc.h"
|
2012-08-01 04:34:13 +08:00
|
|
|
#include "ocinternal.h"
|
|
|
|
#include "ocdebug.h"
|
|
|
|
#include "ochttp.h"
|
|
|
|
#include "ocread.h"
|
|
|
|
#include "occurlfunctions.h"
|
2020-10-14 09:12:15 +08:00
|
|
|
#include "ncpathmgr.h"
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/*Forward*/
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
static int readpacket(OCstate* state, NCURI*, NCbytes*, OCdxd, OCflags, long*);
|
2017-03-09 08:01:10 +08:00
|
|
|
static int readfile(const char* path, const char* suffix, NCbytes* packet);
|
2012-08-01 04:34:13 +08:00
|
|
|
static int readfiletofile(const char* path, const char* suffix, FILE* stream, off_t*);
|
|
|
|
|
|
|
|
int
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
readDDS(OCstate* state, OCtree* tree, OCflags flags)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
|
|
|
long lastmodified = -1;
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
ncurisetquery(state->uri,tree->constraint);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2012-08-22 00:46:10 +08:00
|
|
|
#ifdef OCDEBUG
|
|
|
|
fprintf(stderr,"readDDS:\n");
|
|
|
|
#endif
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
stat = readpacket(state,state->uri,state->packet,OCDDS, flags,
|
2012-08-01 04:34:13 +08:00
|
|
|
&lastmodified);
|
|
|
|
if(stat == OC_NOERR) state->ddslastmodified = lastmodified;
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
readDAS(OCstate* state, OCtree* tree, OCflags flags)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
ncurisetquery(state->uri,tree->constraint);
|
2012-08-22 00:46:10 +08:00
|
|
|
#ifdef OCDEBUG
|
|
|
|
fprintf(stderr,"readDAS:\n");
|
|
|
|
#endif
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
stat = readpacket(state,state->uri,state->packet,OCDAS,flags,NULL);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int
|
2017-03-09 08:01:10 +08:00
|
|
|
readversion(OCstate* state, NCURI* url, NCbytes* packet)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
return readpacket(state,url,packet,OCVER,NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ocdxdextension(OCdxd dxd)
|
|
|
|
{
|
|
|
|
switch(dxd) {
|
|
|
|
case OCDDS: return ".dds";
|
|
|
|
case OCDAS: return ".das";
|
|
|
|
case OCDATADDS: return ".dods";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
readpacket(OCstate* state, NCURI* url, NCbytes* packet, OCdxd dxd, OCflags ocflags, long* lastmodified)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
|
|
|
int fileprotocol = 0;
|
|
|
|
const char* suffix = ocdxdextension(dxd);
|
|
|
|
char* fetchurl = NULL;
|
|
|
|
CURL* curl = state->curl;
|
|
|
|
|
|
|
|
fileprotocol = (strcmp(url->protocol,"file")==0);
|
|
|
|
|
2017-09-03 08:09:36 +08:00
|
|
|
if(fileprotocol) {
|
|
|
|
/* Short circuit file://... urls and read directly */
|
2017-03-09 08:01:10 +08:00
|
|
|
fetchurl = ncuribuild(url,NULL,NULL,NCURIBASE);
|
2012-08-01 04:34:13 +08:00
|
|
|
stat = readfile(fetchurl,suffix,packet);
|
|
|
|
} else {
|
2017-03-09 08:01:10 +08:00
|
|
|
int flags = NCURIBASE;
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
if(ocflags & OCENCODEPATH)flags |= NCURIENCODEPATH;
|
|
|
|
if(ocflags & OCENCODEQUERY) flags |= NCURIENCODEQUERY;
|
2017-03-09 08:01:10 +08:00
|
|
|
if(!fileprotocol) flags |= NCURIQUERY;
|
|
|
|
fetchurl = ncuribuild(url,NULL,suffix,flags);
|
2012-08-01 04:34:13 +08:00
|
|
|
MEMCHECK(fetchurl,OC_ENOMEM);
|
|
|
|
if(ocdebug > 0)
|
|
|
|
{fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);}
|
2017-09-01 04:19:56 +08:00
|
|
|
stat = ocfetchurl(curl,fetchurl,packet,lastmodified);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(stat)
|
|
|
|
oc_curl_printerror(state);
|
|
|
|
if(ocdebug > 0)
|
|
|
|
{fprintf(stderr,"fetch complete\n"); fflush(stderr);}
|
|
|
|
}
|
|
|
|
free(fetchurl);
|
2012-08-22 00:46:10 +08:00
|
|
|
#ifdef OCDEBUG
|
2014-01-22 04:04:52 +08:00
|
|
|
{
|
2012-08-22 00:46:10 +08:00
|
|
|
fprintf(stderr,"readpacket: packet.size=%lu\n",
|
2017-03-09 08:01:10 +08:00
|
|
|
(unsigned long)ncbyteslength(packet));
|
2014-01-22 04:04:52 +08:00
|
|
|
}
|
2012-08-22 00:46:10 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
return OCTHROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
readDATADDS(OCstate* state, OCtree* tree, OCflags ocflags)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
|
|
|
long lastmod = -1;
|
|
|
|
|
2012-08-22 00:46:10 +08:00
|
|
|
#ifdef OCDEBUG
|
|
|
|
fprintf(stderr,"readDATADDS:\n");
|
|
|
|
#endif
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
if((ocflags & OCONDISK) == 0) {
|
2017-03-09 08:01:10 +08:00
|
|
|
ncurisetquery(state->uri,tree->constraint);
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
stat = readpacket(state,state->uri,state->packet,OCDATADDS,ocflags,&lastmod);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(stat == OC_NOERR)
|
|
|
|
state->datalastmodified = lastmod;
|
2017-03-09 08:01:10 +08:00
|
|
|
tree->data.datasize = ncbyteslength(state->packet);
|
2012-08-01 04:34:13 +08:00
|
|
|
} else { /*((flags & OCONDISK) != 0) */
|
2017-03-09 08:01:10 +08:00
|
|
|
NCURI* url = state->uri;
|
2012-08-01 04:34:13 +08:00
|
|
|
int fileprotocol = 0;
|
|
|
|
char* readurl = NULL;
|
|
|
|
|
|
|
|
fileprotocol = (strcmp(url->protocol,"file")==0);
|
|
|
|
|
2017-09-03 08:09:36 +08:00
|
|
|
if(fileprotocol) {
|
2017-03-09 08:01:10 +08:00
|
|
|
readurl = ncuribuild(url,NULL,NULL,NCURIBASE);
|
2012-08-01 04:34:13 +08:00
|
|
|
stat = readfiletofile(readurl, ".dods", tree->data.file, &tree->data.datasize);
|
|
|
|
} else {
|
2017-03-09 08:01:10 +08:00
|
|
|
int flags = NCURIBASE;
|
Yet another fix for DAP2 double URL encoding.
re: https://github.com/Unidata/netcdf-c/issues/1876
and: https://github.com/Unidata/netcdf-c/pull/1835
and: https://github.com/Unidata/netcdf4-python/issues/1041
The change in PR 1835 was correct with respect to using %20 instead of '+'
for encoding blanks. However, it was a mistake to assume everything was
unencoded and then to do encoding ourselves. The problem is that
different servers do different things, with Columbia being an outlier.
So, I have added a set of client controls that can at least give
the caller some control over this. The caller can append
the following fragment to his URL to control what gets encoded before
sending it to the server. The syntax is as follows:
````
https://<host>/<path>/<query>#encode=path|query|all|none
````
The possible values:
* path -- URL encode (i.e. %xx encode) as needed in the path part of the URL.
* query -- URL encode as needed in the query part of the URL.
* all -- equivalent to ````#encode=path,query````.
* none -- do not url encode any part of the URL sent to the server; not strictly necessary, so mostly for completeness.
Note that if "encode=" is used, then before it is processed, all encoding
is turned of so that ````#encode=path```` will only encode the path
and not the query.
The default is ````#encode=query````, so the path is left untouched,
but the query is always encoded.
Internally, this required changes to pass the encode flags down into
the OC2 library.
Misc. Unrelated Changes:
* Shut up those irritating warning from putget.m4
2020-11-06 02:04:56 +08:00
|
|
|
if(ocflags & OCENCODEPATH)
|
|
|
|
flags |= NCURIENCODEPATH;
|
|
|
|
if(ocflags & OCENCODEQUERY)
|
|
|
|
flags |= NCURIENCODEQUERY;
|
2017-03-09 08:01:10 +08:00
|
|
|
if(!fileprotocol) flags |= NCURIQUERY;
|
|
|
|
ncurisetquery(url,tree->constraint);
|
|
|
|
readurl = ncuribuild(url,NULL,".dods",flags);
|
2012-08-01 04:34:13 +08:00
|
|
|
MEMCHECK(readurl,OC_ENOMEM);
|
|
|
|
if (ocdebug > 0)
|
|
|
|
{fprintf(stderr, "fetch url=%s\n", readurl);fflush(stderr);}
|
|
|
|
stat = ocfetchurl_file(state->curl, readurl, tree->data.file,
|
|
|
|
&tree->data.datasize, &lastmod);
|
|
|
|
if(stat == OC_NOERR)
|
|
|
|
state->datalastmodified = lastmod;
|
|
|
|
if (ocdebug > 0)
|
|
|
|
{fprintf(stderr,"fetch complete\n"); fflush(stderr);}
|
|
|
|
}
|
|
|
|
free(readurl);
|
|
|
|
}
|
|
|
|
return OCTHROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
readfiletofile(const char* path, const char* suffix, FILE* stream, off_t* sizep)
|
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
2017-03-09 08:01:10 +08:00
|
|
|
NCbytes* packet = ncbytesnew();
|
2012-08-01 04:34:13 +08:00
|
|
|
size_t len;
|
|
|
|
/* check for leading file:/// */
|
|
|
|
if(ocstrncmp(path,"file:///",8)==0) path += 7; /* assume absolute path*/
|
|
|
|
stat = readfile(path,suffix,packet);
|
2012-08-22 00:46:10 +08:00
|
|
|
#ifdef OCDEBUG
|
|
|
|
fprintf(stderr,"readfiletofile: packet.size=%lu\n",
|
2017-03-09 08:01:10 +08:00
|
|
|
(unsigned long)ncbyteslength(packet));
|
2012-08-22 00:46:10 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
if(stat != OC_NOERR) goto unwind;
|
2017-03-09 08:01:10 +08:00
|
|
|
len = nclistlength(packet);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(stat == OC_NOERR) {
|
|
|
|
size_t written;
|
|
|
|
fseek(stream,0,SEEK_SET);
|
2017-03-09 08:01:10 +08:00
|
|
|
written = fwrite(ncbytescontents(packet),1,len,stream);
|
2012-08-22 00:46:10 +08:00
|
|
|
if(written != len) {
|
|
|
|
#ifdef OCDEBUG
|
|
|
|
fprintf(stderr,"readfiletofile: written!=length: %lu :: %lu\n",
|
|
|
|
(unsigned long)written,(unsigned long)len);
|
|
|
|
#endif
|
|
|
|
stat = OC_EIO;
|
|
|
|
}
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
if(sizep != NULL) *sizep = len;
|
|
|
|
unwind:
|
2017-03-09 08:01:10 +08:00
|
|
|
ncbytesfree(packet);
|
2012-08-01 04:34:13 +08:00
|
|
|
return OCTHROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-03-09 08:01:10 +08:00
|
|
|
readfile(const char* path, const char* suffix, NCbytes* packet)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int stat = OC_NOERR;
|
|
|
|
char filename[1024];
|
|
|
|
/* check for leading file:/// */
|
|
|
|
if(ocstrncmp(path,"file://",7)==0) path += 7; /* assume absolute path*/
|
2021-05-15 01:33:03 +08:00
|
|
|
strncpy(filename,path,sizeof(filename));
|
|
|
|
strlcat(filename,(suffix != NULL ? suffix : ""),sizeof(filename));
|
2017-09-03 08:09:36 +08:00
|
|
|
stat = NC_readfile(filename,packet);
|
2012-08-01 04:34:13 +08:00
|
|
|
return OCTHROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|