home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / osrc_149.lzh / ommmscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-08  |  8.2 KB  |  268 lines

  1. /***************************************************************************/
  2. /***                                                                     ***/
  3. /***               oMMM - The Outbound Matrix Message Masher             ***/
  4. /***                      Copyright 1989 BS Software                     ***/
  5. /***                                                                     ***/
  6. /***                         FILENAME: OMMMSCAN.C                        ***/
  7. /***                                                                     ***/
  8. /***                           Mail area scanner                         ***/
  9. /***                                                                     ***/
  10. /***                 Based on the original oMMM, a portion of            ***/
  11. /***               the Opus Computer-Based Conversation System           ***/
  12. /***                     Copyright 1986, Wynn Wagner III                 ***/
  13. /***                                                                     ***/
  14. /***************************************************************************/
  15. /***                                                                     ***/
  16. /***                    Tabs set at every 4th column                     ***/
  17. /***                                                                     ***/
  18. /***************************************************************************/
  19.  
  20. /*
  21.     Polytron Version Control System Comments:
  22.  
  23.     The revision of this file is *** $Revision:   1.40  $ ***
  24.  
  25.     History of changes from 1.30 release version
  26.  
  27.     $Log:   C:/OMMM/PROJFILE/OMMMSCAN.C_V  $
  28.  * 
  29.  *    Rev 1.40   12 Feb 1989  4:56:16   Marshall Presnell
  30.  * Public Release Version 1.40
  31.  * 
  32.  *    Rev 1.31   31 Jan 1989  0:58:20   Marshall Presnell
  33.  * oMMM 1.35 Beta Release Version
  34.  * 
  35.  *    Rev 1.30   23 Jan 1989 17:53:58   Marshall Presnell
  36.  * Public Source Code Release - Version 1.30
  37.  
  38. */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Include files                                                            */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include    "ommm.h"
  45. #include    <stdlib.h>
  46. #include    <string.h>
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. /* Static function declarations                                             */
  50. /*--------------------------------------------------------------------------*/
  51.  
  52. static struct _pending *    find_pointer(struct _pending *,int);
  53. static void                    find_addr(struct _msg * msg);
  54.  
  55. /*--------------------------------------------------------------------------*/
  56. /* Static variable definitions                                              */
  57. /*--------------------------------------------------------------------------*/
  58.  
  59. static struct _pending *    temppend;
  60. static char                 mjunk[16000];
  61.  
  62. /*--------------------------------------------------------------------------*/
  63. /* External variable declarations                                           */
  64. /*--------------------------------------------------------------------------*/
  65.  
  66. extern ADDRESS                ctlnet[];
  67. extern int                    num_addrs;
  68.  
  69. /****************************************************************************/
  70.  
  71. /*--------------------------------------------------------------------------*/
  72. /* FIND POINTER                                                             */
  73. /*--------------------------------------------------------------------------*/
  74.  
  75.  static struct _pending *
  76. find_pointer(struct _pending * rootptr,int number)
  77. {
  78.  
  79.     register struct _pending *    tree;
  80.     register struct _msglist *    mlist;
  81.     struct _msglist *            tmp;
  82.  
  83.     tree  = rootptr;
  84.     while(tree) {
  85.         if ((tree->id1==dest.net) && (tree->id2==dest.node) && (tree->id3==dest.zone)) {
  86.             mlist = tree->lastmsg;
  87.             tmp = (struct _msglist *) malloc(sizeof(struct _msglist));
  88.             tmp->number = number;
  89.             while (mlist->number < number) {
  90.                 if (mlist->next == NULL) {
  91.                     tmp->next     = NULL;
  92. /* BUGFIX: */    tmp->prev     = mlist;
  93.                     mlist->next   = tmp;
  94.                     return(NULL);
  95.                 } else
  96.                     mlist = mlist->next;
  97.             }
  98.             tmp->next = mlist;
  99.             tmp->prev = mlist->prev;
  100.             if (mlist->prev) {
  101.                 mlist->prev->next = tmp;
  102.                 mlist->prev = tmp;
  103.             } else {
  104.                 mlist->prev = tmp;
  105.                 tree->lastmsg = tree->firstmsg = tmp;
  106.             }
  107.             return (NULL);
  108.         }
  109.         tree  = tree->next;
  110.     }
  111.     tree             = (struct _pending *) malloc(sizeof(struct _pending));
  112.     tree->id1     = dest.net;
  113.     tree->id2     = dest.node;
  114.     tree->id3     = dest.zone;
  115.     tree->firstmsg   = tree->lastmsg   = NULL;
  116.  
  117.     tree->firstmsg   = tree->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
  118.     (tree->firstmsg)->number= (tree->lastmsg)->number  = number;
  119.     (tree->firstmsg)->next  = (tree->lastmsg)->next    = NULL;
  120.     (tree->firstmsg)->prev  = (tree->lastmsg)->prev    = NULL;
  121.  
  122.     tree->next       = rootptr;
  123.     return(tree);
  124. }
  125.  
  126. /*--------------------------------------------------------------------------*/
  127. /* SCAN MESSAGES                                                            */
  128. /*--------------------------------------------------------------------------*/
  129.  
  130.  int
  131. scan_messages()
  132. {
  133.     int                loci;
  134.     struct _msg *    msg;
  135.  
  136.     msg = (struct _msg *) &mjunk[0];
  137.     sprintf(template,"%s*.MSG",message_path);
  138.  
  139.     if (dir_findfirst(template,NORMAL,&dta)) {
  140.         printf("\nNo messages (%s)\n",message_path);
  141.         fflush(stdout);
  142.         return(0);
  143.     }
  144.  
  145.     /*--------------------------------------------------------------------*/
  146.     /* Scan for outbound messages                                         */
  147.     /*--------------------------------------------------------------------*/
  148.  
  149.     printf("Scanning mail area...\n");
  150.     fflush(stdout);
  151.     do {
  152.         if (dta.size < (long) sizeof(struct _msg))
  153.             continue;
  154.  
  155.         if ((j=atoi(dta.name)) <= 0)
  156.             continue;
  157.  
  158.         sprintf(template,"%s%s",message_path,dta.name);
  159.  
  160. #if DEBUG
  161.     puts(template);
  162.     fflush(stdout);
  163. #endif
  164.  
  165.         if (open_read_and_close(template,mjunk,16000) < 0) {
  166.             printf("Can't read %s\n",template);
  167.             fflush(stdout);
  168.             continue;
  169.         }
  170.  
  171. #if DEBUG
  172.     puts("open okay");
  173.     fflush(stdout);
  174. #endif
  175.  
  176.         /* swap_msg((struct _msg *)mjunk);  amigaspec */
  177.         /* If we are not supposed to forward, then don't! */
  178.  
  179.         if (noforward) {
  180.             for (loci = 0; loci < num_addrs; loci++) {
  181.                 if ((msg->orig_net == ctlnet[loci].net) &&
  182.                  (msg->orig    == ctlnet[loci].node)) {
  183.                     break;
  184.                 }
  185.             }
  186.             if (loci == num_addrs) {
  187.                 continue;
  188.             }
  189.         }
  190.  
  191. #if DEBUG
  192.     puts("forward okay");
  193.     fflush(stdout);
  194. #endif
  195.  
  196.         if ((msg->dest_net>=0) && (!(msg->attr&MSGSENT)) && (!(msg->attr&MSGORPHAN))) {
  197.  
  198.             find_addr (msg);
  199.  
  200.             for (loci = 0; loci < num_addrs; loci++) {
  201.                     if ((dest.net == ctlnet[loci].net) && (dest.node == ctlnet[loci].node)) {
  202.                     break;
  203.                 }
  204.             }
  205.             if (loci == num_addrs) {
  206.  
  207. #if DEBUG
  208.     puts("sending");
  209.     fflush(stdout);
  210. #endif
  211.  
  212.                 if (root) {
  213.                     if (NULL!=(temppend=find_pointer(root,j)))
  214.                         root = temppend;
  215.                 } else {
  216.                     root        = (struct _pending *)malloc(sizeof(struct _pending));
  217.                     root->next  = NULL;
  218.                     root->id1   = dest.net;
  219.                     root->id2   = dest.node;
  220.                     root->id3   = dest.zone;
  221.                     root->firstmsg  = root->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
  222.                     (root->firstmsg)->number=(root->lastmsg)->number=j;
  223.                     (root->firstmsg)->next=(root->lastmsg)->next=NULL;
  224.                     (root->firstmsg)->prev=(root->lastmsg)->prev=NULL;
  225.                 }
  226.             }
  227.         }
  228.     } while(!dir_findnext(&dta));
  229.  
  230. #if DEBUG
  231.     puts("scan done");
  232.     fflush(stdout);
  233. #endif
  234.  
  235.     return(1);
  236. }
  237.  
  238. /*--------------------------------------------------------------------------*/
  239. /* FIND ADDR                                                                */
  240. /*--------------------------------------------------------------------------*/
  241.  
  242.  static void
  243. find_addr(struct _msg * msg)
  244. {
  245.     char *            p;
  246.  
  247.     dest.zone = our_zone;
  248.  
  249.     p = strstr(&mjunk[sizeof (struct _msg)], "\001INTL");
  250.  
  251.     if ((p == NULL) || (our_zone == 0) || ((use_gates) && (!(msg->attr&(MSGCRASH|MSGFILE|MSGFRQ|MSGURQ))))) {
  252.         dest.net  = msg->dest_net;
  253.         dest.node = msg->dest;
  254.     } else {
  255.          sscanf(p+6, "%d:%d/%d", &(dest.zone), &(dest.net), &(dest.node));
  256.     }
  257.  
  258.     if ((!never_gate) && (our_zone == msg->dest_net) && (dest.zone == msg->dest)) {
  259.         dest.net = msg->dest_net;
  260.         dest.node = msg->dest;
  261.         dest.zone = our_zone;
  262.     }
  263. }
  264.  
  265.  
  266. /*-------------------------------------------------------------------------*/
  267. /* ID: 167.25@8283  Last Changed: 08 Apr 1990 15:57:50 by max */
  268.