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