6 * Copyright (C) 1987, 1990 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * This routine is part of the client library. It handles
11 * creating a connection to the mr server.
15 static char *rcsid_sms_connect_c = "$Header$";
18 #include <mit-copyright.h>
19 #include "mr_private.h"
20 #include <moira_site.h>
23 static char *mr_server_host = 0;
26 * Open a connection to the mr server. Looks for the server name
27 * 1) passed as an argument, 2) in environment variable, 3) by hesiod
28 * 4) compiled in default (from sms_app.h).
31 int mr_connect(server)
35 char *p, **pp, sbuf[256];
36 extern char *getenv(), **hes_resolve();
38 if (!mr_inited) mr_init();
39 if (_mr_conn) return MR_ALREADY_CONNECTED;
41 if (!server || (strlen(server) == 0)) {
42 server = getenv("MOIRASERVER");
46 if (!server || (strlen(server) == 0)) {
47 pp = hes_resolve("moira", "sloc");
52 if (!server || (strlen(server) == 0)) {
53 server = MOIRA_SERVER;
56 if (!index(server, ':')) {
57 p = index(MOIRA_SERVER, ':');
59 sprintf(sbuf, "%s:%s", server, p);
64 _mr_conn = start_server_connection(server, "");
67 if (connection_status(_mr_conn) == CON_STOPPED) {
68 register status = connection_errno(_mr_conn);
69 if (!status) status = MR_CANT_CONNECT;
75 * stash hostname for later use
78 mr_server_host = strsave(server);
79 if (p = index(mr_server_host, ':'))
81 mr_server_host = canonicalize_hostname(mr_server_host);
88 _mr_conn = sever_connection(_mr_conn);
94 int mr_host(host, size)
100 /* If we are connected, mr_server_host points to a valid string. */
101 strncpy(host, mr_server_host, size);
109 struct mr_params *params = NULL;
110 struct mr_params *reply = NULL;
114 params->mr_version_no = sending_version_no;
115 params->mr_procno = MR_NOOP;
117 params->mr_argl = NULL;
118 params->mr_argv = NULL;
120 if ((status = mr_do_call(params, &reply)) == 0)
121 status = reply->mr_status;
123 mr_destroy_reply(reply);