My fork of the HTTPServer (working)

Dependents:   DGWWebServer LAN2

Committer:
screamer
Date:
Mon Aug 06 09:23:14 2012 +0000
Revision:
0:7a64fbb4069d
[mbed] converted /DGWWebServer/HTTPServer

Who changed what in which revision?

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