]>
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 | /* | |
26 | * Open a connection to the sms server. | |
27 | */ | |
28 | ||
bba84689 | 29 | int sms_connect(server) |
30 | char *server; | |
e2a67c78 | 31 | { |
83e80378 | 32 | extern int errno; |
05fb8281 | 33 | char *p; |
6c00b7c4 | 34 | |
83e80378 | 35 | if (!sms_inited) sms_init(); |
36 | if (_sms_conn) return SMS_ALREADY_CONNECTED; | |
37 | ||
38 | /* | |
a4af6a7e | 39 | * XXX should do a hesiod call to find the sms machine name & service |
40 | * number/name. | |
41 | */ | |
83e80378 | 42 | errno = 0; |
bba84689 | 43 | if (!server || (strlen(server) == 0)) |
8d6097b1 | 44 | server = SMS_SERVER; |
bba84689 | 45 | _sms_conn = start_server_connection(server, ""); |
a4af6a7e | 46 | if (_sms_conn == NULL) |
83e80378 | 47 | return errno; |
a4af6a7e | 48 | if (connection_status(_sms_conn) == CON_STOPPED) { |
49 | register status = connection_errno(_sms_conn); | |
355e74e0 | 50 | if (!status) status = SMS_CANT_CONNECT; |
a4af6a7e | 51 | sms_disconnect(); |
52 | return status; | |
83e80378 | 53 | } |
05fb8281 | 54 | |
55 | /* | |
56 | * stash hostname for later use | |
57 | */ | |
58 | ||
59 | sms_server_host = strsave(server); | |
60 | if (p = index(sms_server_host, ':')) | |
61 | *p = 0; | |
62 | sms_server_host = canonicalize_hostname(sms_server_host); | |
83e80378 | 63 | return 0; |
e2a67c78 | 64 | } |
65 | ||
66 | int sms_disconnect() | |
67 | { | |
83e80378 | 68 | CHECK_CONNECTED; |
69 | _sms_conn = sever_connection(_sms_conn); | |
05fb8281 | 70 | free(sms_server_host); |
71 | sms_server_host = 0; | |
83e80378 | 72 | return 0; |
e2a67c78 | 73 | } |
74 | ||
05fb8281 | 75 | int sms_host(host, size) |
76 | char *host; | |
77 | int size; | |
78 | { | |
79 | CHECK_CONNECTED; | |
80 | ||
81 | /* If we are connected, sms_server_host points to a valid string. */ | |
82 | strncpy(host, sms_server_host, size); | |
83 | return(0); | |
84 | } | |
85 | ||
e2a67c78 | 86 | int sms_noop() |
87 | { | |
83e80378 | 88 | int status; |
89 | sms_params param_st; | |
90 | struct sms_params *params = NULL; | |
91 | struct sms_params *reply = NULL; | |
e2a67c78 | 92 | |
83e80378 | 93 | CHECK_CONNECTED; |
94 | params = ¶m_st; | |
89371417 | 95 | params->sms_version_no = sending_version_no; |
83e80378 | 96 | params->sms_procno = SMS_NOOP; |
97 | params->sms_argc = 0; | |
98 | params->sms_argl = NULL; | |
99 | params->sms_argv = NULL; | |
e2a67c78 | 100 | |
83e80378 | 101 | if ((status = sms_do_call(params, &reply)) == 0) |
102 | status = reply->sms_status; | |
ca401c43 | 103 | |
83e80378 | 104 | sms_destroy_reply(reply); |
6c00b7c4 | 105 | |
83e80378 | 106 | return status; |
6c00b7c4 | 107 | } |