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