summarylogtreecommitdiffstats
path: root/syslog-ng-fix-protobuf-30.0-compatibility.patch
blob: 69d900910a92570adbdf15183f5a518e5e1d7489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
From 7a71fe8d8c561ac5a1a81ff6929754eaf8cfd093 Mon Sep 17 00:00:00 2001
From: Christian Heusel <gromit@archlinux.org>
Date: Sat, 19 Apr 2025 23:06:04 +0200
Subject: [PATCH 1/2] grpc: protobuf 30.0 compatibility
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Christian Heusel <gromit@archlinux.org>
Signed-off-by: László Várady <laszlo.varady@anno.io>
---
 modules/grpc/common/schema/grpc-schema.cpp       |  3 ++-
 modules/grpc/otel/filterx/object-otel-array.cpp  |  4 ++--
 modules/grpc/otel/filterx/object-otel-kvlist.cpp |  4 ++--
 modules/grpc/otel/filterx/otel-field.cpp         | 12 ++++++------
 modules/grpc/otel/filterx/protobuf-field.cpp     |  8 ++++----
 modules/grpc/otel/filterx/protobuf-field.hpp     | 13 ++++++++++++-
 6 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/modules/grpc/common/schema/grpc-schema.cpp b/modules/grpc/common/schema/grpc-schema.cpp
index 433791a27..9bc9e7f8a 100644
--- a/modules/grpc/common/schema/grpc-schema.cpp
+++ b/modules/grpc/common/schema/grpc-schema.cpp
@@ -190,7 +190,8 @@ Schema::load_protobuf_schema()
 
       LogTemplate *value = (LogTemplate *) current_value->data;
 
-      this->fields.push_back(Field{field->name(), (google::protobuf::FieldDescriptorProto::Type) field->type(), value});
+      this->fields.push_back(Field{std::string(field->name()),
+                                   (google::protobuf::FieldDescriptorProto::Type) field->type(), value});
       this->fields[i].field_desc = field;
 
       current_value = current_value->next;
diff --git a/modules/grpc/otel/filterx/object-otel-array.cpp b/modules/grpc/otel/filterx/object-otel-array.cpp
index 6cc13cb43..6ab7b479b 100644
--- a/modules/grpc/otel/filterx/object-otel-array.cpp
+++ b/modules/grpc/otel/filterx/object-otel-array.cpp
@@ -387,8 +387,8 @@ OtelArrayField::FilterXObjectSetter(google::protobuf::Message *message, ProtoRef
         }
 
       msg_error("otel-array: Failed to convert field, type is unsupported",
-                evt_tag_str("field", reflectors.fieldDescriptor->name().c_str()),
-                evt_tag_str("expected_type", reflectors.fieldDescriptor->type_name()),
+                evt_tag_str("field", reflectors.fieldDescriptor->name().data()),
+                evt_tag_str("expected_type", reflectors.field_type_name()),
                 evt_tag_str("type", object->type->name));
       return false;
     }
diff --git a/modules/grpc/otel/filterx/object-otel-kvlist.cpp b/modules/grpc/otel/filterx/object-otel-kvlist.cpp
index cd0aa7f21..624544d57 100644
--- a/modules/grpc/otel/filterx/object-otel-kvlist.cpp
+++ b/modules/grpc/otel/filterx/object-otel-kvlist.cpp
@@ -537,8 +537,8 @@ OtelKVListField::FilterXObjectSetter(google::protobuf::Message *message, ProtoRe
         }
 
       msg_error("otel-kvlist: Failed to convert field, type is unsupported",
-                evt_tag_str("field", reflectors.fieldDescriptor->name().c_str()),
-                evt_tag_str("expected_type", reflectors.fieldDescriptor->type_name()),
+                evt_tag_str("field", reflectors.fieldDescriptor->name().data()),
+                evt_tag_str("expected_type", reflectors.field_type_name()),
                 evt_tag_str("type", object->type->name));
       return false;
     }
diff --git a/modules/grpc/otel/filterx/otel-field.cpp b/modules/grpc/otel/filterx/otel-field.cpp
index 741e0fd4b..3807266e1 100644
--- a/modules/grpc/otel/filterx/otel-field.cpp
+++ b/modules/grpc/otel/filterx/otel-field.cpp
@@ -104,7 +104,7 @@ AnyField::FilterXObjectGetter(Message *message, ProtoReflectors reflectors)
     }
 
   msg_error("otel-field: Unexpected protobuf field type",
-            evt_tag_str("name", reflectors.fieldDescriptor->name().c_str()),
+            evt_tag_str("name", reflectors.fieldDescriptor->name().data()),
             evt_tag_int("type", reflectors.fieldType));
   return nullptr;
 }
@@ -169,7 +169,7 @@ AnyField::FilterXObjectDirectGetter(AnyValue *anyValue)
       g_assert_not_reached();
     }
 
-  return converter->Get(anyValue, typeFieldName.c_str());
+  return converter->Get(anyValue, typeFieldName.data());
 }
 
 bool
@@ -283,8 +283,8 @@ public:
         return true;
       }
 
-    return protobuf_converter_by_type(reflectors.fieldDescriptor->type())->Set(message, reflectors.fieldDescriptor->name(),
-           object, assoc_object);
+    return protobuf_converter_by_type(reflectors.fieldDescriptor->type())->Set(message,
+           std::string(reflectors.fieldDescriptor->name()), object, assoc_object);
   }
 };
 
@@ -338,7 +338,7 @@ ProtobufField *syslogng::grpc::otel::otel_converter_by_type(FieldDescriptor::Typ
 
 ProtobufField *syslogng::grpc::otel::otel_converter_by_field_descriptor(const FieldDescriptor *fd)
 {
-  const std::string &fieldName = fd->name();
+  const auto &fieldName = fd->name();
   if (fieldName.compare("time_unix_nano") == 0 ||
       fieldName.compare("observed_time_unix_nano") == 0)
     {
@@ -371,7 +371,7 @@ syslogng::grpc::otel::iter_on_otel_protobuf_message_fields(google::protobuf::Mes
     {
       for (const google::protobuf::FieldDescriptor *field : fields)
         {
-          const std::string &name = field->name();
+          const std::string name = std::string(field->name());
           ProtoReflectors field_reflectors(message, name);
           ProtobufField *converter = syslogng::grpc::otel::otel_converter_by_field_descriptor(field_reflectors.fieldDescriptor);
 
diff --git a/modules/grpc/otel/filterx/protobuf-field.cpp b/modules/grpc/otel/filterx/protobuf-field.cpp
index dc92e49a6..3966230de 100644
--- a/modules/grpc/otel/filterx/protobuf-field.cpp
+++ b/modules/grpc/otel/filterx/protobuf-field.cpp
@@ -48,8 +48,8 @@ void
 log_type_error(ProtoReflectors reflectors, const char *type)
 {
   msg_error("protobuf-field: Failed to convert field, type is unsupported",
-            evt_tag_str("field", reflectors.fieldDescriptor->name().c_str()),
-            evt_tag_str("expected_type", reflectors.fieldDescriptor->type_name()),
+            evt_tag_str("field", reflectors.fieldDescriptor->name().data()),
+            evt_tag_str("expected_type", reflectors.field_type_name()),
             evt_tag_str("type", type));
 }
 
@@ -167,7 +167,7 @@ public:
     if (val > INT64_MAX)
       {
         msg_error("protobuf-field: exceeding FilterX number value range",
-                  evt_tag_str("field", reflectors.fieldDescriptor->name().c_str()),
+                  evt_tag_str("field", reflectors.fieldDescriptor->name().data()),
                   evt_tag_long("range_min", INT64_MIN),
                   evt_tag_long("range_max", INT64_MAX),
                   evt_tag_printf("current", "%" G_GUINT64_FORMAT, val));
@@ -234,7 +234,7 @@ public:
         if (!filterx_object_to_json(object, repr))
           {
             msg_error("protobuf-field: json marshal error",
-                      evt_tag_str("field", reflectors.fieldDescriptor->name().c_str()));
+                      evt_tag_str("field", reflectors.fieldDescriptor->name().data()));
             return false;
           }
         len = repr->len;
diff --git a/modules/grpc/otel/filterx/protobuf-field.hpp b/modules/grpc/otel/filterx/protobuf-field.hpp
index ba181b9bb..e805400a0 100644
--- a/modules/grpc/otel/filterx/protobuf-field.hpp
+++ b/modules/grpc/otel/filterx/protobuf-field.hpp
@@ -49,7 +49,8 @@ struct ProtoReflectors
     this->descriptor = message.GetDescriptor();
     if (!this->reflection || !this->descriptor)
       {
-        std::string error_msg = "unable to access reflector for protobuf message: " + message.GetTypeName();
+        std::string error_msg = "unable to access reflector for protobuf message: "
+                                + std::string(message.GetTypeName());
         throw std::invalid_argument(error_msg);
       }
     this->fieldDescriptor = this->descriptor->FindFieldByName(fieldName);
@@ -66,6 +67,16 @@ struct ProtoReflectors
         throw std::invalid_argument(error_msg);
       }
   };
+
+  const char *
+  field_type_name() const
+  {
+#if GOOGLE_PROTOBUF_VERSION >= 6030000
+    return this->fieldDescriptor->type_name().data();
+#else
+    return this->fieldDescriptor->type_name();
+#endif
+  }
 };
 
 class ProtobufField
-- 
2.49.0