Sat, 06 Feb 2021 01:41:47 -0600
Use more get_paren_level
Deduplicate code.
Testing Done:
Compile.
Reviewed at https://reviews.imfreedom.org/r/480/
| 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" |
|
40474
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
40166
diff
changeset
|
13 | |
|
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
40166
diff
changeset
|
14 | #include <purple.h> |
| 2086 | 15 | |
|
12424
af82a40f2488
[gaim-migrate @ 14731]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
16 | static Code_t Z_RetSubs(ZNotice_t *notice, int *nsubs, Z_AuthProc auth_routine); |
| 2086 | 17 | |
| 18 | Code_t ZRetrieveSubscriptions(unsigned short port, int *nsubs) | |
| 19 | { | |
| 20 | int retval; | |
| 21 | ZNotice_t notice; | |
| 22 | char asciiport[50]; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
23 | |
| 2086 | 24 | if (!port) /* use default port */ |
| 25 | port = __Zephyr_port; | |
| 26 | ||
|
40653
503cfa50c8c3
Use GLib's byte-order macros.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40643
diff
changeset
|
27 | retval = ZMakeAscii16(asciiport, sizeof(asciiport), g_ntohs(port)); |
| 2086 | 28 | if (retval != ZERR_NONE) |
| 29 | return (retval); | |
| 30 | ||
| 31 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 32 | notice.z_message = asciiport; | |
| 33 | notice.z_message_len = strlen(asciiport)+1; | |
| 34 | notice.z_opcode = CLIENT_GIMMESUBS; | |
| 35 | ||
| 36 | return(Z_RetSubs(¬ice, nsubs, ZAUTH)); | |
| 37 | } | |
| 38 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39913
diff
changeset
|
39 | static Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39913
diff
changeset
|
40 | Z_RetSubs(register ZNotice_t *notice, int *nsubs, Z_AuthProc auth_routine) |
| 2086 | 41 | { |
| 42 | register int i; | |
| 43 | int retval,nrecv,gimmeack; | |
| 44 | ZNotice_t retnotice; | |
| 45 | char *ptr,*end,*ptr2; | |
| 46 | ||
| 47 | retval = ZFlushSubscriptions(); | |
| 48 | ||
| 49 | if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS) | |
| 50 | return (retval); | |
| 51 | ||
|
40643
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
52 | if (ZGetSocket() == NULL) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
53 | retval = ZOpenPort(NULL); |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
54 | if (retval != ZERR_NONE) { |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
55 | return retval; |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
56 | } |
|
1c9bdf8d3e85
Convert zephyr to gio
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
57 | } |
| 2086 | 58 | |
| 59 | notice->z_kind = ACKED; | |
| 60 | notice->z_port = __Zephyr_port; | |
| 61 | notice->z_class = ZEPHYR_CTL_CLASS; | |
| 62 | notice->z_class_inst = ZEPHYR_CTL_CLIENT; | |
| 63 | notice->z_sender = 0; | |
| 64 | notice->z_recipient = ""; | |
| 65 | notice->z_default_format = ""; | |
| 66 | ||
| 67 | if ((retval = ZSendNotice(notice,auth_routine)) != ZERR_NONE) | |
| 68 | return (retval); | |
| 69 | ||
| 70 | nrecv = 0; | |
| 71 | gimmeack = 0; | |
| 72 | __subscriptions_list = (ZSubscription_t *) 0; | |
| 73 | ||
| 74 | while (!nrecv || !gimmeack) { | |
| 75 | retval = Z_WaitForNotice (&retnotice, ZCompareMultiUIDPred, | |
| 76 | ¬ice->z_multiuid, SRV_TIMEOUT); | |
| 77 | if (retval == ZERR_NONOTICE) | |
| 78 | return ETIMEDOUT; | |
| 79 | else if (retval != ZERR_NONE) | |
| 80 | return retval; | |
| 81 | ||
| 82 | if (retnotice.z_kind == SERVNAK) { | |
| 83 | ZFreeNotice(&retnotice); | |
| 84 | return (ZERR_SERVNAK); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
85 | } |
| 2086 | 86 | /* non-matching protocol version numbers means the |
| 87 | server is probably an older version--must punt */ | |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
88 | if (!purple_strequal(notice->z_version,retnotice.z_version)) { |
| 2086 | 89 | ZFreeNotice(&retnotice); |
| 90 | return(ZERR_VERS); | |
| 91 | } | |
| 92 | if (retnotice.z_kind == SERVACK && | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
35993
diff
changeset
|
93 | purple_strequal(retnotice.z_opcode,notice->z_opcode)) { |
| 2086 | 94 | ZFreeNotice(&retnotice); |
| 95 | gimmeack = 1; | |
| 96 | continue; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
97 | } |
| 2086 | 98 | |
| 99 | if (retnotice.z_kind != ACKED) { | |
| 100 | ZFreeNotice(&retnotice); | |
| 101 | return (ZERR_INTERNAL); | |
| 102 | } | |
| 103 | ||
| 104 | nrecv++; | |
| 105 | ||
| 106 | end = retnotice.z_message+retnotice.z_message_len; | |
| 107 | ||
| 108 | __subscriptions_num = 0; | |
| 109 | for (ptr=retnotice.z_message;ptr<end;ptr++) | |
| 110 | if (!*ptr) | |
| 111 | __subscriptions_num++; | |
| 112 | ||
| 113 | __subscriptions_num = __subscriptions_num / 3; | |
| 114 | ||
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
115 | 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
|
116 | ZFreeNotice(&retnotice); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
117 | continue; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
118 | } |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31955
diff
changeset
|
119 | |
|
35993
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31955
diff
changeset
|
120 | free(__subscriptions_list); |
| 2086 | 121 | __subscriptions_list = (ZSubscription_t *) |
| 122 | malloc((unsigned)(__subscriptions_num* | |
| 123 | sizeof(ZSubscription_t))); | |
|
39913
ce96d4639dc7
Remove redundant conditions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
124 | if (!__subscriptions_list) { |
| 2086 | 125 | ZFreeNotice(&retnotice); |
| 126 | return (ENOMEM); | |
| 127 | } | |
| 128 | ||
| 129 | 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
|
130 | size_t len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
131 | |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
132 | len = strlen(ptr) + 1; |
| 2086 | 133 | __subscriptions_list[i].zsub_class = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
134 | malloc(len); |
| 2086 | 135 | if (!__subscriptions_list[i].zsub_class) { |
| 136 | ZFreeNotice(&retnotice); | |
| 137 | return (ENOMEM); | |
| 138 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
139 | 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
|
140 | ptr += len; |
|
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
141 | len = strlen(ptr) + 1; |
| 2086 | 142 | __subscriptions_list[i].zsub_classinst = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
143 | malloc(len); |
| 2086 | 144 | if (!__subscriptions_list[i].zsub_classinst) { |
| 145 | ZFreeNotice(&retnotice); | |
| 146 | return (ENOMEM); | |
| 147 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
148 | 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
|
149 | ptr += len; |
| 2086 | 150 | ptr2 = ptr; |
| 151 | if (!*ptr2) | |
| 152 | ptr2 = "*"; | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
153 | len = strlen(ptr2) + 1; |
| 2086 | 154 | __subscriptions_list[i].zsub_recipient = (char *) |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
155 | malloc(len); |
| 2086 | 156 | if (!__subscriptions_list[i].zsub_recipient) { |
| 157 | ZFreeNotice(&retnotice); | |
| 158 | return (ENOMEM); | |
| 159 | } | |
|
31955
384153346831
Fix up Zephyr g_strlcpy patch
Ethan Blanton <elb@pidgin.im>
parents:
31954
diff
changeset
|
160 | g_strlcpy(__subscriptions_list[i].zsub_recipient,ptr2,len); |
| 2086 | 161 | ptr += strlen(ptr)+1; |
| 162 | } | |
| 163 | ZFreeNotice(&retnotice); | |
| 164 | } | |
| 165 | ||
| 166 | __subscriptions_next = 0; | |
| 167 | *nsubs = __subscriptions_num; | |
| 168 | ||
| 169 | return (ZERR_NONE); | |
| 170 | } |