These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /** @addtogroup EMAC_uIP
frank26080115 0:bf7b9fba3924 2 * @{
frank26080115 0:bf7b9fba3924 3 */
frank26080115 0:bf7b9fba3924 4 /**
frank26080115 0:bf7b9fba3924 5 * \addtogroup apps
frank26080115 0:bf7b9fba3924 6 * @{
frank26080115 0:bf7b9fba3924 7 */
frank26080115 0:bf7b9fba3924 8
frank26080115 0:bf7b9fba3924 9 /**
frank26080115 0:bf7b9fba3924 10 * \defgroup smtp SMTP E-mail sender
frank26080115 0:bf7b9fba3924 11 * @{
frank26080115 0:bf7b9fba3924 12 *
frank26080115 0:bf7b9fba3924 13 * The Simple Mail Transfer Protocol (SMTP) as defined by RFC821 is
frank26080115 0:bf7b9fba3924 14 * the standard way of sending and transfering e-mail on the
frank26080115 0:bf7b9fba3924 15 * Internet. This simple example implementation is intended as an
frank26080115 0:bf7b9fba3924 16 * example of how to implement protocols in uIP, and is able to send
frank26080115 0:bf7b9fba3924 17 * out e-mail but has not been extensively tested.
frank26080115 0:bf7b9fba3924 18 */
frank26080115 0:bf7b9fba3924 19
frank26080115 0:bf7b9fba3924 20 /**
frank26080115 0:bf7b9fba3924 21 * \file
frank26080115 0:bf7b9fba3924 22 * SMTP example implementation
frank26080115 0:bf7b9fba3924 23 * \author Adam Dunkels <adam@dunkels.com>
frank26080115 0:bf7b9fba3924 24 */
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /*
frank26080115 0:bf7b9fba3924 27 * Copyright (c) 2004, Adam Dunkels.
frank26080115 0:bf7b9fba3924 28 * All rights reserved.
frank26080115 0:bf7b9fba3924 29 *
frank26080115 0:bf7b9fba3924 30 * Redistribution and use in source and binary forms, with or without
frank26080115 0:bf7b9fba3924 31 * modification, are permitted provided that the following conditions
frank26080115 0:bf7b9fba3924 32 * are met:
frank26080115 0:bf7b9fba3924 33 * 1. Redistributions of source code must retain the above copyright
frank26080115 0:bf7b9fba3924 34 * notice, this list of conditions and the following disclaimer.
frank26080115 0:bf7b9fba3924 35 * 2. Redistributions in binary form must reproduce the above copyright
frank26080115 0:bf7b9fba3924 36 * notice, this list of conditions and the following disclaimer in the
frank26080115 0:bf7b9fba3924 37 * documentation and/or other materials provided with the distribution.
frank26080115 0:bf7b9fba3924 38 * 3. Neither the name of the Institute nor the names of its contributors
frank26080115 0:bf7b9fba3924 39 * may be used to endorse or promote products derived from this software
frank26080115 0:bf7b9fba3924 40 * without specific prior written permission.
frank26080115 0:bf7b9fba3924 41 *
frank26080115 0:bf7b9fba3924 42 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
frank26080115 0:bf7b9fba3924 43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
frank26080115 0:bf7b9fba3924 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
frank26080115 0:bf7b9fba3924 45 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
frank26080115 0:bf7b9fba3924 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
frank26080115 0:bf7b9fba3924 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
frank26080115 0:bf7b9fba3924 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
frank26080115 0:bf7b9fba3924 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
frank26080115 0:bf7b9fba3924 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
frank26080115 0:bf7b9fba3924 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
frank26080115 0:bf7b9fba3924 52 * SUCH DAMAGE.
frank26080115 0:bf7b9fba3924 53 *
frank26080115 0:bf7b9fba3924 54 * This file is part of the uIP TCP/IP stack.
frank26080115 0:bf7b9fba3924 55 *
frank26080115 0:bf7b9fba3924 56 * Author: Adam Dunkels <adam@sics.se>
frank26080115 0:bf7b9fba3924 57 *
frank26080115 0:bf7b9fba3924 58 * $Id: smtp.c,v 1.4 2006/06/11 21:46:37 adam Exp $
frank26080115 0:bf7b9fba3924 59 */
frank26080115 0:bf7b9fba3924 60 #include "smtp.h"
frank26080115 0:bf7b9fba3924 61
frank26080115 0:bf7b9fba3924 62 #include "smtp-strings.h"
frank26080115 0:bf7b9fba3924 63 #include "psock.h"
frank26080115 0:bf7b9fba3924 64 #include "uip.h"
frank26080115 0:bf7b9fba3924 65
frank26080115 0:bf7b9fba3924 66 #include <string.h>
frank26080115 0:bf7b9fba3924 67
frank26080115 0:bf7b9fba3924 68 static struct smtp_state s;
frank26080115 0:bf7b9fba3924 69
frank26080115 0:bf7b9fba3924 70 static char *localhostname;
frank26080115 0:bf7b9fba3924 71 static uip_ipaddr_t smtpserver;
frank26080115 0:bf7b9fba3924 72
frank26080115 0:bf7b9fba3924 73 #define ISO_nl 0x0a
frank26080115 0:bf7b9fba3924 74 #define ISO_cr 0x0d
frank26080115 0:bf7b9fba3924 75
frank26080115 0:bf7b9fba3924 76 #define ISO_period 0x2e
frank26080115 0:bf7b9fba3924 77
frank26080115 0:bf7b9fba3924 78 #define ISO_2 0x32
frank26080115 0:bf7b9fba3924 79 #define ISO_3 0x33
frank26080115 0:bf7b9fba3924 80 #define ISO_4 0x34
frank26080115 0:bf7b9fba3924 81 #define ISO_5 0x35
frank26080115 0:bf7b9fba3924 82
frank26080115 0:bf7b9fba3924 83
frank26080115 0:bf7b9fba3924 84 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 85 static
frank26080115 0:bf7b9fba3924 86 PT_THREAD(smtp_thread(void))
frank26080115 0:bf7b9fba3924 87 {
frank26080115 0:bf7b9fba3924 88 PSOCK_BEGIN(&s.psock);
frank26080115 0:bf7b9fba3924 89
frank26080115 0:bf7b9fba3924 90 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 91
frank26080115 0:bf7b9fba3924 92 if(strncmp(s.inputbuffer, smtp_220, 3) != 0) {
frank26080115 0:bf7b9fba3924 93 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 94 smtp_done(2);
frank26080115 0:bf7b9fba3924 95 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 96 }
frank26080115 0:bf7b9fba3924 97
frank26080115 0:bf7b9fba3924 98 PSOCK_SEND_STR(&s.psock, (char *)smtp_helo);
frank26080115 0:bf7b9fba3924 99 PSOCK_SEND_STR(&s.psock, localhostname);
frank26080115 0:bf7b9fba3924 100 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 101
frank26080115 0:bf7b9fba3924 102 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 103
frank26080115 0:bf7b9fba3924 104 if(s.inputbuffer[0] != ISO_2) {
frank26080115 0:bf7b9fba3924 105 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 106 smtp_done(3);
frank26080115 0:bf7b9fba3924 107 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 108 }
frank26080115 0:bf7b9fba3924 109
frank26080115 0:bf7b9fba3924 110 PSOCK_SEND_STR(&s.psock, (char *)smtp_mail_from);
frank26080115 0:bf7b9fba3924 111 PSOCK_SEND_STR(&s.psock, s.from);
frank26080115 0:bf7b9fba3924 112 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 113
frank26080115 0:bf7b9fba3924 114 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 115
frank26080115 0:bf7b9fba3924 116 if(s.inputbuffer[0] != ISO_2) {
frank26080115 0:bf7b9fba3924 117 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 118 smtp_done(4);
frank26080115 0:bf7b9fba3924 119 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 120 }
frank26080115 0:bf7b9fba3924 121
frank26080115 0:bf7b9fba3924 122 PSOCK_SEND_STR(&s.psock, (char *)smtp_rcpt_to);
frank26080115 0:bf7b9fba3924 123 PSOCK_SEND_STR(&s.psock, s.to);
frank26080115 0:bf7b9fba3924 124 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 125
frank26080115 0:bf7b9fba3924 126 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 127
frank26080115 0:bf7b9fba3924 128 if(s.inputbuffer[0] != ISO_2) {
frank26080115 0:bf7b9fba3924 129 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 130 smtp_done(5);
frank26080115 0:bf7b9fba3924 131 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 132 }
frank26080115 0:bf7b9fba3924 133
frank26080115 0:bf7b9fba3924 134 if(s.cc != 0) {
frank26080115 0:bf7b9fba3924 135 PSOCK_SEND_STR(&s.psock, (char *)smtp_rcpt_to);
frank26080115 0:bf7b9fba3924 136 PSOCK_SEND_STR(&s.psock, s.cc);
frank26080115 0:bf7b9fba3924 137 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 138
frank26080115 0:bf7b9fba3924 139 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 140
frank26080115 0:bf7b9fba3924 141 if(s.inputbuffer[0] != ISO_2) {
frank26080115 0:bf7b9fba3924 142 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 143 smtp_done(6);
frank26080115 0:bf7b9fba3924 144 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 145 }
frank26080115 0:bf7b9fba3924 146 }
frank26080115 0:bf7b9fba3924 147
frank26080115 0:bf7b9fba3924 148 PSOCK_SEND_STR(&s.psock, (char *)smtp_data);
frank26080115 0:bf7b9fba3924 149
frank26080115 0:bf7b9fba3924 150 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 151
frank26080115 0:bf7b9fba3924 152 if(s.inputbuffer[0] != ISO_3) {
frank26080115 0:bf7b9fba3924 153 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 154 smtp_done(7);
frank26080115 0:bf7b9fba3924 155 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 156 }
frank26080115 0:bf7b9fba3924 157
frank26080115 0:bf7b9fba3924 158 PSOCK_SEND_STR(&s.psock, (char *)smtp_to);
frank26080115 0:bf7b9fba3924 159 PSOCK_SEND_STR(&s.psock, s.to);
frank26080115 0:bf7b9fba3924 160 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 161
frank26080115 0:bf7b9fba3924 162 if(s.cc != 0) {
frank26080115 0:bf7b9fba3924 163 PSOCK_SEND_STR(&s.psock, (char *)smtp_cc);
frank26080115 0:bf7b9fba3924 164 PSOCK_SEND_STR(&s.psock, s.cc);
frank26080115 0:bf7b9fba3924 165 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 166 }
frank26080115 0:bf7b9fba3924 167
frank26080115 0:bf7b9fba3924 168 PSOCK_SEND_STR(&s.psock, (char *)smtp_from);
frank26080115 0:bf7b9fba3924 169 PSOCK_SEND_STR(&s.psock, s.from);
frank26080115 0:bf7b9fba3924 170 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 171
frank26080115 0:bf7b9fba3924 172 PSOCK_SEND_STR(&s.psock, (char *)smtp_subject);
frank26080115 0:bf7b9fba3924 173 PSOCK_SEND_STR(&s.psock, s.subject);
frank26080115 0:bf7b9fba3924 174 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
frank26080115 0:bf7b9fba3924 175
frank26080115 0:bf7b9fba3924 176 PSOCK_SEND(&s.psock, s.msg, s.msglen);
frank26080115 0:bf7b9fba3924 177
frank26080115 0:bf7b9fba3924 178 PSOCK_SEND_STR(&s.psock, (char *)smtp_crnlperiodcrnl);
frank26080115 0:bf7b9fba3924 179
frank26080115 0:bf7b9fba3924 180 PSOCK_READTO(&s.psock, ISO_nl);
frank26080115 0:bf7b9fba3924 181 if(s.inputbuffer[0] != ISO_2) {
frank26080115 0:bf7b9fba3924 182 PSOCK_CLOSE(&s.psock);
frank26080115 0:bf7b9fba3924 183 smtp_done(8);
frank26080115 0:bf7b9fba3924 184 PSOCK_EXIT(&s.psock);
frank26080115 0:bf7b9fba3924 185 }
frank26080115 0:bf7b9fba3924 186
frank26080115 0:bf7b9fba3924 187 PSOCK_SEND_STR(&s.psock, (char *)smtp_quit);
frank26080115 0:bf7b9fba3924 188 smtp_done(SMTP_ERR_OK);
frank26080115 0:bf7b9fba3924 189 PSOCK_END(&s.psock);
frank26080115 0:bf7b9fba3924 190 }
frank26080115 0:bf7b9fba3924 191 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 192 void
frank26080115 0:bf7b9fba3924 193 smtp_appcall(void)
frank26080115 0:bf7b9fba3924 194 {
frank26080115 0:bf7b9fba3924 195 if(uip_closed()) {
frank26080115 0:bf7b9fba3924 196 s.connected = 0;
frank26080115 0:bf7b9fba3924 197 return;
frank26080115 0:bf7b9fba3924 198 }
frank26080115 0:bf7b9fba3924 199 if(uip_aborted() || uip_timedout()) {
frank26080115 0:bf7b9fba3924 200 s.connected = 0;
frank26080115 0:bf7b9fba3924 201 smtp_done(1);
frank26080115 0:bf7b9fba3924 202 return;
frank26080115 0:bf7b9fba3924 203 }
frank26080115 0:bf7b9fba3924 204 smtp_thread();
frank26080115 0:bf7b9fba3924 205 }
frank26080115 0:bf7b9fba3924 206 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 207 /**
frank26080115 0:bf7b9fba3924 208 * Specificy an SMTP server and hostname.
frank26080115 0:bf7b9fba3924 209 *
frank26080115 0:bf7b9fba3924 210 * This function is used to configure the SMTP module with an SMTP
frank26080115 0:bf7b9fba3924 211 * server and the hostname of the host.
frank26080115 0:bf7b9fba3924 212 *
frank26080115 0:bf7b9fba3924 213 * \param lhostname The hostname of the uIP host.
frank26080115 0:bf7b9fba3924 214 *
frank26080115 0:bf7b9fba3924 215 * \param server A pointer to a 4-byte array representing the IP
frank26080115 0:bf7b9fba3924 216 * address of the SMTP server to be configured.
frank26080115 0:bf7b9fba3924 217 */
frank26080115 0:bf7b9fba3924 218 void
frank26080115 0:bf7b9fba3924 219 smtp_configure(char *lhostname, void *server)
frank26080115 0:bf7b9fba3924 220 {
frank26080115 0:bf7b9fba3924 221 localhostname = lhostname;
frank26080115 0:bf7b9fba3924 222 uip_ipaddr_copy(smtpserver, server);
frank26080115 0:bf7b9fba3924 223 }
frank26080115 0:bf7b9fba3924 224 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 225 /**
frank26080115 0:bf7b9fba3924 226 * Send an e-mail.
frank26080115 0:bf7b9fba3924 227 *
frank26080115 0:bf7b9fba3924 228 * \param to The e-mail address of the receiver of the e-mail.
frank26080115 0:bf7b9fba3924 229 * \param cc The e-mail address of the CC: receivers of the e-mail.
frank26080115 0:bf7b9fba3924 230 * \param from The e-mail address of the sender of the e-mail.
frank26080115 0:bf7b9fba3924 231 * \param subject The subject of the e-mail.
frank26080115 0:bf7b9fba3924 232 * \param msg The actual e-mail message.
frank26080115 0:bf7b9fba3924 233 * \param msglen The length of the e-mail message.
frank26080115 0:bf7b9fba3924 234 */
frank26080115 0:bf7b9fba3924 235 unsigned char
frank26080115 0:bf7b9fba3924 236 smtp_send(char *to, char *cc, char *from,
frank26080115 0:bf7b9fba3924 237 char *subject, char *msg, u16_t msglen)
frank26080115 0:bf7b9fba3924 238 {
frank26080115 0:bf7b9fba3924 239 struct uip_conn *conn;
frank26080115 0:bf7b9fba3924 240
frank26080115 0:bf7b9fba3924 241 conn = uip_connect(smtpserver, HTONS(25));
frank26080115 0:bf7b9fba3924 242 if(conn == NULL) {
frank26080115 0:bf7b9fba3924 243 return 0;
frank26080115 0:bf7b9fba3924 244 }
frank26080115 0:bf7b9fba3924 245 s.connected = 1;
frank26080115 0:bf7b9fba3924 246 s.to = to;
frank26080115 0:bf7b9fba3924 247 s.cc = cc;
frank26080115 0:bf7b9fba3924 248 s.from = from;
frank26080115 0:bf7b9fba3924 249 s.subject = subject;
frank26080115 0:bf7b9fba3924 250 s.msg = msg;
frank26080115 0:bf7b9fba3924 251 s.msglen = msglen;
frank26080115 0:bf7b9fba3924 252
frank26080115 0:bf7b9fba3924 253 PSOCK_INIT(&s.psock, s.inputbuffer, sizeof(s.inputbuffer));
frank26080115 0:bf7b9fba3924 254
frank26080115 0:bf7b9fba3924 255 return 1;
frank26080115 0:bf7b9fba3924 256 }
frank26080115 0:bf7b9fba3924 257 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 258 void
frank26080115 0:bf7b9fba3924 259 smtp_init(void)
frank26080115 0:bf7b9fba3924 260 {
frank26080115 0:bf7b9fba3924 261 s.connected = 0;
frank26080115 0:bf7b9fba3924 262 }
frank26080115 0:bf7b9fba3924 263 /*---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 264 /** @} */
frank26080115 0:bf7b9fba3924 265 /** @} */
frank26080115 0:bf7b9fba3924 266 /** @} */