+/*
+ * Add a message number to a room's message list.
+ * So, why doesn't this function use the get_msglist() and put_msglist() stuff
+ * defined above? Because the room the message number is being written to
+ * may not be the current room (as is the case with cmd_move() for example).
+ */
+void AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
+ char dbkey[256];
+ struct cdbdata *cdbfr;
+ int num_msgs;
+ long *msglist;
+
+ msglist_key(dbkey, whichroom);
+ cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey));
+ if (cdbfr == NULL) {
+ msglist = NULL;
+ num_msgs = 0;
+ }
+ else {
+ msglist = malloc(cdbfr->len);
+ num_msgs = cdbfr->len / sizeof(long);
+ memcpy(msglist, cdbfr->ptr, cdbfr->len);
+ cdb_free(cdbfr);
+ }
+
+ /* Now add the new message */
+ ++num_msgs;
+ msglist = realloc(msglist,
+ (num_msgs * sizeof(long)) );
+
+ if (msglist == NULL) {
+ lprintf(3, "ERROR: can't realloc message list!\n");
+ }
+
+ msglist[num_msgs - 1] = newmsgid;
+
+ /* Write it back to disk. */
+ cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey),
+ msglist, num_msgs * sizeof(long));
+
+ /* And finally, free up the memory we used. */
+ free(msglist);
+ }
+
+