From Gerhard Gappmeier via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5410 :
[obnox/wireshark/wip.git] / plugins / opcua / opcua_extensionobjecttable.c
1 /******************************************************************************
2 ** $Id$
3 **
4 ** Copyright (C) 2006-2009 ascolab GmbH. All Rights Reserved.
5 ** Web: http://www.ascolab.com
6 ** 
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 ** 
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 ** 
15 ** Project: OpcUa Wireshark Plugin
16 **
17 ** Description: Service table and service dispatcher.
18 **
19 ** This file was autogenerated on 31.03.2009.
20 ** DON'T MODIFY THIS FILE!
21 ** XXX - well, except that you may have to.  See the README.
22 **
23 ******************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include "opcua_simpletypes.h"
32 #include "opcua_complextypeparser.h"
33 #include "opcua_extensionobjectids.h"
34 #include "opcua_hfindeces.h"
35
36 ExtensionObjectParserEntry g_arExtensionObjectParserTable[] = {
37     { OpcUaId_DataChangeNotification_Encoding_DefaultBinary, parseDataChangeNotification, "DataChangeNotification" },
38     { OpcUaId_EventNotificationList_Encoding_DefaultBinary, parseEventNotificationList, "EventNotificationList" },
39 };
40 const int g_NumTypes = sizeof(g_arExtensionObjectParserTable) / sizeof(ExtensionObjectParserEntry);
41
42 /** Dispatch all extension objects to a special parser function. */
43 void dispatchExtensionObjectType(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int TypeId)
44 {
45     gint    iOffset = *pOffset;
46     int     index = 0;
47     int     bFound = 0;
48     gint32  iLen = 0;
49
50     /* get the length of the body */
51     iLen = tvb_get_letohl(tvb, iOffset);
52     iOffset += 4;
53
54     while (index < g_NumTypes)
55     {
56         if (g_arExtensionObjectParserTable[index].iRequestId == TypeId)
57         {
58             bFound = 1;
59             (*g_arExtensionObjectParserTable[index].pParser)(tree, tvb, &iOffset, g_arExtensionObjectParserTable[index].typeName);
60             break;
61         }
62         index++;
63     }
64
65     /* display contained object as ByteString if unknown type */
66     if (bFound == 0)
67     {
68         if (iLen == -1)
69         {
70             proto_tree_add_text(tree, tvb, iOffset, 0, "[OpcUa Null ByteString]");
71         }
72         else if (iLen >= 0)
73         {
74             proto_tree_add_item(tree, hf_opcua_ByteString, tvb, iOffset, iLen, TRUE);
75             iOffset += iLen; /* eat the whole bytestring */
76         }
77         else
78         {
79             char *szValue = ep_strdup_printf("[Invalid ByteString] Invalid length: %d", iLen);
80             proto_tree_add_text(tree, tvb, iOffset, 0, "%s", szValue);
81         }
82     }
83
84     *pOffset = iOffset;
85 }
86