Export libwireshark symbols using WS_DLL_PUBLIC define
[jlayton/wireshark.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #ifndef PACKET_GIOP_H
29 #define PACKET_GIOP_H
30
31 #include "ws_symbol_export.h"
32
33 /*
34  * Useful visible data/structs
35  */
36
37 #define GIOP_HEADER_SIZE    12
38 #define GIOP_MAGIC_NUMBER       0x47494F50  /* "GIOP" */
39
40 typedef struct Version {
41   guint8 major;
42   guint8 minor;
43 } Version;
44
45
46 /*
47  * Useful data collected from message header. Note, this
48  * struct encapsulates useful data from GIOP header, as well
49  * as request_id and reply_status for use by sub dissectors.
50  */
51
52 typedef struct MessageHeader {
53
54   /* Common Data */
55
56   guint8 magic[4];
57   Version GIOP_version;
58   guint8 flags;                 /* byte_order in 1.0 */
59   guint8 message_type;
60   guint32 message_size;
61   guint32 req_id;               /* request id in MSG  */
62
63   /* MSG dependant data */
64
65   guint32 rep_status;           /* reply status in MSG if available */
66   gchar *exception_id;             /* exception string if a USER EXCEPTION occurs  */
67
68 } MessageHeader;
69
70 typedef enum MsgType {
71   Request = 0,
72   Reply,
73   CancelRequest,
74   LocateRequest,
75   LocateReply,
76   CloseConnection,
77   MessageError,
78   Fragment                      /* GIOP 1.1 only */
79
80 } MsgType;
81
82
83
84 /*
85  * Reply Status
86  *
87  */
88
89 typedef enum ReplyStatusType {
90   NO_EXCEPTION = 0,
91   USER_EXCEPTION,
92   SYSTEM_EXCEPTION,
93   LOCATION_FORWARD,
94   LOCATION_FORWARD_PERM,        /* new for GIOP 1.2 */
95   NEEDS_ADDRESSING_MODE         /* new for GIOP 1.2 */
96 } ReplyStatusType;
97
98 /*
99  * Prototype for sub dissector function calls.
100  */
101
102 typedef gboolean (giop_sub_dissector_t)(tvbuff_t *, packet_info *, proto_tree *, int *,
103                                   MessageHeader *, const gchar * , gchar *);
104
105 /*
106  * Generic Subdissector handle, wraps user info.
107  */
108
109 typedef struct giop_sub_handle {
110   giop_sub_dissector_t *sub_fn;  /* ptr to sub dissector function */
111   const gchar *sub_name;         /* subdissector string name */
112   protocol_t *sub_proto;         /* protocol_t for subprotocol */
113 } giop_sub_handle_t;
114
115 /* Main GIOP entry point */
116
117 extern gboolean dissect_giop(tvbuff_t *, packet_info *, proto_tree *); /* new interface */
118
119 /*
120  * GIOP Users register interest via this function.
121  * This is for heuristic dissection
122  */
123
124 WS_DLL_PUBLIC void register_giop_user(giop_sub_dissector_t *sub, const gchar *name,
125     int sub_proto);
126
127 /*
128  * GIOP Users remove interest via this function.
129  * This is for heuristic dissection
130  */
131
132 extern void delete_giop_user(giop_sub_dissector_t *sub, gchar *name);
133
134
135 /*
136  * GIOP Users register their module and interface names via this function.
137  * This is for explicit dissection.
138  */
139
140 WS_DLL_PUBLIC void register_giop_user_module(giop_sub_dissector_t *sub, const gchar *name,
141     const gchar *module, int sub_proto);
142
143 /*
144  * GIOP Users remove their module and interface names via this function.
145  * This is for explicit dissection.
146  */
147
148 extern void delete_giop_user_module(giop_sub_dissector_t *sub, gchar *name,
149     gchar *module);
150
151
152 /*
153  * General CDR accessors start here. They are listed in alphabetical
154  * order. They may however, belong to 1 of 3 distinct CDR data types.
155  *
156  * - Primitive
157  * - OMG IDL Constructed Types
158  * - Pseudo Object Types
159  *
160  *
161  * Altough some of these look redundant, I have separated them
162  * out for all CDR types, to assist in auto generation of
163  * IDL dissectors later, see idl2wrs -- FS
164  *
165  */
166
167
168 /*
169  * Gets data of type any. This is encoded as a TypeCode
170  * followed by the encoded value.
171  *
172  * Data is added to tree directly if present.
173  */
174
175 WS_DLL_PUBLIC void get_CDR_any(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item,
176                         gint *offset, gboolean stream_is_big_endian, 
177                         int boundary, MessageHeader * header);
178
179
180 /* Copy a 1 octet sequence from the tvbuff
181  * which represents a boolean value, and convert
182  * it to a boolean value.
183  * Offset is then incremented by 1, to indicate the 1 octet which
184  * has been processed.
185  */
186
187 WS_DLL_PUBLIC gboolean get_CDR_boolean(tvbuff_t *tvb, int *offset);
188
189
190 /* Copy a 1 octet sequence from the tvbuff
191  * which represents a char, and convert
192  * it to an char value.
193  * offset is then incremented by 1, to indicate the 1 octet which
194  * has been processed.
195  */
196
197 WS_DLL_PUBLIC guint8 get_CDR_char(tvbuff_t *tvb, int *offset);
198
199
200
201 /*
202  * Floating Point Data Type double IEEE 754-1985
203  *
204  * Copy an 8 octet sequence from the tvbuff
205  * which represents a double value, and convert
206  * it to a double value, taking into account byte order.
207  * offset is first incremented so that it falls on a proper alignment
208  * boundary for double values.
209  * offset is then incremented by 8, to indicate the 8 octets which
210  * have been processed.
211  */
212
213 WS_DLL_PUBLIC gdouble get_CDR_double(tvbuff_t *tvb, int *offset,
214     gboolean stream_is_big_endian, int boundary);
215
216
217 /* Copy a 4 octet sequence from the tvbuff
218  * which represents an enum value, and convert
219  * it to an enum value, taking into account byte order.
220  * offset is first incremented so that it falls on a proper alignment
221  * boundary for an enum (4)
222  * offset is then incremented by 4, to indicate the 4 octets which
223  * have been processed.
224  *
225  * Enum values are encoded as unsigned long.
226  */
227
228 WS_DLL_PUBLIC guint32 get_CDR_enum(tvbuff_t *tvb, int *offset,
229     gboolean stream_is_big_endian, int boundary);
230
231
232
233 /*
234  * Copy an octet sequence from the tvbuff
235  * which represents a Fixed point decimal type, and create a string representing
236  * a Fixed point decimal type. There are no alignment restrictions.
237  * Size and scale of fixed decimal type is determined by IDL.
238  *
239  * digits - IDL specified number of "digits" for this fixed type
240  * scale  - IDL specified "scale" for this fixed type
241  *
242  *
243  * eg: typedef fixed <5,2> fixed_t;
244  *     could represent numbers like 123.45, 789.12,
245  *
246  *
247  * As the fixed type could be any size, I will not try to fit it into our
248  * simple types like gdouble or glong etc. I will just create a string buffer holding
249  * a  representation (after scale is applied), and with a decimal point or zero padding
250  * inserted at the right place if necessary. The string is null terminated
251  *
252  * so string may look like
253  *
254  *
255  *  "+1.234" or "-3456.78" or "1234567309475760377365465897891" or "-2789000000" etc
256  *
257  * According to spec, digits <= 31
258  * and scale is positive (except for constants eg: 1000 has digit=1 and implied scale = -3)
259  * or <4,0> ?
260  *
261  */
262
263 WS_DLL_PUBLIC void get_CDR_fixed(tvbuff_t *tvb, packet_info *pinfo, proto_item *item, 
264                           gchar **seq, gint *offset, guint32 digits, gint32 scale);
265
266
267 /*
268  * Floating Point Data Type float IEEE 754-1985
269  *
270  * Copy a 4 octet sequence from the tvbuff
271  * which represents a float value, and convert
272  * it to a float value, taking into account byte order.
273  * offset is first incremented so that it falls on a proper alignment
274  * boundary for float values.
275  * offset is then incremented by 4, to indicate the 4 octets which
276  * have been processed.
277  */
278
279 WS_DLL_PUBLIC gfloat get_CDR_float(tvbuff_t *tvb, int *offset,
280     gboolean stream_is_big_endian, int boundary);
281
282
283 /*
284  * Decode an Interface type, and display it on the tree.
285  */
286
287 WS_DLL_PUBLIC void get_CDR_interface(tvbuff_t *tvb, packet_info *pinfo,
288     proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
289
290
291 /* Copy a 4 octet sequence from the tvbuff
292  * which represents a signed long value, and convert
293  * it to an signed long vaule, taking into account byte order.
294  * offset is first incremented so that it falls on a proper alignment
295  * boundary for long values.
296  * offset is then incremented by 4, to indicate the 4 octets which
297  * have been processed.
298  */
299
300 WS_DLL_PUBLIC gint32 get_CDR_long(tvbuff_t *tvb, int *offset,
301     gboolean stream_is_big_endian, int boundary);
302
303
304
305 /* Copy a 16 octet sequence from the tvbuff
306  * which represents a long double value, and convert
307  * it to a long double value, taking into account byte order.
308  * offset is first incremented so that it falls on a proper alignment
309  * boundary for  long double values.
310  * offset is then incremented by 16, to indicate the 16 octets which
311  * have been processed.
312  */
313
314 #ifdef G_HAVE_GLONG_DOUBLE
315
316 WS_DLL_PUBLIC glong_double get_CDR_long_double(tvbuff_t *tvb, int *offset,
317     gboolean stream_is_big_endian, int boundary);
318 #else
319
320 /* FIX -- Cast long double to gdouble until I figure this out -- FS*/
321
322 WS_DLL_PUBLIC gdouble get_CDR_long_double(tvbuff_t *tvb, int *offset,
323     gboolean stream_is_big_endian, int boundary);
324
325 #endif
326
327
328 /* Copy an 8 octet sequence from the tvbuff
329  * which represents a signed long long value, and convert
330  * it to a signed long long value, taking into account byte order.
331  * offset is first incremented so that it falls on a proper alignment
332  * boundary for long long values.
333  * offset is then incremented by 8, to indicate the 8 octets which
334  * have been processed.
335  */
336
337 WS_DLL_PUBLIC gint64 get_CDR_long_long(tvbuff_t *tvb, int *offset,
338     gboolean stream_is_big_endian, int boundary);
339
340 /*
341  * Decode an Object type, and display it on the tree.
342  */
343
344 WS_DLL_PUBLIC void get_CDR_object(tvbuff_t *tvb, packet_info *pinfo,
345     proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
346
347
348 /* Copy a 1 octet sequence from the tvbuff
349  * which represents a octet, and convert
350  * it to an octet value.
351  * offset is then incremented by 1, to indicate the 1 octet which
352  * has been processed.
353  */
354
355 WS_DLL_PUBLIC guint8 get_CDR_octet(tvbuff_t *tvb, int *offset);
356
357
358 /* Copy a sequence of octets from the tvbuff.
359  * Caller of this function must remember to free the
360  * array pointed to by seq.
361  * This function also increments offset by len.
362  */
363
364 WS_DLL_PUBLIC void get_CDR_octet_seq(tvbuff_t *tvb, const gchar **seq, int *offset, guint32 len);
365
366 /* Copy a 2 octet sequence from the tvbuff
367  * which represents a signed short value, and convert
368  * it to a signed short value, taking into account byte order.
369  * offset is first incremented so that it falls on a proper alignment
370  * boundary for short values.
371  * offset is then incremented by 2, to indicate the 2 octets which
372  * have been processed.
373  */
374
375 WS_DLL_PUBLIC gint16 get_CDR_short(tvbuff_t *tvb, int *offset,
376     gboolean stream_is_big_endian, int boundary);
377
378
379 extern void giop_add_CDR_string(proto_tree *tree, tvbuff_t *tvb, int *offset,
380     gboolean stream_is_big_endian, int boundary,
381     int hf);
382
383 /* Copy an octet sequence from the tvbuff
384  * which represents a string, and convert
385  * it to an string value, taking into account byte order.
386  * offset is first incremented so that it falls on a proper alignment
387  * boundary for string values. (begins with an unsigned long LI)
388  *
389  * String sequence is copied to a  buffer "seq". This must
390  * be freed by the calling program.
391  * offset is then incremented  , to indicate the  octets which
392  * have been processed.
393  *
394  * returns number of octets in the sequence
395  *
396  * Note: This function only supports single byte encoding at the
397  *       moment until I get a handle on multibyte encoding etc.
398  *
399  */
400
401 WS_DLL_PUBLIC guint32 get_CDR_string(tvbuff_t *tvb, const gchar **seq, int *offset,
402     gboolean stream_is_big_endian, int boundary);
403
404
405 /* Process a sequence of octets that represent the
406  * Pseudo Object Type "TypeCode". Typecodes are used for example,
407  * by "Any values".
408  * This function also increments offset to the correct position.
409  *
410  * It will parse the TypeCode and output data to the "tree" provided
411  * by the user
412  *
413  * It returns a guint32 representing a TCKind value.
414  */
415
416 WS_DLL_PUBLIC guint32 get_CDR_typeCode(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, gint *offset,
417     gboolean stream_is_big_endian, int boundary, MessageHeader * header );
418
419 /* Copy a 4 octet sequence from the tvbuff
420  * which represents an unsigned long value, and convert
421  * it to an unsigned long value, taking into account byte order.
422  * offset is first incremented so that it falls on a proper alignment
423  * boundary for unsigned long values.
424  * offset is then incremented by 4, to indicate the 4 octets which
425  * have been processed.
426  */
427
428 WS_DLL_PUBLIC guint32 get_CDR_ulong(tvbuff_t *tvb, int *offset,
429     gboolean stream_is_big_endian, int boundary);
430
431
432 /* Copy an 8 octet sequence from the tvbuff
433  * which represents an unsigned long long value, and convert
434  * it to an unsigned long long value, taking into account byte order.
435  * offset is first incremented so that it falls on a proper alignment
436  * boundary for unsigned long long values.
437  * offset is then incremented by 8, to indicate the 8 octets which
438  * have been processed.
439  */
440
441 WS_DLL_PUBLIC guint64 get_CDR_ulong_long(tvbuff_t *tvb, int *offset,
442     gboolean stream_is_big_endian, int boundary);
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 WS_DLL_PUBLIC 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 WS_DLL_PUBLIC gint get_CDR_wchar(tvbuff_t *tvb, const 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 WS_DLL_PUBLIC guint32 get_CDR_wstring(tvbuff_t *tvb, const 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 WS_DLL_PUBLIC 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 WS_DLL_PUBLIC 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 /* Take in an array of char and create a new ephemeral string.
538  * Replace non-printable characters with periods.
539  *
540  * The array may contain \0's so dont use strdup
541  * The string is \0 terminated, and thus longer than
542  * the initial sequence.
543  */
544
545 WS_DLL_PUBLIC gchar * make_printable_string (const gchar *in, guint32 len);
546
547 /*
548  * Enums for TCkind
549  */
550
551 enum TCKind {
552   tk_null = 0,
553   tk_void,
554   tk_short,
555   tk_long,
556   tk_ushort,
557   tk_ulong,
558   tk_float,
559   tk_double,
560   tk_boolean,
561   tk_char,
562   tk_octet,
563   tk_any,
564   tk_TypeCode,
565   tk_Principal,
566   tk_objref,
567   tk_struct,
568   tk_union,
569   tk_enum,
570   tk_string,
571   tk_sequence,
572   tk_array,
573   tk_alias,
574   tk_except,
575   tk_longlong,
576   tk_ulonglong,
577   tk_longdouble,
578   tk_wchar,
579   tk_wstring,
580   tk_fixed,
581   tk_value,
582   tk_value_box,
583   tk_native,
584   tk_abstract_interface
585
586   /* - none -   0xffffffff TODO */
587 };
588
589 #define tk_none  0xffffffff
590
591 typedef enum TCKind TCKind_t;
592
593
594 /*
595  * ServiceId's for ServiceContextList
596  *
597  * Chapter 13 Corba 2.4.2
598  */
599
600 #define IOP_ServiceId_TransactionService                0
601 #define IOP_ServiceId_CodeSets                          1
602 #define IOP_ServiceId_ChainBypassCheck                  2
603 #define IOP_ServiceId_ChainBypassInfo                   3
604 #define IOP_ServiceId_LogicalThreadId                   4
605 #define IOP_ServiceId_BI_DIR_IIOP                       5
606 #define IOP_ServiceId_SendingContextRunTime             6
607 #define IOP_ServiceId_INVOCATION_POLICIES               7
608 #define IOP_ServiceId_FORWARD_IDENTITY                  8
609 #define IOP_ServiceId_UnknownExceptionInfo              9
610
611 #endif /* PACKET_GIOP_H */