Skip to content

Commit

Permalink
libsoup-3.0 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Oct 16, 2023
1 parent 71e2cea commit 6f8471c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
10 changes: 9 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ endif
if get_option('libcurl')
libcurl = dependency('libcurl', static:get_option('static'), required:false)
if not libcurl.found()
conf += ['no_libcurl']
else
conf += ['libcurl']
args += run_command('pkg-config', '--libs','libcurl', pkgconfig_arg ,check:true).stdout().strip().split(' ')
if get_option('libbrotli')
args += ['-lbrotlicommon']
endif
endif
#libsoup-3.0 (no vapi)
elif get_option('libsoup')
libsoup = dependency('libsoup-3.0', static:get_option('static'), required:false)
if not libsoup.found()
else
conf += ['libsoup']
args += run_command('pkg-config', '--libs', '--cflags', 'libsoup-3.0', pkgconfig_arg ,check:true).stdout().strip().split(' ')
endif
endif

#libmagic (no vapi)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option('check_oem', type: 'boolean', value: 'true')
option('libarchive', type: 'boolean', value: 'true')
option('libreadline', type: 'boolean', value: 'true')
option('libcurl', type: 'boolean', value: 'true')
option('libsoup', type: 'boolean', value: 'true')
option('libmagic', type: 'boolean', value: 'true')
option('libbrotli', type: 'boolean', value: 'true')
option('storagedir', type: 'string', value: 'var/lib/ymp')
Expand Down
2 changes: 1 addition & 1 deletion src/ccode/fetcher.c → src/ccode/fetcher_curl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef no_libcurl
#ifdef libcurl
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down
40 changes: 40 additions & 0 deletions src/ccode/fetcher_soup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifdef libsoup

#ifndef readfile_raw
char* readfile_raw(char* file);
int remove_file(char* file);
#endif

#include <libsoup/soup.h>
int fetch (char* url, char* path){
GError *error = NULL;
SoupSession * session = soup_session_new();
SoupMessage * msg = soup_message_new(SOUP_METHOD_GET, url);
GInputStream * in_stream = soup_session_send(
session,
msg,
NULL,
&error);
GFile * output_file = g_file_new_for_path(path);
GFileOutputStream * out_stream = g_file_create(output_file,
G_FILE_CREATE_NONE, NULL, NULL);
g_output_stream_splice((GOutputStream * ) out_stream, in_stream,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
NULL, &error);
if(error){
return 0;
}
return 1;
}

char* fetch_string(char* url){
char* file = "/tmp/.ymp-soup-file.tmp";
if(fetch(url, file)){
return "";
}
char* ctx = readfile_raw(file);
remove_file(file);
return ctx;
}

#endif
2 changes: 1 addition & 1 deletion src/util/fetcher.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public delegate void fetcher_process (double current, double total, string filename);
#if no_libcurl
#if no_fetcher
public bool fetch (string url, string path) {
return 0 == run ("wget -U '" + get_value ("useragent") + "' -c '" + url + "' -O '" + path + "'");
}
Expand Down

0 comments on commit 6f8471c

Please sign in to comment.