[Turqstat-commits] [SCM] Turquoise SuperStat - http://www.softwolves.pp.se/sw/software/turquoise branch, synchronet, updated. release-2_2_4-12-g84d1e08

Peter Karlsson peter at softwolves.pp.se
Thu Mar 13 08:00:23 UTC 2008


The following commit has been merged in the synchronet branch:
commit b32ea0f5326f02ad36d7f151e76e6a27f4f70c3f
Author: Stephen Hurd <shurd at sasktel.net>
Date:   Thu Mar 13 08:57:02 2008 +0100

    Added remaining changes for Synchronet BBS support.
    
    From: Stephen Hurd <shurd at sasktel.net>
    To: Peter Karlsson <peter at softwolves.pp.se>
    Date: Mon, 10 Mar 2008 23:30:43 -0700
    Subject: Re: Synchronet support in Turquoise SuperStat

diff --git a/Makefile.in b/Makefile.in
index b321cb2..4c75c63 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -104,6 +104,9 @@ jamread.o: jamread.cpp jamread.h datatypes.h statengine.h arearead.h config.h ou
 smbread.o: smbread.cpp smbread.h datatypes.h statengine.h arearead.h config.h output.h convert.h utility.h
 	@CXX@ $(CXXFLAGS) -c $(srcdir)/smbread.cpp
 
+smbread.o: smbread.cpp smbread.h datatypes.h statengine.h arearead.h config.h output.h convert.h utility.h
+	@CXX@ $(CXXFLAGS) -c $(srcdir)/smbread.cpp
+
 mypointread.o: mypointread.cpp mypointread.h datatypes.h statengine.h arearead.h config.h output.h convert.h utility.h
 	@CXX@ $(CXXFLAGS) -c $(srcdir)/mypointread.cpp
 
diff --git a/qtgui.cpp b/qtgui.cpp
index 82ade26..c2b6dce 100644
--- a/qtgui.cpp
+++ b/qtgui.cpp
@@ -397,6 +397,10 @@ void InfoWindow::open()
             area = new SMBRead(path);
             break;
 
+        case SMB:
+            area = new SMBRead(path);
+            break;
+
         case MYPOINT:
             area = new MyPointRead(path, areanum);
             break;
diff --git a/smbread.cpp b/smbread.cpp
new file mode 100644
index 0000000..1cdcf05
--- /dev/null
+++ b/smbread.cpp
@@ -0,0 +1,244 @@
+// Copyright (c) 2007-2008 Stephen Hurd
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+#include <config.h>
+#include <string>
+#ifdef HAVE_IOSTREAM
+# include <iostream>
+#else
+# include <iostream.h>
+#endif
+#include <time.h>
+#include <stdio.h>
+#include <smblib.h>
+
+#include "smbread.h"
+#include "utility.h"
+#include "statengine.h"
+#include "output.h"
+
+SMBRead::SMBRead(const char *path)
+{
+    areapath = strdup(path);
+}
+
+SMBRead::~SMBRead()
+{
+    if (areapath) free(areapath);
+}
+
+bool SMBRead::Transfer(time_t starttime, time_t endtime,
+                       StatEngine &destination)
+{
+    // Get the output object
+    TDisplay *display = TDisplay::GetOutputObject();
+
+    // Check that we got the path correctly in initialization
+    if (!areapath)
+    {
+        display->InternalErrorQuit(TDisplay::area_not_allocated, 1);
+    }
+
+	// Initialize the smb object
+	memset(&smb,0,sizeof(smb));
+
+    // Open the message area files
+    // <name>.jdx - contains one record per message
+	sprintf(smb.file,"%.*s",sizeof(smb.file)-1,areapath);
+	char *lastdot=strrchr(smb.file, '.');
+	if(lastdot && (!stricmp(lastdot,".shd")))
+		*lastdot=0;
+
+    if (smb_open(&smb))
+    {
+        display->ErrorMessage(TDisplay::cannot_open, areapath);
+        return false;
+    }
+
+    // Read messages one by one
+    unsigned active = 0, total = smb.status.total_msgs;
+	ulong		msgnum,l;
+	smbmsg_t	msg;
+
+    string ctrlinfo, sender, recipient, subject;
+    char *buf;
+
+    display->SetMessagesTotal(total);
+
+#if 0
+	destination.NewsArea();
+#endif
+
+    for(msgnum=0; msgnum < smb.status.total_msgs; msgnum++)
+    {
+		/* Read the index */
+		msg.hdr.number=0;
+		msg.offset=msgnum;
+		if(smb_getmsgidx(&smb, &msg))
+        {
+            // Could not read message index, quit
+            display->ErrorMessage(TDisplay::cannot_read_header,
+                                  msgnum);
+            continue;
+        }
+
+        if  (!(msg.idx.attr & MSG_DELETE))
+        {
+            // This is message is active
+            active ++;
+            display->UpdateProgress(active);
+
+            // Check if message is outside time range
+            if (time_t(msg.idx.time) < starttime
+	                || time_t(msg.idx.time) > endtime)
+                continue;
+
+			// Read message header
+			if (smb_getmsghdr(&smb, &msg)) {
+        		// Could not read message, quit
+        		display->ErrorMessage(TDisplay::cannot_read_header,
+                                	  msgnum);
+        		continue;
+			}
+
+            // Retrieve message body
+            buf = smb_getmsgtxt(&smb, &msg, GETMSGTXT_BODY_ONLY);
+
+            if (!buf)
+            {
+                display->WarningMessage(TDisplay::cannot_allocate_body,
+                                        msgnum);
+				smb_freemsgmem(&msg);
+                continue;
+            }
+
+            // Locate sender, recipient, subject and PID and MSGID kludges
+            // from subfields.
+            sender = (const char *)msg.from;
+            recipient = (const char *)msg.to;
+            subject = (const char *)msg.subj;
+            ctrlinfo = "";
+#if 0
+			if(msg.ftn_msgid) {
+				ctrlinfo += "\1MSGID: ";
+				ctrlinfo += (const char *)msg.ftn_msgid;
+			}
+			else {
+				/*
+				 * MSGID is hacked up for network addres...
+				 * hack harder.
+				 */
+				if(msg.from_net.type != NET_NONE && msg.from_net.addr && strlen((const char *)msg.from_net.addr)) {
+					ctrlinfo += "\1MSGID: ";
+					ctrlinfo += (const char *)msg.from_net.addr;
+					ctrlinfo += " hackmebaby";
+				}
+			}
+#else
+			/*
+			 * MSGID is hacked up for network addres...
+			 * hack harder.
+			 */
+			if(msg.from_net.type != NET_NONE) {
+				ctrlinfo += "\1MSGID: ";
+				ctrlinfo += (const char *)smb_netaddr(&(msg.from_net));
+				ctrlinfo += " hackmebaby hack hack";
+			}
+#endif
+			ctrlinfo += "\1From: ";
+			ctrlinfo += (const char *)msg.from;
+			ctrlinfo += "@";
+			if(msg.from_net.type != NET_NONE)
+				ctrlinfo += (const char *)smb_netaddr(&(msg.from_net));
+			ctrlinfo += "\1To: ";
+			ctrlinfo += (const char *)msg.to;
+			if(msg.ftn_reply) {
+				ctrlinfo += "\1REPLY: ";
+				ctrlinfo += (const char *)msg.ftn_reply;
+			}
+			if(msg.ftn_area) {
+				ctrlinfo += "\1AREA: ";
+				ctrlinfo += (const char *)msg.ftn_area;
+			}
+			if(msg.ftn_flags) {
+				ctrlinfo += "\1FLAGS: ";
+				ctrlinfo += (const char *)msg.ftn_flags;
+			}
+			if(msg.ftn_pid) {
+				ctrlinfo += "\1PID: ";
+				ctrlinfo += (const char *)msg.ftn_pid;
+			}
+			if(msg.ftn_tid) {
+				ctrlinfo += "\1TID: ";
+				ctrlinfo += (const char *)msg.ftn_tid;
+			}
+
+			// Add text headers
+		    /* variable fields */
+            for(l=0;l<msg.total_hfields;l++) {
+				switch(msg.hfield[l].type) {
+					case RFC822HEADER:
+						ctrlinfo += "\1";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case RFC822MSGID:
+						ctrlinfo += "\1";
+						ctrlinfo += "Message-Id: ";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case RFC822REPLYID:
+						ctrlinfo += "\1";
+						ctrlinfo += "Reply-Id: ";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case RFC822TO:
+						ctrlinfo += "\1";
+						ctrlinfo += "To: ";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case RFC822FROM:
+						ctrlinfo += "\1";
+						ctrlinfo += "From: ";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case RFC822REPLYTO:
+						ctrlinfo += "\1";
+						ctrlinfo += "In-Reply-To: ";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					/* Don't know how to do this yet...
+					case USENETPATH:
+						ctrlinfo += "\1";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break;
+					case USENETNEWSGROUPS:
+						ctrlinfo += "\1";
+						ctrlinfo += (const char *)msg.hfield_dat[l];
+						break; */
+				}
+			}
+
+            destination.AddData(sender, recipient, subject,
+                                ctrlinfo, string(buf),
+                                msg.hdr.when_written.time,
+								msg.idx.time);
+
+            smb_freemsgtxt(buf);
+			smb_freemsgmem(&msg);
+        }
+    }
+
+    return true;
+}
diff --git a/newsspoolread.h b/smbread.h
similarity index 67%
copy from newsspoolread.h
copy to smbread.h
index 39158de..7d2f501 100644
--- a/newsspoolread.h
+++ b/smbread.h
@@ -1,6 +1,5 @@
-// Copyright (c) 2000-2001 Peter Karlsson
-//
-// $Id$
+// Copyright (c) 1999-2001 Peter Karlsson
+// Copyright (c) 2007-2008 Stephen Hurd
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -15,28 +14,36 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-#ifndef __NEWSSPOOLREAD_H
-#define __NEWSSPOOLREAD_H
+#ifndef __SMBREAD_H
+#define __SMBREAD_H
+
+#include <config.h>
 
+#include <smblib.h>
+
+#include "datatypes.h"
 #include "arearead.h"
 
+#if defined(__GNUC__) || defined(__EMX__)
+# pragma pack(1)
+#endif
+
 class StatEngine;
 
 /**
- * Class that reads Usenet news spools.
- * This class reads message bases stored in the standard text-based Usenet
- * news spool format.
+ * Class that reads SMB message bases.
+ * This class reads message bases stored in the SMB format.
  */
-class NewsSpoolRead : public AreaRead
+class SMBRead : public AreaRead
 {
 public:
     /** Standard constructor.
-     * Creates the Usenet spool reader object.
-     * @param path Directory for the news spool.
+     * Creates the SMB message base reader object.
+     * @param path Directory and base name for message base.
      */
-    NewsSpoolRead(const char *path);
+    SMBRead(const char *path);
     /** Standard destructor. */
-    virtual ~NewsSpoolRead();
+    virtual ~SMBRead();
 
     /**
      * Transfer function. 
@@ -53,8 +60,14 @@ public:
                           StatEngine &destination);
 
 protected:
-    /** Path to spool directory. */
-    char    *areapath;
+    /** Path to message base. */
+    char        *areapath;
+
+	smb_t		smb;
 };
 
+#if defined(__GNUC__) || defined(__EMX__)
+# pragma pack()
+#endif
+
 #endif
diff --git a/turqstat.cpp b/turqstat.cpp
index e241aec..8d5bb1b 100644
--- a/turqstat.cpp
+++ b/turqstat.cpp
@@ -314,6 +314,10 @@ StatRetr::StatRetr(StatEngine &engine, StatView &view,
                 area = new SMBRead(areapath[counter]);
                 break;
 
+            case smb:
+                area = new SMBRead(areapath[counter]);
+                break;
+
             case mypoint:
                 areanum = strtoul(areapath[counter], NULL, 10);
                 area = new MyPointRead(basepath, areanum);

-- 
Turquoise SuperStat - http://www.softwolves.pp.se/sw/software/turquoise



More information about the Turqstat-commits mailing list