summaryrefslogtreecommitdiffstats
path: root/src/util/profile/testmod
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2011-07-20 19:14:28 +0000
committerGreg Hudson <ghudson@mit.edu>2011-07-20 19:14:28 +0000
commit6ea59e4695628ef53bf18ce2e837c2edc4879d0f (patch)
tree023906e6a8112e9cd5ef231d5613d2f891f04a6d /src/util/profile/testmod
parenteeb43dd0f42f3f9cd93cf19dda0a303dbbca0909 (diff)
downloadkrb5-6ea59e4695628ef53bf18ce2e837c2edc4879d0f.tar.gz
krb5-6ea59e4695628ef53bf18ce2e837c2edc4879d0f.tar.xz
krb5-6ea59e4695628ef53bf18ce2e837c2edc4879d0f.zip
Add support for loadable profile modules
ticket: 6929 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25025 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/testmod')
-rw-r--r--src/util/profile/testmod/Makefile.in22
-rw-r--r--src/util/profile/testmod/deps7
-rw-r--r--src/util/profile/testmod/proftest.exports1
-rw-r--r--src/util/profile/testmod/testmod_main.c104
4 files changed, 134 insertions, 0 deletions
diff --git a/src/util/profile/testmod/Makefile.in b/src/util/profile/testmod/Makefile.in
new file mode 100644
index 0000000000..fdd3663282
--- /dev/null
+++ b/src/util/profile/testmod/Makefile.in
@@ -0,0 +1,22 @@
+mydir=util$(S)profile$(S)testmod
+BUILDTOP=$(REL)..$(S)..$(S)..
+KRB5_RUN_ENV = @KRB5_RUN_ENV@
+DEFS=@DEFS@
+
+LOCALINCLUDES = -I.. -I$(srcdir)/..
+
+LIBBASE=proftest
+LIBMAJOR=0
+LIBMINOR=0
+SO_EXT=.so
+
+STOBJLISTS=OBJS.ST
+STLIBOBJS=testmod_main.o
+
+SRCS=$(srcdir)/testmod_main.c
+
+check-unix:: proftest$(DYNOBJEXT)
+clean-unix:: clean-libs clean-libobjs
+
+@libnover_frag@
+@libobj_frag@
diff --git a/src/util/profile/testmod/deps b/src/util/profile/testmod/deps
new file mode 100644
index 0000000000..c5583074ff
--- /dev/null
+++ b/src/util/profile/testmod/deps
@@ -0,0 +1,7 @@
+#
+# Generated makefile dependencies follow.
+#
+testmod_main.so testmod_main.po $(OUTPRE)testmod_main.$(OBJEXT): \
+ $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/profile.h \
+ $(COM_ERR_DEPS) $(top_srcdir)/include/k5-platform.h \
+ $(top_srcdir)/include/k5-thread.h testmod_main.c
diff --git a/src/util/profile/testmod/proftest.exports b/src/util/profile/testmod/proftest.exports
new file mode 100644
index 0000000000..b1b975ffa2
--- /dev/null
+++ b/src/util/profile/testmod/proftest.exports
@@ -0,0 +1 @@
+profile_module_init
diff --git a/src/util/profile/testmod/testmod_main.c b/src/util/profile/testmod/testmod_main.c
new file mode 100644
index 0000000000..c58ac04874
--- /dev/null
+++ b/src/util/profile/testmod/testmod_main.c
@@ -0,0 +1,104 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* util/profile/proftest/test.c - Test dynamic profile module */
+/*
+ * Copyright (C) 2011 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+/*
+ * This file implements a very simple profile module which just returns the
+ * residual string and the number of copies in response to any query. The full
+ * range of vtable profile operations is tested elsewhere.
+ */
+
+#include "k5-platform.h"
+#include "profile.h"
+
+struct data {
+ char *residual;
+ int gen;
+};
+
+static long
+get_values(void *cbdata, const char *const *names, char ***ret_values)
+{
+ struct data *d = cbdata;
+
+ *ret_values = calloc(3, sizeof(*ret_values));
+ (*ret_values)[0] = strdup(d->residual);
+ asprintf(&(*ret_values)[1], "%d", d->gen);
+ (*ret_values)[2] = NULL;
+ return 0;
+}
+
+static void
+free_values(void *cbdata, char **values)
+{
+ char **v;
+
+ for (v = values; *v; v++)
+ free(*v);
+ free(values);
+}
+
+static void
+cleanup(void *cbdata)
+{
+ struct data *d = cbdata;
+
+ free(d->residual);
+ free(d);
+}
+
+static long
+copy(void *cbdata, void **ret_cbdata)
+{
+ struct data *old_data = cbdata, *new_data;
+
+ new_data = malloc(sizeof(*new_data));
+ new_data->residual = strdup(old_data->residual);
+ new_data->gen = old_data->gen + 1;
+ *ret_cbdata = new_data;
+ return 0;
+}
+
+long
+profile_module_init(const char *residual, struct profile_vtable *vtable,
+ void **cb_ret);
+
+long
+profile_module_init(const char *residual, struct profile_vtable *vtable,
+ void **cb_ret)
+{
+ struct data *d;
+
+ d = malloc(sizeof(*d));
+ d->residual = strdup(residual);
+ d->gen = 0;
+ *cb_ret = d;
+
+ vtable->get_values = get_values;
+ vtable->free_values = free_values;
+ vtable->cleanup = cleanup;
+ vtable->copy = copy;
+ return 0;
+}