[Armadillo:00723] Re: Armadillo-J のCGI : template.cの外にあるCGIページアクセス方法について

kurosaki email@hidden
2005年 12月 8日 (木) 23:54:01 JST


ありがとうございます。ざっと、やってみましたがうまく動作しないようです。
別のプログラム作成で時間をとられしまい、この課題はしばらく後になりそうです。
再度着手し、見えなくなりましたらまたご指南くださるとありがたいです。

よろしくお願いいたします。


-----Original Message-----
From: email@hidden
[mailto:email@hidden]On Behalf Of Makoto
Nakamura
Sent: Thursday, December 08, 2005 6:08 PM
To: Armadillo series general discussion list
Subject: [Armadillo:00721] Re: Armadillo-J のCGI : templat
e.cの外にあるCGIページアクセス方法について


いつもお世話になっています。中村です。

ちょっと外しているかもしれませんが、
私の行っているCでCGIを実行している説明です。

以下のようなファイルを作成。

#include <stdio.h>
#include <stdlib.h>
#include <string.h> ※使うものを定義

int main(void)
{
    char *reqMethod;

    reqMethod = getenv("REQUEST_METHOD");
    if(reqMethod == NULL){
        printf("Content-type: text/html; charset=Shift_jis\n\n");
        printf("REQUEST_METHOD ERORR\n");
        exit(2);
    }
    if((strcmp(reqMethod,"GET"))==0){
        doGet();
    }else if((strcmp(reqMethod,"POST"))==0){
        doPost();
    }else {
        printf("Content-type: text/html; charset=Shift_jis\n\n");
        printf("REQUEST_METHOD ERORR\n");
        exit(2);
    }
    return 0;

}

int doGet(void)
{
    printf("Content-type: text/html; charset=Shift_jis\n");
    printf("<HTML>);
    ・・・HTMLの出力・・・

    fflush(stdout);

}
int doPost(void)
{
    int content_length;
    char *postinput;
  
  // postパラメータの取得
    postinput = (char *)getenv("CONTENT_LENGTH");
    if (postinput == NULL) {
        return NULL;
    }
    content_length = atoi(postinput);
    if (content_length == 0) {
        return NULL;
    }
    postinput = (char *)malloc(content_length + 1);
    if (postinput == NULL) {
        return NULL;
    }
    ret = fread(postinput, content_length, 1, stdin);
    if(ret == 0){
        free(postinput);
        return NULL;
    }
    ・・・postパラメータ取得・・・
    ・・・postinputに取得したデータが入っている・・・

    printf("Content-type: text/html; charset=Shift_jis\n");
    printf("<HTML>);
    ・・・HTMLの出力・・・

    fflush(stdout);

}

上記をコンパイルしたものを、
atmark-dist/romfs/home/www/cgi-bin/
に配置。
パーミッションは744。

Makefileはユーザーズガイドに載っているものを
参考にファイル名等を変更するだけです。

thttpdの起動は、
thttpd -d /home/www -c 'cgi-bin/*' &
としています。

あとは、アルマジロを起動して
ブラウザ等からhttp://xxx.xxx.xxx.xxx/cgi-bin/{作ったファイル名}
でアクセスすれば実行されます。

"kurosaki" <email@hidden>さん:
> お世話になります。黒崎です。
>
> 残念ながらご指摘の場所に以下のような実行ファイルをおいてみたのですが起動せ
> ず、ダウンロードするか実行するかとブラウザがは応答してしまいます。
>
> ファイル名: s.cgi    パーミッション775
>
> #!/bin/sh
>
>   echo "Content-type: text/html\n\n"
>   echo "<HTML>"
>   echo "<P>Can you see me!</P>"
>   echo "</HTML>"
>
> cでcgiとして実行できるものを作成するには、ヘッダーやmakeなどいくつ
か
> ハードルがありそうです。実績のあるかたいらっしゃいましたら、よろしくお願い
い
> たします。
>
> -----Original Message-----
> From: email@hidden
> [mailto:email@hidden]On Behalf Of Fumito
> Morishima
> Sent: Wednesday, December 07, 2005 9:16 PM
> To: Armadillo series general discussion list
> Subject: [Armadillo:00715] Re: Armadillo-J のCGI : templat
> e.cの外にあるCGIページアクセス方法について
>
>
> 森島です。
>
> template.c ですが、
> http://armadillo.atmark-techno.com/armadillo-j/memo/circuitRelay2
> で、説明されているファイルですね?
>
> 質問の回答になっているか、自信がありませんが、
> HTMLで <FORM ACTION="実行したいファイル名"> と記述することで、
> 任意のプログラムを実行できると思います。
>
> template.c なら、以下の行です。
> printf("<FORM ACTION=\"%s\" METHOD=POST>", "/cgi-bin/cgi_demo");
> cgi_demoの代わりに実行したいプログラム名を記載します。
> プログラムはcgi-binディレクトリ以下に配置する必要があります。
>
> perlは、現状のArmadillo-Jの環境では動作しないと思います。
>
> kurosaki wrote:
> > SYSCOM。黒崎です。
> >
> >  template.c からそれ以外のcのプログラムで作成したcgiへも起動をかけた
い
>> > ですが、どのように作成すればよいかご存じの方いらっしゃいましたらご指南く
だ
>> > い。例題のtemplate.c は自分を再度自分で呼んでいますので方法が見えませ
ん。
> >
> > ユザーにtelnetでメニューの設定させる時代ではないですから、なんとか
し
>> > ければと思っています。
> > ちなみにperlで記述できればそちらの方がよいと思っています。もしその方
法
>> > ご存じの方いらしゃいましたら、よろしくお願いいたします。
> >
> >
> > _______________________________________________
> > armadillo mailing list
> > email@hidden
> > http://lists.atmark-techno.com/mailman/listinfo/armadillo
> _______________________________________________
> armadillo mailing list
> email@hidden
> http://lists.atmark-techno.com/mailman/listinfo/armadillo
>
> _______________________________________________
> armadillo mailing list
> email@hidden
> http://lists.atmark-techno.com/mailman/listinfo/armadillo
>

_______________________________________________
armadillo mailing list
email@hidden
http://lists.atmark-techno.com/mailman/listinfo/armadillo




armadillo メーリングリストの案内