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>
25 static char *mr_server_host = 0;
28 * Open a connection to the mr server. Looks for the server name
29 * 1) passed as an argument, 2) in environment variable, 3) by hesiod
30 * 4) compiled in default (from sms_app.h).
33 int mr_connect(char *server)
36 char *p, **pp, sbuf[256];
41 return MR_ALREADY_CONNECTED;
43 if (!server || (strlen(server) == 0))
44 server = getenv("MOIRASERVER");
47 if (!server || (strlen(server) == 0))
49 pp = hes_resolve("moira", "sloc");
55 if (!server || (strlen(server) == 0))
56 server = MOIRA_SERVER;
58 if (!strchr(server, ':'))
60 p = strchr(MOIRA_SERVER, ':');
62 sprintf(sbuf, "%s:%s", server, p);
67 _mr_conn = start_server_connection(server, "");
70 if (connection_status(_mr_conn) == CON_STOPPED)
72 int status = connection_errno(_mr_conn);
74 status = MR_CANT_CONNECT;
80 * stash hostname for later use
83 mr_server_host = strsave(server);
84 if ((p = strchr(mr_server_host, ':')))
86 mr_server_host = canonicalize_hostname(mr_server_host);
90 int mr_disconnect(void)
93 _mr_conn = sever_connection(_mr_conn);
99 int mr_host(char *host, int size)
103 /* If we are connected, mr_server_host points to a valid string. */
104 strncpy(host, mr_server_host, size);
112 struct mr_params *params = NULL;
113 struct mr_params *reply = NULL;
117 params->mr_version_no = sending_version_no;
118 params->mr_procno = MR_NOOP;
120 params->mr_argl = NULL;
121 params->mr_argv = NULL;
123 if ((status = mr_do_call(params, &reply)) == 0)
124 status = reply->mr_status;
126 mr_destroy_reply(reply);