aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/Webserver/Lib/HTTPServerApp.h
blob: 11c39d87ed82ba9b9ba7432909890dfc8240d1a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *
 *  Header file for HTTPServerApp.c.
 */

#ifndef _HTTPSERVER_APP_H_
#define _HTTPSERVER_APP_H_

	/* Includes: */
		#include <avr/pgmspace.h>
		#include <string.h>

		#include <LUFA/Version.h>

		#include "Config/AppConfig.h"

		#include <uip.h>
		#include <ff.h>

	/* Enums: */
		/** States for each HTTP connection to the webserver. */
		enum Webserver_States_t
		{
			WEBSERVER_STATE_OpenRequestedFile, /**< Currently opening requested file */
			WEBSERVER_STATE_SendResponseHeader, /**< Currently sending HTTP response headers to the client */
			WEBSERVER_STATE_SendData, /**< Currently sending HTTP page data to the client */
			WEBSERVER_STATE_Closing, /**< Ready to close the connection to the client */
			WEBSERVER_STATE_Closed, /**< Connection closed after all data sent */
		};

	/* Type Defines: */
		/** Type define for a MIME type handler. */
		typedef struct
		{
			char* Extension; /**< File extension (no leading '.' character) */
			char* MIMEType;  /**< Appropriate MIME type to send when the extension is encountered */
		} MIME_Type_t;

	/* Macros: */
		/** TCP listen port for incoming HTTP traffic. */
		#define HTTP_SERVER_PORT  80

	/* Function Prototypes: */
		void HTTPServerApp_Init(void);
		void HTTPServerApp_Callback(void);

		#if defined(INCLUDE_FROM_HTTPSERVERAPP_C)
			static void HTTPServerApp_OpenRequestedFile(void);
			static void HTTPServerApp_SendResponseHeader(void);
			static void HTTPServerApp_SendData(void);
		#endif

#endif
/span> static inline uint16_t bswap16(uint16_t x) { return bswap_16(x); } static inline uint32_t bswap32(uint32_t x) { return bswap_32(x); } static inline uint64_t bswap64(uint64_t x) { return bswap_64(x); } static inline void bswap16s(uint16_t *s) { *s = bswap16(*s); } static inline void bswap32s(uint32_t *s) { *s = bswap32(*s); } static inline void bswap64s(uint64_t *s) { *s = bswap64(*s); } #if defined(WORDS_BIGENDIAN) #define be_bswap(v, size) (v) #define le_bswap(v, size) bswap ## size(v) #define be_bswaps(v, size) #define le_bswaps(p, size) *p = bswap ## size(*p); #else #define le_bswap(v, size) (v) #define be_bswap(v, size) bswap ## size(v) #define le_bswaps(v, size) #define be_bswaps(p, size) *p = bswap ## size(*p); #endif #define CPU_CONVERT(endian, size, type)\ static inline type endian ## size ## _to_cpu(type v)\ {\ return endian ## _bswap(v, size);\ }\ \ static inline type cpu_to_ ## endian ## size(type v)\ {\ return endian ## _bswap(v, size);\ }\ \ static inline void endian ## size ## _to_cpus(type *p)\ {\ endian ## _bswaps(p, size)\ }\ \ static inline void cpu_to_ ## endian ## size ## s(type *p)\ {\ endian ## _bswaps(p, size)\ }\ \ static inline type endian ## size ## _to_cpup(const type *p)\ {\ return endian ## size ## _to_cpu(*p);\ }\ \ static inline void cpu_to_ ## endian ## size ## w(type *p, type v)\ {\ *p = cpu_to_ ## endian ## size(v);\ } CPU_CONVERT(be, 16, uint16_t) CPU_CONVERT(be, 32, uint32_t) CPU_CONVERT(be, 64, uint64_t) CPU_CONVERT(le, 16, uint16_t) CPU_CONVERT(le, 32, uint32_t) CPU_CONVERT(le, 64, uint64_t) /* unaligned versions (optimized for frequent unaligned accesses)*/ #if defined(__i386__) || defined(__powerpc__) #define cpu_to_le16wu(p, v) cpu_to_le16w(p, v) #define cpu_to_le32wu(p, v) cpu_to_le32w(p, v) #define le16_to_cpupu(p) le16_to_cpup(p) #define le32_to_cpupu(p) le32_to_cpup(p) #define cpu_to_be16wu(p, v) cpu_to_be16w(p, v) #define cpu_to_be32wu(p, v) cpu_to_be32w(p, v) #else static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) { uint8_t *p1 = (uint8_t *)p; p1[0] = v; p1[1] = v >> 8; } static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) { uint8_t *p1 = (uint8_t *)p; p1[0] = v; p1[1] = v >> 8; p1[2] = v >> 16; p1[3] = v >> 24; } static inline uint16_t le16_to_cpupu(const uint16_t *p) { const uint8_t *p1 = (const uint8_t *)p; return p1[0] | (p1[1] << 8); } static inline uint32_t le32_to_cpupu(const uint32_t *p) { const uint8_t *p1 = (const uint8_t *)p; return p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); } static inline void cpu_to_be16wu(uint16_t *p, uint16_t v) { uint8_t *p1 = (uint8_t *)p; p1[0] = v >> 8; p1[1] = v; } static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) { uint8_t *p1 = (uint8_t *)p; p1[0] = v >> 24; p1[1] = v >> 16; p1[2] = v >> 8; p1[3] = v; } #endif #ifdef WORDS_BIGENDIAN #define cpu_to_32wu cpu_to_be32wu #else #define cpu_to_32wu cpu_to_le32wu #endif #undef le_bswap #undef be_bswap #undef le_bswaps #undef be_bswaps #endif /* BSWAP_H */