]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add encode / decode callbacks for dictionaries
authorAlan T. DeKok <aland@freeradius.org>
Thu, 25 Jan 2024 16:49:40 +0000 (11:49 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 25 Jan 2024 17:01:06 +0000 (12:01 -0500)
with forward definitions for fr_pair_list_t, and fr_dbuff_t,
so that we don't have circular references

src/lib/util/dict.h
src/lib/util/pair.h

index 84f5986b5e30087342ee322b1a476e2e74094274..f7d933fad30a7356ef351a868236a1ba1e073e00 100644 (file)
@@ -288,6 +288,45 @@ typedef enum {
 typedef bool (*fr_dict_attr_valid_func_t)(fr_dict_t *dict, fr_dict_attr_t const *parent,
                                          char const *name, int attr, fr_type_t type, fr_dict_attr_flags_t *flags);
 
+/*
+ *     Forward declarations to avoid circular references.
+ */
+typedef struct pair_list_s fr_pair_list_t;
+typedef struct fr_dbuff_s fr_dbuff_t;
+
+/** A generic interface for decoding packets to fr_pair_ts
+ *
+ * A decoding function should decode a single top level packet from wire format.
+ *
+ * Note that unlike #fr_tp_proto_decode_t, this function is NOT passed an encode_ctx.  That is because when we
+ * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
+ *
+ * @param[in] ctx              to allocate new pairs in.
+ * @param[in] vps              where new VPs will be added
+ * @param[in] data             to decode.
+ * @param[in] data_len         The length of the incoming data.
+ * @return
+ *     - <= 0 on error.  May be the offset (as a negative value) where the error occurred.
+ *     - > 0 on success.  How many bytes were decoded.
+ */
+typedef ssize_t (*fr_dict_attr_decode_func_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps,
+                                             uint8_t const *data, size_t data_len);
+
+/** A generic interface for encoding fr_pair_ts to packets
+ *
+ * An encoding function should encode multiple VPs to a wire format packet
+ *
+ * Note that unlike #fr_tp_proto_encode_t, this function is NOT passed an encode_ctx.  That is because when we
+ * do cross-protocol encoding, the "outer" protocol has no information it can share with the "inner" protocol.
+ *
+ * @param[in] vps              vps to encode
+ * @param[in] dbuff            buffer where data can be written
+ * @return
+ *     - <= 0 on error.  May be the offset (as a negative value) where the error occurred.
+ *     - > 0 on success.  How many bytes were encoded
+ */
+typedef ssize_t(*fr_dict_attr_encode_func_t)(fr_dbuff_t *dbuff, fr_pair_list_t *vps);
+
 /** Protocol-specific callbacks in libfreeradius-PROTOCOL
  *
  */
@@ -298,6 +337,8 @@ typedef struct {
        fr_table_num_ordered_t  const *subtype_table;           //!< for "encrypt=1", etc.
        size_t                  subtype_table_len;              //!< length of subtype_table
        fr_dict_attr_valid_func_t attr_valid;                   //!< validation function for new attributes
+       fr_dict_attr_decode_func_t decode;                      //!< for decoding attributes
+       fr_dict_attr_encode_func_t encode;                      //!< for encoding attributes
 } fr_dict_protocol_t;
 
 typedef struct fr_dict_gctx_s fr_dict_gctx_t;
index 5e7fc7b66c322ff6e3f92da98789849f880fbeaa..84e96db4bfab0e2b344b38b439eeb618cf89205e 100644 (file)
@@ -49,7 +49,7 @@ typedef struct value_pair_s fr_pair_t;
 
 FR_TLIST_TYPES(fr_pair_order_list)
 
-typedef struct {
+typedef struct pair_list_s {
         FR_TLIST_HEAD(fr_pair_order_list)      order;                  //!< Maintains the relative order of pairs in a list.
 
        bool                             _CONST is_child;               //!< is a child of a VP