mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
aabbdbf64c
re: https://github.com/Unidata/netcdf-c/issues/2337 re: https://github.com/Unidata/netcdf-c/issues/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: https://github.com/Unidata/netcdf-c/issues/2407 Modify dhttp.c to use the .rc entry HTTP.CAINFO if defined.
52 lines
1.0 KiB
C
52 lines
1.0 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "netcdf.h"
|
|
#include "ncrc.h"
|
|
#include "nc4internal.h"
|
|
|
|
static void
|
|
printrc(NCglobalstate* ngs)
|
|
{
|
|
size_t i,nentries = 0;
|
|
NCRCinfo* info = NULL;
|
|
NCRCentry* entry = NULL;
|
|
|
|
info = ngs->rcinfo;
|
|
if(info->ignore) {
|
|
fprintf(stderr,".rc ignored\n");
|
|
return;
|
|
}
|
|
|
|
/* Print out the .rc entries */
|
|
if((nentries = NC_rcfile_length(info))==0) {
|
|
printf("<empty>\n");
|
|
exit(0);
|
|
}
|
|
for(i=0;i<nentries;i++) {
|
|
entry = NC_rcfile_ith(info,i);
|
|
if(entry == NULL) abort();
|
|
if(entry->host != NULL) {
|
|
printf("[%s ",entry->host);
|
|
if(entry->urlpath != NULL)
|
|
printf("/%s] ",entry->urlpath);
|
|
printf("]");
|
|
}
|
|
printf("|%s|->|%s|\n",entry->key,entry->value);
|
|
}
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
NCglobalstate* ngs = NC_getglobalstate();
|
|
|
|
/* Cause the .rc files to be read and merged */
|
|
nc_initialize();
|
|
|
|
if((ngs = NC_getglobalstate())==NULL) abort();
|
|
printrc(ngs);
|
|
|
|
return 0;
|
|
}
|