Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[citadel.git] / citadel / aidepost.c
1 /* aidepost.c
2  * This is just a little hack to copy standard input to a message in Aide>
3  * v1.6
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <limits.h>
11 #include "citadel.h"
12 #include "config.h"
13
14 void make_message(char *filename)
15 {
16         FILE *fp;
17         int a;
18         long bb,cc,now;
19         time(&now);
20         fp=fopen(filename,"wb"); if (fp==NULL) exit(22);
21         putc(255,fp);
22         putc(MES_NORMAL,fp);
23         putc(1,fp);
24         fprintf(fp,"Proom_aide"); putc(0,fp);
25         fprintf(fp,"T%ld",now); putc(0,fp);
26         fprintf(fp,"ACitadel"); putc(0,fp);
27         fprintf(fp,"OAide"); putc(0,fp);
28         fprintf(fp,"N%s",NODENAME); putc(0,fp);
29         putc('M',fp);
30         bb=ftell(fp);
31         while (a=getc(stdin), a>0) {
32                 if (a!=8) putc(a,fp);
33                 else {
34                         cc=ftell(fp);
35                         if (cc!=bb) fseek(fp,(-1L),1);
36                         }
37                 }
38         putc(0,fp);
39         putc(0,fp);
40         putc(0,fp);
41         fclose(fp);
42         }
43
44 void main(int argc, char **argv)
45 {
46         char tempbase[32];
47         char temptmp[64];
48         char tempspool[64];
49         char movecmd[256];
50         
51         get_config();
52         sprintf(tempbase,"ap.%d",getpid());
53         sprintf(temptmp,"/tmp/%s", tempbase);
54         sprintf(tempspool,"./network/spoolin/%s", tempbase);
55         make_message(temptmp);
56
57         sprintf(movecmd, "/bin/mv %s %s", temptmp, tempspool);
58         system(movecmd);
59
60         execlp("./netproc","netproc",NULL);
61         fprintf(stderr,"aidepost: could not run netproc\n");
62         exit(1);
63         }