static OCerror ocextract_credentials(const char *url, char **userpwd, char **result_url) { OCURI* parsed = NULL; if(!ocuriparse(url,&parsed)) return OCTHROW(OC_EBADURL); if(parsed->userpwd == NULL) { ocurifree(parsed); return OCTHROW(OC_EBADURL); } if(userpwd) *userpwd = strdup(parsed->userpwd); ocurifree(parsed); return OC_NOERR; }
OCerror ocopen(OCstate** statep, const char* url) { int stat = OC_NOERR; OCstate * state = NULL; OCURI* tmpurl = NULL; CURL* curl = NULL; /* curl handle*/ if(!ocuriparse(url,&tmpurl)) {OCTHROWCHK(stat=OC_EBADURL); goto fail;} stat = occurlopen(&curl); if(stat != OC_NOERR) {OCTHROWCHK(stat); goto fail;} state = (OCstate*)ocmalloc(sizeof(OCstate)); /* ocmalloc zeros memory*/ if(state == NULL) {OCTHROWCHK(stat=OC_ENOMEM); goto fail;} /* Setup DAP state*/ state->header.magic = OCMAGIC; state->header.occlass = OC_State; state->curl = curl; state->trees = oclistnew(); state->uri = tmpurl; if(!ocuridecodeparams(state->uri)) { oclog(OCLOGWARN,"Could not parse client parameters"); } state->packet = ocbytesnew(); ocbytessetalloc(state->packet,DFALTPACKETSIZE); /*initial reasonable size*/ /* capture curl properties for this link from rc file1*/ stat = ocset_curlproperties(state); if(stat != OC_NOERR) goto fail; /* Set the one-time curl flags */ if((stat=ocset_flags_perlink(state))!= OC_NOERR) goto fail; #if 1 /* temporarily make per-link */ if((stat=ocset_flags_perfetch(state))!= OC_NOERR) goto fail; #endif if(statep) *statep = state; else { if(state != NULL) ocfree(state); } return OCTHROW(stat); fail: ocurifree(tmpurl); if(state != NULL) ocfree(state); if(curl != NULL) occurlclose(curl); return OCTHROW(stat); }
OCerror ocopen(OCstate** statep, const char* url) { int stat = OC_NOERR; OCstate * state = NULL; OCURI* tmpurl = NULL; CURL* curl = NULL; /* curl handle*/ if(!ocuriparse(url,&tmpurl)) {OCTHROWCHK(stat=OC_EBADURL); goto fail;} stat = occurlopen(&curl); if(stat != OC_NOERR) {OCTHROWCHK(stat); goto fail;} state = (OCstate*)ocmalloc(sizeof(OCstate)); /* ocmalloc zeros memory*/ if(state == NULL) {OCTHROWCHK(stat=OC_ENOMEM); goto fail;} /* Setup DAP state*/ state->magic = OCMAGIC; state->curl = curl; state->trees = oclistnew(); state->uri = tmpurl; if(!ocuridecodeparams(state->uri)) { oc_log(LOGWARN,"Could not parse client parameters"); } state->packet = ocbytesnew(); ocbytessetalloc(state->packet,DFALTPACKETSIZE); /*initial reasonable size*/ /* set curl properties for this link */ ocsetcurlproperties(state); /* Set up list to support reuse/reclamation of OCcontent objects. */ state->contentlist = NULL; if(statep) *statep = state; return OCTHROW(stat); fail: ocurifree(tmpurl); if(state != NULL) ocfree(state); if(curl != NULL) occurlclose(curl); return OCTHROW(stat); }
/* Create a triple store from a file */ static int ocrc_compile(const char* path) { char line0[MAXRCLINESIZE+1]; FILE *in_file = NULL; int linecount = 0; struct OCTriplestore* ocrc = &ocglobalstate.rc.daprc; ocrc->ntriples = 0; /* reset; nothing to free */ in_file = fopen(path, "r"); /* Open the file to read it */ if (in_file == NULL) { oclog(OCLOGERR, "Could not open configuration file: %s",path); return OC_EPERM; } for(;;) { char *line,*key,*value; int c; if(!rcreadline(in_file,line0,sizeof(line0))) break; linecount++; if(linecount >= MAXRCLINES) { oclog(OCLOGERR, ".rc has too many lines"); return 0; } line = line0; /* check for comment */ c = line[0]; if (c == '#') continue; rctrim(line); /* trim leading and trailing blanks */ if(strlen(line) == 0) continue; if(strlen(line) >= MAXRCLINESIZE) { oclog(OCLOGERR, "%s line too long: %s",path,line0); return 0; } /* setup */ ocrc->triples[ocrc->ntriples].host[0] = '\0'; ocrc->triples[ocrc->ntriples].key[0] = '\0'; ocrc->triples[ocrc->ntriples].value[0] = '\0'; if(line[0] == LTAG) { OCURI* uri; char* url = ++line; char* rtag = strchr(line,RTAG); if(rtag == NULL) { oclog(OCLOGERR, "Malformed [url] in %s entry: %s",path,line); continue; } line = rtag + 1; *rtag = '\0'; /* compile the url and pull out the host */ if(!ocuriparse(url,&uri)) { oclog(OCLOGERR, "Malformed [url] in %s entry: %s",path,line); continue; } strncpy(ocrc->triples[ocrc->ntriples].host,uri->host,MAXRCLINESIZE-1); if(uri->port != NULL) { strncat(ocrc->triples[ocrc->ntriples].host,":",MAXRCLINESIZE-1); strncat(ocrc->triples[ocrc->ntriples].host,uri->port,MAXRCLINESIZE-1); } ocurifree(uri); } /* split off key and value */ key=line; value = strchr(line, '='); if(value == NULL) value = line + strlen(line); else { *value = '\0'; value++; } strncpy(ocrc->triples[ocrc->ntriples].key,key,MAXRCLINESIZE); if(*value == '\0') strcpy(ocrc->triples[ocrc->ntriples].value,"1");/*dfalt*/ else strncpy(ocrc->triples[ocrc->ntriples].value,value,(MAXRCLINESIZE-1)); rctrim( ocrc->triples[ocrc->ntriples].key); rctrim( ocrc->triples[ocrc->ntriples].value); OCDBG2("rc: key=%s value=%s", ocrc->triples[ocrc->ntriples].key, ocrc->triples[ocrc->ntriples].value); ocrc->ntriples++; } fclose(in_file); sorttriplestore(&ocglobalstate.rc.daprc); return 1; }