static int readpacket(CURL* curl,DAPURL* url,OCbytes* packet,OCdxd dxd,long* lastmodified) { int stat; int fileprotocol = 0; char* suffix = ocdxdextension[dxd]; fileprotocol = (strncmp(url->base,"file:",5)==0); if(fileprotocol && !oc_curl_file_supported) { /* Short circuit file://... urls*/ /* We do this because the test code always needs to read files*/ stat = readfile(url->base,suffix,packet); } else { char* fetchurl = dapurlgeturl(url,NULL,suffix,!fileprotocol); MEMCHECK(fetchurl,OC_ENOMEM); if(ocdebug > 0) {fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);} stat = ocfetchurl(curl,fetchurl,packet,lastmodified); if(ocdebug > 0) {fprintf(stderr,"fetch complete\n"); fflush(stderr);} free(fetchurl); } return THROW(stat); }
static int readpacket(OCstate* state, OCURI* url,OCbytes* packet,OCdxd dxd,long* lastmodified) { int stat = OC_NOERR; int fileprotocol = 0; const char* suffix = ocdxdextension(dxd); char* fetchurl = NULL; CURL* curl = state->curl; fileprotocol = (strcmp(url->protocol,"file")==0); if(fileprotocol && !state->curlflags.proto_file) { /* Short circuit file://... urls*/ /* We do this because the test code always needs to read files*/ fetchurl = ocuribuild(url,NULL,NULL,0); stat = readfile(fetchurl,suffix,packet); } else { int flags = 0; if(!fileprotocol) { flags |= OCURICONSTRAINTS; } flags |= OCURIENCODE; fetchurl = ocuribuild(url,NULL,suffix,flags); MEMCHECK(fetchurl,OC_ENOMEM); if(ocdebug > 0) {fprintf(stderr,"fetch url=%s\n",fetchurl); fflush(stderr);} stat = ocfetchurl(curl,fetchurl,packet,lastmodified,&state->creds); if(stat) oc_curl_printerror(state); if(ocdebug > 0) {fprintf(stderr,"fetch complete\n"); fflush(stderr);} } free(fetchurl); #ifdef OCDEBUG { fprintf(stderr,"readpacket: packet.size=%lu\n", (unsigned long)ocbyteslength(packet)); } #endif return OCTHROW(stat); }