]> andersk Git - moira.git/blob - lib/mr_connect.c
missing coma in last change, causes compile_et to coredump
[moira.git] / lib / mr_connect.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987, 1990 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  *      
10  *      This routine is part of the client library.  It handles
11  *      creating a connection to the mr server.
12  */
13
14 #ifndef lint
15 static char *rcsid_sms_connect_c = "$Header$";
16 #endif lint
17
18 #include <mit-copyright.h>
19 #include "mr_private.h"
20 #include <moira_site.h>
21 #include <string.h>
22
23 static char *mr_server_host = 0;
24
25 /*
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).
29  */
30
31 int mr_connect(server)
32 char *server;
33 {
34     extern int errno;
35     char *p, **pp, sbuf[256];
36     extern char *getenv(), **hes_resolve();
37         
38     if (!mr_inited) mr_init();
39     if (_mr_conn) return MR_ALREADY_CONNECTED;
40                 
41     if (!server || (strlen(server) == 0)) {
42         server = getenv("MOIRASERVER");
43     }
44
45 #ifdef HESIOD
46     if (!server || (strlen(server) == 0)) {
47         pp = hes_resolve("moira", "sloc");
48         if (pp) server = *pp;
49     }
50 #endif HESIOD
51
52     if (!server || (strlen(server) == 0)) {
53         server = MOIRA_SERVER;
54     }
55
56     if (!strchr(server, ':')) {
57         p = strchr(MOIRA_SERVER, ':');
58         p++;
59         sprintf(sbuf, "%s:%s", server, p);
60         server = sbuf;
61     }
62
63     errno = 0;
64     _mr_conn = start_server_connection(server, ""); 
65     if (_mr_conn == NULL)
66         return errno;
67     if (connection_status(_mr_conn) == CON_STOPPED) {
68         register status = connection_errno(_mr_conn);
69         if (!status) status = MR_CANT_CONNECT;
70         mr_disconnect();
71         return status;
72     }
73
74     /*
75      * stash hostname for later use
76      */
77
78     mr_server_host = strsave(server);
79     if (p = strchr(mr_server_host, ':'))
80         *p = 0;
81     mr_server_host = canonicalize_hostname(mr_server_host);
82     return 0;
83 }
84         
85 int mr_disconnect()
86 {
87     CHECK_CONNECTED;
88     _mr_conn = sever_connection(_mr_conn);
89     free(mr_server_host);
90     mr_server_host = 0;
91     return 0;
92 }
93
94 int mr_host(host, size)
95   char *host;
96   int size;
97 {
98     CHECK_CONNECTED;
99
100     /* If we are connected, mr_server_host points to a valid string. */
101     strncpy(host, mr_server_host, size);
102     return(0);
103 }
104
105 int mr_noop()
106 {
107     int status;
108     mr_params param_st;
109     struct mr_params *params = NULL;
110     struct mr_params *reply = NULL;
111
112     CHECK_CONNECTED;
113     params = &param_st;
114     params->mr_version_no = sending_version_no;
115     params->mr_procno = MR_NOOP;
116     params->mr_argc = 0;
117     params->mr_argl = NULL;
118     params->mr_argv = NULL;
119         
120     if ((status = mr_do_call(params, &reply)) == 0)
121         status = reply->mr_status;
122         
123     mr_destroy_reply(reply);
124
125     return status;
126 }
This page took 0.383707 seconds and 5 git commands to generate.