struct_type.c 5.86 KB
Newer Older
1
2
3
4
5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Cedric Roux's avatar
 
Cedric Roux committed
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

27
28
#define G_LOG_DOMAIN ("PARSER")

Cedric Roux's avatar
 
Cedric Roux committed
29
30
31
32
#include "rc.h"

#include "struct_type.h"
#include "buffers.h"
33
#include "ui_callbacks.h"
Cedric Roux's avatar
 
Cedric Roux committed
34
35
#include "ui_interface.h"

Cedric Roux's avatar
Cedric Roux committed
36
int struct_dissect_from_buffer(
winckel's avatar
winckel committed
37
38
    types_t *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
    buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line)
Cedric Roux's avatar
Cedric Roux committed
39
{
Cedric Roux's avatar
 
Cedric Roux committed
40
    int i;
41
    char cbuf[50 + (type->name ? strlen (type->name) : 0)];
42
    int length = 0;
winckel's avatar
winckel committed
43
    char *name;
Cedric Roux's avatar
 
Cedric Roux committed
44

45
    memset (cbuf, 0, sizeof(cbuf));
Cedric Roux's avatar
 
Cedric Roux committed
46

47
48
    DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset);

winckel's avatar
winckel committed
49
    if (new_line) {
Cedric Roux's avatar
 
Cedric Roux committed
50
51
52
        DISPLAY_TYPE("Str");
    }

winckel's avatar
winckel committed
53
54
55
56
57
58
    if (type->name) {
        name = type->name;
    }
    else {
        name = "_anonymous_";
    }
Cedric Roux's avatar
 
Cedric Roux committed
59

60
    if ((strcmp (name, "IttiMsgText_s") == 0) &&
61
        (type->members_child[0] != NULL) && (strcmp (type->members_child[0]->name, "size") == 0) &&
62
        (type->members_child[1] != NULL) && (strcmp (type->members_child[1]->name, "text") == 0)) {
63
64
65
66
67
68
        uint8_t *buf;

        length = buffer_get_uint32_t (buffer, offset + parent_offset);
        buf = malloc (length + 1);
        buf[0] = '\n';
        buffer_fetch_nbytes(buffer, parent_offset + offset + 32, length, &buf[1]);
69
70
        length = ui_callback_check_string ((char *) &buf[1], length, 0);
        ui_set_signal_text_cb(user_data, (char *) buf, length + 1);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    }
    else
    {
        INDENTED_STRING(cbuf, new_line ? indent : 0, length = sprintf (cbuf, "%s :", name));
        DISPLAY_BRACE(length += sprintf(&cbuf[length], " {"););
        length += sprintf(&cbuf[length], "\n");
        ui_set_signal_text_cb(user_data, cbuf, length);

        for (i = 0; i < type->nb_members; i++) {
            if (type->members_child[i] != NULL)
                type->members_child[i]->type_dissect_from_buffer (
                    type->members_child[i], ui_set_signal_text_cb, user_data,
                    buffer, offset, parent_offset, indent + DISPLAY_TAB_SIZE, TRUE);
        }
Cedric Roux's avatar
 
Cedric Roux committed
85
86
87
    }

    DISPLAY_BRACE(
winckel's avatar
winckel committed
88
            DISPLAY_TYPE("Str");
Cedric Roux's avatar
Cedric Roux committed
89

winckel's avatar
winckel committed
90
            INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "};\n"));
Cedric Roux's avatar
Cedric Roux committed
91
            ui_set_signal_text_cb(user_data, cbuf, length);)
Cedric Roux's avatar
 
Cedric Roux committed
92
93
94
95

    return 0;
}

winckel's avatar
winckel committed
96
int struct_type_file_print(types_t *type, int indent, FILE *file) {
Cedric Roux's avatar
 
Cedric Roux committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    int i;
    if (type == NULL)
        return -1;
    if (file == NULL)
        return -1;
    INDENTED(file, indent, fprintf(file, "<Struct>\n"));
    INDENTED(file, indent+4, fprintf(file, "Name .......: %s\n", type->name));
    INDENTED(file, indent+4, fprintf(file, "Id .........: %d\n", type->id));
    INDENTED(file, indent+4, fprintf(file, "Size .......: %d\n", type->size));
    INDENTED(file, indent+4, fprintf(file, "Align ......: %d\n", type->align));
    INDENTED(file, indent+4, fprintf(file, "Artificial .: %d\n", type->artificial));
    INDENTED(file, indent+4, fprintf(file, "File .......: %s\n", type->file));
    INDENTED(file, indent+4, fprintf(file, "Line .......: %d\n", type->line));
    INDENTED(file, indent+4, fprintf(file, "Members ....: %s\n", type->members));
    INDENTED(file, indent+4, fprintf(file, "Mangled ....: %s\n", type->mangled));
    INDENTED(file, indent+4, fprintf(file, "Demangled ..: %s\n", type->demangled));
    if (type->file_ref != NULL)
        type->file_ref->type_file_print (type->file_ref, indent + 4, file);
    for (i = 0; i < type->nb_members; i++) {
        if (type->members_child[i] != NULL)
            type->members_child[i]->type_file_print (type->members_child[i], indent + 4, file);
    }
    INDENTED(file, indent, fprintf(file, "</Struct>\n"));

    return 0;
}

winckel's avatar
winckel committed
124
int struct_type_hr_display(types_t *type, int indent) {
Cedric Roux's avatar
 
Cedric Roux committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    int i;
    if (type == NULL)
        return -1;
    INDENTED(stdout, indent, printf("<Struct>\n"));
    INDENTED(stdout, indent+4, printf("Name .......: %s\n", type->name));
    INDENTED(stdout, indent+4, printf("Id .........: %d\n", type->id));
    INDENTED(stdout, indent+4, printf("Size .......: %d\n", type->size));
    INDENTED(stdout, indent+4, printf("Align ......: %d\n", type->align));
    INDENTED(stdout, indent+4, printf("Artificial .: %d\n", type->artificial));
    INDENTED(stdout, indent+4, printf("File .......: %s\n", type->file));
    INDENTED(stdout, indent+4, printf("Line .......: %d\n", type->line));
    INDENTED(stdout, indent+4, printf("Members ....: %s\n", type->members));
    INDENTED(stdout, indent+4, printf("Mangled ....: %s\n", type->mangled));
    INDENTED(stdout, indent+4, printf("Demangled ..: %s\n", type->demangled));
    if (type->file_ref != NULL)
        type->file_ref->type_hr_display (type->file_ref, indent + 4);
    for (i = 0; i < type->nb_members; i++) {
        if (type->members_child[i] != NULL)
            type->members_child[i]->type_hr_display (type->members_child[i], indent + 4);
    }
    INDENTED(stdout, indent, printf("</Struct>\n"));

    return 0;
}