]>
Commit | Line | Data |
---|---|---|
e2a67c78 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
babbc197 | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
e2a67c78 | 9 | * |
10 | * This routine is part of the client library. It handles | |
babbc197 | 11 | * creating a connection to the sms server. |
e2a67c78 | 12 | */ |
13 | ||
14 | #ifndef lint | |
15 | static char *rcsid_sms_connect_c = "$Header$"; | |
16 | #endif lint | |
17 | ||
babbc197 | 18 | #include <mit-copyright.h> |
e2a67c78 | 19 | #include "sms_private.h" |
8d6097b1 | 20 | #include <sms_app.h> |
05fb8281 | 21 | #include <strings.h> |
22 | ||
23 | static char *sms_server_host = 0; | |
e2a67c78 | 24 | |
25 | /* | |
5450e3a1 | 26 | * Open a connection to the sms 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). | |
e2a67c78 | 29 | */ |
30 | ||
bba84689 | 31 | int sms_connect(server) |
32 | char *server; | |
e2a67c78 | 33 | { |
83e80378 | 34 | extern int errno; |
5450e3a1 | 35 | char *p, **pp, sbuf[256]; |
36 | extern char *getenv(), **hes_resolve(); | |
6c00b7c4 | 37 | |
83e80378 | 38 | if (!sms_inited) sms_init(); |
39 | if (_sms_conn) return SMS_ALREADY_CONNECTED; | |
40 | ||
5450e3a1 | 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 = SMS_SERVER; | |
54 | } | |
55 | ||
56 | if (!index(server, ':')) { | |
57 | p = index(SMS_SERVER, ':'); | |
58 | p++; | |
59 | sprintf(sbuf, "%s:%s", server, p); | |
60 | server = sbuf; | |
61 | } | |
62 | ||
83e80378 | 63 | errno = 0; |
bba84689 | 64 | _sms_conn = start_server_connection(server, ""); |
a4af6a7e | 65 | if (_sms_conn == NULL) |
83e80378 | 66 | return errno; |
a4af6a7e | 67 | if (connection_status(_sms_conn) == CON_STOPPED) { |
68 | register status = connection_errno(_sms_conn); | |
355e74e0 | 69 | if (!status) status = SMS_CANT_CONNECT; |
a4af6a7e | 70 | sms_disconnect(); |
71 | return status; | |
83e80378 | 72 | } |
05fb8281 | 73 | |
74 | /* | |
75 | * stash hostname for later use | |
76 | */ | |
77 | ||
78 | sms_server_host = strsave(server); | |
79 | if (p = index(sms_server_host, ':')) | |
80 | *p = 0; | |
81 | sms_server_host = canonicalize_hostname(sms_server_host); | |
83e80378 | 82 | return 0; |
e2a67c78 | 83 | } |
84 | ||
85 | int sms_disconnect() | |
86 | { | |
83e80378 | 87 | CHECK_CONNECTED; |
88 | _sms_conn = sever_connection(_sms_conn); | |
05fb8281 | 89 | free(sms_server_host); |
90 | sms_server_host = 0; | |
83e80378 | 91 | return 0; |
e2a67c78 | 92 | } |
93 | ||
05fb8281 | 94 | int sms_host(host, size) |
95 | char *host; | |
96 | int size; | |
97 | { | |
98 | CHECK_CONNECTED; | |
99 | ||
100 | /* If we are connected, sms_server_host points to a valid string. */ | |
101 | strncpy(host, sms_server_host, size); | |
102 | return(0); | |
103 | } | |
104 | ||
e2a67c78 | 105 | int sms_noop() |
106 | { | |
83e80378 | 107 | int status; |
108 | sms_params param_st; | |
109 | struct sms_params *params = NULL; | |
110 | struct sms_params *reply = NULL; | |
e2a67c78 | 111 | |
83e80378 | 112 | CHECK_CONNECTED; |
113 | params = ¶m_st; | |
89371417 | 114 | params->sms_version_no = sending_version_no; |
83e80378 | 115 | params->sms_procno = SMS_NOOP; |
116 | params->sms_argc = 0; | |
117 | params->sms_argl = NULL; | |
118 | params->sms_argv = NULL; | |
e2a67c78 | 119 | |
83e80378 | 120 | if ((status = sms_do_call(params, &reply)) == 0) |
121 | status = reply->sms_status; | |
ca401c43 | 122 | |
83e80378 | 123 | sms_destroy_reply(reply); |
6c00b7c4 | 124 | |
83e80378 | 125 | return status; |
6c00b7c4 | 126 | } |