From: zhang@dset.UUCP (Ju Zhang)
Newsgroups: comp.protocols.iso
Subject: Re: Adding semantics to ASN.1; pointers to other work?
Date: 7 Apr 92 00:49:15 GMT
Organization: DSET Corporation, Lebanon, NJ
Summary: Dynamical Loading in ASN.C

In article <SES.92Apr5143252@cmns-sun.think.com>, ses@cmns-sun.think.com (Simon Edward Spero) writes:
> 
> 
> I'm currently working on a public domain implementation of NISO Z39.50-1992
> (better known as WAIS). The current setup uses are permanantly resident
> ASN.1 interpreter, together with generic BER encode and decode functions
> which operate on the ASN.1 parse tree. The BER is then pumped directly into
> the transport layer, according to the relevant profile.
> 
> The reason for using a resident ASN.1 interpreter is to allow a client to
> download and compile record syntaxes on the fly.
> 
(text deleted)

ASN.C from DSET has the feature of dynamical loading.

ASN.1 parser is kind of big. So we don't put an ASN.1 interpreter 
permanantly resident. Instead, we have the ASN.1 compiler generate 
a table which a client will use to download on the fly.

A function 

D_type_rd (file_descriptor, type_name, type_pointer_pointer)

is supplied to load the type from a file. Other functions are 
supplied for server to generate, examine, navigate and access 
data instances of a dynamically loaded type.

It seems easier to receive data of dynmically loaded type than to  
assign value and encode it.

Here I come up a code to encode. The server code could be like:

-----------------------------------------------
while (true) { /*permanant cycle*/

  <interactively get the type name and file name from client>
  file_descriptor = fopen(file_name);

  D_type_rd (file_descriptor, type_name, &type_table_pointer);
  data_instance = D_ad_create(type_table_pointer);

  while (<client wnats to allocate space for an array field>) {
	scanf("%s", field_path);
	scanf("%d", &array_size);
	D_array_alloc(D_ad_nodeP(data_instance, field_path), array_size);
  }

  while (<client wants to update a field>) {
	scanf("%s", field_path);
	<examine type of the field>
	switch (filed_type) {
	case AD_INT:
	    <ask for a number>
	    *(int *)D_ad_valP(D_ad_nodeP(data_instance, field_path))= num;
	    break;	
	case AD_PRINTABLE_STR:
	    <ask for a string>
	    strcpy((char *)D_ad_valP(D_ad_nodeP(data_instance,field_path)),
		    user_supplied_string);
	    break;	
	}
  }

  /*print the data*/
  D_ad_pr(data_instance);

  /*encode data_instance*/
  D_ad_enc_buf(data_instance, AD_BER, &bufP, &size);

  <transport data of size pointed to by bufP> 
}
-----------------------------------------------

With this server program, you can load and access new ASN.1 
types without taking down the server.

Assume you ASN.1 type is like:

-----------------------------------------------
T ::= SET OF SET OF SET {
                a INTEGER
        }
-----------------------------------------------

The loading table will be generated

-----------------------------------------------
!!!dyn
/* automatically generated by asncom, do not edit! */
$T 4 1 5 1 2 0 2 0 3 5 1 0
## 2 1 2 16 18 0 17 1 17 2 17 2 17 3
## 4 40 40 0
## "a" 1 0 0 "T" 4 0 1
##
.
-----------------------------------------------

Interactively, you can ask the server to allocate space:

-----------------------------------------------
Alocate Space
Field: 
Size: 1
More?: y
Field: [0]
size: 1
More?: n
-----------------------------------------------

Then update field:

-----------------------------------------------
Update Field
Field: [0][0].a
Number: 12
-----------------------------------------------

D_ad_pr will print out

-----------------------------------------------
SET size 1
:   SET size 1
:   : 	SET
:   :	:a  INTEGER 12
-----------------------------------------------

And it will be encoded and transmitted with whatever API you
have.

To make it easier to input new data value, we are also working 
on dynamically loading an ASN.1 value described in the ASN.1 
value notation.

P.S. API presented here is slightly different from what is 
described in the draft of reference manual I mailed upon 
requests because that was prepared several months ago.

The final version of ASN.C 3.0 Reference manual will be sold 
separately for evaluation purpose starting from May 15.  If you 
are interested, you may send an email to dset!bsb@uunet.uu.net.


					Ju Zhang


(908)526-2837
-- DSET Co., NJ