summaryrefslogtreecommitdiffstats
path: root/tcpd/tlscachetest.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /tcpd/tlscachetest.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'tcpd/tlscachetest.c')
-rw-r--r--tcpd/tlscachetest.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/tcpd/tlscachetest.c b/tcpd/tlscachetest.c
new file mode 100644
index 0000000..ce58d1d
--- /dev/null
+++ b/tcpd/tlscachetest.c
@@ -0,0 +1,72 @@
+/*
+** Copyright 2002-2006 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+#define TLSCACHEMINSIZE (sizeof(struct hdr) + 5 * (sizeof(struct obj)+8))
+#include "tlscache.c"
+
+
+static int printcache(void *rec, size_t recsize, int *doupdate,
+ void *arg)
+{
+ if (fwrite((const char *)rec, recsize, 1, stdout) == 1)
+ printf("\n");
+ return 0;
+}
+
+static int replacecache(void *rec, size_t recsize, int *doupdate,
+ void *arg)
+{
+ const char *p=(const char *)arg;
+ const char *q;
+
+ if ((q=strchr(p, '-')) == NULL || strlen(q+1) != q-p)
+ return (0);
+
+ if (recsize == q-p && memcmp(rec, p, q-p) == 0)
+ {
+ memcpy(rec, q+1, q-p);
+ *doupdate=1;
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct CACHE *p=tls_cache_open("test.dat", TLSCACHEMINSIZE);
+
+ if (!p)
+ {
+ perror("test.dat");
+ return (-1);
+ }
+
+ if (argc > 1)
+ {
+ char *s=argv[1];
+
+ if (*s == '+')
+ {
+ ++s;
+ if (tls_cache_add(p, s, strlen(s)))
+ {
+ perror("tls_cache_add");
+ }
+ }
+
+ if (*s == '-')
+ {
+ if (tls_cache_walk(p, replacecache, s+1) < 0)
+ {
+ perror("tls_cache_walk");
+ exit(1);
+ }
+ }
+ }
+
+ if (tls_cache_walk(p, printcache, NULL) < 0)
+ perror("tls_cache_walk");
+ tls_cache_close(p);
+ return (0);
+}