home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /*** ***/
- /*** oMMM - The Outbound Matrix Message Masher ***/
- /*** Copyright 1989 BS Software ***/
- /*** ***/
- /*** FILENAME: OMMMSCAN.C ***/
- /*** ***/
- /*** Mail area scanner ***/
- /*** ***/
- /*** Based on the original oMMM, a portion of ***/
- /*** the Opus Computer-Based Conversation System ***/
- /*** Copyright 1986, Wynn Wagner III ***/
- /*** ***/
- /***************************************************************************/
- /*** ***/
- /*** Tabs set at every 4th column ***/
- /*** ***/
- /***************************************************************************/
-
- /*
- Polytron Version Control System Comments:
-
- The revision of this file is *** $Revision: 1.40 $ ***
-
- History of changes from 1.30 release version
-
- $Log: C:/OMMM/PROJFILE/OMMMSCAN.C_V $
- *
- * Rev 1.40 12 Feb 1989 4:56:16 Marshall Presnell
- * Public Release Version 1.40
- *
- * Rev 1.31 31 Jan 1989 0:58:20 Marshall Presnell
- * oMMM 1.35 Beta Release Version
- *
- * Rev 1.30 23 Jan 1989 17:53:58 Marshall Presnell
- * Public Source Code Release - Version 1.30
-
- */
-
- /*--------------------------------------------------------------------------*/
- /* Include files */
- /*--------------------------------------------------------------------------*/
-
- #include "ommm.h"
- #include <stdlib.h>
- #include <string.h>
-
- /*--------------------------------------------------------------------------*/
- /* Static function declarations */
- /*--------------------------------------------------------------------------*/
-
- static struct _pending * find_pointer(struct _pending *,int);
- static void find_addr(struct _msg * msg);
-
- /*--------------------------------------------------------------------------*/
- /* Static variable definitions */
- /*--------------------------------------------------------------------------*/
-
- static struct _pending * temppend;
- static char mjunk[16000];
-
- /*--------------------------------------------------------------------------*/
- /* External variable declarations */
- /*--------------------------------------------------------------------------*/
-
- extern ADDRESS ctlnet[];
- extern int num_addrs;
-
- /****************************************************************************/
-
- /*--------------------------------------------------------------------------*/
- /* FIND POINTER */
- /*--------------------------------------------------------------------------*/
-
- static struct _pending *
- find_pointer(struct _pending * rootptr,int number)
- {
-
- register struct _pending * tree;
- register struct _msglist * mlist;
- struct _msglist * tmp;
-
- tree = rootptr;
- while(tree) {
- if ((tree->id1==dest.net) && (tree->id2==dest.node) && (tree->id3==dest.zone)) {
- mlist = tree->lastmsg;
- tmp = (struct _msglist *) malloc(sizeof(struct _msglist));
- tmp->number = number;
- while (mlist->number < number) {
- if (mlist->next == NULL) {
- tmp->next = NULL;
- /* BUGFIX: */ tmp->prev = mlist;
- mlist->next = tmp;
- return(NULL);
- } else
- mlist = mlist->next;
- }
- tmp->next = mlist;
- tmp->prev = mlist->prev;
- if (mlist->prev) {
- mlist->prev->next = tmp;
- mlist->prev = tmp;
- } else {
- mlist->prev = tmp;
- tree->lastmsg = tree->firstmsg = tmp;
- }
- return (NULL);
- }
- tree = tree->next;
- }
- tree = (struct _pending *) malloc(sizeof(struct _pending));
- tree->id1 = dest.net;
- tree->id2 = dest.node;
- tree->id3 = dest.zone;
- tree->firstmsg = tree->lastmsg = NULL;
-
- tree->firstmsg = tree->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
- (tree->firstmsg)->number= (tree->lastmsg)->number = number;
- (tree->firstmsg)->next = (tree->lastmsg)->next = NULL;
- (tree->firstmsg)->prev = (tree->lastmsg)->prev = NULL;
-
- tree->next = rootptr;
- return(tree);
- }
-
- /*--------------------------------------------------------------------------*/
- /* SCAN MESSAGES */
- /*--------------------------------------------------------------------------*/
-
- int
- scan_messages()
- {
- int loci;
- struct _msg * msg;
-
- msg = (struct _msg *) &mjunk[0];
- sprintf(template,"%s*.MSG",message_path);
-
- if (dir_findfirst(template,NORMAL,&dta)) {
- printf("\nNo messages (%s)\n",message_path);
- fflush(stdout);
- return(0);
- }
-
- /*--------------------------------------------------------------------*/
- /* Scan for outbound messages */
- /*--------------------------------------------------------------------*/
-
- printf("Scanning mail area...\n");
- fflush(stdout);
- do {
- if (dta.size < (long) sizeof(struct _msg))
- continue;
-
- if ((j=atoi(dta.name)) <= 0)
- continue;
-
- sprintf(template,"%s%s",message_path,dta.name);
-
- #if DEBUG
- puts(template);
- fflush(stdout);
- #endif
-
- if (open_read_and_close(template,mjunk,16000) < 0) {
- printf("Can't read %s\n",template);
- fflush(stdout);
- continue;
- }
-
- #if DEBUG
- puts("open okay");
- fflush(stdout);
- #endif
-
- /* swap_msg((struct _msg *)mjunk); amigaspec */
- /* If we are not supposed to forward, then don't! */
-
- if (noforward) {
- for (loci = 0; loci < num_addrs; loci++) {
- if ((msg->orig_net == ctlnet[loci].net) &&
- (msg->orig == ctlnet[loci].node)) {
- break;
- }
- }
- if (loci == num_addrs) {
- continue;
- }
- }
-
- #if DEBUG
- puts("forward okay");
- fflush(stdout);
- #endif
-
- if ((msg->dest_net>=0) && (!(msg->attr&MSGSENT)) && (!(msg->attr&MSGORPHAN))) {
-
- find_addr (msg);
-
- for (loci = 0; loci < num_addrs; loci++) {
- if ((dest.net == ctlnet[loci].net) && (dest.node == ctlnet[loci].node)) {
- break;
- }
- }
- if (loci == num_addrs) {
-
- #if DEBUG
- puts("sending");
- fflush(stdout);
- #endif
-
- if (root) {
- if (NULL!=(temppend=find_pointer(root,j)))
- root = temppend;
- } else {
- root = (struct _pending *)malloc(sizeof(struct _pending));
- root->next = NULL;
- root->id1 = dest.net;
- root->id2 = dest.node;
- root->id3 = dest.zone;
- root->firstmsg = root->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
- (root->firstmsg)->number=(root->lastmsg)->number=j;
- (root->firstmsg)->next=(root->lastmsg)->next=NULL;
- (root->firstmsg)->prev=(root->lastmsg)->prev=NULL;
- }
- }
- }
- } while(!dir_findnext(&dta));
-
- #if DEBUG
- puts("scan done");
- fflush(stdout);
- #endif
-
- return(1);
- }
-
- /*--------------------------------------------------------------------------*/
- /* FIND ADDR */
- /*--------------------------------------------------------------------------*/
-
- static void
- find_addr(struct _msg * msg)
- {
- char * p;
-
- dest.zone = our_zone;
-
- p = strstr(&mjunk[sizeof (struct _msg)], "\001INTL");
-
- if ((p == NULL) || (our_zone == 0) || ((use_gates) && (!(msg->attr&(MSGCRASH|MSGFILE|MSGFRQ|MSGURQ))))) {
- dest.net = msg->dest_net;
- dest.node = msg->dest;
- } else {
- sscanf(p+6, "%d:%d/%d", &(dest.zone), &(dest.net), &(dest.node));
- }
-
- if ((!never_gate) && (our_zone == msg->dest_net) && (dest.zone == msg->dest)) {
- dest.net = msg->dest_net;
- dest.node = msg->dest;
- dest.zone = our_zone;
- }
- }
-
-
- /*-------------------------------------------------------------------------*/
- /* ID: 167.25@8283 Last Changed: 08 Apr 1990 15:57:50 by max */
-