2017-08-26

tDOM 0.9.0

ANNOUNCE: tDOM 0.9.0


tDOM 在很長一段時間的 0.8.3 以後,釋出了一個新版 v0.9.0。這版加入了 JSON 的支援,並且在編譯時開啟 html5 選項(需要連結 Google Gumbo html parser library)的情況下就有 html5 parser 可以用。

tDOM contains:

    *  for convenience expat 2.2.0, the XML parser originated from
       James Clark, although you're able to link tDOM with other
       expat versions or the library provided by the system.
    *  building a DOM tree from XML in one go implemented in C for
       maximum performance and minimum memory usage, and DOM I and II
       methods to work on such a tree using either a OO-like or a
       handle syntax.
    *  a Tcl interface to expat for event-like (SAX-like) XML parsing.
    *  a complete, compliant and fast XPath implementation in C
       following the November 99 W3C recommendation for navigating and
       data extraction.
    *  a fast XSLT implementation in C following the W3C Recommendation
       16 November 1999.
    *  optional DTD validation.
    *  a JSON parser which parses any possible JSON input into a DOM
       tree without losing information.
    *  an efficient and Tcl'ish way to create XML and HTML documents
       and JSON string.
    *  as build option an interface to the gumbo HTML5 parser, which
       also digests almost any other HTML.
    *  an even faster simple XML parser for trusted XML input.
    *  additional convenience methods.

2017-08-21

tcl-rocksdb v0.1.1

tcl-rocksdb


RocksDB 更改了授權,從原本的 BSD+PATENTS 變成 BSD+PATENTS/GPL v2 (dual license) 然後又變成 Apache 2.0/GPL v2 (dual license)。

而會修改授權,是因為 Apache 基金會接到 Apache Cassandra Team 的請求,希望能夠釐清使用 RocksDB 是否會有版權上的疑慮以後,公佈了結果,Facebook BSD+PATENTS license 被列為 category-x,同時提出了下列的建議:
  • No new project, sub-project or codebase, which has not used Facebook BSD+patents licensed jars (or similar), are allowed to use them. In other words, if you haven't been using them, you aren't allowed to start. It is Cat-X.
  • If you have been using it, and have done so in a *release*, you have a temporary exclusion from the Cat-X classification thru August 31, 2017. At that point in time, ANY and ALL usage of these Facebook BSD+patents licensed artifacts are DISALLOWED. You must either find a suitably licensed replacement, or do without. There will be NO exceptions.
  • Any situation not covered by the above is an implicit DISALLOWAL of usage.

所以如果 RocksDB 沒有修改授權,那麼 Apache Cassandra 就無法使用 RocksDB,已經使用的 Apache Flink, Apache Samza 等各個專案也需要開始尋找替代品。而 RocksDB team 在 Apache 基金會公佈結果以後,很快就修改了授權,變成 Apache 2.0/GPL v2 (dual license)。

既然授權的疑慮清除(PATENTS 是很複雜的議題,如果可以,我會儘量避開),所以我實作了 tcl-rocksdb (prototype),實作一些最基本的操作,同時也寫了簡易的 test case 測試。因為其它的部份我不知道怎麼實作成 Tcl extension 比較好,所以目前的 v0.1.1 就是我實作上比較知道怎麼做的部份了。


2017/08/22
加入幾個新的 command,更新版本為 v0.2。

另外,我發現 LevelDB 和 RocksDB 的基本操作長的很像,所以按照目前的資料,也寫了一個 tcl-leveldb

2017-08-05

Apache Tomcat HTTP/2 與 TclCurl

一閈始是設定 Apache Tomcat HTTP/2 的部份(Apache Tomcat 在 8.5 及以後的版本開始支援)。

HTTP/2 需要 Apache Tomcat Native Library 的支援才行, 所以首先是先安裝 Apache Tomcat Native Library。

Tomcat Native Library 需要 libapr1,所以如果是使用 openSUSE,
sudo zypper install libapr1-devel

再來是自己編譯 Tomcat 或者是使用 RPM 安裝

然後,需要創造 OpenSSL Certificate。 可以參考 Howto: Make Your Own Cert With OpenSSL。

如果只是要自己測試使用所以使用 self-signed,在 conf 目錄下使用下列的指令:
openssl genrsa -out ca.key 4096
openssl req -new -x509 -days 1826 -key ca.key -out ca.crt

最後修改 conf 目錄下的 server.xml,開啟 HTTP/2 的支援並且修改如下:

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/ca.key"
                         certificateFile="conf/ca.crt" />
        </SSLHostConfig>
    </Connector>

再來重新開啟 Apache Tomcat server,如果 https://localhost:8443 可以瀏覽,就正確的設定好了(* 因為是 self-signed,所以會看到安全性警告)。


TclCurl 在最近的版本有支援 HTTP/2,下面是驗證 Apache Tomcat HTTP/2 (self-signed) 的範例:
package require TclCurl

set curlHandle [curl::init]
$curlHandle configure -url https://localhost:8443 -sslverifyhost 0 \
    -sslverifypeer 0 -bodyvar result
$curlHandle setopt CURLOPT_HTTP_VERSION 2TLS

catch { $curlHandle perform } curlErrorNumber
if { $curlErrorNumber != 0 } {
    puts "error [curl::easystrerror $curlErrorNumber]"
}

# Print result and clean up
puts $result
$curlHandle cleanup

那麼我們怎麼知道真的是使用 HTTP/2 協定呢?這只要檢查 Tomcat logs 目錄下的 log 就可以確定。

2017-08-03

TclCurl and HTTP/2

TclCurl


HTTP/2 預計在 Java 9 加入支援,所以我想預計會開始增加使用率。

目前 BitBucket 上的 TclCurl 已經加上 HTTP/2 的支援,所以如果要測試 HTTP/2,需要使用 TclCurl。根據 Tcler's Wiki 的資料,目前好像也只有 TclCurl 可以使用 (PS. 目前內建的 http 套件只支援到 1.1)。

Debian 方面,7.22.0+hg20160822-1 這個版本就是使用目前 BitBucket 上到最近的 source code。

openSUSE 的部份我檢查了一下,發現還停留在原作者最後一個釋出的版本,所以我把 openSUSE 的檔案拿過來,加上 BitBucket 上的 source code,然後修改 spec 的 URL 到目前的來源,試著 build 一版看會不會有問題。比較有問題的是版本號碼,因為同一個版本會造成問題(也就是我有可能會進行一些調整,只是還不知道怎麼做比較好) (更新:版本設為 7.22.0+hg20160822) (2017/08/06 更新:放上去 openSUSE build service 測試以後,將版本更新為 7.22.0_hg20160822)。

(另外一個問題是 openSUSE 42.x CURL 版本停在 7.37.0,這表示我可能需要升級 CURL)
(升級到 7.54.1,然後 TclCurl 會發生 libssh2_scp_recv2 找不到的問題,這需要升級 libssh2-1 到新的版本,我升到 libssh2-1-1.8.0-56.2.x86_64 以後解決問題)


更新:
Tools for debugging, testing and using HTTP/2
( 所以 CURL 在  7.43.0及以後的版本,使用 nghttp2 這個函式庫來支援 HTTP/2)

cURL 的文件部份:
HTTP/2 with curl

HTTP/2 解釋文件:
http2 explained

另外的文件:
Introduction to HTTP/2
Chapter 12. HTTP/2

2017-08-01

Swapping variables

資料來自於 Tcler's Wiki - Tcl Gems


使用 Tcl 8.5 內建命令 lassign:
lassign [list $b $a] a b

lassign 可以將一個 list unpack 然後設定其它的變數,利用這一點,就可以交換二個變數的值,很有趣的做法。