1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright 2013 Red Hat, Inc.
4 */
5
6 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9
10 #include "soup-socket-private.h"
11 #include "soup.h"
12
13 SoupSocketProperties *
soup_socket_properties_new(GMainContext * async_context,gboolean use_thread_context,GProxyResolver * proxy_resolver,SoupAddress * local_addr,GTlsDatabase * tlsdb,GTlsInteraction * tls_interaction,gboolean ssl_strict,guint io_timeout,guint idle_timeout)14 soup_socket_properties_new (GMainContext *async_context,
15 gboolean use_thread_context,
16 GProxyResolver *proxy_resolver,
17 SoupAddress *local_addr,
18 GTlsDatabase *tlsdb,
19 GTlsInteraction *tls_interaction,
20 gboolean ssl_strict,
21 guint io_timeout,
22 guint idle_timeout)
23 {
24 SoupSocketProperties *props;
25
26 props = g_slice_new (SoupSocketProperties);
27 props->ref_count = 1;
28
29 props->async_context = async_context ? g_main_context_ref (async_context) : NULL;
30 props->use_thread_context = use_thread_context;
31
32 props->proxy_resolver = proxy_resolver ? g_object_ref (proxy_resolver) : NULL;
33 props->local_addr = local_addr ? g_object_ref (local_addr) : NULL;
34
35 props->tlsdb = tlsdb ? g_object_ref (tlsdb) : NULL;
36 props->tls_interaction = tls_interaction ? g_object_ref (tls_interaction) : NULL;
37 props->ssl_strict = ssl_strict;
38
39 props->io_timeout = io_timeout;
40 props->idle_timeout = idle_timeout;
41
42 return props;
43 }
44
45 SoupSocketProperties *
soup_socket_properties_ref(SoupSocketProperties * props)46 soup_socket_properties_ref (SoupSocketProperties *props)
47 {
48 g_atomic_int_inc (&props->ref_count);
49 return props;
50 }
51
52 void
soup_socket_properties_unref(SoupSocketProperties * props)53 soup_socket_properties_unref (SoupSocketProperties *props)
54 {
55 if (!g_atomic_int_dec_and_test (&props->ref_count))
56 return;
57
58 g_clear_pointer (&props->async_context, g_main_context_unref);
59 g_clear_object (&props->proxy_resolver);
60 g_clear_object (&props->local_addr);
61 g_clear_object (&props->tlsdb);
62 g_clear_object (&props->tls_interaction);
63
64 g_slice_free (SoupSocketProperties, props);
65 }
66
67 void
soup_socket_properties_push_async_context(SoupSocketProperties * props)68 soup_socket_properties_push_async_context (SoupSocketProperties *props)
69 {
70 if (props->async_context && !props->use_thread_context)
71 g_main_context_push_thread_default (props->async_context);
72 }
73
74 void
soup_socket_properties_pop_async_context(SoupSocketProperties * props)75 soup_socket_properties_pop_async_context (SoupSocketProperties *props)
76 {
77 if (props->async_context && !props->use_thread_context)
78 g_main_context_pop_thread_default (props->async_context);
79 }
80
81 G_DEFINE_BOXED_TYPE (SoupSocketProperties, soup_socket_properties, soup_socket_properties_ref, soup_socket_properties_unref)
82