home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / utilities / iu-14-as225.lha / INetUtils-1.4 / contrib / AmiPOP115.lha / AmiPOP115 / source / pop_main.c < prev    next >
C/C++ Source or Header  |  1994-12-08  |  9KB  |  494 lines

  1. /* AmiPOP By Scott Ellis */
  2.  
  3. #include "pop.h"
  4.  
  5. static const char VersionID[]="\0$VER:AmiPOP 1.15 (8.12.94)";
  6.  
  7. /* Variables in pop.h */
  8.  
  9. char *pophost=NULL;
  10. char *username=NULL;
  11. char *password=NULL;
  12. char *passfake=NULL;
  13. char *maildir=NULL;
  14. char *cxname=NULL;
  15. char *cxdesc=NULL;
  16. char *hotkey=NULL;
  17. char *title=NULL;
  18. char *temp=NULL;
  19. char *buf=NULL;
  20. UBYTE *PubScreenName=NULL;
  21.  
  22. const char bum[]="Ok";
  23.  
  24. BOOL delmail=FALSE;
  25. BOOL checkper=FALSE;
  26. BOOL appfile=TRUE;
  27. BOOL winop=TRUE;
  28. BOOL notify=FALSE;
  29. BOOL immediate=FALSE;
  30. BOOL quiet=FALSE;
  31. BOOL once=FALSE;
  32.  
  33. int timecheck=10;
  34. int port=110;
  35.  
  36. struct MsgPort *amipop_mp=NULL;
  37. struct MsgPort *timer_mp=NULL;
  38. struct timerequest *timerio=NULL;
  39. CxObj *broker=NULL;
  40. struct Library *TimerBase=NULL;
  41. struct IntuitionBase *IntuitionBase=NULL;
  42. struct Library *GadToolsBase=NULL;
  43.  
  44.  
  45. struct NewBroker newbroker = {
  46.     NB_VERSION,   /* nb_Version - Version of the NewBroker structure */
  47.     "Not Active", /* nb_Name */
  48.     "Amiga POP ⌐ 1994 Scott Ellis",     /* nb_Title - Title of commodity that appears in CXExchange */
  49.     "Not Active", /* nb_Descr */
  50.     NBU_NOTIFY | NBU_UNIQUE ,            /* nb_Unique - Tells CX not to launch another commodity with same name */
  51.     COF_SHOW_HIDE,            /* nb_Flags - Tells CX if this commodity has a window */
  52.     0,            /* nb_Pri - This commodity's priority */
  53.     0,            /* nb_Port - MsgPort CX talks to */
  54.     0             /* nb_ReservedChannel - reserved for later use */
  55. };
  56.  
  57. struct EasyStruct ereq =
  58.     {
  59.     sizeof(struct EasyStruct),
  60.     0,
  61.     "AmiPOP Notice",
  62.     "%s",
  63.     "%s",
  64.     };
  65.  
  66. UWORD __chip waitPointer[] =
  67.     {
  68.     0x0000, 0x0000,     /* reserved, must be NULL */
  69.  
  70.     0x0400, 0x07C0,
  71.     0x0000, 0x07C0,
  72.     0x0100, 0x0380,
  73.     0x0000, 0x07E0,
  74.     0x07C0, 0x1FF8,
  75.     0x1FF0, 0x3FEC,
  76.     0x3FF8, 0x7FDE,
  77.     0x3FF8, 0x7FBE,
  78.     0x7FFC, 0xFF7F,
  79.     0x7EFC, 0xFFFF,
  80.     0x7FFC, 0xFFFF,
  81.     0x3FF8, 0x7FFE,
  82.     0x3FF8, 0x7FFE,
  83.     0x1FF0, 0x3FFC,
  84.     0x07C0, 0x1FF8,
  85.     0x0000, 0x07E0,
  86.  
  87.     0x0000, 0x0000,     /* reserved, must be NULL */
  88.     };
  89.  
  90. enum args
  91.     {
  92.     USERNAME,
  93.     PASSWORD,
  94.     POPHOST,
  95.     MAILDIR,
  96.     CHECKPER,
  97.     TIME,
  98.     DELETE,
  99.     APPEND,
  100.     NOWINDOW,
  101.     PORT,
  102.     NOTIFY,
  103.     CX_POPKEY,
  104.     IMMEDIATE,
  105.     QUIET,
  106.     PUBSCREEN,
  107.     ONCE
  108.     };
  109.  
  110. /* Configure SAS Specific routines */
  111.  
  112. void __regargs __chkabort(void) {}
  113. long __stack = 20000;
  114.  
  115. /* End SAS */
  116.  
  117. /* Now define the structure that we will get when we start up the program */
  118. typedef struct popstruct {
  119.     char pophost[BIGSTRING];
  120.     char username[SMALLSTRING];
  121.     char password[SMALLSTRING];
  122.     char passfake[SMALLSTRING];
  123.     char maildir[BIGSTRING];
  124.     char cxname[BIGSTRING];
  125.     char cxdesc[3*BIGSTRING];
  126.     char hotkey[BIGSTRING];
  127.     char title[256];
  128.     char temp[BUFSIZE];
  129.     char buf[BUFSIZE];
  130.     char PubScreenName[SMALLSTRING];
  131. } PopStruct;
  132.  
  133. ULONG            sigmask=NULL;
  134. ULONG            cxsigflag=NULL;
  135. ULONG            timesigflag=NULL;
  136.  
  137. struct Library *IconBase;
  138. struct RDArgs   *RDA;
  139.  
  140. int main(int argc, char **argv)
  141. {
  142.     int foo=0;
  143.     ULONG    mysig;
  144.  
  145.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37L);
  146.     GadToolsBase = OpenLibrary("gadtools.library",37L);
  147.  
  148.     if (GadToolsBase && IntuitionBase)
  149.     {
  150.         if (makevars())
  151.         {
  152.             freevars();
  153.             return(20);
  154.         }
  155.  
  156.         if ( parse(argc) )
  157.         {
  158.             if ( setuptime() )
  159.             {
  160.                 timesigflag = 1L << timer_mp->mp_SigBit;
  161.                 timereq();
  162.                 foo=1;
  163.  
  164.                 if ( setupcx() )
  165.                 {
  166.                     if (winop)
  167.                     {
  168.                         openup();
  169.                     }
  170.                 }
  171.                 else
  172.                 {
  173.                     foo=0;
  174.                 }
  175.             }
  176.         }
  177.         else
  178.         {
  179.             foo=0;
  180.         }
  181.  
  182.         if (once && foo)
  183.         {
  184.             MYGAD_BUTTONClicked();
  185.             foo=0;
  186.         }
  187.  
  188.         if (immediate && foo) MYGAD_BUTTONClicked(); /* Check mail immediately */
  189.  
  190.         while (foo)
  191.         {
  192.             if (winop)
  193.             {
  194.                 sigmask= 1 << Project0Wnd->UserPort->mp_SigBit ;
  195.             }
  196.             else
  197.             {
  198.                 sigmask= NULL;
  199.             }
  200.  
  201.             mysig=Wait ( sigmask | cxsigflag | timesigflag | SIGBREAKF_CTRL_C );
  202.  
  203.             if ( mysig & cxsigflag )
  204.             {
  205.                 foo=docx();
  206.             }
  207.                    if ( mysig & sigmask )
  208.             {
  209.                 foo=HandleProject0IDCMP();
  210.             }
  211.  
  212.             if ( mysig & timesigflag )
  213.             {
  214.                 if (checkper)
  215.                 {
  216.                     MYGAD_BUTTONClicked();
  217.                 }
  218.                 timereq();
  219.             }
  220.  
  221.             if (mysig & SIGBREAKF_CTRL_C )
  222.             {
  223.                 foo=0;
  224.             }
  225.         }
  226.  
  227.         closedown();
  228.  
  229.         closetime();
  230.  
  231.         closecx();
  232.  
  233.         freevars();
  234.  
  235.     }
  236.  
  237.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  238.     if (GadToolsBase) CloseLibrary(GadToolsBase);
  239.  
  240.     return(0);
  241. }
  242.  
  243. void openup(void)
  244. {
  245.     SetupScreen();
  246.     OpenProject0Window();
  247.  
  248.     winop=TRUE;
  249. }
  250.  
  251. void closedown(void)
  252. {
  253.     CloseProject0Window();
  254.     CloseDownScreen();
  255.  
  256.     winop=FALSE;
  257. }
  258.  
  259. BOOL parse( int argc )
  260. {
  261.     char    *OriginalTemplate =    "Username/K,Password/K,POPHost/K,MailDir/K,CheckPer/S,"
  262.                                 "Time/K/N,Delete/S,Append/S,NoWindow/S,Port/K/N,Notify/S,"
  263.                                 "Cx_Popkey/K,Immediate/S,Quiet/S,PubScreen/K,Once/S";
  264.  
  265.     LONG    *ArgumentArray;        /* array for storing arguments retrieved by */
  266.  
  267.     char    **ToolArrayIndex,    /* workbench tooltypes array */
  268.             *ToolStringIndex,    /* index into string of concatenated workbench tooltypes */
  269.             *Template;            /* readargs template - varies slightly for WB or CLI */
  270.  
  271.     struct DiskObject    *DiskObject;    /* pointer to diskobject associated with program icon */
  272.     WORD    ArgCount = 1;        /* number of arguments in template */
  273.  
  274.     const char none[]="None Given";
  275.  
  276.     RDA = AllocDosObjectTags(DOS_RDARGS, TAG_DONE);
  277.     RDA->RDA_ExtHelp = NULL;
  278.  
  279.     Template = AllocVec(strlen(OriginalTemplate)+16,MEMF_CLEAR);
  280.  
  281.     for (    ToolStringIndex = OriginalTemplate;
  282.             ToolStringIndex = strchr(ToolStringIndex,',');
  283.             ToolStringIndex++, ArgCount++);
  284.  
  285.     ArgumentArray = AllocVec((ArgCount+1)*4,MEMF_CLEAR);
  286.  
  287.     if (argc==0)
  288.     {
  289.         if (IconBase = OpenLibrary("icon.library", 36L ) )
  290.         {
  291.  
  292.             CurrentDir(_WBenchMsg->sm_ArgList->wa_Lock);
  293.  
  294.             if (DiskObject = GetDiskObject(_WBenchMsg->sm_ArgList->wa_Name))
  295.             {
  296.                 for (    ToolArrayIndex = DiskObject->do_ToolTypes;
  297.                         *ToolArrayIndex;
  298.                         ToolArrayIndex++)
  299.                 {
  300.                     RDA->RDA_Source.CS_Length += (strlen(*ToolArrayIndex)+1);
  301.                 }
  302.  
  303.                 if (RDA->RDA_Source.CS_Length)
  304.                 {
  305.                     RDA->RDA_Source.CS_Buffer = AllocVec(RDA->RDA_Source.CS_Length+1,MEMF_CLEAR);
  306.                     ToolStringIndex = RDA->RDA_Source.CS_Buffer;
  307.  
  308.                     for (    ToolArrayIndex = DiskObject->do_ToolTypes;
  309.                             *ToolArrayIndex;
  310.                             ToolArrayIndex++)
  311.                     {
  312.                         ToolStringIndex = stpcpy(stpcpy(ToolStringIndex,*ToolArrayIndex)," ");
  313.                     }
  314.  
  315.                     *(ToolStringIndex-1) = '\n';
  316.                     FreeDiskObject(DiskObject);
  317.                 }
  318.             }
  319.  
  320.             stpcpy(stpcpy(Template,OriginalTemplate),",ThrowAway/M");
  321.  
  322.             CloseLibrary(IconBase);
  323.         }
  324.     }
  325.     else
  326.     {
  327.         strcpy(Template,OriginalTemplate);
  328.     }
  329.  
  330.     RDA = ReadArgs(Template,ArgumentArray,RDA);
  331.  
  332.     FreeVec(Template);
  333.  
  334.     if (RDA)
  335.     {
  336.         if (ArgumentArray[USERNAME])
  337.         {
  338.             strcpy(username,(char *)ArgumentArray[USERNAME]);
  339.         }
  340.         else
  341.         {
  342.             strcpy(username,none);
  343.         }
  344.  
  345.         if (ArgumentArray[PASSWORD])
  346.         {
  347.             strcpy(password,(char *)ArgumentArray[PASSWORD]);
  348.         }
  349.         else
  350.         {
  351.             strcpy(password,"");
  352.         }
  353.  
  354.         if (ArgumentArray[POPHOST])
  355.         {
  356.             strcpy(pophost,(char *)ArgumentArray[POPHOST]);
  357.         }
  358.         else
  359.         {
  360.             strcpy(pophost,none);
  361.         }
  362.  
  363.         if (ArgumentArray[MAILDIR])
  364.         {
  365.             strcpy(maildir,(char *)ArgumentArray[MAILDIR]);
  366.         }
  367.         else
  368.         {
  369.             strcpy(maildir,none);
  370.         }
  371.  
  372.         checkper=(BOOL)ArgumentArray[CHECKPER];
  373.  
  374.         if (ArgumentArray[TIME])
  375.         {
  376.             timecheck=*(int *)ArgumentArray[TIME];
  377.         }
  378.  
  379.         delmail=(BOOL)ArgumentArray[DELETE];
  380.         appfile=(BOOL)ArgumentArray[APPEND];
  381.         winop=!( (BOOL)ArgumentArray[NOWINDOW] );
  382.  
  383.         if (ArgumentArray[PORT])
  384.         {
  385.             port = *(int *)ArgumentArray[PORT];
  386.         }
  387.  
  388.         notify=(BOOL)ArgumentArray[NOTIFY];
  389.  
  390.         if (ArgumentArray[CX_POPKEY])
  391.         {
  392.             strcpy(hotkey,(char *)ArgumentArray[CX_POPKEY]);
  393.         }
  394.  
  395.         if (ArgumentArray[IMMEDIATE])
  396.         {
  397.             immediate=TRUE;
  398.         }
  399.  
  400.         if (ArgumentArray[QUIET])
  401.         {
  402.             quiet=TRUE;
  403.         }
  404.  
  405.         if (ArgumentArray[PUBSCREEN])
  406.         {
  407.             strcpy(PubScreenName,(UBYTE *)ArgumentArray[PUBSCREEN]);
  408.         }
  409.  
  410.         if (ArgumentArray[ONCE])
  411.         {
  412.             once=TRUE;
  413.         }
  414.  
  415.         FreeParameters(ArgumentArray);
  416.  
  417.         return(TRUE);
  418.     }
  419.     else
  420.     {
  421.         FreeParameters(ArgumentArray);
  422.  
  423.         return(FALSE);
  424.     }
  425. }
  426.  
  427. void FreeParameters(LONG *ArgumentArray)
  428. {
  429.     if (RDA)
  430.     {
  431.         if ((RDA->RDA_Source.CS_Length) && (RDA->RDA_Source.CS_Buffer))
  432.         {
  433.             FreeVec(RDA->RDA_Source.CS_Buffer);
  434.         }
  435.  
  436.         FreeArgs(RDA);
  437.         FreeDosObject(DOS_RDARGS,RDA);
  438.     }
  439.     else
  440.     {
  441.         PrintFault(IoErr(), NULL);
  442.     }
  443.  
  444.     if (ArgumentArray)
  445.     {
  446.         FreeVec(ArgumentArray);
  447.     }
  448. }
  449.  
  450.  
  451. int doreq( const char *mes, const char *but)
  452. {
  453.     LONG answer;
  454.  
  455.     if ( !quiet )
  456.     {
  457.         answer= EasyRequest(NULL, &ereq, NULL, mes, but);
  458.  
  459.         if (Project0Wnd)
  460.         {
  461.             SetWindowTitles(Project0Wnd,Project0Wdt, (UBYTE *) ~0);
  462.         }
  463.  
  464.         return(answer);
  465.     }
  466. }
  467.  
  468. BOOL makevars(void)
  469. {
  470. PopStruct *blockptr;
  471.     if ( blockptr=AllocVec(sizeof(PopStruct),MEMF_CLEAR) )
  472.     {
  473.         pophost=blockptr->pophost;
  474.         username=blockptr->username;
  475.         password=blockptr->password;
  476.         passfake=blockptr->passfake;
  477.         maildir=blockptr->maildir;
  478.         cxname=blockptr->cxname;
  479.         cxdesc=blockptr->cxdesc;
  480.         hotkey=blockptr->hotkey;
  481.         title=blockptr->title;
  482.         temp=blockptr->temp;
  483.         buf=blockptr->buf;
  484.         PubScreenName=blockptr->PubScreenName;
  485.         return(FALSE);
  486.     }
  487.     return(TRUE);
  488. }
  489.  
  490. void freevars(void)
  491. {
  492.     if (pophost) FreeVec(pophost);
  493. }
  494.