]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add proto by subtrs function
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 23 May 2018 12:59:14 +0000 (18:59 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 23 May 2018 13:10:22 +0000 (19:10 +0600)
src/include/dict.h
src/lib/util/dict.c

index 8e225d2d995e0d83f87bd8a7601dd969656e1a6a..d8568d3096c6010ef39d12de78352a7999b1ceb9 100644 (file)
@@ -256,6 +256,8 @@ ssize_t                     fr_dict_attr_by_oid(fr_dict_t *dict, fr_dict_attr_t const **parent,
  */
 fr_dict_attr_t const   *fr_dict_root(fr_dict_t const *dict);
 
+fr_dict_t              *fr_dict_by_protocol_substr(char const **name);
+
 fr_dict_t              *fr_dict_by_protocol_name(char const *name);
 
 fr_dict_t              *fr_dict_by_protocol_num(unsigned int num);
index 1652121c7cdb8f18f881f8094485be297cd7ee6e..97e440adfb578cdaa9a7c8bc9d61246406a10891 100644 (file)
@@ -2877,6 +2877,55 @@ fr_dict_attr_t const *fr_dict_root(fr_dict_t const *dict)
        return dict->root;
 }
 
+/** Look up a protocol name embedded in another string
+ *
+ * @param[in,out] name         string start.
+ * @return
+ *     - Attribute matching name.
+ *     - NULL if no matching attribute could be found.
+ */
+fr_dict_t *fr_dict_by_protocol_substr(char const **name)
+{
+       fr_dict_attr_t          root;
+       fr_dict_t               find = { .root = &root };
+
+       fr_dict_t               *dict;
+       char const              *p;
+       size_t                  len;
+
+       if (!protocol_by_name || !name || !*name) return NULL;
+
+       memset(&root, 0, sizeof(root));
+
+       /*
+        *      Advance p until we get something that's not part of
+        *      the dictionary attribute name.
+        */
+       for (p = *name; fr_dict_attr_allowed_chars[(int)*p] && (*p != '.'); p++);
+
+       len = p - *name;
+       if (len > FR_DICT_ATTR_MAX_NAME_LEN) {
+               fr_strerror_printf("Attribute name too long");
+               return NULL;
+       }
+
+       root.name = talloc_bstrndup(NULL, *name, len);
+       if (!root.name) {
+               fr_strerror_printf("Out of memory");
+               return NULL;
+       }
+       dict = fr_hash_table_finddata(protocol_by_name, &find);
+       talloc_const_free(root.name);
+
+       if (!dict) {
+               fr_strerror_printf("Unknown protocol '%.*s'", (int) len, *name);
+               return NULL;
+       }
+       *name = p;
+
+       return dict;
+}
+
 /** Lookup a protocol by its name
  *
  * @param[in] name of the protocol to locate.