]> andersk Git - moira.git/blob - lib/mr_connect.c
dcm.h is no longer used
[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
17
18 #include <mit-copyright.h>
19 #include "mr_private.h"
20 #include <moira_site.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <hesiod.h>
24
25 static char *mr_server_host = 0;
26
27 /*
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).
31  */
32
33 int mr_connect(server)
34 char *server;
35 {
36     extern int errno;
37     char *p, **pp, sbuf[256];
38         
39     if (!mr_inited) mr_init();
40     if (_mr_conn) return MR_ALREADY_CONNECTED;
41                 
42     if (!server || (strlen(server) == 0)) {
43         server = getenv("MOIRASERVER");
44     }
45
46 #ifdef HESIOD
47     if (!server || (strlen(server) == 0)) {
48         pp = hes_resolve("moira", "sloc");
49         if (pp) server = *pp;
50     }
51 #endif
52
53     if (!server || (strlen(server) == 0)) {
54         server = MOIRA_SERVER;
55     }
56
57     if (!strchr(server, ':')) {
58         p = strchr(MOIRA_SERVER, ':');
59         p++;
60         sprintf(sbuf, "%s:%s", server, p);
61         server = sbuf;
62     }
63
64     errno = 0;
65     _mr_conn = start_server_connection(server, ""); 
66     if (_mr_conn == NULL)
67         return errno;
68     if (connection_status(_mr_conn) == CON_STOPPED) {
69         register status = connection_errno(_mr_conn);
70         if (!status) status = MR_CANT_CONNECT;
71         mr_disconnect();
72         return status;
73     }
74
75     /*
76      * stash hostname for later use
77      */
78
79     mr_server_host = strsave(server);
80     if (p = strchr(mr_server_host, ':'))
81         *p = 0;
82     mr_server_host = canonicalize_hostname(mr_server_host);
83     return 0;
84 }
85         
86 int mr_disconnect()
87 {
88     CHECK_CONNECTED;
89     _mr_conn = sever_connection(_mr_conn);
90     free(mr_server_host);
91     mr_server_host = 0;
92     return 0;
93 }
94
95 int mr_host(host, size)
96   char *host;
97   int size;
98 {
99     CHECK_CONNECTED;
100
101     /* If we are connected, mr_server_host points to a valid string. */
102     strncpy(host, mr_server_host, size);
103     return(0);
104 }
105
106 int mr_noop()
107 {
108     int status;
109     mr_params param_st;
110     struct mr_params *params = NULL;
111     struct mr_params *reply = NULL;
112
113     CHECK_CONNECTED;
114     params = &param_st;
115     params->mr_version_no = sending_version_no;
116     params->mr_procno = MR_NOOP;
117     params->mr_argc = 0;
118     params->mr_argl = NULL;
119     params->mr_argv = NULL;
120         
121     if ((status = mr_do_call(params, &reply)) == 0)
122         status = reply->mr_status;
123         
124     mr_destroy_reply(reply);
125
126     return status;
127 }
This page took 0.047631 seconds and 5 git commands to generate.