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