home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / uuconf.subproj / tlocnm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  3.0 KB  |  113 lines

  1. /* tlocnm.c
  2.    Get the local name to use from the Taylor UUCP configuration files.
  3.  
  4.    Copyright (C) 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP uuconf library.
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public License
  10.    as published by the Free Software Foundation; either version 2 of
  11.    the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucnfi.h"
  27.  
  28. #if USE_RCS_ID
  29. const char _uuconf_tlocnm_rcsid[] = "$Id: tlocnm.c,v 1.6 1995/06/21 19:24:45 ian Rel $";
  30. #endif
  31.  
  32. #include <errno.h>
  33.  
  34. /* Get the local name to use, based on the login name, from the Taylor
  35.    UUCP configuration files.  This could probably be done in a
  36.    slightly more intelligent fashion, but no matter what it has to
  37.    read the systems files.  */
  38.  
  39. int
  40. uuconf_taylor_login_localname (pglobal, zlogin, pzname)
  41.      pointer pglobal;
  42.      const char *zlogin;
  43.      char **pzname;
  44. {
  45.   struct sglobal *qglobal = (struct sglobal *) pglobal;
  46.   char **pznames, **pz;
  47.   int iret;
  48.  
  49.   if (! qglobal->qprocess->fread_syslocs)
  50.     {
  51.       iret = _uuconf_iread_locations (qglobal);
  52.       if (iret != UUCONF_SUCCESS)
  53.     return iret;
  54.     }
  55.  
  56.   /* As a simple optimization, if there is no "myname" command we can
  57.      simply return immediately.  */
  58.   if (! qglobal->qprocess->fuses_myname)
  59.     {
  60.       *pzname = NULL;
  61.       return UUCONF_NOT_FOUND;
  62.     }
  63.  
  64.   iret = uuconf_taylor_system_names (pglobal, &pznames, 0);
  65.   if (iret != UUCONF_SUCCESS)
  66.     return iret;
  67.  
  68.   *pzname = NULL;
  69.   iret = UUCONF_NOT_FOUND;
  70.  
  71.   for (pz = pznames; *pz != NULL; pz++)
  72.     {
  73.       struct uuconf_system ssys;
  74.       struct uuconf_system *qsys;
  75.  
  76.       iret = uuconf_system_info (pglobal, *pz, &ssys);
  77.       if (iret != UUCONF_SUCCESS)
  78.     break;
  79.  
  80.       for (qsys = &ssys; qsys != NULL; qsys = qsys->uuconf_qalternate)
  81.     {
  82.       if (qsys->uuconf_zlocalname != NULL
  83.           && qsys->uuconf_fcalled
  84.           && qsys->uuconf_zcalled_login != NULL
  85.           && strcmp (qsys->uuconf_zcalled_login, zlogin) == 0)
  86.         {
  87.           *pzname = strdup (qsys->uuconf_zlocalname);
  88.           if (*pzname != NULL)
  89.         iret = UUCONF_SUCCESS;
  90.           else
  91.         {
  92.           qglobal->ierrno = errno;
  93.           iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
  94.         }
  95.           break;
  96.         }
  97.     }
  98.  
  99.       (void) uuconf_system_free (pglobal, &ssys);
  100.  
  101.       if (qsys != NULL)
  102.     break;
  103.  
  104.       iret = UUCONF_NOT_FOUND;
  105.     }
  106.  
  107.   for (pz = pznames; *pz != NULL; pz++)
  108.     free ((pointer) *pz);
  109.   free ((pointer) pznames);
  110.  
  111.   return iret;
  112. }
  113.