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 ZSetLocation, ZUnsetLocation, and | |
| 3 | * ZFlushMyLocations 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:
18220
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:
31294
diff
changeset
|
13 | #include "util.h" |
| 2086 | 14 | |
| 10867 | 15 | #ifndef WIN32 |
| 2086 | 16 | #include <pwd.h> |
| 10867 | 17 | #endif |
| 2086 | 18 | |
|
13583
29c0a756c086
[gaim-migrate @ 15964]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
19 | #include <stdlib.h> |
|
29c0a756c086
[gaim-migrate @ 15964]
Richard Laager <rlaager@pidgin.im>
parents:
11105
diff
changeset
|
20 | #include <errno.h> |
| 2086 | 21 | |
| 22 | Code_t ZSetLocation(exposure) | |
| 23 | char *exposure; | |
| 24 | { | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
18220
diff
changeset
|
25 | return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH, |
| 2086 | 26 | "$sender logged in to $1 on $3 at $2")); |
| 27 | } | |
| 28 | ||
| 29 | Code_t ZUnsetLocation() | |
| 30 | { | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
18220
diff
changeset
|
31 | return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH, |
| 2086 | 32 | "$sender logged out of $1 on $3 at $2")); |
| 33 | } | |
| 34 | ||
| 35 | Code_t ZFlushMyLocations() | |
| 36 | { | |
| 37 | return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); | |
| 38 | } | |
| 39 | ||
|
18220
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
40 | static char host[MAXHOSTNAMELEN]; |
|
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
41 | static char *mytty = NULL; |
| 2086 | 42 | static int reenter = 0; |
| 43 | ||
| 44 | Code_t Z_SendLocation(class, opcode, auth, format) | |
| 45 | char *class; | |
| 46 | char *opcode; | |
| 47 | Z_AuthProc auth; | |
| 48 | char *format; | |
| 49 | { | |
| 50 | int retval; | |
| 51 | time_t ourtime; | |
| 52 | ZNotice_t notice, retnotice; | |
| 10867 | 53 | char *bptr[3]; |
| 2086 | 54 | #ifndef X_DISPLAY_MISSING |
| 55 | char *display; | |
| 56 | #endif | |
| 10867 | 57 | #ifndef WIN32 |
| 2086 | 58 | char *ttyp; |
| 10867 | 59 | char *p; |
| 60 | #endif | |
| 2086 | 61 | struct hostent *hent; |
| 62 | short wg_port = ZGetWGPort(); | |
| 63 | ||
| 64 | (void) memset((char *)¬ice, 0, sizeof(notice)); | |
| 65 | notice.z_kind = ACKED; | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2419
diff
changeset
|
66 | notice.z_port = (unsigned short) ((wg_port == -1) ? 0 : wg_port); |
| 2086 | 67 | notice.z_class = class; |
| 68 | notice.z_class_inst = ZGetSender(); | |
| 69 | notice.z_opcode = opcode; | |
| 70 | notice.z_sender = 0; | |
| 71 | notice.z_recipient = ""; | |
| 72 | notice.z_num_other_fields = 0; | |
| 73 | notice.z_default_format = format; | |
| 74 | ||
| 75 | /* | |
| 76 | keep track of what we said before so that we can be consistent | |
| 77 | when changing location information. | |
| 78 | This is done mainly for the sake of the WindowGram client. | |
| 79 | */ | |
| 80 | ||
| 81 | if (!reenter) { | |
| 82 | if (gethostname(host, MAXHOSTNAMELEN) < 0) | |
| 83 | return (errno); | |
| 84 | ||
| 85 | hent = gethostbyname(host); | |
| 86 | if (hent) { | |
| 87 | (void) strncpy(host, hent->h_name, sizeof(host)); | |
| 88 | host[sizeof(host) - 1] = '\0'; | |
| 89 | } | |
| 90 | #ifndef X_DISPLAY_MISSING | |
| 91 | if ((display = getenv("DISPLAY")) && *display) { | |
|
18220
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
92 | mytty = g_strdup(display); |
| 2086 | 93 | } else { |
| 94 | #endif | |
| 10867 | 95 | #ifdef WIN32 |
|
18220
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
96 | mytty = g_strdup("WinPurple"); |
| 10867 | 97 | #else |
| 2086 | 98 | ttyp = ttyname(0); |
| 2419 | 99 | if (ttyp && *ttyp) { |
| 100 | p = strchr(ttyp + 1, '/'); | |
|
18220
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
101 | mytty = g_strdup((p) ? p + 1 : ttyp); |
| 2419 | 102 | } else { |
|
18220
c88669a9d3dd
Use dynamicly allocated string manipulation here as well to avoid a
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
103 | mytty = g_strdup("unknown"); |
| 2086 | 104 | } |
| 10867 | 105 | #endif |
| 2086 | 106 | #ifndef X_DISPLAY_MISSING |
| 107 | } | |
| 108 | #endif | |
| 109 | reenter = 1; | |
| 110 | } | |
| 111 | ||
| 112 | ourtime = time((time_t *)0); | |
| 2419 | 113 | bptr[0] = host; |
| 2086 | 114 | bptr[1] = ctime(&ourtime); |
| 115 | bptr[1][strlen(bptr[1])-1] = '\0'; | |
| 2419 | 116 | bptr[2] = mytty; |
| 2086 | 117 | |
| 118 | if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) | |
| 119 | return (retval); | |
| 120 | ||
| 121 | retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, ¬ice.z_uid, | |
| 122 | SRV_TIMEOUT); | |
| 123 | if (retval != ZERR_NONE) | |
| 124 | return retval; | |
| 125 | ||
| 126 | if (retnotice.z_kind == SERVNAK) { | |
| 127 | if (!retnotice.z_message_len) { | |
| 128 | ZFreeNotice(&retnotice); | |
| 129 | return (ZERR_SERVNAK); | |
| 130 | } | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31294
diff
changeset
|
131 | if (purple_strequal(retnotice.z_message, ZSRVACK_NOTSENT)) { |
| 2086 | 132 | ZFreeNotice(&retnotice); |
| 133 | return (ZERR_AUTHFAIL); | |
| 134 | } | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
31294
diff
changeset
|
135 | if (purple_strequal(retnotice.z_message, ZSRVACK_FAIL)) { |
| 2086 | 136 | ZFreeNotice(&retnotice); |
| 137 | return (ZERR_LOGINFAIL); | |
| 138 | } | |
| 139 | ZFreeNotice(&retnotice); | |
| 140 | return (ZERR_SERVNAK); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
18220
diff
changeset
|
141 | } |
|
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
18220
diff
changeset
|
142 | |
| 2086 | 143 | if (retnotice.z_kind != SERVACK) { |
| 144 | ZFreeNotice(&retnotice); | |
| 145 | return (ZERR_INTERNAL); | |
| 146 | } | |
| 147 | ||
| 148 | if (!retnotice.z_message_len) { | |
| 149 | ZFreeNotice(&retnotice); | |
| 150 | return (ZERR_INTERNAL); | |
| 151 | } | |
| 152 | ||
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
153 | if (!purple_strequal(retnotice.z_message, ZSRVACK_SENT) && |
|
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
154 | !purple_strequal(retnotice.z_message, ZSRVACK_NOTSENT)) { |
| 2086 | 155 | ZFreeNotice(&retnotice); |
| 156 | return (ZERR_INTERNAL); | |
| 157 | } | |
| 158 | ||
| 159 | ZFreeNotice(&retnotice); | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
18220
diff
changeset
|
160 | |
| 2086 | 161 | return (ZERR_NONE); |
| 162 | } |