📄 smtp__client_8c-source.html
字号:
00481 <span class="keywordflow">if</span>(<a class="code" href="tcp_8c.html#a6">tcp_connect</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle, <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remip, <a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.remport, 0) >= 0)00482 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a4">SMTP_CONNECTIONOPEN_SENT</a>);00483 00484 <span class="keywordflow">return</span>;00485 }00486 00487 00488 00489 <span class="keywordflow">if</span>( <a class="code" href="tcp_8c.html#a9">tcp_getstate</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle) != <a class="code" href="tcp__ip_8h.html#a53">TCP_STATE_CONNECTED</a> ) {00490 <span class="keywordflow">return</span>;00491 }00492 00493 <span class="keywordflow">if</span>( <a class="code" href="tcp_8c.html#a10">tcp_checksend</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle) < 0 )00494 <span class="keywordflow">return</span>;00495 00496 <span class="comment">/* It's connected and no unacked data so try to send */</span>00497 00498 00499 <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#a6">SMTP_SERVER_READY</a>) {00500 <span class="comment">/* Send HELO */</span>00501 smtpc_sendhelo();00502 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a7">SMTP_HELO_SENT</a>);00503 DEBUGOUT(<span class="stringliteral">"SMTP HELO packet sent\r\n"</span>);00504 <span class="keywordflow">return</span>;00505 }00506 00507 <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#a8">SMTP_HELO_ACKED</a>) {00508 <span class="comment">/* Send MAIL FROM */</span>00509 smtpc_sendmailfrom();00510 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a9">SMTP_MAILFROM_SENT</a>);00511 DEBUGOUT(<span class="stringliteral">"SMTP MAIL FROM packet sent\r\n"</span>);00512 <span class="keywordflow">return</span>;00513 } 00514 00515 <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#a10">SMTP_MAILFROM_ACKED</a>) {00516 <span class="comment">/* Send RCPT TO */</span>00517 smtpc_sendrcptto();00518 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a11">SMTP_RCPTTO_SENT</a>);00519 DEBUGOUT(<span class="stringliteral">"SMTP RCPT TO packet sent\r\n"</span>);00520 <span class="keywordflow">return</span>;00521 } 00522 00523 <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#a12">SMTP_RCPTTO_ACKED</a>) {00524 <span class="comment">/* Send DATA */</span>00525 smtpc_senddatareq();00526 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a13">SMTP_DATAREQ_SENT</a>);00527 DEBUGOUT(<span class="stringliteral">"SMTP DATA packet sent\r\n"</span>);00528 <span class="keywordflow">return</span>;00529 } 00530 00531 <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#a14">SMTP_DATAREQ_ACKED</a>) {00532 <span class="comment">/* Send BODY */</span>00533 smtpc_sendbody();00534 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a15">SMTP_BODY_SENT</a>);00535 DEBUGOUT(<span class="stringliteral">"SMTP BODY packet sent\r\n"</span>);00536 <span class="keywordflow">return</span>;00537 } 00538 00539 00540 <span class="comment">/* Body is part of plain text so we just make internal state change */</span>00541 <span class="comment">/* when TCP has acked the body packet. This pseudo-state just helps */</span>00542 <span class="comment">/* us to regenerate the body when needed */</span>00543 00544 <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#a15">SMTP_BODY_SENT</a>)00545 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a16">SMTP_SENDING_DATA</a>);00546 00547 <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#a16">SMTP_SENDING_DATA</a>) {00548 <span class="comment">/* Inform user app that old data is acked now */</span>00549 00550 <a class="code" href="smtpc__callbacks_8c.html#a45">smtpc_dataacked</a>(); 00551 00552 <span class="keywordflow">if</span> (smtpc_senddata() < 0) {00553 <span class="comment">/* End of data, send CRLF.CRLF */</span>00554 00555 DEBUGOUT(<span class="stringliteral">"SMTP End of data reached\r\n"</span>);00556 smtpc_senddataend();00557 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a18">SMTP_DATAEND_SENT</a>);00558 00559 }00560 <span class="keywordflow">return</span>;00561 } 00562 00563 00564 <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#a19">SMTP_DATAEND_ACKED</a>) {00565 <span class="comment">/* Send QUIT */</span>00566 smtpc_sendquit();00567 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a20">SMTP_QUIT_SENT</a>);00568 DEBUGOUT(<span class="stringliteral">"SMTP QUIT packet sent\r\n"</span>);00569 <span class="keywordflow">return</span>;00570 } 00571 00572 00573 <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#a21">SMTP_QUIT_ACKED</a>) {00574 00575 <span class="comment">/* Inform application that data is sent OK */</span>00576 00577 <a class="code" href="smtpc__callbacks_8c.html#a47">smtpc_allok</a>();00578 00579 <span class="comment">/* Try to close TCP */</span>00580 00581 <span class="keywordflow">if</span>(<a class="code" href="tcp_8c.html#a8">tcp_close</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle) >= 0) {00582 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a>);00583 DEBUGOUT(<span class="stringliteral">"SMTP connection closed OK\r\n"</span>);00584 <span class="keywordflow">return</span>;00585 }00586 00587 <span class="comment">/* Close is not accepted by TCP. See if timeout */</span>00588 00589 <span class="keywordflow">if</span>(<a class="code" href="timers_8c.html#a7">check_timer</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.tmrhandle) == 0) {00590 <span class="comment">/* Use brute force */</span>00591 00592 <a class="code" href="tcp_8c.html#a11">tcp_abort</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle);00593 smtpc_changestate(<a class="code" href="smtp__client_8h.html#a2">SMTP_CLOSED</a>);00594 DEBUGOUT(<span class="stringliteral">"SMTP connection closed by ABORT\r\n"</span>);00595 <span class="keywordflow">return</span>;00596 }00597 00598 <span class="comment">/* Keep trying untill timeout */</span>00599 00600 <span class="keywordflow">return</span>;00601 00602 } 00603 00604 <span class="keywordflow">return</span>;00605 00606 }00607 00608 00609 <span class="keywordtype">void</span> smtpc_sendhelo (<span class="keywordtype">void</span>)00610 {00611 INT8 i;00612 UINT8* buf;00613 00614 <span class="comment">/* Fill TCP Tx buffer with "HELO " and use callback function */</span>00615 <span class="comment">/* smtp_getdomain in order to get domain from systems and send */</span>00616 <span class="comment">/* that combined "HELO domainnname" to SMTP server */</span>00617 00618 buf = &net_buf[<a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>];00619 00620 *buf++ = <span class="charliteral">'H'</span>;00621 *buf++ = <span class="charliteral">'E'</span>;00622 *buf++ = <span class="charliteral">'L'</span>;00623 *buf++ = <span class="charliteral">'O'</span>;00624 *buf++ = <span class="charliteral">' '</span>; 00625 00626 i = <a class="code" href="smtpc__callbacks_8c.html#a2">smtpc_getdomain</a>(buf);00627 00628 <span class="keywordflow">if</span>(i < 0)00629 <span class="keywordflow">return</span>;00630 00631 buf += i; 00632 00633 <span class="comment">/* Insert CRLF */</span>00634 00635 *buf++ = <span class="charliteral">'\r'</span>;00636 *buf = <span class="charliteral">'\n'</span>;00637 00638 00639 <a class="code" href="tcp_8c.html#a7">tcp_send</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle, &net_buf[<a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>], <a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a> - <a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>, i + 7);00640 00641 }00642 00643 00644 00645 <span class="keywordtype">void</span> smtpc_sendmailfrom (<span class="keywordtype">void</span>)00646 {00647 INT8 i;00648 UINT8* buf;00649 00650 <span class="comment">/* Fill TCP Tx buffer with "MAIL FROM: <" and use callback function */</span>00651 <span class="comment">/* smtp_getsender in order to get local e-mail address from user and send */</span>00652 <span class="comment">/* that combined "MAIL FROM: <myadr>" to SMTP server */</span>00653 00654 buf = &net_buf[<a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>];00655 00656 *buf++ = <span class="charliteral">'M'</span>;00657 *buf++ = <span class="charliteral">'A'</span>;00658 *buf++ = <span class="charliteral">'I'</span>;00659 *buf++ = <span class="charliteral">'L'</span>;00660 *buf++ = <span class="charliteral">' '</span>; 00661 *buf++ = <span class="charliteral">'F'</span>;00662 *buf++ = <span class="charliteral">'R'</span>;00663 *buf++ = <span class="charliteral">'O'</span>;00664 *buf++ = <span class="charliteral">'M'</span>;00665 *buf++ = <span class="charliteral">':'</span>;00666 *buf++ = <span class="charliteral">' '</span>;00667 *buf++ = <span class="charliteral">'<'</span>; 00668 00669 i = <a class="code" href="smtpc__callbacks_8c.html#a3">smtpc_getsender</a>(buf);00670 00671 <span class="keywordflow">if</span>(i < 0)00672 <span class="keywordflow">return</span>;00673 00674 buf += i;00675 00676 <span class="comment">/* Insert >CRLF */</span>00677 00678 *buf++ = <span class="charliteral">'>'</span>;00679 *buf++ = <span class="charliteral">'\r'</span>;00680 *buf = <span class="charliteral">'\n'</span>;00681 00682 00683 <a class="code" href="tcp_8c.html#a7">tcp_send</a>(<a class="code" href="smtp__client_8c.html#a8">smtp_client</a>.sochandle, &net_buf[<a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>], <a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a> - <a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>, i + 15);00684 00685 }00686 00687 00688 00689 <span class="keywordtype">void</span> smtpc_sendrcptto (<span class="keywordtype">void</span>)00690 {00691 INT8 i;00692 UINT8* buf;00693 00694 <span class="comment">/* Fill TCP Tx buffer with "RCPT TO: <" and use callback function */</span>00695 <span class="comment">/* smtp_getreceiver in order to get receiver address from user and send */</span>00696 <span class="comment">/* that combined "RCPT To: <rcvadr>" to SMTP server */</span>00697 00698 buf = &net_buf[<a class="code" href="tcp__ip_8h.html#a61">TCP_APP_OFFSET</a>];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -