tthttpd でStarbug1を動かした

昨日の続き

mattnさんが公開したtthttpdでStarbug1を動かそうとしています。問題を報告した日に、早速修正してもらいました。mattnさん、ありがとうございます。

それで動かしてみたんですが、なんか動かない。昨日の問題は解決していたんですが、CのCGIを動かすには、まだ壁がありました。良いプログラマのソースを見るのは良い勉強。ということで、C++の勉強にも兼ねて、gdbでステップ実行しながらパッチを書いてみました。

下のパッチを適応した状態で、Starbug1のSeleniumのテストが全て通ったので、Starbug1のtthttpdでの動作確認完了ということです!もうちょっと簡単に(apache無しで)Starbug1を簡単に動かすための、手順とかも書いてみたいです。バイナリ配布とかまで行けたらいいかもしれない。

tthttpd0.0.4で、Starbug1を動作させるためのpatch

パッチの内容です。

  • パッチの内容は、ubuntuでCのCGI(といってもStarbug1)が動くために必要だった修正です。
  • Windows側のソースは全く動作確認してませんm(_ _)m
  • perl,phpなどのCGI動作は全く動作確認してませんm(_ _)m
  • 0.0.4の修正は、不要だったみたいです(意図がわからないのでなんとも言えません)。0.0.4の修正を外したら動作しました。

というような程度ですので、添削おねがいします。

% diff -cw httpd.cxx.org httpd.cxx
*** httpd.cxx.org 2009-08-03 22:05:32.000000000 +0900
--- httpd.cxx 2009-08-03 23:38:15.000000000 +0900
***************
*** 154,160 ****
return (dwAttr != (DWORD)-1 && (dwAttr & FILE_ATTRIBUTE_DIRECTORY));
}
! bool res_isexe(std::string& file, std::string& path_info) {
std::vector<std::string> split_path = split_string(file, "/");
std::string path = "";
for (std::vector<std::string>::iterator it = split_path.begin(); it != split_path.end(); it++) {
--- 154,160 ----
return (dwAttr != (DWORD)-1 && (dwAttr & FILE_ATTRIBUTE_DIRECTORY));
}
! bool res_isexe(std::string& file, std::string& path_info, std::string& script_name) {
std::vector<std::string> split_path = split_string(file, "/");
std::string path = "";
for (std::vector<std::string>::iterator it = split_path.begin(); it != split_path.end(); it++) {
***************
*** 166,171 ****
--- 166,172 ----
if (S_ISREG(st.st_mode) && stat((char *)path.c_str(), &st) == 0 &&
path.substr(path.size() - 4) == ".exe") {
path_info = file.c_str() + path.size();
+           script_name.resize(script_name.size() - path_info.size());
file = path;
return true;
}
***************
*** 173,178 ****
--- 174,180 ----
stat((char *)tmp.c_str(), &st);
if (S_ISREG(st.st_mode) && stat((char *)tmp.c_str(), &st) == 0) {
path_info = file.c_str() + path.size();
+           script_name.resize(script_name.size() - path_info.size());
file = tmp;
return true;
}
***************
*** 441,447 ****
return statbuf.st_mode & S_IFDIR;
}
! bool res_isexe(std::string& file, std::string& path_info) {
std::vector<std::string> split_path = split_string(file, "/");
std::string path = "";
for (std::vector<std::string>::iterator it = split_path.begin(); it != split_path.end(); it++) {
--- 443,449 ----
return statbuf.st_mode & S_IFDIR;
}
! bool res_isexe(std::string& file, std::string& path_info, std::string& script_name) {
std::vector<std::string> split_path = split_string(file, "/");
std::string path = "";
for (std::vector<std::string>::iterator it = split_path.begin(); it != split_path.end(); it++) {
***************
*** 453,458 ****
--- 455,461 ----
continue;
if (S_ISREG(st.st_mode) && access(path.c_str(), X_OK) == 0) {
path_info = file.c_str() + path.size();
+           script_name.resize(script_name.size() - path_info.size());
file = path;
return true;
}
***************
*** 561,567 ****
envs_ptr = new char*[envs.size() + 1];
for(n = 0, it = args.begin(); it != args.end(); n++, it++) {
!      if (n == 1 && args[1].at(0) == '/') {
std::string path = args[1];
size_t end_pos = path.find_last_of('/');
if (end_pos != std::string::npos)
--- 564,570 ----
envs_ptr = new char*[envs.size() + 1];
for(n = 0, it = args.begin(); it != args.end(); n++, it++) {
!      if (n == 1 && args.size() > 1 && args[1].size() > 0 && args[1].at(0) == '/') { //spawn_executableの場合に長さ0の文字列の0番目にアクセスしないように。
std::string path = args[1];
size_t end_pos = path.find_last_of('/');
if (end_pos != std::string::npos)
***************
*** 846,852 ****
server::MimeTypes::iterator it_mime;
std::string type;
!              if (httpd->spawn_executable && res_isexe(path, path_info)) {
type = "@";
} else {
tstring dot = _T(".");
--- 849,855 ----
server::MimeTypes::iterator it_mime;
std::string type;
!              if (httpd->spawn_executable && res_isexe(path, path_info, script_name)) {
type = "@";
} else {
tstring dot = _T(".");
***************
*** 965,971 ****
if (type.size() == 1) {
args.push_back(path);
!                      args.push_back("");
} else {
args.push_back(type.substr(1));
args.push_back(path);
--- 968,974 ----
if (type.size() == 1) {
args.push_back(path);
! //                         args.push_back("");
} else {
args.push_back(type.substr(1));
args.push_back(path);

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


The reCAPTCHA verification period has expired. Please reload the page.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください