|
|
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 u
Length: 4194 (0x1062)
Types: TextFile
Names: »ut_qid.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Lib/pp/ut_qid.c«
/* ut_qid.c: A qid2dir mapping utility */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/pp/RCS/ut_qid.c,v 5.0 90/09/20 16:13:22 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Lib/pp/RCS/ut_qid.c,v 5.0 90/09/20 16:13:22 pp Exp Locker: pp $
*
* $Log: ut_qid.c,v $
* Revision 5.0 90/09/20 16:13:22 pp
* rcsforce : 5.0 public release
*
*/
#include "util.h"
#include "adr.h"
#include <sys/stat.h>
extern char *quedfldir; /* -- "/usr/spool/pp/queues" -- */
extern char *mquedir; /* -- "msg/" -- */
extern char *bquedir; /* -- "base" -- */
static void QID_free ();
static int QID_stat_dir ();
static int QID_adr_chks ();
static int QID_get_dirname ();
/* --------------------- Begin Routines -------------------------------- */
/* --- *** ---
Maps a given q-id (e.g msg.XXXX), and address, onto its current dir
(e.g Q/msg/msg.XXX/base.rfmt.rfmt)
--- *** --- */
int qid2dir (qid, ap, exists, cpp)
char *qid; /* -- queue id (given) -- */
ADDR *ap; /* -- recipient address (given) -- */
int exists; /* -- return NOTOK, if exists==TRUE && if the dir
required does not exist -- */
char **cpp; /* -- malloced to contain the dir name (updated) -- */
{
char msg_dir[FILNSIZE];
PP_DBG (("Lib/pp/qid2dir (%s)", qid));
QID_free (cpp);
/* -- checks that the directories exist by stat ing them -- */
if (QID_stat_dir (quedfldir) == NOTOK)
return (NOTOK);
else {
(void) sprintf (msg_dir, "%s/%s", mquedir, qid);
if (QID_stat_dir (msg_dir) == NOTOK)
return (NOTOK);
}
/* -- checks that a valid recipient address has been specified -- */
if (exists && QID_adr_chks (ap) == NOTOK)
return (NOTOK);
/* -- *** ---
gets the current dir for that msg version associated with that
recipient address
--- *** --- */
if (QID_get_dirname (ap, msg_dir, cpp) == NOTOK)
return (NOTOK);
/* -- checks that the directory exists by stat ing it -- */
if ((exists == TRUE) && (QID_stat_dir (*cpp) == NOTOK)) {
if (*cpp)
QID_free (cpp);
return (NOTOK);
}
return (OK);
}
/* --------------------- Static Routines ------------------------------- */
static int QID_stat_dir (dir)
char *dir;
{
struct stat statbuf;
PP_DBG (("Lib/pp/QID_stat_dir (%s)", dir));
if (dir == NULLCP) {
PP_LOG (LLOG_EXCEPTIONS, ("Lib/pp/QID_stat_dir no dir given"));
return (NOTOK);
}
if ((stat (dir,&statbuf) != OK)
&& ((statbuf.st_mode & S_IFMT) != S_IFDIR)) {
PP_LOG (LLOG_EXCEPTIONS,
("Lib/pp/QID_stat_dir:'stat %s' failed", dir));
return (NOTOK);
}
return (OK);
}
static int QID_adr_chks (ap)
ADDR *ap;
{
PP_DBG (("Lib/pp/QID_adr_chks()"));
if (ap == NULLADDR) {
PP_DBG (("Lib/pp/QID_adr_chks no ADDR given"));
return (NOTOK);
}
if (ap->ad_status == AD_STAT_DONE) {
PP_LOG (LLOG_EXCEPTIONS, ("Lib/pp/QID_adr_chks (stat err %d)",
ap->ad_status));
return (NOTOK);
}
return (OK);
}
static int QID_get_dirname (ap, msg_dir, cpp)
ADDR *ap;
char *msg_dir, **cpp;
{
char buf[FILNSIZE];
LIST_RCHAN *rp = ap->ad_fmtchan;
int i;
PP_DBG (("Lib/pp/QID_get_dirname()"));
if (ap->ad_rcnt == 0) {
*cpp = malloc ((unsigned) (strlen (msg_dir) + 1
+ 1 + strlen (bquedir)));
(void) sprintf (*cpp, "%s/%s", msg_dir, bquedir);
return (OK);
}
else if (rp == NULLIST_RCHAN && ap->ad_rcnt != 0) {
PP_LOG (LLOG_EXCEPTIONS, ("Lib/pp/QID_get_dirname (null err)"));
return (NOTOK);
}
buf[0] = '\0';
for (i=ap->ad_rcnt; i; i--)
if (rp) {
(void) strcat (buf, rp->li_chan->ch_name);
rp = rp->li_next;
if ((rp) && (i > 1))
(void) strcat (buf, ".");
}
else {
PP_LOG (LLOG_EXCEPTIONS,
("Lib/pp/QID_get_dirname (rfmt err)"));
return (NOTOK);
}
*cpp = (char *) malloc ((unsigned) (strlen (msg_dir) + 1
+ 1 + strlen (bquedir)
+ 1 + strlen (buf)));
(void) sprintf (*cpp, "%s/%s.%s", msg_dir, bquedir, buf);
return (OK);
}
void static QID_free (cpp)
char **cpp;
{
if (*cpp)
free (*cpp);
*cpp = NULLCP;
}