D-Bus 1.4.6

dbus-server-win.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-server-win.c Server implementation for WIN network protocols.
00003  *
00004  * Copyright (C) 2002, 2003, 2004  Red Hat Inc.
00005  * Copyright (C) 2007 Ralf Habacker <ralf.habacker@freenet.de>
00006  *
00007  * Licensed under the Academic Free License version 2.1
00008  * 
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  */
00024 
00025 #include <config.h>
00026 #include "dbus-internals.h"
00027 #include "dbus-server-win.h"
00028 #include "dbus-server-socket.h"
00029 
00049 DBusServerListenResult
00050 _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
00051                                        DBusServer      **server_p,
00052                                        DBusError        *error)
00053 {
00054   const char *method;
00055 
00056   *server_p  = NULL;
00057 
00058   method = dbus_address_entry_get_method (entry);
00059 
00060   if (strcmp (method, "nonce-tcp") == 0)
00061     {
00062       const char *host;
00063       const char *port;
00064       const char *bind;
00065       const char *family;
00066 
00067       host = dbus_address_entry_get_value (entry, "host");
00068       bind = dbus_address_entry_get_value (entry, "bind");
00069       port = dbus_address_entry_get_value (entry, "port");
00070       family = dbus_address_entry_get_value (entry, "family");
00071 
00072       *server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
00073                                                    family, error, TRUE);
00074 
00075       if (*server_p)
00076         {
00077           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
00078           return DBUS_SERVER_LISTEN_OK;
00079         }
00080       else
00081         {
00082           _DBUS_ASSERT_ERROR_IS_SET(error);
00083           return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
00084         }
00085     }
00086   else if (strcmp (method, "autolaunch") == 0)
00087     {
00088       const char *host = "localhost";
00089       const char *bind = "localhost";
00090       const char *port = "0";
00091       const char *family = "ipv4";
00092       const char *scope = dbus_address_entry_get_value (entry, "scope");
00093 
00094       if (_dbus_daemon_is_session_bus_address_published (scope))
00095           return DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED;
00096 
00097       *server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
00098                                                    family, error, FALSE);
00099       if (*server_p)
00100         {
00101           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
00102           (*server_p)->published_address =
00103               _dbus_daemon_publish_session_bus_address ((*server_p)->address, scope);
00104           return DBUS_SERVER_LISTEN_OK;
00105         }
00106       else
00107         {
00108           // make sure no handle is open
00109           _dbus_daemon_unpublish_session_bus_address ();
00110           _DBUS_ASSERT_ERROR_IS_SET(error);
00111           return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
00112         }
00113     }
00114   else
00115     {
00116        _DBUS_ASSERT_ERROR_IS_CLEAR(error);
00117        return DBUS_SERVER_LISTEN_NOT_HANDLED;
00118     }
00119 }
00120