void ImageDecoderQt::setData(const IncomingData &data, bool allDataReceived) { reset(); ReadContext readContext(data, ReadContext::LoadComplete, m_imageList); if (debugImageDecoderQt) qDebug() << " setData " << data.size() << " image bytes, complete=" << allDataReceived; const ReadContext::ReadResult readResult = readContext.read(allDataReceived); if (debugImageDecoderQt) qDebug() << " read returns " << readResult; switch ( readResult) { case ReadContext::ReadFailed: m_failed = true; break; case ReadContext::ReadEOF: case ReadContext::ReadPartial: case ReadContext::ReadComplete: // Did we read anything - try to set the size. if (hasFirstImageHeader()) { m_sizeAvailable = true; m_size = m_imageList[0].m_image.size(); } break; } }
DataSet DataSet::readTADMDataSet(istream &iss) { string line; ContextVector contexts; while (iss) { // Would really like to avoid reading the context here, // so try to detect EOF. if (iss.peek() == EOF) break; contexts.push_back(readContext(iss)); } return DataSet(contexts); }
static Type readType(FILE *f) { Context hypos = readContext(f); CId cat = readCId(f); int i; int count = readInt(f); Type ty = (Type) malloc(sizeof(struct _Type)+count*sizeof(Expr)); ty->hypos = hypos; ty->cat = cat; ty->nArgs = count; for (i = 0; i < count; i++) { ty->args[i] = readExpr(f); } return ty; }
ScriptCached *CacheReader::readCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *S) { // Check file handle if (!objFile || objFile->getFD() < 0 || !infoFile || infoFile->getFD() < 0) { return NULL; } mObjFile = objFile; mInfoFile = infoFile; // Allocate ScriptCached object mpResult.reset(new (nothrow) ScriptCached(S)); if (!mpResult) { LOGE("Unable to allocate ScriptCached object.\n"); return NULL; } bool result = checkFileSize() && readHeader() && checkHeader() && checkMachineIntType() && checkSectionOffsetAndSize() && readStringPool() && checkStringPool() && readDependencyTable() && checkDependency() && readExportVarList() && readExportFuncList() && readPragmaList() && readFuncTable() && readObjectSlotList() && readContext() && checkContext() //&& readRelocationTable() //&& relocate() ; return result ? mpResult.take() : NULL; }
void ImageDecoderQt::setData(const IncomingData &data, bool allDataReceived) { reset(); ReadContext readContext(data, ReadContext::LoadComplete, m_imageList); if (debugImageDecoderQt) qDebug() << " setData " << data.size() << " image bytes, complete=" << allDataReceived; const ReadContext::ReadResult readResult = readContext.read(allDataReceived); if (hasFirstImageHeader()) m_hasAlphaChannel = m_imageList[0].m_image.hasAlphaChannel(); if (debugImageDecoderQt) qDebug() << " read returns " << readResult; switch ( readResult) { case ReadContext::ReadFailed: m_failed = true; break; case ReadContext::ReadEOF: case ReadContext::ReadPartial: case ReadContext::ReadComplete: // Did we read anything - try to set the size. if (hasFirstImageHeader()) { m_sizeAvailable = true; m_size = m_imageList[0].m_image.size(); if (readContext.reader()->supportsAnimation()) { if (readContext.reader()->loopCount() != -1) m_loopCount = readContext.reader()->loopCount(); else m_loopCount = 0; //loop forever } } break; } }
virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool fromRepl = false ) { // --- parse NamespaceString ns( dbname, cmdObj[name].String() ); Status status = userAllowedWriteNS( ns ); if ( !status.isOK() ) return appendCommandStatus( result, status ); if ( cmdObj["indexes"].type() != Array ) { errmsg = "indexes has to be an array"; result.append( "cmdObj", cmdObj ); return false; } std::vector<BSONObj> specs; { BSONObjIterator i( cmdObj["indexes"].Obj() ); while ( i.more() ) { BSONElement e = i.next(); if ( e.type() != Object ) { errmsg = "everything in indexes has to be an Object"; result.append( "cmdObj", cmdObj ); return false; } specs.push_back( e.Obj() ); } } if ( specs.size() == 0 ) { errmsg = "no indexes to add"; return false; } // check specs for ( size_t i = 0; i < specs.size(); i++ ) { BSONObj spec = specs[i]; if ( spec["ns"].eoo() ) { spec = _addNsToSpec( ns, spec ); specs[i] = spec; } if ( spec["ns"].type() != String ) { errmsg = "spec has no ns"; result.append( "spec", spec ); return false; } if ( ns != spec["ns"].String() ) { errmsg = "namespace mismatch"; result.append( "spec", spec ); return false; } } { // We first take a read lock to see if we need to do anything // as many calls are ensureIndex (and hence no-ops), this is good so its a shared // lock for common calls. We only take write lock if needed. // Note: createIndexes command does not currently respect shard versioning. Client::ReadContext readContext( ns, storageGlobalParams.dbpath, false /* doVersion */ ); const Collection* collection = readContext.ctx().db()->getCollection( ns.ns() ); if ( collection ) { for ( size_t i = 0; i < specs.size(); i++ ) { BSONObj spec = specs[i]; StatusWith<BSONObj> statusWithSpec = collection->getIndexCatalog()->prepareSpecForCreate( spec ); status = statusWithSpec.getStatus(); if ( status.code() == ErrorCodes::IndexAlreadyExists ) { specs.erase( specs.begin() + i ); i--; continue; } if ( !status.isOK() ) return appendCommandStatus( result, status ); } if ( specs.size() == 0 ) { result.append( "numIndexesBefore", collection->getIndexCatalog()->numIndexesTotal() ); result.append( "note", "all indexes already exist" ); return true; } // need to create index } } // now we know we have to create index(es) // Note: createIndexes command does not currently respect shard versioning. Client::WriteContext writeContext( ns.ns(), storageGlobalParams.dbpath, false /* doVersion */ ); Database* db = writeContext.ctx().db(); Collection* collection = db->getCollection( txn, ns.ns() ); result.appendBool( "createdCollectionAutomatically", collection == NULL ); if ( !collection ) { collection = db->createCollection( txn, ns.ns() ); invariant( collection ); } result.append( "numIndexesBefore", collection->getIndexCatalog()->numIndexesTotal() ); for ( size_t i = 0; i < specs.size(); i++ ) { BSONObj spec = specs[i]; if ( spec["unique"].trueValue() ) { status = checkUniqueIndexConstraints( ns.ns(), spec["key"].Obj() ); if ( !status.isOK() ) { appendCommandStatus( result, status ); return false; } } status = collection->getIndexCatalog()->createIndex(txn, spec, true); if ( status.code() == ErrorCodes::IndexAlreadyExists ) { if ( !result.hasField( "note" ) ) result.append( "note", "index already exists" ); continue; } if ( !status.isOK() ) { appendCommandStatus( result, status ); return false; } if ( !fromRepl ) { std::string systemIndexes = ns.getSystemIndexesCollection(); repl::logOp(txn, "i", systemIndexes.c_str(), spec); } } result.append( "numIndexesAfter", collection->getIndexCatalog()->numIndexesTotal() ); return true; }
static int listBal(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; const char *ctxFile; const char *outFile; AB_IMEXPORTER_CONTEXT *ctx=0; AB_IMEXPORTER_ACCOUNTINFO *iea=0; const char *bankId; const char *accountId; const char *bankName; const char *accountName; FILE *f; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankId", /* name */ 0, /* minnum */ 1, /* maxnum */ "b", /* short option */ "bank", /* long option */ "Specify the bank code", /* short description */ "Specify the bank code" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "Specify the account number", /* short description */ "Specify the account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankName", /* name */ 0, /* minnum */ 1, /* maxnum */ "N", /* short option */ "bankname", /* long option */ "Specify the bank name", /* short description */ "Specify the bank name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountName", /* name */ 0, /* minnum */ 1, /* maxnum */ "n", /* short option */ "accountname", /* long option */ "Specify the account name", /* short description */ "Specify the account name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "ctxFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "c", /* short option */ "ctxfile", /* long option */ "Specify the file to store the context in", /* short description */ "Specify the file to store the context in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify the file to store the data in", /* short description */ "Specify the file to store the data in" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0); bankName=GWEN_DB_GetCharValue(db, "bankName", 0, 0); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0); accountName=GWEN_DB_GetCharValue(db, "accountName", 0, 0); rv=AB_Banking_Init(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0); rv=readContext(ctxFile, &ctx, 1); if (rv<0) { DBG_ERROR(0, "Error reading context (%d)", rv); return 4; } /* open output stream */ outFile=GWEN_DB_GetCharValue(db, "outFile", 0, 0); if (outFile==0) f=stdout; else f=fopen(outFile, "w+"); if (f==0) { DBG_ERROR(0, "Error selecting output file: %s", strerror(errno)); return 4; } iea=AB_ImExporterContext_GetFirstAccountInfo(ctx); while(iea) { int matches=1; const char *s; if (matches && bankId) { s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankId, 0)) matches=0; } if (matches && bankName) { s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s) s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankName, 0)) matches=0; } if (matches && accountId) { s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountId, 0)) matches=0; } if (matches && accountName) { s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s) s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountName, 0)) matches=0; } if (matches) { AB_ACCOUNT_STATUS *ast; ast=_getLastAccountStatus(iea); if (ast) { const GWEN_TIME *ti; const char *s; fprintf(f, "Account\t"); s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s) s=""; fprintf(f, "%s\t", s); s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s) s=""; fprintf(f, "%s\t", s); ti=AB_AccountStatus_GetTime(ast); _dumpBal(AB_AccountStatus_GetBookedBalance(ast), ti, f); _dumpBal(AB_AccountStatus_GetNotedBalance(ast), ti, f); fprintf(f, "\n"); } } /* if matches */ iea=AB_ImExporterContext_GetNextAccountInfo(ctx); } /* while */ if (outFile) { if (fclose(f)) { DBG_ERROR(0, "Error closing output file: %s", strerror(errno)); return 4; } } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
static void readAbsCat(FILE *f, AbsCat cat) { cat->name = readCId(f); cat->hypos = readContext(f); cat->funs = readCIdList(f); }
Status MMAPV1Engine::repairDatabase( OperationContext* txn, const std::string& dbName, bool preserveClonedFilesOnFailure, bool backupOriginalFiles ) { // We must hold some form of lock here invariant(txn->lockState()->threadState()); invariant( dbName.find( '.' ) == string::npos ); scoped_ptr<RepairFileDeleter> repairFileDeleter; log() << "repairDatabase " << dbName << endl; BackgroundOperation::assertNoBgOpInProgForDb(dbName); txn->recoveryUnit()->syncDataAndTruncateJournal(); // Must be done before and after repair intmax_t totalSize = dbSize( dbName ); intmax_t freeSize = File::freeSpace(storageGlobalParams.repairpath); if ( freeSize > -1 && freeSize < totalSize ) { return Status( ErrorCodes::OutOfDiskSpace, str::stream() << "Cannot repair database " << dbName << " having size: " << totalSize << " (bytes) because free disk space is: " << freeSize << " (bytes)" ); } txn->checkForInterrupt(); Path reservedPath = uniqueReservedPath( ( preserveClonedFilesOnFailure || backupOriginalFiles ) ? "backup" : "_tmp" ); MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::create_directory( reservedPath ) ); string reservedPathString = reservedPath.string(); if ( !preserveClonedFilesOnFailure ) repairFileDeleter.reset( new RepairFileDeleter( txn, dbName, reservedPathString, reservedPath ) ); { Database* originalDatabase = dbHolder().get(txn, dbName); if (originalDatabase == NULL) { return Status(ErrorCodes::NamespaceNotFound, "database does not exist to repair"); } scoped_ptr<MMAPV1DatabaseCatalogEntry> dbEntry; scoped_ptr<Database> tempDatabase; { dbEntry.reset( new MMAPV1DatabaseCatalogEntry( txn, dbName, reservedPathString, storageGlobalParams.directoryperdb, true ) ); invariant( !dbEntry->exists() ); tempDatabase.reset( new Database( txn, dbName, dbEntry.get() ) ); } map<string,CollectionOptions> namespacesToCopy; { string ns = dbName + ".system.namespaces"; Client::Context ctx(txn, ns ); Collection* coll = originalDatabase->getCollection( txn, ns ); if ( coll ) { scoped_ptr<RecordIterator> it( coll->getIterator( txn, DiskLoc(), false, CollectionScanParams::FORWARD ) ); while ( !it->isEOF() ) { DiskLoc loc = it->getNext(); BSONObj obj = coll->docFor( loc ); string ns = obj["name"].String(); NamespaceString nss( ns ); if ( nss.isSystem() ) { if ( nss.isSystemDotIndexes() ) continue; if ( nss.coll() == "system.namespaces" ) continue; } if ( !nss.isNormal() ) continue; CollectionOptions options; if ( obj["options"].isABSONObj() ) { Status status = options.parse( obj["options"].Obj() ); if ( !status.isOK() ) return status; } namespacesToCopy[ns] = options; } } } for ( map<string,CollectionOptions>::const_iterator i = namespacesToCopy.begin(); i != namespacesToCopy.end(); ++i ) { string ns = i->first; CollectionOptions options = i->second; Collection* tempCollection = NULL; { Client::Context tempContext(txn, ns, tempDatabase ); WriteUnitOfWork wunit(txn); tempCollection = tempDatabase->createCollection(txn, ns, options, true, false); wunit.commit(); } Client::Context readContext(txn, ns, originalDatabase); Collection* originalCollection = originalDatabase->getCollection( txn, ns ); invariant( originalCollection ); // data // TODO SERVER-14812 add a mode that drops duplicates rather than failing MultiIndexBlock indexer(txn, tempCollection ); { vector<BSONObj> indexes; IndexCatalog::IndexIterator ii = originalCollection->getIndexCatalog()->getIndexIterator( false ); while ( ii.more() ) { IndexDescriptor* desc = ii.next(); indexes.push_back( desc->infoObj() ); } Client::Context tempContext(txn, ns, tempDatabase); Status status = indexer.init( indexes ); if ( !status.isOK() ) return status; } scoped_ptr<RecordIterator> iterator( originalCollection->getIterator( txn, DiskLoc(), false, CollectionScanParams::FORWARD )); while ( !iterator->isEOF() ) { DiskLoc loc = iterator->getNext(); invariant( !loc.isNull() ); BSONObj doc = originalCollection->docFor( loc ); Client::Context tempContext(txn, ns, tempDatabase); WriteUnitOfWork wunit(txn); StatusWith<DiskLoc> result = tempCollection->insertDocument(txn, doc, &indexer, false); if ( !result.isOK() ) return result.getStatus(); wunit.commit(); txn->checkForInterrupt(false); } Status status = indexer.doneInserting(); if (!status.isOK()) return status; { Client::Context tempContext(txn, ns, tempDatabase); WriteUnitOfWork wunit(txn); indexer.commit(); wunit.commit(); } } txn->recoveryUnit()->syncDataAndTruncateJournal(); globalStorageEngine->flushAllFiles(true); // need both in case journaling is disabled txn->checkForInterrupt(false); } // at this point if we abort, we don't want to delete new files // as they might be the only copies if ( repairFileDeleter.get() ) repairFileDeleter->success(); dbHolder().close( txn, dbName ); if ( backupOriginalFiles ) { _renameForBackup( dbName, reservedPath ); } else { // first make new directory before deleting data Path newDir = Path(storageGlobalParams.dbpath) / dbName; MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); // this deletes old files _deleteDataFiles( dbName ); if ( !boost::filesystem::exists(newDir) ) { // we deleted because of directoryperdb // re-create MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); } } _replaceWithRecovered( dbName, reservedPathString.c_str() ); if ( !backupOriginalFiles ) MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::remove_all( reservedPath ) ); return Status::OK(); }
int listBal(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; const char *ctxFile; AB_IMEXPORTER_CONTEXT *ctx=0; AB_IMEXPORTER_ACCOUNTINFO *iea=0; uint32_t aid; const char *bankId; const char *accountId; const char *subAccountId; const char *iban; const char *tmplString; const char *s; AB_BALANCE_TYPE bt=AB_Balance_TypeBooked; /* parse command line arguments */ db=_readCommandLine(dbArgs, argc, argv); if (db==NULL) { /* error in command line */ return 1; } /* read command line arguments */ aid=(uint32_t)GWEN_DB_GetIntValue(db, "uniqueAccountId", 0, 0); bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0); subAccountId=GWEN_DB_GetCharValue(db, "subAccountId", 0, 0); iban=GWEN_DB_GetCharValue(db, "iban", 0, 0); tmplString=GWEN_DB_GetCharValue(db, "template", 0, "$(dateAsString)\t" "$(valueAsString)\t" "$(iban)"); /* determine balance type */ s=GWEN_DB_GetCharValue(db, "balanceType", 0, "noted"); if (s && *s) { AB_BALANCE_TYPE tempBalanceType; tempBalanceType=AB_Balance_Type_fromString(s); if (tempBalanceType==AB_Balance_TypeUnknown) { DBG_ERROR(0, "Invalid balance type given (%s)", s); return 1; } bt=tempBalanceType; } /* init AqBanking */ rv=AB_Banking_Init(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } /* load ctx file */ ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0); rv=readContext(ctxFile, &ctx, 1); if (rv<0) { DBG_ERROR(0, "Error reading context (%d)", rv); AB_ImExporterContext_free(ctx); return 4; } /* copy context, but only keep wanted accounts and transactions */ iea=AB_ImExporterContext_GetFirstAccountInfo(ctx); while (iea) { if (AB_ImExporterAccountInfo_Matches(iea, aid, /* unique account id */ "*", bankId, accountId, subAccountId, iban, "*", /* currency */ AB_AccountType_Unknown)) { AB_BALANCE *bal; GWEN_DB_NODE *dbAccount; const char *s; dbAccount=GWEN_DB_Group_new("dbAccount"); s=AB_ImExporterAccountInfo_GetBankCode(iea); if (s && *s) GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "bankCode", s); s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (s && *s) GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "accountNumber", s); s=AB_ImExporterAccountInfo_GetBic(iea); if (s && *s) GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "bic", s); s=AB_ImExporterAccountInfo_GetIban(iea); if (s && *s) GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "iban", s); bal=AB_Balance_List_GetLatestByType(AB_ImExporterAccountInfo_GetBalanceList(iea), bt); if (bal) { GWEN_DB_NODE *dbElement; const AB_VALUE *v; const GWEN_DATE *dt; GWEN_BUFFER *dbuf; dbElement=GWEN_DB_Group_dup(dbAccount); AB_Balance_toDb(bal, dbElement); /* translate value */ dbuf=GWEN_Buffer_new(0, 256, 0, 1); v=AB_Balance_GetValue(bal); if (v) { AB_Value_toHumanReadableString(v, dbuf, 2, 0); GWEN_DB_SetCharValue(dbElement, GWEN_DB_FLAGS_OVERWRITE_VARS, "valueAsString", GWEN_Buffer_GetStart(dbuf)); GWEN_Buffer_Reset(dbuf); } /* translate date */ dt=AB_Balance_GetDate(bal); if (dt) { rv=GWEN_Date_toStringWithTemplate(dt, I18N("DD.MM.YYYY"), dbuf); if (rv>=0) { GWEN_DB_SetCharValue(dbElement, GWEN_DB_FLAGS_OVERWRITE_VARS, "dateAsString", GWEN_Buffer_GetStart(dbuf)); } GWEN_Buffer_Reset(dbuf); } GWEN_DB_ReplaceVars(dbElement, tmplString, dbuf); fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(dbuf)); GWEN_Buffer_free(dbuf); GWEN_DB_Group_free(dbElement); } /* if bal */ GWEN_DB_Group_free(dbAccount); } /* if account matches */ iea=AB_ImExporterAccountInfo_List_Next(iea); } /* while */ AB_ImExporterContext_free(ctx); /* deinit */ rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
Status repairDatabase( string dbName, bool preserveClonedFilesOnFailure, bool backupOriginalFiles ) { scoped_ptr<RepairFileDeleter> repairFileDeleter; doingRepair dr; dbName = nsToDatabase( dbName ); log() << "repairDatabase " << dbName << endl; invariant( cc().database()->name() == dbName ); invariant( cc().database()->path() == storageGlobalParams.dbpath ); BackgroundOperation::assertNoBgOpInProgForDb(dbName); getDur().syncDataAndTruncateJournal(); // Must be done before and after repair intmax_t totalSize = dbSize( dbName ); intmax_t freeSize = File::freeSpace(storageGlobalParams.repairpath); if ( freeSize > -1 && freeSize < totalSize ) { return Status( ErrorCodes::OutOfDiskSpace, str::stream() << "Cannot repair database " << dbName << " having size: " << totalSize << " (bytes) because free disk space is: " << freeSize << " (bytes)" ); } killCurrentOp.checkForInterrupt(); Path reservedPath = uniqueReservedPath( ( preserveClonedFilesOnFailure || backupOriginalFiles ) ? "backup" : "_tmp" ); MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::create_directory( reservedPath ) ); string reservedPathString = reservedPath.string(); if ( !preserveClonedFilesOnFailure ) repairFileDeleter.reset( new RepairFileDeleter( dbName, reservedPathString, reservedPath ) ); { Database* originalDatabase = dbHolder().get( dbName, storageGlobalParams.dbpath ); if ( originalDatabase == NULL ) return Status( ErrorCodes::NamespaceNotFound, "database does not exist to repair" ); Database* tempDatabase = NULL; { bool justCreated = false; tempDatabase = dbHolderW().getOrCreate( dbName, reservedPathString, justCreated ); invariant( justCreated ); } map<string,CollectionOptions> namespacesToCopy; { string ns = dbName + ".system.namespaces"; Client::Context ctx( ns ); Collection* coll = originalDatabase->getCollection( ns ); if ( coll ) { scoped_ptr<CollectionIterator> it( coll->getIterator( DiskLoc(), false, CollectionScanParams::FORWARD ) ); while ( !it->isEOF() ) { DiskLoc loc = it->getNext(); BSONObj obj = coll->docFor( loc ); string ns = obj["name"].String(); NamespaceString nss( ns ); if ( nss.isSystem() ) { if ( nss.isSystemDotIndexes() ) continue; if ( nss.coll() == "system.namespaces" ) continue; } if ( !nss.isNormal() ) continue; CollectionOptions options; if ( obj["options"].isABSONObj() ) { Status status = options.parse( obj["options"].Obj() ); if ( !status.isOK() ) return status; } namespacesToCopy[ns] = options; } } } for ( map<string,CollectionOptions>::const_iterator i = namespacesToCopy.begin(); i != namespacesToCopy.end(); ++i ) { string ns = i->first; CollectionOptions options = i->second; Collection* tempCollection = NULL; { Client::Context tempContext( ns, tempDatabase ); tempCollection = tempDatabase->createCollection( ns, options, true, false ); } Client::Context readContext( ns, originalDatabase ); Collection* originalCollection = originalDatabase->getCollection( ns ); invariant( originalCollection ); // data MultiIndexBlock indexBlock( tempCollection ); { vector<BSONObj> indexes; IndexCatalog::IndexIterator ii = originalCollection->getIndexCatalog()->getIndexIterator( false ); while ( ii.more() ) { IndexDescriptor* desc = ii.next(); indexes.push_back( desc->infoObj() ); } Client::Context tempContext( ns, tempDatabase ); Status status = indexBlock.init( indexes ); if ( !status.isOK() ) return status; } scoped_ptr<CollectionIterator> iterator( originalCollection->getIterator( DiskLoc(), false, CollectionScanParams::FORWARD ) ); while ( !iterator->isEOF() ) { DiskLoc loc = iterator->getNext(); invariant( !loc.isNull() ); BSONObj doc = originalCollection->docFor( loc ); Client::Context tempContext( ns, tempDatabase ); StatusWith<DiskLoc> result = tempCollection->insertDocument( doc, indexBlock ); if ( !result.isOK() ) return result.getStatus(); getDur().commitIfNeeded(); killCurrentOp.checkForInterrupt(false); } { Client::Context tempContext( ns, tempDatabase ); Status status = indexBlock.commit(); if ( !status.isOK() ) return status; } } getDur().syncDataAndTruncateJournal(); MongoFile::flushAll(true); // need both in case journaling is disabled killCurrentOp.checkForInterrupt(false); Client::Context tempContext( dbName, reservedPathString ); Database::closeDatabase( dbName, reservedPathString ); } // at this point if we abort, we don't want to delete new files // as they might be the only copies if ( repairFileDeleter.get() ) repairFileDeleter->success(); Client::Context ctx( dbName ); Database::closeDatabase(dbName, storageGlobalParams.dbpath); if ( backupOriginalFiles ) { _renameForBackup( dbName, reservedPath ); } else { // first make new directory before deleting data Path newDir = Path(storageGlobalParams.dbpath) / dbName; MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); // this deletes old files _deleteDataFiles( dbName ); if ( !boost::filesystem::exists(newDir) ) { // we deleted because of directoryperdb // re-create MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); } } _replaceWithRecovered( dbName, reservedPathString.c_str() ); if ( !backupOriginalFiles ) MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::remove_all( reservedPath ) ); return Status::OK(); }
static int addTransaction(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; AB_JOB_TYPE transferType; const char *ctxFile; const char *bankId; const char *accountId; const char *subAccountId; AB_IMEXPORTER_CONTEXT *ctx=0; AB_ACCOUNT_LIST2 *al; AB_ACCOUNT *a; AB_TRANSACTION *t; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "ctxFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "c", /* short option */ "ctxfile", /* long option */ "Specify the file to store the context in", /* short description */ "Specify the file to store the context in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankId", /* name */ 0, /* minnum */ 1, /* maxnum */ "b", /* short option */ "bank", /* long option */ "overwrite the bank code", /* short description */ "overwrite the bank code" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "overwrite the account number", /* short description */ "overwrite the account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "subAccountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "aa", /* short option */ "subaccount", /* long option */ "Specify the sub account id (Unterkontomerkmal)", /* short description */ "Specify the sub account id (Unterkontomerkmal)" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "remoteBankId", /* name */ 1, /* minnum */ 1, /* maxnum */ 0, /* short option */ "rbank", /* long option */ "Specify the remote bank code",/* short description */ "Specify the remote bank code" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "remoteAccountId", /* name */ 1, /* minnum */ 1, /* maxnum */ 0, /* short option */ "raccount", /* long option */ "Specify the remote account number", /* short description */ "Specify the remote account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "remoteIban", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "riban", /* long option */ "Specify the remote IBAN", /* short description */ "Specify the remote IBAN" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "remoteBic", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "rbic", /* long option */ "Specify the remote BIC", /* short description */ "Specify the remote BIC" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "value", /* name */ 1, /* minnum */ 1, /* maxnum */ "v", /* short option */ "value", /* long option */ "Specify the transfer amount", /* short description */ "Specify the transfer amount" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Int, /* type */ "textkey", /* name */ 0, /* minnum */ 1, /* maxnum */ "t", /* short option */ "textkey", /* long option */ "Specify the text key (51 for normal transfer)", /* short description */ "Specify the text key (51 for normal transfer)" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "remoteName", /* name */ 1, /* minnum */ 2, /* maxnum */ 0, /* short option */ "rname", /* long option */ "Specify the remote name", /* short description */ "Specify the remote name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "purpose", /* name */ 1, /* minnum */ 6, /* maxnum */ "p", /* short option */ "purpose", /* long option */ "Specify the purpose", /* short description */ "Specify the purpose" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0); subAccountId=GWEN_DB_GetCharValue(db, "subAccountId", 0, 0); rv=AB_Banking_Init(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } rv=AB_Banking_OnlineInit(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } /* get account */ al=AB_Banking_FindAccounts(ab, "*", "*", bankId, accountId, subAccountId); if (al==NULL || AB_Account_List2_GetSize(al)==0) { DBG_ERROR(0, "Account not found"); AB_Account_List2_free(al); return 2; } else if (AB_Account_List2_GetSize(al)>1) { DBG_ERROR(0, "Ambiguous account specification"); AB_Account_List2_free(al); return 2; } a=AB_Account_List2_GetFront(al); AB_Account_List2_free(al); /* create transaction from arguments */ t=mkTransfer(a, db, &transferType); if (t==NULL) { DBG_ERROR(0, "Could not create transaction from arguments"); return 2; } ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0); rv=readContext(ctxFile, &ctx, 0); if (rv<0) { DBG_ERROR(0, "Error reading context (%d)", rv); AB_Transaction_free(t); return 4; } AB_ImExporterContext_AddTransaction(ctx, t); rv=writeContext(ctxFile, ctx); AB_ImExporterContext_free(ctx); if (rv<0) { DBG_ERROR(0, "Error writing context (%d)", rv); return 4; } /* that's it */ rv=AB_Banking_OnlineFini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); AB_Banking_Fini(ab); return 5; } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
SourceContext ResourceManager::readContext(const SourceLocation &location) { return readContext(location, SourceContextReader::MAX_MAX_CONTEXT_LENGTH); }
static int listTrans(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; const char *ctxFile; const char *outFile; const char *exporterName; const char *profileName; const char *profileFile; AB_IMEXPORTER_CONTEXT *ctx=0; AB_IMEXPORTER_CONTEXT *nctx=0; AB_IMEXPORTER_ACCOUNTINFO *iea=0; const char *bankId; const char *accountId; const char *bankName; const char *accountName; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankId", /* name */ 0, /* minnum */ 1, /* maxnum */ "b", /* short option */ "bank", /* long option */ "Specify the bank code", /* short description */ "Specify the bank code" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "Specify the account number", /* short description */ "Specify the account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankName", /* name */ 0, /* minnum */ 1, /* maxnum */ "N", /* short option */ "bankname", /* long option */ "Specify the bank name", /* short description */ "Specify the bank name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountName", /* name */ 0, /* minnum */ 1, /* maxnum */ "n", /* short option */ "accountname", /* long option */ "Specify the account name", /* short description */ "Specify the account name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "ctxFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "c", /* short option */ "ctxfile", /* long option */ "Specify the file to store the context in", /* short description */ "Specify the file to store the context in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify the file to store the data in", /* short description */ "Specify the file to store the data in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "exporterName", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "exporter", /* long option */ "Specify the exporter to use", /* short description */ "Specify the exporter to use" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "profileName", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "profile", /* long option */ "Specify the export profile to use", /* short description */ "Specify the export profile to use" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "profileFile", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "profile-file", /* long option */ "Specify the file to load the export profile from",/* short description */ "Specify the file to load the export profile from" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } exporterName=GWEN_DB_GetCharValue(db, "exporterName", 0, "csv"); profileName=GWEN_DB_GetCharValue(db, "profileName", 0, "default"); profileFile=GWEN_DB_GetCharValue(db, "profileFile", 0, NULL); bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0); bankName=GWEN_DB_GetCharValue(db, "bankName", 0, 0); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0); accountName=GWEN_DB_GetCharValue(db, "accountName", 0, 0); outFile=GWEN_DB_GetCharValue(db, "outFile", 0, 0); rv=AB_Banking_Init(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } /* load ctx file */ ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0); rv=readContext(ctxFile, &ctx, 1); if (rv<0) { DBG_ERROR(0, "Error reading context (%d)", rv); AB_ImExporterContext_free(ctx); return 4; } nctx=AB_ImExporterContext_new(); iea=AB_ImExporterContext_GetFirstAccountInfo(ctx); while(iea) { int matches=1; const char *s; if (matches && bankId) { s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankId, 0)) matches=0; } if (matches && bankName) { s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankName, 0)) matches=0; } if (matches && accountId) { s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountId, 0)) matches=0; } if (matches && accountName) { s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountName, 0)) matches=0; } if (matches) { AB_IMEXPORTER_ACCOUNTINFO *nai; nai=AB_ImExporterAccountInfo_dup(iea); AB_ImExporterContext_AddAccountInfo(nctx, nai); } /* if matches */ iea=AB_ImExporterContext_GetNextAccountInfo(ctx); } /* while */ AB_ImExporterContext_free(ctx); /* export new context */ rv=AB_Banking_ExportToFileWithProfile(ab, exporterName, nctx, profileName, profileFile, outFile); if (rv<0) { DBG_ERROR(0, "Error exporting (%d).", rv); AB_ImExporterContext_free(nctx); return 4; } AB_ImExporterContext_free(nctx); rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
int main(int argc, char** argv) { boost::program_options::options_description options("Usage"); options.add_options() ("gridGraph", boost::program_options::value<int>(), "(int) The dimension of the square grid graph to use.") ("graphFile", boost::program_options::value<std::string>(), "(string) The path to a graphml file. ") ("completeGraph", boost::program_options::value<int>(), "(int) The number of vertices of the complete graph to use. ") ("opProbability", boost::program_options::value<std::string>(), "(float) The probability that an edge is operational") ("seed", boost::program_options::value<int>(), "(int) The random seed used to generate the random graphs") ("pointSize", boost::program_options::value<float>(), "(float) The size of graph vertices. Defaults to 0.1") ("interestVertices", boost::program_options::value<std::vector<int> >()->multitoken(), "(int) The vertices of interest, that should be connected. ") ("help", "Display this message"); #if defined(_WIN32) && defined(_MSC_VER) redirectConsoleOutput(); #endif boost::program_options::variables_map variableMap; try { boost::program_options::store(boost::program_options::parse_command_line(argc, argv, options), variableMap); } catch(boost::program_options::error& ee) { std::cerr << "Error parsing command line arguments: " << ee.what() << std::endl << std::endl; std::cerr << options << std::endl; std::cerr << "Only one of gridGraph, graphFile and completeGraph can be specified" << std::endl; return -1; } if(variableMap.count("help") > 0) { std::cout << options << std::endl; std::cout << "Only one of gridGraph, graphFile and completeGraph can be specified" << std::endl; return 0; } boost::mt19937 randomSource; readSeed(variableMap, randomSource); mpfr_class probability; if(!readProbabilityString(variableMap, probability)) { std::cout << "Please enter a single value for input `opProbability'" << std::endl; return 0; } Context context = Context::emptyContext(); if(!readContext(variableMap, context, probability)) { return 0; } #if defined(_WIN32) registerQTPluginDir(); #endif float pointSize = 0.1f; if(variableMap.count("pointSize") >= 1) { pointSize = variableMap["pointSize"].as<float>(); } QApplication app(argc, argv); observationVisualiser viewer(context, randomSource, pointSize); viewer.show(); app.exec(); return 0; }