source: trunk/third/moira/lib/mr_ops.c @ 24319

Revision 24319, 2.5 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1/* $Id: mr_ops.c 3956 2010-01-05 20:56:56Z zacheiss $
2 *
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.
6 *
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>.
10 */
11
12#include <mit-copyright.h>
13#include <moira.h>
14#include "mr_private.h"
15
16#include <errno.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/lib/mr_ops.c $ $Id: mr_ops.c 3956 2010-01-05 20:56:56Z zacheiss $");
22
23/* Invoke a DCM update. */
24
25int mr_do_update(void)
26{
27  int status;
28  mr_params params, reply;
29
30  CHECK_CONNECTED;
31  params.u.mr_procno = MR_DO_UPDATE;
32  params.mr_argc = 0;
33  params.mr_argl = NULL;
34  params.mr_argv = NULL;
35
36  if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
37    status = reply.u.mr_status;
38
39  mr_destroy_reply(reply);
40
41  return status;
42}
43
44
45/* Get the Moira motd.  This returns a Moira status, and motd will either
46 * point to NULL or the motd in a static buffer.
47 */
48
49int mr_motd(char **motd)
50{
51  int status;
52  mr_params params, reply;
53  static char *buffer = NULL;
54
55  *motd = NULL;
56  CHECK_CONNECTED;
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)))
63    goto punt;
64
65  while ((status = reply.u.mr_status) == MR_MORE_DATA)
66    {
67      if (reply.mr_argc > 0)
68        {
69          buffer = realloc(buffer, reply.mr_argl[0] + 1);
70          if (!buffer)
71            {
72              mr_disconnect();
73              return ENOMEM;
74            }
75          strcpy(buffer, reply.mr_argv[0]);
76          *motd = buffer;
77        }
78      mr_destroy_reply(reply);
79      if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
80        {
81          mr_disconnect();
82          return MR_ABORTED;
83        }
84    }
85punt:
86  mr_destroy_reply(reply);
87
88  return status;
89}
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}
Note: See TracBrowser for help on using the repository browser.