• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2021 Igalia S.L.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include "gstsouploader.h"
20 #include <gmodule.h>
21 
22 #ifdef HAVE_RTLD_NOLOAD
23 #include <dlfcn.h>
24 #endif
25 
26 #ifdef G_OS_WIN32
27 #include <windows.h>
28 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
29 #define GST_WINAPI_ONLY_APP
30 #endif
31 #endif /* G_OS_WIN32 */
32 
33 GST_DEBUG_CATEGORY (gst_soup_debug);
34 #define GST_CAT_DEFAULT gst_soup_debug
35 
36 #ifndef STATIC_SOUP
37 
38 /* G_OS_WIN32 is handled separately below */
39 #ifdef __APPLE__
40 #define LIBSOUP_3_SONAME "libsoup-3.0.0.dylib"
41 #define LIBSOUP_2_SONAME "libsoup-2.4.1.dylib"
42 #else
43 #define LIBSOUP_3_SONAME "libsoup-3.0.so.0"
44 #define LIBSOUP_2_SONAME "libsoup-2.4.so.1"
45 #endif
46 
47 
48 #define LOAD_SYMBOL(name) G_STMT_START {                                \
49     if (!g_module_symbol (module, G_STRINGIFY (name), (gpointer *) &G_PASTE (vtable->_, name))) { \
50       GST_ERROR ("Failed to load '%s' from %s, %s", G_STRINGIFY (name), g_module_name (module), g_module_error()); \
51       goto error;                                                       \
52     }                                                                   \
53   } G_STMT_END;
54 
55 #define LOAD_VERSIONED_SYMBOL(version, name) G_STMT_START {             \
56   if (!g_module_symbol(module, G_STRINGIFY(name), (gpointer *)&G_PASTE(vtable->_, G_PASTE(name, G_PASTE(_, version))))) { \
57     GST_WARNING ("Failed to load '%s' from %s, %s", G_STRINGIFY(name),  \
58                 g_module_name(module), g_module_error());               \
59     goto error;                                                         \
60   }                                                                     \
61   } G_STMT_END;
62 
63 typedef struct _GstSoupVTable
64 {
65   gboolean loaded;
66   guint lib_version;
67 
68   /* *INDENT-OFF* */
69 
70   /* Symbols present only in libsoup 3 */
71 #if GLIB_CHECK_VERSION(2, 66, 0)
72   GUri *(*_soup_message_get_uri_3)(SoupMessage * msg);
73 #endif
74   SoupLogger *(*_soup_logger_new_3) (SoupLoggerLogLevel level);
75   SoupMessageHeaders *(*_soup_message_get_request_headers_3) (SoupMessage * msg);
76   SoupMessageHeaders *(*_soup_message_get_response_headers_3) (SoupMessage * msg);
77   void (*_soup_message_set_request_body_from_bytes_3) (SoupMessage * msg,
78     const char * content_type, GBytes * data);
79   const char *(*_soup_message_get_reason_phrase_3) (SoupMessage * msg);
80   SoupStatus (*_soup_message_get_status_3) (SoupMessage * msg);
81 
82   /* Symbols present only in libsoup 2 */
83   SoupLogger *(*_soup_logger_new_2) (SoupLoggerLogLevel, int);
84   SoupURI *(*_soup_uri_new_2) (const char *);
85   SoupURI *(*_soup_message_get_uri_2) (SoupMessage *);
86   char *(*_soup_uri_to_string_2) (SoupURI *, gboolean);
87   void (*_soup_message_body_append_2) (SoupMessageBody *, SoupMemoryUse,
88     gconstpointer, gsize);
89   void (*_soup_uri_free_2) (SoupURI *);
90   void (*_soup_session_cancel_message_2) (SoupSession *, SoupMessage *, guint);
91 
92   /* Symbols present in libsoup 2 and libsoup 3 */
93   GType (*_soup_content_decoder_get_type) (void);
94   GType (*_soup_cookie_jar_get_type) (void);
95   guint (*_soup_get_major_version) (void);
96   guint (*_soup_get_minor_version) (void);
97   guint (*_soup_get_micro_version) (void);
98   GType (*_soup_logger_log_level_get_type) (void);
99   void (*_soup_logger_set_printer) (SoupLogger * logger, SoupLoggerPrinter printer, gpointer user_data,
100     GDestroyNotify destroy_notify);
101   void (*_soup_message_disable_feature) (SoupMessage * message, GType feature_type);
102   void (*_soup_message_headers_append) (SoupMessageHeaders * hdrs, const char * name,
103     const char * value);
104   void (*_soup_message_headers_foreach) (SoupMessageHeaders * hdrs,
105     SoupMessageHeadersForeachFunc callback, gpointer user_data);
106   goffset (*_soup_message_headers_get_content_length) (SoupMessageHeaders * hdrs);
107   const char *(*_soup_message_headers_get_content_type) (SoupMessageHeaders * hdrs,
108     GHashTable ** value);
109   SoupEncoding (*_soup_message_headers_get_encoding) (SoupMessageHeaders * hdrs);
110   const char *(*_soup_message_headers_get_one) (SoupMessageHeaders * hdrs,
111     const char * name);
112   void (*_soup_message_headers_remove) (SoupMessageHeaders * hdrs, const char * name);
113   SoupMessage *(*_soup_message_new) (const char * method, const char * location);
114   void (*_soup_message_set_flags) (SoupMessage * msg, SoupMessageFlags flags);
115   void (*_soup_session_abort) (SoupSession * session);
116   void (*_soup_session_add_feature) (SoupSession * session, SoupSessionFeature * feature);
117   void (*_soup_session_add_feature_by_type) (SoupSession * session, GType feature_type);
118   GType (*_soup_session_get_type) (void);
119 
120   void (*_soup_auth_authenticate) (SoupAuth * auth, const char *username,
121     const char *password);
122   const char *(*_soup_message_get_method_3) (SoupMessage * msg);
123   GInputStream *(*_soup_session_send_async_2) (SoupSession * session, SoupMessage * msg,
124     GCancellable * cancellable, GAsyncReadyCallback callback, gpointer user_data);
125   GInputStream *(*_soup_session_send_async_3) (SoupSession * session, SoupMessage * msg,
126     int io_priority, GCancellable * cancellable, GAsyncReadyCallback callback, gpointer user_data);
127   GInputStream *(*_soup_session_send_finish) (SoupSession * session,
128     GAsyncResult * result, GError ** error);
129   GInputStream *(*_soup_session_send) (SoupSession * session, SoupMessage * msg,
130     GCancellable * cancellable, GError ** error);
131   /* *INDENT-ON* */
132 } GstSoupVTable;
133 
134 static GstSoupVTable gst_soup_vtable = { 0, };
135 
136 gboolean
gst_soup_load_library(void)137 gst_soup_load_library (void)
138 {
139   GModule *module;
140   GstSoupVTable *vtable;
141   const gchar *libsoup_sonames[5] = { 0 };
142   guint len = 0;
143 
144   if (gst_soup_vtable.loaded)
145     return TRUE;
146 
147   g_assert (g_module_supported ());
148 
149   GST_DEBUG_CATEGORY_INIT (gst_soup_debug, "soup", 0, "soup");
150 
151 #ifdef HAVE_RTLD_NOLOAD
152   {
153     gpointer handle = NULL;
154 
155     /* In order to avoid causing conflicts we detect if libsoup 2 or 3 is loaded already.
156      * If so use that. Otherwise we will try to load our own version to use preferring 3. */
157 
158     if ((handle = dlopen (LIBSOUP_3_SONAME, RTLD_NOW | RTLD_NOLOAD))) {
159       libsoup_sonames[0] = LIBSOUP_3_SONAME;
160       GST_DEBUG ("LibSoup 3 found");
161     } else if ((handle = dlopen (LIBSOUP_2_SONAME, RTLD_NOW | RTLD_NOLOAD))) {
162       libsoup_sonames[0] = LIBSOUP_2_SONAME;
163       GST_DEBUG ("LibSoup 2 found");
164     } else {
165       GST_DEBUG ("Trying all libsoups");
166       libsoup_sonames[0] = LIBSOUP_3_SONAME;
167       libsoup_sonames[1] = LIBSOUP_2_SONAME;
168     }
169 
170     g_clear_pointer (&handle, dlclose);
171   }
172 #else /* !HAVE_RTLD_NOLOAD */
173 
174 #ifdef G_OS_WIN32
175 
176 #define LIBSOUP2_MSVC_DLL "soup-2.4-1.dll"
177 #define LIBSOUP3_MSVC_DLL "soup-3.0-0.dll"
178 #define LIBSOUP2_MINGW_DLL "libsoup-2.4-1.dll"
179 #define LIBSOUP3_MINGW_DLL "libsoup-3.0-0.dll"
180 
181   {
182 #ifdef _MSC_VER
183     const char *candidates[5] = { LIBSOUP3_MSVC_DLL, LIBSOUP2_MSVC_DLL,
184       LIBSOUP3_MINGW_DLL, LIBSOUP2_MINGW_DLL, 0
185     };
186 #else
187     const char *candidates[5] = { LIBSOUP3_MINGW_DLL, LIBSOUP2_MINGW_DLL,
188       LIBSOUP3_MSVC_DLL, LIBSOUP2_MSVC_DLL, 0
189     };
190 #endif /* _MSC_VER */
191 
192     guint len = g_strv_length ((gchar **) candidates);
193 #if !GST_WINAPI_ONLY_APP
194     for (guint i = 0; i < len; i++) {
195       HMODULE phModule;
196       BOOL loaded =
197           GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
198           candidates[i], &phModule);
199       if (loaded) {
200         GST_DEBUG ("%s is resident. Using it.", candidates[i]);
201         libsoup_sonames[0] = candidates[i];
202         break;
203       }
204     }
205 #endif
206     if (libsoup_sonames[0] == NULL) {
207       GST_DEBUG ("No resident libsoup, trying them all");
208       for (guint i = 0; i < len; i++) {
209         libsoup_sonames[i] = candidates[i];
210       }
211     }
212   }
213 #else /* !G_OS_WIN32 */
214   libsoup_sonames[0] = LIBSOUP_3_SONAME;
215   libsoup_sonames[1] = LIBSOUP_2_SONAME;
216 #endif /* G_OS_WIN32 */
217 
218 #endif /* HAVE_RTLD_NOLOAD */
219 
220   vtable = &gst_soup_vtable;
221   len = g_strv_length ((gchar **) libsoup_sonames);
222 
223   for (guint i = 0; i < len; i++) {
224     module =
225         g_module_open (libsoup_sonames[i],
226         G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
227     if (module) {
228       GST_DEBUG ("Loaded %s", g_module_name (module));
229       if (g_strstr_len (libsoup_sonames[i], -1, "soup-2")) {
230         vtable->lib_version = 2;
231         LOAD_VERSIONED_SYMBOL (2, soup_logger_new);
232         LOAD_VERSIONED_SYMBOL (2, soup_message_body_append);
233         LOAD_VERSIONED_SYMBOL (2, soup_uri_free);
234         LOAD_VERSIONED_SYMBOL (2, soup_uri_new);
235         LOAD_VERSIONED_SYMBOL (2, soup_uri_to_string);
236         LOAD_VERSIONED_SYMBOL (2, soup_message_get_uri);
237         LOAD_VERSIONED_SYMBOL (2, soup_session_cancel_message);
238         LOAD_VERSIONED_SYMBOL (2, soup_session_send_async);
239       } else {
240         vtable->lib_version = 3;
241         LOAD_VERSIONED_SYMBOL (3, soup_logger_new);
242         LOAD_VERSIONED_SYMBOL (3, soup_message_get_request_headers);
243         LOAD_VERSIONED_SYMBOL (3, soup_message_get_response_headers);
244         LOAD_VERSIONED_SYMBOL (3, soup_message_set_request_body_from_bytes);
245 #if GLIB_CHECK_VERSION(2, 66, 0)
246         LOAD_VERSIONED_SYMBOL (3, soup_message_get_uri);
247 #endif
248         LOAD_VERSIONED_SYMBOL (3, soup_message_get_method);
249         LOAD_VERSIONED_SYMBOL (3, soup_message_get_reason_phrase);
250         LOAD_VERSIONED_SYMBOL (3, soup_message_get_status);
251         LOAD_VERSIONED_SYMBOL (3, soup_session_send_async);
252       }
253 
254       LOAD_SYMBOL (soup_auth_authenticate);
255       LOAD_SYMBOL (soup_content_decoder_get_type);
256       LOAD_SYMBOL (soup_cookie_jar_get_type);
257       LOAD_SYMBOL (soup_get_major_version);
258       LOAD_SYMBOL (soup_get_micro_version);
259       LOAD_SYMBOL (soup_get_minor_version);
260       LOAD_SYMBOL (soup_logger_log_level_get_type);
261       LOAD_SYMBOL (soup_logger_set_printer);
262       LOAD_SYMBOL (soup_message_disable_feature);
263       LOAD_SYMBOL (soup_message_headers_append);
264       LOAD_SYMBOL (soup_message_headers_foreach);
265       LOAD_SYMBOL (soup_message_headers_get_content_length);
266       LOAD_SYMBOL (soup_message_headers_get_content_type);
267       LOAD_SYMBOL (soup_message_headers_get_encoding);
268       LOAD_SYMBOL (soup_message_headers_get_one);
269       LOAD_SYMBOL (soup_message_headers_remove);
270       LOAD_SYMBOL (soup_message_new);
271       LOAD_SYMBOL (soup_message_set_flags);
272       LOAD_SYMBOL (soup_session_abort);
273       LOAD_SYMBOL (soup_session_add_feature);
274       LOAD_SYMBOL (soup_session_add_feature_by_type);
275       LOAD_SYMBOL (soup_session_get_type);
276       LOAD_SYMBOL (soup_session_send);
277       LOAD_SYMBOL (soup_session_send_finish);
278 
279       vtable->loaded = TRUE;
280       goto beach;
281 
282     error:
283       GST_DEBUG ("Failed to find all libsoup symbols");
284       g_clear_pointer (&module, g_module_close);
285       continue;
286     } else {
287       GST_DEBUG ("Module %s not found", libsoup_sonames[i]);
288       continue;
289     }
290   beach:
291     break;
292   }
293 
294   return vtable->loaded;
295 }
296 
297 #endif /* !STATIC_SOUP */
298 
299 guint
gst_soup_loader_get_api_version(void)300 gst_soup_loader_get_api_version (void)
301 {
302 #ifdef STATIC_SOUP
303   return STATIC_SOUP;
304 #else
305   return gst_soup_vtable.lib_version;
306 #endif
307 }
308 
309 SoupSession *
_soup_session_new_with_options(const char * optname1,...)310 _soup_session_new_with_options (const char *optname1, ...)
311 {
312   SoupSession *session;
313   va_list ap;
314 
315   va_start (ap, optname1);
316   session =
317       (SoupSession *) g_object_new_valist (_soup_session_get_type (), optname1,
318       ap);
319   va_end (ap);
320   return session;
321 }
322 
323 SoupLogger *
_soup_logger_new(SoupLoggerLogLevel level)324 _soup_logger_new (SoupLoggerLogLevel level)
325 {
326 #ifdef STATIC_SOUP
327 #if STATIC_SOUP == 2
328   return soup_logger_new (level, -1);
329 #elif STATIC_SOUP == 3
330   return soup_logger_new (level);
331 #endif
332 #else
333   if (gst_soup_vtable.lib_version == 2) {
334     g_assert (gst_soup_vtable._soup_logger_new_2 != NULL);
335     return gst_soup_vtable._soup_logger_new_2 (level, -1);
336   }
337   g_assert (gst_soup_vtable._soup_logger_new_3 != NULL);
338   return gst_soup_vtable._soup_logger_new_3 (level);
339 #endif
340 }
341 
342 void
_soup_logger_set_printer(SoupLogger * logger,SoupLoggerPrinter printer,gpointer printer_data,GDestroyNotify destroy)343 _soup_logger_set_printer (SoupLogger * logger, SoupLoggerPrinter printer,
344     gpointer printer_data, GDestroyNotify destroy)
345 {
346 #ifdef STATIC_SOUP
347   soup_logger_set_printer (logger, printer, printer_data, destroy);
348 #else
349   g_assert (gst_soup_vtable._soup_logger_set_printer != NULL);
350   gst_soup_vtable._soup_logger_set_printer (logger, printer, printer_data,
351       destroy);
352 #endif
353 }
354 
355 void
_soup_session_add_feature(SoupSession * session,SoupSessionFeature * feature)356 _soup_session_add_feature (SoupSession * session, SoupSessionFeature * feature)
357 {
358 #ifdef STATIC_SOUP
359   soup_session_add_feature (session, feature);
360 #else
361   g_assert (gst_soup_vtable._soup_session_add_feature != NULL);
362   gst_soup_vtable._soup_session_add_feature (session, feature);
363 #endif
364 }
365 
366 GstSoupUri *
gst_soup_uri_new(const char * uri_string)367 gst_soup_uri_new (const char *uri_string)
368 {
369   GstSoupUri *uri = g_new0 (GstSoupUri, 1);
370 #ifdef STATIC_SOUP
371 #if STATIC_SOUP == 2
372   uri->soup_uri = soup_uri_new (uri_string);
373 #else
374   uri->uri = g_uri_parse (uri_string, SOUP_HTTP_URI_FLAGS, NULL);
375 #endif
376 #else
377   if (gst_soup_vtable.lib_version == 2) {
378     g_assert (gst_soup_vtable._soup_uri_new_2 != NULL);
379     uri->soup_uri = gst_soup_vtable._soup_uri_new_2 (uri_string);
380   } else {
381 #if GLIB_CHECK_VERSION(2, 66, 0)
382     uri->uri = g_uri_parse (uri_string, SOUP_HTTP_URI_FLAGS, NULL);
383 #endif
384   }
385 #endif
386   return uri;
387 }
388 
389 void
gst_soup_uri_free(GstSoupUri * uri)390 gst_soup_uri_free (GstSoupUri * uri)
391 {
392 #if (defined(STATIC_SOUP) && STATIC_SOUP == 3) || (!defined(STATIC_SOUP) && GLIB_CHECK_VERSION(2, 66, 0))
393   if (uri->uri) {
394     g_uri_unref (uri->uri);
395   }
396 #endif
397 
398 #if defined(STATIC_SOUP)
399 #if STATIC_SOUP == 2
400   if (uri->soup_uri) {
401     soup_uri_free (uri->soup_uri);
402   }
403 #endif
404 #else /* !STATIC_SOUP */
405   if (uri->soup_uri) {
406     g_assert (gst_soup_vtable._soup_uri_free_2 != NULL);
407     gst_soup_vtable._soup_uri_free_2 (uri->soup_uri);
408   }
409 #endif /* STATIC_SOUP */
410   g_free (uri);
411 }
412 
413 char *
gst_soup_uri_to_string(GstSoupUri * uri)414 gst_soup_uri_to_string (GstSoupUri * uri)
415 {
416 #if (defined(STATIC_SOUP) && STATIC_SOUP == 3) || (!defined(STATIC_SOUP) && GLIB_CHECK_VERSION(2, 66, 0))
417   if (uri->uri) {
418     return g_uri_to_string_partial (uri->uri, G_URI_HIDE_PASSWORD);
419   }
420 #endif
421 
422 #if defined(STATIC_SOUP)
423 #if STATIC_SOUP == 2
424   if (uri->soup_uri) {
425     return soup_uri_to_string (uri->soup_uri, FALSE);
426   }
427 #endif
428 #else /* !STATIC_SOUP */
429   if (uri->soup_uri) {
430     g_assert (gst_soup_vtable._soup_uri_to_string_2 != NULL);
431     return gst_soup_vtable._soup_uri_to_string_2 (uri->soup_uri, FALSE);
432   }
433 #endif /* STATIC_SOUP */
434 
435   g_assert_not_reached ();
436   return NULL;
437 }
438 
439 char *
gst_soup_message_uri_to_string(SoupMessage * msg)440 gst_soup_message_uri_to_string (SoupMessage * msg)
441 {
442 #ifdef STATIC_SOUP
443 #if STATIC_SOUP == 2
444   SoupURI *uri = NULL;
445   uri = soup_message_get_uri (msg);
446   return soup_uri_to_string (uri, FALSE);
447 #elif STATIC_SOUP == 3
448   GUri *uri = NULL;
449   uri = soup_message_get_uri (msg);
450   return g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD);
451 #endif
452 #else
453   if (gst_soup_vtable.lib_version == 2) {
454     SoupURI *uri = NULL;
455     g_assert (gst_soup_vtable._soup_message_get_uri_2 != NULL);
456     uri = gst_soup_vtable._soup_message_get_uri_2 (msg);
457     return gst_soup_vtable._soup_uri_to_string_2 (uri, FALSE);
458   } else {
459 #if GLIB_CHECK_VERSION(2, 66, 0)
460     GUri *uri = NULL;
461     g_assert (gst_soup_vtable._soup_message_get_uri_3 != NULL);
462     uri = gst_soup_vtable._soup_message_get_uri_3 (msg);
463     return g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD);
464 #endif
465   }
466 #endif
467   /*
468    * If we reach this, it means the plugin was built for old glib, but somehow
469    * we managed to load libsoup3, which requires a very recent glib. As this
470    * is a contradiction, we can assert, I guess?
471    */
472   g_assert_not_reached ();
473   return NULL;
474 }
475 
476 guint
_soup_get_major_version(void)477 _soup_get_major_version (void)
478 {
479 #ifdef STATIC_SOUP
480   return soup_get_major_version ();
481 #else
482   g_assert (gst_soup_vtable._soup_get_major_version != NULL);
483   return gst_soup_vtable._soup_get_major_version ();
484 #endif
485 }
486 
487 guint
_soup_get_minor_version(void)488 _soup_get_minor_version (void)
489 {
490 #ifdef STATIC_SOUP
491   return soup_get_minor_version ();
492 #else
493   g_assert (gst_soup_vtable._soup_get_minor_version != NULL);
494   return gst_soup_vtable._soup_get_minor_version ();
495 #endif
496 }
497 
498 guint
_soup_get_micro_version(void)499 _soup_get_micro_version (void)
500 {
501 #ifdef STATIC_SOUP
502   return soup_get_micro_version ();
503 #else
504   g_assert (gst_soup_vtable._soup_get_micro_version != NULL);
505   return gst_soup_vtable._soup_get_micro_version ();
506 #endif
507 }
508 
509 void
_soup_message_set_request_body_from_bytes(SoupMessage * msg,const char * content_type,GBytes * bytes)510 _soup_message_set_request_body_from_bytes (SoupMessage * msg,
511     const char *content_type, GBytes * bytes)
512 {
513 #ifdef STATIC_SOUP
514 #if STATIC_SOUP == 2
515   gsize size;
516   gconstpointer data = g_bytes_get_data (bytes, &size);
517   soup_message_body_append (msg->request_body, SOUP_MEMORY_COPY, data, size);
518 #elif STATIC_SOUP == 3
519   soup_message_set_request_body_from_bytes (msg, content_type, bytes);
520 #endif
521 #else
522   if (gst_soup_vtable.lib_version == 3) {
523     g_assert (gst_soup_vtable._soup_message_set_request_body_from_bytes_3 !=
524         NULL);
525     gst_soup_vtable._soup_message_set_request_body_from_bytes_3 (msg,
526         content_type, bytes);
527   } else {
528     gsize size;
529     gconstpointer data = g_bytes_get_data (bytes, &size);
530     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
531     g_assert (gst_soup_vtable._soup_message_body_append_2 != NULL);
532     gst_soup_vtable._soup_message_body_append_2 (msg2->request_body,
533         SOUP_MEMORY_COPY, data, size);
534   }
535 #endif
536 }
537 
538 GType
_soup_session_get_type(void)539 _soup_session_get_type (void)
540 {
541 #ifdef STATIC_SOUP
542   return soup_session_get_type ();
543 #else
544   g_assert (gst_soup_vtable._soup_session_get_type != NULL);
545   return gst_soup_vtable._soup_session_get_type ();
546 #endif
547 }
548 
549 GType
_soup_logger_log_level_get_type(void)550 _soup_logger_log_level_get_type (void)
551 {
552 #ifdef STATIC_SOUP
553   return soup_logger_log_level_get_type ();
554 #else
555   g_assert (gst_soup_vtable._soup_logger_log_level_get_type != NULL);
556   return gst_soup_vtable._soup_logger_log_level_get_type ();
557 #endif
558 }
559 
560 GType
_soup_content_decoder_get_type(void)561 _soup_content_decoder_get_type (void)
562 {
563 #ifdef STATIC_SOUP
564   return soup_content_decoder_get_type ();
565 #else
566   g_assert (gst_soup_vtable._soup_content_decoder_get_type != NULL);
567   return gst_soup_vtable._soup_content_decoder_get_type ();
568 #endif
569 }
570 
571 GType
_soup_cookie_jar_get_type(void)572 _soup_cookie_jar_get_type (void)
573 {
574 #ifdef STATIC_SOUP
575   return soup_cookie_jar_get_type ();
576 #else
577   g_assert (gst_soup_vtable._soup_cookie_jar_get_type != NULL);
578   return gst_soup_vtable._soup_cookie_jar_get_type ();
579 #endif
580 }
581 
582 void
_soup_session_abort(SoupSession * session)583 _soup_session_abort (SoupSession * session)
584 {
585 #ifdef STATIC_SOUP
586   soup_session_abort (session);
587 #else
588   g_assert (gst_soup_vtable._soup_session_abort != NULL);
589   gst_soup_vtable._soup_session_abort (session);
590 #endif
591 }
592 
593 SoupMessage *
_soup_message_new(const char * method,const char * uri_string)594 _soup_message_new (const char *method, const char *uri_string)
595 {
596 #ifdef STATIC_SOUP
597   return soup_message_new (method, uri_string);
598 #else
599   g_assert (gst_soup_vtable._soup_message_new != NULL);
600   return gst_soup_vtable._soup_message_new (method, uri_string);
601 #endif
602 }
603 
604 SoupMessageHeaders *
_soup_message_get_request_headers(SoupMessage * msg)605 _soup_message_get_request_headers (SoupMessage * msg)
606 {
607 #ifdef STATIC_SOUP
608 #if STATIC_SOUP == 2
609   return msg->request_headers;
610 #elif STATIC_SOUP == 3
611   return soup_message_get_request_headers (msg);
612 #endif
613 #else
614   if (gst_soup_vtable.lib_version == 3) {
615     g_assert (gst_soup_vtable._soup_message_get_request_headers_3 != NULL);
616     return gst_soup_vtable._soup_message_get_request_headers_3 (msg);
617   } else {
618     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
619     return msg2->request_headers;
620   }
621 #endif
622 }
623 
624 SoupMessageHeaders *
_soup_message_get_response_headers(SoupMessage * msg)625 _soup_message_get_response_headers (SoupMessage * msg)
626 {
627 #ifdef STATIC_SOUP
628 #if STATIC_SOUP == 2
629   return msg->response_headers;
630 #elif STATIC_SOUP == 3
631   return soup_message_get_response_headers (msg);
632 #endif
633 #else
634   if (gst_soup_vtable.lib_version == 3) {
635     g_assert (gst_soup_vtable._soup_message_get_response_headers_3 != NULL);
636     return gst_soup_vtable._soup_message_get_response_headers_3 (msg);
637   } else {
638     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
639     return msg2->response_headers;
640   }
641 #endif
642 }
643 
644 void
_soup_message_headers_remove(SoupMessageHeaders * hdrs,const char * name)645 _soup_message_headers_remove (SoupMessageHeaders * hdrs, const char *name)
646 {
647 #ifdef STATIC_SOUP
648   soup_message_headers_remove (hdrs, name);
649 #else
650   g_assert (gst_soup_vtable._soup_message_headers_remove != NULL);
651   gst_soup_vtable._soup_message_headers_remove (hdrs, name);
652 #endif
653 }
654 
655 void
_soup_message_headers_append(SoupMessageHeaders * hdrs,const char * name,const char * value)656 _soup_message_headers_append (SoupMessageHeaders * hdrs, const char *name,
657     const char *value)
658 {
659 #ifdef STATIC_SOUP
660   soup_message_headers_append (hdrs, name, value);
661 #else
662   g_assert (gst_soup_vtable._soup_message_headers_append != NULL);
663   gst_soup_vtable._soup_message_headers_append (hdrs, name, value);
664 #endif
665 }
666 
667 void
_soup_message_set_flags(SoupMessage * msg,SoupMessageFlags flags)668 _soup_message_set_flags (SoupMessage * msg, SoupMessageFlags flags)
669 {
670 #ifdef STATIC_SOUP
671   soup_message_set_flags (msg, flags);
672 #else
673   g_assert (gst_soup_vtable._soup_message_set_flags != NULL);
674   gst_soup_vtable._soup_message_set_flags (msg, flags);
675 #endif
676 }
677 
678 void
_soup_session_add_feature_by_type(SoupSession * session,GType feature_type)679 _soup_session_add_feature_by_type (SoupSession * session, GType feature_type)
680 {
681 #ifdef STATIC_SOUP
682   soup_session_add_feature_by_type (session, feature_type);
683 #else
684   g_assert (gst_soup_vtable._soup_session_add_feature_by_type != NULL);
685   gst_soup_vtable._soup_session_add_feature_by_type (session, feature_type);
686 #endif
687 }
688 
689 void
_soup_message_headers_foreach(SoupMessageHeaders * hdrs,SoupMessageHeadersForeachFunc func,gpointer user_data)690 _soup_message_headers_foreach (SoupMessageHeaders * hdrs,
691     SoupMessageHeadersForeachFunc func, gpointer user_data)
692 {
693 #ifdef STATIC_SOUP
694   soup_message_headers_foreach (hdrs, func, user_data);
695 #else
696   g_assert (gst_soup_vtable._soup_message_headers_foreach != NULL);
697   gst_soup_vtable._soup_message_headers_foreach (hdrs, func, user_data);
698 #endif
699 }
700 
701 SoupEncoding
_soup_message_headers_get_encoding(SoupMessageHeaders * hdrs)702 _soup_message_headers_get_encoding (SoupMessageHeaders * hdrs)
703 {
704 #ifdef STATIC_SOUP
705   return soup_message_headers_get_encoding (hdrs);
706 #else
707   g_assert (gst_soup_vtable._soup_message_headers_get_encoding != NULL);
708   return gst_soup_vtable._soup_message_headers_get_encoding (hdrs);
709 #endif
710 }
711 
712 goffset
_soup_message_headers_get_content_length(SoupMessageHeaders * hdrs)713 _soup_message_headers_get_content_length (SoupMessageHeaders * hdrs)
714 {
715 #ifdef STATIC_SOUP
716   return soup_message_headers_get_content_length (hdrs);
717 #else
718   g_assert (gst_soup_vtable._soup_message_headers_get_content_length != NULL);
719   return gst_soup_vtable._soup_message_headers_get_content_length (hdrs);
720 #endif
721 }
722 
723 SoupStatus
_soup_message_get_status(SoupMessage * msg)724 _soup_message_get_status (SoupMessage * msg)
725 {
726 #ifdef STATIC_SOUP
727 #if STATIC_SOUP == 2
728   return msg->status_code;
729 #elif STATIC_SOUP == 3
730   return soup_message_get_status (msg);
731 #endif
732 #else
733   if (gst_soup_vtable.lib_version == 3) {
734     g_assert (gst_soup_vtable._soup_message_get_status_3 != NULL);
735     return gst_soup_vtable._soup_message_get_status_3 (msg);
736   } else {
737     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
738     return msg2->status_code;
739   }
740 #endif
741 }
742 
743 const char *
_soup_message_get_reason_phrase(SoupMessage * msg)744 _soup_message_get_reason_phrase (SoupMessage * msg)
745 {
746 #ifdef STATIC_SOUP
747 #if STATIC_SOUP == 2
748   return msg->reason_phrase;
749 #elif STATIC_SOUP == 3
750   return soup_message_get_reason_phrase (msg);
751 #endif
752 #else
753   if (gst_soup_vtable.lib_version == 3) {
754     g_assert (gst_soup_vtable._soup_message_get_reason_phrase_3 != NULL);
755     return gst_soup_vtable._soup_message_get_reason_phrase_3 (msg);
756   } else {
757     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
758     return msg2->reason_phrase;
759   }
760 #endif
761 }
762 
763 const char *
_soup_message_headers_get_one(SoupMessageHeaders * hdrs,const char * name)764 _soup_message_headers_get_one (SoupMessageHeaders * hdrs, const char *name)
765 {
766 #ifdef STATIC_SOUP
767   return soup_message_headers_get_one (hdrs, name);
768 #else
769   g_assert (gst_soup_vtable._soup_message_headers_get_one != NULL);
770   return gst_soup_vtable._soup_message_headers_get_one (hdrs, name);
771 #endif
772 }
773 
774 void
_soup_message_disable_feature(SoupMessage * msg,GType feature_type)775 _soup_message_disable_feature (SoupMessage * msg, GType feature_type)
776 {
777 #ifdef STATIC_SOUP
778   soup_message_disable_feature (msg, feature_type);
779 #else
780   g_assert (gst_soup_vtable._soup_message_disable_feature != NULL);
781   gst_soup_vtable._soup_message_disable_feature (msg, feature_type);
782 #endif
783 }
784 
785 const char *
_soup_message_headers_get_content_type(SoupMessageHeaders * hdrs,GHashTable ** params)786 _soup_message_headers_get_content_type (SoupMessageHeaders * hdrs,
787     GHashTable ** params)
788 {
789 #ifdef STATIC_SOUP
790   return soup_message_headers_get_content_type (hdrs, params);
791 #else
792   g_assert (gst_soup_vtable._soup_message_headers_get_content_type != NULL);
793   return gst_soup_vtable._soup_message_headers_get_content_type (hdrs, params);
794 #endif
795 }
796 
797 void
_soup_auth_authenticate(SoupAuth * auth,const char * username,const char * password)798 _soup_auth_authenticate (SoupAuth * auth, const char *username,
799     const char *password)
800 {
801 #ifdef STATIC_SOUP
802   soup_auth_authenticate (auth, username, password);
803 #else
804   g_assert (gst_soup_vtable._soup_auth_authenticate != NULL);
805   gst_soup_vtable._soup_auth_authenticate (auth, username, password);
806 #endif
807 }
808 
809 const char *
_soup_message_get_method(SoupMessage * msg)810 _soup_message_get_method (SoupMessage * msg)
811 {
812 #ifdef STATIC_SOUP
813 #if STATIC_SOUP == 2
814   return msg->method;
815 #elif STATIC_SOUP == 3
816   return soup_message_get_method (msg);
817 #endif
818 #else
819   if (gst_soup_vtable.lib_version == 3) {
820     g_assert (gst_soup_vtable._soup_message_get_method_3 != NULL);
821     return gst_soup_vtable._soup_message_get_method_3 (msg);
822   } else {
823     SoupMessage2 *msg2 = (SoupMessage2 *) msg;
824     return msg2->method;
825   }
826 #endif
827 }
828 
829 void
_soup_session_send_async(SoupSession * session,SoupMessage * msg,GCancellable * cancellable,GAsyncReadyCallback callback,gpointer user_data)830 _soup_session_send_async (SoupSession * session, SoupMessage * msg,
831     GCancellable * cancellable, GAsyncReadyCallback callback,
832     gpointer user_data)
833 {
834 #ifdef STATIC_SOUP
835 #if STATIC_SOUP == 2
836   soup_session_send_async (session, msg, cancellable, callback, user_data);
837 #else
838   soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable,
839       callback, user_data);
840 #endif
841 #else
842   if (gst_soup_vtable.lib_version == 3) {
843     g_assert (gst_soup_vtable._soup_session_send_async_3 != NULL);
844     gst_soup_vtable._soup_session_send_async_3 (session, msg,
845         G_PRIORITY_DEFAULT, cancellable, callback, user_data);
846   } else {
847     g_assert (gst_soup_vtable._soup_session_send_async_2 != NULL);
848     gst_soup_vtable._soup_session_send_async_2 (session, msg,
849         cancellable, callback, user_data);
850   }
851 #endif
852 }
853 
854 GInputStream *
_soup_session_send_finish(SoupSession * session,GAsyncResult * result,GError ** error)855 _soup_session_send_finish (SoupSession * session,
856     GAsyncResult * result, GError ** error)
857 {
858 #ifdef STATIC_SOUP
859   return soup_session_send_finish (session, result, error);
860 #else
861   g_assert (gst_soup_vtable._soup_session_send_finish != NULL);
862   return gst_soup_vtable._soup_session_send_finish (session, result, error);
863 #endif
864 }
865 
866 GInputStream *
_soup_session_send(SoupSession * session,SoupMessage * msg,GCancellable * cancellable,GError ** error)867 _soup_session_send (SoupSession * session, SoupMessage * msg,
868     GCancellable * cancellable, GError ** error)
869 {
870 #ifdef STATIC_SOUP
871   return soup_session_send (session, msg, cancellable, error);
872 #else
873   g_assert (gst_soup_vtable._soup_session_send != NULL);
874   return gst_soup_vtable._soup_session_send (session, msg, cancellable, error);
875 #endif
876 }
877 
878 void
gst_soup_session_cancel_message(SoupSession * session,SoupMessage * msg,GCancellable * cancellable)879 gst_soup_session_cancel_message (SoupSession * session, SoupMessage * msg,
880     GCancellable * cancellable)
881 {
882 #ifdef STATIC_SOUP
883 #if STATIC_SOUP == 3
884   g_cancellable_cancel (cancellable);
885 #else
886   soup_session_cancel_message (session, msg, SOUP_STATUS_CANCELLED);
887 #endif
888 #else
889   if (gst_soup_vtable.lib_version == 3) {
890     g_cancellable_cancel (cancellable);
891   } else {
892     g_assert (gst_soup_vtable._soup_session_cancel_message_2 != NULL);
893     gst_soup_vtable._soup_session_cancel_message_2 (session, msg,
894         SOUP_STATUS_CANCELLED);
895   }
896 #endif
897 }
898