Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDKCOM-4663 RDKDEV-999:Xdial-Parse-authorized-domains #108

Open
wants to merge 1 commit into
base: 24Q2_sprint
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else()
endif()
pkg_search_module (SOUP REQUIRED libsoup-2.4)
pkg_search_module (XML2 REQUIRED libxml-2.0)
pkg_search_module (JSON-C REQUIRED json-c)

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ")
Expand Down Expand Up @@ -90,6 +91,7 @@ target_link_libraries (gdial-server
${GSSDP_LIBRARIES}
${SOUP_LIBRARIES}
${XML2_LIBRARIES}
${JSON-C_LIBRARIES}
gdial-plat
uuid
)
111 changes: 37 additions & 74 deletions server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <stdio.h>
#include <glib.h>
#include <libsoup/soup.h>
#include <json-c/json.h>
#include <json-c/json_object.h>
#include <json-c/json_object_iterator.h>

#include "gdial-config.h"
#include "gdial-debug.h"
Expand Down Expand Up @@ -186,7 +189,20 @@ static void gdial_quit_thread(int signum)
usleep(50000); //Sleeping 50 ms to allow existing request to finish processing.
g_print(" calling g_main_loop_quit loop_: %p \r\n",loop_);
if(loop_)g_main_loop_quit(loop_);
}

static char* get_app_name(const char *config_name)
{
static int prefix_len = strlen("/apps/");
static int suffix_len = strlen("/dial_data");

int size = strlen(config_name);
int app_name_size = size - (prefix_len + suffix_len);
char *app_name = malloc(app_name_size + 1);
strncpy(app_name, config_name + prefix_len, app_name_size);
app_name[app_name_size] = '\0';

return app_name;
}

int main(int argc, char *argv[]) {
Expand Down Expand Up @@ -285,89 +301,36 @@ int main(int argc, char *argv[]) {
}
else {
g_print("app_list to be enabled from command line %s\r\n", options_.app_list);
size_t app_list_len = strlen(options_.app_list);
gchar *app_list_low = g_ascii_strdown(options_.app_list, app_list_len);
if (g_strstr_len(app_list_low, app_list_len, "netflix")) {
g_print("netflix is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".netflix.com");
gdial_rest_server_register_app(dial_rest_server, "Netflix", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("netflix is not enabled from cmdline\r\n");
}

if (g_strstr_len(app_list_low, app_list_len, "youtube")) {
g_print("youtube is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".youtube.com");
gdial_rest_server_register_app(dial_rest_server, "YouTube", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("youtube is not enabled from cmdline\r\n");
}
struct json_object *root = json_tokener_parse(options_.app_list);
struct json_object_iterator it = json_object_iter_begin(root);
struct json_object_iterator it_end = json_object_iter_end(root);

if (g_strstr_len(app_list_low, app_list_len, "youtubetv")) {
g_print("youtubetv is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".youtube.com");
gdial_rest_server_register_app(dial_rest_server, "YouTubeTV", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("youtubetv is not enabled from cmdline\r\n");
}
while (!json_object_iter_equal(&it, &it_end)) {
const char *config_name = json_object_iter_peek_name(&it);
const char *app_name = get_app_name(config_name);
g_print("%s is enabled from cmdline\r\n", app_name);

if (g_strstr_len(app_list_low, app_list_len, "youtubekids")) {
g_print("youtubekids is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".youtube.com");
gdial_rest_server_register_app(dial_rest_server, "YouTubeKids", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("youtubekids is not enabled from cmdline\r\n");
}
struct json_object *origins = json_object_iter_peek_value(&it);
int arraylen = json_object_array_length(origins);

if (g_strstr_len(app_list_low, app_list_len, "amazoninstantvideo")) {
g_print("AmazonInstantVideo is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".amazonprime.com");
gdial_rest_server_register_app(dial_rest_server, "AmazonInstantVideo", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("AmazonInstantVideo is not enabled from cmdline\r\n");
}
GList *allowed_origins = NULL;
for (int i = 0; i < arraylen; i++) {
struct json_object *origin = json_object_array_get_idx(origins, i);
char *origin_value = g_strdup(json_object_get_string(origin));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how u r passing origin and other params?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xdial app list is initially populated from the command line. This commit
replaces the naive parsing implementation, which adds the
allowed origins based on hardcoded values with implementation, which
honors the passed origins.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you share the sample command line args passed to the process after this change

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the -A argument as below,

-A {"/apps/AmazonInstantVideo/dial_data":["www.primevideo.com"],"/apps/Netflix/dial_data":["www.netflix.com","www4.netflix.com"],"/apps/YouTube/dial_data":["www.youtube.com"],"/apps/YouTubeKids/dial_data":["www.youtube.com"],"/apps/system/dial_data":[]}

it can be found as in below,
Hi @apatel859 with this change in place, the -A argument is now a JSon formatted string, earlier it was a plain text and a list w/ or w/o delimeter (as i see in the code, it was just searching for some expected strings like netflix, youtube etc.)

following is something you could see if you check status of the XDial Service,

systemctl status xdial
xdial.service - Service to start/stop xdialserver
Loaded: loaded (/lib/systemd/system/xdial.service; static; vendor preset: enabled)
Active: active (running)
since Wed 2024-04-10 14:38:38 CEST; 54min ago; monotonic: 54min ago
TriggeredBy: * xdial.socket
Process: 7827 ExecStartPre=/container/DIAL/launcher/dial.sh preXdial (code=exited, status=0/SUCCESS)
Main PID: 7918 (gdial-server)
Memory: 392.0K
CGroup: /lxc.slice/xdial.service
`-7915 /usr/bin/lxc-attach -n DIAL -o none -l NOTICE -f /container/DIAL/conf/lxc.conf -u 227 -g 227 -- /bin/sh /usr/share/xdial/startXdial.sh /tmp/env_variables

7918 /usr/share/xdial/gdial-server -I eth2 -F Telenet box -R Mediabox -M 2008C-STB-DEV -U aa6658e6-143e-4e3f-8bed-23a05438bd88 -A {"/apps/AmazonInstantVideo/dial_data":["www.primevideo.com"],"/apps/Netflix/dial_data":["www.netflix.com","www4.netflix.com"],"/apps/YouTube/dial_data":["www.youtube.com"],"/apps/YouTubeKids/dial_data":["www.youtube.com"],"/apps/system/dial_data":[]} --feature-friendlyname --feature-wolwake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So static list is a legacy solution which we dont want to update. Instead app can whilte list the apps using curl -H "Authorization: Bearer WPEFrameworkSecurityUtility | cut -d '"' -f 4" --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","id":"3","method": "org.rdk.Xcast.1.registerApplications","params":{"applications":[{"names":["YouTube", "YouTubeKids", "YouTubeTV"],"cors":[".youtube.com"],"properties":{"allowStop" :true}}]}}' http://127.0.0.1:9998/jsonrpc

g_print("\t origin %s\r\n", origin_value);

if (g_strstr_len(app_list_low, app_list_len, "spotify")) {
g_print("spotify is enabled from cmdline\r\n");
GList *app_prefixes= g_list_prepend(NULL, "com.spotify");
GList *allowed_origins = g_list_prepend(NULL, ".spotify.com");
gdial_rest_server_register_app(dial_rest_server, "com.spotify.Spotify.TV", app_prefixes, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
g_list_free(app_prefixes);
}
else {
g_print("spotify is not enabled from cmdline\r\n");
}
allowed_origins = g_list_prepend(allowed_origins, origin_value);
}

if (g_strstr_len(app_list_low, app_list_len, "pairing")) {
g_print("pairing is enabled from cmdline\r\n");
GList *allowed_origins = g_list_prepend(NULL, ".comcast.com");
gdial_rest_server_register_app(dial_rest_server, "Pairing", NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free(allowed_origins);
}
else {
g_print("pairing is not enabled from cmdline\r\n");
}
gdial_rest_server_register_app(dial_rest_server, app_name, NULL, NULL, TRUE, TRUE, allowed_origins);
g_list_free_full(allowed_origins, g_free);
free(app_name);

if (g_strstr_len(app_list_low, app_list_len, "system")) {
g_print("system is enabled from cmdline\r\n");
gdial_rest_server_register_app(dial_rest_server, "system", NULL, NULL, TRUE, TRUE, NULL);
}
else {
g_print("system is not enabled from cmdline\r\n");
json_object_iter_next(&it);
}

g_free(app_list_low);
json_object_put(root);
}

g_signal_connect(dial_rest_server, "invalid-uri", G_CALLBACK(signal_handler_rest_server_invalid_uri), NULL);
Expand Down