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