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

  1. /* ut_ext.c: Common Function Routines for external body parts */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/asn/RCS/ut_ext.c,v 6.0 1991/12/18 20:16:07 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/asn/RCS/ut_ext.c,v 6.0 1991/12/18 20:16:07 jpo Rel $
  9.  *
  10.  * $Log: ut_ext.c,v $
  11.  * Revision 6.0  1991/12/18  20:16:07  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17. #include "asn1/ExtDef-types.h"
  18. #include "head.h"
  19. #include "asn.h"
  20. #include "oid.h"
  21.  
  22.  
  23. /* -- stuff from pepsy -- */
  24. #define EXT_BP            struct type_ExtDef_ExtDefBodyPart
  25. #define EXT_UNIV        struct type_UNIV_EXTERNAL
  26. #define EXT_UNIV_CHOICE        struct choice_UNIV_0
  27. #define Choice_Asn1        choice_UNIV_0_single__ASN1__type
  28.  
  29.  
  30.  
  31. typedef struct oid_struct {
  32.     int    type;
  33.     char    *oid_prm;
  34.     char    *oid_data;
  35.     } TBL_OIDS;
  36.  
  37.  
  38. static TBL_OIDS  tbl_oids [] = {/* -- oids for external body parts -- */
  39.     GENERALTEXT,    "2.6.1.11.11",        "2.6.1.4.11",
  40.     0,        0,            0
  41.     };
  42.  
  43.  
  44.  
  45.  
  46. /* ----------------------------  Begin Routines ----------------------------- */
  47.  
  48.  
  49.  
  50.  
  51. pe2external (pptr, pe_prm, pe_data, type)
  52. PE    *pptr;
  53. PE    pe_prm;
  54. PE    pe_data;
  55. int    type;
  56. {
  57.     EXT_BP        *ext_bp;
  58.     EXT_UNIV    *ext_prm, *ext_data;
  59.     char        *oid_prm, *oid_data;
  60.     int        retval;
  61.  
  62.     oid_srch (type, &oid_prm, &oid_data);
  63.  
  64.     PP_TRACE (("pe2external (%d, %s, %s)", type, oid_prm, oid_data));
  65.  
  66.     ext_bp = (EXT_BP *) smalloc (sizeof (EXT_BP));
  67.     bzero ((char *) ext_bp, sizeof (EXT_BP));
  68.  
  69.     malloc_univ_external (&ext_prm, oid_prm, pe_prm);
  70.     malloc_univ_external (&ext_data, oid_data, pe_data);
  71.  
  72.     ext_bp -> parameters = ext_prm;
  73.     ext_bp -> data = ext_data;
  74.  
  75.     retval = encode_ExtDef_ExtDefBodyPart
  76.             (pptr, 1, NULLIP, NULLVP, ext_bp);
  77.     if (retval == NOTOK)    pe_done (*pptr);  /* -- exit -- */
  78.  
  79.     PP_PDUP (ExtDef_ExtDefBodyPart, *pptr,
  80.             "External Body Part", PDU_WRITE);
  81.  
  82.     free_ExtDef_ExtDefBodyPart(ext_bp);
  83. }
  84.  
  85.  
  86.  
  87.  
  88. external2pe (pe, pe_prm, pe_data, type)
  89. PE    pe;
  90. PE    *pe_prm;
  91. PE    *pe_data;
  92. int    type;
  93. {
  94.     EXT_BP        *ext_bp;
  95.     EXT_UNIV    *ext_prm, *ext_data;
  96.     char        *oid_prm, *oid_data, *cp; 
  97.     int        retval;
  98.  
  99.     oid_srch (type, &oid_prm, &oid_data);
  100.  
  101.     PP_TRACE (("pe2external (%d, %s, %s)", type, oid_prm, oid_data));
  102.  
  103.     PP_PDUP (ExtDef_ExtDefBodyPart, pe,
  104.                 "External Body Part", PDU_READ);
  105.  
  106.     retval = decode_ExtDef_ExtDefBodyPart
  107.             (pe, 1, NULLIP, NULLVP, &ext_bp);
  108.     if (retval == NOTOK)  pe_done (pe); /* -- exit -- */
  109.  
  110.     ext_prm = ext_bp -> parameters;
  111.     ext_data = ext_bp -> data;
  112.  
  113.     if ((ext_prm -> encoding -> offset != Choice_Asn1) || 
  114.         (ext_data -> encoding -> offset != Choice_Asn1)) {
  115.         PP_LOG (LLOG_EXCEPTIONS, ("Error: No External ASN1 found"));
  116.         exit(1);
  117.     }
  118.  
  119.  
  120.     cp = sprintoid (ext_prm  -> direct__reference);
  121.     if (lexequ (cp, oid_prm) != 0) { 
  122.         PP_LOG (LLOG_EXCEPTIONS,
  123.             ("Error: Parameter OID mismatch  %s  %s", cp, oid_prm));
  124.         exit (1);
  125.     }
  126.  
  127.     cp = sprintoid (ext_data -> direct__reference);
  128.     if (lexequ (cp, oid_data) != 0) {
  129.         PP_LOG (LLOG_EXCEPTIONS,
  130.             ("Error: Data OID mismatch  %s  %s", cp, oid_data));
  131.         exit(1);
  132.     }
  133.  
  134.     *pe_prm  = ext_prm -> encoding -> un.single__ASN1__type;
  135.     *pe_data = ext_data -> encoding -> un.single__ASN1__type;
  136.  
  137.     ext_prm -> encoding -> un.single__ASN1__type = NULLPE;
  138.     ext_data -> encoding -> un.single__ASN1__type = NULLPE;
  139.     free (oid_prm);
  140.     free (oid_data);
  141.     free_ExtDef_ExtDefBodyPart(ext_bp);
  142. }
  143.  
  144.  
  145.  
  146.  
  147. /* ----------------------------- Static Routines ---------------------------- */
  148.  
  149.  
  150.  
  151.  
  152. static oid_srch (type, prm, data)
  153. int    type;
  154. char    **prm;
  155. char    **data;
  156. {
  157.     TBL_OIDS    *tbl = tbl_oids;
  158.  
  159.     PP_TRACE (("oid_srch (%d)", type));
  160.  
  161.     for(*prm = *data = NULLCP; tbl->type != NULL; tbl++)
  162.         if (type == tbl->type) {
  163.             *prm  = strdup (tbl->oid_prm);
  164.             *data = strdup (tbl->oid_data);
  165.         }
  166.  
  167.  
  168.     if (*prm == NULLCP && *data == NULLCP) {
  169.         PP_LOG (LLOG_EXCEPTIONS, ("Error: Unknown OIDS for %d", type));
  170.         exit(1);
  171.     }
  172. }
  173.  
  174.  
  175.  
  176.  
  177. malloc_univ_external (pptr, oid, pe)
  178. EXT_UNIV    **pptr;
  179. char        *oid;
  180. PE        pe;
  181. {
  182.     EXT_UNIV    *ExtUniv;
  183.     int        n;
  184.  
  185.     n = sizeof (EXT_UNIV);
  186.     ExtUniv = (EXT_UNIV *) smalloc (n);
  187.     bzero ((char *) ExtUniv, n);
  188.  
  189.     n = sizeof (EXT_UNIV_CHOICE);
  190.     ExtUniv -> encoding = (EXT_UNIV_CHOICE *) smalloc (n);
  191.     bzero ((char *) ExtUniv -> encoding, n);
  192.  
  193.     ExtUniv -> direct__reference = oid_cpy (str2oid (oid));
  194.     ExtUniv -> encoding -> offset = Choice_Asn1;
  195.     ExtUniv -> encoding -> un.single__ASN1__type = pe;
  196.  
  197.     *pptr = ExtUniv;
  198. }
  199.