TEST_F(VirtualTableTests, test_sqlite3_attach_vtable) { auto table = std::make_shared<sampleTablePlugin>(); table->setName("sample"); //sqlite3* db = nullptr; //sqlite3_open(":memory:", &db); auto dbc = SQLiteDBManager::get(); // Virtual tables require the registry/plugin API to query tables. auto status = tables::attachTableInternal("failed_sample", "(foo INTEGER)", dbc.db()); EXPECT_EQ(status.getCode(), SQLITE_ERROR); // The table attach will complete only when the table name is registered. Registry::add<sampleTablePlugin>("table", "sample"); PluginResponse response; status = Registry::call("table", "sample", {{"action", "columns"}}, response); EXPECT_TRUE(status.ok()); // Use the table name, plugin-generated schema to attach. status = tables::attachTableInternal( "sample", tables::columnDefinition(response), dbc.db()); EXPECT_EQ(status.getCode(), SQLITE_OK); std::string q = "SELECT sql FROM sqlite_temp_master WHERE tbl_name='sample';"; QueryData results; status = queryInternal(q, results, dbc.db()); EXPECT_EQ("CREATE VIRTUAL TABLE sample USING sample(foo INTEGER, bar TEXT)", results[0]["sql"]); }
void PurchaseEditor::addItemToList() { ProductInfo pInfo; Azahar *myDb = new Azahar; myDb->setDatabase(db); bool ok=false; if (ui->editCode->text().isEmpty()) ui->editCode->setFocus(); else if (ui->editDesc->text().isEmpty()) ui->editDesc->setFocus(); else if (ui->editPoints->text().isEmpty()) ui->editPoints->setFocus(); else if (ui->editCost->text().isEmpty()) ui->editCost->setFocus(); else if (ui->editTax->text().isEmpty()) ui->editTax->setFocus(); else if (ui->editFinalPrice->text().isEmpty()) ui->editFinalPrice->setFocus(); else if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") ui->editQty->setFocus(); else if ((ui->editUtility->text().isEmpty() && ui->editFinalPrice->text().isEmpty()) || ui->editFinalPrice->text().toDouble()<=ui->editCost->text().toDouble() ) ui->editFinalPrice->setFocus(); else if (ui->groupBoxedItem->isChecked() && (ui->editItemsPerBox->text().isEmpty() || ui->editItemsPerBox->text()=="0")) ui->editItemsPerBox->setFocus(); else if (ui->groupBoxedItem->isChecked() && (ui->editPricePerBox->text().isEmpty() || ui->editPricePerBox->text()=="0")) ui->editPricePerBox->setFocus(); else ok = true; if (ok) { ProductInfo info = myDb->getProductInfo( QString::number( getCode() ) ); //FIX BUG: dont allow enter new products.. dont know why? new code on 'continue' statement. if (info.code == 0) { //new product info.code = getCode(); info.stockqty = 0; //new product info.lastProviderId=1; //for now.. fixme in the future } //update p.info from the dialog info.desc = getDescription(); info.price = getPrice(); info.cost = getCost(); info.tax = getTax1(); info.extratax= getTax2(); info.photo = getPhotoBA(); info.units = getMeasureId(); info.category= getCategoryId(); info.utility = getProfit(); info.points = getPoints(); info.purchaseQty = getPurchaseQty(); info.validDiscount = productExists; //used to check if product is already on db. if (info.isAGroup) { // get each product fo the group/pack QStringList list = gelem.split(","); for (int i=0; i<list.count(); ++i) { QStringList tmp = list.at(i).split("/"); if (tmp.count() == 2) { //ok 2 fields qulonglong code = tmp.at(0).toULongLong(); pInfo = myDb->getProductInfo(QString::number(code)); pInfo.purchaseQty = getPurchaseQty(); pInfo.validDiscount = true; // all grouped products exists insertProduct(pInfo); ///inserting each product of the group } // correct fields }//for each element } else insertProduct(info); resetEdits(); ui->editCode->setFocus(); } }
/* Most resource in the banks are compacted. */ bool Bank::unpack() { _unpCtx.size = 0; _unpCtx.datasize = READ_BE_UINT32(_iBuf); _iBuf -= 4; _oBuf = _startBuf + _unpCtx.datasize - 1; _unpCtx.crc = READ_BE_UINT32(_iBuf); _iBuf -= 4; _unpCtx.chk = READ_BE_UINT32(_iBuf); _iBuf -= 4; _unpCtx.crc ^= _unpCtx.chk; do { if (!nextChunk()) { _unpCtx.size = 1; if (!nextChunk()) { decUnk1(3, 0); } else { decUnk2(8); } } else { uint16_t c = getCode(2); if (c == 3) { decUnk1(8, 8); } else { if (c < 2) { _unpCtx.size = c + 2; decUnk2(c + 9); } else { _unpCtx.size = getCode(8); decUnk2(12); } } } } while (_unpCtx.datasize > 0); return (_unpCtx.crc == 0); }
TEST_F(VirtualTableTests, test_sqlite3_attach_vtable) { auto table = std::make_shared<sampleTablePlugin>(); table->setName("sample"); // Request a managed "connection". // This will be a single (potentially locked) instance or a transient // SQLite database if there is contention and a lock was not requested. auto dbc = SQLiteDBManager::get(); // Virtual tables require the registry/plugin API to query tables. auto status = attachTableInternal("failed_sample", "(foo INTEGER)", dbc.db()); EXPECT_EQ(status.getCode(), SQLITE_ERROR); // The table attach will complete only when the table name is registered. Registry::add<sampleTablePlugin>("table", "sample"); PluginResponse response; status = Registry::call("table", "sample", {{"action", "columns"}}, response); EXPECT_TRUE(status.ok()); // Use the table name, plugin-generated schema to attach. status = attachTableInternal("sample", columnDefinition(response), dbc.db()); EXPECT_EQ(status.getCode(), SQLITE_OK); std::string q = "SELECT sql FROM sqlite_temp_master WHERE tbl_name='sample';"; QueryData results; status = queryInternal(q, results, dbc.db()); EXPECT_EQ( "CREATE VIRTUAL TABLE sample USING sample(`foo` INTEGER, `bar` TEXT)", results[0]["sql"]); }
rsXSDExtension* RSSmoothing::createSmoothingToolXSDExtension() { rsXSDExtension* toolExtension = (rsXSDExtension*)malloc(sizeof(rsXSDExtension)); toolExtension->name = getCode(); toolExtension->file = RSTOOLS_DATA_DIR "/" PACKAGE "/jobs/plugins/rssmoothing.xsdext"; toolExtension->type = getCode(); return toolExtension; }
rsXSDExtension* RSCorrelation::createCorrelationToolXSDExtension() { rsXSDExtension* toolExtension = (rsXSDExtension*)malloc(sizeof(rsXSDExtension)); toolExtension->name = getCode(); toolExtension->file = RSTOOLS_DATA_DIR "/" PACKAGE "/jobs/plugins/rscorrelation.xsdext"; toolExtension->type = getCode(); return toolExtension; }
rsXSDExtension* Realignment::createRealignmentToolXSDExtension() { rsXSDExtension* toolExtension = (rsXSDExtension*)malloc(sizeof(rsXSDExtension)); toolExtension->name = getCode(); toolExtension->file = RSTOOLS_DATA_DIR "/" PACKAGE "/jobs/plugins/realignment.xsdext"; toolExtension->type = getCode(); return toolExtension; }
rsXSDExtension* RSBandpass::createBandpassToolXSDExtension() { rsXSDExtension* toolExtension = (rsXSDExtension*)malloc(sizeof(rsXSDExtension)); toolExtension->name = getCode(); toolExtension->file = RSTOOLS_DATA_DIR "/" PACKAGE "/jobs/plugins/rsbandpass.xsdext"; toolExtension->type = getCode(); return toolExtension; }
void Bank::decUnk1(uint8_t numChunks, uint8_t addCount) { uint16_t count = getCode(numChunks) + addCount + 1; debug(DBG_BANK, "Bank::decUnk1(%d, %d) count=%d", numChunks, addCount, count); _unpCtx.datasize -= count; while (count--) { assert(_oBuf >= _iBuf && _oBuf >= _startBuf); *_oBuf = (uint8_t)getCode(8); --_oBuf; } }
char getInstruction() { if (ss.str() == "") getCode(); char c = ss.get(); while (c == -1) { getCode(); c = ss.get(); } // std::cerr << c; return c; }
String ArduinoHttpServer::StreamHttpErrorReply::getHtmlBody(const String& data) { String body; body += "<html><head><title>Error: "; body += getCode(); body += "</title></head><body><h3>Error "; body += getCode(); body += ": "; body += data; body += "</h3></body></html>"; return body; }
TEST_F(LoggerTests, test_feature_request) { // Retrieve the test logger plugin. auto plugin = RegistryFactory::get().plugin("logger", "test"); auto logger = std::dynamic_pointer_cast<TestLoggerPlugin>(plugin); logger->shouldLogEvent = false; logger->shouldLogStatus = false; auto status = Registry::call("logger", "test", {{"action", "features"}}); EXPECT_EQ(0, status.getCode()); logger->shouldLogStatus = true; status = Registry::call("logger", "test", {{"action", "features"}}); EXPECT_EQ(LOGGER_FEATURE_LOGSTATUS, status.getCode()); }
void initLogger(const std::string& name) { // Check if logging is disabled, if so then no need to shuttle intermediates. if (FLAGS_disable_logging) { return; } // Stop the buffering sink and store the intermediate logs. BufferedLogSink::disable(); auto intermediate_logs = std::move(BufferedLogSink::dump()); // Start the custom status logging facilities, which may instruct Glog as is // the case with filesystem logging. PluginRequest init_request = {{"init", name}}; serializeIntermediateLog(intermediate_logs, init_request); if (!init_request["log"].empty()) { init_request["log"].pop_back(); } bool forward = false; PluginRequest features_request = {{"action", "features"}}; const auto& logger_plugin = Registry::getActive("logger"); // Allow multiple loggers, make sure each is accessible. for (const auto& logger : osquery::split(logger_plugin, ",")) { if (!Registry::exists("logger", logger)) { continue; } Registry::call("logger", logger, init_request); auto status = Registry::call("logger", logger, features_request); if ((status.getCode() & LOGGER_FEATURE_LOGSTATUS) > 0) { // Glog status logs are forwarded to logStatus. forward = true; // To support multiple plugins we only add the names of plugins that // return a success status after initialization. BufferedLogSink::addPlugin(logger); } if ((status.getCode() & LOGGER_FEATURE_LOGEVENT) > 0) { EventFactory::addForwarder(logger); } } if (forward) { // Turn on buffered log forwarding only after all plugins have going through // their initialization. BufferedLogSink::forward(true); BufferedLogSink::enable(); } }
void Entity::save(std::ofstream& file) { saveByte(file, getCode()[0]); saveByte(file, getCode()[1]); unsigned char posBuffer[4]; PackInteger32(posBuffer, int(position_.x)); for (int i = 0; i < 4; i++) saveByte(file, posBuffer[i]); PackInteger32(posBuffer, int(position_.y)); for (int i = 0; i < 4; i++) saveByte(file, posBuffer[i]); }
void ExtensionHandler::call(ExtensionResponse& _return, const std::string& registry, const std::string& item, const ExtensionPluginRequest& request) { // Call will receive an extension or core's request to call the other's // internal registry call. It is the ONLY actor that resolves registry // item aliases. auto local_item = Registry::getAlias(registry, item); PluginResponse response; PluginRequest plugin_request; for (const auto& request_item : request) { // Create a PluginRequest from an ExtensionPluginRequest. plugin_request[request_item.first] = request_item.second; } auto status = Registry::call(registry, local_item, plugin_request, response); _return.status.code = status.getCode(); _return.status.message = status.getMessage(); _return.status.uuid = uuid_; if (status.ok()) { for (const auto& response_item : response) { // Translate a PluginResponse to an ExtensionPluginResponse. _return.response.push_back(response_item); } } }
Point2 CohenSutherlandClip(Point2 p1, Point2 p2) //function to tell us if the line intersects with the rectangle { //returns a set of points if such intersection occurs unsigned char code = getCode(p1); //takes the first point to test the location Point2 p(p1.getX(), p1.getY()); //takes the first point and places it into a local variable float tempX, tempY; float dely = p2.getY() - p1.getY(); //these values help determine the slope of the line float delx = p2.getX() - p1.getX(); if(code & 8) { //to the left tempY = p.getY() + ((LEFT - p.getX()) * dely / delx); //obtains the y value where the line crosses tempX = LEFT; //obtains the x value where the line crosses p.set(tempX, tempY); //places these values into p } if(code & 2) { //to the right tempY = p.getY() + ((RIGHT - p.getX()) * dely / delx); //obtains the y value where the line crosses tempX = RIGHT; //obtains the x value where the line crosses p.set(tempX, tempY); //places these value into p } if(code & 1) { //to the bottom if(p.getY()<BOTTOM) { tempX = p.getX() + ((BOTTOM - p.getY()) * delx / dely); //obtains the x value where line crosses tempY = BOTTOM; //obtains the y value where line crosses p.set(tempX, tempY); } } if(code & 4) { if(p.getY()>TOP) //to the top { tempX = p.getX() + ((TOP - p.getY()) * delx / dely); //obtains the x value where line crosses tempY = TOP; //obtains the y value where line crosses p.set(tempX, tempY); } } return p; //returns the point where the line intersects with the rectangle }
void CtrlrLuaMethod::triggerSourceChangeFromEditor(const bool recompile) { if (methodCodeEditor == nullptr || methodCodeEditor.wasObjectDeleted()) { jassertfalse; // no editor and we got a trigger from it ? that's just f****d up return; } if (isSourceInFile()) { // replace the contents of the file with the editors content getSourceFile().replaceWithText (methodCodeEditor->getCodeDocument().getAllContent()); } else { // replace the contents of the property with the editors content methodTree.setProperty (Ids::luaMethodCode, methodCodeEditor->getCodeDocument().getAllContent(), nullptr); } if (recompile) { // we need to recompile our code setCodeInternal (getCode()); } else { errorString.clear(); errorString.append (Time::getCurrentTime().formatted (getName()+" saved at %m/%d/%y %H:%M:%S\n"), out, Colours::black); } }
void printCode(char *filename) { stack_func.pointer = -1; stack_arg.pointer = -1; spaddHead = NULL; sp = 0; if(codeListHead == NULL) { printf("No valuable code\n"); return; } InterCode temp = codeListHead->next; if ((stream= fopen(filename, "w")) == NULL) { fprintf(stderr, "Cannot open file.\n"); return; } fprintf(stream, ".data\n"); fprintf(stream, "_prompt: .asciiz \"Enter an integer:\"\n"); fprintf(stream, "_ret: .asciiz \"\\n\"\n"); fprintf(stream, ".globl main\n"); fprintf(stream, ".text\n"); for (InterCode temp = codeListHead->next; temp != codeListTail; temp = temp ->next) { fprintf(stream, "#"); getInterCode(stream, temp); getCode(temp); fprintf(stream, "\n"); } printf("OK.\n"); }
TEST_F(ExtensionsTest, test_extension_start) { auto status = startExtensionManager(socket_path); EXPECT_TRUE(status.ok()); EXPECT_TRUE(socketExistsLocal(socket_path)); auto& rf = RegistryFactory::get(); // Now allow duplicates (for testing, since EM/E are the same). rf.allowDuplicates(true); status = startExtension(socket_path, "test", "0.1", "0.0.0", "9.9.9"); // This will not be false since we are allowing duplicate items. // Otherwise, starting an extension and extensionManager would fatal. ASSERT_NE(status.getCode(), (int)ExtensionCode::EXT_FAILED); // Checks for version comparisons (also used by packs). ASSERT_FALSE(versionAtLeast("1.1.1", "0.0.1")); ASSERT_TRUE(versionAtLeast("1.1.1", "1.1.1")); ASSERT_TRUE(versionAtLeast("1.1.1", "1.1.2")); // The `startExtension` internal call (exposed for testing) returns the // uuid of the extension in the success status. RouteUUID uuid = (RouteUUID)stoi(status.getMessage(), nullptr, 0); // We can test-wait for the extensions's socket to open. EXPECT_TRUE(socketExistsLocal(socket_path + "." + std::to_string(uuid))); // Then clean up the registry modifications. rf.removeBroadcast(uuid); rf.allowDuplicates(false); }
/*----------------------------------------------------Escaper::Decoder::match-+ | | +----------------------------------------------------------------------------*/ Escaper::Decoder::Answer Escaper::Decoder::match(char const * p, int max) { char const * pS = getCode(); int sMax = strlen(pS); int i = (sMax > max)? max : sMax; while (i--) if (*p++ != *pS++) return NOT_ME; return (max < sMax)? ME_DUNNO : ME_MATCH; }
// Takes FILE pointer of dictionary, filename for error messages and // pointer to root of Trie. // processes each line in the file, sending the code to buildTrie // returns the root after all word insertions struct node* getDict(FILE* fp, char* fileName, struct node* root) { char* line = (char*)malloc(sizeof(char) * MAXLINE); int* code = (int*)malloc(sizeof(int) * MAXLINE); char* word = (char*) malloc(sizeof(char) * MAXLINE); // check malloc if ((line == NULL) || (code == NULL) || (word == NULL)) fprintf(stderr, MLCFAIL); while ((fgets(line, MAXLINE, fp)) != NULL) { int i = 0; while ((line[i] != '\0') && (line[i] != '\n') && (i < MAXLINE)) { // convert to T9code code[i] = getCode(tolower(line[i])); i++; } // trim to word strncpy(word, line, i); root = buildTrie(code, word, i, 0, root); } free(word); free(line); free(code); return root; }
const ValueVector & htmInterface::convexHullCmd( char *str ) { cmd_ = str; if(t_ != NULL) delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); getDepth(); polyCorners_.clear(); while( parseVec( code, v ) ) { if(code == J2000) { SpatialVector tv(v[0],v[1]); setPolyCorner(tv); } else { SpatialVector tv(v[0],v[1],v[2]); setPolyCorner(tv); } } return doHull(); }
const char * htmInterface::lookupNameCmd(char *str) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); if(code == ID) { uint64 id = getInt64(); index_->nameById(id, name_); } else { getDepth(); if(! parseVec(code, v) ) throw SpatialInterfaceError("htmInterface:lookupNameCmd: Expect vector in Command. ", cmd_.data()); if( code == J2000 ) index_->nameByPoint(v[0], v[1], name_); else { SpatialVector tv(v[0], v[1], v[2]); index_->nameByPoint(tv, name_); } } return name_; }
const ValVec<htmRange> & htmInterface::domainCmd( char *str ) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); cmdCode code = getCode(); if(code != HTMDOMAIN) throw SpatialInterfaceError("htmInterface:domainCmd: missing keyword HTMDOMAIN"); getDepth(); int32 nx,nc; nx = getInteger(); SpatialDomain dom; for(int32 i = 0 ; i < nx; i++ ) { SpatialConvex convex; nc = getInteger(); for(int32 j = 0; j < nc; j++ ) { float64 x = getFloat(); float64 y = getFloat(); float64 z = getFloat(); float64 d = getFloat(); SpatialConstraint c(SpatialVector(x,y,z),d); convex.add(c); } dom.add(convex); } return domain(dom); }
std::shared_ptr<cs5400::Shader<T>> make_shader(std::string path) { auto code = getCode(path); auto shader = std::make_shared<cs5400::Shader<T>>(); setCode(shader->getHandle(),code); return shader; }
uint64 htmInterface::lookupIDCmd(char *str) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); if(code == NAME) { VarStr token = t_->next(); if(token.empty()) throw SpatialInterfaceError("htmInterface:lookupIDCmd: expected Name"); return index_->idByName(token.data()); } getDepth(); if(! parseVec(code, v) ) throw SpatialInterfaceError("htmInterface:lookupIDCmd: Expect vector in Command. ", cmd_.data()); if( code == J2000 ) return lookupID(v[0], v[1]); return lookupID(v[0], v[1], v[2]); }
const ValVec<htmRange> & htmInterface::convexHullCmd( char *str ) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); getDepth(); polyCorners_.cut(polyCorners_.length()); // the next positions give the coordinate while( parseVec( code, v ) ) { if(code == J2000) { SpatialVector tv(v[0],v[1]); setPolyCorner(tv); } else { SpatialVector tv(v[0],v[1],v[2]); setPolyCorner(tv); } } return doHull(); }
void MessageBus::processMsgQueue() { while (!pStopped) { std::unique_lock<std::mutex> lck(cv_m); cv.wait(lck); while (!this->pMsgQueue.empty()) { auto queuedMsg = this->pMsgQueue.front(); this->pMsgQueue.pop(); // process queuedItem here auto msgCode = queuedMsg.getCode(); switch (msgCode) { case Code::PLAY_SOUND: // handle play sound message std::cout << "PLAY_SOUND message received!" << std::endl; break; case Code::STOP_SOUND: std::cout << "STOP_SOUND message receieved!" << std::endl; break; case Code::FLUSH_BUFFER: std::cout << "FLUSH_BUFFER message received!" << std::endl; break; } } } }
std::string Item::getFlipAnimationPath() const { // TODO: extract mapping from exe switch (getCode()) { case icOther: switch (getType()) { case itPOT: return "items/fbttle.cel"; default: break; } break; case icSword: return "items/swrdflip.cel"; case icAxe: return "items/axe.cel"; case icBow: return "items/bow.cel"; case icBlunt: return "items/mace.cel"; case icShield: return "items/shield.cel"; case icLightArmour: return "items/larmor.cel"; case icHelm: return "items/helmut.cel"; case icMidArmour: return "items/armor2.cel"; case icHeavyArmour: return "items/FPlateAr.cel"; case icStave: return "items/staff.cel"; case icGold: return "items/goldflip.cel"; case icRing: case icAmulet: return "items/ring.cel"; } return ""; }
// Type-parameterized test. void TypedTest_ImportChain() { std::string Code = getCode() + getCode(); auto Pattern = getPattern(); TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc"); auto *FromD0 = FirstDeclMatcher<DeclTy>().match(FromTu, Pattern); auto *FromD1 = LastDeclMatcher<DeclTy>().match(FromTu, Pattern); auto *ToD0 = Import(FromD0, Lang_CXX); auto *ToD1 = Import(FromD1, Lang_CXX); EXPECT_TRUE(ToD0); ASSERT_TRUE(ToD1); EXPECT_NE(ToD0, ToD1); EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); }