Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 6c21d55247420ace69cad1d05267fc34 > files > 305

pcsc-lite-doc-1.7.2-4.fc15.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>pcsc-lite: winscard_msg_srv.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">pcsc-lite&#160;<span id="projectnumber">1.7.2</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_7a4553ee0c3b13d0e595a5d1659110a6.html">src</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">winscard_msg_srv.c</div>  </div>
</div>
<div class="contents">
<a href="winscard__msg__srv_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * MUSCLE SmartCard Development ( http://www.linuxnet.com )</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2001-2004</span>
<a name="l00005"></a>00005 <span class="comment"> *  David Corcoran &lt;corcoran@linuxnet.com&gt;</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright (C) 2003-2004</span>
<a name="l00007"></a>00007 <span class="comment"> *  Damien Sauveron &lt;damien.sauveron@labri.fr&gt;</span>
<a name="l00008"></a>00008 <span class="comment"> * Copyright (C) 2002-2010</span>
<a name="l00009"></a>00009 <span class="comment"> *  Ludovic Rousseau &lt;ludovic.rousseau@free.fr&gt;</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $Id: winscard_msg_srv.c 5391 2010-11-08 14:53:02Z rousseau $</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;config.h&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#ifdef HAVE_SYS_FILIO_H</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/filio.h&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;misc.h&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="pcscd_8h.html" title="This keeps a list of defines for pcsc-lite.">pcscd.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="winscard_8h.html" title="This handles smartcard reader communications.">winscard.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="debuglog_8h.html" title="This handles debugging.">debuglog.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="winscard__msg_8h.html" title="This defines some structures and #defines to be used over the transport layer.">winscard_msg.h</a>&quot;</span>
<a name="l00045"></a>00045 
<a name="l00049"></a><a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c">00049</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> = 0;
<a name="l00050"></a>00050 <span class="keyword">extern</span> <span class="keywordtype">char</span> AraKiri;
<a name="l00051"></a>00051 
<a name="l00063"></a><a class="code" href="winscard__msg__srv_8c.html#a7c421010b7e933a8ed46927e5b9316e8">00063</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="winscard__msg__srv_8c.html#a7c421010b7e933a8ed46927e5b9316e8" title="Accepts a Client connection.">ProcessCommonChannelRequest</a>(<span class="comment">/*@out@*/</span> uint32_t *pdwClientID)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065     socklen_t clnt_len;
<a name="l00066"></a>00066     <span class="keywordtype">int</span> new_sock;
<a name="l00067"></a>00067     <span class="keyword">struct </span>sockaddr_un clnt_addr;
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     clnt_len = <span class="keyword">sizeof</span>(clnt_addr);
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     <span class="keywordflow">if</span> ((new_sock = accept(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, (<span class="keyword">struct</span> sockaddr *) &amp;clnt_addr,
<a name="l00072"></a>00072                 &amp;clnt_len)) &lt; 0)
<a name="l00073"></a>00073     {
<a name="l00074"></a>00074         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Accept on common socket: %s&quot;</span>,
<a name="l00075"></a>00075             strerror(errno));
<a name="l00076"></a>00076         <span class="keywordflow">return</span> -1;
<a name="l00077"></a>00077     }
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     *pdwClientID = new_sock;
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     <span class="keywordflow">return</span> 0;
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00098"></a><a class="code" href="winscard__msg__srv_8c.html#a061a490f5d2103751eb6b64573b5fb9d">00098</a> INTERNAL int32_t <a class="code" href="winscard__msg__srv_8c.html#a061a490f5d2103751eb6b64573b5fb9d" title="Prepares the communication channel used by the server to talk to the clients.">InitializeSocket</a>(<span class="keywordtype">void</span>)
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100     <span class="keyword">struct </span>sockaddr_un serv_adr;
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     <span class="comment">/*</span>
<a name="l00103"></a>00103 <span class="comment">     * Create the common shared connection socket</span>
<a name="l00104"></a>00104 <span class="comment">     */</span>
<a name="l00105"></a>00105     <span class="keywordflow">if</span> ((<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> = socket(PF_UNIX, SOCK_STREAM, 0)) &lt; 0)
<a name="l00106"></a>00106     {
<a name="l00107"></a>00107         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to create common socket: %s&quot;</span>,
<a name="l00108"></a>00108             strerror(errno));
<a name="l00109"></a>00109         <span class="keywordflow">return</span> -1;
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     serv_adr.sun_family = AF_UNIX;
<a name="l00113"></a>00113     strncpy(serv_adr.sun_path, PCSCLITE_CSOCK_NAME,
<a name="l00114"></a>00114         <span class="keyword">sizeof</span>(serv_adr.sun_path));
<a name="l00115"></a>00115     (void)<span class="keyword">remove</span>(PCSCLITE_CSOCK_NAME);
<a name="l00116"></a>00116 
<a name="l00117"></a>00117     <span class="keywordflow">if</span> (bind(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, (<span class="keyword">struct</span> sockaddr *) &amp;serv_adr,
<a name="l00118"></a>00118             <span class="keyword">sizeof</span>(serv_adr.sun_family) + strlen(serv_adr.sun_path) + 1) &lt; 0)
<a name="l00119"></a>00119     {
<a name="l00120"></a>00120         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to bind common socket: %s&quot;</span>,
<a name="l00121"></a>00121             strerror(errno));
<a name="l00122"></a>00122         <span class="keywordflow">return</span> -1;
<a name="l00123"></a>00123     }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125     <span class="keywordflow">if</span> (listen(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, 1) &lt; 0)
<a name="l00126"></a>00126     {
<a name="l00127"></a>00127         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Unable to listen common socket: %s&quot;</span>,
<a name="l00128"></a>00128             strerror(errno));
<a name="l00129"></a>00129         <span class="keywordflow">return</span> -1;
<a name="l00130"></a>00130     }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132     <span class="comment">/*</span>
<a name="l00133"></a>00133 <span class="comment">     * Chmod the public entry channel</span>
<a name="l00134"></a>00134 <span class="comment">     */</span>
<a name="l00135"></a>00135     (void)chmod(PCSCLITE_CSOCK_NAME, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
<a name="l00136"></a>00136 
<a name="l00137"></a>00137     <span class="keywordflow">return</span> 0;
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00153"></a>00153 <span class="preprocessor">#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)</span>
<a name="l00154"></a>00154 <span class="preprocessor"></span><span class="preprocessor">#define DO_TIMEOUT</span>
<a name="l00155"></a>00155 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00156"></a><a class="code" href="winscard__msg__srv_8c.html#a187cf841551d3e7b97e23d73067ec2d3">00156</a> <span class="preprocessor"></span>INTERNAL int32_t <a class="code" href="winscard__msg__srv_8c.html#a187cf841551d3e7b97e23d73067ec2d3" title="Looks for messages sent by clients.">ProcessEventsServer</a>(uint32_t *pdwClientID)
<a name="l00157"></a>00157 {
<a name="l00158"></a>00158     fd_set read_fd;
<a name="l00159"></a>00159     <span class="keywordtype">int</span> selret;
<a name="l00160"></a>00160 <span class="preprocessor">#ifdef DO_TIMEOUT</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span>    <span class="keyword">struct </span>timeval tv;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163     tv.tv_sec = 1;
<a name="l00164"></a>00164     tv.tv_usec = 0;
<a name="l00165"></a>00165 <span class="preprocessor">#endif</span>
<a name="l00166"></a>00166 <span class="preprocessor"></span>
<a name="l00167"></a>00167     FD_ZERO(&amp;read_fd);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169     <span class="comment">/*</span>
<a name="l00170"></a>00170 <span class="comment">     * Set up the bit masks for select</span>
<a name="l00171"></a>00171 <span class="comment">     */</span>
<a name="l00172"></a>00172     FD_SET(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, &amp;read_fd);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     selret = select(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a> + 1, &amp;read_fd, (fd_set *) NULL,
<a name="l00175"></a>00175         (fd_set *) NULL,
<a name="l00176"></a>00176 #ifdef DO_TIMEOUT
<a name="l00177"></a>00177         &amp;tv
<a name="l00178"></a>00178 #<span class="keywordflow">else</span>
<a name="l00179"></a>00179         NULL
<a name="l00180"></a>00180 #endif
<a name="l00181"></a>00181         );
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     <span class="keywordflow">if</span> (selret &lt; 0)
<a name="l00184"></a>00184     {
<a name="l00185"></a>00185         <span class="keywordflow">if</span> (EINTR == errno)
<a name="l00186"></a>00186             <span class="keywordflow">return</span> -2;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Select returns with failure: %s&quot;</span>,
<a name="l00189"></a>00189             strerror(errno));
<a name="l00190"></a>00190         <span class="keywordflow">return</span> -1;
<a name="l00191"></a>00191     }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193     <span class="keywordflow">if</span> (selret == 0)
<a name="l00194"></a>00194         <span class="comment">/* timeout. On *BSD only */</span>
<a name="l00195"></a>00195         <span class="keywordflow">return</span> 2;
<a name="l00196"></a>00196 
<a name="l00197"></a>00197     <span class="comment">/*</span>
<a name="l00198"></a>00198 <span class="comment">     * A common pipe packet has arrived - it could be a new application</span>
<a name="l00199"></a>00199 <span class="comment">     */</span>
<a name="l00200"></a>00200     <span class="keywordflow">if</span> (FD_ISSET(<a class="code" href="winscard__msg__srv_8c.html#a840eb2cc63fe5b38ec8edb835bc7c40c" title="Socket to a file, used for clients-server comminication.">commonSocket</a>, &amp;read_fd))
<a name="l00201"></a>00201     {
<a name="l00202"></a>00202         Log1(PCSC_LOG_DEBUG, <span class="stringliteral">&quot;Common channel packet arrival&quot;</span>);
<a name="l00203"></a>00203         <span class="keywordflow">if</span> (<a class="code" href="winscard__msg__srv_8c.html#a7c421010b7e933a8ed46927e5b9316e8" title="Accepts a Client connection.">ProcessCommonChannelRequest</a>(pdwClientID) == -1)
<a name="l00204"></a>00204         {
<a name="l00205"></a>00205             Log2(PCSC_LOG_ERROR,
<a name="l00206"></a>00206                 <span class="stringliteral">&quot;error in ProcessCommonChannelRequest: %d&quot;</span>, *pdwClientID);
<a name="l00207"></a>00207             <span class="keywordflow">return</span> -1;
<a name="l00208"></a>00208         }
<a name="l00209"></a>00209     }
<a name="l00210"></a>00210     <span class="keywordflow">else</span>
<a name="l00211"></a>00211         <span class="keywordflow">return</span> -1;
<a name="l00212"></a>00212 
<a name="l00213"></a>00213     Log2(PCSC_LOG_DEBUG,
<a name="l00214"></a>00214         <span class="stringliteral">&quot;ProcessCommonChannelRequest detects: %d&quot;</span>, *pdwClientID);
<a name="l00215"></a>00215 
<a name="l00216"></a>00216     <span class="keywordflow">return</span> 0;
<a name="l00217"></a>00217 }
<a name="l00218"></a>00218 
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Thu Sep 15 2011 for pcsc-lite by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>