浏览代码

Client: Forward UA_String to NetworkLayer plugin

Julius Pfrommer 5 年之前
父节点
当前提交
734782360d
共有 5 个文件被更改,包括 36 次插入36 次删除
  1. 18 18
      arch/ua_network_tcp.c
  2. 12 13
      arch/ua_network_tcp.h
  3. 2 2
      include/ua_plugin_network.h
  4. 2 2
      src/client/ua_client_connect.c
  5. 2 1
      src/client/ua_client_connect_async.c

+ 18 - 18
arch/ua_network_tcp.c

@@ -523,7 +523,7 @@ ServerNetworkLayerTCP_deleteMembers(UA_ServerNetworkLayer *nl) {
 
 UA_ServerNetworkLayer
 UA_ServerNetworkLayerTCP(UA_ConnectionConfig config, UA_UInt16 port,
-                         const UA_Logger *logger) {
+                         UA_Logger *logger) {
     UA_ServerNetworkLayer nl;
     memset(&nl, 0, sizeof(UA_ServerNetworkLayer));
     nl.deleteMembers = ServerNetworkLayerTCP_deleteMembers;
@@ -738,8 +738,8 @@ UA_StatusCode UA_ClientConnectionTCP_poll(UA_Client *client, void *data) {
 }
 
 UA_Connection
-UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const char *endpointUrl,
-                            const UA_UInt32 timeout, const UA_Logger *logger) {
+UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const UA_String endpointUrl,
+                            UA_UInt32 timeout, UA_Logger *logger) {
     UA_Connection connection;
     memset(&connection, 0, sizeof(UA_Connection));
 
@@ -757,18 +757,18 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const char *endpointUrl,
                     sizeof(TCPClientConnection));
     connection.handle = (void*) tcpClientConnection;
     tcpClientConnection->timeout = timeout;
-    UA_String endpointUrlString = UA_STRING((char*) (uintptr_t) endpointUrl);
     UA_String hostnameString = UA_STRING_NULL;
     UA_String pathString = UA_STRING_NULL;
     UA_UInt16 port = 0;
     char hostname[512];
     tcpClientConnection->connStart = UA_DateTime_nowMonotonic();
 
-    UA_StatusCode parse_retval = UA_parseEndpointUrl(&endpointUrlString,
+    UA_StatusCode parse_retval = UA_parseEndpointUrl(&endpointUrl,
                     &hostnameString, &port, &pathString);
     if (parse_retval != UA_STATUSCODE_GOOD || hostnameString.length > 511) {
             UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-                            "Server url is invalid: %s", endpointUrl);
+                           "Server url is invalid: %.*s",
+                           (int)endpointUrl.length, endpointUrl.data);
             connection.state = UA_CONNECTION_CLOSED;
             return connection;
     }
@@ -798,8 +798,8 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const char *endpointUrl,
 }
 
 UA_Connection
-UA_ClientConnectionTCP(UA_ConnectionConfig config, const char *endpointUrl,
-                       const UA_UInt32 timeout, const UA_Logger *logger) {
+UA_ClientConnectionTCP(UA_ConnectionConfig config, const UA_String endpointUrl,
+                       UA_UInt32 timeout, UA_Logger *logger) {
     UA_initialize_architecture_network();
 
     UA_Connection connection;
@@ -815,18 +815,17 @@ UA_ClientConnectionTCP(UA_ConnectionConfig config, const char *endpointUrl,
     connection.releaseRecvBuffer = connection_releaserecvbuffer;
     connection.handle = NULL;
 
-    UA_String endpointUrlString = UA_STRING((char*)(uintptr_t)endpointUrl);
     UA_String hostnameString = UA_STRING_NULL;
     UA_String pathString = UA_STRING_NULL;
     UA_UInt16 port = 0;
     char hostname[512];
 
     UA_StatusCode parse_retval =
-        UA_parseEndpointUrl(&endpointUrlString, &hostnameString,
-                            &port, &pathString);
+        UA_parseEndpointUrl(&endpointUrl, &hostnameString, &port, &pathString);
     if(parse_retval != UA_STATUSCODE_GOOD || hostnameString.length > 511) {
         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-                       "Server url is invalid: %s", endpointUrl);
+                       "Server url is invalid: %.*s",
+                       (int)endpointUrl.length, endpointUrl.data);
         return connection;
     }
     memcpy(hostname, hostnameString.data, hostnameString.length);
@@ -893,8 +892,8 @@ UA_ClientConnectionTCP(UA_ConnectionConfig config, const char *endpointUrl,
             ClientNetworkLayerTCP_close(&connection);
             UA_LOG_SOCKET_ERRNO_WRAP(
                     UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-                                   "Connection to %s failed with error: %s",
-                                   endpointUrl, errno_str));
+                                   "Connection to %.*s failed with error: %s",
+                                   (int)endpointUrl.length, endpointUrl.data, errno_str));
             UA_freeaddrinfo(server);
             return connection;
         }
@@ -957,8 +956,9 @@ UA_ClientConnectionTCP(UA_ConnectionConfig config, const char *endpointUrl,
                     if (so_error != ECONNREFUSED) {
                         ClientNetworkLayerTCP_close(&connection);
                         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-                                       "Connection to %s failed with error: %s",
-                                       endpointUrl, strerror(ret == 0 ? so_error : UA_ERRNO));
+                                       "Connection to %.*s failed with error: %s",
+                                       (int)endpointUrl.length, endpointUrl.data,
+                                       strerror(ret == 0 ? so_error : UA_ERRNO));
                         UA_freeaddrinfo(server);
                         return connection;
                     }
@@ -986,8 +986,8 @@ UA_ClientConnectionTCP(UA_ConnectionConfig config, const char *endpointUrl,
         if (connection.state != UA_CONNECTION_CLOSED)
             ClientNetworkLayerTCP_close(&connection);
         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-                       "Trying to connect to %s timed out",
-                       endpointUrl);
+                       "Trying to connect to %.*s timed out",
+                       (int)endpointUrl.length, endpointUrl.data);
         return connection;
     }
 

+ 12 - 13
arch/ua_network_tcp.h

@@ -7,27 +7,26 @@
 #ifndef UA_NETWORK_TCP_H_
 #define UA_NETWORK_TCP_H_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include "ua_server.h"
 #include "ua_client.h"
 #include "ua_plugin_log.h"
 
+_UA_BEGIN_DECLS
+
 UA_ServerNetworkLayer UA_EXPORT
-UA_ServerNetworkLayerTCP(UA_ConnectionConfig conf, UA_UInt16 port, const UA_Logger *logger);
+UA_ServerNetworkLayerTCP(UA_ConnectionConfig conf, UA_UInt16 port, UA_Logger *logger);
 
 UA_Connection UA_EXPORT
-UA_ClientConnectionTCP(UA_ConnectionConfig conf, const char *endpointUrl,
-                       const UA_UInt32 timeout, const UA_Logger *logger);
+UA_ClientConnectionTCP(UA_ConnectionConfig conf, const UA_String endpointUrl,
+                       UA_UInt32 timeout, UA_Logger *logger);
+
+UA_StatusCode UA_EXPORT
+UA_ClientConnectionTCP_poll(UA_Client *client, void *data);
 
-UA_StatusCode UA_ClientConnectionTCP_poll(UA_Client *client, void *data);
 UA_Connection UA_EXPORT
-UA_ClientConnectionTCP_init(UA_ConnectionConfig conf, const char *endpointUrl,
-                            const UA_UInt32 timeout, const UA_Logger *logger);
-#ifdef __cplusplus
-} // extern "C"
-#endif
+UA_ClientConnectionTCP_init(UA_ConnectionConfig conf, const UA_String endpointUrl,
+                            UA_UInt32 timeout, UA_Logger *logger);
+
+_UA_END_DECLS
 
 #endif /* UA_NETWORK_TCP_H_ */

+ 2 - 2
include/ua_plugin_network.h

@@ -198,8 +198,8 @@ struct UA_ServerNetworkLayer {
  * @param timeout in ms until the connection try times out if remote not reachable
  * @param logger the logger to use */
 typedef UA_Connection
-(*UA_ConnectClientConnection)(UA_ConnectionConfig config, const char *endpointUrl,
-                              const UA_UInt32 timeout, const UA_Logger *logger);
+(*UA_ConnectClientConnection)(UA_ConnectionConfig config, UA_String endpointUrl,
+                              UA_UInt32 timeout, UA_Logger *logger);
 
 _UA_END_DECLS
 

+ 2 - 2
src/client/ua_client_connect.c

@@ -563,8 +563,8 @@ UA_Client_connectInternal(UA_Client *client, const char *endpointUrl,
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     client->connection =
         client->config.connectionFunc(client->config.localConnectionConfig,
-                                      endpointUrl, client->config.timeout,
-                                      &client->config.logger);
+                                      UA_STRING((char*)(uintptr_t)endpointUrl),
+                                      client->config.timeout, &client->config.logger);
     if(client->connection.state != UA_CONNECTION_OPENING) {
         retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
         goto cleanup;

+ 2 - 1
src/client/ua_client_connect_async.c

@@ -571,7 +571,8 @@ UA_Client_connect_async(UA_Client *client, const char *endpointUrl,
 
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     client->connection = client->config.initConnectionFunc(
-            client->config.localConnectionConfig, endpointUrl,
+            client->config.localConnectionConfig,
+            UA_STRING((char*)(uintptr_t)endpointUrl),
             client->config.timeout, &client->config.logger);
     if(client->connection.state != UA_CONNECTION_OPENING) {
         UA_LOG_TRACE(&client->config.logger, UA_LOGCATEGORY_CLIENT,