void CreateCourseScreen::on_pushButton_Import_clicked()
{
    model = new QStandardItemModel(this);
    ui->tableView->setModel(model);
    QString fileName = QFileDialog::getOpenFileName (this, "Open CSV file",
                                                     QDir::currentPath(), "CSV (*.csv)");
    QFile file (fileName);
    if (file.open(QIODevice::ReadOnly)) {
        QString data = file.readAll();
        data.remove( QRegExp("\r") ); //remove all ocurrences of CR (Carriage Return)
        QString temp;
        QChar character;
        QTextStream textStream(&data);
        while (!textStream.atEnd()) {
            textStream >> character;
            if (character == ',') {
                checkString(temp, character);
            } else if (character == '\n') {
                checkString(temp, character);
            } else if (textStream.atEnd()) {
                temp.append(character);
                checkString(temp);
            } else {
                temp.append(character);
            }
        }
    }
Esempio n. 2
0
bool Dispatcher::CLI_StringPar()
{
//    char temp[] = "read cube_test_1.cli";
//    input = temp;
    char * pch;
    pch = strtok (input," ,");
    currentCommand = string(pch);

    if(!checkString(pch))
    {
        return false;
    }
    else
    {
        while (pch != NULL)
        {
            pch = strtok (NULL, " ,");
            if(pch !=0)
            {
                if(!checkString(pch))
                    return false;
                else
                {
                    string para = string(pch);
                    parameters.push_back(para);
                }
            }
        }
    }
    return true;
}
void MainWindow::loadClicked(){
    model = new QStandardItemModel(this);
    ui->courseView->setModel(model);
    QString fileName = QFileDialog::getOpenFileName(this,"Load CSV File",
                                                    QDir::currentPath(),"*.csv");

    QFile file(fileName);
    if (file.open(QIODevice::ReadOnly)){
        QString data = file.readAll();
        data.remove(QRegExp("\r"));
        QString temp;
        QChar ch;
        QTextStream inStream(&data);
        while (!inStream.atEnd()){
            if (ch==',')
                checkString(temp,ch);
            else if (ch=='\n')
                checkString(temp,ch);
            else if (inStream.atEnd()){
                temp.append(ch);
                checkString(temp);
            } else
                temp.append(ch);
        }
    }
}
Esempio n. 4
0
void EventHandler::processRegister(EventCmd &e,vector<string> &check_cmd)
{
    if(check_cmd.size()!=4) return;
    //1.eqid 2.name 3.passwd
    if(check_cmd[1].size() == 0 || check_cmd[2].size() == 0 || check_cmd[3].size() == 0) return;
    if(check_cmd[1].size()>32 || check_cmd[2].size()>32 || check_cmd[3].size()>32) return;
    if(checkString(check_cmd[1])==false || checkString(check_cmd[2])==false || checkString(check_cmd[3]) == false){
        LOG4CXX_WARN(logger_, "check string false:"<<check_cmd[1]<<";"<<check_cmd[2]<<";"<<check_cmd[3]);
    }
    bool check = false;
    check = dh_->usernameHasBeenUsed(check_cmd[2]);
    if(check == true){
        sendErrorResponse(e.fd_, CMD_REGISTER,ERROR_USERNAME_HAS_BEEN_USED);
        return;
    }else{
        if(dh_->db_error_ != 0){
            sendErrorResponse(e.fd_, CMD_REGISTER, ERROR_SYSTEM_CRITICAL_ERROR);
            return;
        }
        long long user_id;
        check = dh_->registerNewUser(check_cmd[2],check_cmd[3],check_cmd[1],user_id);
        if(check == true){
            LOG4CXX_INFO(logger_, "register;"<<user_id);
            string res = buildRegisterResponse();
            nh_->sendString(e.fd_, res);
            return;
        }else{
            sendErrorResponse(e.fd_, CMD_REGISTER,ERROR_SYSTEM_CRITICAL_ERROR);
            return;
        }
    }
    //string res = buildRegisterResponse();
    //nh_->sendString(e.fd_, res);
    return;
}
Esempio n. 5
0
void dateTimeHandlerTest::dateTest()
{
	ptr<data> tag(new data(ptr<baseObject>(0)));
	{
		ptr<handlers::dataHandler> hTag= tag->getDataHandler(0, true, "DA");
		hTag->setSize(1);

		hTag->setDate(0, 2004, 11, 5, 9, 20, 30, 5000, 1, 2);

		imbxInt32 year, month, day, hour, minutes, seconds, nanoseconds, offsetHours, offsetMinutes;
		hTag->getDate(0, &year, &month, &day, &hour, &minutes, &seconds, &nanoseconds, &offsetHours, &offsetMinutes);

		QVERIFY(year == 2004);
		QVERIFY(month == 11);
		QVERIFY(day == 5);
		QVERIFY(hour == 0);
		QVERIFY(minutes == 0);
		QVERIFY(seconds == 0);
		QVERIFY(nanoseconds == 0);
		QVERIFY(offsetHours == 0);
		QVERIFY(offsetMinutes == 0);

		QVERIFY(hTag->getUnicodeString(0) == L"2004-11-05");
	}

	{
		ptr<handlers::dataHandlerRaw> hTag= tag->getDataHandlerRaw(0, true, "DA");
		std::basic_string<imbxUint8> checkString(hTag->getMemory()->data(), hTag->getMemory()->size());
		QVERIFY(checkString == (imbxUint8*)"20041105");
		hTag->getMemory()->assign((imbxUint8*)"2004-11-5", 9);
	}

	{
		ptr<handlers::dataHandlerRaw> hTag= tag->getDataHandlerRaw(0, false, "DA");
		std::basic_string<imbxUint8> checkString(hTag->getMemory()->data(), hTag->getMemory()->size());
		stringUint8 compString((imbxUint8*)"2004-11-5", 9);
		compString += (imbxUint8)0; // buffer's size is always even!
		QVERIFY(checkString == compString);
	}

	{
		ptr<handlers::dataHandler> hTag= tag->getDataHandler(0, false, "DA");

		imbxInt32 year, month, day, hour, minutes, seconds, nanoseconds, offsetHours, offsetMinutes;
		hTag->getDate(0, &year, &month, &day, &hour, &minutes, &seconds, &nanoseconds, &offsetHours, &offsetMinutes);

		QVERIFY(year == 2004);
		QVERIFY(month == 11);
		QVERIFY(day == 5);
		QVERIFY(hour == 0);
		QVERIFY(minutes == 0);
		QVERIFY(seconds == 0);
		QVERIFY(nanoseconds == 0);
		QVERIFY(offsetHours == 0);
		QVERIFY(offsetMinutes == 0);

		QVERIFY(hTag->getUnicodeString(0) == L"2004-11-05");
	}
}
Esempio n. 6
0
File: util.c Progetto: bji/libs3
int64_t parseIso8601Time(const char *str)
{
    // Check to make sure that it has a valid format
    if (!checkString(str, "dddd-dd-ddTdd:dd:dd")) {
        return -1;
    }

#define nextnum() (((*str - '0') * 10) + (*(str + 1) - '0'))

    // Convert it
    struct tm stm;
    memset(&stm, 0, sizeof(stm));

    stm.tm_year = (nextnum() - 19) * 100;
    str += 2;
    stm.tm_year += nextnum();
    str += 3;

    stm.tm_mon = nextnum() - 1;
    str += 3;

    stm.tm_mday = nextnum();
    str += 3;

    stm.tm_hour = nextnum();
    str += 3;

    stm.tm_min = nextnum();
    str += 3;

    stm.tm_sec = nextnum();
    str += 2;

    stm.tm_isdst = -1;

    int64_t ret = mktime(&stm);

    // Skip the millis

    if (*str == '.') {
        str++;
        while (isdigit(*str)) {
            str++;
        }
    }

    if (checkString(str, "-dd:dd") || checkString(str, "+dd:dd")) {
        int sign = (*str++ == '-') ? -1 : 1;
        int hours = nextnum();
        str += 3;
        int minutes = nextnum();
        ret += (-sign * (((hours * 60) + minutes) * 60));
    }
    // Else it should be Z to be a conformant time string, but we just assume
    // that it is rather than enforcing that

    return ret;
}
Esempio n. 7
0
PyObject* makeGBFFDataDict(gb_data *ptGBFFData) {
    int i;

    PyObject *GBFFDataDict;
    PyObject *FeatureList;
    PyObject *ReferenceList;
    PyObject *RegionTuple;

    GBFFDataDict =  PyDict_New();

    PyDict_SetItemString(GBFFDataDict, "locus_name", PyString_FromString((char *) &(ptGBFFData->sLocusName)));
    PyDict_SetItemString(GBFFDataDict, "length", PyInt_FromLong((long) ptGBFFData->lLength));
    PyDict_SetItemString(GBFFDataDict, "type", PyString_FromString((char *) &(ptGBFFData->sType)));
    PyDict_SetItemString(GBFFDataDict, "topology", PyString_FromString((char *) &(ptGBFFData->sTopology)));
    PyDict_SetItemString(GBFFDataDict, "division_code", PyString_FromString((char *) &(ptGBFFData->sDivisionCode)));
    PyDict_SetItemString(GBFFDataDict, "date", PyString_FromString((char *) &(ptGBFFData->sDate)));
    PyDict_SetItemString(GBFFDataDict, "feature_num", PyInt_FromLong((long) ptGBFFData->iFeatureNum));
    PyDict_SetItemString(GBFFDataDict, "sequence", PyString_FromString(checkString(ptGBFFData->sSequence)));
    PyDict_SetItemString(GBFFDataDict, "accession", PyString_FromString(checkString(ptGBFFData->sAccession)));
    PyDict_SetItemString(GBFFDataDict, "comment", PyString_FromString(checkString(ptGBFFData->sComment)));
    PyDict_SetItemString(GBFFDataDict, "definition", PyString_FromString(checkString(ptGBFFData->sDef)));
    PyDict_SetItemString(GBFFDataDict, "gi", PyString_FromString(checkString(ptGBFFData->sGI)));
    PyDict_SetItemString(GBFFDataDict, "keywords", PyString_FromString(checkString(ptGBFFData->sKeywords)));
    PyDict_SetItemString(GBFFDataDict, "lineage", PyString_FromString(checkString(ptGBFFData->sLineage)));
    PyDict_SetItemString(GBFFDataDict, "organism", PyString_FromString(checkString(ptGBFFData->sOrganism)));
    PyDict_SetItemString(GBFFDataDict, "source", PyString_FromString(checkString(ptGBFFData->sSource)));
    PyDict_SetItemString(GBFFDataDict, "version", PyString_FromString(checkString(ptGBFFData->sVersion)));

    /* Create list of region */
    RegionTuple = PyTuple_New(2);

    PyTuple_SetItem(RegionTuple, 0, PyInt_FromLong((long) ptGBFFData->lRegion[0]));
    PyTuple_SetItem(RegionTuple, 1, PyInt_FromLong((long) ptGBFFData->lRegion[1]));

    PyDict_SetItemString(GBFFDataDict, "region", RegionTuple);


    /* Create list of references */
    ReferenceList = PyList_New(0);

    for(i = 0; i < ptGBFFData->iReferenceNum; i++)
        PyList_Append(ReferenceList, makeReferenceDict((ptGBFFData->ptReferences) + i));

    PyDict_SetItemString(GBFFDataDict, "references", ReferenceList);

    /* Create list of features */
    FeatureList = PyList_New(0);

    for(i = 0; i < ptGBFFData->iFeatureNum; i++)
        PyList_Append(FeatureList, makeFeatureDict((ptGBFFData->ptFeatures) + i));

    PyDict_SetItemString(GBFFDataDict, "features", FeatureList);


    return GBFFDataDict;
}
SymmetricSolver* SymmetricSolver::readFromFile(std::istream& s) {
    SymmetricSolver* foo = new SymmetricSolver();
    checkString("(SymmetricSolver)",s);
    foo->the_ixn = BlockCMat::readFromFile(s);
    s.read((char*)&foo->singular_epsilon,    sizeof(foo->singular_epsilon));
    s.read((char*)&foo->the_GF,                sizeof(foo->the_GF));
    if(foo->the_GF) foo->the_GF = BlockCMat_SVD::readFromFile(s);
    checkString("(/SymmetricSolver)",s);
    return foo;
}
Esempio n. 9
0
bool wave_open()
{
    static char    *channel_mappings[] = {NULL,"mono","stereo"};
    unsigned short  wFormatTag;
    unsigned long   dAvgBytesPerSec;
    unsigned short  wBlockAlign;
    long            filesize;
    long            header_size;

    //if((config.wave.file = fopen(config.infile,"rb")) == NULL) ERROR("Unable to open file");

    if(!checkString(config.wave.file,"RIFF")) ERROR("Input not a MS-RIFF file");
    filesize = Read32BitsLowHigh(config.wave.file); /* complete wave chunk size */
    fprintf(stderr, "Microsoft RIFF, ");

    if(!checkString(config.wave.file,"WAVE")) ERROR("Input not WAVE audio");
    fprintf(stderr, "WAVE audio, ");

/* WAVE FMT format chunk */
    if(!checkString(config.wave.file,"fmt "))  ERROR("Can't find format chunk");
/* my total header size calculations don't work, so this is bogus... */
    header_size = Read32BitsLowHigh(config.wave.file); /* chunk size */

    wFormatTag = Read16BitsLowHigh(config.wave.file);
    if(wFormatTag!=0x0001) ERROR("Unknown WAVE format");
    config.wave.type = WAVE_RIFF_PCM;

    config.wave.channels   = Read16BitsLowHigh(config.wave.file);
    config.wave.samplerate = Read32BitsLowHigh(config.wave.file);
    dAvgBytesPerSec        = Read32BitsLowHigh(config.wave.file);
    wBlockAlign            = Read16BitsLowHigh(config.wave.file);

/* PCM specific */
    if(config.wave.channels>2) ERROR("More than 2 channels\n");
   fprintf(stderr, "PCM, %s %ldHz ", 
           channel_mappings[config.wave.channels], config.wave.samplerate);
    config.wave.bits       = Read16BitsLowHigh(config.wave.file);
    if(config.wave.bits!=16) ERROR("NOT 16 Bit !!!\n");
    fprintf(stderr, "%dbit, ", config.wave.bits);

    if(!checkString(config.wave.file,"data")) ERROR("Can't find data chunk");

    header_size = ftell(config.wave.file);
    fseek(config.wave.file, 0, SEEK_END);
    filesize = ftell(config.wave.file);
    fseek(config.wave.file, header_size, SEEK_SET);

    config.wave.total_samples = (filesize-header_size)/(2*config.wave.channels);
    config.wave.length = config.wave.total_samples/config.wave.samplerate;
    fprintf(stderr, "Length: %2ld:%2ld:%2ld\n", (config.wave.length/3600), 
                                       (config.wave.length/60)%60,
                                       (config.wave.length%60));
    return true;
}
Esempio n. 10
0
void EventHandler::processLogin(EventCmd &e, vector<string> &check_cmd)
{
    cout<<check_cmd[1]<<endl;
    if(check_cmd.size()!=4) return;
    if(check_cmd[1].size() == 0 || check_cmd[2].size() == 0 || check_cmd[3].size() == 0) return;
    if(check_cmd[1].size()>32 || check_cmd[2].size()>32 || check_cmd[3].size() > 32) return;
    if(checkString(check_cmd[1])==false || checkString(check_cmd[2])==false || checkString(check_cmd[3]) == false){
        LOG4CXX_WARN(logger_, "check string false:"<<check_cmd[1]<<";"<<check_cmd[2]<<";"<<check_cmd[3]);
    }
    UserBasicInfo ubi;
    bool check = dh_->getUserBasicInfo(check_cmd[2], check_cmd[3], ubi);
    if(check == false){
        if(dh_->db_error_ != 0){
            sendErrorResponse(e.fd_, CMD_LOGIN,ERROR_SYSTEM_CRITICAL_ERROR);
            return;
        }else{
            sendErrorResponse(e.fd_, CMD_LOGIN,ERROR_USER_OR_PASSWD_WRONG);
            return;
        }
    }else{
        /*if(check_cmd[3] == ubi.eqid_){
         string res = buildLoginResponse(ubi.uid_, -1);
         nh_->sendString(e.fd_, res);
         return;
         }else{
         check = dh_->changeEquipment(ubi.uid_, check_cmd[3]);
         if(dh_->db_error_ !=0||check == false){
         sendErrorResponse(e.fd_, CMD_LOGIN,ERROR_SYSTEM_CRITICAL_ERROR);
         return;
         }else{
         string res = buildLoginResponse(ubi.uid_, getAuthorizeCode(ubi.uid_));
         nh_->sendString(e.fd_, res);
         return;
         }
         }*/
        if(check_cmd[1]!= ubi.eqid_){
            check = dh_->changeEquipment(ubi.uid_, check_cmd[1]);
            if(dh_->db_error_ !=0||check == false){
                sendErrorResponse(e.fd_, CMD_LOGIN,ERROR_SYSTEM_CRITICAL_ERROR);
                return;
            }
        }
        LOG4CXX_INFO(logger_, "login;"<<ubi.uid_);
        long long now = time(NULL);
        long long reaccess_check = now/86400 - ubi.create_time_/86400;
        if((reaccess_check>=1 && reaccess_check<=6)||reaccess_check == 13 || reaccess_check == 29 || reaccess_check == 59 || reaccess_check == 89){
            LOG4CXX_INFO(logger_, "reaccess;"<<reaccess_check<<";"<<ubi.uid_);
        }
        string res = buildLoginResponse(ubi.uid_, getAuthorizeCode(ubi.uid_));
        nh_->sendString(e.fd_, res);
        return;
    }
}
Esempio n. 11
0
PyObject* makeReferenceDict(gb_reference *ptReference) {
    PyObject *ReferenceDict;

    ReferenceDict =  PyDict_New();

    PyDict_SetItemString(ReferenceDict, "authors", PyString_FromString(checkString(ptReference->sAuthors)));
    PyDict_SetItemString(ReferenceDict, "consrtm", PyString_FromString(checkString(ptReference->sConsrtm)));
    PyDict_SetItemString(ReferenceDict, "title", PyString_FromString(checkString(ptReference->sTitle)));
    PyDict_SetItemString(ReferenceDict, "journal", PyString_FromString(checkString(ptReference->sJournal)));
    PyDict_SetItemString(ReferenceDict, "pubmed", PyString_FromString(checkString(ptReference->sPubMed)));
    PyDict_SetItemString(ReferenceDict, "number", PyInt_FromLong((long) ptReference->iNum));

    return ReferenceDict; 
}
Esempio n. 12
0
ATF_TC_BODY(data_string_new, tc) {
    struct data_string new_string;
    const char *src = "Really? Latin? ... geeks";
    int len_arg = 0;
    const char *error;

    /* Case 1: Call with an invalid data_string pointer, should fail */
    if (data_string_new(NULL, src, len_arg, MDL)) {
        atf_tc_fail("case 1: call should have failed");
    }

    /* Case 2: Passing in NULL src should fail */
    if (data_string_new(&new_string, NULL, 10, MDL)) {
        atf_tc_fail("case 2: did not return success");
    }

    /* Case 3: Call with valid params, length includes NULL */
    len_arg = strlen(src) + 1;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 3: did not return success");
    }

    error = checkString(&new_string, src);
    ATF_REQUIRE_MSG((error == NULL), "case 3: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 4: Call with valid params, length does not include NULL */
    len_arg = 7;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 4: did not return success");
    }

    error = checkString(&new_string, "Really?");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 5: Call with valid params, source string is "" */
    len_arg = 0;
    if (data_string_new(&new_string, "", len_arg, MDL) == 0) {
        atf_tc_fail("case 5: did not return success");
    }

    error = checkString(&new_string, "");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


}
Esempio n. 13
0
/**
 * @brief Parses in the argument context for the given node.
 */
void NepParser::genCtxArg(Nepeta::Node &data)
{
	while( notEof() ) {
		char ch = getCurRaw();
		
		if( isSpace(ch) ) {
			iterCur();
		} else if( checkIdentifier(ch) ) {
			genArgWord(data);
		} else if( checkString(ch) ) {
			genArgString(data);
		} else if( checkBlock(ch) ) {
			genArgBlock(data);
		} else if( isNewline(ch) || ch == ';' ) {
			iterCur();
			return;
		} else if( ch == '\\' ) {
			iterCur();
			helpSeekNewline(true);
		} else if( ch == '&' ) {
			genArgReference(data);
		} else {
			mScript.addError(Nepeta::ErrIllegalCharacter, std::string(1,ch),
				getCurLine(), getCurCol());
			helpSeekNewline(false);
			break;
		}
	}
}
Esempio n. 14
0
void 
RegexValidator::checkImpl(const Context *ctx, const Param &value) const
{
    if(!checkString(value.asString(ctx))) {
        throw ValidatorException();
    }
}
Esempio n. 15
0
CommandBase* Parser::parse(const char* str, bool throwException)
{
    if (str == NULL) return NULL;

    bool helpMode = false;
    m_tokens.clear();

    //LOG_INFO << "Command: " << str;
    int ret = m_toker.tokenize(str);
    if (ret != 0) return new ParserFailedCommand("Failed to tokenize command");

    if ((m_tokens.size() > 0) && checkString( m_tokens[0], "help" )) {
        helpMode = true;
        m_tokens.erase( m_tokens.begin() );
    }

    Command* result = NULL;
    try {
        result = detectCommand(helpMode);
        if (result == NULL) {
            result = new ParserFailedCommand("Failed to detect command");
        }
        else if (helpMode)
            result->setHelpMode();
        else
            result->parse(m_tokens);
    }
    catch(Exception& e) {
        if (throwException) throw; // for testing purposes
        result = new ParserFailedCommand(e.cause());
    }

    return result;
}
Esempio n. 16
0
Entity parserCore(std::string input)
{
	input.erase(remove_if(input.begin(), input.end(), isspace), input.end());
	
	checkString(input);
	
	return _parserCore(input, syntaxAnalysis(input));
}
Esempio n. 17
0
QString codepageStringCombination(const DataPointer& start, int length) {
	if(!checkString(start + 1, length - 1)) return "";
	QString rv = QString::fromLatin1(start.toPointer(1), length - 1).trimmed();
	if(start[0] > 16){
		qDebug() << rv << "does not seem to be a codepage-string-combination";
	}
	return rv;
}
Esempio n. 18
0
void Filtering::filterWith (const QString& f)
{
	kdebugf();
	
	bool filter_number = config_file.readBoolEntry ("filtering", "filter-number", false);
	bool filter_email = config_file.readBoolEntry ("filtering", "filter-email", false);
	bool filter_mobile = config_file.readBoolEntry ("filtering", "filter-mobile", false);
	bool filter_startswith = config_file.readBoolEntry ("filtering", "filter-startswith", false);
	
	foreach(const UserListElement &u, userlist->toUserListElements()) {
		if (checkString (u.firstName (), f, filter_startswith)
				|| checkString (u.lastName (), f, filter_startswith)
				|| checkString (u.altNick (), f, filter_startswith)
				|| checkString (u.nickName (), f, filter_startswith)
				|| (filter_number && u.usesProtocol ("Gadu") && checkString (u.ID ("Gadu"), f, filter_startswith))
				|| (filter_email && checkString (u.email (), f, filter_startswith))
				|| (filter_mobile && checkString (u.mobile (), f, filter_startswith))) {
			filter->addUser (u);
		}
	}
	
	kadu->userbox ()->applyFilter (filter);
	
	kdebugf2();
}
Esempio n. 19
0
CsvImportDialog::CsvImportDialog(QWidget *parent)
    : QDialog(parent), ui(new Ui::CsvImportDialog) {
  ui->setupUi(this);
  model = new QStandardItemModel(this);
  ui->tableView->setModel(model);

#if QT_VERSION >= 0x050000
  QStringList dataDirList =
      QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);

  // Use user space
  QString dataBaseDirAndFile = dataDirList.at(0);
#else
  QString dataBaseDirAndFile = QDir::homePath();
#endif

  QString fileName = QFileDialog::getOpenFileName(
      0, tr("open CSV file"), dataBaseDirAndFile, QLatin1String("CSV (*.csv)"));
  QFile file(fileName);

  if (file.open(QFile::Text | QIODevice::ReadOnly)) {
    QString data = QLatin1String(file.readAll());

    data.remove(QRegExp(QLatin1String("\r")));
    QString temp;
    QChar character;
    QTextStream textStream(&data);

    while (!textStream.atEnd()) {
      textStream >> character;
      if (character == QLatin1Char(',')) {
        checkString(temp, character);
      } else if (character == QLatin1Char(';')) {
        character = QLatin1Char(',');
        checkString(temp, character);
      } else if (character == QLatin1Char('\n')) {
        checkString(temp, character);
      } else if (textStream.atEnd()) {
        temp.append(character);
        checkString(temp);
      } else {
        temp.append(character);
      }
    }
  }
Esempio n. 20
0
QString fixedString(const DataPointer& start, int length) {
	if(!checkString(start, length)) return "";
	QString rv = QString::fromLatin1(start.toPointer(0),length).trimmed();
	if(start[0] <= 16 && start[0] >= 1){
		qDebug() << rv << "might be a codepage-string combination, codepage" << (int)start[0] << "parsing as such";
		return codepageStringCombination(start, length);
	}
	return rv;
}
Esempio n. 21
0
 void checkString(vector<vector<int> > &vv, int index, string s, const string &str) {
     for(int j = 0; j < vv[index].size(); ++j) {
         if(vv[index][j] == -1) {
             v.push_back(str.substr(0, index + 1) + s);
         } else {
             checkString(vv, vv[index][j], " " + str.substr(vv[index][j] + 1, index - vv[index][j]) + s, str);
         }
     }
 }
Esempio n. 22
0
void ListDataspacesCommand::parse(Tokens& tokens)
{
    if (tokens.size() > 2) {
        if ((tokens.size() != 4) ||
            !checkString(tokens[2], "filter") ||
            (tokens[3].m_angen != ANGEN_TITLE)) THROW("Invalid format of LIST DATASPACES command");
        m_pattern = tokens[3].m_val.m_str;
    }
}
Esempio n. 23
0
/**
 * @brief writeRegister Method to append a whole registry. Add new element to database.
 * @param pFileName is the name of database file to add to.
 * @param pColumnData it's what to append.
 * @param columnPos is where to append it.
 */
bool writefile::writeRegister(string pFileName, array<char*>* pColumnData ,
                              array<char*>* pColumnNam){

    int currSeek = file.tellg();
    string standardDir = createNewFile(pFileName);
    file.open(standardDir.c_str());
    bool isOpen = true;

    if(!file.is_open()){
        cout << "NED "  + pFileName << endl;
        return false;
    }

    file.seekg(K->ZE_ROW);

    int spacesToMove;
    int Csize;
    int lon = pColumnNam->getLenght();

    array<char*> tempCDataArr = *pColumnData;
    array<char*> tempNames = *pColumnNam;
    array<int> ColumnPos (lon);

    string registerToWrite = K->EMPTY_STRING;
    string Cdata;

    const char* charT ;

    for (int i = K->ZE_ROW ; i < lon ; i++){
        charT  = tempNames[i];
        string strToAdd(charT);
        ColumnPos[i] = getColumnNumber(&pFileName, &strToAdd);
    }

    //Get the register and fill the blanks.
    fillString (&registerToWrite , getRegisterSize());

    for (int i = 0 ; i < ColumnPos.getLenght() ; i++){
        Cdata  = tempCDataArr[i];
        checkString(&Cdata);
        Csize = columnSize(ColumnPos[i]);
        //Not sure
        spacesToMove = sizeUntilColumn(ColumnPos[i]);
        fillString(&Cdata ,Csize);
        registerToWrite.replace(spacesToMove , Csize , Cdata.c_str());
    }

    if (file.is_open()){
        file.seekg(K->ZE_ROW , ios::end);
        file << registerToWrite;
    }
    file.seekg(currSeek);
    file.close();
    return isOpen;
}
Esempio n. 24
0
LogReader::LogReader(QObject *parent) : QObject(parent)
{

    if (!isRunning("mongod.exe")){
        qDebug() << "MongoDB Server is not running!";
        exit(0);
    }

    connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
    connect(this, SIGNAL(dataReceived(QString)), &sHandle, SLOT(checkString(QString)));
    connect(&sHandle, SIGNAL(codeChanged(CodeType)), &json, SLOT(inputCode(CodeType)));
    connect(&sHandle, SIGNAL(codeChanged(CodeType)), &db, SLOT(inputCode(CodeType)));
    connect(&sHandle, SIGNAL(dataValidated(QRegularExpressionMatch)), &json, SLOT(inputData(QRegularExpressionMatch)));
    connect(&json, SIGNAL(jsonCreated(QJsonObject)), &db, SLOT(receiveData(QJsonObject)));
    connect(this, SIGNAL(readToWrite()), &db, SLOT(openMongoConn()));
    connect(this, SIGNAL(writenDone()), &db, SLOT(closeMongoConn()));

    directory.setPath("Z:/Log");
    fileList << "/Pvqvscmw.log"  << "/Pvqvscmw1.log"
             << "/Pvqvscmw2.log" << "/Pvqvscmw3.log"
             << "/Pvqvscmw4.log" << "/Pvqvscmw5.log"
             << "/Pvqvscmw6.log" << "/Pvqvscmw7.log"
             << "/Pvqvscmw8.log" << "/Pvqvscmw9.log";

//    directory.setPath("C:/Temp/Data");
//    fileList << "/Pvqvscmw.log";

//    directory.setPath("C:/Temp/Data");
//    fileList << "/Log (1).log" << "/Log (2).log"
//             << "/Log (3).log" << "/Log (4).log"
//             << "/Log (5).log" << "/Log (6).log"
//             << "/Log (7).log" << "/Log (8).log"
//             << "/Log (9).log" << "/Log (10).log"
//             << "/Log (11).log" << "/Log (12).log"
//             << "/Log (13).log" << "/Log (14).log"
//             << "/Log (15).log" << "/Log (16).log"
//             << "/Log (17).log" << "/Log (18).log"
//             << "/Log (19).log" << "/Log (20).log"
//             << "/Log (21).log" << "/Log (22).log"
//             << "/Log (23).log" << "/Log (24).log"
//             << "/Log (25).log" << "/Log (26).log"
//             << "/Log (27).log" << "/Log (28).log"
//             << "/Log (29).log" << "/Log (30).log"
//             << "/Log (31).log" << "/Log (32).log"
//             << "/Log (33).log" << "/Log (34).log"
//             << "/Log (35).log" << "/Log (36).log"
//             << "/Log (37).log" << "/Log (38).log"
//             << "/Log (39).log" << "/Log (40).log"
//             << "/Log (41).log" << "/Log (42).log";

    // Força a leitura no arquivo na inicialização.
    readFile(0);
    watcher.addPath(directory.absolutePath()+fileList.at(0));
}
Esempio n. 25
0
void EventHandler::processCreateUser(EventCmd &e, vector<string> &check_cmd)
{
    if(check_cmd.size()!=4)return;
    uid_type uid;
    bool check = safeAtoll(check_cmd[1], uid);
    if(check == false) return;
    if(check_cmd[2].size() == 0 || check_cmd[2].size()>32) return;
    if(check_cmd[3].size() == 0 || check_cmd[3].size()>32) return;
    if(checkString(check_cmd[2]) == false || checkString(check_cmd[3]) == false) return;
    User * user = dh_->getUser(uid);
    if(dh_->db_error_ != 0){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_SYSTEM_CRITICAL_ERROR);
        return;
    }
    if(user != NULL){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_USER_ALREADY_REGISTERED);
        return;
    }
    /*check = dh_->checkNick(check_cmd[3]);
    if(dh_->db_error_ != 0){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_SYSTEM_CRITICAL_ERROR);
        return;
    }
    if(check == false){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_NICKNAME_USED);
        return;
    }*/
    check = dh_->createUser(uid,check_cmd);
    if(dh_->db_error_ != 0){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_SYSTEM_CRITICAL_ERROR);
        return;
    }
    if(check == false){
        sendErrorResponse(e.fd_, CMD_CREATEUSER, ERROR_CREATE_USER_FAIL);
        return;
    }
    LOG4CXX_INFO(logger_, "register;"<<uid);
    string res = buildCreateUserResponse();
    nh_->sendString(e.fd_, res);
    return;
}
Esempio n. 26
0
void EventHandler::processLogin(EventCmd &e, vector<string> &check_cmd)
{
    if(check_cmd.size()!= 5) return;
    if(check_cmd[1].size()==0 || check_cmd[2].size()==0 || check_cmd[3].size()==0 || check_cmd[4].size() == 0) return;
    if(check_cmd[1].size()>32 || check_cmd[2].size()>32 || check_cmd[3].size() > 32 || check_cmd[4].size() >32) return;
    if(checkString(check_cmd[3])==false || checkString(check_cmd[4]) == false) return;
    uid_type uid ;
    bool check = safeAtoll(check_cmd[1], uid);
    if(check == false) return;
    struct sessionVerifyInfo * svi = new struct sessionVerifyInfo();
    svi->uid = uid;
    svi->fd_=e.fd_;
    svi->eq = eq_;
    svi->nickname = new string(check_cmd[4]);
    svi->eqid = new string(check_cmd[2]);
    string sign = buildSessionVerifyString(check_cmd);
    svi->sign = new string(sign);
    pthread_t tid;
    pthread_create(&tid, NULL, sessionVerify, (void *)svi );
    return;
}
Esempio n. 27
0
void RenameDataspaceCommand::parse(Tokens& tokens)
{
    if (tokens.size() != 5) THROW("Invalid RENAME DATASPACE command");

    if (tokens[2].m_angen != ANGEN_IDENT) THROW("Expected existing dataspace name");
    m_oldName = tokens[2].m_val.m_str;

    if (!checkString(tokens[3], "to")) THROW("Expected key word TO");

    if (tokens[4].m_angen != ANGEN_IDENT) THROW("Expected new dataspace name");
    m_newName = tokens[4].m_val.m_str;
}
Esempio n. 28
0
void permute(int index){
	if (index == length){
		checkString();
		return;
	} else {
		int i = 0;
		for (i = 0; i < 3; i++){
			string[index] = buttons[sequence[index]-2][i];
			permute(index+1);
		}
	}
}
Esempio n. 29
0
void RenameMetricCommand::parse(Tokens& tokens)
{
    if (tokens.size() != 5) THROW("Invalid RENAME METRIC command");

    if (tokens[2].m_angen != ANGEN_IDENT) THROW("Expected existing metric name");
    m_oldName = tokens[2].m_val.m_str;

    if (!checkString(tokens[3], "to")) THROW("Expected key word TO");

    if (tokens[4].m_angen != ANGEN_IDENT) THROW("Expected new metric name");
    m_newName = tokens[4].m_val.m_str;
}
Esempio n. 30
0
void dateTimeHandlerTest::timeTest()
{
	ptr<data> tag(new data(ptr<baseObject>(0)));
	{
		ptr<handlers::dataHandler> hTag= tag->getDataHandler(0, true, "TM");
		hTag->setSize(1);

		hTag->setDate(0, 2004, 11, 5, 9, 20, 40, 5000, 1, 2);

		imbxInt32 year, month, day, hour, minutes, seconds, nanoseconds, offsetHours, offsetMinutes;
		hTag->getDate(0, &year, &month, &day, &hour, &minutes, &seconds, &nanoseconds, &offsetHours, &offsetMinutes);

		QVERIFY(year == 0);
		QVERIFY(month == 0);
		QVERIFY(day == 0);
		QVERIFY(hour == 9);
		QVERIFY(minutes == 20);
		QVERIFY(seconds == 40);
		QVERIFY(nanoseconds == 5000);
		QVERIFY(offsetHours == 0);
		QVERIFY(offsetMinutes == 0);

		QVERIFY(hTag->getUnicodeString(0) == L"09:20:40.005000");
	}

	{
		ptr<handlers::dataHandlerRaw> hTag= tag->getDataHandlerRaw(0, true, "TM");
		stringUint8 compString((imbxUint8*)"092040.005000");
		compString += (imbxUint8)0;
		std::basic_string<imbxUint8> checkString(hTag->getMemory()->data(), hTag->getMemory()->size());
		QVERIFY(checkString == compString);
		hTag->getMemory()->assign((imbxUint8*)"9:20:40", 7);
	}

	{
		ptr<handlers::dataHandler> hTag= tag->getDataHandler(0, false, "TM");

		imbxInt32 year, month, day, hour, minutes, seconds, nanoseconds, offsetHours, offsetMinutes;
		hTag->getDate(0, &year, &month, &day, &hour, &minutes, &seconds, &nanoseconds, &offsetHours, &offsetMinutes);

		QVERIFY(year == 0);
		QVERIFY(month == 0);
		QVERIFY(day == 0);
		QVERIFY(hour == 9);
		QVERIFY(minutes == 20);
		QVERIFY(seconds == 40);
		QVERIFY(nanoseconds == 0);
		QVERIFY(offsetHours == 0);
		QVERIFY(offsetMinutes == 0);

		QVERIFY(hTag->getUnicodeString(0) == L"09:20:40.000000");
	}
}