Example #1
0
//return the root node of the tree
XmlNode *plainconf::parseFile(const char *configFilePath,
                              const char *rootTag)
{
#ifdef TEST_OUTPUT_PLAIN_CONF
    char *tmp = (char *)new char[5 * 1024 * 1024];

    if (tmp)
        delete []tmp;

#endif
    XmlNode *rootNode = new XmlNode;
    const char *attr = NULL;
    rootNode->init(rootTag, &attr);
    gModuleList.push_back(rootNode);

    loadConfFile(configFilePath);

    if (gModuleList.size() != 1)
        logToMem(LOG_LEVEL_ERR,
                 "parseFile find '{' and '}' do not match in the end of file %s, rootTag %s.",
                 configFilePath, rootTag);

    gModuleList.clear();

    handleSpecialCaseLoop(rootNode);


#ifdef TEST_OUTPUT_PLAIN_CONF
    char sPlainFile[512] = {0};
    strcpy(sPlainFile, configFilePath);
    strcat(sPlainFile, ".txt");
    plainconf::testOutputConfigFile(rootNode, sPlainFile);
#endif
    return rootNode;
}
Example #2
0
void plainconf::loadDirectory(const char *pPath, const char *pPattern)
{
    DIR *pDir = opendir(pPath);

    if (!pDir)
    {
        logToMem(LOG_LEVEL_ERR, "Failed to open directory [%s].", pPath);
        return ;
    }

    struct dirent *dir_ent;

    char str[4096] = {0};
    strcpy(str, pPath);
    strcatchr(str, '/', 4096);
    int offset = strlen(str);
    StringList AllEntries;

    while ((dir_ent = readdir(pDir)))
    {
        const char *pName = dir_ent->d_name;

        if ((strcmp(pName, ".") == 0) ||
            (strcmp(pName, "..") == 0) ||
            (*(pName + strlen(pName) - 1) == '~'))
            continue;

        if (pPattern)
        {
            //Beside the unmatch, also must exclude *,v which was created by rcs
            if(fnmatch(pPattern, pName, FNM_PATHNAME) != 0
                || fnmatch("*,v", pName, FNM_PATHNAME) == 0)
                continue;
        }

        strcpy(str + offset, pName);
        struct stat st;
        if (stat(str, &st) == 0)
        {
            if (S_ISDIR(st.st_mode)
                || pPattern
                || fnmatch("*.conf", pName, FNM_PATHNAME) == 0)
                AllEntries.add(str);
        }
    }
    closedir(pDir);
    AllEntries.sort();

    StringList::iterator iter;
    for (iter = AllEntries.begin(); iter != AllEntries.end(); ++iter)
    {
        const char *pName = (*iter)->c_str();
        logToMem(LOG_LEVEL_INFO, "Processing config file: %s", pName);
        loadConfFile(pName);
    }
}
Example #3
0
void plainconf::loadDirectory(const char *pPath, const char *pPattern)
{
    DIR *pDir = opendir(pPath);

    if (!pDir)
    {
        logToMem(LOG_LEVEL_ERR, "Failed to open directory [%s].", pPath);
        return ;
    }

    struct dirent *dir_ent;

    StringList AllEntries;

    while ((dir_ent = readdir(pDir)))
    {
        const char *pName = dir_ent->d_name;

        if ((strcmp(pName, ".") == 0) ||
            (strcmp(pName, "..") == 0) ||
            (*(pName + strlen(pName) - 1) == '~'))
            continue;

        if (pPattern)
        {
            if (fnmatch(pPattern, pName, FNM_PATHNAME))
                continue;
        }

        char str[4096] = {0};
        strcpy(str, pPath);
        strcatchr(str, '/', 4096);
        strcat(str, pName);
        AllEntries.add(str);
    }

    closedir(pDir);

    //Sort the filename order
    AllEntries.sort();
    StringList::iterator iter;

    for (iter = AllEntries.begin(); iter != AllEntries.end(); ++iter)
    {
        const char *p = (*iter)->c_str();
        logToMem(LOG_LEVEL_INFO, "Processing config file: %s", p);
        loadConfFile(p);
    }
}
form_UserRegistration::form_UserRegistration(QStringList filialList, QString ip) {
    form_UserReg.setupUi(this);
    QIcon icon;
    icon.addFile(QString::fromUtf8("images/reguser.png"), QSize(), QIcon::Normal, QIcon::Off);
    this->setWindowIcon(icon);
    
    form_UserReg.pbSendToServer->setEnabled(true);
    
    irbis64 = new engine(APM_REGUSER, "f10", "f10");
            
    isOVD = true;
    
    
/*  запрос пароля
 *  если сохранен в таблице - то автовход
 * 
 *  form_Login.myIP = ip;
    form_Login.setModal(true);
    QStringList account = form_Login.bd.checkAccountAvailable(ip);
    if (account.count() == 0)
        form_Login.show();
    else
    {
        irbis64->login = account.at(0).toStdString();
        irbis64->pass = account.at(1).toStdString();
    }
*/  
    
    maxWorkAge = 55;
    dt = new datetime();
    form_UserReg.leBirthYear_21->setText(QString::number(dt->year().toInt() - 8));

    form_UserReg.cbFilial->addItems(filialList);
    filialName = form_UserReg.cbFilial->currentText();
    
    // начальная обработка года рождения
    slotOnBirthYearChange("");
    
    form_UserReg.leBirthYear_21->connect(form_UserReg.leBirthYear_21, SIGNAL(textChanged(QString)), this, SLOT(slotOnBirthYearChange(QString)));
//    form_UserReg.leFam_10->connect(form_UserReg.leFam_10, SIGNAL(textChanged(QString)), this, SLOT(slotOnFamChange(QString)));
    
    connect(form_UserReg.leFam_10, SIGNAL(textEdited(QString)), this, SLOT(slotCheckUserExists(QString)));
    connect(form_UserReg.leName_11, SIGNAL(textEdited(QString)), this, SLOT(slotCheckUserExists(QString)));
    connect(form_UserReg.leSurname_12, SIGNAL(textEdited(QString)), this, SLOT(slotCheckUserExists(QString)));
    connect(form_UserReg.leBirthYear_21, SIGNAL(textEdited(QString)), this, SLOT(slotCheckUserExists(QString)));

    form_UserReg.cbAddressRegistration->connect(form_UserReg.cbAddressRegistration, SIGNAL(clicked()), this, SLOT(slotOnAdditionalAddress()));
    
    form_UserReg.pbSendToServer->connect(form_UserReg.pbSendToServer, SIGNAL(clicked()), this, SLOT(slotRegUser()));
    form_UserReg.pbClearForm->connect(form_UserReg.pbClearForm, SIGNAL(clicked()), this, SLOT(slotClearForm()));
    
    QList< QLineEdit* > list;
    list = form_UserReg.gbNewUserReg->findChildren<QLineEdit *>();
    for (int i = 0; i < list.size(); i++)
    {
        connect(list.at(i), SIGNAL(returnPressed()), this, SLOT(slotKeyPressed()));
    }
    
    loadConfFile();
    loadCfgFile();
    
    connect(form_UserReg.cbStreet_13, SIGNAL(editTextChanged(QString)), this, SLOT(slotStreetChanged(QString)));
    slotStreetChanged(form_UserReg.cbStreet_13->currentText());
    
    connect(form_UserReg.cbStreet_14, SIGNAL(editTextChanged(QString)), this, SLOT(slotStreetChanged(QString)));
    connect(form_UserReg.leSerial_14, SIGNAL(textEdited(QString)), this, SLOT(slotSetOVD_OUFMS_Year(QString)));
}
Example #5
0
//This function may be recruse called
void plainconf::loadConfFile(const char *path)
{
    logToMem(LOG_LEVEL_INFO, "start parsing file %s", path);

    int type = checkFiletype(path);

    if (type == 0)
        return;

    else if (type == 2)
        loadDirectory(path, NULL);

    else if (type == 3)
    {
        AutoStr2 prefixPath = path;
        const char *p = strrchr(path, '/');

        if (p)
            prefixPath.setStr(path, p - path);

        struct stat sb;

        //removed the wildchar filename, should be a directory if exist
        if (stat(prefixPath.c_str(), &sb) == -1)
        {
            logToMem(LOG_LEVEL_ERR, "LoadConfFile error 1, path:%s directory:%s",
                     path, prefixPath.c_str());
            return ;
        }

        if ((sb.st_mode & S_IFMT) != S_IFDIR)
        {
            logToMem(LOG_LEVEL_ERR, "LoadConfFile error 2, path:%s directory:%s",
                     path, prefixPath.c_str());
            return ;
        }

        loadDirectory(prefixPath.c_str(), p + 1);
    }

    else //existed file
    {
        //gModuleList.push_back();
        //XmlNode *xmlNode = new XmlNode;
        FILE *fp = fopen(path, "r");

        if (fp == NULL)
        {
            logToMem(LOG_LEVEL_ERR, "Cannot open configuration file: %s", path);
            return;
        }


        const int MAX_LINE_LENGTH = 8192;
        char sLine[MAX_LINE_LENGTH];
        char *p;
        char sLines[MAX_LINE_LENGTH] = {0};
        int lineNumber = 0;
        const int MAX_MULLINE_SIGN_LENGTH = 128;
        char sMultiLineModeSign[MAX_MULLINE_SIGN_LENGTH] = {0};
        size_t  nMultiLineModeSignLen = 0;  //>0 is mulline mode

        while (fgets(sLine, MAX_LINE_LENGTH, fp), !feof(fp))
        {
            ++lineNumber;
            p = sLine;

            if (nMultiLineModeSignLen)
            {
                //Check if reach the END of the milline mode
                size_t len = 0;
                const char *pLineStart = getStrNoSpace(p, len);

                if (len == nMultiLineModeSignLen &&
                    strncasecmp(pLineStart, sMultiLineModeSign, nMultiLineModeSignLen) == 0)
                {
                    nMultiLineModeSignLen = 0;
                    removeSpace(sLines,
                                1);   //Remove the last \r\n so that if it is one line, it will still be one line
                    parseLine(path, lineNumber, sLines);
                    sLines[0] = 0x00;
                }
                else
                    strcat(sLines, p);

                continue;
            }

            removeSpace(p, 0);
            removeSpace(p, 1);

            if (!isValidline(p))
                continue;

            AutoStr2 pathInclude;

            if (isInclude(p, pathInclude))
            {
                char achBuf[512] = {0};
                getIncludeFile(pathInclude.c_str(), achBuf);
                loadConfFile(achBuf);
            }
            else
            {
                nMultiLineModeSignLen = checkMultiLineMode(p, sMultiLineModeSign,
                                        MAX_MULLINE_SIGN_LENGTH);

                if (nMultiLineModeSignLen > 0)
                    strncat(sLines, p, strlen(p) - (3 + nMultiLineModeSignLen));
                //need to continue
                else if (isChunkedLine(p))
                {
                    strncat(sLines, p, strlen(p) - 1);
                    //strcatchr(sLines, ' ', MAX_LINE_LENGTH); //add a space at the end of the line which has a '\\'
                }

                else
                {
                    strcat(sLines, p);
                    parseLine(path, lineNumber, sLines);
                    sLines[0] = 0x00;
                }
            }
        }

        fclose(fp);

        //Parsed, check in it
        checkInFile(path);
    }
}