]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zhm/zhm_client.c
03514c66ed4f0e3c188116a3bc213a4f10d66a0d
[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 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 void transmission_tower(ZNotice_t *notice,
25                         char *packet,
26                         int pak_len)
27 {
28     ZNotice_t gack;
29     Code_t ret;
30     struct sockaddr_in gsin;
31
32     nclt++;
33     if (notice->z_kind == HMCTL) {
34         if (!strcmp(notice->z_opcode, CLIENT_FLUSH)) {
35             if (noflushflag)
36                 syslog(LOG_INFO, "Client requested hm flush (disabled).");
37             else {
38                 send_flush_notice(HM_FLUSH);
39                 deactivated = 1;
40             }
41         } else if (!strcmp(notice->z_opcode, CLIENT_NEW_SERVER)) {
42             new_server((char *)NULL);
43         } else {
44             syslog (LOG_INFO, "Bad control notice from client.");
45         }
46         return;
47     } else {
48         if (notice->z_kind != UNSAFE) {
49             gack = *notice;
50             gack.z_kind = HMACK;
51             gack.z_message_len = 0;
52             gack.z_multinotice = "";
53             gsin = cli_sin;
54             gsin.sin_port = from.sin_port;
55             if (gack.z_port == 0)
56                 gack.z_port = from.sin_port;
57             DPR2 ("Client Port = %u\n", ntohs(gack.z_port));
58             notice->z_port = gack.z_port;
59             if ((ret = ZSetDestAddr(&gsin)) != ZERR_NONE) {
60                 Zperr(ret);
61                 com_err("hm", ret, "setting destination");
62             }
63             /* Bounce ACK to library */
64             if ((ret = send_outgoing(&gack)) != ZERR_NONE) {
65                 Zperr(ret);
66                 com_err("hm", ret, "sending raw notice");
67             }
68         }
69     }
70     if (!no_server) {
71         DPR2 ("Server Port = %u\n", ntohs(serv_sin.sin_port));
72         if ((ret = ZSetDestAddr(&serv_sin)) != ZERR_NONE) {
73             Zperr(ret);
74             com_err("hm", ret, "setting destination");
75         }
76         if ((ret = ZSendPacket(packet, pak_len, 0)) != ZERR_NONE) {
77             Zperr(ret);
78             com_err("hm", ret, "while sending raw notice");
79         }
80     }
81     if (add_notice_to_queue(notice, packet, &gsin, pak_len) != ZERR_NONE)
82         syslog(LOG_INFO, "Hey! Insufficient memory to add notice to queue!");
83 }
84
85 Code_t
86 send_outgoing(ZNotice_t *notice)
87 {
88     Code_t retval;
89     char *packet;
90     int length;
91
92     if (!(packet = (char *) malloc((unsigned)sizeof(ZPacket_t))))
93         return(ENOMEM);
94
95     if ((retval = ZFormatSmallRawNotice(notice, packet, &length))
96         != ZERR_NONE) {
97         free(packet);
98         return(retval);
99     }
100     retval = ZSendPacket(packet, length, 0);
101     free(packet);
102     return(retval);
103 }
104