Skip to content

Commit

Permalink
Make public a limited API for programmatic access to internal .rc tables
Browse files Browse the repository at this point in the history
re: Unidata#2337
re: Unidata#2407

Add two functions to netcdf.h to allow programs to get/set
selected entries into the internal .rc tables. This should fix
the above issues by allowing HTTP.CAINFO to be set to the
certificates directory.  Note that the changes should be
performed as early as possible in the program because some of
the .rc table entries may get cached internally and changing the
entry after that caching occurs may have no effect.

The new signatures are as follows:

1. Get the value of a simple .rc entry of the form "key=value".
Note that caller must free the returned value, which might be NULL.
````
char* nc_rc_get(char* const * key);

@param key table entry key
@return value if .rc table has entry of the form key=value
@return NULL if no such entry is found.
````

2. Insert/Overwrite the specified key=value pair in the .rc table.
````
int nc_rc_set(const char* key, const char* value);

@param key table entry key -- may not be NULL
@param value table entry value -- may not be NULL
@return NC_NOERR if no error
@return NC_EINVAL if error
````

Addendum:

re: Unidata#2407

Modify dhttp.c to use the .rc entry HTTP.CAINFO if defined.
  • Loading branch information
DennisHeimbigner committed Jun 17, 2022
1 parent 7375f4b commit aabbdbf
Show file tree
Hide file tree
Showing 17 changed files with 407 additions and 124 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ endif()
if(MSVC)
SET(ISMSVC yes)
endif()
if(osname MATCHES "MINGW.*")
if(osname MATCHES "MINGW.*" OR osname MATCHES "MSYS.*")
SET(ISMINGW yes)
SET(MINGW yes)
endif()
Expand Down
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This file contains a high-level description of this package's evolution. Release

## 4.9.1 - T.B.D.


* [Enhancement] Provide a simple API to allow user access to the internal .rc file table: supports get/set/overwrite of entries of the form "key=value". See [Github #????](https://github.com/Unidata/netcdf-c/pull/????).
* [Bug Fix] Use env variable USERPROFILE instead of HOME for windows and mingw. See [Github #2405](https://github.com/Unidata/netcdf-c/pull/2405).
* [Bug Fix] Fix the nc_def_var_fletcher32 code in hdf5 to properly test value of the fletcher32 argument. See [Github #2403](https://github.com/Unidata/netcdf-c/pull/2403).

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ case "`uname`" in
Darwin*) ISOSX=yes;;
WIN*) ISMSVC=yes;;
MINGW*) ISMINGW=yes;;
MSYS*) ISMINGW=yes;;
esac

if test "x$MSYSTEM" != x ; then
Expand Down
4 changes: 2 additions & 2 deletions include/ncrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ and accessing rc files (e.g. .daprc).

typedef struct NCRCentry {
char* host; /* combined host:port */
char* path; /* prefix to match or NULL */
char* urlpath; /* prefix to match or NULL */
char* key;
char* value;
} NCRCentry;
Expand Down Expand Up @@ -67,7 +67,7 @@ extern "C" {

/* From drc.c */
EXTERNL void ncrc_initialize(void);
EXTERNL int NC_rcfile_insert(const char* key, const char* value, const char* hostport, const char* path);
EXTERNL int NC_rcfile_insert(const char* key, const char* hostport, const char* path, const char* value);
EXTERNL char* NC_rclookup(const char* key, const char* hostport, const char* path);
EXTERNL char* NC_rclookupx(NCURI* uri, const char* key);

Expand Down
8 changes: 8 additions & 0 deletions include/netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,14 @@ EXTERNL int nc_initialize(void);
*/
EXTERNL int nc_finalize(void);

/* Programmatic access to the internal .rc table */

/* Get the value corresponding to key | return NULL; caller frees result */
EXTERNL char* nc_rc_get(const char* key);

/* Set/overwrite the value corresponding to key */
EXTERNL int nc_rc_set(const char* key, const char* value);

#if defined(__cplusplus)
}
#endif
Expand Down
1 change: 0 additions & 1 deletion libdispatch/ddispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ NCDISPATCH_initialize(void)
NCpathcanonical(home,&globalstate->home);
nullfree(home);
}
fprintf(stderr,">>> HOME=|%s|\n",globalstate->home); fflush(stderr);

/* Capture $CWD */
{
Expand Down
19 changes: 19 additions & 0 deletions libdispatch/dhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "nclog.h"
#include "ncbytes.h"
#include "nclist.h"
#include "ncuri.h"
#include "nchttp.h"
#include "ncauth.h"

#undef TRACE

Expand Down Expand Up @@ -482,6 +484,23 @@ setupconn(NC_HTTP_STATE* state, const char* objecturl)
cstat = curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
if (cstat != CURLE_OK) goto fail;

/* Pull some values from .rc tables */
{
NCURI* uri = NULL;
char* hostport = NULL;
char* value = NULL;
ncuriparse(objecturl,&uri);
if(uri == NULL) goto fail;
hostport = NC_combinehostport(uri);
value = NC_rclookup("HTTP.CAINFO",hostport,NULL);
if(value == NULL)
value = NC_rclookup("HTTP.CAINFO",NULL,NULL);
if(value != NULL) {
cstat = CURLERR(curl_easy_setopt(state->curl, CURLOPT_CAINFO, value));
if (cstat != CURLE_OK) goto fail;
}
}

/* Set the method */
if((stat = nc_http_set_method(state,state->request.method))) goto done;

Expand Down
Loading

0 comments on commit aabbdbf

Please sign in to comment.