home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_downgrade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.7 KB  |  145 lines

  1. /* or_downgrade: downgrade an 88 address to an 84 address */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_downgrade.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_downgrade.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_downgrade.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include    "util.h"
  17. #include    "or.h"
  18. #include    "ap.h"
  19.  
  20. extern char    *loc_or;
  21.  
  22. static int is84component(or)
  23. OR_ptr    or;
  24. {
  25.     typestruct    *ptr;
  26.  
  27.     if (or->or_encoding == OR_ENC_PS
  28.         || or->or_encoding == OR_ENC_NUM) {
  29.         for (ptr = typetab; (ptr -> ty_string) != NULLCP; ptr++)
  30.             if (or->or_type == ptr->ty_int)
  31.                 return TRUE;
  32.     }
  33.     return FALSE;
  34. }
  35.  
  36. void or_downgrade(ptree)
  37. OR_ptr    *ptree;
  38. {
  39.     OR_ptr    ix = *ptree, ret, cn = NULLOR;
  40.     int    x40088 = FALSE;
  41.  
  42.     while (ix != NULLOR && x40088 == FALSE) {
  43.         if (is84component(ix) != TRUE) {
  44.             if (ix -> or_type == OR_CN) {
  45.                 cn = ix;
  46.                 ix = ix -> or_next;
  47.             } else
  48.                 x40088 = TRUE;
  49.         } else 
  50.             ix = ix -> or_next;
  51.     }
  52.     
  53.     if (cn != NULLOR && x40088 != TRUE) {
  54.         /* CN sole x40088 comp */
  55.         char    buf[BUFSIZ], *sep;
  56.  
  57.         /* convert cn to DD.Common */
  58.         switch(cn->or_encoding) {
  59.             case OR_ENC_PS:
  60.             (void) strcpy(buf, cn->or_value);
  61.             break;
  62.  
  63.             case OR_ENC_TTX:
  64.             case OR_ENC_TTX_AND_OR_PS:
  65.             if ((sep = index(cn->or_value, '*')) == NULLCP)
  66.                 (void) strcpy (buf, cn->or_value);
  67.             else {
  68.                 *sep = '\0';
  69.                 if (sep != cn->or_value)
  70.                     /* ps encoding */
  71.                     (void) strcpy (buf, cn->or_value);
  72.                 else 
  73.                     /* ttx encoding */
  74.                     (void) or_asc2ps (sep+1, buf);
  75.             }
  76.             break;
  77.  
  78.             default:
  79.             /* give up on DD common */
  80.             cn = NULLOR;
  81.             x40088 = TRUE;
  82.         }
  83.  
  84.         if (cn != NULLOR) {
  85.             /* remove cn */
  86.             if (cn->or_prev)
  87.                 cn->or_prev->or_next = cn->or_next;
  88.             if (cn->or_next)
  89.                 cn->or_next->or_prev = cn->or_prev;
  90.             if (cn == *ptree)
  91.                 *ptree = cn->or_next;
  92.         
  93.             cn->or_next = NULLOR;
  94.             cn->or_prev = NULLOR;
  95.             or_free(cn);
  96.  
  97.             *ptree = or_add(*ptree,
  98.                     or_new_aux (OR_DD, 
  99.                             "Common", 
  100.                             buf, OR_ENC_PS),
  101.                     TRUE);
  102.         }
  103.     }
  104.     
  105.     if (x40088 == TRUE) {
  106.         char    lbuf[LINESIZE],
  107.             dbuf[LINESIZE],
  108.             *cp;
  109.         AP_ptr    local,
  110.             domain;
  111.         OR_ptr    ptr;
  112.                 
  113.         if (or_or2rbits(*ptree, lbuf, dbuf) == NOTOK) {
  114.             PP_LOG (LLOG_EXCEPTIONS,
  115.                 ("or_downgrade: or_or2rbits failed"));
  116.             return;
  117.         }
  118.  
  119.         PP_TRACE (("or_downgrade lbuf='%s' dbuf='%s'",
  120.                lbuf, dbuf));
  121.  
  122.         local = ap_new (AP_MAILBOX, lbuf);
  123.         domain = ap_new (AP_DOMAIN, dbuf);
  124.  
  125.         cp = ap_p2s(NULLAP, NULLAP, local, domain, NULLAP);
  126.         
  127.         
  128.         ap_free(local);
  129.         ap_free(domain);
  130.  
  131.         (void) or_asc2ps (cp, lbuf);
  132.         
  133.         ptr = or_new_aux (OR_DD, "X400-88", lbuf, OR_ENC_PS);
  134.  
  135.         ret = or_std2or(loc_or);
  136.         ret = or_add(ret, ptr, TRUE);
  137.         or_free(*ptree);
  138.         *ptree = ret;
  139.     }
  140.  
  141. }
  142.     
  143.         
  144.  
  145.