THTTPD Server Overview

Source: Internet
Author: User
Tags config http authentication root directory

With the development of microprocessor technology and computer network technology, the network digital video monitoring system based on embedded web has been paid more and more attention. The collection of image acquisition, video compression and web functions in a small volume of equipment, can be directly connected to the local area network and the Internet, Plug and Play, save a variety of complex cables, easy installation, users do not need to install any hardware equipment to watch, This makes the network and expansion of monitoring networks composed of embedded network video monitoring servers extremely flexible and convenient.

2 Web Server System working principle

As shown in Figure 1, the system has two types of network access: Automatic dialing via PPPoE, dynamically acquiring IP connectivity to the Internet, and a custom static IP connection to the LAN.

After that, the whole workflow of the system consists of two main lines: 1. Through the HTTP/TCP/IP way, the resolution from the monitoring side of the Web page request, including: Camera control (PTZ up and down, lens aperture, zoom, etc.), database reading and writing (video parameters such as resolution, brightness chroma, stream, quality), video scheduling and transmission (The sending of video data between multiple users stops and coordinates with each other, system parameters are also placed here).

2. Provide real-time video information for the monitoring end through RTP/UDP/IP mode. The Rtp/udp/ip method takes into account the real-time performance and QoS guarantee of video transmission.

3 Selection of Web servers

According to the working principle, the Web server is located in the core of the whole system, and several difficulties to be solved include:

1. Safety. Only authorized login users can perform system configuration (network parameters, video characteristics, etc.). Ordinary users can only be monitored simply.

2. Flow control. Video data is continuous and large, the server should have a certain ability to coordinate various monitoring data.

3. Real-time performance. The response speed of the Web request instruction on the monitor side, especially in the case of high load.

4. Performance. The response speed of a system in the presence of a multiple-channel monitoring request.

5. Support Serial command. PTZ control command requires serial port support.

6. Database interaction. Including user database, system configuration parameters, and so on, all need to implement offline save.

Uclinux, the main 3 web server:httpd, thttpd and BOA.HTTPD are the simplest of a web Server, it is the weakest, does not support authentication, does not support CGI (Common Gateway Interface, Universal Gateway Interface). THTTPD and Boa All support authentication, CGI and so on, the function is all compared. Boa Source code is open, reliable and stable, but it is a single task Web server. Therefore, we choose simple, compact, easy to transplant, fast and safe thttpd. THTTPD in the default condition, only runs in the ordinary user mode, thus can effectively eliminate the unauthorized system resources and the data access, simultaneously thttpd fully supports the HTTP Basic authentication (RFC2617), can effectively solve the security question.

In addition, THTTPD does not use fork () to derive process processing for concurrent requests, but uses multiplexing (multiplex) technology to achieve high performance, which can effectively improve the system.

Finally, thttpd based on the URL of the file traffic restrictions for continuous video flow control is very convenient, like Apache must use Plug-ins to achieve, less efficient than thttpd. On the official website of THTTPD, there is a contrast graph benchmark with other Web servers.

To sum up, thttpd in the security, performance, flow control and other aspects of effective to meet the system needs, of course, real-time is also a good guarantee. Below, the combination of source code, the first implementation of the basic functions of thttpd, and then the video data forwarding, security, support serial command, database interaction to improve the implementation.

4 The realization of basic function of THTTPD

First, make sure that the thttpd in BusyBox is selected in the step of compiling the Uclinux kernel menuconfig.

Then, as needed, modify the source/user/thttpd under the config.h: #define DEFAULT_PORT 80//server listening Port #define DEFAULT_DIR/HOME/HTTPD//Set server root directory # Define Index_name index.html//Set default home page when accessing server #define AUTH_FILE passwd//Authorized user database file #define CGI_PATTERN/CGI-BIN/*.CGI// CGI file name format #define CGI_PATH/HOME/HTTPD/CGI-BIN//cgi directory

Next, establish the server root directory and file directory:

Because the root file system for Uclinux is ROM FS, read-only, the directories and files should be built before the file system image is generated. The first is the Web server root directory, then the subdirectory under the root directory: the file root directory and the CGI program directory. Modify the/vendor/samsung/4510b/makefile file to add home/httpd (server root directory and file root directory) to the directories listed in Romfs_dirs, Home/httpd/cgi-bin (CGI program directory).

Finally, the Web pages and CGI programs related to the monitoring system are placed in/VENDOR/GENERIC/HTTPD and/vendor/generic/httpd/cgi-bin respectively, and can be automatically copied to the related directories of image as the kernel compiles. Add thttpd to the/VENDOR/SAMSUNG/4510B/RC to automate the implementation of the power on.

5 Implementation of HTTP Basic authentication (RFC2617)

You must first generate a database file that holds the user and his or her password: Because THTTPD is based on b64_decode_table decryption on the implementation of HTTP authentication, you need to provide a database file that corresponds to B64 encryption. Then, compile the/USER/HTPASSWD.C and switch to the appropriate directory to execute. /htpasswd-c passwd root adding password for root. New Password:re-type New Password:

Where-C indicates the creation of a new user data encrypted file named passwd, with the first user named Root.

After that, copy the passwd file to the/VENDOR/GENERIC/HTTPD, and note that the Auth_file and passwd in Thttpd/config.h are the same. At this point, the THTTPD HTTP authentication function is added successfully.

6 Video scheduling and transmission

In this system, the simulation of video data through ad, sampling and other preprocessing into the support of MPEG4 coding ASIC chip compression, the task of packaging sent by the THTTPD completed.

In the case where multiple monitor-side requests exist, the instruction response itself is thttpd, so we only need to implement data transfer.

In the main function, execute get_device,driver_init,device_init and Alloc_resource,interrupt_enable,device_start in sequence before starting the main loop. The coding compression of the video stream begins. Add Timer response function, (void) tmr_create ((struct timeval*) 0, Transfer_bitstream, (clientdata) mpeg4_fd, 0, 1); MPEG4_FD, is the device descriptor for the coded chip, Transfer_bitstream is the response function (content slightly).

Then, according to the change of THTTPD connection request, the function of data dispatch and transmission can be completed by adding the code of simple corresponding connection validity in Handle_read and handle_send.

7 Serial Command Support

The sending of PTZ control instruction needs RS485 support.

Add device support in the main function of THTTPD.C: Open serial device.

int com1fd = open (/dev/ttys1,o_rdwr| O_noctty); setting of transmission baud rate: tcgetattr (com1fd,&oldtio); Cfmakeraw (&oldtio); Cfsetispeed (&oldtio,b9600); Cfsetospeed (&oldtio,b9600); tcsetattr (com1fd,tcsanow,&oldtio); After libhttpd.c contains header files that define the PTZ signaling, in Httpd_parse_ Request to add the following code, memcpy (cmd,yt_focus_in,yt_cmd_num); Convert Web requests to corresponding PTZ signaling stored in the CMD array, and finally, because uclinux all devices as files, So it is possible to send the Com1fd,cmd,yt_cmd_num message through write.

8 Storage of configuration information (MTD driven implementation)

Uclinux in the process of porting on ARM, the Flash file system is generally not used, it is after the bootloader initialization system and mapping memory, by the bootloader kernel and root file system image from flash directly copy to RAM Uclinux the system start address (0x8000) and hand control over to uclinux by setting the PC value.

This method uses the Romfs file system, the system structure is simple, realizes conveniently, but Romfs is the read-only file system. A RAM disk can be written but loses content once it is lost. There are two ways to save an application's configuration file for a long time: one is to draw a few fixed slices of the flash to read and write, to store all of the configuration files that are used, and the other is to create a writable JFFS2 file system. The previous method code is simple and flexible, and is suitable for less frequent file writes. The latter is also simpler to implement, but the cost of time, space, and so on is higher than the previous one, suitable for very frequent file writes (for example, more than 10 times a minute). Based on the real-time requirements of configuration data storage in this system, and embedded resources are very valuable, so consider adopting the first method, which is MTD (memory technology device Memory technology equipment). MTD is a subsystem of Linux for accessing memory devices (ROM, Flash). All of its source code is in the/DRIVERS/MTD subdirectory.

Because MTD's main purpose is to make the new memory device drive simpler, because it is between a particular flash device and a file system, it can be understood that it provides an abstract interface between the hardware and the upper layers. So hardware drivers don't need to know the methods used by user modules like JFFS2 and FTL. All they really need to provide is a set of simple routines for read, write, and erase operations on the underlying flash, that is, mtd-utils.c the corresponding function in the/MTD directory. Will inherit MTD-UTILS.C, in addition, add the manual added Flash partition table to achieve the purpose of saving the configuration file.

This system only has one flash, the size is 2M. The proposed partitions are as follows: Name:bootloader (128KB),

size:0x20000,

offset:0x0,

Mask_flags:mtd_writeable//read-only partitions

Name:kernel & Rootfs (1856KB),

size:0x1d0000,

offset:0x20000

Name:system Config (64KB),

size:0x10000,

offset:0x1f0000

Place the file containing this partition table under Drivers/mtd/map and modify the corresponding makefile to make it valid at compile time.

Then, select the appropriate MTD user module to enable access to Flash: Mtd_char and Mtd_block. Mtd_char provides raw character access to flash memory, while Mtd_block is designed to be a regular block device (like an IDE disk) that can create file systems on the above. The device associated with Mtd_char is adding mtd0,c,90,0, mtd1,c,90,2, mtd2,c,90,4 to the devices of/vendor/samsung/4510b/makefile, and Mtd_ The device associated with the block is the addition of mtdblock0,b,30,0, mtdblock1,b,30,1, and mtdblock2,b,30,2.

Finally, you need to compile the MTD subsystem into the kernel, which opens the option for MTD in make menuconfig.

Because there are multiple profiles to use, and read/write Flash is slow, so do not write flash after each configuration is completed, but first the configuration file exists in the THTTPD code of the temporary array, and then one-time (for example, before the restart) to the specified flash partition.

9 Management of configuration information

The first boot of the system loads a set of default configurations by determining whether Flash's last system config (64KB) partition is not initialized (all 1 or 0). In the main function of THTTPD.C, join open (/DEV/MTD2,O_RDWR) to open mtdblock2. Copy drivers/mtd down to MTD-UTILS.C directory, You can use some of these functions to easily implement the read and write operations of Flash.

10 Conclusion

The combination of embedded system Web server and CGI technology makes the management and use of embedded system simpler and more straightforward. The video monitoring system based on Web is the mainstream and direction of the current monitoring field. In this paper, according to the actual requirements of data throughput and security reliability of the monitoring system, combined with the new progress of related research, the application techniques of Web server in the design of monitoring system are discussed in detail, and the implementation is elaborated. The design of all the monitoring systems based on embedded web technology has a very practical guiding role. The reader can make further improvement on the basis of this study.

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.