欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
APACHE2.0 MOD 模塊開(kāi)發(fā)|技術(shù)文章收集
  • APACHE2.0 MOD 模塊開(kāi)發(fā) [原創(chuàng )]
  • 發(fā)表時(shí)間:(2007-02-05 21:48:34)
  • APACHE2.0 MOD 模塊開(kāi)發(fā) STEP 1

     

    一.目的

    寫(xiě)一個(gè)APACHE2.0MOD模塊,讀取配置,并對所有后綴為.hello的請求進(jìn)行處理。

    二.步驟

    創(chuàng )建一個(gè)mod_hello.c文件

    1.  定義一個(gè)模塊。

    #include "httpd.h"

    #include "http_config.h"

    module AP_MODULE_DECLARE_DATA hello_module;

     

    2.  定義接口。

    module AP_MODULE_DECLARE_DATA hello_module =

    {

            STANDARD20_MODULE_STUFF, // standard stuff; no need to mess with this.

            NULL, // create per-directory configuration structures - we do not.

            NULL, // merge per-directory - no need to merge if we are not creating anything.

            create_modhello_config, // create per-server configuration structures.

            NULL, // merge per-server - hrm - examples I have been reading don‘t bother with this for trivial cases.

            mod_hello_cmds, // configuration directive handlers

            mod_hello_register_hooks, // request handlers

    };

    說(shuō)明:

    其中create_modhello_config函數為用來(lái)為自定義的結構分配空間,mod_hello_cmds定義了參數序列和參數的讀取函數。mod_hello_register_hooks定義了請求處理函數

    3.  初始化配置,讀取配置。

    配置結構的定義:

    typedef struct {

            char   *welcome;

            int    max_process;

    } modhello_config;

    參數的定義:

    static const command_rec mod_hello_cmds[] =

    {

            AP_INIT_TAKE1(

                    "welcome",

                    set_modhello_string,

                    NULL,

                    RSRC_CONF,

                    "hello,apache"

            ),

            AP_INIT_TAKE1(

                    "ModuleMaxProcess",

                    set_modhello_string,

                    NULL,

                    RSRC_CONF,

                    NULL

            ),

            {NULL}

    };

    參數結構的創(chuàng )建,由apache在裝載模塊時(shí)候調用。

    static void *create_modhello_config(apr_pool_t *p, server_rec *s)

    {

            modhello_config *newcfg;

     

            // allocate space for the configuration structure from the provided pool p.

            newcfg = (modhello_config *) apr_pcalloc(p, sizeof(modhello_config));

     

            // return the new server configuration structure.

            return (void *) newcfg;

    }

    參數讀取函數

     static const char *set_modhello_string(cmd_parms *parms, void *mconfig, const char *arg)

    {

            modhello_config *s_cfg = ap_get_module_config(parms->server->module_config, &hello_module);

             if(!strcmp(parms->cmd->name,"welcome")){

                    s_cfg->welcome= (char *) arg;

            }else if(!strcmp(parms->cmd->name,"ModuleMaxProcess")){

                    s_cfg->max_process=atoi(arg);

            }

     

            // success

            return NULL;

    }

     

    4.  處理請求。

    注冊請求。

    static void mod_hello_register_hooks (apr_pool_t *p)

    {

      ap_hook_handler(mod_hello_method_handler, NULL, NULL, APR_HOOK_LAST);

    }

     

    請求處理函數

     static int mod_hello_method_handler (request_rec *r)

    {

            modhello_config *s_cfg ;

            if(strcmp("hello-s cript",r->handler)) return DECLINED;

            s_cfg= ap_get_module_config(r->server->module_config, &hello_module);

            fprintf(stderr,"%s,%s,%d\n",r->content_type,r->handler,s_cfg->max_process);

            ap_rputs("hello,world!",r);

            return 0;

    }

    三.安裝。

    1.       編譯。

    Makefile.

     all:    mod_hello.c

            gcc -g -I/home/wee/apache2/include/ -fPIC -o mod_hello.o -c mod_hello.c

            gcc -shared -I/home/wee/apache2/include/ -o libmodhello.so -lc mod_hello.o

            cp *.so /home/wee/apache2/modules/

    clean:

            rm *.o *.so

    2.       配置。

    修改Httpd.conf。

    增加處理:

     LoadModule hello_module        modules/libmodhello.so

    AddHandler hello-s cript .hello

              增加參數:

                  welcome  "hello,world"

    ModuleMaxProcess   5

    3.       安裝

    gcc -v

    Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs

    gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)

    make.

    四.測試。

    訪(fǎng)問(wèn)http://xxx.xxx.xxx.xxx/a.hello, 屏幕上打印出 “hello,world”,同時(shí)LOG中也有打印信息。

    五.參考資料

    1.  http://threebit.net/tutorials/apache2_modules/tut1/tutorial1.html

    2.  Writing.Apache Modules with Perl and CLincoln Stein and Doug MacEachern

    3.  http://apache-modules.com/

    4.  http://www.apache.org/ 

     

    APACHE MOD 開(kāi)發(fā) Step 2 獲取用戶(hù)輸入

    APACHE MOD 開(kāi)發(fā) Step 2 獲取用戶(hù)輸入

    1. 了解apr_table_t結構
    可以把他理解為一個(gè)HASH表,可以對他進(jìn)行取值賦值操作,常用的有
    apr_table_add
    apr_table_set
    apr_table_get
    例如:
    char *slen=apr_table_get(r->headers_in, "Content-Length");
    2. 了解request_rec
    這是一個(gè)最重要的結構,定義在httpd.h第682行.
    注意到handle函數的唯一的參數
    static int mod_hello_method_handler (request_rec *r);你可以認為從這個(gè)結構里面你可以得到所有一切.

     

     

    重要的幾個(gè)結構成員
        apr_pool_t *pool;
        /** The connection to the client */
        conn_rec *connection;
        /** The virtual host for this request */
    server_rec *server;

     

     

    int method_number; //提交信息的類(lèi)型,GET或者POST
    char *args; //存放GET的參數
    apr_table_t *headers_in; //提交信息的頭信息的保存位置
    const char *handler;    //處理的類(lèi)型

     

     

      
    3. 讀取HTTP頭
    信息在r->headers_in里面,那么就是
    char *slen=apr_table_get(r->headers_in, "Content-Length");

     

     

    4. 獲得GET方法傳遞的數據
    信息在r->args里面.注意,這里的數據是沒(méi)有經(jīng)過(guò)解析的,也就是說(shuō)URL編碼過(guò)的,如果你不使用類(lèi)似libapreq2而自行解析的話(huà),需要自行編碼.
    ap_log_rerror(APLOG_MARK, APLOG_ERR,0,r,"get query string:%s",r->args);
    5. 獲得POST方法傳遞的數據
         數據在request_rec關(guān)聯(lián)的bucket里面.bucket的解釋將在下一步解釋,那么我們簡(jiǎn)單的使用ap_get_client_block來(lái)讀取吧.其實(shí)這個(gè)函數里面也是調用了bucket操作.
      
    6. 簡(jiǎn)單的例子.
            if(strcmp("hello-s cript",r->handler)) return DECLINED;
            //get the comand.
            if(r->method_number==M_GET){
                    ap_log_rerror(APLOG_MARK, APLOG_ERR,0,r,"get query string:%s",r->args);
            }else if(r->method_number==M_POST){
                   handle_post (r);
            }else{
                    return DECLINED;
            }

     

     

    handle_post 函數
     void handle_post(request_rec *r)
    {         
              
            size_t total_bytes;
            int rstat=0;
            char cbuf[HUGE_STRING_LEN];

     

     

            rstat = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK);
            if (ap_should_client_block(r)) {
                    int nbytes;
                    while ((nbytes = ap_get_client_block(r, cbuf, HUGE_STRING_LEN)) > 0){
                            cbuf[nbytes]=‘\0‘;
                            ap_rputs(cbuf,r);
                            total_bytes += nbytes;
                    }
           }
     } 
    7. 小結
    現在對模塊有了簡(jiǎn)單的理解,知道如何寫(xiě)一個(gè)模塊,知道數據在哪.知道如何處理輸入輸出,下面要知道APAHCE內部是如何的運作,APR運行庫的常用函數,然后是利用APACHE的服務(wù)框架完成更多的工作.要把APACHE看做一個(gè)SOCKET服務(wù)器,而不僅僅是一個(gè)WEB服務(wù)器
  • 本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
    打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
    猜你喜歡
    類(lèi)似文章
    C語(yǔ)言擴展Apache模塊開(kāi)發(fā)入門(mén)篇
    抓蝦 - Python Module Auto Reload
    用 Python 和 werobot 開(kāi)發(fā)微信公眾號
    Apache 2.2.17, Python 2.6, mod_python-3.3.1.win32-py2.6-apache2.2
    PHP CI 去掉index.php
    讓XAMPP支持Python及Django
    更多類(lèi)似文章 >>
    生活服務(wù)
    分享 收藏 導長(cháng)圖 關(guān)注 下載文章
    綁定賬號成功
    后續可登錄賬號暢享VIP特權!
    如果VIP功能使用有故障,
    可點(diǎn)擊這里聯(lián)系客服!

    聯(lián)系客服

    欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久