1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* This file is part of the Project Athena Zephyr Notification System.
* It contains source for the ZSubscribeTo, ZUnsubscribeTo, and
* ZCancelSubscriptions functions.
*
* Created by: Robert French
*
* $Source$
* $Author$
*
* Copyright (c) 1987 by the Massachusetts Institute of Technology.
* For copying and distribution information, see the file
* "mit-copyright.h".
*/
/* $Header$ */
#ifndef lint
static char rcsid_ZSubscriptions_c[] = "$Header$";
#endif lint
#include <zephyr/mit-copyright.h>
#include <zephyr/zephyr_internal.h>
Code_t ZSubscribeTo(sublist, nitems, port)
ZSubscription_t *sublist;
int nitems;
u_short port;
{
return (Z_Subscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE, 1));
}
Code_t ZUnsubscribeTo(sublist, nitems, port)
ZSubscription_t *sublist;
int nitems;
u_short port;
{
return (Z_Subscriptions(sublist, nitems, port, CLIENT_UNSUBSCRIBE, 1));
}
Code_t ZCancelSubscriptions(port)
u_short port;
{
return (Z_Subscriptions((ZSubscription_t *)0, 0, port,
CLIENT_CANCELSUB, 0));
}
Z_Subscriptions(sublist, nitems, port, opcode, authit)
ZSubscription_t *sublist;
int nitems;
u_short port;
char *opcode;
int authit;
{
int wait_for_servack();
int i, retval;
ZNotice_t notice, retnotice;
char **list;
list = (char **)malloc((unsigned)nitems*3*sizeof(char *));
if (!list)
return (ENOMEM);
notice.z_kind = ACKED;
notice.z_port = port;
notice.z_class = ZEPHYR_CTL_CLASS;
notice.z_class_inst = ZEPHYR_CTL_CLIENT;
notice.z_opcode = opcode;
notice.z_sender = 0;
notice.z_recipient = "";
notice.z_num_other_fields = 0;
notice.z_default_format = "";
notice.z_message_len = 0;
for (i=0;i<nitems;i++) {
list[i*3] = sublist[i].class;
list[i*3+1] = sublist[i].classinst;
if (sublist[i].recipient && *sublist[i].recipient &&
*sublist[i].recipient != '*')
list[i*3+2] = ZGetSender();
else
list[i*3+2] = "";
}
retval = ZSendList(¬ice, list, nitems*3, ZAUTH);
if (retval != ZERR_NONE && !authit)
retval = ZSendList(¬ice, list, nitems*3, ZNOAUTH);
free((char *)list);
if (retval != ZERR_NONE)
return (retval);
if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
wait_for_servack, (char *)¬ice.z_uid)) !=
ZERR_NONE)
return (retval);
ZFreeNotice(&retnotice);
if (retnotice.z_kind == SERVNAK)
return (ZERR_SERVNAK);
if (retnotice.z_kind != SERVACK)
return (ZERR_INTERNAL);
return (ZERR_NONE);
}
static wait_for_servack(notice, uid)
ZNotice_t *notice;
ZUnique_Id_t *uid;
{
return (notice->z_kind == SERVACK && ZCompareUID(¬ice->z_uid, uid));
}
|