[mw-devel] MW3 r1349 - in trunk/src: . client server webclient
welshbyte at sucs.org
welshbyte at sucs.org
Fri Nov 1 18:29:19 GMT 2013
Author: welshbyte
Date: 2013-11-01 18:29:19 +0000 (Fri, 01 Nov 2013)
New Revision: 1349
Added:
trunk/src/user.c
Modified:
trunk/src/client/edit.c
trunk/src/client/folders.c
trunk/src/client/js.c
trunk/src/client/main.c
trunk/src/client/mesg.c
trunk/src/client/script_inst.c
trunk/src/client/talker.c
trunk/src/client/user.c
trunk/src/client/who.c
trunk/src/files.c
trunk/src/files.h
trunk/src/ipc.c
trunk/src/server/servsock.c
trunk/src/user.h
trunk/src/webclient/comms.c
trunk/src/webclient/import.c
Log:
Rejig the user file code into user.{c,h} as before, we could do with a function to iterate over the user file entries to remove some duplicate code and abstract this stuff away.
Modified: trunk/src/client/edit.c
===================================================================
--- trunk/src/client/edit.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/edit.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -603,7 +603,7 @@
struct person usr;
int ufile;
- ufile=openuserfile(O_RDWR);
+ ufile=userdb_open(O_RDWR);
Lock_File(ufile);
while (read(ufile,&usr,sizeof(usr))>0)
{
Modified: trunk/src/client/folders.c
===================================================================
--- trunk/src/client/folders.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/folders.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -80,7 +80,7 @@
struct person us;
char buff[10];
- ufile=openuserfile(O_RDWR);
+ ufile=userdb_open(O_RDWR);
Lock_File(ufile); /*user file*/
while(get_person(ufile,&us))
{
Modified: trunk/src/client/js.c
===================================================================
--- trunk/src/client/js.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/js.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -667,7 +667,7 @@
int n=0;
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) {
JS_ReportError(cx, "wholist() could not open userdb.");
Modified: trunk/src/client/main.c
===================================================================
--- trunk/src/client/main.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/main.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -1795,7 +1795,7 @@
if (wfile!=0) close(wfile);
if (ufile!=0) close(ufile);
wfile=who_open(O_RDONLY);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return(NULL); /* whoops */
len=strlen(text);
@@ -1838,7 +1838,7 @@
if (wfile!=0) close(wfile);
if (ufile!=0) close(ufile);
wfile=who_open(O_RDONLY);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return(NULL); /* whoops */
len=strlen(text);
@@ -1878,7 +1878,7 @@
if (status==0)
{
if (file!=0) close(file);
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
len=strlen(text);
}
Modified: trunk/src/client/mesg.c
===================================================================
--- trunk/src/client/mesg.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/mesg.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -61,7 +61,7 @@
int ufile,wfile;
wfile=who_open(O_RDONLY);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
while (read(wfile,&w,sizeof(w)))
{
@@ -131,7 +131,7 @@
else if (state==5) mwlog("STATUS %s", text);
wfile=who_open(O_RDONLY);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
while (read(wfile,&w,sizeof(w)))
{
Modified: trunk/src/client/script_inst.c
===================================================================
--- trunk/src/client/script_inst.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/script_inst.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -171,7 +171,7 @@
if (script_debug) escprintf("- %s: Getting idletime of user '%s'.\n", pc->inst->name, uname);
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0)
{
/* hideous problems with user info files */
@@ -364,7 +364,7 @@
what=eval_arg(pc->argv[0], fargc, fargv);
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return; /* whoops */
buff[0] = 0;
@@ -455,7 +455,7 @@
if (script_debug) escprintf("- %s: Getting room of user '%s'.\n", pc->inst->name, uname);
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0)
{
/* hideous problems with user info files */
@@ -636,7 +636,7 @@
struct who w;
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return; /* whoops */
while (read(wfile,&w,sizeof(w)))
Modified: trunk/src/client/talker.c
===================================================================
--- trunk/src/client/talker.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/talker.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -1018,7 +1018,7 @@
struct who w;
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return; /* whoops */
while (read(wfile,&w,sizeof(w)))
Modified: trunk/src/client/user.c
===================================================================
--- trunk/src/client/user.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/user.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -51,7 +51,7 @@
{
int outfile;
- outfile=openuserfile(O_RDWR|O_CREAT);
+ outfile=userdb_open(O_RDWR|O_CREAT);
/*Lock_File(outfile); */
lseek(outfile,userposn,0);
write(outfile,record,sizeof(*record));
@@ -63,7 +63,7 @@
{
int outfile;
- outfile=openuserfile(O_RDWR|O_CREAT);
+ outfile=userdb_open(O_RDWR|O_CREAT);
lseek(outfile,userposn,0);
read(outfile,record,sizeof(*record));
close(outfile);
@@ -331,7 +331,7 @@
user=usr;
printf(_("Creating new user %s\n"),name);
- write_usr(usr,userposn);
+ userdb_write(usr,userposn);
return(true);
}
else return(false);
@@ -342,7 +342,7 @@
int file,found=false;
if (access(USERFILE,00)) return(false);
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
while (!found && get_person(file,usr))
if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
found=true;
@@ -381,7 +381,7 @@
int screen_height = screen_h();
long logout_time;
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
while (get_person(file,&usr))
{
if (!newonly || ( newonly && !u_reg(usr.status) ) )
@@ -420,7 +420,7 @@
int screen_height = screen_h();
long logout_time;
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
while (get_person(file,&usr))
{
if (usr.lastlogout>date)
@@ -462,7 +462,7 @@
long logout_time;
int screen_height=screen_h();
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
while (get_person(file,&usr))
{
if (type==0) check=usr.status;
Modified: trunk/src/client/who.c
===================================================================
--- trunk/src/client/who.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/client/who.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -32,7 +32,7 @@
time_t t;
char * timestr;
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (ufile < 0) return; /* whoops */
while (read(ufile, &u, sizeof(u))) {
@@ -61,7 +61,7 @@
busy++;
wfile=who_open(O_RDWR);
- ufile=openuserfile(O_RDONLY);
+ ufile=userdb_open(O_RDONLY);
if (wfile<0 || ufile<0) return; /* whoops */
/* do we tell them who can hear wiz messages */
Modified: trunk/src/files.c
===================================================================
--- trunk/src/files.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/files.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -48,50 +48,6 @@
}
}
-static int createuserfile(void)
-{
- int fd;
- fd = creat(USERFILE, 0600);
- if (fd < 0) {
- perror("Create User File");
- return -1;
- }
- close(fd);
- return 0;
-}
-
-int openuserfile(int flags)
-{
- int x;
- x=open(USERFILE,flags,S_IRUSR|S_IWUSR|S_IRGRP);
- if (x>=0) return x;
-
- if (errno != ENOENT || createuserfile())
- {
- perror("Open User File");
- exit(-1);
- }
-
- x=open(USERFILE,flags,S_IRUSR|S_IWUSR|S_IRGRP);
- if (x>=0) return x;
-
- perror("Open User File After Create");
- exit(-1);
-}
-
-void write_usr(struct person *record, int32_t *userposn)
-{
- int outfile;
-
- if ((outfile=err_open(USERFILE,O_WRONLY|O_APPEND|O_CREAT,0600))<0)
- exit(-1);
- Lock_File(outfile);
- write(outfile,record,sizeof(*record));
- *userposn=(lseek(outfile,0,1)-sizeof(*record));
- Unlock_File(outfile);
- close(outfile);
-}
-
int openfolderfile(int mode)
{
int x;
Modified: trunk/src/files.h
===================================================================
--- trunk/src/files.h 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/files.h 2013-11-01 18:29:19 UTC (rev 1349)
@@ -5,7 +5,6 @@
#include "user.h"
#define FOLDERFILE STATEDIR"/folders.bb"
-#define USERFILE STATEDIR"/users.bb"
void open_incoming_fifo(const char *host);
void close_fifo(void);
@@ -13,8 +12,6 @@
void Unlock_File(int f);
int openfolderfile(int mode);
int nofolders(void);
-int openuserfile(int flags);
-void write_usr(struct person *record, int32_t *userposn);
void create_folder_file(void);
int foldernumber(const char *name);
int get_folder_entry(int file, struct folder *tmp);
Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/ipc.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -167,7 +167,7 @@
who_fd = who_open(O_RDONLY);
if (who_fd < 0) return 0;
- users_fd = openuserfile(O_RDONLY);
+ users_fd = userdb_open(O_RDONLY);
if (users_fd < 0) {
close(who_fd);
return 0;
Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/server/servsock.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -313,7 +313,7 @@
if (msg->head.type == FOURCC("SAYR")) {
/* eventually this should be a server maintained list */
int who_fd = who_open(O_RDONLY);
- int users_fd = openuserfile(O_RDONLY);
+ int users_fd = userdb_open(O_RDONLY);
struct who who;
struct person user;
json_t * j = json_init(msg);
@@ -355,7 +355,7 @@
if (msg->head.type == FOURCC("SAYU")) {
/* eventually this should be a server maintained list */
int who_fd = who_open(O_RDONLY);
- int users_fd = openuserfile(O_RDONLY);
+ int users_fd = userdb_open(O_RDONLY);
struct who who;
struct person user;
json_t * j = json_init(msg);
@@ -391,7 +391,7 @@
if (msg->head.type == FOURCC("WALL")) {
/* eventually this should be a server maintained list */
int who_fd = who_open(O_RDONLY);
- int users_fd = openuserfile(O_RDONLY);
+ int users_fd = userdb_open(O_RDONLY);
struct who who;
struct person user;
struct person from;
Added: trunk/src/user.c
===================================================================
--- trunk/src/user.c (rev 0)
+++ trunk/src/user.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -0,0 +1,30 @@
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "user.h"
+#include "files.h"
+
+int userdb_open(int flags)
+{
+ int ufd = open(USERFILE, flags|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP);
+ if (ufd < 0) {
+ perror(USERFILE);
+ exit(-1);
+ }
+ return ufd;
+}
+
+void userdb_write(struct person *record, int32_t *userposn)
+{
+ int outfile = userdb_open(O_WRONLY|O_APPEND|O_CREAT);
+ if (outfile < 0)
+ exit(-1);
+ Lock_File(outfile);
+ write(outfile,record,sizeof(*record));
+ *userposn = (lseek(outfile,0,SEEK_CUR) - sizeof(*record));
+ Unlock_File(outfile);
+ close(outfile);
+}
Modified: trunk/src/user.h
===================================================================
--- trunk/src/user.h 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/user.h 2013-11-01 18:29:19 UTC (rev 1349)
@@ -3,6 +3,8 @@
#include <stdint.h>
+#define USERFILE STATEDIR"/users.bb"
+
#define NAMESIZE 16 /* username */
#define PASSWDSIZE 20 /* password (after encryption) */
#define REALNAMESIZE 30 /* real name */
@@ -48,4 +50,7 @@
uint32_t chatmode;
};
+extern int userdb_open(int flags);
+extern void userdb_write(struct person *record, int32_t *userposn);
+
#endif
Modified: trunk/src/webclient/comms.c
===================================================================
--- trunk/src/webclient/comms.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/webclient/comms.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -454,7 +454,7 @@
int count=0;
wfile = who_open(O_RDONLY);
- ufile = openuserfile(O_RDONLY);
+ ufile = userdb_open(O_RDONLY);
mws_add(line, "[");
@@ -632,5 +632,5 @@
} else {
mwlog("CREATED Auto web user");
}
- write_usr(me, userposn);
+ userdb_write(me, userposn);
}
Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c 2013-10-31 22:37:07 UTC (rev 1348)
+++ trunk/src/webclient/import.c 2013-11-01 18:29:19 UTC (rev 1349)
@@ -40,7 +40,7 @@
{
int outfile;
- outfile=openuserfile(O_RDWR|O_CREAT);
+ outfile=userdb_open(O_RDWR|O_CREAT);
/*Lock_File(outfile); */
lseek(outfile,userposn,0);
write(outfile,record,sizeof(*record));
@@ -90,7 +90,7 @@
{
int outfile;
- outfile=openuserfile(O_RDWR|O_CREAT);
+ outfile=userdb_open(O_RDWR|O_CREAT);
lseek(outfile,userposn,0);
read(outfile,record,sizeof(*record));
close(outfile);
@@ -174,7 +174,7 @@
int file,found=false;
if (access(USERFILE,00)) return(false);
- file=openuserfile(O_RDONLY);
+ file=userdb_open(O_RDONLY);
while (!found && get_person(file,usr))
if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
found=true;
More information about the mw-devel
mailing list