/** * Method to fetch Authentication app ID from RegTokenValidityTable * giving the reg token * @param aRegToken The Registration token of the authentication app * @param aAuthAppId [out] The ID of the Authentication app */ void CSmfCredMgrDbUser::readAuthAppIdInRegTokenTable(const TDesC& aRegToken, TDes& aAuthAppId) { TInt err(KErrNone); RSqlStatement sqlReadStatement; TInt paramIndex(KErrNone); TInt64 duration; TBuf<KMaxBufSize> tokenBuf(aRegToken); err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadAuthAppIdInRegTokenTable); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); paramIndex = sqlReadStatement.ParameterIndex(_L(":iID")); err = sqlReadStatement.BindText(paramIndex, tokenBuf); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); while ((err = sqlReadStatement.Next()) == KSqlAtRow) { //sometimes sqlStmt.Next returns KSqlAtRow even if no row is present if (!sqlReadStatement.IsNull(0)) { duration = sqlReadStatement.ColumnInt(1); if (duration) //to be checked with epoch date-time { sqlReadStatement.ColumnText(0, aAuthAppId); } } else { __ASSERT_DEBUG( 0, User::Invariant()); } } sqlReadStatement.Close(); }
bool ParseFoodItem(std::ifstream & infile, FoodItem & item) { if (true == infile.eof()) { return false; } const int MAX_TOKEN = 256; std::string line; std::string tokenBuf(MAX_TOKEN, '\0'); const char * delim = ",\n"; do { float calories = 0; // read line std::getline(infile, line); // grab first token char * token = nullptr; char * nextToken = nullptr; token = strtok_s(&line[0], delim, &nextToken); std::string tokenStr(token); //trim_str(tokenStr); String nameToken(ConvertStringToWString(token)); // read name, 1st token // next token plz token = strtok_s(nullptr, delim, &nextToken); if (token == nullptr) { return false; } // read calories, 2nd token calories = (float)atof(token); if (calories <= 0) { return false; } // read description std::string desc; std::getline(infile, desc); String measurements(ConvertStringToWString(desc)); item = FoodItem(nameToken, measurements, calories); return true; } while (false == infile.eof()); return false; }
int sageStreamer::initNetworks(char *data, bool localPort) { char token[TOKEN_LEN]; sageToken tokenBuf(data); tokenBuf.getToken(token); // e.g. rcvStreamPort 22000, rcvNodeNum 1 131.193.78.140 0 //std::cout << "connection info " << data << std::endl; int rcvPort = atoi(token) + (int)config.protocol; fprintf(stderr, "sageStreamer::%s() : rcvPort = %d + %d = %d\n", __FUNCTION__, atoi(token), (int)config.protocol, rcvPort); sageTcpModule *tcpObj; sageUdpModule *udpObj; switch (config.protocol) { case SAGE_TCP : tcpObj = new sageTcpModule; tcpObj->init(SAGE_SEND, rcvPort, nwCfg); // does nothing nwObj = (streamProtocol *)tcpObj; sage::printLog("sageStreamer::initNetworks : initialize TCP object"); break; case SAGE_UDP : udpObj = new sageUdpModule; udpObj->init(SAGE_SEND, rcvPort, nwCfg); // start sendingThread nwObj = (streamProtocol *)udpObj; sage::printLog("sageStreamer::initNetworks : initialize UDP object"); break; case LAMBDA_STREAM : break; default : std::cerr << "sageStreamer::initNetworks() - error : no network protocol specified" << std::endl; return -1; break; } sage::printLog("sageStreamer::%s() : network object was initialized successfully", __FUNCTION__); connectToRcv(tokenBuf, localPort); setupBlockPool(); nwObj->setFrameRate((double)config.frameRate); streamTimer.reset(); // starts the streamLoop if (pthread_create(&thId, 0, nwThread, (void*)this) != 0) { sage::printLog("sageBlockStreamer : can't create nwThread"); } return 0; }
void streamGroup::parseMessage(char *str) { init(); char token[TOKEN_LEN]; streamInfo info; sageToken tokenBuf(str); tokenBuf.getToken(token); x = atoi(token); tokenBuf.getToken(token); y = atoi(token); tokenBuf.getToken(token); width = atoi(token); tokenBuf.getToken(token); height = atoi(token); int bufLen = tokenBuf.getToken(token); orientation = (sageRotation)atoi(token); if (bufLen < 1) { std::cout << "streamGroup::parseMessage() : error while parsing stream info message" << std::endl; } while(bufLen > 0) { bufLen = tokenBuf.getToken(token); if (bufLen < 1) break; info.x = atoi(token); tokenBuf.getToken(token); info.y = atoi(token); tokenBuf.getToken(token); info.width = atoi(token); tokenBuf.getToken(token); info.height = atoi(token); tokenBuf.getToken(token); info.receiverID = atoi(token); streamList.push_back(info); } }
// --------------------------------------------------------------------------- // Grant access // --------------------------------------------------------------------------- // EXPORT_C TInt RAlfClientBase::GrantAccessToPrivateFile( const RFile& aFile, TInt aObjectIdentfier, TInt aCommandId ) { if (!iEnv || !iEnv->TokenClient()) { return KErrNotReady; } TInt64 token = 0; TPckg<TInt64> tokenBuf(token); TInt err = iEnv->TokenClient()->GenerateToken(aFile, TUid::Uid(KAlfAppServerInterfaceUid3), tokenBuf); if (!err) { err = SendReceive(EAlfDoSubSessionCmd, TIpcArgs(aCommandId,&tokenBuf,&tokenBuf,aObjectIdentfier)); } return err; }
void bridgeStreamGroup::parseMessage(char *str) { char token[TOKEN_LEN]; bridgeStreamInfo info; sageToken tokenBuf(str); tokenBuf.getToken(token); streamNum = atoi(token); if (streamList) delete streamList; streamList = new bridgeStreamInfo[streamNum]; for (int i=0; i<streamNum; i++) { if (i>=1) streamList[i].firstID = streamList[i-1].lastID+1; tokenBuf.getToken(token); streamList[i].lastID = atoi(token); tokenBuf.getToken(token); streamList[i].receiverID = atoi(token); } }
bool ParseMeal(std::ifstream & infile, Meal & meal) { if (true == infile.eof()) { return false; } const int MAX_TOKEN = 256; std::string line; std::string tokenBuf(MAX_TOKEN, '\0'); const char * delim = ",\n"; do { // read line std::getline(infile, line); // grab first token char * token = nullptr; char * nextToken = nullptr; token = strtok_s(&line[0], delim, &nextToken); bool mealTypeParsed = false; bool caloriesParsed = false; // locals for meal header row MealType mealType = MealType::MEAL_BREAKFAST; float calories; // walk the line while (token != nullptr && nextToken != nullptr) { // valid meal type? std::string tokTrimmed = token; trim_str(tokTrimmed); String tokStr(ConvertStringToWString(tokTrimmed)); if (true == StringToMealType(tokStr, mealType)) { mealTypeParsed = true; } else if (true == mealTypeParsed) { calories = (float)atof(token); // if calories column is empty or whitespace, or an invalid number, skip this meal if (calories > 0) { caloriesParsed = true; break; } } // next token plz token = strtok_s(nullptr, delim, &nextToken); } // if we didn't parse a meal line, fail if (false == mealTypeParsed || false == caloriesParsed) { // try the next line continue; } assert(true == IsValidMealType(mealType) && calories > 0); // parse as many food items are below the meal line Meal workingMeal(mealType, calories); FoodItem foodItem; while (false == infile.eof() && true == ParseFoodItem(infile, foodItem)) { workingMeal.AddFoodItem(foodItem); // make sure this line isn't starting a new meal std::string peekFirstToken; if (false == PeekString(infile, delim, peekFirstToken)) { // couldn't read a token, done with this meal return true; } trim_str(peekFirstToken); String strFirstToken(ConvertStringToWString(peekFirstToken)); MealType nextTokMealType; if (true == StringToMealType(strFirstToken, nextTokMealType)) { // next token is a meal type, so we're done with this meal break; } } // meal is valid meal = workingMeal; break; } while (false == infile.eof()); return true; }