Пример #1
0
/**
Directly set any options starting with 'CURL.'
*/
static OCerror
oc_set_curl_options(OCstate* state)
{
    OCerror stat = OC_NOERR;
    struct OCTriplestore* store = NULL;
    struct OCTriple* triple = NULL;
    int i;
    char* hostport = NULL;
    struct OCCURLFLAG* ocflag = NULL;

    hostport = occombinehostport(state->uri);
    if(hostport == NULL) {
      hostport = (char*)malloc(sizeof(char)*1);
      *hostport = "";
    }

    store = &ocglobalstate.rc.ocrc;
    triple = store->triples;

    /* Assume that the triple store has been properly sorted */
    for(i=0;i<store->ntriples;i++,triple++) {
        size_t hostlen = strlen(triple->host);
        const char* flagname;

        if(ocstrncmp("CURL.",triple->key,5) != 0) continue; /* not a curl flag */
        /* do hostport prefix comparison */
        if(hostlen > 0) {
          int t = ocstrncmp(hostport,triple->host,hostlen);
          if(t !=  0) continue;
        }
        flagname = triple->key+5; /* 5 == strlen("CURL."); */
        ocflag = occurlflagbyname(flagname);
        if(ocflag == NULL) {stat = OC_ECURL; goto done;}
        stat = ocset_curlopt(state,ocflag->flag,cvt(triple->value,ocflag->type));
    }
 done:
    if(hostport && strcmp(hostport,"") != 0) free(hostport);
    return stat;
}
Пример #2
0
int
ocrc_process(OCstate* state)
{
    int stat = 0;
    char* value = NULL;
    OCURI* uri = state->uri;
    char* url_userpwd = NULL;
    char* url_hostport = NULL;

    if(!ocglobalstate.initialized)
	ocinternalinitialize();
    if(!ocglobalstate.rc.loaded)
	ocrc_load();
    /* Note, we still must do this function even if
       ocglobalstate.rc.ignore is set in order
       to getinfo e.g. user:pwd from url
    */

    url_userpwd = uri->userpwd;
    url_hostport = occombinehostport(uri);
    if(url_hostport == NULL)
	return OC_ENOMEM;

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

    if(
          (value = ocrc_lookup("HTTP.COOKIEFILE",url_hostport))
       || (value = ocrc_lookup("HTTP.COOKIE_FILE",url_hostport))
       || (value = ocrc_lookup("HTTP.COOKIEJAR",url_hostport))
       || (value = ocrc_lookup("HTTP.COOKIE_JAR",url_hostport))
      ) {
        state->curlflags.cookiejar = strdup(value);
        if(state->curlflags.cookiejar == NULL) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"HTTP.COOKIEJAR: %s", state->curlflags.cookiejar);
    }

    if((value = ocrc_lookup("HTTP.PROXY_SERVER",url_hostport)) != NULL) {
        stat = ocparseproxy(state,value);
        if(stat != OC_NOERR) goto done;
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"HTTP.PROXY_SERVER: %s", value);
    }

    if((value = ocrc_lookup("HTTP.SSL.VALIDATE",url_hostport)) != NULL) {
        if(atoi(value)) {
	    state->ssl.verifypeer = 1;
	    state->ssl.verifyhost = 1;
            if(ocdebug > 0)
                oclog(OCLOGNOTE,"HTTP.SSL.VALIDATE: %ld", 1);
	}
    }

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

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

    if((value = ocrc_lookup("HTTP.SSL.KEYPASSWORD",url_hostport)) != NULL) {
        state->ssl.keypasswd = strdup(value);
        if(state->ssl.keypasswd == NULL) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"HTTP.SSL.KEYPASSWORD: %s", state->ssl.keypasswd);
    }

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

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

    if((value = ocrc_lookup("HTTP.SSL.VERIFYPEER",url_hostport)) != NULL) {
        char* s = strdup(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,"HTTP.SSL.VERIFYPEER: %d", state->ssl.verifypeer);
	free(s);
    }

    if((value = ocrc_lookup("HTTP.NETRC",url_hostport)) != NULL) {
        if(state->curlflags.netrc != NULL)
	    free(state->curlflags.netrc);
        state->curlflags.netrc = strdup(value);
        if(state->curlflags.netrc == NULL) {stat = OC_ENOMEM; goto done;}
        if(ocdebug > 0)
            oclog(OCLOGNOTE,"HTTP.NETRC: %s", state->curlflags.netrc);
    }

    { /* Handle various cases for user + password */
	/* First, see if the user+pwd was in the original url */
	char* userpwd = NULL;
	char* user = NULL;
	char* pwd = NULL;
	if(url_userpwd != NULL)
	    userpwd = url_userpwd;
	else {
   	    user = ocrc_lookup("HTTP.CREDENTIALS.USER",url_hostport);
	    pwd = ocrc_lookup("HTTP.CREDENTIALS.PASSWORD",url_hostport);
	    userpwd = ocrc_lookup("HTTP.CREDENTIALS.USERPASSWORD",url_hostport);
	}
	if(userpwd == NULL && user != NULL && pwd != NULL) {
	    userpwd = combinecredentials(user,pwd);
	    state->creds.userpwd = userpwd;
	} else if(userpwd != NULL)
	    state->creds.userpwd = strdup(userpwd);
    }

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