Get rid of get_ber_last_reated_item() and fix dissection of wIN-TriggerList.
[obnox/wireshark/wip.git] / epan / dissectors / packet-giop.h
1 /* packet-giop.h
2  * Declaration of routines for GIOP/IIOP (CDR) dissection
3  * Copyright 2000, Frank Singleton <frank.singleton@ericsson.com>
4  *
5  * Based on CORBAv2.4.2  Chapter 15 GIOP Description.
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef PACKET_GIOP_H
29 #define PACKET_GIOP_H
30
31 /*
32  * Useful visible data/structs
33  */
34
35 #define GIOP_HEADER_SIZE    12
36
37 typedef struct Version {
38   guint8 major;
39   guint8 minor;
40 } Version;
41
42
43 /*
44  * Useful data collected from message header. Note, this
45  * struct encapsulates useful data from GIOP header, as well
46  * as request_id and reply_status for use by sub dissectors.
47  */
48
49 typedef struct MessageHeader {
50
51   /* Common Data */
52
53   guint8 magic[4];
54   Version GIOP_version;
55   guint8 flags;                 /* byte_order in 1.0 */
56   guint8 message_type;
57   guint32 message_size;
58   guint32 req_id;               /* request id in MSG  */
59
60   /* MSG dependant data */
61
62   guint32 rep_status;           /* reply status in MSG if available */
63   gchar *exception_id;             /* exception string if a USER EXCEPTION occurs  */
64
65 } MessageHeader;
66
67 typedef enum MsgType {
68   Request = 0,
69   Reply,
70   CancelRequest,
71   LocateRequest,
72   LocateReply,
73   CloseConnection,
74   MessageError,
75   Fragment                      /* GIOP 1.1 only */
76
77 } MsgType;
78
79
80
81 /*
82  * Reply Status
83  *
84  */
85
86 typedef enum ReplyStatusType {
87   NO_EXCEPTION = 0,
88   USER_EXCEPTION,
89   SYSTEM_EXCEPTION,
90   LOCATION_FORWARD,
91   LOCATION_FORWARD_PERM,        /* new for GIOP 1.2 */
92   NEEDS_ADDRESSING_MODE         /* new for GIOP 1.2 */
93 } ReplyStatusType;
94
95 /*
96  * Prototype for sub dissector function calls.
97  */
98
99 typedef gboolean (giop_sub_dissector_t)(tvbuff_t *, packet_info *, proto_tree *, int *,
100                                   MessageHeader *, gchar * , gchar *);
101
102 /*
103  * Generic Subdissector handle, wraps user info.
104  */
105
106 typedef struct giop_sub_handle {
107   giop_sub_dissector_t *sub_fn;  /* ptr to sub dissector function */
108   const gchar *sub_name;         /* subdissector string name */
109   protocol_t *sub_proto;         /* protocol_t for subprotocol */
110 } giop_sub_handle_t;
111
112 /* Main GIOP entry point */
113
114 extern gboolean dissect_giop(tvbuff_t *, packet_info *, proto_tree *); /* new interface */
115
116 /*
117  * GIOP Users register interest via this function.
118  * This is for heuristic dissection
119  */
120
121 extern void register_giop_user(giop_sub_dissector_t *sub, const gchar *name,
122     int sub_proto);
123
124 /*
125  * GIOP Users remove interest via this function.
126  * This is for heuristic dissection
127  */
128
129 extern void delete_giop_user(giop_sub_dissector_t *sub, gchar *name);
130
131
132 /*
133  * GIOP Users register their module and interface names via this function.
134  * This is for explicit dissection.
135  */
136
137 extern void register_giop_user_module(giop_sub_dissector_t *sub, gchar *name,
138     gchar *module, int sub_proto);
139
140 /*
141  * GIOP Users remove their module and interface names via this function.
142  * This is for explicit dissection.
143  */
144
145 extern void delete_giop_user_module(giop_sub_dissector_t *sub, gchar *name,
146     gchar *module);
147
148
149 /*
150  * General CDR accessors start here. They are listed in alphabetical
151  * order. They may however, belong to 1 of 3 distinct CDR data types.
152  *
153  * - Primitive
154  * - OMG IDL Constructed Types
155  * - Pseudo Object Types
156  *
157  *
158  * Altough some of these look redundant, I have separated them
159  * out for all CDR types, to assist in auto generation of
160  * IDL dissectors later, see idl2wrs -- FS
161  *
162  */
163
164
165 /*
166  * Gets data of type any. This is encoded as a TypeCode
167  * followed by the encoded value.
168  *
169  * Data is added to tree directly if present.
170  */
171
172 extern void get_CDR_any(tvbuff_t *tvb, proto_tree *tree, gint *offset,
173     gboolean stream_is_big_endian, int boundary, MessageHeader * header );
174
175
176 /* Copy a 1 octet sequence from the tvbuff
177  * which represents a boolean value, and convert
178  * it to a boolean value.
179  * Offset is then incremented by 1, to indicate the 1 octet which
180  * has been processed.
181  */
182
183 extern gboolean get_CDR_boolean(tvbuff_t *tvb, int *offset);
184
185
186 /* Copy a 1 octet sequence from the tvbuff
187  * which represents a char, and convert
188  * it to an char value.
189  * offset is then incremented by 1, to indicate the 1 octet which
190  * has been processed.
191  */
192
193 extern guint8 get_CDR_char(tvbuff_t *tvb, int *offset);
194
195
196
197 /*
198  * Floating Point Data Type double IEEE 754-1985
199  *
200  * Copy an 8 octet sequence from the tvbuff
201  * which represents a double value, and convert
202  * it to a double value, taking into account byte order.
203  * offset is first incremented so that it falls on a proper alignment
204  * boundary for double values.
205  * offset is then incremented by 8, to indicate the 8 octets which
206  * have been processed.
207  */
208
209 extern gdouble get_CDR_double(tvbuff_t *tvb, int *offset,
210     gboolean stream_is_big_endian, int boundary);
211
212
213 /* Copy a 4 octet sequence from the tvbuff
214  * which represents an enum value, and convert
215  * it to an enum value, taking into account byte order.
216  * offset is first incremented so that it falls on a proper alignment
217  * boundary for an enum (4)
218  * offset is then incremented by 4, to indicate the 4 octets which
219  * have been processed.
220  *
221  * Enum values are encoded as unsigned long.
222  */
223
224 extern guint32 get_CDR_enum(tvbuff_t *tvb, int *offset,
225     gboolean stream_is_big_endian, int boundary);
226
227
228
229 /*
230  * Copy an octet sequence from the tvbuff
231  * which represents a Fixed point decimal type, and create a string representing
232  * a Fixed point decimal type. There are no alignment restrictions.
233  * Size and scale of fixed decimal type is determined by IDL.
234  *
235  * digits - IDL specified number of "digits" for this fixed type
236  * scale  - IDL specified "scale" for this fixed type
237  *
238  *
239  * eg: typedef fixed <5,2> fixed_t;
240  *     could represent numbers like 123.45, 789.12,
241  *
242  *
243  * As the fixed type could be any size, I will not try to fit it into our
244  * simple types like gdouble or glong etc. I will just create a string buffer holding
245  * a  representation (after scale is applied), and with a decimal point or zero padding
246  * inserted at the right place if necessary. The string is null terminated
247  *
248  * so string may look like
249  *
250  *
251  *  "+1.234" or "-3456.78" or "1234567309475760377365465897891" or "-2789000000" etc
252  *
253  * According to spec, digits <= 31
254  * and scale is positive (except for constants eg: 1000 has digit=1 and implied scale = -3)
255  * or <4,0> ?
256  *
257  * User must remember to free the buffer
258  *
259  */
260
261 extern void get_CDR_fixed(tvbuff_t *tvb, gchar **seq, gint *offset,
262     guint32 digits, gint32 scale);
263
264
265
266 /*
267  * Floating Point Data Type float IEEE 754-1985
268  *
269  * Copy a 4 octet sequence from the tvbuff
270  * which represents a float value, and convert
271  * it to a float value, taking into account byte order.
272  * offset is first incremented so that it falls on a proper alignment
273  * boundary for float values.
274  * offset is then incremented by 4, to indicate the 4 octets which
275  * have been processed.
276  */
277
278 extern gfloat get_CDR_float(tvbuff_t *tvb, int *offset,
279     gboolean stream_is_big_endian, int boundary);
280
281
282 /*
283  * Decode an Interface type, and display it on the tree.
284  */
285
286 extern void get_CDR_interface(tvbuff_t *tvb, packet_info *pinfo,
287     proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
288
289
290 /* Copy a 4 octet sequence from the tvbuff
291  * which represents a signed long value, and convert
292  * it to an signed long vaule, taking into account byte order.
293  * offset is first incremented so that it falls on a proper alignment
294  * boundary for long values.
295  * offset is then incremented by 4, to indicate the 4 octets which
296  * have been processed.
297  */
298
299 extern gint32 get_CDR_long(tvbuff_t *tvb, int *offset,
300     gboolean stream_is_big_endian, int boundary);
301
302
303
304 /* Copy a 16 octet sequence from the tvbuff
305  * which represents a long double value, and convert
306  * it to a long double value, taking into account byte order.
307  * offset is first incremented so that it falls on a proper alignment
308  * boundary for  long double values.
309  * offset is then incremented by 16, to indicate the 16 octets which
310  * have been processed.
311  */
312
313 #ifdef G_HAVE_GLONG_DOUBLE
314
315 extern glong_double get_CDR_long_double(tvbuff_t *tvb, int *offset,
316     gboolean stream_is_big_endian, int boundary);
317 #else
318
319 /* FIX -- Cast long double to gdouble until I figure this out -- FS*/
320
321 extern gdouble get_CDR_long_double(tvbuff_t *tvb, int *offset,
322     gboolean stream_is_big_endian, int boundary);
323
324 #endif
325
326
327 /* Copy an 8 octet sequence from the tvbuff
328  * which represents a signed long long value, and convert
329  * it to a signed long long value, taking into account byte order.
330  * offset is first incremented so that it falls on a proper alignment
331  * boundary for long long values.
332  * offset is then incremented by 8, to indicate the 8 octets which
333  * have been processed.
334  */
335
336 extern gint64 get_CDR_long_long(tvbuff_t *tvb, int *offset,
337     gboolean stream_is_big_endian, int boundary);
338
339 /*
340  * Decode an Object type, and display it on the tree.
341  */
342
343 extern void get_CDR_object(tvbuff_t *tvb, packet_info *pinfo,
344     proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
345
346
347 /* Copy a 1 octet sequence from the tvbuff
348  * which represents a octet, and convert
349  * it to an octet value.
350  * offset is then incremented by 1, to indicate the 1 octet which
351  * has been processed.
352  */
353
354 extern guint8 get_CDR_octet(tvbuff_t *tvb, int *offset);
355
356
357 /* Copy a sequence of octets from the tvbuff.
358  * Caller of this function must remember to free the
359  * array pointed to by seq.
360  * This function also increments offset by len.
361  */
362
363 extern void get_CDR_octet_seq(tvbuff_t *tvb, gchar **seq, int *offset, guint32 len);
364
365 /* Copy a 2 octet sequence from the tvbuff
366  * which represents a signed short value, and convert
367  * it to a signed short value, taking into account byte order.
368  * offset is first incremented so that it falls on a proper alignment
369  * boundary for short values.
370  * offset is then incremented by 2, to indicate the 2 octets which
371  * have been processed.
372  */
373
374 extern gint16 get_CDR_short(tvbuff_t *tvb, int *offset,
375     gboolean stream_is_big_endian, int boundary);
376
377
378 /* Copy an octet sequence from the tvbuff
379  * which represents a string, and convert
380  * it to an string value, taking into account byte order.
381  * offset is first incremented so that it falls on a proper alignment
382  * boundary for string values. (begins with an unsigned long LI)
383  *
384  * String sequence is copied to a  buffer "seq". This must
385  * be freed by the calling program.
386  * offset is then incremented  , to indicate the  octets which
387  * have been processed.
388  *
389  * returns number of octets in the sequence
390  *
391  * Note: This function only supports single byte encoding at the
392  *       moment until I get a handle on multibyte encoding etc.
393  *
394  */
395
396 extern guint32 get_CDR_string(tvbuff_t *tvb, gchar **seq, int *offset,
397     gboolean stream_is_big_endian, int boundary);
398
399
400 /* Process a sequence of octets that represent the
401  * Pseudo Object Type "TypeCode". Typecodes are used for example,
402  * by "Any values".
403  * This function also increments offset to the correct position.
404  *
405  * It will parse the TypeCode and output data to the "tree" provided
406  * by the user
407  *
408  * It returns a guint32 representing a TCKind value.
409  */
410
411 extern guint32 get_CDR_typeCode(tvbuff_t *tvb, proto_tree *tree, gint *offset,
412     gboolean stream_is_big_endian, int boundary, MessageHeader * header );
413
414 /* Copy a 4 octet sequence from the tvbuff
415  * which represents an unsigned long value, and convert
416  * it to an unsigned long value, taking into account byte order.
417  * offset is first incremented so that it falls on a proper alignment
418  * boundary for unsigned long values.
419  * offset is then incremented by 4, to indicate the 4 octets which
420  * have been processed.
421  */
422
423 extern guint32 get_CDR_ulong(tvbuff_t *tvb, int *offset,
424     gboolean stream_is_big_endian, int boundary);
425
426
427 /* Copy an 8 octet sequence from the tvbuff
428  * which represents an unsigned long long value, and convert
429  * it to an unsigned long long value, taking into account byte order.
430  * offset is first incremented so that it falls on a proper alignment
431  * boundary for unsigned long long values.
432  * offset is then incremented by 8, to indicate the 8 octets which
433  * have been processed.
434  */
435
436 extern guint64 get_CDR_ulong_long(tvbuff_t *tvb, int *offset,
437     gboolean stream_is_big_endian, int boundary);
438
439 /* Copy a 2 octet sequence from the tvbuff
440  * which represents an unsigned short value, and convert
441  * it to an unsigned short value, taking into account byte order.
442  * offset is first incremented so that it falls on a proper alignment
443  * boundary for unsigned short values.
444  * offset is then incremented by 2, to indicate the 2 octets which
445  * have been processed.
446  */
447
448 extern guint16 get_CDR_ushort(tvbuff_t *tvb, int *offset,
449     gboolean stream_is_big_endian, int boundary);
450
451
452 /* Copy a wchar from the tvbuff.
453  * Caller of this function must remember to free the
454  * array pointed to by seq.
455  * This function also increments offset according to
456  * the wchar size.
457  *
458  * For GIOP 1.1 read 2 octets and return size -2. The
459  * negation means there is no size element in the packet
460  * and therefore no size to add to the tree.
461  *
462  * For GIOP 1.2 read size of wchar and the size
463  * octets. size is returned as a gint8.
464  *
465  * For both GIOP versions the wchar is returned
466  * as a printable string.
467  *
468  */
469
470 /* NOTE: This is very primitive in that it just reads
471  * the wchar as a series of octets and returns them
472  * to the user. No translation is attempted based on
473  * byte orientation, nor on code set. I.e it only
474  * really reads past the wchar and increments the offset
475  * by the length of the octet sequence.
476  */
477
478 /* The "decoding" is done according to CORBA chapter 15.
479  * Wchar is not supported for GIOP 1.0.
480  */
481
482 extern gint get_CDR_wchar(tvbuff_t *tvb, gchar **seq, int *offset,
483     MessageHeader * header);
484
485
486 /* Copy a wstring from the tvbuff.
487  * Caller of this function must remember to free the
488  * array pointed to by seq.
489  * This function also increments offset, according to
490  * wstring length. length is returned as guint32
491  */
492
493 /* NOTE: This is very primitive in that it just reads
494  * the wstring as a series of octets and returns them
495  * to the user. No translation is attempted based on
496  * byte orientation, nor on code set. I.e it only
497  * really reads past the wstring and increments the offset
498  * by the length of the octet sequence.
499  */
500
501 /* The "decoding" is done according to CORBA chapter 15.
502  * Wstring is not supported for GIOP 1.0.
503  */
504
505 extern guint32 get_CDR_wstring(tvbuff_t *tvb, gchar **seq, int *offset,
506     gboolean stream_is_big_endian, int boundary, MessageHeader * header);
507
508
509
510 /*
511  *
512  * End of get_CDR_xxx accessors.
513  *
514  */
515
516
517
518 /* Determine the byte order from the GIOP MessageHeader */
519
520 extern gboolean is_big_endian (MessageHeader * header);
521
522 /*
523  * get_encap_info() for any encapsulation  (eg:sequences)
524  * we come across. updates the new boundary and endianess
525  * and *offset, and returns the sequence length.
526  */
527
528 extern guint32 get_CDR_encap_info(tvbuff_t *tvb, proto_tree *tree, gint *offset,
529                            gboolean old_stream_is_big_endian, guint32 old_boundary,
530                            gboolean *new_stream_is_big_endian_ptr, guint32 *new_boundary_ptr );
531
532 /* Take in an array of char and create a new string.
533  * Replace non-printable characters with periods.
534  *
535  * The array may contain \0's so dont use strdup
536  * The string is \0 terminated, and thus longer than
537  * the initial sequence.
538  * Caller must free the new string.
539  */
540
541 extern gchar * make_printable_string (gchar *in, guint32 len);
542
543 /*
544  * Enums for TCkind
545  */
546
547 enum TCKind {
548   tk_null = 0,
549   tk_void,
550   tk_short,
551   tk_long,
552   tk_ushort,
553   tk_ulong,
554   tk_float,
555   tk_double,
556   tk_boolean,
557   tk_char,
558   tk_octet,
559   tk_any,
560   tk_TypeCode,
561   tk_Principal,
562   tk_objref,
563   tk_struct,
564   tk_union,
565   tk_enum,
566   tk_string,
567   tk_sequence,
568   tk_array,
569   tk_alias,
570   tk_except,
571   tk_longlong,
572   tk_ulonglong,
573   tk_longdouble,
574   tk_wchar,
575   tk_wstring,
576   tk_fixed,
577   tk_value,
578   tk_value_box,
579   tk_native,
580   tk_abstract_interface
581
582   /* - none -   0xffffffff TODO */
583 };
584
585 #define tk_none  0xffffffff
586
587 typedef enum TCKind TCKind_t;
588
589
590 /*
591  * ServiceId's for ServiceContextList
592  *
593  * Chapter 13 Corba 2.4.2
594  */
595
596 #define IOP_ServiceId_TransactionService                0
597 #define IOP_ServiceId_CodeSets                          1
598 #define IOP_ServiceId_ChainBypassCheck                  2
599 #define IOP_ServiceId_ChainBypassInfo                   3
600 #define IOP_ServiceId_LogicalThreadId                   4
601 #define IOP_ServiceId_BI_DIR_IIOP                       5
602 #define IOP_ServiceId_SendingContextRunTime             6
603 #define IOP_ServiceId_INVOCATION_POLICIES               7
604 #define IOP_ServiceId_FORWARD_IDENTITY                  8
605 #define IOP_ServiceId_UnknownExceptionInfo              9
606
607 #endif /* PACKET_GIOP_H */