wt-pep.ms
来自「ftam等标准协议服务器和客户端的源代码。」· MS 代码 · 共 202 行
MS
202 行
\" Walk through of the pepsy library routines.NH 2Walk through of pepsy library routines..XSWalk through of pepsy library routines..XE.PPHere we walk through all the pepsy library routines at least briefly.If any new routines are added or a routine changed this documentationis the most likely part that will need changing.First we give some theory as to how the task have have been brockeninto routines then describe each function in detail.We assume you are familiar with \fBISODE\fR's \fBPE\fR datastructure manipulation routines.if not they are documented in the \fBISODE\fR manuals, Volume one, chapter 5,"Encoding of Data-Structures" (It actually covers decoding as well)..NH 3Overview of pepsy library.XSOverview of pepsy library.XE.PPEach seperate task is put into a different file.So all the encoding stuff is in \fIenc.c\fR, all the decoding stuff isin \fIdec.c\fR, printing stuff in \fIprnt.c\fR and freeing stuff in \fIfre.c\fR.Actually it breaks down a little in practice, some of the routines formoving around the tables are used in both \fIenc.c\fR and \fIdec.c\fRfor example.Probably they should defined in \fIutil.c\fR so that linking one of the filesfrom the library doesn't force linking any other except \fIutil.o\fR..PPThere is a common structure to each of the major files as well.There is a main routine which the user calls to obtain the servicesprovided by that file's routines.As all the files revolve about processing the table entries theirstructure is based on running through the table entries..PPWe shall call each array of entries a table or an object.There is a routine, usually with a name ending in _obj, which is designedto process an object.For example \fBen_obj\fR is the routine called to generated an encodedobject.Then there are routines to call on each compound typesuch as \fBen_seq\fR for encode a SEQUENCE.Finally all the primitives are handled by a one function that ends in _type.This lets each routine concentrate on handling the features particular toits type and call the appropriate routine to handle each type it findswith in its compound type..PPMost of these table processing routines have just three arguements:which are called \fBparm\fR, \fBp\fR, \fBmod\fR.The \fBparm\fR is char * or char ** in the encoding and decoding routinesrespectively.This points to the user's \fBC\fR structure that data to be encodedis taken from when encoding.When decoding it is the address of a pointer which is made to pointthe \fBC\fR structure filled with the decode data.The freeing, which is based on the decoding routines, has a char **while the printing routines don't look at the user's data and so don'thave such a pointer.The \fBp\fR points to the current table entry we are up to processing andthe \fBmod\fR arguement points to the \fBmodtyp\fR structure for the currentmodule we are processing..PPAll these processing routines return a \fBPE\fR type,which is defined in \fBISODE\fR's file \fIh/psap.h\fR, and to return zeroif they have an error, but not always.In fact the error handling is needs some work and has notbeen tested very well.Generally it tries to print out the table entry where something went wrong andthe name of the function it was in.It then sometimes does an exit which may not be very pleasent for theuser..NH 3The encoding routines - enc.c.XSThe encoding routines - enc.c.XE.IP enc_fThis is the the routine made available to the user for the encoding routines.It is fairly simple as it leaves all the hard things up to other routines.All it does is use the type number and \fBmodtyp\fR pointer to geta pointer to the table for encoding that type.Then it calls the table or object encoding routine, \fBen_obj\fR,on that object.It first does a consistency check of making sure the first entry in the table is a \fBPE_start\fR.Note that it returns an integer (OK or NOTOK) instead of a \fBPE\fR pointer.This is to be consitent with \fBISODE\fR functions..IP en_objWe loop through the entries until we come to the end of the table and then wereturn the \fBPE\fR we have built up from the user's data which is pointedto by \fBparm\fR.In looping through each entry we call the appropriate routine to encode itsdata.The default case is handled by calling \fBen_type\fR which takes care ofall the primitive types..PPThe macro \fBNEXT_TPE\fR sets its arguement to point to the next typein the table, counting compound types as one type.Thus if \fBNEXT_TPE\fR is called on a \fBSET_START\fR it will skip all theentries up to and including the matching \fBPE_END\fR.As many objects consist of one compound type and its components the mainloop will only be run through once.Even when the object is not based on a compound type it will then consist ofone simple type which is processed by \fBen_type\fR, again probablygoing through the loop only once.In fact the only way it can go through the loop more than onceis to process entries that subsidary to the main type, e.g. \fBETAG\fB entriesand things like that.To double check this is the case there is some code that looks forthe processing of more than one data generating entry..PPMuch of that testing could probably be eliminated with no loss.Similarly prehaps the \fBIMP_OBJ\fR and \fBETAG\fR could be handled by thedefault action of calling \fBen_type\fR.As these routines have evolved after many changes there are things likethat which really need to be looked at closely before trying.The comment /*SUPRESS 288*/ means suppress warning 288 to saber C debuggingtool that we use..IP en_typeThis is one of the longest functions as it has so many cases to handle.It again is structure as a loop over the types until \fBPE_END\fR but itactually returns as soon as it has encoded the next type.We can now look at the encoding of the primative \fBASN.1\fR types in detail..IP DFLT_FBecause we have arranged that for encoding tables, that we precedethe entry with a \fBDFLT_F\fR entry we can neatly handle all the defaultcases.All we do is check if the parameter passed in the user data, in \fBparm\fR,is the same as the default value specified in the \fBDFLT_F\fR entry.The function \fBsame\fR performs this check.If it is the same don't encode anything just return, otherwise continue onand encode it..IP ETAGTo handle explicit tags we merely allocate a \fBPE\fR with the right tagand call \fBen_etype\fR to encode its contents, which are in the followingentries.The switch on the \fBpe_ucode\fR field use to make a differencebut now it is meaningless and should be cleaned up..IP "SEQ_START, SEQOF_START, SET_START, SETOF_START"We merely call the appropriate function handle them.Note one \fIimportant\fR difference in the way they are called here from thatin \fBenc_obj\fR, the parm arguement is used as a base to index off andfetch a new pointer to pass the next function.This seemly bizarre action is quite straight forward when seen written asit is normally in \fBC\fR, "\fBparm->offset\fR".Where the field \fBoffset\fR is a pointer which has an offset from the startof the structure of \fBp->pe_ucode\fR bytes..PPThis is the magic of how we access all the different fieldsof the \fBC\fR data structures with the one piece of code.It is also prehaps the most critical dependency of the whole systemon the implementation of the \fBC\fR language.As the \BGNU\fR \fBC\fR compiler supports this feature then it iscompilerable on most machines.But any porters should pay attention to this to ensure that thier compileris happy generating these offsets and compiling these casts properly..PPThe reason why this is different from the calls in \fBen_obj\fR is thatthis is not the first compound type in the table.The first and only the first does not have an offset and does not need to beindirected through any pointers.All the compound types inside this type will haveas their field a pointer which points to a structure.From here on we shall say \fIindirection\fR to mean thisadding the \fBpe_ucode\fR fieldto the pointer to the structure and using it to reference a pointer.Whether to use \fIindirection\fR or not is very important matterthat really needs to be understood to understand how the routines arestructured..IP IMP_OBJHere we have to handle the case where we can encode the object then have tochange its tag and class after encoding.At the end of this entry this is done very simply by assigning theright values to the appropriate fields after the object has been built.This means that if the intermeadiate form is altered this piece of codemay have to be altered as well.There seems to be no better way of handling this..PPThe complication in handling this field is the handling of all the possibletypes of object.If it is an external object we have to perform a call to \fBenc_f\fR withall the right arguementswhere a normal OBJECT, the last else branch, requires a normal callto \fBen_obj\fR.Note the case of \fBSOBJECT\fR is the sameas \fBOBJECT\fR \fIexcept there is no indirection\fR..IP "SOBJECT and OBJECT"Here is the code that handles the two cases sperately.It is exactly as in the \fBIMP_OBJ\fR case except seperated out.Note the only difference between the two cases is lack of indirection inthe \fBSOBJECT\fR case..IP CHOICE_STARTThis is exactly as all other compound types,like \fBSEQ_START\fR and \fBOBJECT\fR, we call the appropriate routine withindirection.From reading the \fBISODE\fR manuals that the \fBASN.1\fR CHOICE typeis handled by a structure of its own like the other compund types..IP "EXTOBJ and SEXTOBJ"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?