cdb_free(cdbfl);
} else {
if (floor_num == 0) {
- strcpy(flbuf->f_name, "Main Floor");
+ safestrncpy(flbuf->f_name, "Main Floor",
+ sizeof flbuf->f_name);
flbuf->f_flags = F_INUSE;
flbuf->f_ref_count = 3;
}
struct cdbdata *cdbfr;
long *msglist = NULL;
int num_msgs = 0;
+ unsigned int original_v_flags;
/* If the supplied room name is NULL, the caller wants us to know that
* it has already copied the room record into CC->room, so
* we can skip the extra database fetch.
*/
if (where != NULL) {
- strcpy(CC->room.QRname, where);
+ safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
getroom(&CC->room, where);
}
begin_critical_section(S_USERS);
CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
+ original_v_flags = vbuf.v_flags;
/* Know the room ... but not if it's the page log room, or if the
* caller specified that we're only entering this room transiently.
vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
vbuf.v_flags = vbuf.v_flags | V_ACCESS;
}
- CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
+
+ /* Only rewrite the database record if we changed something */
+ if (vbuf.v_flags != original_v_flags) {
+ CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
+ }
end_critical_section(S_USERS);
/* Check for new mail */
if (retmsgs != NULL) *retmsgs = total_messages;
if (retnew != NULL) *retnew = new_messages;
- lprintf(9, "<%s> %d new of %d total messages\n",
+ lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
CC->room.QRname,
new_messages, total_messages
);
((ra & UA_KNOWN) == 0) &&
(CC->user.axlevel < 6)
) {
- lprintf(9, "Failed to acquire private room\n");
- goto NOPE;
+ lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
} else {
memcpy(&CC->room, &QRscratch,
sizeof(struct ctdlroom));
}
}
-NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
+ cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
}
long owner = 0L;
char actual_old_name[SIZ];
- lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
+ lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
old_name, new_name, new_floor);
if (new_floor >= 0) {
lgetfloor(&flbuf, old_floor);
--flbuf.f_ref_count;
lputfloor(&flbuf, old_floor);
- lgetfloor(&flbuf, CC->room.QRfloor);
+ lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
+ lgetfloor(&flbuf, new_floor);
++flbuf.f_ref_count;
- lputfloor(&flbuf, CC->room.QRfloor);
+ lputfloor(&flbuf, new_floor);
+ lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
}
/* ...and everybody say "YATTA!" */
r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
if (r == crr_room_not_found) {
- cprintf("%d Internal error - room not found?\n", ERROR);
+ cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
} else if (r == crr_already_exists) {
cprintf("%d '%s' already exists.\n",
ERROR + ALREADY_EXISTS, new_name);
} else if (r == crr_noneditable) {
- cprintf("%d Cannot edit this room.\n", ERROR);
+ cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
} else if (r == crr_invalid_floor) {
cprintf("%d Target floor does not exist.\n",
ERROR + INVALID_FLOOR_OPERATION);
CC->room.QRname);
} else if (r != crr_ok) {
cprintf("%d Error: CtdlRenameRoom() returned %d\n",
- ERROR, r);
+ ERROR + INTERNAL_ERROR, r);
}
if (r != crr_ok) {
info_fp = fopen(filename, "r");
if (info_fp == NULL) {
- cprintf("%d No info file.\n", ERROR);
+ cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
return;
}
cprintf("%d Info:\n", LISTING_FOLLOWS);
struct floor flbuf;
char filename[100];
- lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
+ lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
/* Delete the info file */
assoc_file_name(filename, sizeof filename, qrbuf, "info");
struct floor flbuf;
struct visit vbuf;
- lprintf(9, "create_room(%s)\n", new_room_name);
+ lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
if (getroom(&qrbuf, new_room_name) == 0) {
- lprintf(9, "%s already exists.\n", new_room_name);
+ lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
return (0); /* already exists */
}
new_room_floor = 0;
if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
- cprintf("%d Invalid room name.\n", ERROR);
+ cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
return;
}
}
if ((new_room_type < 0) || (new_room_type > 5)) {
- cprintf("%d Invalid room type.\n", ERROR);
+ cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
return;
}
if ((config.c_aide_mailboxes == 0)
|| (CC->user.axlevel < 6)) {
cprintf("%d Higher access required\n",
- ERROR+HIGHER_ACCESS_REQUIRED);
+ ERROR + HIGHER_ACCESS_REQUIRED);
return;
}
}
return;
}
assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
- lprintf(9, "opening\n");
+ lprintf(CTDL_DEBUG, "opening\n");
fp = fopen(infofilename, "w");
- lprintf(9, "checking\n");
+ lprintf(CTDL_DEBUG, "checking\n");
if (fp == NULL) {
cprintf("%d Cannot open %s: %s\n",
ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
if (strlen(new_floor_name) == 0) {
cprintf("%d Blank floor name not allowed.\n",
- ERROR+ILLEGAL_VALUE);
+ ERROR + ILLEGAL_VALUE);
return;
}
np = num_parms(argbuf);
if (np < 1) {
- cprintf("%d Usage error.\n", ERROR);
+ cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
return;
}