3 * This routine is part of the client library. It handles
4 * creating a connection to the moira server.
6 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
14 #include "mr_private.h"
24 static char *mr_server_host = 0;
27 * Open a connection to the mr server. Looks for the server name
28 * 1) passed as an argument, 2) in environment variable, 3) by hesiod
29 * 4) compiled in default (from moira_site.h).
32 int mr_connect(char *server)
34 char *p, **pp, sbuf[256];
39 return MR_ALREADY_CONNECTED;
41 if (!server || (strlen(server) == 0))
42 server = getenv("MOIRASERVER");
45 if (!server || (strlen(server) == 0))
47 pp = hes_resolve("moira", "sloc");
53 if (!server || (strlen(server) == 0))
54 server = MOIRA_SERVER;
56 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)
70 int status = connection_errno(_mr_conn);
72 status = MR_CANT_CONNECT;
78 * stash hostname for later use
81 mr_server_host = strdup(server);
82 if ((p = strchr(mr_server_host, ':')))
84 mr_server_host = canonicalize_hostname(mr_server_host);
88 int mr_disconnect(void)
91 _mr_conn = sever_connection(_mr_conn);
97 int mr_host(char *host, int 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);