[mw-devel] MW3 r1270 - in trunk: . src src/server src/webclient

arthur at sucs.org arthur at sucs.org
Mon Nov 5 13:25:52 GMT 2012


Author: arthur
Date: 2012-11-05 13:25:51 +0000 (Mon, 05 Nov 2012)
New Revision: 1270

Modified:
   trunk/Makefile.common
   trunk/src/files.c
   trunk/src/files.h
   trunk/src/ipc.c
   trunk/src/main.c
   trunk/src/server/Makefile
   trunk/src/server/mwserv.c
   trunk/src/server/servsock.c
   trunk/src/socket.c
   trunk/src/socket.h
   trunk/src/strings.c
   trunk/src/talker.c
   trunk/src/user.c
   trunk/src/user.h
   trunk/src/webclient/import.c
   trunk/src/webclient/mwpoll.c
   trunk/src/who.c
   trunk/src/who.h
Log:
reorganise a few files, move who file updates to the server


Modified: trunk/Makefile.common
===================================================================
--- trunk/Makefile.common	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/Makefile.common	2012-11-05 13:25:51 UTC (rev 1270)
@@ -1,7 +1,7 @@
 SVNVER = $(shell ( svnversion -c . 2>/dev/null || echo 0:0 ) | cut -d : -f 2)
 
 VERSION_MAJOR = 2
-VERSION_MINOR = 16
+VERSION_MINOR = 17
 
 ifeq ($(SVNVER),exported)
 # mw.rev is created after an export so we can rely on it to provide the svn rev here

Modified: trunk/src/files.c
===================================================================
--- trunk/src/files.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/files.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -101,21 +101,6 @@
 	exit(-1);
 }
 
-int is_old(struct person *usr, const char *name, int32_t *userposn)
-{
-	int file,found=false;
-
-	if (access(USERFILE,00)) return(false);
-	file=openuserfile(O_RDONLY);
-	while (!found && get_person(file,usr))
-		if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
-			found=true;
-	if (found) 
-		*userposn=lseek(file,0,1)-sizeof(struct person);
-	close(file);
-	return(found);
-}
-
 void write_usr(struct person *record, int32_t *userposn)
 {
 	int outfile;
@@ -183,7 +168,31 @@
 	Unlock_File(wfile);
 	close(wfile);
 }
-	
+
+void who_delete(int pid)
+{
+	int fd;
+	struct who temp;
+	fd=openwhofile(O_RDWR);
+	if(fd==-1)
+	{
+		perror("who_delete");
+		exit(1);
+	}
+	Lock_File(fd);
+	while(read(fd,&temp,sizeof(temp))==sizeof(temp))
+	{
+		if (temp.pid==pid) {
+			lseek(fd,(long)-sizeof(temp),1);
+			temp.pid=-1;
+			temp.posn=-1L;
+			write(fd,&temp,sizeof(temp));
+		}
+	}
+	Unlock_File(fd);
+	close(fd);
+}
+
 int openfolderfile(int mode)
 {
 	int x;

Modified: trunk/src/files.h
===================================================================
--- trunk/src/files.h	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/files.h	2012-11-05 13:25:51 UTC (rev 1270)
@@ -19,10 +19,10 @@
 int openfolderfile(int mode);
 int nofolders(void);
 int openuserfile(int flags);
-int is_old(struct person *usr, const char *name, int32_t *userposn);
 void write_usr(struct person *record, int32_t *userposn);
 int openwhofile(int mode);
 void who_add(int pid, int32_t posn);
+void who_delete(int pid);
 void create_folder_file(void);
 int foldernumber(char *name);
 int get_folder_entry(int file, struct folder *tmp);

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/ipc.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -18,6 +18,8 @@
 ipc_connection_t * ipcsock = NULL;
 char *ipc_parent = NULL;
 
+extern long userposn;
+
 void ipc_connect(const char *target)
 {
 	const char * host = target;
@@ -45,6 +47,7 @@
 
 	pid_t mypid = getpid();
 	ipc_message_t * msg = ipcmsg_create(FOURCC("HELO"), mypid);
+	ipcmsg_append(msg, &userposn, sizeof(userposn));
 	ipcmsg_send(msg, ipcsock);
 }
 

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/main.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -750,7 +750,6 @@
 
 	user->idletime=time(0);
 	update_user(user,userposn);	
-	who_add(getpid(),userposn);
 
 	/* list new BBS items */
 	list_new_items(user,true);
@@ -969,7 +968,6 @@
 
 	mwlog("LOGOUT");
 	sleep(1); //dodgy hack for race condition in checkonoff, cunningly we currently get woken by the very message we're waiting for.
-	who_delete(getpid());
 #ifdef RWHO
 	rwhocli_userlogout(user->name);
 #endif

Modified: trunk/src/server/Makefile
===================================================================
--- trunk/src/server/Makefile	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/server/Makefile	2012-11-05 13:25:51 UTC (rev 1270)
@@ -49,7 +49,7 @@
 
 .PHONY: build install clean test
 
-mwserv: mwserv.o servsock.o ../socket.o
+mwserv: mwserv.o servsock.o ../socket.o ../files.o ../strings.o ../ipc.o ../iconv.o
 	$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
 
 clean:

Modified: trunk/src/server/mwserv.c
===================================================================
--- trunk/src/server/mwserv.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/server/mwserv.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -7,6 +7,11 @@
 #include "../socket.h"
 #include "servsock.h"
 
+/* unused, but necessary to link other util functions */
+int idle = 0;
+int internet = 0;
+int userposn = 0;
+
 struct servopts {
 	uint16_t port;
 	int help;

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/server/servsock.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -17,6 +17,7 @@
 
 #include "../socket.h"
 #include "servsock.h"
+#include "../files.h"
 
 struct list_head connection_list;
 
@@ -120,6 +121,7 @@
 	if (conn->fd != -1) close(conn->fd);
 	conn->fd = -1;
 	conn->state = IPCSTATE_ERROR;
+	who_delete(conn->addr);
 	if (!list_empty(&conn->outq)) {
 		struct list_head *pos, *q;
 		list_for_each_safe(pos, q, &conn->outq) {
@@ -227,6 +229,8 @@
 	/* client just told us who they are */
 	if (msg->head.type == FOURCC("HELO")) {
 		memcpy(&conn->addr, &msg->head.src, sizeof(conn->addr));
+		memcpy(&conn->user, msg->body, sizeof(conn->user));
+		who_add(conn->addr, conn->user);
 		conn->state = IPCSTATE_VALID;
 		ipcmsg_destroy(msg);
 		return;

Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/socket.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -25,7 +25,7 @@
 }
 
 /* add body text to a message, +1 to make C string safe */
-void ipcmsg_append(ipc_message_t *msg, const char * data, int len)
+void ipcmsg_append(ipc_message_t *msg, const void * data, int len)
 {
 	if (msg == NULL) return;
 	int want = msg->bodylen + len + 1;

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/socket.h	2012-11-05 13:25:51 UTC (rev 1270)
@@ -31,7 +31,8 @@
 
 typedef struct {
 	struct list_head 	list;	/* list of connections */
-	uint32_t		addr;	/* id of client at other end */
+	uint32_t		addr;	/* (p)id of client at other end */
+	uint32_t		user;	/* user id of client */
 	enum ipcsock_state	state;
 
 	int 			fd;
@@ -49,7 +50,7 @@
 unsigned int FOURCC(char *a);
 /* socket.c */
 ipc_message_t *ipcmsg_create(uint32_t type,uint32_t src);
-void ipcmsg_append(ipc_message_t *msg, const char *data, int len);
+void ipcmsg_append(ipc_message_t *msg, const void *data, int len);
 void ipcmsg_destination(ipc_message_t *msg, uint32_t dest);
 void ipcmsg_destroy(ipc_message_t *msg);
 void ipcmsg_send(ipc_message_t *msg, ipc_connection_t *conn);

Modified: trunk/src/strings.c
===================================================================
--- trunk/src/strings.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/strings.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -411,3 +411,50 @@
 	new[j]=0;
 	return(new);
 }
+
+/* Strip any trailing quote characters (^a) that may have been left at the end
+ *  * of a buffer by snprintf() truncating a quoted string.
+ *   */
+void strip_quote(char *a)
+{
+    char *end = a + strlen(a);
+
+    /* Step back through quote chars */
+    while (end > a && *(--end) == '\001')
+        *end = '\0';
+}
+
+char *quotetext(const char *a)
+{
+        int     count;
+        int     ai, bi;
+        char    *b;
+
+        ai=0;
+        count=0;
+        while(a[ai]!=0)
+        {
+                if (a[ai]=='|') count++;
+                ai++;
+        }
+
+        b = malloc(sizeof(char) * (strlen(a) + count + 1));
+
+        ai=bi=0;
+        while (a[ai]!=0)
+        {
+                if (a[ai]=='|')
+                {
+                        b[bi]=1;
+                        bi++;
+                }
+
+                b[bi]=a[ai];
+                bi++;
+                ai++;
+        }
+        b[bi]=0;
+
+        return (b);
+}
+

Modified: trunk/src/talker.c
===================================================================
--- trunk/src/talker.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/talker.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -1653,52 +1653,6 @@
 	}
 }
 
-/* Strip any trailing quote characters (^a) that may have been left at the end
- * of a buffer by snprintf() truncating a quoted string.
- */
-void strip_quote(char *a)
-{
-    char *end = a + strlen(a);
-
-    /* Step back through quote chars */
-    while (end > a && *(--end) == '\001')
-	*end = '\0';
-}
-
-char *quotetext(const char *a)
-{
-	int	count;
-	int	ai, bi;
-	char	*b;
-
-	ai=0;
-	count=0;
-	while(a[ai]!=0)
-	{
-		if (a[ai]=='|') count++;
-		ai++;
-	}
-
-	b = malloc(sizeof(char) * (strlen(a) + count + 1));
-
-	ai=bi=0;
-	while (a[ai]!=0)	
-	{
-		if (a[ai]=='|') 
-		{
-			b[bi]=1;
-			bi++;
-		}
-
-		b[bi]=a[ai];
-		bi++;
-		ai++;
-	}
-	b[bi]=0;
-
-	return (b);
-}
-
 struct IgnoreList *is_ignored(char *name, struct IgnoreList **prev)
 {
 	struct IgnoreList *tail;

Modified: trunk/src/user.c
===================================================================
--- trunk/src/user.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/user.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -354,6 +354,21 @@
 	else return(false);	
 }
 
+int is_old(struct person *usr, const char *name, int32_t *userposn)
+{
+	int file,found=false;
+
+	if (access(USERFILE,00)) return(false);
+	file=openuserfile(O_RDONLY);
+	while (!found && get_person(file,usr))
+		if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
+			found=true;
+	if (found)
+		*userposn=lseek(file,0,1)-sizeof(struct person);
+	close(file);
+	return(found);
+}
+
 void login_ok(struct person *usr, int32_t *userposn, int *autochat)
 {	
 	/* main function */

Modified: trunk/src/user.h
===================================================================
--- trunk/src/user.h	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/user.h	2012-11-05 13:25:51 UTC (rev 1270)
@@ -58,5 +58,6 @@
 void pick_salt(char *salt);
 void search(char *args, char *ptr);
 void fetch_user(struct person *record, int32_t userposn);
+int is_old(struct person *usr, const char *name, int32_t *userposn);
 
 #endif

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/webclient/import.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -98,73 +98,6 @@
         close(outfile);
 }
 
-void who_delete(int pid)
-{
-	int fd;
-	struct who temp;
-	fd=openwhofile(O_RDWR);
-	if(fd==-1)
-	{
-		perror("who_delete");
-		exit(1);
-	}
-	Lock_File(fd);
-	while(read(fd,&temp,sizeof(temp))==sizeof(temp))
-	{
-		if (temp.pid==pid) {
-			lseek(fd,(long)-sizeof(temp),1);
-			temp.pid=-1;
-			temp.posn=-1L;
-			write(fd,&temp,sizeof(temp));
-		}
-	}
-	Unlock_File(fd);
-	close(fd);
-}
-
-char *quotetext(const char *a)
-{
-        int     count;
-        int     ai, bi;
-        char    *b;
-
-        ai=0;
-        count=0;
-        while(a[ai]!=0)
-        {
-                if (a[ai]=='|') count++;
-                ai++;
-        }
-
-        b = malloc(sizeof(char) * (strlen(a) + count + 1));
-
-        ai=bi=0;
-        while (a[ai]!=0)
-        {
-                if (a[ai]=='|')
-                {
-                        b[bi]=1;
-                        bi++;
-                }
-
-                b[bi]=a[ai];
-                bi++;
-                ai++;
-        }
-        b[bi]=0;
-
-        return (b);
-}
-
-void strip_quote(char *a)
-{
-    char *end = a + strlen(a);
-
-    /* Step back through quote chars */
-    while (end > a && *(--end) == '\001')
-        *end = '\0';
-}
-
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason)
 {
         char            logofftext[MAXTEXTLENGTH];
@@ -238,3 +171,17 @@
         } else return(NULL);
 }
 
+int is_old(struct person *usr, const char *name, int32_t *userposn)
+{
+        int file,found=false;
+
+        if (access(USERFILE,00)) return(false);
+        file=openuserfile(O_RDONLY);
+        while (!found && get_person(file,usr))
+                if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
+                        found=true;
+        if (found)
+                *userposn=lseek(file,0,1)-sizeof(struct person);
+        close(file);
+        return(found);
+}

Modified: trunk/src/webclient/mwpoll.c
===================================================================
--- trunk/src/webclient/mwpoll.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/webclient/mwpoll.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -24,6 +24,7 @@
 /* unused */
 int internet = 0;
 int idle = 0;
+int32_t userposn = 0;
 
 #define DEFAULT_IDLE 60
 int clientidle = DEFAULT_IDLE;
@@ -70,7 +71,6 @@
 {
 	char *username;
 	int opt;
-	int32_t userposn;
 	int channel = 0;
 	int debug = 0;
 	int dbsession = 0;
@@ -224,7 +224,6 @@
         	return 0;
 	}
 
-	who_add(getpid(),userposn);
 	loggedin = lastcomm = loggedin;
 	
 	/* spock, announce us please... */
@@ -271,7 +270,6 @@
 
 	user->idletime=time(0);
 	update_user(user,userposn);
-	who_delete(getpid());
 	close_fifo();
 	close_cmd();
 	return 0;

Modified: trunk/src/who.c
===================================================================
--- trunk/src/who.c	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/who.c	2012-11-05 13:25:51 UTC (rev 1270)
@@ -28,30 +28,6 @@
 extern struct person *user;
 extern struct room myroom;
 
-void who_delete(int pid)
-{
-	int fd;
-	struct who temp;
-	fd=openwhofile(O_RDWR);
-	if(fd==-1)
-	{
-		perror("who_delete");
-		exit(1);
-	}
-	Lock_File(fd);
-	while(read(fd,&temp,sizeof(temp))==sizeof(temp))
-	{
-		if (temp.pid==pid) {
-			lseek(fd,(long)-sizeof(temp),1);
-			temp.pid=-1;
-			temp.posn=-1L;
-			write(fd,&temp,sizeof(temp));
-		}
-	}
-	Unlock_File(fd);
-	close(fd);
-}
-			
 void what_list(void) {
 	struct person	u;
 	int		ufile;

Modified: trunk/src/who.h
===================================================================
--- trunk/src/who.h	2012-11-05 12:14:20 UTC (rev 1269)
+++ trunk/src/who.h	2012-11-05 13:25:51 UTC (rev 1270)
@@ -12,7 +12,6 @@
 void check_copies(int32_t where);
 void who_list(int mode);
 void what_list(void);
-void who_delete(int pid);
 char *itime(unsigned long t);
 int32_t get_who_userposn(int pid);
 




More information about the mw-devel mailing list