KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /usr/share/devhelp/books/dbus/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/devhelp/books/dbus/api/dbus-internals_8c-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>D-Bus: dbus-internals.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul></div>
<h1>dbus-internals.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-internals.c  random utility stuff (internal to D-Bus implementation)</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003  Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> * </span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "dbus-internals.h"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "dbus-protocol.h"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "dbus-marshal-basic.h"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "dbus-test.h"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;stdarg.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00031"></a>00031 
<a name="l00192"></a><a class="code" href="group__DBusInternalsUtils.html#g34ea28d688e524b6eefa9698b1940fc4">00192</a> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="group__DBusInternalsUtils.html#g34ea28d688e524b6eefa9698b1940fc4">_dbus_no_memory_message</a>[] = <span class="stringliteral">"Not enough memory"</span>;
<a name="l00193"></a>00193 
<a name="l00194"></a>00194 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> warn_initted = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00195"></a>00195 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> fatal_warnings = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00196"></a>00196 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> fatal_warnings_on_check_failed = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00199"></a>00199 init_warnings(<span class="keywordtype">void</span>)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201   <span class="keywordflow">if</span> (!warn_initted)
<a name="l00202"></a>00202     {
<a name="l00203"></a>00203       <span class="keyword">const</span> <span class="keywordtype">char</span> *s;
<a name="l00204"></a>00204       s = <a class="code" href="group__DBusSysdeps.html#gb846071a4de54cb7e518654f9375313a">_dbus_getenv</a> (<span class="stringliteral">"DBUS_FATAL_WARNINGS"</span>);
<a name="l00205"></a>00205       <span class="keywordflow">if</span> (s &amp;&amp; *s)
<a name="l00206"></a>00206         {
<a name="l00207"></a>00207           <span class="keywordflow">if</span> (*s == <span class="charliteral">'0'</span>)
<a name="l00208"></a>00208             {
<a name="l00209"></a>00209               fatal_warnings = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00210"></a>00210               fatal_warnings_on_check_failed = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00211"></a>00211             }
<a name="l00212"></a>00212           <span class="keywordflow">else</span> <span class="keywordflow">if</span> (*s == <span class="charliteral">'1'</span>)
<a name="l00213"></a>00213             {
<a name="l00214"></a>00214               fatal_warnings = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00215"></a>00215               fatal_warnings_on_check_failed = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00216"></a>00216             }
<a name="l00217"></a>00217           <span class="keywordflow">else</span>
<a name="l00218"></a>00218             {
<a name="l00219"></a>00219               fprintf(stderr, <span class="stringliteral">"DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'"</span>,
<a name="l00220"></a>00220                       s);
<a name="l00221"></a>00221             }
<a name="l00222"></a>00222         }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224       warn_initted = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00225"></a>00225     }
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 
<a name="l00237"></a>00237 <span class="keywordtype">void</span>
<a name="l00238"></a><a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">00238</a> <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *format,
<a name="l00239"></a>00239             ...)
<a name="l00240"></a>00240 {
<a name="l00241"></a>00241   va_list args;
<a name="l00242"></a>00242 
<a name="l00243"></a>00243   <span class="keywordflow">if</span> (!warn_initted)
<a name="l00244"></a>00244     init_warnings ();
<a name="l00245"></a>00245   
<a name="l00246"></a>00246   va_start (args, format);
<a name="l00247"></a>00247   vfprintf (stderr, format, args);
<a name="l00248"></a>00248   va_end (args);
<a name="l00249"></a>00249 
<a name="l00250"></a>00250   <span class="keywordflow">if</span> (fatal_warnings)
<a name="l00251"></a>00251     {
<a name="l00252"></a>00252       fflush (stderr);
<a name="l00253"></a>00253       <a class="code" href="group__DBusSysdeps.html#g83c51771d3c4e612522bd5ad72e6ad7a">_dbus_abort</a> ();
<a name="l00254"></a>00254     }
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 
<a name="l00265"></a>00265 <span class="keywordtype">void</span>
<a name="l00266"></a><a class="code" href="group__DBusInternalsUtils.html#g63f2f8a068454b781f214ba596e313b4">00266</a> <a class="code" href="group__DBusInternalsUtils.html#g63f2f8a068454b781f214ba596e313b4">_dbus_warn_check_failed</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format,
<a name="l00267"></a>00267                         ...)
<a name="l00268"></a>00268 {
<a name="l00269"></a>00269   va_list args;
<a name="l00270"></a>00270   
<a name="l00271"></a>00271   <span class="keywordflow">if</span> (!warn_initted)
<a name="l00272"></a>00272     init_warnings ();
<a name="l00273"></a>00273 
<a name="l00274"></a>00274   fprintf (stderr, <span class="stringliteral">"process %lu: "</span>, <a class="code" href="group__DBusSysdeps.html#g1b30aa55e8758ed6e1b62e0f86866543">_dbus_pid_for_log</a> ());
<a name="l00275"></a>00275   
<a name="l00276"></a>00276   va_start (args, format);
<a name="l00277"></a>00277   vfprintf (stderr, format, args);
<a name="l00278"></a>00278   va_end (args);
<a name="l00279"></a>00279 
<a name="l00280"></a>00280   <span class="keywordflow">if</span> (fatal_warnings_on_check_failed)
<a name="l00281"></a>00281     {
<a name="l00282"></a>00282       fflush (stderr);
<a name="l00283"></a>00283       <a class="code" href="group__DBusSysdeps.html#g83c51771d3c4e612522bd5ad72e6ad7a">_dbus_abort</a> ();
<a name="l00284"></a>00284     }
<a name="l00285"></a>00285 }
<a name="l00286"></a>00286 
<a name="l00287"></a>00287 <span class="preprocessor">#ifdef DBUS_ENABLE_VERBOSE_MODE</span>
<a name="l00288"></a>00288 <span class="preprocessor"></span>
<a name="l00289"></a>00289 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> verbose_initted = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00290"></a>00290 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> verbose = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00291"></a>00291 
<a name="l00293"></a>00293 <span class="preprocessor">#define PTHREAD_IN_VERBOSE 0</span>
<a name="l00294"></a>00294 <span class="preprocessor"></span><span class="preprocessor">#if PTHREAD_IN_VERBOSE</span>
<a name="l00295"></a>00295 <span class="preprocessor"></span><span class="preprocessor">#include &lt;pthread.h&gt;</span>
<a name="l00296"></a>00296 <span class="preprocessor">#endif</span>
<a name="l00297"></a>00297 <span class="preprocessor"></span>
<a name="l00298"></a>00298 <span class="preprocessor">#ifdef DBUS_WIN</span>
<a name="l00299"></a>00299 <span class="preprocessor"></span><span class="preprocessor">#define inline</span>
<a name="l00300"></a>00300 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00301"></a>00301 <span class="preprocessor"></span>
<a name="l00302"></a>00302 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span>
<a name="l00303"></a>00303 _dbus_verbose_init (<span class="keywordtype">void</span>)
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305   <span class="keywordflow">if</span> (!verbose_initted)
<a name="l00306"></a>00306     {
<a name="l00307"></a>00307       <span class="keyword">const</span> <span class="keywordtype">char</span> *p = <a class="code" href="group__DBusSysdeps.html#gb846071a4de54cb7e518654f9375313a">_dbus_getenv</a> (<span class="stringliteral">"DBUS_VERBOSE"</span>); 
<a name="l00308"></a>00308       verbose = p != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> &amp;&amp; *p == <span class="charliteral">'1'</span>;
<a name="l00309"></a>00309       verbose_initted = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00310"></a>00310     }
<a name="l00311"></a>00311 }
<a name="l00312"></a>00312 
<a name="l00318"></a>00318 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00319"></a>00319 _dbus_is_verbose_real (<span class="keywordtype">void</span>)
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321   _dbus_verbose_init ();
<a name="l00322"></a>00322   <span class="keywordflow">return</span> verbose;
<a name="l00323"></a>00323 }
<a name="l00324"></a>00324 
<a name="l00333"></a>00333 <span class="keywordtype">void</span>
<a name="l00334"></a>00334 _dbus_verbose_real (<span class="keyword">const</span> <span class="keywordtype">char</span> *format,
<a name="l00335"></a>00335                     ...)
<a name="l00336"></a>00336 {
<a name="l00337"></a>00337   va_list args;
<a name="l00338"></a>00338   <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> need_pid = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00339"></a>00339   <span class="keywordtype">int</span> len;
<a name="l00340"></a>00340   
<a name="l00341"></a>00341   <span class="comment">/* things are written a bit oddly here so that</span>
<a name="l00342"></a>00342 <span class="comment">   * in the non-verbose case we just have the one</span>
<a name="l00343"></a>00343 <span class="comment">   * conditional and return immediately.</span>
<a name="l00344"></a>00344 <span class="comment">   */</span>
<a name="l00345"></a>00345   <span class="keywordflow">if</span> (!_dbus_is_verbose_real())
<a name="l00346"></a>00346     <span class="keywordflow">return</span>;
<a name="l00347"></a>00347 
<a name="l00348"></a>00348   <span class="comment">/* Print out pid before the line */</span>
<a name="l00349"></a>00349   <span class="keywordflow">if</span> (need_pid)
<a name="l00350"></a>00350     {
<a name="l00351"></a>00351 <span class="preprocessor">#if PTHREAD_IN_VERBOSE</span>
<a name="l00352"></a>00352 <span class="preprocessor"></span>      fprintf (stderr, <span class="stringliteral">"%lu: 0x%lx: "</span>, <a class="code" href="group__DBusSysdeps.html#g1b30aa55e8758ed6e1b62e0f86866543">_dbus_pid_for_log</a> (), pthread_self ());
<a name="l00353"></a>00353 <span class="preprocessor">#else</span>
<a name="l00354"></a>00354 <span class="preprocessor"></span>      fprintf (stderr, <span class="stringliteral">"%lu: "</span>, <a class="code" href="group__DBusSysdeps.html#g1b30aa55e8758ed6e1b62e0f86866543">_dbus_pid_for_log</a> ());
<a name="l00355"></a>00355 <span class="preprocessor">#endif</span>
<a name="l00356"></a>00356 <span class="preprocessor"></span>    }
<a name="l00357"></a>00357       
<a name="l00358"></a>00358 
<a name="l00359"></a>00359   <span class="comment">/* Only print pid again if the next line is a new line */</span>
<a name="l00360"></a>00360   len = strlen (format);
<a name="l00361"></a>00361   <span class="keywordflow">if</span> (format[len-1] == <span class="charliteral">'\n'</span>)
<a name="l00362"></a>00362     need_pid = <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00363"></a>00363   <span class="keywordflow">else</span>
<a name="l00364"></a>00364     need_pid = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00365"></a>00365   
<a name="l00366"></a>00366   va_start (args, format);
<a name="l00367"></a>00367   vfprintf (stderr, format, args);
<a name="l00368"></a>00368   va_end (args);
<a name="l00369"></a>00369 
<a name="l00370"></a>00370   fflush (stderr);
<a name="l00371"></a>00371 }
<a name="l00372"></a>00372 
<a name="l00379"></a>00379 <span class="keywordtype">void</span>
<a name="l00380"></a>00380 _dbus_verbose_reset_real (<span class="keywordtype">void</span>)
<a name="l00381"></a>00381 {
<a name="l00382"></a>00382   verbose_initted = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00383"></a>00383 }
<a name="l00384"></a>00384 
<a name="l00385"></a>00385 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_ENABLE_VERBOSE_MODE */</span>
<a name="l00386"></a>00386 
<a name="l00395"></a>00395 <span class="keywordtype">char</span>*
<a name="l00396"></a><a class="code" href="group__DBusInternalsUtils.html#g9d00d77f6595b9d7ac1baf59d44bf58c">00396</a> <a class="code" href="group__DBusInternalsUtils.html#g9d00d77f6595b9d7ac1baf59d44bf58c">_dbus_strdup</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *str)
<a name="l00397"></a>00397 {
<a name="l00398"></a>00398   size_t len;
<a name="l00399"></a>00399   <span class="keywordtype">char</span> *copy;
<a name="l00400"></a>00400   
<a name="l00401"></a>00401   <span class="keywordflow">if</span> (str == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00402"></a>00402     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00403"></a>00403   
<a name="l00404"></a>00404   len = strlen (str);
<a name="l00405"></a>00405 
<a name="l00406"></a>00406   copy = <a class="code" href="group__DBusMemory.html#g0fff22bd7f055f5581a9898116a744b1">dbus_malloc</a> (len + 1);
<a name="l00407"></a>00407   <span class="keywordflow">if</span> (copy == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00408"></a>00408     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00409"></a>00409 
<a name="l00410"></a>00410   memcpy (copy, str, len + 1);
<a name="l00411"></a>00411   
<a name="l00412"></a>00412   <span class="keywordflow">return</span> copy;
<a name="l00413"></a>00413 }
<a name="l00414"></a>00414 
<a name="l00423"></a>00423 <span class="keywordtype">void</span>*
<a name="l00424"></a><a class="code" href="group__DBusInternalsUtils.html#gad95864dca5140b730bc143cb2d1b024">00424</a> <a class="code" href="group__DBusInternalsUtils.html#gad95864dca5140b730bc143cb2d1b024">_dbus_memdup</a> (<span class="keyword">const</span> <span class="keywordtype">void</span>  *mem,
<a name="l00425"></a>00425               size_t       n_bytes)
<a name="l00426"></a>00426 {
<a name="l00427"></a>00427   <span class="keywordtype">void</span> *copy;
<a name="l00428"></a>00428 
<a name="l00429"></a>00429   copy = <a class="code" href="group__DBusMemory.html#g0fff22bd7f055f5581a9898116a744b1">dbus_malloc</a> (n_bytes);
<a name="l00430"></a>00430   <span class="keywordflow">if</span> (copy == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00431"></a>00431     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00432"></a>00432 
<a name="l00433"></a>00433   memcpy (copy, mem, n_bytes);
<a name="l00434"></a>00434   
<a name="l00435"></a>00435   <span class="keywordflow">return</span> copy;
<a name="l00436"></a>00436 }
<a name="l00437"></a>00437 
<a name="l00446"></a>00446 <span class="keywordtype">char</span>**
<a name="l00447"></a><a class="code" href="group__DBusInternalsUtils.html#g53bbcbbd0b564c14c599813dde535443">00447</a> <a class="code" href="group__DBusInternalsUtils.html#g53bbcbbd0b564c14c599813dde535443">_dbus_dup_string_array</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> **array)
<a name="l00448"></a>00448 {
<a name="l00449"></a>00449   <span class="keywordtype">int</span> len;
<a name="l00450"></a>00450   <span class="keywordtype">int</span> i;
<a name="l00451"></a>00451   <span class="keywordtype">char</span> **copy;
<a name="l00452"></a>00452   
<a name="l00453"></a>00453   <span class="keywordflow">if</span> (array == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00454"></a>00454     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00455"></a>00455 
<a name="l00456"></a>00456   <span class="keywordflow">for</span> (len = 0; array[len] != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; ++len)
<a name="l00457"></a>00457     ;
<a name="l00458"></a>00458 
<a name="l00459"></a>00459   copy = <a class="code" href="group__DBusMemory.html#gba9d823abda7f4cadbaf5177d3b8b793">dbus_new0</a> (<span class="keywordtype">char</span>*, len + 1);
<a name="l00460"></a>00460   <span class="keywordflow">if</span> (copy == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00461"></a>00461     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00462"></a>00462 
<a name="l00463"></a>00463   i = 0;
<a name="l00464"></a>00464   <span class="keywordflow">while</span> (i &lt; len)
<a name="l00465"></a>00465     {
<a name="l00466"></a>00466       copy[i] = <a class="code" href="group__DBusInternalsUtils.html#g9d00d77f6595b9d7ac1baf59d44bf58c">_dbus_strdup</a> (array[i]);
<a name="l00467"></a>00467       <span class="keywordflow">if</span> (copy[i] == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00468"></a>00468         {
<a name="l00469"></a>00469           <a class="code" href="group__DBusMemory.html#g6d4674de64d806d238ffd309a486754e">dbus_free_string_array</a> (copy);
<a name="l00470"></a>00470           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00471"></a>00471         }
<a name="l00472"></a>00472 
<a name="l00473"></a>00473       ++i;
<a name="l00474"></a>00474     }
<a name="l00475"></a>00475 
<a name="l00476"></a>00476   <span class="keywordflow">return</span> copy;
<a name="l00477"></a>00477 }
<a name="l00478"></a>00478 
<a name="l00486"></a>00486 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00487"></a><a class="code" href="group__DBusInternalsUtils.html#g751119e7273225a7e59787445b71fcd6">00487</a> <a class="code" href="group__DBusInternalsUtils.html#g751119e7273225a7e59787445b71fcd6">_dbus_string_array_contains</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> **array,
<a name="l00488"></a>00488                              <span class="keyword">const</span> <span class="keywordtype">char</span>  *str)
<a name="l00489"></a>00489 {
<a name="l00490"></a>00490   <span class="keywordtype">int</span> i;
<a name="l00491"></a>00491 
<a name="l00492"></a>00492   i = 0;
<a name="l00493"></a>00493   <span class="keywordflow">while</span> (array[i] != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00494"></a>00494     {
<a name="l00495"></a>00495       <span class="keywordflow">if</span> (strcmp (array[i], str) == 0)
<a name="l00496"></a>00496         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00497"></a>00497       ++i;
<a name="l00498"></a>00498     }
<a name="l00499"></a>00499 
<a name="l00500"></a>00500   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00501"></a>00501 }
<a name="l00502"></a>00502 
<a name="l00509"></a>00509 <span class="keywordtype">void</span>
<a name="l00510"></a><a class="code" href="group__DBusInternalsUtils.html#g08c2922335845e5c857e88399436b9ba">00510</a> <a class="code" href="group__DBusInternalsUtils.html#g08c2922335845e5c857e88399436b9ba">_dbus_generate_uuid</a> (<a class="code" href="unionDBusGUID.html">DBusGUID</a> *uuid)
<a name="l00511"></a>00511 {
<a name="l00512"></a>00512   <span class="keywordtype">long</span> now;
<a name="l00513"></a>00513 
<a name="l00514"></a>00514   <a class="code" href="group__DBusSysdeps.html#g4e3cbe529fc3e7984ed6553672e085f8">_dbus_get_current_time</a> (&amp;now, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00515"></a>00515 
<a name="l00516"></a>00516   uuid-&gt;<a class="code" href="unionDBusGUID.html#3db114d87644fab561564504a8653e72">as_uint32s</a>[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
<a name="l00517"></a>00517   
<a name="l00518"></a>00518   <a class="code" href="group__DBusInternalsUtils.html#ga32f87746e9264b2425736043d02fad4">_dbus_generate_random_bytes_buffer</a> (uuid-&gt;<a class="code" href="unionDBusGUID.html#f45818fb0ae65fdece11aba936af7f09">as_bytes</a>, DBUS_UUID_LENGTH_BYTES - 4);
<a name="l00519"></a>00519 }
<a name="l00520"></a>00520 
<a name="l00528"></a>00528 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00529"></a><a class="code" href="group__DBusInternalsUtils.html#gf08364813376bd2d8f455d435d85323e">00529</a> <a class="code" href="group__DBusInternalsUtils.html#gf08364813376bd2d8f455d435d85323e">_dbus_uuid_encode</a> (<span class="keyword">const</span> <a class="code" href="unionDBusGUID.html">DBusGUID</a> *uuid,
<a name="l00530"></a>00530                    <a class="code" href="structDBusString.html">DBusString</a>     *encoded)
<a name="l00531"></a>00531 {
<a name="l00532"></a>00532   <a class="code" href="structDBusString.html">DBusString</a> binary;
<a name="l00533"></a>00533   <a class="code" href="group__DBusString.html#g6792a5c1725faa9d635d95f7a3b5bfae">_dbus_string_init_const_len</a> (&amp;binary, uuid-&gt;<a class="code" href="unionDBusGUID.html#f45818fb0ae65fdece11aba936af7f09">as_bytes</a>, DBUS_UUID_LENGTH_BYTES);
<a name="l00534"></a>00534   <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#gabb4873f436e015944a33cd1e3815cc9">_dbus_string_hex_encode</a> (&amp;binary, 0, encoded, _dbus_string_get_length (encoded));
<a name="l00535"></a>00535 }
<a name="l00536"></a>00536 
<a name="l00537"></a>00537 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00538"></a>00538 _dbus_read_uuid_file_without_creating (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00539"></a>00539                                        <a class="code" href="unionDBusGUID.html">DBusGUID</a>         *uuid,
<a name="l00540"></a>00540                                        <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00541"></a>00541 {
<a name="l00542"></a>00542   <a class="code" href="structDBusString.html">DBusString</a> contents;
<a name="l00543"></a>00543   <a class="code" href="structDBusString.html">DBusString</a> decoded;
<a name="l00544"></a>00544   <span class="keywordtype">int</span> end;
<a name="l00545"></a>00545   
<a name="l00546"></a>00546   <a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&amp;contents);
<a name="l00547"></a>00547   <a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&amp;decoded);
<a name="l00548"></a>00548   
<a name="l00549"></a>00549   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#gd22d468e789139c87f7f4bb97cadf448">_dbus_file_get_contents</a> (&amp;contents, filename, error))
<a name="l00550"></a>00550     <span class="keywordflow">goto</span> error;
<a name="l00551"></a>00551 
<a name="l00552"></a>00552   <a class="code" href="group__DBusString.html#ga92c6ab2c5e24cbefef0a3f3fc76f98b">_dbus_string_chop_white</a> (&amp;contents);
<a name="l00553"></a>00553 
<a name="l00554"></a>00554   <span class="keywordflow">if</span> (_dbus_string_get_length (&amp;contents) != DBUS_UUID_LENGTH_HEX)
<a name="l00555"></a>00555     {
<a name="l00556"></a>00556       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#g6a4e92aa48ed4486eaf48c40c72490c4">DBUS_ERROR_INVALID_FILE_CONTENT</a>,
<a name="l00557"></a>00557                       <span class="stringliteral">"UUID file '%s' should contain a hex string of length %d, not length %d, with no other text"</span>,
<a name="l00558"></a>00558                       _dbus_string_get_const_data (filename),
<a name="l00559"></a>00559                       DBUS_UUID_LENGTH_HEX,
<a name="l00560"></a>00560                       _dbus_string_get_length (&amp;contents));
<a name="l00561"></a>00561       <span class="keywordflow">goto</span> error;
<a name="l00562"></a>00562     }
<a name="l00563"></a>00563 
<a name="l00564"></a>00564   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g0a8c20d855f9ddc05718b9e2ac0e33d8">_dbus_string_hex_decode</a> (&amp;contents, 0, &amp;end, &amp;decoded, 0))
<a name="l00565"></a>00565     {
<a name="l00566"></a>00566       _DBUS_SET_OOM (error);
<a name="l00567"></a>00567       <span class="keywordflow">goto</span> error;
<a name="l00568"></a>00568     }
<a name="l00569"></a>00569 
<a name="l00570"></a>00570   <span class="keywordflow">if</span> (end == 0)
<a name="l00571"></a>00571     {
<a name="l00572"></a>00572       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#g6a4e92aa48ed4486eaf48c40c72490c4">DBUS_ERROR_INVALID_FILE_CONTENT</a>,
<a name="l00573"></a>00573                       <span class="stringliteral">"UUID file '%s' contains invalid hex data"</span>,
<a name="l00574"></a>00574                       _dbus_string_get_const_data (filename));
<a name="l00575"></a>00575       <span class="keywordflow">goto</span> error;
<a name="l00576"></a>00576     }
<a name="l00577"></a>00577 
<a name="l00578"></a>00578   <span class="keywordflow">if</span> (_dbus_string_get_length (&amp;decoded) != DBUS_UUID_LENGTH_BYTES)
<a name="l00579"></a>00579     {
<a name="l00580"></a>00580       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#g6a4e92aa48ed4486eaf48c40c72490c4">DBUS_ERROR_INVALID_FILE_CONTENT</a>,
<a name="l00581"></a>00581                       <span class="stringliteral">"UUID file '%s' contains %d bytes of hex-encoded data instead of %d"</span>,
<a name="l00582"></a>00582                       _dbus_string_get_const_data (filename),
<a name="l00583"></a>00583                       _dbus_string_get_length (&amp;decoded),
<a name="l00584"></a>00584                       DBUS_UUID_LENGTH_BYTES);
<a name="l00585"></a>00585       <span class="keywordflow">goto</span> error;
<a name="l00586"></a>00586     }
<a name="l00587"></a>00587 
<a name="l00588"></a>00588   <a class="code" href="group__DBusString.html#gf97b18e419678dbf967d9b9ad1112ca6">_dbus_string_copy_to_buffer</a> (&amp;decoded, uuid-&gt;<a class="code" href="unionDBusGUID.html#f45818fb0ae65fdece11aba936af7f09">as_bytes</a>, DBUS_UUID_LENGTH_BYTES);
<a name="l00589"></a>00589 
<a name="l00590"></a>00590   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;decoded);
<a name="l00591"></a>00591   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;contents);
<a name="l00592"></a>00592 
<a name="l00593"></a>00593   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00594"></a>00594 
<a name="l00595"></a>00595   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00596"></a>00596   
<a name="l00597"></a>00597  error:
<a name="l00598"></a>00598   _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00599"></a>00599   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;contents);
<a name="l00600"></a>00600   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;decoded);
<a name="l00601"></a>00601   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00602"></a>00602 }
<a name="l00603"></a>00603 
<a name="l00604"></a>00604 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00605"></a>00605 _dbus_create_uuid_file_exclusively (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00606"></a>00606                                     <a class="code" href="unionDBusGUID.html">DBusGUID</a>         *uuid,
<a name="l00607"></a>00607                                     <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00608"></a>00608 {
<a name="l00609"></a>00609   <a class="code" href="structDBusString.html">DBusString</a> encoded;
<a name="l00610"></a>00610 
<a name="l00611"></a>00611   <a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&amp;encoded);
<a name="l00612"></a>00612 
<a name="l00613"></a>00613   <a class="code" href="group__DBusInternalsUtils.html#g08c2922335845e5c857e88399436b9ba">_dbus_generate_uuid</a> (uuid);
<a name="l00614"></a>00614   
<a name="l00615"></a>00615   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gf08364813376bd2d8f455d435d85323e">_dbus_uuid_encode</a> (uuid, &amp;encoded))
<a name="l00616"></a>00616     {
<a name="l00617"></a>00617       _DBUS_SET_OOM (error);
<a name="l00618"></a>00618       <span class="keywordflow">goto</span> error;
<a name="l00619"></a>00619     }
<a name="l00620"></a>00620   
<a name="l00621"></a>00621   <span class="comment">/* FIXME this is racy; we need a save_file_exclusively</span>
<a name="l00622"></a>00622 <span class="comment">   * function. But in practice this should be fine for now.</span>
<a name="l00623"></a>00623 <span class="comment">   *</span>
<a name="l00624"></a>00624 <span class="comment">   * - first be sure we can create the file and it</span>
<a name="l00625"></a>00625 <span class="comment">   *   doesn't exist by creating it empty with O_EXCL</span>
<a name="l00626"></a>00626 <span class="comment">   * - then create it by creating a temporary file and</span>
<a name="l00627"></a>00627 <span class="comment">   *   overwriting atomically with rename()</span>
<a name="l00628"></a>00628 <span class="comment">   */</span>
<a name="l00629"></a>00629   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#g22665c6d5899c913e03930f90d144f46">_dbus_create_file_exclusively</a> (filename, error))
<a name="l00630"></a>00630     <span class="keywordflow">goto</span> error;
<a name="l00631"></a>00631 
<a name="l00632"></a>00632   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga6ecf36e70263659f921a4ef0335db12">_dbus_string_append_byte</a> (&amp;encoded, <span class="charliteral">'\n'</span>))
<a name="l00633"></a>00633     {
<a name="l00634"></a>00634       _DBUS_SET_OOM (error);
<a name="l00635"></a>00635       <span class="keywordflow">goto</span> error;
<a name="l00636"></a>00636     }
<a name="l00637"></a>00637   
<a name="l00638"></a>00638   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#gb974e23b29afbbae447129c273173502">_dbus_string_save_to_file</a> (&amp;encoded, filename, error))
<a name="l00639"></a>00639     <span class="keywordflow">goto</span> error;
<a name="l00640"></a>00640 
<a name="l00641"></a>00641   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#g7c83e2e20811330d1d1b2f6249dbe66c">_dbus_make_file_world_readable</a> (filename, error))
<a name="l00642"></a>00642     <span class="keywordflow">goto</span> error;
<a name="l00643"></a>00643 
<a name="l00644"></a>00644   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;encoded);
<a name="l00645"></a>00645 
<a name="l00646"></a>00646   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00647"></a>00647   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00648"></a>00648   
<a name="l00649"></a>00649  error:
<a name="l00650"></a>00650   _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00651"></a>00651   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;encoded);
<a name="l00652"></a>00652   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;        
<a name="l00653"></a>00653 }
<a name="l00654"></a>00654 
<a name="l00665"></a>00665 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00666"></a><a class="code" href="group__DBusInternalsUtils.html#g709fd30e6b940a5952af38efaf24ad51">00666</a> <a class="code" href="group__DBusInternalsUtils.html#g709fd30e6b940a5952af38efaf24ad51">_dbus_read_uuid_file</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00667"></a>00667                       <a class="code" href="unionDBusGUID.html">DBusGUID</a>         *uuid,
<a name="l00668"></a>00668                       <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>       create_if_not_found,
<a name="l00669"></a>00669                       <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00670"></a>00670 {
<a name="l00671"></a>00671   <a class="code" href="structDBusError.html">DBusError</a> read_error;
<a name="l00672"></a>00672 
<a name="l00673"></a>00673   <a class="code" href="group__DBusErrors.html#g8ce28eae754237703296599967d7ab77">dbus_error_init</a> (&amp;read_error);
<a name="l00674"></a>00674 
<a name="l00675"></a>00675   <span class="keywordflow">if</span> (_dbus_read_uuid_file_without_creating (filename, uuid, &amp;read_error))
<a name="l00676"></a>00676     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00677"></a>00677 
<a name="l00678"></a>00678   <span class="keywordflow">if</span> (!create_if_not_found)
<a name="l00679"></a>00679     {
<a name="l00680"></a>00680       <a class="code" href="group__DBusErrors.html#g9857517c813b19ef87b12f00558cecda">dbus_move_error</a> (&amp;read_error, error);
<a name="l00681"></a>00681       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00682"></a>00682     }
<a name="l00683"></a>00683 
<a name="l00684"></a>00684   <span class="comment">/* If the file exists and contains junk, we want to keep that error</span>
<a name="l00685"></a>00685 <span class="comment">   * message instead of overwriting it with a "file exists" error</span>
<a name="l00686"></a>00686 <span class="comment">   * message when we try to write</span>
<a name="l00687"></a>00687 <span class="comment">   */</span>
<a name="l00688"></a>00688   <span class="keywordflow">if</span> (<a class="code" href="group__DBusErrors.html#gd4a073fdbcfe5170ebb984fb79c7a94f">dbus_error_has_name</a> (&amp;read_error, <a class="code" href="group__DBusProtocol.html#g6a4e92aa48ed4486eaf48c40c72490c4">DBUS_ERROR_INVALID_FILE_CONTENT</a>))
<a name="l00689"></a>00689     {
<a name="l00690"></a>00690       <a class="code" href="group__DBusErrors.html#g9857517c813b19ef87b12f00558cecda">dbus_move_error</a> (&amp;read_error, error);
<a name="l00691"></a>00691       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00692"></a>00692     }
<a name="l00693"></a>00693   <span class="keywordflow">else</span>
<a name="l00694"></a>00694     {
<a name="l00695"></a>00695       <a class="code" href="group__DBusErrors.html#gd192d53cf930b1b12e1ce91bc0963709">dbus_error_free</a> (&amp;read_error);
<a name="l00696"></a>00696       <span class="keywordflow">return</span> _dbus_create_uuid_file_exclusively (filename, uuid, error);
<a name="l00697"></a>00697     }
<a name="l00698"></a>00698 }
<a name="l00699"></a>00699 
<a name="l00700"></a>00700 <a class="code" href="group__DBusInternalsUtils.html#gc8d22e9846ecc2845959082076de899b">_DBUS_DEFINE_GLOBAL_LOCK</a> (machine_uuid);
<a name="l00701"></a>00701 <span class="keyword">static</span> <span class="keywordtype">int</span> machine_uuid_initialized_generation = 0;
<a name="l00702"></a>00702 <span class="keyword">static</span> <a class="code" href="unionDBusGUID.html">DBusGUID</a> machine_uuid;
<a name="l00703"></a>00703 
<a name="l00714"></a>00714 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00715"></a><a class="code" href="group__DBusInternalsUtils.html#g49ba67405d677af6cde9329ed87ea91f">00715</a> <a class="code" href="group__DBusInternalsUtils.html#g49ba67405d677af6cde9329ed87ea91f">_dbus_get_local_machine_uuid_encoded</a> (<a class="code" href="structDBusString.html">DBusString</a> *uuid_str)
<a name="l00716"></a>00716 {
<a name="l00717"></a>00717   <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> ok;
<a name="l00718"></a>00718   
<a name="l00719"></a>00719   <a class="code" href="group__DBusInternalsUtils.html#g3b56fdb9df58277ee69d9f56a73bf383">_DBUS_LOCK</a> (machine_uuid);
<a name="l00720"></a>00720   <span class="keywordflow">if</span> (machine_uuid_initialized_generation != <a class="code" href="group__DBusMemoryInternals.html#g7c224d82013e2bdc181c1d85dcb6f295">_dbus_current_generation</a>)
<a name="l00721"></a>00721     {
<a name="l00722"></a>00722       <a class="code" href="structDBusError.html">DBusError</a> error;
<a name="l00723"></a>00723       <a class="code" href="group__DBusErrors.html#g8ce28eae754237703296599967d7ab77">dbus_error_init</a> (&amp;error);
<a name="l00724"></a>00724       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#g3f073afc8ef8397471531baf513e1bb5">_dbus_read_local_machine_uuid</a> (&amp;machine_uuid, <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>,
<a name="l00725"></a>00725                                           &amp;error))
<a name="l00726"></a>00726         {          
<a name="l00727"></a>00727 <span class="preprocessor">#ifndef DBUS_BUILD_TESTS</span>
<a name="l00728"></a>00728 <span class="preprocessor"></span>          <span class="comment">/* For the test suite, we may not be installed so just continue silently</span>
<a name="l00729"></a>00729 <span class="comment">           * here. But in a production build, we want to be nice and loud about</span>
<a name="l00730"></a>00730 <span class="comment">           * this.</span>
<a name="l00731"></a>00731 <span class="comment">           */</span>
<a name="l00732"></a>00732           <a class="code" href="group__DBusInternalsUtils.html#g63f2f8a068454b781f214ba596e313b4">_dbus_warn_check_failed</a> (<span class="stringliteral">"D-Bus library appears to be incorrectly set up; failed to read machine uuid: %s\n"</span>
<a name="l00733"></a>00733                                    <span class="stringliteral">"See the manual page for dbus-uuidgen to correct this issue.\n"</span>,
<a name="l00734"></a>00734                                    error.<a class="code" href="structDBusError.html#fb559175326de5b6b340e26204e92d72">message</a>);
<a name="l00735"></a>00735 <span class="preprocessor">#endif</span>
<a name="l00736"></a>00736 <span class="preprocessor"></span>          
<a name="l00737"></a>00737           <a class="code" href="group__DBusErrors.html#gd192d53cf930b1b12e1ce91bc0963709">dbus_error_free</a> (&amp;error);
<a name="l00738"></a>00738           
<a name="l00739"></a>00739           <a class="code" href="group__DBusInternalsUtils.html#g08c2922335845e5c857e88399436b9ba">_dbus_generate_uuid</a> (&amp;machine_uuid);
<a name="l00740"></a>00740         }
<a name="l00741"></a>00741     }
<a name="l00742"></a>00742 
<a name="l00743"></a>00743   ok = <a class="code" href="group__DBusInternalsUtils.html#gf08364813376bd2d8f455d435d85323e">_dbus_uuid_encode</a> (&amp;machine_uuid, uuid_str);
<a name="l00744"></a>00744 
<a name="l00745"></a>00745   <a class="code" href="group__DBusInternalsUtils.html#g1b7db80a2ea11235768ec8aa698df0a5">_DBUS_UNLOCK</a> (machine_uuid);
<a name="l00746"></a>00746 
<a name="l00747"></a>00747   <span class="keywordflow">return</span> ok;
<a name="l00748"></a>00748 }
<a name="l00749"></a>00749 
<a name="l00750"></a>00750 <span class="preprocessor">#ifdef DBUS_BUILD_TESTS</span>
<a name="l00751"></a>00751 <span class="preprocessor"></span>
<a name="l00757"></a>00757 <span class="keyword">const</span> <span class="keywordtype">char</span> *
<a name="l00758"></a>00758 _dbus_header_field_to_string (<span class="keywordtype">int</span> header_field)
<a name="l00759"></a>00759 {
<a name="l00760"></a>00760   <span class="keywordflow">switch</span> (header_field)
<a name="l00761"></a>00761     {
<a name="l00762"></a>00762     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g075b0efc570129393d3fb653ce4bbd76">DBUS_HEADER_FIELD_INVALID</a>:
<a name="l00763"></a>00763       <span class="keywordflow">return</span> <span class="stringliteral">"invalid"</span>;
<a name="l00764"></a>00764     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g0cd885e6e808b28ff082a7f8a2c9f579">DBUS_HEADER_FIELD_PATH</a>:
<a name="l00765"></a>00765       <span class="keywordflow">return</span> <span class="stringliteral">"path"</span>;
<a name="l00766"></a>00766     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g296b5f099b6c347f65d53ef0a6fa2b0d">DBUS_HEADER_FIELD_INTERFACE</a>:
<a name="l00767"></a>00767       <span class="keywordflow">return</span> <span class="stringliteral">"interface"</span>;
<a name="l00768"></a>00768     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g2aa9d65ef983ac9c08c1d4cb31366818">DBUS_HEADER_FIELD_MEMBER</a>:
<a name="l00769"></a>00769       <span class="keywordflow">return</span> <span class="stringliteral">"member"</span>;
<a name="l00770"></a>00770     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#gc551be0f921390d01104cce30a814a5e">DBUS_HEADER_FIELD_ERROR_NAME</a>:
<a name="l00771"></a>00771       <span class="keywordflow">return</span> <span class="stringliteral">"error-name"</span>;
<a name="l00772"></a>00772     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g1067e28a7151a161e5fd601a3b017584">DBUS_HEADER_FIELD_REPLY_SERIAL</a>:
<a name="l00773"></a>00773       <span class="keywordflow">return</span> <span class="stringliteral">"reply-serial"</span>;
<a name="l00774"></a>00774     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#gde98f71a08a1e0198d095fdb6d46cab9">DBUS_HEADER_FIELD_DESTINATION</a>:
<a name="l00775"></a>00775       <span class="keywordflow">return</span> <span class="stringliteral">"destination"</span>;
<a name="l00776"></a>00776     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g3ba84ae623951832bd73e2796bb13e71">DBUS_HEADER_FIELD_SENDER</a>:
<a name="l00777"></a>00777       <span class="keywordflow">return</span> <span class="stringliteral">"sender"</span>;
<a name="l00778"></a>00778     <span class="keywordflow">case</span> <a class="code" href="group__DBusProtocol.html#g450d63fa110d3cb891082e23291580b4">DBUS_HEADER_FIELD_SIGNATURE</a>:
<a name="l00779"></a>00779       <span class="keywordflow">return</span> <span class="stringliteral">"signature"</span>;
<a name="l00780"></a>00780     <span class="keywordflow">default</span>:
<a name="l00781"></a>00781       <span class="keywordflow">return</span> <span class="stringliteral">"unknown"</span>;
<a name="l00782"></a>00782     }
<a name="l00783"></a>00783 }
<a name="l00784"></a>00784 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_BUILD_TESTS */</span>
<a name="l00785"></a>00785 
<a name="l00786"></a>00786 <span class="preprocessor">#ifndef DBUS_DISABLE_CHECKS</span>
<a name="l00787"></a>00787 <span class="preprocessor"></span>
<a name="l00788"></a><a class="code" href="group__DBusInternalsUtils.html#g7599f9e4a6b9551b28e68b51b66851d3">00788</a> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="group__DBusInternalsUtils.html#g7599f9e4a6b9551b28e68b51b66851d3">_dbus_return_if_fail_warning_format</a>[] =
<a name="l00789"></a>00789 <span class="stringliteral">"arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"</span>
<a name="l00790"></a>00790 <span class="stringliteral">"This is normally a bug in some application using the D-Bus library.\n"</span>;
<a name="l00791"></a>00791 <span class="preprocessor">#endif</span>
<a name="l00792"></a>00792 <span class="preprocessor"></span>
<a name="l00793"></a>00793 <span class="preprocessor">#ifndef DBUS_DISABLE_ASSERT</span>
<a name="l00794"></a>00794 <span class="preprocessor"></span>
<a name="l00806"></a>00806 <span class="keywordtype">void</span>
<a name="l00807"></a>00807 _dbus_real_assert (<a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>  condition,
<a name="l00808"></a>00808                    <span class="keyword">const</span> <span class="keywordtype">char</span>  *condition_text,
<a name="l00809"></a>00809                    <span class="keyword">const</span> <span class="keywordtype">char</span>  *file,
<a name="l00810"></a>00810                    <span class="keywordtype">int</span>          line,
<a name="l00811"></a>00811                    <span class="keyword">const</span> <span class="keywordtype">char</span>  *func)
<a name="l00812"></a>00812 {
<a name="l00813"></a>00813   <span class="keywordflow">if</span> (_DBUS_UNLIKELY (!condition))
<a name="l00814"></a>00814     {
<a name="l00815"></a>00815       <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="stringliteral">"%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n"</span>,
<a name="l00816"></a>00816                   <a class="code" href="group__DBusSysdeps.html#g1b30aa55e8758ed6e1b62e0f86866543">_dbus_pid_for_log</a> (), condition_text, file, line, func);
<a name="l00817"></a>00817       <a class="code" href="group__DBusSysdeps.html#g83c51771d3c4e612522bd5ad72e6ad7a">_dbus_abort</a> ();
<a name="l00818"></a>00818     }
<a name="l00819"></a>00819 }
<a name="l00820"></a>00820 
<a name="l00831"></a>00831 <span class="keywordtype">void</span>
<a name="l00832"></a>00832 _dbus_real_assert_not_reached (<span class="keyword">const</span> <span class="keywordtype">char</span> *explanation,
<a name="l00833"></a>00833                                <span class="keyword">const</span> <span class="keywordtype">char</span> *file,
<a name="l00834"></a>00834                                <span class="keywordtype">int</span>         line)
<a name="l00835"></a>00835 {
<a name="l00836"></a>00836   <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="stringliteral">"File \"%s\" line %d process %lu should not have been reached: %s\n"</span>,
<a name="l00837"></a>00837               file, line, <a class="code" href="group__DBusSysdeps.html#g1b30aa55e8758ed6e1b62e0f86866543">_dbus_pid_for_log</a> (), explanation);
<a name="l00838"></a>00838   <a class="code" href="group__DBusSysdeps.html#g83c51771d3c4e612522bd5ad72e6ad7a">_dbus_abort</a> ();
<a name="l00839"></a>00839 }
<a name="l00840"></a>00840 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_DISABLE_ASSERT */</span>
<a name="l00841"></a>00841   
<a name="l00842"></a>00842 <span class="preprocessor">#ifdef DBUS_BUILD_TESTS</span>
<a name="l00843"></a>00843 <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00844"></a>00844 run_failing_each_malloc (<span class="keywordtype">int</span>                    n_mallocs,
<a name="l00845"></a>00845                          <span class="keyword">const</span> <span class="keywordtype">char</span>            *description,
<a name="l00846"></a>00846                          DBusTestMemoryFunction func,
<a name="l00847"></a>00847                          <span class="keywordtype">void</span>                  *data)
<a name="l00848"></a>00848 {
<a name="l00849"></a>00849   n_mallocs += 10; <span class="comment">/* fudge factor to ensure reallocs etc. are covered */</span>
<a name="l00850"></a>00850   
<a name="l00851"></a>00851   <span class="keywordflow">while</span> (n_mallocs &gt;= 0)
<a name="l00852"></a>00852     {      
<a name="l00853"></a>00853       _dbus_set_fail_alloc_counter (n_mallocs);
<a name="l00854"></a>00854 
<a name="l00855"></a>00855       _dbus_verbose (<span class="stringliteral">"\n===\n%s: (will fail malloc %d with %d failures)\n===\n"</span>,
<a name="l00856"></a>00856                      description, n_mallocs,
<a name="l00857"></a>00857                      _dbus_get_fail_alloc_failures ());
<a name="l00858"></a>00858 
<a name="l00859"></a>00859       <span class="keywordflow">if</span> (!(* func) (data))
<a name="l00860"></a>00860         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00861"></a>00861       
<a name="l00862"></a>00862       n_mallocs -= 1;
<a name="l00863"></a>00863     }
<a name="l00864"></a>00864 
<a name="l00865"></a>00865   _dbus_set_fail_alloc_counter (<a class="code" href="group__DBusInternalsUtils.html#g5627db5e165848477e620846f6414db1">_DBUS_INT_MAX</a>);
<a name="l00866"></a>00866 
<a name="l00867"></a>00867   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00868"></a>00868 }                        
<a name="l00869"></a>00869 
<a name="l00883"></a>00883 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00884"></a>00884 _dbus_test_oom_handling (<span class="keyword">const</span> <span class="keywordtype">char</span>             *description,
<a name="l00885"></a>00885                          DBusTestMemoryFunction  func,
<a name="l00886"></a>00886                          <span class="keywordtype">void</span>                   *data)
<a name="l00887"></a>00887 {
<a name="l00888"></a>00888   <span class="keywordtype">int</span> approx_mallocs;
<a name="l00889"></a>00889   <span class="keyword">const</span> <span class="keywordtype">char</span> *setting;
<a name="l00890"></a>00890   <span class="keywordtype">int</span> max_failures_to_try;
<a name="l00891"></a>00891   <span class="keywordtype">int</span> i;
<a name="l00892"></a>00892 
<a name="l00893"></a>00893   <span class="comment">/* Run once to see about how many mallocs are involved */</span>
<a name="l00894"></a>00894   
<a name="l00895"></a>00895   _dbus_set_fail_alloc_counter (<a class="code" href="group__DBusInternalsUtils.html#g5627db5e165848477e620846f6414db1">_DBUS_INT_MAX</a>);
<a name="l00896"></a>00896 
<a name="l00897"></a>00897   _dbus_verbose (<span class="stringliteral">"Running once to count mallocs\n"</span>);
<a name="l00898"></a>00898   
<a name="l00899"></a>00899   <span class="keywordflow">if</span> (!(* func) (data))
<a name="l00900"></a>00900     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00901"></a>00901   
<a name="l00902"></a>00902   approx_mallocs = <a class="code" href="group__DBusInternalsUtils.html#g5627db5e165848477e620846f6414db1">_DBUS_INT_MAX</a> - _dbus_get_fail_alloc_counter ();
<a name="l00903"></a>00903 
<a name="l00904"></a>00904   _dbus_verbose (<span class="stringliteral">"\n=================\n%s: about %d mallocs total\n=================\n"</span>,
<a name="l00905"></a>00905                  description, approx_mallocs);
<a name="l00906"></a>00906 
<a name="l00907"></a>00907   setting = <a class="code" href="group__DBusSysdeps.html#gb846071a4de54cb7e518654f9375313a">_dbus_getenv</a> (<span class="stringliteral">"DBUS_TEST_MALLOC_FAILURES"</span>);
<a name="l00908"></a>00908   <span class="keywordflow">if</span> (setting != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00909"></a>00909     {
<a name="l00910"></a>00910       <a class="code" href="structDBusString.html">DBusString</a> str;
<a name="l00911"></a>00911       <span class="keywordtype">long</span> v;
<a name="l00912"></a>00912       <a class="code" href="group__DBusString.html#g374640ddfa2f0b27a8356e2379ba8043">_dbus_string_init_const</a> (&amp;str, setting);
<a name="l00913"></a>00913       v = 4;
<a name="l00914"></a>00914       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g93e22894a5e2e0d65c179c7d36a8b1c8">_dbus_string_parse_int</a> (&amp;str, 0, &amp;v, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>))
<a name="l00915"></a>00915         <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="stringliteral">"couldn't parse '%s' as integer\n"</span>, setting);
<a name="l00916"></a>00916       max_failures_to_try = v;
<a name="l00917"></a>00917     }
<a name="l00918"></a>00918   <span class="keywordflow">else</span>
<a name="l00919"></a>00919     {
<a name="l00920"></a>00920       max_failures_to_try = 4;
<a name="l00921"></a>00921     }
<a name="l00922"></a>00922 
<a name="l00923"></a>00923   i = setting ? max_failures_to_try - 1 : 1;
<a name="l00924"></a>00924   <span class="keywordflow">while</span> (i &lt; max_failures_to_try)
<a name="l00925"></a>00925     {
<a name="l00926"></a>00926       _dbus_set_fail_alloc_failures (i);
<a name="l00927"></a>00927       <span class="keywordflow">if</span> (!run_failing_each_malloc (approx_mallocs, description, func, data))
<a name="l00928"></a>00928         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00929"></a>00929       ++i;
<a name="l00930"></a>00930     }
<a name="l00931"></a>00931   
<a name="l00932"></a>00932   _dbus_verbose (<span class="stringliteral">"\n=================\n%s: all iterations passed\n=================\n"</span>,
<a name="l00933"></a>00933                  description);
<a name="l00934"></a>00934 
<a name="l00935"></a>00935   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00936"></a>00936 }
<a name="l00937"></a>00937 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_BUILD_TESTS */</span>
<a name="l00938"></a>00938 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Dec 14 22:26:11 2009 for D-Bus by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>

Anon7 - 2021