char* makepathstring(NClist* path, const char* separator, int flags) { int i,len,first; NCbytes* pathname = NULL; char* result; CDFnode* node; len = nclistlength(path); ASSERT(len > 0); /* dataset at least */ if(len == 1) {/* dataset only */ node = (CDFnode*)nclistget(path,0); return nulldup(node->ncbasename); } pathname = ncbytesnew(); for(first=1,i=0;i<len;i++) { CDFnode* node = (CDFnode*)nclistget(path,i); char* name; if(!node->elided || (flags & PATHELIDE)==0) { if(node->nctype != NC_Dataset) { name = node->ncbasename; assert(name != NULL); if(!first) ncbytescat(pathname,separator); ncbytescat(pathname,name); first = 0; } } } result = ncbytesextract(pathname); ncbytesfree(pathname); return result; }
char* dcelisttostring(NClist* list, char* sep) { char* s; NCbytes* buf = ncbytesnew(); dcelisttobuffer(list,buf,sep); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
char* dcetostring(DCEnode* node) { char* s; NCbytes* buf = ncbytesnew(); dcetobuffer(node,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
char* dcerawlisttostring(NClist* list) { char* s; NCbytes* buf = ncbytesnew(); dcedumprawlist(list,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
/* Mostly for debugging */ char* dcerawtostring(void* node) { char* s; NCbytes* buf = ncbytesnew(); dcedumpraw((DCEnode*)node,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
/** * @internal Build _NCProperties attribute value. * * Convert a NCPROPINFO instance to a single string. * * @param info Properties info. * @param propdatap Pointer that gets properties string. * * @return ::NC_NOERR No error. * @return ::NC_EINVAL failed. * @author Dennis Heimbigner */ int NC4_buildpropinfo(struct NCPROPINFO* info, char** propdatap) { int stat = NC_NOERR; int i; NCbytes* buffer = NULL; char sversion[64]; LOG((3, "%s", __func__)); if(info == NULL || info->version == 0 || propdatap == NULL) {stat = NC_EINVAL; goto done;} *propdatap = NULL; buffer = ncbytesnew(); if(!buffer) {stat = NC_ENOMEM; goto done;} /* start with version */ ncbytescat(buffer,NCPVERSION); ncbytesappend(buffer,'='); snprintf(sversion,sizeof(sversion),"%d",info->version); ncbytescat(buffer,sversion); for(i=0;i<nclistlength(info->properties);i+=2) { char* value, *name; name = nclistget(info->properties,i); if(name == NULL) continue; value = nclistget(info->properties,i+1); ncbytesappend(buffer,NCPROPSSEP2); /* terminate last entry */ escapify(buffer,name); ncbytesappend(buffer,'='); escapify(buffer,value); } /* Force null termination */ ncbytesnull(buffer); *propdatap = ncbytesextract(buffer); done: if(buffer != NULL) ncbytesfree(buffer); return stat; }
char* makeocpathstring(OClink conn, OCddsnode node, const char* sep) { int i,len,first; char* result; char* name; OCtype octype; NClist* ocpath = NULL; NCbytes* pathname = NULL; /* If we are asking for the dataset path only, then include it, otherwise elide it */ oc_dds_type(conn,node,&octype); if(octype == OC_Dataset) { oc_dds_name(conn,node,&name); return nulldup(name); } ocpath = nclistnew(); collectocpath(conn,node,ocpath); len = nclistlength(ocpath); assert(len > 0); /* dataset at least */ pathname = ncbytesnew(); for(first=1,i=1;i<len;i++) { /* start at 1 to skip dataset name */ OCddsnode node = (OCddsnode)nclistget(ocpath,i); char* name; oc_dds_type(conn,node,&octype); oc_dds_name(conn,node,&name); if(!first) ncbytescat(pathname,sep); ncbytescat(pathname,name); nullfree(name); first = 0; } result = ncbytesextract(pathname); ncbytesfree(pathname); nclistfree(ocpath); return result; }
static int readfile(NCD4INFO* state, const NCURI* uri, const char* suffix, NCbytes* packet) { int stat = NC_NOERR; NCbytes* tmp = ncbytesnew(); char* filename = NULL; ncbytescat(tmp,uri->path); if(suffix != NULL) ncbytescat(tmp,suffix); ncbytesnull(tmp); filename = ncbytesextract(tmp); ncbytesfree(tmp); #ifdef HAVE_GETTIMEOFDAY struct timeval time0; struct timeval time1; #endif state->fileproto.filename = filename; /* filename is alloc'd here anyway */ if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { char* surl = NULL; #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time0,NULL); #endif surl = ncuribuild((NCURI*)uri,NULL,NULL,NCURIALL); nclog(NCLOGDBG,"fetch uri=%s file=%s",surl,filename); } stat = NC_readfile(filename,packet); if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { double secs; #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time1,NULL); secs = deltatime(time0,time1); #endif nclog(NCLOGDBG,"fetch complete: %0.3f",secs); } return THROW(stat); }
char* ncuribuild(NCURI* duri, const char* prefix, const char* suffix, int flags) { char* newuri = NULL; NCbytes* buf = ncbytesnew(); #ifdef NEWESCAPE const int encode = (flags&NCURIENCODE ? 1 : 0); #else const int encode = 0; #endif if(prefix != NULL) ncbytescat(buf,prefix); ncbytescat(buf,duri->protocol); ncbytescat(buf,"://"); /* this will produce file:///... */ if((flags & NCURIPWD) && duri->user != NULL && duri->password != NULL) { /* The user and password must be encoded */ char* encoded = ncuriencodeonly(duri->user,userpwdallow); ncbytescat(buf,encoded); nullfree(encoded); ncbytescat(buf,":"); encoded = ncuriencodeonly(duri->password,userpwdallow); ncbytescat(buf,encoded); nullfree(encoded); ncbytescat(buf,"@"); } if(duri->host != NULL) ncbytescat(buf,duri->host); if(duri->port != NULL) { ncbytescat(buf,":"); ncbytescat(buf,duri->port); } if((flags & NCURIPATH)) { if(duri->path == NULL) ncbytescat(buf,"/"); else if(encode) { char* encoded = ncuriencodeonly(duri->path,pathallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,duri->path); } /* The suffix is intended to some kind of path extension (e.g. .dds) so insert here */ if(suffix != NULL) ncbytescat(buf,suffix); if((flags & NCURIQUERY) && duri->querylist != NULL) { char** p; int first = 1; for(p=duri->querylist;*p;p+=2,first=0) { ncbytescat(buf,(first?"?":"&")); ncbytescat(buf,p[0]); if(p[1] != NULL && strlen(p[1]) > 0) { ncbytescat(buf,"="); if(encode) { char* encoded = ncuriencodeonly(p[1],queryallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,p[1]); } } } if((flags & NCURIFRAG) && duri->fraglist != NULL) { char** p; int first = 1; for(p=duri->fraglist;*p;p+=2,first=0) { ncbytescat(buf,(first?"#":"&")); ncbytescat(buf,p[0]); if(p[1] != NULL && strlen(p[1]) > 0) { ncbytescat(buf,"="); if(encode) { char* encoded = ncuriencodeonly(p[1],queryallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,p[1]); } } } ncbytesnull(buf); newuri = ncbytesextract(buf); ncbytesfree(buf); return newuri; }