summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-07 22:52:47 +0800
committerMole Shang <[email protected]>2023-08-07 22:59:19 +0800
commit204ab98bea93754beef914fe93ee249e346ee628 (patch)
treec056c82f4de392be506ed2298dbb66411414e350 /src/main.c
parentb6c2d97d3bf98c46656a7e6697c1c0f4686d7d97 (diff)
downloadhinata-204ab98bea93754beef914fe93ee249e346ee628.tar.gz
hinata-204ab98bea93754beef914fe93ee249e346ee628.tar.bz2
hinata-204ab98bea93754beef914fe93ee249e346ee628.zip
hinata: support specifying cookies in curl_easy
We use tomlc99 to parse strings. To use cookies for higher resolution video downloading, add a config.toml in the executable path. e.g. ```filename: config.toml cookie="SESSDATA=xxx; some_more_cookie=xxx" ```
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index e9d22f1..ecd9381 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,10 +1,12 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <curl/curl.h>
+#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
+#include "toml.h"
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
#define NK_INCLUDE_FIXED_TYPES
@@ -29,6 +31,7 @@
#include "unifont.h"
extern int win_width, win_height;
+static char *cookie;
extern void load_ui(struct ui_struct *);
static void error_callback(int e, const char *d) {
printf("Error %d: %s\n", e, d);
@@ -40,8 +43,34 @@ int main(void) {
/* Set locale*/
setlocale(LC_ALL, ".UTF-8");
+ /* Parse config */
+ // NOTICE: string parsed from toml should always be freed afterwards!!!
+ {
+ FILE *fp;
+ const char *config_file = "config.toml";
+ char errbuf[UCHAR_MAX];
+
+ fp = fopen(config_file, "r");
+ if (!fp) {
+ fprintf(stderr, "[tomlc99] Cannot open %s, applying default config...\n",
+ config_file);
+ } else {
+ toml_table_t *conf = toml_parse_file(fp, errbuf, sizeof(errbuf));
+ fclose(fp);
+
+ if (!conf) {
+ fprintf(stderr, "[tomlc99] Cannot parse %s\n", config_file);
+ }
+ toml_datum_t cookie_datum = toml_string_in(conf, "cookie");
+ if (cookie_datum.ok) {
+ printf("[tomlc99] Found cookie string in config.toml, applying...\n");
+ cookie = cookie_datum.u.s;
+ }
+ }
+ }
+
/* Curl */
- curl_init();
+ curl_init(cookie);
/* GLFW */
struct nk_glfw glfw = {0};