index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-server-debug-pipe.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-server-debug-pipe.c In-proc debug server implementation
00003
*
00004
* Copyright (C) 2003  CodeFactory AB
00005
* Copyright (C) 2003, 2004  Red Hat, Inc.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022
*
00023
*/
00024
00025
#include "dbus-internals.h"
00026
#include "dbus-server-debug-pipe.h"
00027
#include "dbus-transport-unix.h"
00028
#include "dbus-connection-internal.h"
00029
#include "dbus-hash.h"
00030
#include "dbus-string.h"
00031
#include "dbus-protocol.h"
00032
00033
#ifdef DBUS_BUILD_TESTS
00034
00049
typedef
struct
DBusServerDebugPipe DBusServerDebugPipe;
00050
00055
struct
DBusServerDebugPipe
00056 {
00057
structDBusServer.html
DBusServer
base;
00059
char
*name;
00061
group__DBusTypes.html#ga2
dbus_bool_t
disconnected;
00062 };
00063
00064
/* FIXME not threadsafe (right now the test suite doesn't use threads anyhow ) */
00065
static
structDBusHashTable.html
DBusHashTable
*server_pipe_hash;
00066
static
int
server_pipe_hash_refcount = 0;
00067
00068
static
group__DBusTypes.html#ga2
dbus_bool_t
00069 pipe_hash_ref (
void
)
00070 {
00071
if
(!server_pipe_hash)
00072     {
00073
group__DBusInternalsUtils.html#ga130
_dbus_assert
(server_pipe_hash_refcount == 0);
00074
00075       server_pipe_hash =
group__DBusHashTable.html#ga1
_dbus_hash_table_new
(DBUS_HASH_STRING,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00076
00077
if
(!server_pipe_hash)
00078
return
group__DBusMacros.html#ga3
FALSE
;
00079     }
00080
00081   server_pipe_hash_refcount = 1;
00082
00083
return
group__DBusMacros.html#ga2
TRUE
;
00084 }
00085
00086
static
void
00087 pipe_hash_unref (
void
)
00088 {
00089
group__DBusInternalsUtils.html#ga130
_dbus_assert
(server_pipe_hash !=
group__DBusMacros.html#ga4
NULL
);
00090
group__DBusInternalsUtils.html#ga130
_dbus_assert
(server_pipe_hash_refcount > 0);
00091
00092   server_pipe_hash_refcount -= 1;
00093
if
(server_pipe_hash_refcount == 0)
00094     {
00095
group__DBusHashTable.html#ga3
_dbus_hash_table_unref
(server_pipe_hash);
00096       server_pipe_hash =
group__DBusMacros.html#ga4
NULL
;
00097     }
00098 }
00099
00100
static
void
00101 debug_finalize (
structDBusServer.html
DBusServer
*server)
00102 {
00103   DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
00104
00105   pipe_hash_unref ();
00106
00107
group__DBusServerInternals.html#ga9
_dbus_server_finalize_base
(server);
00108
00109
group__DBusMemory.html#ga3
dbus_free
(debug_server->name);
00110
group__DBusMemory.html#ga3
dbus_free
(server);
00111 }
00112
00113
static
void
00114 debug_disconnect (
structDBusServer.html
DBusServer
*server)
00115 {
00116   ((DBusServerDebugPipe*)server)->disconnected =
group__DBusMacros.html#ga2
TRUE
;
00117 }
00118
00119
static
structDBusServerVTable.html
DBusServerVTable
debug_vtable = {
00120   debug_finalize,
00121   debug_disconnect
00122 };
00123
00131
structDBusServer.html
DBusServer
*
00132 _dbus_server_debug_pipe_new (
const
char
*server_name,
00133
structDBusError.html
DBusError
*error)
00134 {
00135   DBusServerDebugPipe *debug_server;
00136
structDBusString.html
DBusString
address;
00137
structDBusString.html
DBusString
name_str;
00138
00139   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00140
00141
if
(!pipe_hash_ref ())
00142
return
group__DBusMacros.html#ga4
NULL
;
00143
00144
if
(
group__DBusHashTable.html#ga16
_dbus_hash_table_lookup_string
(server_pipe_hash, server_name) !=
group__DBusMacros.html#ga4
NULL
)
00145     {
00146
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_ADDRESS_IN_USE,
group__DBusMacros.html#ga4
NULL
);
00147       pipe_hash_unref ();
00148
return
group__DBusMacros.html#ga4
NULL
;
00149     }
00150
00151   debug_server =
group__DBusMemory.html#ga7
dbus_new0
(DBusServerDebugPipe, 1);
00152
if
(debug_server ==
group__DBusMacros.html#ga4
NULL
)
00153
goto
nomem_0;
00154
00155
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&address))
00156
goto
nomem_1;
00157
00158
group__DBusString.html#ga7
_dbus_string_init_const
(&name_str, server_name);
00159
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&address,
"debug-pipe:name="
) ||
00160       !
group__DBusAddress.html#ga4
_dbus_address_append_escaped
(&address, &name_str))
00161
goto
nomem_2;
00162
00163   debug_server->name =
group__DBusInternalsUtils.html#ga8
_dbus_strdup
(server_name);
00164
if
(debug_server->name ==
group__DBusMacros.html#ga4
NULL
)
00165
goto
nomem_2;
00166
00167
if
(!
group__DBusServerInternals.html#ga8
_dbus_server_init_base
(&debug_server->base,
00168                                &debug_vtable, &address))
00169
goto
nomem_3;
00170
00171
if
(!
group__DBusHashTable.html#ga22
_dbus_hash_table_insert_string
(server_pipe_hash,
00172                                        debug_server->name,
00173                                        debug_server))
00174
goto
nomem_4;
00175
00176
group__DBusString.html#ga9
_dbus_string_free
(&address);
00177
00178
/* server keeps the pipe hash ref */
00179
00180
return
(
structDBusServer.html
DBusServer
*)debug_server;
00181
00182  nomem_4:
00183
group__DBusServerInternals.html#ga9
_dbus_server_finalize_base
(&debug_server->base);
00184  nomem_3:
00185
group__DBusMemory.html#ga3
dbus_free
(debug_server->name);
00186  nomem_2:
00187
group__DBusString.html#ga9
_dbus_string_free
(&address);
00188  nomem_1:
00189
group__DBusMemory.html#ga3
dbus_free
(debug_server);
00190  nomem_0:
00191   pipe_hash_unref ();
00192
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00193
return
group__DBusMacros.html#ga4
NULL
;
00194 }
00195
00205
structDBusTransport.html
DBusTransport
*
00206 _dbus_transport_debug_pipe_new (
const
char
*server_name,
00207
structDBusError.html
DBusError
*error)
00208 {
00209
structDBusTransport.html
DBusTransport
*client_transport;
00210
structDBusTransport.html
DBusTransport
*server_transport;
00211
structDBusConnection.html
DBusConnection
*connection;
00212
int
client_fd, server_fd;
00213
structDBusServer.html
DBusServer
*server;
00214
structDBusString.html
DBusString
address;
00215
00216   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00217
00218
if
(server_pipe_hash ==
group__DBusMacros.html#ga4
NULL
)
00219     {
00220
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_SERVER,
group__DBusMacros.html#ga4
NULL
);
00221
return
group__DBusMacros.html#ga4
NULL
;
00222     }
00223
00224   server =
group__DBusHashTable.html#ga16
_dbus_hash_table_lookup_string
(server_pipe_hash,
00225                                            server_name);
00226
if
(server ==
group__DBusMacros.html#ga4
NULL
||
00227       ((DBusServerDebugPipe*)server)->disconnected)
00228     {
00229
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_SERVER,
group__DBusMacros.html#ga4
NULL
);
00230
return
group__DBusMacros.html#ga4
NULL
;
00231     }
00232
00233
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&address))
00234     {
00235
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00236
return
group__DBusMacros.html#ga4
NULL
;
00237     }
00238
00239
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&address,
"debug-pipe:name="
) ||
00240       !
group__DBusString.html#ga27
_dbus_string_append
(&address, server_name))
00241     {
00242
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00243
group__DBusString.html#ga9
_dbus_string_free
(&address);
00244
return
group__DBusMacros.html#ga4
NULL
;
00245     }
00246
00247
if
(!
group__DBusInternalsUtils.html#ga104
_dbus_full_duplex_pipe
(&client_fd, &server_fd,
group__DBusMacros.html#ga3
FALSE
,
00248
group__DBusMacros.html#ga4
NULL
))
00249     {
00250       _dbus_verbose (
"failed to create full duplex pipe\n"
);
00251
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_FAILED,
"Could not create full-duplex pipe"
);
00252
group__DBusString.html#ga9
_dbus_string_free
(&address);
00253
return
group__DBusMacros.html#ga4
NULL
;
00254     }
00255
00256
group__DBusInternalsUtils.html#ga98
_dbus_fd_set_close_on_exec
(client_fd);
00257
group__DBusInternalsUtils.html#ga98
_dbus_fd_set_close_on_exec
(server_fd);
00258
00259   client_transport =
group__DBusTransportUnix.html#ga19
_dbus_transport_new_for_fd
(client_fd,
00260
group__DBusMacros.html#ga3
FALSE
, &address);
00261
if
(client_transport ==
group__DBusMacros.html#ga4
NULL
)
00262     {
00263
group__DBusInternalsUtils.html#ga101
_dbus_close
(client_fd,
group__DBusMacros.html#ga4
NULL
);
00264
group__DBusInternalsUtils.html#ga101
_dbus_close
(server_fd,
group__DBusMacros.html#ga4
NULL
);
00265
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00266
group__DBusString.html#ga9
_dbus_string_free
(&address);
00267
return
group__DBusMacros.html#ga4
NULL
;
00268     }
00269
00270
group__DBusString.html#ga9
_dbus_string_free
(&address);
00271
00272   client_fd = -1;
00273
00274   server_transport =
group__DBusTransportUnix.html#ga19
_dbus_transport_new_for_fd
(server_fd,
00275                                                  &server->guid_hex,
group__DBusMacros.html#ga4
NULL
);
00276
if
(server_transport ==
group__DBusMacros.html#ga4
NULL
)
00277     {
00278
group__DBusTransport.html#ga5
_dbus_transport_unref
(client_transport);
00279
group__DBusInternalsUtils.html#ga101
_dbus_close
(server_fd,
group__DBusMacros.html#ga4
NULL
);
00280
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00281
return
group__DBusMacros.html#ga4
NULL
;
00282     }
00283
00284   server_fd = -1;
00285
00286
if
(!
group__DBusTransport.html#ga24
_dbus_transport_set_auth_mechanisms
(server_transport,
00287                                             (
const
char
**) server->auth_mechanisms))
00288     {
00289
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00290
group__DBusTransport.html#ga5
_dbus_transport_unref
(server_transport);
00291
group__DBusTransport.html#ga5
_dbus_transport_unref
(client_transport);
00292
return
group__DBusMacros.html#ga3
FALSE
;
00293     }
00294
00295   connection =
group__DBusConnectionInternals.html#ga42
_dbus_connection_new_for_transport
(server_transport);
00296
group__DBusTransport.html#ga5
_dbus_transport_unref
(server_transport);
00297   server_transport =
group__DBusMacros.html#ga4
NULL
;
00298
00299
if
(connection ==
group__DBusMacros.html#ga4
NULL
)
00300     {
00301
group__DBusTransport.html#ga5
_dbus_transport_unref
(client_transport);
00302
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00303
return
group__DBusMacros.html#ga4
NULL
;
00304     }
00305
00306
/* See if someone wants to handle this new connection,
00307
* self-referencing for paranoia
00308
*/
00309
if
(server->new_connection_function)
00310     {
00311
group__DBusServer.html#ga2
dbus_server_ref
(server);
00312       (* server->new_connection_function) (server, connection,
00313                                            server->new_connection_data);
00314
group__DBusServer.html#ga3
dbus_server_unref
(server);
00315     }
00316
00317
/* If no one grabbed a reference, the connection will die,
00318
* and the client transport will get an immediate disconnect
00319
*/
00320
group__DBusConnection.html#ga5
dbus_connection_unref
(connection);
00321
00322
return
client_transport;
00323 }
00324
00325
00328
#endif
/* DBUS_BUILD_TESTS */
00329
Generated on Tue Sep 13 01:28:07 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
