Beispiel #1
0
csdbparser::enResult csdbparser::file_sanity_check(const char *fn)
{
    smartFILE fp;
    tempbuf buf(20000);
    int hdr_len=0;
    std::string s;

// Does the file exist?
    if (check_fileExists(fn) == false)
    {
        return resFILE_NOT_FOUND;
    }

// Try to open the file for reading
    fp = fopen(fn, "r");
    if (fp == NULL)
    {
        return resFILE_ACCESS_ERR;
    }

// Read out the first line i.e. the header
    if (fgets(buf.get(), 20000, fp.get()) == NULL)
    {
        return resFILE_ACCESS_ERR;
    }
    chomp(buf.get());

    s = static_cast<const char*>(buf.get());
    hdr_len = strlen(buf.get());

// Header should be at least 19 bytes long and starts with "cscope "
    if ((hdr_len<19)||(s.compare(0, strlen("cscope "), "cscope ") != 0))
    {
        return resUNRECOG_FORMAT;
    }

// Compare the cscope version used to build the database
    if (s.compare(7, strlen(CSDBP_SUPPORTED_VER), CSDBP_SUPPORTED_VER) != 0)
    {
        return resINCORRECT_VER;
    }

// Compare the parameters used to build the database with the supported one
    if (s.compare(hdr_len - 28, strlen(CSDBP_SUP_PARAM), CSDBP_SUP_PARAM) != 0)
        if (s.compare(hdr_len - 14, strlen(CSDBP_SUP_PARAM2), CSDBP_SUP_PARAM2) != 0)
        {
            return resUNSUPPORTED_PARAM;
        }

// Trailer offset should be a positive number, normally > 20
    if (atol(s.substr(hdr_len - 10).c_str()) < 20)
    {
        return resUNRECOG_FORMAT;
    }

// Header looks OK so far!

    return resOK;
}
Beispiel #2
0
csdbparser::enResult csdbparser::file_sanity_check(const char *fn)
{
smartFILE fp;
tempbuf buf(20000);
unsigned int i;
std::string s;
bool chkok;

// Does the file exist?
if (check_fileExists(fn) == false) {return resFILE_NOT_FOUND;}

// Try to open the file for reading
fp = fopen(fn, "r");
if (fp == NULL) {return resFILE_ACCESS_ERR;}

// Read out the first line i.e. the header
if (fgets(buf.get(), 20000, fp.get()) == NULL) {return resFILE_ACCESS_ERR;}
chomp(buf.get());

s = static_cast<const char*>(buf.get());
csdbheader hdr;

hdr.set_header(s);
if (hdr.parse() == false)
     {return resUNRECOG_FORMAT;}

// Compare the cscope version used to build the database
if (hdr.get_version() != CSDBP_SUPPORTED_VER_NUM)
     {return resINCORRECT_VER;}

// Compare the parameters used to build the database with the supported one
// We must have "c", we don't mind "q" and we cannot have any other
chkok = false;
tVecStr vs = hdr.get_param_list();
for(i=0; i< vs.size(); i++)
{
	if (vs[i].compare("c") == 0) chkok = true;
}
if (chkok == false) {return resUNSUPPORTED_PARAM;}

for(i=0; i< vs.size(); i++)
{
	if ((vs[i].compare("c") != 0) && 
		(vs[i].compare("q") != 0)) chkok = false;
}
if (chkok == false) {return resUNSUPPORTED_PARAM;}

// Trailer offset should be a positive number, normally > 20
if (hdr.get_trailer_start() < 20) {return resUNRECOG_FORMAT;}

// Header looks OK so far!

return resOK;
}
Beispiel #3
0
sqlquery::en_filereadstatus sqlquery::open_dbfile(tStr dbfn)
{
    if (dbfn.empty()) return sqlfileOPENERROR;

    smartFILE fp;
    // Does the file exist?
    if (check_fileExists(dbfn.c_str()) == false)
    {
        return sqlfileOPENERROR;
    }
    // Try to open the file for reading
    fp = fopen(dbfn.c_str(), "r");
    if (fp == NULL)
    {
        return sqlfileOPENERROR;
    }
    fp.close_file();

    int rc = sqlite3_open_v2(dbfn.c_str(),
                             &m_db, SQLITE_OPEN_READONLY, NULL);
    if ((rc != SQLITE_OK)||(m_db == NULL))
    {
        close_dbfile();
        return sqlfileOPENERROR;
    }
    tempstmt stmt;

    sqlite3_exec(m_db, /*"PRAGMA synchronous = OFF;"
		"PRAGMA journal_mode = OFF;"
		"PRAGMA locking_mode = EXCLUSIVE;"
		"PRAGMA automatic_index = FALSE;"*/
                 "PRAGMA cache_size = 20000;", NULL, 0, NULL);

    tStr majorver = read_configtbl("DB_MAJOR_VER", stmt.get());
    tStr minorver = read_configtbl("DB_MINOR_VER", stmt.get());
    if ((majorver.empty())||(minorver.empty()))
    {
        return sqlfileNOTCORRECTDB;
    }
    if (majorver.compare(tStr("0")) != 0) return sqlfileINCORRECTVER;
    if (minorver.compare(tStr("1")) != 0) return sqlfileINCORRECTVER;
    m_basepath = read_configtbl("DB_BASE_PATH", stmt.get());
    if (m_basepath.empty())
    {
        return sqlfileNOTCORRECTDB;
    }
    rc = sqlite3_prepare_v2(m_db, SQL_AUTOCOMPLETE, strlen(SQL_AUTOCOMPLETE),
                            &(m_autocompstmt.m_stmt), NULL);
    if (rc != SQLITE_OK)
    {
        return sqlfileNOTCORRECTDB;
    }
    return sqlfileOK;
}