コード例 #1
0
ファイル: ocinternal.c プロジェクト: qingu/WRF-Libraries
/*
    Set curl properties for link based on rc files
*/
static void
ocsetcurlproperties(OCstate* state)
{
    CURLcode cstat = CURLE_OK;

    /* process the triple store wrt to this state */
    if(ocdodsrc_process(state) != OC_NOERR) {
	oc_log(LOGERR,"Malformed .opendaprc configuration file");
	goto fail;
    }
    if(state->creds.username == NULL && state->creds.password == NULL) {
        if(state->uri->user != NULL && state->uri->password != NULL) {
	    /* this overrides .dodsrc */
            if(state->creds.password) free(state->creds.password);
            state->creds.password = nulldup(state->uri->password);
            if(state->creds.username) free(state->creds.username);
            state->creds.username = nulldup(state->uri->user);
	}
    }
    return;

fail:
    if(cstat != CURLE_OK)
	oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat));
    return;
}
コード例 #2
0
ファイル: ocinternal.c プロジェクト: rprinceley/netcdf-c
/*
    Set curl properties for link based on rc files
*/
static void
ocsetcurlproperties(OCstate* state)
{
    CURLcode cstat = CURLE_OK;

    /* process the triple store wrt to this state */
    if(ocdodsrc_process(state) != OC_NOERR) {
	oclog(OCLOGERR,"Malformed .opendaprc configuration file");
	goto fail;
    }
    if(state->creds.username == NULL && state->creds.password == NULL) {
        if(state->uri->user != NULL && state->uri->password != NULL) {
	    /* this overrides .dodsrc */
            if(state->creds.password) free(state->creds.password);
            state->creds.password = nulldup(state->uri->password);
            if(state->creds.username) free(state->creds.username);
            state->creds.username = nulldup(state->uri->user);
	}
    }
    if(state->curlflags.useragent == NULL) {
        size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
	char* agent = (char*)malloc(len+1);
	if(occopycat(agent,len,2,DFALTUSERAGENT,VERSION))
	  state->curlflags.useragent = agent;
	else
	  free(agent);
    }
    return;

fail:
    if(cstat != CURLE_OK)
	oclog(OCLOGERR, "curl error: %s", curl_easy_strerror(cstat));
    return;
}
コード例 #3
0
/*
    Set curl properties for link based on rc files
*/
static void
ocsetcurlproperties(OCstate* state)
{
    CURL* curl = state->curl;
    CURLcode cstat = CURLE_OK;
    int stat = OC_NOERR;

    /* process the triple store wrt to this state */
    if(ocdodsrc_process(state) != OC_NOERR) {
	oc_log(LOGERR,"Malformed .dodsrc");
	goto fail;
    }
    /* Set username+password from .dodsrc */
    stat=ocset_user_password(curl,state->creds.username,
                                  state->creds.password);
    if(stat != OC_NOERR) goto fail;    

    if (occredentials_in_url(state->url.url)) {
	/* this overrides .dodsrc */
        char *result_url = NULL;
        char* userName = NULL;
        char* password = NULL;
        if (ocextract_credentials(state->url.url, &userName, &password, &result_url) != OC_NOERR)
            goto fail;
	dapurlclear(&state->url);
	dapurlparse(result_url,&state->url);
	/* this overrides .dodsrc */
        if(password != NULL && strlen(password) > 0) {
            if(state->creds.password) free(state->creds.password);
            state->creds.password = password;
	}
        if(userName != NULL && strlen(userName) > 0) {
            if(state->creds.username) free(state->creds.username);
            state->creds.username = userName;
	}
    }

    /* Set curl properties */
    if((stat=ocset_curl_flags(curl,state)) != OC_NOERR) goto fail;
    /* Set curl proxy */
    if((stat=ocset_proxy(curl,state)) != OC_NOERR) goto fail;
    /* Set curl ssl */
    if((stat=ocset_ssl(curl,state)) != OC_NOERR) goto fail;

    return;

fail:
    if(cstat != CURLE_OK)
	oc_log(LOGERR, "curl error: %s", curl_easy_strerror(cstat));
    return;
}
コード例 #4
0
ファイル: ocinternal.c プロジェクト: ArtisticCoding/libmesh
/*
    Set curl properties for link based on rc files etc.
*/
static int
ocsetcurlproperties(OCstate* state)
{
    CURLcode cstat = CURLE_OK;

    /* process the triple store wrt to this state */
    if(ocdodsrc_process(state) != OC_NOERR) {
	oclog(OCLOGERR,"Malformed .opendaprc configuration file");
	goto fail;
    }
    if(state->creds.username == NULL && state->creds.password == NULL) {
        if(state->uri->user != NULL && state->uri->password != NULL) {
	    /* this overrides .dodsrc */
            if(state->creds.password) free(state->creds.password);
            state->creds.password = nulldup(state->uri->password);
            if(state->creds.username) free(state->creds.username);
            state->creds.username = nulldup(state->uri->user);
	}
    }
    if(state->curlflags.useragent == NULL) {
        size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
	char* agent = (char*)malloc(len+1);
	if(occopycat(agent,len,2,DFALTUSERAGENT,VERSION))
	    state->curlflags.useragent = agent;
	else
	    free(agent);
    }

    /* Some servers (e.g. thredds and columbia) appear to require a place
       to put cookies in order for some security functions to work
    */
    if(state->curlflags.cookiejar == NULL
       || *state->curlflags.cookiejar) {
#if 1
	/* Apparently anything non-null will work */
	state->curlflags.cookiejar = strdup("");
#else
	/* If no cookie file was defined, define a default */
	char* tmp;
	int fd;
        int stat;

        tmp = (char*)malloc(strlen(ocglobalstate.home)
				  +strlen("/")
				  +strlen(OCDIR)
				  +strlen("/")
				  +1);
	if(tmp == NULL)
	    return OC_ENOMEM;
	strcpy(tmp,ocglobalstate.home);
	strcat(tmp,"/");
	strcat(tmp,OCDIR);
	strcat(tmp,"/");
	stat = mkdir(tmp,S_IRUSR | S_IWUSR | S_IXUSR);
	if(stat != 0 && errno != EEXIST) {
	    fprintf(stderr,"Cannot create cookie file\n");
	    return stat;
	}
	errno = 0;
	/* Create the actual cookie file */
	stat = ocmktmp(tmp,&state->curlflags.cookiejar,&fd);
	close(fd);

#if 0
	fd = creat(tmp,S_IRUSR | S_IWUSR);
	if(fd < 0) {
	    fprintf(stderr,"Cannot create cookie file\n");
	    return OC_EPERM;
	}else
	    close(fd);
#endif
#endif
    }
    return OC_NOERR;

fail:
    if(cstat != CURLE_OK)
	oclog(OCLOGERR, "curl error: %s", curl_easy_strerror(cstat));
    return OC_ECURL;
}