2017-08-31 02:05:04 +08:00
|
|
|
/*
|
|
|
|
Copyright (c) 1998-2017 University Corporation for Atmospheric Research/Unidata
|
|
|
|
See LICENSE.txt for license information.
|
|
|
|
*/
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDARG_H
|
|
|
|
#include <stdarg.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "netcdf.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "ncbytes.h"
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "ncuri.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "ncrc.h"
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "nclog.h"
|
|
|
|
#include "ncwinpath.h"
|
|
|
|
|
|
|
|
#define RCFILEENV "DAPRCFILE"
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
#define RTAG ']'
|
|
|
|
#define LTAG '['
|
|
|
|
|
|
|
|
#define TRIMCHARS " \t\r\n"
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
#undef MEMCHECK
|
|
|
|
#define MEMCHECK(x) if((x)==NULL) {goto nomem;} else {}
|
|
|
|
|
|
|
|
/* Forward */
|
|
|
|
static char* rcreadline(char** nextlinep);
|
|
|
|
static void rctrim(char* text);
|
2018-02-09 10:53:40 +08:00
|
|
|
static void rcorder(NClist* rc);
|
2017-08-31 07:44:57 +08:00
|
|
|
static int rccompile(const char* path);
|
|
|
|
static struct NCTriple* rclocate(const char* key, const char* hostport);
|
|
|
|
static int rcsearch(const char* prefix, const char* rcname, char** pathp);
|
2017-09-01 04:19:56 +08:00
|
|
|
static void rcfreetriples(NClist* rc);
|
2017-08-31 07:44:57 +08:00
|
|
|
#ifdef D4DEBUG
|
|
|
|
static void storedump(char* msg, NClist* triples);
|
|
|
|
#endif
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/* Define default rc files and aliases, also defines search order*/
|
|
|
|
static char* rcfilenames[] = {".daprc",".dodsrc",NULL};
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
2017-08-31 07:44:57 +08:00
|
|
|
/* External Entry Points */
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/* locate, read and compile the rc file, if any */
|
2017-03-09 08:01:10 +08:00
|
|
|
int
|
2017-08-31 07:44:57 +08:00
|
|
|
NC_rcload(void)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
int ret = NC_NOERR;
|
2017-03-09 08:01:10 +08:00
|
|
|
char* path = NULL;
|
|
|
|
|
2017-09-01 04:19:56 +08:00
|
|
|
if(ncrc_globalstate.rcinfo.ignore) {
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGDBG,"No runtime configuration file specified; continuing");
|
2017-08-31 07:44:57 +08:00
|
|
|
return (NC_NOERR);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-09-01 04:19:56 +08:00
|
|
|
if(ncrc_globalstate.rcinfo.loaded) return (NC_NOERR);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
/* locate the configuration files in the following order:
|
2017-08-31 07:44:57 +08:00
|
|
|
1. specified by NC_set_rcfile
|
|
|
|
2. set by DAPRCFILE env variable
|
|
|
|
3. ./<rcfile> (current directory)
|
|
|
|
4. $HOME/<rcfile>
|
2017-03-09 08:01:10 +08:00
|
|
|
*/
|
2017-09-01 04:19:56 +08:00
|
|
|
if(ncrc_globalstate.rcinfo.rcfile != NULL) { /* always use this */
|
|
|
|
path = strdup(ncrc_globalstate.rcinfo.rcfile);
|
2017-08-31 07:44:57 +08:00
|
|
|
} else if(getenv(RCFILEENV) != NULL && strlen(getenv(RCFILEENV)) > 0) {
|
|
|
|
path = strdup(getenv(RCFILEENV));
|
|
|
|
} else {
|
2017-03-09 08:01:10 +08:00
|
|
|
char** rcname;
|
2017-08-31 07:44:57 +08:00
|
|
|
int found = 0;
|
|
|
|
for(rcname=rcfilenames;!found && *rcname;rcname++) {
|
|
|
|
ret = rcsearch(".",*rcname,&path);
|
|
|
|
if(ret == NC_NOERR && path == NULL) /* try $HOME */
|
|
|
|
ret = rcsearch(ncrc_globalstate.home,*rcname,&path);
|
|
|
|
if(ret != NC_NOERR)
|
|
|
|
goto done;
|
|
|
|
if(path != NULL)
|
|
|
|
found = 1;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(path == NULL) {
|
|
|
|
nclog(NCLOGDBG,"Cannot find runtime configuration file; continuing");
|
2017-08-31 07:44:57 +08:00
|
|
|
} else {
|
|
|
|
#ifdef D4DEBUG
|
|
|
|
fprintf(stderr, "RC file: %s\n", path);
|
|
|
|
#endif
|
|
|
|
if((ret=rccompile(path))) {
|
|
|
|
nclog(NCLOGERR, "Error parsing %s\n",path);
|
|
|
|
goto done;
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
done:
|
2017-09-01 04:19:56 +08:00
|
|
|
ncrc_globalstate.rcinfo.loaded = 1; /* even if not exists */
|
2017-08-31 07:44:57 +08:00
|
|
|
nullfree(path);
|
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/**
|
|
|
|
* Locate a triple by property key and host+port (may be null|"")
|
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
NC_rclookup(const char* key, const char* hostport)
|
|
|
|
{
|
|
|
|
struct NCTriple* triple = rclocate(key,hostport);
|
2017-03-09 08:01:10 +08:00
|
|
|
return (triple == NULL ? NULL : triple->value);
|
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/*!
|
|
|
|
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.
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
\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
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
NC_set_rcfile(const char* rcfile)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
FILE* f = NULL;
|
|
|
|
|
|
|
|
if(rcfile != NULL && strlen(rcfile) == 0)
|
|
|
|
rcfile = NULL;
|
|
|
|
f = NCfopen(rcfile,"r");
|
|
|
|
if(f == NULL) {
|
|
|
|
stat = NC_ERCFILE;
|
|
|
|
goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
fclose(f);
|
2017-09-01 04:19:56 +08:00
|
|
|
nullfree(ncrc_globalstate.rcinfo.rcfile);
|
|
|
|
ncrc_globalstate.rcinfo.rcfile = strdup(rcfile);
|
|
|
|
/* Clear ncrc_globalstate.rcinfo */
|
|
|
|
NC_rcclear(&ncrc_globalstate.rcinfo);
|
2017-08-31 07:44:57 +08:00
|
|
|
/* (re) load the rcfile and esp the triplestore*/
|
|
|
|
stat = NC_rcload();
|
|
|
|
done:
|
|
|
|
return stat;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
void
|
|
|
|
NC_rcclear(NCRCinfo* info)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
if(info == NULL) return;
|
2017-09-01 04:19:56 +08:00
|
|
|
nullfree(info->rcfile);
|
|
|
|
rcfreetriples(info->triples);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 04:19:56 +08:00
|
|
|
void
|
|
|
|
rcfreetriples(NClist* rc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<nclistlength(rc);i++) {
|
|
|
|
NCTriple* t = (NCTriple*)nclistget(rc,i);
|
|
|
|
nullfree(t->host);
|
|
|
|
nullfree(t->key);
|
|
|
|
nullfree(t->value);
|
|
|
|
free(t);
|
|
|
|
}
|
|
|
|
nclistfree(rc);
|
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* RC processing functions */
|
|
|
|
|
|
|
|
static char*
|
|
|
|
rcreadline(char** nextlinep)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
char* line;
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
line = (p = *nextlinep);
|
|
|
|
if(*p == '\0') return NULL; /*signal done*/
|
|
|
|
for(;*p;p++) {
|
|
|
|
if(*p == '\r' && p[1] == '\n') *p = '\0';
|
|
|
|
else if(*p == '\n') break;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
*p++ = '\0'; /* null terminate line; overwrite newline */
|
|
|
|
*nextlinep = p;
|
|
|
|
return line;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/* Trim TRIMCHARS from both ends of text; */
|
2017-03-09 08:01:10 +08:00
|
|
|
static void
|
2017-08-31 07:44:57 +08:00
|
|
|
rctrim(char* text)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
char* p = text;
|
|
|
|
size_t len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
len = strlen(text);
|
|
|
|
/* locate first non-trimchar */
|
|
|
|
for(;*p;p++) {
|
|
|
|
if(strchr(TRIMCHARS,*p) == NULL) break; /* hit non-trim char */
|
|
|
|
}
|
|
|
|
memmove(text,p,strlen(p)+1);
|
|
|
|
len = strlen(text);
|
|
|
|
/* locate last non-trimchar */
|
|
|
|
if(len > 0) {
|
|
|
|
for(i=(len-1);i>=0;i--) {
|
|
|
|
if(strchr(TRIMCHARS,text[i]) == NULL) {
|
|
|
|
text[i+1] = '\0'; /* elide trailing trimchars */
|
|
|
|
break;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Order the triples: those with urls must be first,
|
|
|
|
but otherwise relative order does not matter.
|
|
|
|
*/
|
2018-02-09 10:53:40 +08:00
|
|
|
static void
|
2017-08-31 07:44:57 +08:00
|
|
|
rcorder(NClist* rc)
|
|
|
|
{
|
2017-11-09 21:24:18 +08:00
|
|
|
int i;
|
2017-08-31 07:44:57 +08:00
|
|
|
int len = nclistlength(rc);
|
2018-02-09 10:53:40 +08:00
|
|
|
NClist* tmprc = nclistnew();
|
|
|
|
if(rc == NULL || len == 0) return;
|
|
|
|
/* Copy rc into tmprc and clear rc */
|
2017-08-31 07:44:57 +08:00
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
NCTriple* ti = nclistget(rc,i);
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistpush(tmprc,ti);
|
|
|
|
}
|
|
|
|
nclistclear(rc);
|
|
|
|
/* Two passes: 1) pull triples with host */
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
NCTriple* ti = nclistget(tmprc,i);
|
2017-08-31 07:44:57 +08:00
|
|
|
if(ti->host == NULL) continue;
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistpush(rc,ti);
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
|
|
|
/* pass 2 pull triples without host*/
|
|
|
|
for(i=0;i<len;i++) {
|
2018-02-09 10:53:40 +08:00
|
|
|
NCTriple* ti = nclistget(tmprc,i);
|
2017-08-31 07:44:57 +08:00
|
|
|
if(ti->host != NULL) continue;
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistpush(rc,ti);
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
|
|
|
#ifdef D4DEBUG
|
2018-02-09 10:53:40 +08:00
|
|
|
storedump("reorder:",rc);
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistfree(tmprc);
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a triple store from a file */
|
|
|
|
static int
|
2017-08-31 07:44:57 +08:00
|
|
|
rccompile(const char* path)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
int ret = NC_NOERR;
|
2018-02-09 10:53:40 +08:00
|
|
|
NClist* rc = NULL;
|
2017-08-31 07:44:57 +08:00
|
|
|
char* contents = NULL;
|
|
|
|
NCbytes* tmp = ncbytesnew();
|
|
|
|
NCURI* uri = NULL;
|
|
|
|
char* nextline = NULL;
|
|
|
|
|
|
|
|
if((ret=NC_readfile(path,tmp))) {
|
|
|
|
nclog(NCLOGERR, "Could not open configuration file: %s",path);
|
|
|
|
goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
contents = ncbytesextract(tmp);
|
|
|
|
if(contents == NULL) contents = strdup("");
|
2018-02-09 10:53:40 +08:00
|
|
|
/* Either reuse or create new */
|
|
|
|
rc = ncrc_globalstate.rcinfo.triples;
|
|
|
|
if(rc != NULL)
|
|
|
|
rcfreetriples(rc); /* clear out any old data */
|
|
|
|
else {
|
|
|
|
rc = nclistnew();
|
|
|
|
ncrc_globalstate.rcinfo.triples = rc;
|
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
nextline = contents;
|
2017-03-09 08:01:10 +08:00
|
|
|
for(;;) {
|
|
|
|
char* line;
|
2017-08-31 07:44:57 +08:00
|
|
|
char* key;
|
|
|
|
char* value;
|
|
|
|
size_t llen;
|
|
|
|
NCTriple* triple;
|
|
|
|
|
|
|
|
line = rcreadline(&nextline);
|
|
|
|
if(line == NULL) break; /* done */
|
|
|
|
rctrim(line); /* trim leading and trailing blanks */
|
|
|
|
if(line[0] == '#') continue; /* comment */
|
|
|
|
if((llen=strlen(line)) == 0) continue; /* empty line */
|
|
|
|
triple = (NCTriple*)calloc(1,sizeof(NCTriple));
|
|
|
|
if(triple == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
if(line[0] == LTAG) {
|
|
|
|
char* url = ++line;
|
|
|
|
char* rtag = strchr(line,RTAG);
|
|
|
|
if(rtag == NULL) {
|
|
|
|
nclog(NCLOGERR, "Malformed [url] in %s entry: %s",path,line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
line = rtag + 1;
|
|
|
|
*rtag = '\0';
|
|
|
|
/* compile the url and pull out the host */
|
|
|
|
if(uri) ncurifree(uri);
|
|
|
|
if(ncuriparse(url,&uri) != NCU_OK) {
|
|
|
|
nclog(NCLOGERR, "Malformed [url] in %s entry: %s",path,line);
|
|
|
|
continue;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
ncbytesclear(tmp);
|
|
|
|
ncbytescat(tmp,uri->host);
|
|
|
|
if(uri->port != NULL) {
|
|
|
|
ncbytesappend(tmp,':');
|
|
|
|
ncbytescat(tmp,uri->port);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
ncbytesnull(tmp);
|
|
|
|
triple->host = ncbytesextract(tmp);
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
/* split off key and value */
|
2017-08-31 07:44:57 +08:00
|
|
|
key=line;
|
2017-03-09 08:01:10 +08:00
|
|
|
value = strchr(line, '=');
|
|
|
|
if(value == NULL)
|
|
|
|
value = line + strlen(line);
|
|
|
|
else {
|
|
|
|
*value = '\0';
|
|
|
|
value++;
|
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
triple->key = strdup(key);
|
|
|
|
triple->value = strdup(value);
|
|
|
|
rctrim(triple->key);
|
|
|
|
rctrim(triple->value);
|
|
|
|
#ifdef D4DEBUG
|
|
|
|
fprintf(stderr,"rc: host=%s key=%s value=%s\n",
|
|
|
|
triple->host,triple->key,triple->valu);
|
|
|
|
#endif
|
|
|
|
nclistpush(rc,triple);
|
|
|
|
triple = NULL;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
rcorder(rc);
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
done:
|
2018-02-09 10:53:40 +08:00
|
|
|
if(contents) free(contents);
|
2017-08-31 07:44:57 +08:00
|
|
|
ncurifree(uri);
|
|
|
|
ncbytesfree(tmp);
|
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/**
|
|
|
|
* (Internal) Locate a triple by property key and host+port (may be null or "").
|
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
|
|
|
static struct NCTriple*
|
|
|
|
rclocate(const char* key, const char* hostport)
|
|
|
|
{
|
2018-02-09 10:53:40 +08:00
|
|
|
int i,found;
|
2017-09-01 04:19:56 +08:00
|
|
|
NClist* rc = ncrc_globalstate.rcinfo.triples;
|
2017-08-31 07:44:57 +08:00
|
|
|
NCTriple* triple = NULL;
|
|
|
|
|
2017-09-01 04:19:56 +08:00
|
|
|
if(ncrc_globalstate.rcinfo.ignore)
|
2017-08-31 07:44:57 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(key == NULL || rc == NULL) return NULL;
|
|
|
|
if(hostport == NULL) hostport = "";
|
|
|
|
|
|
|
|
for(found=0,i=0;i<nclistlength(rc);i++) {
|
|
|
|
triple = (NCTriple*)nclistget(rc,i);
|
2018-02-09 10:53:40 +08:00
|
|
|
size_t hplen = (triple->host == NULL ? 0 : strlen(triple->host));
|
|
|
|
int t;
|
2017-08-31 07:44:57 +08:00
|
|
|
if(strcmp(key,triple->key) != 0) continue; /* keys do not match */
|
|
|
|
/* If the triple entry has no url, then use it
|
|
|
|
(because we have checked all other cases)*/
|
|
|
|
if(hplen == 0) {found=1;break;}
|
|
|
|
/* do hostport match */
|
|
|
|
t = strcmp(hostport,triple->host);
|
|
|
|
if(t == 0) {found=1; break;}
|
|
|
|
}
|
|
|
|
return (found?triple:NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate rc file by searching in directory prefix.
|
|
|
|
* Prefix must end in '/'
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
int
|
|
|
|
rcsearch(const char* prefix, const char* rcname, char** pathp)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
char* path = NULL;
|
|
|
|
FILE* f = NULL;
|
|
|
|
int plen = strlen(prefix);
|
|
|
|
int rclen = strlen(rcname);
|
2017-08-31 07:44:57 +08:00
|
|
|
int ret = NC_NOERR;
|
|
|
|
|
|
|
|
size_t pathlen = plen+rclen+1; /*+1 for '/' */
|
|
|
|
path = (char*)malloc(pathlen+1); /* +1 for nul*/
|
|
|
|
if(path == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
strncpy(path,prefix,pathlen);
|
|
|
|
strncat(path,"/",pathlen);
|
|
|
|
strncat(path,rcname,pathlen);
|
2017-03-09 08:01:10 +08:00
|
|
|
/* see if file is readable */
|
|
|
|
f = fopen(path,"r");
|
|
|
|
if(f != NULL)
|
|
|
|
nclog(NCLOGDBG, "Found rc file=%s",path);
|
|
|
|
done:
|
2017-08-31 07:44:57 +08:00
|
|
|
if(f == NULL || ret != NC_NOERR) {
|
|
|
|
nullfree(path);
|
2017-03-09 08:01:10 +08:00
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
if(f != NULL)
|
2017-08-31 07:44:57 +08:00
|
|
|
fclose(f);
|
2017-03-09 08:01:10 +08:00
|
|
|
if(pathp != NULL)
|
2017-08-31 07:44:57 +08:00
|
|
|
*pathp = path;
|
|
|
|
else {
|
|
|
|
nullfree(path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
#ifdef D4DEBUG
|
|
|
|
static void
|
|
|
|
storedump(char* msg, NClist* triples)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(msg != NULL) fprintf(stderr,"%s\n",msg);
|
|
|
|
if(triples == NULL || nclistlength(triples)==0) {
|
|
|
|
fprintf(stderr,"<EMPTY>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for(i=0;i<nclistlength(triples);i++) {
|
|
|
|
NCTriple* t = (NCTriple*)nclistget(triples,i);
|
|
|
|
fprintf(stderr,"\t%s\t%s\t%s\n",
|
|
|
|
((t->host == NULL || strlen(t->host)==0)?"--":t->host),t->key,t->value);
|
|
|
|
}
|
|
|
|
fflush(stderr);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
|
|
|
|