7a9f96bbd7e866c03207e9fa1c91496067a7ca76
[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 "citadel.h"
11
12 void get_config();
13 struct config config;
14
15 void make_message(filename)
16 char *filename; {
17         FILE *fp;
18         int a;
19         long bb,cc,now;
20         time(&now);
21         fp=fopen(filename,"wb"); if (fp==NULL) exit(22);
22         putc(255,fp);
23         putc(MES_NORMAL,fp);
24         putc(1,fp);
25         fprintf(fp,"Proom_aide"); putc(0,fp);
26         fprintf(fp,"T%ld",now); putc(0,fp);
27         fprintf(fp,"ACitadel"); putc(0,fp);
28         fprintf(fp,"OAide"); putc(0,fp);
29         fprintf(fp,"N%s",NODENAME); putc(0,fp);
30         putc('M',fp);
31         bb=ftell(fp);
32         while (a=getc(stdin), a>0) {
33                 if (a!=8) putc(a,fp);
34                 else {
35                         cc=ftell(fp);
36                         if (cc!=bb) fseek(fp,(-1L),1);
37                         }
38                 }
39         putc(0,fp);
40         putc(0,fp);
41         putc(0,fp);
42         fclose(fp);
43         }
44
45 void main(argc,argv)
46 int argc;
47 char *argv[];
48 {
49         char tempbase[32];
50         char temptmp[64];
51         char tempspool[64];
52         char movecmd[256];
53         
54         get_config();
55         sprintf(tempbase,"ap.%d",getpid());
56         sprintf(temptmp,"/tmp/%s", tempbase);
57         sprintf(tempspool,"./network/spoolin/%s", tempbase);
58         make_message(temptmp);
59
60         sprintf(movecmd, "/bin/mv %s %s", temptmp, tempspool);
61         system(movecmd);
62
63         execlp("./netproc","netproc",NULL);
64         fprintf(stderr,"aidepost: could not run netproc\n");
65         exit(1);
66         }