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(server)
37 char *p, **pp, sbuf[256];
39 if (!mr_inited) mr_init();
40 if (_mr_conn) return MR_ALREADY_CONNECTED;
42 if (!server || (strlen(server) == 0)) {
43 server = getenv("MOIRASERVER");
47 if (!server || (strlen(server) == 0)) {
48 pp = hes_resolve("moira", "sloc");
53 if (!server || (strlen(server) == 0)) {
54 server = MOIRA_SERVER;
57 if (!strchr(server, ':')) {
58 p = strchr(MOIRA_SERVER, ':');
60 sprintf(sbuf, "%s:%s", server, p);
65 _mr_conn = start_server_connection(server, "");
68 if (connection_status(_mr_conn) == CON_STOPPED) {
69 register status = connection_errno(_mr_conn);
70 if (!status) status = MR_CANT_CONNECT;
76 * stash hostname for later use
79 mr_server_host = strsave(server);
80 if (p = strchr(mr_server_host, ':'))
82 mr_server_host = canonicalize_hostname(mr_server_host);
89 _mr_conn = sever_connection(_mr_conn);
95 int mr_host(host, size)
101 /* If we are connected, mr_server_host points to a valid string. */
102 strncpy(host, mr_server_host, size);
110 struct mr_params *params = NULL;
111 struct mr_params *reply = NULL;
115 params->mr_version_no = sending_version_no;
116 params->mr_procno = MR_NOOP;
118 params->mr_argl = NULL;
119 params->mr_argv = NULL;
121 if ((status = mr_do_call(params, &reply)) == 0)
122 status = reply->mr_status;
124 mr_destroy_reply(reply);