]> andersk Git - moira.git/blame - lib/mr_ops.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / mr_ops.c
CommitLineData
fa59b86f 1/* $Id$
de56407f 2 *
7ac48069 3 * This routine is part of the client library. It handles
4 * the protocol operations: invoking an update and getting the
5 * Moira message of the day.
5eaef520 6 *
7ac48069 7 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
de56407f 10 */
11
babbc197 12#include <mit-copyright.h>
7ac48069 13#include <moira.h>
8defc06b 14#include "mr_private.h"
de56407f 15
a3bbcc2b 16#include <errno.h>
6c0f18be 17#include <stdio.h>
a3bbcc2b 18#include <stdlib.h>
7ac48069 19#include <string.h>
20
21RCSID("$Header$");
5f9f27e4 22
23/* Invoke a DCM update. */
24
5eaef520 25int mr_do_update(void)
de56407f 26{
5eaef520 27 int status;
85330553 28 mr_params params, reply;
de56407f 29
5eaef520 30 CHECK_CONNECTED;
85330553 31 params.u.mr_procno = MR_DO_UPDATE;
32 params.mr_argc = 0;
33 params.mr_argl = NULL;
34 params.mr_argv = NULL;
5eaef520 35
85330553 36 if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
37 status = reply.u.mr_status;
5eaef520 38
39 mr_destroy_reply(reply);
40
41 return status;
de56407f 42}
43
5f9f27e4 44
59ec8dae 45/* Get the Moira motd. This returns a Moira status, and motd will either
5f9f27e4 46 * point to NULL or the motd in a static buffer.
de56407f 47 */
5f9f27e4 48
5eaef520 49int mr_motd(char **motd)
5f9f27e4 50{
5eaef520 51 int status;
85330553 52 mr_params params, reply;
a3bbcc2b 53 static char *buffer = NULL;
5eaef520 54
55 *motd = NULL;
56 CHECK_CONNECTED;
85330553 57 params.u.mr_procno = MR_MOTD;
58 params.mr_argc = 0;
59 params.mr_argl = NULL;
60 params.mr_argv = NULL;
61
62 if ((status = mr_do_call(&params, &reply)))
5eaef520 63 goto punt;
64
85330553 65 while ((status = reply.u.mr_status) == MR_MORE_DATA)
5eaef520 66 {
85330553 67 if (reply.mr_argc > 0)
5eaef520 68 {
85330553 69 buffer = realloc(buffer, reply.mr_argl[0] + 1);
a3bbcc2b 70 if (!buffer)
71 {
72 mr_disconnect();
73 return ENOMEM;
74 }
85330553 75 strcpy(buffer, reply.mr_argv[0]);
5eaef520 76 *motd = buffer;
5f9f27e4 77 }
5eaef520 78 mr_destroy_reply(reply);
85330553 79 if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
5eaef520 80 {
81 mr_disconnect();
85330553 82 return MR_ABORTED;
5f9f27e4 83 }
5eaef520 84 }
85punt:
86 mr_destroy_reply(reply);
85330553 87
88 return status;
5f9f27e4 89}
6c0f18be 90
91/* Exchange query version info with the server. */
92
93int mr_version(int version)
94{
95 int status;
96 mr_params params, reply;
97 char vbuf[10], *arg;
98
99 CHECK_CONNECTED;
100
101 sprintf(vbuf, "%d", version);
102 arg = strdup(vbuf);
103 params.u.mr_procno = MR_SETVERSION;
104 params.mr_argc = 1;
105 params.mr_argl = NULL;
106 params.mr_argv = &arg;
107
108 status = mr_do_call(&params, &reply);
109 free(arg);
110
111 if (status == MR_SUCCESS)
112 {
113 status = reply.u.mr_status;
114
115 if (status == MR_VERSION_LOW && getenv("MOIRA_LOW_VERSION_WARNING"))
116 fprintf(stderr, "Warning: This client is out of date.\n");
117 }
118 mr_destroy_reply(reply);
119
120 return status;
121}
This page took 0.710735 seconds and 5 git commands to generate.