TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:075157567b0c 1 /*
nxpfan 0:075157567b0c 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
nxpfan 0:075157567b0c 3 * All rights reserved.
nxpfan 0:075157567b0c 4 *
nxpfan 0:075157567b0c 5 * Redistribution and use in source and binary forms, with or without modification,
nxpfan 0:075157567b0c 6 * are permitted provided that the following conditions are met:
nxpfan 0:075157567b0c 7 *
nxpfan 0:075157567b0c 8 * 1. Redistributions of source code must retain the above copyright notice,
nxpfan 0:075157567b0c 9 * this list of conditions and the following disclaimer.
nxpfan 0:075157567b0c 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
nxpfan 0:075157567b0c 11 * this list of conditions and the following disclaimer in the documentation
nxpfan 0:075157567b0c 12 * and/or other materials provided with the distribution.
nxpfan 0:075157567b0c 13 * 3. The name of the author may not be used to endorse or promote products
nxpfan 0:075157567b0c 14 * derived from this software without specific prior written permission.
nxpfan 0:075157567b0c 15 *
nxpfan 0:075157567b0c 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
nxpfan 0:075157567b0c 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
nxpfan 0:075157567b0c 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
nxpfan 0:075157567b0c 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
nxpfan 0:075157567b0c 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
nxpfan 0:075157567b0c 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
nxpfan 0:075157567b0c 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
nxpfan 0:075157567b0c 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
nxpfan 0:075157567b0c 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
nxpfan 0:075157567b0c 25 * OF SUCH DAMAGE.
nxpfan 0:075157567b0c 26 *
nxpfan 0:075157567b0c 27 * This file is part of the lwIP TCP/IP stack.
nxpfan 0:075157567b0c 28 *
nxpfan 0:075157567b0c 29 * Author: Adam Dunkels <adam@sics.se>
nxpfan 0:075157567b0c 30 *
nxpfan 0:075157567b0c 31 */
nxpfan 0:075157567b0c 32 #ifndef __LWIP_UDP_H__
nxpfan 0:075157567b0c 33 #define __LWIP_UDP_H__
nxpfan 0:075157567b0c 34
nxpfan 0:075157567b0c 35 #include "lwip/opt.h"
nxpfan 0:075157567b0c 36
nxpfan 0:075157567b0c 37 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
nxpfan 0:075157567b0c 38
nxpfan 0:075157567b0c 39 #include "lwip/pbuf.h"
nxpfan 0:075157567b0c 40 #include "lwip/netif.h"
nxpfan 0:075157567b0c 41 #include "lwip/ip_addr.h"
nxpfan 0:075157567b0c 42 #include "lwip/ip.h"
nxpfan 0:075157567b0c 43
nxpfan 0:075157567b0c 44 #ifdef __cplusplus
nxpfan 0:075157567b0c 45 extern "C" {
nxpfan 0:075157567b0c 46 #endif
nxpfan 0:075157567b0c 47
nxpfan 0:075157567b0c 48 #define UDP_HLEN 8
nxpfan 0:075157567b0c 49
nxpfan 0:075157567b0c 50 /* Fields are (of course) in network byte order. */
nxpfan 0:075157567b0c 51 #ifdef PACK_STRUCT_USE_INCLUDES
nxpfan 0:075157567b0c 52 # include "arch/bpstruct.h"
nxpfan 0:075157567b0c 53 #endif
nxpfan 0:075157567b0c 54 PACK_STRUCT_BEGIN
nxpfan 0:075157567b0c 55 struct udp_hdr {
nxpfan 0:075157567b0c 56 PACK_STRUCT_FIELD(u16_t src);
nxpfan 0:075157567b0c 57 PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
nxpfan 0:075157567b0c 58 PACK_STRUCT_FIELD(u16_t len);
nxpfan 0:075157567b0c 59 PACK_STRUCT_FIELD(u16_t chksum);
nxpfan 0:075157567b0c 60 } PACK_STRUCT_STRUCT;
nxpfan 0:075157567b0c 61 PACK_STRUCT_END
nxpfan 0:075157567b0c 62 #ifdef PACK_STRUCT_USE_INCLUDES
nxpfan 0:075157567b0c 63 # include "arch/epstruct.h"
nxpfan 0:075157567b0c 64 #endif
nxpfan 0:075157567b0c 65
nxpfan 0:075157567b0c 66 #define UDP_FLAGS_NOCHKSUM 0x01U
nxpfan 0:075157567b0c 67 #define UDP_FLAGS_UDPLITE 0x02U
nxpfan 0:075157567b0c 68 #define UDP_FLAGS_CONNECTED 0x04U
nxpfan 0:075157567b0c 69 #define UDP_FLAGS_MULTICAST_LOOP 0x08U
nxpfan 0:075157567b0c 70
nxpfan 0:075157567b0c 71 struct udp_pcb;
nxpfan 0:075157567b0c 72
nxpfan 0:075157567b0c 73 /** Function prototype for udp pcb receive callback functions
nxpfan 0:075157567b0c 74 * addr and port are in same byte order as in the pcb
nxpfan 0:075157567b0c 75 * The callback is responsible for freeing the pbuf
nxpfan 0:075157567b0c 76 * if it's not used any more.
nxpfan 0:075157567b0c 77 *
nxpfan 0:075157567b0c 78 * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
nxpfan 0:075157567b0c 79 * makes 'addr' invalid, too.
nxpfan 0:075157567b0c 80 *
nxpfan 0:075157567b0c 81 * @param arg user supplied argument (udp_pcb.recv_arg)
nxpfan 0:075157567b0c 82 * @param pcb the udp_pcb which received data
nxpfan 0:075157567b0c 83 * @param p the packet buffer that was received
nxpfan 0:075157567b0c 84 * @param addr the remote IP address from which the packet was received
nxpfan 0:075157567b0c 85 * @param port the remote port from which the packet was received
nxpfan 0:075157567b0c 86 */
nxpfan 0:075157567b0c 87 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 88 ip_addr_t *addr, u16_t port);
nxpfan 0:075157567b0c 89
nxpfan 0:075157567b0c 90
nxpfan 0:075157567b0c 91 struct udp_pcb {
nxpfan 0:075157567b0c 92 /* Common members of all PCB types */
nxpfan 0:075157567b0c 93 IP_PCB;
nxpfan 0:075157567b0c 94
nxpfan 0:075157567b0c 95 /* Protocol specific PCB members */
nxpfan 0:075157567b0c 96
nxpfan 0:075157567b0c 97 struct udp_pcb *next;
nxpfan 0:075157567b0c 98
nxpfan 0:075157567b0c 99 u8_t flags;
nxpfan 0:075157567b0c 100 /** ports are in host byte order */
nxpfan 0:075157567b0c 101 u16_t local_port, remote_port;
nxpfan 0:075157567b0c 102
nxpfan 0:075157567b0c 103 #if LWIP_IGMP
nxpfan 0:075157567b0c 104 /** outgoing network interface for multicast packets */
nxpfan 0:075157567b0c 105 ip_addr_t multicast_ip;
nxpfan 0:075157567b0c 106 #endif /* LWIP_IGMP */
nxpfan 0:075157567b0c 107
nxpfan 0:075157567b0c 108 #if LWIP_UDPLITE
nxpfan 0:075157567b0c 109 /** used for UDP_LITE only */
nxpfan 0:075157567b0c 110 u16_t chksum_len_rx, chksum_len_tx;
nxpfan 0:075157567b0c 111 #endif /* LWIP_UDPLITE */
nxpfan 0:075157567b0c 112
nxpfan 0:075157567b0c 113 /** receive callback function */
nxpfan 0:075157567b0c 114 udp_recv_fn recv;
nxpfan 0:075157567b0c 115 /** user-supplied argument for the recv callback */
nxpfan 0:075157567b0c 116 void *recv_arg;
nxpfan 0:075157567b0c 117 };
nxpfan 0:075157567b0c 118 /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
nxpfan 0:075157567b0c 119 extern struct udp_pcb *udp_pcbs;
nxpfan 0:075157567b0c 120
nxpfan 0:075157567b0c 121 /* The following functions is the application layer interface to the
nxpfan 0:075157567b0c 122 UDP code. */
nxpfan 0:075157567b0c 123 struct udp_pcb * udp_new (void);
nxpfan 0:075157567b0c 124 void udp_remove (struct udp_pcb *pcb);
nxpfan 0:075157567b0c 125 err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr,
nxpfan 0:075157567b0c 126 u16_t port);
nxpfan 0:075157567b0c 127 err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr,
nxpfan 0:075157567b0c 128 u16_t port);
nxpfan 0:075157567b0c 129 void udp_disconnect (struct udp_pcb *pcb);
nxpfan 0:075157567b0c 130 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
nxpfan 0:075157567b0c 131 void *recv_arg);
nxpfan 0:075157567b0c 132 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 133 ip_addr_t *dst_ip, u16_t dst_port,
nxpfan 0:075157567b0c 134 struct netif *netif);
nxpfan 0:075157567b0c 135 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 136 ip_addr_t *dst_ip, u16_t dst_port);
nxpfan 0:075157567b0c 137 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
nxpfan 0:075157567b0c 138
nxpfan 0:075157567b0c 139 #if LWIP_CHECKSUM_ON_COPY
nxpfan 0:075157567b0c 140 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 141 ip_addr_t *dst_ip, u16_t dst_port,
nxpfan 0:075157567b0c 142 struct netif *netif, u8_t have_chksum,
nxpfan 0:075157567b0c 143 u16_t chksum);
nxpfan 0:075157567b0c 144 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 145 ip_addr_t *dst_ip, u16_t dst_port,
nxpfan 0:075157567b0c 146 u8_t have_chksum, u16_t chksum);
nxpfan 0:075157567b0c 147 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
nxpfan 0:075157567b0c 148 u8_t have_chksum, u16_t chksum);
nxpfan 0:075157567b0c 149 #endif /* LWIP_CHECKSUM_ON_COPY */
nxpfan 0:075157567b0c 150
nxpfan 0:075157567b0c 151 #define udp_flags(pcb) ((pcb)->flags)
nxpfan 0:075157567b0c 152 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
nxpfan 0:075157567b0c 153
nxpfan 0:075157567b0c 154 /* The following functions are the lower layer interface to UDP. */
nxpfan 0:075157567b0c 155 void udp_input (struct pbuf *p, struct netif *inp);
nxpfan 0:075157567b0c 156
nxpfan 0:075157567b0c 157 #define udp_init() /* Compatibility define, not init needed. */
nxpfan 0:075157567b0c 158
nxpfan 0:075157567b0c 159 #if UDP_DEBUG
nxpfan 0:075157567b0c 160 void udp_debug_print(struct udp_hdr *udphdr);
nxpfan 0:075157567b0c 161 #else
nxpfan 0:075157567b0c 162 #define udp_debug_print(udphdr)
nxpfan 0:075157567b0c 163 #endif
nxpfan 0:075157567b0c 164
nxpfan 0:075157567b0c 165 #ifdef __cplusplus
nxpfan 0:075157567b0c 166 }
nxpfan 0:075157567b0c 167 #endif
nxpfan 0:075157567b0c 168
nxpfan 0:075157567b0c 169 #endif /* LWIP_UDP */
nxpfan 0:075157567b0c 170
nxpfan 0:075157567b0c 171 #endif /* __LWIP_UDP_H__ */