]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: introduce new YANG helper function
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 4 Jan 2019 21:08:10 +0000 (19:08 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 18 Jan 2019 18:15:41 +0000 (16:15 -0200)
One use case for the new yang_data_list_find() function is to find
input parameters in RPC northbound callbacks easily, without the
need to iterate over the input parameters manually.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/yang.c
lib/yang.h

index 71b41c35d8225a660650a573549b1c93617c12a2..4077b29746a01ed5a1cdb72c922b0c90b214e9bc 100644 (file)
@@ -608,6 +608,25 @@ struct list *yang_data_list_new(void)
        return list;
 }
 
+struct yang_data *yang_data_list_find(const struct list *list,
+                                     const char *xpath_fmt, ...)
+{
+       char xpath[XPATH_MAXLEN];
+       struct yang_data *data;
+       struct listnode *node;
+       va_list ap;
+
+       va_start(ap, xpath_fmt);
+       vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap);
+       va_end(ap);
+
+       for (ALL_LIST_ELEMENTS_RO(list, node, data))
+               if (strmatch(data->xpath, xpath))
+                       return data;
+
+       return NULL;
+}
+
 static void *ly_dup_cb(const void *priv)
 {
        /* Make a shallow copy of the priv pointer. */
index 3259189e987099ba9ab83f1c388a8b25e999b258..09d92cafddf128bffcce93a33e585ad7f0f70fef 100644 (file)
@@ -509,6 +509,21 @@ extern void yang_data_free(struct yang_data *data);
  */
 extern struct list *yang_data_list_new(void);
 
+/*
+ * Find the yang_data structure corresponding to an XPath in a list.
+ *
+ * list
+ *    list of yang_data structures to operate on.
+ *
+ * xpath_fmt
+ *    XPath to search for (format string).
+ *
+ * Returns:
+ *    Pointer to yang_data if found, NULL otherwise.
+ */
+extern struct yang_data *yang_data_list_find(const struct list *list,
+                                            const char *xpath_fmt, ...);
+
 /*
  * Initialize the YANG subsystem. Should be called only once during the
  * daemon initialization process.