Wed, 21 Aug 2013 14:59:29 +0200
Fix most of libpurple warnings about -Wsign-compare
| 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 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
9 | * "mit-copyright.h". |
| 2086 | 10 | */ |
| 11 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
12 | #include "internal.h" |
| 2086 | 13 | |
|
12424
af82a40f2488
[gaim-migrate @ 14731]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
14 | static Code_t Z_RetSubs(ZNotice_t *notice, int *nsubs, Z_AuthProc auth_routine); |
| 2086 | 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]; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
28 | |
| 2086 | 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 | ||
|
12424
af82a40f2488
[gaim-migrate @ 14731]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
44 | #if 0 |
| 2086 | 45 | Code_t ZRetrieveDefaultSubscriptions(nsubs) |
| 46 | int *nsubs; | |
| 47 | { | |
| 48 | ZNotice_t notice; | |
| 49 | ||
| 50 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 51 | notice.z_message = (char *) 0; | |
| 52 | notice.z_message_len = 0; | |
| 53 | notice.z_opcode = CLIENT_GIMMEDEFS; | |
| 54 | ||
| 55 | return(Z_RetSubs(¬ice, nsubs, ZNOAUTH)); | |
| 56 | ||
| 57 | } | |
|
12424
af82a40f2488
[gaim-migrate @ 14731]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
58 | #endif |
| 2086 | 59 | |
| 60 | static Code_t Z_RetSubs(notice, nsubs, auth_routine) | |
| 61 | register ZNotice_t *notice; | |
| 62 | int *nsubs; | |
| 63 | Z_AuthProc auth_routine; | |
| 64 | { | |
| 65 | register int i; | |
| 66 | int retval,nrecv,gimmeack; | |
| 67 | ZNotice_t retnotice; | |
| 68 | char *ptr,*end,*ptr2; | |
| 69 | ||
| 70 | retval = ZFlushSubscriptions(); | |
| 71 | ||
| 72 | if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS) | |
| 73 | return (retval); | |
| 74 | ||
| 75 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
76 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 77 | return (retval); |
| 78 | ||
| 79 | notice->z_kind = ACKED; | |
| 80 | notice->z_port = __Zephyr_port; | |
| 81 | notice->z_class = ZEPHYR_CTL_CLASS; | |
| 82 | notice->z_class_inst = ZEPHYR_CTL_CLIENT; | |
| 83 | notice->z_sender = 0; | |
| 84 | notice->z_recipient = ""; | |
| 85 | notice->z_default_format = ""; | |
| 86 | ||
| 87 | if ((retval = ZSendNotice(notice,auth_routine)) != ZERR_NONE) | |
| 88 | return (retval); | |
| 89 | ||
| 90 | nrecv = 0; | |
| 91 | gimmeack = 0; | |
| 92 | __subscriptions_list = (ZSubscription_t *) 0; | |
| 93 | ||
| 94 | while (!nrecv || !gimmeack) { | |
| 95 | retval = Z_WaitForNotice (&retnotice, ZCompareMultiUIDPred, | |
| 96 | ¬ice->z_multiuid, SRV_TIMEOUT); | |
| 97 | if (retval == ZERR_NONOTICE) | |
| 98 | return ETIMEDOUT; | |
| 99 | else if (retval != ZERR_NONE) | |
| 100 | return retval; | |
| 101 | ||
| 102 | if (retnotice.z_kind == SERVNAK) { | |
| 103 | ZFreeNotice(&retnotice); | |
| 104 | return (ZERR_SERVNAK); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
105 | } |
| 2086 | 106 | /* non-matching protocol version numbers means the |
| 107 | server is probably an older version--must punt */ | |
| 108 | if (strcmp(notice->z_version,retnotice.z_version)) { | |
| 109 | ZFreeNotice(&retnotice); | |
| 110 | return(ZERR_VERS); | |
| 111 | } | |
| 112 | if (retnotice.z_kind == SERVACK && | |
| 113 | !strcmp(retnotice.z_opcode,notice->z_opcode)) { | |
| 114 | ZFreeNotice(&retnotice); | |
| 115 | gimmeack = 1; | |
| 116 | continue; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
117 | } |
| 2086 | 118 | |
| 119 | if (retnotice.z_kind != ACKED) { | |
| 120 | ZFreeNotice(&retnotice); | |
| 121 | return (ZERR_INTERNAL); | |
| 122 | } | |
| 123 | ||
| 124 | nrecv++; | |
| 125 | ||
| 126 | end = retnotice.z_message+retnotice.z_message_len; | |
| 127 | ||
| 128 | __subscriptions_num = 0; | |
| 129 | for (ptr=retnotice.z_message;ptr<end;ptr++) | |
| 130 | if (!*ptr) | |
| 131 | __subscriptions_num++; | |
| 132 | ||
| 133 | __subscriptions_num = __subscriptions_num / 3; | |
| 134 | ||
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
135 | if (!__subscriptions_num) { |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
136 | ZFreeNotice(&retnotice); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
137 | continue; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
138 | } |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
139 | |
| 2086 | 140 | __subscriptions_list = (ZSubscription_t *) |
| 141 | malloc((unsigned)(__subscriptions_num* | |
| 142 | sizeof(ZSubscription_t))); | |
| 143 | if (__subscriptions_num && !__subscriptions_list) { | |
| 144 | ZFreeNotice(&retnotice); | |
| 145 | return (ENOMEM); | |
| 146 | } | |
| 147 | ||
| 148 | for (ptr=retnotice.z_message,i = 0; i< __subscriptions_num; i++) { | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
149 | size_t len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
150 | |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
151 | len = strlen(ptr) + 1; |
| 2086 | 152 | __subscriptions_list[i].zsub_class = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
153 | malloc(len); |
| 2086 | 154 | if (!__subscriptions_list[i].zsub_class) { |
| 155 | ZFreeNotice(&retnotice); | |
| 156 | return (ENOMEM); | |
| 157 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
158 | g_strlcpy(__subscriptions_list[i].zsub_class,ptr,len); |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
159 | ptr += len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
160 | len = strlen(ptr) + 1; |
| 2086 | 161 | __subscriptions_list[i].zsub_classinst = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
162 | malloc(len); |
| 2086 | 163 | if (!__subscriptions_list[i].zsub_classinst) { |
| 164 | ZFreeNotice(&retnotice); | |
| 165 | return (ENOMEM); | |
| 166 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
167 | g_strlcpy(__subscriptions_list[i].zsub_classinst,ptr,len); |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
168 | ptr += len; |
| 2086 | 169 | ptr2 = ptr; |
| 170 | if (!*ptr2) | |
| 171 | ptr2 = "*"; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
172 | len = strlen(ptr2) + 1; |
| 2086 | 173 | __subscriptions_list[i].zsub_recipient = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
174 | malloc(len); |
| 2086 | 175 | if (!__subscriptions_list[i].zsub_recipient) { |
| 176 | ZFreeNotice(&retnotice); | |
| 177 | return (ENOMEM); | |
| 178 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
179 | g_strlcpy(__subscriptions_list[i].zsub_recipient,ptr2,len); |
| 2086 | 180 | ptr += strlen(ptr)+1; |
| 181 | } | |
| 182 | ZFreeNotice(&retnotice); | |
| 183 | } | |
| 184 | ||
| 185 | __subscriptions_next = 0; | |
| 186 | *nsubs = __subscriptions_num; | |
| 187 | ||
| 188 | return (ZERR_NONE); | |
| 189 | } |