NCerror freeNCDAPCOMMON(NCDAPCOMMON* dapcomm) { /* abort the metadata file */ (void)nc_abort(getncid(dapcomm)); freenccache(dapcomm,dapcomm->cdf.cache); nclistfree(dapcomm->cdf.projectedvars); nullfree(dapcomm->cdf.recorddimname); /* free the trees */ freecdfroot34(dapcomm->cdf.ddsroot); dapcomm->cdf.ddsroot = NULL; freecdfroot34(dapcomm->cdf.fullddsroot); dapcomm->cdf.fullddsroot = NULL; if(dapcomm->oc.ocdasroot != NULL) oc_root_free(dapcomm->oc.conn,dapcomm->oc.ocdasroot); dapcomm->oc.ocdasroot = NULL; oc_close(dapcomm->oc.conn); /* also reclaims remaining OC trees */ ncurifree(dapcomm->oc.url); nullfree(dapcomm->oc.urltext); nullfree(dapcomm->oc.rawurltext); dcefree((DCEnode*)dapcomm->oc.dapconstraint); dapcomm->oc.dapconstraint = NULL; free(dapcomm); return NC_NOERR; }
void freenccachenode(NCDAPCOMMON* nccomm, NCcachenode* node) { if(node == NULL) return; oc_data_free(nccomm->oc.conn,node->content); oc_data_free(nccomm->oc.conn,node->content); freencconstraint(node->constraint); freecdfroot34(node->datadds); nclistfree(node->vars); efree(node); }
void freenccachenode(NCDAPCOMMON* nccomm, NCcachenode* node) { if(node == NULL) return; oc_data_free(nccomm->oc.conn,node->content); #ifdef IGNORE oc_root_free(nccomm->oc.conn,node->ocroot); #endif dcefree((DCEnode*)node->constraint); freecdfroot34(node->datadds); nclistfree(node->vars); nullfree(node); }
void freenccachenode(NCDAPCOMMON* nccomm, NCcachenode* node) { if(node == NULL) return; #ifdef DEBUG fprintf(stderr,"freecachenode: %s\n", dumpcachenode(node)); #endif oc_data_free(nccomm->oc.conn,node->content); dcefree((DCEnode*)node->constraint); freecdfroot34(node->datadds); nclistfree(node->vars); nullfree(node); }
NCerror buildcachenode34(NCDAPCOMMON* nccomm, DCEconstraint* constraint, NClist* varlist, NCcachenode** cachep, NCFLAGS flags) { NCerror ncstat = NC_NOERR; OCerror ocstat = OC_NOERR; OClink conn = nccomm->oc.conn; OCddsnode ocroot = NULL; CDFnode* dxdroot = NULL; NCcachenode* cachenode = NULL; char* ce = NULL; int isprefetch = 0; if((flags & NCF_PREFETCH) != 0) isprefetch = 1; if((flags & NCF_PREFETCH_ALL) == 0) ce = buildconstraintstring3(constraint); ocstat = dap_fetch(nccomm,conn,ce,OCDATADDS,&ocroot); nullfree(ce); if(ocstat) {THROWCHK(ocerrtoncerr(ocstat)); goto done;} ncstat = buildcdftree34(nccomm,ocroot,OCDATA,&dxdroot); if(ncstat) {THROWCHK(ncstat); goto done;} /* re-struct*/ if(!FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) { ncstat = restruct3(dxdroot,nccomm->cdf.ddsroot,constraint->projections); if(ncstat) {THROWCHK(ncstat); goto done;} } /* create the cache node */ cachenode = createnccachenode(); cachenode->isprefetch = isprefetch; cachenode->vars = nclistclone(varlist); cachenode->datadds = dxdroot; /* Give the constraint over to the cachenode */ cachenode->constraint = constraint; constraint = NULL; cachenode->wholevariable = iscacheableconstraint(cachenode->constraint); /* save the root content*/ cachenode->ocroot = ocroot; ocstat = oc_data_getroot(conn,ocroot,&cachenode->content); if(ocstat) {THROWCHK(ocerrtoncerr(ocstat)); goto done;} /* capture the packet size */ ocstat = oc_raw_xdrsize(conn,ocroot,&cachenode->xdrsize); if(ocstat) {THROWCHK(ocerrtoncerr(ocstat)); goto done;} #ifdef DEBUG fprintf(stderr,"buildcachenode: new cache node: %s\n", dumpcachenode(cachenode)); #endif /* Insert into the cache. If not caching, then remove any previous cache node */ if(!isprefetch) { NCcache* cache = nccomm->cdf.cache; if(cache->nodes == NULL) cache->nodes = nclistnew(); /* remove cache nodes to get below the max cache size */ while(cache->cachesize + cachenode->xdrsize > cache->cachelimit && nclistlength(cache->nodes) > 0) { NCcachenode* node = (NCcachenode*)nclistremove(cache->nodes,0); #ifdef DEBUG fprintf(stderr,"buildcachenode: purge cache node: %s\n", dumpcachenode(cachenode)); #endif cache->cachesize -= node->xdrsize; freenccachenode(nccomm,node); } /* Remove cache nodes to get below the max cache count */ /* If not caching, then cachecount should be 0 */ while(nclistlength(cache->nodes) > cache->cachecount) { NCcachenode* node = (NCcachenode*)nclistremove(cache->nodes,0); #ifdef DEBUG fprintf(stderr,"buildcachenode: count purge cache node: %s\n", dumpcachenode(node)); #endif cache->cachesize -= node->xdrsize; freenccachenode(nccomm,node); } nclistpush(nccomm->cdf.cache->nodes,(void*)cachenode); cache->cachesize += cachenode->xdrsize; } #ifdef DEBUG fprintf(stderr,"buildcachenode: %s\n",dumpcachenode(cachenode)); #endif done: if(constraint != NULL) dcefree((DCEnode*)constraint); if(cachep) *cachep = cachenode; if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); if(ncstat) { freecdfroot34(dxdroot); freenccachenode(nccomm,cachenode); } return THROW(ncstat); }
static NCerror getseqdimsize(NCDAPCOMMON* dapcomm, CDFnode* seq, size_t* sizep) { NCerror ncstat = NC_NOERR; OCerror ocstat = OC_NOERR; OClink conn = dapcomm->oc.conn; OCdatanode rootcontent = NULL; OCddsnode ocroot; CDFnode* dxdroot; CDFnode* xseq; NCbytes* seqcountconstraints = ncbytesnew(); size_t seqsize; /* Read the minimal amount of data in order to get the count */ /* If the url is unconstrainable, then get the whole thing */ computeseqcountconstraints3(dapcomm,seq,seqcountconstraints); #ifdef DEBUG fprintf(stderr,"seqcountconstraints: %s\n",ncbytescontents(seqcountconstraints)); #endif /* Fetch the minimal data */ if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) ocstat = dap_fetch(dapcomm,conn,NULL,OCDATADDS,&ocroot); else ocstat = dap_fetch(dapcomm,conn,ncbytescontents(seqcountconstraints),OCDATADDS,&ocroot); if(ocstat) goto fail; ncstat = buildcdftree34(dapcomm,ocroot,OCDATA,&dxdroot); if(ncstat) goto fail; /* attach DATADDS to DDS */ ncstat = attach34(dxdroot,seq); if(ncstat) goto fail; /* WARNING: we are now switching to datadds tree */ xseq = seq->attachment; ncstat = countsequence(dapcomm,xseq,&seqsize); if(ncstat) goto fail; #ifdef DEBUG fprintf(stderr,"sequencesize: %s = %lu\n",seq->ocname,(unsigned long)seqsize); #endif /* throw away the fetch'd trees */ unattach34(dapcomm->cdf.ddsroot); freecdfroot34(dxdroot); if(ncstat != NC_NOERR) { /* Cannot get DATADDDS*/ char* code; char* msg; long httperr; oc_svcerrordata(dapcomm->oc.conn,&code,&msg,&httperr); if(code != NULL) { nclog(NCLOGERR,"oc_fetch_datadds failed: %s %s %l", code,msg,httperr); } ocstat = OC_NOERR; } if(sizep) *sizep = seqsize; fail: ncbytesfree(seqcountconstraints); oc_data_free(conn,rootcontent); if(ocstat) ncstat = ocerrtoncerr(ocstat); return ncstat; }