1. Unify the rc file reading into libdispatch/drc.c. Eventually extend

if we need rc file for netcdf itself as opposed to the dap code.
This commit is contained in:
Dennis Heimbigner 2017-08-30 17:44:57 -06:00
parent 15db0f15ea
commit 7c592cfb2a
24 changed files with 912 additions and 890 deletions

View File

@ -1,26 +1,95 @@
/*********************************************************************
* Copyright 2016, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
/*
Copyright (c) 1998-2017 University Corporation for Atmospheric Research/Unidata
See LICENSE.txt for license information.
*/
#ifndef NCRC_H
#define NCRC_H
#include "ncbytes.h"
#include "nclist.h"
#include "ncuri.h"
typedef struct NCTriple {
char* tag;
char* host; /* combined host:port */
char* key;
char* value;
} NCTriple;
typedef struct NCTripleStore {
NClist* triples; /* list of NCTriple* */
} NCTripleStore;
typedef struct NCRCinfo {
struct curlflags {
int proto_file; /* Is file: supported? */
int proto_https; /* is https: supported? */
int compress; /*CURLOPT_ENCODING*/
int verbose; /*CURLOPT_ENCODING*/
int timeout; /*CURLOPT_TIMEOUT*/
int maxredirs; /*CURLOPT_MAXREDIRS*/
char* useragent; /*CURLOPT_USERAGENT*/
/* track which of these are created by oc */
#define COOKIECREATED 1
#define NETRCCREATED 2
int createdflags;
char* cookiejar; /*CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE*/
char* netrc; /*CURLOPT_NETRC,CURLOPT_NETRC_FILE*/
} curlflags;
struct ssl {
int verifypeer; /* CURLOPT_SSL_VERIFYPEER;
do not do this when cert might be self-signed
or temporarily incorrect */
int verifyhost; /* CURLOPT_SSL_VERIFYHOST; for client-side verification */
char* certificate; /*CURLOPT_SSLCERT*/
char* key; /*CURLOPT_SSLKEY*/
char* keypasswd; /*CURLOPT_SSLKEYPASSWD*/
char* cainfo; /* CURLOPT_CAINFO; certificate authority */
char* capath; /*CURLOPT_CAPATH*/
} ssl;
struct proxy {
char *host; /*CURLOPT_PROXY*/
int port; /*CURLOPT_PROXYPORT*/
char* user; /*CURLOPT_PROXYUSERNAME*/
char* pwd; /*CURLOPT_PROXYPASSWORD*/
} proxy;
struct credentials {
char *user; /*CURLOPT_USERNAME*/
char *pwd; /*CURLOPT_PASSWORD*/
} creds;
} NCRCinfo;
/* Collect global state info in one place */
typedef struct NCRCglobalstate {
int initialized;
char* tempdir; /* track a usable temp dir */
char* home; /* track $HOME for use in creating $HOME/.oc dir */
struct {
int proto_file;
int proto_https;
} curl;
struct {
int ignore; /* if 1, then do not use any rc file */
int loaded;
NClist* triples; /* the rc file triple store fields*/
char* rcfile; /* specified rcfile; overrides anything else */
} rc;
} NCRCglobalstate;
extern NCRCglobalstate ncrc_globalstate;
/* From drc.c */
/* read and compile the rc file, if any */
extern int ncrc_load(const char* filename);
extern char* ncrc_lookup(NCTripleStore*, char* key, char* hostport);
extern void ncrc_reset(NCTripleStore*);
extern int NC_rcload(void);
extern int NC_rcprocess(NCRCinfo* info, NCURI* uri);
extern char* NC_rclookup(const char* key, const char* hostport);
extern void NC_rcfreetriples(NClist* rc);
extern void NC_rcclear(NCRCinfo* info);
/* From dutil.c */
extern int NC__testurl(const char* path, char** basenamep);
extern int NC_isLittleEndian(void);
extern char* NC_backslashEscape(const char* s);
extern char* NC_backslashUnescape(const char* esc);
extern char* NC_entityescape(const char* s);
extern int NC_readfile(const char* filename, NCbytes* content);
extern int NC_mktmp(const char* base, char** tmpnamep);
extern char* NC_combinehostport(const char* host, const char* port);
#endif /*NCRC_H*/

View File

@ -452,7 +452,9 @@ by the desired type. */
#define NC_ECANTEXTEND (-130) /**< Attempt to extend dataset during ind. I/O operation. */
#define NC_EMPI (-131) /**< MPI operation failed. */
#define NC4_LAST_ERROR (-131)
#define NC_ERCFILE (-132) /**< RC file failure */
#define NC4_LAST_ERROR (-132)
/* This is used in netCDF-4 files for dimensions without coordinate
* vars. */

View File

@ -19,7 +19,6 @@ SRC= \
d4crc32.c \
d4curlfunctions.c \
d4curlflags.c \
d4rc.c \
d4fix.c \
d4data.c \
d4file.c \

View File

@ -22,15 +22,15 @@
#define CHECK(state,flag,value) {if(check(state,flag,(void*)value) != NC_NOERR) {goto done;}}
/* forward */
static int set_curlflag(NCD4INFO* state, int flag);
static int set_curlopt(NCD4INFO* state, int flag, void* value);
static int set_curl_options(NCD4INFO* state);
static int set_curlflag(NCD4INFO*, int flag);
static int set_curlopt(NCD4INFO*, int flag, void* value);
static int set_curl_options(NCD4INFO*);
static void* cvt(char* value, enum CURLFLAGTYPE type);
static int
check(NCD4INFO* state, int flag, void* value)
check(NCD4INFO* info, int flag, void* value)
{
int ret = set_curlopt(state,flag,value);
int ret = set_curlopt(info,flag,value);
return THROW(ret);
}
@ -57,37 +57,37 @@ set_curlflag(NCD4INFO* state, int flag)
int ret = NC_NOERR;
switch (flag) {
case CURLOPT_USERPWD: /* Do both user and pwd */
if(state->curl->creds.user != NULL
&& state->curl->creds.pwd != NULL) {
CHECK(state, CURLOPT_USERNAME, state->curl->creds.user);
CHECK(state, CURLOPT_PASSWORD, state->curl->creds.pwd);
if(state->curl->rcinfo.creds.user != NULL
&& state->curl->rcinfo.creds.pwd != NULL) {
CHECK(state, CURLOPT_USERNAME, state->curl->rcinfo.creds.user);
CHECK(state, CURLOPT_PASSWORD, state->curl->rcinfo.creds.pwd);
CHECK(state, CURLOPT_HTTPAUTH, (OPTARG)CURLAUTH_ANY);
}
break;
case CURLOPT_COOKIEJAR: case CURLOPT_COOKIEFILE:
if(state->curl->curlflags.cookiejar) {
if(state->curl->rcinfo.curlflags.cookiejar) {
/* Assume we will read and write cookies to same place */
CHECK(state, CURLOPT_COOKIEJAR, state->curl->curlflags.cookiejar);
CHECK(state, CURLOPT_COOKIEFILE, state->curl->curlflags.cookiejar);
CHECK(state, CURLOPT_COOKIEJAR, state->curl->rcinfo.curlflags.cookiejar);
CHECK(state, CURLOPT_COOKIEFILE, state->curl->rcinfo.curlflags.cookiejar);
}
break;
case CURLOPT_NETRC: case CURLOPT_NETRC_FILE:
if(state->curl->curlflags.netrc) {
if(state->curl->rcinfo.curlflags.netrc) {
CHECK(state, CURLOPT_NETRC, (OPTARG)CURL_NETRC_REQUIRED);
CHECK(state, CURLOPT_NETRC_FILE, state->curl->curlflags.netrc);
CHECK(state, CURLOPT_NETRC_FILE, state->curl->rcinfo.curlflags.netrc);
}
break;
case CURLOPT_VERBOSE:
if(state->curl->curlflags.verbose)
if(state->curl->rcinfo.curlflags.verbose)
CHECK(state, CURLOPT_VERBOSE, (OPTARG)1L);
break;
case CURLOPT_TIMEOUT:
if(state->curl->curlflags.timeout)
CHECK(state, CURLOPT_TIMEOUT, (OPTARG)((long)state->curl->curlflags.timeout));
if(state->curl->rcinfo.curlflags.timeout)
CHECK(state, CURLOPT_TIMEOUT, (OPTARG)((long)state->curl->rcinfo.curlflags.timeout));
break;
case CURLOPT_USERAGENT:
if(state->curl->curlflags.useragent)
CHECK(state, CURLOPT_USERAGENT, state->curl->curlflags.useragent);
if(state->curl->rcinfo.curlflags.useragent)
CHECK(state, CURLOPT_USERAGENT, state->curl->rcinfo.curlflags.useragent);
break;
case CURLOPT_FOLLOWLOCATION:
CHECK(state, CURLOPT_FOLLOWLOCATION, (OPTARG)1L);
@ -100,19 +100,19 @@ set_curlflag(NCD4INFO* state, int flag)
break;
case CURLOPT_ENCODING:
#ifdef CURLOPT_ENCODING
if(state->curl->curlflags.compress) {
if(state->curl->rcinfo.curlflags.compress) {
CHECK(state, CURLOPT_ENCODING,"deflate, gzip");
}
#endif
break;
case CURLOPT_PROXY:
if(state->curl->proxy.host != NULL) {
CHECK(state, CURLOPT_PROXY, state->curl->proxy.host);
CHECK(state, CURLOPT_PROXYPORT, (OPTARG)(long)state->curl->proxy.port);
if(state->curl->proxy.user != NULL
&& state->curl->proxy.pwd != NULL) {
CHECK(state, CURLOPT_PROXYUSERNAME, state->curl->proxy.user);
CHECK(state, CURLOPT_PROXYPASSWORD, state->curl->proxy.pwd);
if(state->curl->rcinfo.proxy.host != NULL) {
CHECK(state, CURLOPT_PROXY, state->curl->rcinfo.proxy.host);
CHECK(state, CURLOPT_PROXYPORT, (OPTARG)(long)state->curl->rcinfo.proxy.port);
if(state->curl->rcinfo.proxy.user != NULL
&& state->curl->rcinfo.proxy.pwd != NULL) {
CHECK(state, CURLOPT_PROXYUSERNAME, state->curl->rcinfo.proxy.user);
CHECK(state, CURLOPT_PROXYPASSWORD, state->curl->rcinfo.proxy.pwd);
#ifdef CURLOPT_PROXYAUTH
CHECK(state, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
#endif
@ -123,7 +123,7 @@ set_curlflag(NCD4INFO* state, int flag)
case CURLOPT_SSLCERT: case CURLOPT_SSLKEY:
case CURLOPT_SSL_VERIFYPEER: case CURLOPT_SSL_VERIFYHOST:
{
struct ssl* ssl = &state->curl->ssl;
struct ssl* ssl = &state->curl->rcinfo.ssl;
CHECK(state, CURLOPT_SSL_VERIFYPEER, (OPTARG)(ssl->verifypeer?1L:0L));
CHECK(state, CURLOPT_SSL_VERIFYHOST, (OPTARG)(ssl->verifyhost?1L:0L));
if(ssl->certificate)
@ -195,11 +195,11 @@ set_curl_options(NCD4INFO* state)
NCD4_hostport(state->uri,hostport,sizeof(hostport));
store = NCD4_globalstate->rc.rc;
store = ncrc_globalstate.rc.triples;
for(i=0;i<nclistlength(store);i++) {
struct CURLFLAG* flag;
NCD4triple* triple = (NCD4triple*)nclistget(store,i);
NCTriple* triple = (NCTriple*)nclistget(store,i);
size_t hostlen = strlen(triple->host);
const char* flagname;
if(strncmp("CURL.",triple->key,5) != 0) continue; /* not a curl flag */
@ -241,7 +241,7 @@ cvt(char* value, enum CURLFLAGTYPE type)
void
NCD4_curl_debug(NCD4INFO* state)
{
state->curl->curlflags.verbose = 1;
state->curl->rcinfo.curlflags.verbose = 1;
set_curlflag(state,CURLOPT_VERBOSE);
set_curlflag(state,CURLOPT_ERRORBUFFER);
}
@ -252,7 +252,7 @@ NCD4_curl_debug(NCD4INFO* state)
"file://..." &/or "https://..." urls.
*/
void
NCD4_curl_protocols(NCD4globalstate* state)
NCD4_curl_protocols(NCRCglobalstate* state)
{
const char* const* proto; /*weird*/
curl_version_info_data* curldata;
@ -280,26 +280,26 @@ NCD4_set_curlstate(NCD4INFO* state, int flag, void* value)
int ret = NC_NOERR;
switch (flag) {
case CURLOPT_USERPWD:
if(state->curl->creds.userpwd != NULL) free(state->curl->creds.userpwd);
state->curl->creds.userpwd = strdup((char*)value);
if(info->creds.userpwd != NULL) free(info->creds.userpwd);
info->creds.userpwd = strdup((char*)value);
break;
case CURLOPT_COOKIEJAR: case CURLOPT_COOKIEFILE:
if(state->curl->curlflags.cookiejar != NULL) free(state->curl->curlflags.cookiejar);
state->curl->curlflags.cookiejar = strdup((char*)value);
if(info->curlflags.cookiejar != NULL) free(info->curlflags.cookiejar);
info->curlflags.cookiejar = strdup((char*)value);
break;
case CURLOPT_NETRC: case CURLOPT_NETRC_FILE:
if(state->curl->curlflags.netrc != NULL) free(state->curl->curlflags.netrc);
state->curl->curlflags.netrc = strdup((char*)value);
if(info->curlflags.netrc != NULL) free(info->curlflags.netrc);
info->curlflags.netrc = strdup((char*)value);
break;
case CURLOPT_VERBOSE:
state->curl->curlflags.verbose = (long)value;
info->curlflags.verbose = (long)value;
break;
case CURLOPT_TIMEOUT:
state->curl->curlflags.timeout = (long)value;
info->curlflags.timeout = (long)value;
break;
case CURLOPT_USERAGENT:
if(state->curl->curlflags.useragent != NULL) free(state->curl->curlflags.useragent);
state->curl->curlflags.useragent = strdup((char*)value);
if(info->curlflags.useragent != NULL) free(info->curlflags.useragent);
info->curlflags.useragent = strdup((char*)value);
break;
case CURLOPT_FOLLOWLOCATION:
/* no need to store; will always be set */
@ -315,38 +315,38 @@ NCD4_set_curlstate(NCD4INFO* state, int flag, void* value)
break;
case CURLOPT_PROXY:
/* We assume that the value is the proxy url */
if(state->curl->proxy.host != NULL) free(state->curl->proxy.host);
if(state->curl->proxy.userpwd != NULL) free(state->curl->proxy.userpwd);
state->curl->proxy.host = NULL;
state->curl->proxy.userpwd = NULL;
if(info->proxy.host != NULL) free(info->proxy.host);
if(info->proxy.userpwd != NULL) free(info->proxy.userpwd);
info->proxy.host = NULL;
info->proxy.userpwd = NULL;
if(!NCD4_parseproxy(state,(char*)value))
{ret = NC_EINVAL; goto done;}
break;
case CURLOPT_SSLCERT:
if(state->curl->ssl.certificate != NULL) free(state->curl->ssl.certificate);
state->curl->ssl.certificate = strdup((char*)value);
if(info->ssl.certificate != NULL) free(info->ssl.certificate);
info->ssl.certificate = strdup((char*)value);
break;
case CURLOPT_SSLKEY:
if(state->curl->ssl.key != NULL) free(state->curl->ssl.key);
state->curl->ssl.key = strdup((char*)value);
if(info->ssl.key != NULL) free(info->ssl.key);
info->ssl.key = strdup((char*)value);
break;
case CURLOPT_KEYPASSWD:
if(state->curl->ssl.keypasswd!= NULL) free(state->curl->ssl.keypasswd);
state->curl->ssl.keypasswd = strdup((char*)value);
if(info->ssl.keypasswd!= NULL) free(info->ssl.keypasswd);
info->ssl.keypasswd = strdup((char*)value);
break;
case CURLOPT_SSL_VERIFYPEER:
state->curl->ssl.verifypeer = (long)value;
info->ssl.verifypeer = (long)value;
break;
case CURLOPT_SSL_VERIFYHOST:
state->curl->ssl.verifyhost = (long)value;
info->ssl.verifyhost = (long)value;
break;
case CURLOPT_CAINFO:
if(state->curl->ssl.cainfo != NULL) free(state->curl->ssl.cainfo);
state->curl->ssl.cainfo = strdup((char*)value);
if(info->ssl.cainfo != NULL) free(info->ssl.cainfo);
info->ssl.cainfo = strdup((char*)value);
break;
case CURLOPT_CAPATH:
if(state->curl->ssl.capath != NULL) free(state->curl->ssl.capath);
state->curl->ssl.capath = strdup((char*)value);
if(info->ssl.capath != NULL) free(info->ssl.capath);
info->ssl.capath = strdup((char*)value);
break;
default: break;

View File

@ -24,6 +24,6 @@ extern ncerror NCD4_set_curlflag(NCD4INFO*,int);
extern void NCD4_curl_debug(NCD4INFO* state);
extern struct CURLFLAG* NCD4_curlflagbyname(const char* name);
extern void NCD4_curl_protocols(NCD4globalstate* state);
extern void NCD4_curl_protocols(NCRCglobalstate* state);
#endif /*D4CURLFUNCTIONS_H*/

View File

@ -29,7 +29,6 @@ static void freeInfo(NCD4INFO*);
static int paramcheck(NCD4INFO*, const char* key, const char* subkey);
static const char* getparam(NCD4INFO* info, const char* key);
static int set_curl_properties(NCD4INFO*);
static void d4removecookies(const char* path);
/**************************************************/
/* Constants */
@ -319,21 +318,7 @@ freeCurl(NCD4curl* curl)
ncbytesfree(curl->packet);
nullfree(curl->errdata.code);
nullfree(curl->errdata.message);
nullfree(curl->curlflags.useragent);
nullfree(curl->curlflags.netrc);
nullfree(curl->ssl.certificate);
nullfree(curl->ssl.key);
nullfree(curl->ssl.keypasswd);
nullfree(curl->ssl.cainfo);
nullfree(curl->ssl.capath);
nullfree(curl->proxy.host);
nullfree(curl->proxy.user);
nullfree(curl->proxy.pwd);
nullfree(curl->creds.user);
nullfree(curl->creds.pwd);
if(curl->curlflags.createdflags & COOKIECREATED)
d4removecookies(curl->curlflags.cookiejar);
nullfree(curl->curlflags.cookiejar);
NC_rcclear(&curl->rcinfo);
}
/* Define the set of protocols known to be constrainable */
@ -364,24 +349,24 @@ set_curl_properties(NCD4INFO* d4info)
/* extract the relevant triples into d4info */
NCD4_rcprocess(d4info);
if(d4info->curl->curlflags.useragent == NULL) {
if(d4info->curl->rcinfo.curlflags.useragent == NULL) {
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
char* agent = (char*)malloc(len+1);
strncpy(agent,DFALTUSERAGENT,len);
strncat(agent,VERSION,len);
d4info->curl->curlflags.useragent = agent;
d4info->curl->rcinfo.curlflags.useragent = agent;
}
/* Some servers (e.g. thredds and columbia) appear to require a place
to put cookies in order for some security functions to work
*/
if(d4info->curl->curlflags.cookiejar != NULL
&& strlen(d4info->curl->curlflags.cookiejar) == 0) {
free(d4info->curl->curlflags.cookiejar);
d4info->curl->curlflags.cookiejar = NULL;
if(d4info->curl->rcinfo.curlflags.cookiejar != NULL
&& strlen(d4info->curl->rcinfo.curlflags.cookiejar) == 0) {
free(d4info->curl->rcinfo.curlflags.cookiejar);
d4info->curl->rcinfo.curlflags.cookiejar = NULL;
}
if(d4info->curl->curlflags.cookiejar == NULL) {
if(d4info->curl->rcinfo.curlflags.cookiejar == NULL) {
/* If no cookie file was defined, define a default */
int ok;
char* path = NULL;
@ -390,12 +375,12 @@ set_curl_properties(NCD4INFO* d4info)
errno = 0;
/* Create the unique cookie file name */
len =
strlen(NCD4_globalstate->tempdir)
strlen(ncrc_globalstate.tempdir)
+ 1 /* '/' */
+ strlen("ncd4cookies");
path = (char*)malloc(len+1);
if(path == NULL) return NC_ENOMEM;
snprintf(path,len,"%s/nc4cookies",NCD4_globalstate->tempdir);
snprintf(path,len,"%s/nc4cookies",ncrc_globalstate.tempdir);
/* Create the unique cookie file name */
ok = NCD4_mktmp(path,&name);
free(path);
@ -403,16 +388,16 @@ set_curl_properties(NCD4INFO* d4info)
fprintf(stderr,"Cannot create cookie file\n");
goto fail;
}
d4info->curl->curlflags.cookiejar = name;
d4info->curl->curlflags.createdflags |= COOKIECREATED;
d4info->curl->rcinfo.curlflags.cookiejar = name;
d4info->curl->rcinfo.curlflags.createdflags |= COOKIECREATED;
errno = 0;
}
assert(d4info->curl->curlflags.cookiejar != NULL);
assert(d4info->curl->rcinfo.curlflags.cookiejar != NULL);
/* Make sure the cookie jar exists and can be read and written */
{
FILE* f = NULL;
char* fname = d4info->curl->curlflags.cookiejar;
char* fname = d4info->curl->rcinfo.curlflags.cookiejar;
/* See if the file exists already */
f = fopen(fname,"r");
if(f == NULL) {
@ -516,12 +501,3 @@ getparam(NCD4INFO* info, const char* key)
return value;
}
static void
d4removecookies(const char* path)
{
#ifdef _MSC_VER
DeleteFile(path);
#else
remove(path);
#endif
}

View File

@ -32,6 +32,7 @@
#include "netcdf.h"
#include "nc.h"
#include "ncrc.h"
#include "ncbytes.h"
#include "nclist.h"
#include "ncuri.h"

View File

@ -37,7 +37,7 @@ NCD4_readDAP(NCD4INFO* state, int flags)
} else { /*((flags & NCF_ONDISK) != 0) */
NCURI* url = state->uri;
int fileprotocol = (strcmp(url->protocol,"file")==0);
if(fileprotocol && !state->curl->curlflags.proto_file) {
if(fileprotocol && !state->curl->rcinfo.curlflags.proto_file) {
stat = readfiletofile(url, ".dap", state->data.ondiskfile, &state->data.datasize);
} else {
char* readurl = NULL;
@ -86,7 +86,7 @@ readpacket(NCD4INFO* state, NCURI* url, NCbytes* packet, NCD4mode dxx, long* las
fileprotocol = (strcmp(url->protocol,"file")==0);
if(fileprotocol && !state->curl->curlflags.proto_file) {
if(fileprotocol && !state->curl->rcinfo.curlflags.proto_file) {
/* Short circuit file://... urls*/
/* We do this because the test code always needs to read files*/
stat = readfile(url,suffix,packet);
@ -99,7 +99,7 @@ readpacket(NCD4INFO* state, NCURI* url, NCbytes* packet, NCD4mode dxx, long* las
MEMCHECK(fetchurl);
if(state->debug > 0)
{fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);}
stat = NCD4_fetchurl(curl,fetchurl,packet,lastmodified,&state->curl->creds);
stat = NCD4_fetchurl(curl,fetchurl,packet,lastmodified,&state->curl->rcinfo.creds);
nullfree(fetchurl);
if(stat) goto fail;
if(state->debug > 0)

View File

@ -408,21 +408,6 @@ NCD4_hostport(NCURI* uri, char* space, size_t len)
}
}
#if 0
void
NCD4_userpwd(NCURI* uri, char* space, size_t len)
{
if(space != NULL && len > 0) {
space[0] = '\0'; /* so we can use strncat */
if(uri->user != NULL && uri->password != NULL) {
strncat(space,uri->user,len);
strncat(space,":",len);
strncat(space,uri->password,len);
}
}
}
#endif
#ifdef BLOB
void
NCD4_saveblob(NCD4meta* meta, void* mem)

View File

@ -63,14 +63,6 @@ NCD4_initialize(void)
int
NCD4_finalize(void)
{
if(NCD4_globalstate != NULL) {
nullfree(NCD4_globalstate->tempdir);
nullfree(NCD4_globalstate->home);
nclistfree(NCD4_globalstate->rc.rc);
nullfree(NCD4_globalstate->rc.rcfile);
free(NCD4_globalstate);
NCD4_globalstate = NULL;
}
return THROW(NC_NOERR);
}

View File

@ -13,6 +13,8 @@ are defined here.
#undef COMPILEBYDEFAULT
#include "ncrc.h"
/*
Control if struct fields can be map targets.
Currently turned off because semantics are unclear.
@ -261,31 +263,6 @@ typedef struct NCD4parser {
/**************************************************/
typedef struct NCD4triple {
char* host; /* includes port if specified */
char* key;
char* value;
} NCD4triple;
/**************************************************/
/* Collect global state info in one place */
struct NCD4globalstate {
struct {
int proto_file;
int proto_https;
} curl;
char* tempdir; /* track a usable temp dir */
char* home; /* track $HOME for use in creating $HOME/.oc dir */
struct {
int ignore; /* if 1, then do not use any rc file */
int loaded;
NClist* rc; /*NClist<NCD4triple>; the rc file triple store fields*/
char* rcfile; /* specified rcfile; overrides anything else */
} rc;
};
/* Curl info */
struct NCD4curl {
CURL* curl; /* curl handle*/
@ -296,42 +273,7 @@ struct NCD4curl {
long httpcode;
char errorbuf[CURL_ERROR_SIZE]; /* CURLOPT_ERRORBUFFER*/
} errdata;
struct curlflags {
int proto_file; /* Is file: supported? */
int proto_https; /* is https: supported? */
int compress; /*CURLOPT_ENCODING*/
int verbose; /*CURLOPT_ENCODING*/
int timeout; /*CURLOPT_TIMEOUT*/
int maxredirs; /*CURLOPT_MAXREDIRS*/
char* useragent; /*CURLOPT_USERAGENT*/
/* track which of these are created by oc */
#define COOKIECREATED 1
#define NETRCCREATED 2
int createdflags;
char* cookiejar; /*CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE*/
char* netrc; /*CURLOPT_NETRC,CURLOPT_NETRC_FILE*/
} curlflags;
struct ssl {
int verifypeer; /* CURLOPT_SSL_VERIFYPEER;
do not do this when cert might be self-signed
or temporarily incorrect */
int verifyhost; /* CURLOPT_SSL_VERIFYHOST; for client-side verification */
char* certificate; /*CURLOPT_SSLCERT*/
char* key; /*CURLOPT_SSLKEY*/
char* keypasswd; /*CURLOPT_SSLKEYPASSWD*/
char* cainfo; /* CURLOPT_CAINFO; certificate authority */
char* capath; /*CURLOPT_CAPATH*/
} ssl;
struct proxy {
char *host; /*CURLOPT_PROXY*/
int port; /*CURLOPT_PROXYPORT*/
char* user; /*CURLOPT_PROXYUSERNAME*/
char* pwd; /*CURLOPT_PROXYPASSWORD*/
} proxy;
struct credentials {
char *user; /*CURLOPT_USERNAME*/
char *pwd; /*CURLOPT_PASSWORD*/
} creds;
NCRCinfo rcinfo;
};
/**************************************************/

View File

@ -1,4 +1,4 @@
SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c dwinpath.c)
SET(libdispatch_SOURCES dparallel.c dcopy.c dfile.c ddim.c datt.c dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c dvarinq.c ddispatch.c nclog.c dstring.c dutf8.c dinternal.c doffsets.c ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c nc.c nclistmgr.c utf8proc.h utf8proc.c dwinpath.c dutil.c)
IF(USE_NETCDF4)
SET(libdispatch_SOURCES ${libdispatch_SOURCES} dgroup.c dvlen.c dcompound.c dtype.c denum.c dopaque.c ncaux.c)

View File

@ -20,7 +20,7 @@ dattinq.c dattput.c dattget.c derror.c dvar.c dvarget.c dvarput.c \
dvarinq.c dinternal.c ddispatch.c dutf8.c \
nclog.c dstring.c \
ncuri.c nclist.c ncbytes.c nchashmap.c nctime.c \
nc.c nclistmgr.c drc.c doffsets.c dwinpath.c
nc.c nclistmgr.c drc.c doffsets.c dwinpath.c dutil.c
# Add the utf8 codebase
libdispatch_la_SOURCES += utf8proc.c utf8proc.h

View File

@ -1,5 +1,26 @@
/*
Copyright (c) 1998-2017 University Corporation for Atmospheric Research/Unidata
See LICENSE.txt for license information.
*/
#include "config.h"
#include "ncdispatch.h"
#include "ncuri.h"
#include "nclog.h"
#include "ncbytes.h"
#include "ncrc.h"
/* Required for getcwd, other functions. */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* Required for getcwd, other functions. */
#ifdef _MSC_VER
#include <direct.h>
#define getcwd _getcwd
#endif
/* Define vectors of zeros and ones for use with various nc_get_varX function*/
size_t nc_sizevector0[NC_MAX_VAR_DIMS];
@ -24,6 +45,8 @@ static struct NCPROTOCOLLIST {
{NULL,NULL,0} /* Terminate search */
};
NCRCglobalstate ncrc_globalstate;
/*
static nc_type longtype = (sizeof(long) == sizeof(int)?NC_INT:NC_INT64);
static nc_type ulongtype = (sizeof(unsigned long) == sizeof(unsigned int)?NC_UINT:NC_UINT64);
@ -35,6 +58,9 @@ NCDISPATCH_initialize(void)
{
int status = NC_NOERR;
int i;
memset(&ncrc_globalstate,0,sizeof(NCRCglobalstate));
for(i=0;i<NC_MAX_VAR_DIMS;i++) {
nc_sizevector0[i] = 0;
nc_sizevector1[i] = 1;
@ -44,6 +70,68 @@ NCDISPATCH_initialize(void)
NC_coord_one[i] = 1;
NC_coord_zero[i] = 0;
}
/* Capture temp dir*/
{
char* tempdir;
char* p;
char* q;
char cwd[4096];
#ifdef _MSC_VER
tempdir = getenv("TEMP");
#else
tempdir = "/tmp";
#endif
if(tempdir == NULL) {
fprintf(stderr,"Cannot find a temp dir; using ./\n");
tempdir = getcwd(cwd,sizeof(cwd));
if(tempdir == NULL || *tempdir == '\0') tempdir = ".";
}
ncrc_globalstate.tempdir= (char*)malloc(strlen(tempdir) + 1);
for(p=tempdir,q=ncrc_globalstate.tempdir;*p;p++,q++) {
if((*p == '/' && *(p+1) == '/')
|| (*p == '\\' && *(p+1) == '\\')) {p++;}
*q = *p;
}
*q = '\0';
#ifdef _MSC_VER
#else
/* Canonicalize */
for(p=ncrc_globalstate.tempdir;*p;p++) {
if(*p == '\\') {*p = '/'; };
}
*q = '\0';
#endif
}
/* Capture $HOME */
{
char* p;
char* q;
char* home = getenv("HOME");
if(home == NULL) {
/* use tempdir */
home = ncrc_globalstate.tempdir;
}
ncrc_globalstate.home = (char*)malloc(strlen(home) + 1);
for(p=home,q=ncrc_globalstate.home;*p;p++,q++) {
if((*p == '/' && *(p+1) == '/')
|| (*p == '\\' && *(p+1) == '\\')) {p++;}
*q = *p;
}
*q = '\0';
#ifdef _MSC_VER
#else
/* Canonicalize */
for(p=home;*p;p++) {
if(*p == '\\') {*p = '/'; };
}
#endif
}
ncloginit();
return status;
}
@ -51,6 +139,11 @@ int
NCDISPATCH_finalize(void)
{
int status = NC_NOERR;
nullfree(ncrc_globalstate->tempdir);
nullfree(ncrc_globalstate->home);
NC_freetriples(ncrc_globalstate->rc.triples);
nullfree(ncrc_globalstate->rc.rcfile);
memset(&ncrc_globalstate,0,sizeof(NCRCglobalstate));
return status;
}

View File

@ -194,8 +194,6 @@ const char *nc_strerror(int ncerr1)
return "NetCDF: Authorization failure";
case NC_ENOTFOUND:
return "NetCDF: file not found";
case NC_ECANTEXTEND:
return "NetCDF: Attempt to extend dataset during NC_INDEPENDENT I/O operation. Use nc_var_par_access to set mode NC_COLLECTIVE before extending variable.";
case NC_ECANTREMOVE:
return "NetCDF: cannot delete file";
case NC_EHDFERR:
@ -257,6 +255,11 @@ const char *nc_strerror(int ncerr1)
"when netCDF was built.";
case NC_EDISKLESS:
return "NetCDF: Error in using diskless access";
case NC_ECANTEXTEND:
return "NetCDF: Attempt to extend dataset during NC_INDEPENDENT I/O operation. Use nc_var_par_access to set mode NC_COLLECTIVE before extending variable.";
case NC_EMPI: return "NetCDF: MPI operation failed.";
case NC_ERCFILE:
return "NetCDF: RC File Failure.";
default:
#ifdef USE_PNETCDF
/* The behavior of ncmpi_strerror here is to return

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ occlientparams.c occompile.c occurlfunctions.c \
ocdata.c ocdebug.c ocdump.c \
ocinternal.c ocnode.c \
ochttp.c \
ocrc.c ocread.c ocutil.c \
ocread.c ocutil.c \
occurlflags.c \
xxdr.c

View File

@ -11,6 +11,7 @@
#include "ocdebug.h"
#include "ocdump.h"
#include "nclog.h"
#include "ncrc.h"
#include "occlientparams.h"
#include "occurlfunctions.h"
#include "ochttp.h"
@ -56,7 +57,6 @@ oc_open(const char* url, OCobject* linkp)
{
OCerror ocerr;
OCstate* state = NULL;
if(!ocglobalstate.initialized) oc_initialize();
ocerr = ocopen(&state,url);
if(ocerr == OC_NOERR && linkp) {
*linkp = (OCobject)(state);
@ -2118,44 +2118,6 @@ oc_set_useragent(OCobject link, const char* agent)
return OCTHROW(ocset_useragent(state,agent));
}
/*!
Set the absolute path to use for the rc file.
WARNING: this MUST be called before any other
call in order for this to take effect.
\param[in] rcfile The path to use. If NULL, or "",
then do not use any rcfile.
\retval OC_NOERR if the request succeeded.
\retval OC_ERCFILE if the file failed to load
*/
OCerror
oc_set_rcfile(const char* rcfile)
{
OCerror stat = OC_NOERR;
if(rcfile != NULL && strlen(rcfile) == 0)
rcfile = NULL;
if(!ocglobalstate.initialized)
ocinternalinitialize(); /* so ocglobalstate is defined, but not triplestore */
if(rcfile == NULL) {
ocglobalstate.rc.ignore = 1;
} else {
FILE* f = NCfopen(rcfile,"r");
if(f == NULL) {
stat = (OC_ERCFILE);
goto done;
}
fclose(f);
ocglobalstate.rc.rcfile = strdup(rcfile);
/* (re) load the rcfile and esp the triplestore*/
stat = ocrc_load();
}
done:
return OCTHROW(stat);
}
/*!
Force the curl library to trace its actions.
@ -2174,21 +2136,4 @@ oc_trace_curl(OCobject link)
return OCTHROW(OC_NOERR);
}
OCerror
oc_initialize(void)
{
OCerror status = OC_NOERR;
if(!ocglobalstate.initialized) {
/* Clean up before re-initializing */
if(ocglobalstate.tempdir != NULL) free(ocglobalstate.tempdir);
if(ocglobalstate.home != NULL) free(ocglobalstate.home);
if(ocglobalstate.rc.rcfile != NULL) free(ocglobalstate.rc.rcfile);
}
ocglobalstate.initialized = 0;
status = ocinternalinitialize();
/* (re) load the rcfile */
status = ocrc_load();
return OCTHROW(status);
}
/**@}*/

View File

@ -2,6 +2,7 @@
See the COPYRIGHT file for more information. */
#include "config.h"
#include "ncrc.h"
#include "ocinternal.h"
#include "ocdebug.h"
#include "occurlfunctions.h"
@ -21,10 +22,6 @@
#define CHECK(state,flag,value) {if(check(state,flag,(void*)value) != OC_NOERR) {goto done;}}
/* forward */
static OCerror oc_set_curl_options(OCstate* state);
static void* cvt(char* value, enum OCCURLFLAGTYPE type);
static OCerror
check(OCstate* state, int flag, void* value)
{
@ -45,31 +42,6 @@ check(OCstate* state, int flag, void* value)
return stat;
}
#if 0
static void
showopt(int flag, void* value)
{
struct OCCURLFLAG* f = occurlflagbyflag(flag);
if(f == NULL) {
OCDBG1("Unsupported flag: %d",flag);
} else switch (f->type) {
case CF_LONG:
OCDBG2("%s=%ld",f->name,(long)value);
break;
case CF_STRING: {
char show[65];
char* s = (char*)value;
strncpy(show,s,64);
show[64] = '\0';
OCDBG2("%s=%s",f->name,show);
} break;
case CF_UNKNOWN: case CF_OTHER:
OCDBG1("%s=<something>",f->name);
break;
}
}
#endif
/*
Set a specific curl flag; primary wrapper for curl_easy_setopt
*/
@ -228,77 +200,9 @@ ocset_flags_perlink(OCstate* state)
if(stat == OC_NOERR) stat = ocset_curlflag(state, CURLOPT_FOLLOWLOCATION);
if(stat == OC_NOERR) stat = ocset_curlflag(state, CURLOPT_MAXREDIRS);
if(stat == OC_NOERR) stat = ocset_curlflag(state, CURLOPT_ERRORBUFFER);
/* Set the CURL. options */
if(stat == OC_NOERR) stat = oc_set_curl_options(state);
return stat;
}
/**
Directly set any options starting with 'CURL.'
*/
static OCerror
oc_set_curl_options(OCstate* state)
{
OCerror stat = OC_NOERR;
struct OCTriplestore* store = NULL;
struct OCTriple* triple = NULL;
int i;
char* hostport = NULL;
struct OCCURLFLAG* ocflag = NULL;
hostport = occombinehostport(state->uri);
if(hostport == NULL) {
hostport = (char*)malloc(sizeof(char)*1);
*hostport = '\0';
}
store = &ocglobalstate.rc.daprc;
triple = store->triples;
/* Assume that the triple store has been properly sorted */
for(i=0;i<store->ntriples;i++,triple++) {
size_t hostlen = strlen(triple->host);
const char* flagname;
if(ocstrncmp("CURL.",triple->key,5) != 0) continue; /* not a curl flag */
/* do hostport prefix comparison */
if(hostlen > 0) {
int t = ocstrncmp(hostport,triple->host,hostlen);
if(t != 0) continue;
}
flagname = triple->key+5; /* 5 == strlen("CURL."); */
ocflag = occurlflagbyname(flagname);
if(ocflag == NULL) {stat = OC_ECURL; goto done;}
stat = ocset_curlopt(state,ocflag->flag,cvt(triple->value,ocflag->type));
}
done:
if(hostport && strlen(hostport) > 0) free(hostport);
return stat;
}
static void*
cvt(char* value, enum OCCURLFLAGTYPE type)
{
switch (type) {
case CF_LONG: {
/* Try to convert to long value */
const char* p = value;
char* q = NULL;
long longvalue = strtol(p,&q,10);
if(*q != '\0')
return NULL;
return (void*)longvalue;
}
case CF_STRING:
return (void*)value;
case CF_UNKNOWN: case CF_OTHER:
return (void*)value;
}
return NULL;
}
void
oc_curl_debug(OCstate* state)
{
@ -326,7 +230,7 @@ oc_curl_printerror(OCstate* state)
"file://..." &/or "https://..." urls.
*/
void
oc_curl_protocols(struct OCGLOBALSTATE* state)
oc_curl_protocols(NCRCglobalstate* state)
{
const char* const* proto; /*weird*/
curl_version_info_data* curldata;
@ -340,115 +244,3 @@ oc_curl_protocols(struct OCGLOBALSTATE* state)
nclog(NCLOGNOTE,"Curl https:// support = %d",state->curl.proto_https);
}
}
#if 0
/*
"Inverse" of ocset_curlflag;
Given a flag and value, it updates state.
Update a specific flag from state->curlflags.
*/
OCerror
ocset_curlstate(OCstate* state, int flag, void* value)
{
OCerror stat = OC_NOERR;
switch (flag) {
case CURLOPT_USERNAME:
if(state->creds.user != NULL) free(state->creds.user);
state->creds.user = strdup((char*)value);
break;
case CURLOPT_PASSWORD:
if(state->creds.pwd != NULL) free(state->creds.pwd);
state->creds.pwd = strdup((char*)value);
break;
case CURLOPT_COOKIEJAR: case CURLOPT_COOKIEFILE:
if(state->curlflags.cookiejar != NULL) free(state->curlflags.cookiejar);
state->curlflags.cookiejar = strdup((char*)value);
break;
case CURLOPT_NETRC: case CURLOPT_NETRC_FILE:
if(state->curlflags.netrc != NULL) free(state->curlflags.netrc);
state->curlflags.netrc = strdup((char*)value);
break;
case CURLOPT_VERBOSE:
state->curlflags.verbose = (long)value;
break;
case CURLOPT_TIMEOUT:
state->curlflags.timeout = (long)value;
break;
case CURLOPT_USERAGENT:
if(state->curlflags.useragent != NULL) free(state->curlflags.useragent);
state->curlflags.useragent = strdup((char*)value);
break;
case CURLOPT_FOLLOWLOCATION:
/* no need to store; will always be set */
break;
case CURLOPT_MAXREDIRS:
/* no need to store; will always be set */
break;
case CURLOPT_ERRORBUFFER:
/* no need to store; will always be set */
break;
case CURLOPT_ENCODING:
/* no need to store; will always be set to fixed value */
break;
case CURLOPT_PROXY:
/* We assume that the value is the proxy url */
if(state->proxy.host != NULL) free(state->proxy.host);
if(state->proxy.userpwd != NULL) free(state->proxy.userpwd);
state->proxy.host = NULL;
state->proxy.userpwd = NULL;
if(!ocparseproxy(state,(char*)value))
{stat = OC_EINVAL; goto done;}
break;
case CURLOPT_SSLCERT:
if(state->ssl.certificate != NULL) free(state->ssl.certificate);
state->ssl.certificate = strdup((char*)value);
break;
case CURLOPT_SSLKEY:
if(state->ssl.key != NULL) free(state->ssl.key);
state->ssl.key = strdup((char*)value);
break;
case CURLOPT_KEYPASSWD:
if(state->ssl.keypasswd!= NULL) free(state->ssl.keypasswd);
state->ssl.keypasswd = strdup((char*)value);
break;
case CURLOPT_SSL_VERIFYPEER:
state->ssl.verifypeer = (long)value;
break;
case CURLOPT_SSL_VERIFYHOST:
state->ssl.verifyhost = (long)value;
break;
case CURLOPT_CAINFO:
if(state->ssl.cainfo != NULL) free(state->ssl.cainfo);
state->ssl.cainfo = strdup((char*)value);
break;
case CURLOPT_CAPATH:
if(state->ssl.capath != NULL) free(state->ssl.capath);
state->ssl.capath = strdup((char*)value);
break;
default: {
struct OCCURLFLAG* f = occurlflagbyflag(flag);
if(f != NULL)
nclog(NCLOGWARN,"Attempt to add unexpected curl flag to state: %s",
f->name);
} break;
}
done:
return stat;
}
#endif

View File

@ -23,7 +23,7 @@ extern void oc_curl_debug(OCstate* state);
extern void oc_curl_printerror(OCstate* state);
extern int ocrc_netrc_required(OCstate* state);
extern void oc_curl_protocols(struct OCGLOBALSTATE*);
extern void oc_curl_protocols(NCRCglobalstate*);
/* From occurlflags.c */
extern struct OCCURLFLAG* occurlflags(void);

View File

@ -22,6 +22,7 @@
#include <errno.h>
#include "ncrc.h"
#include "ocinternal.h"
#include "ocdebug.h"
#include "occlientparams.h"
@ -48,14 +49,16 @@ static OCerror ocset_curlproperties(OCstate*);
extern OCnode* makeunlimiteddimension(void);
/* Collect global state info in one place */
struct OCGLOBALSTATE ocglobalstate;
int ocinitialized = 0;
OCerror
ocinternalinitialize(void)
{
int stat = OC_NOERR;
if(ocinitialized) return OC_NOERR;
ocinitialized = 1;
#if 0
if(sizeof(off_t) != sizeof(void*)) {
fprintf(stderr,"OC xxdr depends on the assumption that sizeof(off_t) == sizeof(void*)\n");
@ -66,80 +69,15 @@ ocinternalinitialize(void)
}
#endif
if(!ocglobalstate.initialized) {
CURLcode cstat = CURLE_OK;
cstat = curl_global_init(CURL_GLOBAL_ALL);
if(cstat != CURLE_OK)
CURLcode cstat = CURLE_OK;
cstat = curl_global_init(CURL_GLOBAL_ALL);
if(cstat != CURLE_OK)
fprintf(stderr,"curl_global_init failed!\n");
memset((void*)&ocglobalstate,0,sizeof(ocglobalstate));
ocglobalstate.initialized = 1;
}
/* Capture temp dir*/
{
char* tempdir;
char* p;
char* q;
char cwd[4096];
#ifdef _MSC_VER
tempdir = getenv("TEMP");
#else
tempdir = "/tmp";
#endif
if(tempdir == NULL) {
fprintf(stderr,"Cannot find a temp dir; using ./\n");
tempdir = getcwd(cwd,sizeof(cwd));
if(tempdir == NULL || *tempdir == '\0') tempdir = ".";
}
ocglobalstate.tempdir= (char*)malloc(strlen(tempdir) + 1);
for(p=tempdir,q=ocglobalstate.tempdir;*p;p++,q++) {
if((*p == '/' && *(p+1) == '/')
|| (*p == '\\' && *(p+1) == '\\')) {p++;}
*q = *p;
}
*q = '\0';
#ifdef _MSC_VER
#else
/* Canonicalize */
for(p=ocglobalstate.tempdir;*p;p++) {
if(*p == '\\') {*p = '/'; };
}
*q = '\0';
#endif
}
/* Capture $HOME */
{
char* p;
char* q;
char* home = getenv("HOME");
if(home == NULL) {
/* use tempdir */
home = ocglobalstate.tempdir;
}
ocglobalstate.home = (char*)malloc(strlen(home) + 1);
for(p=home,q=ocglobalstate.home;*p;p++,q++) {
if((*p == '/' && *(p+1) == '/')
|| (*p == '\\' && *(p+1) == '\\')) {p++;}
*q = *p;
}
*q = '\0';
#ifdef _MSC_VER
#else
/* Canonicalize */
for(p=home;*p;p++) {
if(*p == '\\') {*p = '/'; };
}
#endif
}
/* Compute some xdr related flags */
xxdr_init();
ncloginit();
oc_curl_protocols(&ocglobalstate); /* see what protocols are supported */
oc_curl_protocols(&ncrc_globalstate); /* see what protocols are supported */
return OCTHROW(stat);
}
@ -366,12 +304,12 @@ createtempfile(OCstate* state, OCtree* tree)
int len;
len =
strlen(ocglobalstate.tempdir)
strlen(ncrc_globalstate.tempdir)
+ 1 /* '/' */
+ strlen(DATADDSFILE);
path = (char*)malloc(len+1);
if(path == NULL) return OC_ENOMEM;
occopycat(path,len,3,ocglobalstate.tempdir,"/",DATADDSFILE);
occopycat(path,len,3,ncrc_globalstate.tempdir,"/",DATADDSFILE);
stat = ocmktmp(path,&name);
free(path);
if(stat != OC_NOERR) goto fail;
@ -601,12 +539,12 @@ ocset_curlproperties(OCstate* state)
errno = 0;
/* Create the unique cookie file name */
len =
strlen(ocglobalstate.tempdir)
strlen(ncrc_globalstate.tempdir)
+ 1 /* '/' */
+ strlen("occookies");
path = (char*)malloc(len+1);
if(path == NULL) return OC_ENOMEM;
occopycat(path,len,3,ocglobalstate.tempdir,"/","occookies");
occopycat(path,len,3,ncrc_globalstate.tempdir,"/","occookies");
stat = ocmktmp(path,&name);
fprintf(stderr,"%s => %s\n",state->uri->uri,name); fflush(stderr);
free(path);

View File

@ -158,23 +158,6 @@ struct OCTriplestore {
} triples[MAXRCLINES];
};
/* Collect global state info in one place */
extern struct OCGLOBALSTATE {
int initialized;
struct {
int proto_file;
int proto_https;
} curl;
char* tempdir; /* track a usable temp dir */
char* home; /* track $HOME for use in creating $HOME/.oc dir */
struct {
int ignore; /* if 1, then do not use any rc file */
int loaded;
struct OCTriplestore daprc; /* the rc file triple store fields*/
char* rcfile; /* specified rcfile; overrides anything else */
} rc;
} ocglobalstate;
/*! Specifies the OCstate = non-opaque version of OClink */
struct OCstate {
OCheader header; /* class=OC_State */
@ -263,6 +246,9 @@ extern int cedebug;
extern NClist* CEparse(OCstate*,char* input);
#endif
extern int ocinitialized;
extern OCerror ocopen(OCstate** statep, const char* url);
extern void occlose(OCstate* state);
extern OCerror ocfetch(OCstate*, const char*, OCdxd, OCflags, OCnode**);

View File

@ -323,7 +323,7 @@ ocrc_compile(const char* path)
char line0[MAXRCLINESIZE+1];
FILE *in_file = NULL;
int linecount = 0;
struct OCTriplestore* ocrc = &ocglobalstate.rc.daprc;
struct OCTriplestore* ocrc = &ncrc_globalstate.rc.daprc;
ocrc->ntriples = 0; /* reset; nothing to free */
@ -400,7 +400,7 @@ ocrc_compile(const char* path)
ocrc->ntriples++;
}
fclose(in_file);
sorttriplestore(&ocglobalstate.rc.daprc);
sorttriplestore(&ncrc_globalstate.rc.daprc);
return 1;
}
@ -411,11 +411,11 @@ ocrc_load(void)
OCerror stat = OC_NOERR;
char* path = NULL;
if(ocglobalstate.rc.ignore) {
if(ncrc_globalstate.rc.ignore) {
nclog(NCLOGDBG,"No runtime configuration file specified; continuing");
return OC_NOERR;
}
if(ocglobalstate.rc.loaded) return OC_NOERR;
if(ncrc_globalstate.rc.loaded) return OC_NOERR;
/* locate the configuration files in the following order:
1. specified by set_rcfile
@ -423,8 +423,8 @@ ocrc_load(void)
3. '.'/<rcfile>
4. $HOME/<rcfile>
*/
if(ocglobalstate.rc.rcfile != NULL) { /* always use this */
path = strdup(ocglobalstate.rc.rcfile);
if(ncrc_globalstate.rc.rcfile != NULL) { /* always use this */
path = strdup(ncrc_globalstate.rc.rcfile);
} else if(getenv(OCRCFILEENV) != NULL && strlen(getenv(OCRCFILEENV)) > 0) {
path = strdup(getenv(OCRCFILEENV));
} else {
@ -433,7 +433,7 @@ ocrc_load(void)
for(rcname=rcfilenames;!found && *rcname;rcname++) {
stat = rc_search(".",*rcname,&path);
if(stat == OC_NOERR && path == NULL) /* try $HOME */
stat = rc_search(ocglobalstate.home,*rcname,&path);
stat = rc_search(ncrc_globalstate.home,*rcname,&path);
if(stat != OC_NOERR)
goto done;
if(path != NULL)
@ -451,7 +451,7 @@ ocrc_load(void)
}
}
done:
ocglobalstate.rc.loaded = 1; /* even if not exists */
ncrc_globalstate.rc.loaded = 1; /* even if not exists */
if(path != NULL)
free(path);
return stat;
@ -465,12 +465,12 @@ ocrc_process(OCstate* state)
NCURI* uri = state->uri;
char* url_hostport = NULL;
if(!ocglobalstate.initialized)
if(!ncrc_globalstate.initialized)
ocinternalinitialize();
if(!ocglobalstate.rc.loaded)
if(!ncrc_globalstate.rc.loaded)
ocrc_load();
/* Note, we still must do this function even if
ocglobalstate.rc.ignore is set in order
ncrc_globalstate.rc.ignore is set in order
to getinfo e.g. user:pwd from url
*/
@ -623,12 +623,12 @@ static struct OCTriple*
ocrc_locate(char* key, char* hostport)
{
int i,found;
struct OCTriplestore* ocrc = &ocglobalstate.rc.daprc;
struct OCTriplestore* ocrc = &ncrc_globalstate.rc.daprc;
struct OCTriple* triple;
if(ocglobalstate.rc.ignore)
if(ncrc_globalstate.rc.ignore)
return NULL;
if(!ocglobalstate.rc.loaded)
if(!ncrc_globalstate.rc.loaded)
ocrc_load();
triple = ocrc->triples;
@ -665,7 +665,7 @@ static void
storedump(char* msg, struct OCTriple* triples, int ntriples)
{
int i;
struct OCTriplestore* ocrc = &ocglobalstate.rc.daprc;
struct OCTriplestore* ocrc = &ncrc_globalstate.rc.daprc;
if(msg != NULL) fprintf(stderr,"%s\n",msg);
if(ocrc == NULL) {
@ -711,15 +711,15 @@ ocreadrc(void)
char* path = NULL;
/* locate the configuration files: first if specified,
then '.', then $HOME */
if(ocglobalstate.rc.rcfile != NULL) { /* always use this */
path = ocglobalstate.rc.rcfile;
if(ncrc_globalstate.rc.rcfile != NULL) { /* always use this */
path = ncrc_globalstate.rc.rcfile;
} else {
char** rcname;
int found = 0;
for(rcname=rcfilenames;!found && *rcname;rcname++) {
stat = rc_search(".",*rcname,&path);
if(stat == OC_NOERR && path == NULL) /* try $HOME */
stat = rc_search(ocglobalstate.home,*rcname,&path);
stat = rc_search(ncrc_globalstate.home,*rcname,&path);
if(stat != OC_NOERR)
goto done;
if(path != NULL)

View File

@ -17,6 +17,7 @@
#define O_BINARY _O_BINARY
#endif
#endif
#include "ncrc.h"
#include "ocinternal.h"
#include "ocdebug.h"
#include "ochttp.h"