mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-19 17:30:27 +08:00
sync with oc2.0
This commit is contained in:
parent
911bdab962
commit
2bc308432d
@ -2,12 +2,12 @@ NCLIB=../liblib/.libs/libnetcdf.a
|
||||
NCINCL=-I ../liblib
|
||||
|
||||
#CYGWIN
|
||||
LFLAG=-L/usr/lib -L/usr/local/lib
|
||||
HDF5LIB=/usr/lib/libhdf5_hl.a /usr/lib/libhdf5.a
|
||||
#LFLAG=-L/usr/lib -L/usr/local/lib
|
||||
#HDF5LIB=/usr/lib/libhdf5_hl.a /usr/lib/libhdf5.a
|
||||
|
||||
#!CYGWIN
|
||||
#LFLAG=-L/upc/share/ed/local/${HOST}/lib
|
||||
#HDF5LIB=/share/ed/local/${HOST}/lib/libhdf5_hl.a /share/ed/local/${HOST}/lib/libhdf5.a
|
||||
LFLAG=-L/upc/share/ed/local/${HOST}/lib
|
||||
HDF5LIB=/share/ed/local/${HOST}/lib/libhdf5_hl.a /share/ed/local/${HOST}/lib/libhdf5.a
|
||||
|
||||
CURLLIB=-lcurl
|
||||
ZLIB=-lz
|
||||
@ -15,7 +15,7 @@ ZLIB=-lz
|
||||
OTHERLIBS=-lm
|
||||
|
||||
LIBS=${NCLIB} ${LFLAG} ${CURLLIB} ${HDF5LIB} ${ZLIB} ${OTHERLIBS}
|
||||
INCL=-I. -I.. -I../include ${NCINCL}
|
||||
INCL=-I. -I.. -I../include -I../libsrc -I../libsrc4 ${NCINCL}
|
||||
RPATH=-Wl,-rpath,${LFLAG}
|
||||
|
||||
# Might want to specify a particular C compiler with flags
|
||||
@ -216,8 +216,7 @@ cpp::
|
||||
|
||||
##################################################
|
||||
# ncd
|
||||
NCDUMPC=../ncdump/dumplib.c ../ncdump/indent.c ../ncdump/ncdump.c ../ncdump/nctime0.c ../ncdump/vardata.c ../ncdump/utils.c ../ncdump/nciter.c
|
||||
NCDUMPH=../ncdump/cdl.h ../ncdump/dumplib.h ../ncdump/indent.h ../ncdump/isnan.h ../ncdump/ncdump.h ../ncdump/nctime0.h ../ncdump/vardata.h ../ncdump/utils.h
|
||||
NCDUMPC= ../ncdump/ncdump.c ../ncdump/vardata.c ../ncdump/dumplib.c ../ncdump/indent.c ../ncdump/nctime0.c ../ncdump/nciter.c ../ncdump/utils.c
|
||||
|
||||
NCDUMPOBJ=${NCDUMPC:../ncdump/%.c=%.o}
|
||||
|
||||
@ -258,7 +257,12 @@ fix::
|
||||
done
|
||||
|
||||
##################################################
|
||||
T=junk
|
||||
E=common34
|
||||
e::
|
||||
cc -E -g -c ${E}.c ${INCL} -I../oc2 >${E}.txt
|
||||
|
||||
##################################################
|
||||
T=
|
||||
|
||||
v::
|
||||
cc -g -c ${T}.c ${INCL}
|
||||
|
@ -7,9 +7,9 @@
|
||||
#define DEBUG_H
|
||||
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
#define DAPDEBUG 1
|
||||
#define OCDEBUG
|
||||
#define OCDEBUG 1
|
||||
#endif
|
||||
|
||||
#include "ocdebug.h"
|
||||
|
19
libdap2/env
19
libdap2/env
@ -5,17 +5,18 @@ TOP="/home/dmh/mach/trunk"
|
||||
#TOP="/cygdrive/f/svn/trunk"
|
||||
#TOP="/cygdrive/c/Users/dmh/svn/trunk"
|
||||
|
||||
#PROG=./ncd
|
||||
PROG="$TOP/ncdump/ncdump"
|
||||
PROG=./ncd
|
||||
#PROG="$TOP/ncdump/ncdump"
|
||||
|
||||
P=`pwd`
|
||||
|
||||
#F='http://colossus.dl.stevens-tech.edu/thredds/dodsC/fmrc/NYBight/NYHOPS_Forecast_Collection_for_the_New_York_Bight_best.ncd'
|
||||
F="http://iridl.ldeo.columbia.edu/SOURCES/.Models/.NMME/.NASA-GMAO/.MONTHLY/.sst/dods"
|
||||
|
||||
#F="http://ticket:ticket1@utmea.enea.it:8080/thredds/dodsC/UNIDATA_passwd/head_out.nc"
|
||||
|
||||
#CON='xpos'
|
||||
#VAR=data
|
||||
|
||||
F="http://opendap.deltares.nl/opendap/test/testNcWithManyVariables/test3000.nc"
|
||||
|
||||
PARMS="log"
|
||||
#PARMS="${PARMS}&netcdf3"
|
||||
#PARMS="${PARMS}&fetch=disk"
|
||||
@ -23,13 +24,15 @@ PARMS="log"
|
||||
#PARMS="${PARMS}&nocache"
|
||||
#PARMS="${PARMS}&wholevar"
|
||||
PARMS="${PARMS}&show=fetch"
|
||||
#PARMS="${PARMS}&noprefetch"
|
||||
PARMS="${PARMS}&noprefetch"
|
||||
#PARMS="${PARMS}&prefetch"
|
||||
#PARMS="${PARMS}&prefetch=eager"
|
||||
|
||||
VARGS="--leak-check=full"
|
||||
|
||||
# Pick in order
|
||||
if test "x$PROG" = x ; then
|
||||
for f in ../ncdump/.libs/lt-ncdump ../ncdump/.libs/ncdump ../ncdump/ncdump ./ncd ; do
|
||||
for f in ./ncd ../ncdump/.libs/lt-ncdump ../ncdump/.libs/ncdump ../ncdump/ncdump ; do
|
||||
if test -f $f ; then
|
||||
PROG="$f"
|
||||
break;
|
||||
@ -50,8 +53,6 @@ UALL="$U${PARMS}"
|
||||
#ARGS="-c $ARGS"
|
||||
if test "x$VAR" != "x" ; then ARGS="$ARGS -v $VAR" ; fi
|
||||
|
||||
VARGS="--leak-check=full"
|
||||
|
||||
alias qq="gdb --args $PROG $ARGS '$U'"
|
||||
alias qv="valgrind $VARGS PROG $ARGS '$U'"
|
||||
alias q0="$PROG $ARGS '$UALL'"
|
||||
|
@ -50,6 +50,7 @@ static int
|
||||
ncd3initialize(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
compute_nccalignments();
|
||||
for(i=0;i<NC_MAX_VAR_DIMS;i++) {
|
||||
dap_one[i] = 1;
|
||||
|
@ -209,7 +209,6 @@ static int
|
||||
check_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, const size_t *chunksizes)
|
||||
{
|
||||
NC_TYPE_INFO_T *type_info;
|
||||
size_t prod;
|
||||
double dprod;
|
||||
size_t type_len;
|
||||
int d;
|
||||
@ -302,7 +301,7 @@ nc4_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
#ifdef LOGGING
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
total_chunk_size *= (double) var->chunksizes[d];
|
||||
p LOG((4, "total_chunk_size %f", total_chunk_size));
|
||||
LOG((4, "total_chunk_size %f", total_chunk_size));
|
||||
#endif
|
||||
|
||||
/* But did this add up to a chunk that is too big? */
|
||||
|
@ -235,7 +235,7 @@ srcsetfill(Datasrc* ds, Datalist* list)
|
||||
|
||||
|
||||
/**************************************************/
|
||||
#ifdef DEBUG
|
||||
#ifdef GENDEBUG
|
||||
void
|
||||
report(char* lead, Datalist* list)
|
||||
{
|
||||
|
@ -17,15 +17,14 @@
|
||||
#endif
|
||||
|
||||
#ifdef GENDEBUG
|
||||
# define DEBUG
|
||||
# if GENDEBUG > 0
|
||||
# define DEBUG1
|
||||
# define GENDEBUG1
|
||||
# endif
|
||||
# if GENDEBUG > 1
|
||||
# define DEBUG2
|
||||
# define GENDEBUG2
|
||||
# endif
|
||||
# if GENDEBUG > 2
|
||||
# define DEBUG3
|
||||
# define GENDEBUG3
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -377,7 +377,7 @@ genbin_writevar(Generator* generator, Symbol* vsym, Bytebuffer* memory,
|
||||
{ int i; for(i=0;i<rank;i++) count[i] = indices[i] - start[i];}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef GENDEBUG
|
||||
{
|
||||
int i;
|
||||
fprintf(stderr,"startset = [");
|
||||
@ -498,7 +498,7 @@ genbin_writeattr(Generator* generator, Symbol* asym, Bytebuffer* databuf,
|
||||
stat = nc_put_att(grpid,varid,asym->name,typid,
|
||||
len,(void*)data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
#ifdef DEBUG
|
||||
#ifdef GENDEBUG
|
||||
{
|
||||
char out[4096];
|
||||
memset(out,0x77,sizeof(out));
|
||||
|
@ -36,7 +36,7 @@ getfiller(Symbol* tvsym)
|
||||
filler = builddatalist(0);
|
||||
fill(tsym,filler);
|
||||
}
|
||||
#ifdef DEBUG2
|
||||
#ifdef GENDEBUG2
|
||||
dumpdatalist(filler,"getfiller");
|
||||
#endif
|
||||
if(tvsym->objectclass == NC_VAR) {
|
||||
|
@ -441,7 +441,7 @@ dimdecl:
|
||||
dimd '=' UINT_CONST
|
||||
{
|
||||
$1->dim.declsize = (size_t)uint32_val;
|
||||
#ifdef DEBUG1
|
||||
#ifdef GENDEBUG1
|
||||
fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize);
|
||||
#endif
|
||||
}
|
||||
@ -452,7 +452,7 @@ fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize)
|
||||
YYABORT;
|
||||
}
|
||||
$1->dim.declsize = (size_t)int32_val;
|
||||
#ifdef DEBUG1
|
||||
#ifdef GENDEBUG1
|
||||
fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize);
|
||||
#endif
|
||||
}
|
||||
@ -465,7 +465,7 @@ fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize)
|
||||
if (double_val - (size_t) double_val > 0)
|
||||
yyerror("dimension length must be an integer");
|
||||
$1->dim.declsize = (size_t)double_val;
|
||||
#ifdef DEBUG1
|
||||
#ifdef GENDEBUG1
|
||||
fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize);
|
||||
#endif
|
||||
}
|
||||
@ -473,7 +473,7 @@ fprintf(stderr,"dimension: %s = %lu\n",$1->name,(unsigned long)$1->dim.declsize)
|
||||
{
|
||||
$1->dim.declsize = NC_UNLIMITED;
|
||||
$1->dim.isunlimited = 1;
|
||||
#ifdef DEBUG1
|
||||
#ifdef GENDEBUG1
|
||||
fprintf(stderr,"dimension: %s = UNLIMITED\n",$1->name);
|
||||
#endif
|
||||
}
|
||||
|
@ -1122,7 +1122,7 @@ computeunlimitedsizes(Dimset* dimset, int dimindex, Datalist* data, int ischar)
|
||||
unlimsize = length / xproduct;
|
||||
if(length % xproduct != 0)
|
||||
unlimsize++; /* => fill requires at some point */
|
||||
#ifdef DEBUG2
|
||||
#ifdef GENDEBUG2
|
||||
fprintf(stderr,"unlimsize: dim=%s declsize=%lu xproduct=%lu newsize=%lu\n",
|
||||
thisunlim->name,
|
||||
(unsigned long)thisunlim->dim.declsize,
|
||||
@ -1164,7 +1164,7 @@ thisunlim->name,
|
||||
unlimsize = length / xproduct;
|
||||
if(length % xproduct != 0)
|
||||
unlimsize++; /* => fill requires at some point */
|
||||
#ifdef DEBUG2
|
||||
#ifdef GENDEBUG2
|
||||
fprintf(stderr,"unlimsize: dim=%s declsize=%lu xproduct=%lu newsize=%lu\n",
|
||||
thisunlim->name,
|
||||
(unsigned long)thisunlim->dim.declsize,
|
||||
@ -1208,7 +1208,7 @@ processunlimiteddims(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG1
|
||||
#ifdef GENDEBUG1
|
||||
/* print unlimited dim size */
|
||||
if(listlength(dimdefs) == 0)
|
||||
fprintf(stderr,"unlimited: no unlimited dimensions\n");
|
||||
|
1443
oc2/daptab.c
1443
oc2/daptab.c
File diff suppressed because it is too large
Load Diff
91
oc2/daptab.h
91
oc2/daptab.h
@ -1,19 +1,19 @@
|
||||
/* A Bison parser, made by GNU Bison 2.6.4. */
|
||||
/* A Bison parser, made by GNU Bison 3.0. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
|
||||
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
@ -26,13 +26,13 @@
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
#ifndef YY_DAP_DAP_TAB_H_INCLUDED
|
||||
# define YY_DAP_DAP_TAB_H_INCLUDED
|
||||
/* Enabling traces. */
|
||||
/* Debug traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 1
|
||||
#endif
|
||||
@ -40,61 +40,48 @@
|
||||
extern int dapdebug;
|
||||
#endif
|
||||
|
||||
/* Tokens. */
|
||||
/* Token type. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
SCAN_ALIAS = 258,
|
||||
SCAN_ARRAY = 259,
|
||||
SCAN_ATTR = 260,
|
||||
SCAN_BYTE = 261,
|
||||
SCAN_CODE = 262,
|
||||
SCAN_DATASET = 263,
|
||||
SCAN_DATA = 264,
|
||||
SCAN_ERROR = 265,
|
||||
SCAN_FLOAT32 = 266,
|
||||
SCAN_FLOAT64 = 267,
|
||||
SCAN_GRID = 268,
|
||||
SCAN_INT16 = 269,
|
||||
SCAN_INT32 = 270,
|
||||
SCAN_MAPS = 271,
|
||||
SCAN_MESSAGE = 272,
|
||||
SCAN_SEQUENCE = 273,
|
||||
SCAN_STRING = 274,
|
||||
SCAN_STRUCTURE = 275,
|
||||
SCAN_UINT16 = 276,
|
||||
SCAN_UINT32 = 277,
|
||||
SCAN_URL = 278,
|
||||
SCAN_PTYPE = 279,
|
||||
SCAN_PROG = 280,
|
||||
WORD_WORD = 281,
|
||||
WORD_STRING = 282
|
||||
};
|
||||
enum yytokentype
|
||||
{
|
||||
SCAN_ALIAS = 258,
|
||||
SCAN_ARRAY = 259,
|
||||
SCAN_ATTR = 260,
|
||||
SCAN_BYTE = 261,
|
||||
SCAN_CODE = 262,
|
||||
SCAN_DATASET = 263,
|
||||
SCAN_DATA = 264,
|
||||
SCAN_ERROR = 265,
|
||||
SCAN_FLOAT32 = 266,
|
||||
SCAN_FLOAT64 = 267,
|
||||
SCAN_GRID = 268,
|
||||
SCAN_INT16 = 269,
|
||||
SCAN_INT32 = 270,
|
||||
SCAN_MAPS = 271,
|
||||
SCAN_MESSAGE = 272,
|
||||
SCAN_SEQUENCE = 273,
|
||||
SCAN_STRING = 274,
|
||||
SCAN_STRUCTURE = 275,
|
||||
SCAN_UINT16 = 276,
|
||||
SCAN_UINT32 = 277,
|
||||
SCAN_URL = 278,
|
||||
SCAN_PTYPE = 279,
|
||||
SCAN_PROG = 280,
|
||||
WORD_WORD = 281,
|
||||
WORD_STRING = 282
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef int YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef YYPARSE_PARAM
|
||||
#if defined __STDC__ || defined __cplusplus
|
||||
int dapparse (void *YYPARSE_PARAM);
|
||||
#else
|
||||
int dapparse ();
|
||||
#endif
|
||||
#else /* ! YYPARSE_PARAM */
|
||||
#if defined __STDC__ || defined __cplusplus
|
||||
|
||||
int dapparse (DAPparsestate* parsestate);
|
||||
#else
|
||||
int dapparse ();
|
||||
#endif
|
||||
#endif /* ! YYPARSE_PARAM */
|
||||
|
||||
#endif /* !YY_DAP_DAP_TAB_H_INCLUDED */
|
||||
|
21
oc2/oc.c
21
oc2/oc.c
@ -11,6 +11,7 @@
|
||||
#include "ocdump.h"
|
||||
#include "oclog.h"
|
||||
#include "occlientparams.h"
|
||||
#include "occurlfunctions.h"
|
||||
#include "ochttp.h"
|
||||
|
||||
#undef TRACK
|
||||
@ -1929,6 +1930,26 @@ oc_set_useragent(OCobject link, const char* agent)
|
||||
return ocsetuseragent(state,agent);
|
||||
}
|
||||
|
||||
/*!
|
||||
Force the curl library to trace its actions.
|
||||
|
||||
\param[in] link The link through which the server is accessed.
|
||||
|
||||
\retval OC_NOERR if the request succeeded.
|
||||
\retval OC_EINVAL if the request failed.
|
||||
|
||||
*/
|
||||
|
||||
OCerror
|
||||
oc_trace_curl(OCobject link)
|
||||
{
|
||||
OCstate* state;
|
||||
OCVERIFY(OC_State,link);
|
||||
OCDEREF(OCstate*,state,link);
|
||||
oc_curl_debug(state);
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
/**************************************************/
|
||||
|
6
oc2/oc.h
6
oc2/oc.h
@ -531,6 +531,12 @@ extern OCerror oc_svcerrordata(OClink link, char** codep,
|
||||
/**************************************************/
|
||||
/* Experimental/Undocumented */
|
||||
|
||||
/*
|
||||
Cause the curl library
|
||||
to be verbose
|
||||
*/
|
||||
extern OCerror oc_trace_curl(OClink link);
|
||||
|
||||
/* Given an arbitrary OCnode, return the connection of which it is a part */
|
||||
extern OCerror oc_get_connection(OCobject ocnode, OCobject* linkp);
|
||||
|
||||
|
@ -56,6 +56,10 @@ ocset_curl_flags(OCstate* state)
|
||||
CURL* curl = state->curl;
|
||||
struct OCcurlflags* flags = &state->curlflags;
|
||||
|
||||
#if 0
|
||||
cstat = curl_easy_reset(curl);
|
||||
#endif
|
||||
|
||||
#ifdef CURLOPT_ENCODING
|
||||
if (flags->compress) {
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_ENCODING,"deflate, gzip");
|
||||
@ -63,18 +67,19 @@ ocset_curl_flags(OCstate* state)
|
||||
OCDBG(1,"CURLOPT_ENCODING=deflate, gzip");
|
||||
}
|
||||
#endif
|
||||
if (flags->cookiejar || flags->cookiefile) {
|
||||
#if 0
|
||||
Do not think this is correct
|
||||
if (flags->cookiejar) {
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1);
|
||||
if (cstat != CURLE_OK) goto done;
|
||||
OCDBG(1,"CURLOPT_COOKIESESSION=1");
|
||||
}
|
||||
#endif
|
||||
if (flags->cookiejar) {
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_COOKIEJAR, flags->cookiejar);
|
||||
if (cstat != CURLE_OK) goto done;
|
||||
OCDBG1(1,"CURLOPT_COOKIEJAR=%s",flags->cookiejar);
|
||||
}
|
||||
if (flags->cookiefile) {
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_COOKIEFILE, flags->cookiefile);
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_COOKIEFILE, flags->cookiejar);
|
||||
if (cstat != CURLE_OK) goto done;
|
||||
OCDBG1(1,"CURLOPT_COOKIEFILE=%s",flags->cookiefile);
|
||||
}
|
||||
@ -101,6 +106,10 @@ ocset_curl_flags(OCstate* state)
|
||||
OCDBG1(1,"CURLOPT_FOLLOWLOCATION=%ld",1L);
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
|
||||
OCDBG1(1,"CURLOPT_MAXREDIRS=%ld",10L);
|
||||
#if 0
|
||||
cstat = curl_setopt(curl,CURLOPT_RETURNTRANSFER, 1L);
|
||||
OCDBG1(1,"CURLOPT_RETURNTRANSFER=%ld",1L);
|
||||
#endif
|
||||
|
||||
cstat = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, state->error.curlerrorbuf);
|
||||
OCDBG1(1,"CURLOPT_ERRORBUFFER",0);
|
||||
|
@ -247,7 +247,6 @@ ocdata_read(OCstate* state, OCdata* data, size_t start, size_t count,
|
||||
assert(memory != NULL);
|
||||
assert(memsize > 0);
|
||||
|
||||
data = data;
|
||||
template = data->template;
|
||||
octype = template->octype;
|
||||
assert(octype == OC_Atomic);
|
||||
|
195
oc2/ocinternal.c
195
oc2/ocinternal.c
@ -3,12 +3,14 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include "ocinternal.h"
|
||||
#include "ocdebug.h"
|
||||
@ -21,14 +23,14 @@
|
||||
|
||||
/* Note: TMPPATH must end in '/' */
|
||||
#ifdef __CYGWIN__
|
||||
#define TMPPATH1 "/cygdrive/c/temp/"
|
||||
#define TMPPATH2 "./"
|
||||
#define TMPPATH1 "/cygdrive/c/temp/datadds"
|
||||
#define TMPPATH2 "./datadds"
|
||||
#elif _WIN32
|
||||
#define TMPPATH1 "c:\\temp\\"
|
||||
#define TMPPATH2 ".\\"
|
||||
#define TMPPATH1 "c:\\temp\\datadds"
|
||||
#define TMPPATH2 ".\\datadds"
|
||||
#else
|
||||
#define TMPPATH1 "/tmp/"
|
||||
#define TMPPATH2 "./"
|
||||
#define TMPPATH1 "/tmp/datadds"
|
||||
#define TMPPATH2 "./datadds"
|
||||
#endif
|
||||
|
||||
#define CLBRACE '{'
|
||||
@ -42,10 +44,9 @@ static int ocextractddsinmemory(OCstate*,OCtree*,int);
|
||||
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*);
|
||||
static int ocsetcurlproperties(OCstate*);
|
||||
|
||||
extern OCnode* makeunlimiteddimension(void);
|
||||
|
||||
@ -74,6 +75,32 @@ ocinternalinitialize(void)
|
||||
ocglobalstate.initialized = 1;
|
||||
}
|
||||
|
||||
/* Capture $HOME */
|
||||
{
|
||||
char* p;
|
||||
char* q;
|
||||
char* home = getenv("HOME");
|
||||
char cwd[4096];
|
||||
if(ocglobalstate.home == NULL) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
home = getenv("TEMP");
|
||||
#else
|
||||
home = "/tmp";
|
||||
#endif
|
||||
}
|
||||
if(home == NULL) {
|
||||
home = getcwd(cwd,sizeof(cwd));
|
||||
if(home == NULL || *home == '\0') home = ".";
|
||||
}
|
||||
|
||||
/* Convert '\' to '/' */
|
||||
ocglobalstate.home = (char*)malloc(strlen(home) + 1);
|
||||
for(p=home,q=ocglobalstate.home;*p;p++,q++) {
|
||||
if(*p == '\\') {*q = '/'; } else {*q = *p;}
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
|
||||
/* Compute some xdr related flags */
|
||||
xxdr_init();
|
||||
|
||||
@ -84,7 +111,6 @@ ocinternalinitialize(void)
|
||||
/* compile the .dodsrc, if any */
|
||||
{
|
||||
char* path = NULL;
|
||||
char* homepath = NULL;
|
||||
char** alias;
|
||||
FILE* f = NULL;
|
||||
/* locate the configuration files: . first in '.', then $HOME */
|
||||
@ -93,8 +119,8 @@ ocinternalinitialize(void)
|
||||
path = (char*)malloc(pathlen);
|
||||
if(path == NULL) return OC_ENOMEM;
|
||||
if(!occopycat(path,pathlen,2,"./",*alias)) {
|
||||
if(path) free(path);
|
||||
return OC_EOVERRUN;
|
||||
if(path) free(path);
|
||||
return OC_EOVERRUN;
|
||||
}
|
||||
/* see if file is readable */
|
||||
f = fopen(path,"r");
|
||||
@ -103,20 +129,17 @@ ocinternalinitialize(void)
|
||||
}
|
||||
if(f == NULL) { /* try $HOME */
|
||||
OCASSERT(path == NULL);
|
||||
homepath = getenv("HOME");
|
||||
if (homepath!= NULL) {
|
||||
for(alias=rcfilenames;*alias;alias++) {
|
||||
size_t pathlen = strlen(homepath)+1+strlen(*alias)+1;
|
||||
path = (char*)malloc(pathlen);
|
||||
if(path == NULL) return OC_ENOMEM;
|
||||
if(!occopycat(path,pathlen,3,homepath,"/",*alias)) {
|
||||
if(path) {free(path);}
|
||||
return OC_EOVERRUN;
|
||||
}
|
||||
f = fopen(path,"r");
|
||||
if(f != NULL) break;
|
||||
if(path != NULL) {free(path); path=NULL;}
|
||||
for(alias=rcfilenames;*alias;alias++) {
|
||||
size_t pathlen = strlen(ocglobalstate.home)+1+strlen(*alias)+1;
|
||||
path = (char*)malloc(pathlen);
|
||||
if(path == NULL) return OC_ENOMEM;
|
||||
if(!occopycat(path,pathlen,3,ocglobalstate.home,"/",*alias)) {
|
||||
if(path) free(path);
|
||||
return OC_EOVERRUN;
|
||||
}
|
||||
f = fopen(path,"r");
|
||||
if(f != NULL) break;
|
||||
if(path != NULL) {free(path); path=NULL;}
|
||||
}
|
||||
}
|
||||
if(f == NULL) {
|
||||
@ -131,6 +154,7 @@ ocinternalinitialize(void)
|
||||
}
|
||||
if(path != NULL) free(path);
|
||||
}
|
||||
|
||||
return OCTHROW(stat);
|
||||
}
|
||||
|
||||
@ -164,7 +188,7 @@ ocopen(OCstate** statep, const char* url)
|
||||
ocbytessetalloc(state->packet,DFALTPACKETSIZE); /*initial reasonable size*/
|
||||
|
||||
/* set curl properties for this link */
|
||||
ocsetcurlproperties(state);
|
||||
stat = ocsetcurlproperties(state);
|
||||
|
||||
if(statep) *statep = state;
|
||||
return OCTHROW(stat);
|
||||
@ -344,16 +368,14 @@ fail:
|
||||
static OCerror
|
||||
createtempfile(OCstate* state, OCtree* tree)
|
||||
{
|
||||
int stat = OC_NOERR;
|
||||
int fd = 0;
|
||||
char* name = NULL;
|
||||
fd = createtempfile1(TMPPATH1,&name);
|
||||
if(fd < 0)
|
||||
fd = createtempfile1(TMPPATH2,&name);
|
||||
if(fd < 0) {
|
||||
oclog(OCLOGERR,"oc_open: attempt to open tmp file failed: %s",name);
|
||||
if(name) free(name);
|
||||
return errno;
|
||||
}
|
||||
|
||||
stat = ocmktmp(TMPPATH1,&name, &fd);
|
||||
if(stat != OC_NOERR)
|
||||
stat = ocmktmp(TMPPATH2,&name,&fd);
|
||||
if(stat != OC_NOERR) goto fail;
|
||||
#ifdef OCDEBUG
|
||||
oclog(OCLOGNOTE,"oc_open: using tmp file: %s",name);
|
||||
#endif
|
||||
@ -362,49 +384,12 @@ createtempfile(OCstate* state, OCtree* tree)
|
||||
if(tree->data.file == NULL) return OC_EOPEN;
|
||||
/* unlink the temp file so it will automatically be reclaimed */
|
||||
if(ocdebug == 0) unlink(tree->data.filename);
|
||||
return OC_NOERR;
|
||||
}
|
||||
return stat;
|
||||
|
||||
int
|
||||
createtempfile1(char* tmppath, char** tmpnamep)
|
||||
{
|
||||
int fd = 0;
|
||||
char* tmpname = NULL;
|
||||
size_t tmpsize = strlen(tmppath)+strlen("dataddsXXXXXX") + 1;
|
||||
tmpname = (char*)malloc(tmpsize);
|
||||
if(tmpname == NULL) return -1;
|
||||
if(!occopycat(tmpname,tmpsize,1,tmppath))
|
||||
return OC_EOVERRUN;
|
||||
#ifdef HAVE_MKSTEMP
|
||||
if(!occoncat(tmpname,tmpsize,1,"dataddsXXXXXX"))
|
||||
return OC_EOVERRUN;
|
||||
/* Note Potential problem: old versions of this function
|
||||
leave the file in mode 0666 instead of 0600 */
|
||||
umask(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
fd = mkstemp(tmpname);
|
||||
#else /* !HAVE_MKSTEMP */
|
||||
/* Need to simulate by using some kind of pseudo-random number */
|
||||
if(!occoncat(tmpname,tmpsize,1,"datadds"))
|
||||
return OC_EOVERRUN;
|
||||
{
|
||||
int rno = rand();
|
||||
char spid[7];
|
||||
if(rno < 0) rno = -rno;
|
||||
snprintf(spid,sizeof(spid),"%06d",rno);
|
||||
if(!occoncat(tmpname,tmpsize,1,spid))
|
||||
return OC_EOVERRUN;
|
||||
# ifdef _WIN32
|
||||
fd=open(tmpname,O_RDWR|O_BINARY|O_CREAT|O_EXCL|FILE_ATTRIBUTE_TEMPORARY, _S_IREAD|_S_IWRITE);
|
||||
# else
|
||||
fd=open(tmpname,O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
|
||||
# endif
|
||||
}
|
||||
#endif /* !HAVE_MKSTEMP */
|
||||
if(tmpname == NULL) return -1;
|
||||
if(tmpnamep) *tmpnamep = tmpname;
|
||||
else
|
||||
free(tmpname);
|
||||
return fd;
|
||||
fail:
|
||||
if(name != NULL) free(name);
|
||||
oclog(OCLOGERR,"oc_open: attempt to create tmp file failed: %s",name);
|
||||
return stat;
|
||||
}
|
||||
|
||||
void
|
||||
@ -426,7 +411,6 @@ occlose(OCstate* state)
|
||||
ocfree(state->error.message);
|
||||
ocfree(state->curlflags.useragent);
|
||||
ocfree(state->curlflags.cookiejar);
|
||||
ocfree(state->curlflags.cookiefile);
|
||||
ocfree(state->ssl.certificate);
|
||||
ocfree(state->ssl.key);
|
||||
ocfree(state->ssl.keypasswd);
|
||||
@ -567,12 +551,14 @@ ocupdatelastmodifieddata(OCstate* state)
|
||||
}
|
||||
|
||||
/*
|
||||
Set curl properties for link based on rc files
|
||||
Set curl properties for link based on rc files etc.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
ocsetcurlproperties(OCstate* state)
|
||||
{
|
||||
CURLcode cstat = CURLE_OK;
|
||||
CURL* curl = state->curl;
|
||||
int stat;
|
||||
|
||||
/* process the triple store wrt to this state */
|
||||
if(ocdodsrc_process(state) != OC_NOERR) {
|
||||
@ -592,16 +578,57 @@ ocsetcurlproperties(OCstate* state)
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
|
||||
char* agent = (char*)malloc(len+1);
|
||||
if(occopycat(agent,len,2,DFALTUSERAGENT,VERSION))
|
||||
state->curlflags.useragent = agent;
|
||||
state->curlflags.useragent = agent;
|
||||
else
|
||||
free(agent);
|
||||
free(agent);
|
||||
}
|
||||
return;
|
||||
|
||||
/* Some servers (e.g. thredds and columbia) appear to require a place
|
||||
to put cookies in order for some security functions to work
|
||||
*/
|
||||
if(state->curlflags.cookiejar == NULL
|
||||
|| *state->curlflags.cookiejar) {
|
||||
/* If no cookie file was defined, define a default */
|
||||
char id[17];
|
||||
char* tmp;
|
||||
int fd;
|
||||
|
||||
snprintf(id,sizeof(id),"%016lx",*(long*)&curl);
|
||||
|
||||
tmp = (char*)malloc(strlen(ocglobalstate.home)
|
||||
+strlen("/")
|
||||
+strlen(OCDIR)
|
||||
+strlen("/")
|
||||
+strlen(id)
|
||||
+1);
|
||||
if(tmp == NULL)
|
||||
return OC_ENOMEM;
|
||||
strcpy(tmp,ocglobalstate.home);
|
||||
strcat(tmp,"/");
|
||||
strcat(tmp,OCDIR);
|
||||
stat = mkdir(tmp,S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
if(stat != 0 && errno != EEXIST) {
|
||||
fprintf(stderr,"Cannot create cookie file\n");
|
||||
return stat;
|
||||
}
|
||||
errno = 0;
|
||||
/* Create the actual cookie file */
|
||||
strcat(tmp,"/");
|
||||
strcat(tmp,id);
|
||||
fd = creat(tmp,S_IRUSR | S_IWUSR);
|
||||
if(fd < 0) {
|
||||
fprintf(stderr,"Cannot create cookie file\n");
|
||||
return OC_EPERM;
|
||||
} else
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return OC_NOERR;
|
||||
|
||||
fail:
|
||||
if(cstat != CURLE_OK)
|
||||
oclog(OCLOGERR, "curl error: %s", curl_easy_strerror(cstat));
|
||||
return;
|
||||
return OC_ECURL;
|
||||
}
|
||||
|
||||
OCerror
|
||||
|
@ -87,6 +87,8 @@ typedef struct OCheader {
|
||||
#define nullstring(s) (s==NULL?"(null)":s)
|
||||
#define PATHSEPARATOR "."
|
||||
|
||||
#define OCDIR ".oc"
|
||||
|
||||
/* Define infinity for memory size */
|
||||
#if SIZEOF_SIZE_T == 4
|
||||
#define OCINFINITY ((size_t)0xffffffff)
|
||||
@ -114,6 +116,7 @@ extern struct OCGLOBALSTATE {
|
||||
int proto_https;
|
||||
} curl;
|
||||
struct OCTriplestore* ocdodsrc; /* the .dodsrc triple store */
|
||||
char* home; /* track $HOME for use in creating $HOME/.oc dir */
|
||||
} ocglobalstate;
|
||||
|
||||
/*! Specifies the OCstate = non-opaque version of OClink */
|
||||
@ -140,7 +143,6 @@ struct OCstate {
|
||||
int maxredirs;
|
||||
char* useragent;
|
||||
char* cookiejar;
|
||||
char* cookiefile;
|
||||
} curlflags;
|
||||
struct OCSSL {
|
||||
int validate;
|
||||
|
14
oc2/ocrc.c
14
oc2/ocrc.c
@ -387,12 +387,6 @@ ocdodsrc_process(OCstate* state)
|
||||
oclog(OCLOGNOTE,"USERAGENT: %s", state->curlflags.useragent);
|
||||
}
|
||||
|
||||
if((value = curllookup("COOKIEFILE",url)) != NULL) {
|
||||
state->curlflags.cookiefile = strdup(TRIM(value));
|
||||
if(!state->curlflags.cookiefile) {stat = OC_ENOMEM; goto done;}
|
||||
if(ocdebug > 0)
|
||||
oclog(OCLOGNOTE,"COOKIEFILE: %s", state->curlflags.cookiefile);
|
||||
}
|
||||
if((value = curllookup("COOKIEJAR",url))
|
||||
|| (value = curllookup("COOKIE_JAR",url))) {
|
||||
state->curlflags.cookiejar = strdup(TRIM(value));
|
||||
@ -401,14 +395,6 @@ ocdodsrc_process(OCstate* state)
|
||||
oclog(OCLOGNOTE,"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 = curllookup("PROXY_SERVER",url)) != NULL) {
|
||||
stat = parseproxy(state,TRIM(value));
|
||||
if(stat != OC_NOERR) goto done;
|
||||
|
@ -104,7 +104,10 @@ readpacket(OCstate* state, OCURI* url,OCbytes* packet,OCdxd dxd,long* lastmodifi
|
||||
stat = readfile(fetchurl,suffix,packet);
|
||||
} else {
|
||||
int flags = 0;
|
||||
if(!fileprotocol) flags |= OCURICONSTRAINTS;
|
||||
if(!fileprotocol) {
|
||||
flags |= OCURICONSTRAINTS;
|
||||
flags |= OCURIUSERPWD;
|
||||
}
|
||||
flags |= OCURIENCODE;
|
||||
fetchurl = ocuribuild(url,NULL,suffix,flags);
|
||||
MEMCHECK(fetchurl,OC_ENOMEM);
|
||||
@ -153,6 +156,7 @@ fprintf(stderr,"readDATADDS:\n");
|
||||
int flags = 0;
|
||||
if(!fileprotocol) flags |= OCURICONSTRAINTS;
|
||||
flags |= OCURIENCODE;
|
||||
flags |= OCURIUSERPWD;
|
||||
ocurisetconstraints(url,tree->constraint);
|
||||
readurl = ocuribuild(url,NULL,".dods",flags);
|
||||
MEMCHECK(readurl,OC_ENOMEM);
|
||||
|
51
oc2/ocutil.c
51
oc2/ocutil.c
@ -8,6 +8,11 @@
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include "ocinternal.h"
|
||||
#include "ocdebug.h"
|
||||
|
||||
@ -668,3 +673,49 @@ done:
|
||||
va_end(args);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Wrap mktmp
|
||||
*/
|
||||
|
||||
int
|
||||
ocmktmp(const char* base, char** tmpnamep, int* fdp)
|
||||
{
|
||||
int fd;
|
||||
char* tmpname = NULL;
|
||||
mode_t oldmask;
|
||||
size_t tmpsize = strlen(base)+strlen("XXXXXX") + 1;
|
||||
|
||||
tmpname = (char*)malloc(tmpsize);
|
||||
if(tmpname == NULL) return OC_ENOMEM;
|
||||
if(!occopycat(tmpname,tmpsize,1,base))
|
||||
return OC_EOVERRUN;
|
||||
#ifdef HAVE_MKSTEMP
|
||||
if(!occoncat(tmpname,tmpsize,1,"XXXXXX"))
|
||||
return OC_EOVERRUN;
|
||||
/* Note Potential problem: old versions of this function
|
||||
leave the file in mode 0666 instead of 0600 */
|
||||
oldmask= umask(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
fd = mkstemp(tmpname);
|
||||
umask(oldmask); /* restore */
|
||||
#else /* !HAVE_MKSTEMP */
|
||||
/* Need to simulate by using some kind of pseudo-random number */
|
||||
{
|
||||
int rno = rand();
|
||||
char spid[7];
|
||||
if(rno < 0) rno = -rno;
|
||||
snprintf(spid,sizeof(spid),"%06d",rno);
|
||||
if(!occoncat(tmpname,tmpsize,1,spid))
|
||||
return OC_EOVERRUN;
|
||||
# ifdef _WIN32
|
||||
fd=open(tmpname,O_RDWR|O_BINARY|O_CREAT|O_EXCL|FILE_ATTRIBUTE_TEMPORARY, _S_IREAD|_S_IWRITE);
|
||||
# else
|
||||
fd=open(tmpname,O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
|
||||
# endif
|
||||
}
|
||||
#endif /* !HAVE_MKSTEMP */
|
||||
if(tmpnamep) *tmpnamep = tmpname;
|
||||
if(fdp) *fdp = fd;
|
||||
return OC_NOERR;
|
||||
}
|
||||
|
@ -41,6 +41,9 @@ extern int ocfindbod(OCbytes* buffer, size_t*, size_t*);
|
||||
extern void ocfreeprojectionclause(OCprojectionclause* clause);
|
||||
|
||||
/* Misc. */
|
||||
|
||||
extern int ocmktmp(const char* base, char** tmpnamep, int* fdp);
|
||||
|
||||
extern void ocdataddsmsg(struct OCstate*, struct OCtree*);
|
||||
|
||||
extern const char* ocdtmodestring(OCDT mode,int compact);
|
||||
|
@ -222,7 +222,8 @@ xxdr_skip(XXDR* xdrs, off_t len)
|
||||
unsigned int pos;
|
||||
pos = xxdr_getpos(xdrs);
|
||||
pos = (pos + len);
|
||||
if(pos < 0) pos = 0;
|
||||
// Removed the following; pos is unsigned. jhrg 9/30/13
|
||||
// if(pos < 0) pos = 0;
|
||||
return xxdr_setpos(xdrs,pos);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user