Skip to content

Commit f14dcd5

Browse files
committed
platform channels: helpers for decoding method calls
- add `raw_std_method_call_from_buffer` to create a "raw_std_value" from a byte buffer & size, and check whether its encoding is valid - add `platch_respond_malformed_message_std` to send a pre-determined response if the encoding was invalid
1 parent 8870ffb commit f14dcd5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/platformchannel.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,10 @@ int platch_respond_native_error_std(const FlutterPlatformMessageResponseHandle *
13201320
return platch_respond_error_std(handle, "nativeerror", strerror(_errno), &STDINT32(_errno));
13211321
}
13221322

1323+
int platch_respond_malformed_message_std(const FlutterPlatformMessage *message) {
1324+
return platch_respond_error_std(message->response_handle, "malformed-message", "The platform message received was malformed.", &STDNULL);
1325+
}
1326+
13231327
/************************
13241328
* JSON METHOD CHANNELS *
13251329
************************/
@@ -2483,3 +2487,13 @@ MALLOCLIKE MUST_CHECK char *raw_std_method_call_get_method_dup(const struct raw_
24832487
ATTR_PURE const struct raw_std_value *raw_std_method_call_get_arg(const struct raw_std_value *value) {
24842488
return raw_std_value_after(value);
24852489
}
2490+
2491+
ATTR_PURE const struct raw_std_value *raw_std_method_call_from_buffer(const void *buffer, size_t buffer_size) {
2492+
const struct raw_std_value *envelope = (const struct raw_std_value *) buffer;
2493+
2494+
if (!raw_std_method_call_check(envelope, buffer_size)) {
2495+
return NULL;
2496+
} else {
2497+
return envelope;
2498+
}
2499+
}

src/platformchannel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Platform Channels
44
*
55
* Encoding/Decoding of flutter platform messages, with different
6-
*
6+
*
77
* Supported codecs:
88
* - standard message & method codec,
99
* - json message & method codec
@@ -1491,6 +1491,8 @@ int platch_respond_illegal_arg_ext_std(const FlutterPlatformMessageResponseHandl
14911491

14921492
int platch_respond_native_error_std(const FlutterPlatformMessageResponseHandle *handle, int _errno);
14931493

1494+
int platch_respond_malformed_message_std(const FlutterPlatformMessage *message);
1495+
14941496
int platch_respond_success_json(const FlutterPlatformMessageResponseHandle *handle, struct json_value *return_value);
14951497

14961498
int platch_respond_error_json(
@@ -1614,6 +1616,7 @@ ATTR_PURE bool raw_std_method_call_check(const struct raw_std_value *value, size
16141616
ATTR_PURE bool raw_std_method_call_response_check(const struct raw_std_value *value, size_t buffer_size);
16151617
ATTR_PURE bool raw_std_event_check(const struct raw_std_value *value, size_t buffer_size);
16161618

1619+
ATTR_PURE const struct raw_std_value *raw_std_method_call_from_buffer(const void *buffer, size_t buffer_size);
16171620
ATTR_PURE const struct raw_std_value *raw_std_method_call_get_method(const struct raw_std_value *value);
16181621
ATTR_PURE bool raw_std_method_call_is_method(const struct raw_std_value *value, const char *method_name);
16191622
MALLOCLIKE MUST_CHECK char *raw_std_method_call_get_method_dup(const struct raw_std_value *value);

0 commit comments

Comments
 (0)