当前位置: 首页 > 工具软件 > Dillo > 使用案例 >

Dillo 2.0 学习笔记二

江棋
2023-12-01

从a_Cache_process_dbuf开始,Dillo开始解析Http协议:

1. 解析Http头。一个典型的Http头可能是如下所示:

HTTP/1.1 200 OK
Date: Mon, 06 Dec 1999 20:54:26 GMT
Server: Apache/1.3.6 (Unix)
Last-Modified: Fri, 04 Oct 1996 14:06:11 GMT
ETag: "2f5cd-964-381e1bd6"
Accept-Ranges: bytes
Content-length: 327
Connection: close
Content-type: text/html

<title>Sample Homepage</title>
<img src="/images/oreilly_mast.gif">
<h1>Welcome</h1>
Hi there, this is a simple web page.  Granted,
it may not be as elegant as some other web
pages you've seen on the net, but there are 
some common qualities:

<ul>
  <li> An image,
  <li> Text,
  <li> and a <a href="/example2.html"> hyperlink. </a>
</ul>

Dillo 通过查找连续/n(丢弃/r)来确定包头的位置,并填充CacheEntry_t->Header。将Http头全部取出之后,交由Cache_parse_header处理。

Cache_parse_header首先根据Http状态码(第10,11,12字节)判断是否是continue,404以及redirect标志。如果不是以上标志,则根据Transfer-Encoding域初始化TransferDecoder,根据Content-Encoding初始化ContentDecoder,以及根据Content-Type初始化CharsetDecoder。

接下来处理body的内容:将内容依次通过3个Decoder,完成chunk分段、gzip解压和字符转码(至UTF8)的工作,得到真正的内容,并将3个Decoder释放。

终于要开始处理Http内容了,当然还要先处理一些杂事,比如更新一下界面上的状态栏,还有进度条等等。最关键的是这一句:

(Client->Callback)(CA_Close, Client);

即调用Client的Callback来处理页面的真正内容。该回调函数的设置是在设置type的时候调用a_Mime_set_viewer完成的。具体来说,就是初始化时向mime管理注册各种类型的处理器,比如a_Html_text,该函数的功能就是设置这个Callback。当Dillo处理到对应类型时,会根据类型名称字符串Content-Type找到对应type的注册函数并进行注册,这样Client->Callback就被设置了。

对于text/html来说,调用a_Html_text来注册,最终调用的是Html_callback。

今天就到这里,明天分析Html_text中的词法分析~

 类似资料: