📄 smtp__client_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/smtp/smtp_client.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindex" href="examples.html">Examples</a> </center><hr><h1>/opentcp/smtp/smtp_client.c</h1><a href="smtp__client_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> * "This product includes software developed by Viola </span>00019 <span class="comment"> * Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *<http://www.violasystems.com/>.</span>00052 <span class="comment"> */</span>00053 00067 <span class="preprocessor">#include <<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>></span>00068 <span class="preprocessor">#include <<a class="code" href="debug_8h.html">inet/debug.h</a>></span>00069 <span class="preprocessor">#include <<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>></span>00070 <span class="preprocessor">#include <<a class="code" href="system_8h.html">inet/system.h</a>></span>00071 <span class="preprocessor">#include <<a class="code" href="timers_8h.html">inet/timers.h</a>></span>00072 <span class="preprocessor">#include <<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>></span>00073 <span class="preprocessor">#include <<a class="code" href="smtp__client_8h.html">inet/smtp/smtp_client.h</a>></span>00074 <a name="l00075"></a><a class="code" href="smtp__client_8c.html#a0">00075</a> UINT8 <a class="code" href="smtp__client_8c.html#a0">smtpc_init_done</a> = 0; 00083 <span class="keyword">struct</span>00084 <span class="keyword"></span>{00085 UINT8 <a class="code" href="structpop3c__struct.html#m0">state</a>;00086 UINT32 <a class="code" href="structpop3c__struct.html#m1">remip</a>;00087 UINT16 <a class="code" href="structpop3c__struct.html#m2">remport</a>;00088 INT8 <a class="code" href="structpop3c__struct.html#m3">sochandle</a>;00089 UINT8 <a class="code" href="structpop3c__struct.html#m4">tmrhandle</a>;00090 UINT16 <a class="code" href="structpop3c__struct.html#m5">unacked</a>;00091 UINT16 bufindex;00092 00093 }<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>;00094 00095 00096 <span class="comment">/* The applications that use TCP must implement following function stubs */</span>00097 <span class="comment">/* void application_name_init (void) - call once when processor starts */</span>00098 <span class="comment">/* void application_name_run (void) - call periodically on main loop */</span>00099 <span class="comment">/* INT32 application_name_eventlistener (INT8, UINT8, UINT32, UINT32) */</span>00100 <span class="comment">/* - called by TCP input process to inform arriving data, errors etc */</span>00101 00102 <span class="comment">/* SMTP client application */</span>00103 <a name="l00120"></a><a class="code" href="smtp__client_8c.html#a9">00120</a> INT8 <a class="code" href="smtp__client_8c.html#a9">smtpc_connect</a> (UINT32 ip, UINT16 port){00121 <span class="comment">/* Do we have socket */</span>00122 00123 <span class="keywordflow">if</span>( <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle < 0 ) {00124 DEBUGOUT(<span class="stringliteral">"smtpc_connect() called but no socket\r\n"</span>);00125 <span class="keywordflow">return</span>(-1);00126 }00127 00128 <span class="keywordflow">if</span>( <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.state < <a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a> ) {00129 DEBUGOUT(<span class="stringliteral">"smtpc_connect() called but uninitialized\r\n"</span>);00130 <span class="keywordflow">return</span>(-1);00131 }00132 00133 <span class="keywordflow">if</span>( <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.state == <a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a> ) {00134 DEBUGOUT(<span class="stringliteral">"SMTP Connection request going to be processed\r\n"</span>);00135 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remip = ip;00136 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remport = port;00137 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a3">SMTP_OPEN_REQUESTED</a>);00138 <span class="keywordflow">return</span>(1);00139 }00140 00141 <span class="keywordflow">return</span>(-1); 00142 00143 }00144 00145 <a name="l00155"></a><a class="code" href="smtp__client_8c.html#a10">00155</a> <span class="keywordtype">void</span> <a class="code" href="smtp__client_8c.html#a27">smtpc_init</a> (<span class="keywordtype">void</span>){00156 00157 <span class="keywordflow">if</span>(smtpc_init_done) {00158 DEBUGOUT(<span class="stringliteral">"smtp client already initialized\r\n"</span>);00159 <span class="keywordflow">return</span>;00160 }00161 00162 00163 <span class="comment">/* Get timer handle */</span>00164 00165 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.tmrhandle = <a class="code" href="timers_8c.html#a2">get_timer</a>();00166 00167 <span class="comment">/* Get TCP Socket */</span>00168 00169 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle = <a class="code" href="tcp_8c.html#a3">tcp_getsocket</a>(<a class="code" href="tcp__ip_8h.html#a40">TCP_TYPE_CLIENT</a>, <a class="code" href="tcp__ip_8h.html#a18">TCP_TOS_NORMAL</a>, <a class="code" href="group__opentcp__config.html#a14">TCP_DEF_TOUT</a>, smtpc_eventlistener);00170 00171 <span class="keywordflow">if</span>( <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle < 0 ) {00172 DEBUGOUT(<span class="stringliteral">"smtpc_init() uncapable of getting socket\r\n"</span>);00173 <a class="code" href="system_8h.html#a6">RESET_SYSTEM</a>();00174 } 00175 00176 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a>);00177 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.bufindex = <a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>;00178 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.unacked = 0; 00179 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remip = 0;00180 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remport = 0;00181 00182 <a class="code" href="smtp__client_8c.html#a0">smtpc_init_done</a> = 0x01;00183 00184 }00185 <a name="l00193"></a><a class="code" href="smtp__client_8c.html#a11">00193</a> UINT8 <a class="code" href="smtp__client_8c.html#a30">smtpc_getstate</a> (<span class="keywordtype">void</span>){00194 <span class="keywordflow">return</span>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.state);00195 00196 }00197 00198 <span class="comment">/********************************************************************************</span>00199 <span class="comment">Function: smtpc_eventlistener</span>00200 <span class="comment"></span>00201 <span class="comment">Parameters: INT8 cbhandle - handle to TCP socket where event is coming from </span>00202 <span class="comment"> UINT8 event - type of event</span>00203 <span class="comment"> UINT32 par1 - parameter the meaning of depends on event</span>00204 <span class="comment"> UINT32 par2 - parameter the meaning of depends on event</span>00205 <span class="comment"> </span>00206 <span class="comment">Return val: INT32 - depends on event but usually (-1) is error of some</span>00207 <span class="comment"> kind and positive reply means OK</span>00208 <span class="comment"> </span>00209 <span class="comment">Date: 21.7.2002</span>00210 <span class="comment"></span>00211 <span class="comment">Desc: This function is given to TCP socket as function pointer to be</span>00212 <span class="comment"> used by TCP engine to make callbacks to inform about events</span>00213 <span class="comment"> on TCP e.g. arriving data. Main functionality of this function </span>00214 <span class="comment"> is to parse data from TCP to detect SMTP server reply commands,</span>00215 <span class="comment"> handling out retransmissions and making state changes</span>00216 <span class="comment">*********************************************************************************/</span>00217 00218 00219 INT32 smtpc_eventlistener (INT8 cbhandle, UINT8 event, UINT32 par1, UINT32 par2)00220 {00221 <span class="comment">/* This function is called by TCP stack to inform about events */</span>00222 00223 UINT16 cmd;00224 00225 00226 <span class="keywordflow">if</span>( cbhandle != <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle) <span class="comment">/* Not our handle */</span>00227 <span class="keywordflow">return</span>(-1);00228 00229 <span class="keywordflow">switch</span>( event ) {00230 00231 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a54">TCP_EVENT_CONREQ</a>:00232 00233 <span class="comment">/* We don't allow incoming connections */</span>00234 00235 <span class="keywordflow">return</span>(-1);00236 00237 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a57">TCP_EVENT_ABORT</a>:00238 00239 <span class="keywordflow">if</span>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.state > <a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a>) {00240 <span class="comment">/* Inform application */</span> 00241 <a class="code" href="smtpc__callbacks_8c.html#a46">smtpc_error</a>(); 00242 }00243 00244 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a>);00245 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.unacked = 0;00246 00247 <span class="keywordflow">return</span>(1);00248 00249 <span class="keywordflow">break</span>;00250 00251 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a55">TCP_EVENT_CONNECTED</a>:00252 00253 <span class="keywordflow">if</span>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.state == <a class="code" href="smtp__client_8h.html#a4">SMTP_CONNECTIONOPEN_SENT</a>) {00254 DEBUGOUT(<span class="stringliteral">"SMTP TCP connection opened\r\n"</span>);00255 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a5">SMTP_CONNECTION_OPENED</a>);00256 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.unacked = 0;00257 <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.bufindex = <a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>;00258 <span class="keywordflow">return</span>(-1);00259 }00260 00261 <span class="keywordflow">break</span>;00262
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -