Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewbonney 0:ec559500a63f 1 /*
andrewbonney 0:ec559500a63f 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
andrewbonney 0:ec559500a63f 3 * All rights reserved.
andrewbonney 0:ec559500a63f 4 *
andrewbonney 0:ec559500a63f 5 * Redistribution and use in source and binary forms, with or without modification,
andrewbonney 0:ec559500a63f 6 * are permitted provided that the following conditions are met:
andrewbonney 0:ec559500a63f 7 *
andrewbonney 0:ec559500a63f 8 * 1. Redistributions of source code must retain the above copyright notice,
andrewbonney 0:ec559500a63f 9 * this list of conditions and the following disclaimer.
andrewbonney 0:ec559500a63f 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
andrewbonney 0:ec559500a63f 11 * this list of conditions and the following disclaimer in the documentation
andrewbonney 0:ec559500a63f 12 * and/or other materials provided with the distribution.
andrewbonney 0:ec559500a63f 13 * 3. The name of the author may not be used to endorse or promote products
andrewbonney 0:ec559500a63f 14 * derived from this software without specific prior written permission.
andrewbonney 0:ec559500a63f 15 *
andrewbonney 0:ec559500a63f 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
andrewbonney 0:ec559500a63f 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
andrewbonney 0:ec559500a63f 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
andrewbonney 0:ec559500a63f 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
andrewbonney 0:ec559500a63f 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
andrewbonney 0:ec559500a63f 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
andrewbonney 0:ec559500a63f 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
andrewbonney 0:ec559500a63f 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
andrewbonney 0:ec559500a63f 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
andrewbonney 0:ec559500a63f 25 * OF SUCH DAMAGE.
andrewbonney 0:ec559500a63f 26 *
andrewbonney 0:ec559500a63f 27 * This file is part of the lwIP TCP/IP stack.
andrewbonney 0:ec559500a63f 28 *
andrewbonney 0:ec559500a63f 29 * Author: Adam Dunkels <adam@sics.se>
andrewbonney 0:ec559500a63f 30 *
andrewbonney 0:ec559500a63f 31 */
andrewbonney 0:ec559500a63f 32 #ifndef __LWIP_API_MSG_H__
andrewbonney 0:ec559500a63f 33 #define __LWIP_API_MSG_H__
andrewbonney 0:ec559500a63f 34
andrewbonney 0:ec559500a63f 35 #include "lwip/opt.h"
andrewbonney 0:ec559500a63f 36
andrewbonney 0:ec559500a63f 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
andrewbonney 0:ec559500a63f 38
andrewbonney 0:ec559500a63f 39 #include <stddef.h> /* for size_t */
andrewbonney 0:ec559500a63f 40
andrewbonney 0:ec559500a63f 41 #include "lwip/ip_addr.h"
andrewbonney 0:ec559500a63f 42 #include "lwip/err.h"
andrewbonney 0:ec559500a63f 43 #include "lwip/sys.h"
andrewbonney 0:ec559500a63f 44 #include "lwip/igmp.h"
andrewbonney 0:ec559500a63f 45 #include "lwip/api.h"
andrewbonney 0:ec559500a63f 46
andrewbonney 0:ec559500a63f 47 #ifdef __cplusplus
andrewbonney 0:ec559500a63f 48 extern "C" {
andrewbonney 0:ec559500a63f 49 #endif
andrewbonney 0:ec559500a63f 50
andrewbonney 0:ec559500a63f 51 #define NETCONN_SHUT_RD 1
andrewbonney 0:ec559500a63f 52 #define NETCONN_SHUT_WR 2
andrewbonney 0:ec559500a63f 53 #define NETCONN_SHUT_RDWR 3
andrewbonney 0:ec559500a63f 54
andrewbonney 0:ec559500a63f 55 /* IP addresses and port numbers are expected to be in
andrewbonney 0:ec559500a63f 56 * the same byte order as in the corresponding pcb.
andrewbonney 0:ec559500a63f 57 */
andrewbonney 0:ec559500a63f 58 /** This struct includes everything that is necessary to execute a function
andrewbonney 0:ec559500a63f 59 for a netconn in another thread context (mainly used to process netconns
andrewbonney 0:ec559500a63f 60 in the tcpip_thread context to be thread safe). */
andrewbonney 0:ec559500a63f 61 struct api_msg_msg {
andrewbonney 0:ec559500a63f 62 /** The netconn which to process - always needed: it includes the semaphore
andrewbonney 0:ec559500a63f 63 which is used to block the application thread until the function finished. */
andrewbonney 0:ec559500a63f 64 struct netconn *conn;
andrewbonney 0:ec559500a63f 65 /** The return value of the function executed in tcpip_thread. */
andrewbonney 0:ec559500a63f 66 err_t err;
andrewbonney 0:ec559500a63f 67 /** Depending on the executed function, one of these union members is used */
andrewbonney 0:ec559500a63f 68 union {
andrewbonney 0:ec559500a63f 69 /** used for do_send */
andrewbonney 0:ec559500a63f 70 struct netbuf *b;
andrewbonney 0:ec559500a63f 71 /** used for do_newconn */
andrewbonney 0:ec559500a63f 72 struct {
andrewbonney 0:ec559500a63f 73 u8_t proto;
andrewbonney 0:ec559500a63f 74 } n;
andrewbonney 0:ec559500a63f 75 /** used for do_bind and do_connect */
andrewbonney 0:ec559500a63f 76 struct {
andrewbonney 0:ec559500a63f 77 ip_addr_t *ipaddr;
andrewbonney 0:ec559500a63f 78 u16_t port;
andrewbonney 0:ec559500a63f 79 } bc;
andrewbonney 0:ec559500a63f 80 /** used for do_getaddr */
andrewbonney 0:ec559500a63f 81 struct {
andrewbonney 0:ec559500a63f 82 ip_addr_t *ipaddr;
andrewbonney 0:ec559500a63f 83 u16_t *port;
andrewbonney 0:ec559500a63f 84 u8_t local;
andrewbonney 0:ec559500a63f 85 } ad;
andrewbonney 0:ec559500a63f 86 /** used for do_write */
andrewbonney 0:ec559500a63f 87 struct {
andrewbonney 0:ec559500a63f 88 const void *dataptr;
andrewbonney 0:ec559500a63f 89 size_t len;
andrewbonney 0:ec559500a63f 90 u8_t apiflags;
andrewbonney 0:ec559500a63f 91 } w;
andrewbonney 0:ec559500a63f 92 /** used for do_recv */
andrewbonney 0:ec559500a63f 93 struct {
andrewbonney 0:ec559500a63f 94 u32_t len;
andrewbonney 0:ec559500a63f 95 } r;
andrewbonney 0:ec559500a63f 96 /** used for do_close (/shutdown) */
andrewbonney 0:ec559500a63f 97 struct {
andrewbonney 0:ec559500a63f 98 u8_t shut;
andrewbonney 0:ec559500a63f 99 } sd;
andrewbonney 0:ec559500a63f 100 #if LWIP_IGMP
andrewbonney 0:ec559500a63f 101 /** used for do_join_leave_group */
andrewbonney 0:ec559500a63f 102 struct {
andrewbonney 0:ec559500a63f 103 ip_addr_t *multiaddr;
andrewbonney 0:ec559500a63f 104 ip_addr_t *netif_addr;
andrewbonney 0:ec559500a63f 105 enum netconn_igmp join_or_leave;
andrewbonney 0:ec559500a63f 106 } jl;
andrewbonney 0:ec559500a63f 107 #endif /* LWIP_IGMP */
andrewbonney 0:ec559500a63f 108 #if TCP_LISTEN_BACKLOG
andrewbonney 0:ec559500a63f 109 struct {
andrewbonney 0:ec559500a63f 110 u8_t backlog;
andrewbonney 0:ec559500a63f 111 } lb;
andrewbonney 0:ec559500a63f 112 #endif /* TCP_LISTEN_BACKLOG */
andrewbonney 0:ec559500a63f 113 } msg;
andrewbonney 0:ec559500a63f 114 };
andrewbonney 0:ec559500a63f 115
andrewbonney 0:ec559500a63f 116 /** This struct contains a function to execute in another thread context and
andrewbonney 0:ec559500a63f 117 a struct api_msg_msg that serves as an argument for this function.
andrewbonney 0:ec559500a63f 118 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
andrewbonney 0:ec559500a63f 119 struct api_msg {
andrewbonney 0:ec559500a63f 120 /** function to execute in tcpip_thread context */
andrewbonney 0:ec559500a63f 121 void (* function)(struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 122 /** arguments for this function */
andrewbonney 0:ec559500a63f 123 struct api_msg_msg msg;
andrewbonney 0:ec559500a63f 124 };
andrewbonney 0:ec559500a63f 125
andrewbonney 0:ec559500a63f 126 #if LWIP_DNS
andrewbonney 0:ec559500a63f 127 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
andrewbonney 0:ec559500a63f 128 it has its own struct (to avoid struct api_msg getting bigger than necessary).
andrewbonney 0:ec559500a63f 129 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
andrewbonney 0:ec559500a63f 130 (see netconn_gethostbyname). */
andrewbonney 0:ec559500a63f 131 struct dns_api_msg {
andrewbonney 0:ec559500a63f 132 /** Hostname to query or dotted IP address string */
andrewbonney 0:ec559500a63f 133 const char *name;
andrewbonney 0:ec559500a63f 134 /** Rhe resolved address is stored here */
andrewbonney 0:ec559500a63f 135 ip_addr_t *addr;
andrewbonney 0:ec559500a63f 136 /** This semaphore is posted when the name is resolved, the application thread
andrewbonney 0:ec559500a63f 137 should wait on it. */
andrewbonney 0:ec559500a63f 138 sys_sem_t *sem;
andrewbonney 0:ec559500a63f 139 /** Errors are given back here */
andrewbonney 0:ec559500a63f 140 err_t *err;
andrewbonney 0:ec559500a63f 141 };
andrewbonney 0:ec559500a63f 142 #endif /* LWIP_DNS */
andrewbonney 0:ec559500a63f 143
andrewbonney 0:ec559500a63f 144 void do_newconn ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 145 void do_delconn ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 146 void do_bind ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 147 void do_connect ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 148 void do_disconnect ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 149 void do_listen ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 150 void do_send ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 151 void do_recv ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 152 void do_write ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 153 void do_getaddr ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 154 void do_close ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 155 void do_shutdown ( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 156 #if LWIP_IGMP
andrewbonney 0:ec559500a63f 157 void do_join_leave_group( struct api_msg_msg *msg);
andrewbonney 0:ec559500a63f 158 #endif /* LWIP_IGMP */
andrewbonney 0:ec559500a63f 159
andrewbonney 0:ec559500a63f 160 #if LWIP_DNS
andrewbonney 0:ec559500a63f 161 void do_gethostbyname(void *arg);
andrewbonney 0:ec559500a63f 162 #endif /* LWIP_DNS */
andrewbonney 0:ec559500a63f 163
andrewbonney 0:ec559500a63f 164 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
andrewbonney 0:ec559500a63f 165 void netconn_free(struct netconn *conn);
andrewbonney 0:ec559500a63f 166
andrewbonney 0:ec559500a63f 167 #ifdef __cplusplus
andrewbonney 0:ec559500a63f 168 }
andrewbonney 0:ec559500a63f 169 #endif
andrewbonney 0:ec559500a63f 170
andrewbonney 0:ec559500a63f 171 #endif /* LWIP_NETCONN */
andrewbonney 0:ec559500a63f 172
andrewbonney 0:ec559500a63f 173 #endif /* __LWIP_API_MSG_H__ */