コード例 #1
0
ファイル: ocread.c プロジェクト: gitter-badger/quinoa
int
readDATADDS(OCstate* state, OCtree* tree, OCflags flags)
{
    int stat = OC_NOERR;
    long lastmod = -1;

#ifdef OCDEBUG
fprintf(stderr,"readDATADDS:\n");
#endif
    if((flags & OCONDISK) == 0) {
        ocurisetconstraints(state->uri,tree->constraint);
        stat = readpacket(state,state->uri,state->packet,OCDATADDS,&lastmod);
        if(stat == OC_NOERR)
            state->datalastmodified = lastmod;
        tree->data.datasize = ocbyteslength(state->packet);
    } else { /*((flags & OCONDISK) != 0) */
        OCURI* url = state->uri;
        int fileprotocol = 0;
        char* readurl = NULL;

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

        if(fileprotocol && !state->curlflags.proto_file) {
            readurl = ocuribuild(url,NULL,NULL,0);
            stat = readfiletofile(readurl, ".dods", tree->data.file, &tree->data.datasize);
        } else {
            int flags = 0;
            if(!fileprotocol) flags |= OCURICONSTRAINTS;
            flags |= OCURIENCODE;
	    flags |= OCURIUSERPWD;
            ocurisetconstraints(url,tree->constraint);
            readurl = ocuribuild(url,NULL,".dods",flags);
            MEMCHECK(readurl,OC_ENOMEM);
            if (ocdebug > 0) 
                {fprintf(stderr, "fetch url=%s\n", readurl);fflush(stderr);}
            stat = ocfetchurl_file(state->curl, readurl, tree->data.file,
                                   &tree->data.datasize, &lastmod);
            if(stat == OC_NOERR)
                state->datalastmodified = lastmod;
            if (ocdebug > 0) 
                {fprintf(stderr,"fetch complete\n"); fflush(stderr);}
        }
        free(readurl);
    }
    return OCTHROW(stat);
}
コード例 #2
0
ファイル: ocread.c プロジェクト: gitter-badger/quinoa
static int
readpacket(OCstate* state, OCURI* url,OCbytes* packet,OCdxd dxd,long* lastmodified)
{
   int stat = OC_NOERR;
   int fileprotocol = 0;
   const char* suffix = ocdxdextension(dxd);
   char* fetchurl = NULL;
   CURL* curl = state->curl;

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

   if(fileprotocol && !state->curlflags.proto_file) {
        /* Short circuit file://... urls*/
	/* We do this because the test code always needs to read files*/
	fetchurl = ocuribuild(url,NULL,NULL,0);
	stat = readfile(fetchurl,suffix,packet);
    } else {
	int flags = 0;
	if(!fileprotocol) {
	    flags |= OCURICONSTRAINTS;
	}
	flags |= OCURIENCODE;
        fetchurl = ocuribuild(url,NULL,suffix,flags);
	MEMCHECK(fetchurl,OC_ENOMEM);
	if(ocdebug > 0)
            {fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);}
        stat = ocfetchurl(curl,fetchurl,packet,lastmodified,&state->creds);
	if(stat)
	    oc_curl_printerror(state);
	if(ocdebug > 0)
            {fprintf(stderr,"fetch complete\n"); fflush(stderr);}
    }
    free(fetchurl);
#ifdef OCDEBUG
  {
fprintf(stderr,"readpacket: packet.size=%lu\n",
		(unsigned long)ocbyteslength(packet));
  }
#endif
    return OCTHROW(stat);
}
コード例 #3
0
ファイル: ocinternal.c プロジェクト: qingu/WRF-Libraries
OCerror
ocupdatelastmodifieddata(OCstate* state)
{
    OCerror status = OC_NOERR;
    long lastmodified;
    char* base = NULL;
    base = ocuribuild(state->uri,NULL,NULL,OCURIENCODE);
    status = ocfetchlastmodified(state->curl, base, &lastmodified);
    free(base);
    if(status == OC_NOERR) {
	state->datalastmodified = lastmodified;
    }
    return status;
}
コード例 #4
0
ファイル: ocrc.c プロジェクト: UV-CDAT/netcdf
int
ocdodsrc_process(OCstate* state)
{
    int stat = 0;
    char* value;
    char* url = ocuribuild(state->uri,NULL,NULL,OCURIENCODE);
    struct OCTriplestore* ocdodsrc = ocglobalstate.ocdodsrc;

    if(ocdodsrc == NULL) goto done;
    value = curllookup("DEFLATE",url);
    if(value != NULL) {
        if(atoi(value)) state->curlflags.compress = 1;
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"Compression: %ld", state->curlflags.compress);
    }
    if((value = curllookup("VERBOSE",url)) != NULL) {
        if(atoi(value)) state->curlflags.verbose = 1;
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"curl.verbose: %ld", state->curlflags.verbose);
    }
    if((value = curllookup("TIMEOUT",url)) != NULL) {
        if(atoi(value)) state->curlflags.timeout = atoi(value);
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"curl.timeout: %ld", state->curlflags.timeout);
    }
    if((value = curllookup("USERAGENT",url)) != NULL) {
        if(atoi(value)) state->curlflags.useragent = strdup(TRIM(value));
        if(!state->curlflags.useragent) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"USERAGENT: %s", state->curlflags.useragent);
    }

    if((value = curllookup("COOKIEFILE",url)) != NULL) {
        state->curlflags.cookiefile = strdup(TRIM(value));
        if(!state->curlflags.cookiefile) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"COOKIEFILE: %s", state->curlflags.cookiefile);
    }
    if((value = curllookup("COOKIEJAR",url))
       || (value = curllookup("COOKIE_JAR",url))) {
        state->curlflags.cookiejar = strdup(TRIM(value));
        if(!state->curlflags.cookiejar) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"COOKIEJAR: %s", state->curlflags.cookiejar);
    }

    /* Some servers (e.g. thredds) appear to require a place
       to put cookies in order for some security functions to work
    */
    if(state->curlflags.cookiejar == NULL
       && state->curlflags.cookiefile == NULL) {
	state->curlflags.cookiefile = strdup("");
    }

    if((value = curllookup("PROXY_SERVER",url)) != NULL) {
        stat = parseproxy(state,TRIM(value));
        if(stat != OC_NOERR) goto done;
    }

    if((value = curllookup("SSL.VALIDATE",url)) != NULL) {
        if(atoi(value)) state->ssl.validate = 1;
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"CURL.SSL.VALIDATE: %ld", state->ssl.validate);
    }

    if((value = curllookup("SSL.CERTIFICATE",url)) != NULL) {
        state->ssl.certificate = strdup(TRIM(value));
        if(!state->ssl.certificate) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"CREDENTIALS.SSL.CERTIFICATE: %s", state->ssl.certificate);
    }

    if((value = curllookup("SSL.KEY",url)) != NULL) {
        state->ssl.key = strdup(TRIM(value));
        if(!state->ssl.key) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"CREDENTIALS.SSL.KEY: %s", state->ssl.key);
    }

    if((value = curllookup("SSL.KEYPASSWORD",url)) != NULL) {
        state->ssl.keypasswd = strdup(TRIM(value));
        if(!state->ssl.keypasswd) {stat = OC_ENOMEM; goto done;}
#ifdef INSECURE
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"CREDENTIALS.SSL.KEYPASSWORD: %s", state->ssl.keypasswd);
#endif
    }

    if((value = curllookup("SSL.CAINFO",url)) != NULL) {
        state->ssl.cainfo = strdup(TRIM(value));
        if(!state->ssl.cainfo) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"SSL.CAINFO: %s", state->ssl.cainfo);
    }

    if((value = curllookup("SSL.CAPATH",url)) != NULL) {
        state->ssl.capath = strdup(TRIM(value));
        if(!state->ssl.capath) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"SSL.CAPATH: %s", state->ssl.capath);
    }

    if((value = curllookup("SSL.VERIFYPEER",url)) != NULL) {
	char* s = strdup(TRIM(value));
	int tf = 0;
	if(s == NULL || strcmp(s,"0")==0 || strcasecmp(s,"false")==0)
	    tf = 0;
	else if(strcmp(s,"1")==0 || strcasecmp(s,"true")==0)
	    tf = 1;
	else
	    tf = 1; /* default if not null */
        state->ssl.verifypeer = tf;
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"SSL.VERIFYPEER: %d", state->ssl.verifypeer);
    }

    if((value = curllookup("CREDENTIALS.USER",url)) != NULL) {
        state->creds.username = strdup(TRIM(value));
        if(!state->creds.username) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"CREDENTIALS.USER: %s", state->creds.username);
    }

    if((value = curllookup("CREDENTIALS.PASSWORD",url)) != NULL) {
        state->creds.password = strdup(TRIM(value));
        if(!state->creds.password) {stat = OC_ENOMEM; goto done;}
    }
    /* else ignore */    

done:
    if(url != NULL) free(url);
    return stat;
}