Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > 926d2d1e3111287cee1b0a4fad4fb4f6 > files > 115

lib64dbus-1_3-devel-0.92-6mdv2007.0.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>dbus-server-debug-pipe.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>dbus-server-debug-pipe.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font>
00002 <font class="comment">/* dbus-server-debug-pipe.c In-proc debug server implementation </font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Copyright (C) 2003  CodeFactory AB</font>
00005 <font class="comment"> * Copyright (C) 2003  Red Hat, Inc.</font>
00006 <font class="comment"> *</font>
00007 <font class="comment"> * Licensed under the Academic Free License version 2.0</font>
00008 <font class="comment"> * </font>
00009 <font class="comment"> * This program is free software; you can redistribute it and/or modify</font>
00010 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00011 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or</font>
00012 <font class="comment"> * (at your option) any later version.</font>
00013 <font class="comment"> *</font>
00014 <font class="comment"> * This program is distributed in the hope that it will be useful,</font>
00015 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</font>
00017 <font class="comment"> * GNU General Public License for more details.</font>
00018 <font class="comment"> * </font>
00019 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00020 <font class="comment"> * along with this program; if not, write to the Free Software</font>
00021 <font class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> */</font>
00024 
00025 <font class="preprocessor">#include "dbus-internals.h"</font>
00026 <font class="preprocessor">#include "dbus-server-debug-pipe.h"</font>
00027 <font class="preprocessor">#include "dbus-transport-unix.h"</font>
00028 <font class="preprocessor">#include "dbus-connection-internal.h"</font>
00029 <font class="preprocessor">#include "dbus-hash.h"</font>
00030 <font class="preprocessor">#include "dbus-string.h"</font>
00031 
00032 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font>
00033 <font class="preprocessor"></font>
<a name="l00048"></a><a class="code" href="group__DBusServerDebugPipe.html#a0">00048</a> <font class="keyword">typedef</font> <font class="keyword">struct </font><a class="code" href="structDBusServerDebugPipe.html">DBusServerDebugPipe</a> DBusServerDebugPipe;
00049 
<a name="l00054"></a><a class="code" href="structDBusServerDebugPipe.html">00054</a> <font class="keyword">struct </font>DBusServerDebugPipe
00055 {
<a name="l00056"></a><a class="code" href="structDBusServerDebugPipe.html#m0">00056</a>   <a class="code" href="structDBusServer.html">DBusServer</a> <a class="code" href="structDBusServerDebugPipe.html#m0">base</a>;  
<a name="l00058"></a><a class="code" href="structDBusServerDebugPipe.html#m1">00058</a>   <font class="keywordtype">char</font> *<a class="code" href="structDBusServerDebugPipe.html#m1">name</a>; 
<a name="l00060"></a><a class="code" href="structDBusServerDebugPipe.html#m2">00060</a>   dbus_bool_t <a class="code" href="structDBusServerDebugPipe.html#m2">disconnected</a>; 
00061 };
00062 
00063 <font class="comment">/* FIXME not threadsafe (right now the test suite doesn't use threads anyhow ) */</font>
00064 <font class="keyword">static</font> <a class="code" href="structDBusHashTable.html">DBusHashTable</a> *server_pipe_hash;
00065 <font class="keyword">static</font> <font class="keywordtype">int</font> server_pipe_hash_refcount = 0;
00066 
00067 <font class="keyword">static</font> dbus_bool_t
00068 pipe_hash_ref (<font class="keywordtype">void</font>)
00069 {
00070   <font class="keywordflow">if</font> (!server_pipe_hash)
00071     {
00072       _dbus_assert (server_pipe_hash_refcount == 0);
00073       
00074       server_pipe_hash = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, NULL);
00075 
00076       <font class="keywordflow">if</font> (!server_pipe_hash)
00077         <font class="keywordflow">return</font> FALSE;
00078     }
00079 
00080   server_pipe_hash_refcount = 1;
00081 
00082   <font class="keywordflow">return</font> TRUE;
00083 }
00084 
00085 <font class="keyword">static</font> <font class="keywordtype">void</font>
00086 pipe_hash_unref (<font class="keywordtype">void</font>)
00087 {
00088   _dbus_assert (server_pipe_hash != NULL);
00089   _dbus_assert (server_pipe_hash_refcount &gt; 0);
00090 
00091   server_pipe_hash_refcount -= 1;
00092   <font class="keywordflow">if</font> (server_pipe_hash_refcount == 0)
00093     {
00094       _dbus_hash_table_unref (server_pipe_hash);
00095       server_pipe_hash = NULL;
00096     }
00097 }
00098 
00099 <font class="keyword">static</font> <font class="keywordtype">void</font>
00100 debug_finalize (<a class="code" href="structDBusServer.html">DBusServer</a> *server)
00101 {
00102   DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
00103 
00104   pipe_hash_unref ();
00105   
00106   _dbus_server_finalize_base (server);
00107 
00108   dbus_free (debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m1">name</a>);
00109   dbus_free (server);
00110 }
00111 
00112 <font class="keyword">static</font> <font class="keywordtype">void</font>
00113 debug_disconnect (<a class="code" href="structDBusServer.html">DBusServer</a> *server)
00114 {
00115   ((DBusServerDebugPipe*)server)-&gt;disconnected = TRUE;
00116 }
00117 
00118 <font class="keyword">static</font> <a class="code" href="structDBusServerVTable.html">DBusServerVTable</a> debug_vtable = {
00119   debug_finalize,
00120   debug_disconnect
00121 };
00122 
00130 <a class="code" href="structDBusServer.html">DBusServer</a>*
<a name="l00131"></a><a class="code" href="group__DBusServerDebugPipe.html#a8">00131</a> _dbus_server_debug_pipe_new (<font class="keyword">const</font> <font class="keywordtype">char</font>     *server_name,
00132                              <a class="code" href="structDBusError.html">DBusError</a>      *error)
00133 {
00134   DBusServerDebugPipe *debug_server;
00135   <a class="code" href="structDBusString.html">DBusString</a> address;
00136   
00137   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00138   
00139   <font class="keywordflow">if</font> (!pipe_hash_ref ())
00140     <font class="keywordflow">return</font> NULL;
00141   
00142   <font class="keywordflow">if</font> (_dbus_hash_table_lookup_string (server_pipe_hash, server_name) != NULL)
00143     {
00144       dbus_set_error (error, DBUS_ERROR_ADDRESS_IN_USE, NULL);
00145       pipe_hash_unref ();
00146       <font class="keywordflow">return</font> NULL;
00147     }
00148   
00149   debug_server = dbus_new0 (DBusServerDebugPipe, 1);
00150   <font class="keywordflow">if</font> (debug_server == NULL)
00151     <font class="keywordflow">goto</font> nomem_0;
00152 
00153   <font class="keywordflow">if</font> (!_dbus_string_init (&amp;address))
00154     <font class="keywordflow">goto</font> nomem_1;
00155 
00156   <font class="keywordflow">if</font> (!_dbus_string_append (&amp;address, <font class="stringliteral">"debug-pipe:name="</font>) ||
00157       !_dbus_string_append (&amp;address, server_name))
00158     <font class="keywordflow">goto</font> nomem_2;
00159   
00160   debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m1">name</a> = _dbus_strdup (server_name);
00161   <font class="keywordflow">if</font> (debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m1">name</a> == NULL)
00162     <font class="keywordflow">goto</font> nomem_2;
00163   
00164   <font class="keywordflow">if</font> (!_dbus_server_init_base (&amp;debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m0">base</a>,
00165                                &amp;debug_vtable, &amp;address))
00166     <font class="keywordflow">goto</font> nomem_3;
00167 
00168   <font class="keywordflow">if</font> (!_dbus_hash_table_insert_string (server_pipe_hash,
00169                                        debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m1">name</a>,
00170                                        debug_server))
00171     <font class="keywordflow">goto</font> nomem_4;
00172 
00173   _dbus_string_free (&amp;address);
00174 
00175   <font class="comment">/* server keeps the pipe hash ref */</font>
00176   
00177   <font class="keywordflow">return</font> (<a class="code" href="structDBusServer.html">DBusServer</a> *)debug_server;
00178 
00179  nomem_4:
00180   _dbus_server_finalize_base (&amp;debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m0">base</a>);
00181  nomem_3:
00182   dbus_free (debug_server-&gt;<a class="code" href="structDBusServerDebugPipe.html#m1">name</a>);
00183  nomem_2:
00184   _dbus_string_free (&amp;address);
00185  nomem_1:
00186   dbus_free (debug_server);
00187  nomem_0:
00188   pipe_hash_unref ();
00189   dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00190   <font class="keywordflow">return</font> NULL;
00191 }
00192 
00202 <a class="code" href="structDBusTransport.html">DBusTransport</a>*
<a name="l00203"></a><a class="code" href="group__DBusServerDebugPipe.html#a9">00203</a> _dbus_transport_debug_pipe_new (<font class="keyword">const</font> <font class="keywordtype">char</font>     *server_name,
00204                                 <a class="code" href="structDBusError.html">DBusError</a>      *error)
00205 {
00206   <a class="code" href="structDBusTransport.html">DBusTransport</a> *client_transport;
00207   <a class="code" href="structDBusTransport.html">DBusTransport</a> *server_transport;
00208   <a class="code" href="structDBusConnection.html">DBusConnection</a> *connection;
00209   <font class="keywordtype">int</font> client_fd, server_fd;
00210   <a class="code" href="structDBusServer.html">DBusServer</a> *server;
00211   <a class="code" href="structDBusString.html">DBusString</a> address;
00212   
00213   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00214 
00215   <font class="keywordflow">if</font> (server_pipe_hash == NULL)
00216     {
00217       dbus_set_error (error, DBUS_ERROR_NO_SERVER, NULL);
00218       <font class="keywordflow">return</font> NULL;
00219     }
00220   
00221   server = _dbus_hash_table_lookup_string (server_pipe_hash,
00222                                            server_name);
00223   <font class="keywordflow">if</font> (server == NULL ||
00224       ((DBusServerDebugPipe*)server)-&gt;disconnected)
00225     {
00226       dbus_set_error (error, DBUS_ERROR_NO_SERVER, NULL);
00227       <font class="keywordflow">return</font> NULL;
00228     }
00229 
00230   <font class="keywordflow">if</font> (!_dbus_string_init (&amp;address))
00231     {
00232       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00233       <font class="keywordflow">return</font> NULL;
00234     }
00235 
00236   <font class="keywordflow">if</font> (!_dbus_string_append (&amp;address, <font class="stringliteral">"debug-pipe:name="</font>) ||
00237       !_dbus_string_append (&amp;address, server_name))
00238     {
00239       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00240       _dbus_string_free (&amp;address);
00241       <font class="keywordflow">return</font> NULL;
00242     }
00243   
00244   <font class="keywordflow">if</font> (!_dbus_full_duplex_pipe (&amp;client_fd, &amp;server_fd, FALSE,
00245                                NULL))
00246     {
00247       _dbus_verbose (<font class="stringliteral">"failed to create full duplex pipe\n"</font>);
00248       dbus_set_error (error, DBUS_ERROR_FAILED, <font class="stringliteral">"Could not create full-duplex pipe"</font>);
00249       _dbus_string_free (&amp;address);
00250       <font class="keywordflow">return</font> NULL;
00251     }
00252 
00253   _dbus_fd_set_close_on_exec (client_fd);
00254   _dbus_fd_set_close_on_exec (server_fd);
00255   
00256   client_transport = _dbus_transport_new_for_fd (client_fd,
00257                                                  FALSE, &amp;address);
00258   <font class="keywordflow">if</font> (client_transport == NULL)
00259     {
00260       _dbus_close (client_fd, NULL);
00261       _dbus_close (server_fd, NULL);
00262       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00263       _dbus_string_free (&amp;address);
00264       <font class="keywordflow">return</font> NULL;
00265     }
00266 
00267   _dbus_string_free (&amp;address);
00268   
00269   client_fd = -1;
00270   
00271   server_transport = _dbus_transport_new_for_fd (server_fd,
00272                                                  TRUE, NULL);
00273   <font class="keywordflow">if</font> (server_transport == NULL)
00274     {
00275       _dbus_transport_unref (client_transport);
00276       _dbus_close (server_fd, NULL);
00277       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00278       <font class="keywordflow">return</font> NULL;
00279     }
00280 
00281   server_fd = -1;
00282 
00283   <font class="keywordflow">if</font> (!_dbus_transport_set_auth_mechanisms (server_transport,
00284                                             (<font class="keyword">const</font> <font class="keywordtype">char</font>**) server-&gt;<a class="code" href="structDBusServer.html#m10">auth_mechanisms</a>))
00285     {
00286       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00287       _dbus_transport_unref (server_transport);
00288       _dbus_transport_unref (client_transport);
00289       <font class="keywordflow">return</font> FALSE;
00290     }
00291   
00292   connection = _dbus_connection_new_for_transport (server_transport);
00293   _dbus_transport_unref (server_transport);
00294   server_transport = NULL;
00295   
00296   <font class="keywordflow">if</font> (connection == NULL)
00297     {
00298       _dbus_transport_unref (client_transport);
00299       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00300       <font class="keywordflow">return</font> NULL;
00301     }
00302 
00303   <font class="comment">/* See if someone wants to handle this new connection,</font>
00304 <font class="comment">   * self-referencing for paranoia</font>
00305 <font class="comment">   */</font>
00306   <font class="keywordflow">if</font> (server-&gt;<a class="code" href="structDBusServer.html#m7">new_connection_function</a>)
00307     {
00308       dbus_server_ref (server);
00309       (* server-&gt;<a class="code" href="structDBusServer.html#m7">new_connection_function</a>) (server, connection,
00310                                            server-&gt;<a class="code" href="structDBusServer.html#m8">new_connection_data</a>);
00311       dbus_server_unref (server);
00312     }
00313   
00314   <font class="comment">/* If no one grabbed a reference, the connection will die,</font>
00315 <font class="comment">   * and the client transport will get an immediate disconnect</font>
00316 <font class="comment">   */</font>
00317   dbus_connection_unref (connection);
00318 
00319   <font class="keywordflow">return</font> client_transport;
00320 }
00321 
00322 
00325 <font class="preprocessor">#endif </font><font class="comment">/* DBUS_BUILD_TESTS */</font>
00326 
</pre></div><hr><address align="right"><small>Generated on Wed Jun 9 05:01:26 2004 for D-BUS by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>