|
|
1.1 ! root 1: /* putnode.cpp */ ! 2: ! 3: /* Synchronet node information writing routines */ ! 4: ! 5: /* $Id: putnode.cpp,v 1.17 2005/09/25 22:56:57 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: ! 40: /****************************************************************************/ ! 41: /* Write the data from the structure 'node' into node.dab */ ! 42: /* getnodedat(num,&node,1); must have been called before calling this func */ ! 43: /* NOTE: ------^ the indicates the node record has been locked */ ! 44: /****************************************************************************/ ! 45: int sbbs_t::putnodedat(uint number, node_t* node) ! 46: { ! 47: char str[256],firston[25]; ! 48: char path[MAX_PATH+1]; ! 49: int wr=0; ! 50: int wrerr=0; ! 51: int attempts; ! 52: ! 53: if(!number) ! 54: return(-1); ! 55: ! 56: if(number>cfg.sys_nodes) { ! 57: errormsg(WHERE,ERR_CHK,"node number",number); ! 58: return(-1); ! 59: } ! 60: if(number==cfg.node_num) { ! 61: if((node->status==NODE_INUSE || node->status==NODE_QUIET) ! 62: && node->action<NODE_LAST_ACTION ! 63: && text[NodeActionMain+node->action][0]) { ! 64: node->misc|=NODE_EXT; ! 65: memset(str,0,128); ! 66: sprintf(str,text[NodeActionMain+node->action] ! 67: ,useron.alias ! 68: ,useron.level ! 69: ,getage(&cfg,useron.birth) ! 70: ,useron.sex ! 71: ,useron.comp ! 72: ,useron.note ! 73: ,unixtodstr(&cfg,useron.firston,firston) ! 74: ,node->aux&0xff ! 75: ,node->connection ! 76: ); ! 77: putnodeext(number,str); ! 78: } ! 79: else ! 80: node->misc&=~NODE_EXT; ! 81: } ! 82: ! 83: sprintf(path,"%snode.dab",cfg.ctrl_dir); ! 84: if(nodefile==-1) { ! 85: if((nodefile=nopen(path,O_CREAT|O_RDWR|O_DENYNONE))==-1) { ! 86: errormsg(WHERE,ERR_OPEN,path,O_CREAT|O_RDWR|O_DENYNONE); ! 87: return(errno); ! 88: } ! 89: } ! 90: ! 91: number--; /* make zero based */ ! 92: lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t)); ! 93: for(attempts=0;attempts<10;attempts++) { ! 94: lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET); ! 95: wr=write(nodefile,node,sizeof(node_t)); ! 96: if(wr==sizeof(node_t)) ! 97: break; ! 98: wrerr=errno; /* save write error */ ! 99: mswait(100); ! 100: } ! 101: unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t)); ! 102: if(cfg.node_misc&NM_CLOSENODEDAB) { ! 103: close(nodefile); ! 104: nodefile=-1; ! 105: } ! 106: ! 107: if(wr!=sizeof(node_t)) { ! 108: errno=wrerr; ! 109: errormsg(WHERE,ERR_WRITE,"nodefile",number+1); ! 110: return(errno); ! 111: } ! 112: ! 113: utime(path,NULL); /* Update mod time for NFS/smbfs compatibility */ ! 114: ! 115: return(0); ! 116: } ! 117: ! 118: int sbbs_t::putnodeext(uint number, char *ext) ! 119: { ! 120: char str[MAX_PATH+1]; ! 121: int count; ! 122: int wr; ! 123: ! 124: if(!number || number>cfg.sys_nodes) { ! 125: errormsg(WHERE,ERR_CHK,"node number",number); ! 126: return(-1); ! 127: } ! 128: number--; /* make zero based */ ! 129: ! 130: sprintf(str,"%snode.exb",cfg.ctrl_dir); ! 131: if((node_ext=nopen(str,O_CREAT|O_RDWR|O_DENYNONE))==-1) { ! 132: errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_RDWR|O_DENYNONE); ! 133: return(errno); ! 134: } ! 135: for(count=0;count<LOOP_NODEDAB;count++) { ! 136: if(count) ! 137: mswait(100); ! 138: lseek(node_ext,(long)number*128L,SEEK_SET); ! 139: if(lock(node_ext,(long)number*128L,128)==-1) ! 140: continue; ! 141: wr=write(node_ext,ext,128); ! 142: unlock(node_ext,(long)number*128L,128); ! 143: if(wr==128) ! 144: break; ! 145: } ! 146: close(node_ext); ! 147: node_ext=-1; ! 148: ! 149: if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) { ! 150: sprintf(str,"NODE.EXB (node %d) COLLISION - Count: %d" ! 151: ,number+1, count); ! 152: logline("!!",str); ! 153: } ! 154: if(count==LOOP_NODEDAB) { ! 155: errormsg(WHERE,ERR_WRITE,"NODE.EXB",number+1); ! 156: return(-2); ! 157: } ! 158: ! 159: return(0); ! 160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.