Beispiel #1
0
int httpreqHeaderRecved(lsi_cb_param_t *rec)
{
    const char *host, *ua, *uri, *accept;
    char *headerBuf;
    int hostLen, uaLen, acceptLen, headerLen;
    char uaBuf[1024], hostBuf[128], acceptBuf[512];
    ls_xpool_t *pPool = g_api->get_session_pool(rec->_session);

    uri = g_api->get_req_uri(rec->_session, NULL);
    host = g_api->get_req_header(rec->_session, "Host", 4, &hostLen);
    ua = g_api->get_req_header(rec->_session, "User-Agent", 10, &uaLen);
    accept = g_api->get_req_header(rec->_session, "Accept", 6, &acceptLen);
    g_api->log(NULL, LSI_LOG_DEBUG,
               "#### mymodulehttp test, httpreqHeaderRecved URI:%s host:%s, ua:%s accept:%s\n",
               uri, getNullEndString(host, hostLen, hostBuf, 128), getNullEndString(ua,
                       uaLen, uaBuf, 1024), getNullEndString(accept, acceptLen, acceptBuf, 512));

    headerLen = g_api->get_req_raw_headers_length(rec->_session);
    headerBuf = (char *)ls_xpool_alloc(pPool, headerLen + 1);
    memset(headerBuf, 0, headerLen + 1);
    g_api->get_req_raw_headers(rec->_session, headerBuf, headerLen);
    g_api->log(NULL, LSI_LOG_DEBUG,
               "#### mymodulehttp test, httpreqHeaderRecved whole header: %s, length: %d\n",
               headerBuf, headerLen);

    ls_xpool_free(pPool, headerBuf);
    return 0;

}
Beispiel #2
0
static int initdata(lsi_cb_param_t *param)
{
    mydata_t *mydata = (mydata_t *)g_api->get_module_data(param->_session,
                       &MNAME, LSI_MODULE_DATA_HTTP);
    ls_xpool_t *pPool = g_api->get_session_pool(param->_session);
    mydata = (mydata_t *)ls_xpool_alloc(pPool, sizeof(mydata_t));
    memset(mydata, 0, sizeof(mydata_t));
    g_api->log(NULL, LSI_LOG_DEBUG, "#### reqinfomodule initdata\n");
    g_api->set_module_data(param->_session, &MNAME, LSI_MODULE_DATA_HTTP,
                           (void *)mydata);
    return 0;
}
Beispiel #3
0
int httpinit(lsi_cb_param_t *rec)
{
    MyData *myData = (MyData *)g_api->get_module_data(rec->_session, &MNAME,
                     LSI_MODULE_DATA_HTTP);
    ls_xpool_t *pool = g_api->get_session_pool(rec->_session);
    myData = (MyData *)ls_xpool_alloc(pool, sizeof(MyData));
    ls_loopbuf_x(&myData->inWBuf, MAX_BLOCK_BUFSIZE, pool);
    ls_loopbuf_x(&myData->outWBuf, MAX_BLOCK_BUFSIZE, pool);

    g_api->log(NULL, LSI_LOG_DEBUG, "#### mymodulehttp init\n");
    g_api->set_module_data(rec->_session, &MNAME, LSI_MODULE_DATA_HTTP,
                           (void *)myData);
    return 0;
}
Beispiel #4
0
static char *ls_str_do_dupstr(const char *pStr, int len, ls_xpool_t *pool)
{
    char *p;
    if (pool != NULL)
    {
        if ((p = (char *)ls_xpool_alloc(pool, len + 1)) == NULL)
            return NULL;
        memmove(p, pStr, len);
    }
    else if ((p = ls_pdupstr2(pStr, len + 1)) == NULL)
        return NULL;
    *(p + len) = '\0';
    return p;
}
static int addoutput(lsi_param_t *rec, const char *level)
{
    int len = 0, lenNew;
    char *pBuf;
    if (rec->len1 <= 0)
        return g_api->stream_write_next(rec, rec->ptr1, rec->len1);
    pBuf = ls_xpool_alloc(g_api->get_session_pool(rec->session),
                          rec->len1 + strlen(level) + 1);
    snprintf(pBuf, rec->len1 + strlen(level) + 1, "%.*s%.*s",
             rec->len1, (const char *)rec->ptr1, strlen(level) + 1, level);
    lenNew = rec->len1 + strlen(level);
    len = g_api->stream_write_next(rec, pBuf, lenNew);
    if (len < lenNew)
        *rec->flag_out = LSI_CBFO_BUFFERED;
    if (len < rec->len1)
        return len;
    return rec->len1;
}
static int addoutput(lsi_cb_param_t *rec, const char *level)
{
    int len = 0, lenNew;
    char *pBuf;
    if (rec->_param_len <= 0)
        return g_api->stream_write_next(rec, rec->_param, rec->_param_len);
    pBuf = ls_xpool_alloc(g_api->get_session_pool(rec->_session),
                          rec->_param_len + strlen(level) + 1);
    snprintf(pBuf, rec->_param_len + strlen(level) + 1, "%.*s%.*s",
             rec->_param_len, (const char *)rec->_param, strlen(level) + 1, level);
    lenNew = rec->_param_len + strlen(level);
    len = g_api->stream_write_next(rec, pBuf, lenNew);
    if (len < lenNew)
        *rec->_flag_out = LSI_CB_FLAG_OUT_BUFFERED_DATA;
    if (len < rec->_param_len)
        return len;
    return rec->_param_len;
}
Beispiel #7
0
static int begin_process(lsi_session_t *session)
{
#define VALMAXSIZE 4096
#define LINEMAXSIZE (VALMAXSIZE + 50)
    char val[VALMAXSIZE], line[LINEMAXSIZE] = {0};
    int n;
    int i;
    const char *p;
    char *buf;
    mydata_t *mydata = (mydata_t *)g_api->get_module_data(session, &MNAME,
                       LSI_MODULE_DATA_HTTP);
    ls_xpool_t *pPool = g_api->get_session_pool(session);

    //Create response body
    append(session, CONTENT_HEAD, 0);

    //Original request header
    n = g_api->get_req_raw_headers_length(session);
    buf = (char *)ls_xpool_alloc(pPool, n + 1);
    memset(buf, 0, n + 1);
    n = g_api->get_req_raw_headers(session, buf, n + 1);
    append(session, "Original request<table border=1><tr><td><pre>\r\n", 0);
    append(session, buf, n);
    append(session, "\r\n</pre></td></tr>\r\n", 0);
    ls_xpool_free(pPool, buf);

    append(session, "\r\n</table><br>Request headers<br><table border=1>\r\n",
           0);
    for (i = 0; i < sizeof(reqhdr_array) / sizeof(char *); ++i)
    {
        p = g_api->get_req_header(session, reqhdr_array[i],
                                  strlen(reqhdr_array[i]), &n);
        if ((p != NULL) && p[0] != 0 && n > 0)
        {
            memcpy(val, p, n);
            val[n] = '\0';
            n = snprintf(line, LINEMAXSIZE - 1, CONTENT_FORMAT, reqhdr_array[i],
                         val);
            append(session, line, n);
        }
    }


    append(session,
           "\r\n</table><br>Server req env<br><table border=1>\r\n", 0);
    //Server req env
    for (i = LSI_REQ_VAR_REMOTE_ADDR; i < LSI_REQ_COUNT; ++i)
    {
        n = g_api->get_req_var_by_id(session, i, val, VALMAXSIZE);
        if (n > 0)
        {
            val[n] = '\0';
            n = snprintf(line, LINEMAXSIZE - 1, CONTENT_FORMAT, req_array[i],
                         val);
            append(session, line, n);
        }
    }

    append(session, "\r\n</table><br>env varibles<br><table border=1>\r\n", 0);
    for (i = 0; i < sizeof(env_array) / sizeof(char *); ++i)
    {
        //env varibles
        n = g_api->get_req_env(session, env_array[i], strlen(env_array[i]), val,
                               VALMAXSIZE);
        if (n > 0)
        {
            val[n] = '\0';
            n = snprintf(line, LINEMAXSIZE - 1, CONTENT_FORMAT, env_array[i],
                         val);
            append(session, line, n);
        }
    }


    p = g_api->get_req_cookies(session, &n);
    if ((p != NULL) && p[0] != 0 && n > 0)
    {
        append(session,
               "\r\n</table><br>Request cookies<br><table border=1>\r\n", 0);
        append(session, "<tr><td>Cookie</td><td>", 0);
        append(session, p, n);
        append(session, "</td></tr>", 0);
    }

    n = g_api->get_req_cookie_count(session);
    if (n > 0)
    {
        //try get a certen cookie
        p = g_api->get_cookie_value(session, "LSWSWEBUI", 9, &n);
        if ((p != NULL) && n > 0)
        {
            append(session, "<tr><td>cookie_LSWSWEBUI</td><td>", 0);
            append(session, p, n);
            append(session, "</td></tr>", 0);
        }
    }
    append(session, "</table>", 0);

    n = get_reqbody_dealertype(session);

    mydata->req_body_len = g_api->get_req_content_length(session);
    mydata->rcvd_req_body_len = 0;
    mydata->type = n;
    sprintf(line,
            "Will deal with the req body.Type = %d, req body lenghth = %d<br>",
            n, mydata->req_body_len);

    append(session, line, 0);
    if (mydata->type == 0)
    {
        append(session, CONTENT_TAIL, 0);
        mydata->rcvd_done = 1;
        mydata->resp_done = 1;
    }

    g_api->set_status_code(session, 200);

    if (mydata->type == 3)  // Save to file
        mydata->fp = fopen("/tmp/uploadfile", "wb");
    else if (mydata->type == 2)   // Md5
        MD5_Init(&mydata->ctx);

    g_api->flush(session);

//     if ( mydata->type != 0)
    on_read(session);

    //g_api->end_resp(session);
    return 0;
}
Beispiel #8
0
static int enablehook(lsi_session_t *session, lsi_module_t *pModule,
                      int isSend, uint8_t compresslevel)
{
    int ret, aEnableHkpt[5], iEnableCount = 0;
    zmoddata_t *myData = (zmoddata_t *)g_api->get_module_data(session,
                         pModule, LSI_DATA_HTTP);
    ls_xpool_t *pPool = g_api->get_session_pool(session);
    if (myData == NULL)
    {
        myData = (zmoddata_t *)ls_xpool_alloc(pPool, sizeof(zmoddata_t));
        if (myData == NULL)
        {
            g_api->log(session, LSI_LOG_ERROR,
                       "[%s] AddHooks failed: not enough memory.\n",
                       g_api->get_module_name(pModule));
            return LS_FAIL;
        }
        else
            memset(myData, 0, sizeof(*myData));
    }

    ret = LS_FAIL;
    if (isSend)
    {
        if ((myData->send != NULL)
            || ((myData->send = ls_zbufinfo_get(session, pModule,
                                                compresslevel)) != NULL))
            aEnableHkpt[iEnableCount++] = LSI_HKPT_SEND_RESP_BODY;
    }
    else
    {
        if ((myData->recv != NULL)
            || ((myData->recv = ls_zbufinfo_get(session, pModule,
                                                compresslevel)) != NULL))
        {
            aEnableHkpt[iEnableCount++] = LSI_HKPT_RECV_RESP_BODY;
            aEnableHkpt[iEnableCount++] = LSI_HKPT_RCVD_RESP_BODY;
        }
    }

    aEnableHkpt[iEnableCount++] = LSI_HKPT_HTTP_END;
    aEnableHkpt[iEnableCount++] = LSI_HKPT_HANDLER_RESTART;
    ret = g_api->enable_hook(session, pModule, 1, aEnableHkpt,
            iEnableCount);
    if (ret == LS_OK)
    {
        g_api->set_module_data(session, pModule, LSI_DATA_HTTP,
                               (void *)myData);
        return ret;
    }
    if (myData->recv != NULL)
    {
        myData->recv->compresslevel = 0;
        ls_objpool_recycle(&zpooldeflate, myData->recv);
    }
    if (myData->send != NULL)
    {
        myData->send->compresslevel = 0;
        ls_objpool_recycle(&zpooldeflate, myData->send);
    }

    g_api->log(session, LSI_LOG_ERROR,
               "[%s] AddHooks failed: not enough memory or "
               "enable hooks failed.\n", g_api->get_module_name(pModule));
    return LS_FAIL;
}
Beispiel #9
0
ls_inline void *ls_hash_do_alloc(ls_xpool_t *pool, size_t size)
{
    return ((pool != NULL) ? ls_xpool_alloc(pool, size) : ls_palloc(size));
}