#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "HsFFI.h"
struct session;
struct session *c_newSession();
void c_freeSession(struct session*);
struct page;
struct page *c_initialReferer();
void *c_fetchURL(struct session*, char*, struct page*, char*);
//struct page **c_fetchURLs(struct session*, struct page*, char**); // FIXME segfaults.
void c_freePage(struct page*);
char *c_renderDoc(struct session*, struct page*);
char **c_extractLinks(struct page*);
char **c_docLinksAndRendering(struct session*, struct page*); // FIXME segfaults.
int main(int argc, char **argv) {
hs_init(&argc, &argv);
struct session *session = c_newSession();
struct page *referer = c_initialReferer();
struct page *page = c_fetchURL(session, "text/xml text/html text/plain", referer, argv[1]);
char *ssml = c_renderDoc(session, page);
char **links = c_extractLinks(page);
printf("%s\n", ssml);
for (int i = 0; strcmp(links[i], " ") != 0; i++) fprintf(stderr, "%s\n", links[i]);
c_freePage(page);
c_freePage(referer);
c_freeSession(session);
hs_exit();
}