浏览代码

simplify securechannel.h

Julius Pfrommer 6 年之前
父节点
当前提交
3354917233
共有 3 个文件被更改,包括 22 次插入37 次删除
  1. 13 0
      src/ua_securechannel.c
  2. 0 25
      src/ua_securechannel.h
  3. 9 12
      tests/check_chunking.c

+ 13 - 0
src/ua_securechannel.c

@@ -25,6 +25,19 @@
 const UA_ByteString
     UA_SECURITY_POLICY_NONE_URI = {47, (UA_Byte *) "http://opcfoundation.org/UA/SecurityPolicy#None"};
 
+/* Callback data for sending responses in multiple chunks */
+typedef struct {
+    UA_SecureChannel *channel;
+    UA_UInt32 requestId;
+    UA_UInt32 messageType;
+
+    UA_UInt16 chunksSoFar;
+    size_t messageSizeSoFar;
+
+    UA_ByteString messageBuffer;
+    UA_Boolean final;
+} UA_ChunkInfo;
+
 UA_StatusCode
 UA_SecureChannel_init(UA_SecureChannel *channel,
                       const UA_SecurityPolicy *securityPolicy,

+ 0 - 25
src/ua_securechannel.h

@@ -103,36 +103,11 @@ UA_StatusCode
 UA_SecureChannel_sendAsymmetricOPNMessage(UA_SecureChannel *channel, UA_UInt32 requestId,
                                           const void *content, const UA_DataType *contentType);
 
-/**
- * Chunking
- * -------- */
-
-/* For sending responses in multiple chunks */
-typedef struct {
-    UA_SecureChannel *channel;
-    UA_UInt32 requestId;
-    UA_UInt32 messageType;
-
-    UA_UInt16 chunksSoFar;
-    size_t messageSizeSoFar;
-
-    UA_ByteString messageBuffer;
-    UA_Boolean final;
-} UA_ChunkInfo;
-
 typedef UA_StatusCode
 (UA_ProcessMessageCallback)(void *application, UA_SecureChannel *channel,
                             UA_MessageType messageType, UA_UInt32 requestId,
                             const UA_ByteString *message);
 
-typedef UA_StatusCode
-(UA_AsymHeaderCallback)(void *application, UA_SecureChannel *channel,
-                        UA_AsymmetricAlgorithmSecurityHeader *asymHeader);
-
-typedef UA_StatusCode
-(UA_SymHeaderCallback)(void *application, UA_SecureChannel *channel,
-                       UA_UInt32 tokenId);
-
 /* Process a single chunk. This also decrypts the chunk if required. The
  * callback function is called with the complete message body if the message is
  * complete.

+ 9 - 12
tests/check_chunking.c

@@ -17,7 +17,7 @@ size_t counter;
 size_t dataCount;
 
 static UA_StatusCode
-sendChunkMockUp(UA_ChunkInfo *ci, UA_Byte **bufPos, const UA_Byte **bufEnd) {
+sendChunkMockUp(void *_, UA_Byte **bufPos, const UA_Byte **bufEnd) {
     size_t offset = (uintptr_t)(*bufPos - buffers[bufIndex].data);
     bufIndex++;
     *bufPos = buffers[bufIndex].data;
@@ -31,7 +31,6 @@ START_TEST(encodeArrayIntoFiveChunksShallWork) {
     size_t arraySize = 30; //number of elements within the array which should be encoded
     size_t chunkCount = 6; // maximum chunk count
     size_t chunkSize = 30; //size in bytes of each chunk
-    UA_ChunkInfo ci;
     bufIndex = 0;
     counter = 0;
     dataCount = 0;
@@ -50,8 +49,8 @@ START_TEST(encodeArrayIntoFiveChunksShallWork) {
     UA_ByteString workingBuffer = buffers[0];
     UA_Byte *pos = workingBuffer.data;
     const UA_Byte *end = &workingBuffer.data[workingBuffer.length];
-    UA_StatusCode retval = UA_encodeBinary(&v,&UA_TYPES[UA_TYPES_VARIANT], &pos, &end,
-                                           (UA_exchangeEncodeBuffer)sendChunkMockUp, &ci);
+    UA_StatusCode retval = UA_encodeBinary(&v,&UA_TYPES[UA_TYPES_VARIANT],
+                                           &pos, &end, sendChunkMockUp, NULL);
 
     ck_assert_uint_eq(retval,UA_STATUSCODE_GOOD);
     ck_assert_int_eq(counter,4); //5 chunks allocated - callback called 4 times
@@ -70,7 +69,6 @@ START_TEST(encodeStringIntoFiveChunksShallWork) {
     size_t chunkSize = 30; //size in bytes of each chunk
 
     UA_String string;
-    UA_ChunkInfo ci;
     bufIndex = 0;
     counter = 0;
     dataCount = 0;
@@ -95,8 +93,8 @@ START_TEST(encodeStringIntoFiveChunksShallWork) {
 
     UA_Byte *pos = workingBuffer.data;
     const UA_Byte *end = &workingBuffer.data[workingBuffer.length];
-    UA_StatusCode retval = UA_encodeBinary(&v, &UA_TYPES[UA_TYPES_VARIANT], &pos, &end,
-                                           (UA_exchangeEncodeBuffer)sendChunkMockUp, &ci);
+    UA_StatusCode retval = UA_encodeBinary(&v, &UA_TYPES[UA_TYPES_VARIANT],
+                                           &pos, &end, sendChunkMockUp, NULL);
 
     ck_assert_uint_eq(retval,UA_STATUSCODE_GOOD);
     ck_assert_int_eq(counter,4); //5 chunks allocated - callback called 4 times
@@ -115,7 +113,6 @@ START_TEST(encodeTwoStringsIntoTenChunksShallWork) {
     size_t chunkSize = 30; //size in bytes of each chunk
 
     UA_String string;
-    UA_ChunkInfo ci;
     bufIndex = 0;
     counter = 0;
     dataCount = 0;
@@ -137,15 +134,15 @@ START_TEST(encodeTwoStringsIntoTenChunksShallWork) {
 
     UA_Byte *pos = workingBuffer.data;
     const UA_Byte *end = &workingBuffer.data[workingBuffer.length];
-    UA_StatusCode retval = UA_encodeBinary(&string, &UA_TYPES[UA_TYPES_STRING], &pos, &end,
-                                           (UA_exchangeEncodeBuffer)sendChunkMockUp, &ci);
+    UA_StatusCode retval = UA_encodeBinary(&string, &UA_TYPES[UA_TYPES_STRING],
+                                           &pos, &end, sendChunkMockUp, NULL);
     ck_assert_uint_eq(retval,UA_STATUSCODE_GOOD);
     ck_assert_int_eq(counter,4); //5 chunks allocated - callback called 4 times
     size_t offset = (uintptr_t)(pos - buffers[bufIndex].data);
     ck_assert_int_eq(UA_calcSizeBinary(&string,&UA_TYPES[UA_TYPES_STRING]), dataCount + offset);
 
-    retval = UA_encodeBinary(&string,&UA_TYPES[UA_TYPES_STRING], &pos, &end,
-                             (UA_exchangeEncodeBuffer)sendChunkMockUp, &ci);
+    retval = UA_encodeBinary(&string,&UA_TYPES[UA_TYPES_STRING],
+                             &pos, &end, sendChunkMockUp, NULL);
     dataCount += (uintptr_t)(pos - buffers[bufIndex].data);
     ck_assert_uint_eq(retval,UA_STATUSCODE_GOOD);
     ck_assert_int_eq(counter,9); //10 chunks allocated - callback called 4 times