BOOL CALLBACK InfoDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { HWND hDlg; HDC hdcDlg; switch(Message) { case WM_CTLCOLORDLG: hdcDlg=(HDC)wParam; hDlg=(HWND)lParam; return (LONG)hBackground; break; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_BUTTON1: //Snooze button nclog(L"Button1 clicked\n"); stopBeeper(); resetIdleThread(); //MessageBox(hwnd, L"Hi!", L"This is a message", MB_OK | MB_ICONEXCLAMATION); break; case ID_BUTTON2: nclog(L"Button2 clicked\n"); ShowWindow(hDlgInfo, SW_HIDE); bInfoDlgVisible=FALSE; //MessageBox(hwnd, L"Bye!", L"This is also a message", MB_OK | MB_ICONEXCLAMATION); break; } break; default: return FALSE; } return TRUE; }
NCerror fetchtemplatemetadata3(NCDAPCOMMON* dapcomm) { NCerror ncstat = NC_NOERR; OCerror ocstat = OC_NOERR; OCddsnode ocroot = NULL; CDFnode* ddsroot = NULL; char* ce = NULL; /* Temporary hack: we need to get the selection string from the url */ /* Get (almost) unconstrained DDS; In order to handle functions correctly, those selections must always be included */ if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) ce = NULL; else ce = nulldup(dapcomm->oc.url->selection); /* Get selection constrained DDS */ ocstat = dap_fetch(dapcomm,dapcomm->oc.conn,ce,OCDDS,&ocroot); if(ocstat != OC_NOERR) { /* Special Hack. If the protocol is file, then see if we can get the dds from the .dods file */ if(strcmp(dapcomm->oc.url->protocol,"file") != 0) { THROWCHK(ocstat); goto done; } /* Fetch the data dds */ ocstat = dap_fetch(dapcomm,dapcomm->oc.conn,ce,OCDATADDS,&ocroot); if(ocstat != OC_NOERR) { THROWCHK(ocstat); goto done; } /* Note what we did */ nclog(NCLOGWARN,"Cannot locate .dds file, using .dods file"); } /* Get selection constrained DAS */ ocstat = dap_fetch(dapcomm,dapcomm->oc.conn,ce,OCDAS,&dapcomm->oc.ocdasroot); if(ocstat != OC_NOERR) { /* Ignore but complain */ nclog(NCLOGWARN,"Could not read DAS; ignored"); dapcomm->oc.ocdasroot = NULL; ocstat = OC_NOERR; } /* Construct the netcdf cdf tree corresponding to the dds tree*/ ncstat = buildcdftree34(dapcomm,ocroot,OCDDS,&ddsroot); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} dapcomm->cdf.fullddsroot = ddsroot; done: nullfree(ce); if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); return ncstat; }
static int readpacket(NCD4INFO* state, NCURI* url, NCbytes* packet, NCD4mode dxx, long* lastmodified) { int stat = NC_NOERR; int fileprotocol = 0; const char* suffix = dxxextension(dxx); CURL* curl = state->curl->curl; #ifdef HAVE_GETTIMEOFDAY struct timeval time0; struct timeval time1; #endif fileprotocol = (strcmp(url->protocol,"file")==0); if(fileprotocol) { /* Short circuit file://... urls*/ /* We do this because the test code always needs to read files*/ stat = readfile(state, url,suffix,packet); } else { char* fetchurl = NULL; int flags = NCURIBASE; if(!fileprotocol) flags |= NCURIQUERY; flags |= NCURIENCODE; fetchurl = ncuribuild(url,NULL,suffix,flags); MEMCHECK(fetchurl); if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { nclog(NCLOGDBG,"fetch url=%s",fetchurl); #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time0,NULL); #endif } stat = NCD4_fetchurl(curl,fetchurl,packet,lastmodified); nullfree(fetchurl); if(stat) goto fail; if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { double secs = 0; #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time1,NULL); secs = deltatime(time0,time1); #endif nclog(NCLOGDBG,"fetch complete: %0.3f",secs); } } #ifdef D4DEBUG { fprintf(stderr,"readpacket: packet.size=%lu\n", (unsigned long)ncbyteslength(packet)); } #endif fail: return THROW(stat); }
/* Parse incoming url constraints, if any, to check for syntactic correctness */ NCerror parsedapconstraints(NCDAPCOMMON* dapcomm, char* constraints, DCEconstraint* dceconstraint) { NCerror ncstat = NC_NOERR; char* errmsg; ASSERT(dceconstraint != NULL); nclistclear(dceconstraint->projections); nclistclear(dceconstraint->selections); ncstat = dapceparse(constraints,dceconstraint,&errmsg); if(ncstat) { nclog(NCLOGWARN,"DCE constraint parse failure: %s",errmsg); nullfree(errmsg); nclistclear(dceconstraint->projections); nclistclear(dceconstraint->selections); } else { #ifdef IGNORE int i; #ifdef DEBUG NClist* allnodes; fprintf(stderr,"constraint: %s",dumpconstraint(dceconstraint)); #endif /* Go thru each node and add annotation */ allnodes = dceallnodes((DCEnode*)dceconstraint,CES_NIL); for(i=0;i<nclistlength(allnodes);i++) { DCEnode* node = (DCEnode*)nclistget(allnodes,i); } #endif } return ncstat; }
void ShowError(LONG er) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, er, 0, // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); TCHAR temp[MAX_PATH]; wsprintf(temp, (LPTSTR)lpMsgBuf); // Process any inserts in lpMsgBuf. // ... #ifdef DEBUG DEBUGMSG( 1, ( temp ) ); nclog(temp); #else // Display the string. MessageBox( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONINFORMATION ); #endif // Free the buffer. LocalFree( lpMsgBuf ); }
/** @param ncclass - type class for which alignment is requested; excludes ENUM|COMPOUND */ EXTERNL size_t ncaux_class_alignment(int ncclass) { if(ncclass <= NC_MAX_ATOMIC_TYPE || ncclass == NC_VLEN || ncclass == NC_OPAQUE) return NC_class_alignment(ncclass); nclog(NCLOGERR,"ncaux_class_alignment: class %d; alignment cannot be determermined",ncclass); return 0; }
~_nclog_module() { if (wsa_socket!=INVALID_SOCKET) { nclog(L"nclog goes down\n"); shutdown(wsa_socket,2); closesocket(wsa_socket); } }
~_nclog_module() { #ifdef USEWINSOCK if (wsa_socket!=INVALID_SOCKET) { nclog(L"nclog goes down\n"); shutdown(wsa_socket,2); closesocket(wsa_socket); } #endif }
static void setdefaults(NCauth* auth) { int ret = NC_NOERR; const char** p; for(p=AUTHDEFAULTS;*p;p+=2) { ret = setauthfield(auth,p[0],p[1]); if(ret) { nclog(NCLOGERR, "RC file defaulting failed for: %s=%s",p[0],p[1]); } } }
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { NCbytes* buf = data; size_t realsize = size * nmemb; Trace("WriteMemoryCallback"); if(realsize == 0) nclog(NCLOGWARN,"WriteMemoryCallback: zero sized chunk"); ncbytesappendn(buf, ptr, realsize); return realsize; }
//====================================================================== // Look for windows starting with "Installing... or "Setup ..." and let them come to front int ListWindows() { getProcList(); DEBUGMSG(1, (L"Window List\nnr\thwnd\tprocID\tprocName\tclass\ttitle\tpos/size\tstate\n")); nclog(L"Window List\nthis\tnr\thwnd\tprocID\tprocName\tclass\ttitle\tpos/size\tstate\n"); int iLevel=0; EnumWindows(procEnumWindows, iLevel); return 0; }
static size_t HeaderCallback(char *buffer, size_t size, size_t nitems, void *data) { NClist* list = data; size_t realsize = size * nitems; char* name = NULL; char* value = NULL; char* p = NULL; size_t i; int havecolon; Trace("HeaderCallback"); if(realsize == 0) nclog(NCLOGWARN,"HeaderCallback: zero sized chunk"); i = 0; /* Look for colon separator */ for(p=buffer;(i < realsize) && (*p != ':');p++,i++); havecolon = (i < realsize); if(i == 0) nclog(NCLOGWARN,"HeaderCallback: malformed header: %s",buffer); name = malloc(i+1); memcpy(name,buffer,i); name[i] = '\0'; value = NULL; if(havecolon) { size_t vlen = (realsize - i); value = malloc(vlen+1); p++; /* skip colon */ memcpy(value,p,vlen); value[vlen] = '\0'; trim(value); } nclistpush(list,name); name = NULL; if(value == NULL) value = strdup(""); nclistpush(list,value); value = NULL; return realsize; }
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); }
/* Report a conflicting model field assignment; see the conflictset macro above */ static int conflictfail(enum mfield f, int dst, int src) { const char* sf = NULL; switch (f) { case MF: sf = "format"; break; case MI: sf = "impl"; break; case MIO: sf = "iosp"; break; case MV: sf = "version"; break; default: sf = "?"; break; } nclog(NCLOGERR,"Model inference conflict: field=%s dst=%d src=%d", sf,dst,src); return NC_EINVAL; }
DWORD msgThread(LPVOID lpParam){ HWND hWnd = (HWND)lpParam; hwndMsg=hWnd; DEBUGMSG(1,(L"Waiting for Bluetooth notifications with hwnd=%i...\n", hWnd)); nclog(L"%s: Waiting for Bluetooth notifications...\n", logDateTime()); TCHAR szMsg[MAX_PATH]; wsprintf(szMsg, L"\r\n%s: Waiting for Bluetooth notifications...", logDateTime()); printMsg(szMsg, hWnd); BTEVENT btEvent; DWORD dwBytesRead; DWORD dwFlags; BOOL fRet; while (FALSE == bStop) { DWORD dwWait = WaitForSingleObject (hMsgQ, 5000);//wait up to 5 seconds INFINITE); switch (dwWait){ case WAIT_OBJECT_0: // We have got a Bluetooth event! dwFlags = 0; dwBytesRead = 0; fRet = ReadMsgQueue (hMsgQ, &btEvent, sizeof(BTEVENT), &dwBytesRead, 10, &dwFlags); if (! fRet) { DEBUGMSG(1,(L"Error - Failed to read message from queue!\n")); //bStop=TRUE; } else { dumpBTevent(btEvent, hWnd); } break; case WAIT_TIMEOUT: break; case WAIT_ABANDONED: DEBUGMSG(1,(L"Error - Unexpected return value from WaitForSingleObject!\n")); //bStop=TRUE; break; case WAIT_FAILED: DEBUGMSG(1,(L"Error - Unexpected return value from WaitForSingleObject!\n")); //bStop=TRUE; break; }//switch }//while return 0; }
void startMsgQueue(HWND hWnd){ DEBUGMSG(1, (L"Entering msgQueue with hwnd=%i\n", hWnd)); MSGQUEUEOPTIONS mqOptions; memset (&mqOptions, 0, sizeof(mqOptions)); mqOptions.dwFlags = 0; mqOptions.dwSize = sizeof(mqOptions); mqOptions.dwMaxMessages = 10; mqOptions.cbMaxMessage = sizeof(BTEVENT); mqOptions.bReadAccess = TRUE; hMsgQ = CreateMsgQueue(NULL, &mqOptions); if (! hMsgQ) { nclog(L"Error creating message queue.\n"); goto exit; } hBTNotif = RequestBluetoothNotifications( BTE_CLASS_CONNECTIONS | BTE_CONNECTION | BTE_DISCONNECTION | BTE_ROLE_SWITCH | BTE_MODE_CHANGE | BTE_PAGE_TIMEOUT | BTE_CONNECTION_AUTH_FAILURE | BTE_CLASS_PAIRING | BTE_KEY_NOTIFY | BTE_KEY_REVOKED | BTE_CLASS_DEVICE | BTE_LOCAL_NAME | BTE_COD | BTE_CLASS_STACK | BTE_STACK_UP | BTE_STACK_DOWN , hMsgQ); bStop=FALSE; CreateThread(NULL, 0, msgThread, hWnd, 0, &threadID); exit: ; }
//====================================================================== BOOL CALLBACK procEnumWindows(HWND hwnd, LPARAM lParam) //find window for PID { // LONG_PTR iLevel = lParam; //change iLevel++; TCHAR caption[MAX_PATH]; TCHAR classname[MAX_PATH]; TCHAR procname[MAX_PATH]; TCHAR* szName; szName = (TCHAR*)malloc (MAX_PATH); GetClassName(hwnd, classname, MAX_PATH); //hack as it hangs for "Button" if(wcscmp(classname,L"Button")==0){ wsprintf(caption, L""); } else{ if ( GetWindowTextLength(hwnd)>0 ) GetWindowText(hwnd, caption, MAX_PATH); else wsprintf(caption, L""); } DWORD dwProcID=0; GetWindowThreadProcessId(hwnd, &dwProcID); //dimensions and position RECT rect; GetWindowRect(hwnd, &rect); TCHAR szRect[64]; wsprintf(szRect, L"%i;%i/%i;%i (%ix%i)", rect.left, rect.top, rect.right, rect.bottom, rect.right-rect.left, rect.bottom-rect.top); ////visible?, MINIMIZED not supported DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); TCHAR szStyle[64]; wsprintf(szStyle, L"[%s]", dwStyle&WS_VISIBLE ? L"visible":L"hidden" ); wsprintf(procname, L"%s", getProcessName(dwProcID, szName)); DEBUGMSG(1, (L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle)); nclog(L"%i\t0x%08x\t0x%08x\t('%s')\t'%s'\t'%s'\t%s\t%s\n", iLevel, hwnd, dwProcID, procname, classname, caption, szRect, szStyle); free(szName); //return FALSE; // to stop iteration before end of window list return true; }
/* Parse incoming url constraints, if any, to check for syntactic correctness */ NCerror parsedapconstraints(NCDAPCOMMON* dapcomm, char* constraints, DCEconstraint* dceconstraint) { NCerror ncstat = NC_NOERR; char* errmsg; ASSERT(dceconstraint != NULL); nclistclear(dceconstraint->projections); nclistclear(dceconstraint->selections); ncstat = dapceparse(constraints,dceconstraint,&errmsg); if(ncstat) { nclog(NCLOGWARN,"DCE constraint parse failure: %s",errmsg); nullfree(errmsg); nclistclear(dceconstraint->projections); nclistclear(dceconstraint->selections); } return ncstat; }
void applyclientparamcontrols3(NCDAPCOMMON* dapcomm) { /* clear the flags */ CLRFLAG(dapcomm->controls,NCF_CACHE); CLRFLAG(dapcomm->controls,NCF_SHOWFETCH); CLRFLAG(dapcomm->controls,NCF_NC3); CLRFLAG(dapcomm->controls,NCF_NCDAP); CLRFLAG(dapcomm->controls,NCF_PREFETCH); CLRFLAG(dapcomm->controls,NCF_PREFETCH_EAGER); /* Turn on any default on flags */ SETFLAG(dapcomm->controls,DFALT_ON_FLAGS); SETFLAG(dapcomm->controls,(NCF_NC3|NCF_NCDAP)); /* enable/disable caching */ if(paramcheck34(dapcomm,"cache",NULL)) SETFLAG(dapcomm->controls,NCF_CACHE); else if(paramcheck34(dapcomm,"nocache",NULL)) CLRFLAG(dapcomm->controls,NCF_CACHE); /* enable/disable cache prefetch and lazy vs eager*/ if(paramcheck34(dapcomm,"prefetch","eager")) { SETFLAG(dapcomm->controls,NCF_PREFETCH); SETFLAG(dapcomm->controls,NCF_PREFETCH_EAGER); } else if(paramcheck34(dapcomm,"prefetch","lazy") || paramcheck34(dapcomm,"prefetch",NULL)) { SETFLAG(dapcomm->controls,NCF_PREFETCH); CLRFLAG(dapcomm->controls,NCF_PREFETCH_EAGER); } else if(paramcheck34(dapcomm,"noprefetch",NULL)) CLRFLAG(dapcomm->controls,NCF_PREFETCH); if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) SETFLAG(dapcomm->controls,NCF_CACHE); if(paramcheck34(dapcomm,"show","fetch")) SETFLAG(dapcomm->controls,NCF_SHOWFETCH); nclog(NCLOGNOTE,"Caching=%d",FLAGSET(dapcomm->controls,NCF_CACHE)); }
/* A variable is prefetchable if 1. it is atomic 2. it's size is sufficiently small 3. it is not contained in sequence or a dimensioned structure. */ NCerror markprefetch(NCDAPCOMMON* nccomm) { int i,j; NClist* allvars = nccomm->cdf.fullddsroot->tree->varnodes; assert(allvars != NULL); /* mark those variables of sufficiently small size */ for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); size_t nelems; /* If var is not atomic, then it is not prefetchable */ if(var->nctype != NC_Atomic) continue; /* if var is under a sequence, then never prefetch */ if(dapinsequence(var)) continue; /* Compute the # of elements in the variable */ for(nelems=1,j=0;j<nclistlength(var->array.dimsettrans);j++) { CDFnode* dim = (CDFnode*)nclistget(var->array.dimsettrans,j); nelems *= dim->dim.declsize; } if(nelems <= nccomm->cdf.smallsizelimit && FLAGSET(nccomm->controls,NCF_PREFETCH)) { var->prefetchable = 1; if(SHOWFETCH) { extern char* ocfqn(OCddsnode); char *tmp = ocfqn(var->ocnode); nclog(NCLOGDBG,"prefetchable: %s=%lu", tmp,(unsigned long)nelems); free(tmp); } } } return NC_NOERR; }
/* Parse incoming url constraints, if any, to check for syntactic correctness */ int dapparseconstraints(char* constraints, DCEconstraint* dapconstraint) { int ncstat = NC_NOERR; char* errmsg; assert(dapconstraint != NULL); nclistclear(dapconstraint->projections); nclistclear(dapconstraint->selections); ncstat = dapceparse(constraints,dapconstraint,&errmsg); if(ncstat) { nclog(NCLOGWARN,"DAP constraint parse failure: %s",errmsg); if(errmsg) free(errmsg); nclistclear(dapconstraint->projections); nclistclear(dapconstraint->selections); } #ifdef DEBUG fprintf(stderr,"constraint: %s",dcetostring((DCEnode*)dapconstraint)); #endif return ncstat; }
/* See ncd3dispatch.c for other version */ int NCD3_open(const char * path, int mode, int basepe, size_t *chunksizehintp, int useparallel, void* mpidata, NC_Dispatch* dispatch, NC** ncpp) { NCerror ncstat = NC_NOERR; OCerror ocstat = OC_NOERR; NC* drno = NULL; NCDAPCOMMON* dapcomm = NULL; const char* value; char* tmpname = NULL; if(!nc3dinitialized) nc3dinitialize(); if(path == NULL) return NC_EDAPURL; if(dispatch == NULL) PANIC("NC3D_open: no dispatch table"); /* Setup our NC and NCDAPCOMMON state*/ drno = (NC*)calloc(1,sizeof(NC)); if(drno == NULL) {ncstat = NC_ENOMEM; goto done;} /* compute an ncid */ ncstat = add_to_NCList(drno); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} dapcomm = (NCDAPCOMMON*)calloc(1,sizeof(NCDAPCOMMON)); if(dapcomm == NULL) {ncstat = NC_ENOMEM; goto done;} drno->dispatch = dispatch; drno->dispatchdata = dapcomm; dapcomm->controller = (NC*)drno; dapcomm->cdf.separator = "."; dapcomm->cdf.smallsizelimit = DFALTSMALLLIMIT; dapcomm->cdf.cache = createnccache(); #ifdef HAVE_GETRLIMIT { struct rlimit rl; if(getrlimit(RLIMIT_NOFILE, &rl) >= 0) { dapcomm->cdf.cache->cachecount = (size_t)(rl.rlim_cur / 2); } } #endif #ifdef OCCOMPILEBYDEFAULT /* set the compile flag by default */ dapcomm->oc.rawurltext = (char*)emalloc(strlen(path)+strlen("[compile]")+1); strcpy(dapcomm->oc.rawurltext,"[compile]"); strcat(dapcomm->oc.rawurltext, path); #else dapcomm->oc.rawurltext = strdup(path); #endif nc_uriparse(dapcomm->oc.rawurltext,&dapcomm->oc.url); /* parse the client parameters */ nc_uridecodeparams(dapcomm->oc.url); if(!constrainable34(dapcomm->oc.url)) SETFLAG(dapcomm->controls,NCF_UNCONSTRAINABLE); /* Use libsrc code for storing metadata */ tmpname = nulldup(PSEUDOFILE); /* Now, use the file to create the netcdf file */ if(sizeof(size_t) == sizeof(unsigned int)) ncstat = nc_create(tmpname,NC_CLOBBER,&drno->substrate); else ncstat = nc_create(tmpname,NC_CLOBBER|NC_64BIT_OFFSET,&drno->substrate); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} /* free the filename so it will automatically go away*/ unlink(tmpname); nullfree(tmpname); /* Avoid fill */ nc_set_fill(drno->substrate,NC_NOFILL,NULL); dapcomm->oc.dapconstraint = (DCEconstraint*)dcecreate(CES_CONSTRAINT); dapcomm->oc.dapconstraint->projections = nclistnew(); dapcomm->oc.dapconstraint->selections = nclistnew(); /* Parse constraints to make sure they are syntactically correct */ ncstat = parsedapconstraints(dapcomm,dapcomm->oc.url->constraint,dapcomm->oc.dapconstraint); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} /* Complain if we are unconstrainable but have constraints */ if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) { if(dapcomm->oc.url->constraint != NULL && strlen(dapcomm->oc.url->constraint) > 0) { nclog(NCLOGWARN,"Attempt to constrain an unconstrainable data source: %s", dapcomm->oc.url->constraint); } } /* Construct a url for oc minus any parameters */ dapcomm->oc.urltext = nc_uribuild(dapcomm->oc.url,NULL,NULL, (NC_URIALL ^ NC_URICONSTRAINTS)); /* Pass to OC */ ocstat = oc_open(dapcomm->oc.urltext,&dapcomm->oc.conn); if(ocstat != OC_NOERR) {THROWCHK(ocstat); goto done;} nullfree(dapcomm->oc.urltext); /* clean up */ dapcomm->oc.urltext = NULL; /* process control client parameters */ applyclientparamcontrols3(dapcomm); /* Turn on logging; only do this after oc_open*/ if((value = paramvalue34(dapcomm,"log")) != NULL) { ncloginit(); ncsetlogging(1); nclogopen(value); oc_loginit(); oc_setlogging(1); oc_logopen(value); } /* fetch and build the (almost) unconstrained DDS for use as template */ ncstat = fetchtemplatemetadata3(dapcomm); if(ncstat != NC_NOERR) goto done; /* fetch and build the constrained DDS */ ncstat = fetchconstrainedmetadata3(dapcomm); if(ncstat != NC_NOERR) goto done; #ifdef DEBUG2 fprintf(stderr,"constrained dds: %s\n",dumptree(dapcomm->cdf.ddsroot)); #endif /* The following actions are (mostly) WRT to the constrained tree */ /* Accumulate useful nodes sets */ ncstat = computecdfnodesets3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Fix grids */ ncstat = fixgrids3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Locate and mark usable sequences */ ncstat = sequencecheck3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* suppress variables not in usable sequences */ ncstat = suppressunusablevars3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* apply client parameters */ ncstat = applyclientparams34(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Add (as needed) string dimensions*/ ncstat = addstringdims(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} if(nclistlength(dapcomm->cdf.seqnodes) > 0) { /* Build the sequence related dimensions */ ncstat = defseqdims(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} } /* Define the dimsetplus and dimsetall lists */ ncstat = definedimsets3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Re-compute the dimension names*/ ncstat = computecdfdimnames34(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Deal with zero size dimensions */ ncstat = fixzerodims3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} /* Attempt to use the DODS_EXTRA info to turn one of the dimensions into unlimited. Assume computecdfdimnames34 has already been called. */ ncstat = defrecorddim3(dapcomm); if(ncstat) {THROWCHK(ncstat); goto done;} if(dapcomm->cdf.recorddimname != NULL && nclistlength(dapcomm->cdf.seqnodes) > 0) { /*nclog(NCLOGWARN,"unlimited dimension specified, but sequences exist in DDS");*/ PANIC("unlimited dimension specified, but sequences exist in DDS"); } /* Re-compute the var names*/ ncstat = computecdfvarnames3(dapcomm,dapcomm->cdf.ddsroot,dapcomm->cdf.varnodes); if(ncstat) {THROWCHK(ncstat); goto done;} /* Transfer data from the unconstrained DDS data to the unconstrained DDS */ ncstat = dimimprint3(dapcomm); if(ncstat) goto done; /* Process the constraints to map to the constrained CDF tree */ /* (must follow fixgrids3 */ ncstat = mapconstraints3(dapcomm->oc.dapconstraint,dapcomm->cdf.ddsroot); if(ncstat != NC_NOERR) goto done; /* Canonicalize the constraint */ ncstat = fixprojections(dapcomm->oc.dapconstraint->projections); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} /* Fill in segment information */ ncstat = qualifyconstraints3(dapcomm->oc.dapconstraint); if(ncstat != NC_NOERR) goto done; /* using the modified constraint, rebuild the constraint string */ if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) { /* ignore all constraints */ dapcomm->oc.urltext = nc_uribuild(dapcomm->oc.url,NULL,NULL,0); } else { char* constraintstring = buildconstraintstring3(dapcomm->oc.dapconstraint); nc_urisetconstraints(dapcomm->oc.url,constraintstring); nullfree(constraintstring); dapcomm->oc.urltext = nc_uribuild(dapcomm->oc.url,NULL,NULL,NC_URICONSTRAINTS); } #ifdef DEBUG fprintf(stderr,"ncdap3: final constraint: %s\n",dapcomm->oc.url->constraint); #endif /* Estimate the variable sizes */ estimatevarsizes3(dapcomm); /* Build the meta data */ ncstat = buildncstructures3(dapcomm); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} /* Do any necessary data prefetch */ if(FLAGSET(dapcomm->controls,NCF_PREFETCH)) { ncstat = prefetchdata3(dapcomm); if(ncstat != NC_NOERR) { del_from_NCList((NC*)drno); /* undefine here */ {THROWCHK(ncstat); goto done;} } } { /* Mark as no longer writable and no longer indef; requires breaking abstraction */ NC* nc; ncstat = NC_check_id(drno->substrate, &nc); /* Mark as no longer writeable */ fClr(nc->nciop->ioflags, NC_WRITE); /* Mark as no longer indef; (do NOT use nc_enddef until diskless is working)*/ fSet(nc->flags, NC_INDEF); } if(ncpp) *ncpp = (NC*)drno; return ncstat; done: if(drno != NULL) NCD3_abort(drno->ext_ncid); if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); return THROW(ncstat); }
NCerror fixprojections(NClist* list) { int i,j,k; NCerror ncstat = NC_NOERR; NClist* tmp = nclistnew(); /* misc. uses */ #ifdef DEBUG fprintf(stderr,"fixprojection: list = %s\n",dumpprojections(list)); #endif if(nclistlength(list) == 0) goto done; /* Step 1: remove duplicates and complain about slice mismatches */ for(i=0;i<nclistlength(list);i++) { DCEprojection* p1 = (DCEprojection*)nclistget(list,i); if(p1 == NULL) continue; if(p1->discrim != CES_VAR) continue; /* dont try to unify functions */ for(j=i;j<nclistlength(list);j++) { DCEprojection* p2 = (DCEprojection*)nclistget(list,j); if(p2 == NULL) continue; if(p1 == p2) continue; if(p2->discrim != CES_VAR) continue; if(p1->var->annotation != p2->var->annotation) continue; /* check for slice mismatches */ if(!slicematch(p1->var->segments,p2->var->segments)) { /* complain */ nclog(NCLOGWARN,"Malformed projection: same variable with different slicing"); } /* remove p32 */ nclistset(list,j,(ncelem)NULL); dcefree((DCEnode*)p2); } } /* Step 2: remove containers when a field is also present */ for(i=0;i<nclistlength(list);i++) { DCEprojection* p1 = (DCEprojection*)nclistget(list,i); if(p1 == NULL) continue; if(p1->discrim != CES_VAR) continue; /* dont try to unify functions */ if(!iscontainer((CDFnode*)p1->var->annotation)) continue; for(j=i;j<nclistlength(list);j++) { DCEprojection* p2 = (DCEprojection*)nclistget(list,j); if(p2 == NULL) continue; if(p2->discrim != CES_VAR) continue; nclistclear(tmp); collectnodepath3((CDFnode*)p2->var->annotation,tmp,WITHDATASET); for(k=0;k<nclistlength(tmp);k++) { void* candidate = (void*)nclistget(tmp,k); if(candidate == p1->var->annotation) { nclistset(list,i,(ncelem)NULL); dcefree((DCEnode*)p1); goto next; } } } next: continue; } /* Step 3: expand all containers recursively down to the leaf nodes */ for(;;) { nclistclear(tmp); for(i=0;i<nclistlength(list);i++) { DCEprojection* target = (DCEprojection*)nclistget(list,i); CDFnode* leaf; if(target == NULL) continue; if(target->discrim != CES_VAR) continue; /* dont try to unify functions */ leaf = (CDFnode*)target->var->annotation; ASSERT(leaf != NULL); if(iscontainer(leaf)) {/* capture container */ if(!nclistcontains(tmp,(ncelem)target)) nclistpush(tmp,(ncelem)target); nclistset(list,i,(ncelem)NULL); } } if(nclistlength(tmp) == 0) break; /*done*/ /* Now explode the containers */ for(i=0;i<nclistlength(tmp);i++) { DCEprojection* container = (DCEprojection*)nclistget(tmp,i); CDFnode* leaf = (CDFnode*)container->var->annotation; for(j=0;i<nclistlength(leaf->subnodes);j++) { CDFnode* field = (CDFnode*)nclistget(leaf->subnodes,j); /* Convert field node to a proper constraint */ DCEprojection* proj = projectify(field,container); nclistpush(list,(ncelem)proj); } /* reclaim the container */ dcefree((DCEnode*)container); } } /*for(;;)*/ /* remove all NULL elements */ for(i=nclistlength(list)-1;i>=0;i--) { DCEprojection* target = (DCEprojection*)nclistget(list,i); if(target == NULL) nclistremove(list,i); } done: #ifdef DEBUG fprintf(stderr,"fixprojection: exploded = %s\n",dumpprojections(list)); #endif nclistfree(tmp); return ncstat; }
static NCerror matchpartialname3(NClist* nodes, NClist* segments, CDFnode** nodep) { int i,nsegs; NCerror ncstat = NC_NOERR; DCEsegment* lastseg = NULL; NClist* namematches = nclistnew(); NClist* matches = nclistnew(); NClist* matchpath = nclistnew(); /* Locate all nodes with the same name as the last element in the segment path */ nsegs = nclistlength(segments); lastseg = (DCEsegment*)nclistget(segments,nsegs-1); for(i=0;i<nclistlength(nodes);i++) { CDFnode* node = (CDFnode*)nclistget(nodes,i); if(node->ocname == null) continue; /* Path names come from oc space */ if(strcmp(node->ocname,lastseg->name) != 0) continue; /* Only look at selected kinds of nodes */ if(node->nctype != NC_Sequence && node->nctype != NC_Structure && node->nctype != NC_Grid && node->nctype != NC_Primitive ) continue; nclistpush(namematches,(ncelem)node); } if(nclistlength(namematches)==0) { nclog(NCLOGERR,"No match for projection name: %s",lastseg->name); ncstat = NC_EDDS; goto done; } /* Now, collect and compare paths of the matching nodes */ for(i=0;i<nclistlength(namematches);i++) { CDFnode* matchnode = (CDFnode*)nclistget(namematches,i); nclistclear(matchpath); collectnodepath3(matchnode,matchpath,0); /* Do a suffix match */ if(matchsuffix3(matchpath,segments)) { nclistpush(matches,(ncelem)matchnode); #ifdef DEBUG fprintf(stderr,"matchpartialname: pathmatch: %s :: %s\n", matchnode->ncfullname,dumpsegments(segments)); #endif } } /* |matches|==0 => no match; |matches|>1 => ambiguity */ switch (nclistlength(matches)) { case 0: nclog(NCLOGERR,"No match for projection name: %s",lastseg->name); ncstat = NC_EDDS; break; case 1: if(nodep) *nodep = (CDFnode*)nclistget(matches,0); break; default: { CDFnode* minnode = NULL; int minpath = 0; int nmin = 0; /* to catch multiple ones with same short path */ /* ok, see if one of the matches has a path that is shorter then all the others */ for(i=0;i<nclistlength(matches);i++) { CDFnode* candidate = (CDFnode*)nclistget(matches,i); nclistclear(matchpath); collectnodepath3(candidate,matchpath,0); if(minpath == 0) { minpath = nclistlength(matchpath); minnode = candidate; } else if(nclistlength(matchpath) == minpath) { nmin++; } else if(nclistlength(matchpath) < minpath) { minpath = nclistlength(matchpath); minnode = candidate; nmin = 1; } } /*for*/ if(minnode == NULL || nmin > 1) { nclog(NCLOGERR,"Ambiguous match for projection name: %s", lastseg->name); ncstat = NC_EDDS; } else if(nodep) *nodep = minnode; } break; } #ifdef DEBUG fprintf(stderr,"matchpartialname: choice: %s %s for %s\n", (nclistlength(matches) > 1?"":"forced"), (*nodep)->ncfullname,dumpsegments(segments)); #endif done: return THROW(ncstat); }
/* Recursive helper that does the bulk of the work */ static int bin_generate_data_r(NCConstant* instance, Symbol* tsym, Datalist* fillvalue, Bytebuffer* databuf) { int stat = NC_NOERR; if(instance->nctype == NC_FILLVALUE) { /* replace with fillvalue for the type */ Datalist* filllist = (fillvalue == NULL ? getfiller(tsym) : fillvalue); ASSERT(datalistlen(filllist)==1) instance = datalistith(filllist,0); } switch (tsym->subclass) { case NC_PRIM: { switch (tsym->nc_id) { case NC_CHAR: { char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_CHAR; convert1(instance,tmp); p = &tmp->value.charv;; bbAppendn(databuf,p,sizeof(char)); reclaimconstant(tmp); } break; case NC_BYTE: { signed char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_BYTE; convert1(instance,tmp); p = &tmp->value.int8v; bbAppendn(databuf,p,sizeof(signed char)); reclaimconstant(tmp); } break; case NC_UBYTE: { unsigned char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UBYTE; convert1(instance,tmp); p = &tmp->value.uint8v; bbAppendn(databuf,p,sizeof(unsigned char)); reclaimconstant(tmp); } break; case NC_SHORT: { short* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_SHORT; convert1(instance,tmp); p = &tmp->value.int16v; bbAppendn(databuf,p,sizeof(short)); reclaimconstant(tmp); } break; case NC_USHORT: { unsigned short* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_USHORT; convert1(instance,tmp); p = &tmp->value.uint16v; bbAppendn(databuf,p,sizeof(unsigned short)); reclaimconstant(tmp); } break; case NC_INT: { int* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_INT; convert1(instance,tmp); p = &tmp->value.int32v; bbAppendn(databuf,p,sizeof(int)); reclaimconstant(tmp); } break; case NC_UINT: { unsigned int* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UINT; convert1(instance,tmp); p = &tmp->value.uint32v; bbAppendn(databuf,p,sizeof(unsigned int)); reclaimconstant(tmp); } break; case NC_INT64: { long long* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_INT64; convert1(instance,tmp); p = &tmp->value.int64v; bbAppendn(databuf,p,sizeof(long long)); reclaimconstant(tmp); } break; case NC_UINT64: { unsigned long long* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_UINT64; convert1(instance,tmp); p = &tmp->value.uint64v; bbAppendn(databuf,p,sizeof(unsigned long long)); reclaimconstant(tmp); } break; case NC_FLOAT: { float* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_FLOAT; convert1(instance,tmp); p = &tmp->value.floatv; bbAppendn(databuf,p,sizeof(float)); reclaimconstant(tmp); } break; case NC_DOUBLE: { double* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_DOUBLE; convert1(instance,tmp); p = &tmp->value.doublev; bbAppendn(databuf,p,sizeof(double)); reclaimconstant(tmp); } break; case NC_STRING: { char* p = NULL; NCConstant* tmp = nullconst(); tmp->nctype = NC_STRING; convert1(instance,tmp); p = emalloc(tmp->value.stringv.len+1); memcpy(p,tmp->value.stringv.stringv,tmp->value.stringv.len); p[tmp->value.stringv.len] = '\0'; bbAppendn(databuf,&p,sizeof(char*)); reclaimconstant(tmp); } break; default: stat = NC_EINTERNAL; goto done; /* Should never happen */ } break; /*switch*/ } break; /*NC_PRIM*/ case NC_ENUM: { Symbol* basetype = tsym->typ.basetype; /* Pretend */ stat = bin_generate_data_r(instance,basetype,fillvalue,databuf); } break; case NC_OPAQUE: { unsigned char* bytes = NULL; size_t len = 0; if(instance->nctype != NC_OPAQUE) {stat = NC_EBADTYPE; goto done;} /* Assume the opaque string has been normalized */ bytes=makebytestring(instance->value.opaquev.stringv,&len); if(bytes == NULL) {stat = NC_ENOMEM; goto done;} bbAppendn(databuf,(void*)bytes,len); free(bytes); } break; case NC_VLEN: { Datalist* sublist = NULL; Bytebuffer* vlendata = NULL; nc_vlen_t p; if(instance->nctype != NC_COMPOUND) { nclog(NCLOGERR,"Translating vlen: expected sublist"); stat = NC_EBADTYPE; goto done; } sublist = instance->value.compoundv; vlendata = bbNew(); if((stat = binary_generate_data(sublist,tsym->typ.basetype,NULL,vlendata))) goto done; p.len = datalistlen(sublist); p.p = bbContents(vlendata); bbAppendn(databuf,(char*)&p,sizeof(nc_vlen_t)); } break; case NC_COMPOUND: { /* The really hard one */ size_t nfields, fid, i; Datalist* cmpd = instance->value.compoundv; write_alignment(tsym->typ.cmpdalign,databuf); /* Get info about each field in turn and build it*/ nfields = listlength(tsym->subnodes); for(fid=0;fid<nfields;fid++) { Symbol* field = listget(tsym->subnodes,fid); NCConstant* fieldinstance = datalistith(cmpd,fid); int ndims = field->typ.dimset.ndims; size_t arraycount; if(ndims == 0) { ndims=1; /* fake the scalar case */ } /* compute the total number of elements in the field array */ arraycount = 1; for(i=0;i<ndims;i++) arraycount *= field->typ.dimset.dimsyms[i]->dim.declsize; write_alignment(field->typ.alignment,databuf); /* Write the instances */ for(i=0;i<arraycount;i++) { if((stat = bin_generate_data_r(fieldinstance, field->typ.basetype, NULL, databuf))) goto done; } } } break; default: stat = NC_EINTERNAL; goto done; /* Should never happen */ } done: return stat; }
int dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCobject dasroot) { unsigned int i,j; NCerror ncerr = NC_NOERR; OCerror ocstat = OC_NOERR; OCconnection conn = nccomm->oc.conn; unsigned int nsubnodes, nobjects; OCobject* dasobjects = NULL; NClist* dasglobals = nclistnew(); NClist* dasnodes = nclistnew(); NClist* dodsextra = nclistnew(); NClist* varnodes = nclistnew(); NClist* allddsnodes = ddsroot->tree->nodes; if(ddsroot == NULL || dasroot == NULL) return NC_NOERR; nobjects = oc_inq_nobjects(conn,dasroot); dasobjects = oc_inq_objects(conn,dasroot); /* 1. collect all the relevant DAS nodes; namely those that contain at least one attribute value. Simultaneously look for potential ambiguities if found; complain but continue: result are indeterminate. also collect globals and DODS_EXTRA separately. */ for(i=0;i<nobjects;i++) { OCobject das = dasobjects[i]; OCtype octype; char* ocname = NULL; int isglobal = 0; int hasattributes = 0; OCHECK(oc_inq_class(conn,das,&octype)); if(octype == OC_Attribute) continue; /* ignore these for now*/ OCHECK(oc_inq_name(conn,das,&ocname)); OCHECK(oc_inq_nsubnodes(conn,das,&nsubnodes)); isglobal = (ocname == NULL ? 0 : isglobalname3(ocname)); /* catch DODS_EXTRA */ if(isglobal && ocname != NULL && strcmp(ocname,"DODS_EXTRA")==0) { nclistpush(dodsextra,(ncelem)das); nullfree(ocname); continue; } if(ocname == NULL || isglobal) { nclistpush(dasglobals,(ncelem)das); nullfree(ocname); continue; } hasattributes = hasattribute3(conn,das); if(hasattributes) { /* Look for previously collected nodes with same name*/ for(j=0;j<nclistlength(dasnodes);j++) { OCobject das2 = (OCobject)nclistget(dasnodes,j); char* ocname2; OCHECK(oc_inq_name(conn,das2,&ocname2)); if(ocname2 == NULL || ocname == NULL) goto loop; if(strcmp(ocname2,"DODS")==0) goto loop; if(strcmp(ocname,ocname2)==0) nclog(NCLOGWARN,"nc_mergedas: potentially ambiguous DAS name: %s",ocname2); loop: nullfree(ocname2); } nclistpush(dasnodes,(ncelem)das); } nullfree(ocname); } /* 2. collect all the leaf DDS nodes (of type NC_Primitive)*/ for(i=0;i<nclistlength(allddsnodes);i++) { CDFnode* dds = (CDFnode*)nclistget(allddsnodes,i); if(dds->nctype == NC_Primitive) nclistpush(varnodes,(ncelem)dds); } /* 3. For each das node, lncate matching DDS node(s) and attach attributes to the DDS node(s). Match means: 1. DAS->fullname :: DDS->fullname 2. DAS->name :: DDS->fullname (support DAS names with embedded '.' 3. DAS->name :: DDS->name 4. special case for DODS. Apply 1-3 on DODS parent. */ for(i=0;i<nclistlength(dasnodes);i++) { OCobject das = (OCobject)nclistget(dasnodes,i); char* ocfullname = NULL; char* ocbasename = NULL; if(das == OCNULL) continue; OCHECK(oc_inq_name(conn,das,&ocbasename)); if(strcmp(ocbasename,"DODS")==0) { OCobject container; OCHECK(oc_inq_container(conn,das,&container)); if(container == OCNULL) { ASSERT(container != OCNULL); } ocfullname = makeocpathstring3(conn,container,"."); } else { ocfullname = makeocpathstring3(conn,das,"."); } for(j=0;j<nclistlength(varnodes);j++) { CDFnode* dds = (CDFnode*)nclistget(varnodes,j); char* ddsfullname = makecdfpathstring3(dds,"."); if(strcmp(ocfullname,ddsfullname)==0 || strcmp(ocbasename,ddsfullname)==0 || strcmp(ocbasename,dds->ocname)==0) { mergedas1(nccomm,conn,dds,das); /* remove from dasnodes list*/ nclistset(dasnodes,i,(ncelem)NULL); } nullfree(ddsfullname); } nullfree(ocfullname); nullfree(ocbasename); } /* 4. Assign globals */ for(i=0;i<nclistlength(dasglobals);i++) { OCobject das = (OCobject)nclistget(dasglobals,i); mergedas1(nccomm,conn,ddsroot,das); } /* 5. Assign DOD_EXTRA */ for(i=0;i<nclistlength(dodsextra);i++) { OCobject das = (OCobject)nclistget(dodsextra,i); mergedas1(nccomm,conn,ddsroot,das); } done: /* cleanup*/ nullfree(dasobjects); nclistfree(dasglobals); nclistfree(dasnodes); nclistfree(dodsextra); nclistfree(varnodes); if(ocstat != OC_NOERR) ncerr = ocerrtoncerr(ocstat); return THROW(ncerr); }
/* Compute the set of prefetched data. Notes: 1. All prefetches are whole variable fetches. 2. If the data set is unconstrainable, we will prefetch the whole thing */ NCerror prefetchdata3(NCDAPCOMMON* nccomm) { int i; NCFLAGS flags; NCerror ncstat = NC_NOERR; NClist* allvars = nccomm->cdf.ddsroot->tree->varnodes; DCEconstraint* urlconstraint = nccomm->oc.dapconstraint; NClist* vars = nclistnew(); NCcachenode* cache = NULL; DCEconstraint* newconstraint = NULL; if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) { /* If we cannot constrain and caching is enabled, then pull in everything */ if(FLAGSET(nccomm->controls,NCF_CACHE)) { for(i=0;i<nclistlength(allvars);i++) { nclistpush(vars,nclistget(allvars,i)); } } else { /* do no prefetching */ nccomm->cdf.cache->prefetch = NULL; goto done; } } else { /* pull in those variables previously marked as prefetchable */ for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); /* Most of the important testing was already done */ if(!var->basenode->prefetchable) continue; /* Do not attempt to prefetch any variables in the nc_open url's projection list */ if(nclistcontains(nccomm->cdf.projectedvars,(void*)var)) continue; /* Should be prefetchable */ nclistpush(vars,(void*)var); if(SHOWFETCH) { nclog(NCLOGDBG,"prefetch: %s",var->ncfullname); } } } /* If there are no vars, then do nothing */ if(nclistlength(vars) == 0) { nccomm->cdf.cache->prefetch = NULL; goto done; } /* Create a single constraint consisting of the projections for the variables; each projection is whole variable. The selections are passed on as is. The exception is if we are prefetching everything. */ newconstraint = (DCEconstraint*)dcecreate(CES_CONSTRAINT); newconstraint->projections = nclistnew(); newconstraint->selections = dceclonelist(urlconstraint->selections); for(i=0;i<nclistlength(vars);i++) { CDFnode* var = (CDFnode*)nclistget(vars,i); DCEprojection* varprojection; /* convert var to a projection */ ncstat = dapvar2projection(var,&varprojection); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} nclistpush(newconstraint->projections,(void*)varprojection); } if(SHOWFETCH) { char* s = dumpprojections(newconstraint->projections); LOG1(NCLOGNOTE,"prefetch.final: %s",s); nullfree(s); } flags = NCF_PREFETCH; if(nclistlength(allvars) == nclistlength(vars)) flags |= NCF_PREFETCH_ALL; ncstat = buildcachenode34(nccomm,newconstraint,vars,&cache,flags); newconstraint = NULL; /* buildcachenode34 takes control of newconstraint */ if(ncstat) goto done; cache->wholevariable = 1; /* All prefetches are whole variable */ /* Make cache node be the prefetch node */ nccomm->cdf.cache->prefetch = cache; if(SHOWFETCH) { LOG0(NCLOGNOTE,"prefetch.complete"); } if(SHOWFETCH) { char* s = NULL; /* Log the set of prefetch variables */ NCbytes* buf = ncbytesnew(); ncbytescat(buf,"prefetch.vars: "); for(i=0;i<nclistlength(vars);i++) { CDFnode* var = (CDFnode*)nclistget(vars,i); ncbytescat(buf," "); s = makecdfpathstring3(var,"."); ncbytescat(buf,s); nullfree(s); } ncbytescat(buf,"\n"); nclog(NCLOGNOTE,"%s",ncbytescontents(buf)); ncbytesfree(buf); } done: nclistfree(vars); dcefree((DCEnode*)newconstraint); if(ncstat) freenccachenode(nccomm,cache); return THROW(ncstat); }
void stopMsgQueue(){ StopBluetoothNotifications(hBTNotif); nclog(L"BT notification ended: %s\n", logDateTime()); }
static int setauthfield(NCauth* auth, const char* flag, const char* value) { int ret = NC_NOERR; if(value == NULL) goto done; if(strcmp(flag,"HTTP.DEFLATE")==0) { if(atoi(value)) auth->curlflags.compress = 1; #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.DEFLATE: %ld", infoflags.compress); #endif } if(strcmp(flag,"HTTP.VERBOSE")==0) { if(atoi(value)) auth->curlflags.verbose = 1; #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.VERBOSE: %ld", auth->curlflags.verbose); #endif } if(strcmp(flag,"HTTP.TIMEOUT")==0) { if(atoi(value)) auth->curlflags.timeout = atoi(value); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.TIMEOUT: %ld", auth->curlflags.timeout); #endif } if(strcmp(flag,"HTTP.USERAGENT")==0) { if(atoi(value)) auth->curlflags.useragent = strdup(value); MEMCHECK(auth->curlflags.useragent); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.USERAGENT: %s", auth->curlflags.useragent); #endif } if( strcmp(flag,"HTTP.COOKIEFILE")==0 || strcmp(flag,"HTTP.COOKIE_FILE")==0 || strcmp(flag,"HTTP.COOKIEJAR")==0 || strcmp(flag,"HTTP.COOKIE_JAR")==0 ) { nullfree(auth->curlflags.cookiejar); auth->curlflags.cookiejar = strdup(value); MEMCHECK(auth->curlflags.cookiejar); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.COOKIEJAR: %s", auth->curlflags.cookiejar); #endif } if(strcmp(flag,"HTTP.PROXY.SERVER")==0 || strcmp(flag,"HTTP.PROXY_SERVER")==0) { ret = NC_parseproxy(auth,value); if(ret != NC_NOERR) goto done; #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.PROXY.SERVER: %s", value); #endif } if(strcmp(flag,"HTTP.SSL.VALIDATE")==0) { if(atoi(value)) { auth->ssl.verifypeer = 1; auth->ssl.verifyhost = 1; #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.VALIDATE: %ld", 1); #endif } } if(strcmp(flag,"HTTP.SSL.CERTIFICATE")==0) { nullfree(auth->ssl.certificate); auth->ssl.certificate = strdup(value); MEMCHECK(auth->ssl.certificate); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.CERTIFICATE: %s", auth->ssl.certificate); #endif } if(strcmp(flag,"HTTP.SSL.KEY")==0) { nullfree(auth->ssl.key); auth->ssl.key = strdup(value); MEMCHECK(auth->ssl.key); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.KEY: %s", auth->ssl.key); #endif } if(strcmp(flag,"HTTP.SSL.KEYPASSWORD")==0) { nullfree(auth->ssl.keypasswd) ; auth->ssl.keypasswd = strdup(value); MEMCHECK(auth->ssl.keypasswd); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.KEYPASSWORD: %s", auth->ssl.keypasswd); #endif } if(strcmp(flag,"HTTP.SSL.CAINFO")==0) { nullfree(auth->ssl.cainfo) ; auth->ssl.cainfo = strdup(value); MEMCHECK(auth->ssl.cainfo); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.CAINFO: %s", auth->ssl.cainfo); #endif } if(strcmp(flag,"HTTP.SSL.CAPATH")==0) { nullfree(auth->ssl.capath) ; auth->ssl.capath = strdup(value); MEMCHECK(auth->ssl.capath); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.CAPATH: %s", auth->ssl.capath); #endif } if(strcmp(flag,"HTTP.SSL.VERIFYPEER")==0) { const char* s = value; int tf = 0; if(s == NULL || strcmp(s,"0")==0 || strcasecmp(s,"false")==0) tf = 0; else if(strcmp(s,"1")==0 || strcasecmp(s,"true")==0) tf = 1; else tf = 1; /* default if not null */ auth->ssl.verifypeer = tf; #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.SSL.VERIFYPEER: %d", auth->ssl.verifypeer); #endif } if(strcmp(flag,"HTTP.NETRC")==0) { nullfree(auth->curlflags.netrc); auth->curlflags.netrc = strdup(value); MEMCHECK(auth->curlflags.netrc); #ifdef D4DEBUG nclog(NCLOGNOTE,"HTTP.NETRC: %s", auth->curlflags.netrc); #endif } if(strcmp(flag,"HTTP.CREDENTIALS.USERNAME")==0) { nullfree(auth->creds.user); auth->creds.user = strdup(value); MEMCHECK(auth->creds.user); } if(strcmp(flag,"HTTP.CREDENTIALS.PASSWORD")==0) { nullfree(auth->creds.pwd); auth->creds.pwd = strdup(value); MEMCHECK(auth->creds.pwd); } done: return (ret); nomem: return (NC_ENOMEM); }
void dumpBTevent(BTEVENT btEvent, HWND hwnd){ BT_CONNECT_EVENT* cntEvt = NULL; BT_DISCONNECT_EVENT* discntEvt=NULL; BT_ROLE_SWITCH_EVENT* rolSwitchEvt=NULL; BT_MODE_CHANGE_EVENT* btModeChgEvt=NULL; BT_LINK_KEY_EVENT* btLnkKeyEvt=NULL; TCHAR btAddress[18]; TCHAR hConn[12]; TCHAR encMode[5]; TCHAR linkType[5]; TCHAR szTemp[MAX_PATH]; TCHAR szMsg[MAX_PATH]; wsprintf(szMsg, L"\r\n"); switch (btEvent.dwEventId){ case BTE_KEY_NOTIFY: wsprintf(szMsg, L"\r\n%s: BTE_KEY_NOTIFY:", logDateTime()); break; case BTE_KEY_REVOKED: btLnkKeyEvt = (BT_LINK_KEY_EVENT*)btEvent.baEventData; //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX wsprintf(btAddress, L"%s", btAddr2Mac( btLnkKeyEvt->bta, btAddress)); wsprintf(szMsg, L"\r\n%s: BTE_KEY_REVOKED: mac=%s", logDateTime(), btAddress); break; case BTE_LOCAL_NAME: wsprintf(szMsg, L"\r\n%s: BTE_LOCAL_NAME:", logDateTime()); break; case BTE_COD: wsprintf(szMsg, L"\r\n%s: BTE_COD:", logDateTime()); break; case BTE_STACK_UP: wsprintf(szMsg, L"\r\n%s: BTE_STACK_UP:", logDateTime()); break; case BTE_STACK_DOWN: wsprintf(szMsg,L"\r\n%s: BTE_STACK_DOWN:", logDateTime()); break; case BTE_CONNECTION: cntEvt = (BT_CONNECT_EVENT*)btEvent.baEventData; btAddr2Mac(cntEvt->bta, btAddress); wsprintf(btAddress, L"%s", btAddress);// L"0x00 n/a"); wsprintf(hConn, L"0x%08x", cntEvt->hConnection); wsprintf(encMode, L"0x%02x", cntEvt->ucEncryptMode); wsprintf(linkType, L"0x%02x", cntEvt->ucLinkType); wsprintf(szMsg, L"\r\n%s: BTE_CONNECTION: hnd=%s, mac=%s, enc=%s, lnk=%s", logDateTime(), hConn, btAddress, encMode, linkType); break; case BTE_PAGE_TIMEOUT: wsprintf(szMsg,L"\r\n%s: BTE_PAGE_TIMEOUT:", logDateTime()); break; case BTE_MODE_CHANGE: btModeChgEvt = (BT_MODE_CHANGE_EVENT*)btEvent.baEventData; wsprintf(btAddress, L"%s", btAddr2Mac(btModeChgEvt->bta, btAddress)); wsprintf(hConn, L"0x%08x", btModeChgEvt->hConnection); wsprintf(encMode, L"0x%02x", btModeChgEvt->bMode); wsprintf(szTemp, L"%i", btModeChgEvt->usInterval); wsprintf(szMsg, L"\r\n%s: BTE_MODE_CHANGE: cnt=%s, mac=%s, mod=%s, int=%s", logDateTime(), hConn, btAddress, encMode, szTemp); break; case BTE_ROLE_SWITCH: rolSwitchEvt = (BT_ROLE_SWITCH_EVENT*)btEvent.baEventData; wsprintf(btAddress, L"%s", btAddr2Mac(rolSwitchEvt->bta, btAddress)); wsprintf(szTemp, L"0x%02x", rolSwitchEvt->fRole); wsprintf(szMsg, L"\r\n%s: BTE_ROLE_SWITCH: mac=%s, new role=%s", logDateTime(), btAddress, szTemp); break; case BTE_DISCONNECTION: discntEvt = (BT_DISCONNECT_EVENT*)btEvent.baEventData; wsprintf(hConn, L"0x%08x", discntEvt->hConnection); wsprintf(szTemp, L"%i", discntEvt->ucReason); if( discntEvt->ucReason <= lastError) wsprintf(szTemp, L"'%s'", szBTerror[discntEvt->ucReason]); wsprintf(szMsg, L"\r\n%s: BTE_DISCONNECTION: hnd=%s, why=%s", logDateTime(), hConn, szTemp); break; case BTE_CONNECTION_AUTH_FAILURE: wsprintf(szMsg, L"\r\n%s BTE_CONNECTION_AUTH_FAILURE", logDateTime()); break; default: wsprintf(szMsg, L"\r\n%s: unknown BT event: %i", logDateTime(), btEvent.dwEventId); break; }//switch DEBUGMSG(1, (szMsg)); nclog(szMsg); printMsg(szMsg, hwnd); }