summaryrefslogtreecommitdiff
path: root/http/init.c
blob: 7f0c146514baf94352d63328aacca97f42cc0934 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*  Init
 *
 *  This routine is the initialization task for this test program.
 *
 *  Don't forget to change the IP addresses
 */

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS	20
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

#define CONFIGURE_EXECUTIVE_RAM_SIZE	(512*1024)
#define CONFIGURE_MAXIMUM_SEMAPHORES	20
#define CONFIGURE_MAXIMUM_TASKS		20

#define CONFIGURE_MICROSECONDS_PER_TICK	10000

#define CONFIGURE_INIT_TASK_STACK_SIZE	(10*1024)
#define CONFIGURE_INIT_TASK_PRIORITY	120
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
                                           RTEMS_NO_TIMESLICE | \
                                           RTEMS_NO_ASR | \
                                           RTEMS_INTERRUPT_LEVEL(0))

#define CONFIGURE_INIT

#include "system.h"
#include <bsp.h>

#include <errno.h>
#include <time.h>

#include <rtems/confdefs.h>
#include <stdio.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/ftpd.h>
#include <rtems/untar.h>

     
#include <rtems/error.h>
#include <rpc/rpc.h>
#include <netinet/in.h>
#include <time.h>

#include <arpa/inet.h>
#include <sys/socket.h>
#include "../networkconfig.h"

#include <rtems_webserver.h>

#define ARGUMENT 0

/*
 *  The tarfile is built automatically externally so we need to account
 *  for the leading symbol on the names.
 */
#if defined(__sh__)
  #define SYM(_x) _x
#else
  #define SYM(_x) _ ## _x
#endif

extern int SYM(binary_tarfile_start);
extern int SYM(binary_tarfile_size);
#define TARFILE_START SYM(binary_tarfile_start)
#define TARFILE_SIZE SYM(binary_tarfile_size)

#if defined(USE_FTPD)
  boolean FTPD_enabled = TRUE;
  struct rtems_ftpd_configuration rtems_ftpd_configuration = {
    10,                     /* FTPD task priority            */
    1024,                   /* Maximum buffersize for hooks  */
    21,                     /* Well-known port     */
    NULL                    /* List of hooks       */
 };
#else
 boolean FTPD_enabled = FALSE;
#endif

#if defined(USE_GOAHEAD_HTTPD)
  boolean GoAhead_HTTPD_enabled = TRUE;

  /* GoAhead Trace Handler */
  #include <goahead/uemf.h>
  void quietTraceHandler(int level, char *buf)
  {
    /* do nothing */
  }
#else
  boolean GoAhead_HTTPD_enabled = FALSE;
#endif

#if defined(USE_SIMPLE_HTTPD)
  boolean Simple_HTTPD_enabled = TRUE;

  #include <shttpd/shttpd.h>
#else
  boolean Simple_HTTPD_enabled = FALSE;
#endif

#define bool2string(_b) ((_b) ? "true" : "false")

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;

  printf("\n\n*** HTTP TEST ***\n\r" );
  printf("GoAhead HTTPD Enabled: %s\n", bool2string(GoAhead_HTTPD_enabled) );
  printf("Simple HTTPD Enabled: %s\n", bool2string(Simple_HTTPD_enabled) );
  printf("FTPD Enabled: %s\n", bool2string(FTPD_enabled) );
  printf("\n");

  /*
   * Load filesystem image
   */
  printf("Loading filesystem image");
  status = Untar_FromMemory((void *)(&TARFILE_START), (size_t)&TARFILE_SIZE);
   
  printf("Initializing Network");
  rtems_bsdnet_initialize_network ();

  #if defined(USE_FTPD)
    printf( "Initializing FTPD\n" );
    rtems_initialize_ftpd();
  #endif

  #if defined(USE_GOAHEAD_HTTPD)
    printf( "Initializing GoAhead HTTPD\n" );
    status = rtems_initialize_webserver();
    if ( status )
      printf( "ERROR -- failed to initialize webserver\n" );

    traceSetHandler( quietTraceHandler );
  #endif

  #if defined(USE_SIMPLE_HTTPD)
    printf( "Initializing Simple HTTPD\n" );
    status = rtems_initialize_webserver(
      100,                             /* initial priority */
      RTEMS_MINIMUM_STACK_SIZE * 2,    /* stack size */
      RTEMS_DEFAULT_MODES,             /* initial modes */
      RTEMS_DEFAULT_ATTRIBUTES,        /* attributes */
      NULL,                            /* init_callback */
      NULL,                            /* addpages_callback */
      "/",                             /* initial priority */
      80                               /* port to listen on */
    );
    if ( status )
      printf( "ERROR -- failed to initialize webserver\n" );

  #endif

  status = rtems_task_delete( RTEMS_SELF );
}