home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / ListSERV1_4.lha / ListSERV / source / RCS / subscribe.c,v < prev   
Encoding:
Text File  |  1993-12-29  |  13.1 KB  |  548 lines

  1. head    1.4;
  2. branch    1.4.1;
  3. access;
  4. symbols;
  5. locks
  6.     simons:1.4.1.10
  7.     andy:1.4; strict;
  8. comment    @ * @;
  9.  
  10.  
  11. 1.4
  12. date    92.09.14.11.04.20;    author andy;    state Exp;
  13. branches
  14.     1.4.1.1;
  15. next    ;
  16.  
  17. 1.4.1.1
  18. date    93.12.26.00.42.45;    author simons;    state Exp;
  19. branches;
  20. next    1.4.1.2;
  21.  
  22. 1.4.1.2
  23. date    93.12.26.19.35.55;    author simons;    state Exp;
  24. branches;
  25. next    1.4.1.3;
  26.  
  27. 1.4.1.3
  28. date    93.12.26.19.56.04;    author simons;    state Exp;
  29. branches;
  30. next    1.4.1.4;
  31.  
  32. 1.4.1.4
  33. date    93.12.26.20.26.43;    author simons;    state Exp;
  34. branches;
  35. next    1.4.1.5;
  36.  
  37. 1.4.1.5
  38. date    93.12.26.21.22.27;    author simons;    state Exp;
  39. branches;
  40. next    1.4.1.6;
  41.  
  42. 1.4.1.6
  43. date    93.12.27.17.37.04;    author simons;    state Exp;
  44. branches;
  45. next    1.4.1.7;
  46.  
  47. 1.4.1.7
  48. date    93.12.28.17.24.22;    author simons;    state Exp;
  49. branches;
  50. next    1.4.1.8;
  51.  
  52. 1.4.1.8
  53. date    93.12.28.22.16.34;    author simons;    state Exp;
  54. branches;
  55. next    1.4.1.9;
  56.  
  57. 1.4.1.9
  58. date    93.12.29.06.24.47;    author simons;    state Exp;
  59. branches;
  60. next    1.4.1.10;
  61.  
  62. 1.4.1.10
  63. date    93.12.29.06.56.57;    author simons;    state Exp;
  64. branches;
  65. next    ;
  66.  
  67.  
  68. desc
  69. @Original Unix-Listserv distribution.
  70. @
  71.  
  72.  
  73. 1.4
  74. log
  75. @checked in with -k by simons at 1993/12/26 00:08:53
  76. @
  77. text
  78. @#include "listserv.h"
  79.  
  80. static char rcsid[] = "$Header: /usr/local/src/mail/listserv/RCS/subscribe.c,v 1.4 92/09/14 11:04:20 andy Exp Locker: andy $";
  81.  
  82. extern FILE *msg;
  83. extern FILE *mailer;
  84.  
  85. subscription(from,command,add,outsider)
  86. char *from,*command;
  87. int add,outsider;
  88.         {
  89.         FILE *list;
  90.         FILE *listtmp;
  91.         char grp[256];
  92.         char adr[256];
  93.         char tmp[256];
  94.         char buf[BUFSIZ];
  95.         int del = 0;
  96.         int i, l;
  97.         int aliasok;
  98.  
  99.         printf("subscription %s %s %d\n", from, command, add);
  100.  
  101.         i = sscanf(command,"%s%s%s", tmp, adr, grp);
  102.         if (i < 2 || i > 3)
  103.                 sendhelp(from, command);
  104.         if (i == 2)
  105.                 {
  106.                 strcpy(grp, adr);
  107.                 strcpy(adr, from);
  108.                 }
  109.  
  110.         cleanup(grp,&i);
  111.         cleanup(adr,&outsider);
  112.  
  113.         if (strcasecmp(grp, adr) == 0)
  114.                 {
  115.                 callmailer("", from, "");
  116.                 fprintf(mailer,"Subscription address loop: %s\n", adr);
  117.                 fflush(mailer);
  118.                 pclose(mailer);
  119.                 return(-1);
  120.                 }
  121.  
  122.         if (outsider)
  123.                 sprintf(tmp,"%s/%s.pub", SERVDIR, grp);
  124.         else
  125.                 sprintf(tmp,"%s/%s.info", SERVDIR, grp);
  126.         if (access(tmp,R_OK) != 0)
  127.                 {
  128.                 callmailer("", from, "");
  129.                 fprintf(mailer,"The mailing list \"%s\" could not be found.\n",
  130.                         grp);
  131.                 fprintf(mailer,"You may use the INDEX command to get a listing\n");
  132.                 fprintf(mailer,"of available mailing lists.\n");
  133.                 fflush(mailer);
  134.                 pclose(mailer);
  135.                 return(-1);
  136.                 }
  137.  
  138.         strcpy(tmp, SERVDIR);
  139.         strcat(tmp, "/");
  140.         strcat(tmp, grp);
  141.         if (add)
  142.                 {
  143.                 l = open(tmp, AFLAGS, AMODE);
  144.                 if (l == -1)
  145.                         {
  146.                         callmailer(LISTSERVMANAGER, from, "");
  147.                         fprintf(mailer,"Error[1] processing request. Please try later.\n");
  148.                         fprintf(mailer,">%s\n", command);
  149.                         fflush(mailer);
  150.                         pclose(mailer);
  151.                         return(-1);
  152.                         }
  153.                 else
  154.                         {
  155.                         list = fdopen(l, "a");
  156.                         if (list == NULL)
  157.                                 {
  158.                                 callmailer(LISTSERVMANAGER, from, "");
  159.                                 fprintf(mailer,"Error[1] processing request. Please try later.\n");
  160.                                 fprintf(mailer,">%s\n", command);
  161.                                 fflush(mailer);
  162.                                 pclose(mailer);
  163.                                 return(-1);
  164.                                 }
  165.                         }
  166.                 flock(l, LOCK_EX);
  167.                 fprintf(list, "%s\n", adr);
  168.                 fflush(list);
  169.                 flock(l, LOCK_UN);
  170.                 close(l);
  171.                 }
  172.         else
  173.                 {
  174.                 del = 0;
  175.                 list = fopen(tmp, "r");
  176.                 if (list == NULL)
  177.                         {
  178.                         callmailer(LISTSERVMANAGER, from, "");
  179.                         fprintf(mailer,"Error[2] processing request. Please try later.\n");
  180.                         fprintf(mailer,">%s\n", command);
  181.                         fflush(mailer);
  182.                         pclose(mailer);
  183.                         return(-1);
  184.                         }
  185.                 flock(fileno(list), LOCK_EX);
  186.  
  187.                 strcpy(tmp, SERVDIR);
  188.                 strcat(tmp, "/");
  189.                 strcat(tmp, grp);
  190.                 strcat(tmp, ".tmp");
  191.                 listtmp = fopen(tmp, "w");
  192.                 if (listtmp == NULL)
  193.                         {
  194.                         callmailer(LISTSERVMANAGER, from, "");
  195.                         fprintf(mailer,"Error[3] processing request. Please try later.\n");
  196.                         fprintf(mailer,">%s\n", command);
  197.                         fflush(mailer);
  198.                         pclose(mailer);
  199.                         return(-1);
  200.                         }
  201.                 /* copy the list, omitting the one address */
  202.                 while (fgets(buf, sizeof(buf), list))
  203.                         {
  204.                         buf[strlen(buf)-1] = '\0';
  205.                         if (strcasecmp(buf, adr))
  206.                                 {
  207.                                 fputs(buf, listtmp);
  208.                                 fputs("\n", listtmp);
  209.                                 }
  210.                         else
  211.                                 del++;
  212.                         }
  213.                 fflush(listtmp);
  214.                 fclose(listtmp);
  215.  
  216.                 /* replace the old list with the shortened one */
  217.                 strcpy(buf, SERVDIR);
  218.                 strcat(buf, "/");
  219.                 strcat(buf, grp);
  220.                 unlink(buf);    /* delete original file */
  221.                 rename(tmp, buf);       /* put updated one in place */
  222.                 flock(fileno(list), LOCK_UN);   /* release lock */
  223.                 }
  224. #ifndef DEBUG
  225.         if (strcmp(from, adr))
  226.                 {
  227.                 callmailer(adr, from, command);
  228.                 fprintf(mailer,"Per request by %s\n", from);
  229.                 }
  230.         else
  231.                 {
  232.                 callmailer("", from, command);
  233.                 fprintf(mailer,"Per your request\n");
  234.                 }
  235. #else
  236.                 callmailer("", from, command);
  237.                 fprintf(mailer,"Per your request\n");
  238. #endif
  239.  
  240.                 fprintf(mailer,"\t\"%s\"\n", command);
  241.         /* Mail subscription confirmation and info/intro files.*/
  242.         if (add)
  243.                 {
  244.                 fprintf(mailer,"'%s' was ADDED to the '%s' mailing list.\n",
  245.                         adr, grp);
  246.                 fflush(mailer);
  247.                 pclose(mailer);
  248.  
  249.                 sprintf(tmp, "%s/%s.intro", SERVDIR,grp);
  250.                 if (access(tmp,R_OK) == 0)
  251.                         {
  252. #ifndef DEBUG
  253.                 callmailer("", adr, command);
  254. #else
  255.                 callmailer("", from, command);
  256. #endif
  257.                 mailcat(tmp, "");
  258.                 sprintf(tmp, "%s/%s.faq", SERVDIR, grp);
  259.                 if(access(tmp,R_OK) == 0)
  260.                         mailcat(tmp,"\n\n");
  261.                 fflush(mailer);
  262.                 pclose(mailer);
  263.                         }
  264.                 }
  265.  
  266.         else
  267.                 if (del)
  268.                         {
  269.                         fprintf(mailer,
  270.                         "'%s' was DELETED from the '%s' mailing list.\n",
  271.                                 adr, grp);
  272.                         fprintf(mailer,
  273.                         "\nAlthough you have been deleted from the list,");
  274.                         fprintf(mailer,
  275.                         " some mail sent previous to your deletion may be\n");
  276.                         fprintf(mailer,
  277.                         "queued in the system. Please don't panic if you");
  278.                         fprintf(mailer,
  279.                         " receive a few last pieces of mail.\n");
  280.                         fflush(mailer);
  281.                         pclose(mailer);
  282.                         }
  283.                 else
  284.                         {
  285.                         fprintf(mailer,
  286.                         "'%s' was NOT FOUND on the '%s' mailing list.\n",
  287.                                 adr, grp);
  288.                         fflush(mailer);
  289.                         pclose(mailer);
  290.                         }
  291.  
  292.         }
  293. @
  294.  
  295.  
  296. 1.4.1.1
  297. log
  298. @Changed source code to compiler under SAS/C 6.50.
  299. @
  300. text
  301. @a1 1
  302. #include "protos.h"
  303. d3 1
  304. a3 1
  305. static char rcsid[] = "$Id$";
  306. d5 4
  307. a8 1
  308. int subscription(from,command,add,outsider)
  309. @
  310.  
  311.  
  312. 1.4.1.2
  313. log
  314. @Removed the complete local/non-local user determination, including
  315. all >outsider< parameters and the cleanup() routine.
  316. Changed UNIX-paths to conform with AmigaDOS.
  317. @
  318. text
  319. @d4 1
  320. a4 1
  321. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.1 1993/12/26 00:42:45 simons Exp simons $";
  322. d6 1
  323. a6 1
  324. int subscription(from,command,add)
  325. d8 1
  326. a8 1
  327. int add;
  328. d31 3
  329. d43 4
  330. a46 1
  331.         sprintf(tmp,"%s%s.pub", SERVDIR, grp);
  332. d60 1
  333. d109 1
  334. d139 1
  335. d170 1
  336. a170 1
  337.                 sprintf(tmp, "%s%s.intro", SERVDIR,grp);
  338. d179 1
  339. a179 1
  340.                 sprintf(tmp, "%s%s.faq", SERVDIR, grp);
  341. @
  342.  
  343.  
  344. 1.4.1.3
  345. log
  346. @Fixed the 'ADD'-command. Currently, it's not detected when somebody
  347. adds his address several times to the same list.
  348. @
  349. text
  350. @d4 1
  351. a4 1
  352. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.2 1993/12/26 19:35:55 simons Exp simons $";
  353. d17 2
  354. a18 1
  355.         int i;
  356. d31 1
  357. a31 1
  358.         if (!strcasecmp(grp, adr))
  359. d40 2
  360. a41 2
  361.         sprintf(tmp,"%s%s/LIST", LISTDIR, grp);
  362.         if (access(tmp,R_OK))
  363. d53 2
  364. d57 2
  365. a58 1
  366.                 if (!(list = fopen(tmp, "a")))
  367. d67 14
  368. a80 1
  369.                 /* FileLock(tmp)        ---FIXME */
  370. d82 3
  371. a84 2
  372.                 fclose(list);
  373.                 /* UnFileLock(tmp)        ---FIXME */
  374. @
  375.  
  376.  
  377. 1.4.1.4
  378. log
  379. @Corrected the routine handling 'DELETE'-commands.
  380. @
  381. text
  382. @d4 1
  383. a4 1
  384. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.3 1993/12/26 19:56:04 simons Exp simons $";
  385. d12 4
  386. a15 1
  387.         char grp[256], adr[256], tmp[256], tmp2[256], buf[BUFSIZ];
  388. a53 1
  389.                 /* FileLock(tmp)        ---FIXME */
  390. d63 1
  391. d71 2
  392. a72 2
  393.                 /* FileLock(tmp)        ---FIXME */
  394.                 if (!(list = fopen(tmp, "r")))
  395. d81 1
  396. d83 5
  397. a87 2
  398.                 sprintf(tmp2, "%s.tmp", tmp);
  399.                 if (!(listtmp = fopen(tmp2, "w")))
  400. d108 1
  401. d110 1
  402. a110 1
  403.                 fclose(list);
  404. d112 5
  405. a116 4
  406.  
  407.                 remove(tmp);            /* delete original file */
  408.                 rename(tmp2, tmp);      /* put updated one in place */
  409.                 /* UnFileLock(tmp);        ---FIXME */
  410. @
  411.  
  412.  
  413. 1.4.1.5
  414. log
  415. @Added filelocking mechanism.
  416. @
  417. text
  418. @d4 1
  419. a4 1
  420. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.4 1993/12/26 20:26:43 simons Exp simons $";
  421. d51 1
  422. a51 1
  423.                 LockFile(tmp);
  424. d63 1
  425. a63 1
  426.                 UnLockFile(tmp);
  427. d68 1
  428. a68 1
  429.                 LockFile(tmp);
  430. a79 1
  431.                 LockFile(tmp2);
  432. d107 1
  433. a107 2
  434.                 UnLockFile(tmp);
  435.                 UnLockFile(tmp2);
  436. @
  437.  
  438.  
  439. 1.4.1.6
  440. log
  441. @Changes filenames for the address-list.
  442. @
  443. text
  444. @d4 1
  445. a4 1
  446. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.5 1993/12/26 21:22:27 simons Exp simons $";
  447. d36 1
  448. a36 1
  449.         sprintf(tmp,"%s%s/List", LISTDIR, grp);
  450. @
  451.  
  452.  
  453. 1.4.1.7
  454. log
  455. @Improved file-locking.
  456. Notification about un-/subscription is now directed to the address that
  457. is changed, not the the from line.
  458. LISTSERVMANAGER receives a carbon copy of any list-change.
  459. @
  460. text
  461. @d4 1
  462. a4 1
  463. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.6 1993/12/27 17:37:04 simons Exp simons $";
  464. d29 1
  465. a29 1
  466.                 callmailer(LISTSERVMANAGER, from, "");
  467. a36 1
  468.         LockFile(tmp);
  469. a38 1
  470.                 UnLockFile(tmp);
  471. d51 1
  472. a53 1
  473.                         UnLockFile(tmp);
  474. d68 1
  475. a70 1
  476.                         UnLockFile(tmp);
  477. d111 1
  478. a111 4
  479.  
  480.  
  481.         /* Mail subscription confirmation and introduction files.*/
  482.  
  483. d114 2
  484. a115 2
  485.                 callmailer(LISTSERVMANAGER, adr, command);
  486.                 fprintf(mailer, "Per request by %s\n", from);
  487. d119 1
  488. a119 1
  489.                 callmailer(LISTSERVMANAGER, from, command);
  490. d122 4
  491. d128 1
  492. a128 1
  493.  
  494. d136 15
  495. a150 3
  496.                 /* mail introduction file       --TODO
  497.                  */
  498.  
  499. @
  500.  
  501.  
  502. 1.4.1.8
  503. log
  504. @Changed function declarations to ANSI-compliant style.
  505. @
  506. text
  507. @d4 1
  508. a4 1
  509. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.7 1993/12/28 17:24:22 simons Exp simons $";
  510. d6 4
  511. a9 4
  512. int subscription(char *from,
  513.                  char *command,
  514.                  int add)
  515. {
  516. @
  517.  
  518.  
  519. 1.4.1.9
  520. log
  521. @Removed the strange internal string compare routines.
  522. @
  523. text
  524. @d4 1
  525. a4 1
  526. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.8 1993/12/28 22:16:34 simons Exp simons $";
  527. d27 1
  528. a27 1
  529.         if (!stricmp(grp, adr))
  530. d96 1
  531. a96 1
  532.                         if (stricmp(buf, adr))
  533. @
  534.  
  535.  
  536. 1.4.1.10
  537. log
  538. @Changed a string comparison to be case-independent.
  539. @
  540. text
  541. @d4 1
  542. a4 1
  543. static char rcsid[] = "$Id: subscribe.c,v 1.4.1.9 1993/12/29 06:24:47 simons Exp simons $";
  544. d117 1
  545. a117 1
  546.         if (stricmp(from, adr))
  547. @
  548.