|
|
1.1 root 1: /* data_ovl.cpp */
2:
3: /* Synchronet hi-level data access routines */
4:
1.1.1.2 ! root 5: /* $Id: data_ovl.cpp,v 1.16 2011/03/01 22:27:02 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: * *
1.1.1.2 ! root 11: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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: /* Fills the 'ptr' element of the each element of the cfg.sub[] array of sub_t */
42: /* and the sub_cfg and sub_ptr global variables */
43: /* Called from function main */
44: /****************************************************************************/
45: void sbbs_t::getmsgptrs()
46: {
47: if(!useron.number)
48: return;
49: bputs(text[LoadingMsgPtrs]);
50: ::getmsgptrs(&cfg,useron.number,subscan);
51: bputs(text[LoadedMsgPtrs]);
52: }
53:
54: extern "C" BOOL DLLCALL getmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan)
55: {
1.1.1.2 ! root 56: char str[256];
! 57: uint i;
! 58: int file;
! 59: long length;
! 60: FILE* stream;
1.1 root 61:
62: /* Initialize to configured defaults */
63: for(i=0;i<cfg->total_subs;i++) {
64: subscan[i].ptr=subscan[i].sav_ptr=0;
65: subscan[i].last=subscan[i].sav_last=0;
66: subscan[i].cfg=0xff;
67: if(!(cfg->sub[i]->misc&SUB_NSDEF))
68: subscan[i].cfg&=~SUB_CFG_NSCAN;
69: if(!(cfg->sub[i]->misc&SUB_SSDEF))
70: subscan[i].cfg&=~SUB_CFG_SSCAN;
71: subscan[i].sav_cfg=subscan[i].cfg;
72: }
73:
74: if(!usernumber)
75: return(FALSE);
76:
77: sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg->data_dir,usernumber);
78: if((stream=fnopen(&file,str,O_RDONLY))==NULL)
79: return(TRUE);
80:
1.1.1.2 ! root 81: length=(long)filelength(file);
1.1 root 82: for(i=0;i<cfg->total_subs;i++) {
83: if(length>=(cfg->sub[i]->ptridx+1)*10L) {
84: fseek(stream,(long)cfg->sub[i]->ptridx*10L,SEEK_SET);
85: fread(&subscan[i].ptr,sizeof(subscan[i].ptr),1,stream);
86: fread(&subscan[i].last,sizeof(subscan[i].last),1,stream);
87: fread(&subscan[i].cfg,sizeof(subscan[i].cfg),1,stream);
88: }
89: subscan[i].sav_ptr=subscan[i].ptr;
90: subscan[i].sav_last=subscan[i].last;
91: subscan[i].sav_cfg=subscan[i].cfg;
92: }
93: fclose(stream);
94: return(TRUE);
95: }
96:
97: void sbbs_t::putmsgptrs()
98: {
99: ::putmsgptrs(&cfg,useron.number,subscan);
100: }
101:
102: /****************************************************************************/
103: /* Writes to DATA\USER\PTRS\xxxx.DAB the msgptr array for the current user */
104: /* Called from functions main and newuser */
105: /****************************************************************************/
106: extern "C" BOOL DLLCALL putmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan)
107: {
1.1.1.2 ! root 108: char str[256];
! 109: ushort idx;
! 110: uint16_t scancfg;
! 111: uint i,j;
! 112: int file;
! 113: ulong length;
! 114: uint32_t l=0L;
1.1 root 115:
116: if(!usernumber)
117: return(FALSE);
118: sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg->data_dir,usernumber);
119: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) {
120: return(FALSE);
121: }
1.1.1.2 ! root 122: length=(ulong)filelength(file);
1.1 root 123: for(i=0;i<cfg->total_subs;i++) {
124: if(subscan[i].sav_ptr==subscan[i].ptr
125: && subscan[i].sav_last==subscan[i].last
126: && length>=((cfg->sub[i]->ptridx+1)*10UL)
127: && subscan[i].sav_cfg==subscan[i].cfg)
128: continue;
129: while(filelength(file)<(long)(cfg->sub[i]->ptridx)*10) {
130: lseek(file,0L,SEEK_END);
131: idx=(ushort)(tell(file)/10);
132: for(j=0;j<cfg->total_subs;j++)
133: if(cfg->sub[j]->ptridx==idx)
134: break;
135: write(file,&l,sizeof(l));
136: write(file,&l,sizeof(l));
137: scancfg=0xff;
138: if(j<cfg->total_subs) {
139: if(!(cfg->sub[j]->misc&SUB_NSDEF))
140: scancfg&=~SUB_CFG_NSCAN;
141: if(!(cfg->sub[j]->misc&SUB_SSDEF))
142: scancfg&=~SUB_CFG_SSCAN;
143: } else /* default to scan OFF for unknown sub */
144: scancfg&=~(SUB_CFG_NSCAN|SUB_CFG_SSCAN);
145: write(file,&scancfg,sizeof(scancfg));
146: }
147: lseek(file,(long)((long)(cfg->sub[i]->ptridx)*10),SEEK_SET);
148: write(file,&(subscan[i].ptr),sizeof(subscan[i].ptr));
149: write(file,&(subscan[i].last),sizeof(subscan[i].last));
150: write(file,&(subscan[i].cfg),sizeof(subscan[i].cfg));
151: }
152: close(file);
153: if(!flength(str)) /* Don't leave 0 byte files */
154: remove(str);
155:
156: return(TRUE);
157: }
158:
159: /****************************************************************************/
160: /* Checks for a duplicate user field starting at user record offset */
161: /* 'offset', reading in 'datlen' chars, comparing to 'str' for each user */
1.1.1.2 ! root 162: /* except 'usernumber' if it is non-zero, or starting at 'usernumber' if */
! 163: /* 'next' is true. Comparison is NOT case sensitive. */
1.1 root 164: /* 'del' is true if the search is to include deleted/inactive users */
165: /* Returns the usernumber of the dupe if found, 0 if not */
166: /****************************************************************************/
167: uint sbbs_t::userdatdupe(uint usernumber, uint offset, uint datlen, char *dat
1.1.1.2 ! root 168: ,bool del, bool next)
1.1 root 169: {
170: bputs(text[SearchingForDupes]);
1.1.1.2 ! root 171: uint i=::userdatdupe(&cfg, usernumber, offset, datlen, dat, del, next);
1.1 root 172: bputs(text[SearchedForDupes]);
173: return(i);
174: }
175:
176:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.