Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

399 lines
18 KiB

  1. /*****************************************************************************/
  2. /* Copyright (C) 1992-1999 Open Systems Solutions, Inc. All rights reserved.*/
  3. /*****************************************************************************/
  4. /* THIS FILE IS PROPRIETARY MATERIAL OF OPEN SYSTEMS SOLUTIONS, INC. AND
  5. * MAY BE USED ONLY BY DIRECT LICENSEES OF OPEN SYSTEMS SOLUTIONS, INC.
  6. * THIS FILE MAY NOT BE DISTRIBUTED. */
  7. /*****************************************************************************/
  8. /* FILE: @(#)osstrace.h 5.4.1.1 97/06/08 */
  9. /* */
  10. /* When tracing is in effect in the OSS ASN.1 Tools encoder/decoder the */
  11. /* user user-replaceable trace routine, osstrace(), is called to trace */
  12. /* the value that is being encoded/decoded. This header file describes */
  13. /* the parameters passed to osstrace(). */
  14. /* */
  15. /* Detailed descriptions appear after the declarations. */
  16. /*****************************************************************************/
  17. #if _MSC_VER > 1000
  18. #pragma once
  19. #endif
  20. #include "ossdll.h"
  21. #if defined(_MSC_VER) && (defined(_WIN32) || defined(WIN32))
  22. #pragma pack(push, ossPacking, 4)
  23. #elif defined(_MSC_VER) && (defined(_WINDOWS) || defined(_MSDOS))
  24. #pragma pack(1)
  25. #elif defined(__BORLANDC__) && defined(__MSDOS__)
  26. #ifdef _BC31
  27. #pragma option -a-
  28. #else
  29. #pragma option -a1
  30. #endif /* _BC31 */
  31. #elif defined(__BORLANDC__) && defined(__WIN32__)
  32. #pragma option -a4
  33. #elif defined(__IBMC__)
  34. #pragma pack(4)
  35. #elif defined(__WATCOMC__) && defined(__NT__)
  36. #pragma pack(push, 4)
  37. #elif defined(__WATCOMC__) && (defined(__WINDOWS__) || defined(__DOS__))
  38. #pragma pack(push, 1)
  39. #endif /* _MSC_VER && _WIN32 */
  40. #ifdef macintosh
  41. #pragma options align=mac68k
  42. #endif
  43. /* traceKind: describes the type of TraceRecord */
  44. enum traceKind
  45. {
  46. endOfContentsTrace = 0, /* end-of-contents octets */
  47. valueTrace, /* traceRecord contains a traced value */
  48. skippedFieldTrace, /* a value whose type is not recognized
  49. * is being skipped */
  50. messageTrace /* error message is in the field "value" */
  51. };
  52. /* fieldKind: describes the contents of "fieldNumber". "fieldKind" is
  53. * meaningful only if "fieldNumber" is not 0
  54. */
  55. enum fieldKind
  56. {
  57. setOrSequenceField = 0, /* "fieldNumber" is the position of the
  58. * component within a SET or SEQUENCE */
  59. pduNumber, /* "fieldNumber" is a PDU number */
  60. setOrSequenceOfElement, /* "fieldNumber" is the position of the
  61. * component within a SET OF or SEQUENCE OF
  62. * components */
  63. stringElement /* "fieldNumber" is the position of the
  64. * substring within a constructed STRING */
  65. };
  66. enum prtType
  67. {
  68. seqsetType = 0, /* SEQUENCE and SET uses [fieldcount = n] */
  69. seqofType, /* SEQUENCE OF and SET OF use [length = n] */
  70. choiceType, /* CHOICE type uses format [index = n] */
  71. pseudoType, /* No length info is printed or [not encoded] */
  72. primeType, /* All other types use the format */
  73. /* [length = [(not encoded)] nbytes.nbits] */
  74. /* fragmentation is printed for OCTET */
  75. /* STRING and BIT STRING. */
  76. closeType /* Trace message at the end of encoding. */
  77. };
  78. /* tag_length: specifies the tag and length of a value. */
  79. struct tag_length
  80. {
  81. unsigned long int length; /* length of type, if definite */
  82. unsigned short int tag; /* 16 bits of the form CCTTTTTTTTTTTTTT,
  83. * with "CC" the class number, and "T...T"
  84. * the tag. (If tag is 0, then "length",
  85. * "primitive" and "definite" are
  86. * not significant). */
  87. unsigned int definite: 1; /* 1: definite-length encoding */
  88. };
  89. /* traceRecord: OSS ASN.1 Tools trace record */
  90. struct traceRecord
  91. {
  92. enum traceKind kind; /* kind of trace record */
  93. void *p; /* reserved for OSS */
  94. char *identifier, /* SET/SEQUENCE/CHOICE component name*/
  95. *typeReference,/* defined type name */
  96. *builtinTypeName; /* ASN.1 builtin type defined in *
  97. * ISO 8824 or "Character String"*/
  98. void *valueName; /* reserved for future use */
  99. unsigned taggingCount; /* number of entries in the tag&length
  100. * or content-end-octet array */
  101. union /* tag&length or end-of-contents-octets array. */
  102. {
  103. struct tag_length *tag_length;
  104. int *depth;
  105. } tagging;
  106. enum prtType prtType; /* Refer to prtType above for details */
  107. char lenEncoded; /* Indicate whether length is encoded */
  108. long length; /* Length in bits for all prime types */
  109. /* fieldcount for SET and SEQUENCE */
  110. /* length of components for SET OF */
  111. /* choice index for type CHOICE */
  112. int fragment; /* Fragment for OCTET STRING and BIT */
  113. /* STRING, PER fragment when too long */
  114. enum fieldKind fieldKind; /* kind of value in "fieldNumber" */
  115. unsigned int fieldNumber; /* component number, 0 if not
  116. * applicable */
  117. unsigned int depth; /* the depth of this value, from 0 on up */
  118. unsigned int primitive: 1; /* indicates structure of encoding */
  119. char value[1]; /* the formatted value for simple
  120. * type and ANY. If the first byte
  121. * is 0, no value is present. */
  122. };
  123. extern void DLL_ENTRY osstrace(struct ossGlobal *g, struct traceRecord *p, size_t traceRecordLen);
  124. /* osstrace(): User-replaceable trace routine.
  125. *
  126. * Parameters:
  127. * g - Reserved. This is always set to NULL for now.
  128. * p - traceRecord, described below.
  129. * traceRecordLen - True length of traceRecord, including first \0 in "value"
  130. *
  131. * osstrace() is called:
  132. *
  133. * - once for each builtin ASN.1 type, regardless of tagging, with the
  134. * field "kind" set to valueTrace. So given a PDU of value "fooBar":
  135. *
  136. * Sample DEFINITIONS EXPLICIT TAGS ::= BEGIN
  137. * fooBar Foo ::= {age 6, living TRUE}
  138. * Foo ::= SET {age INTEGER, living [1] [2] Alive}
  139. * Alive ::= BOOLEAN
  140. * END
  141. *
  142. * it is called called three times with "kind" set to valueTrace - once
  143. * for the SET, once for the INTEGER, and once for the BOOLEAN.
  144. *
  145. * When the traceRecord "kind" field is set to valueTrace ...
  146. *
  147. * The field "identifier" contains the component identifier of
  148. * the type if one is present in the ASN.1 definition. So in
  149. * the above example, "identifier" will be empty on the call for
  150. * the SET, while on the call for the INTEGER it will contain "age",
  151. * and "living" on the call for the BOOLEAN.
  152. *
  153. * The field "typeReference" contains the name of the associated ASN.1
  154. * typereference, if any. So in the above example, "typeReference"
  155. * will contain "Foo" on the call for the SET, "Alive" on the call
  156. * for the BOOLEAN, and will be empty on the call for the INTEGER.
  157. *
  158. * The field "builtinTypeName" contains the name of the ASN.1 builtin
  159. * type. So in the above example, "builtinTypeName" will contain
  160. * "SET", "INTEGER", and "BOOLEAN" on the calls as appropriate.
  161. * Note that for all character string types "builtinTypeName" is
  162. * set to "Character String". This will be changed in the near future
  163. * to reflect the true character string type.
  164. *
  165. * The field "taggingCount" contains the number of entries in the array
  166. * of tag_length structs pointed to by tagging.tag_length, and reflects
  167. * the number of tags present in the encoding. Note that an entry
  168. * exists in the tag_length array for each ANY and CHOICE value as
  169. * though they had tags defined for them in the ASN.1 Standard. So in
  170. * the above example, "taggingCount" is 1 on the calls for the SET and
  171. * INTEGER, and on the call for the BOOLEAN "taggingCount" is 3 since
  172. * EXPLICIT TAGS is in effect.
  173. *
  174. * The field "tagging.tag_length" points to an array of tag_length
  175. * structs.
  176. *
  177. * The field "tagging.tag_length->tag" is the BER tag represented
  178. * in the form CCTTTTTTTTTTTTTT with "CC" the class number, and
  179. * "TTTTTTTTTTTTTT" the tag number. Since the ANY and CHOICE
  180. * types do not have tags of their own, the last entry in the
  181. * tag_length array for these types always has 0 as the value of
  182. * the "tag" field. So in the above example, "tag" is 0x11 on the
  183. * call for the the SET.
  184. *
  185. * The field "tagging.tag_length->length" is the length of the
  186. * encoded value if the length is of definite form (i.e.,
  187. * "definite" is 1).
  188. *
  189. * The field "tagging.tag_length->definite" indicates when the
  190. * length is definite or indefinite. This field is significant
  191. * only if "tag" is non-zero.
  192. *
  193. * The field "fieldKind" indicates whether the number in "field" is:
  194. * -- the position of a component within a SET or SEQUENCE, or
  195. * -- the PDU number assigned by the ASN.1 compiler, or
  196. * -- the position of a component within a SET OF or SEQUENCE OF, or
  197. * -- the position of a substring within a constructed string.
  198. * "fieldKind" is significant only if "field" is non-zero. So in
  199. * the example above, "fieldKind" has a value of pduNumber on the
  200. * call for the SET, and a value of setOrSequenceField on the calls for
  201. * the INTEGER and BOOLEAN.
  202. *
  203. * The field "fieldNumber" is a ordinal number indicating the position
  204. * of a component within a SET, SEQUENCE, SET OF, SEQUENCE OF, or
  205. * constructed string, or the PDU number assigned by the ASN.1 compiler.
  206. * So in the above example, "fieldNumber" is 1 (the PDU number) on the
  207. * call for the SET, 1 (the position of the component "age") on the
  208. * call for the INTEGER, and 2 (the position of the component "living"
  209. * on the call for the BOOLEAN.
  210. *
  211. * The field "depth" is the level of nesting of the value relative to
  212. * the outermost type, which has a "depth" value of 0. So in the above
  213. * example, "depth" is 0 on the call for the SET, and 1 on the calls
  214. * for the INTEGER and BOOLEAN.
  215. *
  216. * The field "primitive" is set to 1 if the builtin ASN.1 type is
  217. * simple (i.e., the primitive/constructed bit in the identifier
  218. * octet is set to 0), so it is 0 for SET, SEQUENCE, SET OF, SEQUENCE
  219. * OF, and CHOICE because they are structured. It is also set to 0 if
  220. * the type is an ANY. It is 1 for all other builtin types.
  221. *
  222. * The field "value" contains formatted data if the builtin type
  223. * is simple or ANY, regardless of tagging. Hence, in the above
  224. * example the call for SET will not contain any data in "value"
  225. * (because the builtin type is a constructed type), while for the
  226. * INTEGER and BOOLEAN types "value" will contain formatted data.
  227. * The maximum number of bytes of formatted data placed into "value"
  228. * is controlled by the external variable "asn1chop". If "asn1chop"
  229. * is set to 0 the maximum length of the traced value is determined
  230. * by the maximum internal buffer size variable, "ossblock".
  231. *
  232. * - once for each end-of-contents octets pair that is generated/
  233. * encountered while encoding/decoding a constructed value whose
  234. * length is of the indefinite-length form. A call with a "valueTrace"
  235. * record is always made to osstrace() before one is made with an
  236. * "endOfContentsTrace" record.
  237. *
  238. * A single "endOfContentsTrace" call is made to osstrace() for each
  239. * builtin type that is processed if the indefinite-length form of
  240. * encoding is used. If the builtin type is a structured type (CHOICE,
  241. * SET, SEQUENCE, SET OF, SEQUENCE OF) then there may be multiple
  242. * "valueTrace" and possible "endOfContentsTrace" calls made to
  243. * osstrace() before the matching "endOfContentsTrace" call is made.
  244. *
  245. * When the traceRecord "kind" field is set to endOfContentsTrace ...
  246. *
  247. * The field "taggingCount" contains the number of entries in the array
  248. * of "depth" indicators pointed to by tagging.depth, and reflects
  249. * the nesting of each pair of end-of-contents-octets associated with
  250. * the builtin type being encoded/decoded. So in the above example,
  251. * if indefinite-length encoding is being used, "taggingCount" will
  252. * be 1 on the call for the SET (since it has a single constructed
  253. * tag), and 2 on the call for the BOOLEAN (since it has two explicit
  254. * tags, for which the "constructed" bit in the encoding must be set).
  255. *
  256. * The field "tagging.depth" points to an array of "depth" indicators
  257. * that reflect the nesting of each pair of end-of-contents-octets
  258. * associated with a builtin type. So in the above example, if
  259. * indefinite-length encoding is being used, "tagging.depth" will point
  260. * to a single 0 on the call for the SET since it has a single tag for
  261. * which the constructed bit is set; while on the call for the BOOLEAN
  262. * "tagging.depth" will point to an array whose two entries are 1 and 2
  263. * since there are two explicit tags on the BOOLEAN.
  264. *
  265. * All other fields in the traceRecord are insignificant for an
  266. * endOfContentsTrace record.
  267. *
  268. * - once for each value that is skipped while decoding, with a "kind"
  269. * value of skippedFieldTrace. The skippedFieldTrace "kind" is just
  270. * means of indicating that an unexpected value was encountered in the
  271. * message and is being skipped. This is not an error if the type is
  272. * extensible.
  273. *
  274. * When the traceRecord "kind" field is set to skippedFieldTrace ...
  275. *
  276. * The field of the traceRecord are the same as when "kind" is set to
  277. * valueTrace, except that:
  278. * -- the skipped value is always reported as having one tag, hence
  279. * -- there is only one entry in the tag_length array.
  280. * -- the content of the field "value" is always "<skipped>", and
  281. * -- "typeReference" is always NULL.
  282. *
  283. * - once for each error message issued, in which case the "kind" field
  284. * is set to messageTrace.
  285. *
  286. * When the traceRecord "kind" field is set to messageTrace the "value"
  287. * field contains the error message, and other fields are
  288. * insignificant.
  289. */
  290. /* tag_length: describes the tag and length of a value.
  291. *
  292. * "tag" is 0 if the value is an ANY or CHOICE value, in which
  293. * case "definite" is not significant since ANY and CHOICE do
  294. * not have a tag of their own.
  295. *
  296. * If "tag" is not 0, "definite" indicates whether the value
  297. * is encoded using definite- or indefinite-length form.
  298. *
  299. * If "definite" is 1, "length" is the length of the value, else
  300. * it is not significant (indefinite-length encoding was used).
  301. */
  302. /* tagging: tag&length or end-of-contents-octets array.
  303. *
  304. * The tag and length array, tag_length, is present if this
  305. * is a valueTrace or skippedFieldTrace record. There is one array
  306. * entry for each tag present in the encoding of a given value, so
  307. * "[1] EXPLICIT [2] EXPLICIT INTEGER" gets three tag_length
  308. * array entries, where each entry describes the tag and length
  309. * information that precedes the value.
  310. *
  311. * The depth array, "depth", is present only if this is a
  312. * endOfContentsTrace record. There is one array entry for each
  313. * indefinite length present in the encoding of a value, so
  314. * "[1] EXPLICIT [2] EXPLICIT INTEGER" gets two "depth" entries
  315. * corresponding to the two explicit tags, where the value of each
  316. * tag indicates the depth of the tagged value relative to outmost type
  317. * that contains the INTEGER (e.g., relative to the containing SET).
  318. */
  319. /* Odds and ends:
  320. *
  321. * - When the value of a field is not significant the field is set to 0.
  322. */
  323. /* Augmenting for Packed Encoding Rule (PER) tracing.
  324. *
  325. * PER does not encode tag for any ASN.1 type. For some types, length
  326. * may or may not be encoded. PER does not always use octet aligned
  327. * encoding, therefore, the length should be in unit of bit.
  328. *
  329. * We classified ASN.1 types in to the following:
  330. *
  331. * (1). For all primitive types (including ANY), the prtType in traceRecord
  332. * is set to primeType, length is the total length of the content
  333. * in bits. The file osstrace.c prints length in the format
  334. * length = nbytes.nbits, and the total length should be 8*nbytes+nbits.
  335. * If the length is not encoded, "(not encoded)" will be added to the
  336. * output string. For BIT STRING with length longer than 64K (bits), and
  337. * for OCTET STRING longer that 16K (bytes), fragmentation is needed
  338. * and this is indicated by the string "fragment = n" after the length.
  339. * The fragmentation index is field fragment in traceRecord.
  340. * (2). For SEQUENCE and SET, prtType is seqsetType. In this case, the length
  341. * in traceRecord is the fieldcount of the SEQUENCE or SET.
  342. * (3). For SEQUENCE OF and SET OF, prtType is seqofType, and the length
  343. * in traceRecord is the count of components in the SEQUENCE OF (SET OF).
  344. * (4). For CHOICE, prtType is choiceType, and the length field in
  345. * traceRecord indicates the choice index.
  346. * (5). Total number of bits for the entire encoding is reported at the end
  347. * of encoding and decoding. The prtType for this trace is closeType.
  348. */
  349. #if defined(_MSC_VER) && (defined(_WIN32) || defined(WIN32))
  350. #pragma pack(pop, ossPacking)
  351. #elif defined(_MSC_VER) && (defined(_WINDOWS) || defined(_MSDOS))
  352. #pragma pack()
  353. #elif defined(__BORLANDC__) && (defined(__WIN32__) || defined(__MSDOS__))
  354. #pragma option -a.
  355. #elif defined(__IBMC__)
  356. #pragma pack()
  357. #elif defined(__WATCOMC__)
  358. #pragma pack(pop)
  359. #endif /* _MSC_VER && _WIN32 */
  360. #ifdef macintosh
  361. #pragma options align=reset
  362. #endif