*/
mptr = (struct march *) malloc(sizeof(struct march));
mptr->next = NULL;
+ mptr->march_order = 0;
+ mptr->march_floor = 0;
strcpy(mptr->march_name, "_BASEROOM_");
if (march == NULL) {
march = mptr;
struct ctdlroomlisting *rs;
int list_it;
char rmname[ROOMNAMELEN];
- int rmslot;
+ int rmslot = 0;
int rmtotal;
+ struct ctdlroom *attr = NULL;
+
+ /* Fetch the existing room config */
+ r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ return;
+ }
+ strcpy (room_name , attr->QRname);
+ free(attr);
/* Ask the server for a room list */
r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
int CtdlIPCQuit(CtdlIPC *ipc)
{
register int ret = 221; /* Default to successful quit */
- char aaa[128];
+ char aaa[SIZ];
CtdlIPC_lock(ipc);
if (ipc->sock > -1) {
int CtdlIPCLogout(CtdlIPC *ipc)
{
register int ret;
- char aaa[128];
+ char aaa[SIZ];
CtdlIPC_lock(ipc);
CtdlIPC_putline(ipc, "LOUT");
char aaa[SIZ];
char buf[4096];
FILE *fd;
+ int ferr;
if (!cret) return -1;
if (!path) return -1;
}
if (progress_gauge_callback)
progress_gauge_callback(ipc, 1, 1);
- return (!ferror(fd) ? ret : -2);
+ ferr = ferror(fd);
+ fclose(fd);
+ return (!ferr ? ret : -2);
}
serv_read(ipc, &buf[i], 1);
/* Strip the trailing newline (and carriage return, if present) */
- if (buf[i] == 10) buf[i--] = 0;
- if (buf[i] == 13) buf[i--] = 0;
+ if (i>=0 && buf[i] == 10) buf[i--] = 0;
+ if (i>=0 && buf[i] == 13) buf[i--] = 0;
}
void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
lprintf(CTDL_INFO, "Closing databases\n");
close_databases();
- /* flush the networker stuff */
-/* destroy_network_queue_room();*/
-
/* Do system-dependent stuff */
sysdep_master_cleanup();
}
else ptr++;
}
- while (isspace((buf[strlen(buf)-1]))) {
- buf[strlen(buf)-1] = 0;
+ ptr--;
+ while (ptr>buf && isspace(*ptr)) {
+ *(ptr--) = 0;
}
if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
if ((strlen(public_clients) +
strcpy(buf, "");
strcpy(wbuf, "");
+ strcpy(last_user, "");
color(BRIGHT_YELLOW);
sln_printf_if("\n");
sln_printf("> ");
if (r / 100 != 1) {
err_printf("*** msg #%ld: %d %s\n", num, r, buf);
++lines_printed;
- lines_printed =
- checkpagin(lines_printed, pagin, screenheight);
+ lines_printed = checkpagin(lines_printed, pagin, screenheight);
stty_ctdl(0);
+ free(message->text);
+ free_parts(message->attachments);
+ free(message);
return (0);
}
}
pprintf("\n");
stty_ctdl(0);
+ free(message->text);
+ free_parts(message->attachments);
+ free(message);
return (0);
}
if (sigcaught == 0) {
linelen = strlen(lineptr);
- if (lineptr[linelen-1] == '\r') {
+ if (linelen && (lineptr[linelen-1] == '\r')) {
lineptr[--linelen] = 0;
}
if (dest) {
scr_printf("\n");
++lines_printed;
lines_printed = checkpagin(lines_printed, pagin, screenheight);
+ fr = sigcaught;
}
}
r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
}
- if (e == 3)
+ if (e == SIGQUIT)
return;
- if (((userflags & US_NOPROMPT) || (e == 2))
- && (((room_flags & QR_MAILBOX) == 0)
+ if (((userflags & US_NOPROMPT) || (e == SIGINT))
+ && (((room_flags & QR_MAILBOX) == 0)
|| (rc_force_mail_prompts == 0))) {
e = 'n';
} else {
* connected that it's inevitable.)
*/
if (network_usetable(msg) != 0) {
+ CtdlFreeMessage(msg);
return;
}
return;
}
if (download_len > 0)
- lprintf(CTDL_NOTICE, "Received %ld octets from <%s>",
+ lprintf(CTDL_NOTICE, "Received %ld octets from <%s>\n",
download_len, remote_nodename);
- lprintf(CTDL_DEBUG, "%s", buf);
+ lprintf(CTDL_DEBUG, "%s\n", buf);
/* TODO: make move inline. forking is verry expensive. */
snprintf(buf,
sizeof buf,
/* and yank any nulls */
while ((numitems > 0) && (listptrs[0] == 0L)) {
- memcpy(&listptrs[0], &listptrs[1],
+ memmove(&listptrs[0], &listptrs[1],
(sizeof(long) * (numitems - 1)));
--numitems;
}
if (CtdlAccessCheck(ac_logged_in)) return;
- if (CC->user.axlevel < config.c_createax || CC->internal_pgm) {
+ if (CC->user.axlevel < config.c_createax && !CC->internal_pgm) {
cprintf("%d You need higher access to create rooms.\n",
ERROR + HIGHER_ACCESS_REQUIRED);
return;
#define IFNAIDE if (axlevel<6)
extern unsigned userflags;
-extern char *axdefs[7];
+//extern char *axdefs[8];
extern char sigcaught;
extern char rc_floor_mode;
extern int rc_ansi_color;
if (cmd == 96) {
scr_printf("Do you want to delete this user? ");
- if (!yesno()) return;
+ if (!yesno()) {
+ free(user);
+ return;
+ }
user->axlevel = 0;
}
extern char temp[];
extern char tempdir[];
-extern char *axdefs[7];
+extern char *axdefs[8];
extern long highest_msg_read;
extern long maxmsgnum;
extern unsigned room_flags;
if (a == 11)
scr_printf("%s\n", buf);
} while (!IsEmptyStr(resp));
+
+/* TODODRW: discrepancy here. Parts of the code refer to axdefs[7] as the highest
+ * but most of it limits it to axdefs[6].
+ * Webcit limits to 6 as does the code here but there are 7 in axdefs.h
+ */
scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
} else {
scr_printf("%s\n%s\n", user, &cmd[4]);
#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
void wait_indicator(int state) {
- if (!isendwin() && statuswindow) {
+ if (statuswindow && !isendwin()) {
mvwinch(statuswindow, 0, screenwidth - 2);
switch (state) {
S_RPLIST,
S_SIEVELIST,
S_CHKPWD,
+ S_LOG,
MAX_SEMAPHORES
};
#ifdef HAVE_RUN_DIR
struct stat filestats;
#endif
+
+ /* initialise semaphores here. Patch by Matt and davew
+ * its called here as they are needed by lprintf for thread safety
+ */
+ InitialiseSemaphores();
/* initialize the master context */
InitializeMasterCC();
config.c_ctdluid = atoi(ctdluidname);
}
}
- }
#endif
+ }
break;
case 3:
* lprintf() ... Write logging information
*/
void lprintf(enum LogLevel loglevel, const char *format, ...) {
+ char *buf;
va_list arg_ptr;
if (enable_syslog) {
}
/* stderr output code */
- if (enable_syslog || running_as_daemon) return;
+ if (enable_syslog || running_as_daemon) {
+ return;
+ }
/* if we run in forground and syslog is disabled, log to terminal */
if (loglevel <= verbosity) {
/* Promote to time_t; types differ on some OSes (like darwin) */
unixtime = tv.tv_sec;
localtime_r(&unixtime, &tim);
+// begin_critical_section(S_LOG);
+
+ buf = malloc(SIZ+strlen(format));
+
if (CC->cs_pid != 0) {
- fprintf(stderr,
+ sprintf(buf,
"%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ",
tim.tm_year + 1900, tim.tm_mon + 1,
tim.tm_mday, tim.tm_hour, tim.tm_min,
tim.tm_sec, (long)tv.tv_usec,
CC->cs_pid);
} else {
- fprintf(stderr,
+ sprintf(buf,
"%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
tim.tm_year + 1900, tim.tm_mon + 1,
tim.tm_mday, tim.tm_hour, tim.tm_min,
tim.tm_sec, (long)tv.tv_usec);
}
- va_start(arg_ptr, format);
- vfprintf(stderr, format, arg_ptr);
+ strcat(buf, format);
+ va_start(arg_ptr, buf);
+ vfprintf(stderr, buf, arg_ptr);
va_end(arg_ptr);
fflush(stderr);
+// end_critical_section(S_LOG);
}
}
master_cleanup(signum);
}
+
+
+
+void InitialiseSemaphores(void)
+{
+ int i;
+
+ /* Set up a bunch of semaphores to be used for critical sections */
+ for (i=0; i<MAX_SEMAPHORES; ++i) {
+ pthread_mutex_init(&Critters[i], NULL);
+ }
+}
+
+
+
/*
* Some initialization stuff...
*/
void init_sysdep(void) {
- int i;
sigset_t set;
/* Avoid vulnerabilities related to FD_SETSIZE if we can. */
init_ssl();
#endif
- /* Set up a bunch of semaphores to be used for critical sections */
- for (i=0; i<MAX_SEMAPHORES; ++i) {
- pthread_mutex_init(&Critters[i], NULL);
- }
-
/*
* Set up a place to put thread-specific data.
* We only need a single pointer per thread - it points to the
void InitializeMasterCC(void);
void init_master_fdset(void);
void create_worker(void);
+void InitialiseSemaphores(void);
extern int num_sessions;
extern volatile int time_to_die;