* $Author$
* $Header$
*
- * Copyright (C) 1987 by the Massachusetts Institute of Technology
+ * Copyright (C) 1987, 1990 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
- * creating a connection to the sms server.
+ * creating a connection to the mr server.
*/
#ifndef lint
static char *rcsid_sms_connect_c = "$Header$";
#endif lint
-#include <gdb.h>
-#include "sms_private.h"
+#include <mit-copyright.h>
+#include "mr_private.h"
+#include <moira_site.h>
+#include <string.h>
+
+static char *mr_server_host = 0;
/*
- * Open a connection to the sms server.
+ * Open a connection to the mr server. Looks for the server name
+ * 1) passed as an argument, 2) in environment variable, 3) by hesiod
+ * 4) compiled in default (from sms_app.h).
*/
-int sms_connect()
+int mr_connect(server)
+char *server;
{
- gdb_init(); /* Harmless if called twice. */
- /*
- * should do a hesiod call to find the sms machine name & service
- * number/name.
- */
-
- _sms_conn = start_server_connection(SMS_GDB_SERV, "XXX");
- /* XXX gdb doesn't give real return codes. Can we trust errno?*/
- if (_sms_conn == NULL) {
- perror("gdb_connect");
- return SMS_CANT_CONNECT;
- }
- return 0;
-}
+ extern int errno;
+ char *p, **pp, sbuf[256];
+ extern char *getenv(), **hes_resolve();
-int sms_disconnect()
-{
- if (!_sms_conn) {
- return SMS_NOT_CONNECTED;
- }
- /* Is this guaranteed NOT to fail?? I don't believe it, but.. */
- _sms_conn = sever_connection(_sms_conn);
- return 0;
-}
+ if (!mr_inited) mr_init();
+ if (_mr_conn) return MR_ALREADY_CONNECTED;
+
+ if (!server || (strlen(server) == 0)) {
+ server = getenv("MOIRASERVER");
+ }
-int sms_noop()
-{
- int status;
- struct sms_params *parms;
+#ifdef HESIOD
+ if (!server || (strlen(server) == 0)) {
+ pp = hes_resolve("moira", "sloc");
+ if (pp) server = *pp;
+ }
+#endif HESIOD
- if (!_sms_conn) {
- return SMS_NOT_CONNECTED;
- }
+ if (!server || (strlen(server) == 0)) {
+ server = MOIRA_SERVER;
+ }
- if (!sms_call_op)
- sms_call_op = create_operation();
+ if (!strchr(server, ':')) {
+ p = strchr(MOIRA_SERVER, ':');
+ p++;
+ sprintf(sbuf, "%s:%s", server, p);
+ server = sbuf;
+ }
- parms = (struct sms_params *) malloc(sizeof(*parms));
-
- parms->procno = SMS_NOOP;
- parms->argc = 0;
+ errno = 0;
+ _mr_conn = start_server_connection(server, "");
+ if (_mr_conn == NULL)
+ return errno;
+ if (connection_status(_mr_conn) == CON_STOPPED) {
+ register status = connection_errno(_mr_conn);
+ if (!status) status = MR_CANT_CONNECT;
+ mr_disconnect();
+ return status;
+ }
- gdb_inop(sms_call_op, sms_start_call, &parms, sms_abort_call);
- gdb_qop(_sms_conn, CON_OUTPUT, sms_call_op);
+ /*
+ * stash hostname for later use
+ */
- gdb_inop(sms_recv_op, sms_start_recv, &reply, sms_abort_recv);
- gdb_qop(_sms_conn, CON_INPUT, sms_recv_op);
+ mr_server_host = strsave(server);
+ if (p = strchr(mr_server_host, ':'))
+ *p = 0;
+ mr_server_host = canonicalize_hostname(mr_server_host);
+ return 0;
+}
+
+int mr_disconnect()
+{
+ CHECK_CONNECTED;
+ _mr_conn = sever_connection(_mr_conn);
+ free(mr_server_host);
+ mr_server_host = 0;
+ return 0;
+}
- /* Block until operation done. */
- gdb_cmpo(sms_call_op);
- gdb_cmpo(sms_recv_op);
+int mr_host(host, size)
+ char *host;
+ int size;
+{
+ CHECK_CONNECTED;
- /* Look at results */
- if (OP_STATUS(sms_recv_op) != OP_COMPLETE) {
- return SMS_ABORTED;
- }
- /* should look at return code from server.. */
- return 0;
+ /* If we are connected, mr_server_host points to a valid string. */
+ strncpy(host, mr_server_host, size);
+ return(0);
}
+int mr_noop()
+{
+ int status;
+ mr_params param_st;
+ struct mr_params *params = NULL;
+ struct mr_params *reply = NULL;
+
+ CHECK_CONNECTED;
+ params = ¶m_st;
+ params->mr_version_no = sending_version_no;
+ params->mr_procno = MR_NOOP;
+ params->mr_argc = 0;
+ params->mr_argl = NULL;
+ params->mr_argv = NULL;
+
+ if ((status = mr_do_call(params, &reply)) == 0)
+ status = reply->mr_status;
+ mr_destroy_reply(reply);
+
+ return status;
+}