17:39
[skypekit:skypekit.git] / skypekit_2.0.0.190_29281_CB30 / interfaces / skype / cpp_embedded / documentation / html / skype-pipe-transport_8cpp_source.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5 <title>SkypeKit C++ Wrapper: Main Page</title>
6 <link href="tabs.css" rel="stylesheet" type="text/css"/>
7 <link href="islander.css" rel="stylesheet" type="text/css"/>
8 </head>
9 <body>
10 <img src="..\skypekit.png" align="right">
11 <!-- Generated by Doxygen 1.6.2 -->
12 <script type="text/javascript">
13 <!--
14 function changeDisplayState (e){
15   var num=this.id.replace(/[^[0-9]/g,'');
16   var button=this.firstChild;
17   var sectionDiv=document.getElementById('dynsection'+num);
18   if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
19     sectionDiv.style.display='block';
20     button.src='open.gif';
21   }else{
22     sectionDiv.style.display='none';
23     button.src='closed.gif';
24   }
25 }
26 function initDynSections(){
27   var divs=document.getElementsByTagName('div');
28   var sectionCounter=1;
29   for(var i=0;i<divs.length-1;i++){
30     if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
31       var header=divs[i];
32       var section=divs[i+1];
33       var button=header.firstChild;
34       if (button!='IMG'){
35         divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
36         button=document.createElement('img');
37         divs[i].insertBefore(button,divs[i].firstChild);
38       }
39       header.style.cursor='pointer';
40       header.onclick=changeDisplayState;
41       header.id='dynheader'+sectionCounter;
42       button.src='closed.gif';
43       section.id='dynsection'+sectionCounter;
44       section.style.display='none';
45       section.style.marginLeft='14px';
46       sectionCounter++;
47     }
48   }
49 }
50 window.onload = initDynSections;
51 -->
52 </script>
53 <div class="navigation" id="top">
54   <div class="tabs">
55     <ul>
56       <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
57       <li><a href="annotated.html"><span>Classes</span></a></li>
58       <li class="current"><a href="files.html"><span>Files</span></a></li>
59       <li><a href="examples.html"><span>Examples</span></a></li>
60     </ul>
61   </div>
62   <div class="tabs">
63     <ul>
64       <li><a href="files.html"><span>File&nbsp;List</span></a></li>
65       <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
66     </ul>
67   </div>
68 <h1>skype-pipe-transport.cpp</h1><a href="skype-pipe-transport_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
69 <a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="skype-pipe-transport_8h.html">skype-pipe-transport.h</a>&quot;</span>
70 <a name="l00003"></a>00003 
71 <a name="l00004"></a>00004 <span class="preprocessor">#ifndef SE_NO_WINDOWS_PIPE_TRANSPORT</span>
72 <a name="l00005"></a>00005 <span class="preprocessor"></span>
73 <a name="l00006"></a>00006 <span class="preprocessor">#include &lt;windows.h&gt;</span>
74 <a name="l00007"></a>00007 
75 <a name="l00008"></a>00008 <span class="preprocessor">#ifdef SE_SKYPE_TEST</span>
76 <a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#include &lt;skype-test.h&gt;</span>
77 <a name="l00010"></a>00010 <span class="preprocessor">#endif</span>
78 <a name="l00011"></a>00011 <span class="preprocessor"></span>
79 <a name="l00012"></a><a class="code" href="skype-pipe-transport_8cpp.html#ae010c0e8c152308980d11026cc219b7a">00012</a> <span class="preprocessor">#define LOG(t)  if (log) log(t)</span>
80 <a name="l00013"></a>00013 <span class="preprocessor"></span>
81 <a name="l00014"></a><a class="code" href="skype-pipe-transport_8h.html#adf79ec0ed1094d4fb1db33ec3d8d4a1c">00014</a> HANDLE <a class="code" href="skype-pipe-transport_8cpp.html#a8baf4340e923dfdb884dca2982923536">g_hReadPipeParent</a> = INVALID_HANDLE_VALUE, <a class="code" href="skype-pipe-transport_8cpp.html#adf79ec0ed1094d4fb1db33ec3d8d4a1c">g_hWritePipeParent</a> = INVALID_HANDLE_VALUE;
82 <a name="l00015"></a>00015 
83 <a name="l00016"></a><a class="code" href="class_s_e_pipe_transport.html#a998fed5b118ce675442da2d099893065">00016</a> <a class="code" href="class_s_e_pipe_transport.html#a998fed5b118ce675442da2d099893065">SEPipeTransport::SEPipeTransport</a>(HANDLE hReadPipe, HANDLE hWritePipe) : <a class="code" href="class_s_e_transport.html" title="Abstract interface for transport layer.">SETransport</a>(),
84 <a name="l00017"></a>00017                 connected(false),
85 <a name="l00018"></a>00018                 hReadPipeParent(hReadPipe),
86 <a name="l00019"></a>00019                 hWritePipeParent(hWritePipe)
87 <a name="l00020"></a>00020 {
88 <a name="l00021"></a>00021 }
89 <a name="l00022"></a>00022 
90 <a name="l00023"></a><a class="code" href="class_s_e_pipe_transport.html#afa8e8c7d6e23112babe3fff2dc7f05d5">00023</a> <a class="code" href="class_s_e_pipe_transport.html#afa8e8c7d6e23112babe3fff2dc7f05d5">SEPipeTransport::~SEPipeTransport</a>()
91 <a name="l00024"></a>00024 {
92 <a name="l00025"></a>00025         cleanup();
93 <a name="l00026"></a>00026 }
94 <a name="l00027"></a>00027 
95 <a name="l00028"></a>00028 <span class="keywordtype">void</span> SEPipeTransport::cleanup()
96 <a name="l00029"></a>00029 {
97 <a name="l00030"></a>00030         <span class="keywordflow">if</span> (hReadPipeParent != INVALID_HANDLE_VALUE) {
98 <a name="l00031"></a>00031                 ::CloseHandle(hReadPipeParent);
99 <a name="l00032"></a>00032                 hReadPipeParent = INVALID_HANDLE_VALUE;
100 <a name="l00033"></a>00033         }
101 <a name="l00034"></a>00034 
102 <a name="l00035"></a>00035         <span class="keywordflow">if</span> (hWritePipeParent != INVALID_HANDLE_VALUE) {
103 <a name="l00036"></a>00036                 ::CloseHandle(hWritePipeParent);
104 <a name="l00037"></a>00037                 hWritePipeParent = INVALID_HANDLE_VALUE;
105 <a name="l00038"></a>00038         }
106 <a name="l00039"></a>00039 }
107 <a name="l00040"></a>00040 
108 <a name="l00041"></a><a class="code" href="class_s_e_pipe_transport.html#a3fa08c05b6749187828c2148745211cb">00041</a> <span class="keywordtype">bool</span> <a class="code" href="class_s_e_pipe_transport.html#a3fa08c05b6749187828c2148745211cb">SEPipeTransport::connect</a>()
109 <a name="l00042"></a>00042 {
110 <a name="l00043"></a>00043         <span class="comment">// read out skypekit logo etc</span>
111 <a name="l00044"></a>00044         BYTE buffer[256];
112 <a name="l00045"></a>00045         DWORD to_read = <span class="keyword">sizeof</span>(buffer), <a class="code" href="class_s_e_transport.html#a6ac0733481dec47755d90d1f410c16d5">read</a> = 0, bytes_avail;
113 <a name="l00046"></a>00046 
114 <a name="l00047"></a>00047         <span class="keywordflow">do</span> {
115 <a name="l00048"></a>00048                 bytes_avail = 0;
116 <a name="l00049"></a>00049                 <span class="comment">// peek</span>
117 <a name="l00050"></a>00050                 <span class="keywordflow">if</span> (!::PeekNamedPipe(hReadPipeParent, NULL, 0, NULL, &amp;bytes_avail, NULL))
118 <a name="l00051"></a>00051                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
119 <a name="l00052"></a>00052 
120 <a name="l00053"></a>00053                 <span class="comment">// nothing left ?</span>
121 <a name="l00054"></a>00054                 <span class="keywordflow">if</span> (!bytes_avail)
122 <a name="l00055"></a>00055                         <span class="keywordflow">break</span>;
123 <a name="l00056"></a>00056 
124 <a name="l00057"></a>00057                 <span class="comment">// remove</span>
125 <a name="l00058"></a>00058                 <span class="keywordflow">if</span> (!::ReadFile(hReadPipeParent, buffer, to_read, &amp;<a class="code" href="class_s_e_transport.html#a6ac0733481dec47755d90d1f410c16d5">read</a>, NULL)) {
126 <a name="l00059"></a>00059                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
127 <a name="l00060"></a>00060                 }
128 <a name="l00061"></a>00061         } <span class="keywordflow">while</span> (911);
129 <a name="l00062"></a>00062 
130 <a name="l00063"></a>00063         connected = <span class="keyword">true</span>;
131 <a name="l00064"></a>00064 
132 <a name="l00065"></a>00065         <span class="keywordflow">return</span> <span class="keyword">true</span>;
133 <a name="l00066"></a>00066 }
134 <a name="l00067"></a>00067 
135 <a name="l00068"></a><a class="code" href="class_s_e_pipe_transport.html#ad1db9fcdda1ff05351a5340838f303fb">00068</a> <span class="keywordtype">void</span> <a class="code" href="class_s_e_pipe_transport.html#ad1db9fcdda1ff05351a5340838f303fb" title="Disconnects from skypekit.">SEPipeTransport::disconnect</a>()
136 <a name="l00069"></a>00069 {
137 <a name="l00070"></a>00070         <span class="comment">// invalidate both pipe sides,</span>
138 <a name="l00071"></a>00071         <span class="comment">// other side if in blocking ReadFile, ends with error code ERROR_BROKEN_PIPE</span>
139 <a name="l00072"></a>00072         cleanup();
140 <a name="l00073"></a>00073 
141 <a name="l00074"></a>00074         connected = <span class="keyword">false</span>;
142 <a name="l00075"></a>00075 }
143 <a name="l00076"></a>00076 
144 <a name="l00077"></a><a class="code" href="class_s_e_pipe_transport.html#a74303df2ee89f373edf9a14320a258d3">00077</a> <span class="keywordtype">void</span> <a class="code" href="class_s_e_pipe_transport.html#a74303df2ee89f373edf9a14320a258d3">SEPipeTransport::push</a>(<span class="keyword">const</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>&amp; message)
145 <a name="l00078"></a>00078 {
146 <a name="l00079"></a>00079         <span class="keywordflow">if</span> (!connected) {
147 <a name="l00080"></a>00080                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;SKYPE ERROR - SEPipeTransport::push(), not connected&quot;</span>);
148 <a name="l00081"></a>00081                 <span class="keywordflow">return</span>;
149 <a name="l00082"></a>00082         }
150 <a name="l00083"></a>00083 
151 <a name="l00084"></a>00084         <span class="comment">// message is copied because STTester modifies the buffer and needs a non-const</span>
152 <a name="l00085"></a>00085         <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a> msg = message;
153 <a name="l00086"></a>00086         STTester_ON_OUTGOING_EVENT(msg);
154 <a name="l00087"></a>00087 
155 <a name="l00088"></a>00088         <span class="keywordtype">size_t</span> msg_len = msg.<a class="code" href="class_s_e_string.html#a87a356c4ae857391795bd5d49aa6c903">length</a>();
156 <a name="l00089"></a>00089 
157 <a name="l00090"></a>00090         <span class="keywordtype">int</span> len = msg_len;
158 <a name="l00091"></a>00091 
159 <a name="l00092"></a>00092 <span class="preprocessor">#ifndef SE_NO_TRANSPORT_CRYPTO</span>
160 <a name="l00093"></a>00093 <span class="preprocessor"></span>        rc4_send.ProcessString((uchar*)&amp;len, <span class="keyword">sizeof</span>(len));
161 <a name="l00094"></a>00094 <span class="preprocessor">#endif</span>
162 <a name="l00095"></a>00095 <span class="preprocessor"></span>
163 <a name="l00096"></a>00096         DWORD written = 0;
164 <a name="l00097"></a>00097         BOOL no_error = ::WriteFile(hWritePipeParent, (LPCVOID)&amp;len, <span class="keyword">sizeof</span>(len), &amp;written, NULL);
165 <a name="l00098"></a>00098         <span class="keywordflow">if</span> (!no_error || written != <span class="keyword">sizeof</span>(len)) {
166 <a name="l00099"></a>00099                 connected = <span class="keyword">false</span>;
167 <a name="l00100"></a>00100                 <span class="keywordflow">return</span>;
168 <a name="l00101"></a>00101         }
169 <a name="l00102"></a>00102 
170 <a name="l00103"></a>00103 <span class="preprocessor">#ifndef SE_NO_TRANSPORT_CRYPTO</span>
171 <a name="l00104"></a>00104 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (<a class="code" href="class_s_e_transport.html#a5e680ec4f492e3db6b5e27da9851ec1f">debug</a>) {
172 <a name="l00105"></a>00105                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;TRANSPORT: Writing message \&quot;&quot;</span> + msg + <span class="stringliteral">&quot;\&quot;&quot;</span>);
173 <a name="l00106"></a>00106         }
174 <a name="l00107"></a>00107         rc4_send.ProcessString((uchar*)(<span class="keyword">const</span> <span class="keywordtype">char</span>*)msg, msg_len);
175 <a name="l00108"></a>00108 <span class="preprocessor">#endif</span>
176 <a name="l00109"></a>00109 <span class="preprocessor"></span>
177 <a name="l00110"></a>00110         written = 0;
178 <a name="l00111"></a>00111         no_error = ::WriteFile(hWritePipeParent, (LPCVOID)(<span class="keyword">const</span> <span class="keywordtype">char</span>*)msg, msg_len, &amp;written, NULL);
179 <a name="l00112"></a>00112         <span class="keywordflow">if</span> (!no_error || written != msg_len) {
180 <a name="l00113"></a>00113                 connected = <span class="keyword">false</span>;
181 <a name="l00114"></a>00114                 <span class="keywordflow">return</span>;
182 <a name="l00115"></a>00115         }
183 <a name="l00116"></a>00116 
184 <a name="l00117"></a>00117 <span class="preprocessor">#ifdef SE_NO_TRANSPORT_CRYPTO</span>
185 <a name="l00118"></a>00118 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (<a class="code" href="class_s_e_transport.html#a5e680ec4f492e3db6b5e27da9851ec1f">debug</a>) {
186 <a name="l00119"></a>00119                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;TRANSPORT: Wrote message \&quot;&quot;</span> + msg + <span class="stringliteral">&quot;\&quot;&quot;</span>);
187 <a name="l00120"></a>00120         }
188 <a name="l00121"></a>00121 <span class="preprocessor">#endif</span>
189 <a name="l00122"></a>00122 <span class="preprocessor"></span>}
190 <a name="l00123"></a>00123 
191 <a name="l00124"></a><a class="code" href="class_s_e_pipe_transport.html#a3b04fa797b00d3289ec6621c8ca5266d">00124</a> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a> <a class="code" href="class_s_e_pipe_transport.html#a3b04fa797b00d3289ec6621c8ca5266d">SEPipeTransport::pull</a>(<span class="keywordtype">bool</span> block)
192 <a name="l00125"></a>00125 {
193 <a name="l00126"></a>00126         <span class="keywordflow">if</span> (!connected) {
194 <a name="l00127"></a>00127                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;SKYPE ERROR - SEPipeTransport::pull(), not connected&quot;</span>);
195 <a name="l00128"></a>00128                 <span class="keywordflow">return</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>();
196 <a name="l00129"></a>00129         }
197 <a name="l00130"></a>00130 
198 <a name="l00131"></a>00131         <span class="keywordflow">if</span> ((!block) &amp;&amp; !<a class="code" href="class_s_e_pipe_transport.html#a57d2be9c46dec2ecb739d428cad75a60">hasMore</a>())
199 <a name="l00132"></a>00132                 <span class="keywordflow">return</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>();
200 <a name="l00133"></a>00133 
201 <a name="l00134"></a>00134         STTester_PROCESS_BUFFER();
202 <a name="l00135"></a>00135 
203 <a name="l00136"></a>00136         <span class="keywordtype">int</span> len = 0;
204 <a name="l00137"></a>00137 
205 <a name="l00138"></a>00138         DWORD bytes_read = 0;
206 <a name="l00139"></a>00139         BOOL no_error = ::ReadFile(hReadPipeParent, &amp;len, <span class="keyword">sizeof</span>(len), &amp;bytes_read, NULL);
207 <a name="l00140"></a>00140         <span class="keywordflow">if</span> (!no_error || bytes_read != <span class="keyword">sizeof</span>(len)) {
208 <a name="l00141"></a>00141                 connected = <span class="keyword">false</span>;
209 <a name="l00142"></a>00142                 <span class="keywordflow">return</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>();
210 <a name="l00143"></a>00143         }
211 <a name="l00144"></a>00144 
212 <a name="l00145"></a>00145 <span class="preprocessor">#ifndef SE_NO_TRANSPORT_CRYPTO</span>
213 <a name="l00146"></a>00146 <span class="preprocessor"></span>        rc4_recv.ProcessString((uchar*)&amp;len, <span class="keyword">sizeof</span>(len));
214 <a name="l00147"></a>00147 <span class="preprocessor">#endif</span>
215 <a name="l00148"></a>00148 <span class="preprocessor"></span>
216 <a name="l00149"></a>00149         <span class="comment">// sanity check if some data get lost in the socket connection for some buggy platforms</span>
217 <a name="l00150"></a>00150         <span class="keywordflow">if</span> (len &gt; 0x00FFFFFF) {
218 <a name="l00151"></a>00151                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;SKYPE ERROR - SEPipeTransport::pull(), len &gt; 0x00FFFFFF, most likely garbage&quot;</span>);
219 <a name="l00152"></a>00152                 connected = <span class="keyword">false</span>; <span class="comment">// better disconnect with skypekit if things have gone that wrong</span>
220 <a name="l00153"></a>00153                 <span class="keywordflow">return</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>();
221 <a name="l00154"></a>00154         }
222 <a name="l00155"></a>00155 
223 <a name="l00156"></a>00156         <span class="keywordtype">char</span> *msg = <span class="keyword">new</span> <span class="keywordtype">char</span>[len + 1];
224 <a name="l00157"></a>00157 
225 <a name="l00158"></a>00158         no_error = ::ReadFile(hReadPipeParent, msg, len, &amp;bytes_read, NULL);
226 <a name="l00159"></a>00159         <span class="keywordflow">if</span> (!no_error || bytes_read != len) {
227 <a name="l00160"></a>00160                 connected = <span class="keyword">false</span>;
228 <a name="l00161"></a>00161                 <span class="keywordflow">return</span> <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>();
229 <a name="l00162"></a>00162         }
230 <a name="l00163"></a>00163 
231 <a name="l00164"></a>00164 <span class="preprocessor">#ifndef SE_NO_TRANSPORT_CRYPTO</span>
232 <a name="l00165"></a>00165 <span class="preprocessor"></span>        rc4_recv.ProcessString((uchar*)msg, bytes_read);
233 <a name="l00166"></a>00166 <span class="preprocessor">#endif</span>
234 <a name="l00167"></a>00167 <span class="preprocessor"></span>
235 <a name="l00168"></a>00168         msg[len] = <span class="charliteral">&#39;\0&#39;</span>;
236 <a name="l00169"></a>00169 
237 <a name="l00170"></a>00170         <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a> ret = <a class="code" href="class_s_e_string.html" title="SEString is basic char* based string class.">SEString</a>(msg);
238 <a name="l00171"></a>00171 
239 <a name="l00172"></a>00172         <span class="keyword">delete</span>[] msg;
240 <a name="l00173"></a>00173 
241 <a name="l00174"></a>00174         <span class="keywordflow">if</span> (<a class="code" href="class_s_e_transport.html#a5e680ec4f492e3db6b5e27da9851ec1f">debug</a>)
242 <a name="l00175"></a>00175                 <a class="code" href="class_s_e_transport.html#a907c927da81aec7894dbdcc14d905d05">LOG</a>(<span class="stringliteral">&quot;TRANSPORT: Got message (len=&quot;</span> + <a class="code" href="class_s_e_string.html#a315f0dd8f3d6e532192b4e95835ebf92">SEString::from</a>(len) + <span class="stringliteral">&quot;) \&quot;&quot;</span> + ret + <span class="stringliteral">&quot;\&quot;&quot;</span>);
243 <a name="l00176"></a>00176 
244 <a name="l00177"></a>00177         STTester_ON_INCOMING_EVENT(ret);
245 <a name="l00178"></a>00178 
246 <a name="l00179"></a>00179         <span class="keywordflow">return</span> ret;
247 <a name="l00180"></a>00180 }
248 <a name="l00181"></a>00181 
249 <a name="l00182"></a><a class="code" href="class_s_e_pipe_transport.html#a57d2be9c46dec2ecb739d428cad75a60">00182</a> <span class="keywordtype">bool</span> <a class="code" href="class_s_e_pipe_transport.html#a57d2be9c46dec2ecb739d428cad75a60">SEPipeTransport::hasMore</a>(<span class="keywordtype">int</span> wait)
250 <a name="l00183"></a>00183 {
251 <a name="l00184"></a>00184         <span class="keywordflow">if</span> (!connected)
252 <a name="l00185"></a>00185                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
253 <a name="l00186"></a>00186 
254 <a name="l00187"></a>00187         STTester_HAS_MORE();
255 <a name="l00188"></a>00188 
256 <a name="l00189"></a>00189         <span class="comment">// check, if we have something, immediately return true</span>
257 <a name="l00190"></a>00190         <span class="comment">// if we dont, wait, go to next cycle, return</span>
258 <a name="l00191"></a>00191         <span class="keywordtype">int</span> wait_cycle = 0;
259 <a name="l00192"></a>00192         <span class="keywordflow">do</span> {
260 <a name="l00193"></a>00193                 DWORD bytes_avail = 0;
261 <a name="l00194"></a>00194                 <span class="keywordflow">if</span> (!::PeekNamedPipe(hReadPipeParent, NULL, 0, NULL, &amp;bytes_avail, NULL)) {
262 <a name="l00195"></a>00195                         connected = <span class="keyword">false</span>;
263 <a name="l00196"></a>00196                         <span class="keywordflow">return</span> <span class="keyword">false</span>;
264 <a name="l00197"></a>00197                 }
265 <a name="l00198"></a>00198 
266 <a name="l00199"></a>00199                 <span class="keywordflow">if</span> (bytes_avail) {
267 <a name="l00200"></a>00200                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
268 <a name="l00201"></a>00201                 }
269 <a name="l00202"></a>00202 
270 <a name="l00203"></a>00203                 <span class="keywordflow">if</span> (!wait_cycle) {
271 <a name="l00204"></a>00204                         ::Sleep(wait);
272 <a name="l00205"></a>00205                 }
273 <a name="l00206"></a>00206                 wait_cycle++;
274 <a name="l00207"></a>00207 
275 <a name="l00208"></a>00208         } <span class="keywordflow">while</span> (wait_cycle != 2);
276 <a name="l00209"></a>00209         <span class="keywordflow">return</span> <span class="keyword">false</span>;
277 <a name="l00210"></a>00210 }
278 <a name="l00211"></a>00211 
279 <a name="l00212"></a><a class="code" href="class_s_e_pipe_transport.html#ab01628d5f35b72408a60b86de933fbcb">00212</a> <span class="keywordtype">bool</span> <a class="code" href="class_s_e_pipe_transport.html#ab01628d5f35b72408a60b86de933fbcb" title="Check if the connection to skypekit is still there.">SEPipeTransport::isConnected</a>()<span class="keyword"> const</span>
280 <a name="l00213"></a>00213 <span class="keyword"></span>{
281 <a name="l00214"></a>00214         <span class="keywordflow">return</span> connected;
282 <a name="l00215"></a>00215 }
283 <a name="l00216"></a>00216 
284 <a name="l00217"></a><a class="code" href="class_s_e_pipe_transport.html#a9c9cc5adc1d250460cdc44009494eb01">00217</a> <span class="keywordtype">int</span> <a class="code" href="class_s_e_pipe_transport.html#a9c9cc5adc1d250460cdc44009494eb01" title="Returns the socket descriptor which can be used to manually call select on. If the...">SEPipeTransport::getSocket</a>()<span class="keyword"> const</span>
285 <a name="l00218"></a>00218 <span class="keyword"></span>{
286 <a name="l00219"></a>00219         <span class="keywordflow">return</span> -1;
287 <a name="l00220"></a>00220 }
288 <a name="l00221"></a>00221 
289 <a name="l00222"></a>00222 <span class="preprocessor">#ifndef SE_NO_TRANSPORT_CRYPTO</span>
290 <a name="l00223"></a>00223 <span class="preprocessor"></span>
291 <a name="l00224"></a>00224 <span class="preprocessor">#include &lt;intrin.h&gt;</span>
292 <a name="l00225"></a>00225 <span class="preprocessor">#pragma intrinsic(_rotl16, _rotr16)</span>
293 <a name="l00226"></a>00226 <span class="preprocessor"></span>
294 <a name="l00227"></a><a class="code" href="skype-pipe-transport_8cpp.html#a6eadbe97b2a87646315eb5acba75266c">00227</a> <span class="preprocessor">#define TRANSFORM_02(x, y, z) (y ^ (x | ~z))</span>
295 <a name="l00228"></a>00228 <span class="preprocessor"></span>
296 <a name="l00229"></a><a class="code" href="class_s_e_pipe_transport.html#a5a862916799117ece7f3116a30248f20">00229</a> <span class="keywordtype">void</span> <a class="code" href="class_s_e_pipe_transport.html#a5a862916799117ece7f3116a30248f20">SEPipeTransport::set_keys</a>(DWORD handle00, DWORD handle01, DWORD handle02)
297 <a name="l00230"></a>00230 {
298 <a name="l00231"></a>00231         BYTE crypto_seed[64*4];
299 <a name="l00232"></a>00232 
300 <a name="l00233"></a>00233         DWORD feedback = 0x8b44f7af, state = (handle00*handle01*handle02)+0xefcdab89;
301 <a name="l00234"></a>00234         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> idx=0; idx != 16; idx++) {
302 <a name="l00235"></a>00235                 feedback = (handle01*state)|(handle02*feedback)^(handle00*state);
303 <a name="l00236"></a>00236                 ((DWORD*)crypto_seed)[idx*4] = feedback;
304 <a name="l00237"></a>00237                 state = feedback^(_rotr16(LOWORD(feedback), idx+3) | _rotl16(HIWORD(feedback), idx+7));
305 <a name="l00238"></a>00238         }
306 <a name="l00239"></a>00239         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> idx=0; idx != 16; idx++) {
307 <a name="l00240"></a>00240                 feedback = (handle01*state)|(handle02*(*((DWORD*)crypto_seed+(idx*4+0))))^(handle00*state);
308 <a name="l00241"></a>00241                 ((DWORD*)crypto_seed)[idx*4+1] = feedback;
309 <a name="l00242"></a>00242                 state = feedback^(_rotl16(LOWORD(feedback), idx+2) | _rotr16(HIWORD(state), idx+9));
310 <a name="l00243"></a>00243 
311 <a name="l00244"></a>00244                 ((DWORD*)crypto_seed)[idx*4+2] = <a class="code" href="skype-pipe-transport_8cpp.html#a6eadbe97b2a87646315eb5acba75266c">TRANSFORM_02</a>(*((DWORD*)crypto_seed+(idx*4+0)), state, feedback);
312 <a name="l00245"></a>00245                 ((DWORD*)crypto_seed)[idx*4+3] = <a class="code" href="skype-pipe-transport_8cpp.html#a6eadbe97b2a87646315eb5acba75266c">TRANSFORM_02</a>(*((DWORD*)crypto_seed+(idx*4+2)), *((DWORD*)crypto_seed+(idx*4+0)), *((DWORD*)crypto_seed+(idx*4+1)));
313 <a name="l00246"></a>00246         }
314 <a name="l00247"></a>00247         rc4_recv.SetKey(crypto_seed, <span class="keyword">sizeof</span>(crypto_seed));
315 <a name="l00248"></a>00248         rc4_send.SetKey(crypto_seed, <span class="keyword">sizeof</span>(crypto_seed));
316 <a name="l00249"></a>00249 }
317 <a name="l00250"></a>00250 <span class="preprocessor">#endif</span>
318 <a name="l00251"></a>00251 <span class="preprocessor"></span>
319 <a name="l00252"></a>00252 <span class="preprocessor">#endif // SE_NO_WINDOWS_PIPE_TRANSPORT</span>
320 </pre></div></div>
321
322 <hr/>   
323                 <p><b>(c) Skype Technologies S.A. Confidential/Proprietary</b></p>              
324                 <p>Last updated: 18 Jun 2010</p>                
325                 </BODY>
326 </HTML>