source: network-demos/http/init.c @ 81f6c2e

4.11network-demos-4-10-branch
Last change on this file since 81f6c2e was 0fe6b0d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/09 at 14:31:53

2009-11-23 Joel Sherrill <joel.sherrill@…>

  • Makefile, goahead_index.html, init.c, shttpd_ext.c, shttpd_index.html: Add Mongoose HTTPD support.
  • mongoose_ext.c, mongoose_index.html: New files.
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *
5 *  Don't forget to change the IP addresses
6 */
7
8#include "system.h"
9#include <bsp.h>
10
11#include <errno.h>
12#include <time.h>
13
14#include <stdio.h>
15#include <rtems/rtems_bsdnet.h>
16#include <rtems/ftpd.h>
17#include <rtems/untar.h>
18
19     
20#include <rtems/error.h>
21#include <rpc/rpc.h>
22#include <netinet/in.h>
23#include <time.h>
24
25#include <arpa/inet.h>
26#include <sys/socket.h>
27#include "../networkconfig.h"
28
29#include <rtems_webserver.h>
30
31#define ARGUMENT 0
32
33/*
34 *  The tarfile image is built automatically externally.
35 */
36#include "FilesystemImage.h"
37
38#if defined(USE_FTPD)
39  bool FTPD_enabled = true;
40  struct rtems_ftpd_configuration rtems_ftpd_configuration = {
41    10,                     /* FTPD task priority            */
42    1024,                   /* Maximum buffersize for hooks  */
43    21,                     /* Well-known port     */
44    NULL,                   /* List of hooks       */
45    NULL,                   /* Root for FTPD or 0 for / */
46    0,                      /* Max. connections    */
47    0,                      /* Idle timeout in seoconds
48                               or 0 for no (inf) timeout */
49    0,                      /* 0 - r/w, 1 - read-only,
50                               2 - write-only,
51                               3 - browse-only */
52 };
53
54#else
55 bool FTPD_enabled = false;
56#endif
57
58#if defined(USE_GOAHEAD_HTTPD) && !defined(RTEMS_POSIX_API)
59  #warning "GoAhead server requires POSIX API - switching to SHTTPD"
60  #undef USE_GOAHEAD_HTTPD
61  #undef USE_SIMPLE_HTTPD
62#endif
63
64#if defined(USE_GOAHEAD_HTTPD)
65  bool GoAhead_HTTPD_enabled = true;
66
67  /* GoAhead Trace Handler */
68  #include <goahead/uemf.h>
69  void quietTraceHandler(int level, char *buf)
70  {
71    /* do nothing */
72  }
73#else
74  bool GoAhead_HTTPD_enabled = false;
75#endif
76
77#if defined(USE_SIMPLE_HTTPD)
78  bool Simple_HTTPD_enabled = true;
79
80  #include <shttpd/shttpd.h>
81#else
82  bool Simple_HTTPD_enabled = false;
83#endif
84
85#if defined(USE_MONGOOSE_HTTPD)
86  #include <mghttpd/mongoose.h>
87
88  void example_mongoose_addpages(
89    struct mg_context *server
90  );
91#endif
92
93#define bool2string(_b) ((_b) ? "true" : "false")
94
95#if defined(USE_SIMPLE_HTTPD)
96extern void example_shttpd_addpages(struct shttpd_ctx *ctx);
97#endif
98
99rtems_task Init(
100  rtems_task_argument argument
101)
102{
103  rtems_status_code status;
104
105  printf("\n\n*** HTTP TEST ***\n\r" );
106  printf("GoAhead HTTPD Enabled: %s\n", bool2string(GoAhead_HTTPD_enabled) );
107  printf("Simple HTTPD Enabled: %s\n", bool2string(Simple_HTTPD_enabled) );
108  printf("FTPD Enabled: %s\n", bool2string(FTPD_enabled) );
109  printf("\n");
110
111  /*
112   * Load filesystem image
113   */
114  printf("Loading filesystem image\n");
115  status = Untar_FromMemory( (char *)FilesystemImage, FilesystemImage_size );
116   
117  printf("Initializing Network\n");
118  rtems_bsdnet_initialize_network ();
119
120  #if defined(USE_FTPD)
121    printf( "Initializing FTPD\n" );
122    rtems_initialize_ftpd();
123  #endif
124
125  #if defined(USE_GOAHEAD_HTTPD)
126    printf( "Initializing GoAhead HTTPD\n" );
127    status = rtems_initialize_webserver();
128    if ( status )
129      printf( "ERROR -- failed to initialize webserver\n" );
130
131    traceSetHandler( quietTraceHandler );
132  #endif
133
134  #if defined(USE_SIMPLE_HTTPD)
135    /*
136     *  SHTTPD uses about 37K of stack even in this test on a PowerPC.
137     *  There is no point in doing math for the stack size.  Bump it
138     *  until there isn't a problem.
139     */
140    printf( "Initializing Simple HTTPD\n" );
141    status = rtems_initialize_webserver(
142      100,                             /* initial priority */
143      (48 * 1024),                     /* stack size */
144      RTEMS_DEFAULT_MODES,             /* initial modes */
145      RTEMS_DEFAULT_ATTRIBUTES,        /* attributes */
146      NULL,                            /* init_callback */
147      example_shttpd_addpages,         /* addpages_callback */
148      "/",                             /* initial priority */
149      80                               /* port to listen on */
150    );
151    if ( status )
152      printf( "ERROR -- failed to initialize webserver\n" );
153
154  #endif
155
156  #if defined(USE_MONGOOSE_HTTPD)
157    {
158      struct mg_context *WebServer;
159      printf( "Initializing Mongoose HTTPD\n" );
160      WebServer = mg_start();
161
162      mg_set_option(WebServer, "root", "/" );
163      mg_set_option(WebServer, "ports", "80" );
164      example_mongoose_addpages( WebServer );
165
166    }
167  #endif
168  status = rtems_task_delete( RTEMS_SELF );
169}
170
171
172/*
173 *  Configuration
174 */
175#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
176#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
177#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
178#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS        20
179#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
180
181#define CONFIGURE_EXECUTIVE_RAM_SIZE    (512*1024)
182#define CONFIGURE_MAXIMUM_SEMAPHORES    20
183#define CONFIGURE_MAXIMUM_TASKS         20
184
185#if defined(USE_MONGOOSE_HTTPD)
186#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
187#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 30
188#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
189#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (32 * 1024)
190#define CONFIGURE_UNIFIED_WORK_AREAS
191#endif
192
193#define CONFIGURE_MICROSECONDS_PER_TICK 10000
194
195#define CONFIGURE_INIT_TASK_STACK_SIZE  (10*1024)
196#define CONFIGURE_INIT_TASK_PRIORITY    120
197#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
198                                           RTEMS_NO_TIMESLICE | \
199                                           RTEMS_NO_ASR | \
200                                           RTEMS_INTERRUPT_LEVEL(0))
201
202#define CONFIGURE_STACK_CHECKER_ENABLED
203#define CONFIGURE_INIT
204
205#include <rtems/confdefs.h>
206
Note: See TracBrowser for help on using the repository browser.