This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-goldedplus/goldlib/gmb3/gmoxbbs1.cpp

297 lines
7.1 KiB
C++
Raw Normal View History

2000-02-25 10:15:17 +00:00
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
// Copyright (C) 1990-1999 Odinn Sorensen
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// AdeptXBBS messagebase engine.
// ------------------------------------------------------------------
#include <gdbgerr.h>
#include <gmemdbg.h>
#include <gdbgtrk.h>
#include <gmoxbbs.h>
// ------------------------------------------------------------------
XbbsWide* xbbswide = NULL;
XbbsData* xbbsdata = NULL;
int xbbsdatano = 0;
// ------------------------------------------------------------------
void XbbsArea::data_open() {
wide = xbbswide;
data = xbbsdata + (xbbsdatano++);
}
// ------------------------------------------------------------------
void XbbsArea::data_close() {
xbbsdatano--;
}
// ------------------------------------------------------------------
void XbbsArea::raw_close() {
GFTRK("XbbsRawClose");
if(data->fhdata != -1) ::close(data->fhdata); data->fhdata = -1;
if(data->fhindex != -1) ::close(data->fhindex); data->fhindex = -1;
if(data->fhtext != -1) ::close(data->fhtext); data->fhtext = -1;
2006-05-13 16:15:35 +00:00
if (wide->isopen)
{
if (wide->isopen == 1)
{
if (wide->user->gufh != -1)
{
::close(wide->user->gufh);
wide->user->gufh = -1;
2000-02-25 10:15:17 +00:00
}
}
wide->isopen--;
}
GFTRK(NULL);
}
// ------------------------------------------------------------------
int XbbsArea::test_open(const char* __file, int sharemode) {
GFTRK("XbbsTestOpen");
int _fh;
long _tries = 0;
if(sharemode == -1)
sharemode = WideSharemode;
do {
_fh = ::sopen(__file, O_RDWR|O_BINARY|O_CREAT, sharemode, S_STDRW);
if(_fh == -1) {
// Tell the world
2002-10-26 16:28:01 +00:00
if((errno != EACCES) or (PopupLocked(++_tries, false, __file) == false)) {
2000-02-25 10:15:17 +00:00
// User requested to exit
WideLog->ErrOpen();
raw_close();
WideLog->printf("! An AdeptXBBS msgbase file could not be opened.");
WideLog->printf(": %s.", __file);
WideLog->ErrOSInfo();
OpenErrorExit();
}
}
} while(_fh == -1);
// Remove the popup window
if(_tries)
PopupLocked(0, 0, NULL);
GFTRK(NULL);
return _fh;
}
// ------------------------------------------------------------------
void XbbsArea::raw_open() {
GFTRK("XbbsRawOpen");
2002-05-12 13:07:37 +00:00
data->fhdata = test_open(AddPath(real_path(), ".Data"));
data->fhindex = test_open(AddPath(real_path(), ".Index"));
data->fhtext = test_open(AddPath(real_path(), ".Text"));
2000-02-25 10:15:17 +00:00
wide->isopen++;
2006-05-13 16:15:35 +00:00
if (wide->isopen == 1)
wide->user->gufh = ::sopen(AddPath(wide->path, "Users"), O_RDONLY|O_BINARY, WideSharemode, S_STDRW);
2000-02-25 10:15:17 +00:00
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsExit() {
if(xbbswide)
delete xbbswide->user;
throw_release(xbbswide);
throw_release(xbbsdata);
}
// ------------------------------------------------------------------
void XbbsInit(const char* path, int userno) {
xbbsdata = (XbbsData*)throw_calloc(3, sizeof(XbbsData));
2000-02-25 10:15:17 +00:00
xbbswide = (XbbsWide*)throw_calloc(1, sizeof(XbbsWide));
xbbswide->path = path;
xbbswide->userno = userno;
xbbswide->user = new XbbsUser;
throw_new(xbbswide->user);
2006-05-13 16:15:35 +00:00
xbbswide->user->gufh = -1;
2000-02-25 10:15:17 +00:00
xbbswide->fhpmi = -1;
xbbswide->pmi = NULL;
xbbswide->isopen = 0;
const char* _username = WideUsername[0];
2006-05-13 16:15:35 +00:00
if (xbbswide->userno == -1)
{
xbbswide->user->gufh = ::sopen(AddPath(xbbswide->path, "Users"), O_RDONLY|O_BINARY, WideSharemode, S_STDRD);
if (xbbswide->user->gufh != -1)
{
2000-02-25 10:15:17 +00:00
xbbswide->user->find(_username);
2001-04-15 19:24:44 +00:00
if(not xbbswide->user->found) {
2000-02-25 10:15:17 +00:00
xbbswide->userno = 0;
//WideLog->printf("* User \"%s\" not found in %sUsers.", _username, xbbswide->path);
//xbbswide->user->add(_username);
//WideLog->printf("* Now added with user number %u.", xbbswide->user->index);
}
2006-05-13 16:15:35 +00:00
close(xbbswide->user->gufh);
2000-02-25 10:15:17 +00:00
}
xbbswide->userno = xbbswide->user->index;
}
}
// ------------------------------------------------------------------
void XbbsArea::open() {
GFTRK("XbbsOpen");
isopen++;
if(isopen > 2) {
WideLog->ErrTest();
WideLog->printf("! Trying to open an AdeptXBBS msgbase more than twice.");
WideLog->printf(": %s, %s.", echoid(), path());
WideLog->printf("+ Info: This indicates a serious bug.");
WideLog->printf("+ Advice: Report to the Author immediately.");
TestErrorExit();
}
if(isopen == 1) {
2001-12-17 15:44:55 +00:00
if(ispacked()) {
isopen--;
const char* newpath = Unpack(path());
2001-12-26 13:00:18 +00:00
if(newpath == NULL)
packed(false);
2001-12-17 15:44:55 +00:00
set_real_path(newpath ? newpath : path());
isopen++;
}
2000-02-25 10:15:17 +00:00
data_open();
raw_open();
refresh();
scan();
}
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::save_lastread() {
GFTRK("XbbsSaveLastread");
2002-05-12 13:07:37 +00:00
int _fh = ::sopen(AddPath(real_path(), ".lmr"), O_RDWR|O_CREAT|O_BINARY, WideSharemode, S_STDRW);
2000-02-25 10:15:17 +00:00
if(_fh != -1) {
2005-10-07 12:41:11 +00:00
uint32_t _lastread = Msgn->CvtReln(lastread);
lseekset(_fh, wide->userno+1, sizeof(uint32_t));
write(_fh, &_lastread, sizeof(uint32_t));
2000-02-25 10:15:17 +00:00
::close(_fh);
}
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::close() {
GFTRK("XbbsClose");
if(isopen) {
if(isopen == 1) {
save_lastread();
raw_close();
Msgn->Reset();
throw_release(data->idx);
data_close();
2001-12-17 15:44:55 +00:00
if(ispacked()) {
CleanUnpacked(real_path());
}
2000-02-25 10:15:17 +00:00
}
isopen--;
}
else {
WideLog->ErrTest();
WideLog->printf("! Trying to close an already closed AdeptXBBS msgbase.");
WideLog->printf(": %s, %s.", echoid(), path());
WideLog->printf("+ Info: This indicates a potentially serious bug.");
WideLog->printf("+ Advice: Report to the Author immediately.");
TestErrorExit();
}
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::suspend() {
GFTRK("XbbsSuspend");
save_lastread();
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::resume() {
GFTRK("XbbsResume");
GFTRK(NULL);
}
// ------------------------------------------------------------------