]> andersk Git - moira.git/blob - lib/mr_ops.c
e3a468a58daa11f2005eafafbdffe35dc7c70870
[moira.git] / lib / mr_ops.c
1 /* $Id$
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 <string.h>
17
18 RCSID("$Header$");
19
20 /* Invoke a DCM update. */
21
22 int mr_do_update(void)
23 {
24   int status;
25   mr_params param_st;
26   struct mr_params *params = NULL;
27   struct mr_params *reply = NULL;
28
29   CHECK_CONNECTED;
30   params = &param_st;
31   params->mr_version_no = sending_version_no;
32   params->mr_procno = MR_DO_UPDATE;
33   params->mr_argc = 0;
34   params->mr_argl = NULL;
35   params->mr_argv = NULL;
36
37   if ((status = mr_do_call(params, &reply)) == 0)
38     status = reply->mr_status;
39
40   mr_destroy_reply(reply);
41
42   return status;
43 }
44
45
46 /* Get the Moira motd.  This returns a Moira status, and motd will either
47  * point to NULL or the motd in a static buffer.
48  */
49
50 int mr_motd(char **motd)
51 {
52   int status;
53   mr_params param_st;
54   struct mr_params *params = NULL;
55   struct mr_params *reply = NULL;
56   static char buffer[1024];
57
58   *motd = NULL;
59   CHECK_CONNECTED;
60   params = &param_st;
61   params->mr_version_no = sending_version_no;
62   params->mr_procno = MR_MOTD;
63   params->mr_argc = 0;
64   params->mr_argl = NULL;
65   params->mr_argv = NULL;
66
67   if ((status = mr_do_call(params, &reply)))
68     goto punt;
69
70   while ((status = reply->mr_status) == MR_MORE_DATA)
71     {
72       if (reply->mr_argc > 0)
73         {
74           strncpy(buffer, reply->mr_argv[0], sizeof(buffer));
75           *motd = buffer;
76         }
77       mr_destroy_reply(reply);
78       reply = NULL;
79
80       initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL);
81       queue_operation(_mr_conn, CON_INPUT, _mr_recv_op);
82
83       complete_operation(_mr_recv_op);
84       if (OP_STATUS(_mr_recv_op) != OP_COMPLETE)
85         {
86           mr_disconnect();
87           status = MR_ABORTED;
88           return status;
89         }
90     }
91 punt:
92   mr_destroy_reply(reply);
93   /* for backwards compatability */
94   if (status == MR_UNKNOWN_PROC)
95     return 0;
96   else
97     return status;
98 }
This page took 0.039949 seconds and 3 git commands to generate.