Add quick check for Error {...} at start of the datadds data part

This commit is contained in:
Dennis Heimbigner 2013-02-07 22:14:57 +00:00
parent 8d6bfcd534
commit 4109174d00
6 changed files with 75 additions and 15 deletions

View File

@ -10,17 +10,7 @@ PROG="$TOP/ncdump/ncdump"
P=`pwd`
#T="1990-S1700101.HDF.WVC_Lat"
T="synth10"
F="file://$TOP/ncdap_test/testdata3/$T"
#F="http://motherlode.ucar.edu:8081/dts/$T?f64"
#F="http://nomads.ncep.noaa.gov:9090/dods/gfs_hd/gfs_hd20120801/gfs_hd_00z"
#F="http://hycom.coaps.fsu.edu/thredds/dodsC/atl_ops"
#F="http://testbedapps-dev.sura.org/thredds/dodsC/auto/in.usf.fvcom.ike.ultralite.vardrag.nowave.2d"
#F="http://motherlode.ucar.edu:8081/dts/test.06"
#F="http://motherlode.ucar.edu:8081/thredds/dodsC/testdods/nametest3.nc"
#F="http://ingrid.ldeo.columbia.edu/SOURCES/.USTOPO/dods"
F="http://motherlode.ucar.edu:9080/thredds/dodsC/grib/NCEP/NAM/CONUS_12km/best"
#CON="OneD.amp,TwoD.amp,ThreeD.amp"
@ -104,6 +94,14 @@ F="http://motherlode.ucar.edu:8080/thredds/dodsC/station/metar/Surface_METAR_201
CON="weather[0:10]"
F="http://nomad1.ncep.noaa.gov:9090/dods/reanalyses/reanalysis-1/6hr/pgb/pgb"
VAR=hgtprs
F="file://$TOP/ncdap_test/testdata3/$T"
#F="http://motherlode.ucar.edu:8081/dts/$T?f64"
#F="http://nomads.ncep.noaa.gov:9090/dods/gfs_hd/gfs_hd20120801/gfs_hd_00z"
#F="http://hycom.coaps.fsu.edu/thredds/dodsC/atl_ops"
#F="http://testbedapps-dev.sura.org/thredds/dodsC/auto/in.usf.fvcom.ike.ultralite.vardrag.nowave.2d"
#F="http://motherlode.ucar.edu:8081/dts/test.06"
#F="http://motherlode.ucar.edu:8081/thredds/dodsC/testdods/nametest3.nc"
#F="http://ingrid.ldeo.columbia.edu/SOURCES/.USTOPO/dods"
fi

View File

@ -43,13 +43,16 @@ static char* nctagname(int tag);
void
ncloginit(void)
{
const char* file = getenv(NCENVFLAG);
const char* file;
if(nclogginginitialized)
return;
nclogginginitialized = 1;
ncsetlogging(0);
nclogfile = NULL;
nclogstream = NULL;
/* Use environment variables to preset nclogging state*/
/* I hope this is portable*/
file = getenv(NCENVFLAG);
if(file != NULL && strlen(file) > 0) {
if(nclogopen(file)) {
ncsetlogging(1);

View File

@ -554,7 +554,6 @@ oc_dds_fieldbyname(OCobject link, OCobject ddsnode, const char* name, OCobject*
size_t count,i;
OCVERIFY(OC_Node,ddsnode);
OCDEREF(OCnode*,node,ddsnode);
if(!iscontainer(node->octype))
return OC_EBADTYPE;

View File

@ -31,6 +31,10 @@
#define TMPPATH2 "./"
#endif
#define CLBRACE '{'
#define CRBRACE '}'
/* Define default rc files and aliases*/
static char* rcfilenames[4] = {".daprc",".dodsrc",".ocrc",NULL};
@ -39,6 +43,7 @@ static int ocextractddsinfile(OCstate*,OCtree*,int);
static char* constraintescape(const char* url);
static OCerror createtempfile(OCstate*,OCtree*);
static int createtempfile1(char*,char**);
static int dataError(XXDR* xdrs, OCstate*);
static void ocsetcurlproperties(OCstate*);
@ -299,6 +304,17 @@ fprintf(stderr,"ocfetch.datadds.memory: datasize=%lu bod=%lu\n",
= xxdr_memcreate(tree->data.memory,tree->data.datasize,tree->data.bod);
}
MEMCHECK(tree->data.xdrs,OC_ENOMEM);
/* Do a quick check to see if server returned an ERROR {}
at the beginning of the data
*/
if(dataError(tree->data.xdrs,state)) {
stat = OC_EDATADDS;
oclog(OCLOGERR,"oc_open: server error retrieving url: code=%s message=\"%s\"",
state->error.code,
(state->error.message?state->error.message:""));
goto fail;
}
/* Compile the data into a more accessible format */
stat = occompile(state,tree->root);
if(stat != OC_NOERR)
@ -589,3 +605,43 @@ ocsetuseragent(OCstate* state, const char* agent)
return OC_ENOMEM;
return OC_NOERR;
}
static char* ERROR_TAG = "Error ";
static int
dataError(XXDR* xdrs, OCstate* state)
{
int depth;
off_t ckp,avail,i;
char* errmsg;
char errortext[16]; /* bigger thant |ERROR_TAG|*/
avail = xxdr_getavail(xdrs);
if(avail < strlen(ERROR_TAG))
return 0; /* assume it is ok */
ckp = xxdr_getpos(xdrs);
/* Read enough characters to test for 'ERROR ' */
errortext[0] = '\0';
xxdr_getbytes(xdrs,errortext,(off_t)strlen(ERROR_TAG));
if(ocstrncmp(errortext,ERROR_TAG,strlen(ERROR_TAG)) != 0)
return 0; /* not an immediate error */
/* Try to locate the whole error body */
xxdr_setpos(xdrs,ckp);
for(depth=0,i=0;i<avail;i++) {
xxdr_getbytes(xdrs,errortext,1);
if(errortext[0] == CLBRACE) depth++;
else if(errortext[0] == CRBRACE) {
depth--;
if(depth == 0) {i++; break;}
}
}
errmsg = (char*)malloc(i+1);
if(errmsg == NULL) return 1;
xxdr_setpos(xdrs,ckp);
xxdr_getbytes(xdrs,errmsg,i);
errmsg[i] = '\0';
state->error.message = errmsg;
state->error.code = strdup("?");
state->error.httpcode = 404;
xxdr_setpos(xdrs,ckp);
return 1;
}

View File

@ -45,8 +45,11 @@ static char* octagname(int tag);
void
ocloginit(void)
{
const char* file = getenv(OCENVFLAG);
const char* file;
if(oclogginginitialized)
return;
oclogginginitialized = 1;
file = getenv(OCENVFLAG);
ocsetlogging(0);
oclogfile = NULL;
oclogstream = NULL;

View File

@ -27,7 +27,8 @@ ocstrndup(const char* s, size_t len)
return dup;
}
/* Do not trust strncmp semantics */
/* Do not trust strncmp semantics; this one
compares upto len chars or to null terminators */
int
ocstrncmp(const char* s1, const char* s2, size_t len)
{