annotate src/protocols/zephyr/ZhmStat.c @ 8351:ffa642240fc1

[gaim-migrate @ 9075] marv is incredibly patient, waiting a long time for this to go in you should all be using Jabber for file transfer anyway, but if you're still stuck in the stone age, now you can transfer files via IRC committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 27 Feb 2004 01:45:26 +0000
parents 7ba69b8e0de5
children 43d6c08d7e96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2419
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* This file is part of the Project Athena Zephyr Notification System.
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * It contains the ZhmStat() function.
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * Created by: Marc Horowitz
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * $Id: ZhmStat.c 2432 2001-10-03 19:38:28Z warmenhoven $
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 *
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * Copyright (c) 1996 by the Massachusetts Institute of Technology.
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * For copying and distribution information, see the file
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 * "mit-copyright.h".
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 */
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #include <internal.h>
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #include <sys/socket.h>
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 #ifndef INADDR_LOOPBACK
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 #define INADDR_LOOPBACK 0x7f000001
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 #endif
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 Code_t ZhmStat(hostaddr, notice)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 struct in_addr *hostaddr;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 ZNotice_t *notice;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 {
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 struct servent *sp;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 struct sockaddr_in sin;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 ZNotice_t req;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 Code_t code;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 struct timeval tv;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 fd_set readers;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in));
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 sp = getservbyname(HM_SVCNAME, "udp");
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 sin.sin_family = AF_INET;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 if (hostaddr)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 sin.sin_addr = *hostaddr;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 else
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 (void) memset((char *)&req, 0, sizeof(req));
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 req.z_kind = STAT;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 req.z_port = 0;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 req.z_class = HM_STAT_CLASS;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 req.z_class_inst = HM_STAT_CLIENT;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 req.z_opcode = HM_GIMMESTATS;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 req.z_sender = "";
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 req.z_recipient = "";
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 req.z_default_format = "";
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 req.z_message_len = 0;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 if ((code = ZSetDestAddr(&sin)) != ZERR_NONE)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 return(code);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 return(code);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 /* Wait up to ten seconds for a response. */
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 FD_ZERO(&readers);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 FD_SET(ZGetFD(), &readers);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 tv.tv_sec = 10;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 tv.tv_usec = 0;
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 code = select(ZGetFD() + 1, &readers, NULL, NULL, &tv);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 if (code < 0 && errno != EINTR)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 return(errno);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 if (code == 0 || (code < 0 && errno == EINTR) || ZPending() == 0)
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 return(ZERR_HMDEAD);
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 return(ZReceiveNotice(notice, (struct sockaddr_in *) 0));
7ba69b8e0de5 [gaim-migrate @ 2432]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 }