]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zhm/zhm_client.c
r4275@bucket (orig r265): kcr | 2008-01-21 02:57:32 -0500
[1ts-debian.git] / zephyr / zhm / zhm_client.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains the hostmanager <--> client interaction routines.
3  *
4  *      Created by:     David C. Jedlinsky
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #include "zhm.h"
14
15 #ifndef lint
16 #ifndef SABER
17 static const char rcsid_hm_client_c[] = "$Id$";
18 #endif /* SABER */
19 #endif /* lint */
20
21 extern int no_server, nclt, deactivated, noflushflag;
22 extern struct sockaddr_in cli_sin, serv_sin, from;
23
24 extern void send_flush_notice(char *);
25 extern void new_server(char *sugg_serv);
26
27 void transmission_tower(ZNotice_t *notice,
28                         char *packet,
29                         int pak_len)
30 {
31     ZNotice_t gack;
32     Code_t ret;
33     struct sockaddr_in gsin;
34
35     nclt++;
36     if (notice->z_kind == HMCTL) {
37         if (!strcmp(notice->z_opcode, CLIENT_FLUSH)) {
38             if (noflushflag)
39                 syslog(LOG_INFO, "Client requested hm flush (disabled).");
40             else {
41                 send_flush_notice(HM_FLUSH);
42                 deactivated = 1;
43             }
44         } else if (!strcmp(notice->z_opcode, CLIENT_NEW_SERVER)) {
45             new_server((char *)NULL);
46         } else {
47             syslog (LOG_INFO, "Bad control notice from client.");
48         }
49         return;
50     } else {
51         if (notice->z_kind != UNSAFE) {
52             gack = *notice;
53             gack.z_kind = HMACK;
54             gack.z_message_len = 0;
55             gack.z_multinotice = "";
56             gsin = cli_sin;
57             gsin.sin_port = from.sin_port;
58             if (gack.z_port == 0)
59                 gack.z_port = from.sin_port;
60             DPR2 ("Client Port = %u\n", ntohs(gack.z_port));
61             notice->z_port = gack.z_port;
62             if ((ret = ZSetDestAddr(&gsin)) != ZERR_NONE) {
63                 Zperr(ret);
64                 com_err("hm", ret, "setting destination");
65             }
66             /* Bounce ACK to library */
67             if ((ret = send_outgoing(&gack)) != ZERR_NONE) {
68                 Zperr(ret);
69                 com_err("hm", ret, "sending raw notice");
70             }
71         }
72     }
73     if (!no_server) {
74         DPR2 ("Server Port = %u\n", ntohs(serv_sin.sin_port));
75         if ((ret = ZSetDestAddr(&serv_sin)) != ZERR_NONE) {
76             Zperr(ret);
77             com_err("hm", ret, "setting destination");
78         }
79         if ((ret = ZSendPacket(packet, pak_len, 0)) != ZERR_NONE) {
80             Zperr(ret);
81             com_err("hm", ret, "while sending raw notice");
82         }
83     }
84     if (add_notice_to_queue(notice, packet, &gsin, pak_len) != ZERR_NONE)
85         syslog(LOG_INFO, "Hey! Insufficient memory to add notice to queue!");
86 }
87
88 Code_t
89 send_outgoing(ZNotice_t *notice)
90 {
91     Code_t retval;
92     char *packet;
93     int length;
94
95     if (!(packet = (char *) malloc((unsigned)sizeof(ZPacket_t))))
96         return(ENOMEM);
97
98     if ((retval = ZFormatSmallRawNotice(notice, packet, &length))
99         != ZERR_NONE) {
100         free(packet);
101         return(retval);
102     }
103     retval = ZSendPacket(packet, length, 0);
104     free(packet);
105     return(retval);
106 }
107