Use varnishd to extract vmod declarations

parent 0bc8866b
......@@ -25,9 +25,11 @@ TESTS = \
if CHKSUM
import_vmod_blob.h: vmod_get_h $(VMOD_BLOB)
PATH="$(VARNISH_TEST_PATH):$(PATH)" \
$(builddir)/vmod_get_h blob $(VMOD_BLOB) >$@.tmp
mv -f $@.tmp $@
import_vmod_blobdigest.h: vmod_get_h $(VMOD_BLOBDIGEST)
PATH="$(VARNISH_TEST_PATH):$(PATH)" \
$(builddir)/vmod_get_h blobdigest $(VMOD_BLOBDIGEST) >$@.tmp
mv -f $@.tmp $@
libvmod_tus_la_SOURCES = tus_blob.c
......
......@@ -32,6 +32,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include "vdef.h"
#include "vrt.h"
......@@ -45,10 +47,11 @@ const struct vrt_blob *vrt_null_blob = &(struct vrt_blob){
int
main(int argc, char **argv) {
void *dlhdl;
char buf[256];
char buf[256], vcl[64];
const struct vmod_data *d;
const char *name;
const char *file;
int i, fd;
if (argc < 3) {
fprintf(stderr, "need 2 arguments\n");
......@@ -58,6 +61,25 @@ main(int argc, char **argv) {
name = argv[1];
file = argv[2];
bprintf(buf, "vcl 4.1;backend none none;import %s from \"%s\";\n",
name, file);
bprintf(vcl, "/tmp/vmod_get_h_%s_XXXXXX", name);
fd = mkstemp(vcl);
assert(fd >= 0);
i = write(fd, buf, strlen(buf));
assert(i > 0);
i = close(fd);
assert(i == 0);
bprintf(buf, "varnishd -Cf %s 2>&1 | awk '"
"/BEGIN VMOD %s/ {p=1} "
"/END VMOD %s/ {exit} "
"/./ {if (p == 1) { print }; n;}"
"'", vcl, name, name);
printf("/* %s */\n", buf);
i = system(buf);
assert(i == 0);
dlhdl = dlopen(file, RTLD_LAZY | RTLD_LOCAL);
if (dlhdl == NULL) {
......@@ -71,7 +93,6 @@ main(int argc, char **argv) {
return (1);
}
printf("%s",d->proto);
printf("\nstatic const struct vmod_data import_%s = {\n", buf);
printf("\t.name =\t\t\"%s\",\n", d->name);
printf("\t.file_id =\t\"%s\",\n", d->file_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment