home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / bgcheck / System / examine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-30  |  9.0 KB  |  377 lines

  1. #define PROGNAME "Examine"
  2.  
  3. #include"bbs:bgcheck/bgcheck.h"
  4. #include "env:timedate.h"
  5. #include "aedoor.h"
  6.  
  7.  
  8.  
  9. static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" ("REVDATE")";
  10. #define ws WriteStr
  11.  
  12. void Start(int node);
  13.  
  14. void main(int argc, char *argv[])
  15. {
  16.     int    Node=0;
  17. if(argc<2)
  18. {
  19.     printf("Sorry, %s must be called from S!X or /X\n",argv[0]);
  20.     exit(0);
  21. }
  22. Node=atoi(argv[1]);
  23. Register(Node);
  24.  
  25. XIM_Msg->Command=140;                    
  26. CheckMessage();
  27. SetTaskPri(FindTask(0),atol(XIM_Msg->String));
  28.  
  29. Start(Node);
  30. ShutDown();
  31.  
  32. }
  33.  
  34.  
  35.  
  36. void Start(Node)
  37. {
  38.     char    buffer[255],            handle[50],
  39.             playpen[255],            workpath[255],
  40.             filename[255],            confpath[255],
  41.             **main_fileid=NULL,
  42.             **main_config=NULL,        *p=NULL,
  43.             *ptr=NULL,                slot[5];
  44.     int        lines=0,                len=0,                        confnumber=0,
  45.             axx=0,nodenumber=0,    priority=0;
  46.     BPTR    readfh=NULL,            writefh=NULL,                lock=NULL;
  47.     BOOL    msgbase=FALSE,            clearline=FALSE;
  48.     ULONG    dirinkbyte=0,            pos=0,                        delaycount=0;
  49.     struct     Filedata    *filedata=NULL;
  50.     BOOL    file_id_passed=FALSE,file_id=FALSE,all_passed=FALSE;
  51.  
  52.     ws("BGExtractor "REVISION" by Joe Cool",0);
  53.  
  54.     SendStrDataCmd(BB_MAINLINE,"",1);
  55.     strcpy(buffer,XIM_Msg->String);
  56.     ptr=strrchr(buffer,'/');
  57.     strcpy(filename,ptr+1);
  58.     upperstring(filename);
  59.  
  60.     sprintf(buffer,"  Processing: %s",filename);
  61.     ws(buffer,1);
  62.  
  63.     sprintf(workpath,"bbs:node%d/work/",Node);
  64.  
  65.     sprintf(buffer,"EX: %s",filename);
  66.     SendStrDataCmd(177,buffer,0);
  67.  
  68.     GetDT(913,"");
  69.     dirinkbyte=XIM_Msg->Data; 
  70.  
  71.     GetDT(BB_CONFLOCAL,"");
  72.     strcpy(confpath,XIM_Msg->String);
  73.  
  74.     GetDT(DT_SLOTNUMBER,"");
  75.     strcpy(slot,XIM_Msg->String);
  76.  
  77.     GetDT(DT_NAME,"");
  78.     strcpy(handle,XIM_Msg->String);
  79.  
  80.     GetDT(SIG_PLAYPEN,"");
  81.     strcpy(playpen,XIM_Msg->String);
  82.  
  83.     GetDT(DT_SECSTATUS,"");
  84.     axx=atoi(XIM_Msg->String);
  85.  
  86.     GetDT(BB_CONFNUM,"");
  87.     confnumber=atoi(XIM_Msg->String);
  88.     confnumber++;
  89.  
  90.  
  91.     sprintf(buffer,"t:MSGBASE.%d",Node);
  92.     lock=Lock(buffer,ACCESS_READ);
  93.     if (lock)
  94.     {
  95.         msgbase=TRUE;
  96.         UnLock(lock);
  97.     }
  98.  
  99.  
  100.     pos=0;
  101.     strcpy(buffer,"bbs:bgcheck/bgfilehandler.config");
  102.     readfh=Open(buffer,MODE_OLDFILE);
  103.     if (!readfh && pos!=60)
  104.     {
  105.         pos++;
  106.         readfh=Open(buffer,MODE_OLDFILE);
  107.         if (!readfh) Delay(TICKS_PER_SECOND);
  108.     }
  109.  
  110.     main_config=(char **) realloc(main_config,sizeof(char *));
  111.     main_config[0]=NULL;
  112.  
  113.     if (readfh) 
  114.     {
  115.         for (pos=0;FGets(readfh,buffer,254);pos++)
  116.         {
  117.             main_config=(char **) realloc(main_config,(pos+1)*sizeof(char *));
  118.             main_config[pos]=NULL;
  119.             len=strlen(buffer);
  120.             if (buffer[len-1]=='\n') buffer[--len]='\0';
  121.             upperstring(buffer);
  122.             main_config[pos]=(char *) malloc (len+1);
  123.             if (main_config[pos]!=NULL)
  124.                 strcpy(main_config[pos],buffer);
  125.         }
  126.         Close(readfh);
  127.         main_config=(char **) realloc(main_config,(pos+1)*sizeof(char *));
  128.         main_config[pos]=NULL;
  129.     }
  130.  
  131.     if (p=getconfig(main_config,"PRIORITY"))
  132.     {
  133.         priority=atoi(p);
  134.     }
  135.  
  136.     Forbid();
  137.     filedata=(struct  Filedata    *)FindSemaphore(filename);
  138.     Permit();
  139.     if (!filedata)
  140.     {
  141.         if (filedata=(struct Filedata *) AllocMem(sizeof(struct Filedata),MEMF_PUBLIC|MEMF_CLEAR))
  142.         {
  143.             filedata->semi.ss_Link.ln_Pri=0;
  144.             filedata->semi.ss_Link.ln_Name=filedata->filename;
  145.             
  146.             strcpy(filedata->filename,filename);
  147.             strcpy(filedata->filepath,playpen);
  148.             sprintf(buffer,"%d",Node);
  149.             strcpy(filedata->nodenumber,buffer);
  150.             strcpy(filedata->handle,handle);
  151.             strcpy(filedata->confpath,confpath);
  152.             sprintf(buffer,"%d",dirinkbyte);
  153.             strcpy(filedata->dirinkbyte,buffer);
  154.             strcpy(filedata->slotnumber,slot);
  155.             filedata->confnumber=confnumber;
  156.             filedata->Main_Fileid=NULL;
  157.             filedata->Filesize=0;
  158.             filedata->MsgBase=msgbase;
  159.             filedata->Hold=FALSE;
  160.             filedata->axx=axx;
  161.  
  162.             sprintf(buffer,"t:UploadDelay.%d",Node);
  163.             lock=Lock(buffer,ACCESS_READ);
  164.             if (lock)
  165.             {
  166.                 filedata->Delay=TRUE;
  167.                 UnLock(lock);
  168.             }
  169.             else
  170.             {
  171.                 filedata->Delay=FALSE;
  172.             }
  173.  
  174.             filedata->Immediately=FALSE;
  175.             filedata->bghandler=FALSE;
  176.             filedata->add_fileid=FALSE;
  177.             filedata->Filecheck_passed=FALSE;
  178.             filedata->Filecheck_ok=FALSE;
  179.             filedata->file_id_passed=FALSE;
  180.             filedata->file_id=FALSE;
  181.             filedata->all_passed=FALSE;
  182.             filedata->dupe=FALSE;
  183.  
  184.             AddSemaphore((struct SignalSemaphore *)filedata);    
  185.             sprintf(buffer,"run >nil: bbs:bgcheck/bgfilehandler \"%s\"",filename);    
  186.             SystemTags(buffer,NP_Priority,priority,NULL);
  187.  
  188.         }            
  189.     
  190.     }
  191.  
  192.     all_passed=FALSE;
  193.     file_id_passed=FALSE;
  194.     file_id=FALSE;
  195.     delaycount=0;
  196.     while (!all_passed)
  197.     {
  198.         if (file_id_passed && !file_id)
  199.         {
  200.             ObtainSemaphore((struct SignalSemaphore *) filedata);
  201.             filedata->file_id_passed=FALSE;
  202.             ReleaseSemaphore((struct SignalSemaphore *) filedata);
  203.  
  204.             ws("c",1);
  205.             ws("",1);
  206.             ws("- -- --- ---- -----------------------------=[ bGCHECKER "REVISION" bY jOE cOOL ]=-",1);
  207.             ws("",1);
  208.             ws("C pUT \"/\" aS FIRST cHAR 2 mAKE uPLOAD 2 sYSOP!",1);
  209.             ws("Please Enter a Description      [---------|---------|---------|---------|----]",1);
  210.             lines=0;
  211.             XIM_Msg->String[0]=0;
  212.             sprintf(buffer,"BA%-12.12sC[C]D",filename);
  213.  
  214.             while ((XIM_Msg->String[0]==0) && (XIM_Msg->Data!=-1) && (lines==0))
  215.             {
  216.                 SendStrDataCmd(5,buffer,44);
  217.                 if (XIM_Msg->String[0]!=0) 
  218.                 {
  219.                     lines++;
  220.                     main_fileid=(char **) realloc(main_fileid,(lines)*sizeof(char *));
  221.                     main_fileid[lines-1]=NULL;
  222.                     len=strlen(XIM_Msg->String);
  223.                     main_fileid[lines-1]=(char *) malloc (len+1);
  224.                     if (main_fileid[lines-1]!=NULL)
  225.                         strcpy(main_fileid[lines-1],XIM_Msg->String);
  226.                 }
  227.                 sprintf(buffer,"AC[C]D");
  228.             }
  229.             while (XIM_Msg->String[0]!=0 && XIM_Msg->Data!=-1 && lines<=14)
  230.             {
  231.                 SendStrDataCmd(5,"C[C]D",44);
  232.                 if (XIM_Msg->String[0]!=0) 
  233.                 {
  234.                     lines++;
  235.                     main_fileid=(char **) realloc(main_fileid,(lines)*sizeof(char *));
  236.                     main_fileid[lines-1]=NULL;
  237.                     len=strlen(XIM_Msg->String);
  238.                     main_fileid[lines-1]=(char *) malloc (len+1);
  239.                     if (main_fileid[lines-1]!=NULL)
  240.                         strcpy(main_fileid[lines-1],XIM_Msg->String);
  241.                 }
  242.             }
  243.             ws ("",0);
  244.             {
  245.         
  246.                 if (!lines)
  247.                 {
  248.                     lines++;
  249.                     main_fileid=(char **) realloc(main_fileid,(lines)*sizeof(char *));
  250.                     main_fileid[lines-1]=NULL;
  251.                     len=strlen("No Description -> Lost Carrier!");
  252.                     main_fileid[lines-1]=(char *) malloc (len+1);
  253.                     if (main_fileid[lines-1]!=NULL)
  254.                         strcpy(main_fileid[lines-1],"No Description -> Lost Carrier!");
  255.                 }
  256.                 main_fileid=(char **) realloc(main_fileid,(lines+1)*sizeof(char *));
  257.                 main_fileid[lines]=NULL;
  258.     
  259.                 sprintf(buffer,"t:%s",filename);
  260.                 writefh=Open(buffer,MODE_NEWFILE);            
  261.  
  262.                 lines=0;
  263.                 while(main_fileid[lines])
  264.                 {
  265.                     sprintf(buffer,"%s\n",main_fileid[lines]);
  266.                     FPuts(writefh,buffer);
  267.                     lines++;
  268.                 }
  269.                 Close (writefh);
  270.     
  271.                 for (lines=0;main_fileid[lines]!=NULL;lines++)
  272.                     free(main_fileid[lines]);
  273.                 if (main_fileid) free (main_fileid);
  274.  
  275.             }
  276.  
  277.             ObtainSemaphore((struct SignalSemaphore *) filedata);
  278.             filedata->bghandler=FALSE;
  279.             filedata->add_fileid=TRUE;
  280.             ReleaseSemaphore((struct SignalSemaphore *) filedata);
  281.  
  282.             sprintf(buffer,"run >nil: bbs:bgcheck/bgfilehandler \"%s\"",filename);    
  283.             SystemTags(buffer,NP_Priority,priority,NULL);
  284.             
  285.         }
  286.  
  287.         ObtainSemaphore((struct SignalSemaphore *) filedata);
  288.         all_passed=filedata->all_passed;
  289.         file_id=filedata->file_id;
  290.         file_id_passed=filedata->file_id_passed;
  291.         ReleaseSemaphore((struct SignalSemaphore *) filedata);
  292.         if (delaycount==8)
  293.         {
  294.             clearline=TRUE;
  295.             ws(".",0);
  296.             delaycount=0;
  297.         }
  298.         delaycount++;
  299.         if (!all_passed) Delay(TICKS_PER_SECOND/5);        
  300.  
  301.     }
  302.  
  303.     ObtainSemaphore((struct SignalSemaphore *) filedata);
  304.     if (clearline)    ws("",1);
  305.     if (filedata->dupe) ws("Duplicate Upload!",1);
  306.     if (!filedata->Filecheck_ok && !filedata->dupe)    ws("Filecheck failed!",1);
  307.     if (filedata->Delay) ws("Upload delayed!",1);
  308.     if (filedata->Hold) ws("Upload moved into Hold-dir!",1);
  309.     nodenumber=atoi(filedata->nodenumber);
  310.  
  311.     if (filedata->dupe || !filedata->Filecheck_ok || filedata->Hold) 
  312.     {
  313.         sprintf(buffer,"%s%s",filedata->filepath,filedata->filename);
  314.         DeleteFile(buffer);
  315.     }
  316.  
  317.     ReleaseSemaphore((struct SignalSemaphore *) filedata);
  318.  
  319.     
  320.  
  321.  
  322.  
  323.     sprintf(buffer,"bbs:node%d/CallersLog",nodenumber);
  324.     writefh=Open(buffer,MODE_READWRITE);
  325.     while (!writefh)
  326.     {
  327.            Delay(20);
  328.            writefh=Open(buffer,MODE_READWRITE);
  329.     }
  330.     Seek(writefh,0,OFFSET_END);
  331.  
  332.     ObtainSemaphore((struct SignalSemaphore *) filedata);
  333.     sprintf(buffer,"\tUpload moved to %s\n",filedata->movetopath);
  334.     ReleaseSemaphore((struct SignalSemaphore *) filedata);
  335.  
  336.     FPuts(writefh,buffer);
  337.     Close(writefh);
  338.  
  339.  
  340.     sprintf(buffer,"%s%s",workpath,filename);
  341.     writefh=Open(buffer,MODE_NEWFILE);    
  342.     if (writefh) Close (writefh);
  343.  
  344.     
  345.  
  346.     pos=0;
  347.     sprintf(buffer,"EXAMINE.%d",pos);
  348.     while (p=getconfig(main_config,buffer))
  349.     {
  350.         if (p[0]!=0)
  351.         {
  352.             sprintf(buffer,"%s %d",p,Node);
  353.             System(buffer,NULL);
  354.         }
  355.         pos++;
  356.         sprintf(buffer,"EXAMINE.%d",pos);
  357.     }
  358.  
  359.     if (msgbase)
  360.     {
  361.         RemSemaphore((struct SignalSemaphore *)filedata);
  362.         ObtainSemaphore((struct SignalSemaphore *)filedata);
  363.         ReleaseSemaphore((struct SignalSemaphore *)filedata);
  364.         FreeMem(filedata,sizeof(struct Filedata));
  365.     }
  366.  
  367.     for (pos=0;main_config[pos]!=NULL;pos++)
  368.         free(main_config[pos]);
  369.     if (main_config) free (main_config);
  370.  
  371.  
  372.     
  373. }
  374.  
  375.  
  376.  
  377.