Skip to content

Commit 32d9e2d

Browse files
authored
refactor: remove localhost references in command destination settings across multiple files (#840)
1 parent da30589 commit 32d9e2d

File tree

84 files changed

+108
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+108
-250
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"request": "launch",
138138
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
139139
"args": [
140-
"--gtest_filter=ExtensionTest.ExtensionWithSameName"
140+
"--gtest_filter=ExtensionTest.HttpServerExtensionTwoExtensions"
141141
],
142142
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
143143
"env": {

core/include/ten_runtime/binding/cpp/detail/extension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class extension_t : public binding_handle_t {
132132
ten_shared_ptr_t *stop_graph_cmd = ten_cmd_stop_graph_create();
133133
TEN_ASSERT(stop_graph_cmd, "Should not happen.");
134134

135-
ten_msg_clear_and_set_dest(stop_graph_cmd, "localhost", nullptr, nullptr,
135+
ten_msg_clear_and_set_dest(stop_graph_cmd, nullptr, nullptr, nullptr,
136136
nullptr);
137137
ten_env_send_cmd(ten_env.get_c_ten_env(), stop_graph_cmd, nullptr, nullptr,
138138
nullptr, nullptr);

core/include/ten_runtime/binding/cpp/detail/msg/msg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class msg_t {
5656
return ten_msg_get_name(c_msg);
5757
}
5858

59-
bool set_dest(const char *uri, const char *graph, const char *extension_name,
60-
error_t *err = nullptr) const {
59+
bool set_dest(const char *app_uri, const char *graph_id,
60+
const char *extension_name, error_t *err = nullptr) const {
6161
TEN_ASSERT(c_msg, "Should not happen.");
6262

6363
if (c_msg == nullptr) {
@@ -69,7 +69,7 @@ class msg_t {
6969
}
7070

7171
return ten_msg_clear_and_set_dest(
72-
c_msg, uri, graph, extension_name,
72+
c_msg, app_uri, graph_id, extension_name,
7373
err != nullptr ? err->get_c_error() : nullptr);
7474
}
7575

core/include_internal/ten_runtime/extension/extension_info/extension_info.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ TEN_RUNTIME_PRIVATE_API bool ten_extensions_info_clone(ten_list_t *from,
4646
TEN_RUNTIME_PRIVATE_API bool ten_extension_info_check_integrity(
4747
ten_extension_info_t *self, bool check_thread);
4848

49-
TEN_RUNTIME_PRIVATE_API void ten_extension_info_translate_localhost_to_app_uri(
50-
ten_extension_info_t *self, const char *app_uri);
51-
5249
TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *get_extension_info_in_extensions_info(
5350
ten_list_t *extensions_info, const char *app_uri, const char *graph_id,
5451
const char *extension_group_name, const char *extension_addon_name,

core/include_internal/ten_runtime/extension/msg_dest_info/all_msg_type_dest_info.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,3 @@ TEN_RUNTIME_PRIVATE_API void ten_all_msg_type_dest_info_init(
2424

2525
TEN_RUNTIME_PRIVATE_API void ten_all_msg_type_dest_info_deinit(
2626
ten_all_msg_type_dest_info_t *self);
27-
28-
TEN_RUNTIME_PRIVATE_API void
29-
ten_all_msg_type_dest_info_translate_localhost_to_app_uri(
30-
ten_all_msg_type_dest_info_t *self, const char *uri);

core/include_internal/ten_runtime/extension/msg_dest_info/msg_dest_info.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,5 @@ TEN_RUNTIME_PRIVATE_API ten_shared_ptr_t *ten_msg_dest_info_clone(
3535
TEN_RUNTIME_PRIVATE_API void ten_msg_dest_info_destroy(
3636
ten_msg_dest_info_t *self);
3737

38-
TEN_RUNTIME_PRIVATE_API void ten_msg_dest_info_translate_localhost_to_app_uri(
39-
ten_msg_dest_info_t *self, const char *uri);
40-
4138
TEN_RUNTIME_PRIVATE_API bool ten_msg_dest_info_qualified(
4239
ten_msg_dest_info_t *self, const char *msg_name);

core/src/ten_runtime/addon/protocol/protocol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ static void ten_app_create_protocol_with_uri_task(void *self_, void *arg) {
217217
}
218218

219219
bool ten_addon_create_protocol_with_uri(
220-
ten_env_t *ten_env, const char *uri, TEN_PROTOCOL_ROLE role,
220+
ten_env_t *ten_env, const char *app_uri, TEN_PROTOCOL_ROLE role,
221221
ten_env_addon_on_create_protocol_async_cb_t cb, void *user_data,
222222
ten_error_t *err) {
223-
TEN_ASSERT(uri && role > TEN_PROTOCOL_ROLE_INVALID, "Should not happen.");
223+
TEN_ASSERT(app_uri && role > TEN_PROTOCOL_ROLE_INVALID, "Should not happen.");
224224
TEN_ASSERT(ten_env, "Should not happen.");
225225
TEN_ASSERT(ten_env_check_integrity(ten_env, true), "Should not happen.");
226226
TEN_ASSERT(err, "Invalid argument.");
@@ -253,7 +253,7 @@ bool ten_addon_create_protocol_with_uri(
253253
"Should not happen.");
254254

255255
ten_addon_create_protocol_ctx_t *ctx =
256-
ten_addon_create_protocol_ctx_create(uri, role, cb, user_data);
256+
ten_addon_create_protocol_ctx_create(app_uri, role, cb, user_data);
257257
TEN_ASSERT(ctx, "Failed to allocate memory.");
258258

259259
ten_addon_context_t *addon_context = ten_addon_context_create();

core/src/ten_runtime/app/metadata.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,9 @@ bool ten_app_init_uri(ten_app_t *self, ten_value_t *value) {
9898
return false;
9999
}
100100

101-
ten_string_t default_url;
102-
ten_string_init_formatted(&default_url, TEN_STR_LOCALHOST);
103-
104-
const char *url_str = ten_value_peek_raw_str(value, NULL)
105-
? ten_value_peek_raw_str(value, NULL)
106-
: ten_string_get_raw_str(&default_url);
107-
108-
ten_string_set_from_c_str(&self->uri, url_str);
109-
110-
ten_string_deinit(&default_url);
101+
if (ten_value_peek_raw_str(value, NULL)) {
102+
ten_string_set_from_c_str(&self->uri, ten_value_peek_raw_str(value, NULL));
103+
}
111104

112105
return true;
113106
}

core/src/ten_runtime/app/msg_interface/common.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ bool ten_app_dispatch_msg(ten_app_t *self, ten_shared_ptr_t *msg,
408408
TEN_ASSERT(dest_loc, "Should not happen.");
409409
TEN_ASSERT(ten_loc_check_integrity(dest_loc), "Should not happen.");
410410
TEN_ASSERT(ten_msg_get_dest_cnt(msg) == 1, "Should not happen.");
411-
TEN_ASSERT(!ten_string_is_empty(&dest_loc->app_uri),
412-
"App URI should not be empty.");
413411

414412
if (!ten_string_is_equal_c_str(&dest_loc->app_uri, ten_app_get_uri(self))) {
415413
TEN_ASSERT(0, "Handle this condition, msg dest '%s', app '%s'",
@@ -619,9 +617,7 @@ void ten_app_push_to_in_msgs_queue(ten_app_t *self, ten_shared_ptr_t *msg) {
619617
TEN_ASSERT(ten_app_check_integrity(self, false), "Should not happen.");
620618
TEN_ASSERT(msg && ten_msg_is_cmd_and_result(msg), "Invalid argument.");
621619
TEN_ASSERT(!ten_cmd_base_cmd_id_is_empty(msg), "Invalid argument.");
622-
TEN_ASSERT(
623-
ten_msg_get_src_app_uri(msg) && strlen(ten_msg_get_src_app_uri(msg)),
624-
"Invalid argument.");
620+
TEN_ASSERT(ten_msg_get_src_app_uri(msg), "Invalid argument.");
625621
TEN_ASSERT((ten_msg_get_dest_cnt(msg) == 1), "Invalid argument.");
626622

627623
TEN_UNUSED bool rc = ten_mutex_lock(self->in_msgs_lock);

core/src/ten_runtime/app/ten_env/on_xxx.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void ten_app_continue_run_after_load_all_extensions_if_specified(
140140
goto error;
141141
}
142142

143-
if (!ten_string_is_equal_c_str(&self->uri, TEN_STR_LOCALHOST) &&
143+
if (!ten_string_is_empty(&self->uri) &&
144144
!ten_string_starts_with(&self->uri, TEN_STR_CLIENT)) {
145145
// Create the app listening endpoint protocol if specifying one.
146146
bool rc = ten_addon_create_protocol_with_uri(
@@ -253,10 +253,6 @@ void ten_app_on_configure_done(ten_env_t *ten_env) {
253253
ten_metadata_init_schema_store(&self->manifest, &self->schema_store);
254254
ten_app_adjust_and_validate_property_on_configure_done(self);
255255

256-
if (ten_string_is_empty(&self->uri)) {
257-
ten_string_set_from_c_str(&self->uri, TEN_STR_LOCALHOST);
258-
}
259-
260256
ten_addon_manager_t *manager = ten_addon_manager_get_instance();
261257
TEN_ASSERT(manager, "Should not happen.");
262258

core/src/ten_runtime/engine/msg_interface/common.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ static void ten_engine_handle_in_msgs_sync(ten_engine_t *self) {
109109
ten_shared_ptr_t *msg = ten_smart_ptr_listnode_get(iter.node);
110110
TEN_ASSERT(msg, "Should not happen.");
111111
TEN_ASSERT(ten_msg_check_integrity(msg), "Should not happen.");
112-
TEN_ASSERT(!ten_msg_src_is_empty(msg),
113-
"The message source should have been set.");
114112

115113
if (ten_msg_is_cmd_and_result(msg)) {
116114
const char *src_uri = ten_msg_get_src_app_uri(msg);

core/src/ten_runtime/extension/extension_info/extension_info.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,6 @@ bool ten_extension_info_check_integrity(ten_extension_info_t *self,
372372
return true;
373373
}
374374

375-
void ten_extension_info_translate_localhost_to_app_uri(
376-
ten_extension_info_t *self, const char *uri) {
377-
TEN_ASSERT(self, "Should not happen.");
378-
TEN_ASSERT(ten_extension_info_check_integrity(self, false),
379-
"Should not happen.");
380-
TEN_ASSERT(uri, "Should not happen.");
381-
382-
if (ten_string_is_equal_c_str(&self->loc.app_uri, TEN_STR_LOCALHOST) ||
383-
ten_string_is_empty(&self->loc.app_uri)) {
384-
ten_string_init_from_c_str_with_size(&self->loc.app_uri, uri, strlen(uri));
385-
}
386-
}
387-
388375
ten_extension_info_t *ten_extension_info_from_smart_ptr(
389376
ten_smart_ptr_t *extension_info_smart_ptr) {
390377
TEN_ASSERT(extension_info_smart_ptr, "Invalid argument.");
@@ -448,8 +435,7 @@ static void ten_extension_info_fill_loc_info(ten_extension_info_t *self,
448435
ten_string_set_formatted(&self->loc.graph_id, "%s", graph_id);
449436
}
450437

451-
if (ten_string_is_empty(&self->loc.app_uri) ||
452-
ten_string_is_equal_c_str(&self->loc.app_uri, TEN_STR_LOCALHOST)) {
438+
if (ten_string_is_empty(&self->loc.app_uri)) {
453439
ten_string_set_formatted(&self->loc.app_uri, app_uri);
454440
}
455441

@@ -466,8 +452,7 @@ static void ten_extension_info_fill_loc_info(ten_extension_info_t *self,
466452
graph_id);
467453
}
468454

469-
if (ten_string_is_empty(&self->loc.app_uri) ||
470-
ten_string_is_equal_c_str(&self->loc.app_uri, TEN_STR_LOCALHOST)) {
455+
if (ten_string_is_empty(&self->loc.app_uri)) {
471456
ten_string_set_formatted(&self->loc.app_uri, app_uri);
472457
}
473458
}
@@ -501,19 +486,10 @@ void ten_extensions_info_fill_loc_info(ten_list_t *extensions_info,
501486
ten_list_foreach (&dest_info->dest, dest_iter) {
502487
ten_extension_info_t *dest_extension_info =
503488
ten_smart_ptr_get_data(ten_smart_ptr_listnode_get(dest_iter.node));
504-
if (ten_string_is_empty(&dest_extension_info->loc.app_uri)) {
505-
TEN_ASSERT(0, "extension_info->loc.app_uri should not be empty.");
506-
return;
507-
}
508-
509489
if (ten_string_is_equal_c_str(&dest_extension_info->loc.app_uri,
510490
TEN_STR_LOCALHOST)) {
511-
if (!ten_string_is_equal_c_str(&dest_extension_info->loc.app_uri,
512-
app_uri)) {
513-
TEN_ASSERT(0,
514-
"extension_info->loc.app_uri should not be localhost.");
515-
return;
516-
}
491+
TEN_ASSERT(0, "extension_info->loc.app_uri should not be localhost.");
492+
return;
517493
}
518494

519495
if (ten_string_is_empty(&dest_extension_info->loc.graph_id)) {

core/src/ten_runtime/extension/msg_dest_info/all_msg_type_dest_info.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
#include "include_internal/ten_runtime/extension/msg_dest_info/all_msg_type_dest_info.h"
88

9-
#include "include_internal/ten_runtime/extension/msg_dest_info/msg_dest_info.h"
10-
#include "ten_utils/lib/smart_ptr.h"
119
#include "ten_utils/macro/check.h"
1210

1311
void ten_all_msg_type_dest_info_init(ten_all_msg_type_dest_info_t *self) {
@@ -27,47 +25,3 @@ void ten_all_msg_type_dest_info_deinit(ten_all_msg_type_dest_info_t *self) {
2725
ten_list_clear(&self->audio_frame);
2826
ten_list_clear(&self->data);
2927
}
30-
31-
static void translate_localhost_to_app_uri_for_msg_dest(ten_shared_ptr_t *dest,
32-
const char *uri) {
33-
ten_msg_dest_info_t *raw_dest = ten_shared_ptr_get_data(dest);
34-
ten_msg_dest_info_translate_localhost_to_app_uri(raw_dest, uri);
35-
}
36-
37-
static void translate_localhost_to_app_uri_for_dest(
38-
ten_listnode_t *node, const char *uri,
39-
void (*translate_func)(ten_shared_ptr_t *dest, const char *uri)) {
40-
TEN_ASSERT(node, "Invalid argument.");
41-
TEN_ASSERT(uri, "Invalid argument.");
42-
TEN_ASSERT(translate_func, "Invalid argument.");
43-
44-
ten_shared_ptr_t *shared_dest = ten_smart_ptr_listnode_get(node);
45-
TEN_ASSERT(shared_dest, "Should not happen.");
46-
47-
translate_func(shared_dest, uri);
48-
}
49-
50-
void ten_all_msg_type_dest_info_translate_localhost_to_app_uri(
51-
ten_all_msg_type_dest_info_t *self, const char *uri) {
52-
TEN_ASSERT(self && uri, "Invalid argument.");
53-
54-
ten_list_foreach (&self->cmd, iter) {
55-
translate_localhost_to_app_uri_for_dest(
56-
iter.node, uri, translate_localhost_to_app_uri_for_msg_dest);
57-
}
58-
59-
ten_list_foreach (&self->data, iter) {
60-
translate_localhost_to_app_uri_for_dest(
61-
iter.node, uri, translate_localhost_to_app_uri_for_msg_dest);
62-
}
63-
64-
ten_list_foreach (&self->video_frame, iter) {
65-
translate_localhost_to_app_uri_for_dest(
66-
iter.node, uri, translate_localhost_to_app_uri_for_msg_dest);
67-
}
68-
69-
ten_list_foreach (&self->audio_frame, iter) {
70-
translate_localhost_to_app_uri_for_dest(
71-
iter.node, uri, translate_localhost_to_app_uri_for_msg_dest);
72-
}
73-
}

core/src/ten_runtime/extension/msg_dest_info/msg_dest_info.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,6 @@ ten_shared_ptr_t *ten_msg_dest_info_clone(ten_shared_ptr_t *self,
9696
return ten_shared_ptr_create(new_self, ten_msg_dest_info_destroy);
9797
}
9898

99-
void ten_msg_dest_info_translate_localhost_to_app_uri(ten_msg_dest_info_t *self,
100-
const char *uri) {
101-
TEN_ASSERT(self && uri, "Should not happen.");
102-
103-
ten_list_foreach (&self->dest, iter) {
104-
ten_shared_ptr_t *shared_dest =
105-
ten_weak_ptr_lock(ten_smart_ptr_listnode_get(iter.node));
106-
107-
ten_extension_info_t *extension_info = ten_shared_ptr_get_data(shared_dest);
108-
ten_extension_info_translate_localhost_to_app_uri(extension_info, uri);
109-
110-
ten_shared_ptr_destroy(shared_dest);
111-
}
112-
}
113-
11499
bool ten_msg_dest_info_qualified(ten_msg_dest_info_t *self,
115100
const char *msg_name) {
116101
TEN_ASSERT(self && ten_msg_dest_info_check_integrity(self) && msg_name,

core/src/ten_runtime/msg/msg.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,28 @@ void ten_msg_set_src_to_loc(ten_shared_ptr_t *self, ten_loc_t *loc) {
105105

106106
// The semantics of the following function is to replace the destination
107107
// information to one which is specified through the parameters.
108-
static bool ten_raw_msg_clear_and_set_dest(ten_msg_t *self, const char *uri,
108+
static bool ten_raw_msg_clear_and_set_dest(ten_msg_t *self, const char *app_uri,
109109
const char *graph_id,
110110
const char *extension_name,
111111
TEN_UNUSED ten_error_t *err) {
112112
TEN_ASSERT(self, "Should not happen.");
113113
TEN_ASSERT(ten_raw_msg_check_integrity(self), "Should not happen.");
114-
TEN_ASSERT((uri != NULL || extension_name != NULL), "Should not happen.");
115114

116115
ten_list_clear(&self->dest_loc);
117116
ten_list_push_ptr_back(&self->dest_loc,
118-
ten_loc_create(uri, graph_id, extension_name),
117+
ten_loc_create(app_uri, graph_id, extension_name),
119118
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
120119

121120
return true;
122121
}
123122

124-
void ten_raw_msg_add_dest(ten_msg_t *self, const char *uri,
123+
void ten_raw_msg_add_dest(ten_msg_t *self, const char *app_uri,
125124
const char *graph_id, const char *extension_name) {
126125
TEN_ASSERT(self, "Should not happen.");
127126
TEN_ASSERT(ten_raw_msg_check_integrity(self), "Should not happen.");
128127

129128
ten_list_push_ptr_back(&self->dest_loc,
130-
ten_loc_create(uri, graph_id, extension_name),
129+
ten_loc_create(app_uri, graph_id, extension_name),
131130
(ten_ptr_listnode_destroy_func_t)ten_loc_destroy);
132131
}
133132

@@ -332,13 +331,13 @@ void ten_msg_set_src_engine_if_unspecified(ten_shared_ptr_t *self,
332331
}
333332
}
334333

335-
bool ten_msg_clear_and_set_dest(ten_shared_ptr_t *self, const char *uri,
334+
bool ten_msg_clear_and_set_dest(ten_shared_ptr_t *self, const char *app_uri,
336335
const char *graph_id,
337336
const char *extension_name, ten_error_t *err) {
338337
TEN_ASSERT(self, "Should not happen.");
339338
TEN_ASSERT(ten_msg_check_integrity(self), "Should not happen.");
340339

341-
return ten_raw_msg_clear_and_set_dest(ten_msg_get_raw_msg(self), uri,
340+
return ten_raw_msg_clear_and_set_dest(ten_msg_get_raw_msg(self), app_uri,
342341
graph_id, extension_name, err);
343342
}
344343

@@ -984,11 +983,9 @@ void ten_msg_correct_dest(ten_shared_ptr_t *msg, ten_engine_t *engine) {
984983

985984
if (ten_string_is_equal_c_str(&dest_loc->app_uri, app_uri)) {
986985
is_local_app = true;
987-
} else if (ten_string_is_equal_c_str(&dest_loc->app_uri,
988-
TEN_STR_LOCALHOST)) {
989-
// When an extension uses 'localhost' to indicate the destination is the
990-
// local app, we need to replace 'localhost' with the actual URI of the
991-
// app.
986+
} else if (ten_string_is_empty(&dest_loc->app_uri)) {
987+
// When an extension uses empty string to indicate the destination is the
988+
// local app, we need to replace it with the actual URI of the app.
992989
ten_string_set_from_c_str(&dest_loc->app_uri, app_uri);
993990
is_local_app = true;
994991
}
@@ -1017,20 +1014,6 @@ void ten_msg_correct_dest(ten_shared_ptr_t *msg, ten_engine_t *engine) {
10171014
}
10181015
}
10191016
}
1020-
1021-
// Special handling for start_graph commands:
1022-
// In a start_graph command, extension URIs might be specified as 'localhost',
1023-
// indicating they should be located in the local app.
1024-
// We need to replace these 'localhost' references with the actual app URI.
1025-
if (ten_msg_get_type(msg) == TEN_MSG_TYPE_CMD_START_GRAPH) {
1026-
ten_list_t *extensions_info = ten_cmd_start_graph_get_extensions_info(msg);
1027-
ten_list_foreach (extensions_info, iter) {
1028-
ten_extension_info_t *extension_info =
1029-
ten_shared_ptr_get_data(ten_smart_ptr_listnode_get(iter.node));
1030-
ten_extension_info_translate_localhost_to_app_uri(extension_info,
1031-
app_uri);
1032-
}
1033-
}
10341017
}
10351018

10361019
static bool ten_raw_msg_dump_internal(ten_msg_t *msg, ten_error_t *err,

0 commit comments

Comments
 (0)