Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / protocols / zephyr / ZLocations.c
blob66703975d6b385cbd305c501fa703c6d50e35f66
1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZSetLocation, ZUnsetLocation, and
3 * ZFlushMyLocations functions.
5 * Created by: Robert French
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".
12 #include "internal.h"
13 #include "util.h"
15 #ifndef WIN32
16 #include <pwd.h>
17 #endif
19 #include <stdlib.h>
20 #include <errno.h>
22 Code_t ZSetLocation(exposure)
23 char *exposure;
25 return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH,
26 "$sender logged in to $1 on $3 at $2"));
29 Code_t ZUnsetLocation()
31 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH,
32 "$sender logged out of $1 on $3 at $2"));
35 Code_t ZFlushMyLocations()
37 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
40 static char host[MAXHOSTNAMELEN];
41 static char *mytty = NULL;
42 static int reenter = 0;
44 Code_t Z_SendLocation(class, opcode, auth, format)
45 char *class;
46 char *opcode;
47 Z_AuthProc auth;
48 char *format;
50 int retval;
51 time_t ourtime;
52 ZNotice_t notice, retnotice;
53 char *bptr[3];
54 #ifndef X_DISPLAY_MISSING
55 char *display;
56 #endif
57 #ifndef WIN32
58 char *ttyp;
59 char *p;
60 #endif
61 struct hostent *hent;
62 short wg_port = ZGetWGPort();
64 (void) memset((char *)&notice, 0, sizeof(notice));
65 notice.z_kind = ACKED;
66 notice.z_port = (unsigned short) ((wg_port == -1) ? 0 : wg_port);
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;
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.
81 if (!reenter) {
82 if (gethostname(host, MAXHOSTNAMELEN) < 0)
83 return (errno);
85 hent = gethostbyname(host);
86 if (hent) {
87 (void) strncpy(host, hent->h_name, sizeof(host));
88 host[sizeof(host) - 1] = '\0';
90 #ifndef X_DISPLAY_MISSING
91 if ((display = getenv("DISPLAY")) && *display) {
92 mytty = g_strdup(display);
93 } else {
94 #endif
95 #ifdef WIN32
96 mytty = g_strdup("WinPurple");
97 #else
98 ttyp = ttyname(0);
99 if (ttyp && *ttyp) {
100 p = strchr(ttyp + 1, '/');
101 mytty = g_strdup((p) ? p + 1 : ttyp);
102 } else {
103 mytty = g_strdup("unknown");
105 #endif
106 #ifndef X_DISPLAY_MISSING
108 #endif
109 reenter = 1;
112 ourtime = time((time_t *)0);
113 bptr[0] = host;
114 bptr[1] = ctime(&ourtime);
115 bptr[1][strlen(bptr[1])-1] = '\0';
116 bptr[2] = mytty;
118 if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
119 return (retval);
121 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, &notice.z_uid,
122 SRV_TIMEOUT);
123 if (retval != ZERR_NONE)
124 return retval;
126 if (retnotice.z_kind == SERVNAK) {
127 if (!retnotice.z_message_len) {
128 ZFreeNotice(&retnotice);
129 return (ZERR_SERVNAK);
131 if (purple_strequal(retnotice.z_message, ZSRVACK_NOTSENT)) {
132 ZFreeNotice(&retnotice);
133 return (ZERR_AUTHFAIL);
135 if (purple_strequal(retnotice.z_message, ZSRVACK_FAIL)) {
136 ZFreeNotice(&retnotice);
137 return (ZERR_LOGINFAIL);
139 ZFreeNotice(&retnotice);
140 return (ZERR_SERVNAK);
143 if (retnotice.z_kind != SERVACK) {
144 ZFreeNotice(&retnotice);
145 return (ZERR_INTERNAL);
148 if (!retnotice.z_message_len) {
149 ZFreeNotice(&retnotice);
150 return (ZERR_INTERNAL);
153 if (!purple_strequal(retnotice.z_message, ZSRVACK_SENT) &&
154 !purple_strequal(retnotice.z_message, ZSRVACK_NOTSENT)) {
155 ZFreeNotice(&retnotice);
156 return (ZERR_INTERNAL);
159 ZFreeNotice(&retnotice);
161 return (ZERR_NONE);