summaryrefslogtreecommitdiff
path: root/lib/ZLocations.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
commit031ec0f258f152c1e20905b381aa7f5974db1f3d (patch)
tree1c15619ec8a5192e2d5095c6efde5e9a47ddc7ce /lib/ZLocations.c
parent4d21b4b5da809cdf4499190a1e27bff679a90422 (diff)
All sorts of changes for ver 0.2
Diffstat (limited to 'lib/ZLocations.c')
-rw-r--r--lib/ZLocations.c173
1 files changed, 97 insertions, 76 deletions
diff --git a/lib/ZLocations.c b/lib/ZLocations.c
index 7baf4d3..ebb5081 100644
--- a/lib/ZLocations.c
+++ b/lib/ZLocations.c
@@ -29,97 +29,118 @@ static char rcsid_ZLocations_c[] = "$Header$";
uid_t getuid();
Code_t ZSetLocation(exposure)
- char *exposure;
+ char *exposure;
{
- return (Z_SendLocation(LOGIN_CLASS,exposure,ZAUTH,
- "$sender logged in to $1 on $3 at $2"));
+ return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH,
+ "$sender logged in to $1 on $3 at $2"));
}
Code_t ZUnsetLocation()
{
- return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_LOGOUT,ZNOAUTH,
- "$sender logged out of $1 on $3 at $2"));
+ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH,
+ "$sender logged out of $1 on $3 at $2"));
}
Code_t ZFlushMyLocations()
{
- return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_FLUSH,ZAUTH,""));
+ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
}
-Z_SendLocation(class,opcode,auth,format)
- char *class;
- char *opcode;
- int (*auth)();
- char *format;
+Z_SendLocation(class, opcode, auth, format)
+ char *class;
+ char *opcode;
+ int (*auth)();
+ char *format;
{
- char *ttyname(),*ctime();
-
- int retval;
- long ourtime;
- ZNotice_t notice,retnotice;
- ZPacket_t buffer;
- char *bptr[3],host[MAXHOSTNAMELEN],mytty[100];
- struct hostent *hent;
-
- notice.z_kind = ACKED;
- notice.z_port = 0;
- notice.z_class = class;
- notice.z_class_inst = ZGetSender();
- notice.z_opcode = opcode;
- notice.z_sender = 0;
- notice.z_recipient = "";
- notice.z_default_format = format;
-
- if (gethostname(host,MAXHOSTNAMELEN) < 0)
- return (errno);
-
- hent = gethostbyname(host);
- if (!hent)
- bptr[0] = "unknown";
- else {
- (void) strcpy(host,hent->h_name);
- bptr[0] = host;
- }
-
- ourtime = time((long *)0);
- bptr[1] = ctime(&ourtime);
- bptr[1][strlen(bptr[1])-1] = '\0';
-
- (void) strcpy(mytty,ttyname(0));
- bptr[2] = rindex(mytty,'/');
+ char *ttyname(), *ctime();
+
+ int retval;
+ long ourtime;
+ ZNotice_t notice, retnotice;
+ char *bptr[3], host[MAXHOSTNAMELEN], mytty[MAXHOSTNAMELEN];
+ char *display;
+ struct hostent *hent;
+
+ notice.z_kind = ACKED;
+ notice.z_port = 0;
+ notice.z_class = class;
+ notice.z_class_inst = ZGetSender();
+ notice.z_opcode = opcode;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_num_other_fields = 0;
+ notice.z_default_format = format;
+
+ if (gethostname(host, MAXHOSTNAMELEN) < 0)
+ return (errno);
+
+ hent = gethostbyname(host);
+ if (!hent)
+ bptr[0] = "unknown";
+ else {
+ (void) strcpy(host, hent->h_name);
+ bptr[0] = host;
+ }
+
+ ourtime = time((long *)0);
+ bptr[1] = ctime(&ourtime);
+ bptr[1][strlen(bptr[1])-1] = '\0';
+
+ if ((display = (char *)getenv("DISPLAY")) && *display) {
+ strcpy(mytty, display);
+ bptr[2] = mytty;
+ }
+ else {
+ (void) strcpy(mytty, ttyname(0));
+ bptr[2] = rindex(mytty, '/');
if (bptr[2])
- bptr[2]++;
+ bptr[2]++;
else
- bptr[2] = mytty;
+ bptr[2] = mytty;
+ }
- if ((retval = ZSendList(&notice,bptr,3,auth)) != ZERR_NONE)
- return (retval);
-
- if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,
- (struct sockaddr_in *)0,
- ZCompareUIDPred,(char *)&notice.z_uid)) !=
- ZERR_NONE)
- return (retval);
-
- if (retnotice.z_kind == SERVNAK) {
- if (!retnotice.z_message_len)
- return (ZERR_SERVNAK);
- if (!strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
- return (ZERR_AUTHFAIL);
- if (!strcmp(retnotice.z_message,ZSRVACK_FAIL))
- return (ZERR_LOGINFAIL);
- return (ZERR_SERVNAK);
- }
+ if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
+ return (retval);
+
+ if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
+ ZCompareUIDPred, (char *)&notice.z_uid)) !=
+ ZERR_NONE)
+ return (retval);
+
+ if (retnotice.z_kind == SERVNAK) {
+ if (!retnotice.z_message_len) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_SERVNAK);
+ }
+ if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_AUTHFAIL);
+ }
+ if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_LOGINFAIL);
+ }
+ ZFreeNotice(&retnotice);
+ return (ZERR_SERVNAK);
+ }
- if (retnotice.z_kind != SERVACK)
- return (ZERR_INTERNAL);
-
- if (!retnotice.z_message_len)
- return (ZERR_INTERNAL);
-
- if (strcmp(retnotice.z_message,ZSRVACK_SENT) &&
- strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
- return (ZERR_INTERNAL);
+ if (retnotice.z_kind != SERVACK) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ if (!retnotice.z_message_len) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ if (strcmp(retnotice.z_message, ZSRVACK_SENT) &&
+ strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ ZFreeNotice(&retnotice);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}