#include "http_curl.h"
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *url_encode(char *s) { return curl_easy_escape(NULL, s, 0); }

char *web_search(char *q) {
  char url[4096];
  char *q_encoded = url_encode(q);
  if (!q_encoded) {
    return NULL;
  }
  snprintf(url, sizeof(url), "https://static.molodetz.nl/search.cgi?query=%s", q_encoded);
  free(q_encoded);
  char *ret = curl_get(url);
  return ret;
}

char *web_search_news(char *q) {
  return web_search(q);
}
