]> andersk Git - moira.git/blob - lib/mr_connect.c
make it work with negative keys
[moira.git] / lib / mr_connect.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 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 sms 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 "sms_private.h"
20 #include <sms_app.h>
21 #include <strings.h>
22
23 static char *sms_server_host = 0;
24
25 /*
26  * Open a connection to the sms server.
27  */
28
29 int sms_connect(server)
30 char *server;
31 {
32     extern int errno;
33     char *p;
34         
35     if (!sms_inited) sms_init();
36     if (_sms_conn) return SMS_ALREADY_CONNECTED;
37                 
38     /* 
39      * XXX should do a hesiod call to find the sms machine name & service
40      * number/name.
41      */
42     errno = 0;
43     if (!server || (strlen(server) == 0))
44       server = SMS_SERVER;
45     _sms_conn = start_server_connection(server, ""); 
46     if (_sms_conn == NULL)
47         return errno;
48     if (connection_status(_sms_conn) == CON_STOPPED) {
49         register status = connection_errno(_sms_conn);
50         if (!status) status = SMS_CANT_CONNECT;
51         sms_disconnect();
52         return status;
53     }
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);
63     return 0;
64 }
65         
66 int sms_disconnect()
67 {
68     CHECK_CONNECTED;
69     _sms_conn = sever_connection(_sms_conn);
70     free(sms_server_host);
71     sms_server_host = 0;
72     return 0;
73 }
74
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
86 int sms_noop()
87 {
88     int status;
89     sms_params param_st;
90     struct sms_params *params = NULL;
91     struct sms_params *reply = NULL;
92
93     CHECK_CONNECTED;
94     params = &param_st;
95     params->sms_version_no = sending_version_no;
96     params->sms_procno = SMS_NOOP;
97     params->sms_argc = 0;
98     params->sms_argl = NULL;
99     params->sms_argv = NULL;
100         
101     if ((status = sms_do_call(params, &reply)) == 0)
102         status = reply->sms_status;
103         
104     sms_destroy_reply(reply);
105
106     return status;
107 }
This page took 0.046214 seconds and 5 git commands to generate.