]> andersk Git - moira.git/blob - lib/mr_ops.c
don't call the callback if it's NULL...
[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 <errno.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 RCSID("$Header$");
21
22 /* Invoke a DCM update. */
23
24 int mr_do_update(void)
25 {
26   int status;
27   mr_params params, reply;
28
29   CHECK_CONNECTED;
30   params.u.mr_procno = MR_DO_UPDATE;
31   params.mr_argc = 0;
32   params.mr_argl = NULL;
33   params.mr_argv = NULL;
34
35   if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
36     status = reply.u.mr_status;
37
38   mr_destroy_reply(reply);
39
40   return status;
41 }
42
43
44 /* Get the Moira motd.  This returns a Moira status, and motd will either
45  * point to NULL or the motd in a static buffer.
46  */
47
48 int mr_motd(char **motd)
49 {
50   int status;
51   mr_params params, reply;
52   static char *buffer = NULL;
53
54   *motd = NULL;
55   CHECK_CONNECTED;
56   params.u.mr_procno = MR_MOTD;
57   params.mr_argc = 0;
58   params.mr_argl = NULL;
59   params.mr_argv = NULL;
60
61   if ((status = mr_do_call(&params, &reply)))
62     goto punt;
63
64   while ((status = reply.u.mr_status) == MR_MORE_DATA)
65     {
66       if (reply.mr_argc > 0)
67         {
68           buffer = realloc(buffer, reply.mr_argl[0] + 1);
69           if (!buffer)
70             {
71               mr_disconnect();
72               return ENOMEM;
73             }
74           strcpy(buffer, reply.mr_argv[0]);
75           *motd = buffer;
76         }
77       mr_destroy_reply(reply);
78       if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
79         {
80           mr_disconnect();
81           return MR_ABORTED;
82         }
83     }
84 punt:
85   mr_destroy_reply(reply);
86
87   return status;
88 }
This page took 0.106667 seconds and 5 git commands to generate.