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: use atclient_connection_read/write in notify/monitor #353

Open
JeremyTubongbanua opened this issue Jul 30, 2024 · 0 comments
Open
Assignees

Comments

@JeremyTubongbanua
Copy link
Member

Throughout our code base, we do something like this:

static int atclient_get_self_key_validate_arguments(const atclient *atclient, const atclient_atkey *atkey,
                                                const char **value, const atclient_get_self_key_request_options *request_options) {
  int ret = 1;

  if (atclient == NULL) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient is NULL\n");
    goto exit;
  }

  if (!atclient_is_atsign_initialized(atclient)) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_is_atsign_initialized is false\n");
    goto exit;
  }

  if (!atclient_is_atserver_connection_started(atclient)) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_is_atserver_connection_started is false\n");
    goto exit;
  }

  if (atclient->async_read) {
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR,
                 "atclient_get_self_key cannot be called from an async_read atclient, it will cause a race condition\n");
    return 1;
  }

  if (atkey == NULL) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey is NULL\n");
    goto exit;
  }

  if (!atclient_atkey_is_key_initialized(atkey)) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.key is not initialized when it should be\n");
    goto exit;
  }

  if (!atclient_atkey_is_shared_by_initialized(atkey)) {
    ret = 1;
    atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.shared_by is not initialized when it should be\n");
    goto exit;
  }

  ret = 0;
exit: { return ret; }
}

We should follow the same pattern to avoid segfaults in notify/monitor

@JeremyTubongbanua JeremyTubongbanua self-assigned this Jul 30, 2024
@JeremyTubongbanua JeremyTubongbanua changed the title at_c: clean up notify and monitor with optimizations and arguments validation at_c: clean up notify and monitor with optimizations and arguments validation and use atclient_connection_read/write Jul 30, 2024
@JeremyTubongbanua JeremyTubongbanua changed the title at_c: clean up notify and monitor with optimizations and arguments validation and use atclient_connection_read/write at_c: notify/monitor: optimizations, arguments validation, and use atclient_connection_read/write Jul 30, 2024
@JeremyTubongbanua JeremyTubongbanua changed the title at_c: notify/monitor: optimizations, arguments validation, and use atclient_connection_read/write at_c: use atclient_connection_read/write in notify/monitor Jul 30, 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