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
22 Code_t
ZSetLocation(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
)
52 ZNotice_t notice
, retnotice
;
54 #ifndef X_DISPLAY_MISSING
62 short wg_port
= ZGetWGPort();
64 (void) memset((char *)¬ice
, 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
;
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.
82 if (gethostname(host
, MAXHOSTNAMELEN
) < 0)
85 hent
= gethostbyname(host
);
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
);
96 mytty
= g_strdup("WinPurple");
100 p
= strchr(ttyp
+ 1, '/');
101 mytty
= g_strdup((p
) ? p
+ 1 : ttyp
);
103 mytty
= g_strdup("unknown");
106 #ifndef X_DISPLAY_MISSING
112 ourtime
= time((time_t *)0);
114 bptr
[1] = ctime(&ourtime
);
115 bptr
[1][strlen(bptr
[1])-1] = '\0';
118 if ((retval
= ZSendList(¬ice
, bptr
, 3, auth
)) != ZERR_NONE
)
121 retval
= Z_WaitForNotice (&retnotice
, ZCompareUIDPred
, ¬ice
.z_uid
,
123 if (retval
!= ZERR_NONE
)
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
);