static dlr_host_server_t *prv_host_server_new(const gchar *device_if, guint port, GError **error) { dlr_host_server_t *server = NULL; SoupAddress *addr; addr = soup_address_new(device_if, port); if (soup_address_resolve_sync(addr, NULL) != SOUP_STATUS_OK) { *error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_HOST_FAILED, "Unable to create host server on %s", device_if); goto on_error; } server = g_new(dlr_host_server_t, 1); server->files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, prv_host_file_delete); server->soup_server = soup_server_new(SOUP_SERVER_INTERFACE, addr, NULL); soup_server_add_handler(server->soup_server, DLR_HOST_SERVICE_ROOT, prv_soup_server_cb, server, NULL); soup_server_run_async(server->soup_server); server->counter = 0; on_error: g_object_unref(addr); return server; }
static void do_ipv6_test (void) { SoupServer *ipv6_server; SoupURI *ipv6_uri; SoupAddress *ipv6_addr; SoupSession *session; SoupMessage *msg; debug_printf (1, "\nIPv6 server test\n"); ipv6_addr = soup_address_new ("::1", SOUP_ADDRESS_ANY_PORT); soup_address_resolve_sync (ipv6_addr, NULL); ipv6_server = soup_server_new (SOUP_SERVER_INTERFACE, ipv6_addr, NULL); g_object_unref (ipv6_addr); soup_server_add_handler (ipv6_server, NULL, ipv6_server_callback, NULL, NULL); soup_server_run_async (ipv6_server); ipv6_uri = soup_uri_new ("http://[::1]/"); soup_uri_set_port (ipv6_uri, soup_server_get_port (ipv6_server)); session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); debug_printf (1, " HTTP/1.1\n"); msg = soup_message_new_from_uri ("GET", ipv6_uri); soup_session_send_message (session, msg); if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { debug_printf (1, " request failed: %d %s\n", msg->status_code, msg->reason_phrase); errors++; } g_object_unref (msg); debug_printf (1, " HTTP/1.0\n"); msg = soup_message_new_from_uri ("GET", ipv6_uri); soup_message_set_http_version (msg, SOUP_HTTP_1_0); soup_session_send_message (session, msg); if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { debug_printf (1, " request failed: %d %s\n", msg->status_code, msg->reason_phrase); errors++; } g_object_unref (msg); soup_uri_free (ipv6_uri); soup_test_session_abort_unref (session); soup_test_server_quit_unref (ipv6_server); }
SoupServer * soupcut_server_take_new (GMainContext *context) { SoupServer *server; SoupAddress *address; address = soup_address_new("localhost", SOUP_ADDRESS_ANY_PORT); soup_address_resolve_sync(address, NULL); server = soup_server_new(SOUP_SERVER_INTERFACE, address, SOUP_SERVER_ASYNC_CONTEXT, context, NULL); g_object_unref(address); return soupcut_server_take(server); }
static SoupServer * test_server_new (gboolean in_own_thread, gboolean ssl) { SoupServer *server; GMainContext *async_context; const char *ssl_cert_file, *ssl_key_file; SoupAddress *addr; async_context = in_own_thread ? g_main_context_new () : NULL; if (ssl) { ssl_cert_file = SRCDIR "/test-cert.pem"; ssl_key_file = SRCDIR "/test-key.pem"; } else ssl_cert_file = ssl_key_file = NULL; addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT); soup_address_resolve_sync (addr, NULL); server = soup_server_new (SOUP_SERVER_INTERFACE, addr, SOUP_SERVER_ASYNC_CONTEXT, async_context, SOUP_SERVER_SSL_CERT_FILE, ssl_cert_file, SOUP_SERVER_SSL_KEY_FILE, ssl_key_file, NULL); g_object_unref (addr); if (async_context) g_main_context_unref (async_context); if (!server) { fprintf (stderr, "Unable to create server\n"); exit (1); } if (in_own_thread) { GThread *thread; thread = g_thread_create (run_server_thread, server, TRUE, NULL); g_object_set_data (G_OBJECT (server), "thread", thread); } else soup_server_run_async (server); return server; }
WebKitTestServer::WebKitTestServer(ServerType type) { GUniquePtr<char> sslCertificateFile; GUniquePtr<char> sslKeyFile; if (type == ServerHTTPS) { CString resourcesDir = Test::getResourcesDir(); sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL)); sslKeyFile.reset(g_build_filename(resourcesDir.data(), "test-key.pem", NULL)); } GRefPtr<SoupAddress> address = adoptGRef(soup_address_new("127.0.0.1", SOUP_ADDRESS_ANY_PORT)); soup_address_resolve_sync(address.get(), 0); m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_INTERFACE, address.get(), SOUP_SERVER_SSL_CERT_FILE, sslCertificateFile.get(), SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), nullptr)); m_baseURI = type == ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/"); soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer.get())); }
gboolean rcd_rpc_remote_server_start (void) { SoupServerAuthContext auth_ctx = { 0 }; int port = rcd_prefs_get_remote_server_port (); const char *bind_ip; /* Server's already running... */ if (soup_server != NULL) return TRUE; rc_debug (RC_DEBUG_LEVEL_MESSAGE, "Starting remote server"); bind_ip = rcd_prefs_get_bind_ipaddress (); if (bind_ip) { SoupAddress *bind_address; bind_address = soup_address_new (bind_ip, port); if (!bind_address) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Unable to bind remote server to '%s'", bind_ip); return FALSE; } if (soup_address_resolve_sync (bind_address) != SOUP_STATUS_OK) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Unable to bind remote server to '%s': Unable to " "resolve address", bind_ip); return FALSE; } soup_server = soup_server_new (SOUP_SERVER_INTERFACE, bind_address, SOUP_SERVER_PORT, port, SOUP_SERVER_SSL_CERT_FILE, SHAREDIR"/rcd.pem", SOUP_SERVER_SSL_KEY_FILE, SHAREDIR"/rcd.pem", NULL); g_object_unref (bind_address); } else { soup_server = soup_server_new (SOUP_SERVER_PORT, port, SOUP_SERVER_SSL_CERT_FILE, SHAREDIR"/rcd.pem", SOUP_SERVER_SSL_KEY_FILE, SHAREDIR"/rcd.pem", NULL); } if (!soup_server) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Could not start RPC server on port %d", port); rc_debug (RC_DEBUG_LEVEL_ERROR, "(This may mean that another rcd process is already running, or that"); rc_debug (RC_DEBUG_LEVEL_ERROR, "you are not running as root and do not have the correct privileges"); rc_debug (RC_DEBUG_LEVEL_ERROR, "on this port.)"); return FALSE; } g_object_set (G_OBJECT (soup_server_get_listener (soup_server)), SOUP_SOCKET_FLAG_CLOEXEC, TRUE, NULL); auth_ctx.types = SOUP_AUTH_TYPE_DIGEST; auth_ctx.callback = soup_auth_callback; auth_ctx.digest_info.realm = "RCD"; auth_ctx.digest_info.allow_algorithms = SOUP_ALGORITHM_MD5; auth_ctx.digest_info.force_integrity = FALSE; soup_server_add_handler (soup_server, "/RPC2", &auth_ctx, soup_rpc_callback, NULL, NULL); soup_server_add_handler (soup_server, NULL, NULL, soup_default_callback, NULL, NULL); soup_server_run_async (soup_server); g_object_unref (soup_server); notify_port_change (port); return TRUE; }
static void do_callback_unref_test (void) { SoupServer *bad_server; SoupAddress *addr; SoupSession *session; SoupMessage *one, *two; GMainLoop *loop; char *bad_uri; debug_printf (1, "\nCallback unref handling\n"); /* Get a guaranteed-bad URI */ addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT); soup_address_resolve_sync (addr, NULL); bad_server = soup_server_new (SOUP_SERVER_INTERFACE, addr, NULL); g_object_unref (addr); bad_uri = g_strdup_printf ("http://127.0.0.1:%u/", soup_server_get_port (bad_server)); g_object_unref (bad_server); session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); g_object_add_weak_pointer (G_OBJECT (session), (gpointer *)&session); loop = g_main_loop_new (NULL, TRUE); one = soup_message_new ("GET", bad_uri); g_object_add_weak_pointer (G_OBJECT (one), (gpointer *)&one); two = soup_message_new ("GET", bad_uri); g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two); g_free (bad_uri); soup_session_queue_message (session, one, cu_one_completed, loop); soup_session_queue_message (session, two, cu_two_completed, loop); g_main_loop_run (loop); g_main_loop_unref (loop); if (session) { g_object_remove_weak_pointer (G_OBJECT (session), (gpointer *)&session); debug_printf (1, " Session not destroyed?\n"); errors++; g_object_unref (session); } if (one) { g_object_remove_weak_pointer (G_OBJECT (one), (gpointer *)&one); debug_printf (1, " Message 1 not destroyed?\n"); errors++; g_object_unref (one); } if (two) { g_object_remove_weak_pointer (G_OBJECT (two), (gpointer *)&two); debug_printf (1, " Message 2 not destroyed?\n"); errors++; g_object_unref (two); } /* Otherwise, if we haven't crashed, we're ok. */ }