[mw-devel] [Git][arthur/mw][master] Decouple mwlog() from the client

Andrew Price welshbyte at sucs.org
Thu Nov 22 08:32:57 GMT 2018


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
4e82e903 by Andrew Price at 2018-11-22T08:30:15+00:00
Decouple mwlog() from the client

Should make it simpler to move logging into the server.

- - - - -


13 changed files:

- src/bb.h
- src/client/edit.c
- src/client/folders.c
- src/client/main.c
- src/client/mesg.c
- src/client/mesg.h
- src/client/newmain.c
- src/client/talker.c
- src/client/uri.c
- src/client/user.c
- + src/mwlog.c
- + src/mwlog.h
- src/webclient/comms.c


Changes:

=====================================
src/bb.h
=====================================
--- a/src/bb.h
+++ b/src/bb.h
@@ -10,10 +10,6 @@
 #define HOMEPATH	"/usr/local/lib/mw"
 #endif
 
-#ifndef LOGDIR
-#define LOGDIR		"/var/log/mw"
-#endif
-
 #ifndef STATEDIR
 #define STATEDIR	"/var/lib/mw"
 #endif
@@ -22,7 +18,6 @@
 #define MSGDIR		"/run/mw"
 #endif
 
-#define LOGFILE		LOGDIR"/log.bb"
 #define LOGIN_BANNER    HOMEPATH"/login.banner"
 #define LOCKFILE	"/tmp/bb.locked"
 #define EDITOR		"/usr/bin/vim"
@@ -41,7 +36,6 @@
 #define CMD_TALK_STR	"."
 #define CMD_SCRIPT_STR	","
 
-#define LOGLINESIZE	2048	/* size of a line printed to log file */
 #define MAXTEXTLENGTH	2048	/* text buffer size */
 #define MAXPIPELENGTH	4096	/* maximum length of a pipe message */
 


=====================================
src/client/edit.c
=====================================
--- a/src/client/edit.c
+++ b/src/client/edit.c
@@ -18,6 +18,7 @@
 #include <signal.h>
 
 #include <util.h>
+#include <mwlog.h>
 #include "talker_privs.h"
 #include "special.h"
 #include "incoming.h"
@@ -189,7 +190,7 @@ void edit_user(const char *args, const char *name)
 			ipc_send_to_username(usr->name, IPC_STATUS, stats);
 			show_change(oldstats, statout, "%s has just changed %s's status",
 			            user->record.name, usr->name);
-			mwlog("CHANGE(STATUS) of %s by %s", usr->name, stats);
+			mwlog(user, "CHANGE(STATUS) of %s by %s", usr->name, stats);
 		}
 		free(oldstats);
 	}else
@@ -213,7 +214,7 @@ void edit_user(const char *args, const char *name)
 			ipc_send_to_username(usr->name, IPC_SPECIAL, stats);
 			show_change(oldstats, statout, "%s has just changed %s's specials",
 			            user->record.name, usr->name);
-			mwlog("CHANGE(SPECIAL) of %s by %s", usr->name, stats);
+			mwlog(user, "CHANGE(SPECIAL) of %s by %s", usr->name, stats);
 		}
 		free(oldstats);
 	}else
@@ -234,7 +235,7 @@ void edit_user(const char *args, const char *name)
 			show_change(oldstats, display_cpflags(usr->chatprivs),
 			           "%s has just changed %s's chatprivs",
 			           user->record.name, usr->name);
-			mwlog("CHANGE(CHATPRIV) of %s by %s", usr->name, stats);
+			mwlog(user, "CHANGE(CHATPRIV) of %s by %s", usr->name, stats);
 		}
 		free(oldstats);
 	}else
@@ -269,7 +270,7 @@ void edit_user(const char *args, const char *name)
 
 			broadcast(3, "%s has just changed %s's protection from %s to %d/%d.",
 			         user->record.name, usr->name, oldstats, cpl, apl);
-			mwlog("CHANGE(PROTLEVEL) of %s to %d/%d", usr->name, cpl, apl);
+			mwlog(user, "CHANGE(PROTLEVEL) of %s to %d/%d", usr->name, cpl, apl);
 		} else if (*stats)
 		{
 			printf(_("Invalid protection level.\n"));
@@ -295,7 +296,7 @@ void edit_user(const char *args, const char *name)
 			            user->record.name, usr->name);
 			if (*stats)
 			{
-				mwlog("CHANGE(CHATMODE) of %s by %s", usr->name, stats);
+				mwlog(user, "CHANGE(CHATMODE) of %s by %s", usr->name, stats);
 			}
 		}
 		free(oldstats);
@@ -314,7 +315,7 @@ void edit_user(const char *args, const char *name)
 		{
 			usr->groups = folder_groups(stats, usr->groups);
 			ipc_send_to_username(usr->name, IPC_GROUPS, stats);
-			mwlog("CHANGE(GROUPS) of %s by %s", usr->name, stats);
+			mwlog(user, "CHANGE(GROUPS) of %s by %s", usr->name, stats);
 
 			show_fold_groups(usr->groups, stats, false);
 			show_change(oldstats, stats, "%s has just changed %s's groups",
@@ -339,7 +340,7 @@ void edit_user(const char *args, const char *name)
 			strcpy(usr->passwd, pass1);
 			printf(_("Password changed.\n"));
 			broadcast(3, "%s has just changed %s's password.", user->record.name, usr->name);
-			mwlog("CHANGE(PASSWD) of %s", usr->name);
+			mwlog(user, "CHANGE(PASSWD) of %s", usr->name);
 			ipc_send_to_username(usr->name, IPC_PASSWD, usr->passwd);
 		}
 	}else
@@ -359,7 +360,7 @@ void edit_user(const char *args, const char *name)
 			printf(_("New name set.\n"));
 			broadcast(3, "%s has just changed %s's realname from \"%s\" to \"%s\".",
 			          user->record.name, usr->name, oldreal, realname);
-			mwlog("CHANGE(REALNAME) of %s to %s", usr->name, realname);
+			mwlog(user, "CHANGE(REALNAME) of %s to %s", usr->name, realname);
 		}
 		free(oldreal);
 	}else
@@ -393,7 +394,7 @@ void edit_user(const char *args, const char *name)
 			printf(_("Room changed to %d.\n"), usr->room);
 			broadcast(3, "%s has just changed %s's room from %d to %d.",
 			          user->record.name, usr->name, oldroom, newroom);
-			mwlog("CHANGE(ROOM) of %s to %d", usr->name, newroom);
+			mwlog(user, "CHANGE(ROOM) of %s to %d", usr->name, newroom);
 		}
 	}else
 	if (stringcmp(args,"username",1))
@@ -435,7 +436,7 @@ void edit_user(const char *args, const char *name)
 				printf(_("New name set.\n"));
 				broadcast(3, "%s has just renamed %s to %s.",
 				          user->record.name, oldname, username);
-				mwlog("CHANGE(USERNAME) of %s to %s", oldname, username);
+				mwlog(user, "CHANGE(USERNAME) of %s to %s", oldname, username);
 			}else
 				printf(_("Change cancelled.\n"));
 		}else
@@ -454,7 +455,7 @@ void edit_user(const char *args, const char *name)
 			printf(_("New address set.\n"));
 			broadcast(3, "%s has just changed %s's contact to %s.",
 			          user->record.name, usr->name, contact);
-			mwlog("CHANGE(CONTACT) of %s to %s", usr->name, contact);
+			mwlog(user, "CHANGE(CONTACT) of %s to %s", usr->name, contact);
 		}
 	}else
 	if (stringcmp(args,"doing",2))
@@ -471,14 +472,14 @@ void edit_user(const char *args, const char *name)
 			printf(_("New status set.\n"));
 			broadcast(3, "%s has just changed %s's status to %s.",
 			          user->record.name, usr->name, doing);
-			mwlog("CHANGE(STATUS) of %s to %s", usr->name, doing);
+			mwlog(user, "CHANGE(STATUS) of %s to %s", usr->name, doing);
 		} else {
 			*(usr->doing) = 0;
 			usr->dowhen = 0;
 			ipc_send_to_username(usr->name, IPC_DOING, usr->doing);
 			printf(_("New status set.\n"));
 			broadcast(3, "%s has just cleared %s's status.", user->record.name, usr->name);
-			mwlog("CHANGE(STATUS) cleared %s", doing);
+			mwlog(user, "CHANGE(STATUS) cleared %s", doing);
 		}
 	}else
 	if (stringcmp(args,"timeout",1))
@@ -511,7 +512,7 @@ void edit_user(const char *args, const char *name)
 					printf(_("TIMEOUT now disabled.\n"));
 					broadcast(3, "%s has just disabled %s's timeout.",
 					         user->record.name, usr->name);
-					mwlog("CHANGE(TIMEOUT) of %s to disabled", usr->name);
+					mwlog(user, "CHANGE(TIMEOUT) of %s to disabled", usr->name);
 				}
 				else
 				{
@@ -530,7 +531,7 @@ void edit_user(const char *args, const char *name)
 				broadcast(3, "%s has just changed %s's timeout to %"PRId32" seconds.",
 				          user->record.name, usr->name, usr->timeout);
 				printf(_("New timeout set to %"PRId32" seconds.\n"), usr->timeout);
-				mwlog("CHANGE(TIMEOUT) of %s to %"PRId32" seconds", usr->name, usr->timeout);
+				mwlog(user, "CHANGE(TIMEOUT) of %s to %"PRId32" seconds", usr->name, usr->timeout);
 			}
 		}
 	}else
@@ -667,7 +668,7 @@ void edit_folder(const char *args, const char *name)
 				printf(_("WARNING: folder may get written over by the next folder created.\n"));
 		}
 		log[255] = '\0';
-		mwlog("%s", log);
+		mwlog(user, "%s", log);
 	}else
 	if (stringcmp(args,"groups",2))
 	{
@@ -678,7 +679,7 @@ void edit_folder(const char *args, const char *name)
 		if (*tmp)
 		{
 			fold.groups=folder_groups(tmp,fold.groups);
-			mwlog("FOLDER(GROUPS) of %s by %s", fold.name, tmp);
+			mwlog(user, "FOLDER(GROUPS) of %s by %s", fold.name, tmp);
 			show_fold_groups(fold.groups,tmp,true);
 			printf(_("Groups changed to [%s]\n"),tmp);
 		}
@@ -691,7 +692,7 @@ void edit_folder(const char *args, const char *name)
 		if (*tmp == '\0' || strchr(tmp, '/') != NULL) {
 			printf("Bad folder name\n");
 		} else {
-			mwlog("FOLDER(RENAME) of %s to %s", fold.name, tmp);
+			mwlog(user, "FOLDER(RENAME) of %s to %s", fold.name, tmp);
 			if (rename_folder(&fold, tmp) == 0)
 				printf(_("Name changed to %s\n"), fold.name);
 		}
@@ -737,7 +738,7 @@ void edit_folder(const char *args, const char *name)
 		{
 			strcpy(fold.topic,tmp);
 			printf(_("Topic changed to '%s'\n"),fold.topic);
-			mwlog("FOLDER(TOPIC) of %s to %s", fold.name, tmp);
+			mwlog(user, "FOLDER(TOPIC) of %s to %s", fold.name, tmp);
 		}
 	}else
 	if (stringcmp(args,"delete",6))
@@ -756,7 +757,7 @@ void edit_folder(const char *args, const char *name)
 			fold.name[0]=0;
 			users_lastread(folnum);
 			printf(_("Folder deleted.\n"));
-			mwlog("FOLDER(DELETE) %s", fold.name);
+			mwlog(user, "FOLDER(DELETE) %s", fold.name);
 		}else
 		{
 			printf(_("Not done.\n"));
@@ -977,7 +978,7 @@ void edit_contact(void)
 		strcpy(user->record.contact, contact);
 		printf(_("New address set.\n"));
 		broadcast(3, "Contact for %s has just changed to %s.", user->record.name, contact);
-		mwlog("CHANGE(CONTACT) of %s to %s", user->record.name, contact);
+		mwlog(user, "CHANGE(CONTACT) of %s to %s", user->record.name, contact);
 	}
 	update_user(user);
 }


=====================================
src/client/folders.c
=====================================
--- a/src/client/folders.c
+++ b/src/client/folders.c
@@ -8,6 +8,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
+
+#include <mwlog.h>
 #include "ipc.h"
 #include "files.h"
 #include "perms.h"
@@ -17,6 +19,8 @@
 #include "folders.h"
 #include "mesg.h"
 
+extern struct user * const user;
+
 void add_folder(void)
 {
 	struct folder new;
@@ -70,7 +74,7 @@ void add_folder(void)
 	}
 	Unlock_File(file);
 	close(file);
-	mwlog("FOLDER(CREATED) %s", new.name);
+	mwlog(user, "FOLDER(CREATED) %s", new.name);
 }
 
 void auto_subscribe(int folnum, int state)


=====================================
src/client/main.c
=====================================
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -17,6 +17,7 @@
 #include <netinet/in.h>
 #include <signal.h>
 
+#include <mwlog.h>
 #include "command.h"
 #include "alarm.h"
 #include "strings.h"
@@ -193,12 +194,12 @@ static void accept_line(char *line)
 	{
 		*comm=0;
 		eof_count++;
-		mwlog("EOF");
+		mwlog(user, "EOF");
 		if (eof_count>3)
 		{
 			broadcast(1, "\03304%s'%s connection has just dropped.", user->record.name,
 			          user->record.name[strlen(user->record.name)] == 's' ? "" : "s");
-			mwlog("EOF(LOGOUT)");
+			mwlog(user, "EOF(LOGOUT)");
 			close_down(LOGOFF_EOFS, NULL, NULL);
 		}
 	} else
@@ -650,9 +651,9 @@ int main(int argc, char **argv)
 		ss=sizeof(sa);
 		/* can we log a hostname ? */
 		if (getpeername(fileno(stdin), (struct sockaddr *)&sa, &ss))
-			mwlog("LOGIN");
+			mwlog(user, "LOGIN");
 		else
-			mwlog("LOGIN from %s", inet_ntoa(sa.sin_addr));
+			mwlog(user, "LOGIN from %s", inet_ntoa(sa.sin_addr));
 	}
 
 	time_t when = user->record.lastlogout;
@@ -758,7 +759,7 @@ int main(int argc, char **argv)
 			printf("<%d>\n", busy);
 			fflush(stdout);
 			perror("stdin");
-			mwlog("ERROR on stdin");
+			mwlog(user, "ERROR on stdin");
 			close_down(LOGOFF_ERROR, NULL, NULL);
 		}
 		if (!busy && MesgIsStacked())
@@ -909,7 +910,7 @@ void close_down(int logofftype, char *sourceuser, char *reason)
 	if (!quietmode && logofftype != LOGOFF_TIMEOUT && logofftype != LOGOFF_EOFS)
 		broadcast(1, "\03302%s has just left the board.", user->record.name);
 
-	mwlog("LOGOUT");
+	mwlog(user, "LOGOUT");
 	sleep(1); //dodgy hack for race condition in checkonoff, cunningly we currently get woken by the very message we're waiting for.
 
 	ipc_close();
@@ -1259,7 +1260,7 @@ static void time_out(void *idle_count_p)
 		write(1,msg,strlen(msg));
 
 		broadcast(1, _("\03304%s has been timed out."), user->record.name);
-		mwlog("TIMEOUT(LOGOUT)");
+		mwlog(user, "TIMEOUT(LOGOUT)");
 		close_down(LOGOFF_TIMEOUT, NULL, NULL);
 	}
 	else if (*icnt==0)
@@ -1272,7 +1273,7 @@ static void time_out(void *idle_count_p)
 	}
 	else
 	{
-		mwlog("TIMEOUT(BLOCKED)");
+		mwlog(user, "TIMEOUT(BLOCKED)");
 		close_down(LOGOFF_TIMEOUT, NULL, NULL);
 	}
 


=====================================
src/client/mesg.c
=====================================
--- a/src/client/mesg.c
+++ b/src/client/mesg.c
@@ -9,6 +9,7 @@
 #include <sys/stat.h>
 
 #include <util.h>
+#include <mwlog.h>
 #include "talker_privs.h"
 #include "special.h"
 #include "ipc.h"
@@ -63,10 +64,10 @@ void broadcast(int state, const char *fmt, ...)
 	israw = (state & 0x100) != 0;
 	state &= ~0x100;
 
-	if (state==0) mwlog("WALL %s", text);
-	else if (state==1 && israw) mwlog("BROADCAST %s", text);
-	else if (state==2) mwlog("WIZ %s", text);
-	else if (state==5) mwlog("STATUS %s", text);
+	if (state==0) mwlog(user, "WALL %s", text);
+	else if (state==1 && israw) mwlog(user, "BROADCAST %s", text);
+	else if (state==2) mwlog(user, "WIZ %s", text);
+	else if (state==5) mwlog(user, "STATUS %s", text);
 
 	switch (state) {
 		case 1:
@@ -102,31 +103,3 @@ void broadcast(int state, const char *fmt, ...)
 			ipc_send_to_all(IPC_TEXT, buff);
 	}
 }
-
-void mwlog(const char *fmt, ...)
-{
-	char detail[LOGLINESIZE];
-	mode_t mask;
-	va_list ap;
-	time_t t;
-	char *ts;
-	FILE *fp;
-
-	mask = umask(077);
-	fp = fopen(LOGFILE, "a");
-	umask(mask);
-	if (fp == NULL) {
-		perror(LOGFILE);
-		return;
-	}
-	t=time(0);
-	ts = asctime(gmtime(&t));
-	if (ts != NULL && *ts != '\0')
-		ts[strlen(ts) - 1] = '\0';
-	va_start(ap, fmt);
-	vsnprintf(detail, LOGLINESIZE-1, fmt, ap);
-	va_end(ap);
-	fprintf(fp, "%s | %*s | %s\n", ts, NAMESIZE, user->record.name, detail);
-	fclose(fp);
-}
-


=====================================
src/client/mesg.h
=====================================
--- a/src/client/mesg.h
+++ b/src/client/mesg.h
@@ -6,6 +6,5 @@
 void broadcast(int state, const char *fmt, ...) __attribute__((format(printf,2,3)));
 void inform_of_mail(char *to);
 void postinfo(struct user *who, struct folder *fol, struct Header *mesg);
-void mwlog(const char *fmt, ...) __attribute__((format(printf,1,2)));
 
 #endif /* MESG_H */


=====================================
src/client/newmain.c
=====================================
--- a/src/client/newmain.c
+++ b/src/client/newmain.c
@@ -11,6 +11,7 @@
 #include <stdbool.h>
 #include <locale.h>
 
+#include <mwlog.h>
 #include "folders.h"
 #include "iconv.h"
 #include "strings.h"
@@ -468,7 +469,7 @@ void c_mesg(CommandList *cm, int argc, const char **argv, char *args)
 	busy++;
 	mesg_edit(argv[1], &user->folder, atoi(argv[2]), user);
 	busy--;
-	mwlog("MESSAGE %s %s:%d",argv[1], user->folder.name, atoi(argv[2]));
+	mwlog(user, "MESSAGE %s %s:%d",argv[1], user->folder.name, atoi(argv[2]));
 }
 
 void c_latest(CommandList *cm, int argc, const char **argv, char *args)
@@ -815,7 +816,7 @@ void c_passwd(CommandList *cm, int argc, const char **argv, char *args)
 			strcpy(user->record.passwd, pw1);
 			update_user(user);
 			printf(_("Password set.\n"));
-			mwlog("CHANGE(PASSWD)");
+			mwlog(user, "CHANGE(PASSWD)");
 		}
 	}
 }


=====================================
src/client/talker.c
=====================================
--- a/src/client/talker.c
+++ b/src/client/talker.c
@@ -7,6 +7,7 @@
 #include <stdbool.h>
 
 #include <sqlite.h>
+#include <mwlog.h>
 #include "bb.h"
 #include "talker_privs.h"
 #include "special.h"
@@ -60,7 +61,7 @@ static void talk_send_to_room(const char * text, int channel, const char * type,
 }
 
 void talk_send_shout(char * text){
-	mwlog("SHOUT %s", text);
+	mwlog(user, "SHOUT %s", text);
 	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOALL, user->posn);
 	json_t * j = json_init(NULL);
 	json_addstring(j, "text", text);
@@ -71,25 +72,25 @@ void talk_send_shout(char * text){
 
 static void talk_send_say(const char * text, int channel)
 {
-	mwlog("SAY %s", text);
+	mwlog(user, "SAY %s", text);
 	catchuri(text);
 	talk_send_to_room(text, channel, "say", -1);
 }
 
 void talk_send_raw(char * text, int channel){
-	mwlog("RAW %s", text);
+	mwlog(user, "RAW %s", text);
 	catchuri(text);
 	talk_send_to_room(text, channel, "raw", -1);
 }
 
 void talk_send_rawbcast(char * text){
-	mwlog("RAWBCAST %s", text);
+	mwlog(user, "RAWBCAST %s", text);
 	ipc_send_to_all(IPC_TEXT, text);
 }
 
 void talk_send_emote(char * text, int channel, int plural){
 	catchuri(text);
-	mwlog("EMOTE %s", text);
+	mwlog(user, "EMOTE %s", text);
 	talk_send_to_room(text, channel, "emote", plural);
 }
 
@@ -104,7 +105,7 @@ void talk_sayto(char *text, const char *to, const char *type)
 	json_decref(j);
 	ipcmsg_transmit(msg);
 
-	mwlog("SAYTO %s %s",to,text);
+	mwlog(user, "SAYTO %s %s",to,text);
 }
 
 int screen_h(void)
@@ -415,7 +416,7 @@ void t_notsayto(CommandList *cm, int argc, const char **argv, char *args)
 	char text[MAXTEXTLENGTH];
 
 	snprintf(text, MAXTEXTLENGTH, "%s", args);
-	mwlog("NSAYTO %s %s", argv[1], text);
+	mwlog(user, "NSAYTO %s %s", argv[1], text);
 
 	/* variant of say_to_room but with an exclude clause */
 	ipc_message_t * msg = ipcmsg_create(IPC_SAYTOROOM, user->posn);
@@ -1048,11 +1049,11 @@ void t_topic(CommandList *cm, int argc, const char **argv, char *args)
 		if (topic == NULL || *topic == 0) {
 			snprintf(text, MAXTEXTLENGTH-1, "\03315%s has cleared the channel topic.",
 			         user->record.name);
-			mwlog("TOPIC <empty>");
+			mwlog(user, "TOPIC <empty>");
 		} else {
 			snprintf(text, MAXTEXTLENGTH-1, "\03315%s has set the topic to \"%s\".",
 			         user->record.name, topic);
-			mwlog("TOPIC %s", topic);
+			mwlog(user, "TOPIC %s", topic);
 		}
 		talk_send_raw(text, user->record.room);
 	} else {
@@ -1198,9 +1199,9 @@ void sendipc(const char *to, const char *text, int bcast)
 	}else
 	{
 		if (bcast)
-			mwlog("SENDIPB %s", text);
+			mwlog(user, "SENDIPB %s", text);
 		else
-			mwlog("SENDIPC(%s) %s",to,text);
+			mwlog(user, "SENDIPC(%s) %s",to,text);
 	}
 }
 
@@ -1224,9 +1225,9 @@ void sendrpc(const char *to, const char *type, const char *text, int bcast)
 	}else
 	{
 		if (bcast)
-			mwlog("SENDRPB(%s) %s", type, text);
+			mwlog(user, "SENDRPB(%s) %s", type, text);
 		else
-			mwlog("SENDRPC(%s, %s) %s", to, type, text);
+			mwlog(user, "SENDRPC(%s, %s) %s", to, type, text);
 	}
 }
 


=====================================
src/client/uri.c
=====================================
--- a/src/client/uri.c
+++ b/src/client/uri.c
@@ -6,6 +6,7 @@
 
 #include <sqlite.h>
 #include <util.h>
+#include <mwlog.h>
 #include "uri.h"
 #include "sqlite.h"
 #include "talker.h"
@@ -420,7 +421,7 @@ void uri_delete(int argc, const char **argv, int wiz)
 							snprintf(mesg, MAXTEXTLENGTH-1, "\03315%s has just deleted %s's uri %s [%s] from mwuri", user->record.name, username, uri, added);
 							broadcast(1, "%s", mesg);
 							snprintf(mesg, MAXTEXTLENGTH-1, "MWURI %s deleted uri: %s <%s> [%s]",  user->record.name, username, uri, added);
-							mwlog("%s", mesg);
+							mwlog(user, "%s", mesg);
 						}
 						else
 						{
@@ -515,7 +516,7 @@ static void uri_set_flag(int argc, const char **argv, int wiz, int flag)
 							snprintf(mesg, MAXTEXTLENGTH-1, "\03304%s has just %sset the %s flag on %s's uri %s [%s] in mwuri", user->record.name, flag&flags?"":"un", desc_str, username, uri, added);
 							broadcast(3, "%s", mesg);
 							snprintf(mesg, MAXTEXTLENGTH-1, "MWURI %s %sset %s flag on uri: %s <%s> [%s]",  user->record.name, flag&flags?"":"un", desc_str, username, uri, added);
-							mwlog("%s", mesg);
+							mwlog(user, "%s", mesg);
 						}
 						else
 						{


=====================================
src/client/user.c
=====================================
--- a/src/client/user.c
+++ b/src/client/user.c
@@ -12,6 +12,8 @@
 #include <pwd.h>
 #include <time.h>
 #include <stdbool.h>
+
+#include <mwlog.h>
 #include "special.h"
 #include "talker_privs.h"
 #include "talker.h"
@@ -224,7 +226,7 @@ MAX OF 10 MESSAGES IN THE LAST 2 WEEKS
 			tmp->groups|=1;
 			tmp->chatprivs|=CP_SCRIPT;
 		}
-		mwlog("AUTOREGISTER %s",getmylogin());
+		mwlog(user, "AUTOREGISTER %s",getmylogin());
 		ret = 1; /* Autoregistered */
 	}
 	return ret;
@@ -284,7 +286,7 @@ static int new_usr(char *name, struct user *u)
 		get_str(usr->contact,CONTACTSIZE);
 		strip_str(usr->contact);
 
-		mwlog("CREATED: %s <%s>",usr->realname, usr->contact);
+		mwlog(user, "CREATED: %s <%s>",usr->realname, usr->contact);
 
 		int ret = 2; /* New user */
 		ret += set_defaults(usr);


=====================================
src/mwlog.c
=====================================
--- /dev/null
+++ b/src/mwlog.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <time.h>
+
+#include "mwlog.h"
+
+void mwlog(struct user *user, const char *fmt, ...)
+{
+	char detail[LOGLINESIZE];
+	mode_t mask;
+	va_list ap;
+	time_t t;
+	char *ts;
+	FILE *fp;
+
+	mask = umask(077);
+	fp = fopen(LOGFILE, "a");
+	umask(mask);
+	if (fp == NULL) {
+		perror(LOGFILE);
+		return;
+	}
+	t = time(0);
+	ts = asctime(gmtime(&t));
+	if (ts != NULL && *ts != '\0')
+		ts[strlen(ts) - 1] = '\0';
+	va_start(ap, fmt);
+	vsnprintf(detail, LOGLINESIZE-1, fmt, ap);
+	va_end(ap);
+	fprintf(fp, "%s | %*s | %s\n", ts, NAMESIZE, user->record.name, detail);
+	fclose(fp);
+}


=====================================
src/mwlog.h
=====================================
--- /dev/null
+++ b/src/mwlog.h
@@ -0,0 +1,14 @@
+#ifndef MWLOG_H
+#define MWLOG_H
+
+#include "user.h"
+
+#ifndef LOGDIR
+#define LOGDIR "/var/log/mw"
+#endif
+#define LOGFILE LOGDIR "/log.bb"
+#define LOGLINESIZE 2048
+
+void mwlog(struct user *user, const char *fmt, ...) __attribute__((format(printf,2,3)));
+
+#endif /* MWLOG_H */


=====================================
src/webclient/comms.c
=====================================
--- a/src/webclient/comms.c
+++ b/src/webclient/comms.c
@@ -23,6 +23,7 @@
 #include <perms.h>
 #include <bb.h>
 #include <util.h>
+#include <mwlog.h>
 #include "import.h"
 #include "comms.h"
 #include "mwstring.h"
@@ -71,8 +72,6 @@ struct list_head connlist;
 char * json_escape(char *in);
 static void handle_mesg(void);
 
-void mwlog(const char *fmt, ...) __attribute__((format(printf,1,2)));
-
 /* unix socket to accept control commands from */
 void open_command_socket()
 {
@@ -454,7 +453,7 @@ static int handle_command(CONNECTION *co)
 		json_decref(j);
 		ipcmsg_transmit(msg);
 
-		mwlog("SAYTO %s %s", to, text);
+		mwlog(user, "SAYTO %s %s", to, text);
 
 		asprintf(&status, "{\"status\":\"sayto sent to %s (%s)\"}", to, text);
 		send(co->fd, status, strlen(status), 0);
@@ -463,7 +462,7 @@ static int handle_command(CONNECTION *co)
 	}else
         if (co->authd && strncasecmp(buff, "emote ", 6)==0) {
 		talk_send_to_room(&buff[6], user->record.room, "emote", 0);
-		mwlog("EMOTE %s", &buff[6]);
+		mwlog(user, "EMOTE %s", &buff[6]);
                 snprintf(buff, sizeof buff, "{\"status\":\"Emote Sent to channel %d\"}", user->record.room);
                 send(co->fd, buff, strlen(buff), 0);
 		user->record.idletime = lastcomm;
@@ -522,7 +521,7 @@ static int handle_command(CONNECTION *co)
 	}else
 	if (co->authd && strncasecmp(buff, "say ", 4)==0) {
 		talk_send_to_room(&buff[4], user->record.room, "say", -1);
-		mwlog("SAY %s", &buff[4]);
+		mwlog(user, "SAY %s", &buff[4]);
 		snprintf(buff, sizeof buff, "{\"status\":\"Message Sent to channel %d\"}", user->record.room);
 		send(co->fd, buff, strlen(buff), 0);
 		user->record.idletime = lastcomm;
@@ -610,40 +609,13 @@ void create_user(struct user *me, const char *username, const char *password)
 	if ((pw=getpwnam(username))!=NULL) {
 		snprintf(urec->realname, sizeof(urec->realname), "%s", pw->pw_gecos);
 		snprintf(urec->contact, sizeof(urec->contact), "%s at sucs.org", pw->pw_name);
-		mwlog("CREATED %s <%s>", urec->realname, urec->contact);
+		mwlog(user, "CREATED %s <%s>", urec->realname, urec->contact);
 	} else {
-		mwlog("CREATED Auto web user");
+		mwlog(user, "CREATED Auto web user");
 	}
 	userdb_write(me);
 }
 
-void mwlog(const char *fmt, ...)
-{
-	char detail[LOGLINESIZE];
-	mode_t mask;
-	va_list ap;
-	time_t t;
-	char *ts;
-	FILE *fp;
-
-	mask = umask(077);
-	fp = fopen(LOGFILE, "a");
-	umask(mask);
-	if (fp == NULL) {
-		perror(LOGFILE);
-		return;
-	}
-	t=time(0);
-	ts = asctime(gmtime(&t));
-	if (ts != NULL && *ts != '\0')
-		ts[strlen(ts) - 1] = '\0';
-	va_start(ap, fmt);
-	vsnprintf(detail, LOGLINESIZE-1, fmt, ap);
-	va_end(ap);
-	fprintf(fp, "%s | %*s | %s\n", ts, NAMESIZE, user->record.name, detail);
-	fclose(fp);
-}
-
 int32_t who_find(const char *username)
 {
           if (whoinfo == NULL) return -1;



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/4e82e903f326d269f702ccd63803473afa70a6cb

-- 
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/4e82e903f326d269f702ccd63803473afa70a6cb
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20181122/d3c86692/attachment-0001.html>


More information about the mw-devel mailing list