summaryrefslogtreecommitdiff
path: root/lib/ZLocations.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ZLocations.c')
-rw-r--r--lib/ZLocations.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/lib/ZLocations.c b/lib/ZLocations.c
index 7701a8d..a0a2d4f 100644
--- a/lib/ZLocations.c
+++ b/lib/ZLocations.c
@@ -18,17 +18,43 @@ static char rcsid_ZLocations_c[] =
"$Zephyr: /afs/athena.mit.edu/astaff/project/zephyr/src/lib/RCS/ZLocations.c,v 1.30 90/12/20 03:04:39 raeburn Exp $";
#endif
-#include <zephyr/mit-copyright.h>
-
-#include <zephyr/zephyr_internal.h>
+#include <internal.h>
#include <pwd.h>
-#include <sys/file.h>
-#include <sys/param.h>
-#include <netdb.h>
-extern char *getenv();
-extern int errno;
+static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN];
+static int location_info_set = 0;
+
+Code_t ZInitLocationInfo(hostname, tty)
+ char *hostname;
+ char *tty;
+{
+ char *ttyp, *p;
+ struct hostent *hent;
+
+ if (hostname) {
+ strcpy(host, hostname);
+ } else {
+ if (gethostname(host, MAXHOSTNAMELEN) < 0)
+ return (errno);
+ hent = gethostbyname(host);
+ if (hent)
+ (void) strcpy(host, hent->h_name);
+ }
+ if (tty) {
+ strcpy(mytty, tty);
+ } else {
+ ttyp = ttyname(0);
+ if (ttyp) {
+ p = strrchr(ttyp, '/');
+ strcpy(mytty, (p) ? p + 1 : ttyp);
+ } else {
+ strcpy(mytty, "unknown");
+ }
+ }
+ location_info_set = 1;
+ return (ZERR_NONE);
+}
Code_t ZSetLocation(exposure)
char *exposure;
@@ -48,29 +74,42 @@ Code_t ZFlushMyLocations()
return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
}
-static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN];
-static int reenter = 0;
+char *ZParseExposureLevel(text)
+ char *text;
+{
+ if (!strcasecmp(text, EXPOSE_NONE))
+ return (EXPOSE_NONE);
+ else if (!strcasecmp(text, EXPOSE_OPSTAFF))
+ return (EXPOSE_OPSTAFF);
+ else if (!strcasecmp(text, EXPOSE_REALMVIS))
+ return (EXPOSE_REALMVIS);
+ else if (!strcasecmp(text, EXPOSE_REALMANN))
+ return (EXPOSE_REALMANN);
+ else if (!strcasecmp(text, EXPOSE_NETVIS))
+ return (EXPOSE_NETVIS);
+ else if (!strcasecmp(text, EXPOSE_NETANN))
+ return (EXPOSE_NETANN);
+ else
+ return(NULL);
+}
-Z_SendLocation(class, opcode, auth, format)
+Code_t Z_SendLocation(class, opcode, auth, format)
char *class;
char *opcode;
- int (*auth)();
+ Z_AuthProc auth;
char *format;
{
- char *ttyname(), *ctime();
-
int retval;
- long ourtime;
+ time_t ourtime;
ZNotice_t notice, retnotice;
char *bptr[3];
-#ifdef X11
- char *display;
-#endif /* X11 */
- char *ttyp;
struct hostent *hent;
short wg_port = ZGetWGPort();
- (void) memset((char *)&notice, 0, sizeof(notice));
+ if (!location_info_set)
+ ZInitLocationInfo(NULL, NULL);
+
+ memset((char *)&notice, 0, sizeof(notice));
notice.z_kind = ACKED;
notice.z_port = (u_short) ((wg_port == -1) ? 0 : wg_port);
notice.z_class = class;
@@ -81,51 +120,12 @@ Z_SendLocation(class, opcode, auth, format)
notice.z_num_other_fields = 0;
notice.z_default_format = format;
- /*
- keep track of what we said before so that we can be consistent
- when changing location information.
- This is done mainly for the sake of the WindowGram client.
- */
-
- if (!reenter) {
- if (gethostname(host, MAXHOSTNAMELEN) < 0)
- return (errno);
-
- hent = gethostbyname(host);
- if (hent)
- (void) strcpy(host, hent->h_name);
- bptr[0] = host;
-#ifdef X11
- if ((display = getenv("DISPLAY")) && *display) {
- (void) strcpy(mytty, display);
- bptr[2] = mytty;
- } else {
-#endif /* X11 */
- ttyp = ttyname(0);
- if (ttyp) {
- bptr[2] = strrchr(ttyp, '/');
- if (bptr[2])
- bptr[2]++;
- else
- bptr[2] = ttyp;
- }
- else
- bptr[2] = "unknown";
- (void) strcpy(mytty, bptr[2]);
-#ifdef X11
- }
-#endif /* X11 */
- reenter = 1;
- } else {
- bptr[0] = host;
- bptr[2] = mytty;
- }
-
- ourtime = time((long *)0);
+ bptr[0] = host;
+ ourtime = time((time_t *)0);
bptr[1] = ctime(&ourtime);
bptr[1][strlen(bptr[1])-1] = '\0';
+ bptr[2] = mytty;
-
if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
return (retval);