home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / LORAWIN.CPP < prev    next >
C/C++ Source or Header  |  1998-05-12  |  148KB  |  4,600 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "_ldefs.h"
  20. #include "lorawin.h"
  21.  
  22. #define MAIL_IMPORTKNOWN         0x0001L
  23. #define MAIL_IMPORTPROTECTED     0x0002L
  24. #define MAIL_IMPORTNORMAL        0x0004L
  25. #define MAIL_EXPORT              0x0008L
  26. #define MAIL_PACK                0x0010L
  27. #define MAIL_NEWSGROUP           0x0020L
  28. #define MAIL_TIC                 0x0040L
  29. #define MAIL_EMAIL               0x0080L
  30. #define MAIL_IMPORTBAD           0x0100L
  31. #define MAIL_NOEXTERNAL          0x2000L
  32. #define MAIL_STARTTIMER          0x4000L
  33. #define MAIL_POSTQUIT            0x8000L
  34.  
  35. #if defined(__OS2__)
  36. #define IDOK            1
  37. #define IDCANCEL        2
  38. #endif
  39.  
  40. #define INITIALIZE         1
  41. #define WAITFOROK          2
  42. #define WAITFORCALL        3
  43. #define ANSWERING          4
  44. #define HANGUP             5
  45. #define WAITFORCONNECT     6
  46. #define BBSEXIT            7
  47. #define UNDEFINED          99
  48.  
  49. PSZ statusText[] = {
  50.    "Startup",
  51.    "Initialize",
  52.    "WaitForOK",
  53.    "WaitForCall",
  54.    "Answering",
  55.    "Hangup",
  56.    "WaitForConnect",
  57.    "BBSExit"
  58. };
  59.  
  60. #define MODEM_DELAY        200
  61. #define EVENTS_DELAY       1000
  62. #define REINIT_DELAY       60000L
  63.  
  64. #if defined(__OS2__)
  65. HAB  hab;
  66. HWND hwndMainFrame, hwndMainClient;
  67. HWND help_hWnd;
  68. FILEDLG fild;
  69. #elif defined(__NT__)
  70. HINSTANCE hinst;
  71. HWND hwndMainClient, hwndMainList, hwndModemList, hwndStatusList, hwndOutboundList;
  72. #endif
  73.  
  74. USHORT Status, Current, gotPort, gotSpeed, timeLimit = 0;
  75. CHAR   PollNode[64], ExternalProgram[128];
  76. LONG   TimeOut, CallTimer = 0L;
  77. ULONG  comHandle = 0L, connectSpeed = 0L;
  78. UCHAR  ErrorLevel = 1;
  79. class  TConfig *Cfg;
  80. class  TModem *Modem;
  81. class  TPMLog *Log;
  82. class  TEvents *Events;
  83. class  TOutbound *Outbound;
  84.  
  85. #define WMU_STARTTIMER              10
  86.  
  87. VOID StartTimer (HWND hwnd, int id, ULONG msec)
  88. {
  89. #if defined(__OS2__)
  90.    WinStartTimer (hab, hwnd, id, msec);
  91. #elif defined(__NT__)
  92.    SetTimer (hwnd, id, msec, NULL);
  93. #endif
  94. }
  95.  
  96. VOID StopTimer (HWND hwnd, int id)
  97. {
  98. #if defined(__OS2__)
  99.    WinStopTimer (hab, hwnd, id);
  100. #elif defined(__NT__)
  101.    KillTimer (hwnd, id);
  102. #endif
  103. }
  104.  
  105. // ----------------------------------------------------------------------
  106. // Product informations dialog
  107. // ----------------------------------------------------------------------
  108.  
  109. #if !defined(__POINT__)
  110.  
  111. class CProductDlg : public CDialog
  112. {
  113. public:
  114.    CProductDlg (HWND p_hWnd);
  115.  
  116.    USHORT OnInitDialog (VOID);
  117. };
  118.  
  119. CProductDlg::CProductDlg (HWND p_hWnd) : CDialog ("100", p_hWnd)
  120. {
  121. }
  122.  
  123. USHORT CProductDlg::OnInitDialog (VOID)
  124. {
  125.    CHAR Temp[128], RegName[64], RegNumber[16];
  126.  
  127.    Center ();
  128.  
  129.    return (TRUE);
  130. }
  131.  
  132. // ----------------------------------------------------------------------
  133. // Outbound details dialog
  134. // ----------------------------------------------------------------------
  135.  
  136. class CDetailsDlg : public CDialog
  137. {
  138. public:
  139.    CDetailsDlg (HWND p_hWnd);
  140.    ~CDetailsDlg (void);
  141.  
  142.    USHORT DoRebuild;
  143.    CHAR   Address[64];
  144.  
  145.    VOID   OnHelp (VOID);
  146.    USHORT OnInitDialog (VOID);
  147.  
  148. private:
  149.    CHAR   Temp[1024];
  150.    class  TOutbound *Out;
  151.    DECLARE_MESSAGE_MAP ()
  152.  
  153.    VOID   Add (VOID);
  154.    VOID   ChangeToNormal (VOID);
  155.    VOID   ChangeToDirect (VOID);
  156.    VOID   ChangeToCrash (VOID);
  157.    VOID   ChangeToHold (VOID);
  158.    VOID   Delete (VOID);
  159.    VOID   DeleteEntry (VOID);
  160.    VOID   Refresh (VOID);
  161.    VOID   ToggleImmediate (VOID);
  162. };
  163.  
  164. BEGIN_MESSAGE_MAP (CDetailsDlg, CDialog)
  165.    ON_COMMAND (48, ChangeToNormal)
  166.    ON_COMMAND (49, ChangeToDirect)
  167.    ON_COMMAND (50, ChangeToCrash)
  168.    ON_COMMAND (51, ChangeToHold)
  169.    ON_COMMAND (52, ToggleImmediate)
  170.    ON_COMMAND (115, Add)
  171.    ON_COMMAND (116, Delete)
  172.    ON_COMMAND (117, DeleteEntry)
  173. END_MESSAGE_MAP ()
  174.  
  175. CDetailsDlg::CDetailsDlg (HWND p_hWnd) : CDialog ("47", p_hWnd)
  176. {
  177.    DoRebuild = FALSE;
  178.    if ((Out = new TOutbound (Cfg->Outbound)) != NULL) {
  179.       Cfg->MailAddress.First ();
  180.       Out->DefaultZone = Cfg->MailAddress.Zone;
  181.    }
  182. }
  183.  
  184. CDetailsDlg::~CDetailsDlg (void)
  185. {
  186.    if (Out != NULL)
  187.       delete Out;
  188. }
  189.  
  190. VOID CDetailsDlg::OnHelp (VOID)
  191. {
  192.    WinHelp ("lora.hlp>h_ref", 47);
  193. }
  194.  
  195. USHORT CDetailsDlg::OnInitDialog (VOID)
  196. {
  197.    class TNodes *Nodes;
  198.  
  199.    Center ();
  200.  
  201.    LVM_AllocateColumns (101, 4);
  202.    LVM_InsertColumn (101, "Name", LVC_LEFT);
  203.    LVM_InsertColumn (101, "Size", LVC_RIGHT);
  204.    LVM_InsertColumn (101, "Flag", LVC_CENTER);
  205.    LVM_InsertColumn (101, "Location", LVC_LEFT);
  206.  
  207.    if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  208.       if (Nodes->Read (Address) == TRUE) {
  209.          SetDlgItemText (102, Nodes->SystemName);
  210.          SetDlgItemText (103, Nodes->Address);
  211.          SetDlgItemText (109, Nodes->Location);
  212.          SetDlgItemText (102, Nodes->SysopName);
  213.       }
  214.       delete Nodes;
  215.    }
  216.  
  217.    Refresh ();
  218.  
  219.    return (TRUE);
  220. }
  221.  
  222. VOID CDetailsDlg::Delete (VOID)
  223. {
  224.    int item;
  225.  
  226.    if ((item = LVM_QuerySelectedItem (101)) >= 0 && Out != NULL) {
  227.       if (MessageBox ("Do you really want to delete the selected file ?", "Delete", MB_YESNO|MB_ICONQUESTION) == IDYES) {
  228.          if (Out->First () == TRUE)
  229.             do {
  230.                if (item == 0) {
  231.                   Out->Remove ();
  232.                   Out->Update ();
  233.                   LVM_DeleteItem (101, LVM_QuerySelectedItem (101));
  234.                   DoRebuild = TRUE;
  235.                   break;
  236.                }
  237.                item--;
  238.             } while (Out->Next () == TRUE);
  239.       }
  240.    }
  241. }
  242.  
  243. VOID CDetailsDlg::DeleteEntry (VOID)
  244. {
  245.    if (Out != NULL) {
  246.       if (MessageBox ("Do you really want to delete this node's entry ?", "Delete", MB_YESNO|MB_ICONQUESTION) == IDYES) {
  247.          while (Out->First () == TRUE)
  248.             Out->Remove ();
  249.          Out->Update ();
  250.          LVM_DeleteAll (101);
  251.          DoRebuild = TRUE;
  252.          EndDialog (FALSE);
  253.       }
  254.    }
  255. }
  256.  
  257. VOID CDetailsDlg::Add (VOID)
  258. {
  259.    class TAddress Addr;
  260.    struct stat statbuf;
  261. #if defined(__OS2__)
  262.    ULONG i;
  263.    FILEDLG fild;
  264.  
  265.    Addr.Parse (Address);
  266.  
  267.    memset (&fild, 0, sizeof (FILEDLG));
  268.    fild.cbSize = sizeof (FILEDLG);
  269.    fild.fl = FDS_CENTER|FDS_OPEN_DIALOG|FDS_MULTIPLESEL;
  270.    fild.pszTitle = "Add File";
  271.    sprintf (fild.szFullFile, "*.*");
  272.  
  273.    WinFileDlg (HWND_DESKTOP, m_hWnd, &fild);
  274.    if (fild.lReturn == DID_OK) {
  275.       if (fild.papszFQFilename != NULL) {
  276.          for (i = 0; i < fild.ulFQFCount; i++) {
  277.             Out->New ();
  278.             Out->Zone = Addr.Zone;
  279.             Out->Net = Addr.Net;
  280.             Out->Node = Addr.Node;
  281.             Out->Point = Addr.Point;
  282.             strcpy (Out->Complete, fild.papszFQFilename[i][0]);
  283.             if (stat (Out->Complete, &statbuf) == 0)
  284.                Out->Size = statbuf.st_size;
  285.             Out->Status = 'h';
  286.             Out->Add ();
  287.          }
  288.       }
  289.       else {
  290.          Out->New ();
  291.          Out->Zone = Addr.Zone;
  292.          Out->Net = Addr.Net;
  293.          Out->Node = Addr.Node;
  294.          Out->Point = Addr.Point;
  295.          strcpy (Out->Complete, fild.szFullFile);
  296.          if (stat (Out->Complete, &statbuf) == 0)
  297.             Out->Size = statbuf.st_size;
  298.          Out->Status = 'h';
  299.          Out->Add ();
  300.       }
  301.       Out->Update ();
  302.       DoRebuild = TRUE;
  303.       Refresh ();
  304.    }
  305.    if (fild.papszFQFilename != NULL)
  306.       WinFreeFileDlgList (fild.papszFQFilename);
  307. #elif defined(__NT__)
  308.    CHAR Path[256], *p;
  309.    OPENFILENAME OpenFileName;
  310.  
  311.    Addr.Parse (Address);
  312.  
  313.    Temp[0] = '\0';
  314.    OpenFileName.lStructSize = sizeof (OPENFILENAME);
  315.    OpenFileName.hwndOwner = m_hWnd;
  316.    OpenFileName.hInstance = NULL;
  317.    OpenFileName.lpstrFilter = "All files (*.*)\0*.*";
  318.    OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
  319.    OpenFileName.nMaxCustFilter = 0L;
  320.    OpenFileName.nFilterIndex = 1L;
  321.    OpenFileName.lpstrFile = Temp;
  322.    OpenFileName.nMaxFile = sizeof (Temp) - 1;
  323.    OpenFileName.lpstrFileTitle = NULL;
  324.    OpenFileName.nMaxFileTitle = 0;
  325.    OpenFileName.lpstrInitialDir = NULL;
  326.    OpenFileName.lpstrTitle = "Add File";
  327.    OpenFileName.nFileOffset = 0;
  328.    OpenFileName.nFileExtension = 0;
  329.    OpenFileName.lpstrDefExt = "";
  330.    OpenFileName.lCustData = 0;
  331.    OpenFileName.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_CREATEPROMPT|OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT;
  332.  
  333.    if (GetOpenFileName (&OpenFileName) == TRUE) {
  334.       if ((p = strtok (Temp, " ")) != NULL) {
  335.          strcpy (Path, p);
  336.          if (Path[strlen (Path) - 1] != '\\')
  337.             strcat (Path, "\\");
  338.          do {
  339.             Out->New ();
  340.             Out->Zone = Addr.Zone;
  341.             Out->Net = Addr.Net;
  342.             Out->Node = Addr.Node;
  343.             Out->Point = Addr.Point;
  344.             sprintf (Out->Complete, "%s%s", Path, p);
  345.             if (stat (Out->Complete, &statbuf) == 0)
  346.                Out->Size = statbuf.st_size;
  347.             Out->Status = 'h';
  348.             Out->Add ();
  349.          } while ((p = strtok (NULL, " ")) != NULL);
  350.  
  351.          Out->Update ();
  352.          DoRebuild = TRUE;
  353.          Refresh ();
  354.       }
  355.    }
  356. #endif
  357. }
  358.  
  359. VOID CDetailsDlg::ToggleImmediate (VOID)
  360. {
  361.    USHORT Found = FALSE;
  362.  
  363.    if (Out->First () == TRUE)
  364.       do {
  365.          if (Out->Poll == TRUE && toupper (Out->Status) == 'I') {
  366.             Out->Remove ();
  367.             Out->Update ();
  368.             Found = TRUE;
  369.             break;
  370.          }
  371.       } while (Out->Next () == TRUE);
  372.  
  373.    if (Found == FALSE)
  374.       Out->PollNode (Address, 'i');
  375.  
  376.    Refresh ();
  377.    DoRebuild = TRUE;
  378. }
  379.  
  380. VOID CDetailsDlg::Refresh (VOID)
  381. {
  382.    class TAddress Addr;
  383.  
  384.    LVM_DeleteAll (101);
  385.  
  386.    if (Out != NULL) {
  387.       Out->Clear ();
  388.       Addr.Parse (Address);
  389.       Out->Add (Addr.Zone, Addr.Net, Addr.Node, Addr.Point);
  390.       if (Out->First () == TRUE)
  391.          do {
  392.             LVM_InsertItem (101);
  393.  
  394.             if (Out->Poll == FALSE) {
  395.                LVM_SetItemText (101, 0, Out->Name);
  396.                sprintf (Temp, "%lu", Out->Size);
  397.                LVM_SetItemText (101, 1, Temp);
  398.                sprintf (Temp, "%c", toupper (Out->Status));
  399.                LVM_SetItemText (101, 2, Temp);
  400.                LVM_SetItemText (101, 3, Out->Complete);
  401.             }
  402.             else {
  403.                LVM_SetItemText (101, 0, "<POLL>");
  404.                LVM_SetItemText (101, 1, "0");
  405.                sprintf (Temp, "%c", toupper (Out->Status));
  406.                LVM_SetItemText (101, 2, Temp);
  407.                LVM_SetItemText (101, 3, "");
  408.             }
  409.          } while (Out->Next () == TRUE);
  410.    }
  411.  
  412.    LVM_InvalidateView (101);
  413. }
  414.  
  415. VOID CDetailsDlg::ChangeToHold (VOID)
  416. {
  417.    class TMailProcessor *Processor;
  418.  
  419.    if ((Processor = new TMailProcessor) != NULL) {
  420.       Processor->Cfg = Cfg;
  421.       Processor->Log = NULL;
  422.       Processor->Output = NULL;
  423.       Processor->Status = NULL;
  424.       strcpy (Processor->Outbound, Cfg->Outbound);
  425.       if (Processor->Outbound[strlen (Processor->Outbound) - 1] == '\\' || Processor->Outbound[strlen (Processor->Outbound) - 1] == '/')
  426.          Processor->Outbound[strlen (Processor->Outbound) - 1] = '\0';
  427.  
  428.       sprintf (Temp, "Change Normal Hold %s", Address);
  429.       strtok (Temp, " ");
  430.       Processor->Change ();
  431.  
  432.       sprintf (Temp, "Change Crash Hold %s", Address);
  433.       strtok (Temp, " ");
  434.       Processor->Change ();
  435.  
  436.       sprintf (Temp, "Change Direct Hold %s", Address);
  437.       strtok (Temp, " ");
  438.       Processor->Change ();
  439.  
  440.       delete Processor;
  441.    }
  442.  
  443.    Refresh ();
  444.    DoRebuild = TRUE;
  445. }
  446.  
  447. VOID CDetailsDlg::ChangeToCrash (VOID)
  448. {
  449.    class TMailProcessor *Processor;
  450.  
  451.    if ((Processor = new TMailProcessor) != NULL) {
  452.       Processor->Cfg = Cfg;
  453.       Processor->Log = NULL;
  454.       Processor->Output = NULL;
  455.       Processor->Status = NULL;
  456.       strcpy (Processor->Outbound, Cfg->Outbound);
  457.       if (Processor->Outbound[strlen (Processor->Outbound) - 1] == '\\' || Processor->Outbound[strlen (Processor->Outbound) - 1] == '/')
  458.          Processor->Outbound[strlen (Processor->Outbound) - 1] = '\0';
  459.  
  460.       sprintf (Temp, "Change Normal Crash %s", Address);
  461.       strtok (Temp, " ");
  462.       Processor->Change ();
  463.  
  464.       sprintf (Temp, "Change Hold Crash %s", Address);
  465.       strtok (Temp, " ");
  466.       Processor->Change ();
  467.  
  468.       sprintf (Temp, "Change Direct Crash %s", Address);
  469.       strtok (Temp, " ");
  470.       Processor->Change ();
  471.  
  472.       delete Processor;
  473.    }
  474.  
  475.    Refresh ();
  476.    DoRebuild = TRUE;
  477. }
  478.  
  479. VOID CDetailsDlg::ChangeToDirect (VOID)
  480. {
  481.    class TMailProcessor *Processor;
  482.  
  483.    if ((Processor = new TMailProcessor) != NULL) {
  484.       Processor->Cfg = Cfg;
  485.       Processor->Log = NULL;
  486.       Processor->Output = NULL;
  487.       Processor->Status = NULL;
  488.       strcpy (Processor->Outbound, Cfg->Outbound);
  489.       if (Processor->Outbound[strlen (Processor->Outbound) - 1] == '\\' || Processor->Outbound[strlen (Processor->Outbound) - 1] == '/')
  490.          Processor->Outbound[strlen (Processor->Outbound) - 1] = '\0';
  491.  
  492.       sprintf (Temp, "Change Normal Direct %s", Address);
  493.       strtok (Temp, " ");
  494.       Processor->Change ();
  495.  
  496.       sprintf (Temp, "Change Crash Direct %s", Address);
  497.       strtok (Temp, " ");
  498.       Processor->Change ();
  499.  
  500.       sprintf (Temp, "Change Hold Direct %s", Address);
  501.       strtok (Temp, " ");
  502.       Processor->Change ();
  503.  
  504.       delete Processor;
  505.    }
  506.  
  507.    Refresh ();
  508.    DoRebuild = TRUE;
  509. }
  510.  
  511. VOID CDetailsDlg::ChangeToNormal (VOID)
  512. {
  513.    class TMailProcessor *Processor;
  514.  
  515.    if ((Processor = new TMailProcessor) != NULL) {
  516.       Processor->Cfg = Cfg;
  517.       Processor->Log = NULL;
  518.       Processor->Output = NULL;
  519.       Processor->Status = NULL;
  520.       strcpy (Processor->Outbound, Cfg->Outbound);
  521.       if (Processor->Outbound[strlen (Processor->Outbound) - 1] == '\\' || Processor->Outbound[strlen (Processor->Outbound) - 1] == '/')
  522.          Processor->Outbound[strlen (Processor->Outbound) - 1] = '\0';
  523.  
  524.       sprintf (Temp, "Change Hold Normal %s", Address);
  525.       strtok (Temp, " ");
  526.       Processor->Change ();
  527.  
  528.       sprintf (Temp, "Change Crash Normal %s", Address);
  529.       strtok (Temp, " ");
  530.       Processor->Change ();
  531.  
  532.       sprintf (Temp, "Change Direct Normal %s", Address);
  533.       strtok (Temp, " ");
  534.       Processor->Change ();
  535.  
  536.       delete Processor;
  537.    }
  538.  
  539.    Refresh ();
  540.    DoRebuild = TRUE;
  541. }
  542.  
  543. #endif
  544.  
  545. // ---------------------------------------------------------------------------
  546. // Windowed log file display
  547. // ---------------------------------------------------------------------------
  548.  
  549. TPMLog::TPMLog (HWND hwnd)
  550. {
  551.    hwndList = hwnd;
  552.    First = TRUE;
  553. }
  554.  
  555. TPMLog::~TPMLog (void)
  556. {
  557. }
  558.  
  559. VOID TPMLog::Write (PSZ pszFormat, ...)
  560. {
  561.    va_list arglist;
  562.    time_t t;
  563.    struct tm *timep;
  564.    struct stat statbuf;
  565.  
  566.    if (First == TRUE && fp != NULL) {
  567.       if (Cfg->ReloadLog == TRUE) {
  568.          fstat (fileno (fp), &statbuf);
  569.          if (statbuf.st_size >= 5192L) {
  570.             fseek (fp, statbuf.st_size - 5192L, SEEK_SET);
  571.             fgets (Temp, sizeof (Temp) - 1, fp);
  572.          }
  573.          else
  574.             fseek (fp, 0L, SEEK_SET);
  575.  
  576.          while (fgets (Temp, sizeof (Temp) - 1, fp) != NULL) {
  577.             Temp[strlen (Temp) - 1] = '\0';
  578.             if (Temp[0] != '\0') {
  579.                strcpy (&Temp[14], &Temp[17]);
  580.                strcpy (&Temp[2], &Temp[9]);
  581.                strcpy (&Temp[8], &Temp[13]);
  582. #if defined(__OS2__)
  583.                WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDLOGITEM), MPFROMP (Temp));
  584. #elif defined(__NT__)
  585.                SendMessage (hwndList, WM_USER, WMU_ADDLOGITEM, (LPARAM)Temp);
  586. #endif
  587.             }
  588.          }
  589.       }
  590.       First = FALSE;
  591.    }
  592.  
  593.    va_start (arglist, pszFormat);
  594.    vsprintf (Buffer, pszFormat, arglist);
  595.    va_end (arglist);
  596.  
  597.    t = time (NULL);
  598.    timep = localtime (&t);
  599.    sprintf (Temp, "%c %02d %3s %02d:%02d:%02d %s %s", Buffer[0], timep->tm_mday, Months[timep->tm_mon], timep->tm_hour, timep->tm_min, timep->tm_sec, "LORA", &Buffer[1]);
  600.  
  601.    if (fp != NULL) {
  602.       fprintf (fp, "%s\n", Temp);
  603. #if !defined(__NT__)
  604.       fflush (fp);
  605. #endif
  606.    }
  607.  
  608.    if (hwndList != NULL) {
  609.       sprintf (Temp, "%c %02d:%02d %s", Buffer[0], timep->tm_hour, timep->tm_min, &Buffer[1]);
  610. #if defined(__OS2__)
  611.       WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDLOGITEM), MPFROMP (Temp));
  612. #elif defined(__NT__)
  613.       SendMessage (hwndList, WM_USER, WMU_ADDLOGITEM, (LPARAM)Temp);
  614. #endif
  615.    }
  616. }
  617.  
  618. // ----------------------------------------------------------------------------
  619. // Status window manager
  620. // ----------------------------------------------------------------------------
  621.  
  622. TPMStatus::TPMStatus (HWND hwnd)
  623. {
  624.    hwndList = hwnd;
  625. }
  626.  
  627. TPMStatus::~TPMStatus (void)
  628. {
  629. }
  630.  
  631. VOID TPMStatus::Clear (VOID)
  632. {
  633. #if defined(__OS2__)
  634.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 0), MPFROMP (""));
  635.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 1), MPFROMP (""));
  636. #elif defined(__NT__)
  637.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE0, (LPARAM)"");
  638.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE1, (LPARAM)"");
  639. #endif
  640. }
  641.  
  642. VOID TPMStatus::SetLine (USHORT line, PSZ text, ...)
  643. {
  644.    va_list arglist;
  645.    CHAR Temp[128];
  646.  
  647.    va_start (arglist, text);
  648.    vsprintf (Temp, text, arglist);
  649.    va_end (arglist);
  650.  
  651. #if defined(__OS2__)
  652.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, line), MPFROMP (Temp));
  653. #elif defined(__NT__)
  654.    SendMessage (hwndList, WM_USER, (WPARAM)(WMU_SETSTATUSLINE0 + line), (LPARAM)Temp);
  655. #endif
  656. }
  657.  
  658. // ----------------------------------------------------------------------------
  659. // File transfer progress indicator
  660. // ----------------------------------------------------------------------------
  661.  
  662. class TPMProgress : public TProgress
  663. {
  664. public:
  665.    TPMProgress (HWND hwnd);
  666.    ~TPMProgress (void);
  667.  
  668.    VOID   Begin (VOID);
  669.    VOID   End (VOID);
  670.    VOID   Update (VOID);
  671.  
  672. private:
  673.    HWND   hwndList;
  674. };
  675.  
  676. TPMProgress::TPMProgress (HWND hwnd)
  677. {
  678.    hwndList = hwnd;
  679. }
  680.  
  681. TPMProgress::~TPMProgress (void)
  682. {
  683. }
  684.  
  685. VOID TPMProgress::Begin (VOID)
  686. {
  687.    CHAR Temp[128];
  688.  
  689.    if (Type == FILE_RECEIVING)
  690.       sprintf (Temp, "Receiving %s; %lu bytes", RxFileName, RxSize);
  691.    else if (Type == FILE_SENDING)
  692.       sprintf (Temp, "Sending %s; %lu bytes", TxFileName, TxSize);
  693. #if defined(__OS2__)
  694.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 0), MPFROMP (Temp));
  695. #elif defined(__NT__)
  696.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE0, (LPARAM)Temp);
  697. #endif
  698. }
  699.  
  700. VOID TPMProgress::Update (VOID)
  701. {
  702.    CHAR Temp[128];
  703.  
  704.    if (Type == FILE_RECEIVING)
  705.       sprintf (Temp, "%8lu %5u", RxPosition, RxBlockSize);
  706.    else if (Type == FILE_SENDING)
  707.       sprintf (Temp, "%8lu %5u", TxPosition, TxBlockSize);
  708. #if defined(__OS2__)
  709.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 1), MPFROMP (Temp));
  710. #elif defined(__NT__)
  711.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE1, (LPARAM)Temp);
  712. #endif
  713. }
  714.  
  715. VOID TPMProgress::End (VOID)
  716. {
  717.    CHAR Temp[128];
  718.  
  719.    sprintf (Temp, "");
  720. #if defined(__OS2__)
  721.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 0), MPFROMP (Temp));
  722.    WinSendMsg (hwndList, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 1), MPFROMP (Temp));
  723. #elif defined(__NT__)
  724.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE0, (LPARAM)Temp);
  725.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_SETSTATUSLINE1, (LPARAM)Temp);
  726. #endif
  727. }
  728.  
  729. // ----------------------------------------------------------------------------
  730. // Mailer status
  731. // ----------------------------------------------------------------------------
  732.  
  733. #define CENTER_LINE     70
  734.  
  735. class TPMMailStatus : public TMailerStatus
  736. {
  737. public:
  738. #if defined(__OS2__) || defined(__NT__)
  739.    TPMMailStatus (HWND hwnd);
  740. #elif defined(__DOS__)
  741.    TPMMailStatus (void);
  742. #endif
  743.    ~TPMMailStatus (void);
  744.  
  745.    VOID   Update (VOID);
  746.  
  747. private:
  748. #if defined(__OS2__) || defined(__NT__)
  749.    HWND   hwndList;
  750. #endif
  751.    CHAR   Temp[256];
  752. };
  753.  
  754. #if defined(__OS2__) || defined(__NT__)
  755. TPMMailStatus::TPMMailStatus (HWND hwnd)
  756. {
  757.    hwndList = hwnd;
  758. }
  759. #elif defined(__DOS__)
  760. TPMMailStatus::TPMMailStatus (void)
  761. {
  762. }
  763. #endif
  764.  
  765. TPMMailStatus::~TPMMailStatus (void)
  766. {
  767. }
  768.  
  769. VOID TPMMailStatus::Update (VOID)
  770. {
  771.    CHAR Line[128], Num[16];
  772.  
  773. #if defined(__OS2__)
  774.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_CLEAROUTBOUND), 0L);
  775. #elif defined(__NT__)
  776.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_CLEAROUTBOUND, 0L);
  777. #elif defined(__DOS__)
  778.    fill_ (13, 1, 20, 78, ' ', LGREY|_BLACK);
  779. #endif
  780.  
  781.    sprintf (Temp, "%s, %s, %s, %s", Address, SysopName, SystemName, Location);
  782.    if (strlen (Temp) > CENTER_LINE)
  783.       Temp[CENTER_LINE] = '\0';
  784.    memset (Line, ' ', sizeof (Line));
  785.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  786. #if defined(__OS2__)
  787.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  788. #elif defined(__NT__)
  789.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  790. #elif defined(__DOS__)
  791.    prints (13, 4, LGREY|_BLACK, Line);
  792. #endif
  793.  
  794.    sprintf (Temp, "Connected at %lu baud with %s", Speed, Program);
  795.    if (strlen (Temp) > CENTER_LINE)
  796.       Temp[CENTER_LINE] = '\0';
  797.    memset (Line, ' ', sizeof (Line));
  798.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  799. #if defined(__OS2__)
  800.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  801. #elif defined(__NT__)
  802.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  803. #elif defined(__DOS__)
  804.    prints (14, 4, LGREY|_BLACK, Line);
  805. #endif
  806.  
  807.    if (Akas[0] == '\0')
  808.       strcpy (Temp, "AKAs: No aka presented");
  809.    else
  810.       sprintf (Temp, "AKAs: %s", Akas);
  811.    if (strlen (Temp) > CENTER_LINE)
  812.       Temp[CENTER_LINE] = '\0';
  813.    memset (Line, ' ', sizeof (Line));
  814.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  815. #if defined(__OS2__)
  816.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  817. #elif defined(__NT__)
  818.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  819. #elif defined(__DOS__)
  820.    prints (15, 4, LGREY|_BLACK, Line);
  821. #endif
  822.  
  823. #if defined(__OS2__) || defined(__DOS__)
  824.    strcpy (Temp, " ┌────MailPKT───────Data─────┐     ┌────MailPKT───────Data─────┐ ");
  825. #elif defined(__NT__)
  826.    strcpy (Temp, " +----MailPKT-------Data-----+     +----MailPKT-------Data-----+ ");
  827. #endif
  828.    memset (Line, ' ', sizeof (Line));
  829.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  830. #if defined(__OS2__)
  831.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  832. #elif defined(__NT__)
  833.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  834. #elif defined(__DOS__)
  835.    prints (17, 4, LCYAN|_BLACK, Line);
  836. #endif
  837.  
  838. #if defined(__OS2__) || defined(__DOS__)
  839.    strcpy (Temp, "·······························   ·······························");
  840. #elif defined(__NT__)
  841.    strcpy (Temp, "╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖   ╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖");
  842. #endif
  843.    if (InPktFiles == 0xFFFFU)
  844.       strcpy (Num, "N/A");
  845.    else
  846.       sprintf (Num, "%u", InPktFiles);
  847.    memcpy (&Temp[11 - strlen (Num) + 1], Num, strlen (Num));
  848.    if (InDataFiles == 0xFFFFU)
  849.       strcpy (Num, "N/A");
  850.    else
  851.       sprintf (Num, "%u", InDataFiles);
  852.    memcpy (&Temp[22 - strlen (Num) + 1], Num, strlen (Num));
  853.    if (OutPktFiles == 0xFFFFU)
  854.       strcpy (Num, "N/A");
  855.    else
  856.       sprintf (Num, "%u", OutPktFiles);
  857.    memcpy (&Temp[45 - strlen (Num) + 1], Num, strlen (Num));
  858.    if (OutDataFiles == 0xFFFFU)
  859.       strcpy (Num, "N/A");
  860.    else
  861.       sprintf (Num, "%u", OutDataFiles);
  862.    memcpy (&Temp[56 - strlen (Num) + 1], Num, strlen (Num));
  863.    memset (Line, ' ', sizeof (Line));
  864.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  865. #if defined(__OS2__)
  866.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  867. #elif defined(__NT__)
  868.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  869. #elif defined(__DOS__)
  870.    prints (18, 4, LCYAN|_BLACK, Line);
  871. #endif
  872.  
  873. #if defined(__OS2__) || defined(__DOS__)
  874.    strcpy (Temp, "·······························   ·······························");
  875. #elif defined(__NT__)
  876.    strcpy (Temp, "╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖   ╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖╖");
  877. #endif
  878.    if (InPktFiles == 0xFFFFU)
  879.       strcpy (Num, "N/A");
  880.    else
  881.       sprintf (Num, "%lu", InPktBytes);
  882.    memcpy (&Temp[11 - strlen (Num) + 1], Num, strlen (Num));
  883.    if (InDataFiles == 0xFFFFU)
  884.       strcpy (Num, "N/A");
  885.    else
  886.       sprintf (Num, "%lu", InDataBytes);
  887.    memcpy (&Temp[22 - strlen (Num) + 1], Num, strlen (Num));
  888.    if (OutPktFiles == 0xFFFFU)
  889.       strcpy (Num, "N/A");
  890.    else
  891.       sprintf (Num, "%lu", OutPktBytes);
  892.    memcpy (&Temp[45 - strlen (Num) + 1], Num, strlen (Num));
  893.    if (OutDataFiles == 0xFFFFU)
  894.       strcpy (Num, "N/A");
  895.    else
  896.       sprintf (Num, "%lu", OutDataBytes);
  897.    memcpy (&Temp[56 - strlen (Num) + 1], Num, strlen (Num));
  898.    memset (Line, ' ', sizeof (Line));
  899.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  900. #if defined(__OS2__)
  901.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  902. #elif defined(__NT__)
  903.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  904. #elif defined(__DOS__)
  905.    prints (19, 4, LCYAN|_BLACK, Line);
  906. #endif
  907.  
  908. #if defined(__OS2__) || defined(__DOS__)
  909.    strcpy (Temp, " └──────INBOUND TRAFFIC──────┘     └─────OUTBOUND TRAFFIC──────┘ ");
  910. #elif defined(__NT__)
  911.    strcpy (Temp, " +------INBOUND TRAFFIC------+     +-----OUTBOUND TRAFFIC------+ ");
  912. #endif
  913.    memset (Line, ' ', sizeof (Line));
  914.    memcpy (&Line[(CENTER_LINE - strlen (Temp)) / 2], Temp, strlen (Temp) + 1);
  915. #if defined(__OS2__)
  916.    WinSendMsg (hwndList, WM_USER, MPFROMSHORT (WMU_ADDOUTBOUNDLINE), MPFROMP (Line));
  917. #elif defined(__NT__)
  918.    SendMessage (hwndList, WM_USER, (WPARAM)WMU_ADDOUTBOUNDLINE, (LPARAM)Line);
  919. #elif defined(__DOS__)
  920.    prints (20, 4, LCYAN|_BLACK, Line);
  921. #endif
  922. }
  923.  
  924. #if defined(__OS2__) || defined(__NT__)
  925.  
  926. // ----------------------------------------------------------------------
  927. // Ask a FidoNet address
  928. // ----------------------------------------------------------------------
  929.  
  930. class CAskAddressDlg : public CDialog
  931. {
  932. public:
  933.    CAskAddressDlg (HWND p_hWnd);
  934.  
  935.    CHAR   Title[128];
  936.    CHAR   String[128];
  937.  
  938.    USHORT OnInitDialog (VOID);
  939.    VOID   OnOK (VOID);
  940. };
  941.  
  942. CAskAddressDlg::CAskAddressDlg (HWND p_hWnd) : CDialog ("26", p_hWnd)
  943. {
  944. }
  945.  
  946. USHORT CAskAddressDlg::OnInitDialog (VOID)
  947. {
  948.    Center ();
  949.  
  950.    SetDlgItemText (101, "Address:");
  951.    SetWindowTitle (Title);
  952.    EM_SetTextLimit (128, sizeof (String) - 1);
  953.  
  954.    return (TRUE);
  955. }
  956.  
  957. VOID CAskAddressDlg::OnOK (VOID)
  958. {
  959.    GetDlgItemText (128, GetDlgItemTextLength (128), String);
  960.    EndDialog (TRUE);
  961. }
  962.  
  963. // ----------------------------------------------------------------------
  964. // Forced poll
  965. // ----------------------------------------------------------------------
  966.  
  967. class CPollDlg : public CDialog
  968. {
  969. public:
  970.    CPollDlg (HWND p_hWnd);
  971.  
  972.    CHAR   Address[128];
  973.  
  974.    USHORT OnInitDialog (VOID);
  975.    VOID   OnOK (VOID);
  976. };
  977.  
  978. CPollDlg::CPollDlg (HWND p_hWnd) : CDialog ("13", p_hWnd)
  979. {
  980. }
  981.  
  982. USHORT CPollDlg::OnInitDialog (VOID)
  983. {
  984.    CHAR Temp[128];
  985.    class CAskAddressDlg *Dlg;
  986.    class TNodes *Nodes;
  987.    class TAddress Addr;
  988.  
  989.    Center ();
  990.  
  991.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  992.       strcpy (Dlg->Title, "Forced poll");
  993.       if (Dlg->DoModal () == FALSE)
  994.          EndDialog (FALSE);
  995.       else {
  996.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  997.             Addr.Parse (Dlg->String);
  998.             if (Cfg->MailAddress.First () == TRUE) {
  999.                if (Addr.Zone == 0)
  1000.                   Addr.Zone = Cfg->MailAddress.Zone;
  1001.                if (Addr.Net == 0)
  1002.                   Addr.Net = Cfg->MailAddress.Net;
  1003.                Addr.Add ();
  1004.                Addr.First ();
  1005.             }
  1006.             strcpy (Address, Addr.String);
  1007.             if (Nodes->Read (Addr) == TRUE) {
  1008.                SetDlgItemText (102, Nodes->SystemName);
  1009.                SetDlgItemText (103, Nodes->Address);
  1010.                SetDlgItemText (109, Nodes->Location);
  1011.                SetDlgItemText (104, Nodes->SysopName);
  1012.                BM_SetCheck (105, TRUE);
  1013.             }
  1014.             else {
  1015.                sprintf (Temp, "Node %s not found !", Address);
  1016.                MessageBox (Temp, "Forced poll", MB_OK);
  1017.                EndDialog (FALSE);
  1018.             }
  1019.             delete Nodes;
  1020.          }
  1021.       }
  1022.       delete Dlg;
  1023.    }
  1024.  
  1025.    return (TRUE);
  1026. }
  1027.  
  1028. VOID CPollDlg::OnOK (VOID)
  1029. {
  1030.    CHAR Flag;
  1031.  
  1032.    Flag = 'f';
  1033.    if (BM_QueryCheck (105) == TRUE)
  1034.       Flag = 'i';
  1035.    else if (BM_QueryCheck (106) == TRUE)
  1036.       Flag = 'c';
  1037.    else if (BM_QueryCheck (107) == TRUE)
  1038.       Flag = 'd';
  1039.  
  1040.    if (Outbound != NULL) {
  1041.       Outbound->PollNode (Address, Flag);
  1042.  
  1043.       if (Log != NULL)
  1044.          Log->Write ("+Building the outbound queue");
  1045.       Outbound->BuildQueue (Cfg->Outbound);
  1046.       unlink ("rescan.now");
  1047.       if (Log != NULL)
  1048.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  1049.  
  1050. #if defined(__OS2__)
  1051.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  1052. #elif defined(__NT__)
  1053.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  1054. #endif
  1055.    }
  1056.  
  1057.    EndDialog (TRUE);
  1058. }
  1059.  
  1060. // ----------------------------------------------------------------------
  1061. // File request
  1062. // ----------------------------------------------------------------------
  1063.  
  1064. class CRequestDlg : public CDialog
  1065. {
  1066. public:
  1067.    CRequestDlg (HWND p_hWnd);
  1068.  
  1069.    CHAR   Address[128];
  1070.  
  1071.    USHORT OnInitDialog (VOID);
  1072.    VOID   OnOK (VOID);
  1073. };
  1074.  
  1075. CRequestDlg::CRequestDlg (HWND p_hWnd) : CDialog ("32", p_hWnd)
  1076. {
  1077. }
  1078.  
  1079. USHORT CRequestDlg::OnInitDialog (VOID)
  1080. {
  1081.    CHAR Temp[128];
  1082.    class CAskAddressDlg *Dlg;
  1083.    class TNodes *Nodes;
  1084.    class TAddress Addr;
  1085.  
  1086.    Center ();
  1087.  
  1088.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  1089.       strcpy (Dlg->Title, "File request");
  1090.       if (Dlg->DoModal () == FALSE)
  1091.          EndDialog (FALSE);
  1092.       else {
  1093.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1094.             Addr.Parse (Dlg->String);
  1095.             if (Cfg->MailAddress.First () == TRUE) {
  1096.                if (Addr.Zone == 0)
  1097.                   Addr.Zone = Cfg->MailAddress.Zone;
  1098.                if (Addr.Net == 0)
  1099.                   Addr.Net = Cfg->MailAddress.Net;
  1100.                Addr.Add ();
  1101.                Addr.First ();
  1102.             }
  1103.             strcpy (Address, Addr.String);
  1104.             if (Nodes->Read (Addr) == TRUE) {
  1105.                SetDlgItemText (102, Nodes->SystemName);
  1106.                SetDlgItemText (103, Nodes->Address);
  1107.                SetDlgItemText (109, Nodes->Location);
  1108.                SetDlgItemText (104, Nodes->SysopName);
  1109.                BM_SetCheck (105, TRUE);
  1110.             }
  1111.             else {
  1112.                sprintf (Temp, "Node %s not found !", Address);
  1113.                MessageBox (Temp, "File request", MB_OK);
  1114.                EndDialog (FALSE);
  1115.             }
  1116.             delete Nodes;
  1117.          }
  1118.       }
  1119.       delete Dlg;
  1120.    }
  1121.  
  1122.    return (TRUE);
  1123. }
  1124.  
  1125. VOID CRequestDlg::OnOK (VOID)
  1126. {
  1127.    FILE *fp;
  1128.    CHAR File[128], Temp[256], *p, Flag;
  1129.    class TAddress Addr;
  1130.  
  1131.    Flag = 'f';
  1132.    if (BM_QueryCheck (105) == TRUE)
  1133.       Flag = 'i';
  1134.    else if (BM_QueryCheck (106) == TRUE)
  1135.       Flag = 'c';
  1136.    else if (BM_QueryCheck (107) == TRUE)
  1137.       Flag = 'd';
  1138.  
  1139.    Addr.Parse (Address);
  1140.  
  1141.    Cfg->MailAddress.First ();
  1142.    strcpy (Temp, Cfg->Outbound);
  1143.    Temp[strlen (Temp) - 1] = '\0';
  1144.  
  1145.    if (Cfg->MailAddress.Zone != Addr.Zone) {
  1146.       sprintf (File, "%s.%03x", Temp, Addr.Zone);
  1147.       mkdir (File);
  1148.       if (Addr.Point != 0) {
  1149.          sprintf (File, "%s.%03x\\%04x%04x.pnt", Temp, Addr.Zone, Addr.Net, Addr.Node);
  1150.          mkdir (File);
  1151.          sprintf (File, "%s.%03x\\%04x%04x.pnt\\%08x.req", Temp, Addr.Zone, Addr.Net, Addr.Node, Addr.Point);
  1152.       }
  1153.       else
  1154.          sprintf (File, "%s.%03x\\%04x%04x.req", Temp, Addr.Zone, Addr.Net, Addr.Node);
  1155.    }
  1156.    else {
  1157.       if (Addr.Point != 0) {
  1158.          sprintf (File, "%s\\%04x%04x.pnt", Temp, Addr.Net, Addr.Node);
  1159.          mkdir (File);
  1160.          sprintf (File, "%s\\%04x%04x.pnt\\%08x.req", Temp, Addr.Net, Addr.Node, Addr.Point);
  1161.       }
  1162.       else
  1163.          sprintf (File, "%s\\%04x%04x.req", Temp, Addr.Net, Addr.Node);
  1164.    }
  1165.  
  1166.    if ((fp = fopen (File, "at")) != NULL) {
  1167.       GetDlgItemText (112, GetDlgItemTextLength (112), Temp);
  1168.       if ((p = strtok (Temp, " ")) != NULL)
  1169.          do {
  1170.             fprintf (fp, "%s\n", p);
  1171.          } while ((p = strtok (NULL, " ")) != NULL);
  1172.       fclose (fp);
  1173.    }
  1174.  
  1175.    if (Outbound != NULL) {
  1176.       Outbound->PollNode (Address, Flag);
  1177.  
  1178.       if (Log != NULL)
  1179.          Log->Write ("+Building the outbound queue");
  1180.       Outbound->BuildQueue (Cfg->Outbound);
  1181.       unlink ("rescan.now");
  1182.       if (Log != NULL)
  1183.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  1184.  
  1185. #if defined(__OS2__)
  1186.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  1187. #elif defined(__NT__)
  1188.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  1189. #endif
  1190.    }
  1191.  
  1192.    EndDialog (TRUE);
  1193. }
  1194.  
  1195. // ----------------------------------------------------------------------
  1196. // New ECHOmaill Link
  1197. // ----------------------------------------------------------------------
  1198.  
  1199. class CNewEchoLinkDlg : public CDialog
  1200. {
  1201. public:
  1202.    CNewEchoLinkDlg (HWND p_hWnd);
  1203.  
  1204.    CHAR   Address[128];
  1205.  
  1206.    USHORT OnInitDialog (VOID);
  1207.    VOID   OnOK (VOID);
  1208.  
  1209. private:
  1210.    CHAR   Command[512];
  1211. };
  1212.  
  1213. CNewEchoLinkDlg::CNewEchoLinkDlg (HWND p_hWnd) : CDialog ("52", p_hWnd)
  1214. {
  1215. }
  1216.  
  1217. USHORT CNewEchoLinkDlg::OnInitDialog (VOID)
  1218. {
  1219.    CHAR Temp[128];
  1220.    class CAskAddressDlg *Dlg;
  1221.    class TNodes *Nodes;
  1222.    class TAddress Addr;
  1223.  
  1224.    Center ();
  1225.  
  1226.    EM_SetTextLimit (112, sizeof (Command) - 1);
  1227.  
  1228.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  1229.       strcpy (Dlg->Title, "New Echomail Link");
  1230.       if (Dlg->DoModal () == FALSE)
  1231.          EndDialog (FALSE);
  1232.       else {
  1233.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1234.             Addr.Parse (Dlg->String);
  1235.             if (Cfg->MailAddress.First () == TRUE) {
  1236.                if (Addr.Zone == 0)
  1237.                   Addr.Zone = Cfg->MailAddress.Zone;
  1238.                if (Addr.Net == 0)
  1239.                   Addr.Net = Cfg->MailAddress.Net;
  1240.                Addr.Add ();
  1241.                Addr.First ();
  1242.             }
  1243.             strcpy (Address, Addr.String);
  1244.             if (Nodes->Read (Addr) == TRUE) {
  1245.                SetDlgItemText (102, Nodes->SystemName);
  1246.                SetDlgItemText (103, Nodes->Address);
  1247.                SetDlgItemText (109, Nodes->Location);
  1248.                SetDlgItemText (104, Nodes->SysopName);
  1249.                strcpy (Address, Nodes->Address);
  1250.             }
  1251.             else {
  1252.                sprintf (Temp, "Node %s not found !", Address);
  1253.                MessageBox (Temp, "New Echomail Link", MB_OK);
  1254.                EndDialog (FALSE);
  1255.             }
  1256.             delete Nodes;
  1257.          }
  1258.       }
  1259.       delete Dlg;
  1260.    }
  1261.  
  1262.    return (TRUE);
  1263. }
  1264.  
  1265. VOID CNewEchoLinkDlg::OnOK (VOID)
  1266. {
  1267.    CHAR *p, *t;
  1268.    class TAddress Addr;
  1269.    class TAreaManager *AreaMgr;
  1270.  
  1271.    if ((AreaMgr = new TAreaManager) != NULL) {
  1272.       AreaMgr->Cfg = Cfg;
  1273.       AreaMgr->Log = Log;
  1274.  
  1275.       GetDlgItemText (112, GetDlgItemTextLength (112), Command);
  1276.       t = Command;
  1277.  
  1278.       while ((p = strtok (t, " ")) != NULL) {
  1279.          t = strtok (NULL, "");
  1280.          if (!stricmp (p, "%-ALL"))
  1281.             AreaMgr->RemoveAll (Address);
  1282.          else if (*p == '-')
  1283.             AreaMgr->RemoveArea (Address, ++p);
  1284.          else {
  1285.             if (*p == '+')
  1286.                p++;
  1287.             AreaMgr->AddArea (Address, p);
  1288.          }
  1289.       }
  1290.  
  1291.       delete AreaMgr;
  1292.    }
  1293.  
  1294.    EndDialog (TRUE);
  1295. }
  1296.  
  1297. // ----------------------------------------------------------------------
  1298. // Request ECHOlink
  1299. // ----------------------------------------------------------------------
  1300.  
  1301. class CRequestEchoLinkDlg : public CDialog
  1302. {
  1303. public:
  1304.    CRequestEchoLinkDlg (HWND p_hWnd);
  1305.  
  1306.    CHAR   Address[128];
  1307.  
  1308.    USHORT OnInitDialog (VOID);
  1309.    VOID   OnOK (VOID);
  1310.  
  1311. private:
  1312.    CHAR   Command[512];
  1313. };
  1314.  
  1315. CRequestEchoLinkDlg::CRequestEchoLinkDlg (HWND p_hWnd) : CDialog ("52", p_hWnd)
  1316. {
  1317. }
  1318.  
  1319. USHORT CRequestEchoLinkDlg::OnInitDialog (VOID)
  1320. {
  1321.    CHAR Temp[128];
  1322.    class CAskAddressDlg *Dlg;
  1323.    class TNodes *Nodes;
  1324.    class TAddress Addr;
  1325.  
  1326.    Center ();
  1327.  
  1328.    EM_SetTextLimit (112, sizeof (Command) - 1);
  1329.  
  1330.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  1331.       strcpy (Dlg->Title, "Request Echomail Link");
  1332.       if (Dlg->DoModal () == FALSE)
  1333.          EndDialog (FALSE);
  1334.       else {
  1335.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1336.             Addr.Parse (Dlg->String);
  1337.             if (Cfg->MailAddress.First () == TRUE) {
  1338.                if (Addr.Zone == 0)
  1339.                   Addr.Zone = Cfg->MailAddress.Zone;
  1340.                if (Addr.Net == 0)
  1341.                   Addr.Net = Cfg->MailAddress.Net;
  1342.                Addr.Add ();
  1343.                Addr.First ();
  1344.             }
  1345.             strcpy (Address, Addr.String);
  1346.             if (Nodes->Read (Addr) == TRUE) {
  1347.                SetDlgItemText (102, Nodes->SystemName);
  1348.                SetDlgItemText (103, Nodes->Address);
  1349.                SetDlgItemText (109, Nodes->Location);
  1350.                SetDlgItemText (104, Nodes->SysopName);
  1351.                strcpy (Address, Nodes->Address);
  1352.             }
  1353.             else {
  1354.                sprintf (Temp, "Node %s not found !", Address);
  1355.                MessageBox (Temp, "Request Echomail Link", MB_OK);
  1356.                EndDialog (FALSE);
  1357.             }
  1358.             delete Nodes;
  1359.          }
  1360.       }
  1361.       delete Dlg;
  1362.    }
  1363.  
  1364.    return (TRUE);
  1365. }
  1366.  
  1367. VOID CRequestEchoLinkDlg::OnOK (VOID)
  1368. {
  1369.    CHAR *p;
  1370.    struct dosdate_t d_date;
  1371.    struct dostime_t d_time;
  1372.    class TAddress Addr;
  1373.    class TNodes *Nodes;
  1374.    class TMsgBase *Msg;
  1375.  
  1376.    if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1377.       Nodes->Read (Address);
  1378.       switch (Cfg->NetMailStorage) {
  1379.          case ST_JAM:
  1380.             Msg = new JAM (Cfg->NetMailPath);
  1381.             break;
  1382.          case ST_SQUISH:
  1383.             Msg = new SQUISH (Cfg->NetMailPath);
  1384.             break;
  1385.          case ST_FIDO:
  1386.             Msg = new FIDOSDM (Cfg->NetMailPath);
  1387.             break;
  1388.          case ST_ADEPT:
  1389.             Msg = new ADEPT (Cfg->NetMailPath);
  1390.             break;
  1391.          case ST_HUDSON:
  1392.             Msg = new HUDSON (Cfg->HudsonPath, (UCHAR)Cfg->NetMailBoard);
  1393.             break;
  1394.          default:
  1395.             Msg = NULL;
  1396.             break;
  1397.       }
  1398.       if (Msg != NULL) {
  1399.          Msg->New ();
  1400.          Cfg->MailAddress.First ();
  1401.  
  1402.          strcpy (Msg->From, Cfg->SysopName);
  1403.          strcpy (Msg->FromAddress, Cfg->MailAddress.String);
  1404.          strcpy (Msg->To, "Areafix");
  1405.          strcpy (Msg->ToAddress, Address);
  1406.          strcpy (Msg->Subject, Nodes->AreaMgrPwd);
  1407.  
  1408.          _dos_getdate (&d_date);
  1409.          _dos_gettime (&d_time);
  1410.  
  1411.          Msg->Arrived.Day = Msg->Written.Day = d_date.day;
  1412.          Msg->Arrived.Month = Msg->Written.Month = d_date.month;
  1413.          Msg->Arrived.Year = Msg->Written.Year = (USHORT)d_date.year;
  1414.          Msg->Arrived.Hour = Msg->Written.Hour = d_time.hour;
  1415.          Msg->Arrived.Minute = Msg->Written.Minute = d_time.minute;
  1416.          Msg->Arrived.Second = Msg->Written.Second = d_time.second;
  1417.  
  1418.          GetDlgItemText (112, GetDlgItemTextLength (112), Command);
  1419.          if ((p = strtok (Command, " ")) != NULL)
  1420.             do {
  1421.                Msg->Text.Add (p);
  1422.             } while ((p = strtok (NULL, " ")) != NULL);
  1423.  
  1424.          Msg->Text.Add ("---");
  1425.          Msg->Add ();
  1426.  
  1427.          delete Msg;
  1428.       }
  1429.       delete Nodes;
  1430.    }
  1431.  
  1432.    EndDialog (TRUE);
  1433. }
  1434.  
  1435. // ----------------------------------------------------------------------
  1436. // Rescan ECHOmail
  1437. // ----------------------------------------------------------------------
  1438.  
  1439. class CRescanDlg : public CDialog
  1440. {
  1441. public:
  1442.    CRescanDlg (HWND p_hWnd);
  1443.  
  1444.    CHAR   Address[128];
  1445.  
  1446.    USHORT OnInitDialog (VOID);
  1447.    VOID   OnOK (VOID);
  1448.  
  1449. private:
  1450.    CHAR   Command[512];
  1451. };
  1452.  
  1453. CRescanDlg::CRescanDlg (HWND p_hWnd) : CDialog ("52", p_hWnd)
  1454. {
  1455. }
  1456.  
  1457. USHORT CRescanDlg::OnInitDialog (VOID)
  1458. {
  1459.    CHAR Temp[128];
  1460.    class CAskAddressDlg *Dlg;
  1461.    class TNodes *Nodes;
  1462.    class TAddress Addr;
  1463.  
  1464.    SetWindowTitle ("Rescan Area(s)");
  1465.    Center ();
  1466.  
  1467.    EM_SetTextLimit (112, sizeof (Command) - 1);
  1468.  
  1469.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  1470.       strcpy (Dlg->Title, "Rescan EchoMail");
  1471.       if (Dlg->DoModal () == FALSE)
  1472.          EndDialog (FALSE);
  1473.       else {
  1474.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1475.             Addr.Parse (Dlg->String);
  1476.             if (Cfg->MailAddress.First () == TRUE) {
  1477.                if (Addr.Zone == 0)
  1478.                   Addr.Zone = Cfg->MailAddress.Zone;
  1479.                if (Addr.Net == 0)
  1480.                   Addr.Net = Cfg->MailAddress.Net;
  1481.                Addr.Add ();
  1482.                Addr.First ();
  1483.             }
  1484.             strcpy (Address, Addr.String);
  1485.             if (Nodes->Read (Addr) == TRUE) {
  1486.                SetDlgItemText (102, Nodes->SystemName);
  1487.                SetDlgItemText (103, Nodes->Address);
  1488.                SetDlgItemText (109, Nodes->Location);
  1489.                SetDlgItemText (104, Nodes->SysopName);
  1490.                strcpy (Address, Nodes->Address);
  1491.             }
  1492.             else {
  1493.                sprintf (Temp, "Node %s not found !", Address);
  1494.                MessageBox (Temp, "File request", MB_OK);
  1495.                EndDialog (FALSE);
  1496.             }
  1497.             delete Nodes;
  1498.          }
  1499.       }
  1500.       delete Dlg;
  1501.    }
  1502.  
  1503.    return (TRUE);
  1504. }
  1505.  
  1506. VOID CRescanDlg::OnOK (VOID)
  1507. {
  1508.    CHAR *p, *t;
  1509.    class TAddress Addr;
  1510.    class TAreaManager *AreaMgr;
  1511.  
  1512.    if ((AreaMgr = new TAreaManager) != NULL) {
  1513.       AreaMgr->Cfg = Cfg;
  1514.       AreaMgr->Log = Log;
  1515.  
  1516.       GetDlgItemText (112, GetDlgItemTextLength (112), Command);
  1517.       t = Command;
  1518.  
  1519.       while ((p = strtok (t, " ")) != NULL) {
  1520.          t = strtok (NULL, "");
  1521.          AreaMgr->Rescan (p, Address);
  1522.       }
  1523.  
  1524.       delete AreaMgr;
  1525.    }
  1526.  
  1527.    EndDialog (TRUE);
  1528. }
  1529.  
  1530. // ----------------------------------------------------------------------
  1531. // File attach
  1532. // ----------------------------------------------------------------------
  1533.  
  1534. class CAttachDlg : public CDialog
  1535. {
  1536. public:
  1537.    CAttachDlg (HWND p_hWnd);
  1538.  
  1539.    CHAR   Address[128];
  1540.  
  1541.    USHORT OnInitDialog (VOID);
  1542.    VOID   OnOK (VOID);
  1543.  
  1544. private:
  1545.    CHAR   Temp[4096];
  1546.    DECLARE_MESSAGE_MAP ()
  1547.  
  1548.    VOID   Browse (VOID);
  1549. };
  1550.  
  1551. BEGIN_MESSAGE_MAP (CAttachDlg, CDialog)
  1552.    ON_COMMAND (113, Browse)
  1553. END_MESSAGE_MAP ()
  1554.  
  1555. CAttachDlg::CAttachDlg (HWND p_hWnd) : CDialog ("49", p_hWnd)
  1556. {
  1557. }
  1558.  
  1559. USHORT CAttachDlg::OnInitDialog (VOID)
  1560. {
  1561.    class CAskAddressDlg *Dlg;
  1562.    class TNodes *Nodes;
  1563.    class TAddress Addr;
  1564.  
  1565.    Center ();
  1566.  
  1567.    EM_SetTextLimit (112, sizeof (Temp) - 1);
  1568.  
  1569.    if ((Dlg = new CAskAddressDlg (m_hWnd)) != NULL) {
  1570.       strcpy (Dlg->Title, "File attach");
  1571.       if (Dlg->DoModal () == FALSE)
  1572.          EndDialog (FALSE);
  1573.       else {
  1574.          if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  1575.             Addr.Parse (Dlg->String);
  1576.             if (Cfg->MailAddress.First () == TRUE) {
  1577.                if (Addr.Zone == 0)
  1578.                   Addr.Zone = Cfg->MailAddress.Zone;
  1579.                if (Addr.Net == 0)
  1580.                   Addr.Net = Cfg->MailAddress.Net;
  1581.                Addr.Add ();
  1582.                Addr.First ();
  1583.             }
  1584.             strcpy (Address, Addr.String);
  1585.             if (Nodes->Read (Addr) == TRUE) {
  1586.                SetDlgItemText (102, Nodes->SystemName);
  1587.                SetDlgItemText (103, Nodes->Address);
  1588.                SetDlgItemText (109, Nodes->Location);
  1589.                SetDlgItemText (104, Nodes->SysopName);
  1590.                BM_SetCheck (105, TRUE);
  1591.             }
  1592.             else {
  1593.                sprintf (Temp, "Node %s not found !", Address);
  1594.                MessageBox (Temp, "File attach", MB_OK);
  1595.                EndDialog (FALSE);
  1596.             }
  1597.             delete Nodes;
  1598.          }
  1599.       }
  1600.       delete Dlg;
  1601.    }
  1602.  
  1603.    return (TRUE);
  1604. }
  1605.  
  1606. VOID CAttachDlg::Browse (VOID)
  1607. {
  1608. #if defined(__OS2__)
  1609.    ULONG i;
  1610.    FILEDLG fild;
  1611.  
  1612.    Temp[0] = '\0';
  1613.  
  1614.    memset (&fild, 0, sizeof (FILEDLG));
  1615.    fild.cbSize = sizeof (FILEDLG);
  1616.    fild.fl = FDS_CENTER|FDS_OPEN_DIALOG|FDS_MULTIPLESEL;
  1617.    fild.pszTitle = "Attach files";
  1618.    sprintf (fild.szFullFile, "*.*");
  1619.  
  1620.    WinFileDlg (HWND_DESKTOP, m_hWnd, &fild);
  1621.    if (fild.lReturn == DID_OK) {
  1622.       if (fild.papszFQFilename != NULL) {
  1623.          for (i = 0; i < fild.ulFQFCount; i++) {
  1624.             if (i != 0)
  1625.                strcat (Temp, " ");
  1626.             strcat (Temp, fild.papszFQFilename[i][0]);
  1627.          }
  1628.       }
  1629.       else
  1630.          strcpy (Temp, fild.szFullFile);
  1631.    }
  1632.    if (fild.papszFQFilename != NULL)
  1633.       WinFreeFileDlgList (fild.papszFQFilename);
  1634.    SetDlgItemText (112, Temp);
  1635.  
  1636. #elif defined(__NT__)
  1637.    CHAR Path[256], File[512], *p;
  1638.    OPENFILENAME OpenFileName;
  1639.  
  1640.    File[0] = '\0';
  1641.    OpenFileName.lStructSize = sizeof (OPENFILENAME);
  1642.    OpenFileName.hwndOwner = m_hWnd;
  1643.    OpenFileName.hInstance = NULL;
  1644.    OpenFileName.lpstrFilter = "All files (*.*)\0*.*";
  1645.    OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
  1646.    OpenFileName.nMaxCustFilter = 0L;
  1647.    OpenFileName.nFilterIndex = 1L;
  1648.    OpenFileName.lpstrFile = File;
  1649.    OpenFileName.nMaxFile = sizeof (File) - 1;
  1650.    OpenFileName.lpstrFileTitle = NULL;
  1651.    OpenFileName.nMaxFileTitle = 0;
  1652.    OpenFileName.lpstrInitialDir = NULL;
  1653.    OpenFileName.lpstrTitle = "Attach Files";
  1654.    OpenFileName.nFileOffset = 0;
  1655.    OpenFileName.nFileExtension = 0;
  1656.    OpenFileName.lpstrDefExt = "";
  1657.    OpenFileName.lCustData = 0;
  1658.    OpenFileName.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_CREATEPROMPT|OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT;
  1659.  
  1660.    if (GetOpenFileName (&OpenFileName) == TRUE) {
  1661.       if ((p = strtok (File, " ")) != NULL) {
  1662.          strcpy (Path, p);
  1663.          if (Path[strlen (Path) - 1] != '\\')
  1664.             strcat (Path, "\\");
  1665.          Temp[0] = '\0';
  1666.          while ((p = strtok (NULL, " ")) != NULL) {
  1667.             if (Temp[0] != '\0')
  1668.                strcat (Temp, " ");
  1669.             strcat (Temp, Path);
  1670.             strcat (Temp, p);
  1671.          }
  1672.       }
  1673.       SetDlgItemText (112, Temp);
  1674.    }
  1675. #endif
  1676. }
  1677.  
  1678. VOID CAttachDlg::OnOK (VOID)
  1679. {
  1680.    FILE *fp;
  1681.    CHAR File[128], *p, Flag;
  1682.    class TAddress Addr;
  1683.  
  1684.    Flag = 'f';
  1685.    if (BM_QueryCheck (105) == TRUE)
  1686.       Flag = 'h';
  1687.    else if (BM_QueryCheck (106) == TRUE)
  1688.       Flag = 'c';
  1689.    else if (BM_QueryCheck (107) == TRUE)
  1690.       Flag = 'd';
  1691.  
  1692.    Addr.Parse (Address);
  1693.  
  1694.    Cfg->MailAddress.First ();
  1695.    strcpy (Temp, Cfg->Outbound);
  1696.    Temp[strlen (Temp) - 1] = '\0';
  1697.  
  1698.    if (Cfg->MailAddress.Zone != Addr.Zone) {
  1699.       sprintf (File, "%s.%03x", Temp, Addr.Zone);
  1700.       mkdir (File);
  1701.       if (Addr.Point != 0) {
  1702.          sprintf (File, "%s.%03x\\%04x%04x.pnt", Temp, Addr.Zone, Addr.Net, Addr.Node);
  1703.          mkdir (File);
  1704.          sprintf (File, "%s.%03x\\%04x%04x.pnt\\%08x.%clo", Temp, Addr.Zone, Addr.Net, Addr.Node, Addr.Point, Flag);
  1705.       }
  1706.       else
  1707.          sprintf (File, "%s.%03x\\%04x%04x.%clo", Temp, Addr.Zone, Addr.Net, Addr.Node, Flag);
  1708.    }
  1709.    else {
  1710.       if (Addr.Point != 0) {
  1711.          sprintf (File, "%s\\%04x%04x.pnt", Temp, Addr.Net, Addr.Node);
  1712.          mkdir (File);
  1713.          sprintf (File, "%s\\%04x%04x.pnt\\%08x.%clo", Temp, Addr.Net, Addr.Node, Addr.Point, Flag);
  1714.       }
  1715.       else
  1716.          sprintf (File, "%s\\%04x%04x.%clo", Temp, Addr.Net, Addr.Node, Flag);
  1717.    }
  1718.  
  1719.    if ((fp = fopen (File, "at")) != NULL) {
  1720.       GetDlgItemText (112, GetDlgItemTextLength (112), Temp);
  1721.       if ((p = strtok (Temp, " ")) != NULL)
  1722.          do {
  1723.             fprintf (fp, "%s\n", p);
  1724.          } while ((p = strtok (NULL, " ")) != NULL);
  1725.       fclose (fp);
  1726.    }
  1727.  
  1728.    if (Outbound != NULL) {
  1729.       if (Log != NULL)
  1730.          Log->Write ("+Building the outbound queue");
  1731.       Outbound->BuildQueue (Cfg->Outbound);
  1732.       unlink ("rescan.now");
  1733.       if (Log != NULL)
  1734.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  1735.  
  1736. #if defined(__OS2__)
  1737.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  1738. #elif defined(__NT__)
  1739.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  1740. #endif
  1741.    }
  1742.  
  1743.    EndDialog (TRUE);
  1744. }
  1745.  
  1746. #endif
  1747.  
  1748. // ----------------------------------------------------------------------------
  1749. // Threads
  1750. // ----------------------------------------------------------------------------
  1751.  
  1752. VOID NodelistThread (PVOID args)
  1753. {
  1754.    USHORT OldStatus;
  1755.  
  1756. #if defined(__OS2__)
  1757.    HAB hab;
  1758.    HMQ hmq;
  1759. #endif
  1760.  
  1761. #if defined(__OS2__)
  1762.    hab = WinInitialize (0);
  1763.    hmq = WinCreateMsgQueue (hab, 0);
  1764.    WinCancelShutdown (hmq, TRUE);
  1765. #endif
  1766.  
  1767. #if defined(__OS2__)
  1768.    DosExitCritSec ();
  1769. #endif
  1770.  
  1771.    OldStatus = Status;
  1772.    Status = UNDEFINED;
  1773.  
  1774.    CompileNodelist ((USHORT)args);
  1775.  
  1776.    Status = OldStatus;
  1777.  
  1778. #if defined(__OS2__)
  1779.    if (hmq != NULL)
  1780.       WinDestroyMsgQueue (hmq);
  1781.    WinTerminate (hab);
  1782. #endif
  1783.  
  1784.    StartTimer (hwndMainClient, 1, MODEM_DELAY);
  1785.  
  1786. #if defined(__OS2__) || defined(__NT__)
  1787.    _endthread ();
  1788. #endif
  1789. }
  1790.  
  1791. VOID MailProcessorThread (PVOID Args)
  1792. {
  1793. #if defined(__OS2__)
  1794.    HAB hab;
  1795.    HMQ hmq;
  1796. #endif
  1797.    USHORT OldStatus;
  1798.    ULONG Actions = (ULONG)Args;
  1799.    CHAR Temp[128], *tag;
  1800.    class TMailProcessor *Processor;
  1801.    class TTicProcessor *Tic;
  1802.  
  1803.    Args = Args;
  1804. #if defined(__OS2__)
  1805.    hab = WinInitialize (0);
  1806.    hmq = WinCreateMsgQueue (hab, 0);
  1807.    WinCancelShutdown (hmq, TRUE);
  1808. #endif
  1809.  
  1810. #if defined(__OS2__)
  1811.    DosExitCritSec ();
  1812. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)0, (USHORT)0);
  1813. #endif
  1814.  
  1815.    OldStatus = Status;
  1816.    Status = UNDEFINED;
  1817.  
  1818.    if (Actions & MAIL_TIC) {
  1819.       if ((Tic = new TTicProcessor) != NULL) {
  1820.          Tic->Cfg = Cfg;
  1821.          Tic->Log = Log;
  1822.          Tic->Output = new TPMList (hwndMainClient);
  1823.          if (Tic->Output != NULL)
  1824.             Tic->Output->Clear ();
  1825.          if (Log != NULL)
  1826.             Log->Write ("+Processing inbound TICs");
  1827.          strcpy (Tic->Inbound, Cfg->NormalInbound);
  1828.          Tic->Import ();
  1829.          if (stricmp (Cfg->KnownInbound, Cfg->NormalInbound)) {
  1830.             strcpy (Tic->Inbound, Cfg->KnownInbound);
  1831.             Tic->Import ();
  1832.          }
  1833.          if (stricmp (Cfg->ProtectedInbound, Cfg->NormalInbound) && stricmp (Cfg->ProtectedInbound, Cfg->KnownInbound)) {
  1834.             strcpy (Tic->Inbound, Cfg->ProtectedInbound);
  1835.             Tic->Import ();
  1836.          }
  1837.  
  1838.          if (Tic->Output != NULL)
  1839.             delete Tic->Output;
  1840.          delete Tic;
  1841.       }
  1842.    }
  1843.  
  1844.    if ((Processor = new TMailProcessor) != NULL) {
  1845.       Processor->Cfg = Cfg;
  1846.       Processor->Log = Log;
  1847.       Processor->Output = new TPMList (hwndMainClient);
  1848.       Processor->Status = new TPMStatus (hwndMainClient);
  1849.  
  1850.       if (Actions & MAIL_IMPORTBAD)
  1851.          Processor->ImportBad ();
  1852.  
  1853.       if (Actions & (MAIL_IMPORTNORMAL|MAIL_IMPORTKNOWN|MAIL_IMPORTPROTECTED)) {
  1854.          if (Cfg->ImportCmd[0] != '\0' && !(Actions & MAIL_NOEXTERNAL))
  1855.             RunExternal (Cfg->ImportCmd);
  1856.          else {
  1857.             if (Actions & MAIL_IMPORTNORMAL) {
  1858.                strcpy (Processor->Inbound, Cfg->NormalInbound);
  1859.                while (Processor->IsArcmail () == TRUE)
  1860.                   Processor->UnpackArcmail ();
  1861.                Processor->Import ();
  1862.             }
  1863.             if ((Actions & MAIL_IMPORTKNOWN) && stricmp (Cfg->KnownInbound, Cfg->NormalInbound)) {
  1864.                strcpy (Processor->Inbound, Cfg->KnownInbound);
  1865.                while (Processor->IsArcmail () == TRUE)
  1866.                   Processor->UnpackArcmail ();
  1867.                Processor->Import ();
  1868.             }
  1869.             if ((Actions & MAIL_IMPORTPROTECTED) && stricmp (Cfg->ProtectedInbound, Cfg->NormalInbound) && stricmp (Cfg->ProtectedInbound, Cfg->KnownInbound)) {
  1870.                strcpy (Processor->Inbound, Cfg->ProtectedInbound);
  1871.                while (Processor->IsArcmail () == TRUE)
  1872.                   Processor->UnpackArcmail ();
  1873.                Processor->Import ();
  1874.             }
  1875.  
  1876.             if (Processor->Packets == 0)
  1877.                Log->Write ("+No ECHOmail processed at this time");
  1878.             else
  1879.                Log->Write ("+%d packet(s): %lu NETmail, %lu ECHOmail, %lu Dupes, %lu Bad", Processor->Packets, Processor->NetMail, Processor->MsgTossed - Processor->NetMail, Processor->Duplicate, Processor->Bad);
  1880.          }
  1881.       }
  1882.  
  1883.       if (Actions & MAIL_NEWSGROUP) {
  1884.          Processor->News ();
  1885.          Log->Write ("+%lu message(s): %lu Sent, %lu Received", Processor->MsgSent + Processor->MsgTossed, Processor->MsgSent, Processor->MsgTossed);
  1886.       }
  1887.  
  1888.       if (Actions & MAIL_EMAIL) {
  1889.          Processor->Mail ();
  1890.          Log->Write ("+%lu message(s): %lu Sent, %lu Received", Processor->MsgSent + Processor->MsgTossed, Processor->MsgSent, Processor->MsgTossed);
  1891.       }
  1892.  
  1893.       if ((Actions & MAIL_EXPORT) && (Actions & MAIL_PACK) && Cfg->SeparateNetMail == TRUE) {
  1894.          if (Cfg->PackCmd[0] != '\0' && !(Actions & MAIL_NOEXTERNAL))
  1895.             RunExternal (Cfg->PackCmd);
  1896.          else {
  1897.             Processor->ExportNetMail ();
  1898.             sprintf (Temp, "%sroute.cfg", Cfg->SystemPath);
  1899.             tag = NULL;
  1900.             if (Events != NULL)
  1901.                tag = Events->RouteCmd;
  1902.             Processor->Pack (Temp, tag);
  1903.             if (Processor->DoRescan () == TRUE)
  1904.                Processor->Pack (Temp, tag);
  1905.          }
  1906.       }
  1907.  
  1908.       if (Actions & MAIL_EXPORT) {
  1909.          if (Cfg->ExportCmd[0] != '\0' && !(Actions & MAIL_NOEXTERNAL))
  1910.             RunExternal (Cfg->ExportCmd);
  1911.          else
  1912.             Processor->Export ();
  1913.       }
  1914.  
  1915.       if (Actions & MAIL_PACK) {
  1916.          if (Cfg->PackCmd[0] != '\0' && !(Actions & MAIL_NOEXTERNAL))
  1917.             RunExternal (Cfg->PackCmd);
  1918.          else {
  1919.             Processor->ExportNetMail ();
  1920.             sprintf (Temp, "%sroute.cfg", Cfg->SystemPath);
  1921.             tag = NULL;
  1922.             if (Events != NULL)
  1923.                tag = Events->RouteCmd;
  1924.             Processor->Pack (Temp, tag);
  1925.             if (Processor->DoRescan () == TRUE)
  1926.                Processor->Pack (Temp, tag);
  1927.          }
  1928.       }
  1929.  
  1930.       if (Processor->Status != NULL)
  1931.          delete Processor->Status;
  1932.       if (Processor->Output != NULL)
  1933.          delete Processor->Output;
  1934.       delete Processor;
  1935.    }
  1936.  
  1937.    if ((Actions & MAIL_PACK) && Outbound != NULL) {
  1938.       if (Log != NULL)
  1939.          Log->Write ("+Building the outbound queue");
  1940.       Outbound->BuildQueue (Cfg->Outbound);
  1941.       unlink ("rescan.now");
  1942.       if (Log != NULL)
  1943.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  1944.    }
  1945.  
  1946.    if (!(Actions & MAIL_POSTQUIT)) {
  1947.       if (Log != NULL)
  1948.          Log->WriteBlank ();
  1949.  
  1950. #if defined(__OS2__)
  1951.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  1952. #elif defined(__NT__)
  1953.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  1954. #endif
  1955.  
  1956.       if (Actions & MAIL_STARTTIMER)
  1957.          StartTimer (hwndMainClient, 1, MODEM_DELAY);
  1958.    }
  1959. #if defined(__OS2__)
  1960.    else
  1961.       WinPostMsg (hwndMainClient, WM_CLOSE, 0L, 0L);
  1962. #elif defined(__NT__)
  1963.    else
  1964.       PostMessage (hwndMainClient, WM_CLOSE, 0, 0L);
  1965. #endif
  1966.  
  1967. #if defined(__OS2__)
  1968.    if (hmq != NULL)
  1969.       WinDestroyMsgQueue (hmq);
  1970.    WinTerminate (hab);
  1971. #endif
  1972.  
  1973.    Status = OldStatus;
  1974.  
  1975. #if defined(__OS2__) || defined(__NT__)
  1976.    _endthread ();
  1977. #endif
  1978. }
  1979.  
  1980. #if !defined(__POINT__)
  1981.  
  1982. VOID BbsThread (PVOID Args)
  1983. {
  1984.    USHORT Remote;
  1985.    CHAR Title[64];
  1986.    ULONG Flags;
  1987. #if defined(__OS2__)
  1988.    CHAR ObjBuf[64], PipeName[64], CtlName[64], Temp[128];
  1989.    ULONG id;
  1990.    STARTDATA StartData;
  1991.    PID Pid;
  1992.    HAB hab;
  1993.    HMQ hmq;
  1994.    class TPipe *Pipe = NULL;
  1995. #elif defined(__NT__)
  1996.    class TScreen *Screen;
  1997. #endif
  1998.    class TBbs *Bbs;
  1999.  
  2000.    Args = Args;
  2001.    Remote = REMOTE_NONE;
  2002. #if defined(__OS2__)
  2003.    hab = WinInitialize (0);
  2004.    hmq = WinCreateMsgQueue (hab, 0);
  2005.    WinCancelShutdown (hmq, TRUE);
  2006. #endif
  2007.  
  2008. #if defined(__OS2__)
  2009.    DosExitCritSec ();
  2010. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)31, (USHORT)0);
  2011. #endif
  2012.  
  2013.    sprintf (Title, "Snoop - Line %u", Cfg->TaskNumber);
  2014.  
  2015.    if ((Bbs = new TBbs) != NULL) {
  2016. #if defined(__OS2__)
  2017.       if ((Pipe = new TPipe) != NULL) {
  2018.          sprintf (PipeName, "\\PIPE\\SNOOP%u", Cfg->TaskNumber);
  2019.          sprintf (CtlName, "\\PIPE\\CTL%u", Cfg->TaskNumber);
  2020.  
  2021.          if (Pipe->Initialize (PipeName, CtlName, 1) == TRUE) {
  2022.             Pipe->WaitClient ();
  2023.             Bbs->Snoop = Pipe;
  2024.          }
  2025.  
  2026.          memset (&StartData, 0, sizeof (STARTDATA));
  2027.          StartData.Length = sizeof (STARTDATA);
  2028.          StartData.Related = SSF_RELATED_CHILD;
  2029.          StartData.FgBg = SSF_FGBG_BACK;
  2030.          StartData.TraceOpt = SSF_TRACEOPT_NONE;
  2031.          StartData.PgmTitle = Title;
  2032.          StartData.PgmName = "SNOOP.EXE";
  2033.          sprintf (Temp, "%s %s", PipeName, CtlName);
  2034.          StartData.PgmInputs = Temp;
  2035.          StartData.TermQ = NULL;
  2036.          StartData.Environment = 0;
  2037.          StartData.InheritOpt = SSF_INHERTOPT_PARENT;
  2038.          StartData.SessionType = SSF_TYPE_FULLSCREEN;
  2039.          StartData.IconFile = 0;
  2040.          StartData.PgmHandle = 0;
  2041.          StartData.PgmControl = SSF_CONTROL_VISIBLE;
  2042.          StartData.InitXPos = 30;
  2043.          StartData.InitYPos = 40;
  2044.          StartData.InitXSize = 200;
  2045.          StartData.InitYSize = 140;
  2046.          StartData.Reserved = 0;
  2047.          StartData.ObjectBuffer = ObjBuf;
  2048.          StartData.ObjectBuffLen = sizeof (ObjBuf);
  2049.          DosStartSession (&StartData, &id, &Pid);
  2050.  
  2051.          while (Pipe->WaitClient () == FALSE)
  2052.             DosSleep (1L);
  2053.       }
  2054. #elif defined(__NT__)
  2055.       if ((Screen = new TScreen) != NULL) {
  2056.          if (Screen->Initialize () == TRUE) {
  2057.             SetConsoleTitle (Title);
  2058.             SetForegroundWindow (hwndMainClient);
  2059.             Bbs->Snoop = Screen;
  2060.          }
  2061.       }
  2062. #endif
  2063.  
  2064.       Bbs->Log = Log;
  2065.       Bbs->Cfg = Cfg;
  2066.       Bbs->Events = Events;
  2067.       Bbs->Progress = new TPMProgress (hwndMainClient);
  2068.       Bbs->MailerStatus = new TPMMailStatus (hwndMainClient);
  2069.       Bbs->Status = new TPMStatus (hwndMainClient);
  2070.       if (Modem != NULL) {
  2071.          Bbs->Com = Modem->Serial;
  2072.          Bbs->Speed = Modem->Speed;
  2073.          if (connectSpeed != 0L)
  2074.             Bbs->Speed = connectSpeed;
  2075.       }
  2076.       Bbs->Task = Cfg->TaskNumber;
  2077.       Bbs->TimeLimit = timeLimit;
  2078.       Bbs->Run ();
  2079.       Remote = Bbs->Remote;
  2080.  
  2081.       if (Bbs->Status != NULL) {
  2082.          Bbs->Status->Clear ();
  2083.          delete Bbs->Status;
  2084.       }
  2085.       if (Bbs->MailerStatus != NULL)
  2086.          delete Bbs->MailerStatus;
  2087.       if (Bbs->Progress != NULL)
  2088.          delete Bbs->Progress;
  2089.  
  2090. #if defined(__OS2__)
  2091.       if (Pipe != NULL) {
  2092.          DosStopSession (STOP_SESSION_SPECIFIED, id);
  2093.          delete Pipe;
  2094.       }
  2095. #elif defined(__NT__)
  2096.       if (Screen != NULL)
  2097.          delete Screen;
  2098. #endif
  2099.  
  2100.       delete Bbs;
  2101.    }
  2102.  
  2103.    Modem->SendCommand (Cfg->Hangup);
  2104.    if (Modem->Serial != NULL && Log != NULL) {
  2105.       if (Modem->Serial->Carrier () == TRUE)
  2106.          Log->Write ("!Unable to drop carrier");
  2107.    }
  2108.  
  2109.    if (Remote == REMOTE_MAILRECEIVED && Cfg->AfterMailCmd[0] != '\0') {
  2110.       if (Log != NULL)
  2111.          Log->Write (":Running %s", Cfg->AfterMailCmd);
  2112.       SpawnExternal (Cfg->AfterMailCmd);
  2113.    }
  2114.    else if (Remote == REMOTE_USER && Cfg->AfterCallerCmd[0] != '\0') {
  2115.       if (Log != NULL)
  2116.          Log->Write (":Running %s", Cfg->AfterCallerCmd);
  2117.       SpawnExternal (Cfg->AfterCallerCmd);
  2118.    }
  2119.  
  2120.    if ((Remote == REMOTE_MAILER || Remote == REMOTE_MAILRECEIVED) && Outbound != NULL) {
  2121.       if (Log != NULL)
  2122.          Log->Write ("+Building the outbound queue");
  2123.       Outbound->BuildQueue (Cfg->Outbound);
  2124.       Outbound->FirstNode ();
  2125.       if (Log != NULL)
  2126.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  2127.  
  2128. #if defined(__OS2__)
  2129.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2130. #elif defined(__NT__)
  2131.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2132. #endif
  2133.    }
  2134.  
  2135.    if (Log != NULL)
  2136.       Log->WriteBlank ();
  2137.  
  2138.    Flags = 0L;
  2139.    if (Remote == REMOTE_MAILRECEIVED && Events != NULL) {
  2140.       Flags |= MAIL_STARTTIMER;
  2141.       if (Events->ImportNormal == TRUE)
  2142.          Flags |= MAIL_IMPORTNORMAL;
  2143.       if (Events->ImportKnown == TRUE)
  2144.          Flags |= MAIL_IMPORTKNOWN;
  2145.       if (Events->ImportProtected == TRUE)
  2146.          Flags |= MAIL_IMPORTPROTECTED;
  2147.       if (Events->ExportMail == TRUE)
  2148.          Flags |= (MAIL_EXPORT|MAIL_PACK);
  2149.       if (Events->ProcessTIC == TRUE)
  2150.          Flags |= MAIL_TIC;
  2151.       _beginthread (MailProcessorThread, NULL, 8192, (PVOID)Flags);
  2152.    }
  2153.    else
  2154.       StartTimer (hwndMainClient, 1, MODEM_DELAY);
  2155.  
  2156. #if defined(__OS2__)
  2157.    if (hmq != NULL)
  2158.       WinDestroyMsgQueue (hmq);
  2159.    WinTerminate (hab);
  2160. #endif
  2161.  
  2162. #if defined(__OS2__) || defined(__NT__)
  2163.    _endthread ();
  2164. #endif
  2165. }
  2166.  
  2167. VOID LocalThread (PVOID Args)
  2168. {
  2169.    CHAR Title[64];
  2170. #if defined(__OS2__)
  2171.    CHAR ObjBuf[64], PipeName[64], CtlName[64], Temp[128];
  2172.    ULONG id;
  2173.    STARTDATA StartData;
  2174.    PID Pid;
  2175.    HAB hab;
  2176.    HMQ hmq;
  2177.    class TPipe *Pipe = NULL;
  2178. #elif defined(__NT__)
  2179.    class TScreen *Screen;
  2180. #endif
  2181.    class TBbs *Bbs;
  2182.  
  2183.    Args = Args;
  2184. #if defined(__OS2__)
  2185.    hab = WinInitialize (0);
  2186.    hmq = WinCreateMsgQueue (hab, 0);
  2187.    WinCancelShutdown (hmq, TRUE);
  2188. #endif
  2189.  
  2190. #if defined(__OS2__)
  2191.    DosExitCritSec ();
  2192. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)31, (USHORT)0);
  2193. #endif
  2194.  
  2195.    sprintf (Title, "Snoop - Line %u", Cfg->TaskNumber);
  2196.  
  2197.    if ((Bbs = new TBbs) != NULL) {
  2198. #if defined(__OS2__)
  2199.       if ((Pipe = new TPipe) != NULL) {
  2200.          sprintf (PipeName, "\\PIPE\\SNOOP%u", Cfg->TaskNumber);
  2201.          sprintf (CtlName, "\\PIPE\\CTL%u", Cfg->TaskNumber);
  2202.  
  2203.          if (Pipe->Initialize (PipeName, CtlName, 1) == TRUE) {
  2204.             Pipe->WaitClient ();
  2205.             Bbs->Com = Pipe;
  2206.          }
  2207.  
  2208.          memset (&StartData, 0, sizeof (STARTDATA));
  2209.          StartData.Length = sizeof (STARTDATA);
  2210.          StartData.Related = SSF_RELATED_CHILD;
  2211.          StartData.FgBg = SSF_FGBG_FORE;
  2212.          StartData.TraceOpt = SSF_TRACEOPT_NONE;
  2213.          StartData.PgmTitle = Title;
  2214.          StartData.PgmName = "SNOOP.EXE";
  2215.          sprintf (Temp, "%s %s", PipeName, CtlName);
  2216.          StartData.PgmInputs = Temp;
  2217.          StartData.TermQ = NULL;
  2218.          StartData.Environment = 0;
  2219.          StartData.InheritOpt = SSF_INHERTOPT_PARENT;
  2220.          StartData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  2221.          StartData.IconFile = 0;
  2222.          StartData.PgmHandle = 0;
  2223.          StartData.PgmControl = SSF_CONTROL_VISIBLE;
  2224.          StartData.InitXPos = 30;
  2225.          StartData.InitYPos = 40;
  2226.          StartData.InitXSize = 200;
  2227.          StartData.InitYSize = 140;
  2228.          StartData.Reserved = 0;
  2229.          StartData.ObjectBuffer = ObjBuf;
  2230.          StartData.ObjectBuffLen = sizeof (ObjBuf);
  2231.          DosStartSession (&StartData, &id, &Pid);
  2232.  
  2233.          while (Pipe->WaitClient () == FALSE)
  2234.             DosSleep (1L);
  2235.       }
  2236. #elif defined(__NT__)
  2237.       if ((Screen = new TScreen) != NULL) {
  2238.          if (Screen->Initialize () == TRUE) {
  2239.             SetConsoleTitle (Title);
  2240.             Bbs->Com = Screen;
  2241.          }
  2242.       }
  2243. #endif
  2244.  
  2245.       if (Log != NULL)
  2246.          Log->Write ("+Connect Local");
  2247.       Bbs->Log = Log;
  2248.       Bbs->Cfg = Cfg;
  2249.       Bbs->Events = Events;
  2250.       Bbs->Progress = new TPMProgress (hwndMainClient);
  2251.       Bbs->Status = new TPMStatus (hwndMainClient);
  2252.       Bbs->Speed = 57600L;
  2253.       Bbs->Task = Cfg->TaskNumber;
  2254.       Bbs->TimeLimit = timeLimit;
  2255.       Bbs->Local = TRUE;
  2256.       Bbs->Run ();
  2257.       if (Bbs->Status != NULL) {
  2258.          Bbs->Status->Clear ();
  2259.          delete Bbs->Status;
  2260.       }
  2261.       if (Bbs->Progress != NULL)
  2262.          delete Bbs->Progress;
  2263.  
  2264. #if defined(__OS2__)
  2265.       if (Pipe != NULL) {
  2266.          DosStopSession (STOP_SESSION_SPECIFIED, id);
  2267.          delete Pipe;
  2268.       }
  2269. #elif defined(__NT__)
  2270.       if (Screen != NULL)
  2271.          delete Screen;
  2272. #endif
  2273.  
  2274.       delete Bbs;
  2275.    }
  2276.  
  2277.    Modem->SendCommand (Cfg->Hangup);
  2278.    if (Modem->Serial != NULL && Log != NULL) {
  2279.       if (Modem->Serial->Carrier () == TRUE)
  2280.          Log->Write ("!Unable to drop carrier");
  2281.    }
  2282.  
  2283.    if (Log != NULL) {
  2284.       Log->Display = TRUE;
  2285.       Log->WriteBlank ();
  2286.    }
  2287.  
  2288.    StartTimer (hwndMainClient, 1, MODEM_DELAY);
  2289.  
  2290. #if defined(__OS2__)
  2291.    if (hmq != NULL)
  2292.       WinDestroyMsgQueue (hmq);
  2293.    WinTerminate (hab);
  2294. #endif
  2295.  
  2296. #if defined(__OS2__) || defined(__NT__)
  2297.    _endthread ();
  2298. #endif
  2299. }
  2300.  
  2301. #endif
  2302.  
  2303. VOID MailerThread (PVOID Args)
  2304. {
  2305.    USHORT RetVal = FALSE;
  2306.    ULONG Flags;
  2307. #if defined(__OS2__)
  2308.    HAB hab;
  2309.    HMQ hmq;
  2310. #endif
  2311.    class TDetect *Detect;
  2312.  
  2313.    Args = Args;
  2314. #if defined(__OS2__)
  2315.    hab = WinInitialize (0);
  2316.    hmq = WinCreateMsgQueue (hab, 0);
  2317.    WinCancelShutdown (hmq, TRUE);
  2318. #endif
  2319.  
  2320. #if defined(__OS2__)
  2321.    DosExitCritSec ();
  2322. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)31, (USHORT)0);
  2323. #endif
  2324.  
  2325.    if ((Detect = new TDetect) != NULL) {
  2326.       Detect->Task = Cfg->TaskNumber;
  2327.       Detect->Log = Log;
  2328.       Detect->Cfg = Cfg;
  2329.       Detect->Events = Events;
  2330.       Detect->Progress = new TPMProgress (hwndMainClient);
  2331.       Detect->MailerStatus = new TPMMailStatus (hwndMainClient);
  2332.       Detect->Status = new TPMStatus (hwndMainClient);
  2333.       if (Modem != NULL) {
  2334.          Detect->Com = Modem->Serial;
  2335.          Detect->Speed = Modem->Speed;
  2336.       }
  2337.       if (strchr (PollNode, '/') != NULL || strchr (PollNode, ':') != NULL)
  2338.          Detect->Address.Add (PollNode);
  2339.       RetVal = Detect->RemoteMailer ();
  2340.  
  2341.       if (Detect->Status != NULL) {
  2342.          Detect->Status->Clear ();
  2343.          delete Detect->Status;
  2344.       }
  2345.       if (Detect->MailerStatus != NULL)
  2346.          delete Detect->MailerStatus;
  2347.       if (Detect->Progress != NULL)
  2348.          delete Detect->Progress;
  2349.  
  2350.       delete Detect;
  2351.    }
  2352.  
  2353.    Modem->SendCommand (Cfg->Hangup);
  2354.    if (Modem->Serial != NULL && Log != NULL) {
  2355.       if (Modem->Serial->Carrier () == TRUE)
  2356.          Log->Write ("!Unable to drop carrier");
  2357.    }
  2358.  
  2359.    if (RetVal == REMOTE_MAILRECEIVED && Cfg->AfterMailCmd[0] != '\0') {
  2360.       if (Log != NULL)
  2361.          Log->Write (":Running %s", Cfg->AfterMailCmd);
  2362.       SpawnExternal (Cfg->AfterMailCmd);
  2363.    }
  2364.  
  2365.    if ((RetVal == REMOTE_MAILER || RetVal == REMOTE_MAILRECEIVED) && Outbound != NULL) {
  2366.       if (Log != NULL)
  2367.          Log->Write ("+Building the outbound queue");
  2368.       Outbound->BuildQueue (Cfg->Outbound);
  2369.       Outbound->FirstNode ();
  2370.       if (Log != NULL)
  2371.          Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  2372. #if defined(__OS2__)
  2373.       WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2374. #elif defined(__NT__)
  2375.       PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2376. #endif
  2377.    }
  2378.  
  2379.    if (Log != NULL)
  2380.       Log->WriteBlank ();
  2381.  
  2382.    Flags = MAIL_STARTTIMER;
  2383.    if (RetVal == REMOTE_MAILRECEIVED && Events != NULL) {
  2384.       if (Events->ImportNormal == TRUE)
  2385.          Flags |= MAIL_IMPORTNORMAL;
  2386.       if (Events->ImportKnown == TRUE)
  2387.          Flags |= MAIL_IMPORTKNOWN;
  2388.       if (Events->ImportProtected == TRUE)
  2389.          Flags |= MAIL_IMPORTPROTECTED;
  2390.       if (Events->ExportMail == TRUE)
  2391.          Flags |= (MAIL_EXPORT|MAIL_PACK);
  2392.       if (Events->ProcessTIC == TRUE)
  2393.          Flags |= MAIL_TIC;
  2394.    }
  2395.    if (Flags != MAIL_STARTTIMER)
  2396.       _beginthread (MailProcessorThread, NULL, 8192, (PVOID)Flags);
  2397.    else
  2398.       StartTimer (hwndMainClient, 1, MODEM_DELAY);
  2399.  
  2400. #if defined(__OS2__)
  2401.    if (hmq != NULL)
  2402.       WinDestroyMsgQueue (hmq);
  2403.    WinTerminate (hab);
  2404. #endif
  2405.  
  2406. #if defined(__OS2__) || defined(__NT__)
  2407.    _endthread ();
  2408. #endif
  2409. }
  2410.  
  2411. #if !defined(__POINT__)
  2412.  
  2413. VOID FaxReceiveThread (PVOID Args)
  2414. {
  2415.    CHAR Temp[128];
  2416. #if defined(__OS2__)
  2417.    HAB hab;
  2418.    HMQ hmq;
  2419. #endif
  2420.    class TFax *Fax;
  2421.  
  2422.    Args = Args;
  2423. #if defined(__OS2__)
  2424.    hab = WinInitialize (0);
  2425.    hmq = WinCreateMsgQueue (hab, 0);
  2426.    WinCancelShutdown (hmq, TRUE);
  2427. #endif
  2428.  
  2429. #if defined(__OS2__)
  2430.    DosExitCritSec ();
  2431. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)31, (USHORT)0);
  2432. #endif
  2433.  
  2434.    if (Cfg->ExternalFax == TRUE && Cfg->FaxCommand[0] != '\0') {
  2435. #if !defined(__DOS__)
  2436.       sprintf (Temp, Cfg->FaxCommand, atoi (&Cfg->Device[3]), Cfg->Speed, Modem->Serial->hFile);
  2437. #else
  2438.       sprintf (Temp, Cfg->FaxCommand, atoi (&Cfg->Device[3]), Cfg->Speed, atoi (Cfg->Device) - 1);
  2439. #endif
  2440.  
  2441.       Log->Write ("+Spawning to %s", Temp);
  2442.       Log->Suspend ();
  2443.       RunExternal (Temp);
  2444.       Log->Resume ();
  2445.       Log->Write (":Returned from %s", Temp);
  2446.    }
  2447.    else {
  2448.       if ((Fax = new TFax) != NULL) {
  2449.          strcpy (Fax->DataPath, Cfg->FaxPath);
  2450.          Fax->Format = Cfg->FaxFormat;
  2451.          Fax->Com = Modem->Serial;
  2452.          Fax->Log = Log;
  2453.          if (Fax->faxreceive () == TRUE && Cfg->AfterFaxCmd[0] != '\0')
  2454.             SpawnExternal (Cfg->AfterFaxCmd);
  2455.          delete Fax;
  2456.       }
  2457.    }
  2458.  
  2459.    Modem->SendCommand (Cfg->Hangup);
  2460.    if (Modem->Serial != NULL && Log != NULL) {
  2461.       if (Modem->Serial->Carrier () == TRUE)
  2462.          Log->Write ("!Unable to drop carrier");
  2463.    }
  2464.  
  2465.    StartTimer (hwndMainClient, 1, MODEM_DELAY);
  2466.  
  2467. #if defined(__OS2__)
  2468.    if (hmq != NULL)
  2469.       WinDestroyMsgQueue (hmq);
  2470.    WinTerminate (hab);
  2471. #endif
  2472.  
  2473. #if defined(__OS2__) || defined(__NT__)
  2474.    _endthread ();
  2475. #endif
  2476. }
  2477.  
  2478. #endif
  2479.  
  2480. VOID SendInitThread (PVOID Args)
  2481. {
  2482.    Args = Args;
  2483.    Modem->SendCommand (Cfg->Initialize[Current]);
  2484.  
  2485. #if defined(__OS2__) || defined(__NT__)
  2486.    _endthread ();
  2487. #endif
  2488. }
  2489.  
  2490. VOID ModemTimer (HWND hwnd)
  2491. {
  2492.    USHORT i;
  2493.  
  2494.    switch (Status) {
  2495.       case 0:
  2496.          if (Status != 200) {
  2497.             if (Modem == NULL && Cfg != NULL) {
  2498.                if ((Modem = new TModem) != NULL) {
  2499.                   Modem->Log = Log;
  2500.                   strcpy (Modem->Device, Cfg->Device);
  2501.                   Modem->Speed = Cfg->Speed;
  2502.                   Modem->LockSpeed = Cfg->LockSpeed;
  2503.                   if (Cfg->Ring[0] != '\0')
  2504.                      strcpy (Modem->Ring, Cfg->Ring);
  2505.                   if (Modem->Initialize (comHandle) == TRUE) {
  2506.                      Current = 0;
  2507.                      Modem->hwndWindow = hwnd;
  2508.  
  2509.                      if (Modem->Serial->Carrier () == TRUE && gotPort == TRUE && gotSpeed == TRUE) {
  2510.                         if (Log != NULL)
  2511.                            Log->Write ("+Connect %lu", Modem->Speed);
  2512.                         StopTimer (hwnd, 1);
  2513.                         _beginthread (BbsThread, NULL, 32768U, NULL);
  2514.                         Status = BBSEXIT;
  2515.                      }
  2516.                      else
  2517.                         Status = INITIALIZE;
  2518.                   }
  2519.                   else if (Log != NULL) {
  2520.                      Log->Write ("!Error opening device %s", Modem->Device);
  2521.                      Status = BBSEXIT;
  2522.                   }
  2523.                }
  2524.             }
  2525.             if (Outbound != NULL && Status != BBSEXIT) {
  2526.                if (Log != NULL)
  2527.                   Log->Write ("+Building the outbound queue");
  2528.                Outbound->BuildQueue (Cfg->Outbound);
  2529.                if (Outbound->FirstNode () == FALSE)
  2530.                   Outbound->New ();
  2531.                if (Log != NULL)
  2532.                   Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  2533. #if defined(__OS2__)
  2534.                WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2535. #elif defined(__NT__)
  2536.                PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2537. #endif
  2538.             }
  2539.          }
  2540.          break;
  2541.  
  2542.       case INITIALIZE:
  2543.          if (Modem != NULL && Cfg != NULL) {
  2544.             while (Current < 3 && Cfg->Initialize[Current][0] == '\0')
  2545.                Current++;
  2546.             if (Current >= 3) {
  2547.                Status = WAITFORCALL;
  2548.                TimeOut = TimerSet (REINIT_DELAY);
  2549.                Modem->Terminal = TRUE;
  2550.             }
  2551.             else {
  2552.                Modem->Terminal = FALSE;
  2553.                _beginthread (SendInitThread, NULL, 8192U, NULL);
  2554.                Status = WAITFOROK;
  2555.                TimeOut = TimerSet (500);
  2556.             }
  2557.          }
  2558.          break;
  2559.  
  2560.       case WAITFOROK:
  2561.          if (Modem->GetResponse () == OK) {
  2562.             while (++Current < 3 && Cfg->Initialize[Current][0] == '\0')
  2563.                ;
  2564.             if (Current >= 3) {
  2565.                Status = WAITFORCALL;
  2566.                TimeOut = TimerSet (REINIT_DELAY);
  2567.             }
  2568.             else
  2569.                Status = INITIALIZE;
  2570.          }
  2571.          else if (TimeUp (TimeOut) == TRUE) {
  2572.             if (Log != NULL)
  2573.                Log->Write ("!Modem doesn't report 'Ok'");
  2574.             Status = INITIALIZE;
  2575.          }
  2576.          break;
  2577.  
  2578.       case WAITFORCALL: {
  2579.          USHORT t;
  2580.          struct dostime_t dt;
  2581.  
  2582.          if ((i = Modem->GetResponse ()) == RING && Cfg != NULL) {
  2583.             if (Cfg->ManualAnswer == TRUE) {
  2584.                if (Cfg->LimitedHours == FALSE) {
  2585.                   Modem->SendCommand (Cfg->Answer);
  2586.                   Status = ANSWERING;
  2587.                   TimeOut = TimerSet (4500L);
  2588.                }
  2589.                else {
  2590.                   _dos_gettime (&dt);
  2591.                   t = (USHORT)(dt.hour * 60 + dt.minute);
  2592.                   if (Cfg->StartTime < Cfg->EndTime) {
  2593.                      if (t >= Cfg->StartTime && t <= Cfg->EndTime) {
  2594.                         Modem->SendCommand (Cfg->Answer);
  2595.                         Status = ANSWERING;
  2596.                         TimeOut = TimerSet (4500L);
  2597.                      }
  2598.                   }
  2599.                   else {
  2600.                      if (t >= Cfg->StartTime) {
  2601.                         Modem->SendCommand (Cfg->Answer);
  2602.                         Status = ANSWERING;
  2603.                         TimeOut = TimerSet (4500L);
  2604.                      }
  2605.                      else if (t <= Cfg->EndTime) {
  2606.                         Modem->SendCommand (Cfg->Answer);
  2607.                         Status = ANSWERING;
  2608.                         TimeOut = TimerSet (4500L);
  2609.                      }
  2610.                   }
  2611.                }
  2612.             }
  2613.          }
  2614.          else if (i == CONNECT) {
  2615.             StopTimer (hwnd, 1);
  2616.             _beginthread (BbsThread, NULL, 32768U, NULL);
  2617.             Status = HANGUP;
  2618.          }
  2619.          else if (i == FAX) {
  2620.             StopTimer (hwnd, 1);
  2621.             _beginthread (FaxReceiveThread, NULL, 8192, NULL);
  2622.             Status = HANGUP;
  2623.          }
  2624.          else if (TimeUp (TimeOut) == TRUE) {
  2625.             Status = INITIALIZE;
  2626.             Current = 0;
  2627.          }
  2628.          break;
  2629.       }
  2630.  
  2631.       case ANSWERING:
  2632.          if ((i = Modem->GetResponse ()) == CONNECT) {
  2633.             StopTimer (hwnd, 1);
  2634.             _beginthread (BbsThread, NULL, 32768U, NULL);
  2635.             Status = HANGUP;
  2636.          }
  2637.          else if (i == FAX) {
  2638.             StopTimer (hwnd, 1);
  2639.             _beginthread (FaxReceiveThread, NULL, 8192, NULL);
  2640.             Status = HANGUP;
  2641.          }
  2642.          else if (i != NO_RESPONSE && i != RING)
  2643.             Status = HANGUP;
  2644.          else if (TimeUp (TimeOut) == TRUE) {
  2645.             if (Log != NULL)
  2646.                Log->Write ("!Answer timer expired");
  2647.             Status = HANGUP;
  2648.          }
  2649.          break;
  2650.  
  2651.       case HANGUP:
  2652.          Modem->Speed = Cfg->Speed;
  2653.          Modem->Initialize ();
  2654.          Status = INITIALIZE;
  2655.          Current = 0;
  2656.          CallTimer = 0L;
  2657.          break;
  2658.  
  2659.       case WAITFORCONNECT:
  2660.          if ((i = Modem->GetResponse ()) == CONNECT) {
  2661.             if (PollNode[0] != '\0' && Outbound != NULL)
  2662.                Outbound->AddAttempt (PollNode, TRUE);
  2663.             StopTimer (hwnd, 1);
  2664.             _beginthread (MailerThread, NULL, 32768U, NULL);
  2665.             Status = HANGUP;
  2666.          }
  2667.          else if (i != NO_RESPONSE) {
  2668.             if (PollNode[0] != '\0' && Outbound != NULL) {
  2669.                Outbound->AddAttempt (PollNode, FALSE, Modem->Response);
  2670. //               PollNode[0] = '\0';
  2671. #if defined(__OS2__)
  2672.                WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2673. #elif defined(__NT__)
  2674.                PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2675. #endif
  2676.             }
  2677.             Status = INITIALIZE;
  2678.             Current = 0;
  2679.          }
  2680.          else if (TimeUp (TimeOut) == TRUE) {
  2681.             if (Log != NULL)
  2682.                Log->Write ("!Dialing timer expired");
  2683.             if (PollNode[0] != '\0' && Outbound != NULL) {
  2684.                Outbound->AddAttempt (PollNode, FALSE, "Timeout");
  2685. //               PollNode[0] = '\0';
  2686. #if defined(__OS2__)
  2687.                WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2688. #elif defined(__NT__)
  2689.                PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2690. #endif
  2691.             }
  2692.             Status = HANGUP;
  2693.          }
  2694.          break;
  2695.  
  2696.       case BBSEXIT:
  2697. #if defined(__OS2__)
  2698.          WinPostMsg (hwnd, WM_CLOSE, 0L, 0L);
  2699. #elif defined(__NT__)
  2700.          PostMessage (hwnd, WM_CLOSE, 0, 0L);
  2701. #endif
  2702.          break;
  2703.    }
  2704. }
  2705.  
  2706. //////////////////////////////////////////////////////////////////
  2707. // Processo in background per controllo eventi e poll           //
  2708. //////////////////////////////////////////////////////////////////
  2709. VOID BackgroundThread (PVOID Args)
  2710. {
  2711.    DIR *dir;
  2712.    USHORT i, DoCall, Found, DoEvent;
  2713.    USHORT OldStatus = 99;
  2714.    CHAR Temp[64], *p;
  2715.    ULONG EventsTimer;
  2716.    time_t t;
  2717.    class TAddress Address;
  2718.    class TOutbound *Out;
  2719.    class TNodes *Nodes;
  2720.    struct stat statbuf;
  2721.    struct dirent *ent;
  2722.    struct tm ltm;
  2723.  
  2724. #if defined(__OS2__)
  2725.    HAB hab;
  2726.    HMQ hmq;
  2727. #endif
  2728.  
  2729.    Args = Args;
  2730.    EventsTimer = 0L;
  2731.  
  2732. #if defined(__OS2__)
  2733.    hab = WinInitialize (0);
  2734.    if ((hmq = WinCreateMsgQueue (hab, 0)) != NULL)
  2735.       WinCancelShutdown (hmq, TRUE);
  2736.    DosExitCritSec ();
  2737. //   DosSetPriority ((USHORT)1, (USHORT)0, (SHORT)31, (USHORT)0);
  2738. #endif
  2739.  
  2740.    for (;;) {
  2741.       if (Status != OldStatus) {
  2742.          OldStatus = Status;
  2743. //         if (Status != UNDEFINED)
  2744. //            Log->Write ("> DEBUG: Status=%d (%s)", Status, statusText[Status]);
  2745.          EventsTimer = 0L;
  2746.          CallTimer = 0L;
  2747.       }
  2748.       if (Status == WAITFORCALL) {
  2749.          //////////////////////////////////////////////////////////////////
  2750.          // Controlla se ci sono eventi da eseguire.                     //
  2751.          //////////////////////////////////////////////////////////////////
  2752.          if (TimeUp (EventsTimer)) {
  2753.             Found = DoCall = FALSE;
  2754.             Address.Clear ();
  2755.  
  2756.             Events->TimeToNext ();
  2757.             if (Events->NextNumber != 0) {
  2758.                if ((p = (CHAR *)malloc (128)) != NULL) {
  2759.                   sprintf (p, "Event %d starts in %d minute(s)", Events->NextNumber, Events->TimeRemain);
  2760. #if defined(__OS2__)
  2761.                   WinSendMsg (hwndMainClient, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 0), MPFROMP (p));
  2762. #elif defined(__NT__)
  2763.                   SendMessage (hwndMainClient, WM_USER, (WPARAM)WMU_SETSTATUSLINE0, (LPARAM)p);
  2764. #elif defined(__DOS__)
  2765.                   prints (22, 2, WHITE|_BLACK, p);
  2766. #endif
  2767.                   free (p);
  2768.                }
  2769.  
  2770.                Events->First ();
  2771.                for (i = 1; i < Events->NextNumber; i++)
  2772.                   Events->Next ();
  2773.  
  2774.                if ((p = (CHAR *)malloc (128)) != NULL) {
  2775.                   strcpy (p, "Flags for next event:");
  2776.                   if (Events->MailOnly == FALSE)
  2777.                      strcat (p, " B");
  2778.                   if (Events->SendNormal == FALSE && Events->SendCrash == FALSE && Events->SendDirect == FALSE && Events->SendImmediate == FALSE)
  2779.                      strcat (p, " R");
  2780.                   if (Events->Force == TRUE)
  2781.                      strcat (p, " F");
  2782.                   if (Events->SendCrash == TRUE)
  2783.                      strcat (p, " C");
  2784.                   if (Events->SendDirect == TRUE)
  2785.                      strcat (p, " D");
  2786.                   if (Events->SendImmediate == TRUE)
  2787.                      strcat (p, " I");
  2788.                   if (Events->AllowRequests == FALSE)
  2789.                      strcat (p, " N");
  2790.                   if (Events->Dynamic == TRUE)
  2791.                      strcat (p, " Y");
  2792.                   if (Events->ForceCall == TRUE) {
  2793.                      strcat (p, " P=");
  2794.                      strcat (p, Events->Address);
  2795.                   }
  2796. #if defined(__OS2__)
  2797.                   WinSendMsg (hwndMainClient, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 1), MPFROMP (p));
  2798. #elif defined(__NT__)
  2799.                   SendMessage (hwndMainClient, WM_USER, (WPARAM)WMU_SETSTATUSLINE1, (LPARAM)p);
  2800. #elif defined(__DOS__)
  2801.                   prints (23, 2, WHITE|_BLACK, p);
  2802. #endif
  2803.                   free (p);
  2804.                }
  2805.             }
  2806.  
  2807.             DoEvent = FALSE;
  2808.  
  2809.             if (Events->First () == TRUE)
  2810.                do {
  2811.                   if (Events->Dynamic == TRUE && Events->Completed == FALSE) {
  2812.                      if (Outbound->FirstNode () == TRUE)
  2813.                         do {
  2814.                            if (Events->SendCrash == TRUE && Outbound->Crash == TRUE)
  2815.                               DoEvent = TRUE;
  2816.                            if (Events->SendDirect == TRUE && Outbound->Direct == TRUE)
  2817.                               DoEvent = TRUE;
  2818.                            if (Events->SendNormal == TRUE && Outbound->Normal == TRUE)
  2819.                               DoEvent = TRUE;
  2820.                            if (Events->SendImmediate == TRUE && Outbound->Immediate == TRUE)
  2821.                               DoEvent = TRUE;
  2822.                            if (Events->MaxCalls != 0 && Outbound->Attempts >= Events->MaxCalls)
  2823.                               DoEvent = FALSE;
  2824.                            else if (Events->MaxConnects != 0 && Outbound->Failed >= Events->MaxConnects)
  2825.                               DoEvent = FALSE;
  2826.                         } while (Outbound->NextNode () == TRUE);
  2827.  
  2828.                      if (DoEvent == TRUE) {
  2829.                         t = time (NULL);
  2830.                         memcpy (<m, localtime (&t), sizeof (struct tm));
  2831.                         if (Events->LastDay != ltm.tm_yday)
  2832.                            DoEvent = FALSE;
  2833.                      }
  2834.  
  2835.                      if (DoEvent == TRUE)
  2836.                         break;
  2837.  
  2838.                      Events->Completed = TRUE;
  2839.                      Events->Update ();
  2840.                   }
  2841.                } while (Events->Next () == TRUE);
  2842.  
  2843.             if (DoEvent == FALSE)
  2844.                DoEvent = Events->SetCurrent ();
  2845.  
  2846.             if (DoEvent == TRUE) {
  2847.                if (Events->Started == TRUE) {
  2848.                   if (Log != NULL) {
  2849.                      if (Events->Label[0] != '\0')
  2850.                         Log->Write (":Starting Event %d - %s", Events->Number, Events->Label);
  2851.                      else
  2852.                         Log->Write (":Starting Event %d", Events->Number);
  2853.                   }
  2854.  
  2855.                   if (Events->Command[0] != '\0') {
  2856.                      Log->Write ("#Executing %s", Events->Command);
  2857.                      Log->Suspend ();
  2858.                      RunExternal (Events->Command);
  2859.                      Log->Resume ();
  2860.                   }
  2861.  
  2862.                   if (Events->StartImport == TRUE && Events->StartExport == TRUE && Cfg->UseSinglePass == TRUE) {
  2863.                      Log->Write ("#Executing %s", Cfg->SinglePassCmd);
  2864.                      Log->Suspend ();
  2865.                      RunExternal (Cfg->SinglePassCmd);
  2866.                      Log->Resume ();
  2867.                      Log->Write ("#Executing %s", Cfg->PackCmd);
  2868.                      Log->Suspend ();
  2869.                      RunExternal (Cfg->PackCmd);
  2870.                      Log->Resume ();
  2871.                   }
  2872.                   else {
  2873.                      if (Events->StartImport == TRUE) {
  2874.                         if (Events->ImportNormal == TRUE || Events->ImportProtected == TRUE || Events->ImportKnown == TRUE) {
  2875.                            Log->Write ("#Executing %s", Cfg->ImportCmd);
  2876.                            Log->Suspend ();
  2877.                            RunExternal (Cfg->ImportCmd);
  2878.                            Log->Resume ();
  2879.                         }
  2880.                      }
  2881.                      if (Events->StartExport == TRUE) {
  2882.                         if (Cfg->SeparateNetMail == TRUE) {
  2883.                            Log->Write ("#Executing %s", Cfg->PackCmd);
  2884.                            Log->Suspend ();
  2885.                            RunExternal (Cfg->PackCmd);
  2886.                            Log->Resume ();
  2887.                         }
  2888.                         Log->Write ("#Executing %s", Cfg->ExportCmd);
  2889.                         Log->Suspend ();
  2890.                         RunExternal (Cfg->ExportCmd);
  2891.                         Log->Resume ();
  2892.                         Log->Write ("#Executing %s", Cfg->PackCmd);
  2893.                         Log->Suspend ();
  2894.                         RunExternal (Cfg->PackCmd);
  2895.                         Log->Resume ();
  2896.                      }
  2897.                   }
  2898.  
  2899.                   if (Events->ForceCall == TRUE && Events->Address[0] != '\0') {
  2900.                      if ((Out = new TOutbound (Cfg->Outbound)) != NULL) {
  2901.                         Cfg->MailAddress.First ();
  2902.                         Out->DefaultZone = Cfg->MailAddress.Zone;
  2903.  
  2904.                         Address.Parse (Events->Address);
  2905.                         if (Cfg->MailAddress.First () == TRUE) {
  2906.                            if (Address.Zone == 0)
  2907.                               Address.Zone = Cfg->MailAddress.Zone;
  2908.                            if (Address.Net == 0)
  2909.                               Address.Net = Cfg->MailAddress.Net;
  2910.                         }
  2911.                         Out->Add (Address.Zone, Address.Net, Address.Node, Address.Point);
  2912.  
  2913.                         Out->New ();
  2914.                         Out->Zone = Address.Zone;
  2915.                         Out->Net = Address.Net;
  2916.                         Out->Node = Address.Node;
  2917.                         Out->Point = Address.Point;
  2918.                         Out->Poll = TRUE;
  2919.                         Out->Crash = Events->SendCrash;
  2920.                         Out->Direct = Events->SendDirect;
  2921.                         Out->Normal = Events->SendNormal;
  2922.                         Out->Immediate = Events->SendImmediate;
  2923.                         Out->Add ();
  2924.                         Out->Update ();
  2925.  
  2926.                         delete Out;
  2927.                      }
  2928.                   }
  2929.  
  2930.                   if (Log != NULL)
  2931.                      Log->Write ("+Building the outbound queue");
  2932.                   Outbound->BuildQueue (Cfg->Outbound);
  2933.                   unlink ("rescan.now");
  2934.                   if (Log != NULL)
  2935.                      Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  2936. #if defined(__OS2__)
  2937.                   WinSendMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  2938. #elif defined(__NT__)
  2939.                   SendMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  2940. #endif
  2941.                   CallTimer = 0L;
  2942.  
  2943.                   Events->Save ();
  2944.                }
  2945.             }
  2946.  
  2947.             if (stat ("rescan.now", &statbuf) == 0) {
  2948.                if (Log != NULL)
  2949.                   Log->Write ("+Building the outbound queue");
  2950.                Outbound->BuildQueue (Cfg->Outbound);
  2951.                unlink ("rescan.now");
  2952.                if (Log != NULL)
  2953.                   Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  2954.                CallTimer = 0L;
  2955.             }
  2956.  
  2957.             if ((dir = opendir (".")) != NULL) {
  2958.                sprintf (Temp, "lexit%d", Cfg->TaskNumber);
  2959.                while ((ent = readdir (dir)) != NULL) {
  2960.                   if ((p = strchr (ent->d_name, '.')) != NULL) {
  2961.                      *p++ = '\0';
  2962.                      if (!stricmp (ent->d_name, Temp)) {
  2963.                         ErrorLevel = (UCHAR)atoi (p);
  2964.                         Status = BBSEXIT;
  2965.                         if (Log != NULL)
  2966.                            Log->Write (":Exit with errorlevel %d", ErrorLevel);
  2967.                         break;
  2968.                      }
  2969.                   }
  2970.                }
  2971.                closedir (dir);
  2972.             }
  2973.  
  2974.             EventsTimer = TimerSet (1000L);
  2975.          }
  2976.  
  2977.          if (CallTimer == 0L)
  2978.             CallTimer = TimerSet ((ULONG)Events->CallDelay * 100L);
  2979.  
  2980.          //////////////////////////////////////////////////////////////////
  2981.          // Controlla se c'e' un poll da eseguire.                       //
  2982.          //////////////////////////////////////////////////////////////////
  2983.          if (TimeUp (CallTimer)) {
  2984.             DoCall = FALSE;
  2985.             Address.Clear ();
  2986.  
  2987.             if (Outbound != NULL && Outbound->TotalNodes > 0) {
  2988.                // Verifica se l'evento corrente e' riservato per il poll verso un
  2989.                // certo nodo.
  2990.                if (Events->Address[0] != '\0') {
  2991.                   Address.Parse (Events->Address);
  2992.                   if (Cfg->MailAddress.First () == TRUE) {
  2993.                      if (Address.Zone == 0)
  2994.                         Address.Zone = Cfg->MailAddress.Zone;
  2995.                      if (Address.Net == 0)
  2996.                         Address.Net = Cfg->MailAddress.Net;
  2997.                      Address.Add ();
  2998.                      Address.First ();
  2999.                   }
  3000.                   // Cerca il nodo nel database di outbound e se lo trova lo marca
  3001.                   // immediatamente per il poll.
  3002.                   DoCall = FALSE;
  3003.                   if (Outbound->FirstNode () == TRUE)
  3004.                      do {
  3005.                         if (Outbound->Zone == Address.Zone && Outbound->Net == Address.Net && Outbound->Node == Address.Node && Outbound->Point == Address.Point) {
  3006.                            strcpy (PollNode, Address.String);
  3007.                            DoCall = TRUE;
  3008.                            break;
  3009.                         }
  3010.                      } while (Outbound->NextNode () == TRUE);
  3011.                }
  3012.  
  3013.                // L'evento corrente non e' riservato ad un nodo.
  3014.                if (Events->Address[0] == '\0') {
  3015.                   Address.Clear ();
  3016.                   // Verifica se c'e' gia' stata una chiamata, nel qual caso si posiziona
  3017.                   // sull'entry di quel nodo e comincia la ricerca dal nodo sucessivo (se
  3018.                   // esiste oppure dal primo.
  3019.                   if (PollNode[0] != '\0') {
  3020.                      Address.Clear ();
  3021.                      Address.Parse (PollNode);
  3022.                      if (Cfg->MailAddress.First () == TRUE) {
  3023.                         if (Address.Zone == 0)
  3024.                            Address.Zone = Cfg->MailAddress.Zone;
  3025.                         if (Address.Net == 0)
  3026.                            Address.Net = Cfg->MailAddress.Net;
  3027.                         Address.Add ();
  3028.                         Address.First ();
  3029.                      }
  3030.                      Found = FALSE;
  3031.                      if (Outbound->FirstNode () == TRUE)
  3032.                         do {
  3033.                            if (Outbound->Zone == Address.Zone && Outbound->Net == Address.Net && Outbound->Node == Address.Node && Outbound->Point == Address.Point) {
  3034.                               if (Outbound->NextNode () == TRUE)
  3035.                                  Found = TRUE;
  3036.                               break;
  3037.                            }
  3038.                         } while (Outbound->NextNode () == TRUE);
  3039.                      if (Found == FALSE)
  3040.                         Outbound->FirstNode ();
  3041.                   }
  3042.                   else
  3043.                      Outbound->FirstNode ();
  3044.  
  3045.                   // Verifica i flag di chiamata
  3046.                   DoCall = FALSE;
  3047.                   if (Events->SendCrash == TRUE && Outbound->Crash == TRUE)
  3048.                      DoCall = TRUE;
  3049.                   if (Events->SendDirect == TRUE && Outbound->Direct == TRUE)
  3050.                      DoCall = TRUE;
  3051.                   if (Events->SendNormal == TRUE && Outbound->Normal == TRUE)
  3052.                      DoCall = TRUE;
  3053.                   if (Events->SendImmediate == TRUE && Outbound->Immediate == TRUE)
  3054.                      DoCall = TRUE;
  3055.                   if (Events->MaxCalls != 0 && Outbound->Attempts >= Events->MaxCalls)
  3056.                      DoCall = FALSE;
  3057.                   else if (Events->MaxConnects != 0 && Outbound->Failed >= Events->MaxConnects)
  3058.                      DoCall = FALSE;
  3059.                   if (DoCall == TRUE) {
  3060.                      if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  3061.                         if (Nodes->Read (Outbound->Address) == FALSE)
  3062.                            DoCall = FALSE;
  3063.                         strupr (Nodes->Flags);
  3064.  
  3065.                         // Verifica i flags con i quali puo' chiamare
  3066.                         if (Cfg->CallIf[0] != '\0' && DoCall == TRUE) {
  3067.                            strcpy (Temp, Cfg->CallIf);
  3068.                            DoCall = FALSE;
  3069.                            if ((p = strtok (strupr (Temp), " ,")) != NULL)
  3070.                               do {
  3071.                                  if (strstr (Nodes->Flags, p) != NULL)
  3072.                                     DoCall = TRUE;
  3073.                               } while ((p = strtok (NULL, " ,")) != NULL);
  3074.                         }
  3075.  
  3076.                         // Verifica i flags con i quali non puo' chiamare
  3077.                         if (Cfg->DontCallIf[0] != '\0' && DoCall == TRUE) {
  3078.                            strcpy (Temp, Cfg->DontCallIf);
  3079.                            DoCall = TRUE;
  3080.                            if ((p = strtok (strupr (Temp), " ,")) != NULL)
  3081.                               do {
  3082.                                  if (strstr (Nodes->Flags, p) != NULL)
  3083.                                     DoCall = FALSE;
  3084.                               } while ((p = strtok (NULL, " ,")) != NULL);
  3085.                         }
  3086.  
  3087.                         delete Nodes;
  3088.                      }
  3089.                   }
  3090.                }
  3091.  
  3092.                if (DoCall == FALSE) {
  3093.                   while (Outbound->NextNode () == TRUE) {
  3094.                      if (Events->SendCrash == TRUE && Outbound->Crash == TRUE)
  3095.                         DoCall = TRUE;
  3096.                      if (Events->SendDirect == TRUE && Outbound->Direct == TRUE)
  3097.                         DoCall = TRUE;
  3098.                      if (Events->SendNormal == TRUE && Outbound->Normal == TRUE)
  3099.                         DoCall = TRUE;
  3100.                      if (Events->SendImmediate == TRUE && Outbound->Immediate == TRUE)
  3101.                         DoCall = TRUE;
  3102.                      if (Events->MaxCalls != 0 && Outbound->Attempts >= Events->MaxCalls)
  3103.                         DoCall = FALSE;
  3104.                      else if (Events->MaxConnects != 0 && Outbound->Failed >= Events->MaxConnects)
  3105.                         DoCall = FALSE;
  3106.                      if (DoCall == TRUE) {
  3107.                         if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  3108.                            if (Nodes->Read (Outbound->Address) == FALSE)
  3109.                               DoCall = FALSE;
  3110.                            strupr (Nodes->Flags);
  3111.  
  3112.                            // Verifica i flags con i quali puo' chiamare
  3113.                            if (Cfg->CallIf[0] != '\0' && DoCall == TRUE) {
  3114.                               strcpy (Temp, Cfg->CallIf);
  3115.                               DoCall = FALSE;
  3116.                               if ((p = strtok (strupr (Temp), " ,")) != NULL)
  3117.                                  do {
  3118.                                     if (strstr (Nodes->Flags, p) != NULL)
  3119.                                        DoCall = TRUE;
  3120.                                  } while ((p = strtok (NULL, " ,")) != NULL);
  3121.                            }
  3122.  
  3123.                            // Verifica i flags con i quali non puo' chiamare
  3124.                            if (Cfg->DontCallIf[0] != '\0' && DoCall == TRUE) {
  3125.                               strcpy (Temp, Cfg->DontCallIf);
  3126.                               DoCall = TRUE;
  3127.                               if ((p = strtok (strupr (Temp), " ,")) != NULL)
  3128.                                  do {
  3129.                                     if (strstr (Nodes->Flags, p) != NULL)
  3130.                                        DoCall = FALSE;
  3131.                                  } while ((p = strtok (NULL, " ,")) != NULL);
  3132.                            }
  3133.  
  3134.                            delete Nodes;
  3135.                         }
  3136.                      }
  3137.                      if (DoCall == TRUE)
  3138.                         break;
  3139.                   }
  3140.                }
  3141.  
  3142.                if (DoCall == TRUE) {
  3143.                   strcpy (PollNode, Outbound->Address);
  3144.                   strcpy (Modem->NodelistPath, Cfg->NodelistPath);
  3145.                   strcpy (Modem->DialCmd, Cfg->Dial);
  3146.                   Modem->Poll (PollNode);
  3147.                   Status = WAITFORCONNECT;
  3148.                   TimeOut = TimerSet ((ULONG)Cfg->DialTimeout * 100L);
  3149.                }
  3150.                else
  3151.                   PollNode[0] = '\0';
  3152.             }
  3153.  
  3154.             CallTimer = 0L;
  3155.          }
  3156.       }
  3157.  
  3158. #if defined(__OS2__)
  3159.       DosSleep (1L);
  3160. #elif defined(__NT__)
  3161.       Sleep (1L);
  3162. #endif
  3163.    }
  3164.  
  3165. /*
  3166. #if defined(__OS2__)
  3167.    if (hmq != NULL)
  3168.       WinDestroyMsgQueue (hmq);
  3169.    WinTerminate (hab);
  3170. #endif
  3171.  
  3172. #if defined(__OS2__) || defined(__NT__)
  3173.    _endthread ();
  3174. #endif
  3175. */
  3176. }
  3177.  
  3178. USHORT ProcessSimpleDialog (HWND hwnd, USHORT id)
  3179. {
  3180.    USHORT RetVal = FALSE;
  3181. #if !defined(__POINT__)
  3182.    class CDialog *Dlg = NULL;
  3183.  
  3184.    switch (id) {
  3185.       case 107:      // System / File request
  3186.          Dlg = new CRequestDlg (hwnd);
  3187.          RetVal = TRUE;
  3188.          break;
  3189.       case 108:      // System / File attach
  3190.          Dlg = new CAttachDlg (hwnd);
  3191.          RetVal = TRUE;
  3192.          break;
  3193.       case 111:      // System / Request ECHOmail Link
  3194.          Dlg = new CRequestEchoLinkDlg (hwnd);
  3195.          RetVal = TRUE;
  3196.          break;
  3197.       case 112:      // System / New ECHOmail Link
  3198.          Dlg = new CNewEchoLinkDlg (hwnd);
  3199.          RetVal = TRUE;
  3200.          break;
  3201.       case 113:      // System / Rescan ECHOmail
  3202.          Dlg = new CRescanDlg (hwnd);
  3203.          RetVal = TRUE;
  3204.          break;
  3205.       case 305:      // Mailer / File requests
  3206.          Dlg = new COkFileDlg (hwnd);
  3207.          RetVal = TRUE;
  3208.          break;
  3209.       case 402:      // BBS / Message Areas
  3210.          Dlg = new CMessageDlg (hwnd);
  3211.          RetVal = TRUE;
  3212.          break;
  3213.       case 403:      // BBS / File Areas
  3214.          Dlg = new CFileDlg (hwnd);
  3215.          RetVal = TRUE;
  3216.          break;
  3217.       case 406:      // BBS / User Levels
  3218.          Dlg = new CLimitsDlg (hwnd);
  3219.          RetVal = TRUE;
  3220.          break;
  3221.       case 409:      // BBS / External Protocols
  3222.          Dlg = new CProtocolDlg (hwnd);
  3223.          RetVal = TRUE;
  3224.          break;
  3225.       case 602:      // Manager / Compressors
  3226.          Dlg = new CPackerDlg (hwnd);
  3227.          RetVal = TRUE;
  3228.          break;
  3229.       case 603:
  3230.          Dlg = new CMenuDlg (hwnd);
  3231.          RetVal = TRUE;
  3232.          break;
  3233.       case 604:      // Manager / Nodes
  3234.          Dlg = new CNodesDlg (hwnd);
  3235.          RetVal = TRUE;
  3236.          break;
  3237.       case 605:      // Manager / User editor
  3238.          Dlg = new CUserDlg (hwnd);
  3239.          RetVal = TRUE;
  3240.          break;
  3241.       case 606:      // Manager / Nodelist
  3242.          Dlg = new CNodelistDlg (hwnd);
  3243.          RetVal = TRUE;
  3244.          break;
  3245.       case 607:      // Manager / Origin Lines
  3246.          Dlg = new COriginDlg (hwnd);
  3247.          RetVal = TRUE;
  3248.          break;
  3249.       case 608:      // Manager / Translations
  3250.          Dlg = new CTranslationDlg (hwnd);
  3251.          RetVal = TRUE;
  3252.          break;
  3253.    }
  3254.  
  3255.    if (Dlg != NULL) {
  3256.       Dlg->DoModal ();
  3257.       delete Dlg;
  3258.    }
  3259. #endif
  3260.  
  3261.    return (RetVal);
  3262. }
  3263.  
  3264. USHORT ProcessSaveDialog (HWND hwnd, USHORT id)
  3265. {
  3266.    USHORT RetVal = FALSE;
  3267. #if !defined(__POINT__)
  3268.    class CDialog *Dlg = NULL;
  3269.  
  3270.    switch (id) {
  3271.       case 202:      // Global / Site Informations
  3272.          Dlg = new CSiteInfoDlg (hwnd);
  3273.          RetVal = TRUE;
  3274.          break;
  3275.       case 204:      // Global / Address
  3276.          Dlg = new CAddressDlg (hwnd);
  3277.          RetVal = TRUE;
  3278.          break;
  3279.       case 206:      // Global / Internet Options
  3280.          Dlg = new CInternetDlg (hwnd);
  3281.          RetVal = TRUE;
  3282.          break;
  3283.       case 207:      // Global / Fax Options
  3284.          Dlg = new CFaxOptDlg (hwnd);
  3285.          RetVal = TRUE;
  3286.          break;
  3287.       case 208:      // Global / Directories - Paths
  3288.          Dlg = new CDirectoriesDlg (hwnd);
  3289.          RetVal = TRUE;
  3290.          break;
  3291.       case 302:      // Mailer / Mail processing
  3292.          Dlg = new CMailprocDlg (hwnd);
  3293.          RetVal = TRUE;
  3294.          break;
  3295.       case 303:      // Mailer / Areafix
  3296.          Dlg = new CAreafixDlg (hwnd);
  3297.          RetVal = TRUE;
  3298.          break;
  3299.       case 304:      // Mailer / Raid
  3300.          Dlg = new CRaidDlg (hwnd);
  3301.          RetVal = TRUE;
  3302.          break;
  3303.       case 306:      // Mailer / External processing
  3304.          Dlg = new CExternalDlg (hwnd);
  3305.          RetVal = TRUE;
  3306.          break;
  3307.       case 308:      // Mailer / Miscellaneous
  3308.          Dlg = new CMiscDlg (hwnd);
  3309.          RetVal = TRUE;
  3310.          break;
  3311.       case 404:      // BBS / Offline Reader
  3312.          Dlg = new COfflineDlg (hwnd);
  3313.          RetVal = TRUE;
  3314.          break;
  3315.       case 405:      // BBS / New Users
  3316.          Dlg = new CNewUserDlg (hwnd);
  3317.          RetVal = TRUE;
  3318.          break;
  3319.       case 411:      // BBS / General options
  3320.          Dlg = new CBBSGeneralDlg (hwnd);
  3321.          RetVal = TRUE;
  3322.          break;
  3323.       case 504:      // Modem / Answer control
  3324.          Dlg = new CAnswerDlg (hwnd);
  3325.          RetVal = TRUE;
  3326.          break;
  3327.       case 505:      // Modem / Nodelist flags
  3328.          Dlg = new CNodeFlagsDlg (hwnd);
  3329.          RetVal = TRUE;
  3330.          break;
  3331.    }
  3332.  
  3333.    if (Dlg != NULL) {
  3334.       if (Dlg->DoModal () == TRUE) {
  3335.          Cfg->Save ();
  3336.          if (Cfg->MailAddress.First () == TRUE)
  3337.             Outbound->DefaultZone = Cfg->MailAddress.Zone;
  3338.       }
  3339.       delete Dlg;
  3340.    }
  3341. #endif
  3342.  
  3343.    return (RetVal);
  3344. }
  3345.  
  3346. VOID WinHelp (PSZ help_file, int topic_id, PSZ title)
  3347. {
  3348.    CHAR helpFile[128];
  3349.  
  3350.    getcwd (helpFile, sizeof (helpFile) - 1);
  3351.    if (helpFile[strlen (helpFile) - 1] != '\\')
  3352.       strcat (helpFile, "\\");
  3353.    strcat (helpFile, help_file);
  3354.  
  3355. #if defined(__OS2__)
  3356.    CHAR *p;
  3357.    HELPINIT hini;
  3358.  
  3359.    if ((p = strchr (helpFile, '>')) != NULL)
  3360.       *p = '\0';
  3361.  
  3362.    if (help_hWnd == NULL) {
  3363.       hini.cb = sizeof (HELPINIT);
  3364.       hini.ulReturnCode = 0L;
  3365.       hini.pszTutorialName = NULL;
  3366.       hini.phtHelpTable = (PHELPTABLE)MAKELONG (1, 0xFFFF);
  3367.       hini.hmodHelpTableModule = NULL;
  3368.       hini.hmodAccelActionBarModule = NULL;
  3369.       hini.idAccelTable = 0;
  3370.       hini.idActionBar = 0;
  3371.       hini.pszHelpWindowTitle = title;
  3372.       hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  3373.       hini.pszHelpLibraryName = helpFile;
  3374.       if ((help_hWnd = WinCreateHelpInstance (hab, &hini)) != NULL)
  3375.          WinAssociateHelpInstance (help_hWnd, hwndMainFrame);
  3376.    }
  3377.    if (help_hWnd != NULL) {
  3378.       if (topic_id == HM_HELP_CONTENTS)
  3379.          WinSendMsg (help_hWnd, HM_HELP_CONTENTS, 0L, 0L);
  3380.       else if (topic_id == HM_GENERAL_HELP)
  3381.          WinSendMsg (help_hWnd, HM_GENERAL_HELP, 0L, 0L);
  3382.       else if (topic_id == HM_DISPLAY_HELP)
  3383.          WinSendMsg (help_hWnd, HM_DISPLAY_HELP, 0L, 0L);
  3384.       else
  3385.          WinSendMsg (help_hWnd, HM_DISPLAY_HELP, MPFROM2SHORT (topic_id, 0), MPFROMSHORT (HM_RESOURCEID));
  3386.    }
  3387.  
  3388. #elif defined(__NT__)
  3389.    title = title;
  3390.    ::WinHelp (hwndMainClient, helpFile, HELP_CONTEXT, topic_id);
  3391. #endif
  3392. }
  3393.  
  3394. VOID OutboundDetails (HWND hwnd)
  3395. {
  3396.    USHORT i;
  3397.    CHAR Temp[128], *p;
  3398.    class CDetailsDlg *Dlg;
  3399.  
  3400. #if defined(__OS2__)
  3401.    i = (USHORT)WinSendDlgItemMsg (hwnd, 1004, LM_QUERYSELECTION, MPFROMSHORT (LIT_FIRST), 0L);
  3402.    WinSendDlgItemMsg (hwnd, 1004, LM_QUERYITEMTEXT, MPFROM2SHORT (i, sizeof (Temp) - 1), MPFROMP (Temp));
  3403. #elif defined(__NT__)
  3404.    i = (USHORT)SendDlgItemMessage (hwnd, 1004, LB_GETCURSEL, 0, 0L);
  3405.    SendDlgItemMessage (hwnd, 1004, LB_GETTEXT, (WPARAM)i, (LPARAM)Temp);
  3406. #endif
  3407.  
  3408.    if ((p = strtok (Temp, " ")) != NULL) {
  3409.       if (Outbound->FirstNode () == TRUE)
  3410.          do {
  3411.             if (!strcmp (Outbound->Address, p)) {
  3412.                if ((Dlg = new CDetailsDlg (hwnd)) != NULL) {
  3413.                   strcpy (Dlg->Address, p);
  3414.                   Dlg->DoModal ();
  3415.                   if (Dlg->DoRebuild == TRUE) {
  3416.                      Outbound->BuildQueue (Cfg->Outbound);
  3417.                      unlink ("rescan.now");
  3418. #if defined(__OS2__)
  3419.                      WinPostMsg (hwnd, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  3420. #elif defined(__NT__)
  3421.                      PostMessage (hwnd, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  3422. #endif
  3423.                   }
  3424.                   delete Dlg;
  3425.                }
  3426.                break;
  3427.             }
  3428.          } while (Outbound->NextNode () == TRUE);
  3429.    }
  3430. }
  3431.  
  3432. #if defined(__OS2__)
  3433. MRESULT EXPENTRY MainWinProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3434. #elif defined(__NT__)
  3435. LRESULT CALLBACK MainWinProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  3436. #endif
  3437. {
  3438.    switch (msg) {
  3439.       case WM_CREATE: {
  3440.          CHAR Temp[128];
  3441. #if defined(__OS2__)
  3442.          HWND hwndMainList, hwndMainModem, hwndMainStatus, hwndMainOutbound;
  3443.          ULONG Value;
  3444.  
  3445.          if ((hwndMainList = WinCreateWindow (hwnd, WC_LISTBOX, NULL, LS_NOADJUSTPOS|LS_HORZSCROLL|WS_GROUP|WS_TABSTOP|WS_VISIBLE, 0, 0, 0, 0, hwnd, HWND_TOP, 1001, NULL, NULL)) != NULLHANDLE) {
  3446.             WinSetPresParam (hwndMainList, PP_FONTNAMESIZE, 14, "11.System VIO");
  3447.             Value = 0x000070L;
  3448.             WinSetPresParam (hwndMainList, PP_BACKGROUNDCOLOR, 4, &Value);
  3449.             Value = 0xFFFFFFL;
  3450.             WinSetPresParam (hwndMainList, PP_FOREGROUNDCOLOR, 4, &Value);
  3451.          }
  3452.          if ((hwndMainModem = WinCreateWindow (hwnd, WC_LISTBOX, NULL, LS_NOADJUSTPOS|WS_GROUP|WS_TABSTOP|WS_VISIBLE, 0, 0, 0, 0, hwnd, HWND_TOP, 1002, NULL, NULL)) != NULLHANDLE) {
  3453.             WinSetPresParam (hwndMainModem, PP_FONTNAMESIZE, 14, "11.System VIO");
  3454.             Value = 0x000000L;
  3455.             WinSetPresParam (hwndMainModem, PP_BACKGROUNDCOLOR, 4, &Value);
  3456.             Value = 0xFFFFFFL;
  3457.             WinSetPresParam (hwndMainModem, PP_FOREGROUNDCOLOR, 4, &Value);
  3458.          }
  3459.          if ((hwndMainOutbound = WinCreateWindow (hwnd, WC_LISTBOX, NULL, LS_NOADJUSTPOS|WS_GROUP|WS_TABSTOP|WS_VISIBLE, 0, 0, 0, 0, hwnd, HWND_TOP, 1004, NULL, NULL)) != NULLHANDLE) {
  3460.             WinSetPresParam (hwndMainOutbound, PP_FONTNAMESIZE, 14, "11.System VIO");
  3461.             Value = 0xFFFFFFL;
  3462.          }
  3463.          if ((hwndMainStatus = WinCreateWindow (hwnd, WC_LISTBOX, NULL, LS_NOADJUSTPOS|WS_GROUP|WS_TABSTOP|WS_VISIBLE, 0, 0, 0, 0, hwnd, HWND_TOP, 1003, NULL, NULL)) != NULLHANDLE) {
  3464.             WinSetPresParam (hwndMainStatus, PP_FONTNAMESIZE, 14, "11.System VIO");
  3465.             Value = 0xFFFFFFL;
  3466.             WinSetPresParam (hwndMainStatus, PP_BACKGROUNDCOLOR, 4, &Value);
  3467.             Value = 0x000000L;
  3468.             WinSetPresParam (hwndMainStatus, PP_FOREGROUNDCOLOR, 4, &Value);
  3469.             WinSendMsg (hwndMainStatus, LM_INSERTITEM, MPFROMSHORT (LIT_END), (MPARAM)"");
  3470.             WinSendMsg (hwndMainStatus, LM_INSERTITEM, MPFROMSHORT (LIT_END), (MPARAM)"");
  3471.          }
  3472.  
  3473. #elif defined(__NT__)
  3474.          LOGFONT logFont;
  3475.          HFONT hFont;
  3476.  
  3477.          logFont.lfHeight = 12;
  3478.          logFont.lfWidth = 8;
  3479.          logFont.lfEscapement = 0;
  3480.          logFont.lfOrientation = 0;
  3481.          logFont.lfWeight = FW_NORMAL;
  3482.          logFont.lfItalic = FALSE;
  3483.          logFont.lfUnderline = FALSE;
  3484.          logFont.lfStrikeOut = FALSE;
  3485.          logFont.lfCharSet = OEM_CHARSET;
  3486.          logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
  3487.          logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  3488.          logFont.lfQuality = DEFAULT_QUALITY;
  3489.          logFont.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
  3490.          strcpy (logFont.lfFaceName, "Fixedsys");
  3491.          hFont = CreateFontIndirect (&logFont);
  3492.  
  3493.          if ((hwndMainList = CreateWindow ("LISTBOX", "", LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_CHILD|WS_VSCROLL|WS_HSCROLL, 0, 0, 100, 50, hwnd, (HMENU)1001, hinst, NULL)) != NULL) {
  3494.             if (hFont != NULL)
  3495.                SendMessage (hwndMainList, WM_SETFONT, (WPARAM)hFont, MAKELPARAM (FALSE, 0));
  3496.             ShowWindow (hwndMainList, SW_SHOW);
  3497.          }
  3498.  
  3499.          if ((hwndModemList = CreateWindow ("LISTBOX", "", LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_CHILD|WS_VSCROLL, 0, 0, 100, 50, hwnd, (HMENU)1002, hinst, NULL)) != NULL) {
  3500.             if (hFont != NULL)
  3501.                SendMessage (hwndModemList, WM_SETFONT, (WPARAM)hFont, MAKELPARAM (FALSE, 0));
  3502.             ShowWindow (hwndModemList, SW_SHOW);
  3503.          }
  3504.  
  3505.          if ((hwndOutboundList = CreateWindow ("LISTBOX", "", LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_CHILD|WS_VSCROLL, 0, 0, 100, 50, hwnd, (HMENU)1004, hinst, NULL)) != NULL) {
  3506.             if (hFont != NULL)
  3507.                SendMessage (hwndOutboundList, WM_SETFONT, (WPARAM)hFont, MAKELPARAM (FALSE, 0));
  3508.             ShowWindow (hwndOutboundList, SW_SHOW);
  3509.          }
  3510.  
  3511.          if ((hwndStatusList = CreateWindow ("LISTBOX", "", LBS_NOSEL|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_CHILD, 0, 0, 100, 50, hwnd, (HMENU)1003, hinst, NULL)) != NULL) {
  3512.             if (hFont != NULL)
  3513.                SendMessage (hwndStatusList, WM_SETFONT, (WPARAM)hFont, MAKELPARAM (FALSE, 0));
  3514.             ShowWindow (hwndStatusList, SW_SHOW);
  3515.          }
  3516. #endif
  3517.          if (hwndMainList != NULL) {
  3518.             if ((Log = new TPMLog (hwnd)) != NULL) {
  3519.                if (Cfg->LogFile[0] == '\0')
  3520.                   sprintf (Temp, "lora%u.log", Cfg->TaskNumber);
  3521.                else
  3522.                   sprintf (Temp, Cfg->LogFile, Cfg->TaskNumber);
  3523.  
  3524.                Log->Open (Temp);
  3525. #if defined(__OS2__)
  3526.                Log->Write ("+Begin, v%s (OS/2)", VERSION);
  3527. #elif defined(__NT__)
  3528.                Log->Write ("+Begin, v%s (Win32)", VERSION);
  3529. #endif
  3530.                Log->Write ("+Message-base sharing is enabled");
  3531.             }
  3532.          }
  3533.          break;
  3534.       }
  3535.  
  3536. #if defined(__NT__)
  3537.       case WM_CTLCOLORLISTBOX: {
  3538.          LOGBRUSH logBrush;
  3539.  
  3540.          if ((HWND)lParam == hwndMainList) {
  3541.             SetTextColor ((HDC)wParam, RGB (0xFF, 0xFF, 0xFF));
  3542.             SetBkMode ((HDC)wParam, TRANSPARENT);
  3543.          }
  3544.          else if ((HWND)lParam == hwndModemList) {
  3545.             SetTextColor ((HDC)wParam, RGB (0xFF, 0xFF, 0xFF));
  3546.             SetBkMode ((HDC)wParam, TRANSPARENT);
  3547.          }
  3548.          else if ((HWND)lParam == hwndStatusList) {
  3549.             SetTextColor ((HDC)wParam, RGB (0x00, 0x00, 0x00));
  3550.             SetBkMode ((HDC)wParam, TRANSPARENT);
  3551.          }
  3552.          else if ((HWND)lParam == hwndOutboundList) {
  3553.             SetTextColor ((HDC)wParam, RGB (0x00, 0x00, 0x00));
  3554.             SetBkMode ((HDC)wParam, TRANSPARENT);
  3555.          }
  3556.  
  3557.          logBrush.lbStyle = BS_SOLID;
  3558.          if ((HWND)lParam == hwndMainList)
  3559.             logBrush.lbColor = RGB (0x00, 0x00, 0x70);
  3560.          else if ((HWND)lParam == hwndModemList)
  3561.             logBrush.lbColor = RGB (0x00, 0x00, 0x00);
  3562.          else if ((HWND)lParam == hwndStatusList)
  3563.             logBrush.lbColor = RGB (0xFF, 0xFF, 0xFF);
  3564.          else if ((HWND)lParam == hwndOutboundList)
  3565.             logBrush.lbColor = RGB (0xD0, 0xD0, 0x80);
  3566.          logBrush.lbHatch = 0;
  3567.  
  3568.          return ((BOOL)CreateBrushIndirect (&logBrush));
  3569.       }
  3570. #endif
  3571.  
  3572.       case WM_USER:
  3573. #if defined(__OS2__)
  3574.          switch (SHORT1FROMMP (mp1)) {
  3575. #elif defined(__NT__)
  3576.          switch (wParam) {
  3577. #endif
  3578.             case WMU_ADDLOGITEM: {
  3579.                USHORT Item;
  3580. #if defined(__OS2__)
  3581.                HWND hwndList;
  3582.  
  3583.                hwndList = WinWindowFromID (hwnd, 1001);
  3584.                if ((USHORT)WinSendMsg (hwndList, LM_QUERYITEMCOUNT, 0L, 0L) > 50)
  3585.                   WinSendMsg (hwndList, LM_DELETEITEM, MPFROMSHORT (0), 0L);
  3586.                Item = (USHORT)WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), mp2);
  3587.                WinSendMsg (hwndList, LM_SELECTITEM, MPFROMSHORT (Item), MPFROMSHORT (TRUE));
  3588. #elif defined(__NT__)
  3589.                if (SendMessage (hwndMainList, LB_GETCOUNT, 0, 0L) > 50)
  3590.                   SendMessage (hwndMainList, LB_DELETESTRING, 0, 0L);
  3591.                Item = (USHORT)SendMessage (hwndMainList, LB_ADDSTRING, 0, lParam);
  3592.                SendMessage (hwndMainList, LB_SETCURSEL, (WPARAM)Item, 0L);
  3593. #endif
  3594.                break;
  3595.             }
  3596.             case WMU_ADDMODEMITEM: {
  3597.                USHORT Item;
  3598. #if defined(__OS2__)
  3599.                HWND hwndList;
  3600.  
  3601.                hwndList = WinWindowFromID (hwnd, 1002);
  3602.                if ((USHORT)WinSendMsg (hwndList, LM_QUERYITEMCOUNT, 0L, 0L) > 50)
  3603.                   WinSendMsg (hwndList, LM_DELETEITEM, MPFROMSHORT (0), 0L);
  3604.                Item = (USHORT)WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), mp2);
  3605.                WinSendMsg (hwndList, LM_SELECTITEM, MPFROMSHORT (Item), MPFROMSHORT (TRUE));
  3606. #elif defined(__NT__)
  3607.                if (SendMessage (hwndModemList, LB_GETCOUNT, 0, 0L) > 50)
  3608.                   SendMessage (hwndModemList, LB_DELETESTRING, 0, 0L);
  3609.                Item = (USHORT)SendMessage (hwndModemList, LB_ADDSTRING, 0, lParam);
  3610.                SendMessage (hwndModemList, LB_SETCURSEL, (WPARAM)Item, 0L);
  3611. #endif
  3612.                break;
  3613.             }
  3614. #if defined(__OS2__)
  3615.             case WMU_SETSTATUSLINE: {
  3616.                USHORT Item;
  3617.                HWND hwndList;
  3618.  
  3619.                hwndList = WinWindowFromID (hwnd, 1003);
  3620.                Item = SHORT2FROMMP (mp1);
  3621.                WinSendMsg (hwndList, LM_SETITEMTEXT, MPFROMSHORT (Item), mp2);
  3622.                break;
  3623.             }
  3624. #elif defined(__NT__)
  3625.             case WMU_SETSTATUSLINE0:
  3626.             case WMU_SETSTATUSLINE1: {
  3627.                USHORT Item;
  3628.  
  3629.                Item = (USHORT)(wParam - WMU_SETSTATUSLINE0);
  3630.                SendMessage (hwndStatusList, LB_DELETESTRING, Item, 0L);
  3631.                SendMessage (hwndStatusList, LB_INSERTSTRING, Item, lParam);
  3632.                break;
  3633.             }
  3634. #endif
  3635.             case WMU_REFRESHOUTBOUND: {
  3636.                CHAR String[128], Flags[16], Status[32];
  3637. #if defined(__OS2__)
  3638.                HWND hwndList;
  3639.  
  3640.                hwndList = WinWindowFromID (hwnd, 1004);
  3641.                WinSendMsg (hwndList, LM_DELETEALL, 0L, 0L);
  3642. #elif defined(__NT__)
  3643.                SendMessage (hwndOutboundList, LB_RESETCONTENT, 0, 0L);
  3644. #endif
  3645.  
  3646.                if (Outbound->FirstNode () == TRUE) {
  3647.                   sprintf (String, "Node               Try/Con  Type       Size     Status");
  3648. #if defined(__OS2__)
  3649.                   WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), String);
  3650. #elif defined(__NT__)
  3651.                   SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)String);
  3652. #endif
  3653.                   do {
  3654.                      Flags[0] = (Outbound->Normal == TRUE) ? 'N' : ' ';
  3655.                      Flags[1] = (Outbound->Crash == TRUE) ? 'C' : ' ';
  3656.                      Flags[2] = (Outbound->Direct == TRUE) ? 'D' : ' ';
  3657.                      Flags[3] = (Outbound->Hold == TRUE) ? 'H' : ' ';
  3658.                      Flags[4] = (Outbound->Immediate == TRUE) ? 'I' : ' ';
  3659.                      Flags[5] = '\0';
  3660.                      if (Outbound->Hold == TRUE && Outbound->Normal == FALSE && Outbound->Crash == FALSE && Outbound->Direct == FALSE && Outbound->Immediate == FALSE)
  3661.                         strcpy (Status, "Hold");
  3662.                      else {
  3663.                         strcpy (Status, "Temp. Hold");
  3664.                         if (Outbound->Normal == TRUE && Events->SendNormal == TRUE)
  3665.                            strcpy (Status, Outbound->LastCall);
  3666.                         else if (Outbound->Crash == TRUE && Events->SendCrash == TRUE)
  3667.                            strcpy (Status, Outbound->LastCall);
  3668.                         else if (Outbound->Direct == TRUE && Events->SendDirect == TRUE)
  3669.                            strcpy (Status, Outbound->LastCall);
  3670.                         else if (Outbound->Immediate == TRUE && Events->SendImmediate == TRUE)
  3671.                            strcpy (Status, Outbound->LastCall);
  3672.                         if (Events->MaxCalls != 0 && Outbound->Attempts >= Events->MaxCalls)
  3673.                            strcpy (Status, "Undialable (Try)");
  3674.                         else if (Events->MaxConnects != 0 && Outbound->Failed >= Events->MaxConnects)
  3675.                            strcpy (Status, "Undialable (Con)");
  3676.                      }
  3677.                      sprintf (String, "%-16.16s  %3d %3d   %s  %8lub    %s", Outbound->Address, Outbound->Attempts, Outbound->Failed, Flags, Outbound->Size, Status);
  3678. #if defined(__OS2__)
  3679.                      WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), String);
  3680. #elif defined(__NT__)
  3681.                      SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)String);
  3682. #endif
  3683.                   } while (Outbound->NextNode () == TRUE);
  3684.                }
  3685.                else {
  3686. #if defined(__OS2__)
  3687.                   WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), "");
  3688.                   WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), "");
  3689.                   WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), "");
  3690.                   WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), "                      Nothing in outbound area");
  3691. #elif defined(__NT__)
  3692.                   SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)"");
  3693.                   SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)"");
  3694.                   SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)"");
  3695.                   SendMessage (hwndOutboundList, LB_ADDSTRING, 0, (LPARAM)"                      Nothing in outbound area");
  3696. #endif
  3697.                }
  3698.                break;
  3699.             }
  3700.             case WMU_CLEAROUTBOUND:
  3701. #if defined(__OS2__)
  3702.                WinSendMsg (WinWindowFromID (hwnd, 1004), LM_DELETEALL, 0L, 0L);
  3703. #elif defined(__NT__)
  3704.                SendMessage (hwndOutboundList, LB_RESETCONTENT, 0, 0L);
  3705. #endif
  3706.                break;
  3707.             case WMU_ADDOUTBOUNDLINE: {
  3708.                USHORT Item;
  3709. #if defined(__OS2__)
  3710.                HWND hwndList;
  3711.  
  3712.                hwndList = WinWindowFromID (hwnd, 1004);
  3713.                if ((USHORT)WinSendMsg (hwndList, LM_QUERYITEMCOUNT, 0L, 0L) > 50)
  3714.                   WinSendMsg (hwndList, LM_DELETEITEM, MPFROMSHORT (0), 0L);
  3715.                Item = (USHORT)WinSendMsg (hwndList, LM_INSERTITEM, MPFROMSHORT (LIT_END), mp2);
  3716.                WinSendMsg (hwndList, LM_SELECTITEM, MPFROMSHORT (Item), MPFROMSHORT (TRUE));
  3717. #elif defined(__NT__)
  3718.                if (SendMessage (hwndOutboundList, LB_GETCOUNT, 0, 0L) > 50)
  3719.                   SendMessage (hwndOutboundList, LB_DELETESTRING, 0, 0L);
  3720.                Item = (USHORT)SendMessage (hwndOutboundList, LB_ADDSTRING, 0, lParam);
  3721.                SendMessage (hwndOutboundList, LB_SETCURSEL, (WPARAM)Item, 0L);
  3722. #endif
  3723.                break;
  3724.             }
  3725.             case WMU_REPLACEOUTBOUNDLINE: {
  3726.                USHORT Item;
  3727. #if defined(__OS2__)
  3728.                HWND hwndList;
  3729.  
  3730.                hwndList = WinWindowFromID (hwnd, 1004);
  3731.                if ((Item = (USHORT)WinSendMsg (hwndList, LM_QUERYITEMCOUNT, 0L, 0L)) >= 0)
  3732.                   WinSendMsg (hwndList, LM_SETITEMTEXT, MPFROMSHORT (Item - 1), mp2);
  3733. #elif defined(__NT__)
  3734.                if ((Item = (USHORT)SendMessage (hwndOutboundList, LB_GETCOUNT, 0, 0L)) > 0) {
  3735.                   SendMessage (hwndOutboundList, LB_DELETESTRING, Item - 1, 0L);
  3736.                   Item = (USHORT)SendMessage (hwndOutboundList, LB_ADDSTRING, 0, lParam);
  3737.                   SendMessage (hwndOutboundList, LB_SETCURSEL, (WPARAM)Item, 0L);
  3738.                }
  3739. #endif
  3740.                break;
  3741.             }
  3742.          }
  3743.          break;
  3744.  
  3745.       case WM_TIMER:
  3746. #if defined(__OS2__)
  3747.          if (SHORT1FROMMP (mp1) == 99) {
  3748.             ULONG Value[3];
  3749.  
  3750.             Value[0] = 0L;
  3751.             DosQuerySysInfo (20, 20, (UCHAR *)Value, sizeof (Value));
  3752.             Log->Write ("+%lu bytes remain in heap", Value[0]);
  3753.             break;
  3754.          }
  3755. #endif
  3756.  
  3757. #if defined(__OS2__)
  3758.          if (SHORT1FROMMP (mp1) == 1)
  3759.             ModemTimer (hwnd);
  3760. #elif defined(__NT__)
  3761.          if (wParam == 1)
  3762.             ModemTimer (hwnd);
  3763. #endif
  3764.          break;
  3765.  
  3766.       case WM_SIZE: {
  3767.          USHORT dx, dy, doy;
  3768.  
  3769. #if defined(__OS2__)
  3770.          dx = (USHORT)(((float)SHORT1FROMMP (mp2) / 100.0) * 65.0);
  3771. //         dy = (USHORT)(((float)SHORT2FROMMP (mp2) / 100.0) * 83.0);
  3772.          dy = (USHORT)(SHORT2FROMMP (mp2) - 36);
  3773.          doy = (USHORT)(((float)dy / 100.0) * 45.0);
  3774.          dy -= doy;
  3775.          WinSetWindowPos (WinWindowFromID (hwnd, 1001), NULLHANDLE, 0, SHORT2FROMMP (mp2) - dy - 1, dx, dy, SWP_SIZE|SWP_MOVE|SWP_SHOW);
  3776.          WinSetWindowPos (WinWindowFromID (hwnd, 1002), NULLHANDLE, dx + 1, SHORT2FROMMP (mp2) - dy - 1, SHORT1FROMMP (mp2) - dx - 1, dy, SWP_SIZE|SWP_MOVE|SWP_SHOW);
  3777.          WinSetWindowPos (WinWindowFromID (hwnd, 1004), NULLHANDLE, 0, 35, SHORT1FROMMP (mp2), doy, SWP_SIZE|SWP_MOVE|SWP_SHOW);
  3778.          WinSetWindowPos (WinWindowFromID (hwnd, 1003), NULLHANDLE, 0, 0, SHORT1FROMMP (mp2), 35, SWP_SIZE|SWP_MOVE|SWP_SHOW);
  3779. #elif defined(__NT__)
  3780.          dx = (USHORT)(((float)LOWORD (lParam) / 100.0) * 65.0);
  3781.          dy = (USHORT)(HIWORD (lParam) - 34);
  3782.          doy = (USHORT)(((float)dy / 100.0) * 50.0);
  3783.          dy -= doy;
  3784.          MoveWindow (hwndMainList, 0, 0, dx, dy, TRUE);
  3785.          MoveWindow (hwndModemList, dx + 1, 0, LOWORD (lParam) - dx - 1, dy, TRUE);
  3786.          MoveWindow (hwndOutboundList, 0, dy + 1, LOWORD (lParam), doy, TRUE);
  3787.          MoveWindow (hwndStatusList, 0, HIWORD (lParam) - 33, LOWORD (lParam), 34, TRUE);
  3788. #endif
  3789.          break;
  3790.       }
  3791.  
  3792. #if defined(__OS2__)
  3793.       case WM_ERASEBACKGROUND:
  3794.          return ((MRESULT)TRUE);
  3795. #endif
  3796.  
  3797.       case WM_COMMAND:
  3798. #if defined(__OS2__)
  3799.          if (ProcessSimpleDialog (hwnd, SHORT1FROMMP (mp1)) == TRUE)
  3800.             return (0);
  3801.          if (ProcessSaveDialog (hwnd, SHORT1FROMMP (mp1)) == TRUE)
  3802.             return (0);
  3803.  
  3804.          switch (SHORT1FROMMP (mp1)) {
  3805. #elif defined(__NT__)
  3806.          if (LOWORD (wParam) == 1004 && HIWORD (wParam) == LBN_DBLCLK) {
  3807.             OutboundDetails (hwnd);
  3808.             return (0);
  3809.          }
  3810.          if (ProcessSimpleDialog (hwnd, (USHORT)LOWORD (wParam)) == TRUE)
  3811.             return (0);
  3812.          if (ProcessSaveDialog (hwnd, (USHORT)LOWORD (wParam)) == TRUE)
  3813.             return (0);
  3814.  
  3815.          switch (LOWORD (wParam)) {
  3816. #endif
  3817.             case 101:      // System / Import mail
  3818.                StopTimer (hwnd, 1);
  3819. #if defined(__OS2__)
  3820.                WinSendMsg (hwndMainClient, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 0), MPFROMP (""));
  3821.                WinSendMsg (hwndMainClient, WM_USER, MPFROM2SHORT (WMU_SETSTATUSLINE, 1), MPFROMP (""));
  3822. #elif defined(__NT__)
  3823.                SendMessage (hwndMainClient, WM_USER, (WPARAM)WMU_SETSTATUSLINE0, (LPARAM)"");
  3824.                SendMessage (hwndMainClient, WM_USER, (WPARAM)WMU_SETSTATUSLINE1, (LPARAM)"");
  3825. #endif
  3826.                Status = INITIALIZE;
  3827.                Current = 0;
  3828.                _beginthread (MailProcessorThread, NULL, 8192, (PVOID)(MAIL_IMPORTKNOWN|MAIL_IMPORTPROTECTED|MAIL_IMPORTNORMAL|MAIL_STARTTIMER));
  3829.                break;
  3830.  
  3831.             case 102:      // System / Export mail
  3832.                StopTimer (hwnd, 1);
  3833.                _beginthread (MailProcessorThread, NULL, 8192, (PVOID)(MAIL_EXPORT|MAIL_STARTTIMER));
  3834.                break;
  3835.  
  3836.             case 103:      // System / Pack mail
  3837.                StopTimer (hwnd, 1);
  3838.                _beginthread (MailProcessorThread, NULL, 8192, (PVOID)(MAIL_PACK|MAIL_STARTTIMER));
  3839.                break;
  3840.  
  3841.             case 104:      // System / Process ECHOmail
  3842.                StopTimer (hwnd, 1);
  3843.                _beginthread (MailProcessorThread, NULL, 8192, (PVOID)(MAIL_IMPORTKNOWN|MAIL_IMPORTPROTECTED|MAIL_IMPORTNORMAL|MAIL_EXPORT|MAIL_PACK|MAIL_STARTTIMER));
  3844.                break;
  3845.  
  3846.             case 105:      // System / Process TIC
  3847.                StopTimer (hwnd, 1);
  3848.                _beginthread (MailProcessorThread, NULL, 8192, (PVOID)(MAIL_TIC|MAIL_STARTTIMER));
  3849.                break;
  3850.  
  3851.             case 106:      // System / Rebuild Queue
  3852.                if (Outbound != NULL) {
  3853.                   if (Log != NULL)
  3854.                      Log->Write ("+Building the outbound queue");
  3855.                   Outbound->BuildQueue (Cfg->Outbound);
  3856.                   Outbound->FirstNode ();
  3857.                   if (Log != NULL)
  3858.                      Log->Write ("+%u queue record(s) in database", Outbound->TotalNodes);
  3859. #if defined(__OS2__)
  3860.                   WinPostMsg (hwndMainClient, WM_USER, MPFROMSHORT (WMU_REFRESHOUTBOUND), 0L);
  3861. #elif defined(__NT__)
  3862.                   PostMessage (hwndMainClient, WM_USER, (WPARAM)WMU_REFRESHOUTBOUND, 0L);
  3863. #endif
  3864.                }
  3865.                break;
  3866.  
  3867.             case 109: {    // System / Forced poll
  3868.                class CPollDlg *Dlg;
  3869.  
  3870.                if ((Dlg = new CPollDlg (hwnd)) != NULL) {
  3871.                   if (Dlg->DoModal () == TRUE) {
  3872. /*
  3873.                      strcpy (PollNode, Dlg->Address);
  3874.                      Modem->Terminal = FALSE;
  3875.                      strcpy (Modem->NodelistPath, Cfg->NodelistPath);
  3876.                      strcpy (Modem->DialCmd, Cfg->Dial);
  3877.                      Modem->Poll (PollNode);
  3878.                      Status = WAITFORCONNECT;
  3879.                      TimeOut = TimerSet ((ULONG)Cfg->DialTimeout * 100L);
  3880. */
  3881.                   }
  3882.                   delete Dlg;
  3883.                }
  3884.                break;
  3885.             }
  3886.  
  3887.             case 115:      // Local login
  3888.                StopTimer (hwnd, 1);
  3889.                _beginthread (LocalThread, NULL, 32768U, NULL);
  3890.                Status = HANGUP;
  3891.                break;
  3892.  
  3893.             case 116:      // System / Process NEWSgroups
  3894.                StopTimer (hwnd, 1);
  3895.                _beginthread (MailProcessorThread, NULL, 32768U, (PVOID)(MAIL_NEWSGROUP|MAIL_STARTTIMER));
  3896.                break;
  3897.  
  3898.             case 117: {    // System / EchoMail / Write AREAS.BBS
  3899.                class TAreaManager *Mgr;
  3900.  
  3901.                if ((Mgr = new TAreaManager) != NULL) {
  3902.                   Mgr->Cfg = Cfg;
  3903.                   Mgr->Log = Log;
  3904.                   Mgr->UpdateAreasBBS ();
  3905.                   delete Mgr;
  3906.                }
  3907.                break;
  3908.             }
  3909.  
  3910.             case 118:      // System / Process E-Mail
  3911.                StopTimer (hwnd, 1);
  3912.                _beginthread (MailProcessorThread, NULL, 32768U, (PVOID)(MAIL_EMAIL));
  3913.                break;
  3914.  
  3915.             case 119:      // System / Build nodelist index
  3916.                StopTimer (hwnd, 1);
  3917.                _beginthread (NodelistThread, NULL, 8192U, (PVOID)(TRUE));
  3918.                break;
  3919.  
  3920.             case 120:      // System / Import from bad msgs.
  3921.                StopTimer (hwnd, 1);
  3922.                _beginthread (MailProcessorThread, NULL, 32768U, (PVOID)(MAIL_IMPORTBAD|MAIL_STARTTIMER));
  3923.                break;
  3924.  
  3925.             case 121: {    // System / EchoMail / Import AREAS.BBS
  3926.                class TAreaManager *Mgr;
  3927.  
  3928.                if ((Mgr = new TAreaManager) != NULL) {
  3929.                   Mgr->Cfg = Cfg;
  3930.                   Mgr->Log = Log;
  3931.                   Mgr->ImportAreasBBS ();
  3932.                   delete Mgr;
  3933.                }
  3934.                break;
  3935.             }
  3936.  
  3937.             case 122: {
  3938. #if defined(__OS2__)
  3939.                FILEDLG fild;
  3940.                class TAreaManager *Mgr;
  3941.  
  3942.                memset (&fild, 0, sizeof (FILEDLG));
  3943.                fild.cbSize = sizeof (FILEDLG);
  3944.                fild.fl = FDS_CENTER|FDS_OPEN_DIALOG;
  3945.                fild.pszTitle = "Import Descriptions";
  3946.                sprintf (fild.szFullFile, "*.*");
  3947.  
  3948.                WinFileDlg (HWND_DESKTOP, hwndMainClient, &fild);
  3949.                if (fild.lReturn == DID_OK) {
  3950.                   if ((Mgr = new TAreaManager) != NULL) {
  3951.                      Mgr->Cfg = Cfg;
  3952.                      Mgr->Log = Log;
  3953.                      Mgr->ImportDescriptions (fild.szFullFile);
  3954.                      delete Mgr;
  3955.                   }
  3956.                }
  3957. #elif defined(__NT__)
  3958.                CHAR Temp[128];
  3959.                OPENFILENAME OpenFileName;
  3960.                class TAreaManager *Mgr;
  3961.  
  3962.                OpenFileName.lStructSize = sizeof (OPENFILENAME);
  3963.                OpenFileName.hwndOwner = hwndMainClient;
  3964.                OpenFileName.hInstance = NULL;
  3965.                OpenFileName.lpstrFilter = "All files (*.*)\0*.*";
  3966.                OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
  3967.                OpenFileName.nMaxCustFilter = 0L;
  3968.                OpenFileName.nFilterIndex = 1L;
  3969.                OpenFileName.lpstrFile = Temp;
  3970.                OpenFileName.nMaxFile = sizeof (Temp) - 1;
  3971.                OpenFileName.lpstrFileTitle = NULL;
  3972.                OpenFileName.nMaxFileTitle = 0;
  3973.                OpenFileName.lpstrInitialDir = NULL;
  3974.                OpenFileName.lpstrTitle = "Import Descriptions";
  3975.                OpenFileName.nFileOffset = 0;
  3976.                OpenFileName.nFileExtension = 0;
  3977.                OpenFileName.lpstrDefExt = "";
  3978.                OpenFileName.lCustData = 0;
  3979.                OpenFileName.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_CREATEPROMPT|OFN_NOCHANGEDIR;
  3980.  
  3981.                if (GetOpenFileName (&OpenFileName) == TRUE) {
  3982.                   if ((Mgr = new TAreaManager) != NULL) {
  3983.                      Mgr->Cfg = Cfg;
  3984.                      Mgr->Log = Log;
  3985.                      Mgr->ImportDescriptions (Temp);
  3986.                      delete Mgr;
  3987.                   }
  3988.                }
  3989. #endif
  3990.                break;
  3991.             }
  3992.  
  3993.             case 123: {
  3994. #if defined(__OS2__)
  3995.                FILEDLG fild;
  3996.                class TAreaManager *Mgr;
  3997.  
  3998.                memset (&fild, 0, sizeof (FILEDLG));
  3999.                fild.cbSize = sizeof (FILEDLG);
  4000.                fild.fl = FDS_CENTER|FDS_SAVEAS_DIALOG;
  4001.                fild.pszTitle = "Export Descriptions";
  4002.                sprintf (fild.szFullFile, "*.*");
  4003.  
  4004.                WinFileDlg (HWND_DESKTOP, hwndMainClient, &fild);
  4005.                if (fild.lReturn == DID_OK) {
  4006.                   if ((Mgr = new TAreaManager) != NULL) {
  4007.                      Mgr->Cfg = Cfg;
  4008.                      Mgr->Log = Log;
  4009.                      Mgr->ExportDescriptions (fild.szFullFile);
  4010.                      delete Mgr;
  4011.                   }
  4012.                }
  4013. #elif defined(__NT__)
  4014.                CHAR Temp[128];
  4015.                OPENFILENAME OpenFileName;
  4016.                class TAreaManager *Mgr;
  4017.  
  4018.                OpenFileName.lStructSize = sizeof (OPENFILENAME);
  4019.                OpenFileName.hwndOwner = hwndMainClient;
  4020.                OpenFileName.hInstance = NULL;
  4021.                OpenFileName.lpstrFilter = "All files (*.*)\0*.*";
  4022.                OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
  4023.                OpenFileName.nMaxCustFilter = 0L;
  4024.                OpenFileName.nFilterIndex = 1L;
  4025.                OpenFileName.lpstrFile = Temp;
  4026.                OpenFileName.nMaxFile = sizeof (Temp) - 1;
  4027.                OpenFileName.lpstrFileTitle = NULL;
  4028.                OpenFileName.nMaxFileTitle = 0;
  4029.                OpenFileName.lpstrInitialDir = NULL;
  4030.                OpenFileName.lpstrTitle = "Export Descriptions";
  4031.                OpenFileName.nFileOffset = 0;
  4032.                OpenFileName.nFileExtension = 0;
  4033.                OpenFileName.lpstrDefExt = "";
  4034.                OpenFileName.lCustData = 0;
  4035.                OpenFileName.Flags = OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_CREATEPROMPT|OFN_NOCHANGEDIR;
  4036.  
  4037.                if (GetSaveFileName (&OpenFileName) == TRUE) {
  4038.                   if ((Mgr = new TAreaManager) != NULL) {
  4039.                      Mgr->Cfg = Cfg;
  4040.                      Mgr->Log = Log;
  4041.                      Mgr->ExportDescriptions (Temp);
  4042.                      delete Mgr;
  4043.                   }
  4044.                }
  4045. #endif
  4046.                break;
  4047.             }
  4048.  
  4049.             case 201: {    // Global / General Options
  4050.                CHAR Title[128];
  4051.                class CGeneralDlg *Dlg;
  4052.  
  4053.                if ((Dlg = new CGeneralDlg (hwnd)) != NULL) {
  4054.                   if (Dlg->DoModal () == TRUE) {
  4055.                      Cfg->Save ();
  4056.                      sprintf (Title, "%s v%s%s - Line %u", NAME, VERSION, "", Cfg->TaskNumber);
  4057. #if defined(__OS2__)
  4058.                      WinSetWindowText (hwndMainFrame, Title);
  4059. #elif defined(__NT__)
  4060.                      SetWindowText (hwndMainClient, Title);
  4061. #endif
  4062.                   }
  4063.                   delete Dlg;
  4064.                }
  4065.                break;
  4066.             }
  4067.  
  4068.             case 501: {    // Modem / Hardware
  4069.                class CHardwareDlg *Dlg;
  4070.  
  4071.                if ((Dlg = new CHardwareDlg (hwnd)) != NULL) {
  4072.                   if (Dlg->DoModal () == TRUE) {
  4073.                      Cfg->Save ();
  4074.                      if (Modem != NULL) {
  4075.                         delete Modem;
  4076.                         Modem = NULL;
  4077.                      }
  4078.                      if (Modem == NULL && Cfg != NULL) {
  4079.                         if ((Modem = new TModem) != NULL) {
  4080.                            Modem->Log = Log;
  4081.                            strcpy (Modem->Device, Cfg->Device);
  4082.                            Modem->Speed = Cfg->Speed;
  4083.                            Modem->LockSpeed = Cfg->LockSpeed;
  4084.                            if (Cfg->Ring[0] != '\0')
  4085.                               strcpy (Modem->Ring, Cfg->Ring);
  4086.                            Modem->Initialize ();
  4087.                            Modem->hwndWindow = hwnd;
  4088.                            Status = INITIALIZE;
  4089.                            Current = 0;
  4090.                         }
  4091.                      }
  4092.                   }
  4093.                   delete Dlg;
  4094.                }
  4095.                break;
  4096.             }
  4097.  
  4098.             case 502: {    // Modem / Command Strings
  4099.                class CCommandsDlg *Dlg;
  4100.  
  4101.                if ((Dlg = new CCommandsDlg (hwnd)) != NULL) {
  4102.                   if (Dlg->DoModal () == TRUE) {
  4103.                      Cfg->Save ();
  4104.                      Status = INITIALIZE;
  4105.                      Current = 0;
  4106.                   }
  4107.                   delete Dlg;
  4108.                }
  4109.                break;
  4110.             }
  4111.  
  4112.             case 506:      // Modem / Hangup
  4113.                if (Modem != NULL) {
  4114.                   Modem->SendCommand (Cfg->Hangup);
  4115.                   if (Modem->Serial != NULL && Log != NULL) {
  4116.                      if (Modem->Serial->Carrier () == TRUE)
  4117.                         Log->Write ("!Unable to drop carrier");
  4118.                   }
  4119.                }
  4120.                break;
  4121.  
  4122.             case 507:      // Modem / Answer Now
  4123.                if (Status == WAITFORCALL) {
  4124.                   Modem->SendCommand (Cfg->Answer);
  4125.                   Status = ANSWERING;
  4126.                   TimeOut = TimerSet (4500L);
  4127.                }
  4128.                break;
  4129.  
  4130.             case 601: {    // Manager / Event Scheduler
  4131.                class CEventsDlg *Dlg;
  4132.  
  4133.                if ((Dlg = new CEventsDlg (hwnd)) != NULL) {
  4134.                   Dlg->DoModal ();
  4135.                   delete Dlg;
  4136.                }
  4137.                if (Events != NULL)
  4138.                   Events->Load ();
  4139.                break;
  4140.             }
  4141.  
  4142. #if defined(__OS2__)
  4143.             case 901:
  4144.                WinHelp ("lora.hlp>h_ref", HM_HELP_CONTENTS, "LoraBBS Online Manual");
  4145.                break;
  4146.             case 902:
  4147.                WinHelp ("lora.hlp>h_ref", HM_GENERAL_HELP, "LoraBBS Online Manual");
  4148.                break;
  4149.             case 903:
  4150.                WinHelp ("lora.hlp>h_ref", HM_DISPLAY_HELP, "LoraBBS Online Manual");
  4151.                break;
  4152. #endif
  4153.  
  4154.             case 905: {
  4155.                class CProductDlg *Dlg;
  4156.  
  4157.                if ((Dlg = new CProductDlg (hwnd)) != NULL) {
  4158.                   Dlg->DoModal ();
  4159.                   delete Dlg;
  4160.                }
  4161.                break;
  4162.             }
  4163.          }
  4164.          return (0);
  4165.  
  4166. #if defined(__OS2__)
  4167.       case WM_CONTROL:
  4168.          if (SHORT1FROMMP (mp1) == 1004 && SHORT2FROMMP (mp1) == LN_ENTER)
  4169.             OutboundDetails (hwnd);
  4170.          break;
  4171. #endif
  4172.  
  4173. #if defined(__OS2__)
  4174.       case WM_CLOSE: {
  4175. #elif defined(__NT__)
  4176.       case WM_DESTROY: {
  4177. #endif
  4178.          class TStatistics *Stats;
  4179.  
  4180.          if ((Stats = new TStatistics) != NULL) {
  4181.             Stats->Read (Cfg->TaskNumber);
  4182.             Stats->Status = STAT_OFFLINE;
  4183.             Stats->Update ();
  4184.             delete Stats;
  4185.          }
  4186.  
  4187.          if (Modem != NULL && Status != BBSEXIT)
  4188.             delete Modem;
  4189.          if (Log != NULL) {
  4190.             Log->Write (":End");
  4191.             Log->WriteBlank ();
  4192.             delete Log;
  4193.          }
  4194. #if defined(__NT__)
  4195.          PostQuitMessage (0);
  4196. #endif
  4197.          break;
  4198.       }
  4199.    }
  4200.  
  4201. #if defined(__OS2__)
  4202.    return (WinDefWindowProc (hwnd, msg, mp1, mp2));
  4203. #elif defined(__NT__)
  4204.    return (DefWindowProc (hwnd, msg, wParam, lParam));
  4205. #endif
  4206. }
  4207.  
  4208. #if !defined(__POINT__)
  4209.  
  4210. #if defined(__OS2__)
  4211. int main (int argc, char *argv[])
  4212. {
  4213.    int i, x, y, dx, dy;
  4214.    USHORT Task = 1, Interactive, Setup;
  4215.    USHORT DoImport, DoExport, DoPack, DoNews, DoTic, DoMail, DoNodelist;
  4216.    CHAR Title[128], *Config, *Channel, *Device;
  4217.    HMQ hmq;
  4218.    QMSG qmsg;
  4219.    ULONG flFrame, Flags, Speed;
  4220.    RECTL rc;
  4221.    HACCEL hAccel = NULLHANDLE;
  4222.  
  4223.    Log = NULL;
  4224.    Modem = NULL;
  4225.    Outbound = NULL;
  4226.    Events = NULL;
  4227.    Interactive = Setup = FALSE;
  4228.    DoImport = DoExport = DoPack = DoNews = DoTic = DoMail = DoNodelist = FALSE;
  4229.    Config = Channel = Device = NULL;
  4230.    Speed = 0L;
  4231.    PollNode[0] = '\0';
  4232.    gotPort = gotSpeed = FALSE;
  4233.  
  4234.    for (i = 1; i < argc; i++) {
  4235.       if (!stricmp (argv[i], "/LINE")) {
  4236.          i++;
  4237.          Task = (USHORT)atoi (argv[i]);
  4238.       }
  4239.       else if (!strncmp (argv[i], "-n", 2))
  4240.          Task = (USHORT)atoi (&argv[i][2]);
  4241.       else if (!stricmp (argv[i], "IMPORT") || !stricmp (argv[i], "IN") || !stricmp (argv[i], "TOSS")) {
  4242.          DoImport = TRUE;
  4243.          Interactive = TRUE;
  4244.       }
  4245.       else if (!stricmp (argv[i], "EXPORT") || !stricmp (argv[i], "OUT") || !stricmp (argv[i], "SCAN")) {
  4246.          DoExport = TRUE;
  4247.          Interactive = TRUE;
  4248.       }
  4249.       else if (!stricmp (argv[i], "PACK")) {
  4250.          DoPack = TRUE;
  4251.          Interactive = TRUE;
  4252.       }
  4253.       else if (!stricmp (argv[i], "NEWS")) {
  4254.          DoNews = TRUE;
  4255.          Interactive = TRUE;
  4256.       }
  4257.       else if (!stricmp (argv[i], "TIC")) {
  4258.          DoTic = TRUE;
  4259.          Interactive = TRUE;
  4260.       }
  4261.       else if (!stricmp (argv[i], "MAIL")) {
  4262.          DoMail = TRUE;
  4263.          Interactive = TRUE;
  4264.       }
  4265.       else if (!stricmp (argv[i], "NODELIST")) {
  4266.          DoNodelist = TRUE;
  4267.          Interactive = TRUE;
  4268.       }
  4269.       else if (!stricmp (argv[i], "SETUP"))
  4270.          Setup = TRUE;
  4271.       else if (!strncmp (argv[i], "-p", 2)) {
  4272.          Device = &argv[i][2];
  4273.          gotPort = TRUE;
  4274.       }
  4275.       else if (!strncmp (argv[i], "-b", 2)) {
  4276.          Speed = atol (&argv[i][2]);
  4277.          gotSpeed = TRUE;
  4278.       }
  4279.       else if (!strncmp (argv[i], "-h", 2)) {
  4280.          comHandle = atol (&argv[i][2]);
  4281.          gotPort = TRUE;
  4282.       }
  4283.       else if (!strncmp (argv[i], "-s", 2)) {
  4284.          connectSpeed = atol (&argv[i][2]);
  4285.          gotSpeed = TRUE;
  4286.       }
  4287.       else if (!strncmp (argv[i], "-t", 2))
  4288.          timeLimit = (USHORT)atoi (&argv[i][2]);
  4289.       else if (Config == NULL)
  4290.          Config = argv[i];
  4291.       else if (Channel == NULL)
  4292.          Channel = argv[i];
  4293.    }
  4294.  
  4295.    if (Config == NULL)
  4296.       Config = getenv ("LORA_CONFIG");
  4297.    if (Channel == NULL)
  4298.       Channel = getenv ("LORA_CHANNEL");
  4299.  
  4300.    if ((Cfg = new TConfig) != NULL) {
  4301.       Cfg->TaskNumber = Task;
  4302.       if (Cfg->Load (Config, Channel) == FALSE)
  4303.          Cfg->Default ();
  4304.       if ((Events = new TEvents (Cfg->SchedulerFile)) != NULL)
  4305.          Events->Load ();
  4306.       if ((Outbound = new TOutbound (Cfg->Outbound)) != NULL) {
  4307.          if (Cfg->MailAddress.First () == TRUE)
  4308.             Outbound->DefaultZone = Cfg->MailAddress.Zone;
  4309.       }
  4310.    }
  4311.  
  4312.    if (Device != NULL)
  4313.       strcpy (Cfg->Device, Device);
  4314.    if (Speed != 0L)
  4315.       Cfg->Speed = Speed;
  4316.  
  4317.    if ((hab = WinInitialize (0)) != 0) {
  4318.       if ((hmq = WinCreateMsgQueue (hab, 0)) != 0) {
  4319.          WinRegisterClass (hab, "MAIN_WINDOW", MainWinProc, CS_CLIPCHILDREN|CS_SIZEREDRAW|CS_MOVENOTIFY, 0);
  4320.  
  4321.          flFrame = (FCF_TASKLIST|FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX|FCF_SIZEBORDER|FCF_NOBYTEALIGN|FCF_MENU);
  4322.          if ((hwndMainFrame = WinCreateStdWindow (HWND_DESKTOP, 0, &flFrame, "MAIN_WINDOW", NULL, 0, NULLHANDLE, 256, &hwndMainClient)) != NULLHANDLE) {
  4323.             sprintf (Title, "%s v%s%s - Line %u", NAME, VERSION, "", Cfg->TaskNumber);
  4324.             WinSetWindowText (hwndMainFrame, Title);
  4325.  
  4326.             WinQueryWindowRect (HWND_DESKTOP, &rc);
  4327.             dx = 575;
  4328.             if ((rc.xRight - rc.xLeft) < dx)
  4329.                dx = rc.xRight - rc.xLeft;
  4330.             dy = 330;
  4331.             if ((rc.yTop - rc.yBottom) < dy)
  4332.                dy = rc.yTop - rc.yBottom;
  4333.  
  4334.             x = ((rc.xRight - rc.xLeft) - dx) / 2;
  4335.             y = ((rc.yTop - rc.yBottom) - dy) / 2;
  4336.  
  4337.             WinSetWindowPos (hwndMainFrame, NULLHANDLE, x, y, dx, dy, SWP_SIZE|SWP_MOVE|SWP_SHOW|SWP_ACTIVATE);
  4338.  
  4339.             if (Interactive == FALSE) {
  4340.                if (Setup == FALSE) {
  4341.                   Status = 0;
  4342.                   WinStartTimer (hab, hwndMainClient, 1, MODEM_DELAY);
  4343.                   hAccel = WinLoadAccelTable (hab, NULLHANDLE, 1);
  4344.                   _beginthread (BackgroundThread, NULL, 8192, NULL);
  4345.                }
  4346.                else
  4347.                   Status = 99;
  4348.             }
  4349.             else {
  4350.                if (DoNodelist == TRUE)
  4351.                   CompileNodelist (TRUE);
  4352.  
  4353.                Flags = MAIL_POSTQUIT|MAIL_NOEXTERNAL;
  4354.                if (DoImport == TRUE)
  4355.                   Flags |= MAIL_IMPORTNORMAL|MAIL_IMPORTPROTECTED|MAIL_IMPORTKNOWN;
  4356.                if (DoExport == TRUE)
  4357.                   Flags |= MAIL_EXPORT;
  4358.                if (DoPack == TRUE)
  4359.                   Flags |= MAIL_PACK;
  4360.                if (DoNews == TRUE)
  4361.                   Flags |= MAIL_NEWSGROUP;
  4362.                if (DoTic == TRUE)
  4363.                   Flags |= MAIL_TIC;
  4364.                if (DoMail == TRUE)
  4365.                   Flags |= MAIL_EMAIL;
  4366.                _beginthread (MailProcessorThread, NULL, 32768U, (PVOID)Flags);
  4367.             }
  4368.  
  4369.             while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0)) {
  4370.                if (hAccel != NULLHANDLE)
  4371.                   WinTranslateAccel (hab, hwndMainClient, hAccel, &qmsg);
  4372.                WinDispatchMsg (hab, &qmsg);
  4373.             }
  4374.  
  4375.             if (Interactive == FALSE) {
  4376.                if (hAccel != NULLHANDLE)
  4377.                   WinDestroyAccelTable (hAccel);
  4378.                WinStopTimer (hab, hwndMainClient, 1);
  4379.             }
  4380.  
  4381.             WinDestroyWindow (hwndMainFrame);
  4382.          }
  4383.  
  4384.          WinDestroyMsgQueue (hmq);
  4385.       }
  4386.       WinTerminate (hab);
  4387.    }
  4388.  
  4389.    sprintf (Title, "lexit%d.%d", Cfg->TaskNumber, ErrorLevel);
  4390.    unlink (Title);
  4391.  
  4392.    if (Cfg != NULL)
  4393.       delete Cfg;
  4394.    if (Events != NULL)
  4395.       delete Events;
  4396.    if (Outbound != NULL)
  4397.       delete Outbound;
  4398.  
  4399.    return (ErrorLevel);
  4400. }
  4401. #elif defined(__NT__)
  4402. int PASCAL WinMain (HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
  4403. {
  4404.    int x, y, dx, dy;
  4405.    USHORT Task = 1, Interactive, Setup;
  4406.    USHORT DoImport, DoExport, DoPack, DoNews, DoTic, DoMail, DoNodelist;
  4407.    CHAR *p, Title[128], *Config, *Channel, *Device;
  4408.    ULONG Flags, Speed;
  4409.    MSG msg;
  4410.    WNDCLASS wc;
  4411.    RECT rc;
  4412.    HACCEL hAccel;
  4413.  
  4414.    Log = NULL;
  4415.    Modem = NULL;
  4416.    Events = NULL;
  4417.    Outbound = NULL;
  4418.    Interactive = Setup = FALSE;
  4419.    DoImport = DoExport = DoPack = DoNews = DoTic = DoMail = DoNodelist = FALSE;
  4420.    Config = Channel = Device = NULL;
  4421.    Speed = 0L;
  4422.    lpszCmdLine = lpszCmdLine;
  4423.    PollNode[0] = '\0';
  4424.    gotPort = gotSpeed = FALSE;
  4425.  
  4426.    strcpy (Title, lpszCmdLine);
  4427.    if ((p = strtok (Title, " ")) != NULL)
  4428.       do {
  4429.          if (!stricmp (p, "/LINE")) {
  4430.             if ((p = strtok (NULL, " ")) != NULL)
  4431.                Task = (USHORT)atoi (p);
  4432.          }
  4433.          else if (!strncmp (p, "-n", 2))
  4434.             Task = (USHORT)atoi (&p[2]);
  4435.          else if (!stricmp (p, "IMPORT") || !stricmp (p, "IN") || !stricmp (p, "TOSS")) {
  4436.             DoImport = TRUE;
  4437.             Interactive = TRUE;
  4438.          }
  4439.          else if (!stricmp (p, "EXPORT") || !stricmp (p, "OUT") || !stricmp (p, "SCAN")) {
  4440.             DoExport = TRUE;
  4441.             Interactive = TRUE;
  4442.          }
  4443.          else if (!stricmp (p, "PACK")) {
  4444.             DoPack = TRUE;
  4445.             Interactive = TRUE;
  4446.          }
  4447.          else if (!stricmp (p, "NEWS")) {
  4448.             DoNews = TRUE;
  4449.             Interactive = TRUE;
  4450.          }
  4451.          else if (!stricmp (p, "TIC")) {
  4452.             DoTic = TRUE;
  4453.             Interactive = TRUE;
  4454.          }
  4455.          else if (!stricmp (p, "MAIL")) {
  4456.             DoMail = TRUE;
  4457.             Interactive = TRUE;
  4458.          }
  4459.          else if (!stricmp (p, "NODELIST")) {
  4460.             DoNodelist = TRUE;
  4461.             Interactive = TRUE;
  4462.          }
  4463.          else if (!stricmp (p, "SETUP")) {
  4464.             Setup = TRUE;
  4465.          }
  4466.          else if (!strncmp (p, "-p", 2)) {
  4467.             Device = &p[2];
  4468.             gotPort = TRUE;
  4469.          }
  4470.          else if (!strncmp (p, "-b", 2)) {
  4471.             Speed = atol (&p[2]);
  4472.             gotSpeed = TRUE;
  4473.          }
  4474.          else if (!strncmp (p, "-h", 2)) {
  4475.             comHandle = atol (&p[2]);
  4476.             gotPort = TRUE;
  4477.          }
  4478.          else if (!strncmp (p, "-s", 2))
  4479.             connectSpeed = atol (&p[2]);
  4480.          else if (!strncmp (p, "-t", 2))
  4481.             timeLimit = (USHORT)atoi (&p[2]);
  4482.          else if (Config == NULL)
  4483.             Config = p;
  4484.          else if (Channel == NULL)
  4485.             Channel = p;
  4486.       } while ((p = strtok (NULL, " ")) != NULL);
  4487.  
  4488.    if (Config == NULL)
  4489.       Config = getenv ("LORA_CONFIG");
  4490.    if (Channel == NULL)
  4491.       Channel = getenv ("LORA_CHANNEL");
  4492.  
  4493.    if ((Cfg = new TConfig) != NULL) {
  4494.       Cfg->TaskNumber = Task;
  4495.       if (Cfg->Load (Config, Channel) == FALSE)
  4496.          Cfg->Default ();
  4497.       if ((Events = new TEvents (Cfg->SchedulerFile)) != NULL)
  4498.          Events->Load ();
  4499.       if ((Outbound = new TOutbound (Cfg->Outbound)) != NULL) {
  4500.          if (Cfg->MailAddress.First () == TRUE)
  4501.             Outbound->DefaultZone = Cfg->MailAddress.Zone;
  4502.       }
  4503.    }
  4504.  
  4505.    if (Device != NULL)
  4506.       strcpy (Cfg->Device, Device);
  4507.    if (Speed != 0L)
  4508.       Cfg->Speed = Speed;
  4509.  
  4510.    if (hinstPrevious == NULL) {
  4511.       wc.style         = CS_DBLCLKS;
  4512.       wc.lpfnWndProc   = MainWinProc;
  4513.       wc.cbClsExtra    = 0;
  4514.       wc.cbWndExtra    = 0;
  4515.       wc.hInstance     = hinstCurrent;
  4516.       wc.hIcon         = LoadIcon (NULL, "100");
  4517.       wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
  4518.       wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  4519.       wc.lpszMenuName  = "MENU_1";
  4520.       wc.lpszClassName = "MAIN_WINDOW";
  4521.  
  4522.       if (!RegisterClass (&wc))
  4523.          return (FALSE);
  4524.    }
  4525.  
  4526.    hinst = hinstCurrent;
  4527.    msg.wParam = FALSE;
  4528.  
  4529.    GetClientRect (GetDesktopWindow (), &rc);
  4530.    dx = 575;
  4531.    if ((rc.right - rc.left) < dx)
  4532.       dx = rc.right - rc.left;
  4533.    dy = 330;
  4534.    if ((rc.bottom - rc.top) < dy)
  4535.       dy = rc.bottom - rc.top;
  4536.  
  4537.    x = ((rc.right - rc.left) - dx) / 2;
  4538.    y = ((rc.bottom - rc.top) - dy) / 2;
  4539.  
  4540.    sprintf (Title, "%s v%s%s - Line %u", NAME, VERSION, "", Cfg->TaskNumber);
  4541.  
  4542.    if ((hwndMainClient = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, "MAIN_WINDOW", Title, WS_OVERLAPPEDWINDOW, x, y, dx, dy, NULL, NULL, hinstCurrent, NULL)) != NULL) {
  4543.       ShowWindow (hwndMainClient, nCmdShow);
  4544.  
  4545.       if (Interactive == FALSE) {
  4546.          if (Setup == FALSE) {
  4547.             Status = 0;
  4548.             SetTimer (hwndMainClient, 1, MODEM_DELAY, NULL);
  4549.             _beginthread (BackgroundThread, NULL, 8192, NULL);
  4550.          }
  4551.          else
  4552.             Status = 99;
  4553.       }
  4554.       else {
  4555.          if (DoNodelist == TRUE)
  4556.            CompileNodelist (TRUE);
  4557.  
  4558.          Flags = MAIL_POSTQUIT|MAIL_NOEXTERNAL;
  4559.          if (DoImport == TRUE)
  4560.             Flags |= MAIL_IMPORTNORMAL|MAIL_IMPORTPROTECTED|MAIL_IMPORTKNOWN;
  4561.          if (DoExport == TRUE)
  4562.             Flags |= MAIL_EXPORT;
  4563.          if (DoPack == TRUE)
  4564.             Flags |= MAIL_PACK;
  4565.          if (DoNews == TRUE)
  4566.             Flags |= MAIL_NEWSGROUP;
  4567.          if (DoTic == TRUE)
  4568.             Flags |= MAIL_TIC;
  4569.          if (DoMail == TRUE)
  4570.             Flags |= MAIL_EMAIL;
  4571.          _beginthread (MailProcessorThread, NULL, 8192, (PVOID)Flags);
  4572.       }
  4573.  
  4574.       hAccel = LoadAccelerators (hinstCurrent, "ACCELERATOR_1");
  4575.  
  4576.       while (GetMessage (&msg, NULL, 0, 0)) {
  4577.          if (!TranslateAccelerator (hwndMainClient, hAccel, &msg)) {
  4578.             TranslateMessage (&msg);
  4579.             DispatchMessage (&msg);
  4580.          }
  4581.       }
  4582.  
  4583.       if (Interactive == FALSE)
  4584.          KillTimer (hwndMainClient, 1);
  4585.    }
  4586.  
  4587.    if (Cfg != NULL)
  4588.       delete Cfg;
  4589.    if (Events != NULL)
  4590.       delete Events;
  4591.    if (Outbound != NULL)
  4592.       delete Outbound;
  4593.  
  4594.    return ((int)msg.wParam);
  4595. }
  4596. #endif
  4597.  
  4598. #endif
  4599.  
  4600.