}
+// Retrieve a list of all messages (message numbers) in the specified room.
+// Returns the number of messages in the room, allocates a pointer to the array and stuffs it in the supplied location.
+// Caller must free that memory.
+// Returns (-1) if error.
+int CtdlFetchMsgList(long roomnum, long **msgs) {
+ int num_msgs = 0;
+ struct cdbdata *cdbfr;
+
+ cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
+ if (cdbfr == NULL) {
+ syslog(LOG_ERR, "room_ops: no msglist for room %ld", roomnum);
+ *msgs = NULL;
+ return (-1);
+ }
+
+ *msgs = malloc(cdbfr->len);
+ memcpy(*msgs, cdbfr->ptr, cdbfr->len);
+ num_msgs = cdbfr->len / sizeof(long);
+ cdb_free(cdbfr);
+ return(num_msgs);
+}
+
+
// Make the specified room the current room for this session. No validation
// or access control is done here -- the caller should make sure that the
// specified room exists and is ok to access.
int raideflag;
struct visit vbuf;
char truncated_roomname[ROOMNAMELEN];
- struct cdbdata *cdbfr;
long *msglist = NULL;
int num_msgs = 0;
unsigned int original_v_flags;
info = 1;
}
- cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
- if (cdbfr != NULL) {
- msglist = (long *) cdbfr->ptr;
- cdbfr->ptr = NULL; // CtdlUserGoto() now owns this memory (this requires attention if we move to LMDB)
- num_msgs = cdbfr->len / sizeof(long);
- cdb_free(cdbfr);
- }
+ num_msgs = CtdlFetchMsgList(CC->room.QRnumber, &msglist);
total_messages = 0;
for (a=0; a<num_msgs; ++a) {