Files
iptv-downloader/iptv_api.c
T

27 lines
898 B
C
Raw Normal View History

#include "iptv_api.h"
#include "config.h"
#include "buf.h"
#include <curl/curl.h>
#include <stdio.h>
static size_t curl_write_buf(char *ptr, size_t sz, size_t n, void *ud) {
buf_append((Buf*)ud, ptr, sz*n); return sz*n;
}
char *api_get(const char *action, const char *extra) {
CURL *c = curl_easy_init();
Buf b; buf_init(&b);
char url[1024];
snprintf(url, sizeof(url), "%s?username=%s&password=%s&action=%s%s",
g_cfg.iptv_api, g_cfg.iptv_user, g_cfg.iptv_pass,
action, extra ? extra : "");
curl_easy_setopt(c, CURLOPT_URL, url);
curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, curl_write_buf);
curl_easy_setopt(c, CURLOPT_WRITEDATA, &b);
curl_easy_setopt(c, CURLOPT_TIMEOUT, CURL_API_TIMEOUT);
curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_perform(c);
curl_easy_cleanup(c);
return b.data; /* caller frees */
}