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
21 Code_t
ZSetLocation(exposure
)
24 return (Z_SendLocation(LOGIN_CLASS
, exposure
, ZAUTH
,
25 "$sender logged in to $1 on $3 at $2"));
28 Code_t
ZUnsetLocation()
30 return (Z_SendLocation(LOGIN_CLASS
, LOGIN_USER_LOGOUT
, ZNOAUTH
,
31 "$sender logged out of $1 on $3 at $2"));
34 Code_t
ZFlushMyLocations()
36 return (Z_SendLocation(LOGIN_CLASS
, LOGIN_USER_FLUSH
, ZAUTH
, ""));
39 static char host
[MAXHOSTNAMELEN
];
40 static char *mytty
= NULL
;
41 static int reenter
= 0;
43 Code_t
Z_SendLocation(class, opcode
, auth
, format
)
51 ZNotice_t notice
, retnotice
;
53 #ifndef X_DISPLAY_MISSING
61 short wg_port
= ZGetWGPort();
63 (void) memset((char *)¬ice
, 0, sizeof(notice
));
64 notice
.z_kind
= ACKED
;
65 notice
.z_port
= (unsigned short) ((wg_port
== -1) ? 0 : wg_port
);
66 notice
.z_class
= class;
67 notice
.z_class_inst
= ZGetSender();
68 notice
.z_opcode
= opcode
;
70 notice
.z_recipient
= "";
71 notice
.z_num_other_fields
= 0;
72 notice
.z_default_format
= format
;
75 keep track of what we said before so that we can be consistent
76 when changing location information.
77 This is done mainly for the sake of the WindowGram client.
81 if (gethostname(host
, MAXHOSTNAMELEN
) < 0)
84 hent
= gethostbyname(host
);
86 (void) strncpy(host
, hent
->h_name
, sizeof(host
));
87 host
[sizeof(host
) - 1] = '\0';
89 #ifndef X_DISPLAY_MISSING
90 if ((display
= getenv("DISPLAY")) && *display
) {
91 mytty
= g_strdup(display
);
95 mytty
= g_strdup("WinPurple");
99 p
= strchr(ttyp
+ 1, '/');
100 mytty
= g_strdup((p
) ? p
+ 1 : ttyp
);
102 mytty
= g_strdup("unknown");
105 #ifndef X_DISPLAY_MISSING
111 ourtime
= time((time_t *)0);
113 bptr
[1] = ctime(&ourtime
);
114 bptr
[1][strlen(bptr
[1])-1] = '\0';
117 if ((retval
= ZSendList(¬ice
, bptr
, 3, auth
)) != ZERR_NONE
)
120 retval
= Z_WaitForNotice (&retnotice
, ZCompareUIDPred
, ¬ice
.z_uid
,
122 if (retval
!= ZERR_NONE
)
125 if (retnotice
.z_kind
== SERVNAK
) {
126 if (!retnotice
.z_message_len
) {
127 ZFreeNotice(&retnotice
);
128 return (ZERR_SERVNAK
);
130 if (!strcmp(retnotice
.z_message
, ZSRVACK_NOTSENT
)) {
131 ZFreeNotice(&retnotice
);
132 return (ZERR_AUTHFAIL
);
134 if (!strcmp(retnotice
.z_message
, ZSRVACK_FAIL
)) {
135 ZFreeNotice(&retnotice
);
136 return (ZERR_LOGINFAIL
);
138 ZFreeNotice(&retnotice
);
139 return (ZERR_SERVNAK
);
142 if (retnotice
.z_kind
!= SERVACK
) {
143 ZFreeNotice(&retnotice
);
144 return (ZERR_INTERNAL
);
147 if (!retnotice
.z_message_len
) {
148 ZFreeNotice(&retnotice
);
149 return (ZERR_INTERNAL
);
152 if (strcmp(retnotice
.z_message
, ZSRVACK_SENT
) &&
153 strcmp(retnotice
.z_message
, ZSRVACK_NOTSENT
)) {
154 ZFreeNotice(&retnotice
);
155 return (ZERR_INTERNAL
);
158 ZFreeNotice(&retnotice
);