openc3 5.10.0 → 5.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openc3 might be problematic. Click here for more details.

Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Rakefile +3 -2
  4. data/data/config/target.yaml +9 -0
  5. data/ext/openc3/ext/packet/packet.c +3 -0
  6. data/ext/openc3/ext/reducer_microservice/extconf.rb +13 -0
  7. data/ext/openc3/ext/reducer_microservice/reducer_microservice.c +165 -0
  8. data/ext/openc3/ext/structure/structure.c +7 -9
  9. data/lib/openc3/accessors/accessor.rb +53 -3
  10. data/lib/openc3/accessors/binary_accessor.rb +16 -0
  11. data/lib/openc3/accessors/cbor_accessor.rb +3 -3
  12. data/lib/openc3/accessors/form_accessor.rb +78 -0
  13. data/lib/openc3/accessors/http_accessor.rb +145 -0
  14. data/lib/openc3/accessors/json_accessor.rb +19 -3
  15. data/lib/openc3/accessors/xml_accessor.rb +18 -1
  16. data/lib/openc3/accessors.rb +3 -1
  17. data/lib/openc3/config/config_parser.rb +7 -5
  18. data/lib/openc3/config/meta_config_parser.rb +1 -1
  19. data/lib/openc3/core_ext/string.rb +16 -1
  20. data/lib/openc3/interfaces/http_client_interface.rb +202 -0
  21. data/lib/openc3/interfaces/http_server_interface.rb +183 -0
  22. data/lib/openc3/interfaces/interface.rb +86 -16
  23. data/lib/openc3/interfaces/mqtt_interface.rb +6 -5
  24. data/lib/openc3/interfaces/protocols/burst_protocol.rb +11 -11
  25. data/lib/openc3/interfaces/protocols/cobs_protocol.rb +7 -7
  26. data/lib/openc3/interfaces/protocols/crc_protocol.rb +7 -7
  27. data/lib/openc3/interfaces/protocols/length_protocol.rb +6 -6
  28. data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +9 -5
  29. data/lib/openc3/interfaces/protocols/protocol.rb +8 -6
  30. data/lib/openc3/interfaces/protocols/slip_protocol.rb +8 -8
  31. data/lib/openc3/interfaces/protocols/template_protocol.rb +6 -7
  32. data/lib/openc3/interfaces/protocols/terminated_protocol.rb +4 -4
  33. data/lib/openc3/interfaces/simulated_target_interface.rb +2 -0
  34. data/lib/openc3/interfaces/stream_interface.rb +6 -4
  35. data/lib/openc3/interfaces/tcpip_server_interface.rb +2 -0
  36. data/lib/openc3/interfaces/udp_interface.rb +8 -5
  37. data/lib/openc3/interfaces.rb +2 -0
  38. data/lib/openc3/logs/buffered_packet_log_writer.rb +6 -7
  39. data/lib/openc3/logs/log_writer.rb +2 -10
  40. data/lib/openc3/logs/packet_log_constants.rb +13 -3
  41. data/lib/openc3/logs/packet_log_reader.rb +35 -98
  42. data/lib/openc3/logs/packet_log_writer.rb +24 -62
  43. data/lib/openc3/logs/text_log_writer.rb +32 -6
  44. data/lib/openc3/microservices/cleanup_microservice.rb +23 -16
  45. data/lib/openc3/microservices/decom_microservice.rb +8 -20
  46. data/lib/openc3/microservices/log_microservice.rb +3 -1
  47. data/lib/openc3/microservices/reaction_microservice.rb +22 -11
  48. data/lib/openc3/microservices/reducer_microservice.rb +174 -130
  49. data/lib/openc3/{models/notification_model.rb → microservices/scope_cleanup_microservice.rb} +20 -21
  50. data/lib/openc3/microservices/text_log_microservice.rb +2 -5
  51. data/lib/openc3/microservices/timeline_microservice.rb +0 -1
  52. data/lib/openc3/microservices/trigger_group_microservice.rb +6 -3
  53. data/lib/openc3/migrations/20230915000002_no_scope_log_messages.rb +44 -0
  54. data/lib/openc3/models/microservice_model.rb +1 -1
  55. data/lib/openc3/models/scope_model.rb +65 -34
  56. data/lib/openc3/models/target_model.rb +25 -5
  57. data/lib/openc3/models/tool_model.rb +14 -2
  58. data/lib/openc3/models/widget_model.rb +1 -1
  59. data/lib/openc3/packets/json_packet.rb +10 -2
  60. data/lib/openc3/packets/packet.rb +37 -22
  61. data/lib/openc3/packets/packet_config.rb +6 -2
  62. data/lib/openc3/packets/parsers/packet_item_parser.rb +11 -6
  63. data/lib/openc3/packets/structure.rb +19 -12
  64. data/lib/openc3/packets/structure_item.rb +0 -3
  65. data/lib/openc3/script/storage.rb +1 -1
  66. data/lib/openc3/script/web_socket_api.rb +17 -14
  67. data/lib/openc3/topics/command_decom_topic.rb +0 -4
  68. data/lib/openc3/topics/telemetry_decom_topic.rb +0 -4
  69. data/lib/openc3/topics/telemetry_reduced_topics.rb +1 -13
  70. data/lib/openc3/topics/telemetry_topic.rb +2 -1
  71. data/lib/openc3/topics/topic.rb +0 -8
  72. data/lib/openc3/utilities/aws_bucket.rb +40 -38
  73. data/lib/openc3/utilities/bucket_utilities.rb +2 -0
  74. data/lib/openc3/utilities/cli_generator.rb +1 -1
  75. data/lib/openc3/utilities/logger.rb +62 -47
  76. data/lib/openc3/utilities/metric.rb +19 -1
  77. data/lib/openc3/utilities/sleeper.rb +3 -1
  78. data/lib/openc3/utilities/throttle.rb +76 -0
  79. data/lib/openc3/version.rb +5 -5
  80. data/templates/tool_angular/package.json +20 -20
  81. data/templates/tool_angular/yarn.lock +1815 -1009
  82. data/templates/tool_react/package.json +24 -26
  83. data/templates/tool_react/yarn.lock +1269 -902
  84. data/templates/tool_svelte/.prettierrc.js +5 -0
  85. data/templates/tool_svelte/package.json +26 -26
  86. data/templates/tool_svelte/src/services/cable.js +1 -1
  87. data/templates/tool_svelte/src/services/openc3-api.js +173 -173
  88. data/templates/tool_svelte/yarn.lock +981 -735
  89. data/templates/tool_vue/package.json +13 -13
  90. data/templates/tool_vue/yarn.lock +363 -147
  91. data/templates/widget/package.json +14 -14
  92. data/templates/widget/yarn.lock +367 -99
  93. metadata +41 -4
  94. data/lib/openc3/topics/notifications_topic.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c37c79f2062a5921e13c3370ce281c443b9abba929ca36f152df7cd1bcea92e
4
- data.tar.gz: 643d74e05f61eb9016eaefbe5dca61316939e3d4e063fcf4150423cee4d95474
3
+ metadata.gz: beada8d3ae31acc7a45fff23d454f4667b552a5de293f6c17f6da72626dd8490
4
+ data.tar.gz: 950b07bf2f6a3173284d41a77ae7abf4cf6f9582a885dbedc585d50001fadcd8
5
5
  SHA512:
6
- metadata.gz: 25285376d600c16a3d0b6d485a359998fda7226fc3781f639cdde992370291fa7d23b0ce6ca89e02ddcf4e6386dd596839ed4d8c704003b893e37e726ed1a7e4
7
- data.tar.gz: 3ae81b7ea67047a8e23cfb161aeb77b4e7224e44b2c9c1dc4fa2dd78cb06eae50710b0a5c882cfcaf8da9e0214b6b96e517ec2a6af0b7671f5b8e8a0dc1448fe
6
+ metadata.gz: 7b0e9f874d5a88c167ba9bd78c3718d1b646ab80560106e01fb109189c27d6b399a3f51531b23815129ea24f4b9194770c9448d8e4be832c0926a6f5b8c3f9ad
7
+ data.tar.gz: e5c20e0648e27b311de33c0d06eb27bb229110eac0fcf197619dac6a3232b239334cbda07bf3f79e88ddb7425b773191c04f9929883a6042b36633c99924285a
data/Gemfile CHANGED
@@ -14,4 +14,4 @@ gem 'tzinfo-data'
14
14
  gem 'rspec-rails', '~> 6.0'
15
15
  gem 'simplecov', '~> 0.20'
16
16
  gem 'simplecov-cobertura', '~> 2.1'
17
- gem 'mock_redis'
17
+ gem 'mock_redis', '0.36'
data/Rakefile CHANGED
@@ -17,7 +17,7 @@
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
19
  #
20
- # This file may also be used under the terms of a commercial license
20
+ # This file may also be used under the terms of a commercial license
21
21
  # if purchased from OpenC3, Inc.
22
22
 
23
23
  require 'open3'
@@ -63,7 +63,8 @@ task :build => [:devkit] do
63
63
  'telemetry',
64
64
  'packet',
65
65
  'platform',
66
- 'buffered_file'
66
+ 'buffered_file',
67
+ 'reducer_microservice'
67
68
  ]
68
69
 
69
70
  extensions.each do |extension_name|
@@ -156,6 +156,15 @@ TARGET:
156
156
  required: true
157
157
  description: Number of seconds between runs of the cleanup process (default = 900 = 15 minutes)
158
158
  values: \d+
159
+ REDUCER_DISABLE:
160
+ summary: Disables the data reduction microservice for the target
161
+ REDUCER_MAX_CPU_UTILIZATION:
162
+ summary: Maximum amount of CPU utilization to apply to data reduction
163
+ parameters:
164
+ - name: Percentage
165
+ required: true
166
+ description: 0 to 100 percent (default = 30)
167
+ values: \d+
159
168
  TARGET_MICROSERVICE:
160
169
  summary: Breaks a target microservice out into its own process.
161
170
  description:
@@ -60,6 +60,7 @@ static ID id_ivar_description = 0;
60
60
  static ID id_ivar_stored = 0;
61
61
  static ID id_ivar_extra = 0;
62
62
  static ID id_ivar_template = 0;
63
+ static ID id_ivar_packet_time = 0;
63
64
 
64
65
  /* Sets the target name this packet is associated with. Unidentified packets
65
66
  * will have target name set to nil.
@@ -283,6 +284,7 @@ static VALUE packet_initialize(int argc, VALUE *argv, VALUE self)
283
284
  rb_ivar_set(self, id_ivar_stored, Qfalse);
284
285
  rb_ivar_set(self, id_ivar_extra, Qnil);
285
286
  rb_ivar_set(self, id_ivar_template, Qnil);
287
+ rb_ivar_set(self, id_ivar_packet_time, Qnil);
286
288
  return self;
287
289
  }
288
290
 
@@ -323,6 +325,7 @@ void Init_packet(void)
323
325
  id_ivar_stored = rb_intern("@stored");
324
326
  id_ivar_extra = rb_intern("@extra");
325
327
  id_ivar_template = rb_intern("@template");
328
+ id_ivar_packet_time = rb_intern("@packet_time");
326
329
 
327
330
  cPacket = rb_define_class_under(mOpenC3, "Packet", cStructure);
328
331
  rb_define_method(cPacket, "initialize", packet_initialize, -1);
@@ -0,0 +1,13 @@
1
+ require 'mkmf'
2
+
3
+ unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
4
+ $CFLAGS << ' -O3'
5
+ end
6
+ if /gcc/.match?(CONFIG['CC'])
7
+ $CFLAGS << ' -Wall'
8
+ if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
9
+ $CFLAGS << ' -O0 -ggdb'
10
+ end
11
+ end
12
+
13
+ create_makefile 'openc3/ext/reducer_microservice'
@@ -0,0 +1,165 @@
1
+ /*
2
+ # Copyright 2022 Ball Aerospace & Technologies Corp.
3
+ # All Rights Reserved.
4
+ #
5
+ # This program is free software; you can modify and/or redistribute it
6
+ # under the terms of the GNU Affero General Public License
7
+ # as published by the Free Software Foundation; version 3 with
8
+ # attribution addendums as found in the LICENSE.txt
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ */
15
+
16
+ /*
17
+ # Modified by OpenC3, Inc.
18
+ # All changes Copyright 2022, OpenC3, Inc.
19
+ # All Rights Reserved
20
+ #
21
+ # This file may also be used under the terms of a commercial license
22
+ # if purchased from OpenC3, Inc.
23
+ */
24
+
25
+ #include "ruby.h"
26
+ #include "stdio.h"
27
+ #include "math.h"
28
+
29
+ VALUE mOpenC3;
30
+ VALUE cMicroservice;
31
+ VALUE cReducerMicroservice;
32
+
33
+ static ID id_method_raw_values = 0;
34
+ static ID id_method_converted_values = 0;
35
+ static ID id_method_less_than = 0;
36
+ static ID id_method_greater_than = 0;
37
+
38
+ static int reducer_microservice_update_min_stats_raw_value(VALUE key, VALUE value, VALUE reduced)
39
+ {
40
+ volatile VALUE vals_key = Qnil;
41
+ volatile VALUE n_key = Qnil;
42
+ volatile VALUE x_key = Qnil;
43
+ volatile VALUE reduced_entry = Qnil;
44
+
45
+ if (RTEST(value))
46
+ {
47
+ vals_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
48
+ rb_str_append(vals_key, rb_str_new2("__VALS"));
49
+ reduced_entry = rb_hash_aref(reduced, vals_key);
50
+ if (!(RTEST(reduced_entry)))
51
+ {
52
+ reduced_entry = rb_ary_new();
53
+ rb_hash_aset(reduced, vals_key, reduced_entry);
54
+ }
55
+ rb_ary_push(reduced_entry, value);
56
+
57
+ n_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
58
+ rb_str_append(n_key, rb_str_new2("__N"));
59
+ reduced_entry = rb_hash_aref(reduced, n_key);
60
+ if (!(RTEST(reduced_entry)))
61
+ {
62
+ reduced_entry = value;
63
+ rb_hash_aset(reduced, n_key, value);
64
+ }
65
+ if (RTEST(rb_funcall(value, id_method_less_than, 1, reduced_entry)))
66
+ {
67
+ rb_hash_aset(reduced, n_key, value);
68
+ }
69
+
70
+ x_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
71
+ rb_str_append(x_key, rb_str_new2("__X"));
72
+ reduced_entry = rb_hash_aref(reduced, x_key);
73
+ if (!(RTEST(reduced_entry)))
74
+ {
75
+ reduced_entry = value;
76
+ rb_hash_aset(reduced, x_key, value);
77
+ }
78
+ if (RTEST(rb_funcall(value, id_method_greater_than, 1, reduced_entry)))
79
+ {
80
+ rb_hash_aset(reduced, x_key, value);
81
+ }
82
+ }
83
+
84
+ return ST_CONTINUE;
85
+ }
86
+
87
+ static int reducer_microservice_update_min_stats_converted_value(VALUE key, VALUE value, VALUE reduced)
88
+ {
89
+ volatile VALUE cvals_key = Qnil;
90
+ volatile VALUE cn_key = Qnil;
91
+ volatile VALUE cx_key = Qnil;
92
+ volatile VALUE reduced_entry = Qnil;
93
+
94
+ if (RTEST(value))
95
+ {
96
+ cvals_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
97
+ rb_str_append(cvals_key, rb_str_new2("__CVALS"));
98
+ reduced_entry = rb_hash_aref(reduced, cvals_key);
99
+ if (!(RTEST(reduced_entry)))
100
+ {
101
+ reduced_entry = rb_ary_new();
102
+ rb_hash_aset(reduced, cvals_key, reduced_entry);
103
+ }
104
+ rb_ary_push(reduced_entry, value);
105
+
106
+ cn_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
107
+ rb_str_append(cn_key, rb_str_new2("__CN"));
108
+ reduced_entry = rb_hash_aref(reduced, cn_key);
109
+ if (!(RTEST(reduced_entry)))
110
+ {
111
+ reduced_entry = value;
112
+ rb_hash_aset(reduced, cn_key, value);
113
+ }
114
+ if (RTEST(rb_funcall(value, id_method_less_than, 1, reduced_entry)))
115
+ {
116
+ rb_hash_aset(reduced, cn_key, value);
117
+ }
118
+
119
+ cx_key = rb_str_new(RSTRING_PTR(key), RSTRING_LEN(key));
120
+ rb_str_append(cx_key, rb_str_new2("__CX"));
121
+ reduced_entry = rb_hash_aref(reduced, cx_key);
122
+ if (!(RTEST(reduced_entry)))
123
+ {
124
+ reduced_entry = value;
125
+ rb_hash_aset(reduced, cx_key, value);
126
+ }
127
+ if (RTEST(rb_funcall(value, id_method_greater_than, 1, reduced_entry)))
128
+ {
129
+ rb_hash_aset(reduced, cx_key, value);
130
+ }
131
+ }
132
+
133
+ return ST_CONTINUE;
134
+ }
135
+
136
+ static VALUE reducer_microservice_update_min_stats(VALUE self, VALUE reduced, VALUE state)
137
+ {
138
+ volatile VALUE raw_values = rb_funcall(state, id_method_raw_values, 0);
139
+ volatile VALUE converted_values = rb_funcall(state, id_method_converted_values, 0);
140
+
141
+ /* Update statistics for this packet's raw values */
142
+ rb_hash_foreach(raw_values, reducer_microservice_update_min_stats_raw_value, reduced);
143
+
144
+ /* Update statistics for this packet's converted values */
145
+ rb_hash_foreach(converted_values, reducer_microservice_update_min_stats_converted_value, reduced);
146
+
147
+ return Qnil;
148
+ }
149
+
150
+ /*
151
+ * Initialize methods for ReducerMicroservice
152
+ */
153
+ void Init_reducer_microservice(void)
154
+ {
155
+ id_method_raw_values = rb_intern("raw_values");
156
+ id_method_converted_values = rb_intern("converted_values");
157
+ id_method_less_than = rb_intern("<");
158
+ id_method_greater_than = rb_intern(">");
159
+
160
+ mOpenC3 = rb_define_module("OpenC3");
161
+ rb_require("openc3/conversions/conversion");
162
+ cMicroservice = rb_const_get(mOpenC3, rb_intern("Microservice"));
163
+ cReducerMicroservice = rb_define_class_under(mOpenC3, "ReducerMicroservice", cMicroservice);
164
+ rb_define_method(cReducerMicroservice, "update_min_stats", reducer_microservice_update_min_stats, 2);
165
+ }
@@ -18,7 +18,7 @@
18
18
  # All changes Copyright 2022, OpenC3, Inc.
19
19
  # All Rights Reserved
20
20
  #
21
- # This file may also be used under the terms of a commercial license
21
+ # This file may also be used under the terms of a commercial license
22
22
  # if purchased from OpenC3, Inc.
23
23
  */
24
24
 
@@ -64,6 +64,8 @@ static ID id_method_Integer = 0;
64
64
  static ID id_method_Float = 0;
65
65
  static ID id_method_kind_of = 0;
66
66
  static ID id_method_allocate_buffer_if_needed = 0;
67
+ static ID id_method_new = 0;
68
+ static ID id_method_class2 = 0;
67
69
 
68
70
  static ID id_ivar_buffer = 0;
69
71
  static ID id_ivar_bit_offset = 0;
@@ -1304,21 +1306,15 @@ static VALUE structure_length(VALUE self)
1304
1306
 
1305
1307
  static VALUE read_item_internal(VALUE self, VALUE item, VALUE buffer)
1306
1308
  {
1307
- volatile VALUE data_type = Qnil;
1308
1309
  volatile VALUE accessor = Qnil;
1309
1310
 
1310
- data_type = rb_ivar_get(item, id_ivar_data_type);
1311
- if (data_type == symbol_DERIVED)
1312
- {
1313
- return Qnil;
1314
- }
1311
+ accessor = rb_ivar_get(self, id_ivar_accessor);
1315
1312
 
1316
1313
  if (!(RTEST(buffer)))
1317
1314
  {
1318
1315
  buffer = rb_funcall(self, id_method_allocate_buffer_if_needed, 0);
1319
1316
  }
1320
1317
 
1321
- accessor = rb_ivar_get(self, id_ivar_accessor);
1322
1318
  return rb_funcall(accessor, id_method_read_item, 2, item, buffer);
1323
1319
  }
1324
1320
 
@@ -1556,7 +1552,7 @@ static VALUE structure_initialize(int argc, VALUE *argv, VALUE self)
1556
1552
  rb_ivar_set(self, id_ivar_fixed_size, Qtrue);
1557
1553
  rb_ivar_set(self, id_ivar_short_buffer_allowed, Qfalse);
1558
1554
  rb_ivar_set(self, id_ivar_mutex, Qnil);
1559
- rb_ivar_set(self, id_ivar_accessor, cBinaryAccessor);
1555
+ rb_ivar_set(self, id_ivar_accessor, rb_funcall(cBinaryAccessor, id_method_new, 1, self));
1560
1556
  }
1561
1557
  else
1562
1558
  {
@@ -1605,6 +1601,7 @@ void Init_structure(void)
1605
1601
  cAccessor = rb_define_class_under(mOpenC3, "Accessor", rb_cObject);
1606
1602
  cBinaryAccessor = rb_define_class_under(mOpenC3, "BinaryAccessor", cAccessor);
1607
1603
 
1604
+ id_method_class2 = rb_intern("class");
1608
1605
  id_method_to_s = rb_intern("to_s");
1609
1606
  id_method_raise_buffer_error = rb_intern("raise_buffer_error");
1610
1607
  id_method_read_array = rb_intern("read_array");
@@ -1617,6 +1614,7 @@ void Init_structure(void)
1617
1614
  id_method_Float = rb_intern("Float");
1618
1615
  id_method_kind_of = rb_intern("kind_of?");
1619
1616
  id_method_allocate_buffer_if_needed = rb_intern("allocate_buffer_if_needed");
1617
+ id_method_new = rb_intern("new");
1620
1618
 
1621
1619
  MIN_INT8 = INT2NUM(-128);
1622
1620
  MAX_INT8 = INT2NUM(127);
@@ -13,16 +13,66 @@
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU Affero General Public License for more details.
15
15
  #
16
- # This file may also be used under the terms of a commercial license
16
+ # This file may also be used under the terms of a commercial license
17
17
  # if purchased from OpenC3, Inc.
18
18
 
19
19
  module OpenC3
20
20
  class Accessor
21
+ attr_accessor :packet
22
+
23
+ def initialize(packet = nil)
24
+ @packet = packet
25
+ @args = []
26
+ end
27
+
21
28
  def read_item(item, buffer)
22
- raise "Must be defined by subclass"
29
+ self.class.read_item(item, buffer)
23
30
  end
24
31
 
25
32
  def write_item(item, value, buffer)
33
+ self.class.write_item(item, value, buffer)
34
+ end
35
+
36
+ def read_items(items, buffer)
37
+ result = {}
38
+ items.each do |item|
39
+ result[item.name] = read_item(item, buffer)
40
+ end
41
+ return result
42
+ end
43
+
44
+ def write_items(items, values, buffer)
45
+ items.each_with_index do |item, index|
46
+ write_item(item, values[index], buffer)
47
+ end
48
+ return values
49
+ end
50
+
51
+ def args
52
+ return @args
53
+ end
54
+
55
+ def enforce_encoding
56
+ return 'ASCII-8BIT'.freeze
57
+ end
58
+
59
+ def enforce_length
60
+ return true
61
+ end
62
+
63
+ def enforce_short_buffer_allowed
64
+ return false
65
+ end
66
+
67
+ def enforce_derived_write_conversion(item)
68
+ return true
69
+ end
70
+
71
+ def self.read_item(item, buffer)
72
+ raise "Must be defined by subclass"
73
+ end
74
+
75
+ def self.write_item(item, value, buffer)
26
76
  raise "Must be defined by subclass"
27
77
  end
28
78
 
@@ -38,7 +88,7 @@ module OpenC3
38
88
  items.each_with_index do |item, index|
39
89
  write_item(item, values[index], buffer)
40
90
  end
41
- return buffer
91
+ return values
42
92
  end
43
93
 
44
94
  def self.convert_to_type(value, item)
@@ -1228,5 +1228,21 @@ module OpenC3
1228
1228
  end
1229
1229
  values
1230
1230
  end
1231
+
1232
+ def enforce_encoding
1233
+ return 'ASCII-8BIT'.freeze
1234
+ end
1235
+
1236
+ def enforce_length
1237
+ return true
1238
+ end
1239
+
1240
+ def enforce_short_buffer_allowed
1241
+ return false
1242
+ end
1243
+
1244
+ def enforce_derived_write_conversion(item)
1245
+ return true
1246
+ end
1231
1247
  end # class BinaryAccessor
1232
1248
  end
@@ -13,7 +13,7 @@
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU Affero General Public License for more details.
15
15
  #
16
- # This file may also be used under the terms of a commercial license
16
+ # This file may also be used under the terms of a commercial license
17
17
  # if purchased from OpenC3, Inc.
18
18
 
19
19
  require 'cbor'
@@ -49,7 +49,7 @@ module OpenC3
49
49
  buffer.replace(decoded.to_cbor)
50
50
  end
51
51
 
52
- return buffer
52
+ return value
53
53
  end
54
54
 
55
55
  def self.read_items(items, buffer)
@@ -79,7 +79,7 @@ module OpenC3
79
79
  buffer.replace(decoded.to_cbor)
80
80
  end
81
81
 
82
- return buffer
82
+ return values
83
83
  end
84
84
 
85
85
  end
@@ -0,0 +1,78 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2023 OpenC3, Inc.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU Affero General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # This file may also be used under the terms of a commercial license
17
+ # if purchased from OpenC3, Inc.
18
+
19
+ require 'openc3/accessors/accessor'
20
+ require 'uri'
21
+
22
+ module OpenC3
23
+ class FormAccessor < Accessor
24
+ def self.read_item(item, buffer)
25
+ ary = URI.decode_www_form(buffer)
26
+ value = nil
27
+ ary.each do |key, ary_value|
28
+ if key == item.key
29
+ if value
30
+ if not Array === value
31
+ value_temp = []
32
+ value_temp << value
33
+ value = value_temp
34
+ end
35
+ value << ary_value
36
+ else
37
+ value = ary_value
38
+ end
39
+ end
40
+ end
41
+ return value
42
+ end
43
+
44
+ def self.write_item(item, value, buffer)
45
+ ary = URI.decode_www_form(buffer)
46
+
47
+ # Remove existing item and bad keys from array
48
+ ary.reject! {|key, ary_value| (key == item.key) or (key.to_s[0] == "\u0000")}
49
+
50
+ if Array === value
51
+ value.each do |value_value|
52
+ ary << [item.key, value_value]
53
+ end
54
+ else
55
+ ary << [item.key, value]
56
+ end
57
+
58
+ buffer.replace(URI.encode_www_form(ary))
59
+ return value
60
+ end
61
+
62
+ def enforce_encoding
63
+ return nil
64
+ end
65
+
66
+ def enforce_length
67
+ return false
68
+ end
69
+
70
+ def enforce_short_buffer_allowed
71
+ return true
72
+ end
73
+
74
+ def enforce_derived_write_conversion(item)
75
+ return true
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,145 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2023 OpenC3, Inc.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU Affero General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # This file may also be used under the terms of a commercial license
17
+ # if purchased from OpenC3, Inc.
18
+
19
+ require 'openc3/accessors/accessor'
20
+
21
+ module OpenC3
22
+ class HttpAccessor < Accessor
23
+ def initialize(packet, body_accessor = 'FormAccessor', *body_accessor_args)
24
+ super(packet)
25
+ @args << body_accessor
26
+ body_accessor_args.each do |arg|
27
+ @args << arg
28
+ end
29
+ klass = OpenC3.require_class(body_accessor)
30
+ @body_accessor = klass.new(packet, *body_accessor_args)
31
+ end
32
+
33
+ def read_item(item, buffer)
34
+ item_name = item.name
35
+ case item_name
36
+ when 'HTTP_STATUS'
37
+ return nil unless @packet.extra
38
+ return @packet.extra['HTTP_STATUS']
39
+ when 'HTTP_PATH'
40
+ return nil unless @packet.extra
41
+ return @packet.extra['HTTP_PATH']
42
+ when 'HTTP_METHOD'
43
+ return nil unless @packet.extra
44
+ return @packet.extra['HTTP_METHOD']
45
+ when 'HTTP_PACKET'
46
+ return nil unless @packet.extra
47
+ return @packet.extra['HTTP_PACKET']
48
+ when 'HTTP_ERROR_PACKET'
49
+ return nil unless @packet.extra
50
+ return @packet.extra['HTTP_ERROR_PACKET']
51
+ when /^HTTP_QUERY_/
52
+ return nil unless @packet.extra
53
+ if item.key
54
+ query_name = item.key
55
+ else
56
+ query_name = item_name[11..-1]
57
+ end
58
+ queries = @packet.extra['HTTP_QUERIES']
59
+ if queries
60
+ return queries[query_name]
61
+ else
62
+ return nil
63
+ end
64
+ when /^HTTP_HEADER_/
65
+ return nil unless @packet.extra
66
+ if item.key
67
+ header_name = item.key
68
+ else
69
+ header_name = item_name[12..-1]
70
+ end
71
+ headers = @packet.extra['HTTP_HEADERS']
72
+ if headers
73
+ return headers[header_name]
74
+ else
75
+ return nil
76
+ end
77
+ else
78
+ return @body_accessor.read_item(item, buffer)
79
+ end
80
+ end
81
+
82
+ def write_item(item, value, buffer)
83
+ item_name = item.name
84
+ case item_name
85
+ when 'HTTP_STATUS'
86
+ @packet.extra ||= {}
87
+ @packet.extra['HTTP_STATUS'] = value.to_i
88
+ when 'HTTP_PATH'
89
+ @packet.extra ||= {}
90
+ @packet.extra['HTTP_PATH'] = value.to_s
91
+ when 'HTTP_METHOD'
92
+ @packet.extra ||= {}
93
+ @packet.extra['HTTP_METHOD'] = value.to_s.downcase
94
+ when 'HTTP_PACKET'
95
+ @packet.extra ||= {}
96
+ @packet.extra['HTTP_PACKET'] = value.to_s.upcase
97
+ when 'HTTP_ERROR_PACKET'
98
+ @packet.extra ||= {}
99
+ @packet.extra['HTTP_ERROR_PACKET'] = value.to_s.upcase
100
+ when /^HTTP_QUERY_/
101
+ @packet.extra ||= {}
102
+ if item.key
103
+ query_name = item.key
104
+ else
105
+ query_name = item_name[11..-1]
106
+ end
107
+ queries = @packet.extra['HTTP_QUERIES'] ||= {}
108
+ queries[query_name] = value.to_s
109
+ when /^HTTP_HEADER_/
110
+ @packet.extra ||= {}
111
+ if item.key
112
+ header_name = item.key
113
+ else
114
+ header_name = item_name[12..-1]
115
+ end
116
+ headers = @packet.extra['HTTP_HEADERS'] ||= {}
117
+ headers[header_name] = value.to_s
118
+ else
119
+ @body_accessor.write_item(item, value, buffer)
120
+ end
121
+ return value
122
+ end
123
+
124
+ def enforce_encoding
125
+ return @body_accessor.enforce_encoding
126
+ end
127
+
128
+ def enforce_length
129
+ return @body_accessor.enforce_length
130
+ end
131
+
132
+ def enforce_short_buffer_allowed
133
+ return @body_accessor.enforce_short_buffer_allowed
134
+ end
135
+
136
+ def enforce_derived_write_conversion(item)
137
+ case item.name
138
+ when 'HTTP_STATUS', 'HTTP_PATH', 'HTTP_METHOD', 'HTTP_PACKET', 'HTTP_ERROR_PACKET', /^HTTP_QUERY_/, /^HTTP_HEADER_/
139
+ return false
140
+ else
141
+ return @body_accessor.enforce_derived_write_conversion
142
+ end
143
+ end
144
+ end
145
+ end