Skip to content

Commit a2e0f06

Browse files
This pr should probably be delayed until after Version 4.5.
Primary change is to cleanup code and remove duplicated code. 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. 2. Unify the extraction from the rc file of DAP authorization info. 3. Misc. other small unifications: make temp file, read file. 4. Avoid use of libcurl when reading file:// because there is some kind of problem with the Visual Studio version. Might be related to the winpath problem. In any case, do direct read instead. 5. Add new error code NC_ERCFILE for errors in reading RC file. 6. Complete documentation cleanup as indicated in this comment #472 (comment) 7. Convert some occurrences of #ifdef _WIN32 to #ifdef _MSC_VER
1 parent 3a99220 commit a2e0f06

File tree

19 files changed

+121
-223
lines changed

19 files changed

+121
-223
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
13501350
CHECK_FUNCTION_EXISTS(strtoull HAVE_STRTOULL)
13511351
CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR)
13521352
CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
1353+
CHECK_FUNCTION_EXISTS(mktemp HAVE_MKTEMP)
13531354
CHECK_FUNCTION_EXISTS(rand HAVE_RAND)
13541355
CHECK_FUNCTION_EXISTS(random HAVE_RANDOM)
13551356
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)

cf.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Visual Studio
22
VS=1
3-
#VSSETUP=1
3+
4+
if test "x$1" = xsetup ; then
5+
VSSETUP=1
6+
fi
47

58
#export NCPATHDEBUG=1
69

config.h.cmake.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#cmakedefine HAVE_WINSOCK2_H
1818

1919
#ifdef HAVE_WINSOCK2_H
20-
#define _WINSOCKAPI_
20+
// #define _WINSOCKAPI_
2121
#endif
2222

2323
#if _MSC_VER>=1900
@@ -288,6 +288,9 @@ are set when opening a binary file on Windows. */
288288
/* Define to 1 if you have the `mkstemp' function. */
289289
#cmakedefine HAVE_MKSTEMP 1
290290

291+
/* Define to 1 if you have the `mktemp' function. */
292+
#cmakedefine HAVE_MKTEMP 1
293+
291294
/* Define to 1 if you have a working `mmap' system call. */
292295
#cmakedefine HAVE_MMAP 1
293296

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ AC_CHECK_HEADERS([ftw.h])
796796
# Check for these functions...
797797
AC_CHECK_FUNCS([strlcat strerror snprintf strchr strrchr strcat strcpy \
798798
strdup strcasecmp strtod strtoll strtoull strstr \
799-
mkstemp rand random memcmp \
799+
mkstemp mktemp rand random memcmp \
800800
getrlimit gettimeofday fsync MPI_Comm_f2c])
801801

802802
# Does the user want to use NC_DISKLESS?

docs/auth.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
125125
## Authorization-Related Keys {#AUTHKEYS}
126126

127127
The currently defined set of authorization-related keys are as follows.
128-
The second column is the affected curl_easy_setopt option(s), if any.
128+
The second column is the affected curl_easy_setopt option(s), if any
129+
(see reference #1).
129130
<table>
130131
<tr><th>Key</th><th>Affected curl_easy_setopt Options</th><th>Notes</th>
131132
<tr><td>HTTP.COOKIEJAR</td><td>CURLOPT_COOKIEJAR</td>
132133
<tr><td>HTTP.COOKIEFILE</td><td>CURLOPT_COOKIEJAR</td><td>Alias for CURLOPT_COOKIEJAR</td>
133-
<tr><td>HTTP.PROXY_SERVER</td><td>CURLOPT_PROXY, CURLOPT_PROXYPORT, CURLOPT_PROXYUSERPWD</td>
134+
<tr><td>HTTP.PROXY.SERVER</td><td>CURLOPT_PROXY, CURLOPT_PROXYPORT, CURLOPT_PROXYUSERPWD</td>
135+
<tr><td>HTTP.PROXY_SERVER</td><td>CURLOPT_PROXY, CURLOPT_PROXYPORT, CURLOPT_PROXYUSERPWD</td><td>Decprecated: use HTTP.PROXY.SERVER</td>
134136
<tr><td>HTTP.SSL.CERTIFICATE</td><td>CURLOPT_SSLCERT</td>
135137
<tr><td>HTTP.SSL.KEY</td><td>CURLOPT_SSLKEY</td>
136138
<tr><td>HTTP.SSL.KEYPASSWORD</td><td>CURLOPT_KEYPASSWORD</td>
@@ -191,15 +193,19 @@ specifies the password for accessing the HTTP.SSL.CERTIFICAT/HTTP.SSL.key file.
191193
HTTP.SSL.CAPATH
192194
specifies the path to a directory containing
193195
trusted certificates for validating server sertificates.
196+
See reference #2 for more info.
194197

195198
HTTP.SSL.VALIDATE
196199
is a boolean (1/0) value that if true (1)
197200
specifies that the client should verify the server's presented certificate.
198201

199-
HTTP.PROXY_SERVER
202+
HTTP.PROXY.SERVER
200203
specifies the url for accessing the proxy:
201204
e.g. *http://[username:password@]host[:port]*
202205

206+
HTTP.PROXY_SERVER
207+
deprecated; use HTTP.PROXY.SERVER
208+
203209
HTTP.NETRC
204210
specifies the absolute path of the .netrc file.
205211
See [redirection authorization](#REDIR)
@@ -296,6 +302,11 @@ This requires setting the following entries:
296302

297303
Note that the first two are there to support re-direction based authentication.
298304

305+
## References
306+
307+
1. https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
308+
2. https://curl.haxx.se/docs/ssl-compared.html
309+
299310
## Appendix A. All RC-File Keys {#allkeys}
300311

301312
For completeness, this is the list of all rc-file keys.
@@ -309,6 +320,7 @@ the code is definitive.
309320
<tr><td>HTTP.USERAGENT</td><td>CUROPT_USERAGENT</td>
310321
<tr><td>HTTP.COOKIEJAR</td><td>CUROPT_COOKIEJAR</td>
311322
<tr><td>HTTP.COOKIE_JAR</td><td>CUROPT_COOKIEJAR</td>
323+
<tr valign="top"><td>HTTP.PROXY.SERVER</td><td>CURLOPT_PROXY,<br>CURLOPT_PROXYPORT,<br>CURLOPT_PROXYUSERPWD</td>
312324
<tr valign="top"><td>HTTP.PROXY_SERVER</td><td>CURLOPT_PROXY,<br>CURLOPT_PROXYPORT,<br>CURLOPT_PROXYUSERPWD</td>
313325
<tr><td>HTTP.SSL.CERTIFICATE</td><td>CUROPT_SSLCERT</td>
314326
<tr><td>HTTP.SSL.KEY</td><td>CUROPT_SSLKEY</td>

include/ncauth.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Every curl connection will need a copy of this.
1717

1818
typedef struct NCauth {
1919
struct curlflags {
20-
int proto_file; /* Is file: supported? */
2120
int proto_https; /* is https: supported? */
2221
int compress; /*CURLOPT_ENCODING*/
2322
int verbose; /*CURLOPT_ENCODING*/

include/ncrc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ extern char* NC_backslashEscape(const char* s);
5454
extern char* NC_backslashUnescape(const char* esc);
5555
extern char* NC_entityescape(const char* s);
5656
extern int NC_readfile(const char* filename, NCbytes* content);
57-
extern int NC_mktmp(const char* base, char** tmpnamep);
57+
extern char* NC_mktmp(const char* base);
5858

5959
#endif /*NCRC_H*/

libdap4/d4curlfunctions.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,9 @@ NCD4_curl_protocols(NCD4INFO* state)
258258
curl_version_info_data* curldata;
259259
curldata = curl_version_info(CURLVERSION_NOW);
260260
for(proto=curldata->protocols;*proto;proto++) {
261-
if(strcmp("file",*proto)==0) {state->auth.curlflags.proto_file=1;}
262261
if(strcmp("http",*proto)==0) {state->auth.curlflags.proto_https=1;}
263262
}
264263
#ifdef D4DEBUG
265-
nclog(NCLOGNOTE,"Curl file:// support = %d",state->auth.curlflags.proto_file);
266264
nclog(NCLOGNOTE,"Curl https:// support = %d",state->auth.curlflags.proto_https);
267265
#endif
268266
}

libdap4/d4read.c

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ NCD4_readDAP(NCD4INFO* state, int flags)
3737
} else { /*((flags & NCF_ONDISK) != 0) */
3838
NCURI* url = state->uri;
3939
int fileprotocol = (strcmp(url->protocol,"file")==0);
40-
if(fileprotocol && !state->auth.curlflags.proto_file) {
40+
if(fileprotocol) {
4141
stat = readfiletofile(url, ".dap", state->data.ondiskfile, &state->data.datasize);
4242
} else {
4343
char* readurl = NULL;
@@ -86,7 +86,7 @@ readpacket(NCD4INFO* state, NCURI* url, NCbytes* packet, NCD4mode dxx, long* las
8686

8787
fileprotocol = (strcmp(url->protocol,"file")==0);
8888

89-
if(fileprotocol && !state->auth.curlflags.proto_file) {
89+
if(fileprotocol) {
9090
/* Short circuit file://... urls*/
9191
/* We do this because the test code always needs to read files*/
9292
stat = readfile(url,suffix,packet);
@@ -151,10 +151,6 @@ readfile(const NCURI* uri, const char* suffix, NCbytes* packet)
151151
{
152152
int stat = NC_NOERR;
153153
char buf[1024];
154-
int fd = -1;
155-
int flags = 0;
156-
d4size_t filesize = 0;
157-
d4size_t totalread = 0;
158154
NCbytes* tmp = ncbytesnew();
159155
char* filename = NULL;
160156

@@ -163,53 +159,7 @@ readfile(const NCURI* uri, const char* suffix, NCbytes* packet)
163159
ncbytesnull(tmp);
164160
filename = ncbytesextract(tmp);
165161
ncbytesfree(tmp);
166-
flags = O_RDONLY;
167-
#ifdef O_BINARY
168-
flags |= O_BINARY;
169-
#endif
170-
171-
fd = NCopen2(filename,flags);
172-
if(fd < 0) {
173-
nclog(NCLOGERR,"open failed:%s",filename);
174-
fprintf(stderr,"XXX: open failed: flags=0x%x file=%s\n",flags,filename);
175-
fflush(stderr);
176-
stat = NC_ENOTFOUND;
177-
goto done;
178-
}
179-
/* Get the file size */
180-
filesize = lseek(fd,(d4size_t)0,SEEK_END);
181-
if(filesize < 0) {
182-
stat = NC_EIO;
183-
nclog(NCLOGERR,"lseek failed: %s",filename);
184-
goto done;
185-
}
186-
/* Move file pointer back to the beginning of the file */
187-
(void)lseek(fd,(d4size_t)0,SEEK_SET);
188-
stat = NC_NOERR;
189-
for(totalread=0;;) {
190-
d4size_t count = (d4size_t)read(fd,buf,sizeof(buf));
191-
if(count == 0)
192-
break; /*eof*/
193-
else if(count < 0) {
194-
stat = NC_EIO;
195-
nclog(NCLOGERR,"read failed: %s",filename);
196-
goto done;
197-
}
198-
ncbytesappendn(packet,buf,(unsigned long)count);
199-
totalread += count;
200-
}
201-
if(totalread < filesize) {
202-
stat = NC_EIO;
203-
nclog(NCLOGERR,"short read: |%s|=%lu read=%lu\n",
204-
filename,(unsigned long)filesize,(unsigned long)totalread);
205-
goto done;
206-
}
207162

208-
done:
209-
#ifdef D4DEBUG
210-
fprintf(stderr,"readfile: filesize=%lu totalread=%lu\n",
211-
(unsigned long)filesize,(unsigned long)totalread);
212-
#endif
213-
if(fd >= 0) close(fd);
163+
stat = NC_readfile(filename,packet);
214164
return THROW(stat);
215165
}

libdispatch/dauth.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ See LICENSE.txt for license information.
55

66

77
#include "config.h"
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
811
#ifdef HAVE_UNISTD_H
912
#include <unistd.h>
1013
#endif
1114
#ifdef HAVE_STDARG_H
1215
#include <stdarg.h>
1316
#endif
14-
#include <stdio.h>
15-
#include <stdlib.h>
16-
#include <string.h>
1717
#include "netcdf.h"
1818
#include "ncbytes.h"
1919
#include "ncuri.h"
2020
#include "ncauth.h"
2121
#include "nclog.h"
2222
#include "ncwinpath.h"
2323

24+
#ifdef _MSC_VER
25+
#include <windows.h>
26+
#endif
27+
2428
#undef MEMCHECK
2529
#define MEMCHECK(x) if((x)==NULL) {goto nomem;} else {}
2630

@@ -111,6 +115,8 @@ NC_authsetup(NCauth* auth, NCURI* uri)
111115
NC_rclookup("HTTP.COOKIEJAR",uri_hostport));
112116
setauthfield(auth,"HTTP.COOKIE_JAR",
113117
NC_rclookup("HTTP.COOKIE_JAR",uri_hostport));
118+
setauthfield(auth,"HTTP.PROXY.SERVER",
119+
NC_rclookup("HTTP.PROXY.SERVER",uri_hostport));
114120
setauthfield(auth,"HTTP.PROXY_SERVER",
115121
NC_rclookup("HTTP.PROXY_SERVER",uri_hostport));
116122
setauthfield(auth,"HTTP.SSL.VALIDATE",
@@ -229,11 +235,11 @@ setauthfield(NCauth* auth, const char* flag, const char* value)
229235
nclog(NCLOGNOTE,"HTTP.COOKIEJAR: %s", auth->curlflags.cookiejar);
230236
#endif
231237
}
232-
if(strcmp(flag,"HTTP.PROXY_SERVER")==0) {
238+
if(strcmp(flag,"HTTP.PROXY.SERVER")==0 || strcmp(flag,"HTTP.PROXY_SERVER")==0) {
233239
ret = NC_parseproxy(auth,value);
234240
if(ret != NC_NOERR) goto done;
235241
#ifdef D4DEBUG
236-
nclog(NCLOGNOTE,"HTTP.PROXY_SERVER: %s", value);
242+
nclog(NCLOGNOTE,"HTTP.PROXY.SERVER: %s", value);
237243
#endif
238244
}
239245
if(strcmp(flag,"HTTP.SSL.VALIDATE")==0) {

0 commit comments

Comments
 (0)