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

  1. /* or_or2rfc.c: convert from or address to rfc address */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_or2rfc.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_or2rfc.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_or2rfc.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "or.h"
  19. #include "util.h"
  20. #include "ap.h"
  21. #include <isode/cmd_srch.h>
  22. extern char *loc_dom_site;
  23.  
  24.  
  25.  
  26.  
  27. /* ---------------------  Begin  Routines  -------------------------------- */
  28.  
  29.  
  30.  
  31.  
  32. /*
  33. Maps OR struct into a RFC822 string
  34. */
  35.  
  36. #define UB_DDA_VALUE 128
  37.  
  38. #define    RFC822C1    100
  39. #define    RFC822C2    101
  40. #define    RFC822C3    102
  41.  
  42. CMD_TABLE    ortbl_rfc822ddas[] = { /* type strings for rfc 822 ddas */
  43.     "RFC-822",    OR_DDVALID_RFC822,
  44.     "RFC822C1",    RFC822C1,
  45.     "RFC822C2",    RFC822C2,
  46.     "RFC822C3",    RFC822C3,
  47.     0,        -1
  48.     };
  49.  
  50. int or_or2rfc_aux (or, buf, addr_check)
  51. OR_ptr          or;
  52. char            *buf;
  53. int             addr_check;
  54. {
  55.     AP_ptr      local,
  56.         domain;
  57.     OR_ptr      current_ptr;
  58.     char        lbuf[LINESIZE],
  59.         dbuf[LINESIZE],
  60.         *cp;
  61.  
  62.     PP_DBG (("Lib/or_or2rfc()" ));
  63.     if (or == NULLOR)
  64.         return NOTOK;
  65.  
  66.     or = or_default (or);
  67.     current_ptr = or;
  68.  
  69.     if ((current_ptr = or_find (current_ptr, OR_DD, NULLCP)) != NULLOR) {
  70.         if (current_ptr -> or_next == NULLOR) {
  71.             /* --- single DD attributes --- */
  72.             if (or_ddname_chk (current_ptr -> or_ddname)) {
  73.                 /* --- Special DD type --- */
  74.                 if (or_str_isps(current_ptr->or_value)) {
  75.                     or_ps2asc (current_ptr -> or_value, buf);
  76.                     PP_DBG (("Lib/or_or2rfc: Matched dd, '%s' = '%s'",
  77.                          current_ptr -> or_ddname, buf));
  78.                     return OK;
  79.                 } else {
  80.                     PP_LOG(LLOG_EXCEPTIONS,
  81.                        ("dd '%s' value '%s' is not a printable string",
  82.                         current_ptr->or_ddname, 
  83.                         current_ptr -> or_value));
  84.                     return NOTOK;
  85.                 }
  86.             }
  87.         } else {
  88.             /* --- multiple DD attributes --- */
  89.             /* --- look to merge RFC-822s --- */
  90.             char rfc822[UB_DDA_VALUE+1],
  91.                  rfc822c1[UB_DDA_VALUE+1],
  92.                  rfc822c2[UB_DDA_VALUE+1],
  93.                  rfc822c3[UB_DDA_VALUE+1];
  94.             int  allRFC822s = TRUE;
  95.  
  96.             rfc822[0] = '\0';
  97.             rfc822c1[0] = '\0';
  98.             rfc822c2[0] = '\0';
  99.             rfc822c3[0] = '\0';
  100.             do {
  101.                 if (current_ptr -> or_type == OR_DD) {
  102.                     if (or_str_isps (current_ptr->or_value)) {
  103.                         switch(cmd_srch(current_ptr -> or_ddname,
  104.                                 ortbl_rfc822ddas)) {
  105.                         case OR_DDVALID_RFC822:
  106.                             or_ps2asc(current_ptr->or_value,
  107.                                   rfc822);
  108.                             break;
  109.  
  110.                         case RFC822C1:
  111.                             or_ps2asc(current_ptr->or_value,
  112.                                   rfc822c1);
  113.                             break;
  114.  
  115.                         case RFC822C2:
  116.                             or_ps2asc(current_ptr->or_value,
  117.                                   rfc822c2);
  118.                             break;
  119.                         case RFC822C3:
  120.                             or_ps2asc(current_ptr->or_value,
  121.                                   rfc822c3);
  122.                             break;
  123.                         default:
  124.                             allRFC822s = FALSE;
  125.                             break;
  126.                         }
  127.                         PP_DBG(("Lib/or_or2rfc: Matched dd, '%s' = '%s'",
  128.                             current_ptr->or_ddname,
  129.                             current_ptr->or_value));
  130.                     } else {
  131.                         PP_LOG(LLOG_EXCEPTIONS,
  132.                            ("dd '%s' value '%s' is not a printable string",
  133.                             current_ptr->or_ddname,
  134.                             current_ptr->or_value));
  135.                         return NOTOK;
  136.                     }
  137.                 } else
  138.                     allRFC822s = FALSE;
  139.  
  140.                 current_ptr = current_ptr -> or_next;
  141.             } while (current_ptr != NULLOR);
  142.  
  143.             if (allRFC822s == TRUE) {
  144.                 buf[0] = '\0';
  145.  
  146.                 if (rfc822[0])
  147.                     (void) strcat(buf, rfc822);
  148.  
  149.                 if (rfc822c1[0])
  150.                     (void) strcat(buf, rfc822c1);
  151.  
  152.                 if (rfc822c2[0])
  153.                     (void) strcat(buf, rfc822c2);
  154.  
  155.                 if (rfc822c3[0])
  156.                     (void) strcat(buf, rfc822c3);
  157.                 if (buf[0] != '\0')
  158.                     return OK;
  159.             }
  160.         }
  161.     }
  162.             
  163.     if (or_or2rbits (or, lbuf, dbuf) == NOTOK)
  164.     return NOTOK;
  165.  
  166.  
  167.     /* --- if NUL domain - explicit encoding --- */
  168.  
  169.     if (dbuf[0] == '\0') {
  170.     (void) strcpy (buf, lbuf);
  171.     PP_DBG (("Lib/or_or2rfc Returns '%s'", buf));
  172.     return OK;
  173.     }
  174.  
  175.  
  176.     PP_TRACE (("Lib/or_or2rfc lbuf='%s' dbuf='%s'", lbuf, dbuf));
  177.  
  178.  
  179.     if (lexequ (dbuf, loc_dom_site) == 0)
  180.     if (addr_check)
  181.         return DONE;
  182.  
  183.     local  = ap_new (AP_MAILBOX, lbuf);
  184.     domain = ap_new (AP_DOMAIN, dbuf);
  185.  
  186.     cp = ap_p2s (NULLAP, NULLAP, local, domain, NULLAP);
  187.  
  188.     (void) strcpy (buf, cp);
  189.  
  190.     free (cp);
  191.     ap_free (local);
  192.     ap_free (domain);
  193.  
  194.     PP_TRACE (("Lib/or_or2rfc returns '%s'", buf));
  195.  
  196.     return OK;
  197. }
  198.