From Ronnie Sahlberg: the LSA_REFERENCED_DOMAIN_LIST pointer in a
[obnox/wireshark/wip.git] / 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: packet-giop.h,v 1.7 2001/10/31 07:47:25 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
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   gchar *sub_name;               /* subdissector string name */
109   int sub_proto;                /* proto_XXX value from proto_register_protocol() */
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, 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 idl2eth -- 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 #ifdef G_HAVE_GINT64
337 extern gint64 get_CDR_long_long(tvbuff_t *tvb, int *offset,
338     gboolean stream_is_big_endian, int boundary);
339 #endif
340
341 /*
342  * Decode an Object type, and display it on the tree.
343  */
344
345 extern void get_CDR_object(tvbuff_t *tvb, packet_info *pinfo,
346     proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
347
348
349 /* Copy a 1 octet sequence from the tvbuff 
350  * which represents a octet, and convert
351  * it to an octet value.
352  * offset is then incremented by 1, to indicate the 1 octet which
353  * has been processed.
354  */
355
356 extern guint8 get_CDR_octet(tvbuff_t *tvb, int *offset);
357
358
359 /* Copy a sequence of octets from the tvbuff.
360  * Caller of this function must remember to free the 
361  * array pointed to by seq.
362  * This function also increments offset by len. 
363  */
364
365 extern void get_CDR_octet_seq(tvbuff_t *tvb, gchar **seq, int *offset, int len);
366
367 /* Copy a 2 octet sequence from the tvbuff 
368  * which represents a signed short value, and convert
369  * it to a signed short value, taking into account byte order.
370  * offset is first incremented so that it falls on a proper alignment
371  * boundary for short values.
372  * offset is then incremented by 2, to indicate the 2 octets which
373  * have been processed.
374  */
375
376 extern gint16 get_CDR_short(tvbuff_t *tvb, int *offset,
377     gboolean stream_is_big_endian, int boundary);
378
379
380 /* Copy an octet sequence from the tvbuff 
381  * which represents a string, and convert
382  * it to an string value, taking into account byte order.
383  * offset is first incremented so that it falls on a proper alignment
384  * boundary for string values. (begins with an unsigned long LI)
385  *
386  * String sequence is copied to a  buffer "seq". This must
387  * be freed by the calling program.
388  * offset is then incremented  , to indicate the  octets which
389  * have been processed.
390  *
391  * returns number of octets in the sequence
392  *
393  * Note: This function only supports single byte encoding at the
394  *       moment until I get a handle on multibyte encoding etc.
395  *
396  */
397
398 extern guint32 get_CDR_string(tvbuff_t *tvb, gchar **seq, int *offset,
399     gboolean stream_is_big_endian, int boundary);
400
401
402 /* Process a sequence of octets that represent the 
403  * Pseudo Object Type "TypeCode". Typecodes are used for example,
404  * by "Any values". 
405  * This function also increments offset to the correct position.
406  *
407  * It will parse the TypeCode and output data to the "tree" provided
408  * by the user
409  *
410  * It returns a guint32 representing a TCKind value. 
411  */
412
413 extern guint32 get_CDR_typeCode(tvbuff_t *tvb, proto_tree *tree, gint *offset,
414     gboolean stream_is_big_endian, int boundary, MessageHeader * header );
415
416 /* Copy a 4 octet sequence from the tvbuff 
417  * which represents an unsigned long value, and convert
418  * it to an unsigned long value, taking into account byte order.
419  * offset is first incremented so that it falls on a proper alignment
420  * boundary for unsigned long values.
421  * offset is then incremented by 4, to indicate the 4 octets which
422  * have been processed.
423  */
424
425 extern guint32 get_CDR_ulong(tvbuff_t *tvb, int *offset,
426     gboolean stream_is_big_endian, int boundary);
427
428
429 /* Copy an 8 octet sequence from the tvbuff 
430  * which represents an unsigned long long value, and convert
431  * it to an unsigned long long value, taking into account byte order.
432  * offset is first incremented so that it falls on a proper alignment
433  * boundary for unsigned long long values.
434  * offset is then incremented by 8, to indicate the 8 octets which
435  * have been processed.
436  */
437
438 #ifdef G_HAVE_GINT64
439 extern guint64 get_CDR_ulong_long(tvbuff_t *tvb, int *offset,
440     gboolean stream_is_big_endian, int boundary);
441 #endif
442
443
444 /* Copy a 2 octet sequence from the tvbuff 
445  * which represents an unsigned short value, and convert
446  * it to an unsigned short value, taking into account byte order.
447  * offset is first incremented so that it falls on a proper alignment
448  * boundary for unsigned short values.
449  * offset is then incremented by 2, to indicate the 2 octets which
450  * have been processed.
451  */
452
453 extern guint16 get_CDR_ushort(tvbuff_t *tvb, int *offset,
454     gboolean stream_is_big_endian, int boundary);
455
456
457 /* Copy a wchar from the tvbuff.
458  * Caller of this function must remember to free the 
459  * array pointed to by seq.
460  * This function also increments offset according to
461  * the wchar size.
462  *
463  * For GIOP 1.1 read 2 octets and return size -2. The
464  * negation means there is no size element in the packet
465  * and therefore no size to add to the tree.
466  *
467  * For GIOP 1.2 read size of wchar and the size
468  * octets. size is returned as a gint8.
469  *
470  * For both GIOP versions the wchar is returned
471  * as a printable string.
472  *
473  */
474
475 /* NOTE: This is very primitive in that it just reads
476  * the wchar as a series of octets and returns them
477  * to the user. No translation is attempted based on
478  * byte orientation, nor on code set. I.e it only 
479  * really reads past the wchar and increments the offset
480  * by the length of the octet sequence.
481  */
482
483 /* The "decoding" is done according to CORBA chapter 15.
484  * Wchar is not supported for GIOP 1.0.
485  */
486
487 extern gint8 get_CDR_wchar(tvbuff_t *tvb, gchar **seq, int *offset,
488     MessageHeader * header);
489
490
491 /* Copy a wstring from the tvbuff.
492  * Caller of this function must remember to free the 
493  * array pointed to by seq.
494  * This function also increments offset, according to
495  * wstring length. length is returned as guint32
496  */
497
498 /* NOTE: This is very primitive in that it just reads
499  * the wstring as a series of octets and returns them
500  * to the user. No translation is attempted based on
501  * byte orientation, nor on code set. I.e it only 
502  * really reads past the wstring and increments the offset
503  * by the length of the octet sequence.
504  */
505
506 /* The "decoding" is done according to CORBA chapter 15.
507  * Wstring is not supported for GIOP 1.0.
508  */
509
510 extern guint32 get_CDR_wstring(tvbuff_t *tvb, gchar **seq, int *offset,
511     gboolean stream_is_big_endian, int boundary, MessageHeader * header);
512
513
514
515 /*
516  *
517  * End of get_CDR_xxx accessors.
518  *
519  */
520
521
522
523 /* Determine the byte order from the GIOP MessageHeader */
524
525 extern gboolean is_big_endian (MessageHeader * header);
526
527 /*
528  * get_encap_info() for any encapsulation  (eg:sequences)
529  * we come across. updates the new boundary and endianess
530  * and *offset, and returns the sequence length.
531  */
532
533 extern guint32 get_CDR_encap_info(tvbuff_t *tvb, proto_tree *tree, gint *offset, 
534                            gboolean old_stream_is_big_endian, guint32 old_boundary,
535                            gboolean *new_stream_is_big_endian_ptr, guint32 *new_boundary_ptr );
536
537
538
539 /*
540  * Enums for TCkind
541  */
542
543 enum TCKind {
544   tk_null = 0,
545   tk_void,
546   tk_short,
547   tk_long,
548   tk_ushort,
549   tk_ulong,
550   tk_float,
551   tk_double,
552   tk_boolean,
553   tk_char,
554   tk_octet,
555   tk_any,
556   tk_TypeCode,
557   tk_Principal,
558   tk_objref,
559   tk_struct,
560   tk_union,
561   tk_enum,
562   tk_string,
563   tk_sequence,
564   tk_array,
565   tk_alias,
566   tk_except,
567   tk_longlong,
568   tk_ulonglong,
569   tk_longdouble,
570   tk_wchar,
571   tk_wstring,
572   tk_fixed,
573   tk_value,
574   tk_value_box,
575   tk_native,
576   tk_abstract_interface,
577
578   /* - none -   0xffffffff TODO */
579 };
580
581 #define tk_none  0xffffffff
582
583 typedef enum TCKind TCKind_t;
584
585
586 /*
587  * ServiceId's for ServiceContextList
588  *
589  * Chapter 13 Corba 2.4.2
590  */
591
592 #define IOP_ServiceId_TransactionService                0
593 #define IOP_ServiceId_CodeSets                          1
594 #define IOP_ServiceId_ChainBypassCheck                  2
595 #define IOP_ServiceId_ChainBypassInfo                   3
596 #define IOP_ServiceId_LogicalThreadId                   4
597 #define IOP_ServiceId_BI_DIR_IIOP                       5
598 #define IOP_ServiceId_SendingContextRunTime             6
599 #define IOP_ServiceId_INVOCATION_POLICIES               7
600 #define IOP_ServiceId_FORWARD_IDENTITY                  8
601 #define IOP_ServiceId_UnknownExceptionInfo              9
602
603 #endif /* PACKET_GIOP_H */