1 // This may look like C code, but it is really -*- C++ -*-
2
3 // ------------------------------------------------------------------
4 // The Goldware Library
5 // Copyright (C) 2000 Alexander S. Aganichev
6 // ------------------------------------------------------------------
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 // ------------------------------------------------------------------
21 // $Id: gmosmb2.cpp,v 1.5 2006/05/14 11:45:05 ssianky Exp $
22 // ------------------------------------------------------------------
23 // Synchronet message base
24 // ------------------------------------------------------------------
25
26 #include <gdbgtrk.h>
27 #include <gmemdbg.h>
28 #include <gstrall.h>
29 #include <gmosmb.h>
30
31
32 // ------------------------------------------------------------------
33
raw_scan(bool keep_index,bool scanpm)34 void SMBArea::raw_scan(bool keep_index, bool scanpm)
35 {
36 GFTRK("SMBArea::raw_scan");
37
38 smb_t *_was_data = data;
39 if(_was_data == NULL) {
40 if(ispacked()) {
41 const char* newpath = Unpack(path());
42 if(newpath == NULL)
43 packed(false);
44 set_real_path(newpath ? newpath : path());
45 }
46 data_open();
47 }
48 uint32_t firstmsgno = 0;
49 uint32_t lastmsgno = 0;
50 Msgn->Reset();
51 PMrk->Reset();
52 if(isopen or smb_open(data) == 0) {
53 if(smb_locksmbhdr(data) == 0) {
54 int res = smb_getstatus(data);
55 smb_unlocksmbhdr(data);
56 uint32_t total_msgs = 0;
57 if(res == 0) {
58 total_msgs = data->status.total_msgs;
59 lastmsgno = data->status.last_msg;
60 if(keep_index or scanpm) {
61 smbmsg_t msg;
62 int umax = (WidePersonalmail & PM_ALLNAMES) ? WideUsernames : 1;
63 uint32_t l = 1;
64 rewind(data->sid_fp);
65 while(l <= total_msgs) {
66 if(not fread(&msg.idx, 1, sizeof(idxrec_t), data->sid_fp))
67 break;
68 if(smb_lockmsghdr(data, &msg) == 0) {
69 int rc = smb_getmsghdr(data, &msg);
70 smb_unlockmsghdr(data, &msg);
71 if(rc == 0) {
72 if(firstmsgno == 0)
73 firstmsgno = msg.hdr.number;
74 if(keep_index)
75 Msgn->Append(msg.hdr.number);
76 if(scanpm) {
77 bool gotpm = false;
78 for(int u=0; u<umax; u++) {
79 if(strieql(WideUsername[u], (char *)msg.to)) {
80 gotpm = true;
81 break;
82 }
83 }
84 if(gotpm) {
85 if(not (msg.idx.attr & MSG_READ))
86 PMrk->Append(msg.hdr.number);
87 gotpm = false;
88 }
89 }
90 smb_freemsgmem(&msg);
91 }
92 }
93 l++;
94 }
95 total_msgs = l-1;
96 }
97 }
98 if(not isopen)
99 smb_close(data);
100 Msgn->SetCount(total_msgs);
101 }
102 }
103 if(WideDebug) {
104 WideLog->printf("- %s: t:%u, l:%u, fm:%u, hm:%u, lr:%u, u:%u, pm: %i",
105 echoid(),
106 Msgn->Count(),
107 0,
108 firstmsgno,
109 lastmsgno,
110 0,
111 0,
112 scanpm ? (int)PMrk->Count() : -1
113 );
114 }
115 if(_was_data == NULL) {
116 data_close();
117 if(ispacked()) {
118 CleanUnpacked(real_path());
119 }
120 }
121
122 GFTRK(0);
123 }
124
125
126 // ------------------------------------------------------------------
127
scan()128 void SMBArea::scan()
129 {
130 raw_scan(true);
131 }
132
133
134 // ------------------------------------------------------------------
135
scan_area()136 void SMBArea::scan_area()
137 {
138 raw_scan();
139 }
140
141
142 // ------------------------------------------------------------------
143
scan_area_pm()144 void SMBArea::scan_area_pm()
145 {
146 raw_scan(true, true);
147 }
148
149
150 // ------------------------------------------------------------------
151