386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / dsap / common / psap.c
CommitLineData
04c6839a
WJ
1/* psap.c - General PSAP utility routines */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/dsap/common/RCS/psap.c,v 7.1 91/02/22 09:20:02 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/dsap/common/RCS/psap.c,v 7.1 91/02/22 09:20:02 mrose Interim $
9 *
10 *
11 * $Log: psap.c,v $
12 * Revision 7.1 91/02/22 09:20:02 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 89/11/23 21:44:24 mrose
16 * Release 6.0
17 *
18 */
19
20/*
21 * NOTICE
22 *
23 * Acquisition, use, and distribution of this module and related
24 * materials are subject to the restrictions of a license agreement.
25 * Consult the Preface in the User's Manual for the full terms of
26 * this agreement.
27 *
28 */
29
30
31/* LINTLIBRARY */
32
33#include "quipu/util.h"
34#include "quipu/attr.h"
35#include "psap.h"
36#include "isoaddrs.h"
37#include "../x500as/DO-types.h"
38
39extern LLog * log_dsap;
40
41psap_free (psap)
42struct PSAPaddr * psap;
43{
44 free ((char *)psap) ;
45}
46
47struct PSAPaddr * psap_cpy (a)
48struct PSAPaddr * a;
49{
50struct PSAPaddr * r;
51
52 r = (struct PSAPaddr *) smalloc (sizeof (struct PSAPaddr));
53 bzero ((char *) r,sizeof (struct PSAPaddr));
54
55 *r = *a; /* struct copy */
56
57 return (r);
58}
59
60psap_dup (r,a)
61struct PSAPaddr * r, * a;
62{
63 *r = *a; /* struct copy */
64}
65
66static psap_cmp (r,a)
67struct PSAPaddr *r, *a;
68{
69 return (bcmp ((char *) r, (char *) a, sizeof *a) ? (-1) : 0);
70}
71
72static PE psap_enc (p)
73struct PSAPaddr *p;
74{
75PE ret_pe;
76
77 if (build_DSE_PSAPaddr (&ret_pe,0,0,NULLCP,p) == NOTOK ) {
78 ret_pe = NULLPE;
79 LLOG (log_dsap,LLOG_EXCEPTIONS, ("Failed to encode PSAP"));
80 }
81 return (ret_pe);
82}
83
84static struct PSAPaddr * psap_dec (pe)
85PE pe;
86{
87struct PSAPaddr *psap;
88
89 psap = (struct PSAPaddr *) smalloc (sizeof *psap);
90
91 if (parse_DSE_PSAPaddr (pe,1,NULLIP,NULLVP,psap) == NOTOK) {
92 free ((char *)psap);
93 return (NULLPA);
94 }
95
96 return (psap);
97}
98
99static struct PSAPaddr * psap_parse (s)
100char * s;
101{
102struct PSAPaddr *pa;
103struct PSAPaddr *psap;
104
105 psap = (struct PSAPaddr *) calloc (1,sizeof (struct PSAPaddr));
106 if (pa=str2paddr(s)) {
107 *psap = *pa; /* struct copy */
108 return (psap);
109 } else {
110 parse_error ("invalid presentation address %s",s);
111 free ((char *)psap);
112 return (NULLPA);
113 }
114}
115
116static psap_print (ps,p,format)
117PS ps;
118struct PSAPaddr *p;
119int format;
120{
121 if (format != READOUT)
122 ps_printf (ps, "%s", _paddr2str(p,NULLNA,-1));
123 else
124 ps_printf (ps, "%s", paddr2str(p,NULLNA));
125
126}
127
128psap_syntax ()
129{
130 (void) add_attribute_syntax ("presentationAddress",
131 (IFP) psap_enc, (IFP) psap_dec,
132 (IFP) psap_parse, psap_print,
133 (IFP) psap_cpy, psap_cmp,
134 psap_free, NULLCP,
135 NULLIFP, TRUE );
136}