/*@RRL (c),Jun-1997 */ #include #include #include #include #include #include #include #include "nntp.h" extern void *NNTPCP_CLD; int getYesNo (void); #define INIT_SDESC(dsc, len, ptr) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_S; (dsc).dsc$w_length = (len);\ (dsc).dsc$a_pointer = (ptr);} #define $DESC(string) { sizeof( string ) - 1, DSC$K_DTYPE_T, DSC$K_CLASS_S, string } static struct dsc$descriptor cmd[] = { $DESC("SET"), $DESC("SHOW"), $DESC("HELP"), $DESC("ADD"), $DESC("DELETE") }; static struct dsc$descriptor par[] = { $DESC("GROUP") }; static struct dsc$descriptor q_suck = $DESC("SUCK"); static struct dsc$descriptor q_post = $DESC("POST"); static struct dsc$descriptor q_conf = $DESC("CONFIRM"); static struct dsc$descriptor q_log = $DESC("LOGGING"); static struct dsc$descriptor welcome= $DESC("\n\t\tNNTP Server Control Program,(c)@RRL\n"); static struct dsc$descriptor prompt = $DESC("NNTP-CP>"); char par_buf [ 1024 ]; char tmp_buf [ 1024 ]; static struct dsc$descriptor junk = $DESC(par_buf); WorkerContext *Wctxp; /* *-------------------------------------------------------------------------------- */ void main (void) { long status; status = lib$put_output (&welcome); if (! (status & 1)) lib$signal(status); MsgDBopen(); GrpDBopen(); SuckDBopen(); if ( NULL == (Wctxp = calloc(1,sizeof (WorkerContext))) ) { perror("calloc"); return; } if ( MsgDBopen_stream (&Wctxp->Msgrab) ) { perror("open MsgStream"); return; } if ( GrpDBopen_stream (&Wctxp->Grprab) ) { perror("GrpDBopen_stream."); DBclose_stream(&Wctxp->Msgrab); free (Wctxp); return; } if ( SuckDBopen_stream (&Wctxp->Suckrab) ) { perror("[SuckInit]SuckDBopen_stream"); DBclose_stream(&Wctxp->Msgrab); DBclose_stream(&Wctxp->Grprab); free (Wctxp); } while ( RMS$_EOF != ( status=cli$dcl_parse (0,&NNTPCP_CLD,lib$get_input,lib$get_input,&prompt)) ) { if ( status != CLI$_NORMAL ) continue; status = cli$dispatch(); if ( !(status & 1)) { lib$signal(status); break; } printf("\n"); } NNTPCP_CMD_EXIT (); } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_EXIT (void) { DBclose_stream (&Wctxp->Msgrab); DBclose_stream (&Wctxp->Grprab); DBclose_stream (&Wctxp->Suckrab); DBclose(); exit(0); } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_SET (void) { long status; long len,flag; long suck,post,suck_f,post_f,conf,log; GrpKey *gkeyp = (GrpKey *) &tmp_buf [ 0 ]; int changes; int n; time_t t; len = flag = suck = post = suck_f = post_f = n = 0; conf = log = 1; if ( CLI$_PRESENT != cli$present (&q_conf) ) conf = 0; else conf = 1; if ( CLI$_PRESENT != cli$present (&q_log) ) log = 0; else log = 1; /* */ if ( CLI$_PRESENT == cli$present (&q_suck) ) { status = cli$get_value(&q_suck,&junk,&len); if (! (status & 1)) return status; suck = 1; suck_f = (par_buf[0] == 'Y'?1:0); } /* */ if ( CLI$_PRESENT == cli$present (&q_post) ) { status = cli$get_value(&q_post,&junk,&len); if (! (status & 1)) return status; post = 1; post_f = tolower (par_buf[0]); } status = cli$get_value(&par[0],&junk,&len); if ( !(status & 1) ) return status; par_buf[len] = 0; printf("\nSet for '%s'",par_buf); if ( suck ) printf("\nSucking %s",(suck_f?"ON":"OFF")); if ( post ) printf("\nPosting to '%c'",post_f); printf("\nConfirmation %s",(conf?"ON":"OFF")); printf(" Logging %s",(log?"ON":"OFF")); printf("\n First msg#| Last msg#|P|S|Group Name...."); /* * Check for wildcard and if not, make up for one group only */ if ( !strpbrk (par_buf,"*%") ) { strncpy (gkeyp->GrpName,par_buf,GrpName$_len); if ( 0 >= GrpDBget(&Wctxp->Grprab,gkeyp,gkeyp,0) ) return SS$_NORMAL; if ( log ) printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, gkeyp->SuckFlag?'y':' ', GrpName$_len,gkeyp->GrpName); if ( suck && (gkeyp->SuckFlag != suck_f) ) { gkeyp->SuckFlag = suck_f; changes = 1; } if ( post && (gkeyp->PostFlag != post_f) ) { gkeyp->PostFlag = post_f; changes = 1; } if ( log ) printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, (gkeyp->SuckFlag?'y':' '), GrpName$_len,gkeyp->GrpName); /* */ if ( conf && (0 >= getYesNo ())) return SS$_NORMAL; /* */ if ( 0 >= GrpDBget(&Wctxp->Grprab,gkeyp,gkeyp,1) ) return SS$_NORMAL; if ( suck ) { time(&gkeyp->DateUp); gkeyp->SuckFlag = suck_f; } if ( post ) gkeyp->PostFlag = post_f; GrpDBput(&Wctxp->Grprab,gkeyp,gkeyp); if (log) printf("\nchanges completed"); return SS$_NORMAL; } while ( GrpDBget_seq(&Wctxp->Grprab,(char *) gkeyp,flag++) ) { changes = 0; if ( strmatch (&par_buf[0],&gkeyp->GrpName[0]) ) { /* */ if ( log ) printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, gkeyp->SuckFlag?'y':' ', GrpName$_len,gkeyp->GrpName); if ( suck && (gkeyp->SuckFlag != suck_f) ) { gkeyp->SuckFlag = suck_f; time(&gkeyp->DateUp); changes = 1; } if ( post && (gkeyp->PostFlag != post_f) ) { gkeyp->PostFlag = post_f; changes = 1; } /* */ if ( !changes ) continue; /* */ if ( log ) printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, (gkeyp->SuckFlag?'y':' '), GrpName$_len,gkeyp->GrpName); /* */ if ( conf ) { status = getYesNo (); if ( status < 0 ) break; if ( !status) continue; } /* */ if ( 0 >= GrpDBget(&Wctxp->Grprab,gkeyp,gkeyp,1) ) continue; if ( suck ) { time(&gkeyp->DateUp); gkeyp->SuckFlag = suck_f; } if ( post ) gkeyp->PostFlag = post_f; GrpDBput(&Wctxp->Grprab,gkeyp,gkeyp); n++; } } if (log) printf("\n%d changes completed",n); return SS$_NORMAL; } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_SHOW (void) { long status; long len,flag; int suck; GrpKey *gkeyp = (GrpKey *) &tmp_buf [ 0 ]; char buf [ 128 ]; len = flag = suck = 0; status = cli$get_value(&par[0],&junk,&len); if (! (status & 1)) { lib$signal(status); return status; } par_buf[len] = 0; if ( CLI$_PRESENT == cli$present (&q_suck) ) suck = 1; printf("\nShow information for '%s'",par_buf); printf("\n First msg#| Last msg#|P|S|Group Name...."); if ( !strpbrk(par_buf,"*%") ) { strncpy (gkeyp->GrpName,par_buf,GrpName$_len); if ( 0 >= GrpDBget(&Wctxp->Grprab,gkeyp,gkeyp,0) ) return SS$_NORMAL; printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, gkeyp->SuckFlag?'y':' ', GrpName$_len,gkeyp->GrpName); return SS$_NORMAL; } while ( GrpDBget_seq(&Wctxp->Grprab,(char *) gkeyp,flag++) ) { if ( strmatch (par_buf,gkeyp->GrpName) ) { if ( suck && (!gkeyp->SuckFlag) ) continue; printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, (gkeyp->SuckFlag?'y':' '), GrpName$_len,gkeyp->GrpName); printf("\nDateCr = %s",ctime(&gkeyp->DateCr)); printf("\nDateUp = %s",ctime(&gkeyp->DateUp)); } } return SS$_NORMAL; } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_HELP (void) { long status; char hlp_lib [ ] = "nntpcp.hlb"; struct dsc$descriptor hlp_lib_dsc; long hlp_flg = HLP$M_PROMPT | HLP$M_HELP; INIT_SDESC (hlp_lib_dsc,sizeof(hlp_lib)-1,&hlp_lib[0]); return ( lbr$output_help ( lib$put_output, 0, 0, &hlp_lib_dsc, &hlp_flg, lib$get_input)); } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_DELETE (void) { return SS$_NORMAL; } int getYesNo (void) { long status; char buf [ 2 ]; struct dsc$descriptor dsc_buf; struct dsc$descriptor dsc_yn; long len; char c_buf [] = "\r\nConfirm by press [Y/N]:"; INIT_SDESC (dsc_yn,sizeof(c_buf)-1,c_buf); INIT_SDESC (dsc_buf,sizeof(buf)-1,buf); status = lib$get_input(&dsc_buf,&dsc_yn,&len); if (! (status & 1)) return -1; return ( ((buf[0] == 'y') || (buf[0] == 'Y'))?1:0); } /* *-------------------------------------------------------------------------------- */ int NNTPCP_CMD_ADD (void) { long status; long len,flag; long suck,post,suck_f,post_f,conf,log; GrpKey *gkeyp = (GrpKey *) &tmp_buf [ 0 ]; int changes; int n; time_t t; len = flag = suck = post = suck_f = post_f = n = 0; conf = log = 1; if ( CLI$_PRESENT != cli$present (&q_conf) ) conf = 0; else conf = 1; if ( CLI$_PRESENT != cli$present (&q_log) ) log = 0; else log = 1; /* */ if ( CLI$_PRESENT == cli$present (&q_suck) ) { status = cli$get_value(&q_suck,&junk,&len); if (! (status & 1)) return status; suck = 1; suck_f = (par_buf[0] == 'N'?0:1); } /* */ if ( CLI$_PRESENT == cli$present (&q_post) ) { status = cli$get_value(&q_post,&junk,&len); if (! (status & 1)) return status; post = 1; post_f = tolower (par_buf[0]); } status = cli$get_value(&par[0],&junk,&len); if ( !(status & 1) ) return status; par_buf[len] = 0; printf("\nAdd '%s'",par_buf); if ( suck ) printf("\nSucking %s",(suck_f?"ON":"OFF")); if ( post ) printf("\nPosting to '%c'",post_f); printf("\nConfirmation %s",(conf?"ON":"OFF")); printf(" Logging %s",(log?"ON":"OFF")); printf("\n First msg#| Last msg#|P|S|Group Name...."); /* * Check for wildcard and if not, make up for one group only */ if ( !strpbrk (par_buf,"*%") ) { strncpy (gkeyp->GrpName,par_buf,GrpName$_len); if ( 0 < GrpDBget(&Wctxp->Grprab,gkeyp,gkeyp,0) ) return SS$_NORMAL; time(&gkeyp->DateUp); time(&gkeyp->DateCr); gkeyp->SuckFlag = suck_f; gkeyp->PostFlag = post_f; gkeyp->First = gkeyp->Last = 0; if ( log ) printf("\n%11lu|%11lu|%c|%c|%.*s", gkeyp->First,gkeyp->Last, gkeyp->PostFlag, (gkeyp->SuckFlag?'y':' '), GrpName$_len,gkeyp->GrpName); /* */ if ( conf && (0 >= getYesNo ())) return SS$_NORMAL; GrpDBput(&Wctxp->Grprab,gkeyp,gkeyp); if (log) printf("\ngroup created"); return SS$_NORMAL; } }