From 3d30c8499ae37ca0ff837e9deaad359de0297765 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 18 Feb 2026 23:23:44 +0100 Subject: Rename all identifiers to strict Linux snake_case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Types PascalCase→snake_case, functions camelCase→snake_case, static functions get _s_ prefix, globals get g_ prefix, struct members and locals to snake_case. --- src/client.c | 132 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 67 insertions(+), 65 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 97a9289..35a3e6f 100644 --- a/src/client.c +++ b/src/client.c @@ -35,10 +35,10 @@ typedef enum OP_READ_TIME, OP_DOWNLOAD_CERT, OP_INVALID -} Operation; +} operation; -static Operation -parseOperation (const char *name) +static operation +_s_parse_operation (const char *name) { if (strcmp (name, "find-servers") == 0) return OP_FIND_SERVERS; @@ -61,13 +61,13 @@ parseOperation (const char *name) * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise. */ static int -opFindServers (UA_Client *client, const char *url) +_s_op_find_servers (UA_Client *client, const char *url) { - size_t arraySize = 0; + size_t array_size = 0; UA_ApplicationDescription *array = NULL; UA_StatusCode retval = UA_Client_findServers (client, url, 0, NULL, 0, NULL, - &arraySize, &array); + &array_size, &array); if (retval != UA_STATUSCODE_GOOD) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, @@ -75,10 +75,10 @@ opFindServers (UA_Client *client, const char *url) return EXIT_FAILURE; } - for (size_t i = 0; i < arraySize; i++) - printApplicationDescription (&array[i], i); + for (size_t i = 0; i < array_size; i++) + print_application_description (&array[i], i); - UA_Array_delete (array, arraySize, + UA_Array_delete (array, array_size, &UA_TYPES[UA_TYPES_APPLICATIONDESCRIPTION]); return EXIT_SUCCESS; } @@ -89,13 +89,13 @@ opFindServers (UA_Client *client, const char *url) * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise. */ static int -opGetEndpoints (UA_Client *client, const char *url) +_s_op_get_endpoints (UA_Client *client, const char *url) { - size_t arraySize = 0; + size_t array_size = 0; UA_EndpointDescription *array = NULL; UA_StatusCode retval - = UA_Client_getEndpoints (client, url, &arraySize, &array); + = UA_Client_getEndpoints (client, url, &array_size, &array); if (retval != UA_STATUSCODE_GOOD) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, @@ -103,10 +103,10 @@ opGetEndpoints (UA_Client *client, const char *url) return EXIT_FAILURE; } - for (size_t i = 0; i < arraySize; i++) - printEndpoint (&array[i], i); + for (size_t i = 0; i < array_size; i++) + print_endpoint (&array[i], i); - UA_Array_delete (array, arraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); + UA_Array_delete (array, array_size, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); return EXIT_SUCCESS; } @@ -119,7 +119,7 @@ opGetEndpoints (UA_Client *client, const char *url) * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise. */ static int -opReadTime (UA_Client *client, const char *url) +_s_op_read_time (UA_Client *client, const char *url) { UA_StatusCode retval = UA_Client_connect (client, url); @@ -167,13 +167,14 @@ opReadTime (UA_Client *client, const char *url) * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise. */ static int -opDownloadCert (UA_Client *client, const char *url, const char *outputPath) +_s_op_download_cert (UA_Client *client, const char *url, + const char *output_path) { - size_t arraySize = 0; + size_t array_size = 0; UA_EndpointDescription *array = NULL; UA_StatusCode retval - = UA_Client_getEndpoints (client, url, &arraySize, &array); + = UA_Client_getEndpoints (client, url, &array_size, &array); if (retval != UA_STATUSCODE_GOOD) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, @@ -182,7 +183,7 @@ opDownloadCert (UA_Client *client, const char *url, const char *outputPath) } UA_ByteString *cert = NULL; - for (size_t i = 0; i < arraySize; i++) + for (size_t i = 0; i < array_size; i++) { if (array[i].serverCertificate.length > 0) { @@ -195,17 +196,17 @@ opDownloadCert (UA_Client *client, const char *url, const char *outputPath) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, "No endpoint returned a server certificate"); - UA_Array_delete (array, arraySize, + UA_Array_delete (array, array_size, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); return EXIT_FAILURE; } - FILE *fp = fopen (outputPath, "wb"); + FILE *fp = fopen (output_path, "wb"); if (!fp) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, - "Could not open output file: %s", outputPath); - UA_Array_delete (array, arraySize, + "Could not open output file: %s", output_path); + UA_Array_delete (array, array_size, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); return EXIT_FAILURE; } @@ -224,12 +225,12 @@ opDownloadCert (UA_Client *client, const char *url, const char *outputPath) else { UA_LOG_INFO (UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, - "Certificate saved to %s (%zu bytes)", outputPath, + "Certificate saved to %s (%zu bytes)", output_path, cert->length); rc = EXIT_SUCCESS; } - UA_Array_delete (array, arraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); + UA_Array_delete (array, array_size, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); return rc; } @@ -253,7 +254,7 @@ main (int argc, char **argv) return EXIT_FAILURE; } - Operation op = parseOperation (argv[2]); + operation op = _s_parse_operation (argv[2]); if (op == OP_INVALID) { UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, @@ -263,9 +264,9 @@ main (int argc, char **argv) return EXIT_FAILURE; } - const char *endpointUrl = argv[3]; - const char *outputPath = NULL; - const char *logLevelStr = "info"; + const char *endpoint_url = argv[3]; + const char *output_path = NULL; + const char *log_level_str = "info"; if (op == OP_DOWNLOAD_CERT) { @@ -277,8 +278,8 @@ main (int argc, char **argv) argv[0]); return EXIT_FAILURE; } - outputPath = argv[4]; - logLevelStr = (argc == 6) ? argv[5] : "info"; + output_path = argv[4]; + log_level_str = (argc == 6) ? argv[5] : "info"; } else { @@ -290,47 +291,47 @@ main (int argc, char **argv) argv[0]); return EXIT_FAILURE; } - logLevelStr = (argc == 5) ? argv[4] : "info"; + log_level_str = (argc == 5) ? argv[4] : "info"; } - int logLevel = parseLogLevel (logLevelStr); - if (logLevel < 0) + int log_level = parse_log_level (log_level_str); + if (log_level < 0) { UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Unknown log level: %s " "(expected trace, debug, info, warning, error, fatal)", - logLevelStr); + log_level_str); return EXIT_FAILURE; } - Config cfg; - if (configLoad (argv[1], &cfg) != 0) + config cfg; + if (config_load (argv[1], &cfg) != 0) return EXIT_FAILURE; /* ---- Common config keys ---- */ - const char *applicationUri - = configRequire (&cfg, "applicationUri", "Client"); - if (!applicationUri) + const char *application_uri + = config_require (&cfg, "applicationUri", "Client"); + if (!application_uri) { - configFree (&cfg); + config_free (&cfg); return EXIT_FAILURE; } - SecurityConfig sec; - if (parseSecurityConfig (&cfg, "Client", true, &sec) != 0) + security_config sec; + if (parse_security_config (&cfg, "Client", true, &sec) != 0) { - configFree (&cfg); + config_free (&cfg); return EXIT_FAILURE; } /* ---- Auth config (read-time only) ---- */ - AuthConfig auth = { .mode = AUTH_ANONYMOUS }; + auth_config auth = { .mode = AUTH_ANONYMOUS }; - if (op == OP_READ_TIME && parseAuthConfig (&cfg, "Client", &auth) != 0) + if (op == OP_READ_TIME && parse_auth_config (&cfg, "Client", &auth) != 0) { - freeTrustStore (sec.trustPaths, sec.trustSize); - configFree (&cfg); + free_trust_store (sec.trust_paths, sec.trust_size); + config_free (&cfg); return EXIT_FAILURE; } @@ -340,24 +341,25 @@ main (int argc, char **argv) UA_StatusCode retval; if (op == OP_DOWNLOAD_CERT) - retval = createUnsecureClientConfig (UA_Client_getConfig (client), - applicationUri, NULL); - else if (sec.certPath) - retval = createSecureClientConfig (UA_Client_getConfig (client), - applicationUri, &sec, &auth); + retval = create_unsecure_client_config (UA_Client_getConfig (client), + application_uri, NULL); + else if (sec.cert_path) + retval = create_secure_client_config (UA_Client_getConfig (client), + application_uri, &sec, &auth); else - retval = createUnsecureClientConfig (UA_Client_getConfig (client), - applicationUri, &auth); + retval = create_unsecure_client_config (UA_Client_getConfig (client), + application_uri, &auth); if (retval != UA_STATUSCODE_GOOD) { UA_Client_delete (client); - freeTrustStore (sec.trustPaths, sec.trustSize); - configFree (&cfg); + free_trust_store (sec.trust_paths, sec.trust_size); + config_free (&cfg); return EXIT_FAILURE; } - UA_Client_getConfig (client)->logging->context = (void *)(uintptr_t)logLevel; + UA_Client_getConfig (client)->logging->context + = (void *)(uintptr_t)log_level; /* ---- Dispatch operation ---- */ @@ -365,16 +367,16 @@ main (int argc, char **argv) switch (op) { case OP_FIND_SERVERS: - rc = opFindServers (client, endpointUrl); + rc = _s_op_find_servers (client, endpoint_url); break; case OP_GET_ENDPOINTS: - rc = opGetEndpoints (client, endpointUrl); + rc = _s_op_get_endpoints (client, endpoint_url); break; case OP_READ_TIME: - rc = opReadTime (client, endpointUrl); + rc = _s_op_read_time (client, endpoint_url); break; case OP_DOWNLOAD_CERT: - rc = opDownloadCert (client, endpointUrl, outputPath); + rc = _s_op_download_cert (client, endpoint_url, output_path); break; default: rc = EXIT_FAILURE; @@ -384,8 +386,8 @@ main (int argc, char **argv) /* ---- Cleanup ---- */ UA_Client_delete (client); - freeTrustStore (sec.trustPaths, sec.trustSize); - configFree (&cfg); + free_trust_store (sec.trust_paths, sec.trust_size); + config_free (&cfg); return rc; } -- cgit v1.2.3