[-]
[+]
|
Changed |
_service:tar_git:libgiorpc.spec
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://git.monich.net/git/libgiorpc.git</param>
<param name="branch">master</param>
- <param name="revision">32181e9</param>
+ <param name="revision">7614011</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/LICENSE
^
|
@@ -4,21 +4,23 @@
modification, are permitted provided that the following conditions
are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer
- in the documentation and/or other materials provided with the
- distribution.
- 3. Neither the names of the copyright holders nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer
+ in the documentation and/or other materials provided with the
+ distribution.
+
+ 3. Neither the names of the copyright holders nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/PROTOCOL
^
|
@@ -4,8 +4,8 @@
This library implements a general purpose stream-based RPC protocol.
The protocol is assumed to run on top of a secure, authenticated
-transport. User authentication and protection against network-level
-attacks are assumed to be provided by the underlying protocols.
+stream. User authentication and protection against network-level
+attacks are assumed to be provided by the underlying transport.
One could argue that IID and CODE parameters of NOTIFY and REQUEST
packets are slightly redundant. The motivation behind splitting
@@ -24,13 +24,33 @@
A multi-byte number (MBN) consists of a series of octets, where
the most significant bit is the continuation flag and the remaining
7 bits are a scalar value. The continuation flag indicates that an
-octet is not the end of the multi-byte sequence. A single integer
-value is encoded into a sequence of N octets. The first N-1 octets
-have the continuation flag set to a value of one (1). The final
-octet in the series has a continuation flag value of zero (0).
+octet is not the end of the multi-byte sequence. Most significant
+chunks come first.
+
+A single integer value is encoded into a sequence of N octets.
+The first N-1 octets have the continuation flag set to a value
+of one (1). The final octet in the series has a continuation flag
+value of zero (0).
+
+Values [0..127] are encoded as a single byte.
Multi-byte numbers are unsigned.
+1.2 TLV block
+
+A structure contiaining generic tagged data.
+
+ +---------------
+ | T (MBN) Tag (non-zero)
+ +---------------
+ | L (MBN) Length (can be zero)
+ +---------------
+ | V (L bytes) Value (L bytes of tag specific data)
+ +---------------
+
+The tag defines the format of the data, and if the tag is unknown
+the whole thing can be easily skipped.
+
2. Packet structure
----------------
@@ -54,10 +74,22 @@
0x06 ERROR
The maximum allowed N is 0x1fffff (2097151) bytes, i.e. the data length
-fits into 21 bits (which takes no more than 3 bytes in MBN encoding). If
-the N is larger than that, the connection gets terminated.
+fits into 21 bits (which takes no more than 3 bytes in MBN encoding).
+If the N is larger than that, it's considered a protocol violation and
+the connection gets silently terminated.
+
+The contents of the DATA part of the packet is interface specific. It's
+suggested that it contains a list of TLVs:
-Unknown packet types should be skipped and ignored.
+ +---+---+---+---+---+---+---+---+
+ | N (MBN)
+ +---
+ | TLV (repeated N times)
+ +---
+
+but it can be anything, as long as the peer knows how to decode it.
+
+Packets of unknown types should be skipped and ignored.
2.1 START
@@ -66,15 +98,28 @@
+---+---+---+---+---+---+---+---+
| N (unsigned MBN)
+---
- | VERSION (unsigned MBN)
+ | M (unsigned MBN)
+ +---
+ | TLVs (repeated M times)
+---
This packet must preceed any other packet defined by this specification.
-VERSION is the procotol version implemented by the peer.
+The data is a sequence of TLVs in any order. Duplicate tags are not
+allowed.
+
+The following tags are defined by this spec:
+
+ Tag: 1 (Version)
+ Required: yes
+ Value: Protocol version as an MBN
This specification defines version 1 of the procotol.
+Tags [2..63] are reserved for use by future versions of the core
+protocol. Application specific protocols can add their own protocol
+specific tags to the start packet. Those tags have to start with 64.
+
2.2 FINISH
+---+---+---+---+---+---+---+---+
@@ -100,7 +145,7 @@
| NOTIFY DATA (N - sizeof IID - sizeof CODE) bytes
+---
-One-way request which doesn't require a response.
+One-way notification which doesn't require a response.
IID is the interface id, must be in [1..0x1fffff] range (21 bit)
CODE is the notification code, must be in [1..0x1fffff] range (21 bit)
@@ -124,7 +169,7 @@
| REQUEST DATA (the remaining part of the packet)
+---
-Request that expects a response. The peer sends back exactly one
+Request that may expect a response. The peer sends back exactly one
SUCCESS or ERROR packet with the same ID.
IID is the interface id, must be in [1..0x1fffff] range (21 bit)
@@ -144,7 +189,7 @@
2.3 RESULT
+---+---+---+---+---+---+---+---+
- | 0x02 |
+ | 0x05 |
+---+---+---+---+---+---+---+---+
| N (unsigned MBN)
+---
@@ -154,8 +199,9 @@
+---
This packet is sent back in response to each handled request. The
-ID allows to map it back to the original request. Each request must
-eventually receive a RESULT or ERROR response.
+ID allows the peer to map it back to the original request. Each
+request must eventually receive a RESULT or ERROR response (but
+not both).
ID is copied from the REQUEST packet
RESULT DATA is optional, can be empty
@@ -163,7 +209,7 @@
2.5 ERROR
+---+---+---+---+---+---+---+---+
- | 0x05 |
+ | 0x06 |
+---+---+---+---+---+---+---+---+
| N (unsigned MBN)
+---
@@ -173,8 +219,9 @@
+---
This packet is sent back in response to each unhandled request. The
-ID allows to map it back to the original request. Each request must
-eventually receive a SUCCESS or ERROR response.
+ID allows the peer to map it back to the original request. Each
+request must eventually receive a SUCCESS or ERROR response (but
+not both).
ID is copied from the REQUEST packet
ERROR is one of the following error codes:
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/debian/copyright
^
|
@@ -4,21 +4,23 @@
modification, are permitted provided that the following conditions
are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer
- in the documentation and/or other materials provided with the
- distribution.
- 3. Neither the names of the copyright holders nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer
+ in the documentation and/or other materials provided with the
+ distribution.
+
+ 3. Neither the names of the copyright holders nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/examples/example_echo.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_log.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_peer.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_request.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_types.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_util.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/include/giorpc_version.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_log_p.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_peer.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@@ -58,6 +62,10 @@
GIORPC_PACKET_ERROR = 0x06
} GIORPC_PACKET_TYPE;
+typedef enum giorpc_start_tag {
+ GIORPC_START_TAG_VERSION = 1
+} GIORPC_START_TAG;
+
typedef struct giorpc_peer_packet GIoRpcPeerPacket;
typedef struct giorpc_peer_sync_call_data GIoRpcPeerSyncCall;
typedef struct giorpc_peer_write GIoRpcPeerWrite;
@@ -876,9 +884,7 @@
giorpc_peer_write_data_done(write->data, self,
GIORPC_PEER_ERROR_NONE);
- if (self) {
- g_object_unref(self);
- }
+ gutil_object_unref(self);
}
gutil_weakref_unref(write->ref);
gutil_slice_free(write);
@@ -1286,8 +1292,10 @@
const void* payload,
guint n)
{
- GUtilRange pos;
+ GUtilRange data;
guint64 version;
+ guint tags[2];
+ GUtilData val[G_N_ELEMENTS(tags) - 1];
/*
* START
@@ -1301,27 +1309,37 @@
* payload starts here
*
* +---
- * | VERSION (unsigned MBN)
+ * | M (unsigned MBN)
+ * +---
+ * | TLVs (repeated M times)
* +---
*/
- pos.end = (pos.ptr = payload) + n;
- if (gutil_unsigned_mbn_decode(&pos, &version)) {
+ data.end = (data.ptr = payload) + n;
+ tags[0] = GIORPC_START_TAG_VERSION;
+ tags[1] = 0;
+ if (giorpc_tlv_array_decode(&data, tags, val) &&
+ gutil_unsigned_mbn_decode2(val, &version) &&
+ version > 0) {
GIoRpcPeer* peer = &self->peer;
- if (peer->state == GIORPC_PEER_STATE_STARTING) {
- if (version <= (guint) G_MAXINT) {
- RLOG1(self, "> START v%u", (guint) version);
- peer->version = version;
- giorpc_peer_set_state(self, GIORPC_PEER_STATE_STARTED);
- return TRUE;
+ if (data.ptr == data.end || version > GIORPC_PROTOCOL_VERSION) {
+ if (peer->state == GIORPC_PEER_STATE_STARTING) {
+ if (version <= (guint) G_MAXINT) {
+ RLOG1(self, "> START v%u", (guint) version);
+ peer->version = version;
+ giorpc_peer_set_state(self, GIORPC_PEER_STATE_STARTED);
+ return TRUE;
+ } else {
+ RLOG1(self, "Version %" G_GUINT64_FORMAT " is too large",
+ version);
+ }
} else {
- RLOG1(self, "Version %" G_GUINT64_FORMAT " is too large",
- version);
+ RLOG1(self, "Unexpected START in state %s",
+ giorpc_peer_state_name(peer->state));
}
} else {
- RLOG1(self, "Unexpected START in state %s",
- giorpc_peer_state_name(peer->state));
+ RLOG(self, "Trailing garbage in START payload");
}
} else {
RLOG(self, "Broken START payload");
@@ -2041,11 +2059,16 @@
* +---+---+---+---+---+---+---+---+
* | N (unsigned MBN)
* +---
- * | VERSION (unsigned MBN)
+ * | M (unsigned MBN)
+ * +---
+ * | TLVs (repeated M times)
* +---
*/
static const guchar start[] = {
GIORPC_PACKET_START,
+ 4, /* N */
+ 1, /* M */
+ GIORPC_START_TAG_VERSION,
1,
GIORPC_PROTOCOL_VERSION
};
@@ -2610,11 +2633,7 @@
giorpc_peer_unref(
GIoRpcPeer* peer)
{
- GIoRpcPeerObject* self = giorpc_peer_object_cast(peer);
-
- if (G_LIKELY(self)) {
- g_object_unref(self);
- }
+ gutil_object_unref(giorpc_peer_object_cast(peer));
}
void
@@ -2894,9 +2913,7 @@
g_queue_clear(&self->blocked);
g_queue_clear(&self->writeq);
g_mutex_clear(&self->requests_mutex);
- if (self->stream) {
- g_object_unref(self->stream);
- }
+ gutil_object_unref(self->stream);
if (self->buf) {
g_byte_array_unref(self->buf);
}
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_peer_p.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_request.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_request_p.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_types_p.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_util.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@@ -36,6 +40,7 @@
#include "giorpc_log_p.h"
#include "giorpc_version.h"
+#include <gutil_datapack.h>
#include <gutil_macros.h>
GLOG_MODULE_DEFINE("giorpc");
@@ -53,6 +58,69 @@
}
/*
+ * TLV array is encoded as follows:
+ *
+ * +---+---+---+---+---+---+---+---+
+ * | N (MBN)
+ * +---
+ * | TLV (repeated N times)
+ * +---
+ */
+gboolean
+giorpc_tlv_array_decode(
+ GUtilRange* in,
+ const guint* tags, /* NULL terminated */
+ GUtilData* vals)
+{
+ GUtilRange tmp = *in;
+ guint64 n = 0;
+ const guint* p;
+
+ /* Clear the output values */
+ for (p = tags; *p++; n++);
+ memset(vals, 0, sizeof(vals[0]) * n);
+
+ /* Decode the size of the array */
+ if (gutil_unsigned_mbn_decode(&tmp, &n)) {
+ guint64 i;
+
+ /* Decode TLVs one by one */
+ for (i = 0; i < n; i++) {
+ GUtilData v;
+ guint tag = gutil_tlv_decode(&tmp, &v);
+
+ if (tag) {
+ for (p = tags; *p; p++) {
+ if (*p == tag) {
+ GUtilData* out = vals + (p - tags);
+
+ if (out->bytes) {
+ /* Duplicate tag */
+ return FALSE;
+ }
+
+ /* Found a known tag */
+ *out = v;
+ break;
+ }
+ }
+ /* Unknown tags are ignored */
+ continue;
+ }
+ /* Unable to parse a TLV, that's a failure */
+ break;
+ }
+
+ if (i == n) {
+ /* All TLVs have been successfully parsed */
+ in->ptr = tmp.ptr;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*
* giorpc_read_all_async is a replacement for g_input_stream_read_all_async
* which requires glib 2.44, except that it doesn't report the amount of
* partially read data before EOF (we have no use for it).
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/src/giorpc_util_p.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@@ -75,6 +79,13 @@
gpointer user_data)
G_GNUC_INTERNAL;
+gboolean
+giorpc_tlv_array_decode(
+ GUtilRange* in,
+ const guint* tags,
+ GUtilData* vals)
+ G_GNUC_INTERNAL;
+
#endif /* GIORPC_UTIL_PRIVATE_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/common/test_common.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/common/test_io_stream.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/common/test_io_stream.h
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/common/test_main.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/test_peer/test_peer.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@@ -67,6 +71,16 @@
#define PACKET_RESULT 0x05
#define PACKET_ERROR 0x06
+#define GIORPC_START_VERSION_TAG 1
+#define GIORPC_START_VERSION_TLV_(version) \
+ GIORPC_START_VERSION_TAG, 1, version
+#define GIORPC_START_VERSION_TLV() \
+ GIORPC_START_VERSION_TLV_(GIORPC_PROTOCOL_VERSION)
+#define START_PACKET_(version) \
+ PACKET_START, 4, 1, GIORPC_START_VERSION_TLV_(version)
+#define START_PACKET() \
+ START_PACKET_(GIORPC_PROTOCOL_VERSION)
+
/* Reusable ids */
#define TEST_IID 22
#define TEST_CALL_CODE 128
@@ -3842,9 +3856,7 @@
{
TestSetup1 test;
GCancellable* cancel;
- static const guint8 start[] = {
- PACKET_START, 1, GIORPC_PROTOCOL_VERSION
- };
+ static const guint8 start[] = { START_PACKET() };
static const guint8 data[] = {
0x7f, 0x81, 0x00,
0x11, 0x12, 0x13, 0x13, 0x15, 0x16, 0x17, 0x18,
@@ -3863,7 +3875,7 @@
0x61, 0x62, 0x63, 0x63, 0x65, 0x66, 0x67, 0x68,
0x71, 0x72, 0x73, 0x73, 0x75, 0x76, 0x77, 0x78,
0x81, 0x82, 0x83, 0x83, 0x85, 0x86, 0x87, 0x88,
- PACKET_START, 1, GIORPC_PROTOCOL_VERSION + 1
+ START_PACKET_(GIORPC_PROTOCOL_VERSION + 1)
};
GBytes* start_packet = g_bytes_new_static(start, sizeof(start));
@@ -3951,7 +3963,7 @@
TestCancel1 test;
GIoRpcPeer* peer;
GCancellable* cancel;
- static const guint8 start[] = { PACKET_START, 1, GIORPC_PROTOCOL_VERSION };
+ static const guint8 start[] = { START_PACKET() };
static const guint8 finish[] = { PACKET_FINISH, 0x00 };
gulong handler_id;
guint call_id;
@@ -4041,7 +4053,7 @@
{
TestSetup1 test;
GCancellable* cancel;
- static const guint8 start[] = { PACKET_START, 1, GIORPC_PROTOCOL_VERSION };
+ static const guint8 start[] = { START_PACKET() };
static const guint8 finish[] = { PACKET_FINISH, 0x00 };
static const guint8 req[] = { PACKET_REQUEST };
static const guint8 req_data[] = {
@@ -4120,149 +4132,167 @@
static const guint8 broken_stream1_data[] = { /* Broken START */
PACKET_START, 0x80, 0x80, 0x80
};
+
static const guint8 broken_stream2_data[] = { /* Broken START */
- PACKET_START, 0x05, 0xff, 0xff, 0xff, 0xff, 0x7f
+ PACKET_START, 0x00 /* No data at all */
};
+
static const guint8 broken_stream3_data[] = { /* Broken START */
- PACKET_START, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ PACKET_START, 0x01, 0x00 /* Missing version TLV */
};
-static const guint8 broken_stream4_data[] = { /* Double start */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION
+static const guint8 broken_stream4_data[] = { /* Broken START */
+ PACKET_START, 0x04,
+ 0x01, GIORPC_START_VERSION_TAG, 0x01, 0x00 /* Zero version */
};
-static const guint8 broken_stream5_data[] = { /* NOTIFY before START */
- PACKET_NOTIFY, 0x02, 0x01, 0x01,
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION
+static const guint8 broken_stream5_data[] = { /* Broken START */
+ PACKET_START, 0x08, /* Version too large */
+ 0x01, GIORPC_START_VERSION_TAG, 0x05, 0xff, 0xff, 0xff, 0xff, 0x7f
};
-static const guint8 broken_stream6_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream6_data[] = { /* Broken START */
+ PACKET_START, 0x05,
+ 0x01, GIORPC_START_VERSION_TAG, 0x01, 0x01 /* Version */,
+ 0xff /* Trailing garbage */
+};
+
+static const guint8 broken_stream7_data[] = { /* Double start */
+ START_PACKET(),
+ START_PACKET()
+};
+
+static const guint8 broken_stream8_data[] = { /* NOTIFY before START */
+ START_PACKET(),
+ START_PACKET()
+};
+
+static const guint8 broken_stream9_data[] = { /* Broken NOTIFY */
+ PACKET_NOTIFY, 0x02, 0x01, 0x01,
PACKET_NOTIFY, 0x02, 0x00, 0x01 /* Zero IID */
};
-static const guint8 broken_stream7_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream10_data[] = { /* Broken NOTIFY */
+ START_PACKET(),
PACKET_NOTIFY, 0x02, 0x01, 0x00 /* Zero CODE */
};
-static const guint8 broken_stream8_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream11_data[] = { /* Broken NOTIFY */
+ START_PACKET(),
PACKET_NOTIFY, 0x06, 0xff, 0xff, 0xff, 0xff, 0x7f /* Invalid IID */, 0x01
};
-static const guint8 broken_stream9_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream12_data[] = { /* Broken NOTIFY */
+ START_PACKET(),
PACKET_NOTIFY, 0x06, 0x01, 0xff, 0xff, 0xff, 0xff, 0x7f /* Invalid CODE */
};
-static const guint8 broken_stream10_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream13_data[] = { /* Broken NOTIFY */
+ START_PACKET(),
PACKET_NOTIFY, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
-static const guint8 broken_stream11_data[] = { /* Broken NOTIFY */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream14_data[] = { /* Broken NOTIFY */
+ START_PACKET(),
PACKET_NOTIFY, 0x08, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
-static const guint8 broken_stream12_data[] = { /* REQUEST before START */
+static const guint8 broken_stream15_data[] = { /* REQUEST before START */
PACKET_REQUEST, 0x04, 0x01, 0x02, 0x03, 0x00,
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION
+ START_PACKET()
};
-static const guint8 broken_stream13_data[] = { /* Broken REQUEST */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
+static const guint8 broken_stream16_data[] = { /* Broken REQUEST */
+ START_PACKET(),
PACKET_REQUEST, 0x01, 0x80 /* Truncated IID */
};
-static const guint8 broken_stream14_data[] = { /* Broken REQUEST */
- PACKET_START, 0x01, GIORPC_PROTOCOL_VERSION,
|
[-]
[+]
|
Changed |
_service:tar_git:libgiorpc-1.0.0+master.20231112152746.7614011.tar.bz2/unit/test_util/test_util.c
^
|
@@ -1,25 +1,29 @@
/*
* Copyright (C) 2023 Slava Monich <slava@monich.com>
*
+ * You may use this file under the terms of the BSD license as follows:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the names of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@@ -62,6 +66,115 @@
}
/*==========================================================================*
+ * tlv_array
+ *==========================================================================*/
+typedef struct {
+ const char* name;
+ GUtilData input;
+ const guint* tags;
+ gboolean result;
+ const GUtilData* values;
+} TestTlvArray;
+
+static const guint8 test_tlv_array_input_empty[] = { 0 };
+static const guint test_tlv_array_tags_1[] = { 1, 0 };
+static const guint test_tlv_array_tags_1_2[] = { 1, 2, 0 };
+static const guint8 test_tlv_array_input_dup[] = {
+ 0x02,
+ 0x01, 0x02, 0x03, 0x04,
+ 0x01, 0x00
+};
+static const guint8 test_tlv_array_input_tags_x[] = {
+ 0x01,
+ 0x7f, 0x00
+};
+static const guint8 test_tlv_array_input_tags_2_x[] = {
+ 0x02,
+ 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x7f, 0x00
+};
+static const GUtilData test_tlv_array_output_1_empty[] = { { NULL, 0 } };
+static const guint8 test_tlv_array_output_2_data[] = { 0x04, 0x05, 0x06 };
+static const GUtilData test_tlv_array_output_x_2[] = {
+ { NULL, 0 },
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_output_2_data) }
+};
+static const guint8 test_tlv_array_input_garbage1[] = {
+ 0xff
+};
+static const guint8 test_tlv_array_input_garbage2[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05
+};
+
+static const TestTlvArray test_tlv_array_data[] = {
+#define TEST_CASE(x) TEST_("tlv_array/") x
+ {
+ TEST_CASE("empty"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_empty) },
+ test_tlv_array_tags_1, TRUE, test_tlv_array_output_1_empty
+ },{
+ TEST_CASE("dup"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_dup) },
+ test_tlv_array_tags_1, FALSE, NULL
+ },{
+ TEST_CASE("unknown_tag/1"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_tags_x) },
+ test_tlv_array_tags_1, TRUE, test_tlv_array_output_1_empty
+ },{
+ TEST_CASE("unknown_tag/2"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_tags_2_x) },
+ test_tlv_array_tags_1_2, TRUE, test_tlv_array_output_x_2
+ },{
+ TEST_CASE("garbage/1"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_garbage1) },
+ test_tlv_array_tags_1, FALSE, NULL
+ },{
+ TEST_CASE("garbage/2"),
+ { TEST_ARRAY_AND_SIZE(test_tlv_array_input_garbage2) },
+ test_tlv_array_tags_1, FALSE, NULL
+ }
+#undef TEST_CASE
+};
+
+static
+void
+test_tlv_array(
+ gconstpointer data)
+{
+ const TestTlvArray* test = data;
+ const guint* tag = test->tags;
+ GUtilData* vals = NULL;
+ GUtilRange in;
+ int n = 0;
+
+ while (*tag++) n++;
+ vals = g_new(GUtilData, n);
+ memset(vals, 0xaa, sizeof(vals[0]) * n);
+
+ in.end = (in.ptr = test->input.bytes) + test->input.size;
+ g_assert_cmpint(giorpc_tlv_array_decode(&in, test->tags, vals),
+ ==, test->result);
+
+ if (test->result) {
+ int i;
+
+ g_assert(in.ptr == in.end);
+ for (i = 0; i < n; i++) {
+ const GUtilData* expected = test->values + i;
+
+ g_assert_cmpuint(vals[i].size, == ,expected->size);
+ if (expected->size) {
+ g_assert(!memcmp(vals[i].bytes, test->values[i].bytes,
+ expected->size));
+ }
+ }
+ } else {
+ g_assert(in.ptr == test->input.bytes);
+ }
+ g_free(vals);
+}
+
+/*==========================================================================*
* read_write
*==========================================================================*/
@@ -354,9 +467,15 @@
int main(int argc, char* argv[])
{
+ guint i;
signal(SIGPIPE, SIG_IGN);
g_test_init(&argc, &argv, NULL);
test_init(&test_opt, argc, argv);
+
+ for (i = 0; i < G_N_ELEMENTS(test_tlv_array_data); i++) {
+ g_test_add_data_func(test_tlv_array_data[i].name,
+ test_tlv_array_data + i, test_tlv_array);
+ }
g_test_add_func(TEST_("version"), test_version);
g_test_add_func(TEST_("read_write"), test_read_write);
g_test_add_func(TEST_("read_cancel"), test_read_cancel);
|