Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created June 10, 2013 16:32
Show Gist options
  • Save KristianLyng/5750184 to your computer and use it in GitHub Desktop.
Save KristianLyng/5750184 to your computer and use it in GitHub Desktop.
This is what the world has been waiting for: Integration of COBOL and Varnish. http://kly.no/varnish/cobol.png
backend foo {
.host = "kly.no";
}
C{
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <libcob/common.h>
}C
sub vcl_recv {
error 200 "meh";
}
sub vcl_error {
C{
void *f;
void (*func)(void);
char *error;
FILE *tmp = stdout;
FILE *tmp2;
char buffer[1024];
int i;
int argc = 1;
char *argv[] = {"varnishd"};
f = dlopen("/home/kristian/src/cobol/HELLO-WORLD.so",RTLD_LAZY);
if (!f) {
fprintf(stderr,"%s\n", dlerror());
exit(EXIT_FAILURE);
}
dlerror();
func = dlsym(f, "HELLO__WORLD");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n",error);
exit(EXIT_FAILURE);
}
tmp2 = tmpfile();
stdout = tmp2;
cob_init(argc, argv);
func();
stdout = tmp;
fflush(tmp2);
rewind(tmp2);
i = fread(buffer,1,1023,tmp2);
printf("Got %d bytes\n",i);
if (i>0) {
buffer[i] = '\0';
printf("We got: %s. So there.\n",buffer);
VRT_synth_page(sp, 0, buffer,vrt_magic_string_end);
} else {
printf("Mmeh\n");
}
}C
return(deliver);
}
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, world'.
@KristianLyng
Copy link
Author

Err, btw, this C code is not representative of my regular way of coding. It's also about as thread safe as a cat. And also, will break upon multiple uses. It was just extracted from a PoC main() :)

For real COBOL support, I take 5000USD per hour for consultancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment