Migration of goahead to Web Server

Source: Internet
Author: User
Note: Recently I am working on a GoAhead Web server and porting it to Ti chip + linux. Here I will first turn to a related article to learn about it. I hope it will be helpful...
*******************************
* Migration of goahead to Web Server *
*******************************
2009/02/14 asdjf@163.com www.armecos.com

Many people want to use web server in their products. Therefore, we have summarized more than a dozen Web Server choices. Web server development is no longer a difficult task.

This document introduces powerful Embedded Web Server goahead !!!
Its main features are:

1. Supports ASP.
2. embedded Javascript --- ejscript.
3. Supports Standard CGI.
4. Supports CGI processing in the memory.
5. Fast response. More than 65 requests can be processed per second.
6. comply with HTTP 1.0/HTTP 1.1 standards.
7. There are many extended APIs for user development.
8. SSL 3.0 is supported.
9. Supports user group management.
10. Supports DAA access authentication.
11. Small memory. If SSL is not included, only 60 kb of memory is required: SSL is included and KB of memory is required.
12. Web pages can exist in ROM or file system.
13. multiple operating systems are supported, such as ECOs, Linux, lynxos, QNX, VxWorks, WinCE, and PSOs.


Figure 1 goahead Running Effect.

Figure 2 Structure of the goahead source program

GoAhead Web Server is a small and exquisite Web Server launched by goahead in the early days that can run on a variety of platforms. It has good portability, open source code, and a small amount of code. The GoAhead Web server is particularly suitable for embedded systems.

GoAhead Web Server detailed documentation is located in the webs/docs directory goahead source code, the source code can be downloaded from the http://www.goahead.com. Note: currently, ECOs does not support user groups. Therefore, ECOs does not support goahead's user management and access control functions.

Decompress the goahead source code to the/g directory. You can see that the goahead source code structure is as follows:
/G
|
| \______ Various OS migration subdirectories (for example, ECOs subdirectories)
| \______ Web self-directory (used to save the self-designed webpage)
| \ ______ Goahead Server Source Code (C program)
\ ______ Webcomp. CNET page Compiler

Unlike the common web server, the web pages (such as ASP and HTML) We designed are parsed during the compilation phase and compiled together with the server source code, instead of reading webpages and parsing Content in the running stage like other servers.

The webcomp. c web page compiler under the root directory of goahead is responsible for converting all web pages under the web sub-directory so that it can be compiled together with the GoAhead Web Server Source Code and other ECOs application code.
The web sub-directory contains all web page content. All web pages of the web server must be placed in this directory.
The ECOs subdirectory contains interfaces with ECOs, including the main. c file and MAKEFILE file. You can modify the main. C and makefile files as needed.

According to the MAKEFILE file in the ECOS directory, there are three steps to compile the GoAhead Web Server:
1. Compile the webcomp.c file to generate the web page editor webcomp.exe. Webcomp. C is compiled using the local compiler GCC. The compiled webpage compiler is located under the ECOS subdirectory. The web page compiler converts all web pages in the Web subdirectory and generates the webcomp. c file. The webcomp. c file is stored in the ECOS subdirectory.
2. The cross compiler compiles the Web Server Source Code and webcomp. c file under the root directory of goahead to generate the library file libwebs..
3. the ECOS application is linked to the library file libwebs. A during compilation to generate executable files that can run on the target platform.

The MAKEFILE file in the ECOS subdirectory is shown in the following figure.

# ECOs makefile
ALL: Compile
#
# These definitions come from your ECOs install tree
#
Debug: =-g-wall-O2
# For Cirrus Logic edb72xx Board
Pkg_install_dir: =/tmp/untitled_install
Command_prefix: = arm-elf-
Cflags: =-mcpu = ARM7TDMI $ (Debug)
# For Motorola PowerPC mbx/860
# Pkg_install_dir: =/work/net_mbx/install
# Command_prefix: = PowerPC-Eabi-
# Cflags: =-mcpu = 860-msoft-float $ (Debug)
#
# These shoshould not need to be changed
#
Cc: = $ (command_prefix) GCC
Objcopy: = $ (command_prefix) objcopy
AR: = $ (command_prefix) Ar
Ldflags =-nostartfiles-L $ (pkg_install_dir)/lib-wl, -- GC-sections $ (libs)
Libs =-ttarget. LD-nostdlib
Cxxflags = $ (cflags)
Extracflags =-wall-I $ (pkg_install_dir)/include-ffunction-sections-fdata-Sections
Extracxxflags = $ (extracflags)-fno-exceptions-fno-rtti-fvtable-GC-Finit-priority
# ECOs build rules
%. O: %. c
$ (CC)-c-o $ *. o $ (cflags) $ (extracflags)-WP,-MD, $ *. d $/dev/null
%. O: %. cxx
$ (Cxx)-c-o $ *. o $ (cxxflags) $ (extracxxflags) $. depend
#
# Build archive of Objects
#
$ (ARCH): $ (obj_files)
$ (AR) $ (arflags) $ (ARCH) $?
#
# Primary link
#
$ (Name): makefile main. o $ (ARCH)
$ (CC)-o $ (name) $ (cflags) $ (iflags )\
Main. o $ (ARCH) $ (ldflags)
Clean:
Rm-F $ (name) $ (ARCH) $ (depend_files) $ (obj_files)
Rm-F Main. O webrom. c webcomp web_files. depend
#
# This tool needs to be built using the native C Compiler
#
Webcomp:
Gcc-O webcomp-O2-dwebs-duemf-dos = "Linux"-dlinux-d_struct_timeval-I.../webcomp. c
#
# Build a set of romable pages
#
Webrom. C: webcomp
Find ../Web-name "*. *"> web_files
./Webcomp ../Web web_files> webrom. c
# Dependencies
-Include. depend
We modified several definitions in makefile:
1. pkg_install_dir: =/tmp/untitled_install points to the system library file provided by the ECOS value-added package.
2. Change CC to GCC, And the compiler to GCC in cygwin environment. Add the-d_struct_timeval definition to avoid conflicts between the struct timeval struct definition in UEMF. h and the existing definition in the ECOS library.
Gcc-O webcomp-O2-dwebs-duemf-dos = "Linux"-dlinux-d_struct_timeval-I.../webcomp. c
In addition to makefile modification, the main. c file needs to comment out the final send () and Recv () function definitions because they are in conflict with existing definitions in the ECOS library.
/*************************************** ***************************************/
/*
* Wrappers for depreciated socket I/O functions
*/
/*
Int send (int s, const void * Buf, size_t Len, int flags)
{
Return write (S, Buf, Len );
}
Int Recv (int s, void * Buf, size_t Len, int flags)
{
Return read (S, Buf, Len );
}
*/
/*************************************** ***************************************/
Add the following definitions to the sockgen. c file in the root directory to avoid compilation errors.
# Include "sys/select. H"
# Define nfdbits _ nfdbits

The following definitions in UEMF. h In the root directory conflict with each other. Just comment them out.
// # Define o_rdonly 1
Add the following references to wsintrn. h In the root directory to avoid compilation errors.
# Ifdef ECOs
# Include
# Include
# Endif
All of the above are modifications to the goahead itself. For our applications, we also need to modify the main. c file under the ECOS directory. During migration, you often need to modify two places: the ECOS entry point function main () and the web server initialization function initwebs ().

1. Start the web server. Main. the C file is mainly used for independent testing and debugging of the Web server. Therefore, you can directly use the main () function to start the web server, the GoAhead Web server is generally only a functional module of the ECOS application. In this case, the web server can be started as a thread.

The following code uses the Web server as an instance for thread startup. The goahead_program () function of the thread entry is the number of main () entry functions in the original main. c file. The thread priority of the web server in the Code is 16, and the thread name is "GoAhead Web server ". The ECOs application calls the do_webs () function to start the Web server thread. In this case, it is best to modify the main. c file name and add it to the ECOS application project to compile it with other source code programs. For more information about makefile, see section 12th General makefile writing in multiple directories.
# Include "../UEMF. H"
# Include "../wsintrn. H"
# Include
Cyg_handle_t webs_thread_handle;
Cyg_thread webs_thread_s; // space for Web thread objects
Char webs_stack [2, 4096]; // space for 4 K stacks
Cyg_thread_entry_t goahead_program;
Void do_webs (INT argc, char * argv [])
{
Cyg_thread_create (16, goahead_program, (cyg_addrword_t) 0,
"GoAhead Web server", (void *) webs_stack, 163840,
& Webs_thread_handle, & webs_thread_s );
Cyg_thread_resume (webs_thread_handle );
}
Void goahead_program (cyg_addrword_t data)
{
Bopen (null, (60*1024), B _use_malloc );

If (initwebs () expanded ASP data:

In the MAKEFILE file, Main. after modifying the webpage content of the C file and web sub-directory and several files under the root directory, first go to the ECOS sub-directory of the Web Server Source code in the cygwin environment, then, you can directly use the make command to complete the goahead compilation process. Use make clean to clear compilation garbage. When the source code, content, and main of the Web server are modified. after the c file, you must use this command to clear the previous compilation result and the intermediate compilation file. Otherwise, the procedure may be abnormal.

If you only modified the main. c file, you can use the following command to compile the ECOS application:

$ Arm-elf-GCC main. C-o webs-g-dwebs-duemf-dwebvs_page_rom
-Dos = "ECOs"-decos-d1_ecos-d1_no_fcntl = 1
-I ..-I/h/Ecos-work/mywork_install/include
-L/h/Ecos-work/mywork_install/lib libwebs.
-Ttarget. LD-nostdlib-wall-wl, -- GC-Sections

The application directly uses the previously compiled library file libwebs.. When an ECOs application contains multiple source code files, refer to section 12th General makefile writing in multiple directories. The header file paths of goahead and ECOs are specified in the two "-I" lines in the third command, and the header file paths of eCos and libwebs. A are specified in the fourth line. In actual use, you must modify the path.
Figure 3 JavaScript Testing

Figure 4 ASP form test Input

Figure 5 ASP form test output result

Webpage Design Example

The embedded functions of ASP Web pages have been described earlier. Here we will discuss the design of ASP Web pages. The following is a form webpage forms. asp in the GoAhead Web Server Source Code:
Goform Test
Name:
Address:



Forms. asp is a page that submits names and addresses. It calls the CGI program formtest to process the form. Formtest is a memory CGI program, which must be defined using websformdefine () in the initwebs () function. Main. C provides an example of a form processing function:
Static void formtest (webs_t WP, char_t * path, char_t * query)
{
Char_t * Name, * address;
Name = websgetvar (WP, T ("name"), T ("Joe Smith "));
Address = websgetvar (WP, T ("Address"), T ("1212 Milky Way ave ."));
Websheader (WP );
Webswrite (WP, T ("
Name: % s, address: % s \ n "), name, address );
Websfooter (WP );
Websdone (WP, 200 );
}
This form processing CGI program first obtains the value of the variable name and address, and then outputs the content entered in the form on a separate page. The last four lines of the formtest function show the four basic functions output on the page. Figure 4 and figure 5 show the two pages of form input and output.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.