X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Faidepost.c;h=7b637f548233be8400ce3e426b7dabbe526d8794;hb=4eb74b26380dfde31c86c685f0589e0c653aebf0;hp=a54bc1e18d3751795ec1dbc7c7799e12c71d0422;hpb=2cb3d0539cfeec5498f03420ae57fc2286cf9f72;p=citadel.git diff --git a/citadel/aidepost.c b/citadel/aidepost.c index a54bc1e18..7b637f548 100644 --- a/citadel/aidepost.c +++ b/citadel/aidepost.c @@ -1,65 +1,168 @@ -/* aidepost.c - * This is just a little hack to copy standard input to a message in Aide> - * v1.6 +/* * $Id$ + * + * This is just a little hack to copy standard input to a message in Aide> + * + * Copyright (c) 1987-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include -#include + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + #include +#include +#include #include "citadel.h" +#include "citadel_dirs.h" #include "config.h" -void make_message(char *filename) +#ifndef HAVE_SNPRINTF +#include "snprintf.h" +#endif + + +/* + * Simplified function to generate a message in our format + */ +static void ap_make_message(FILE *fp, char *target_room, char *author, char *subject) { - FILE *fp; int a; - long bb,cc; + long bb, cc; time_t now; time(&now); - fp=fopen(filename,"wb"); if (fp==NULL) exit(22); - putc(255,fp); - putc(MES_NORMAL,fp); - putc(1,fp); - fprintf(fp,"Proom_aide"); putc(0,fp); - fprintf(fp,"T%ld",now); putc(0,fp); - fprintf(fp,"ACitadel"); putc(0,fp); - fprintf(fp,"OAide"); putc(0,fp); - fprintf(fp,"N%s",NODENAME); putc(0,fp); - putc('M',fp); - bb=ftell(fp); - while (a=getc(stdin), a>0) { - if (a!=8) putc(a,fp); + putc(255, fp); + putc(MES_NORMAL, fp); + putc(1, fp); + fprintf(fp, "Proom_aide"); + putc(0, fp); + fprintf(fp, "T%ld", (long)now); + putc(0, fp); + fprintf(fp, "A%s", author); + putc(0, fp); + fprintf(fp, "O%s", target_room); + putc(0, fp); + if (strlen(subject) > 0) { + fprintf(fp, "U%s%c", subject, 0); + } + fprintf(fp, "N%s", NODENAME); + putc(0, fp); + putc('M', fp); + bb = ftell(fp); + while (a = getc(stdin), a > 0) { + if (a != 8) + putc(a, fp); else { - cc=ftell(fp); - if (cc!=bb) fseek(fp,(-1L),1); - } + cc = ftell(fp); + if (cc != bb) + fseek(fp, (-1L), 1); } - putc(0,fp); - putc(0,fp); - putc(0,fp); - fclose(fp); } + putc(0, fp); + putc(0, fp); + putc(0, fp); +} int main(int argc, char **argv) { - char tempbase[32]; - char temptmp[64]; char tempspool[64]; - char movecmd[256]; - + char target_room[ROOMNAMELEN]; + char author[64]; + char subject[256]; + FILE *tempfp, *spoolfp; + int ch; + int i; + + int relh=0; + int home=0; + char relhome[PATH_MAX]=""; + char ctdldir[PATH_MAX]=CTDLDIR; + + /* TODO: should we be able to calculate relative dirs? */ + calc_dirs_n_files(relh, home, relhome, ctdldir, 0); + + get_config(); - snprintf(tempbase,sizeof tempbase,"ap.%d",getpid()); - snprintf(temptmp,sizeof temptmp,"/tmp/%s", tempbase); - snprintf(tempspool,sizeof tempspool,"./network/spoolin/%s", tempbase); - make_message(temptmp); - snprintf(movecmd, sizeof movecmd, "/bin/mv %s %s", temptmp, tempspool); - system(movecmd); + strcpy(target_room, "Aide"); + strcpy(author, "Citadel"); + strcpy(subject, ""); + for (i=1; i= 0)) { + putc(ch, spoolfp); + } + + fclose(tempfp); + fclose(spoolfp); + + exit(0); +}