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

at_c: atclient_notify should check if atclient_notify_params argument is complete #371

Open
JeremyTubongbanua opened this issue Aug 13, 2024 · 0 comments
Assignees

Comments

@JeremyTubongbanua
Copy link
Member

atclient_atkey atkey;
atclient_atkey_init(&atkey);
atclient_notify_params notify_params;
atclient_notify_params_init(&notify_params);
if ((exit_code = atclient_utils_find_atserver_address(ATSERVER_HOST, ATSERVER_PORT, ATSIGN, &atserver_host, &atserver_port)) != 0)
{
    goto exit;
}
if ((exit_code = atclient_utils_populate_atkeys_from_homedir(&atkeys, ATSIGN)) != 0)
{
    goto exit;
}
if ((exit_code = atclient_pkam_authenticate(&atclient1, atserver_host, atserver_port, &atkeys, ATSIGN)) != 0)
{
    goto exit;
}
/*
 * 1a. Set up atkey in our notify_params struct
 */
if((exit_code = atclient_notify_params_set_atkey(&notify_params, &atkey)) != 0) {
    goto exit;
}
/*
 * 1b. Set up value in our notify_params struct
 */
const char *value = "Hello! This is a notification!";
if((exit_code = atclient_notify_params_set_value(&notify_params, value)) != 0) {
    goto exit;
}
/*
 * 2. Send the notification
 * We will pass `NULL` for the commit id.
 */
if((exit_code = atclient_notify(&atclient1, &notify_params, NULL)) != 0) {
    goto exit;

Output of this code

[DEBG] 2024-08-13 16:48:13.556642 | connection |        SENT: "soccer0"
[DEBG] 2024-08-13 16:48:13.604292 | connection |        RECV: "3733e916-a5d4-5f5a-b527-a53645304a6c.swarm0002.atsign.zone:6926"
[DEBG] 2024-08-13 16:48:13.958909 | connection |        SENT: "from:soccer0"
[DEBG] 2024-08-13 16:48:13.995959 | connection |        RECV: "data:_ba803d55-725c-44a0-8bdb-28a0d13d8d36@soccer0:684d1175-294e-4c33-a30a-a7d10bddbcd1"
[DEBG] 2024-08-13 16:48:14.050557 | connection |        SENT: "pkam:Eo5l91lZwGOYFH+Oiw+LVKm8c478ox+qwCk4AXssx0TiDZkiqDBCJ7+Q1Va5GLQ9SFeqd/KdF5CscUqKPseG+7OOMJSuBQL9K0IpsqTaG1a170NUOduoQA4q2Sl6jrtXlJsdc47h8mkj8AEk8Sq6PW5c+9W52O6GusqbKM7uhnqhgzgLH9P0VYBY2LSlc061V6lqGDWfsbSyhlII6lrS8a6wubwgNutLSyKCssHvHQy0wmAPGC3Lvm93iiaDBqzKbqBEMJPPL2oTy8Gl9UR+JN2dZLVavHRLr/FweXnVSP8Wc2LIDoxKWS/jRNBr1AudHUyo4yBoPqrxw0gvRd5WOA=="
[DEBG] 2024-08-13 16:48:14.099731 | connection |        RECV: "data:success"
[ERRO] 2024-08-13 16:48:14.099860 | atclient_notify | atclient_string_utils_atsign_with_at failed with code -1
jeremy@raspberrypi8:~/GitHub/at_demos/demos/get_started_c/4b-notify $ cmake -S . -B build && cmake --build build && ./build/main^C
jeremy@raspberrypi8:~/GitHub/at_demos/demos/get_started_c/4b-notify $ ./build/main
[DEBG] 2024-08-13 16:49:00.579611 | connection |        SENT: "soccer0"
[DEBG] 2024-08-13 16:49:00.615765 | connection |        RECV: "3733e916-a5d4-5f5a-b527-a53645304a6c.swarm0002.atsign.zone:6926"
[DEBG] 2024-08-13 16:49:00.932329 | connection |        SENT: "from:soccer0"
[DEBG] 2024-08-13 16:49:00.968379 | connection |        RECV: "data:_ce19738d-6f00-4ef7-b3f2-ee9015f2f022@soccer0:6aeb5cdc-5ca0-46ae-943c-89bf2a873dbc"
[DEBG] 2024-08-13 16:49:01.006703 | connection |        SENT: "pkam:Sur8ExBwZVBf69544TxNB3pfncVlpZwFk05Y0RF49b4bY7sJDqHnnoPaNZbH5zg7hL/mx9NllUQbLwiCl4OKDzWQfL/t0mJiwaPWLjmE0DqFp9UsYwAacrsVWJOp3rRoIMK2lHy8StEIHr1BonXzUFgm9rFfxy/EWNdWsUlqaVubUweFmZPlGX8hq3JfpKwDEr/GhEGZWKi1Y7PebEHsjtcktpiTRPcr3OcdYca6SM1fg9LPf7LrH0iM+bf9JlEtzRZDos3QUOHKujmaKk+t5/GTQzRT4ToFP+D8WBNjdGAJQbMkByd6mpa633nVIf8UOtnvO8mI2/RsHOEz78K39g=="
[DEBG] 2024-08-13 16:49:01.045019 | connection |        RECV: "data:success"
[ERRO] 2024-08-13 16:49:01.045077 | atclient_notify | atclient_string_utils_atsign_with_at failed with code -1

The following code has an atclient_atkey that has not been populated.

The atclient_notify should check if all the necessary atclient_notify_params fields are filled in, including if atclient_atkey has necessary fields filled in before sending the notification.
It should also output an appropriate error message like "notify_params atkey's sharedby field is missing!"

@JeremyTubongbanua JeremyTubongbanua self-assigned this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant