diff options
author | John Kohl <jtkohl@mit.edu> | 1988-06-15 18:33:10 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1988-06-15 18:33:10 +0000 |
commit | e07b8f5aea2ae9f315121b7c9b351253f1664ae3 (patch) | |
tree | da72f48dd469b07b4f240a15d7f6321d355360cb /lib | |
parent | 8c1a94e50b704d9420941ea70fc9e348fbe2911c (diff) |
new style location
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ZLocateU.c | 100 |
1 files changed, 55 insertions, 45 deletions
diff --git a/lib/ZLocateU.c b/lib/ZLocateU.c index 57af9a5..a8d439d 100644 --- a/lib/ZLocateU.c +++ b/lib/ZLocateU.c @@ -24,10 +24,10 @@ Code_t ZLocateUser(user, nlocs) char *user; int *nlocs; { - int i, retval; + register int i, retval; ZNotice_t notice, retnotice; char *ptr, *end; - + int nrecv, ack; retval = ZFlushLocations(); if (retval != ZERR_NONE && retval != ZERR_NOLOCATIONS) @@ -46,58 +46,68 @@ Code_t ZLocateUser(user, nlocs) if ((retval = ZSendNotice(¬ice, ZAUTH)) != ZERR_NONE) return (retval); - if ((retval = ZIfNotice(&retnotice, NULL, ZCompareUIDPred, - (char *)¬ice.z_uid)) != ZERR_NONE) - return (retval); + nrecv = ack = 0; - if (retnotice.z_kind == SERVNAK) { - ZFreeNotice(&retnotice); - return (ZERR_SERVNAK); - } - - if (retnotice.z_kind != SERVACK) { - ZFreeNotice(&retnotice); - return (ZERR_INTERNAL); - } + while (!nrecv || !ack) { + if ((retval = ZIfNotice(&retnotice, NULL, ZCompareUIDPred, + (char *)¬ice.z_uid)) != ZERR_NONE) + return (retval); + + if (retnotice.z_kind == SERVNAK) { + ZFreeNotice(&retnotice); + return (ZERR_SERVNAK); + } + if (retnotice.z_kind == SERVACK && + !strcmp(retnotice.z_opcode,LOCATE_LOCATE)) { + ack = 1; + continue; + } - end = retnotice.z_message+retnotice.z_message_len; + if (retnotice.z_kind != ACKED) { + ZFreeNotice(&retnotice); + return (ZERR_INTERNAL); + } + nrecv++; - __locate_num = 0; + end = retnotice.z_message+retnotice.z_message_len; + + __locate_num = 0; - for (ptr=retnotice.z_message;ptr<end;ptr++) - if (!*ptr) - __locate_num++; + for (ptr=retnotice.z_message;ptr<end;ptr++) + if (!*ptr) + __locate_num++; - __locate_num /= 3; + __locate_num /= 3; - __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num* - sizeof(ZLocations_t)); - if (!__locate_list) - return (ENOMEM); + __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num* + sizeof(ZLocations_t)); + if (!__locate_list) + return (ENOMEM); - for (ptr=retnotice.z_message, i=0;i<__locate_num;i++) { - __locate_list[i].host = (char *)malloc((unsigned)strlen(ptr)+ - 1); - if (!__locate_list[i].host) - return (ENOMEM); - (void) strcpy(__locate_list[i].host, ptr); - ptr += strlen(ptr)+1; - __locate_list[i].time = (char *)malloc((unsigned)strlen(ptr)+ - 1); - if (!__locate_list[i].time) - return (ENOMEM); - (void) strcpy(__locate_list[i].time, ptr); - ptr += strlen(ptr)+1; - __locate_list[i].tty = (char *)malloc((unsigned)strlen(ptr)+ - 1); - if (!__locate_list[i].tty) - return (ENOMEM); - (void) strcpy(__locate_list[i].tty, ptr); - ptr += strlen(ptr)+1; + for (ptr=retnotice.z_message, i=0;i<__locate_num;i++) { + __locate_list[i].host = (char *) + malloc((unsigned)strlen(ptr)+1); + if (!__locate_list[i].host) + return (ENOMEM); + (void) strcpy(__locate_list[i].host, ptr); + ptr += strlen(ptr)+1; + __locate_list[i].time = (char *) + malloc((unsigned)strlen(ptr)+1); + if (!__locate_list[i].time) + return (ENOMEM); + (void) strcpy(__locate_list[i].time, ptr); + ptr += strlen(ptr)+1; + __locate_list[i].tty = (char *) + malloc((unsigned)strlen(ptr)+1); + if (!__locate_list[i].tty) + return (ENOMEM); + (void) strcpy(__locate_list[i].tty, ptr); + ptr += strlen(ptr)+1; + } + + ZFreeNotice(&retnotice); } - ZFreeNotice(&retnotice); - __locate_next = 0; *nlocs = __locate_num; |