mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-01 17:06:03 +08:00
fix user+password;also the bad-name problem;also merged libncdap3+ncdap4->libdap2
This commit is contained in:
parent
29e8619787
commit
80d8926bad
168
configure.ac
168
configure.ac
@ -113,14 +113,13 @@ test "x$enable_netcdf_4" = xno || enable_netcdf_4=yes
|
||||
AC_MSG_RESULT([$enable_netcdf_4])
|
||||
|
||||
# Synonym
|
||||
# --enable-netcdf-4 is the controlling enable switch
|
||||
if test "x$enable_netcdf_4" = "x" ; then
|
||||
AC_ARG_ENABLE([netcdf4], [AS_HELP_STRING([--enable-netcdf4],
|
||||
# --disable-netcdf-4 is the controlling switch
|
||||
AC_ARG_ENABLE([netcdf4], [AS_HELP_STRING([--disable-netcdf4],
|
||||
[build with netcdf-4 (HDF5 and zlib required)])])
|
||||
enable_netcdf_4="$enable_netcdf4"
|
||||
else
|
||||
enable_netcdf4="$enable_netcdf_4"
|
||||
if test "x$enable_netcdf4" = xno ; then
|
||||
enable_netcdf_4=no
|
||||
fi
|
||||
AC_MSG_RESULT([$enable_netcdf_4])
|
||||
|
||||
# Does the user want to also build the libcf library?
|
||||
AC_MSG_CHECKING([whether libcf is to be built])
|
||||
@ -250,29 +249,12 @@ AC_ARG_ENABLE([logging],
|
||||
test "x$enable_logging" = xyes || enable_logging=no
|
||||
AC_MSG_RESULT([$enable_logging])
|
||||
|
||||
# Capture the state of the --enable-cdmremote flag
|
||||
AC_MSG_CHECKING([whether cdmremote client is to be built])
|
||||
AC_ARG_ENABLE([cdmremote],
|
||||
[AS_HELP_STRING([--enable-cdmremote],
|
||||
[build with cdmremote client support.])])
|
||||
test "x$enable_cdmremote" = xyes || enable_cdmremote=no
|
||||
# CDMREMOTE requires netCDF-4
|
||||
if test "x$enable_netcdf_4" = "xno" ; then enable_cdmremote=no ; fi
|
||||
AC_MSG_RESULT($enable_cdmremote)
|
||||
|
||||
# Figure out if curl support should be enabled.
|
||||
# The primary goal is to first locate curl-config
|
||||
# or the curl library location
|
||||
# The rules we implement are applied in order:
|
||||
# 1. no: if --disable-dap is set
|
||||
# 2. no: if curl library cannot be located
|
||||
# 3. yes: if --enable-dap || --enable-cdmremote is set
|
||||
# 4. yes: if neither --enable-dap nor --disable-dap is specified
|
||||
# and the curl library can be located
|
||||
# true if --enable-dap
|
||||
# true if --enable-cdmremote
|
||||
# false otherwise
|
||||
# Note that for now, cdmremote must be explicitly enabled
|
||||
|
||||
# First capture all the info unconditionally
|
||||
|
||||
# Capture the state of the --enable-dap flag
|
||||
AC_MSG_CHECKING([whether DAP client is to be built])
|
||||
AC_ARG_ENABLE([dap],
|
||||
@ -281,129 +263,35 @@ AC_ARG_ENABLE([dap],
|
||||
test "x$enable_dap" = xno || enable_dap=yes
|
||||
AC_MSG_RESULT($enable_dap)
|
||||
|
||||
# If --disable-dap && --disable cdmremote , then libcurl is not required
|
||||
if test "x$enable_dap" = "xyes" -o "x$enable_cdmremote" = "xyes" ; then
|
||||
require_curl=yes
|
||||
# Capture the state of the --enable-cdmremote flag
|
||||
AC_MSG_CHECKING([whether cdmremote client is to be built])
|
||||
AC_ARG_ENABLE([cdmremote],
|
||||
[AS_HELP_STRING([--enable-cdmremote],
|
||||
[build with cdmremote client support; requires netcdf4.])])
|
||||
test "x$enable_cdmremote" = xyes || enable_cdmremote=no
|
||||
|
||||
# BTW: CDMREMOTE requires netCDF-4
|
||||
if test "x$enable_netcdf_4" = "xno" ; then enable_cdmremote=no ; fi
|
||||
AC_MSG_RESULT($enable_cdmremote)
|
||||
|
||||
# Try to locate curl-config in path
|
||||
if curl-config --version > /dev/null ; then
|
||||
curl_cflags=`curl-config --cflags`
|
||||
curl_libs=`curl-config --libs`
|
||||
curl_dir=`curl-config --prefix`
|
||||
else
|
||||
require_curl=no
|
||||
AC_MSG_NOTICE([Cannot execute curl-config; ignored])
|
||||
curl_cflags=""
|
||||
curl_libs=""
|
||||
curl_dir=""
|
||||
fi
|
||||
|
||||
# Try to locate curl-config
|
||||
#
|
||||
AC_ARG_WITH([curl-config], [AS_HELP_STRING([--with-curl-config=<path>],
|
||||
[Specify path (or the containing directory) of the curl-config program; libcurl is required for opendap.])],
|
||||
[],[])
|
||||
|
||||
AC_MSG_CHECKING([whether a path for curl-config was specified])
|
||||
if test "x$with_curl_config" = "x" ; then
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
AC_MSG_RESULT([$with_curl_config])
|
||||
fi
|
||||
|
||||
# Alternatively, allow specification of the curl installation directory
|
||||
AC_MSG_CHECKING([whether a location for curl installation was specified])
|
||||
AC_ARG_WITH([curl], [AS_HELP_STRING([--with-curl=<directory>.],
|
||||
[Specify location of CURL library; libcurl is required for opendap. Configure will expect to find subdirs bin, include and lib.])],
|
||||
[],[])
|
||||
if test "x$with_curl" = "x" ; then
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
AC_MSG_RESULT([$with_curl])
|
||||
fi
|
||||
|
||||
# Remaining computations are only invoked if curl is required.
|
||||
if test "$require_curl" = yes ; then
|
||||
|
||||
# Tag to indicate where curl info came from
|
||||
curlsrc=
|
||||
|
||||
if test "x$with_curl_config" != "x" ; then
|
||||
curlsrc="withconfig"
|
||||
elif test "x$with_curl" != "x" ; then
|
||||
curlsrc="withcurl"
|
||||
else
|
||||
curlsrc=""
|
||||
fi
|
||||
|
||||
# if curl source was --with-curl
|
||||
# then try to locate curl-config
|
||||
|
||||
if test "x$curlsrc" = "xwithcurl" ; then
|
||||
# look for curl-config in --with-curl directory
|
||||
if $with_curl/bin/curl-config --version >/dev/null 2>&1 ; then
|
||||
# Pretend that --with-curl-config was specified
|
||||
with_curl_config="$with_curl/bin/curl-config"
|
||||
curlsrc="withconfig"
|
||||
fi
|
||||
elif test "x$curlsrc" = "xwithconfig" ; then
|
||||
# look for curl-config using --with-curl-config,
|
||||
# allow for some errors in specifying.
|
||||
if $with_curl_config --version >/dev/null 2>&1 ; then
|
||||
# User specified curl-config directly
|
||||
with_curl_config="$with_curl_config"
|
||||
elif $with_curl_config/curl-config --version >/dev/null 2>&1 ; then
|
||||
# User specified curl-config parent directory
|
||||
with_curl_config="$with_curl_config/curl-config"
|
||||
elif $with_curl_config/bin/curl-config --version >/dev/null 2>&1 ; then
|
||||
# User specified same dir as --with-curl
|
||||
with_curl_config="$with_curl_config/bin/curl-config"
|
||||
else
|
||||
AC_MSG_ERROR([Erroneous --with-curl-config value: ${with_curl_config}])
|
||||
with_curl_config="" # not found
|
||||
fi
|
||||
else
|
||||
# look for curl-config in the path
|
||||
if curl-config --version >/dev/null 2>&1 ; then
|
||||
with_curl_config="curl-config"
|
||||
curlsrc="withconfig"
|
||||
fi
|
||||
fi
|
||||
|
||||
# report on finding of curl-config
|
||||
AC_MSG_CHECKING([checking whether a location for curl-config found])
|
||||
if test "x$with_curl_config" = "x" ; then
|
||||
AC_MSG_RESULT([no])
|
||||
else
|
||||
AC_MSG_RESULT([${with_curl_config}])
|
||||
fi
|
||||
|
||||
# Compute the curl flags and libs
|
||||
if test "x$with_curl_config" != "x" ; then
|
||||
curl_cflags=`$with_curl_config --cflags`
|
||||
curl_libs=`$with_curl_config --libs`
|
||||
curl_dir=`$with_curl_config --prefix`
|
||||
elif test "x$with_curl" != "x" ; then
|
||||
curl_libs="-L$with_curl/lib -lcurl"
|
||||
curl_cflags="-I$with_curl/include"
|
||||
curl_dir="$with_curl"
|
||||
else
|
||||
AC_MSG_ERROR([Cannot locate neither curl-config or a curl directory])
|
||||
fi
|
||||
|
||||
else #!require_curl
|
||||
|
||||
curl_cflags=""
|
||||
curl_libs=""
|
||||
curl_dir=""
|
||||
|
||||
fi #require_curl
|
||||
|
||||
AC_SUBST([CURL_CFLAGS],[${curl_cflags}])
|
||||
AC_SUBST([CURL_FCFLAGS],[${curl_cflags}])
|
||||
AC_SUBST([CURL_FFLAGS],[${curl_cflags}])
|
||||
AC_SUBST([CURL_LIBS],[${curl_libs}])
|
||||
AC_SUBST([CURLDIR],[${curl_dir}])
|
||||
|
||||
# If curl is required but there is no curl, then complain
|
||||
if test "x$curlsrc" = "x" ; then
|
||||
if test "x$require_curl" = "xyes" ; then
|
||||
AC_MSG_NOTICE([libcurl not found; disabling dap and cdmremote support])
|
||||
fi
|
||||
enable_dap=no
|
||||
enable_cdmremote=no
|
||||
fi
|
||||
|
||||
# Default is now to always do the short remote tests
|
||||
AC_MSG_CHECKING([whether dap remote testing should be enabled (default on)])
|
||||
AC_ARG_ENABLE([dap-remote-tests],
|
||||
|
@ -1,48 +1,54 @@
|
||||
/*********************************************************************
|
||||
* Copyright 2010, UCAR/Unidata
|
||||
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
||||
*********************************************************************/
|
||||
/* $Id$ */
|
||||
/* $Header$ */
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#ifndef NC_URL_H
|
||||
#define NC_URL_H
|
||||
|
||||
#include "nclist.h"
|
||||
|
||||
/*! This is an open structure meaning
|
||||
it is ok to directly access its fields*/
|
||||
typedef struct NC_URL {
|
||||
char* wholeurl; /* as passed by the caller */
|
||||
char* url; /* !< without bracketed parameters */
|
||||
char* base; /*!< without constraints*/
|
||||
char* url; /* as passed by the caller */
|
||||
char* protocol;
|
||||
char* constraint;
|
||||
char* user; /* from user:password@ */
|
||||
char* password; /* from user:password@ */
|
||||
char* host; /*!< host*/
|
||||
char* port; /*!< host */
|
||||
char* file; /*!< file */
|
||||
char* constraint; /*!< projection+selection */
|
||||
char* projection; /*!< without leading '?'*/
|
||||
char* selection; /*!< with leading '&'*/
|
||||
char* params;
|
||||
NClist* parammap;
|
||||
char* params; /* all params */
|
||||
char** paramlist; /*!<null terminated list */
|
||||
} NC_URL;
|
||||
|
||||
extern int nc_urlparse(const char* s, NC_URL**);
|
||||
extern int nc_urlparse(const char* s, NC_URL** nc_url);
|
||||
extern void nc_urlfree(NC_URL* nc_url);
|
||||
|
||||
/* Replace the constraints */
|
||||
extern void nc_urlsetconstraints(NC_URL*,const char* constraints);
|
||||
|
||||
/* Replace the protocol */
|
||||
extern void nc_urlsetprotocol(NC_URL*,const char* newprotocol);
|
||||
/* Construct a complete NC_ URL; caller frees returned string */
|
||||
|
||||
/* Construct a complete URL; caller frees returned string */
|
||||
extern char* nc_urlgeturl(NC_URL*,const char* prefix, const char* suffix, int withconstraints);
|
||||
/* Define flags to control what is included */
|
||||
#define NC_URLCONSTRAINTS 1
|
||||
#define NC_URLUSERPWD 2
|
||||
#define NC_URLPARAMS 4
|
||||
|
||||
extern char* nc_urlgeturl(NC_URL*,const char* prefix, const char* suffix, int flags);
|
||||
|
||||
extern int nc_urldecodeparams(NC_URL* nc_url);
|
||||
|
||||
/*! NULL result => entry not found.
|
||||
Empty value should be represented as a zero length list */
|
||||
extern NClist* nc_urllookup(NC_URL*, const char* clientparam);
|
||||
Empty value should be represented as a zero length string */
|
||||
extern const char* nc_urllookup(NC_URL*, const char* param);
|
||||
|
||||
|
||||
extern char** nc_paramdecode(char* params0);
|
||||
extern const char* nc_paramlookup(char** params, const char* key);
|
||||
extern void nc_paramfree(char** params);
|
||||
extern int nc_paramdelete(char** params, const char* key);
|
||||
extern char** nc_paraminsert(char** params, const char* key, const char* value);
|
||||
extern int nc_paramreplace(char** params, const char* key, const char* value);
|
||||
|
||||
/* Convenience: search a list for a given string; NULL if not found */
|
||||
extern const char* nc_urllookupvalue(NClist* list, const char* value);
|
||||
|
||||
#endif /*NC_URL_H*/
|
||||
|
@ -104,6 +104,10 @@ prefetchdata3(NCDAPCOMMON* nccomm)
|
||||
/* If var is a sequence or under a sequence, then never prefetch */
|
||||
if(var->nctype == NC_Sequence || dapinsequence(var)) continue;
|
||||
|
||||
/* If the var name is a bad name like "var_nm.dot" then
|
||||
suppress it
|
||||
*/
|
||||
|
||||
/* Compute the # of elements in the variable */
|
||||
for(j=0;j<nclistlength(var->array.dimensions);j++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(var->array.dimensions,j);
|
||||
|
@ -73,6 +73,8 @@ computevarnodes3(NCDAPCOMMON* nccomm, NClist* allnodes, NClist* varnodes)
|
||||
NClist* allvarnodes = nclistnew();
|
||||
for(i=0;i<nclistlength(allnodes);i++) {
|
||||
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
|
||||
/* If this node has a bad name, make it invisible */
|
||||
if(dap_badname(node->name)) node->visible = 0;
|
||||
if(!node->visible) continue;
|
||||
if(node->nctype == NC_Primitive)
|
||||
nclistpush(allvarnodes,(ncelem)node);
|
||||
|
@ -70,6 +70,8 @@ computevarnodes4(NCDAPCOMMON* nccomm, NClist* varnodes)
|
||||
|
||||
for(i=0;i<nclistlength(toplevel);i++) {
|
||||
CDFnode* var = (CDFnode*)nclistget(toplevel,i);
|
||||
/* If this node has a bad name, make it invisible */
|
||||
if(dap_badname(var->name)) var->visible = 0;
|
||||
if(!var->visible) continue;
|
||||
if(var->nctype == NC_Sequence && singletonsequence(var)) {
|
||||
var->singleton = 1;
|
||||
|
@ -394,7 +394,7 @@ makegetvar34(NCDAPCOMMON* nccomm, CDFnode* var, void* data, nc_type dsttype, Get
|
||||
}
|
||||
|
||||
int
|
||||
constrainable34(DAPURL* durl)
|
||||
constrainable34(OCURI* durl)
|
||||
{
|
||||
char** protocol = constrainableprotocols;
|
||||
for(;*protocol;protocol++) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "dapodom.h"
|
||||
#include "dapdebug.h"
|
||||
#include "dapdump.h"
|
||||
#include "dceparselex.h"
|
||||
|
||||
static NCerror mergeprojection31(DCEprojection*, DCEprojection*);
|
||||
|
||||
@ -42,16 +43,19 @@ parsedapconstraints(NCDAPCOMMON* dapcomm, char* constraints,
|
||||
nclistclear(dceconstraint->projections);
|
||||
nclistclear(dceconstraint->selections);
|
||||
} else {
|
||||
int i;
|
||||
NClist* allnodes;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"constraint: %s",dumpconstraint(dceconstraint));
|
||||
#endif
|
||||
|
||||
#ifdef FIX
|
||||
int i;
|
||||
NClist* allnodes;
|
||||
/* Go thru each node and add annotation */
|
||||
allnodes = dceallnodes((DCEnode*)dceconstraint,CES_NIL);
|
||||
for(i=0;i<nclistlength(allnodes);i++) {
|
||||
DCEnode* node = (DCEnode*)nclistget(allnodes,i);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ncstat;
|
||||
}
|
||||
@ -566,9 +570,8 @@ fprintf(stderr,"restriction.after=|%s|\n",
|
||||
return;
|
||||
}
|
||||
|
||||
/* Return 1 if the specified var is in
|
||||
the projection's leaf's subtree and is
|
||||
visible
|
||||
/* Return 1 if the specified var is in the projection's
|
||||
leaf's subtree and is visible
|
||||
*/
|
||||
|
||||
static int
|
||||
|
@ -26,18 +26,18 @@ extern int oc_dumpnode(OClink, OCobject);
|
||||
int
|
||||
nc__testurl(const char* path, char** basenamep)
|
||||
{
|
||||
DAPURL url;
|
||||
int ok = dapurlparse(path,&url);
|
||||
OCURI* url;
|
||||
int ok = ocuriparse(path,&url);
|
||||
if(ok) {
|
||||
char* slash = strrchr(url.base, '/');
|
||||
char* slash = strrchr(url->file, '/');
|
||||
char* dot;
|
||||
if(slash == NULL) slash = (char*)path; else slash++;
|
||||
slash = nulldup(slash);
|
||||
dot = strrchr(slash, '.');
|
||||
if(dot != NULL && dot != slash) *dot = '\0';
|
||||
if(basenamep) *basenamep=slash ; else free(slash);
|
||||
ocurifree(url);
|
||||
}
|
||||
dapurlclear(&url);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -722,107 +722,6 @@ daptoplevel(CDFnode* node)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Client parameters are assumed to be
|
||||
one or more instances of bracketed pairs:
|
||||
e.g "[...][...]...".
|
||||
The bracket content in turn is assumed to be a
|
||||
comma separated list of <name>=<value> pairs.
|
||||
e.g. x=y,z=,a=b.
|
||||
If the same parameter is specifed more than once,
|
||||
then the first occurrence is used; this is so that
|
||||
is possible to forcibly override user specified
|
||||
parameters by prefixing.
|
||||
IMPORTANT: client parameter string is assumed to
|
||||
have blanks compress out.
|
||||
*/
|
||||
|
||||
NClist*
|
||||
dapparamdecode(char* params0)
|
||||
{
|
||||
char* cp;
|
||||
char* cq;
|
||||
int c;
|
||||
int i;
|
||||
int nparams;
|
||||
NClist* plist = nclistnew();
|
||||
char* params;
|
||||
char* params1;
|
||||
|
||||
if(params0 == NULL) return plist;
|
||||
|
||||
/* Kill the leading "[" and trailing "]" */
|
||||
if(params0[0] == '[')
|
||||
params = nulldup(params0+1);
|
||||
else
|
||||
params = nulldup(params0);
|
||||
|
||||
params[strlen(params)-1] = '\0';
|
||||
|
||||
params1 = nulldup(params);
|
||||
|
||||
/* Pass 1 to replace "][" pairs with ','*/
|
||||
cp=params; cq = params1;
|
||||
while((c=*cp++)) {
|
||||
if(c == RBRACKET && *cp == LBRACKET) {cp++; c = ',';}
|
||||
*cq++ = c;
|
||||
}
|
||||
*cq = '\0';
|
||||
free(params);
|
||||
params = params1;
|
||||
|
||||
/* Pass 2 to break string into pieces and count # of pairs */
|
||||
nparams=0;
|
||||
for(cp=params;(c=*cp);cp++) {
|
||||
if(c == ',') {*cp = '\0'; nparams++;}
|
||||
}
|
||||
nparams++; /* for last one */
|
||||
|
||||
/* Pass 3 to break up each pass into a (name,value) pair*/
|
||||
/* and insert into the param list */
|
||||
/* parameters of the form name name= are converted to name=""*/
|
||||
cp = params;
|
||||
for(i=0;i<nparams;i++) {
|
||||
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
|
||||
char* vp;
|
||||
/*break up the ith param*/
|
||||
vp = strchr(cp,'=');
|
||||
if(vp != NULL) {*vp = '\0'; vp++;} else {vp = "";}
|
||||
if(!nclistcontains(plist,(ncelem)cp)) {
|
||||
nclistpush(plist,(ncelem)nulldup(cp));
|
||||
nclistpush(plist,(ncelem)nulldup(vp));
|
||||
}
|
||||
cp = next;
|
||||
}
|
||||
free(params);
|
||||
return plist;
|
||||
}
|
||||
|
||||
const char*
|
||||
dapparamlookup(NClist* params, const char* clientparam)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || clientparam == NULL) return NULL;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
char* name = (char*)nclistget(params,i);
|
||||
if(strcmp(clientparam,name)==0)
|
||||
return (char*)nclistget(params,i+1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
dapparamfree(NClist* params)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL) return;
|
||||
for(i=0;i<nclistlength(params);i++) {
|
||||
nullfree((void*)nclistget(params,i));
|
||||
}
|
||||
nclistfree(params);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
modeldecode(int translation, const char* smodel,
|
||||
const struct NCTMODEL* models,
|
||||
@ -967,9 +866,9 @@ dap_oc_fetch(NCDAPCOMMON* nccomm, OCconnection conn, const char* ce,
|
||||
if(ce != NULL && strlen(ce) == 0) ce = NULL;
|
||||
if(FLAGSET(nccomm->controls,NCF_SHOWFETCH)) {
|
||||
if(ce == NULL)
|
||||
nclog(NCLOGNOTE,"fetch: %s.%s",nccomm->oc.url.base,ext);
|
||||
nclog(NCLOGNOTE,"fetch: %s.%s",nccomm->oc.url->uri,ext);
|
||||
else
|
||||
nclog(NCLOGNOTE,"fetch: %s.%s?%s",nccomm->oc.url.base,ext,ce);
|
||||
nclog(NCLOGNOTE,"fetch: %s.%s?%s",nccomm->oc.url->uri,ext,ce);
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
gettimeofday(&time0,NULL);
|
||||
#endif
|
||||
@ -987,3 +886,17 @@ dap_oc_fetch(NCDAPCOMMON* nccomm, OCconnection conn, const char* ce,
|
||||
}
|
||||
return ocstat;
|
||||
}
|
||||
|
||||
/* Mark names that cause problems. e.g. "nm.dot" */
|
||||
static char* badchars = "./";
|
||||
int
|
||||
dap_badname(char* name)
|
||||
{
|
||||
char* p;
|
||||
if(name == NULL) return 0;
|
||||
for(p=badchars;*p;p++) {
|
||||
if(strchr(name,*p) != NULL)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -49,11 +49,14 @@ extern int dapgridmap(struct CDFnode* node);
|
||||
extern int dapgridarray(struct CDFnode* node);
|
||||
extern int dapgridelement(struct CDFnode* node);
|
||||
|
||||
#ifdef IGNORE
|
||||
/* Provide alternate path to the url parameters;
|
||||
one that does not require that an OCconnection exist */
|
||||
extern NClist* dapparamdecode(char*);
|
||||
extern void dapparamfree(NClist*);
|
||||
extern const char* dapparamlookup(NClist*, const char*);
|
||||
extern char** dapparamdecode(char*);
|
||||
extern void dapparamfree(char**);
|
||||
extern const char* dapparamlookup(char**, const char*);
|
||||
#endif
|
||||
|
||||
extern unsigned int modeldecode(int, const char*, const struct NCTMODEL*, unsigned int);
|
||||
extern unsigned long getlimitnumber(const char* limit);
|
||||
|
||||
@ -68,4 +71,6 @@ extern int nc__testurl(const char* path, char** basename);
|
||||
/* Provide a wrapper for oc_fetch so we can log what it does */
|
||||
extern OCerror dap_oc_fetch(struct NCDAPCOMMON*,OCconnection,const char*,OCdxd,OCobject*);
|
||||
|
||||
extern int dap_badname(char* name);
|
||||
|
||||
#endif /*DAPUTIL_H*/
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "netcdf.h"
|
||||
#include "dceconstraints.h"
|
||||
#include "dceparselex.h"
|
||||
#include "dapdebug.h"
|
||||
|
||||
#define DEBUG
|
||||
@ -27,7 +28,7 @@
|
||||
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
|
||||
#endif
|
||||
#ifndef nullfree
|
||||
#define nullfree(s) if((s)!=NULL) {free(s);} else {}
|
||||
#define nullfree(s) {if((s)!=NULL) {free(s);}}
|
||||
#endif
|
||||
|
||||
static char* opstrings[] = OPSTRINGS ;
|
||||
@ -271,7 +272,6 @@ buildconstraintstring(DCEconstraint* constraints)
|
||||
DCEnode*
|
||||
dceclone(DCEnode* node)
|
||||
{
|
||||
int i;
|
||||
DCEnode* result = NULL;
|
||||
|
||||
result = (DCEnode*)dcecreate(node->sort);
|
||||
@ -387,8 +387,6 @@ dceclonelist(NClist* list)
|
||||
void
|
||||
dcefree(DCEnode* node)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(node == NULL) return;
|
||||
|
||||
switch (node->sort) {
|
||||
@ -734,14 +732,14 @@ dcecreate(CEsort sort)
|
||||
DCEconstant* target = (DCEconstant*)calloc(1,sizeof(DCEconstant));
|
||||
if(target == NULL) return NULL;
|
||||
node = (DCEnode*)target;
|
||||
target->discrim == CES_NIL;
|
||||
target->discrim = CES_NIL;
|
||||
} break;
|
||||
|
||||
case CES_VALUE: {
|
||||
DCEvalue* target = (DCEvalue*)calloc(1,sizeof(DCEvalue));
|
||||
if(target == NULL) return NULL;
|
||||
node = (DCEnode*)target;
|
||||
target->discrim == CES_NIL;
|
||||
target->discrim = CES_NIL;
|
||||
} break;
|
||||
|
||||
case CES_VAR: {
|
||||
@ -806,9 +804,7 @@ int
|
||||
dceiswholesegment(DCEsegment* seg)
|
||||
{
|
||||
int i,whole;
|
||||
NClist* dimset = NULL;
|
||||
unsigned int rank;
|
||||
|
||||
|
||||
if(!seg->slicesdefined) return 0; /* actually, we don't know */
|
||||
whole = 1; /* assume so */
|
||||
for(i=0;i<seg->rank;i++) {
|
||||
|
@ -95,6 +95,7 @@ extern Object debugobject(Object);
|
||||
#endif
|
||||
|
||||
extern int dapceparse(char* input, DCEconstraint*, char**);
|
||||
extern int dceerror(DCEparsestate* state, char* msg);
|
||||
|
||||
#endif /*DCEPARSELEX_H*/
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
set PARMS=""; set ARGS=""; set CON="" ; set CE=""; set OCON=""
|
||||
set PARMS="[log]"
|
||||
|
||||
set F="file://${HOME}/dmh/ncdap_test/testdata3/synth3"
|
||||
set F="http://motherlode.ucar.edu:8080/thredds/dodsC/testdods/in.nc"
|
||||
if (1 == 0) then
|
||||
set F="http://tiggeUser:tigge@motherlode.ucar.edu:9080/thredds/dodsC/restrict/testdata/testData.nc"
|
||||
set F="http://jcaron:boulder@www.giss.nasa.gov/staff/rschmunk/test/file1.nc"
|
||||
set F="http://jcaron:boulder@www.giss.nasa.gov/staff/rschmunk/test/file2.nc"
|
||||
set F="file:///home/dmh/nc/oc/dataset-duacs-nrt-over30d-global-merged-madt-h"
|
||||
set F="http://oceanwatch.pfeg.noaa.gov/opendap/GLOBEC/GLOBEC_cetaceans"
|
||||
set CON="number&number>6"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef nullfree
|
||||
#define nullfree(m) if((m)!=NULL) {free(m);} else {}
|
||||
#define nullfree(M) {if((M)!=NULL) {free(M);}}
|
||||
#endif
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ typedef struct NCcache {
|
||||
typedef struct NCOC {
|
||||
OCconnection conn;
|
||||
char* urltext; /* as given to nc3d_open*/
|
||||
DAPURL url; /* as given to nc3d_open and parsed*/
|
||||
OCURI* url; /* as given to nc3d_open and parsed*/
|
||||
OCobject ocdasroot;
|
||||
DCEconstraint* dapconstraint; /* from url */
|
||||
} NCOC;
|
||||
@ -306,7 +306,7 @@ extern void unattach34(CDFnode*);
|
||||
extern int nodematch34(CDFnode* node1, CDFnode* node2);
|
||||
extern int simplenodematch34(CDFnode* node1, CDFnode* node2);
|
||||
extern CDFnode* findxnode34(CDFnode* target, CDFnode* xroot);
|
||||
extern int constrainable34(DAPURL*);
|
||||
extern int constrainable34(OCURI*);
|
||||
extern char* makeconstraintstring34(DCEconstraint*);
|
||||
extern size_t estimatedataddssize34(CDFnode* datadds);
|
||||
extern void restrictprojection34(NClist*, NClist*);
|
||||
|
@ -73,7 +73,7 @@ NCD3_open(const char * path, int mode,
|
||||
OCerror ocstat = OC_NOERR;
|
||||
NCDAP3* drno = NULL;
|
||||
char* modifiedpath;
|
||||
DAPURL tmpurl;
|
||||
OCURI* tmpurl;
|
||||
char* ce = NULL;
|
||||
int ncid = -1;
|
||||
const char* value;
|
||||
@ -83,8 +83,8 @@ NCD3_open(const char * path, int mode,
|
||||
if(!nc3dinitialized) nc3dinitialize();
|
||||
|
||||
|
||||
if(!dapurlparse(path,&tmpurl)) PANIC("libncdap3: non-url path");
|
||||
dapurlclear(&tmpurl); /* no longer needed */
|
||||
if(!ocuriparse(path,&tmpurl)) PANIC("libncdap3: non-url path");
|
||||
ocurifree(tmpurl); /* no longer needed */
|
||||
|
||||
#ifdef OCCOMPILEBYDEFAULT
|
||||
/* set the compile flag by default */
|
||||
@ -117,8 +117,8 @@ NCD3_open(const char * path, int mode,
|
||||
/* Setup tentative DRNO state*/
|
||||
drno->dap.controller = (NC*)drno;
|
||||
drno->dap.oc.urltext = modifiedpath;
|
||||
dapurlparse(drno->dap.oc.urltext,&drno->dap.oc.url);
|
||||
if(!constrainable34(&drno->dap.oc.url))
|
||||
ocuriparse(drno->dap.oc.urltext,&drno->dap.oc.url);
|
||||
if(!constrainable34(drno->dap.oc.url))
|
||||
SETFLAG(drno->dap.controls,NCF_UNCONSTRAINABLE);
|
||||
drno->dap.cdf.separator = ".";
|
||||
drno->dap.cdf.smallsizelimit = DFALTSMALLLIMIT;
|
||||
@ -134,15 +134,15 @@ NCD3_open(const char * path, int mode,
|
||||
|
||||
/* Check to see if we are unconstrainable */
|
||||
if(FLAGSET(drno->dap.controls,NCF_UNCONSTRAINABLE)) {
|
||||
if(drno->dap.oc.url.constraint != NULL
|
||||
&& strlen(drno->dap.oc.url.constraint) > 0) {
|
||||
if(drno->dap.oc.url->constraint != NULL
|
||||
&& strlen(drno->dap.oc.url->constraint) > 0) {
|
||||
nclog(NCLOGWARN,"Attempt to constrain an unconstrainable data source: %s",
|
||||
drno->dap.oc.url.constraint);
|
||||
drno->dap.oc.url->constraint);
|
||||
}
|
||||
/* ignore all constraints */
|
||||
} else {
|
||||
/* Parse constraints to make sure that they are syntactically correct */
|
||||
ncstat = parsedapconstraints(&drno->dap,drno->dap.oc.url.constraint,drno->dap.oc.dapconstraint);
|
||||
ncstat = parsedapconstraints(&drno->dap,drno->dap.oc.url->constraint,drno->dap.oc.dapconstraint);
|
||||
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@ -276,7 +276,7 @@ done:
|
||||
cleanNCDAP3(drno);
|
||||
NC3_abort(ncid);
|
||||
}
|
||||
if(ce) nullfree(ce);
|
||||
if(ce!=NULL) nullfree(ce);
|
||||
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
|
||||
return THROW(ncstat);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "dceconstraints.h"
|
||||
|
||||
#include "oc.h"
|
||||
#include "dapurl.h"
|
||||
#include "ocuri.h"
|
||||
|
||||
#include "nc.h"
|
||||
#include "netcdf.h"
|
||||
|
@ -47,7 +47,7 @@ cleanNCDAPCOMMON(NCDAPCOMMON* nccomm)
|
||||
oc_root_free(nccomm->oc.conn,nccomm->oc.ocdasroot);
|
||||
nccomm->oc.ocdasroot = NULL;
|
||||
oc_close(nccomm->oc.conn); /* also reclaims remaining OC trees */
|
||||
dapurlclear(&nccomm->oc.url);
|
||||
ocurifree(nccomm->oc.url);
|
||||
nullfree(nccomm->oc.urltext);
|
||||
|
||||
dcefree((DCEnode*)nccomm->oc.dapconstraint);
|
||||
@ -534,8 +534,8 @@ computeminconstraints3(NCDAPCOMMON* nccomm, CDFnode* seq, NCbytes* minconstraint
|
||||
}
|
||||
nclistfree(path);
|
||||
/* Finally, add in any selection from the original URL */
|
||||
if(nccomm->oc.url.selection != NULL)
|
||||
ncbytescat(minconstraints,nccomm->oc.url.selection);
|
||||
if(nccomm->oc.url->selection != NULL)
|
||||
ncbytescat(minconstraints,nccomm->oc.url->selection);
|
||||
nullfree(prefix);
|
||||
return NC_NOERR;
|
||||
}
|
||||
@ -609,7 +609,7 @@ fetchtemplatemetadata3(NCDAPCOMMON* nccomm)
|
||||
if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE))
|
||||
ce = NULL;
|
||||
else
|
||||
ce = nulldup(nccomm->oc.url.selection);
|
||||
ce = nulldup(nccomm->oc.url->selection);
|
||||
|
||||
/* Get selection constrained DDS */
|
||||
ocstat = dap_oc_fetch(nccomm,nccomm->oc.conn,ce,OCDDS,&ocroot);
|
||||
@ -617,7 +617,7 @@ fetchtemplatemetadata3(NCDAPCOMMON* nccomm)
|
||||
/* Special Hack. If the protocol is file, then see if
|
||||
we can get the dds from the .dods file
|
||||
*/
|
||||
if(strcmp(nccomm->oc.url.protocol,"file") != 0) {
|
||||
if(strcmp(nccomm->oc.url->protocol,"file") != 0) {
|
||||
THROWCHK(ocstat); goto done;
|
||||
}
|
||||
/* Fetch the data dds */
|
||||
@ -775,14 +775,10 @@ fixzerodims3(NCDAPCOMMON* nccomm)
|
||||
void
|
||||
applyclientparamcontrols3(NCDAPCOMMON* nccomm)
|
||||
{
|
||||
NClist* params = NULL;
|
||||
const char* value;
|
||||
|
||||
/* Get client parameters */
|
||||
params = dapparamdecode(nccomm->oc.url.params);
|
||||
|
||||
/* enable/disable caching */
|
||||
value = dapparamlookup(params,"cache");
|
||||
value = oc_clientparam_get(nccomm->oc.conn,"cache");
|
||||
if(value == NULL)
|
||||
SETFLAG(nccomm->controls,DFALTCACHEFLAG);
|
||||
else if(strlen(value) == 0)
|
||||
@ -797,8 +793,6 @@ applyclientparamcontrols3(NCDAPCOMMON* nccomm)
|
||||
|
||||
SETFLAG(nccomm->controls,(NCF_NC3|NCF_NCDAP));
|
||||
|
||||
/* No longer need params */
|
||||
dapparamfree(params);
|
||||
}
|
||||
|
||||
/* Accumulate a set of all the known dimensions */
|
||||
|
@ -1,4 +1,10 @@
|
||||
#include "ncdap4.h"
|
||||
/*********************************************************************
|
||||
* Copyright 1993, UCAR/Unidata
|
||||
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
||||
* $Header: /upc/share/CVS/netcdf-3/libnccommon/nccommon.h,v 1.40 2010/05/30 19:45:52 dmh Exp $
|
||||
*********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_GETRLIMIT
|
||||
#include <sys/time.h>
|
||||
@ -15,6 +21,9 @@
|
||||
#include "nc4dispatch.h"
|
||||
#include "ncd4dispatch.h"
|
||||
|
||||
#include "ncdap4.h"
|
||||
#include "oc.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "dapdump.h"
|
||||
#endif
|
||||
@ -70,7 +79,7 @@ NCD4_open(const char * path, int mode,
|
||||
{
|
||||
NCerror ncstat = NC_NOERR;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
DAPURL tmpurl;
|
||||
OCURI* tmpurl;
|
||||
NCDAP4* drno = NULL; /* reuse the ncdap3 structure*/
|
||||
NC_HDF5_FILE_INFO_T* h5 = NULL;
|
||||
NC_GRP_INFO_T *grp = NULL;
|
||||
@ -84,8 +93,8 @@ NCD4_open(const char * path, int mode,
|
||||
|
||||
if(!nc4dinitialized) nc4dinitialize();
|
||||
|
||||
if(!dapurlparse(path,&tmpurl)) PANIC("libncdap4: non-url path");
|
||||
dapurlclear(&tmpurl); /* no longer needed */
|
||||
if(!ocuriparse(path,&tmpurl)) PANIC("libncdap4: non-url path");
|
||||
ocurifree(tmpurl); /* no longer needed */
|
||||
|
||||
/* Check for legal mode flags */
|
||||
if((mode & NC_WRITE) != 0) ncstat = NC_EINVAL;
|
||||
@ -134,8 +143,8 @@ ocdebug = 1;
|
||||
drno->dap.controller = (NC*)drno;
|
||||
drno->dap.oc.urltext = modifiedpath;
|
||||
drno->dap.cdf.separator = ".";
|
||||
dapurlparse(drno->dap.oc.urltext,&drno->dap.oc.url);
|
||||
if(!constrainable34(&drno->dap.oc.url))
|
||||
ocuriparse(drno->dap.oc.urltext,&drno->dap.oc.url);
|
||||
if(!constrainable34(drno->dap.oc.url))
|
||||
SETFLAG(drno->dap.controls,NCF_UNCONSTRAINABLE);
|
||||
drno->dap.cdf.smallsizelimit = DFALTSMALLLIMIT;
|
||||
drno->dap.cdf.smallsizelimit = DFALTSMALLLIMIT;
|
||||
@ -166,15 +175,15 @@ ocdebug = 1;
|
||||
|
||||
/* Check to see if we are unconstrainable */
|
||||
if(FLAGSET(drno->dap.controls,NCF_UNCONSTRAINABLE)) {
|
||||
if(drno->dap.oc.url.constraint != NULL
|
||||
&& strlen(drno->dap.oc.url.constraint) > 0) {
|
||||
if(drno->dap.oc.url->constraint != NULL
|
||||
&& strlen(drno->dap.oc.url->constraint) > 0) {
|
||||
nclog(NCLOGWARN,"Attempt to constrain an unconstrainable data source: %s",
|
||||
drno->dap.oc.url.constraint);
|
||||
drno->dap.oc.url->constraint);
|
||||
}
|
||||
/* ignore all constraints */
|
||||
} else {
|
||||
/* Parse constraints to make sure that they are syntactically correct */
|
||||
ncstat = parsedapconstraints(&drno->dap,drno->dap.oc.url.constraint,drno->dap.oc.dapconstraint);
|
||||
ncstat = parsedapconstraints(&drno->dap,drno->dap.oc.url->constraint,drno->dap.oc.dapconstraint);
|
||||
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
|
||||
}
|
||||
|
||||
@ -775,14 +784,10 @@ cvtunlimiteddim(NCDAPCOMMON* nccomm, CDFnode* dim)
|
||||
static void
|
||||
applyclientparamcontrols4(NCDAPCOMMON* nccomm)
|
||||
{
|
||||
NClist* params = NULL;
|
||||
const char* value;
|
||||
|
||||
/* Get client parameters */
|
||||
params = dapparamdecode(nccomm->oc.url.params);
|
||||
|
||||
/* enable/disable caching */
|
||||
value = dapparamlookup(params,"cache");
|
||||
value = oc_clientparam_get(nccomm->oc.conn,"cache");
|
||||
if(value == NULL)
|
||||
SETFLAG(nccomm->controls,DFALTCACHEFLAG);
|
||||
else if(strlen(value) == 0)
|
||||
@ -793,6 +798,4 @@ applyclientparamcontrols4(NCDAPCOMMON* nccomm)
|
||||
/* Set the translation base */
|
||||
SETFLAG(nccomm->controls,NCF_NC4);
|
||||
|
||||
/* No longer need params */
|
||||
dapparamfree(params);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "nc.h"
|
||||
|
||||
#include "oc.h"
|
||||
#include "dapurl.h"
|
||||
#include "ocuri.h"
|
||||
|
||||
#include "nccommon.h"
|
||||
#include "ncdap3.h"
|
||||
|
@ -94,12 +94,12 @@ static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8[DIMSIZE];
|
||||
static unsigned char uint8[DIMSIZE];
|
||||
static short int16[DIMSIZE];
|
||||
static int int32[DIMSIZE];
|
||||
static float float32[DIMSIZE];
|
||||
static double float64[DIMSIZE];
|
||||
static signed char int8v[DIMSIZE];
|
||||
static unsigned char uint8v[DIMSIZE];
|
||||
static short int16v[DIMSIZE];
|
||||
static int int32v[DIMSIZE];
|
||||
static float float32v[DIMSIZE];
|
||||
static double float64v[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
@ -187,93 +187,93 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8,int8_data);
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8v,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8,uint8_data);
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8v,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32,int8toint32_data);
|
||||
COMPARE(NC_BYTE,NC_INT,int32v,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,int82float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16,int16_data);
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16v,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32,int16toint32_data);
|
||||
COMPARE(NC_SHORT,NC_INT,int32v,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32,int162float32_data);
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32v,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32,int32_data);
|
||||
COMPARE(NC_INT,NC_INT,int32v,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32,int32tofloat32_data);
|
||||
COMPARE(NC_INT,NC_FLOAT,float32v,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
@ -287,23 +287,23 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64,float64_data);
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64v,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
|
@ -95,12 +95,12 @@ static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8[DIMSIZE];
|
||||
static unsigned char uint8[DIMSIZE];
|
||||
static short int16[DIMSIZE];
|
||||
static int int32[DIMSIZE];
|
||||
static float float32[DIMSIZE];
|
||||
static double float64[DIMSIZE];
|
||||
static signed char int8v[DIMSIZE];
|
||||
static unsigned char uint8v[DIMSIZE];
|
||||
static short int16v[DIMSIZE];
|
||||
static int int32v[DIMSIZE];
|
||||
static float float32v[DIMSIZE];
|
||||
static double float64v[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
@ -188,93 +188,93 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8,int8_data);
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8v,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8,uint8_data);
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8v,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32,int8toint32_data);
|
||||
COMPARE(NC_BYTE,NC_INT,int32v,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,int82float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16,int16_data);
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16v,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32,int16toint32_data);
|
||||
COMPARE(NC_SHORT,NC_INT,int32v,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32,int162float32_data);
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32v,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32,int32_data);
|
||||
COMPARE(NC_INT,NC_INT,int32v,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32,int32tofloat32_data);
|
||||
COMPARE(NC_INT,NC_FLOAT,float32v,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
@ -288,23 +288,23 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64,float64_data);
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64v,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
|
@ -94,12 +94,12 @@ static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8[DIMSIZE];
|
||||
static unsigned char uint8[DIMSIZE];
|
||||
static short int16[DIMSIZE];
|
||||
static int int32[DIMSIZE];
|
||||
static float float32[DIMSIZE];
|
||||
static double float64[DIMSIZE];
|
||||
static signed char int8v[DIMSIZE];
|
||||
static unsigned char uint8v[DIMSIZE];
|
||||
static short int16v[DIMSIZE];
|
||||
static int int32v[DIMSIZE];
|
||||
static float float32v[DIMSIZE];
|
||||
static double float64v[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
@ -187,93 +187,93 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8,int8_data);
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8v,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8,uint8_data);
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8v,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32,int8toint32_data);
|
||||
COMPARE(NC_BYTE,NC_INT,int32v,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,int82float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16,int16_data);
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16v,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32,int16toint32_data);
|
||||
COMPARE(NC_SHORT,NC_INT,int32v,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32,int162float32_data);
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32v,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32,int32_data);
|
||||
COMPARE(NC_INT,NC_INT,int32v,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32,int32tofloat32_data);
|
||||
COMPARE(NC_INT,NC_FLOAT,float32v,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
@ -287,23 +287,23 @@ int main()
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,float32_data);
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64[i]);
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64,float64_data);
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64v,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
|
@ -61,7 +61,7 @@ NC_testurl(const char* path)
|
||||
if(*p == '/') return 0; /* probably an absolute file path */
|
||||
|
||||
/* Ok, try to parse as a url */
|
||||
if(nc_urlparse(path,&tmpurl) == NC_NOERR) {
|
||||
if(nc_urlparse(path,&tmpurl) == 1) {
|
||||
/* Do some extra testing to make sure this really is a url */
|
||||
/* Look for a knownprotocol */
|
||||
struct NCPROTOCOLLIST* protolist;
|
||||
@ -89,7 +89,7 @@ NC_urlmodel(const char* path)
|
||||
NC_URL* tmpurl = NULL;
|
||||
struct NCPROTOCOLLIST* protolist;
|
||||
|
||||
if(nc_urlparse(path,&tmpurl) != NC_NOERR) goto done;
|
||||
if(nc_urlparse(path,&tmpurl) == 0) goto done;
|
||||
|
||||
/* Look at any prefixed parameters */
|
||||
if(nc_urllookup(tmpurl,"netcdf4")
|
||||
@ -107,8 +107,10 @@ NC_urlmodel(const char* path)
|
||||
for(protolist=ncprotolist;protolist->protocol;protolist++) {
|
||||
if(strcmp(tmpurl->protocol,protolist->protocol) == 0) {
|
||||
model |= protolist->modelflags;
|
||||
if(protolist->substitute)
|
||||
nc_urlsetprotocol(tmpurl,protolist->substitute);
|
||||
if(protolist->substitute) {
|
||||
if(tmpurl->protocol != NULL) free(tmpurl->protocol);
|
||||
tmpurl->protocol = protolist->substitute;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,142 +1,208 @@
|
||||
/*********************************************************************
|
||||
* Copyright 2010, UCAR/Unidata
|
||||
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
||||
* $Header$
|
||||
*********************************************************************/
|
||||
|
||||
#include "ncdispatch.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nc_url.h"
|
||||
|
||||
#define NC_URLDEBUG
|
||||
|
||||
#define LBRACKET '['
|
||||
#define RBRACKET ']'
|
||||
|
||||
static NClist* nc_urlparamdecode(char* params0);
|
||||
static NClist* nc_urlparamlookup(NClist* params, const char* clientparam);
|
||||
static void nc_urlparamfree(NClist* params);
|
||||
#ifndef FIX
|
||||
#define FIX(s) ((s)==NULL?"":(s))
|
||||
#endif
|
||||
|
||||
#ifndef NILLEN
|
||||
#define NILLEN(s) ((s)==NULL?0:strlen(s))
|
||||
#endif
|
||||
|
||||
#ifndef nulldup
|
||||
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
|
||||
#endif
|
||||
|
||||
static char* legalprotocols[] = {
|
||||
"file:",
|
||||
"http:",
|
||||
"https:",
|
||||
"ftp:",
|
||||
NULL /* NULL terminate*/
|
||||
};
|
||||
|
||||
/* Do a simple url parse*/
|
||||
int
|
||||
nc_urlparse(const char* url0, NC_URL** ncurlp)
|
||||
nc_urlparse(const char* url0, NC_URL** nc_urlp)
|
||||
{
|
||||
NCerror ncstat = NC_NOERR;
|
||||
char* url = NULL;
|
||||
NC_URL* nc_url = NULL;
|
||||
char* url;
|
||||
char** pp;
|
||||
char* p;
|
||||
char* p1;
|
||||
int c;
|
||||
NC_URL* ncurl;
|
||||
size_t protolen;
|
||||
|
||||
/* accumulate parse points*/
|
||||
char* protocol = NULL;
|
||||
char* params = NULL;
|
||||
char* baseurl = NULL;
|
||||
char* trueurl = NULL;
|
||||
char* host = NULL;
|
||||
char* port = NULL;
|
||||
char* constraint = NULL;
|
||||
char* user = NULL;
|
||||
char* pwd = NULL;
|
||||
char* file = NULL;
|
||||
char* stop;
|
||||
|
||||
/* copy url and remove all whitespace*/
|
||||
url = strdup(url0);
|
||||
if(url == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
nc_url = (NC_URL*)calloc(1,sizeof(NC_URL));
|
||||
if(nc_url == NULL) return 0;
|
||||
|
||||
/* make local copy of url */
|
||||
url = strdup(url0);
|
||||
|
||||
/* remove all whitespace*/
|
||||
p = url;
|
||||
p1 = url;
|
||||
while((c=*p1++)) {if(c != ' ' && c != '\t') *p++ = c;}
|
||||
*p = '\0';
|
||||
|
||||
p = url;
|
||||
stop = p + strlen(p);
|
||||
|
||||
/* break up the url string into pieces*/
|
||||
|
||||
/* 1. leading bracketed parameters */
|
||||
if(*p == LBRACKET) {
|
||||
params = p+1;
|
||||
/* find end of the clientparams*/
|
||||
for(;*p;p++) {if(p[0] == RBRACKET && p[1] != LBRACKET) break;}
|
||||
if(*p == 0) {
|
||||
ncstat = NC_EINVAL; /* malformed client params*/
|
||||
goto done;
|
||||
}
|
||||
if(*p == 0) goto fail; /* malformed client params*/
|
||||
*p = '\0'; /* leave off the trailing rbracket for now */
|
||||
p++; /* move past the params*/
|
||||
}
|
||||
|
||||
trueurl = nulldup(p);
|
||||
baseurl = p;
|
||||
|
||||
/* Note that we dont care what the protocol is ; just collect it */
|
||||
/* find the end of the protocol */
|
||||
p1 = strchr(p,':');
|
||||
if(p1 == NULL || p1 == p) {
|
||||
ncstat = NC_EINVAL; /* missing protocol*/
|
||||
goto done;
|
||||
/* verify that the url starts with an acceptable protocol*/
|
||||
for(pp=legalprotocols;*pp;pp++) {
|
||||
if(strncmp(p,*pp,strlen(*pp))==0) break;
|
||||
}
|
||||
/* Check that the : is followed by "//" */
|
||||
if(p1[1] != '/' || p1[2] != '/') {
|
||||
ncstat = NC_EINVAL;
|
||||
goto done;
|
||||
if(*pp == NULL) goto fail; /* illegal protocol*/
|
||||
/* save the protocol */
|
||||
protocol = *pp;
|
||||
|
||||
/* 4. skip protocol */
|
||||
p += strlen(protocol);
|
||||
|
||||
/* 5. skip // */
|
||||
if(*p != '/' && *(p+1) != '/')
|
||||
goto fail;
|
||||
p += 2;
|
||||
|
||||
/* 6. Mark the end of the host section */
|
||||
file = strchr(p,'/');
|
||||
if(file) {
|
||||
*file++ = '\0'; /* warning: we just overwrote the leading / */
|
||||
}
|
||||
|
||||
/* Simulate strndup */
|
||||
protolen = (size_t)(p1-p);
|
||||
protocol = malloc(1+protolen);
|
||||
if(protocol == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
strncpy(protocol,p,protolen);
|
||||
protocol[protolen] = '\0';
|
||||
/* Look for '?' */
|
||||
constraint = strchr(p,'?');
|
||||
/* 7. extract any user:pwd */
|
||||
p1 = strchr(p,'@');
|
||||
if(p1) {/* Assume we have user:pwd@ */
|
||||
*p1 = '\0';
|
||||
user = p;
|
||||
pwd = strchr(p,':');
|
||||
if(!pwd) goto fail; /* malformed */
|
||||
*pwd++ = '\0';
|
||||
p = pwd+strlen(pwd)+1;
|
||||
}
|
||||
|
||||
/* 8. extract host and port */
|
||||
host = p;
|
||||
port = strchr(p,':');
|
||||
if(port) {
|
||||
*port++ = '\0';
|
||||
}
|
||||
|
||||
/* 9. Look for '?' */
|
||||
constraint = strchr(file,'?');
|
||||
if(constraint) {
|
||||
*constraint++ = '\0';
|
||||
}
|
||||
|
||||
/* assemble the component pieces*/
|
||||
ncurl = calloc(1,sizeof(NC_URL));
|
||||
if(ncurl == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
|
||||
ncurl->wholeurl = nulldup(url0);
|
||||
if(ncurl->wholeurl == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
ncurl->url = trueurl;
|
||||
trueurl = NULL;
|
||||
if(ncurl->url == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
ncurl->base = nulldup(baseurl);
|
||||
if(ncurl->base == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
ncurl->protocol = protocol;
|
||||
ncurl->constraint = nulldup(constraint);
|
||||
if(constraint != NULL && ncurl->constraint == NULL) {ncstat=NC_ENOMEM; goto done;}
|
||||
nc_urlsetconstraints(ncurl,constraint);
|
||||
if(params != NULL) {
|
||||
ncurl->params = (char*)malloc(1+2+strlen(params));
|
||||
if(ncurl->params == NULL) return NC_ENOMEM;
|
||||
strcpy(ncurl->params,"[");
|
||||
strcat(ncurl->params,params);
|
||||
strcat(ncurl->params,"]");
|
||||
if(url0 && strlen(url0) > 0)
|
||||
nc_url->url = strdup(url0);
|
||||
if(protocol && strlen(protocol) > 0) {
|
||||
nc_url->protocol = strdup(protocol);
|
||||
/* remove trailing ':' */
|
||||
nc_url->protocol[strlen(protocol)-1] = '\0';
|
||||
}
|
||||
if(user && strlen(user) > 0)
|
||||
nc_url->user = strdup(user);
|
||||
if(pwd && strlen(pwd) > 0)
|
||||
nc_url->password = strdup(pwd);
|
||||
if(host && strlen(host) > 0)
|
||||
nc_url->host = strdup(host);
|
||||
if(port && strlen(port) > 0)
|
||||
nc_url->port = strdup(port);
|
||||
if(file && strlen(file) > 0) {
|
||||
/* Add back the leading / */
|
||||
nc_url->file = malloc(strlen(file)+2);
|
||||
strcpy(nc_url->file,"/");
|
||||
strcat(nc_url->file,file);
|
||||
}
|
||||
if(constraint && strlen(constraint) > 0)
|
||||
nc_url->constraint = strdup(constraint);
|
||||
nc_urlsetconstraints(nc_url,constraint);
|
||||
if(params != NULL && strlen(params) > 0) {
|
||||
nc_url->params = (char*)malloc(1+2+strlen(params));
|
||||
strcpy(nc_url->params,"[");
|
||||
strcat(nc_url->params,params);
|
||||
strcat(nc_url->params,"]");
|
||||
}
|
||||
if(ncurlp) *ncurlp = ncurl;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"urlparse: params=|%s| base=|%s| projection=|%s| selection=|%s|\n",
|
||||
ncurl->params, ncurl->base, ncurl->projection, ncurl->selection);
|
||||
#ifdef NC_XDEBUG
|
||||
{
|
||||
fprintf(stderr,"nc_url:");
|
||||
fprintf(stderr," params=|%s|",FIX(nc_url->params));
|
||||
fprintf(stderr," protocol=|%s|",FIX(nc_url->protocol));
|
||||
fprintf(stderr," host=|%s|",FIX(nc_url->host));
|
||||
fprintf(stderr," port=|%s|",FIX(nc_url->port));
|
||||
fprintf(stderr," file=|%s|",FIX(nc_url->file));
|
||||
fprintf(stderr," constraint=|%s|",FIX(nc_url->constraint));
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
#endif
|
||||
free(url);
|
||||
if(nc_urlp != NULL) *nc_urlp = nc_url;
|
||||
return 1;
|
||||
|
||||
done:
|
||||
fail:
|
||||
if(url != NULL) free(url);
|
||||
if(trueurl != NULL) free(trueurl);
|
||||
return ncstat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Call must free the actual url instance.*/
|
||||
void
|
||||
nc_urlfree(NC_URL* ncurl)
|
||||
nc_urlfree(NC_URL* nc_url)
|
||||
{
|
||||
if(ncurl == NULL) return;
|
||||
if(ncurl->wholeurl != NULL) {free(ncurl->wholeurl);}
|
||||
if(ncurl->url != NULL) {free(ncurl->url);}
|
||||
if(ncurl->base != NULL) {free(ncurl->base);}
|
||||
if(ncurl->protocol != NULL) {free(ncurl->protocol);}
|
||||
if(ncurl->constraint != NULL) {free(ncurl->constraint);}
|
||||
if(ncurl->projection != NULL) {free(ncurl->projection);}
|
||||
if(ncurl->selection != NULL) {free(ncurl->selection);}
|
||||
if(ncurl->params != NULL) {free(ncurl->params);}
|
||||
if(ncurl->parammap != NULL) nc_urlparamfree(ncurl->parammap);
|
||||
free(ncurl);
|
||||
if(nc_url == NULL) return;
|
||||
if(nc_url->url != NULL) {free(nc_url->url);}
|
||||
if(nc_url->protocol != NULL) {free(nc_url->protocol);}
|
||||
if(nc_url->user != NULL) {free(nc_url->user);}
|
||||
if(nc_url->password != NULL) {free(nc_url->password);}
|
||||
if(nc_url->host != NULL) {free(nc_url->host);}
|
||||
if(nc_url->port != NULL) {free(nc_url->port);}
|
||||
if(nc_url->file != NULL) {free(nc_url->file);}
|
||||
if(nc_url->constraint != NULL) {free(nc_url->constraint);}
|
||||
if(nc_url->projection != NULL) {free(nc_url->projection);}
|
||||
if(nc_url->selection != NULL) {free(nc_url->selection);}
|
||||
if(nc_url->params != NULL) {free(nc_url->params);}
|
||||
if(nc_url->paramlist != NULL) nc_paramfree(nc_url->paramlist);
|
||||
free(nc_url);
|
||||
}
|
||||
|
||||
/* Replace the constraints */
|
||||
@ -147,15 +213,20 @@ nc_urlsetconstraints(NC_URL* durl,const char* constraints)
|
||||
char* select = NULL;
|
||||
const char* p;
|
||||
|
||||
if(durl->constraint == NULL) free(durl->constraint);
|
||||
if(durl->projection != NULL) free(durl->projection);
|
||||
if(durl->selection != NULL) free(durl->selection);
|
||||
durl->constraint = NULL;
|
||||
durl->projection = NULL;
|
||||
durl->selection = NULL;
|
||||
|
||||
if(constraints == NULL || strlen(constraints)==0) return;
|
||||
|
||||
p = constraints;
|
||||
if(p[0] == '?') p++;
|
||||
durl->constraint = strdup(constraints);
|
||||
if(*durl->constraint == '?')
|
||||
strcpy(durl->constraint,durl->constraint+1);
|
||||
|
||||
p = durl->constraint;
|
||||
proj = (char*) p;
|
||||
select = strchr(proj,'&');
|
||||
if(select != NULL) {
|
||||
@ -164,7 +235,6 @@ nc_urlsetconstraints(NC_URL* durl,const char* constraints)
|
||||
proj = NULL;
|
||||
} else {
|
||||
proj = (char*)malloc(plen+1);
|
||||
if(proj == NULL) return;
|
||||
memcpy((void*)proj,p,plen);
|
||||
proj[plen] = '\0';
|
||||
}
|
||||
@ -177,226 +247,247 @@ nc_urlsetconstraints(NC_URL* durl,const char* constraints)
|
||||
durl->selection = select;
|
||||
}
|
||||
|
||||
|
||||
/* Construct a complete NC_ URL without the client params
|
||||
and optionally with the constraints;
|
||||
caller frees returned string
|
||||
*/
|
||||
|
||||
char*
|
||||
nc_urlgeturl(NC_URL* durl, const char* prefix, const char* suffix, int pieces)
|
||||
{
|
||||
size_t len = 0;
|
||||
char* newurl;
|
||||
int withparams = ((pieces&NC_URLPARAMS)
|
||||
&& durl->params != NULL);
|
||||
int withuserpwd = ((pieces&NC_URLUSERPWD)
|
||||
&& durl->user != NULL && durl->password != NULL);
|
||||
int withconstraints = ((pieces&NC_URLCONSTRAINTS)
|
||||
&& durl->constraint != NULL);
|
||||
|
||||
if(prefix != NULL) len += NILLEN(prefix);
|
||||
if(withparams) {
|
||||
len += NILLEN("[]");
|
||||
len += NILLEN(durl->params);
|
||||
}
|
||||
len += (NILLEN(durl->protocol)+NILLEN("://"));
|
||||
if(withuserpwd) {
|
||||
len += (NILLEN(durl->user)+NILLEN(durl->password)+NILLEN(":@"));
|
||||
}
|
||||
len += (NILLEN(durl->host));
|
||||
if(durl->port != NULL) {
|
||||
len += (NILLEN(":")+NILLEN(durl->port));
|
||||
}
|
||||
len += (NILLEN(durl->file));
|
||||
if(suffix != NULL) len += NILLEN(suffix);
|
||||
if(withconstraints) {
|
||||
len += (NILLEN("?")+NILLEN(durl->constraint));
|
||||
}
|
||||
len += 1; /* null terminator */
|
||||
|
||||
newurl = (char*)malloc(len);
|
||||
if(!newurl) return NULL;
|
||||
|
||||
newurl[0] = '\0';
|
||||
if(prefix != NULL) strcat(newurl,prefix);
|
||||
if(withparams) {
|
||||
strcat(newurl,"[");
|
||||
strcat(newurl,durl->params);
|
||||
strcat(newurl,"]");
|
||||
}
|
||||
strcat(newurl,durl->protocol);
|
||||
strcat(newurl,"://");
|
||||
if(withuserpwd) {
|
||||
strcat(newurl,durl->user);
|
||||
strcat(newurl,":");
|
||||
strcat(newurl,durl->password);
|
||||
strcat(newurl,"@");
|
||||
}
|
||||
if(durl->host != NULL) { /* may be null if using file: protocol */
|
||||
strcat(newurl,durl->host);
|
||||
}
|
||||
if(durl->port != NULL) {
|
||||
strcat(newurl,":");
|
||||
strcat(newurl,durl->port);
|
||||
}
|
||||
strcat(newurl,durl->file);
|
||||
if(suffix != NULL) strcat(newurl,suffix);
|
||||
if(withconstraints) {
|
||||
strcat(newurl,"?");
|
||||
strcat(newurl,durl->constraint);
|
||||
}
|
||||
return newurl;
|
||||
}
|
||||
|
||||
int
|
||||
nc_urldecodeparams(NC_URL* ncurl)
|
||||
nc_urldecodeparams(NC_URL* nc_url)
|
||||
{
|
||||
int ok = 0;
|
||||
if(ncurl->parammap == NULL && ncurl->params != NULL) {
|
||||
NClist* map = nc_urlparamdecode(ncurl->params);
|
||||
ncurl->parammap = map;
|
||||
if(nc_url->paramlist == NULL && nc_url->params != NULL) {
|
||||
char** list = nc_paramdecode(nc_url->params);
|
||||
nc_url->paramlist = list;
|
||||
ok = 1;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*! NULL result => entry not found.
|
||||
Empty value should be represented as a zero length list */
|
||||
NClist*
|
||||
Empty value should be represented as a zero length string */
|
||||
const char*
|
||||
nc_urllookup(NC_URL* durl, const char* clientparam)
|
||||
{
|
||||
/* make sure that durl->parammap exists */
|
||||
if(durl->parammap == NULL) nc_urldecodeparams(durl);
|
||||
return nc_urlparamlookup(durl->parammap,clientparam);
|
||||
/* make sure that durl->paramlist exists */
|
||||
if(durl->paramlist == NULL) nc_urldecodeparams(durl);
|
||||
return nc_paramlookup(durl->paramlist,clientparam);
|
||||
}
|
||||
|
||||
/* Convenience: search a list for a given string; NULL if not found */
|
||||
const char*
|
||||
nc_urllookupvalue(NClist* list, const char* value)
|
||||
{
|
||||
int i;
|
||||
if(list == NULL || value == NULL) return NULL;
|
||||
for(i=0;i<nclistlength(list);i++) {
|
||||
char* s = (char*)nclistget(list,i);
|
||||
if(s == NULL) continue;
|
||||
if(strcmp(value,s) == 0) return s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/*
|
||||
/* Parameter support */
|
||||
|
||||
Client parameters are assumed to be one or more instances of
|
||||
bracketed pairs: e.g "[...][...]...". The bracket content
|
||||
in turn is assumed to be a comma separated list of
|
||||
<name>=<value> pairs. e.g. x=y,z=,a=b.
|
||||
The resulting parse is stored in a list where the
|
||||
ith element is the name of the parameter
|
||||
and the i+1'th element is a list
|
||||
of all the occurrences kept in the original order.
|
||||
/*
|
||||
Client parameters are assumed to be
|
||||
one or more instances of bracketed pairs:
|
||||
e.g "[...][...]...".
|
||||
The bracket content in turn is assumed to be a
|
||||
comma separated list of <name>=<value> pairs.
|
||||
e.g. x=y,z=,a=b.
|
||||
If the same parameter is specifed more than once,
|
||||
then the first occurrence is used; this is so that
|
||||
is possible to forcibly override user specified
|
||||
parameters by prefixing.
|
||||
IMPORTANT: client parameter string is assumed to
|
||||
have blanks compress out.
|
||||
*/
|
||||
|
||||
static NClist*
|
||||
nc_urlparamdecode(char* params0)
|
||||
char**
|
||||
nc_paramdecode(char* params0)
|
||||
{
|
||||
char* cp;
|
||||
char* cq;
|
||||
int c;
|
||||
int i;
|
||||
int nparams;
|
||||
NClist* map = nclistnew();
|
||||
char** plist;
|
||||
char* params;
|
||||
char* params1;
|
||||
|
||||
if(params0 == NULL) return map;
|
||||
if(params0 == NULL) return NULL;
|
||||
|
||||
/* Pass 1 is to remove all blanks */
|
||||
params = strdup(params0);
|
||||
cp=params; cq = cp;
|
||||
while((c=*cp++)) {
|
||||
if(c == ' ') cp++; else *cq++ = c;
|
||||
}
|
||||
*cq = '\0';
|
||||
/* Pass 1 to replace beginning '[' and ending ']' */
|
||||
if(params0[0] == '[')
|
||||
params = strdup(params0+1);
|
||||
else
|
||||
params = strdup(params0);
|
||||
|
||||
/* Pass 2 to replace beginning '[' and ending ']' */
|
||||
if(params[0] == '[') {
|
||||
char* p = params;
|
||||
char* q = params+1;
|
||||
/*strcpy(params,params+1); valgrind complains about overlap */
|
||||
while((*p++=*q++));
|
||||
}
|
||||
if(params[strlen(params)-1] == ']')
|
||||
params[strlen(params)-1] = '\0';
|
||||
|
||||
/* Pass 3 to replace "][" pairs with ','*/
|
||||
cp=params; cq = cp;;
|
||||
/* Pass 2 to replace "][" pairs with ','*/
|
||||
params1 = strdup(params);
|
||||
cp=params; cq = params1;
|
||||
while((c=*cp++)) {
|
||||
if(c == RBRACKET && *cp == LBRACKET) {cp++; c = ',';}
|
||||
*cq++ = c;
|
||||
}
|
||||
*cq = '\0';
|
||||
free(params);
|
||||
params = params1;
|
||||
|
||||
/* Pass 4 to break string into pieces and count # of pairs */
|
||||
/* Pass 3 to break string into pieces and count # of pairs */
|
||||
nparams=0;
|
||||
for(cp=params;(c=*cp);cp++) {
|
||||
if(c == ',') {*cp = '\0'; nparams++;}
|
||||
}
|
||||
nparams++; /* for last one */
|
||||
|
||||
/* Pass 5 to break up each pass into a (name,value) pair*/
|
||||
/* and insert into the param map */
|
||||
/* plist is an env style list */
|
||||
plist = (char**)calloc(1,sizeof(char*)*(2*nparams+1)); /* +1 for null termination */
|
||||
|
||||
/* Pass 4 to break up each pass into a (name,value) pair*/
|
||||
/* and insert into the param list */
|
||||
/* parameters of the form name name= are converted to name=""*/
|
||||
cp = params;
|
||||
for(i=0;i<nparams;i++) {
|
||||
int j;
|
||||
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
|
||||
char* vp;
|
||||
NClist* values;
|
||||
/*break up the ith param*/
|
||||
vp = strchr(cp,'=');
|
||||
if(vp != NULL) {*vp = '\0'; vp++;} else {vp = "";}
|
||||
/* Locate any previous name match and get/create the value list*/
|
||||
for(values=NULL,j=0;j<nclistlength(map);j+=2) {
|
||||
if(strcmp(cp,(char*)nclistget(map,j))==0) {
|
||||
values = (NClist*)nclistget(map,j+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(values == NULL) {
|
||||
/*add at end */
|
||||
values = nclistnew();
|
||||
nclistpush(map,(ncelem)nulldup(cp));
|
||||
nclistpush(map,(ncelem)values);
|
||||
}
|
||||
/* Add the value (may result in duplicates */
|
||||
nclistpush(values,(ncelem)nulldup(vp));
|
||||
plist[2*i] = strdup(cp);
|
||||
plist[2*i+1] = strdup(vp);
|
||||
cp = next;
|
||||
}
|
||||
plist[nparams] = NULL;
|
||||
free(params);
|
||||
return map;
|
||||
return plist;
|
||||
}
|
||||
|
||||
/*
|
||||
Lookup the param, if value is non-null, then see
|
||||
if it occurs in the value list
|
||||
*/
|
||||
|
||||
static NClist*
|
||||
nc_urlparamlookup(NClist* params, const char* pname)
|
||||
/* Internal version of lookup; returns the paired index of the key */
|
||||
static int
|
||||
nc_find(char** params, const char* key)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || pname == NULL) return NULL;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
char* name = (char*)nclistget(params,i);
|
||||
if(strcmp(pname,name)==0) {
|
||||
return (NClist*)nclistget(params,i+1);
|
||||
}
|
||||
char** p;
|
||||
for(i=0,p=params;*p;p+=2,i++) {
|
||||
if(strcmp(key,*p)==0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
nc_paramlookup(char** params, const char* key)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || key == NULL) return NULL;
|
||||
i = nc_find(params,key);
|
||||
if(i >= 0)
|
||||
return params[(2*i)+1];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
nc_urlparamfree(NClist* params)
|
||||
{
|
||||
int i,j;
|
||||
if(params == NULL) return;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
NClist* values;
|
||||
char* s = (char*)nclistget(params,i);
|
||||
if(s != NULL) free((void*)s);
|
||||
values = (NClist*)nclistget(params,i+1);
|
||||
for(j=0;j<nclistlength(values);j++) {
|
||||
s = (char*)nclistget(values,j);
|
||||
if(s != NULL) free((void*)s);
|
||||
}
|
||||
nclistfree(values);
|
||||
}
|
||||
nclistfree(params);
|
||||
}
|
||||
|
||||
void
|
||||
nc_urlsetprotocol(NC_URL* ncurl,const char* newprotocol)
|
||||
nc_paramfree(char** params)
|
||||
{
|
||||
if(ncurl != NULL) {
|
||||
if(ncurl->protocol != NULL) free(ncurl->protocol);
|
||||
ncurl->protocol = nulldup(newprotocol);
|
||||
char** p;
|
||||
if(params == NULL) return;
|
||||
for(p=params;*p;p+=2) {
|
||||
free(*p);
|
||||
if(p[1] != NULL) free(p[1]);
|
||||
}
|
||||
free(params);
|
||||
}
|
||||
|
||||
|
||||
#ifdef IGNORE
|
||||
/*
|
||||
Delete the entry.
|
||||
return value = 1 => found and deleted;
|
||||
0 => param not found
|
||||
*/
|
||||
static int
|
||||
nc_urlparamdelete(NClist* params, const char* clientparam)
|
||||
{
|
||||
int i,found = 0;
|
||||
if(params == NULL || clientparam == NULL) return 0;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
char* name = (char*)nclistget(params,i);
|
||||
if(strcmp(clientparam,name)==0) {found=1; break;}
|
||||
}
|
||||
if(found) {
|
||||
nclistremove(params,i+1); /* remove value */
|
||||
nclistremove(params,i); /* remove name */
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/*
|
||||
Replace new client param (name,value);
|
||||
return value = 1 => replacement performed
|
||||
0 => insertion performed
|
||||
*/
|
||||
static int
|
||||
nc_urlparamreplace(NClist* params, const char* clientparam, const char* value)
|
||||
int
|
||||
nc_paramdelete(char** params, const char* key)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || clientparam == NULL) return 0;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
char* name = (char*)nclistget(params,i);
|
||||
if(strcmp(clientparam,name)==0) {
|
||||
nclistinsert(params,i+1,(ncelem)nulldup(value));
|
||||
return 1;
|
||||
}
|
||||
char** p;
|
||||
char** q;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = nc_find(params,key);
|
||||
if(i < 0) return 0;
|
||||
p = params+(2*i);
|
||||
for(q=p+2;*q;) {
|
||||
*p++ = *q++;
|
||||
}
|
||||
nc_urlparaminsert(params,clientparam,value);
|
||||
return 0;
|
||||
*p = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
nc_length(char** params)
|
||||
{
|
||||
int i = 0;
|
||||
if(params != NULL) {
|
||||
while(*params) {params+=2; i++;}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -404,20 +495,38 @@ Insert new client param (name,value);
|
||||
return value = 1 => not already defined
|
||||
0 => param already defined (no change)
|
||||
*/
|
||||
static int
|
||||
nc_urlparaminsert(NClist* params, const char* clientparam, const char* value)
|
||||
char**
|
||||
nc_paraminsert(char** params, const char* key, const char* value)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || clientparam == NULL) return 0;
|
||||
for(i=0;i<nclistlength(params);i+=2) {
|
||||
char* name = (char*)nclistget(params,i);
|
||||
if(strcmp(clientparam,name)==0) return 0;
|
||||
}
|
||||
char** newp;
|
||||
size_t len;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = nc_find(params,key);
|
||||
if(i >= 0) return 0;
|
||||
/* not found, append */
|
||||
nclistpush(params,(ncelem)strdup(clientparam));
|
||||
nclistpush(params,(ncelem)nulldup(value));
|
||||
return 1;
|
||||
i = nc_length(params);
|
||||
len = sizeof(char*)*((2*i)+1);
|
||||
newp = realloc(params,len+2*sizeof(char*));
|
||||
memcpy(newp,params,len);
|
||||
newp[2*i] = strdup(key);
|
||||
newp[2*i+1] = (value==NULL?NULL:strdup(value));
|
||||
return newp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
Replace new client param (name,value);
|
||||
return value = 1 => replacement performed
|
||||
0 => key not found (no change)
|
||||
*/
|
||||
int
|
||||
nc_paramreplace(char** params, const char* key, const char* value)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = nc_find(params,key);
|
||||
if(i < 0) return 0;
|
||||
if(params[2*i+1] != NULL) free(params[2*i+1]);
|
||||
params[2*i+1] = nulldup(value);
|
||||
return 1;
|
||||
}
|
||||
|
@ -157,11 +157,6 @@ nclogtext(int tag, const char* text)
|
||||
void
|
||||
nclogtextn(int tag, const char* text, size_t count)
|
||||
{
|
||||
char line[1024];
|
||||
size_t delta = 0;
|
||||
const char* eol = text;
|
||||
size_t i,pos;
|
||||
|
||||
if(!nclogging || nclogstream == NULL) return;
|
||||
fwrite(text,1,count,nclogstream);
|
||||
fflush(nclogstream);
|
||||
|
@ -51,9 +51,9 @@ extern int dapgridelement(struct CDFnode* node);
|
||||
|
||||
/* Provide alternate path to the url parameters;
|
||||
one that does not require that an OCconnection exist */
|
||||
extern NClist* dapparamdecode(char*);
|
||||
extern void dapparamfree(NClist*);
|
||||
extern const char* dapparamlookup(NClist*, const char*);
|
||||
extern char** dapparamdecode(char*);
|
||||
extern void dapparamfree(char**);
|
||||
extern const char* dapparamlookup(char**, const char*);
|
||||
extern unsigned int modeldecode(int, const char*, const struct NCTMODEL*, unsigned int);
|
||||
extern unsigned long getlimitnumber(const char* limit);
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
set PARMS=""; set ARGS=""; set CON="" ; set CE=""; set OCON=""
|
||||
set PARMS="[log]"
|
||||
|
||||
set F="file://${HOME}/dmh/ncdap_test/testdata3/synth3"
|
||||
set F="http://tiggeUser:tigge@motherlode.ucar.edu:9080/thredds/dodsC/restrict/testdata/testData.nc"
|
||||
if (1 == 0) then
|
||||
set F="http://tiggeUser:tigge@motherlode.ucar.edu:9080/thredds/dodsC/restrict/testdata/testData.nc"
|
||||
set F="file:///home/dmh/nc/oc/dataset-duacs-nrt-over30d-global-merged-madt-h"
|
||||
set F="http://oceanwatch.pfeg.noaa.gov/opendap/GLOBEC/GLOBEC_cetaceans"
|
||||
set CON="number&number>6"
|
||||
|
@ -178,12 +178,12 @@ NC_check_name(const char *name)
|
||||
|
||||
if(*name == 0 /* empty names disallowed */
|
||||
|| strchr(cp, '/')) /* '/' can't be in a name */
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
|
||||
/* check validity of any UTF-8 */
|
||||
utf8_stat = utf8proc_check((const unsigned char *)name);
|
||||
if (utf8_stat < 0)
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
|
||||
/* First char must be [a-z][A-Z][0-9]_ | UTF8 */
|
||||
ch = (uchar)*cp;
|
||||
@ -192,11 +192,11 @@ NC_check_name(const char *name)
|
||||
&& !('a' <= ch && ch <= 'z')
|
||||
&& !('0' <= ch && ch <= '9')
|
||||
&& ch != '_' )
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
cp++;
|
||||
} else {
|
||||
if((skip = nextUTF8(cp)) < 0)
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
cp += skip;
|
||||
}
|
||||
|
||||
@ -205,18 +205,20 @@ NC_check_name(const char *name)
|
||||
/* handle simple 0x00-0x7f characters here */
|
||||
if(ch <= 0x7f) {
|
||||
if( ch < ' ' || ch > 0x7E) /* control char or DEL */
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
cp++;
|
||||
} else {
|
||||
if((skip = nextUTF8(cp)) < 0) return NC_EBADNAME;
|
||||
cp += skip;
|
||||
}
|
||||
if(cp - name > NC_MAX_NAME)
|
||||
return NC_EMAXNAME;
|
||||
goto fail;
|
||||
}
|
||||
if(ch <= 0x7f && isspace(ch)) /* trailing spaces disallowed */
|
||||
return NC_EBADNAME;
|
||||
goto fail;
|
||||
return NC_NOERR;
|
||||
fail:
|
||||
return NC_EBADNAME;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,12 +14,12 @@ CURL_CFLAGS = @CURL_CFLAGS@
|
||||
CURL_LIBS = @CURL_LIBS@
|
||||
|
||||
# OC Sources
|
||||
SRC= curlfunctions.c dapparse.c daplex.c dapurl.c http.c ocbytes.c \
|
||||
SRC= curlfunctions.c dapparse.c daplex.c ocuri.c http.c ocbytes.c \
|
||||
oc.c occompile.c occontent.c ocdata.c ocdebug.c ocdrno.c ocdump.c \
|
||||
ocinternal.c oclist.c oclog.c ocnode.c ocutil.c occlientparams.c \
|
||||
ocxdr_stdio.c rc.c read.c
|
||||
|
||||
HDRS= curlfunctions.h constraints.h dapparselex.h dapurl.h http.h ocbytes.h \
|
||||
HDRS= curlfunctions.h constraints.h dapparselex.h ocuri.h http.h ocbytes.h \
|
||||
occontent.h ocdata.h ocdatatypes.h ocdebug.h ocdrno.h ocdump.h oc.h \
|
||||
ocinternal.h oclist.h oclog.h ocnode.h occlientparams.h ocutil.h rc.h \
|
||||
read.h
|
||||
|
@ -20,9 +20,10 @@ static char* combinecredentials(const char* user, const char* pwd);
|
||||
|
||||
/* Set various general curl flags */
|
||||
int
|
||||
ocset_curl_flags(CURL* curl, OCstate* state)
|
||||
ocset_curl_flags(OCstate* state)
|
||||
{
|
||||
CURLcode cstat = CURLE_OK;
|
||||
CURL* curl = state->curl;
|
||||
struct OCcurlflags* flags = &state->curlflags;
|
||||
#ifdef CURLOPT_ENCODING
|
||||
if (flags->compress) {
|
||||
@ -61,9 +62,10 @@ fail:
|
||||
}
|
||||
|
||||
int
|
||||
ocset_proxy(CURL* curl, OCstate* state)
|
||||
ocset_proxy(OCstate* state)
|
||||
{
|
||||
CURLcode cstat;
|
||||
CURL* curl = state->curl;
|
||||
struct OCproxy *proxy = &state->proxy;
|
||||
struct OCcredentials *creds = &state->creds;
|
||||
|
||||
@ -79,7 +81,6 @@ ocset_proxy(CURL* curl, OCstate* state)
|
||||
char *combined = combinecredentials(creds->username,creds->password);
|
||||
if (!combined) return OC_ENOMEM;
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, combined);
|
||||
free(combined);
|
||||
if (cstat != CURLE_OK) return OC_ECURL;
|
||||
DEBUG1(1,"CURLOPT_PROXYUSERPWD=%s",combined);
|
||||
#ifdef CURLOPT_PROXYAUTH
|
||||
@ -87,14 +88,16 @@ ocset_proxy(CURL* curl, OCstate* state)
|
||||
if(cstat != CURLE_OK) goto fail;
|
||||
DEBUG1(1,"CURLOPT_PROXYAUTH=%ld",(long)CURLAUTH_ANY);
|
||||
#endif
|
||||
free(combined);
|
||||
}
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
||||
int
|
||||
ocset_ssl(CURL* curl, OCstate* state)
|
||||
ocset_ssl(OCstate* state)
|
||||
{
|
||||
CURLcode cstat = CURLE_OK;
|
||||
CURL* curl = state->curl;
|
||||
struct OCSSL* ssl = &state->ssl;
|
||||
long verify = (ssl->validate?1L:0L);
|
||||
cstat=curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, verify);
|
||||
@ -145,14 +148,15 @@ fail:
|
||||
* we may have multiple password sources.
|
||||
*/
|
||||
int
|
||||
ocset_user_password(CURL* curl, const char *userC, const char *passwordC)
|
||||
ocset_user_password(OCstate* state)
|
||||
{
|
||||
CURLcode cstat;
|
||||
CURL* curl = state->curl;
|
||||
char* combined = NULL;
|
||||
const char* userC = state->creds.username;
|
||||
const char* passwordC = state->creds.password;
|
||||
|
||||
if(userC == NULL && passwordC == NULL) return OC_NOERR;
|
||||
if(userC == NULL) userC = "";
|
||||
if(passwordC == NULL) passwordC = "";
|
||||
if(userC == NULL || passwordC == NULL) return OC_NOERR;
|
||||
|
||||
combined = combinecredentials(userC,passwordC);
|
||||
if (!combined) return OC_ENOMEM;
|
||||
|
@ -8,10 +8,10 @@
|
||||
#ifndef _CURLFUNCTION_H_
|
||||
#define _CURLFUNCTION_H_
|
||||
|
||||
extern int ocset_curl_flags(CURL*, OCstate*);
|
||||
extern int ocset_user_password(CURL*, const char *user, const char *pwd);
|
||||
extern int ocset_proxy(CURL*, OCstate*);
|
||||
extern int ocset_ssl(CURL*, OCstate*);
|
||||
extern int ocset_curl_flags(OCstate*);
|
||||
extern int ocset_user_password(OCstate*);
|
||||
extern int ocset_proxy(OCstate*);
|
||||
extern int ocset_ssl(OCstate*);
|
||||
|
||||
#endif /*_CURLFUNCTION_H_*/
|
||||
|
||||
|
224
oc/dapurl.c
224
oc/dapurl.c
@ -1,224 +0,0 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#include "config.h"
|
||||
#include "oclist.h"
|
||||
#include "ocinternal.h"
|
||||
#include "occlientparams.h"
|
||||
#include "ocdebug.h"
|
||||
|
||||
#define LBRACKET '['
|
||||
#define RBRACKET ']'
|
||||
|
||||
static char* legalprotocols[] = {
|
||||
"file:",
|
||||
"http:",
|
||||
"https:",
|
||||
"ftp:",
|
||||
NULL /* NULL terminate*/
|
||||
};
|
||||
|
||||
|
||||
/* Do a simple url parse*/
|
||||
int
|
||||
dapurlparse(const char* url0, DAPURL* dapurl)
|
||||
{
|
||||
char* url;
|
||||
char** pp;
|
||||
char* p;
|
||||
char* p1;
|
||||
int c;
|
||||
|
||||
/* accumulate parse points*/
|
||||
char* protocol = NULL;
|
||||
char* params = NULL;
|
||||
char* baseurl = NULL;
|
||||
char* constraint = NULL;
|
||||
char* stop;
|
||||
|
||||
memset((void*)dapurl,0,sizeof(DAPURL));
|
||||
|
||||
/* copy url and remove all whitespace*/
|
||||
url = strdup(url0);
|
||||
|
||||
p = url;
|
||||
p1 = url;
|
||||
while((c=*p1++)) {if(c != ' ' && c != '\t') *p++ = c;}
|
||||
|
||||
p = url;
|
||||
stop = p + strlen(p);
|
||||
|
||||
/* break up the url string into pieces*/
|
||||
if(*p == LBRACKET) {
|
||||
params = p+1;
|
||||
/* find end of the clientparams*/
|
||||
for(;*p;p++) {if(p[0] == RBRACKET && p[1] != LBRACKET) break;}
|
||||
if(*p == 0) goto fail; /* malformed client params*/
|
||||
*p = '\0'; /* leave off the trailing rbracket for now */
|
||||
p++; /* move past the params*/
|
||||
}
|
||||
|
||||
/* verify that the url starts with an acceptable protocol*/
|
||||
for(pp=legalprotocols;*pp;pp++) {
|
||||
if(strncmp(p,*pp,strlen(*pp))==0) break;
|
||||
}
|
||||
if(*pp == NULL) goto fail; /* illegal protocol*/
|
||||
/* save the protocol */
|
||||
protocol = *pp;
|
||||
|
||||
baseurl = p;
|
||||
|
||||
/* Look for '?' */
|
||||
constraint = strchr(p,'?');
|
||||
if(constraint) {
|
||||
*constraint++ = '\0';
|
||||
}
|
||||
|
||||
/* assemble the component pieces*/
|
||||
dapurl->url = nulldup(url0);
|
||||
dapurl->base = nulldup(baseurl);
|
||||
dapurl->protocol = nulldup(protocol);
|
||||
/* remove trailing ':' */
|
||||
dapurl->protocol[strlen(protocol)-1] = '\0';
|
||||
dapurl->constraint = nulldup(constraint);
|
||||
dapurlsetconstraints(dapurl,constraint);
|
||||
if(params != NULL) {
|
||||
dapurl->params = (char*)ocmalloc(1+2+strlen(params));
|
||||
strcpy(dapurl->params,"[");
|
||||
strcat(dapurl->params,params);
|
||||
strcat(dapurl->params,"]");
|
||||
}
|
||||
|
||||
if(ocdebug > 0) {
|
||||
fprintf(stderr,"dapurl: params=|%s| base=|%s| projection=|%s| selection=|%s|\n",
|
||||
dapurl->params, dapurl->base, dapurl->projection, dapurl->selection);
|
||||
|
||||
}
|
||||
free(url);
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
if(url != NULL) free(url);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Call must free the actual url instance.*/
|
||||
void
|
||||
dapurlclear(DAPURL* dapurl)
|
||||
{
|
||||
if(dapurl->url != NULL) {free(dapurl->url);}
|
||||
if(dapurl->base != NULL) {free(dapurl->base);}
|
||||
if(dapurl->protocol != NULL) {free(dapurl->protocol);}
|
||||
if(dapurl->constraint != NULL) {free(dapurl->constraint);}
|
||||
if(dapurl->projection != NULL) {free(dapurl->projection);}
|
||||
if(dapurl->selection != NULL) {free(dapurl->selection);}
|
||||
if(dapurl->params != NULL) {free(dapurl->params);}
|
||||
if(dapurl->paramlist != NULL) ocparamfree(dapurl->paramlist);
|
||||
memset((void*)dapurl,0,sizeof(DAPURL));
|
||||
}
|
||||
|
||||
/* Replace the constraints */
|
||||
void
|
||||
dapurlsetconstraints(DAPURL* durl,const char* constraints)
|
||||
{
|
||||
char* proj = NULL;
|
||||
char* select = NULL;
|
||||
const char* p;
|
||||
|
||||
if(durl->constraint == NULL) ocfree(durl->constraint);
|
||||
if(durl->projection != NULL) ocfree(durl->projection);
|
||||
if(durl->selection != NULL) ocfree(durl->selection);
|
||||
durl->constraint = NULL;
|
||||
durl->projection = NULL;
|
||||
durl->selection = NULL;
|
||||
|
||||
if(constraints == NULL || strlen(constraints)==0) return;
|
||||
|
||||
durl->constraint = strdup(constraints);
|
||||
if(*durl->constraint == '?')
|
||||
strcpy(durl->constraint,durl->constraint+1);
|
||||
|
||||
p = durl->constraint;
|
||||
proj = (char*) p;
|
||||
select = strchr(proj,'&');
|
||||
if(select != NULL) {
|
||||
size_t plen = (select - proj);
|
||||
if(plen == 0) {
|
||||
proj = NULL;
|
||||
} else {
|
||||
proj = (char*)ocmalloc(plen+1);
|
||||
memcpy((void*)proj,p,plen);
|
||||
proj[plen] = '\0';
|
||||
}
|
||||
select = nulldup(select);
|
||||
} else {
|
||||
proj = nulldup(proj);
|
||||
select = NULL;
|
||||
}
|
||||
durl->projection = proj;
|
||||
durl->selection = select;
|
||||
}
|
||||
|
||||
|
||||
/* Construct a complete DAP URL without the client params
|
||||
and optionally with the constraints;
|
||||
caller frees returned string
|
||||
*/
|
||||
|
||||
char*
|
||||
dapurlgeturl(DAPURL* durl, const char* prefix, const char* suffix,
|
||||
int withconstraints, int withparams)
|
||||
{
|
||||
size_t len = 0;
|
||||
char* newurl;
|
||||
|
||||
len += strlen(durl->base);
|
||||
if(prefix != NULL) len += strlen(prefix);
|
||||
if(suffix != NULL) len += strlen(suffix);
|
||||
if(withparams && durl->params != NULL && strlen(durl->params) > 0)
|
||||
len += strlen(durl->params);
|
||||
if(withconstraints
|
||||
&& durl->constraint != NULL && strlen(durl->constraint)> 0) {
|
||||
len += 1; /* leading '?' */
|
||||
len += strlen(durl->constraint);
|
||||
}
|
||||
len += 1; /* null terminator */
|
||||
|
||||
newurl = (char*)ocmalloc(len);
|
||||
if(!newurl) return NULL;
|
||||
newurl[0] = '\0';
|
||||
if(prefix != NULL) strcat(newurl,prefix);
|
||||
if(withparams && durl->params != NULL && strlen(durl->params) > 0)
|
||||
strcat(newurl,durl->params);
|
||||
strcat(newurl,durl->base);
|
||||
if(suffix != NULL) strcat(newurl,suffix);
|
||||
if(withconstraints
|
||||
&& durl->constraint != NULL && strlen(durl->constraint)> 0) {
|
||||
strcat(newurl,"?");
|
||||
strcat(newurl,durl->constraint);
|
||||
}
|
||||
return newurl;
|
||||
}
|
||||
|
||||
int
|
||||
dapurldecodeparams(DAPURL* dapurl)
|
||||
{
|
||||
int ok = 0;
|
||||
if(dapurl->paramlist == NULL && dapurl->params != NULL) {
|
||||
OClist* list = ocparamdecode(dapurl->params);
|
||||
dapurl->paramlist = list;
|
||||
ok = 1;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*! NULL result => entry not found.
|
||||
Empty value should be represented as a zero length string */
|
||||
const char*
|
||||
dapurllookup(DAPURL* durl, const char* clientparam)
|
||||
{
|
||||
/* make sure that durl->paramlist exists */
|
||||
if(durl->paramlist == NULL) dapurldecodeparams(durl);
|
||||
return ocparamlookup(durl->paramlist,clientparam);
|
||||
}
|
||||
|
40
oc/dapurl.h
40
oc/dapurl.h
@ -1,40 +0,0 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#ifndef DAPURL_H
|
||||
#define DAPURL_H
|
||||
|
||||
/* Forward */
|
||||
struct OClist;
|
||||
|
||||
/*! This is an open structure meaning
|
||||
it is ok to directly access its fields*/
|
||||
typedef struct DAPURL {
|
||||
char* url; /* as passed by the caller */
|
||||
char* base; /*!< without constraints*/
|
||||
char* protocol;
|
||||
char* constraint; /* projection+selection */
|
||||
char* projection; /*!< without leading '?'*/
|
||||
char* selection; /*!< with leading '&'*/
|
||||
char* params; /* all params */
|
||||
struct OClist* paramlist;
|
||||
} DAPURL;
|
||||
|
||||
extern int dapurlparse(const char* s, DAPURL* dapurl);
|
||||
extern void dapurlclear(DAPURL* dapurl);/*!<Release strings associated
|
||||
with the DAPURL, but NOT the struct
|
||||
itself; that is caller's duty.*/
|
||||
|
||||
/* Replace the constraints */
|
||||
extern void dapurlsetconstraints(DAPURL*,const char* constraints);
|
||||
|
||||
/* Construct a complete DAP URL; caller frees returned string */
|
||||
extern char* dapurlgeturl(DAPURL*,const char* prefix, const char* suffix, int withconstraints, int withparams);
|
||||
|
||||
extern int dapurldecodeparams(DAPURL* dapurl);
|
||||
|
||||
/*! NULL result => entry not found.
|
||||
Empty value should be represented as a zero length string */
|
||||
extern const char* dapurllookup(DAPURL*, const char* clientparam);
|
||||
|
||||
#endif /*DAPURL_H*/
|
9
oc/oc.c
9
oc/oc.c
@ -851,9 +851,10 @@ oc_clientparam_get(OCconnection conn, const char* param)
|
||||
OCVERIFYX(OCstate*,state,conn,NULL);
|
||||
OCDEREF(OCstate*,state,conn);
|
||||
|
||||
return ocparamlookup(state->clientparams,param);
|
||||
return ocparamlookup(state,param);
|
||||
}
|
||||
|
||||
#ifdef IGNORE
|
||||
/* Delete client parameter
|
||||
return value:
|
||||
OC_NOERR => defined; deletion performed
|
||||
@ -881,7 +882,8 @@ oc_clientparam_insert(OCconnection conn, const char* param, const char* value)
|
||||
OCVERIFY(OCstate*,state,conn);
|
||||
OCDEREF(OCstate*,state,conn);
|
||||
|
||||
return ocparaminsert(state->clientparams,param,value);
|
||||
state->clientparams = dapparaminsert(state->clientparams,param,value);
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
||||
/* Replace client parameter
|
||||
@ -896,8 +898,9 @@ oc_clientparam_replace(OCconnection conn, const char* param, const char* value)
|
||||
OCVERIFY(OCstate*,state,conn);
|
||||
OCDEREF(OCstate*,state,conn);
|
||||
|
||||
return ocparamreplace(state->clientparams,param,value);
|
||||
return dapparamreplace(state->clientparams,param,value);
|
||||
}
|
||||
#endif
|
||||
|
||||
OCerror
|
||||
oc_dd(OCconnection conn, OCobject root0)
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define RBRACKET ']'
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Client parameters are assumed to be
|
||||
one or more instances of bracketed pairs:
|
||||
@ -24,80 +25,31 @@ IMPORTANT: client parameter string is assumed to
|
||||
have blanks compress out.
|
||||
*/
|
||||
|
||||
OClist*
|
||||
ocparamdecode(char* params0)
|
||||
int
|
||||
ocparamdecode(OCstate* state)
|
||||
{
|
||||
char* cp;
|
||||
char* cq;
|
||||
int c;
|
||||
int i;
|
||||
int nparams;
|
||||
OClist* plist = oclistnew();
|
||||
char* params;
|
||||
char* params1;
|
||||
|
||||
if(params0 == NULL) return plist;
|
||||
|
||||
/* Pass 1 to replace beginning '[' and ending ']' */
|
||||
if(params0[0] == '[')
|
||||
params = strdup(params0+1);
|
||||
else
|
||||
params = strdup(params0);
|
||||
|
||||
if(params[strlen(params)-1] == ']')
|
||||
params[strlen(params)-1] = '\0';
|
||||
|
||||
/* Pass 2 to replace "][" pairs with ','*/
|
||||
params1 = strdup(params);
|
||||
cp=params; cq = params1;
|
||||
while((c=*cp++)) {
|
||||
if(c == RBRACKET && *cp == LBRACKET) {cp++; c = ',';}
|
||||
*cq++ = c;
|
||||
}
|
||||
*cq = '\0';
|
||||
free(params);
|
||||
params = params1;
|
||||
|
||||
/* Pass 3 to break string into pieces and count # of pairs */
|
||||
nparams=0;
|
||||
for(cp=params;(c=*cp);cp++) {
|
||||
if(c == ',') {*cp = '\0'; nparams++;}
|
||||
}
|
||||
nparams++; /* for last one */
|
||||
|
||||
/* Pass 4 to break up each pass into a (name,value) pair*/
|
||||
/* and insert into the param list */
|
||||
/* parameters of the form name name= are converted to name=""*/
|
||||
cp = params;
|
||||
for(i=0;i<nparams;i++) {
|
||||
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
|
||||
char* vp;
|
||||
/*break up the ith param*/
|
||||
vp = strchr(cp,'=');
|
||||
if(vp != NULL) {*vp = '\0'; vp++;} else {vp = "";}
|
||||
if(!oclistcontains(plist,(ocelem)cp)) {
|
||||
oclistpush(plist,(ocelem)strdup(cp));
|
||||
oclistpush(plist,(ocelem)strdup(vp));
|
||||
}
|
||||
cp = next;
|
||||
}
|
||||
free(params);
|
||||
return plist;
|
||||
i = ocuridecodeparams(state->uri);
|
||||
return i?OC_NOERR:OC_EBADURL;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
ocparamlookup(OClist* params, const char* clientparam)
|
||||
ocparamlookup(OCstate* state, const char* key)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || clientparam == NULL) return NULL;
|
||||
for(i=0;i<oclistlength(params);i+=2) {
|
||||
char* name = (char*)oclistget(params,i);
|
||||
if(strcmp(clientparam,name)==0)
|
||||
return (char*)oclistget(params,i+1);
|
||||
}
|
||||
return NULL;
|
||||
if(state == NULL || key == NULL || state->uri == NULL) return NULL;
|
||||
return ocurilookup(state->uri,key);
|
||||
}
|
||||
|
||||
int
|
||||
ocparamset(OCstate* state, const char* params)
|
||||
{
|
||||
int i;
|
||||
i = ocurisetparams(state->uri,params);
|
||||
return i?OC_NOERR:OC_EBADURL;
|
||||
}
|
||||
|
||||
#ifdef IGNORE
|
||||
void
|
||||
ocparamfree(OClist* params)
|
||||
{
|
||||
@ -173,3 +125,4 @@ ocparamreplace(OClist* params, const char* clientparam, const char* value)
|
||||
ocparaminsert(params,clientparam,value);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,14 +1,11 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#ifndef OCCLIENTPARAMS_H
|
||||
#define OCCLIENTPARAMS_H
|
||||
|
||||
extern OClist* ocparamdecode(char* params0);
|
||||
extern const char* ocparamlookup(OClist* params, const char* clientparam);
|
||||
extern int ocparamdelete(OClist* params, const char* clientparam);
|
||||
extern int ocparaminsert(OClist* params, const char* clientparam, const char* value);
|
||||
extern int ocparamreplace(OClist* params, const char* clientparam, const char* value);
|
||||
extern void ocparamfree(OClist* params);
|
||||
extern OClist* ocparamdecode(OCstate*);
|
||||
extern const char* ocparamlookup(OCstate*, const char*);
|
||||
extern void ocparamset(OCstate*,const char*);
|
||||
|
||||
#endif /*OCCLIENTPARAMS_H*/
|
||||
|
20
oc/ocdebug.h
20
oc/ocdebug.h
@ -25,11 +25,21 @@
|
||||
#define OCASSERT(expr) if(!(expr)) {OCPANIC((#expr));} else {}
|
||||
|
||||
/* Need some syntactic trickery to make these macros work*/
|
||||
#define DEBUG(l,msg) if(ocdebug >= l) {oc_log(LOGDBG,msg);} else {}
|
||||
#define DEBUG1(l,msg,arg) if(ocdebug >= l) {oc_log(LOGDBG,msg,arg);} else {}
|
||||
#define DEBUG2(l,msg,arg1,arg2) if(ocdebug >= l) {oc_log(LOGDBG,msg,arg1,arg2);} else {}
|
||||
#define DEBUGTEXT(l,text) if(ocdebug >= l) {oc_logtext(LOGNOTE,text);} else {}
|
||||
#define DEBUGCODE(l,code) if(ocdebug >= l) {code;} else {}
|
||||
#ifdef OCDEBUG
|
||||
#define DEBUG(l,msg) {oc_log(LOGDBG,msg);}
|
||||
#define DEBUG1(l,msg,arg) {oc_log(LOGDBG,msg,arg);}
|
||||
#define DEBUG2(l,msg,arg1,arg2) {oc_log(LOGDBG,msg,arg1,arg2);}
|
||||
#define DEBUGTEXT(l,text) {oc_logtext(LOGNOTE,text);} else {}
|
||||
#define DEBUGCODE(l,code) {code;}
|
||||
|
||||
#else
|
||||
#define DEBUG(l,msg)
|
||||
#define DEBUG1(l,msg,arg)
|
||||
#define DEBUG2(l,msg,arg1,arg2)
|
||||
#define DEBUGTEXT(l,text)
|
||||
#define DEBUGCODE(l,code)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
OCPROGRESS attempts to provide some info
|
||||
|
@ -198,12 +198,10 @@ ocopen(OCstate** statep, const char* url)
|
||||
{
|
||||
int stat = OC_NOERR;
|
||||
OCstate * state = NULL;
|
||||
DAPURL tmpurl;
|
||||
OCURI* tmpurl;
|
||||
CURL* curl = NULL; /* curl handle*/
|
||||
|
||||
memset((void*)&tmpurl,0,sizeof(tmpurl));
|
||||
|
||||
if(!dapurlparse(url,&tmpurl)) {THROWCHK(stat=OC_EBADURL); goto fail;}
|
||||
if(!ocuriparse(url,&tmpurl)) {THROWCHK(stat=OC_EBADURL); goto fail;}
|
||||
|
||||
stat = occurlopen(&curl);
|
||||
if(stat != OC_NOERR) {THROWCHK(stat); goto fail;}
|
||||
@ -216,9 +214,8 @@ ocopen(OCstate** statep, const char* url)
|
||||
state->curl = curl;
|
||||
state->trees = oclistnew();
|
||||
state->contentlist = NULL;
|
||||
state->url = tmpurl;
|
||||
state->clientparams = ocparamdecode(state->url.params);
|
||||
if(state->clientparams == NULL) {
|
||||
state->uri = tmpurl;
|
||||
if(!ocuridecodeparams(state->uri)) {
|
||||
oc_log(LOGWARN,"Could not parse client parameters");
|
||||
}
|
||||
state->packet = ocbytesnew();
|
||||
@ -231,7 +228,7 @@ ocopen(OCstate** statep, const char* url)
|
||||
return THROW(stat);
|
||||
|
||||
fail:
|
||||
dapurlclear(&tmpurl);
|
||||
ocurifree(tmpurl);
|
||||
if(state != NULL) ocfree(state);
|
||||
if(curl != NULL) occurlclose(curl);
|
||||
return THROW(stat);
|
||||
@ -253,6 +250,12 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCnode** rootp)
|
||||
if(tree->constraint == NULL)
|
||||
tree->constraint = nulldup(constraint);
|
||||
|
||||
/* Set curl properties: pwd, flags, proxies, ssl */
|
||||
if((stat=ocset_user_password(state))!= OC_NOERR) goto fail;
|
||||
if((stat=ocset_curl_flags(state)) != OC_NOERR) goto fail;
|
||||
if((stat=ocset_proxy(state)) != OC_NOERR) goto fail;
|
||||
if((stat=ocset_ssl(state)) != OC_NOERR) goto fail;
|
||||
|
||||
ocbytesclear(state->packet);
|
||||
|
||||
switch (kind) {
|
||||
@ -375,6 +378,7 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCnode** rootp)
|
||||
|
||||
unwind:
|
||||
ocfreetree(tree);
|
||||
fail:
|
||||
return THROW(stat);
|
||||
}
|
||||
|
||||
@ -391,7 +395,7 @@ occlose(OCstate* state)
|
||||
ocfreeroot(root);
|
||||
}
|
||||
oclistfree(state->trees);
|
||||
dapurlclear(&state->url);
|
||||
ocurifree(state->uri);
|
||||
ocbytesfree(state->packet);
|
||||
ocfree(state->error.code);
|
||||
ocfree(state->error.message);
|
||||
@ -404,8 +408,18 @@ occlose(OCstate* state)
|
||||
curr = next;
|
||||
}
|
||||
}
|
||||
ocfree(state->curlflags.useragent);
|
||||
ocfree(state->curlflags.cookiejar);
|
||||
ocfree(state->curlflags.cookiefile);
|
||||
ocfree(state->ssl.certificate);
|
||||
ocfree(state->ssl.key);
|
||||
ocfree(state->ssl.keypasswd);
|
||||
ocfree(state->ssl.cainfo);
|
||||
ocfree(state->ssl.capath);
|
||||
ocfree(state->proxy.host);
|
||||
ocfree(state->creds.username);
|
||||
ocfree(state->creds.password);
|
||||
if(state->curl != NULL) occurlclose(state->curl);
|
||||
if(state->clientparams != NULL) ocparamfree(state->clientparams);
|
||||
ocfree(state);
|
||||
}
|
||||
|
||||
@ -553,7 +567,10 @@ ocupdatelastmodifieddata(OCstate* state)
|
||||
{
|
||||
OCerror status = OC_NOERR;
|
||||
long lastmodified;
|
||||
status = ocfetchlastmodified(state->curl, state->url.base, &lastmodified);
|
||||
char* base = NULL;
|
||||
base = ocuribuild(state->uri,NULL,NULL,0);
|
||||
status = ocfetchlastmodified(state->curl, base, &lastmodified);
|
||||
free(base);
|
||||
if(status == OC_NOERR) {
|
||||
state->datalastmodified = lastmodified;
|
||||
}
|
||||
@ -566,47 +583,22 @@ ocupdatelastmodifieddata(OCstate* state)
|
||||
static void
|
||||
ocsetcurlproperties(OCstate* state)
|
||||
{
|
||||
CURL* curl = state->curl;
|
||||
CURLcode cstat = CURLE_OK;
|
||||
int stat = OC_NOERR;
|
||||
|
||||
/* process the triple store wrt to this state */
|
||||
if(ocdodsrc_process(state) != OC_NOERR) {
|
||||
oc_log(LOGERR,"Malformed .dodsrc");
|
||||
goto fail;
|
||||
}
|
||||
/* Set username+password from .dodsrc */
|
||||
stat=ocset_user_password(curl,state->creds.username,
|
||||
state->creds.password);
|
||||
if(stat != OC_NOERR) goto fail;
|
||||
|
||||
if (occredentials_in_url(state->url.url)) {
|
||||
/* this overrides .dodsrc */
|
||||
char *result_url = NULL;
|
||||
char* userName = NULL;
|
||||
char* password = NULL;
|
||||
if (ocextract_credentials(state->url.url, &userName, &password, &result_url) != OC_NOERR)
|
||||
goto fail;
|
||||
dapurlclear(&state->url);
|
||||
dapurlparse(result_url,&state->url);
|
||||
/* this overrides .dodsrc */
|
||||
if(password != NULL && strlen(password) > 0) {
|
||||
if(state->creds.username == NULL && state->creds.password == NULL) {
|
||||
if(state->uri->user != NULL && state->uri->password != NULL) {
|
||||
/* this overrides .dodsrc */
|
||||
if(state->creds.password) free(state->creds.password);
|
||||
state->creds.password = password;
|
||||
}
|
||||
if(userName != NULL && strlen(userName) > 0) {
|
||||
state->creds.password = strdup(state->uri->password);
|
||||
if(state->creds.username) free(state->creds.username);
|
||||
state->creds.username = userName;
|
||||
state->creds.username = strdup(state->uri->user);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set curl properties */
|
||||
if((stat=ocset_curl_flags(curl,state)) != OC_NOERR) goto fail;
|
||||
/* Set curl proxy */
|
||||
if((stat=ocset_proxy(curl,state)) != OC_NOERR) goto fail;
|
||||
/* Set curl ssl */
|
||||
if((stat=ocset_ssl(curl,state)) != OC_NOERR) goto fail;
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "oclist.h"
|
||||
#include "ocbytes.h"
|
||||
#include "ocuri.h"
|
||||
|
||||
#define OCCACHEPOS
|
||||
#ifdef OCCACHEPOS
|
||||
@ -46,13 +47,10 @@ extern void ocxdrstdio_create(XDR*,FILE*,enum xdr_op);
|
||||
|
||||
#undef OC_DISK_STORAGE
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "oc.h"
|
||||
#include "ocdatatypes.h"
|
||||
#include "constraints.h"
|
||||
#include "ocnode.h"
|
||||
#include "dapurl.h"
|
||||
#include "ocutil.h"
|
||||
#include "oclog.h"
|
||||
#include "ocdata.h"
|
||||
@ -83,8 +81,7 @@ typedef struct OCstate
|
||||
unsigned int magic; /* Mark each structure type */
|
||||
CURL* curl; /* curl handle*/
|
||||
OClist* trees; /* list<OCnode*> ; all root objects */
|
||||
DAPURL url; /* base URL */
|
||||
OClist* clientparams;
|
||||
OCURI* uri; /* base URI*/
|
||||
OCbytes* packet; /* shared by all trees during construction */
|
||||
/* OCContent information */
|
||||
struct OCcontent* contentlist;
|
||||
|
537
oc/ocuri.c
Normal file
537
oc/ocuri.c
Normal file
@ -0,0 +1,537 @@
|
||||
/*********************************************************************
|
||||
* Copyright 2010, UCAR/Unidata
|
||||
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
||||
* $Header$
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ocuri.h"
|
||||
|
||||
#define OCURIDEBUG
|
||||
|
||||
#define LBRACKET '['
|
||||
#define RBRACKET ']'
|
||||
|
||||
#ifndef FIX
|
||||
#define FIX(s) ((s)==NULL?"":(s))
|
||||
#endif
|
||||
|
||||
#ifndef NILLEN
|
||||
#define NILLEN(s) ((s)==NULL?0:strlen(s))
|
||||
#endif
|
||||
|
||||
#ifndef nulldup
|
||||
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
|
||||
#endif
|
||||
|
||||
static char* legalprotocols[] = {
|
||||
"file:",
|
||||
"http:",
|
||||
"https:",
|
||||
"ftp:",
|
||||
NULL /* NULL terminate*/
|
||||
};
|
||||
|
||||
static void ocparamfree(char** params);
|
||||
static int ocfind(char** params, const char* key);
|
||||
|
||||
/* Do a simple uri parse: return 0 if fail, 1 otherwise*/
|
||||
int
|
||||
ocuriparse(const char* uri0, OCURI** ocurip)
|
||||
{
|
||||
OCURI* ocuri = NULL;
|
||||
char* uri;
|
||||
char** pp;
|
||||
char* p;
|
||||
char* p1;
|
||||
int c;
|
||||
|
||||
/* accumulate parse points*/
|
||||
char* protocol = NULL;
|
||||
char* params = NULL;
|
||||
char* host = NULL;
|
||||
char* port = NULL;
|
||||
char* constraint = NULL;
|
||||
char* user = NULL;
|
||||
char* pwd = NULL;
|
||||
char* file = NULL;
|
||||
char* stop;
|
||||
|
||||
ocuri = (OCURI*)calloc(1,sizeof(OCURI));
|
||||
if(ocuri == NULL) return 0;
|
||||
|
||||
/* make local copy of uri */
|
||||
uri = strdup(uri0);
|
||||
|
||||
/* remove all whitespace*/
|
||||
p = uri;
|
||||
p1 = uri;
|
||||
while((c=*p1++)) {if(c != ' ' && c != '\t') *p++ = c;}
|
||||
|
||||
p = uri;
|
||||
stop = p + strlen(p);
|
||||
|
||||
/* break up the uri string into pieces*/
|
||||
|
||||
/* 1. leading bracketed parameters */
|
||||
if(*p == LBRACKET) {
|
||||
params = p+1;
|
||||
/* find end of the clientparams*/
|
||||
for(;*p;p++) {if(p[0] == RBRACKET && p[1] != LBRACKET) break;}
|
||||
if(*p == 0) goto fail; /* malformed client params*/
|
||||
*p = '\0'; /* leave off the trailing rbracket for now */
|
||||
p++; /* move past the params*/
|
||||
}
|
||||
|
||||
/* verify that the uri starts with an acceptable protocol*/
|
||||
for(pp=legalprotocols;*pp;pp++) {
|
||||
if(strncmp(p,*pp,strlen(*pp))==0) break;
|
||||
}
|
||||
if(*pp == NULL) goto fail; /* illegal protocol*/
|
||||
/* save the protocol */
|
||||
protocol = *pp;
|
||||
|
||||
/* 4. skip protocol */
|
||||
p += strlen(protocol);
|
||||
|
||||
/* 5. skip // */
|
||||
if(*p != '/' && *(p+1) != '/')
|
||||
goto fail;
|
||||
p += 2;
|
||||
|
||||
/* 6. Mark the end of the host section */
|
||||
file = strchr(p,'/');
|
||||
if(file) {
|
||||
*file++ = '\0'; /* warning: we just overwrote the leading / */
|
||||
}
|
||||
|
||||
/* 7. extract any user:pwd */
|
||||
p1 = strchr(p,'@');
|
||||
if(p1) {/* Assume we have user:pwd@ */
|
||||
*p1 = '\0';
|
||||
user = p;
|
||||
pwd = strchr(p,':');
|
||||
if(!pwd) goto fail; /* malformed */
|
||||
*pwd++ = '\0';
|
||||
p = pwd+strlen(pwd)+1;
|
||||
}
|
||||
|
||||
/* 8. extract host and port */
|
||||
host = p;
|
||||
port = strchr(p,':');
|
||||
if(port) {
|
||||
*port++ = '\0';
|
||||
}
|
||||
|
||||
/* 9. Look for '?' */
|
||||
constraint = strchr(file,'?');
|
||||
if(constraint) {
|
||||
*constraint++ = '\0';
|
||||
}
|
||||
|
||||
/* assemble the component pieces*/
|
||||
if(uri0 && strlen(uri0) > 0)
|
||||
ocuri->uri = strdup(uri0);
|
||||
if(protocol && strlen(protocol) > 0) {
|
||||
ocuri->protocol = strdup(protocol);
|
||||
/* remove trailing ':' */
|
||||
ocuri->protocol[strlen(protocol)-1] = '\0';
|
||||
}
|
||||
if(user && strlen(user) > 0)
|
||||
ocuri->user = strdup(user);
|
||||
if(pwd && strlen(pwd) > 0)
|
||||
ocuri->password = strdup(pwd);
|
||||
if(host && strlen(host) > 0)
|
||||
ocuri->host = strdup(host);
|
||||
if(port && strlen(port) > 0)
|
||||
ocuri->port = strdup(port);
|
||||
if(file && strlen(file) > 0) {
|
||||
/* Add back the leading / */
|
||||
ocuri->file = malloc(strlen(file)+2);
|
||||
strcpy(ocuri->file,"/");
|
||||
strcat(ocuri->file,file);
|
||||
}
|
||||
if(constraint && strlen(constraint) > 0)
|
||||
ocuri->constraint = strdup(constraint);
|
||||
ocurisetconstraints(ocuri,constraint);
|
||||
if(params != NULL && strlen(params) > 0) {
|
||||
ocuri->params = (char*)malloc(1+2+strlen(params));
|
||||
strcpy(ocuri->params,"[");
|
||||
strcat(ocuri->params,params);
|
||||
strcat(ocuri->params,"]");
|
||||
}
|
||||
|
||||
#ifdef OCXDEBUG
|
||||
{
|
||||
fprintf(stderr,"ocuri:");
|
||||
fprintf(stderr," params=|%s|",FIX(ocuri->params));
|
||||
fprintf(stderr," protocol=|%s|",FIX(ocuri->protocol));
|
||||
fprintf(stderr," host=|%s|",FIX(ocuri->host));
|
||||
fprintf(stderr," port=|%s|",FIX(ocuri->port));
|
||||
fprintf(stderr," file=|%s|",FIX(ocuri->file));
|
||||
fprintf(stderr," constraint=|%s|",FIX(ocuri->constraint));
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
#endif
|
||||
free(uri);
|
||||
if(ocurip != NULL) *ocurip = ocuri;
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
if(uri != NULL) free(uri);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ocurifree(OCURI* ocuri)
|
||||
{
|
||||
if(ocuri == NULL) return;
|
||||
if(ocuri->uri != NULL) {free(ocuri->uri);}
|
||||
if(ocuri->protocol != NULL) {free(ocuri->protocol);}
|
||||
if(ocuri->user != NULL) {free(ocuri->user);}
|
||||
if(ocuri->password != NULL) {free(ocuri->password);}
|
||||
if(ocuri->host != NULL) {free(ocuri->host);}
|
||||
if(ocuri->port != NULL) {free(ocuri->port);}
|
||||
if(ocuri->file != NULL) {free(ocuri->file);}
|
||||
if(ocuri->constraint != NULL) {free(ocuri->constraint);}
|
||||
if(ocuri->projection != NULL) {free(ocuri->projection);}
|
||||
if(ocuri->selection != NULL) {free(ocuri->selection);}
|
||||
if(ocuri->params != NULL) {free(ocuri->params);}
|
||||
if(ocuri->paramlist != NULL) ocparamfree(ocuri->paramlist);
|
||||
free(ocuri);
|
||||
}
|
||||
|
||||
/* Replace the constraints */
|
||||
void
|
||||
ocurisetconstraints(OCURI* duri,const char* constraints)
|
||||
{
|
||||
char* proj = NULL;
|
||||
char* select = NULL;
|
||||
const char* p;
|
||||
|
||||
if(duri->constraint == NULL) free(duri->constraint);
|
||||
if(duri->projection != NULL) free(duri->projection);
|
||||
if(duri->selection != NULL) free(duri->selection);
|
||||
duri->constraint = NULL;
|
||||
duri->projection = NULL;
|
||||
duri->selection = NULL;
|
||||
|
||||
if(constraints == NULL || strlen(constraints)==0) return;
|
||||
|
||||
duri->constraint = strdup(constraints);
|
||||
if(*duri->constraint == '?')
|
||||
strcpy(duri->constraint,duri->constraint+1);
|
||||
|
||||
p = duri->constraint;
|
||||
proj = (char*) p;
|
||||
select = strchr(proj,'&');
|
||||
if(select != NULL) {
|
||||
size_t plen = (select - proj);
|
||||
if(plen == 0) {
|
||||
proj = NULL;
|
||||
} else {
|
||||
proj = (char*)malloc(plen+1);
|
||||
memcpy((void*)proj,p,plen);
|
||||
proj[plen] = '\0';
|
||||
}
|
||||
select = nulldup(select);
|
||||
} else {
|
||||
proj = nulldup(proj);
|
||||
select = NULL;
|
||||
}
|
||||
duri->projection = proj;
|
||||
duri->selection = select;
|
||||
}
|
||||
|
||||
|
||||
/* Construct a complete OC URI without the client params
|
||||
and optionally with the constraints;
|
||||
caller frees returned string
|
||||
*/
|
||||
|
||||
char*
|
||||
ocuribuild(OCURI* duri, const char* prefix, const char* suffix, int pieces)
|
||||
{
|
||||
size_t len = 0;
|
||||
char* newuri;
|
||||
int withparams = ((pieces&OCURIPARAMS)
|
||||
&& duri->params != NULL);
|
||||
int withuserpwd = ((pieces&OCURIUSERPWD)
|
||||
&& duri->user != NULL && duri->password != NULL);
|
||||
int withconstraints = ((pieces&OCURICONSTRAINTS)
|
||||
&& duri->constraint != NULL);
|
||||
|
||||
if(prefix != NULL) len += NILLEN(prefix);
|
||||
if(withparams) {
|
||||
len += NILLEN("[]");
|
||||
len += NILLEN(duri->params);
|
||||
}
|
||||
len += (NILLEN(duri->protocol)+NILLEN("://"));
|
||||
if(withuserpwd) {
|
||||
len += (NILLEN(duri->user)+NILLEN(duri->password)+NILLEN(":@"));
|
||||
}
|
||||
len += (NILLEN(duri->host));
|
||||
if(duri->port != NULL) {
|
||||
len += (NILLEN(":")+NILLEN(duri->port));
|
||||
}
|
||||
len += (NILLEN(duri->file));
|
||||
if(suffix != NULL) len += NILLEN(suffix);
|
||||
if(withconstraints) {
|
||||
len += (NILLEN("?")+NILLEN(duri->constraint));
|
||||
}
|
||||
len += 1; /* null terminator */
|
||||
|
||||
newuri = (char*)malloc(len);
|
||||
if(!newuri) return NULL;
|
||||
|
||||
newuri[0] = '\0';
|
||||
if(prefix != NULL) strcat(newuri,prefix);
|
||||
if(withparams) {
|
||||
strcat(newuri,"[");
|
||||
strcat(newuri,duri->params);
|
||||
strcat(newuri,"]");
|
||||
}
|
||||
strcat(newuri,duri->protocol);
|
||||
strcat(newuri,"://");
|
||||
if(withuserpwd) {
|
||||
strcat(newuri,duri->user);
|
||||
strcat(newuri,":");
|
||||
strcat(newuri,duri->password);
|
||||
strcat(newuri,"@");
|
||||
}
|
||||
if(duri->host != NULL) { /* may be null if using file: protocol */
|
||||
strcat(newuri,duri->host);
|
||||
}
|
||||
if(duri->port != NULL) {
|
||||
strcat(newuri,":");
|
||||
strcat(newuri,duri->port);
|
||||
}
|
||||
strcat(newuri,duri->file);
|
||||
if(suffix != NULL) strcat(newuri,suffix);
|
||||
if(withconstraints) {
|
||||
strcat(newuri,"?");
|
||||
strcat(newuri,duri->constraint);
|
||||
}
|
||||
return newuri;
|
||||
}
|
||||
|
||||
/**************************************************/
|
||||
/* Parameter support */
|
||||
|
||||
/*
|
||||
Client parameters are assumed to be
|
||||
one or more instances of bracketed pairs:
|
||||
e.g "[...][...]...".
|
||||
The bracket content in turn is assumed to be a
|
||||
comma separated list of <name>=<value> pairs.
|
||||
e.g. x=y,z=,a=b.
|
||||
If the same parameter is specifed more than once,
|
||||
then the first occurrence is used; this is so that
|
||||
is possible to forcibly override user specified
|
||||
parameters by prefixing.
|
||||
IMPORTANT: client parameter string is assumed to
|
||||
have blanks compress out.
|
||||
Returns 1 if parse suceeded, 0 otherwise;
|
||||
*/
|
||||
|
||||
int
|
||||
ocuridecodeparams(OCURI* ocuri)
|
||||
{
|
||||
char* cp;
|
||||
char* cq;
|
||||
int c;
|
||||
int i;
|
||||
int nparams;
|
||||
char* params0;
|
||||
char* params;
|
||||
char* params1;
|
||||
char** plist;
|
||||
|
||||
if(ocuri == NULL) return 0;
|
||||
if(ocuri->params == NULL) return 1;
|
||||
|
||||
params0 = ocuri->params;
|
||||
|
||||
/* Pass 1 to replace beginning '[' and ending ']' */
|
||||
if(params0[0] == '[')
|
||||
params = strdup(params0+1);
|
||||
else
|
||||
params = strdup(params0);
|
||||
|
||||
if(params[strlen(params)-1] == ']')
|
||||
params[strlen(params)-1] = '\0';
|
||||
|
||||
/* Pass 2 to replace "][" pairs with ','*/
|
||||
params1 = strdup(params);
|
||||
cp=params; cq = params1;
|
||||
while((c=*cp++)) {
|
||||
if(c == RBRACKET && *cp == LBRACKET) {cp++; c = ',';}
|
||||
*cq++ = c;
|
||||
}
|
||||
*cq = '\0';
|
||||
free(params);
|
||||
params = params1;
|
||||
|
||||
/* Pass 3 to break string into pieces and count # of pairs */
|
||||
nparams=0;
|
||||
for(cp=params;(c=*cp);cp++) {
|
||||
if(c == ',') {*cp = '\0'; nparams++;}
|
||||
}
|
||||
nparams++; /* for last one */
|
||||
|
||||
/* plist is an env style list */
|
||||
plist = (char**)calloc(1,sizeof(char*)*(2*nparams+1)); /* +1 for null termination */
|
||||
|
||||
/* Pass 4 to break up each pass into a (name,value) pair*/
|
||||
/* and insert into the param list */
|
||||
/* parameters of the form name name= are converted to name=""*/
|
||||
cp = params;
|
||||
for(i=0;i<nparams;i++) {
|
||||
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
|
||||
char* vp;
|
||||
/*break up the ith param*/
|
||||
vp = strchr(cp,'=');
|
||||
if(vp != NULL) {*vp = '\0'; vp++;} else {vp = "";}
|
||||
plist[2*i] = strdup(cp);
|
||||
plist[2*i+1] = strdup(vp);
|
||||
cp = next;
|
||||
}
|
||||
plist[nparams] = NULL;
|
||||
free(params);
|
||||
if(ocuri->paramlist != NULL)
|
||||
ocparamfree(ocuri->paramlist);
|
||||
ocuri->paramlist = plist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char*
|
||||
ocurilookup(OCURI* uri, const char* key)
|
||||
{
|
||||
int i;
|
||||
if(uri == NULL || key == NULL || uri->params == NULL) return NULL;
|
||||
if(uri->paramlist == NULL) {
|
||||
i = ocuridecodeparams(uri);
|
||||
if(!i) return 0;
|
||||
}
|
||||
i = ocfind(uri->paramlist,key);
|
||||
if(i >= 0)
|
||||
return uri->paramlist[(2*i)+1];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
ocurisetparams(OCURI* uri, const char* newparams)
|
||||
{
|
||||
if(uri == NULL) return 0;
|
||||
if(uri->paramlist != NULL) ocparamfree(uri->paramlist);
|
||||
uri->paramlist = NULL;
|
||||
if(uri->params != NULL) free(uri->params);
|
||||
uri->params = nulldup(newparams);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Internal version of lookup; returns the paired index of the key */
|
||||
static int
|
||||
ocfind(char** params, const char* key)
|
||||
{
|
||||
int i;
|
||||
char** p;
|
||||
for(i=0,p=params;*p;p+=2,i++) {
|
||||
if(strcmp(key,*p)==0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
ocparamfree(char** params)
|
||||
{
|
||||
char** p;
|
||||
if(params == NULL) return;
|
||||
for(p=params;*p;p+=2) {
|
||||
free(*p);
|
||||
if(p[1] != NULL) free(p[1]);
|
||||
}
|
||||
free(params);
|
||||
}
|
||||
|
||||
#ifdef IGNORE
|
||||
/*
|
||||
Delete the entry.
|
||||
return value = 1 => found and deleted;
|
||||
0 => param not found
|
||||
*/
|
||||
int
|
||||
ocparamdelete(char** params, const char* key)
|
||||
{
|
||||
int i;
|
||||
char** p;
|
||||
char** q;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = ocfind(params,key);
|
||||
if(i < 0) return 0;
|
||||
p = params+(2*i);
|
||||
for(q=p+2;*q;) {
|
||||
*p++ = *q++;
|
||||
}
|
||||
*p = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
oclength(char** params)
|
||||
{
|
||||
int i = 0;
|
||||
if(params != NULL) {
|
||||
while(*params) {params+=2; i++;}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
Insert new client param (name,value);
|
||||
return value = 1 => not already defined
|
||||
0 => param already defined (no change)
|
||||
*/
|
||||
char**
|
||||
ocparaminsert(char** params, const char* key, const char* value)
|
||||
{
|
||||
int i;
|
||||
char** newp;
|
||||
size_t len;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = ocfind(params,key);
|
||||
if(i >= 0) return 0;
|
||||
/* not found, append */
|
||||
i = oclength(params);
|
||||
len = sizeof(char*)*((2*i)+1);
|
||||
newp = realloc(params,len+2*sizeof(char*));
|
||||
memcpy(newp,params,len);
|
||||
newp[2*i] = strdup(key);
|
||||
newp[2*i+1] = (value==NULL?NULL:strdup(value));
|
||||
return newp;
|
||||
}
|
||||
|
||||
/*
|
||||
Replace new client param (name,value);
|
||||
return value = 1 => replacement performed
|
||||
0 => key not found (no change)
|
||||
*/
|
||||
int
|
||||
ocparamreplace(char** params, const char* key, const char* value)
|
||||
{
|
||||
int i;
|
||||
if(params == NULL || key == NULL) return 0;
|
||||
i = ocfind(params,key);
|
||||
if(i < 0) return 0;
|
||||
if(params[2*i+1] != NULL) free(params[2*i+1]);
|
||||
params[2*i+1] = nulldup(value);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
48
oc/ocuri.h
Normal file
48
oc/ocuri.h
Normal file
@ -0,0 +1,48 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#ifndef OCURI_H
|
||||
#define OCURI_H
|
||||
|
||||
/*! This is an open structure meaning
|
||||
it is ok to directly access its fields*/
|
||||
typedef struct OCURI {
|
||||
char* uri; /* as passed by the caller */
|
||||
char* protocol;
|
||||
char* user; /* from user:password@ */
|
||||
char* password; /* from user:password@ */
|
||||
char* host; /*!< host*/
|
||||
char* port; /*!< host */
|
||||
char* file; /*!< file */
|
||||
char* constraint; /*!< projection+selection */
|
||||
char* projection; /*!< without leading '?'*/
|
||||
char* selection; /*!< with leading '&'*/
|
||||
char* params; /* all params */
|
||||
char** paramlist; /*!<null terminated list */
|
||||
} OCURI;
|
||||
|
||||
extern int ocuriparse(const char* s, OCURI** ocuri);
|
||||
extern void ocurifree(OCURI* ocuri);
|
||||
|
||||
/* Replace the constraints */
|
||||
extern void ocurisetconstraints(OCURI*,const char* constraints);
|
||||
|
||||
/* Construct a complete OC URI; caller frees returned string */
|
||||
|
||||
/* Define flags to control what is included */
|
||||
#define OCURICONSTRAINTS 1
|
||||
#define OCURIUSERPWD 2
|
||||
#define OCURIPARAMS 4
|
||||
|
||||
extern char* ocuribuild(OCURI*,const char* prefix, const char* suffix, int flags);
|
||||
|
||||
|
||||
/* Param Management */
|
||||
extern int ocuridecodeparams(OCURI* ocuri);
|
||||
extern int ocurisetparams(OCURI* ocuri,const char*);
|
||||
|
||||
/*! NULL result => entry not found.
|
||||
Empty value should be represented as a zero length string */
|
||||
extern const char* ocurilookup(OCURI*, const char* param);
|
||||
|
||||
#endif /*OCURI_H*/
|
14
oc/rc.c
14
oc/rc.c
@ -214,6 +214,7 @@ parseproxy(OCstate* state, char* v)
|
||||
#endif
|
||||
oc_log(LOGNOTE,"port number: %d", state->proxy.port);
|
||||
}
|
||||
if(v) free(v);
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
||||
@ -354,7 +355,7 @@ int
|
||||
ocdodsrc_process(OCstate* state)
|
||||
{
|
||||
char* value;
|
||||
char* url = state->url.base;
|
||||
char* url = ocuribuild(state->uri,NULL,NULL,0);
|
||||
if(ocdodsrc == NULL) return 0;
|
||||
value = ocdodsrc_lookup("CURL.DEFLATE",url);
|
||||
if(value != NULL) {
|
||||
@ -374,7 +375,6 @@ ocdodsrc_process(OCstate* state)
|
||||
if(ocdebug > 0)
|
||||
oc_log(LOGNOTE,"COOKIEFILE: %s", state->curlflags.cookiefile);
|
||||
}
|
||||
|
||||
if((value = ocdodsrc_lookup("CURL.COOKIEJAR",url))
|
||||
|| (value = ocdodsrc_lookup("CURL.COOKIE_JAR",url))) {
|
||||
state->curlflags.cookiejar = strdup(TRIM(value));
|
||||
@ -383,6 +383,14 @@ ocdodsrc_process(OCstate* state)
|
||||
oc_log(LOGNOTE,"COOKIEJAR: %s", state->curlflags.cookiejar);
|
||||
}
|
||||
|
||||
/* Some servers (e.g. thredds) appear to require a place
|
||||
to put cookies in order for some security functions to work
|
||||
*/
|
||||
if(state->curlflags.cookiejar == NULL
|
||||
&& state->curlflags.cookiefile == NULL) {
|
||||
state->curlflags.cookiefile = strdup("");
|
||||
}
|
||||
|
||||
if((value = ocdodsrc_lookup("CURL.PROXY_SERVER",url)) != NULL) {
|
||||
int stat = parseproxy(state,TRIM(value));
|
||||
if(stat != OC_NOERR) return stat;
|
||||
@ -444,6 +452,8 @@ ocdodsrc_process(OCstate* state)
|
||||
}
|
||||
/* else ignore */
|
||||
|
||||
free(url);
|
||||
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
||||
|
90
oc/read.c
90
oc/read.c
@ -14,11 +14,12 @@
|
||||
#include "http.h"
|
||||
#include "read.h"
|
||||
#include "rc.h"
|
||||
#include "curlfunctions.h"
|
||||
|
||||
extern int oc_curl_file_supported;
|
||||
|
||||
/*Forward*/
|
||||
static int readpacket(CURL*, DAPURL*, OCbytes*, OCdxd, long*);
|
||||
static int readpacket(CURL*, OCURI*, OCbytes*, OCdxd, long*);
|
||||
static int readfile(char* path, char* suffix, OCbytes* packet);
|
||||
#ifdef OC_DISK_STORAGE
|
||||
static int readfiletofile(char* path, char* suffix, FILE* stream, unsigned long*);
|
||||
@ -27,24 +28,34 @@ static int readfiletofile(char* path, char* suffix, FILE* stream, unsigned long*
|
||||
int
|
||||
readDDS(OCstate* state, OCtree* tree)
|
||||
{
|
||||
int status;
|
||||
long lastmodified = -1;
|
||||
dapurlsetconstraints(&state->url,tree->constraint);
|
||||
status = readpacket(state->curl,&state->url,state->packet,OCDDS,
|
||||
int stat;
|
||||
long lastmodified = -1;
|
||||
|
||||
|
||||
ocurisetconstraints(state->uri,tree->constraint);
|
||||
|
||||
ocset_user_password(state);
|
||||
|
||||
stat = readpacket(state->curl,state->uri,state->packet,OCDDS,
|
||||
&lastmodified);
|
||||
if(status == OC_NOERR) state->ddslastmodified = lastmodified;
|
||||
return status;
|
||||
if(stat == OC_NOERR) state->ddslastmodified = lastmodified;
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
int
|
||||
readDAS(OCstate* state, OCtree* tree)
|
||||
{
|
||||
dapurlsetconstraints(&state->url,tree->constraint);
|
||||
return readpacket(state->curl,&state->url,state->packet,OCDAS,NULL);
|
||||
int stat = OC_NOERR;
|
||||
|
||||
ocurisetconstraints(state->uri,tree->constraint);
|
||||
stat = readpacket(state->curl,state->uri,state->packet,OCDAS,NULL);
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
int
|
||||
readversion(CURL* curl, DAPURL* url, OCbytes* packet)
|
||||
readversion(CURL* curl, OCURI* url, OCbytes* packet)
|
||||
{
|
||||
return readpacket(curl,url,packet,OCVER,NULL);
|
||||
}
|
||||
@ -58,66 +69,75 @@ char* ocdxdextension[] ={
|
||||
};
|
||||
|
||||
static int
|
||||
readpacket(CURL* curl,DAPURL* url,OCbytes* packet,OCdxd dxd,long* lastmodified)
|
||||
readpacket(CURL* curl,OCURI* url,OCbytes* packet,OCdxd dxd,long* lastmodified)
|
||||
{
|
||||
int stat;
|
||||
int fileprotocol = 0;
|
||||
char* suffix = ocdxdextension[dxd];
|
||||
char* fetchurl = NULL;
|
||||
|
||||
fileprotocol = (strncmp(url->base,"file",4)==0);
|
||||
fileprotocol = (strcmp(url->protocol,"file")==0);
|
||||
|
||||
if(fileprotocol && !oc_curl_file_supported) {
|
||||
/* Short circuit file://... urls*/
|
||||
/* We do this because the test code always needs to read files*/
|
||||
stat = readfile(url->base,suffix,packet);
|
||||
fetchurl = ocuribuild(url,NULL,NULL,0);
|
||||
stat = readfile(fetchurl,suffix,packet);
|
||||
} else {
|
||||
char* fetchurl = dapurlgeturl(url,NULL,suffix,!fileprotocol,0);
|
||||
int flags = 0;
|
||||
if(!fileprotocol) flags |= OCURICONSTRAINTS;
|
||||
fetchurl = ocuribuild(url,NULL,suffix,flags);
|
||||
MEMCHECK(fetchurl,OC_ENOMEM);
|
||||
if(ocdebug > 0)
|
||||
{fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);}
|
||||
stat = ocfetchurl(curl,fetchurl,packet,lastmodified);
|
||||
if(ocdebug > 0)
|
||||
{fprintf(stderr,"fetch complete\n"); fflush(stderr);}
|
||||
free(fetchurl);
|
||||
}
|
||||
free(fetchurl);
|
||||
return THROW(stat);
|
||||
}
|
||||
|
||||
int
|
||||
readDATADDS(OCstate* state, OCtree* tree)
|
||||
{
|
||||
int stat;
|
||||
long lastmod = -1;
|
||||
#ifndef OC_DISK_STORAGE
|
||||
dapurlsetconstraints(&state->url,tree->constraint);
|
||||
stat = readpacket(state->curl,&state->url,state->packet,OCDATADDS,&lastmod);
|
||||
if(stat == OC_NOERR)
|
||||
state->datalastmodified = lastmod;
|
||||
tree->data.datasize = ocbyteslength(state->packet);
|
||||
#else /*OC_DISK_STORAGE*/
|
||||
DAPURL* url = &state->url;
|
||||
int fileprotocol = 0;
|
||||
int stat;
|
||||
long lastmod = -1;
|
||||
|
||||
fileprotocol = (strncmp(url->base,"file",4)==0);
|
||||
#ifndef OC_DISK_STORAGE
|
||||
ocurisetconstraints(state->uri,tree->constraint);
|
||||
stat = readpacket(state->curl,state->uri,state->packet,OCDATADDS,&lastmod);
|
||||
if(stat == OC_NOERR)
|
||||
state->datalastmodified = lastmod;
|
||||
tree->data.datasize = ocbyteslength(state->packet);
|
||||
#else /*OC_DISK_STORAGE*/
|
||||
OCURI* url = state->uri;
|
||||
int fileprotocol = 0;
|
||||
char* readurl = NULL;
|
||||
|
||||
fileprotocol = (strcmp(url->protocol,"file")==0);
|
||||
|
||||
if(fileprotocol && !oc_curl_file_supported) {
|
||||
stat = readfiletofile(url->base, ".dods", tree->data.file, &tree->data.datasize);
|
||||
readurl = ocuribuild(url,NULL,NULL,0);
|
||||
stat = readfiletofile(readurl, ".dods", tree->data.file, &tree->data.datasize);
|
||||
} else {
|
||||
char* fetchurl;
|
||||
dapurlsetconstraints(url,tree->constraint);
|
||||
fetchurl = dapurlgeturl(url,NULL,".dods",!fileprotocol,0);
|
||||
MEMCHECK(fetchurl,OC_ENOMEM);
|
||||
int flags = 0;
|
||||
if(!fileprotocol) flags |= OCURICONSTRAINTS;
|
||||
ocurisetconstraints(url,tree->constraint);
|
||||
readurl = ocuribuild(url,NULL,".dods",flags);
|
||||
MEMCHECK(readurl,OC_ENOMEM);
|
||||
if (ocdebug > 0)
|
||||
{fprintf(stderr, "fetch url=%s\n", fetchurl);fflush(stderr);}
|
||||
stat = ocfetchurl_file(state->curl, fetchurl, tree->data.file,
|
||||
{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(fetchurl);
|
||||
}
|
||||
free(readurl);
|
||||
#endif /*OC_DISK_STORAGE*/
|
||||
|
||||
return THROW(stat);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user