# 2.11BSD#431 - /usr/src/new/notes/src/parsepath.c

##### Functions

    parsepath         X

##### Variables

    authname          X
    fromsys           X
    origsys           X

       1: #include "parms.h"
       2: #include "structs.h"
       3: #include "newsgate.h"
       4:
       5: #ifdef  RCSIDENT
       6: static char rcsid[] = "$Header: parsepath.c,v 1.7.0.3 85/11/29 12:18:43 notes Rel $";
       7: #endif	RCSIDENT
       8:
       9: /*
      10:  *	Parse the supplied path and from lines to determine the
      11:  *	address of the sender.  Look at the "from" line first
      12:  *	to see if it contains a pure domain-style address. If so,
      13:  *	use that for origsys and authname. Otherwise, fall into
      14:  *	intuiting it from the "newspath" argument.
      15:  *
      16:  *	newsinput calls this with header.path and header.from as
      17:  *	args.  nfmail calls it with from and (null) as args.
      18:  *
      19:  *
      20:  * fromsys:	contains system that sent us the article.
      21:  *		this helps us avoid sending unnecessary copies
      22:  *		of the article over the net.
      23:  *
      24:  * origsys:	contains the system name of the author.  Note
      25:  *		that for mailing lists gatewayed to news, this
      26:  *		is not the same as the host in the article-ID.
      27:  *
      28:  *	Thanks to Lou Salkind for this code.
      29:  */
      30:
      31: char    fromsys[SYSSZ + 1];             /* gave it to us */
      32: char    origsys[SYSSZ + 1];             /* started here */
      33: char    authname[NAMESZ + 1];               /* author */
      34:
      35: parsepath (newspath, fromline)
      36: char   *newspath;
      37: char   *fromline;
      38: {
      39:     register int    i,
      40:                     j,
      41:                     c;
      42:     register char  *p,
      43:                    *q;
      44:     char    line[CMDLEN];
      45:     char    strippedline[CMDLEN];
      46:     int     gotname = 0;                /* not yet */
      47:
      48:     if (fromline != (char *) NULL && fromline[0] != '\0')
      49:     {                           /* pure domain exists */
      50:     strcpy (line, fromline);            /* hackable copy */
      51:     if ((p = index (line, '<')) != (char *) NULL)   /* get it */
      52:     {
      53:         if ((q = index (p, '>')) == (char *) NULL)  /* malformed */
      54:         goto usepath;
      55:         *q = '\0';                  /* truncate */
      56:         strcpy (strippedline, ++p);         /* and save */
      57:     }
      58:     else
      59:     {
      60:         int     incomment;
      61:
      62:         p = line;                   /* from start */
      63:         while (*p == ' ' || *p == '\t')
      64:         p++;                    /* leading trash */
      65:
      66:         incomment = 0;
      67:         q = p;
      68:         p = strippedline;
      69:         while (*q != '\0')
      70:         {
      71:         if (incomment > 0 && *q == ')')     /* end comment */
      72:         {
      73:             incomment--;
      74:             q++;
      75:             continue;
      76:         }
      77:         if (incomment > 0)          /* ignore char */
      78:         {
      79:             q++;
      80:             continue;
      81:         }
      82:         if (*q == '(')              /* start comment */
      83:         {
      84:             incomment++;
      85:             ++q;
      86:             continue;
      87:         }
      88:         if (*q == ' ' || *q == '\n' || *q == '\t')/* end of addr */
      89:             break;
      90:         *p++ = *q++;                /* on to next */
      91:         }
      92:         *p = '\0';                  /* terminate */
      93:
      94:     }
      95:     if ((p = index (strippedline, '@')) == (char *) NULL)
      96:         goto usepath;
      97:     *p++ = '\0';                    /* split them */
      98:     strncpy (authname, strippedline, NAMESZ);
      99:     authname[NAMESZ - 1] = '\0';            /* truncate */
     100:     strncpy (origsys, p, HOMESYSSZ);
     101:     origsys[HOMESYSSZ - 1] = '\0';          /* truncate */
     102:     /*
     103: 	 * check to see we got something
     104: 	 */
     105:     if (strlen (authname) > 0)          /* could be null */
     106:         gotname++;                  /* mark as plucked */
     107:     }
     108:     /*
     109:      * Determine user and the real originating system.
     110:      * Tuned for B news 2.10
     111:      */
     112: usepath:                        /* fall through from above */
     113:     strcpy (line, newspath);
     114:     for (i = 0; line[i]; i++)               /* find string end */
     115:     if (line[i] == ' ' || line[i] == '\t' || line[i] == '\n')
     116:     {
     117:         line[i] = '\0';
     118:         break;
     119:     }
     120:     i--;
     121:
     122:     /*
     123:      * Try and parse an author if we don't already have one
     124:      */
     125:     if (!gotname)
     126:     {
     127:     for (j = i; j > 0; j--)             /* find delimiter */
     128:         if (line[j] == '@' || line[j] == '!' || line[j] == ':')
     129:         break;
     130:     if (j <= 0)
     131:     {                       /* user */
     132:         for (i = 0; i < (NAMESZ - 1); i++)
     133:         {
     134:         if ((c = line[i]) == '\0')
     135:             break;
     136:         authname[i] = c;
     137:         }
     138:         authname[i] = '\0';
     139:     }
     140:     else
     141:         if (line[j] == '@')
     142:         {                       /* user@host */
     143:         int     atcount = j;
     144:
     145:         line[atcount] = '\0';           /* drop uucp route */
     146:         for (i = atcount - 1; i > 0; i--)
     147:         {
     148:             if (line[i] == '!' || line[i] == ':')
     149:             {
     150:             i++;
     151:             break;
     152:             }
     153:         }
     154:         j = i;                  /* copy user */
     155:         for (i = 0; i < (NAMESZ - 1); i++)
     156:         {
     157:             if ((c = line[j + i]) == '\0')
     158:             break;
     159:             authname[i] = c;
     160:         }
     161:         authname[i] = '\0';
     162:         j = atcount + 1;            /* copy origsys */
     163:         for (i = 0; i < (SYSSZ - 1); i++)
     164:         {
     165:             if ((c = line[j + i]) == '\0')
     166:             break;
     167: #ifdef  notdef
     168:             /*
     169: 		     * (no longer needed....)
     170: 		     * TEMPORARY KLUDGE...
     171: 		     * throw out domain part until host
     172: 		     * name length increased
     173: 		     */
     174:             if (c == '.')
     175:             break;
     176: #endif	notdef
     177:             origsys[i] = c;
     178:         }
     179:         origsys[i] = '\0';
     180:         }
     181:         else
     182:         {                       /* host!user */
     183:         int     delim = j;
     184:         char    sepchar = line[delim];      /* save delimiter */
     185:
     186:         line[delim] = '\0';         /* drop uucp route */
     187:         for (i = delim - 1; i > 0; i--)
     188:         {
     189:             if (line[i] == '!' || line[i] == ':')
     190:             {
     191:             i++;
     192:             break;
     193:             }
     194:         }
     195:         j = i;                  /* copy host */
     196:         for (i = 0; i < (NAMESZ - 1); i++)
     197:         {
     198:             if ((c = line[j + i]) == '\0')
     199:             break;
     200:             origsys[i] = c;
     201:         }
     202:         origsys[i] = '\0';
     203: #ifdef  FULLDOMAIN
     204:         /*
     205: 		 * if the delimiter was a !, we can place the site in
     206: 		 * the "UUCP" domain.
     207: 		 *
     208: 		 * Exception:  if the site name contains "." [as it will once
     209: 		 * the USENIX/UUCP project gets going], we don't want to
     210: 		 * add a domain since it is probably already there.
     211: 		 */
     212:         if (sepchar == '!')         /* some UUCP site */
     213:         {
     214:             if (index (origsys, '.') == (char *) NULL)
     215:             {
     216:             strcat (origsys, ".UUCP");
     217:             }
     218:             else
     219:             {
     220:             /*
     221: 			 * already contains full domain spec
     222: 			 */
     223:             }
     224:         }
     225:         else
     226:         {
     227:             /*
     228: 		     * a BERKnet site. Don't have a handy domain for them.
     229: 		     */
     230:         }
     231: #endif	FULLDOMAIN
     232:         j = delim + 1;              /* copy user */
     233:         for (i = 0; i < (SYSSZ - 1); i++)
     234:         {
     235:             if ((c = line[j + i]) == '\0')
     236:             break;
     237:             authname[i] = c;
     238:         }
     239:         authname[i] = '\0';
     240:         }
     241:     }                           /* of if !gotname */
     242:
     243:     /*
     244:      * get fromsys, which is the first host in path
     245:      */
     246:
     247:     if (p = index (line, '!'))
     248:     {
     249:     *p = '\0';
     250:     strncpy (fromsys, line, SYSSZ - 1);
     251:     }
     252:     else
     253:     strcpy (fromsys, origsys);
     254: }

#### Defined functions

parsepath defined in line 35; used 3 times

- in /usr/src/new/notes/src/newsinput.c line 105
- in /usr/src/new/notes/src/nfmail.c line 323, 329

#### Defined variables

authname defined in line 33; used 14 times

- in line 98-99(2), 105, 136-138(2), 159-161(2), 237-239(2)
- in /usr/src/new/notes/src/newsinput.c line 114, 655
- in /usr/src/new/notes/src/nfmail.c line 333-337(2), 346

fromsys defined in line 31; used 14 times

- in line 250-253(2)
- in /usr/src/new/notes/src/newsinput.c line 109, 431-433(2), 448, 500, 524, 537, 654, 699, 784, 816
- in /usr/src/new/notes/src/nfmail.c line 348

origsys defined in line 32; used 17 times

- in line 100-101(2), 177-179(2), 200-202(2), 214-216(2), 253
- in /usr/src/new/notes/src/newsinput.c line 108, 589-592(2), 656
- in /usr/src/new/notes/src/nfmail.c line 334-341(3), 347

rcsid defined in line 6; never used

Last modified: 1985-11-29 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1078 |