|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 6282 (0x188a)
Types: TextFile
Names: »tb_getdl.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Lib/table/tb_getdl.c«
/* tb_getdl.c: expand a distribution list */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_getdl.c,v 5.0 90/09/20 16:15:23 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_getdl.c,v 5.0 90/09/20 16:15:23 pp Exp Locker: pp $
*
* $Log: tb_getdl.c,v $
* Revision 5.0 90/09/20 16:15:23 pp
* rcsforce : 5.0 public release
*
*/
#include "util.h"
#include "chan.h"
#include "table.h"
#include "dl.h"
#include "adr.h"
#include "retcode.h"
#include <sys/stat.h>
ADDR *tb_getModerator();
static Table *List = NULLTBL;
static Name *getNames();
static Name *getNamesFromFile();
Name *new_Name();
extern char *compress ();
/*
This routine returns the values:
NOTOK - Table or routine erroe.
OK - List found in Table
DONE - List not found in Table
*/
char *namefile;
extern char *list_tbl;
tb_getdl (key, plist,complain)
char *key;
dl **plist;
int complain;
{
char buf[BUFSIZ],
*ix,
*start,
mod[FILNSIZE],
*str;
int error;
ADDR *adr;
extern char *postmaster;
namefile = NULLCP;
*plist = NULL;
PP_DBG(("tb_getdl (%s)", key));
if (List == NULLTBL)
if ((List = tb_nm2struct(list_tbl)) == NULLTBL) {
PP_LOG(LLOG_EXCEPTIONS, ("tb_getdl (no table)"));
return NOTOK;
}
if (tb_k2val (List, key, buf) == NOTOK) {
if (complain == OK)
PP_LOG(LLOG_EXCEPTIONS,
("Unable to find entry for %s in list table %s",
key, list_tbl));
return (DONE);
}
*plist = (dl *) calloc(1, sizeof(dl));
(*plist) -> dl_listname = strdup(key);
error = FALSE;
start = &(buf[0]);
if ((adr = tb_getModerator(key)) == NULLADDR) {
PP_LOG(LLOG_EXCEPTIONS,
("Unable to get moderator for dl '%s'",key));
error = TRUE;
} else {
(*plist) -> dl_moderator = strdup(adr->ad_value);
adr_free(adr);
}
if ((ix = index(start, ',')) == NULLCP) {
PP_LOG(LLOG_EXCEPTIONS,
("tb_getdl syntax error for '%s' : listname:[uids],...", key));
error = TRUE;
} else {
*ix = '\0';
compress(start,mod);
if (mod[0] != '\0')
(*plist)->dl_uids = getNames(mod, &error);
else
(*plist)->dl_uids = NULL;
}
start = ix+1;
if (error == FALSE) {
str = start;
ix = index(str, ',');
if (ix != NULL)
*ix++ = '\0';
(*plist) -> dl_desc = ix;
(*plist) -> dl_list = getNames(str, &error);
(*plist) -> dl_file = namefile;
}
if (error == TRUE) {
dl_free(*plist);
*plist = NULL;
return NOTOK;
}
return OK;
}
Name *new_Name(str, file)
char *str;
char *file;
{
Name *ret = (Name *) calloc(1, sizeof(Name));
ret -> name = strdup(str);
if (file)
ret -> file = strdup(file);
return ret;
}
static Name *getNames(str, perror)
char *str;
int *perror;
{
Name *head = NULL,
*tail = NULL,
*temp = NULL;
char *ix;
while ((ix = index(str,'|')) != NULL) {
*ix = NULL;
if (strncmp(str,"file=",strlen("file=")) == 0)
temp = getNamesFromFile(str, perror);
else
temp = new_Name(str, NULLCP);
if (head == NULL)
head = tail = temp;
else
tail -> next = temp;
while (tail -> next != NULL)
tail = tail->next;
str = ix + 1;
}
if (strcmp(str,"") != 0) {
if (strncmp(str,"file=",strlen("file=")) == 0)
temp = getNamesFromFile(str,perror);
else
temp = new_Name(str,NULLCP);
if (head == NULL)
head = tail = temp;
else
tail -> next = temp;
}
return head;
}
extern char *postmaster;
extern char *loc_dist_prefix;
ADDR *tb_getModerator(list)
char *list;
{
char moderator[LINESIZE],
*ix;
ADDR *adr;
RP_Buf rp;
if ((ix = index(list, '@')) != NULL)
*ix = '\0';
if (strncmp(list, loc_dist_prefix, strlen(loc_dist_prefix)) == 0) {
/* attempt to strip of loc_dist_prefix to find moderator */
sprintf(moderator,
"%s-request",
(list+strlen(loc_dist_prefix)));
adr = adr_new (moderator, AD_822_TYPE, 0);
adr -> ad_resp = NO;
if (!rp_isbad(ad_parse(adr, &rp, CH_UK_PREF))) {
if (ix != NULL) *ix = '@';
return adr;
}
adr_free(adr);
}
sprintf(moderator,"%s-request",list);
adr = adr_new (moderator, AD_822_TYPE, 0);
adr -> ad_resp = NO;
if (!rp_isbad(ad_parse(adr, &rp, CH_UK_PREF)))
return adr;
adr_free(adr);
adr = adr_new (postmaster, AD_822_TYPE, 0);
adr -> ad_resp = NO;
if (rp_isbad(ad_parse(adr, &rp, CH_UK_PREF))) {
PP_OPER(NULLCP,
("Failed to parse postmaster '%s' [%s]",
postmaster, adr->ad_parse_message));
adr_free(adr);
return NULLADDR;
}
return adr;
}
static Name *getNamesFromFile(file, perror)
char *file;
int *perror;
{
Name *head = NULL,
*tail = NULL,
*temp;
char entry[LINESIZE],
fullname[FILNSIZE],
*ix;
struct stat statbuf;
extern char *tbldfldir;
FILE *fd;
int len;
if ((ix = index(file,'=')) == NULLCP) {
PP_LOG(LLOG_EXCEPTIONS,
("getNamesFromFile: error in parsing '%s'",file));
*perror = TRUE;
return NULL;
}
ix++;
if (ix[0] != '/')
(void) sprintf(fullname, "%s/%s", tbldfldir, ix);
else
(void) sprintf(fullname, "%s", ix);
if (namefile == NULLCP) namefile = strdup(fullname);
if (stat (fullname, &statbuf) != OK) {
PP_OPER(fullname, ("unable to stat file"));
*perror = TRUE;
return NULL;
}
if ((statbuf.st_mode & S_IFMT) != S_IFREG) {
PP_OPER(fullname, ("Not a regular file"));
*perror = TRUE;
return NULL;
}
if ((fd = fopen(fullname,"r")) == NULL) {
PP_OPER(fullname, ("Can't open file"));
*perror = TRUE;
return NULL;
}
while (fgets(entry, LINESIZE, fd) != NULL) {
if (entry[0] == '\n' || entry[0] == '#')
continue;
len = strlen(entry);
if (entry[len-1] == '\n') entry[len-1] = '\0';
temp = new_Name(entry, fullname);
if (head == NULL)
head = tail = temp;
else {
tail->next = temp;
tail = temp;
}
}
fclose(fd);
return head;
}
name_free(list)
Name *list;
{
if (list == NULL)
return;
if (list -> next)
name_free(list -> next);
if (list -> name)
free(list -> name);
if (list -> file)
free(list->file);
free((char *) list);
}
dl_free(list)
dl *list;
{
if (list == NULLDL)
return;
if (list -> dl_listname)
free(list -> dl_listname);
if (list -> dl_moderator)
free(list -> dl_moderator);
if (list -> dl_uids)
name_free(list -> dl_uids);
if (list -> dl_list)
name_free(list -> dl_list);
if (list -> dl_file)
free(list -> dl_file);
free((char *) list);
}