Tue, 05 Nov 2019 21:07:41 -0500
Add some NULL checks to silence scan-build.
| 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" |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
35993
diff
changeset
|
13 | #include "util.h" |
| 2086 | 14 | |
|
12424
af82a40f2488
[gaim-migrate @ 14731]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
15 | static Code_t Z_RetSubs(ZNotice_t *notice, int *nsubs, Z_AuthProc auth_routine); |
| 2086 | 16 | |
| 17 | Code_t ZRetrieveSubscriptions(unsigned short port, int *nsubs) | |
| 18 | { | |
| 19 | int retval; | |
| 20 | ZNotice_t notice; | |
| 21 | char asciiport[50]; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
22 | |
| 2086 | 23 | if (!port) /* use default port */ |
| 24 | port = __Zephyr_port; | |
| 25 | ||
| 26 | retval = ZMakeAscii16(asciiport, sizeof(asciiport), ntohs(port)); | |
| 27 | if (retval != ZERR_NONE) | |
| 28 | return (retval); | |
| 29 | ||
| 30 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 31 | notice.z_message = asciiport; | |
| 32 | notice.z_message_len = strlen(asciiport)+1; | |
| 33 | notice.z_opcode = CLIENT_GIMMESUBS; | |
| 34 | ||
| 35 | return(Z_RetSubs(¬ice, nsubs, ZAUTH)); | |
| 36 | } | |
| 37 | ||
| 38 | static Code_t Z_RetSubs(notice, nsubs, auth_routine) | |
| 39 | register ZNotice_t *notice; | |
| 40 | int *nsubs; | |
| 41 | Z_AuthProc auth_routine; | |
| 42 | { | |
| 43 | register int i; | |
| 44 | int retval,nrecv,gimmeack; | |
| 45 | ZNotice_t retnotice; | |
| 46 | char *ptr,*end,*ptr2; | |
| 47 | ||
| 48 | retval = ZFlushSubscriptions(); | |
| 49 | ||
| 50 | if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS) | |
| 51 | return (retval); | |
| 52 | ||
| 53 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2086
diff
changeset
|
54 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 55 | return (retval); |
| 56 | ||
| 57 | notice->z_kind = ACKED; | |
| 58 | notice->z_port = __Zephyr_port; | |
| 59 | notice->z_class = ZEPHYR_CTL_CLASS; | |
| 60 | notice->z_class_inst = ZEPHYR_CTL_CLIENT; | |
| 61 | notice->z_sender = 0; | |
| 62 | notice->z_recipient = ""; | |
| 63 | notice->z_default_format = ""; | |
| 64 | ||
| 65 | if ((retval = ZSendNotice(notice,auth_routine)) != ZERR_NONE) | |
| 66 | return (retval); | |
| 67 | ||
| 68 | nrecv = 0; | |
| 69 | gimmeack = 0; | |
| 70 | __subscriptions_list = (ZSubscription_t *) 0; | |
| 71 | ||
| 72 | while (!nrecv || !gimmeack) { | |
| 73 | retval = Z_WaitForNotice (&retnotice, ZCompareMultiUIDPred, | |
| 74 | ¬ice->z_multiuid, SRV_TIMEOUT); | |
| 75 | if (retval == ZERR_NONOTICE) | |
| 76 | return ETIMEDOUT; | |
| 77 | else if (retval != ZERR_NONE) | |
| 78 | return retval; | |
| 79 | ||
| 80 | if (retnotice.z_kind == SERVNAK) { | |
| 81 | ZFreeNotice(&retnotice); | |
| 82 | return (ZERR_SERVNAK); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
83 | } |
| 2086 | 84 | /* non-matching protocol version numbers means the |
| 85 | server is probably an older version--must punt */ | |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
86 | if (!purple_strequal(notice->z_version,retnotice.z_version)) { |
| 2086 | 87 | ZFreeNotice(&retnotice); |
| 88 | return(ZERR_VERS); | |
| 89 | } | |
| 90 | if (retnotice.z_kind == SERVACK && | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
35993
diff
changeset
|
91 | purple_strequal(retnotice.z_opcode,notice->z_opcode)) { |
| 2086 | 92 | ZFreeNotice(&retnotice); |
| 93 | gimmeack = 1; | |
| 94 | continue; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
95 | } |
| 2086 | 96 | |
| 97 | if (retnotice.z_kind != ACKED) { | |
| 98 | ZFreeNotice(&retnotice); | |
| 99 | return (ZERR_INTERNAL); | |
| 100 | } | |
| 101 | ||
| 102 | nrecv++; | |
| 103 | ||
| 104 | end = retnotice.z_message+retnotice.z_message_len; | |
| 105 | ||
| 106 | __subscriptions_num = 0; | |
| 107 | for (ptr=retnotice.z_message;ptr<end;ptr++) | |
| 108 | if (!*ptr) | |
| 109 | __subscriptions_num++; | |
| 110 | ||
| 111 | __subscriptions_num = __subscriptions_num / 3; | |
| 112 | ||
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
113 | 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
|
114 | ZFreeNotice(&retnotice); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
115 | continue; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
116 | } |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
117 | |
|
35993
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31955
diff
changeset
|
118 | free(__subscriptions_list); |
| 2086 | 119 | __subscriptions_list = (ZSubscription_t *) |
| 120 | malloc((unsigned)(__subscriptions_num* | |
| 121 | sizeof(ZSubscription_t))); | |
|
39913
ce96d4639dc7
Remove redundant conditions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
122 | if (!__subscriptions_list) { |
| 2086 | 123 | ZFreeNotice(&retnotice); |
| 124 | return (ENOMEM); | |
| 125 | } | |
| 126 | ||
| 127 | 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
|
128 | size_t len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
129 | |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
130 | len = strlen(ptr) + 1; |
| 2086 | 131 | __subscriptions_list[i].zsub_class = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
132 | malloc(len); |
| 2086 | 133 | if (!__subscriptions_list[i].zsub_class) { |
| 134 | ZFreeNotice(&retnotice); | |
| 135 | return (ENOMEM); | |
| 136 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
137 | 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
|
138 | ptr += len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
139 | len = strlen(ptr) + 1; |
| 2086 | 140 | __subscriptions_list[i].zsub_classinst = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
141 | malloc(len); |
| 2086 | 142 | if (!__subscriptions_list[i].zsub_classinst) { |
| 143 | ZFreeNotice(&retnotice); | |
| 144 | return (ENOMEM); | |
| 145 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
146 | 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
|
147 | ptr += len; |
| 2086 | 148 | ptr2 = ptr; |
| 149 | if (!*ptr2) | |
| 150 | ptr2 = "*"; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
151 | len = strlen(ptr2) + 1; |
| 2086 | 152 | __subscriptions_list[i].zsub_recipient = (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_recipient) { |
| 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_recipient,ptr2,len); |
| 2086 | 159 | ptr += strlen(ptr)+1; |
| 160 | } | |
| 161 | ZFreeNotice(&retnotice); | |
| 162 | } | |
| 163 | ||
| 164 | __subscriptions_next = 0; | |
| 165 | *nsubs = __subscriptions_num; | |
| 166 | ||
| 167 | return (ZERR_NONE); | |
| 168 | } |