From: Anjali Nijhara Date: Wed, 14 Jun 2023 08:49:38 +0000 (+0530) Subject: Add an API for getting NTP Server URL X-Git-Tag: accepted/tizen/unified/20230628.023641~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=14cc347953e18ec8a8b2b12ea2a7ab53acd4f582;p=platform%2Fcore%2Fapi%2Fconnection.git Add an API for getting NTP Server URL Change-Id: I834cb189423601a299e84321c5347dac9f236a1e --- diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 9194476..8bb39f4 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -219,6 +219,7 @@ int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle); int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle, gboolean *tcpdump_state); int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool *updated); +int _connection_libnet_get_ntp_server(connection_handle_s *conn_handle, char **ntp_server); int _connection_libnet_set_ntp_server(connection_handle_s *conn_handle, const char *ntp_server); int _connection_libnet_clear_ntp_server(connection_handle_s *conn_handle); diff --git a/src/connection.c b/src/connection.c index 1b444cd..73036cb 100755 --- a/src/connection.c +++ b/src/connection.c @@ -1964,6 +1964,39 @@ EXPORT_API int connection_clock_is_updated(connection_h connection, bool *update return CONNECTION_ERROR_NONE; } +EXPORT_API int connection_get_ntp_server(connection_h connection, char **ntp_server) +{ + CONN_LOCK; + + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (ntp_server == NULL || !(_connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return CONNECTION_ERROR_INVALID_PARAMETER;//LCOV_EXCL_LINE + } + + char *server = NULL; + + int rv = _connection_libnet_get_ntp_server(connection, &server); + + if (rv != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Fail to get ntp server [%d]", rv); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return rv; //LCOV_EXCL_LINE + } + + if (server) { + *ntp_server = strdup(server); + g_free(server); + } + + CONNECTION_LOG(CONNECTION_INFO, "NTP SERVER: %s", *ntp_server); + CONN_UNLOCK; + + return CONNECTION_ERROR_NONE; +} + EXPORT_API int connection_set_ntp_server(connection_h connection, const char *ntp_server) { CONN_LOCK; diff --git a/src/libnetwork.c b/src/libnetwork.c index f235fc6..92f25ce 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -1824,6 +1824,22 @@ int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool return CONNECTION_ERROR_NONE; } +int _connection_libnet_get_ntp_server(connection_handle_s *conn_handle, char **ntp_server) +{ + int rv =0; + + rv = net_get_ntp_server_info(conn_handle->network_info_handle, ntp_server); + if (rv == NET_ERR_ACCESS_DENIED) { + CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE + return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get NTP Server [%d]", rv); //LCOV_EXCL_LINE + return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return CONNECTION_ERROR_NONE; +} + int _connection_libnet_set_ntp_server(connection_handle_s *conn_handle, const char *ntp_server) { int rv = 0;