it is simply the first (sizeof(long)*3) bytes of the structure.
// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
struct visit {
- long v_roomnum;
- long v_roomgen;
- long v_usernum;
+ long v_roomnum; //
+ long v_roomgen; // The first three fields , sizeof(long)*3 , are the index format.
+ long v_usernum; //
long v_lastseen;
unsigned v_flags;
char v_seen[SIZ];
};
+// This is the db index format for "visit" records, which describe the relationship between one user and one room.
+struct visit_index {
+ long iRoomID;
+ long iRoomGen;
+ long iUserID;
+};
+
+
// Supplementary data for a message on disk
// These are kept separate from the message itself for one of two reasons:
// 1. Either their values may change at some point after initial save, or
};
-// This is the db index format for "visit" records, which describe the relationship between one user and one room.
-struct visit_index {
- long iRoomID;
- long iRoomGen;
- long iUserID;
-};
-
-
#endif // SERVER_H
return(sizeof(TheIndex));
}
-
// Back end for CtdlSetRelationship()
void put_visit(struct visit *newvisit) {
- char IndexBuf[32];
- int IndexLen = 0;
-
- memset(IndexBuf, 0, sizeof (IndexBuf));
- // Generate an index
- IndexLen = GenerateRelationshipIndex(IndexBuf, newvisit->v_roomnum, newvisit->v_roomgen, newvisit->v_usernum);
-
- // Store the record
- cdb_store(CDB_VISIT, IndexBuf, IndexLen, newvisit, sizeof(struct visit));
+ cdb_store(CDB_VISIT, newvisit, (sizeof(long)*3), newvisit, sizeof(struct visit));
}
newvisit->v_roomgen = rel_room->QRgen;
newvisit->v_usernum = rel_user->usernum;
+ // Store the record
put_visit(newvisit);
}
// Locate a relationship between a user and a room
void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room) {
- char IndexBuf[32];
- int IndexLen;
struct cdbdata *cdbvisit;
- // Generate an index
- IndexLen = GenerateRelationshipIndex(IndexBuf, rel_room->QRnumber, rel_room->QRgen, rel_user->usernum);
-
// Clear out the buffer
memset(vbuf, 0, sizeof(struct visit));
- cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
+ // Fill out the first three fields; they are also the index
+ vbuf->v_roomnum = rel_room->QRnumber;
+ vbuf->v_roomgen = rel_room->QRgen;
+ vbuf->v_usernum = rel_user->usernum;
+
+ cdbvisit = cdb_fetch(CDB_VISIT, vbuf, (sizeof(long)*3));
if (cdbvisit != NULL) {
memcpy(vbuf, cdbvisit->ptr, ((cdbvisit->len > sizeof(struct visit)) ? sizeof(struct visit) : cdbvisit->len));
cdb_free(cdbvisit);
void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data);
int NewMailCount(void);
int InitialMailCheck(void);
-void put_visit(struct visit *newvisit);
int GenerateRelationshipIndex(char *IndexBuf, long RoomID, long RoomGen, long UserID);
+void put_visit(struct visit *);
int CtdlAssociateSystemUser(char *screenname, char *loginname);
void CtdlSetPassword(char *new_pw);
printf("\033[32m\033[1mVisit: room %ld, gen %ld, user %ld\033[0m\n", visit64->v_roomnum, visit64->v_roomgen, visit64->v_usernum);
- // create the key (which is based on the data, so there is no need to the old key)
+ // create the key (which is based on the data, so there is no need to convert the old key)
out_key->size = sizeof(struct visit_index);
out_key->data = realloc(out_key->data, out_key->size);
struct visit_index *newvisitindex = (struct visit_index *) out_key->data;
DBT in_key, in_data, out_key, out_data, uncomp_data, recomp_data;
int num_rows = 0;
+ snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
+
// create a database handle for the source table
ret = db_create(&src_dbp, src_dbenv, 0);
if (ret) {
}
// open the file containing the source table
- snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
- printf("\033[33m\033[1mdb: opening source %s\033[0m\n", dbfilename);
ret = src_dbp->open(src_dbp, NULL, dbfilename, NULL, DB_BTREE, 0, 0600);
if (ret) {
printf("db: db_open: %s\n", db_strerror(ret));
}
// open the file containing the destination table
- snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
printf("\033[33m\033[1mdb: opening destination %s\033[0m\n", dbfilename);
ret = dst_dbp->open(dst_dbp, NULL, dbfilename, NULL, DB_BTREE, (DB_CREATE | DB_TRUNCATE), 0600);
if (ret) {