|
|
1.1 ! root 1: /* tdial.c ! 2: Find a dialer in 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! 21: ! 22: The author of the program may be contacted at [email protected] or ! 23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254. ! 24: */ ! 25: ! 26: #include "uucnfi.h" ! 27: ! 28: #if USE_RCS_ID ! 29: const char _uuconf_tdial_rcsid[] = "$Id: tdial.c,v 1.1 93/07/30 08:07:40 bin Exp Locker: bin $"; ! 30: #endif ! 31: ! 32: #include <errno.h> ! 33: ! 34: static int iddialer P((pointer pglobal, int argc, char **argv, pointer pvar, ! 35: pointer pinfo)); ! 36: static int idunknown P((pointer pglobal, int argc, char **argv, pointer pvar, ! 37: pointer pinfo)); ! 38: ! 39: /* Find a dialer in the Taylor UUCP configuration files by name. */ ! 40: ! 41: int ! 42: uuconf_taylor_dialer_info (pglobal, zname, qdialer) ! 43: pointer pglobal; ! 44: const char *zname; ! 45: struct uuconf_dialer *qdialer; ! 46: { ! 47: struct sglobal *qglobal = (struct sglobal *) pglobal; ! 48: FILE *e; ! 49: pointer pblock; ! 50: int iret; ! 51: char **pz; ! 52: ! 53: e = NULL; ! 54: pblock = NULL; ! 55: iret = UUCONF_NOT_FOUND; ! 56: ! 57: for (pz = qglobal->qprocess->pzdialfiles; *pz != NULL; pz++) ! 58: { ! 59: struct uuconf_cmdtab as[2]; ! 60: char *zdialer; ! 61: struct uuconf_dialer sdefault; ! 62: int ilineno; ! 63: ! 64: e = fopen (*pz, "r"); ! 65: if (e == NULL) ! 66: { ! 67: if (FNO_SUCH_FILE ()) ! 68: continue; ! 69: qglobal->ierrno = errno; ! 70: iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO; ! 71: break; ! 72: } ! 73: ! 74: qglobal->ilineno = 0; ! 75: ! 76: /* Gather the default information from the top of the file. We ! 77: do this by handling the "dialer" command ourselves and ! 78: passing every other command to _uuconf_idialer_cmd via ! 79: idunknown. The value of zdialer will be an malloc block. */ ! 80: as[0].uuconf_zcmd = "dialer"; ! 81: as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2; ! 82: as[0].uuconf_pvar = (pointer) &zdialer; ! 83: as[0].uuconf_pifn = iddialer; ! 84: ! 85: as[1].uuconf_zcmd = NULL; ! 86: ! 87: pblock = uuconf_malloc_block (); ! 88: if (pblock == NULL) ! 89: { ! 90: qglobal->ierrno = errno; ! 91: iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO; ! 92: break; ! 93: } ! 94: ! 95: _uuconf_uclear_dialer (&sdefault); ! 96: sdefault.uuconf_palloc = pblock; ! 97: zdialer = NULL; ! 98: iret = uuconf_cmd_file (pglobal, e, as, (pointer) &sdefault, ! 99: idunknown, UUCONF_CMDTABFLAG_BACKSLASH, ! 100: pblock); ! 101: ! 102: /* Now skip until we find a dialer with a matching name. */ ! 103: while (iret == UUCONF_SUCCESS ! 104: && zdialer != NULL ! 105: && strcmp (zname, zdialer) != 0) ! 106: { ! 107: free ((pointer) zdialer); ! 108: zdialer = NULL; ! 109: ilineno = qglobal->ilineno; ! 110: iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL, ! 111: (uuconf_cmdtabfn) NULL, ! 112: UUCONF_CMDTABFLAG_BACKSLASH, ! 113: pblock); ! 114: qglobal->ilineno += ilineno; ! 115: } ! 116: ! 117: if (iret != UUCONF_SUCCESS) ! 118: { ! 119: if (zdialer != NULL) ! 120: free ((pointer) zdialer); ! 121: break; ! 122: } ! 123: ! 124: if (zdialer != NULL) ! 125: { ! 126: size_t csize; ! 127: ! 128: /* We've found the dialer we're looking for. Read the rest ! 129: of the commands for it. */ ! 130: as[0].uuconf_pvar = NULL; ! 131: ! 132: *qdialer = sdefault; ! 133: csize = strlen (zdialer) + 1; ! 134: qdialer->uuconf_zname = uuconf_malloc (pblock, csize); ! 135: if (qdialer->uuconf_zname == NULL) ! 136: { ! 137: qglobal->ierrno = errno; ! 138: free ((pointer) zdialer); ! 139: iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO; ! 140: break; ! 141: } ! 142: memcpy ((pointer) qdialer->uuconf_zname, (pointer) zdialer, ! 143: csize); ! 144: free ((pointer) zdialer); ! 145: ! 146: ilineno = qglobal->ilineno; ! 147: iret = uuconf_cmd_file (pglobal, e, as, qdialer, idunknown, ! 148: UUCONF_CMDTABFLAG_BACKSLASH, pblock); ! 149: qglobal->ilineno += ilineno; ! 150: break; ! 151: } ! 152: ! 153: (void) fclose (e); ! 154: e = NULL; ! 155: uuconf_free_block (pblock); ! 156: pblock = NULL; ! 157: ! 158: iret = UUCONF_NOT_FOUND; ! 159: } ! 160: ! 161: if (e != NULL) ! 162: (void) fclose (e); ! 163: if (iret != UUCONF_SUCCESS && pblock != NULL) ! 164: uuconf_free_block (pblock); ! 165: ! 166: if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND) ! 167: { ! 168: qglobal->zfilename = *pz; ! 169: iret |= UUCONF_ERROR_FILENAME; ! 170: } ! 171: ! 172: return iret; ! 173: } ! 174: ! 175: /* Handle a "dialer" command. This copies the string onto the heap ! 176: and returns the pointer in *pvar, unless pvar is NULL. It returns ! 177: UUCONF_CMDTABRET_EXIT to force _uuconf_icmd_file_internal to stop ! 178: reading and return to the code above, which will then check the ! 179: dialer name just read to see if it matches. */ ! 180: ! 181: /*ARGSUSED*/ ! 182: static int ! 183: iddialer (pglobal, argc, argv, pvar, pinfo) ! 184: pointer pglobal; ! 185: int argc; ! 186: char **argv; ! 187: pointer pvar; ! 188: pointer pinfo; ! 189: { ! 190: struct sglobal *qglobal = (struct sglobal *) pglobal; ! 191: char **pz = (char **) pvar; ! 192: ! 193: if (pz != NULL) ! 194: { ! 195: size_t csize; ! 196: ! 197: csize = strlen (argv[1]) + 1; ! 198: *pz = malloc (csize); ! 199: if (*pz == NULL) ! 200: { ! 201: qglobal->ierrno = errno; ! 202: return (UUCONF_MALLOC_FAILED ! 203: | UUCONF_ERROR_ERRNO ! 204: | UUCONF_CMDTABRET_EXIT); ! 205: } ! 206: memcpy ((pointer) *pz, (pointer) argv[1], csize); ! 207: } ! 208: return UUCONF_CMDTABRET_EXIT; ! 209: } ! 210: ! 211: /* Handle an unknown command by passing it on to _uuconf_idialer_cmd, ! 212: which will parse it into the dialer structure. */ ! 213: ! 214: /*ARGSUSED*/ ! 215: static int ! 216: idunknown (pglobal, argc, argv, pvar, pinfo) ! 217: pointer pglobal; ! 218: int argc; ! 219: char **argv; ! 220: pointer pvar; ! 221: pointer pinfo; ! 222: { ! 223: struct sglobal *qglobal = (struct sglobal *) pglobal; ! 224: struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo; ! 225: ! 226: return _uuconf_idialer_cmd (qglobal, argc, argv, qdialer); ! 227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.