]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Move configuration parsing into libcmd
authorSimon Wilkinson <sxw@your-file-system.com>
Sun, 25 Sep 2011 20:30:02 +0000 (21:30 +0100)
committerDerrick Brashear <shadow@dementix.org>
Mon, 9 Apr 2012 22:36:41 +0000 (15:36 -0700)
Rework the API for directly parsing configuration files and move it
out of util/ and into libcmd, where we can actually make use of it.

This is a raw API - it provides direct access to the parser. The
eventual intent is that this will predominantly be contained within
libcmd itself, which will then wrap this with the more general purpose
Option functions

Change-Id: I9f4a9c373c4123023120f69e595068ead6160507
Reviewed-on: http://gerrit.openafs.org/7132
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
src/cmd/Makefile.in
src/cmd/cmd.p.h
src/cmd/krb5_locl.h [new file with mode: 0644]
src/util/Makefile.in
src/util/afsutil_prototypes.h
src/util/krb5_locl.h [deleted file]

index 9af3ce8a2c58844b4e90a652c196fe864ecf27fb..ef44d5b7c0a8418be9c02ac15505db99d379adf1 100644 (file)
@@ -10,7 +10,7 @@ include @TOP_OBJDIR@/src/config/Makefile.config
 include @TOP_OBJDIR@/src/config/Makefile.lwp
 
 
-LIBOBJS=cmd_errors.o cmd.o 
+LIBOBJS=cmd_errors.o cmd.o config_file.o
 LIBPICOBJS=cmd_errors_pic.o cmd_pic.o
 LIB64OBJS=cmd_errors64.o cmd64.o 
 
@@ -42,6 +42,9 @@ cmd_errors.o: cmd_errors.c
 
 cmd.o: cmd.c cmd.h
 
+config_file.o: $(TOP_SRCDIR)/external/heimdal/krb5/config_file.c krb5_locl.h
+       $(AFS_CCRULE) -c $(TOP_SRCDIR)/external/heimdal/krb5/config_file.c
+
 cmd_errors64.o: cmd_errors.c
        ${CC} $(COMMON_CFLAGS) $(CPPFLAGS) ${XCFLAGS64} \
                -c -o cmd_errors64.o cmd_errors.c
index d7c58fe17485d4a341d6df97914aa5fcb505c500..69b5feaa3fdd84134f24dd39c957e1ef599700b0 100644 (file)
@@ -97,4 +97,31 @@ extern int cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **
 extern int cmd_OptionAsFlag(struct cmd_syndesc *syn, int pos, int *value);
 extern int cmd_OptionPresent(struct cmd_syndesc *syn, int pos);
 
+/* Config files */
+
+struct cmd_config_binding {
+    enum { cmd_config_string, cmd_config_list } type;
+    char *name;
+    struct cmd_config_binding *next;
+    union {
+       char *string;
+       struct cmd_config_binding *list;
+       void *generic;
+    } u;
+};
+
+/* Raw config file access */
+typedef struct cmd_config_binding cmd_config_binding;
+typedef struct cmd_config_binding cmd_config_section;
+
+extern int cmd_RawConfigParseFileMulti(const char *, cmd_config_section **);
+extern int cmd_RawConfigParseFile(const char *, cmd_config_section **);
+extern int cmd_RawConfigFileFree(cmd_config_section *s);
+extern const char* cmd_RawConfigGetString(const cmd_config_section *,
+                                         const char *, ...);
+extern int cmd_RawConfigGetBool(const cmd_config_section *, int, ...);
+extern int cmd_RawConfigGetInt(const cmd_config_section *, int, ...);
+extern const cmd_config_binding *cmd_RawConfigGetList
+       (const cmd_config_section *, ...);
+
 #endif /* __CMD_INCL__ */
diff --git a/src/cmd/krb5_locl.h b/src/cmd/krb5_locl.h
new file mode 100644 (file)
index 0000000..9b5b095
--- /dev/null
@@ -0,0 +1,190 @@
+
+/* This header file transforms the Heimdal config_parse.c profile
+ * parser into an AFS profile parser, hiding the krb5-ness of the parser
+ * behind the scenes.
+ */
+
+#include <afsconfig.h>
+#include <afs/stds.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <pwd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <roken.h>
+
+#include "cmd.h"
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+#define KRB5_BUFSIZ 1024
+
+#define KRB5_LIB_FUNCTION static AFS_UNUSED
+#define KRB5_LIB_CALL
+
+#define KRB5_DEPRECATED_FUNCTION(x)
+
+/* This value shouldn't be hard coded */
+#define KRB5_CONFIG_BADFORMAT                    (-1765328248L)
+
+#define N_(X,Y) X
+
+typedef struct cmd_config_binding krb5_config_binding;
+typedef struct cmd_config_binding krb5_config_section;
+
+#define krb5_config_list cmd_config_list
+#define krb5_config_string cmd_config_string
+
+struct krb5_context_data {
+    krb5_config_section *cf;
+};
+
+typedef struct krb5_context_data * krb5_context;
+typedef int krb5_error_code;
+typedef int krb5_boolean;
+typedef time_t krb5_deltat;
+
+static const void *_krb5_config_vget(krb5_context,
+                                    const krb5_config_section *, int,
+                                    va_list);
+static const void *_krb5_config_vget_next(krb5_context,
+                                         const krb5_config_section *,
+                                         const krb5_config_binding **,
+                                         int, va_list);
+static const char *krb5_config_vget_string(krb5_context,
+                                          const krb5_config_section *,
+                                          va_list);
+static const char *krb5_config_vget_string_default(krb5_context,
+                                          const krb5_config_section *,
+                                          const char *,
+                                          va_list);
+static const krb5_config_binding * krb5_config_vget_list
+       (krb5_context, const krb5_config_section *, va_list);
+static krb5_error_code krb5_config_parse_file_multi
+       (krb5_context, const char *, krb5_config_section **);
+static krb5_error_code krb5_config_parse_file
+       (krb5_context, const char *, krb5_config_section **);
+static krb5_error_code krb5_config_file_free
+       (krb5_context, krb5_config_section *);
+static krb5_boolean krb5_config_vget_bool_default
+       (krb5_context, const krb5_config_section *, int, va_list);
+static int krb5_config_vget_int_default
+       (krb5_context, const krb5_config_section *, int, va_list);
+
+static krb5_error_code
+krb5_string_to_deltat(const char *str, krb5_deltat *t) {
+    return 1;
+}
+
+KRB5_LIB_FUNCTION void krb5_clear_error_message(krb5_context context) {
+    return;
+}
+
+static void krb5_set_error_message(krb5_context context, krb5_error_code ret,
+                                  const char *fmt, ...) {
+    return;
+}
+
+static int _krb5_homedir_access(krb5_context context) {
+    return 0;
+}
+
+static krb5_error_code
+krb5_abortx(krb5_context context, const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+
+    abort();
+}
+
+/* Wrappers */
+
+int
+cmd_RawConfigParseFileMulti(const char *fname, cmd_config_section **res) {
+    return krb5_config_parse_file_multi(NULL, fname, res);
+}
+
+int
+cmd_RawConfigParseFile(const char *fname, cmd_config_section **res) {
+    return krb5_config_parse_file(NULL, fname, res);
+}
+
+int
+cmd_RawConfigFileFree(cmd_config_section *s) {
+    return krb5_config_file_free(NULL, s);
+}
+
+const char*
+cmd_RawConfigGetString(const cmd_config_section *c,
+                      const char *defval, ...)
+{
+    const char *ret;
+    va_list args;
+
+    assert(c != NULL);
+
+    va_start(args, defval);
+    ret = krb5_config_vget_string_default (NULL, c, defval, args);
+    va_end(args);
+    return ret;
+}
+
+int
+cmd_RawConfigGetBool(const cmd_config_section *c, int defval, ...)
+{
+    va_list ap;
+    krb5_boolean ret;
+
+    assert(c != NULL);
+
+    va_start(ap, defval);
+    ret = krb5_config_vget_bool_default (NULL, c, defval, ap);
+    va_end(ap);
+    return ret;
+}
+
+int
+cmd_RawConfigGetInt(const cmd_config_section *c, int defval, ...)
+{
+    va_list ap;
+    int ret;
+
+    assert(c != NULL);
+
+    va_start(ap, defval);
+    ret = krb5_config_vget_int_default (NULL, c, defval, ap);
+    va_end(ap);
+    return ret;
+}
+
+const cmd_config_binding *
+cmd_RawConfigGetList(const cmd_config_section *c, ...)
+{
+    va_list ap;
+    const cmd_config_binding *ret;
+
+    assert(c != NULL);
+
+    va_start(ap, c);
+    ret = krb5_config_vget_list (NULL, c, ap);
+    va_end(ap);
+
+    return ret;
+}
index 220cc7fbdba9f8a931436dece4ac8ebafbcdc05f..6de1ba183025cc08472fe2e4a2f2f4cc21fce170 100644 (file)
@@ -12,8 +12,7 @@ include @TOP_OBJDIR@/src/config/Makefile.lwp
 HELPER_SPLINT=@HELPER_SPLINT@
 
 
-objects =base64.o config_file.o ktime.o volparse.o \
-        hostparse.o exec.o \
+objects =base64.o ktime.o volparse.o hostparse.o exec.o \
         hputil.o kreltime.o get_krbrlm.o uuid.o serverLog.o \
         dirpath.o fileutil.o netutils.o flipbase64.o fstab.o \
         afs_atomlist.o afs_lhash.o pthread_glock.o tabular_output.o \
@@ -21,7 +20,6 @@ objects =base64.o config_file.o ktime.o volparse.o \
 
 objects_pic = \
        base64_pic.o \
-       config_file_pic.o \
        ktime_pic.o \
        volparse_pic.o \
        hostparse_pic.o \
@@ -178,9 +176,6 @@ ${objects}: ${includes}
 AFS_component_version_number_pic.o: AFS_component_version_number.c
        $(SHD_CCRULE) AFS_component_version_number.c
 
-config_file.o: ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c krb5_locl.h
-       $(AFS_CCRULE) -c ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c 
-
 sys.o: sys.c AFS_component_version_number.c ${includes}
 
 sys: sys.o 
@@ -190,9 +185,6 @@ sys: sys.o
 base64_pic.o: ${srcdir}/base64.c ${includes}
        $(SHD_CCRULE) ${srcdir}/base64.c
 
-config_file_pic.o: ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c krb5_locl.h
-       $(SHD_CCRULE) ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c
-
 ktime_pic.o: ${srcdir}/ktime.c ${includes}
        $(SHD_CCRULE) ${srcdir}/ktime.c
 
index c1f425a81ddb5803ad1d2c2e17d132673b3ecd12..592ac65fadcf2bca04f35de39a91aa838c9df019 100644 (file)
@@ -27,15 +27,6 @@ extern int base32_to_int(char *s);
 extern char *int_to_base64(b64_string_t s, int a);
 extern int base64_to_int(char *s);
 
-/* config_file.c && krb5_locl.h */
-typedef struct afs_config_section_struct afs_config_section;
-extern int afs_config_parse_file_multi(const char *, afs_config_section **);
-extern int afs_config_parse_file(const char *, afs_config_section **);
-extern int afs_config_file_free(afs_config_section *s);
-extern const char* fs_config_get_string(const afs_config_section *, ...);
-extern int afs_config_get_bool(const afs_config_section *, ...);
-extern int afs_config_get_int(const afs_config_section *c, ...);
-
 /* dirpath.c */
 extern unsigned int initAFSDirPath(void);
 extern const char *getDirPath(afsdir_id_t string_id);
diff --git a/src/util/krb5_locl.h b/src/util/krb5_locl.h
deleted file mode 100644 (file)
index 086eac7..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-
-/* This header file transforms the Heimdal config_parse.c profile
- * parser into an AFS profile parser, hiding the krb5-ness of the parser
- * behind the scenes.
- */
-
-#include <afsconfig.h>
-#include <afs/stds.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <pwd.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#ifndef TRUE
-# define TRUE 1
-#endif
-#ifndef FALSE
-# define FALSE 0
-#endif
-
-#define KRB5_BUFSIZ 1024
-
-#define KRB5_LIB_FUNCTION static AFS_UNUSED
-#define KRB5_LIB_CALL
-
-#define KRB5_DEPRECATED_FUNCTION(x)
-
-/* This value shouldn't be hard coded */
-#define KRB5_CONFIG_BADFORMAT                    (-1765328248L)
-
-#define N_(X,Y) X
-
-struct krb5_config_binding {
-    enum { krb5_config_string, krb5_config_list } type;
-    char *name;
-    struct krb5_config_binding *next;
-    union {
-        char *string;
-        struct krb5_config_binding *list;
-        void *generic;
-    } u;
-};
-
-typedef struct krb5_config_binding krb5_config_binding;
-
-typedef krb5_config_binding krb5_config_section;
-typedef krb5_config_section afs_config_section;
-
-struct krb5_context_data {
-    krb5_config_section *cf;
-};
-
-typedef struct krb5_context_data * krb5_context;
-typedef int krb5_error_code;
-typedef int krb5_boolean;
-typedef time_t krb5_deltat;
-
-static const void *_krb5_config_vget(krb5_context,
-                                    const krb5_config_section *, int,
-                                    va_list);
-static const void *_krb5_config_vget_next(krb5_context,
-                                         const krb5_config_section *,
-                                         const krb5_config_binding **,
-                                         int, va_list);
-static const char *krb5_config_vget_string(krb5_context,
-                                          const krb5_config_section *,
-                                          va_list);
-static const krb5_config_binding * krb5_config_vget_list
-       (krb5_context, const krb5_config_section *, va_list);
-static krb5_error_code krb5_config_parse_file_multi
-       (krb5_context, const char *, krb5_config_section **);
-static krb5_error_code krb5_config_parse_file
-       (krb5_context, const char *, krb5_config_section **);
-static krb5_error_code krb5_config_file_free
-       (krb5_context, krb5_config_section *);
-static krb5_boolean krb5_config_vget_bool
-       (krb5_context, const krb5_config_section *,va_list);
-static int krb5_config_vget_int
-       (krb5_context, const krb5_config_section *, va_list);
-
-static krb5_error_code
-krb5_string_to_deltat(const char *str, krb5_deltat *t) {
-    return 1;
-}
-
-KRB5_LIB_FUNCTION void krb5_clear_error_message(krb5_context context) {
-    return;
-}
-
-static void krb5_set_error_message(krb5_context context, krb5_error_code ret,
-                                  const char *fmt, ...) {
-    return;
-}
-
-/* Play it safe, by saying we're always suid. */
-static int issuid(void) {
-    return 1;
-}
-
-static int _krb5_homedir_access(krb5_context context) {
-    return 0;
-}
-
-static krb5_error_code
-krb5_abortx(krb5_context context, const char *fmt, ...)
-{
-    va_list ap;
-    va_start(ap, fmt);
-
-    vfprintf(stderr, fmt, ap);
-    va_end(ap);
-
-    abort();
-}
-
-/* Wrappers */
-
-int
-afs_config_parse_file_multi(const char *fname, afs_config_section **res) {
-    return krb5_config_parse_file_multi(NULL, fname, res);
-}
-
-int
-afs_config_parse_file(const char *fname, afs_config_section **res) {
-    return krb5_config_parse_file(NULL, fname, res);
-}
-
-int
-afs_config_file_free(afs_config_section *s) {
-    return krb5_config_file_free(NULL, s);
-}
-
-const char*
-afs_config_get_string(const afs_config_section *c, ...)
-{
-    const char *ret;
-    va_list args;
-
-    assert(c != NULL);
-
-    va_start(args, c);
-    ret = krb5_config_vget_string (NULL, c, args);
-    va_end(args);
-    return ret;
-}
-
-int
-afs_config_get_bool(const afs_config_section *c, ...)
-{
-    va_list ap;
-    krb5_boolean ret;
-
-    assert(c != NULL);
-
-    va_start(ap, c);
-    ret = krb5_config_vget_bool (NULL, c, ap);
-    va_end(ap);
-    return ret;
-}
-
-int
-afs_config_get_int(const krb5_config_section *c, ...)
-{
-    va_list ap;
-    int ret;
-
-    assert(c != NULL);
-
-    va_start(ap, c);
-    ret = krb5_config_vget_int (NULL, c, ap);
-    va_end(ap);
-    return ret;
-}
-