#include "stdio.h"
#include "string.h"
#include "sys/types.h"
#include "lp.h"
#include "msgs.h"
#include "printers.h"
#include "form.h"
#include "access.h"
#define WHO_AM_I I_AM_LPADMIN
#include "oam.h"
#include "lpadmin.h"
extern FORM formbuf;
void mount_unmount();
short printer_status;
static char *cur_pwheel;
char *disable_reason,
*reject_reason;
static void inquire_printer_status();
void do_mount (printer, form, pwheel)
char *printer,
*form,
*pwheel;
{
if (form && STREQU(form, NAME_NONE))
form = "";
if (pwheel && (STREQU(pwheel, NAME_ANY) || STREQU(pwheel, NAME_NONE)))
pwheel = "";
if (form && !*form && a)
LP_ERRMSG (WARNING, E_ADM_UNALIGN);
if (form && !*form && pwheel && !*pwheel) {
mount_unmount (S_UNMOUNT, printer, NAME_NONE, NAME_ANY);
form = 0;
pwheel = 0;
} else if (form && !*form) {
mount_unmount (S_UNMOUNT, printer, NAME_NONE, "");
form = 0;
} else if (pwheel && !*pwheel) {
mount_unmount (S_UNMOUNT, printer, "", NAME_ANY);
pwheel = 0;
}
if (!form && !pwheel)
return;
if (!s) {
if (form && *form)
switch (verify_form(form)) {
case -1:
LP_ERRMSG (WARNING, E_ADM_BADMOUNT);
break;
case -2:
LP_ERRMSG1 (ERROR, E_ADM_MANDCHSET, formbuf.chset);
done (1);
}
if (form && *form && !is_form_allowed_printer(form, printer))
LP_ERRMSG2 (WARNING, E_ADM_ICKFORM, form, printer);
if (pwheel && *pwheel && !daisy) {
LP_ERRMSG (ERROR, E_ADM_NOPWHEEL);
done (1);
}
if (form && *form) {
inquire_printer_status (printer);
if (daisy && formbuf.mandatory && formbuf.chset)
if (!pwheel || !*pwheel) {
if (!STREQU(formbuf.chset, cur_pwheel))
LP_ERRMSG1 (
WARNING,
E_ADM_MANDPWHEEL1,
formbuf.chset
);
} else if (!STREQU(formbuf.chset, pwheel)) {
LP_ERRMSG1 (
WARNING,
E_ADM_MANDPWHEEL2,
formbuf.chset
);
}
}
if (
pwheel
&& *pwheel
&& !(
oldp
&& searchlist(pwheel, oldp->char_sets)
)
)
LP_ERRMSG2 (WARNING, E_ADM_ICKPWHEEL, pwheel, printer);
}
if (!a || !do_align(printer, form, pwheel))
mount_unmount (S_MOUNT, printer, NB(form), NB(pwheel));
return;
}
void mount_unmount (type, printer, form, pwheel)
int type;
char *printer,
*form,
*pwheel;
{
int rc;
if (t) {
type = (type == S_MOUNT ? S_MOUNT_TRAY : S_UNMOUNT_TRAY);
send_message(type, printer, form, pwheel, t);
} else
send_message(type, printer, form, pwheel);
rc = output(type + 1);
switch(rc) {
case MOK:
break;
case MNOMEDIA:
LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
done (1);
case MNODEST:
LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
done (1);
case MBUSY:
LP_ERRMSG (ERROR, E_ADM_MNTLATER);
done (1);
case MNOTRAY:
LP_ERRMSG (ERROR, E_ADM_BADTRAY);
done (1);
case MNOPERM:
default:
LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
done (1);
}
return;
}
void
do_max_trays(char *printer)
{
int rc;
if (t)
send_message(S_MAX_TRAYS, printer, t);
rc = output(R_MAX_TRAYS);
switch(rc) {
case MOK:
break;
case MNOMEDIA:
LP_ERRMSG (ERROR, E_ADM_NOMEDIA);
done (1);
case MNODEST:
LP_ERRMSG1 (ERROR, E_ADM_NODEST, printer);
done (1);
case MBUSY:
LP_ERRMSG (ERROR, E_ADM_MNTLATER);
done (1);
case MNOTRAY:
LP_ERRMSG (ERROR, E_ADM_MAXTRAY);
done (1);
case MNOPERM:
default:
LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
done (1);
}
return;
}
static void inquire_printer_status (printer)
char *printer;
{
short status;
char *s_ignore,
buffer[MSGMAX];
long l_ignore;
send_message (S_INQUIRE_PRINTER_STATUS, printer);
if (mrecv(buffer, MSGMAX) != R_INQUIRE_PRINTER_STATUS) {
LP_ERRMSG (ERROR, E_LP_MRECV);
done (1);
}
(void)getmessage (
buffer,
R_INQUIRE_PRINTER_STATUS,
&status,
&s_ignore,
&s_ignore,
&cur_pwheel,
&disable_reason,
&reject_reason,
&printer_status,
&s_ignore,
&l_ignore,
&l_ignore
);
switch (status) {
case MOK:
disable_reason = strdup(disable_reason);
reject_reason = strdup(reject_reason);
cur_pwheel = strdup(cur_pwheel);
break;
case MNODEST:
LP_ERRMSG1 (ERROR, E_LP_PGONE, printer);
done (1);
}
return;
}