Mercurial > pidgin
annotate src/protocols/zephyr/ZRetSubs.c @ 11105:64895571248f
[gaim-migrate @ 13153]
CVS keywords are making my life difficult right now. I know I could change the keyword expansion somehow, but I don't see the use for them here, so I'm taking the easy (and IMO, better long-term) approach of removing them. My apologies for the commit spam.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 14 Jul 2005 02:19:01 +0000 |
parents | 43d6c08d7e96 |
children | 7c2e2c4d45a4 |
rev | line source |
---|---|
2086 | 1 /* This file is part of the Project Athena Zephyr Notification System. |
2 * It contains source for the ZRetrieveSubscriptions and | |
3 * ZRetrieveDefaultSubscriptions functions. | |
4 * | |
5 * Created by: Robert French | |
6 * | |
7 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology. | |
8 * For copying and distribution information, see the file | |
9 * "mit-copyright.h". | |
10 */ | |
11 | |
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
12 #include "internal.h" |
2086 | 13 |
14 static Code_t Z_RetSubs (); | |
15 | |
16 /* Need STDC definition when possible for unsigned short argument. */ | |
17 #ifdef __STDC__ | |
18 Code_t ZRetrieveSubscriptions(unsigned short port, int *nsubs) | |
19 #else | |
20 Code_t ZRetrieveSubscriptions(port,nsubs) | |
21 unsigned short port; | |
22 int *nsubs; | |
23 #endif | |
24 { | |
25 int retval; | |
26 ZNotice_t notice; | |
27 char asciiport[50]; | |
28 | |
29 if (!port) /* use default port */ | |
30 port = __Zephyr_port; | |
31 | |
32 retval = ZMakeAscii16(asciiport, sizeof(asciiport), ntohs(port)); | |
33 if (retval != ZERR_NONE) | |
34 return (retval); | |
35 | |
36 (void) memset((char *)¬ice, 0, sizeof(notice)); | |
37 notice.z_message = asciiport; | |
38 notice.z_message_len = strlen(asciiport)+1; | |
39 notice.z_opcode = CLIENT_GIMMESUBS; | |
40 | |
41 return(Z_RetSubs(¬ice, nsubs, ZAUTH)); | |
42 } | |
43 | |
44 Code_t ZRetrieveDefaultSubscriptions(nsubs) | |
45 int *nsubs; | |
46 { | |
47 ZNotice_t notice; | |
48 | |
49 (void) memset((char *)¬ice, 0, sizeof(notice)); | |
50 notice.z_message = (char *) 0; | |
51 notice.z_message_len = 0; | |
52 notice.z_opcode = CLIENT_GIMMEDEFS; | |
53 | |
54 return(Z_RetSubs(¬ice, nsubs, ZNOAUTH)); | |
55 | |
56 } | |
57 | |
58 static Code_t Z_RetSubs(notice, nsubs, auth_routine) | |
59 register ZNotice_t *notice; | |
60 int *nsubs; | |
61 Z_AuthProc auth_routine; | |
62 { | |
63 register int i; | |
64 int retval,nrecv,gimmeack; | |
65 ZNotice_t retnotice; | |
66 char *ptr,*end,*ptr2; | |
67 | |
68 retval = ZFlushSubscriptions(); | |
69 | |
70 if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS) | |
71 return (retval); | |
72 | |
73 if (ZGetFD() < 0) | |
7475 | 74 if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
2086 | 75 return (retval); |
76 | |
77 notice->z_kind = ACKED; | |
78 notice->z_port = __Zephyr_port; | |
79 notice->z_class = ZEPHYR_CTL_CLASS; | |
80 notice->z_class_inst = ZEPHYR_CTL_CLIENT; | |
81 notice->z_sender = 0; | |
82 notice->z_recipient = ""; | |
83 notice->z_default_format = ""; | |
84 | |
85 if ((retval = ZSendNotice(notice,auth_routine)) != ZERR_NONE) | |
86 return (retval); | |
87 | |
88 nrecv = 0; | |
89 gimmeack = 0; | |
90 __subscriptions_list = (ZSubscription_t *) 0; | |
91 | |
92 while (!nrecv || !gimmeack) { | |
93 retval = Z_WaitForNotice (&retnotice, ZCompareMultiUIDPred, | |
94 ¬ice->z_multiuid, SRV_TIMEOUT); | |
95 if (retval == ZERR_NONOTICE) | |
96 return ETIMEDOUT; | |
97 else if (retval != ZERR_NONE) | |
98 return retval; | |
99 | |
100 if (retnotice.z_kind == SERVNAK) { | |
101 ZFreeNotice(&retnotice); | |
102 return (ZERR_SERVNAK); | |
103 } | |
104 /* non-matching protocol version numbers means the | |
105 server is probably an older version--must punt */ | |
106 if (strcmp(notice->z_version,retnotice.z_version)) { | |
107 ZFreeNotice(&retnotice); | |
108 return(ZERR_VERS); | |
109 } | |
110 if (retnotice.z_kind == SERVACK && | |
111 !strcmp(retnotice.z_opcode,notice->z_opcode)) { | |
112 ZFreeNotice(&retnotice); | |
113 gimmeack = 1; | |
114 continue; | |
115 } | |
116 | |
117 if (retnotice.z_kind != ACKED) { | |
118 ZFreeNotice(&retnotice); | |
119 return (ZERR_INTERNAL); | |
120 } | |
121 | |
122 nrecv++; | |
123 | |
124 end = retnotice.z_message+retnotice.z_message_len; | |
125 | |
126 __subscriptions_num = 0; | |
127 for (ptr=retnotice.z_message;ptr<end;ptr++) | |
128 if (!*ptr) | |
129 __subscriptions_num++; | |
130 | |
131 __subscriptions_num = __subscriptions_num / 3; | |
132 | |
133 __subscriptions_list = (ZSubscription_t *) | |
134 malloc((unsigned)(__subscriptions_num* | |
135 sizeof(ZSubscription_t))); | |
136 if (__subscriptions_num && !__subscriptions_list) { | |
137 ZFreeNotice(&retnotice); | |
138 return (ENOMEM); | |
139 } | |
140 | |
141 for (ptr=retnotice.z_message,i = 0; i< __subscriptions_num; i++) { | |
142 __subscriptions_list[i].zsub_class = (char *) | |
143 malloc((unsigned)strlen(ptr)+1); | |
144 if (!__subscriptions_list[i].zsub_class) { | |
145 ZFreeNotice(&retnotice); | |
146 return (ENOMEM); | |
147 } | |
148 (void) strcpy(__subscriptions_list[i].zsub_class,ptr); | |
149 ptr += strlen(ptr)+1; | |
150 __subscriptions_list[i].zsub_classinst = (char *) | |
151 malloc((unsigned)strlen(ptr)+1); | |
152 if (!__subscriptions_list[i].zsub_classinst) { | |
153 ZFreeNotice(&retnotice); | |
154 return (ENOMEM); | |
155 } | |
156 (void) strcpy(__subscriptions_list[i].zsub_classinst,ptr); | |
157 ptr += strlen(ptr)+1; | |
158 ptr2 = ptr; | |
159 if (!*ptr2) | |
160 ptr2 = "*"; | |
161 __subscriptions_list[i].zsub_recipient = (char *) | |
162 malloc((unsigned)strlen(ptr2)+1); | |
163 if (!__subscriptions_list[i].zsub_recipient) { | |
164 ZFreeNotice(&retnotice); | |
165 return (ENOMEM); | |
166 } | |
167 (void) strcpy(__subscriptions_list[i].zsub_recipient,ptr2); | |
168 ptr += strlen(ptr)+1; | |
169 } | |
170 ZFreeNotice(&retnotice); | |
171 } | |
172 | |
173 __subscriptions_next = 0; | |
174 *nsubs = __subscriptions_num; | |
175 | |
176 return (ZERR_NONE); | |
177 } |