home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OS2OMMM.SRC / OMMMSCAN.C < prev    next >
Text File  |  1989-06-01  |  7KB  |  236 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.40BP 2 June 1989 23:19:00    Bill Andrus
  30.  * Public Release Version 1.40BP (OS/2 Protect Mode, Bound)
  31.  *
  32.  *      Rev 1.40     12 Feb 1989  4:56:16    Marshall Presnell
  33.  * Public Release Version 1.40
  34.  *
  35.  *      Rev 1.31     31 Jan 1989  0:58:20    Marshall Presnell
  36.  * oMMM 1.35 Beta Release Version
  37.  *
  38.  *      Rev 1.30     23 Jan 1989 17:53:58    Marshall Presnell
  39.  * Public Source Code Release - Version 1.30
  40.  
  41. */
  42.  
  43. /*--------------------------------------------------------------------------*/
  44. /* Include files                                                            */
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. #include    "ommm.h"
  48. #include    <stdlib.h>
  49. #include    <string.h>
  50.  
  51. /*--------------------------------------------------------------------------*/
  52. /* Static function declarations                                             */
  53. /*--------------------------------------------------------------------------*/
  54.  
  55. static struct _pending *    find_pointer(struct _pending *,int);
  56. static void                 find_addr(struct _msg * msg);
  57.  
  58. /*--------------------------------------------------------------------------*/
  59. /* Static variable definitions                                                */
  60. /*--------------------------------------------------------------------------*/
  61.  
  62. static struct _pending *    temppend;
  63. static char                 mjunk[16000];
  64.  
  65. /*--------------------------------------------------------------------------*/
  66. /* External variable declarations                                            */
  67. /*--------------------------------------------------------------------------*/
  68.  
  69. extern NETADDRESS            ctlnet[];
  70. extern int                    num_addrs;
  71.  
  72. /****************************************************************************/
  73.  
  74. /*--------------------------------------------------------------------------*/
  75. /* FIND POINTER                                                             */
  76. /*--------------------------------------------------------------------------*/
  77.  
  78.  static struct _pending *
  79. find_pointer(struct _pending * rootptr,int number)
  80. {
  81.  
  82.     register struct _pending *    tree;
  83.     register struct _msglist *    mlist;
  84.     struct _msglist *            tmp;
  85.  
  86.     tree  = rootptr;
  87.     while(tree) {
  88.         if ((tree->id1==dest.net) && (tree->id2==dest.node) && (tree->id3==dest.zone)) {
  89.             mlist = tree->lastmsg;
  90.             tmp = (struct _msglist *) malloc(sizeof(struct _msglist));
  91.             tmp->number = number;
  92.             while (mlist->number < number) {
  93.                 if (mlist->next == NULL) {
  94.                     tmp->next      = NULL;
  95.                     mlist->next   = tmp;
  96.                     return(NULL);
  97.                 } else
  98.                     mlist = mlist->next;
  99.             }
  100.             tmp->next = mlist;
  101.             tmp->prev = mlist->prev;
  102.             if (mlist->prev) {
  103.                 mlist->prev->next = tmp;
  104.                 mlist->prev = tmp;
  105.             } else {
  106.                 mlist->prev = tmp;
  107.                 tree->lastmsg = tree->firstmsg = tmp;
  108.             }
  109.             return (NULL);
  110.         }
  111.         tree  = tree->next;
  112.     }
  113.     tree             = (struct _pending *) malloc(sizeof(struct _pending));
  114.     tree->id1     = dest.net;
  115.     tree->id2     = dest.node;
  116.     tree->id3     = dest.zone;
  117.     tree->firstmsg     = tree->lastmsg   = NULL;
  118.  
  119.     tree->firstmsg     = tree->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
  120.     (tree->firstmsg)->number= (tree->lastmsg)->number  = number;
  121.     (tree->firstmsg)->next    = (tree->lastmsg)->next    = NULL;
  122.     (tree->firstmsg)->prev    = (tree->lastmsg)->prev    = NULL;
  123.  
  124.     tree->next         = rootptr;
  125.     return(tree);
  126. }
  127.  
  128. /*--------------------------------------------------------------------------*/
  129. /* SCAN MESSAGES                                                            */
  130. /*--------------------------------------------------------------------------*/
  131.  
  132.  int
  133. scan_messages()
  134. {
  135.     int             loci;
  136.     struct _msg *    msg;
  137.  
  138.     msg = (struct _msg *) mjunk;
  139.     sprintf(template,"%s*.MSG",message_path);
  140.  
  141.     if (dir_findfirst(template,NORMAL,&dta)) {
  142.         printf("\nNo messages (%s)\n",message_path);
  143.         return(0);
  144.     }
  145.  
  146.     /*--------------------------------------------------------------------*/
  147.     /* Scan for outbound messages                                          */
  148.     /*--------------------------------------------------------------------*/
  149.  
  150.     puts("Scanning mail area...");
  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 (open_read_and_close(template,mjunk,16000) < 0) {
  161.             printf("Can't read %s\n",template);
  162.             continue;
  163.         }
  164.  
  165.         /* If we are not supposed to forward, then don't! */
  166.  
  167.         if (noforward) {
  168.             for (loci = 0; loci < num_addrs; loci++) {
  169.                 if ((msg->orig_net == ctlnet[loci].net) &&
  170.                  (msg->orig == ctlnet[loci].node)) {
  171.                     break;
  172.                 }
  173.             }
  174.             if (loci == num_addrs) {
  175.                 continue;
  176.             }
  177.         }
  178.  
  179.         if ((msg->dest_net>=0) && (!(msg->attr&MSGSENT)) && (!(msg->attr&MSGORPHAN))) {
  180.             find_addr (msg);
  181.             for (loci = 0; loci < num_addrs; loci++) {
  182.                     if ((dest.net == ctlnet[loci].net) && (dest.node == ctlnet[loci].node)) {
  183.                     break;
  184.                 }
  185.             }
  186.             if (loci == num_addrs) {
  187.                 if (root) {
  188.                     if (NULL!=(temppend=find_pointer(root,j)))
  189.                         root = temppend;
  190.                 } else {
  191.                     root        = (struct _pending *)malloc(sizeof(struct _pending));
  192.                     root->next    = NULL;
  193.                     root->id1    = dest.net;
  194.                     root->id2    = dest.node;
  195.                     root->id3    = dest.zone;
  196.                     root->firstmsg    = root->lastmsg = (struct _msglist *)malloc(sizeof(struct _msglist));
  197.                     (root->firstmsg)->number=(root->lastmsg)->number=j;
  198.                     (root->firstmsg)->next=(root->lastmsg)->next=NULL;
  199.                     (root->firstmsg)->prev=(root->lastmsg)->prev=NULL;
  200.                 }
  201.             }
  202.         }
  203.     } while(!dir_findnext(&dta));
  204.     return(1);
  205. }
  206.  
  207. /*--------------------------------------------------------------------------*/
  208. /* FIND ADDR                                                                */
  209. /*--------------------------------------------------------------------------*/
  210.  
  211.  static void
  212. find_addr(struct _msg * msg)
  213. {
  214.     char *            p;
  215.  
  216.     dest.zone = our_zone;
  217.     p = strstr(&mjunk[sizeof (struct _msg)], "\001INTL");
  218.     if ((p == NULL) || (our_zone == 0) || ((use_gates) && (!(msg->attr&(MSGCRASH|MSGFILE|MSGFRQ|MSGURQ))))) {
  219.         dest.net  = msg->dest_net;
  220.         dest.node = msg->dest;
  221.     } else {
  222.          sscanf(p+6, "%d:%d/%d", &(dest.zone), &(dest.net), &(dest.node));
  223.     }
  224.  
  225.     if ((our_zone == msg->dest_net) && (dest.zone == msg->dest)) {
  226.         dest.net = msg->dest_net;
  227.         dest.node = msg->dest;
  228.         dest.zone = our_zone;
  229.     }
  230. }
  231.  
  232. /*--------------------------------------------------------------------------*/
  233. /*                                  END OF FILE                                */
  234. /*--------------------------------------------------------------------------*/
  235.  
  236.