]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move compare to common API
authorAlan T. DeKok <aland@freeradius.org>
Tue, 24 Jul 2018 17:52:54 +0000 (13:52 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 24 Jul 2018 17:52:54 +0000 (13:52 -0400)
src/lib/server/command.c
src/lib/server/command.h
src/lib/server/module.c

index 68f1fcdba39ae4c15ce033f4fdcd0613e760c752..1eab71b2344adbe28150fc832023869c69c31c4c 100644 (file)
@@ -2670,3 +2670,26 @@ int fr_command_print_help(FILE *fp, fr_cmd_t *head, char const *text)
 
        return 0;
 }
+
+/* See if partial string matches a full string.
+ *
+ * @param word the partial word to match
+ * @param name the name which "word" might match
+ * @return
+ *     - false if they do not match
+ *     - true if "word" is a prefix of "name"
+ *
+ */
+bool fr_command_strncmp(const char *word, const char *name)
+{
+       char const *p, *q;
+
+       if (!*word) return true;
+
+       SKIP_NAME(name);
+
+       /*
+        *      If we're done P (partial or full), that's a match.
+        */
+       return (*p == '\0');
+}
index 51e5581ccd101ea8e7ef8fc872c65674cb47785d..deb4c581abea51ff6f7fc98faab631737c1d1dd9 100644 (file)
@@ -90,6 +90,7 @@ void fr_command_info_init(TALLOC_CTX *ctx, fr_cmd_info_t *info);
 int fr_command_complete(fr_cmd_t *head, char const *text, int start,
                        int max_expansions, char const **expansions);
 int fr_command_print_help(FILE *fp, fr_cmd_t *head, char const *text);
+bool fr_command_strncmp(const char *text, const char *name) CC_HINT(nonnull);
 
 #ifdef __cplusplus
 }
index 313889b46bed98790f676ebc97fc9601fd7a0cf4..0647360fb3ec85328609ad13a844222f4d6aaa52 100644 (file)
@@ -756,29 +756,14 @@ static int _module_tab_expand(void *instance, void *ctx)
 {
        module_instance_t *mi = talloc_get_type_abort(instance, module_instance_t);
        module_tab_expand_t *mt = ctx;
-       char const *p, *q;
 
        if (mt->count >= mt->max_expansions) return 1;
 
-       if (!*mt->text) {
-       matched:
+       if (fr_command_strncmp(mt->text, mi->name)) {
                mt->expansions[mt->count] = strdup(mi->name);
                mt->count++;
-               return 0;
-       }
-
-       /*
-        *      @todo - put this in a helper function.
-        */
-       p = mt->text;
-       q = mi->name;
-       while (*p && *q && (*p == *q)) {
-               p++;
-               q++;
        }
 
-       if (!*p) goto matched;
-
        return 0;
 }