void occlose(OCstate* state) { unsigned int i; if(state == NULL) return; /* Warning: ocfreeroot will attempt to remove the root from state->trees */ /* Ok in this case because we are popping the root out of state->trees */ for(i=0;i<oclistlength(state->trees);i++) { OCnode* root = (OCnode*)oclistpop(state->trees); ocfreeroot(root); } oclistfree(state->trees); dapurlclear(&state->url); ocbytesfree(state->packet); ocfree(state->error.code); ocfree(state->error.message); if(state->contentlist != NULL) { struct OCcontent* next; struct OCcontent* curr = state->contentlist; while(curr != NULL) { next = curr->next; ocfree(curr); curr = next; } } if(state->curl != NULL) occurlclose(state->curl); if(state->clientparams != NULL) ocparamfree(state->clientparams); ocfree(state); }
void occlose(OCstate* state) { unsigned int i; if(state == NULL) return; /* Warning: ocfreeroot will attempt to remove the root from state->trees */ /* Ok in this case because we are popping the root out of state->trees */ for(i=0;i<oclistlength(state->trees);i++) { OCnode* root = (OCnode*)oclistpop(state->trees); ocroot_free(root); } oclistfree(state->trees); ocurifree(state->uri); ocbytesfree(state->packet); ocfree(state->error.code); ocfree(state->error.message); ocfree(state->curlflags.useragent); if(state->curlflags.cookiejar) { unlink(state->curlflags.cookiejar); ocfree(state->curlflags.cookiejar); } ocfree(state->ssl.certificate); ocfree(state->ssl.key); ocfree(state->ssl.keypasswd); ocfree(state->ssl.cainfo); ocfree(state->ssl.capath); ocfree(state->proxy.host); ocfree(state->creds.username); ocfree(state->creds.password); if(state->curl != NULL) occurlclose(state->curl); ocfree(state); }
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; DAPURL tmpurl; CURL* curl = NULL; /* curl handle*/ memset((void*)&tmpurl,0,sizeof(tmpurl)); if(!dapurlparse(url,&tmpurl)) {THROWCHK(stat=OC_EBADURL); goto fail;} stat = occurlopen(&curl); if(stat != OC_NOERR) {THROWCHK(stat); goto fail;} state = (OCstate*)ocmalloc(sizeof(OCstate)); /* ocmalloc zeros memory*/ if(state == NULL) {THROWCHK(stat=OC_ENOMEM); goto fail;} /* Setup DAP state*/ state->magic = OCMAGIC; state->curl = curl; state->trees = oclistnew(); state->contentlist = NULL; state->url = tmpurl; state->clientparams = ocparamdecode(state->url.params); if(state->clientparams == NULL) { 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); if(statep) *statep = state; return THROW(stat); fail: dapurlclear(&tmpurl); if(state != NULL) ocfree(state); if(curl != NULL) occurlclose(curl); return THROW(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); }