2012-08-01 04:34:13 +08:00
|
|
|
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
|
|
|
|
#ifndef OCINTERNAL_H
|
|
|
|
#define OCINTERNAL_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2017-09-03 08:09:36 +08:00
|
|
|
#ifdef _MSC_VER
|
2013-03-20 06:40:15 +08:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 07:03:27 +08:00
|
|
|
/* Required for getcwd, other functions. */
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <direct.h>
|
|
|
|
#define getcwd _getcwd
|
|
|
|
#endif
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#ifdef _AIX
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2012-12-07 05:17:36 +08:00
|
|
|
#ifdef HAVE_STRINGS_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2012-12-07 05:17:36 +08:00
|
|
|
#ifdef HAVE_STDARG_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <stdarg.h>
|
2012-12-07 05:17:36 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CURL_DISABLE_TYPECHECK 1
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "netcdf.h"
|
2017-09-01 04:19:56 +08:00
|
|
|
#include "ncauth.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "nclist.h"
|
|
|
|
#include "ncbytes.h"
|
|
|
|
#include "ncuri.h"
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2014-11-22 07:20:44 +08:00
|
|
|
#ifndef HAVE_STRNDUP
|
|
|
|
/* Not all systems have strndup, so provide one*/
|
|
|
|
#define strndup ocstrndup
|
|
|
|
#endif
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#define OCCACHEPOS
|
|
|
|
|
2014-08-08 07:03:27 +08:00
|
|
|
#ifndef HAVE_STRNDUP
|
|
|
|
/* Not all systems have strndup, so provide one*/
|
|
|
|
#define strndup ocstrndup
|
|
|
|
#endif
|
|
|
|
|
2014-12-25 01:22:47 +08:00
|
|
|
#define OCPATHMAX 8192
|
|
|
|
|
|
|
|
#ifndef nullfree
|
|
|
|
#define nullfree(x) {if((x)!=NULL) free(x);}
|
|
|
|
#endif
|
2014-08-08 07:03:27 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Forwards */
|
|
|
|
typedef struct OCstate OCstate;
|
|
|
|
typedef struct OCnode OCnode;
|
|
|
|
typedef struct OCdata OCdata;
|
|
|
|
struct OCTriplestore;
|
|
|
|
|
|
|
|
/* Define the internal node classification values */
|
2017-03-09 08:01:10 +08:00
|
|
|
#define OC_None ((unsigned int)0)
|
|
|
|
#define OC_State ((unsigned int)1)
|
|
|
|
#define OC_Node ((unsigned int)2)
|
|
|
|
#define OC_Data ((unsigned int)3)
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
/* Define a magic number to mark externally visible oc objects */
|
|
|
|
#define OCMAGIC ((unsigned int)0x0c0c0c0c) /*clever, huh*/
|
|
|
|
|
2014-12-25 01:22:47 +08:00
|
|
|
/* Max rc file line size */
|
|
|
|
#define MAXRCLINESIZE 4096
|
|
|
|
|
|
|
|
/* Max number of triples from an rc file */
|
|
|
|
#define MAXRCLINES 4096
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Define a struct that all oc objects must start with */
|
|
|
|
/* OCheader must be defined here to make it available in other headers */
|
|
|
|
typedef struct OCheader {
|
|
|
|
unsigned int magic;
|
|
|
|
unsigned int occlass;
|
|
|
|
} OCheader;
|
|
|
|
|
|
|
|
#include "oc.h"
|
|
|
|
#include "ocx.h"
|
|
|
|
#include "ocnode.h"
|
|
|
|
#include "ocdata.h"
|
|
|
|
#include "occonstraints.h"
|
|
|
|
#include "ocutil.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "nclog.h"
|
2012-08-01 04:34:13 +08:00
|
|
|
#include "xxdr.h"
|
|
|
|
#include "ocdatatypes.h"
|
|
|
|
#include "occompile.h"
|
|
|
|
|
|
|
|
#ifndef nulldup
|
|
|
|
#define nulldup(s) (s==NULL?NULL:strdup(s))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for dealing with flag bits.
|
|
|
|
*/
|
|
|
|
#define fset(t,f) ((t) |= (f))
|
|
|
|
#define fclr(t,f) ((t) &= ~(f))
|
|
|
|
#define fisset(t,f) ((t) & (f))
|
|
|
|
|
|
|
|
#define nullstring(s) (s==NULL?"(null)":s)
|
|
|
|
#define PATHSEPARATOR "."
|
|
|
|
|
2017-07-06 00:03:48 +08:00
|
|
|
#define OCCOOKIEDIR "occookies"
|
2013-11-15 06:13:20 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Define infinity for memory size */
|
|
|
|
#if SIZEOF_SIZE_T == 4
|
|
|
|
#define OCINFINITY ((size_t)0xffffffff)
|
|
|
|
#else
|
|
|
|
#define OCINFINITY ((size_t)0xffffffffffffffff)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Extend the OCdxd type for internal use */
|
|
|
|
#define OCVER 3
|
|
|
|
|
|
|
|
/* Default initial memory packet size */
|
|
|
|
#define DFALTPACKETSIZE 0x20000 /*approximately 100k bytes*/
|
|
|
|
|
|
|
|
/* Default maximum memory packet size */
|
|
|
|
#define DFALTMAXPACKETSIZE 0x3000000 /*approximately 50M bytes*/
|
|
|
|
|
2012-12-04 11:32:41 +08:00
|
|
|
/* Default user agent string (will have version appended)*/
|
2017-03-09 08:01:10 +08:00
|
|
|
#ifndef DFALTUSERAGENT
|
2012-12-04 11:32:41 +08:00
|
|
|
#define DFALTUSERAGENT "oc"
|
2017-03-09 08:01:10 +08:00
|
|
|
#endif
|
2012-12-04 11:32:41 +08:00
|
|
|
|
2018-08-27 07:04:46 +08:00
|
|
|
#if 0
|
2014-12-25 01:22:47 +08:00
|
|
|
/* Hold known curl flags */
|
|
|
|
enum OCCURLFLAGTYPE {CF_UNKNOWN=0,CF_OTHER=1,CF_STRING=2,CF_LONG=3};
|
|
|
|
struct OCCURLFLAG {
|
|
|
|
const char* name;
|
|
|
|
int flag;
|
|
|
|
int value;
|
|
|
|
enum OCCURLFLAGTYPE type;
|
|
|
|
};
|
2018-08-27 07:04:46 +08:00
|
|
|
#endif
|
2014-12-25 01:22:47 +08:00
|
|
|
|
|
|
|
struct OCTriplestore {
|
|
|
|
int ntriples;
|
|
|
|
struct OCTriple {
|
|
|
|
char host[MAXRCLINESIZE]; /* includes port if specified */
|
|
|
|
char key[MAXRCLINESIZE];
|
|
|
|
char value[MAXRCLINESIZE];
|
|
|
|
} triples[MAXRCLINES];
|
|
|
|
};
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/*! Specifies the OCstate = non-opaque version of OClink */
|
|
|
|
struct OCstate {
|
|
|
|
OCheader header; /* class=OC_State */
|
2017-03-09 08:01:10 +08:00
|
|
|
NClist* trees; /* list<OCNODE*> ; all root objects */
|
2017-09-03 08:09:36 +08:00
|
|
|
NCURI* uri; /* parsed base URI*/
|
2017-03-09 08:01:10 +08:00
|
|
|
NCbytes* packet; /* shared by all trees during construction */
|
2012-08-01 04:34:13 +08:00
|
|
|
struct OCerrdata {/* Hold info for an error return from server */
|
|
|
|
char* code;
|
|
|
|
char* message;
|
|
|
|
long httpcode;
|
2014-12-25 01:22:47 +08:00
|
|
|
char curlerrorbuf[CURL_ERROR_SIZE]; /* CURLOPT_ERRORBUFFER*/
|
2012-08-01 04:34:13 +08:00
|
|
|
} error;
|
|
|
|
CURL* curl; /* curl handle*/
|
|
|
|
char curlerror[CURL_ERROR_SIZE];
|
2013-05-16 01:37:04 +08:00
|
|
|
void* usercurldata;
|
2017-09-01 04:19:56 +08:00
|
|
|
NCauth auth; /* curl auth data */
|
2012-08-01 04:34:13 +08:00
|
|
|
long ddslastmodified;
|
|
|
|
long datalastmodified;
|
2018-08-27 07:04:46 +08:00
|
|
|
long curlbuffersize;
|
|
|
|
struct {
|
|
|
|
int active; /* Activate keepalive? */
|
|
|
|
long idle; /* KEEPIDLE value */
|
|
|
|
long interval; /* KEEPINTVL value */
|
|
|
|
} curlkeepalive; /* keepalive info */
|
2012-08-01 04:34:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! OCtree holds extra state info about trees */
|
|
|
|
|
|
|
|
typedef struct OCtree
|
|
|
|
{
|
|
|
|
OCdxd dxdclass;
|
|
|
|
char* constraint;
|
|
|
|
char* text;
|
|
|
|
struct OCnode* root; /* cross link */
|
|
|
|
struct OCstate* state; /* cross link */
|
2017-03-09 08:01:10 +08:00
|
|
|
NClist* nodes; /* all nodes in tree*/
|
2012-08-01 04:34:13 +08:00
|
|
|
/* when dxdclass == OCDATADDS */
|
|
|
|
struct {
|
|
|
|
char* memory; /* allocated memory if OC_ONDISK is not set */
|
|
|
|
char* filename; /* If OC_ONDISK is set */
|
|
|
|
FILE* file;
|
|
|
|
off_t datasize; /* xdr size on disk or in memory */
|
|
|
|
off_t bod; /* offset of the beginning of packet data */
|
|
|
|
off_t ddslen; /* length of ddslen (assert(ddslen <= bod)) */
|
|
|
|
XXDR* xdrs; /* access either memory or file */
|
|
|
|
OCdata* data;
|
|
|
|
} data;
|
|
|
|
} OCtree;
|
|
|
|
|
|
|
|
/* (Almost) All shared procedure definitions are kept here
|
|
|
|
except for: ocdebug.h ocutil.h
|
|
|
|
The true external interface is defined in oc.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Location: ceparselex.c*/
|
|
|
|
extern int cedebug;
|
2017-03-09 08:01:10 +08:00
|
|
|
extern NClist* CEparse(OCstate*,char* input);
|
2012-08-01 04:34:13 +08:00
|
|
|
#endif
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
extern int ocinitialized;
|
|
|
|
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
extern OCerror ocopen(OCstate** statep, const char* url);
|
|
|
|
extern void occlose(OCstate* state);
|
|
|
|
extern OCerror ocfetch(OCstate*, const char*, OCdxd, OCflags, OCnode**);
|
|
|
|
extern int oc_network_order;
|
|
|
|
extern int oc_invert_xdr_double;
|
2014-05-09 04:13:51 +08:00
|
|
|
extern OCerror ocinternalinitialize(void);
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2014-05-09 04:13:51 +08:00
|
|
|
extern OCerror ocupdatelastmodifieddata(OCstate* state);
|
2014-01-22 03:50:15 +08:00
|
|
|
|
2014-12-25 01:22:47 +08:00
|
|
|
extern OCerror ocset_useragent(OCstate* state, const char* agent);
|
|
|
|
extern OCerror ocset_netrc(OCstate* state, const char* path);
|
|
|
|
|
|
|
|
/* From ocrc.c */
|
|
|
|
extern OCerror ocrc_load(); /* find, read, and compile */
|
|
|
|
extern OCerror ocrc_process(OCstate* state); /* extract relevant triples */
|
|
|
|
extern char* ocrc_lookup(char* key, char* url);
|
|
|
|
extern struct OCTriple* ocrc_triple_iterate(char* key, char* url, struct OCTriple* prevp);
|
|
|
|
extern int ocparseproxy(OCstate* state, char* v);
|
2012-12-04 11:32:41 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#endif /*COMMON_H*/
|