void DlgCmd( void ) { char buff[256]; printf( "DBG>" ); fflush( stdout ); // not really necessary gets( buff ); if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) { switch( tolower( buff[0] ) ) { case 'u': WndAsmInspect( GetCodeDot() ); break; case 's': DumpSource(); break; case 'l': DumpLocals(); break; case 'i': RunRequest( REQ_TRACE_INTO ); break; case 'o': RunRequest( REQ_TRACE_OVER ); break; case 'g': RunRequest( REQ_GO ); break; case 'x': if( _IsOn( SW_REMOTE_LINK ) ) { printf( "Can't break remote task!\n" ); } else { HMODULE hmod; PFN proc = NULL; DosQueryModuleHandle( TrapParms, &hmod ); DosQueryProcAddr( hmod, 5, 0, &proc ); // if( proc != NULL ) // proc(); } // break the task break; default: printf( "Error - unrecognized command\n" ); } } else { DoCmd( DupStr( buff ) ); DoInput(); } }
void DlgCmd( void ) { char buff[256]; printf( "DBG>" ); fflush( stdout ); gets( buff ); if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) { switch( tolower( buff[0] ) ) { case 'u': WndAsmInspect( GetCodeDot() ); break; case 's': DumpSource(); break; case 'l': DumpLocals(); break; case 'i': RunRequest( REQ_TRACE_INTO ); break; case 'o': RunRequest( REQ_TRACE_OVER ); break; case 'g': RunRequest( REQ_GO ); break; case 'x': if( _IsOn( SW_REMOTE_LINK ) ) { printf( "Can't break remote task!\n" ); } else { HANDLE hmod; FARPROC proc; hmod = GetModuleHandle( TrapParms ); proc = GetProcAddress( hmod, (LPSTR)5 ); if( proc != NULL ) proc(); CloseHandle( hmod ); } // break the task break; default: printf( "Error - unrecognized command\n" ); } } else { DoCmd( DupStr( buff ) ); DoInput(); } }
int main( int argc, char **argv ) { char buff[256]; TID tid; APIRET rc; MemInit(); getcmd( buff ); CmdData = buff; DebugMain(); _SwitchOff( SW_ERROR_STARTUP ); DoInput(); VarInitInfo( &Locals ); DosCreateEventSem( NULL, &Requestsem, 0, false ); DosCreateEventSem( NULL, &Requestdonesem, 0, false ); DosPostEventSem( Requestdonesem ); // signal req done rc = DosCreateThread( &tid, ControlFunc, 0, 0, 32768 ); if( rc != 0 ) { printf( "Stubugger: Error creating thread!\n" ); } while( !Done ) { DlgCmd(); } DosCloseEventSem( Requestsem ); DosCloseEventSem( Requestdonesem ); DebugFini(); RunRequest( REQ_BYE ); MemFini(); return( 0 ); }
int CHttpRequest::Run() { CSingleLock pLock( &m_pSection, FALSE ); HINTERNET hInternet = InternetOpen( m_sUserAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); if ( hInternet != NULL ) { m_hInternet = hInternet; RunRequest(); // RunDebugRequest(); pLock.Lock(); if ( m_bCancel ) m_nStatusCode = 0; hInternet = m_hInternet; m_hInternet = NULL; pLock.Unlock(); if ( hInternet != NULL ) InternetCloseHandle( hInternet ); } pLock.Lock(); if ( m_hNotifyWnd != NULL ) PostMessage( m_hNotifyWnd, m_nNotifyMsg, m_nNotifyParam, 0 ); pLock.Unlock(); return 0; }
already_AddRefed<Promise> CacheStorage::Keys(ErrorResult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheStorage); if (!HasStorageAccess()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr; } if (NS_WARN_IF(NS_FAILED(mStatus))) { aRv.Throw(mStatus); return nullptr; } RefPtr<Promise> promise = Promise::Create(mGlobal, aRv); if (NS_WARN_IF(!promise)) { return nullptr; } nsAutoPtr<Entry> entry(new Entry()); entry->mPromise = promise; entry->mArgs = StorageKeysArgs(); RunRequest(std::move(entry)); return promise.forget(); }
int main( int argc, char **argv ) { char buff[256]; DWORD tid; HANDLE hThread; MemInit(); SetErrorMode( SEM_FAILCRITICALERRORS ); getcmd( buff ); CmdData = buff; DebugMain(); _SwitchOff( SW_ERROR_STARTUP ); DoInput(); VarInitInfo( &Locals ); Requestsem = CreateSemaphore( NULL, 0, 1, NULL ); Requestdonesem = CreateSemaphore( NULL, 0, 1, NULL ); ReleaseSemaphore( Requestdonesem, 1, NULL ); // signal req done hThread = CreateThread( NULL, 0, ControlFunc, NULL, 0, &tid ); if (hThread == NULL) { MessageBox( NULL, "Error creating thread!", "Stubugger", MB_APPLMODAL+MB_OK ); } while( !Done ) { DlgCmd(); } CloseHandle( Requestsem ); CloseHandle( Requestdonesem ); DebugFini(); RunRequest( REQ_BYE ); MemFini(); return( 0 ); }
void OGRElasticDataSource::FetchMapping(const char* pszIndexName) { if( m_oSetLayers.find(pszIndexName) != m_oSetLayers.end() ) return; CPLString osURL(m_osURL + CPLString("/") + pszIndexName + CPLString("/_mapping?pretty")); json_object* poRes = RunRequest(osURL, nullptr, std::vector<int>({403})); if( poRes ) { json_object* poLayerObj = CPL_json_object_object_get(poRes, pszIndexName); json_object* poMappings = nullptr; if( poLayerObj && json_object_get_type(poLayerObj) == json_type_object ) poMappings = CPL_json_object_object_get(poLayerObj, "mappings"); if( poMappings && json_object_get_type(poMappings) == json_type_object ) { json_object_iter it; it.key = nullptr; it.val = nullptr; it.entry = nullptr; std::vector<CPLString> aosMappings; json_object_object_foreachC( poMappings, it ) { aosMappings.push_back(it.key); } if( aosMappings.size() == 1 && (aosMappings[0] == "FeatureCollection" || aosMappings[0] == "default") ) { m_oSetLayers.insert(pszIndexName); OGRElasticLayer* poLayer = new OGRElasticLayer( pszIndexName, pszIndexName, aosMappings[0], this, papszOpenOptions); poLayer->InitFeatureDefnFromMapping( CPL_json_object_object_get(poMappings, aosMappings[0]), "", std::vector<CPLString>()); m_apoLayers.push_back(std::unique_ptr<OGRElasticLayer>(poLayer)); } else { for(size_t i=0; i<aosMappings.size();i++) { CPLString osLayerName(pszIndexName + CPLString("_") + aosMappings[i]); if( m_oSetLayers.find(osLayerName) == m_oSetLayers.end() ) { m_oSetLayers.insert(osLayerName); OGRElasticLayer* poLayer = new OGRElasticLayer( osLayerName, pszIndexName, aosMappings[i], this, papszOpenOptions); poLayer->InitFeatureDefnFromMapping( CPL_json_object_object_get(poMappings, aosMappings[i]), "", std::vector<CPLString>()); m_apoLayers.push_back(std::unique_ptr<OGRElasticLayer>(poLayer)); } } } }
OGRLayer *OGRPLScenesDataV1Dataset::GetLayerByName(const char* pszName) { // Prevent GetLayerCount() from calling EstablishLayerList() bool bLayerListInitializedBackup = m_bLayerListInitialized; m_bLayerListInitialized = true; OGRLayer* poRet = GDALDataset::GetLayerByName(pszName); m_bLayerListInitialized = bLayerListInitializedBackup; if( poRet != nullptr ) return poRet; CPLString osURL(m_osBaseURL + "item-types/" + pszName); json_object* poObj = RunRequest(osURL); if( poObj == nullptr ) return nullptr; poRet = ParseItemType(poObj); json_object_put(poObj); return poRet; }
void OGRPLScenesDataV1Dataset::EstablishLayerList() { CPLString osURL(m_osNextItemTypesPageURL); m_osNextItemTypesPageURL = ""; while( !osURL.empty() ) { json_object* poObj = RunRequest(osURL); if( poObj == nullptr ) break; if( !ParseItemTypes( poObj, osURL ) ) { json_object_put(poObj); break; } json_object_put(poObj); } }
already_AddRefed<Promise> CacheStorage::Match(JSContext* aCx, const RequestOrUSVString& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheStorage); if (!HasStorageAccess()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr; } if (NS_WARN_IF(NS_FAILED(mStatus))) { aRv.Throw(mStatus); return nullptr; } RefPtr<InternalRequest> request = ToInternalRequest(aCx, aRequest, IgnoreBody, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<Promise> promise = Promise::Create(mGlobal, aRv); if (NS_WARN_IF(!promise)) { return nullptr; } CacheQueryParams params; ToCacheQueryParams(params, aOptions); nsAutoPtr<Entry> entry(new Entry()); entry->mPromise = promise; entry->mArgs = StorageMatchArgs(CacheRequest(), params, GetOpenMode()); entry->mRequest = request; RunRequest(std::move(entry)); return promise.forget(); }
OGRLayer *OGRPLScenesDataset::GetLayerByName(const char* pszName) { OGRLayer* poLayer = GDALDataset::GetLayerByName(pszName); if( poLayer != NULL ) return poLayer; CPLString osURL; osURL = osBaseURL; osURL += pszName; osURL += "/"; json_object* poObj = RunRequest( (osURL + CPLString("?count=10")).c_str() ); if( poObj == NULL ) return NULL; OGRPLScenesLayer* poPLLayer = new OGRPLScenesLayer(this, pszName, osURL, poObj); papoLayers = (OGRPLScenesLayer**) CPLRealloc(papoLayers, sizeof(OGRPLScenesLayer*) * (nLayers + 1)); papoLayers[nLayers ++] = poPLLayer; json_object_put(poObj); return poPLLayer; }
GDALDataset* OGRPLScenesDataV1Dataset::OpenRasterScene(GDALOpenInfo* poOpenInfo, CPLString osScene, char** papszOptions) { if( !(poOpenInfo->nOpenFlags & GDAL_OF_RASTER) ) { CPLError(CE_Failure, CPLE_AppDefined, "The scene option must only be used with vector access"); return nullptr; } int nActivationTimeout = atoi(CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "ACTIVATION_TIMEOUT", "3600")); for( char** papszIter = papszOptions; papszIter && *papszIter; papszIter ++ ) { char* pszKey = nullptr; const char* pszValue = CPLParseNameValue(*papszIter, &pszKey); if( pszValue != nullptr ) { if( !EQUAL(pszKey, "api_key") && !EQUAL(pszKey, "scene") && !EQUAL(pszKey, "product_type") && !EQUAL(pszKey, "asset") && !EQUAL(pszKey, "catalog") && !EQUAL(pszKey, "itemtypes") && !EQUAL(pszKey, "version") && !EQUAL(pszKey, "follow_links") && !EQUAL(pszKey, "metadata")) { CPLError(CE_Failure, CPLE_NotSupported, "Unsupported option %s", pszKey); CPLFree(pszKey); return nullptr; } CPLFree(pszKey); } } const char* pszCatalog = CSLFetchNameValueDef(papszOptions, "itemtypes", CSLFetchNameValueDef(papszOptions, "catalog", CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "ITEMTYPES", CSLFetchNameValue(poOpenInfo->papszOpenOptions, "CATALOG")))); if( pszCatalog == nullptr ) { CPLError(CE_Failure, CPLE_AppDefined, "Missing catalog"); return nullptr; } const char* pszProductType = CSLFetchNameValueDef(papszOptions, "asset", CSLFetchNameValueDef(papszOptions, "product_type", CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "ASSET", CSLFetchNameValue(poOpenInfo->papszOpenOptions, "PRODUCT_TYPE")))); CPLString osRasterURL; osRasterURL = m_osBaseURL; osRasterURL += "item-types/"; osRasterURL += pszCatalog; osRasterURL += "/items/"; osRasterURL += osScene; osRasterURL += "/assets/"; time_t nStartTime = time(nullptr); retry: time_t nCurrentTime = time(nullptr); if( nCurrentTime - nStartTime > nActivationTimeout ) { CPLError(CE_Failure, CPLE_AppDefined, "Activation timeout reached"); return nullptr; } json_object* poObj = RunRequest( osRasterURL ); if( poObj == nullptr ) return nullptr; json_object* poSubObj = nullptr; if( pszProductType != nullptr && (poSubObj = CPL_json_object_object_get(poObj, pszProductType)) != nullptr ) { /* do nothing */ } else if( pszProductType != nullptr && !EQUAL(pszProductType, "LIST") && (poSubObj = CPL_json_object_object_get(poObj, pszProductType)) == nullptr ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot find asset %s", pszProductType); json_object_put(poObj); return nullptr; } else if( pszProductType == nullptr && (poSubObj = CPL_json_object_object_get(poObj, "visual")) != nullptr ) { /* do nothing */ } else { json_object_iter it; it.key = nullptr; it.val = nullptr; it.entry = nullptr; char** papszSubdatasets = nullptr; int nSubDataset = 0; json_object_object_foreachC( poObj, it ) { ++nSubDataset; papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_NAME", nSubDataset), CPLSPrintf("Scene=%s of item types %s, asset %s", osScene.c_str(), pszCatalog, it.key)); papszSubdatasets = CSLSetNameValue(papszSubdatasets, CPLSPrintf("SUBDATASET_%d_DESC", nSubDataset), CPLSPrintf("PLScenes:version=Data_V1,itemtypes=%s,scene=%s,asset=%s", pszCatalog, osScene.c_str(), it.key)); } json_object_put(poObj); if( nSubDataset != 0 ) { GDALDataset* poDS = new OGRPLScenesDataV1Dataset(); poDS->SetMetadata(papszSubdatasets, "SUBDATASETS"); CSLDestroy(papszSubdatasets); return poDS; } return nullptr; }
GDALDataset* OGRPLScenesDataset::OpenRasterScene(GDALOpenInfo* poOpenInfo, CPLString osScene, char** papszOptions) { if( !(poOpenInfo->nOpenFlags & GDAL_OF_RASTER) ) { return NULL; } for( char** papszIter = papszOptions; papszIter && *papszIter; papszIter ++ ) { char* pszKey; const char* pszValue = CPLParseNameValue(*papszIter, &pszKey); if( pszValue != NULL ) { if( !EQUAL(pszKey, "api_key") && !EQUAL(pszKey, "scene") && !EQUAL(pszKey, "product_type") ) { CPLError(CE_Failure, CPLE_NotSupported, "Unsupported option %s", pszKey); CPLFree(pszKey); return NULL; } CPLFree(pszKey); } } const char* pszProductType = CSLFetchNameValueDef(papszOptions, "product_type", CSLFetchNameValueDef(poOpenInfo->papszOpenOptions, "PRODUCT_TYPE", "visual")); CPLString osRasterURL; osRasterURL = osBaseURL; osRasterURL += "ortho/"; osRasterURL += osScene; json_object* poObj = RunRequest( osRasterURL ); if( poObj == NULL ) return NULL; json_object* poProperties = json_object_object_get(poObj, "properties"); if( poProperties == NULL || json_object_get_type(poProperties) != json_type_object ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot find properties object"); json_object_put(poObj); return NULL; } const char* pszLink = NULL; if( EQUAL(pszProductType, "thumb") ) { json_object* poLinks = json_object_object_get(poProperties, "links"); if( poLinks != NULL && json_object_get_type(poLinks) == json_type_object ) { json_object* poThumbnail = json_object_object_get(poLinks, "thumbnail"); if( poThumbnail && json_object_get_type(poThumbnail) == json_type_string ) pszLink = json_object_get_string(poThumbnail); } } else { json_object* poData = json_object_object_get(poProperties, "data"); if( poData != NULL && json_object_get_type(poData) == json_type_object ) { json_object* poProducts = json_object_object_get(poData, "products"); if( poProducts != NULL && json_object_get_type(poProducts) == json_type_object ) { json_object* poProduct = json_object_object_get(poProducts, pszProductType); if( poProduct != NULL && json_object_get_type(poProduct) == json_type_object ) { json_object* poFull = json_object_object_get(poProduct, "full"); if( poFull && json_object_get_type(poFull) == json_type_string ) pszLink = json_object_get_string(poFull); } } } } osRasterURL = pszLink ? pszLink : ""; json_object_put(poObj); if( osRasterURL.size() == 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot find link to scene %s", osScene.c_str()); return NULL; } if( strncmp(osRasterURL, "http://", strlen("http://")) == 0 ) { osRasterURL = "http://" + osAPIKey + ":@" + osRasterURL.substr(strlen("http://")); } else if( strncmp(osRasterURL, "https://", strlen("https://")) == 0 ) { osRasterURL = "https://" + osAPIKey + ":@" + osRasterURL.substr(strlen("https://")); } CPLString osOldHead(CPLGetConfigOption("CPL_VSIL_CURL_USE_HEAD", "")); CPLString osOldExt(CPLGetConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", "")); int bUseVSICURL = CSLFetchBoolean(poOpenInfo->papszOpenOptions, "RANDOM_ACCESS", TRUE); if( bUseVSICURL && !(strncmp(osBaseURL, "/vsimem/", strlen("/vsimem/")) == 0) ) { CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD", "NO"); CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", "{noext}"); VSIStatBufL sStat; if( VSIStatL(("/vsicurl/" + osRasterURL).c_str(), &sStat) == 0 && sStat.st_size > 0 ) { osRasterURL = "/vsicurl/" + osRasterURL; } else { CPLDebug("PLSCENES", "Cannot use random access for that file"); } } GDALDataset* poOutDS = (GDALDataset*) GDALOpen(osRasterURL, GA_ReadOnly); if( poOutDS ) { poOutDS->SetDescription(poOpenInfo->pszFilename); poOutDS->GetFileList(); /* so as to probe all auxiliary files before reseting the allowed extensions */ if( !EQUAL(pszProductType, "thumb") ) { OGRPLScenesLayer* poLayer = new OGRPLScenesLayer(this, "ortho", (osBaseURL + "ortho/").c_str()); papoLayers = (OGRPLScenesLayer**) CPLRealloc(papoLayers, sizeof(OGRPLScenesLayer*) * (nLayers + 1)); papoLayers[nLayers ++] = poLayer; /* Attach scene matadata */ poLayer->SetAttributeFilter(CPLSPrintf("id = '%s'", osScene.c_str())); OGRFeature* poFeat = poLayer->GetNextFeature(); if( poFeat ) { for(int i=0;i<poFeat->GetFieldCount();i++) { if( poFeat->IsFieldSet(i) ) { const char* pszKey = poFeat->GetFieldDefnRef(i)->GetNameRef(); const char* pszVal = poFeat->GetFieldAsString(i); if( strstr(pszKey, "file_size") == NULL && strstr(pszVal, "https://") == NULL ) { poOutDS->SetMetadataItem(pszKey, pszVal); } } } } delete poFeat; } } if( bUseVSICURL ) { CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_USE_HEAD", osOldHead.size() ? osOldHead.c_str(): NULL); CPLSetThreadLocalConfigOption("CPL_VSIL_CURL_ALLOWED_EXTENSIONS", osOldExt.size() ? osOldExt.c_str(): NULL); } return poOutDS; }