fixed file: url case

This commit is contained in:
Dennis Heimbigner 2011-01-04 22:16:55 +00:00
parent 52d1a2b74e
commit 30733da7f6
4 changed files with 30 additions and 16 deletions

View File

@ -118,7 +118,12 @@ ocset_ssl(CURL* curl, OCstate* state)
DEBUG1(1,"CURLOPT_SSLKEY=%s",ssl->key);
}
if(ssl->keypasswd) {
// libcurl prior to 7.16.4 used 'CURLOPT_SSLKEYPASSWD'
#if HAVE_CURLOPT_KEYPASSWD
cstat = curl_easy_setopt(curl, CURLOPT_KEYPASSWD, ssl->keypasswd);
#else
cstat = curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, ssl->keypasswd);
#endif
if(cstat != CURLE_OK) goto fail;
DEBUG1(1,"CURLOPT_SSLKEY=%s",ssl->key);
}

View File

@ -124,15 +124,20 @@ dapurlsetconstraints(DAPURL* durl,const char* constraints)
char* select = NULL;
const char* p;
if(durl->constraint == NULL) ocfree(durl->constraint);
if(durl->projection != NULL) ocfree(durl->projection);
if(durl->selection != NULL) ocfree(durl->selection);
durl->constraint = NULL;
durl->projection = NULL;
durl->selection = NULL;
if(constraints == NULL || strlen(constraints)==0) return;
p = constraints;
if(p[0] == '?') p++;
durl->constraint = strdup(constraints);
if(*durl->constraint == '?')
strcpy(durl->constraint,durl->constraint+1);
p = durl->constraint;
proj = (char*) p;
select = strchr(proj,'&');
if(select != NULL) {
@ -153,13 +158,15 @@ dapurlsetconstraints(DAPURL* durl,const char* constraints)
durl->selection = select;
}
/* Construct a complete DAP URL without the client params
and optionally with the constraints;
caller frees returned string
*/
char*
dapurlgeturl(DAPURL* durl, const char* prefix, const char* suffix,
int withconstraints)
int withconstraints, int withparams)
{
size_t len = 0;
char* newurl;
@ -167,11 +174,12 @@ dapurlgeturl(DAPURL* durl, const char* prefix, const char* suffix,
len += strlen(durl->base);
if(prefix != NULL) len += strlen(prefix);
if(suffix != NULL) len += strlen(suffix);
if(withparams && durl->params != NULL && strlen(durl->params) > 0)
len += strlen(durl->params);
if(withconstraints
&& (durl->projection != NULL || durl->selection != NULL)) {
&& durl->constraint != NULL && strlen(durl->constraint)> 0) {
len += 1; /* leading '?' */
if(durl->projection != NULL) len += strlen(durl->projection);
if(durl->selection != NULL) len += strlen(durl->selection);
len += strlen(durl->constraint);
}
len += 1; /* null terminator */
@ -179,13 +187,14 @@ dapurlgeturl(DAPURL* durl, const char* prefix, const char* suffix,
if(!newurl) return NULL;
newurl[0] = '\0';
if(prefix != NULL) strcat(newurl,prefix);
if(withparams && durl->params != NULL && strlen(durl->params) > 0)
strcat(newurl,durl->params);
strcat(newurl,durl->base);
if(suffix != NULL) strcat(newurl,suffix);
if(withconstraints
&& (durl->projection != NULL || durl->selection != NULL)) {
&& durl->constraint != NULL && strlen(durl->constraint)> 0) {
strcat(newurl,"?");
if(durl->projection != NULL) strcat(newurl,durl->projection);
if(durl->selection != NULL) strcat(newurl,durl->selection);
strcat(newurl,durl->constraint);
}
return newurl;
}

View File

@ -13,10 +13,10 @@ typedef struct DAPURL {
char* url; /* as passed by the caller */
char* base; /*!< without constraints*/
char* protocol;
char* constraint;
char* constraint; /* projection+selection */
char* projection; /*!< without leading '?'*/
char* selection; /*!< with leading '&'*/
char* params;
char* params; /* all params */
struct OClist* paramlist;
} DAPURL;
@ -29,7 +29,7 @@ extern void dapurlclear(DAPURL* dapurl);/*!<Release strings associated
extern void dapurlsetconstraints(DAPURL*,const char* constraints);
/* Construct a complete DAP URL; caller frees returned string */
extern char* dapurlgeturl(DAPURL*,const char* prefix, const char* suffix, int withconstraints);
extern char* dapurlgeturl(DAPURL*,const char* prefix, const char* suffix, int withconstraints, int withparams);
extern int dapurldecodeparams(DAPURL* dapurl);

View File

@ -63,14 +63,14 @@ readpacket(CURL* curl,DAPURL* url,OCbytes* packet,OCdxd dxd,long* lastmodified)
int fileprotocol = 0;
char* suffix = ocdxdextension[dxd];
fileprotocol = (strncmp(url->base,"file:",5)==0);
fileprotocol = (strncmp(url->base,"file",4)==0);
if(fileprotocol && !oc_curl_file_supported) {
/* Short circuit file://... urls*/
/* We do this because the test code always needs to read files*/
stat = readfile(url->base,suffix,packet);
} else {
char* fetchurl = dapurlgeturl(url,NULL,suffix,!fileprotocol);
char* fetchurl = dapurlgeturl(url,NULL,suffix,!fileprotocol,0);
MEMCHECK(fetchurl,OC_ENOMEM);
if(ocdebug > 0)
{fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);}
@ -97,14 +97,14 @@ readDATADDS(OCstate* state, OCtree* tree)
DAPURL* url = &state->url;
int fileprotocol = 0;
fileprotocol = (strncmp(url->base,"file:",5)==0);
fileprotocol = (strncmp(url->base,"file",4)==0);
if(fileprotocol && !oc_curl_file_supported) {
stat = readfiletofile(url->base, ".dods", tree->data.file, &tree->data.datasize);
} else {
char* fetchurl;
dapurlsetconstraints(url,tree->constraint);
fetchurl = dapurlgeturl(url,NULL,".dods",!fileprotocol);
fetchurl = dapurlgeturl(url,NULL,".dods",!fileprotocol,0);
MEMCHECK(fetchurl,OC_ENOMEM);
if (ocdebug > 0)
{fprintf(stderr, "fetch url=%s\n", fetchurl);fflush(stderr);}