int uriindex_delete (char uri[], char subname[]) { DB *dbp = NULL; DBT key; int ret; int forreturn = 1; if (!uriindex_open(&dbp,subname, DB_CREATE)) { fprintf(stderr,"can't open uriindex\n"); return 0; } //resetter minne memset(&key, 0, sizeof(DBT)); //legger inn datane i bdb strukturen key.data = uri; key.size = strlen(uri); if ((ret = dbp->del(dbp, NULL, &key, 0)) == 0) { forreturn = 1; } else { dbp->err(dbp, ret, "DBcursor->get"); forreturn = 0; } uriindex_close(&dbp); return forreturn; }
int uriindex_add (char uri[], unsigned int DocID, unsigned int lastmodified, char subname[]) { DB dbpArray; DB *dbp = NULL; DBT key, data; int ret; struct uriindexFormat uriindex; #ifdef DEBUG printf("uriindex_add: subname %s\n",subname); #endif uriindex_open(&dbp,subname, DB_CREATE); //resetter minne memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); //legger inn datane i bdb strukturen key.data = uri; key.size = strlen(uri); uriindex.DocID = DocID; uriindex.lastmodified = lastmodified; //data.data = &DocID; //data.size = sizeof(DocID); data.data = &uriindex; data.size = sizeof(uriindex); //legger til i databasen if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) != 0) { dbp->err(dbp, ret, "DB->put"); //kan ikke returnere her for da blir den aldr lukket. //return (EXIT_FAILURE); } uriindex_close(&dbp); }
int uriindex_get (char uri[], unsigned int *DocID, unsigned int *lastmodified, char subname[]) { DB dbpArray; DB *dbp = NULL; DBT key, data; int ret; int forreturn = 1; struct uriindexFormat uriindex; if (!uriindex_open(&dbp,subname, DB_RDONLY)) { #ifdef DEBUG fprintf(stderr,"can't open uriindex\n"); #endif return 0; } //resetter minne memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); //legger inn datane i bdb strukturen key.data = uri; key.size = strlen(uri); if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0) { *DocID = (*(struct uriindexFormat *)data.data).DocID; *lastmodified = (*(struct uriindexFormat *)data.data).lastmodified; forreturn = 1; } else if (ret == DB_NOTFOUND) { #ifdef DEBUG dbp->err(dbp, ret, "DBcursor->get"); printf("search for \"%s\", len %i\n",key.data,key.size); #endif forreturn = 0; } else { dbp->err(dbp, ret, "DBcursor->get"); forreturn = 0; } uriindex_close(&dbp); return forreturn; }