/* 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; }
int ocparseproxy(OCstate* state, char* v) { /* Do not free these; they are pointers into v; free v instead */ char *host_pos = NULL; char *port_pos = NULL; if(v == NULL || strlen(v) == 0) return OC_NOERR; /* nothing there*/ if (occredentials_in_url(v)) { char *result_url = NULL; ocextract_credentials(v, &state->proxy.userpwd, &result_url); v = result_url; } /* allocating a bit more than likely needed ... */ host_pos = strstr(v, "http://"); if (host_pos) host_pos += strlen("http://"); else host_pos = v; port_pos = strchr(host_pos, ':'); if (port_pos) { size_t host_len; char *port_sep = port_pos; port_pos++; *port_sep = '\0'; host_len = strlen(host_pos); state->proxy.host = malloc(sizeof(char) * host_len + 1); if (state->proxy.host == NULL) return OCTHROW(OC_ENOMEM); strncpy(state->proxy.host, host_pos, host_len); state->proxy.host[host_len] = '\0'; state->proxy.port = atoi(port_pos); } else { size_t host_len = strlen(host_pos); state->proxy.host = malloc(sizeof(char) * host_len + 1); if (state->proxy.host == NULL) return OCTHROW(OC_ENOMEM); strncpy(state->proxy.host, host_pos, host_len); state->proxy.host[host_len] = '\0'; state->proxy.port = 80; } #if 0 state->proxy.host[v_len] = '\0'; state->proxy.port = atoi(v); s_len = strlen(v); state->proxy.user = malloc(sizeof(char) * s_len + 1); if (state->proxy.user == NULL) return OC_ENOMEM; strncpy(state->proxy.user, v, s_len); state->proxy.user[s_len] = '\0'; p_len = strlen(v); state->proxy.password = malloc(sizeof(char) * p_len + 1); if (state->proxy.password == NULL) return OCTHROW(OC_ENOMEM); strncpy(state->proxy.password, v, p_len); state->proxy.password[p_len] = '\0'; #endif /*0*/ if (ocdebug > 1) { oclog(OCLOGNOTE,"host name: %s", state->proxy.host); #ifdef INSECURE oclog(OCLOGNOTE,"user+pwd: %s", state->proxy.userpwd); #endif oclog(OCLOGNOTE,"port number: %d", state->proxy.port); } if(v) free(v); return OC_NOERR; }
static int parseproxy(OCstate* state, char* v) { char *host_pos = NULL; char *port_pos = NULL; if(strlen(v) == 0) return OC_NOERR; /* nothing there*/ if (occredentials_in_url(v)) { char *result_url = NULL; ocextract_credentials(v, &state->creds.username, &state->creds.password, &result_url); v = result_url; } /* allocating a bit more than likely needed ... */ host_pos = strstr(v, "http://"); if (host_pos) host_pos += strlen("http://"); else host_pos = v; port_pos = strchr(host_pos, ':'); if (port_pos) { int host_len; char *port_sep = port_pos; port_pos++; *port_sep = '\0'; host_len = strlen(host_pos); state->proxy.host = malloc(sizeof(char) * host_len + 1); if (!state->proxy.host) return OC_ENOMEM; strncpy(state->proxy.host, host_pos, host_len); state->proxy.host[host_len + 1] = '\0'; state->proxy.port = atoi(port_pos); } else { int host_len = strlen(host_pos); state->proxy.host = malloc(sizeof(char) * host_len + 1); if (!state->proxy.host) return OC_ENOMEM; strncpy(state->proxy.host, host_pos, host_len); state->proxy.host[host_len + 1] = '\0'; state->proxy.port = 80; } #if 0 state->proxy.host[v_len] = '\0'; state->proxy.port = atoi(v); s_len = strlen(v); state->proxy.user = malloc(sizeof(char) * s_len + 1); if (!state->proxy.user) return OC_ENOMEM; strncpy(state->proxy.user, v, s_len); state->proxy.user[s_len] = '\0'; p_len = strlen(v); state->proxy.password = malloc(sizeof(char) * p_len + 1); if (!state->proxy.password) return OC_ENOMEM; strncpy(state->proxy.password, v, p_len); state->proxy.password[p_len] = '\0'; #endif /*0*/ if (ocdebug > 1) { oc_log(LOGNOTE,"host name: %s", state->proxy.host); oc_log(LOGNOTE,"user name: %s", state->creds.username); #ifdef INSECURE oc_log(LOGNOTE,"password: %s", state->creds.password); #endif oc_log(LOGNOTE,"port number: %d", state->proxy.port); } if(v) free(v); return OC_NOERR; }