]> andersk Git - moira.git/blobdiff - lib/mr_ops.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / mr_ops.c
index 26239e7bdb63fb284bdf5541cc1d761fc37a1fed..50d2194cda2c85b49189e083cd670718a95a5086 100644 (file)
-/*
- *     $Source$
- *     $Author$
- *     $Header$
+/* $Id$
  *
- *     Copyright (C) 1987, 1989 by the Massachusetts Institute of Technology
- *     For copying and distribution information, please see the file
- *     <mit-copyright.h>.
- *     
- *     This routine is part of the client library.  It handles
- *     the protocol operations: invoking an update and getting the
- *     SMS message of the day.
+ * This routine is part of the client library.  It handles
+ * the protocol operations: invoking an update and getting the
+ * Moira message of the day.
+ *
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-#ifndef lint
-static char *rcsid_sms_do_update_c = "$Header$";
-#endif lint
-
 #include <mit-copyright.h>
-#include "sms_private.h"
+#include <moira.h>
+#include "mr_private.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
+RCSID("$Header$");
 
 /* Invoke a DCM update. */
 
-int sms_do_update()
+int mr_do_update(void)
 {
-    int status;
-    sms_params param_st;
-    struct sms_params *params = NULL;
-    struct sms_params *reply = NULL;
-
-    CHECK_CONNECTED;
-    params = &param_st;
-    params->sms_version_no = sending_version_no;
-    params->sms_procno = SMS_DO_UPDATE;
-    params->sms_argc = 0;
-    params->sms_argl = NULL;
-    params->sms_argv = NULL;
-       
-    if ((status = sms_do_call(params, &reply)) == 0)
-       status = reply->sms_status;
-       
-    sms_destroy_reply(reply);
-
-    return status;
+  int status;
+  mr_params params, reply;
+
+  CHECK_CONNECTED;
+  params.u.mr_procno = MR_DO_UPDATE;
+  params.mr_argc = 0;
+  params.mr_argl = NULL;
+  params.mr_argv = NULL;
+
+  if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
+    status = reply.u.mr_status;
+
+  mr_destroy_reply(reply);
+
+  return status;
 }
 
 
-/* Get the SMS motd.  This returns an SMS status, and motd will either
+/* Get the Moira motd.  This returns a Moira status, and motd will either
  * point to NULL or the motd in a static buffer.
  */
 
-int sms_motd(motd)
-char **motd;
+int mr_motd(char **motd)
 {
-    int status;
-    sms_params param_st;
-    struct sms_params *params = NULL;
-    struct sms_params *reply = NULL;
-    static char buffer[1024];
-
-    *motd = NULL;
-    CHECK_CONNECTED;
-    params = &param_st;
-    params->sms_version_no = sending_version_no;
-    params->sms_procno = SMS_MOTD;
-    params->sms_argc = 0;
-    params->sms_argl = NULL;
-    params->sms_argv = NULL;
-       
-    if ((status = sms_do_call(params, &reply)))
-      goto punt;
-
-    while ((status = reply->sms_status) == SMS_MORE_DATA) {
-       if (reply->sms_argc > 0) {
-           strncpy(buffer, reply->sms_argv[0], sizeof(buffer));
-           *motd = buffer;
+  int status;
+  mr_params params, reply;
+  static char *buffer = NULL;
+
+  *motd = NULL;
+  CHECK_CONNECTED;
+  params.u.mr_procno = MR_MOTD;
+  params.mr_argc = 0;
+  params.mr_argl = NULL;
+  params.mr_argv = NULL;
+
+  if ((status = mr_do_call(&params, &reply)))
+    goto punt;
+
+  while ((status = reply.u.mr_status) == MR_MORE_DATA)
+    {
+      if (reply.mr_argc > 0)
+       {
+         buffer = realloc(buffer, reply.mr_argl[0] + 1);
+         if (!buffer)
+           {
+             mr_disconnect();
+             return ENOMEM;
+           }
+         strcpy(buffer, reply.mr_argv[0]);
+         *motd = buffer;
        }
-       sms_destroy_reply(reply);
-       reply = NULL;
-
-       initialize_operation(_sms_recv_op, sms_start_recv, &reply,
-                            (int (*)())NULL);
-       queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
-
-       complete_operation(_sms_recv_op);
-       if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
-           sms_disconnect();
-           status = SMS_ABORTED;
-           return(status);
+      mr_destroy_reply(reply);
+      if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
+       {
+         mr_disconnect();
+         return MR_ABORTED;
        }
-    }  
- punt:
-    sms_destroy_reply(reply);
-    /* for backwards compatability */
-    if (status == SMS_UNKNOWN_PROC)
-      return(0);
-    else
-      return(status);
+    }
+punt:
+  mr_destroy_reply(reply);
+
+  return status;
+}
+
+/* Exchange query version info with the server. */
+
+int mr_version(int version)
+{
+  int status;
+  mr_params params, reply;
+  char vbuf[10], *arg;
+
+  CHECK_CONNECTED;
+
+  sprintf(vbuf, "%d", version);
+  arg = strdup(vbuf);
+  params.u.mr_procno = MR_SETVERSION;
+  params.mr_argc = 1;
+  params.mr_argl = NULL;
+  params.mr_argv = &arg;
+
+  status = mr_do_call(&params, &reply);
+  free(arg);
+
+  if (status == MR_SUCCESS)
+    {
+      status = reply.u.mr_status;
+
+      if (status == MR_VERSION_LOW && getenv("MOIRA_LOW_VERSION_WARNING"))
+       fprintf(stderr, "Warning: This client is out of date.\n");
+    }
+  mr_destroy_reply(reply);
+
+  return status;
 }
This page took 0.103416 seconds and 4 git commands to generate.