home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / SUBREQ.C < prev    next >
C/C++ Source or Header  |  1995-04-25  |  11KB  |  443 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include "subxtr.h"
  22.  
  23.  
  24.  
  25. static void maybe_netmail(xtrasubsnetrec *ni, int add)
  26. {
  27.   prt(5,get_string(217));
  28.   if (yn()) {
  29.     strcpy(irt,get_string(218));
  30.     strcat(irt,ni->stype);
  31.     if (add)
  32.       strcat(irt,get_string(219));
  33.     else
  34.       strcat(irt,get_string(220));
  35.     set_net_num(ni->net_num);
  36.     email(1, ni->host, 0, 0);
  37.   }
  38. }
  39.  
  40. /****************************************************************************/
  41.  
  42.  
  43. void sub_req(int main_type, int minor_type, int tosys, char *extra)
  44. {
  45.   net_header_rec nh;
  46.  
  47.   nh.tosys=tosys;
  48.   nh.touser=1;
  49.   nh.fromsys=net_sysnum;
  50.   nh.fromuser=1;
  51.   nh.main_type=main_type;
  52.   nh.minor_type=minor_type;
  53.   nh.list_len=0;
  54.   time((long *)&nh.daten);
  55.   if (!minor_type)
  56.     nh.length=strlen(extra)+1;
  57.   else {
  58.     nh.length=1;
  59.     extra="";
  60.   }
  61.   nh.method=0;
  62.  
  63.   send_net(&nh, NULL, extra, NULL);
  64.  
  65.   nl();
  66.   if (main_type == main_type_sub_add_req)
  67.     outstr(get_string(221));
  68.   else
  69.     outstr(get_string(222));
  70.   pln(tosys);
  71.   pausescr();
  72. }
  73.  
  74. /****************************************************************************/
  75.  
  76. #define OPTION_AUTO   0x0001
  77. #define OPTION_NO_TAG 0x0002
  78. #define OPTION_GATED  0x0004
  79. #define OPTION_NETVAL 0x0008
  80. #define OPTION_ANSI   0x0010
  81.  
  82.  
  83. int find_hostfor(char *type, unsigned short *ui, char *desc, unsigned short *opt)
  84. {
  85.   int i,i1,done=0;
  86.   char s[161],*ss;
  87.   FILE *f;
  88.   unsigned short h, o,rc=0;
  89.  
  90.   if (desc)
  91.     *desc=0;
  92.   *opt=0;
  93.  
  94.   for (i=0; (i<256) && (!done); i++) {
  95.     if (i)
  96.       sprintf(s,"%sSUBS.%d",net_data,i);
  97.     else
  98.       sprintf(s,"%sSUBS.LST",net_data);
  99.     f=fsh_open(s,"r");
  100.     if (f) {
  101.       while ((!done) && fgets(s,160,f)) {
  102.         if (s[0]>' ') {
  103.           ss=strtok(s," \r\n\t");
  104.           if (ss) {
  105.             if (stricmp(ss,type)==0) {
  106.               ss=strtok(NULL," \r\n\t");
  107.               if (ss) {
  108.                 h=(unsigned short) atol(ss);
  109.                 o=0;
  110.                 ss=strtok(NULL,"\r\n");
  111.                 if (ss) {
  112.                   i1=0;
  113.                   while (*ss && ((*ss==' ') || (*ss=='\t'))) {
  114.                     ++ss;
  115.                     ++i1;
  116.                   }
  117.                   if (i1<4) {
  118.                     while (*ss && (*ss!=' ') && (*ss!='\t')) {
  119.                       switch(*ss) {
  120.                         case 'T': o |= OPTION_NO_TAG; break;
  121.                         case 'R': o |= OPTION_AUTO; break;
  122.                         case 'G': o |= OPTION_GATED; break;
  123.                         case 'N': o |= OPTION_NETVAL; break;
  124.                         case 'A': o |= OPTION_ANSI; break;
  125.                       }
  126.                       ++ss;
  127.                     }
  128.                     while (*ss && ((*ss==' ') || (*ss=='\t')))
  129.                       ++ss;
  130.                   }
  131.                   if (*ui) {
  132.                     if (*ui==h) {
  133.                       done=1;
  134.                       *opt=o;
  135.                       rc=h;
  136.                       if (desc)
  137.                         strcpy(desc,ss);
  138.                     }
  139.                   } else {
  140.                     nl();
  141.                     outstr(get_string(223)); pl(type);
  142.                     outstr(get_string(224)); npr("%u\r\n",h);
  143.                     outstr(get_string(225)); npr("%s\r\n",ss);
  144.                     nl();
  145.                     prt(5,get_string(226));
  146.                     if (yn()) {
  147.                       done=1;
  148.                       *ui=h;
  149.                       *opt=o;
  150.                       rc=h;
  151.                       if (desc)
  152.                         strcpy(desc,ss);
  153.                     }
  154.                   }
  155.                 }
  156.               }
  157.             }
  158.           }
  159.         }
  160.       }
  161.       fsh_close(f);
  162.     } else {
  163.       done=1;
  164.     }
  165.   }
  166.  
  167.   return(rc);
  168. }
  169.  
  170. /****************************************************************************/
  171.  
  172. void sub_xtr_del(int n, int nn, int f)
  173. {
  174.   xtrasubsnetrec xn;
  175.   int i,ok;
  176.   unsigned short opt;
  177.  
  178.   xn=xsubs[n].nets[nn];
  179.  
  180.   if (f) {
  181.     xsubs[n].num_nets--;
  182.  
  183.     for (i=nn; i<xsubs[n].num_nets; i++)
  184.       xsubs[n].nets[i]=xsubs[n].nets[i+1];
  185.   }
  186.  
  187.   set_net_num(xn.net_num);
  188.  
  189.   if ((xn.host) && (valid_system(xn.host))) {
  190.     ok=find_hostfor(xn.stype, (unsigned short *)&xn.host, NULL, &opt);
  191.     if (ok) {
  192.       if (opt&OPTION_AUTO) {
  193.         if (status.net_version>=29) {
  194.           prt(5,get_string(227));
  195.           if (yn())
  196.             sub_req(main_type_sub_drop_req, xn.type, xn.host, xn.stype);
  197.         } else
  198.           maybe_netmail(&xn, 0);
  199.       } else {
  200.         maybe_netmail(&xn, 0);
  201.       }
  202.     } else {
  203.       prt(5,get_string(227));
  204.       if (yn())
  205.         sub_req(main_type_sub_drop_req, xn.type, xn.host, xn.stype);
  206.       else
  207.         maybe_netmail(&xn, 0);
  208.     }
  209.   }
  210. }
  211.  
  212. /****************************************************************************/
  213.  
  214. void sub_xtr_add(int n, int nn)
  215. {
  216.   unsigned short opt, ok, i,i1,f;
  217.   char desc[100],s[100],onx[20],*mmk,ch;
  218.   int onxi, odci,ii,gc;
  219.   xtrasubsnetrec *xnp;
  220.   FILE *ff;
  221.  
  222.   if ((nn<0) || (nn>=xsubs[n].num_nets)) {
  223.  
  224.     if (xsubs[n].num_nets_max<=xsubs[n].num_nets) {
  225.       i1=xsubs[n].num_nets+4;
  226.       xnp=(xtrasubsnetrec *)malloca(i1*sizeof(xtrasubsnetrec));
  227.       if (!xnp)
  228.         return;
  229.       for (i=0; i<xsubs[n].num_nets; i++)
  230.         xnp[i]=xsubs[n].nets[i];
  231.  
  232.       if (xsubs[n].flags&XTRA_MALLOCED)
  233.         bbsfree(xsubs[n].nets);
  234.  
  235.       xsubs[n].nets=xnp;
  236.       xsubs[n].num_nets_max=i1;
  237.       xsubs[n].flags|=XTRA_MALLOCED;
  238.     }
  239.     xnp=&(xsubs[n].nets[xsubs[n].num_nets]);
  240.   } else
  241.     xnp=&(xsubs[n].nets[nn]);
  242.  
  243.   memset(xnp, 0, sizeof(xtrasubsnetrec));
  244.  
  245.   if (net_num_max>1) {
  246.     odc[0]=0;
  247.     odci=0;
  248.     onx[0]='Q';
  249.     onx[1]=0;
  250.     onxi=1;
  251.     nl();
  252.     for (ii=0; ii<net_num_max; ii++) {
  253.       if (ii<9) {
  254.         onx[onxi++]=ii+'1';
  255.         onx[onxi]=0;
  256.       } else {
  257.         odci=(ii+1)/10;
  258.         odc[odci-1]=odci+'0';
  259.         odc[odci]=0;
  260.       }
  261.       npr("%d. %s\r\n",ii+1,net_networks[ii].name);
  262.     }
  263.     pl(get_string(12));
  264.     nl();
  265.     prt(2,get_string(13));
  266.     if (net_num_max<9) {
  267.       ch=onek(onx);
  268.       if (ch=='Q')
  269.         ii=-1;
  270.       else
  271.         ii=ch-'1';
  272.     } else {
  273.       mmk=mmkey(2);
  274.       if (*mmk=='Q')
  275.         ii=-1;
  276.       else
  277.         ii=atoi(mmk)-1;
  278.     }
  279.     if ((ii>=0) && (ii<net_num_max)) {
  280.       set_net_num(ii);
  281.     } else
  282.       return;
  283.   }
  284.   xnp->net_num=net_num;
  285.  
  286.   nl();
  287.   prt(2,get_string(228));
  288.   input(xnp->stype,7);
  289.   if (xnp->stype[0]==0)
  290.     return;
  291.  
  292.   xnp->type=atoi(xnp->stype);
  293.  
  294.   if ((!xnp->type) && (status.net_version<32)) {
  295.     nl();
  296.     pl(get_string(229));
  297.     nl();
  298.     pausescr();
  299.     return;
  300.   }
  301.  
  302.   if (xnp->type)
  303.     sprintf(xnp->stype,"%u",xnp->type);
  304.  
  305.   prt(5,get_string(230));
  306.   if (yn()) {
  307.  
  308.     sprintf(s,"%sN%s.NET",net_data,xnp->stype);
  309.     f=sh_open(s,O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  310.     if (f>0)
  311.       sh_close(f);
  312.  
  313.     prt(5,get_string(231));
  314.     if (ny())
  315.       xnp->flags |= XTRA_NET_AUTO_ADDDROP;
  316.  
  317.     prt(5,get_string(232));
  318.     if (ny()) {
  319.       xnp->flags |= XTRA_NET_AUTO_INFO;
  320.       if (display_sub_categories()) {
  321.         gc=0;
  322.         while (!gc) {
  323.           nl();
  324.           prt(2,get_string(931));
  325.           input(s,3);
  326.           i=atoi(s);
  327.           if (i || (strcmp(s,"0")==0)) {
  328.             sprintf(s,"%sCATEG.NET",net_data);
  329.             ff=fsh_open(s,"r");
  330.             while (fgets(s,100,ff)) {
  331.               i1=atoi(s);
  332.               if (i1==i) {
  333.                 fsh_close(ff);
  334.                 gc=1;
  335.                 xnp->category=i;
  336.                 break;
  337.               }
  338.             }
  339.             fsh_close(ff);
  340.             if (strcmp(s,"0")==0)
  341.               gc=1;
  342.             else if (!xnp->category)
  343.               pl(get_string(932));
  344.           } else {
  345.             if ((strlen(s)==1) && (s[0]=='?')) {
  346.               display_sub_categories();
  347.               continue;
  348.             }
  349.           }
  350.         }
  351.       }
  352.     }
  353.  
  354.   } else {
  355.     ok=find_hostfor(xnp->stype, (unsigned short *) &(xnp->host), desc, &opt);
  356.  
  357.     if (!ok) {
  358.       nl();
  359.       prt(2,get_string(233));
  360.       input(desc,6);
  361.       xnp->host=(unsigned short) atol(desc);
  362.       desc[0]=0;
  363.     }
  364.  
  365.     if (!xsubs[n].desc[0])
  366.       strcpy(xsubs[n].desc, desc);
  367.  
  368.     if (xnp->host==net_sysnum)
  369.       xnp->host=0;
  370.  
  371.     if (xnp->host) {
  372.       if (valid_system(xnp->host)) {
  373.         if (ok) {
  374.           if (opt & OPTION_NO_TAG) {
  375.             subboards[n].anony |= anony_no_tag;
  376.           }
  377.           nl();
  378.           if ((opt & OPTION_AUTO) && (status.net_version>=29)) {
  379.             prt(5,get_string(234));
  380.             if (yn())
  381.               sub_req(main_type_sub_add_req, xnp->type, xnp->host, xnp->stype);
  382.           } else {
  383.             maybe_netmail(xnp, 1);
  384.           }
  385.         } else {
  386.           if (status.net_version>=29) {
  387.             nl();
  388.             prt(5,get_string(234));
  389.             ok=yn();
  390.           } else {
  391.             ok=0;
  392.           }
  393.           if (ok) {
  394.             sub_req(main_type_sub_add_req, xnp->type, xnp->host, xnp->stype);
  395.           } else {
  396.             maybe_netmail(xnp, 1);
  397.           }
  398.         }
  399.       } else {
  400.         nl();
  401.         pl(get_string(235));
  402.         pausescr();
  403.       }
  404.     }
  405.   }
  406.   if ((nn<0) || (nn>=xsubs[n].num_nets)) {
  407.     xsubs[n].num_nets++;
  408.   }
  409. }
  410.  
  411. /****************************************************************************/
  412.  
  413. int display_sub_categories(void)
  414. {
  415.   FILE *ff;
  416.   char s[81], *ss;
  417.   int i;
  418.  
  419.   if (!net_sysnum)
  420.     return(0);
  421.  
  422.   sprintf(s,"%sCATEG.NET",net_data);
  423.   ff=fsh_open(s,"r");
  424.   if (ff) {
  425.     nl();
  426.     pl(get_string(930));
  427.     i=0;
  428.     while (!i && fgets(s,100,ff)) {
  429.       ss=strchr(s,'\n');
  430.       if (ss)
  431.         *ss=0;
  432.       pla(s,&i);
  433.     }
  434.     fsh_close(ff);
  435.     return(1);
  436.   }
  437.   return(0);
  438. }
  439.  
  440. /****************************************************************************/
  441.  
  442.  
  443.