Annotation of sbbs/sbbs3/putnode.cpp, revision 1.1.1.2

1.1       root        1: /* putnode.cpp */
                      2: 
                      3: /* Synchronet node information writing routines */
                      4: 
1.1.1.2 ! root        5: /* $Id: putnode.cpp,v 1.16 2003/05/16 07:46:06 rswindell Exp $ */
1.1       root        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 2000 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: /****************************************************************************/
1.1.1.2 ! root       45: int sbbs_t::putnodedat(uint number, node_t* node)
1.1       root       46: {
1.1.1.2 ! root       47:        char    str[256],firston[25];
        !            48:        char    path[MAX_PATH+1];
        !            49:        int             wr=0;
        !            50:        int             wrerr=0;
        !            51:        int             attempts;
1.1       root       52: 
1.1.1.2 ! root       53:        if(!number)
        !            54:                return(-1);
        !            55: 
        !            56:        if(number>cfg.sys_nodes) {
1.1       root       57:                errormsg(WHERE,ERR_CHK,"node number",number);
1.1.1.2 ! root       58:                return(-1); 
        !            59:        }
1.1       root       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:                                );
1.1.1.2 ! root       77:                        putnodeext(number,str); 
        !            78:                }
1.1       root       79:                else
1.1.1.2 ! root       80:                        node->misc&=~NODE_EXT; 
        !            81:        }
1.1       root       82: 
1.1.1.2 ! root       83:        sprintf(path,"%snode.dab",cfg.ctrl_dir);
1.1       root       84:        if(nodefile==-1) {
1.1.1.2 ! root       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); 
1.1       root       88:                }
                     89:        }
                     90: 
                     91:        number--;       /* make zero based */
1.1.1.2 ! root       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);
1.1       root      100:        }
                    101:        unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t));
1.1.1.2 ! root      102:        if(cfg.node_misc&NM_CLOSENODEDAB) {
        !           103:                close(nodefile);
        !           104:                nodefile=-1;
        !           105:        }
1.1       root      106: 
1.1.1.2 ! root      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);
1.1       root      116: }
                    117: 
1.1.1.2 ! root      118: int sbbs_t::putnodeext(uint number, char *ext)
1.1       root      119: {
1.1.1.2 ! root      120:     char       str[MAX_PATH+1];
        !           121:     int                count;
        !           122:        int             wr;
1.1       root      123: 
                    124:        if(!number || number>cfg.sys_nodes) {
                    125:                errormsg(WHERE,ERR_CHK,"node number",number);
1.1.1.2 ! root      126:                return(-1); 
        !           127:        }
1.1       root      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);
1.1.1.2 ! root      133:                return(errno); 
1.1       root      134:        }
1.1.1.2 ! root      135:        for(count=0;count<LOOP_NODEDAB;count++) {
        !           136:                if(count)
        !           137:                        mswait(100);
1.1       root      138:                lseek(node_ext,(long)number*128L,SEEK_SET);
1.1.1.2 ! root      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)
1.1       root      144:                        break;
1.1.1.2 ! root      145:        }
1.1       root      146:        close(node_ext);
                    147:        node_ext=-1;
                    148: 
                    149:        if(count>(LOOP_NODEDAB/2) && count!=LOOP_NODEDAB) {
1.1.1.2 ! root      150:                sprintf(str,"NODE.EXB (node %d) COLLISION - Count: %d"
        !           151:                        ,number+1, count);
1.1       root      152:                logline("!!",str); 
                    153:        }
                    154:        if(count==LOOP_NODEDAB) {
                    155:                errormsg(WHERE,ERR_WRITE,"NODE.EXB",number+1);
1.1.1.2 ! root      156:                return(-2); 
1.1       root      157:        }
                    158: 
1.1.1.2 ! root      159:        return(0);
        !           160: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.