Пример #1
0
/** Maze z databaze informace o souboru.
 *
 * Presahne-li pocet smazanych polozek MAX_DELETED_ITEMS, reorganizuje
 * databazi.
 *
 * Navratove hodnoty:
 *
 *      -  1      vse OK.
 *      - -1      chyba pri vytvareni klice k souboru
 *      - -2      chyba pri zamykani/odemykani databaze
 *      - -3      chyba pri praci s databazi
 *
 */
int DirectoryDatabase::DeleteFileInfo(string &name) {
    string      key;
    datum       keyd, datad;
    int         ret;

    ret = File2Key(name.c_str(), key);
    if (ret != 1) return -1;
    
    keyd.dptr   = (char *) key.c_str();
    keyd.dsize  = key.size();

// --- zacatek KRITICKE SEKCE ---
    if (LockDatabase() != 1) return -2; 

    // otevreme databazi pro zapis
    db_file = gdbm_open((char *)db_name.c_str(), GDBM_BLOCK_SIZE, GDBM_WRITER, S_IRUSR | S_IWUSR, 0);
    if (db_file == 0) { 
#ifdef DD_DEBUG
        cout << getpid() << "DD::DFI open gdbm_errno = " << gdbm_errno << " ... " << gdbm_strerror(gdbm_errno) << endl;
#endif
        UnlockDatabase(); 
        return -3; 
    }
    

    if (gdbm_delete(db_file, keyd) != 0) {
#ifdef DD_DEBUG
        cout << getpid() << " - Informace o souboru " << name << " nelze z databaze odstranit." << endl;
#endif
        gdbm_close(db_file);
        UnlockDatabase();
        return -3;
    } else {
        
        num_of_deleted_items++; 
        if (num_of_deleted_items >= MAX_DELETED_ITEMS) {
            // gdbm samo nezmensi velikost souboru databaze, je potreba ho
            // donutit pomoci gdbm_reorganize(), ktere by se nemelo volat moc
            // casto
            if (gdbm_reorganize(db_file) != 0) {
#ifdef DD_DEBUG
                cout << getpid() << " - Nejspis se nepovedla reorganizace databaze ..." << endl;
#endif
            }
        
        }
        
    }//else
    
    gdbm_close(db_file);
    if (UnlockDatabase() != 1) return -2;
// --- konec KRITICKE SEKCE ---

    return 1;
}
Пример #2
0
Файл: dic.c Проект: lcion/nadcn
void sterg(void){
datum key, nextkey;
	key = gdbm_firstkey( bz );
	while(key.dptr){
		nextkey = gdbm_nextkey(bz, key);
		gdbm_delete(bz, key);		
		key = nextkey;
	}
	gdbm_reorganize(bz);
	smsg("\n Am initializat dictionarul \n");

}
Пример #3
0
static void
gdbmhashsetfn(Param pm, HashTable ht)
{
    int i;
    HashNode hn;
    GDBM_FILE dbf;
    datum key, content;

    if (!pm->u.hash || pm->u.hash == ht)
	return;

    if (!(dbf = (GDBM_FILE)(pm->u.hash->tmpdata)))
	return;

    key = gdbm_firstkey(dbf);
    while (key.dptr) {
	queue_signals();
	(void)gdbm_delete(dbf, key);
	free(key.dptr);
	unqueue_signals();
	key = gdbm_firstkey(dbf);
    }

    /* just deleted everything, clean up */
    (void)gdbm_reorganize(dbf);

    if (!ht)
	return;

    for (i = 0; i < ht->hsize; i++)
	for (hn = ht->nodes[i]; hn; hn = hn->next) {
	    struct value v;

	    v.isarr = v.flags = v.start = 0;
	    v.end = -1;
	    v.arr = NULL;
	    v.pm = (Param) hn;

	    key.dptr = v.pm->node.nam;
	    key.dsize = strlen(key.dptr) + 1;

	    queue_signals();

	    content.dptr = getstrvalue(&v);
	    content.dsize = strlen(content.dptr) + 1;

	    (void)gdbm_store(dbf, key, content, GDBM_REPLACE);	

	    unqueue_signals();
	}
}
Пример #4
0
static PyObject *
_gdbm_gdbm_reorganize_impl(dbmobject *self)
/*[clinic end generated code: output=38d9624df92e961d input=f6bea85bcfd40dd2]*/
{
    check_dbmobject_open(self);
    errno = 0;
    if (gdbm_reorganize(self->di_dbm) < 0) {
        if (errno != 0)
            PyErr_SetFromErrno(DbmError);
        else
            PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno));
        return NULL;
    }
    Py_INCREF(Py_None);
    return Py_None;
}
Пример #5
0
Файл: dic.c Проект: lcion/nadcn
void stergc(const char *cv, const char *defno){
datum key, nextkey;
int len_cv, i_defno;
	i_defno = atoi(defno);	//aici prelucrez defno
	len_cv = strlen(cv); 
	i_defno = i_defno + 1 + len_cv; //am obtinut key.dsize pe care-l caut

	key = gdbm_firstkey( bz );
	while(key.dptr){
		if(strcmp(key.dptr,cv) == 0 && key.dsize == i_defno){
			gdbm_delete(bz, key);
			smsg("\nAm sters un cuvant \n");	
		}	
		nextkey = gdbm_nextkey(bz, key);
		key = nextkey;
	}
	gdbm_reorganize(bz);

}
Пример #6
0
int pa_database_clear(pa_database *db) {
    datum gdbm_key;

    pa_assert(db);

    gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db));

    while (gdbm_key.dptr) {
        datum next;

        next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key);

        gdbm_delete(MAKE_GDBM_FILE(db), gdbm_key);

        free(gdbm_key.dptr);
        gdbm_key = next;
    }

    return gdbm_reorganize(MAKE_GDBM_FILE(db)) == 0 ? 0 : -1;
}
static ClRcT
cdbGDBMRecordDelete(ClDBHandleT      dbHandle,  /* Handle to the database */
                    ClDBKeyT         dbKey,     /* Handle to the key of the record being deleted */
                    ClUint32T       keySize)   /* Size of the key */
{
  ClRcT errorCode = CL_OK;
  GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle;
  ClInt32T returnCode = 0;
  datum key = {NULL, 0};

  CL_FUNC_ENTER();
  key.dsize = keySize;
  key.dptr = (ClCharT *)dbKey;

  returnCode = gdbm_delete(pGDBMHandle->gdbmInstance, key);

  if(0 != returnCode) {
    errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM delete failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }
  pGDBMHandle->deleteRecCnt++;

  if( CL_GDBM_MAX_DEL_CNT <= pGDBMHandle->deleteRecCnt )
  {
      returnCode = gdbm_reorganize(pGDBMHandle->gdbmInstance);
      if(0 != returnCode) {
          errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
          CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM reorganize failed"));
          CL_FUNC_EXIT();
          return(errorCode);
      }
      pGDBMHandle->deleteRecCnt = 0;
  }
  CL_FUNC_EXIT();
  return(CL_OK);
}
Пример #8
0
int system_dbmreorganize(int handle) {
     return gdbm_reorganize(gdbm_files[handle]);
     }
Пример #9
0
/*
*	execute the 'index' function
*/
int		sblib_func_exec(int index, int param_count, slib_par_t *params, var_t *retval)
{
	int		success = 0;

	switch ( index )	{
	case	0:	// handle <- GDBM_OPEN(file[, block_size, flags, mode])
		{
			char	*file;
			int		bsize, flags, mode;

			success = mod_parstr_ptr(0, params, param_count, &file);
			success = mod_opt_parint(1, params, param_count, &bsize, 0);
			success = mod_opt_parint(2, params, param_count, &flags, GDBM_WRCREAT);
			success = mod_opt_parint(3, params, param_count, &mode, 0666);
		
			if	( success )	{
				int		handle;

				handle = get_free_handle();
				if	( handle >= 0 )	{
					table[handle].dbf = gdbm_open(file, bsize, flags, mode, NULL);
					success = (table[handle].dbf != NULL);
					if	( success )	
						v_setint(retval, handle);
					else
						v_setstr(retval, gdbm_strerror(gdbm_errno));
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_OPEN: NO FREE HANDLES");
					}
				}
			else
				v_setstr(retval, "GDBM_OPEN: argument error");
		}
		break;

	case	1:	// handle <- GDBM_STORE(handle, key, data [, flags])
		{
			int		handle, flags;
			char	*key, *data;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			success = mod_parstr_ptr(2, params, param_count, &data);
			success = mod_opt_parint(3, params, param_count, &flags, GDBM_REPLACE);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key, dt_data;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					dt_data.dptr  = data;
					dt_data.dsize = strlen(data) + 1;
					
					r = gdbm_store(table[handle].dbf, dt_key, dt_data, flags);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_STORE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_STORE: argument error");
		}
		break;

	case	2:	// data <- GDBM_FETCH(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key, dt_data;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					
					dt_data = gdbm_fetch(table[handle].dbf, dt_key);
					v_setstr(retval, (char *) dt_data.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FETCH: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FETCH: argument error");
		}
		break;

	case	3:	// status <- GDBM_DELETE(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					
					r = gdbm_delete(table[handle].dbf, dt_key);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_DELETE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_DELETE: argument error");
		}
		break;

	case	4:	// key <- GDBM_FIRSTKEY(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;

					dt_key = gdbm_firstkey(table[handle].dbf);
					v_setstr(retval, (char *) dt_key.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FIRSTKEY: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FIRSTKEY: argument error");
		}
		break;

	case	5:	// key <- GDBM_NEXTKEY(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;

					dt_key = gdbm_nextkey(table[handle].dbf, dt_key);
					v_setstr(retval, (char *) dt_key.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_NEXTKEY: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_NEXTKEY: argument error");
		}
		break;

	case	6:	// status <- GDBM_REORGANIZE(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_reorganize(table[handle].dbf);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_REORGANIZE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_REORGANIZE: argument error");
		}
		break;

	case	7:	// status <- GDBM_EXISTS(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;

					r = gdbm_exists(table[handle].dbf, dt_key);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_EXISTS: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_EXISTS: argument error");
		}
		break;

	case	8:	// str <- GDBM_STRERROR()
		v_setstr(retval, gdbm_strerror(gdbm_errno));
		break;

	case	9:	// status <- GDBM_SETOPT(handle, option, value, size)
		{
			int		handle, option, value, size;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parint    (1, params, param_count, &option);
			success = mod_parint    (2, params, param_count, &value);
			success = mod_parint    (3, params, param_count, &size);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_setopt(table[handle].dbf, option, &value, size);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_SETOPT: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_SETOPT: argument error");
		}
		break;

	case	10:	// status <- GDBM_FDESC(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_fdesc(table[handle].dbf);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FDESC: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FDESC: argument error");
		}
		break;

	default:
		v_setstr(retval, "GDBM: function does not exist!");
		}

	return success;
}
Пример #10
0
int main( int argc, char **argv )
{
    msgSender=0;
    // Initialize the mime++ library
    DwInitialize();

    KApplication *a=new KApplication ( argc, argv, "krn" );
    //a.enableSessionManagement();

    app=a;
    conf=a->getConfig();

    checkConf();
    nls=a->getLocale();
    keys = new KStdAccel(conf);
    kbp=new KBusyPtr();
    msgSender=new KRNSender();
    msgSender->readConfig();
    msgSender->setMethod(KMSender::smSMTP);
    KMMessage::readConfig();

    addrBook=new KMAddrBook();
    addrBook->readConfig();
    addrBook->load();


    // Create our directory. If it exists, no problem
    // Should do some checking, though

    testDir( "/share" );
    testDir( "/share/config" );
    testDir( "/share/apps" );
    testDir( "/share/apps/krn" );
    testDir( "/share/apps/krn/cache" );
    testDir( "/share/apps/krn/groupinfo" );
    testDir( "/share/apps/krn/outgoing" );

    krnpath = KApplication::localkdedir() + "/share/apps/krn/";

    mkdir (krnpath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    cachepath=krnpath+"/cache/";
    mkdir (cachepath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    groupinfopath=krnpath+"/groupinfo/";
    mkdir (groupinfopath.data(),S_IREAD|S_IWRITE|S_IEXEC);
    outpath=krnpath+"outgoing/";
    mkdir (outpath.data(),S_IREAD|S_IWRITE|S_IEXEC);

    // Create the articles database


    artinfopath=krnpath+"/artinfo.db";
    artdb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);
    artinfopath=krnpath+"/refs.db";
    refsdb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);
    artinfopath=krnpath+"/scores.db";
    scoredb=gdbm_open(artinfopath.data(),0,GDBM_WRCREAT | GDBM_FAST,448,0);

    if ((!artdb) || (!refsdb) || (!scoredb)) //the gdbm open failed!
    {
        int i=KMsgBox::yesNo(0,"KRN - Error",
                             "I have detected another Krn running\n"
                             "Do you REALLY want to continue?\n"
                             "If you are sure there isn't one, press \"Yes\"\n"
                             "But if there *is* another one, it's going to be UGLY\n");
    }
    // Fill the unreadDict
    datum key=gdbm_firstkey ( artdb );
    datum nextkey;


    while ( key.dptr )
    {
        unreadDict.insert(key.dptr,key.dptr);
        nextkey = gdbm_nextkey ( artdb, key );
        free (key.dptr);
        key = nextkey;
    };

    // Load the rules
    ruleFile=new KSimpleConfig(krnpath+"/rules");
    Rule::updateGlobals();


    Groupdlg *k=new Groupdlg();
    main_widget = k;

    //insert this:
    if (a->isRestored())
        k->restore(1);

    a->setMainWidget( k );
    a->setTopWidget( k );

    k->setMinimumSize( 250, 250 );
    k->show();

    a->exec();

    expireCache();

//    k->close();
    gdbm_reorganize(artdb);
    gdbm_reorganize(refsdb);
    gdbm_reorganize(scoredb);

    gdbm_close(artdb);
    gdbm_close(refsdb);
    gdbm_close(scoredb);
//    delete k;
}
int dddb_optimize()
{
	return (gdbm_reorganize(dbp));
}