Changeset dca3b27


Ignore:
Timestamp:
Oct 7, 2009, 5:05:57 PM (15 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
77c87b2
Parents:
6c171f1
git-author:
Karl Ramm <kcr@1ts.org> (09/23/09 10:51:42)
git-committer:
Karl Ramm <kcr@1ts.org> (10/07/09 17:05:57)
Message:
Make owl_zephyr_zlocate return a dynamically allocated result

(and cleanup it and owl_function_zlocate)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r340c3e7 rdca3b27  
    19411941{
    19421942  owl_fmtext fm;
    1943   char *ptr, buff[LINE];
     1943  char *ptr;
     1944  char *result;
    19441945  int i;
    19451946
     
    19471948
    19481949  for (i=0; i<argc; i++) {
    1949     ptr=long_zuser(argv[i]);
    1950     owl_zephyr_zlocate(ptr, buff, auth);
    1951     owl_fmtext_append_normal(&fm, buff);
     1950    ptr = long_zuser(argv[i]);
     1951    result = owl_zephyr_zlocate(ptr, auth);
     1952    owl_fmtext_append_normal(&fm, result);
     1953    owl_free(result);
    19521954    owl_free(ptr);
    19531955  }
  • zephyr.c

    rc79a047 rdca3b27  
    911911#endif
    912912
    913 void owl_zephyr_zlocate(const char *user, char *out, int auth)
     913char *owl_zephyr_zlocate(const char *user, int auth)
    914914{
    915915#ifdef HAVE_LIBZEPHYR
     
    918918  ZLocations_t locations;
    919919  char *myuser;
    920  
    921   strcpy(out, "");
     920  char *p, *result;
     921
    922922  ZResetAuthentication();
    923   ret=ZLocateUser(zstr(user),&numlocs,auth?ZAUTH:ZNOAUTH);
    924   if (ret != ZERR_NONE) {
    925     sprintf(out, "Error locating user %s\n", user);
    926     return;
    927   }
    928 
    929   if (numlocs==0) {
    930     myuser=short_zuser(user);
    931     sprintf(out, "%s: Hidden or not logged in\n", myuser);
    932     owl_free(myuser);
    933     return;
    934   }
    935    
    936   for (;numlocs;numlocs--) {
    937     ZGetLocations(&locations,&one);
    938     myuser=short_zuser(user);
    939     sprintf(out + strlen(out), "%s: %s\t%s\t%s\n", myuser,
    940             locations.host ? locations.host : "?",
    941             locations.tty ? locations.tty : "?",
    942             locations.time ? locations.time : "?");
    943     owl_free(myuser);
    944   }
     923  ret = ZLocateUser(zstr(user), &numlocs, auth ? ZAUTH : ZNOAUTH);
     924  if (ret != ZERR_NONE)
     925    return owl_sprintf("Error locating user %s: %s\n",
     926                       user, error_message(ret));
     927
     928  myuser = short_zuser(user);
     929  if (numlocs == 0) {
     930    result = owl_sprintf("%s: Hidden or not logged in\n", myuser);
     931  } else {
     932    result = owl_strdup("");
     933    for (; numlocs; numlocs--) {
     934      ZGetLocations(&locations, &one);
     935      p = owl_sprintf("%s%s: %s\t%s\t%s\n",
     936                          result, myuser,
     937                          locations.host ? locations.host : "?",
     938                          locations.tty ? locations.tty : "?",
     939                          locations.time ? locations.time : "?");
     940      owl_free(result);
     941      result = p;
     942    }
     943  }
     944
     945  return result;
     946#else
     947  return owl_strdup("");
    945948#endif
    946949}
Note: See TracChangeset for help on using the changeset viewer.