你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

uIP WebServer 实现

[复制链接]
咕噜 发布时间:2015-4-19 18:08
本帖最后由 咕噜 于 2015-4-19 18:25 编辑 4 y6 K; T( _4 D! r- T+ ^7 Q
" W# \- r* \8 @. w# X8 T7 N( q
原帖地址
/ p# r- {; C& ]( U( E& Hhttp://www.ichanging.org/uip-webserver.html+ J8 \  _6 f3 Z0 X! o- `
这篇帖子写的不错,分享一下。对于理解uIP很有帮助。8 o. s. T1 Z& l' R) X
Uip的Webserver比较复杂,用c语言实现一个简单服务器的所有功能,路由功能,GET传参,动态页面生成等。
8 R% c9 T- @  o" |, u7 l5 f8 k
要运行Uip的WebServer 只需要:( P  s( D$ i! Z7 s; d& `; P8 u4 F
1. 修改uip-con.h 里的#inlcude "webserver.h"  去除其注释* m) Z0 A- {7 v; W. r0 a3 z
2. 在User/main.c 里加入      httpd_init();   //初始化服务器
/ b' q( c( V2 R$ {* r4 [+ ~8 m1 t# VUip+ stm32移植参见 Uip + Stm32移植问题总结 % ~! O6 M- I* _9 \: E/ P4 K
浏览器访问 Uip WebServer 页面:
+ u! t3 l) H# A  p1 n2 z. @; h
" p+ W* B; ]" y分析下 Uip Webserver 的运行过程,Uip WebServer使用到相关文件如下:( L6 {4 f1 X; b( k& M" D

1 ?# u3 \8 `! j+ P! S: u5 z0 g1 hhttpd.c                        ) G: K+ N6 T6 k# V: V4 f
httpd.c中定义了一些ASCII码,含义如下% P" Y( O- f* }6 L: i, e/ V
  1. #define ISO_nl      0x0a     // 换行& @) ?: O& {/ t4 q  L4 N" ?8 Y
  2. #define ISO_space   0x20     // 空格
    / q' e0 Z# C, m4 j; \* d
  3. #define ISO_bang    0x21     // !3 Y: c) P7 X9 }3 C, {
  4. #define ISO_percent 0x25     // %$ l6 L! U( B. u3 K1 E
  5. #define ISO_period  0x2e     // .4 s8 ?: l$ h* R3 M# V$ k' B
  6. #define ISO_slash   0x2f     // /: n5 C$ h9 Z! C- T. R/ X) o4 M
  7. #define ISO_colon   0x3a     // :
复制代码

1 J) h6 |4 S. _; W7 Z/ H当Uip接收到Uip接收到底层传递的数据,将接收到的数据通过调用http_appcall(),传递给Webserver处理,再通过handle_connection()先后调用handle_input()函数和handle_output()函数
2 Q% E/ q2 o3 y0 rhandle_input()主要作用是分析http数据流:. D" o* D" E1 K9 S# t
0 ~# G! w3 A+ u) p, v, q
  1. static  PT_THREAD(handle_input(struct httpd_state *s))      //分析http数据流, http数据流格式(eg. "GET /6?user=123 HTTP/ ...")
    . w6 Q7 y% o+ g. a
  2. {7 D0 p1 B( w; E( A7 m+ @. M( m" g
  3.   char * ptr;- D; Z5 `  h9 ~  ?

  4. , }' T: U6 H; A& t
  5.   PSOCK_BEGIN(&s->sin);+ o7 L, y* C: i9 H$ g; m

  6. & O5 W$ z) N& @
  7.   //取出到下一个空格号之前的数据5 U6 C* t- y4 h" {% S- i: _/ S
  8.   PSOCK_READTO(&s->sin, ISO_space);                 //Uip使用这个函数从http数据流中剥离数据& X; V: z' S6 R" E3 D7 m

  9. 1 H' b; @7 j3 q# l$ I7 |7 ~
  10.    5 @. i2 U( [; y4 ^
  11.   if(strncmp(s->inputbuf, http_get, 4) != 0) {             //判断数据流前4位字符是否为"GET ",判断是否为GET传参
    2 }! g0 P9 y! @
  12.     PSOCK_CLOSE_EXIT(&s->sin);
    + L. |: E& Y' \+ _' e# b
  13.   }
    * s+ H. O3 H* e* [

  14. ! w. w  J0 h' u# B) z1 N1 D
  15.   PSOCK_READTO(&s->sin, ISO_space);8 P- Z4 A. K. d; R4 w
  16. 6 Y# W! y- O4 T0 U# z
  17.   if(s->inputbuf[0] != ISO_slash) {                6 t1 I  z: R5 u; A" ^# ]
  18.     PSOCK_CLOSE_EXIT(&s->sin);+ w4 s: Z" V+ z4 Q' B
  19.   }
    & B- K9 D2 X5 u% Y8 M

  20. , X$ ?' ]* r" c/ f" a6 P* {
  21.   if(s->inputbuf[1] == ISO_space) {                   //请求路径为 "/ " (eg. 192.168.1.15/ ) 更新请求页面filename 为/index.html; y/ \) m$ G% f& P7 K$ t8 N8 A' L! P5 p- o
  22.     strncpy(s->filename, http_index_html, sizeof(s->filename));6 M- ]+ O$ ]6 K* b
  23.   } else {                                        //根据请求路径,更新结构体中filename为相应页面名称1 m) [% d1 Z: j0 A' |$ E
  24.     s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
      q) l1 p5 \  R  W
  25.     strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));      
    ( d$ t* p* u( K/ @6 P5 y6 N/ _
  26.   }
    9 G# U* J# J% a9 h* C- P
  27. 7 [) I3 Q' ]6 b% b
  28.   /*  httpd_log_file(uip_conn->ripaddr, s->filename);*/$ O) z" s  h9 D$ N. O0 ?& o
  29.    
    " _$ _; {. d4 E
  30.   s->state = STATE_OUTPUT;
    4 L- X0 Z$ d8 Q
  31. ; n. f/ [/ G, b' ]/ w6 T! T
  32.   while(1) {0 z' y# C. e. b0 j) |# j, S0 x
  33.     PSOCK_READTO(&s->sin, ISO_nl);
    9 q0 O0 |' O7 c3 w) n" u

  34. # u, o' n6 h& Q! y' N& v0 \$ K
  35.     if(strncmp(s->inputbuf, http_referer, 8) == 0) {
    # Z6 Q9 x# d+ a" v& h
  36.       s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
    + M7 }" O( F! ^* g& }# ~" c
  37.       /*      httpd_log(&s->inputbuf[9]);*/
    1 j* O  @/ `6 a3 _8 }, h
  38.     }
    9 V0 R0 Z! {; O
  39.   }) P" k+ x% o: q0 X$ |5 \$ i
  40.    0 w/ y5 b, z  r8 f; a
  41.   PSOCK_END(&s->sin);
    / T$ q2 f7 c, @0 y) d, B
  42. }
复制代码
分析数据得出访问页面的名字,存入一个全局的结构体中,handle_output()函数根据这个结构体获得要输出的页面名字,做相应处理:
- m" y( g  G# X" i! T
  1. static PT_THREAD(handle_output(struct httpd_state *s))3 `4 M9 `' }$ ^( j9 M
  2. {; c+ k+ F$ e( ?- E7 A
  3.   char *ptr;
    , X$ Z/ a9 B9 ]& t, X
  4.    
    , U6 b5 m  g1 e; m- Q
  5.   PT_BEGIN(&s->outputpt);- k& Z  G( r, _8 b) i
  6.   ! n; T  i2 q& `$ I6 u0 ]( f  \
  7.   if(!httpd_fs_open(s->filename, &s->file)) {          //没有此页面,打开404页面
    2 `' `/ k- j& l4 l
  8.     httpd_fs_open(http_404_html, &s->file);
    * }+ C* P9 A! q
  9.     strcpy(s->filename, http_404_html);) I/ L; {2 U; v8 U: Y
  10.     PT_WAIT_THREAD(&s->outputpt,- x( J* l  E& U
  11.            send_headers(s,/ T8 q1 m- r5 [% z, e
  12.            http_header_404));
    8 a) b' c6 C1 ^# t- o% M8 i' V
  13.     PT_WAIT_THREAD(&s->outputpt,
    * F5 T$ x/ ^# A2 m
  14.            send_file(s));- z% t( {3 r; u. U5 Y" S
  15.   } else {                               //正常打印相应页面
    " n6 {5 X) ]) a3 c# z! O& c" }
  16.     PT_WAIT_THREAD(&s->outputpt,                     
    2 g; O% ]/ p( f6 [, \9 |$ H
  17.            send_headers(s,
    $ @& _& o) {& [' a* ]: P
  18.            http_header_200));
    7 \; I" G5 S0 R1 K( V
  19.     ptr = strchr(s->filename, ISO_period);               //查找字符串s->filename中首次出现字符ISO_period的位置,返回首次出现c的位置的指针
    % i2 _- b2 v* f  L' B
  20.     if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) {    //判断是否为 .shtml网页文件    . ]# x* Z# v4 l% A- u) `
  21.       PT_INIT(&s->scriptpt);6 ~3 _5 }2 f8 ?8 U8 }% Y' B1 T
  22.       PT_WAIT_THREAD(&s->outputpt, handle_script(s));    //若为 .shtml页面,则调用handle_script()生成动态网页- @- w+ V; k. J* z* H
  23.     } else {                            //不是 .shtml(eg.  /index.html),输出该页面数据
    8 s/ L( g5 e! d; z
  24.       PT_WAIT_THREAD(&s->outputpt,
    / q6 P6 [2 ^  @# U8 \" o! f% b2 o0 a
  25.              send_file(s));8 j, R4 j9 G: J: U+ Z4 [5 N
  26.     }$ K6 c) ~- M- z* v) T4 N
  27.   }! y! L; e: I, B% p' e
  28.   PSOCK_CLOSE(&s->sout);/ H+ m# H# ^# R
  29.   PT_END(&s->outputpt);- n: [) Z! u0 @; v' ?. k
  30. }
复制代码
7 T( ^* H% F: i4 J- O3 E
httpd_fs_open()定义于httpd-fs.c,用于读取相应页面的数据,将页面数据存入全局结构体中,是实现路由遍历的关键函数:- g; @) w  S) O" V
  1. int  httpd_fs_open(const char *name, struct httpd_fs_file *file)+ Y( C5 t% \6 p$ |/ a2 o  y
  2. {
    3 _3 E: O. `) G
  3. #if HTTPD_FS_STATISTICS" ?# ?* r! I/ l+ A5 q5 v
  4.   u16_t i = 0;
    5 l: U% ~& t% n6 A$ J" D# a1 D$ _9 B
  5. #endif /* HTTPD_FS_STATISTICS */8 v$ G7 @. _" s: Y  B$ R/ l
  6.   struct httpd_fsdata_file_noconst *f;
复制代码
; U0 Z; `+ D: y  W
# i, R" h8 t9 K6 x4 Z$ m9 m
http-fsdata.c 中包含了所有页面的数据。这里的页面数据都转换为ACAll存在数组中,还包括了层叠样式表 (.css文件) 和图片。其数组结构如下:
- D  c& F( |2 K

! ~) P, n2 y. m: B
  1. static const unsigned char data_404_html[] = {
    . z' O7 x! c& B: u
  2.     /* /404.html */6 Z& {- @6 O5 P! o( x/ S+ I% ^
  3.     0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,            //文件名  /404.html
    0 `2 Y3 l: ^4 D9 v
  4.      
    6 \& p1 S4 c: r! Q# v- p
  5.     0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0x20, 0x20, 0x3c,         //html文件转码为16进制数据(ASCLL)1 V% s8 u" k1 H! D+ I
  6.     0x62, 0x6f, 0x64, 0x79, 0x20, 0x62, 0x67, 0x63, 0x6f, 0x6c,
    ; J# _1 P% g# x2 A) N
  7.     0x6f, 0x72, 0x3d, 0x22, 0x77, 0x68, 0x69, 0x74, 0x65, 0x22,
      l: ?) g0 v( k0 _5 U, T1 Y
  8.     0x3e, 0xa, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x63, 0x65, 0x6e,
    " N! p  }4 j' ^0 L: a
  9.     0x74, 0x65, 0x72, 0x3e, 0xa, 0x20, 0x20, 0x20, 0x20, 0x20,
    ) g# O$ S/ [: u- g# W
  10.     0x20, 0x3c, 0x68, 0x31, 0x3e, 0x34, 0x30, 0x34, 0x20, 0x2d,
    4 D3 S( D  Y* p, _6 G. F
  11.     0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20,
    % `3 l) I; E# I, Z6 d5 ~
  12.     0x66, 0x6f, 0x75, 0x6e, 0x64, 0x3c, 0x2f, 0x68, 0x31, 0x3e,   b7 d0 X9 U4 m. s: S
  13.     0xa, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x68, 0x33,
    8 m9 U5 w% W1 c" z
  14.     0x3e, 0x47, 0x6f, 0x20, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65,
    . Z; w! e9 {6 \% n( k) ]0 u9 K' Q
  15.     0x66, 0x3d, 0x22, 0x2f, 0x22, 0x3e, 0x68, 0x65, 0x72, 0x65, 0 p6 Q, W4 X- q- t1 k
  16.     0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x69, 0x6e, 0x73, 0x74, 0x65, , f7 [+ s1 d8 ^$ }, f! f. K0 j
  17.     0x61, 0x64, 0x2e, 0x3c, 0x2f, 0x68, 0x33, 0x3e, 0xa, 0x20,
    % T" b, i% O) i
  18.     0x20, 0x20, 0x20, 0x3c, 0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65,
    6 d! N1 j- [% h  `) f% w
  19.     0x72, 0x3e, 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64,
    3 \: L8 C* z, |0 L
  20.     0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, " {+ Q: S. _2 y# H4 @1 P8 C: S
  21. 0};
复制代码
$ n( t3 I- p' f
需要注意的是以下的一段程序:
  1. //结构体格式说明:      下一个页面地址(用于遍历网页)    ,网页name地址      ,html数据起始地址          ,html数据长度
    2 u4 M& n2 h5 p2 s  o. u
  2. //其中的加减操作是为了去除文件名的长度9 X% Q5 M5 [; b$ `
  3. const struct httpd_fsdata_file file_processes_shtml[] = {{NULL, data_processes_shtml, data_processes_shtml + 17, sizeof(data_processes_shtml) - 17}};
    , d. R8 o4 K* \% e5 |5 r

  4. 7 {( Z+ ?. x% _# d
  5. const struct httpd_fsdata_file file_404_html[] = {{file_processes_shtml, data_404_html, data_404_html + 10, sizeof(data_404_html) - 10}};) i6 @( h' ]5 S% \
  6. $ r( e: e3 \  g" i8 I8 r- g1 A
  7. const struct httpd_fsdata_file file_files_shtml[] = {{file_404_html, data_files_shtml, data_files_shtml + 13, sizeof(data_files_shtml) - 13}};8 f; R4 ?& U9 }, e3 A6 B: b+ ]
  8. " w" t8 `3 V4 j) r  ?. t
  9. const struct httpd_fsdata_file file_footer_html[] = {{file_files_shtml, data_footer_html, data_footer_html + 13, sizeof(data_footer_html) - 13}};- ^( q* k: K1 B' C! g  u0 @5 O# I. p5 u+ v
  10.   Z9 v1 p+ Y5 v* m$ B: j
  11. const struct httpd_fsdata_file file_header_html[] = {{file_footer_html, data_header_html, data_header_html + 13, sizeof(data_header_html) - 13}};
    ' Q: A( X- [; p* G2 u3 U/ K% a/ d* N
  12. 0 w5 U/ i' Q! U0 Z) j
  13. const struct httpd_fsdata_file file_index_html[] = {{file_header_html, data_index_html, data_index_html + 12, sizeof(data_index_html) - 12}};
    + i, |1 _/ `4 P% P9 Y6 }
  14. & f3 J& z/ f: |; d0 y
  15. const struct httpd_fsdata_file file_style_css[] = {{file_index_html, data_style_css, data_style_css + 11, sizeof(data_style_css) - 11}};
    ; m. Y7 W' W# H9 H7 O4 M/ t

  16. 8 [! X+ U" k! W$ w9 [( @
  17. const struct httpd_fsdata_file file_tcp_shtml[] = {{file_style_css, data_tcp_shtml, data_tcp_shtml + 11, sizeof(data_tcp_shtml) - 11}};- \, S6 j) X: L4 E9 m: W  z
  18. * u7 o# P/ @. Y
  19. const struct httpd_fsdata_file file_fade_png[] = {{file_tcp_shtml, data_fade_png, data_fade_png + 10, sizeof(data_fade_png) - 10}};" s! p( A! N& @

  20. 5 Q- A; k4 E4 Q+ F* u& U8 C
  21. const struct httpd_fsdata_file file_stats_shtml[] = {{file_fade_png, data_stats_shtml, data_stats_shtml + 13, sizeof(data_stats_shtml) - 13}};
    / J* Q! n6 q5 z2 m

  22. - S8 k1 z: U3 q. v# k' n" \5 w
  23. #define HTTPD_FS_ROOT file_stats_shtml      //设定路由遍历入口页面,一定要保证所有页面都遍历过一次6 I- T9 f3 c, v2 m
  24. / x7 \3 D$ D: w9 P, q
  25. #define HTTPD_FS_NUMFILES 10                //设定页面数量
复制代码
+ J! p0 e) E# \. R. n
在 httpd_fs_open() 首先加载 file_stats_shtml页面数据 再加载file_stats_shtml结构体中下一个网页的数据 也就是file_fade_png的数据,同理 file_fade_png加载后一个页面数据  即 file_tcp_shtml数据 。。。 这样循环一次 就会加载所有的页面,实现里有遍历
: O; X, _0 h3 A1 E7 q+ Y3 @Uip WebServer的动态网页生成
+ e2 a6 ~& n4 }: f8 I! l在uip/apps/Webserver/http-fs/下有Webserver 页面未转码的html文件,其中有很多 %! 和 %!: 字符 :; J6 x; T' K  r. u5 G
  1. %!: /header.html
    : K/ i+ P5 L3 J- ~
  2. <h1>Network statistics</h1>2 @4 Z6 P; |5 [( K, b
  3. <center>" i. P: f% L+ B
  4. <table width="300" border="0">, O" K3 z5 a2 u. U
  5. <tr><td><pre>
    2 Z2 A7 I' S5 p4 e( j/ f( d* L
  6. IP           Packets received; W2 e; e( K& v9 \8 G
  7.              Packets sent. d; i+ h: @, m  k8 l" X9 F
  8.          Packets dropped
    2 g4 K! ^% _1 D4 A4 u/ S0 q
  9. IP errors    IP version/header length
    1 Q8 z3 N$ `" K, f4 @
  10.              IP length, high byte6 y* }) G: G2 x; y' j& I8 i; v
  11.              IP length, low byte- D+ _" X' V' `7 m0 q; [
  12.              IP fragments$ p! e8 t) L5 h+ s) j  v2 T$ _8 c
  13.              Header checksum
    6 }: f8 f' {7 O* L4 `! r
  14.              Wrong protocol/ E9 f) c9 r* c* _
  15. ICMP         Packets received
    * ]7 I" Z( H; p* `; i7 U
  16.              Packets sent
    ( c7 g# V2 _- y/ f) ]! f
  17.              Packets dropped! Q6 e6 W& a' x
  18.              Type errors
    5 n" V; b0 b+ ~
  19. TCP          Packets received
    ! ?' W+ w- {, y# r
  20.              Packets sent
    6 C3 ?! m, m+ y& ]4 \0 C
  21.              Packets dropped
    . a. g4 |7 p2 ?0 S
  22.              Checksum errors  R" f8 Y. s) }: C6 j; k
  23.              Data packets without ACKs
    8 R, f0 X( A! M3 V! F" G- Z. o
  24.              Resets
    ! Q2 @3 M9 o# n. H" _
  25.              Retransmissions
    : z" J. e. ]2 }! |( w. t, J( g' L' d, D! Z
  26.          No connection avaliable
    * ?9 ~8 h' X9 g8 F$ k+ Y
  27.          Connection attempts to closed ports
    0 ^1 R. I" i; {: l" {- T8 g8 w: h
  28. </pre></td><td><pre>%! net-stats1 f* j, R* ~  I4 N( `
  29. </pre></table>. J9 I) f8 }% o5 b
  30. </center>
    ; s) A( ?# H: ^6 z5 V5 K) q7 Y
  31. %!: /footer.html
复制代码
这是实现动态页面的关键。0 _8 n3 D3 B. z# P

" s# o; M. @! S/ \/ rhandle_output()函数中,找到相应页面数据后,若页面为.shtml,则会调用handle_script()函数:
  1. static  PT_THREAD(handle_script(struct httpd_state *s))                             
    $ z: r+ s# K+ P0 B0 V6 C
  2. {1 W" C5 _& }, O, q4 r1 p4 E+ d; o
  3.   char *ptr;
    7 d7 h; b. r( a- K( A4 b1 y4 k2 j0 t
  4.    
    " @1 m) i' o+ b7 G# L* W
  5.   PT_BEGIN(&s->scriptpt);0 e8 ~/ D; Z  _

  6. 6 a' m6 i# i8 r6 s) {. X

  7. 9 I/ I6 y. U3 _" }
  8.   while(s->file.len > 0) {
    5 v  w. q+ H: V9 X, |( D

  9. ) [7 Q: N0 @$ j2 r9 w, r0 y
  10.     /* Check if we should start executing a script. */      //检测当前html数据(定义于httpd-fsdata.c)中是否存在字符 %! 和 %!:
    4 P/ t' y8 w0 Q' c+ A: C
  11.     if(*s->file.data == ISO_percent &&
    9 d3 [# e7 k% X, t3 G0 k
  12.        *(s->file.data + 1) == ISO_bang) {                    
    * ]% ]  Z' S$ [/ I
  13.       s->scriptptr = s->file.data + 3;                        
      a5 V: P$ I2 ?6 k0 U
  14.       s->scriptlen = s->file.len - 3;/ Q( ?% O, m; y- H
  15.       if(*(s->scriptptr - 1) == ISO_colon) {             //若为 %!:  根据其后变量名,打开并输出相应文件 1 ^+ `8 m9 a2 s8 ?
  16.     httpd_fs_open(s->scriptptr + 1, &s->file);                //eg.  %!: /header.html  打印/header.html. }' b" p$ [& C3 b$ b7 \  z
  17.     PT_WAIT_THREAD(&s->scriptpt, send_file(s));* y) X& X( Y! `. R% I  y8 \
  18.       } else {                                  //若为 %!   根据其后变量名,调用相应处理程序(定义于httpd-cgi.c)
    " w: h( K- L6 X! g8 T8 f
  19.     PT_WAIT_THREAD(&s->scriptpt,                     //eg. %! file-stats     调用file-stats 绑定的file_stats()函数,打印出相关数据,实现动态网页
    & \+ l1 r" _/ v4 X
  20.                httpd_cgi(s->scriptptr)(s, s->scriptptr));
    * I' Z7 [, V8 _+ j  Y1 p
  21.       }  f6 c, Q/ F% ^' M& ]$ O0 D; t
  22.       next_scriptstate(s);
    2 m" `$ V$ O" C) t
  23.        - k& U. b, V  T5 c
  24.       /* The script is over, so we reset the pointers and continue
    - F; D4 `4 u# p, M6 G0 W* R) V
  25.      sending the rest of the file. */. Q4 D- ^$ c/ @: p/ v8 f: Q& [
  26.       s->file.data = s->scriptptr;) V' S+ p4 f  \* P& o
  27.       s->file.len = s->scriptlen;
    8 f) B/ |; k8 W2 f# B
  28.     } else {                                                //当前html数据不存在 %! 和 %!
    * W# o4 C0 O0 c* Q6 M$ S
  29.       /* See if we find the start of script marker in the block of HTML/ d# T; d8 Z, e( \3 n( {" Z% x9 m# m
  30.      to be sent. */5 @3 \9 @6 H0 x. r, _# u" r% U
  31. # h& S" p" z. q* r" {4 e
  32.     ...略去
复制代码

$ L3 [8 p6 E! [uip 载入html数据的方法类似网页里的模板引擎的实现方法。当页面输出时,检测到有字符串 %! 和 %!: 时,则调用相应的cgi程序(httpd-cgi.c)处理,在httpd-cgi.c中做相应的数据处理,实现动态网页。  {% R' f3 _2 H$ u: x$ a
( m6 m, c' z; A

# \' P7 z' @5 G- P9 Q看一下效果吧
3 M9 Z& z5 z$ g
$ F% g& S" I  r6 R( `( X
! t0 Q, z" O1 i% ~7 W

web 访问

web 访问
赞 收藏 评论0 发布时间:2015-4-19 18:08

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版