mod_jk.c

来自「Tomcat 4.1与WebServer集成组件的源代码包.」· C语言 代码 · 共 506 行 · 第 1/2 页

C
506
字号
#ifdef AS400                 /* Fix escapes in Location Header URL*/                ap_fixup_escapes((char *)header_values[h],                 strlen(header_values[h]), ap_hdrs_from_ascii);#endif                 apr_table_set(r->headers_out,                               header_names[h], header_values[h]);            } else if(!strcasecmp(header_names[h], "Content-Length")) {                apr_table_set(r->headers_out,                               header_names[h], header_values[h]);            } else if(!strcasecmp(header_names[h], "Transfer-Encoding")) {                apr_table_set(r->headers_out,                               header_names[h], header_values[h]);            } else if(!strcasecmp(header_names[h], "Last-Modified")) {                /*                 * If the script gave us a Last-Modified header, we can't just                 * pass it on blindly because of restrictions on future values.                 */                ap_update_mtime(r, ap_parseHTTPdate(header_values[h]));                ap_set_last_modified(r);            } else {                                apr_table_add(r->headers_out,                               header_names[h], header_values[h]);            }        }        /* this NOP function was removed in apache 2.0 alpha14 */        /* ap_send_http_header(r); */        p->response_started = JK_TRUE;                return JK_TRUE;    }    return JK_FALSE;}/* * Read a chunk of the request body into a buffer.  Attempt to read len * bytes into the buffer.  Write the number of bytes actually read into * actually_read. * * Think of this function as a method of the apache1.3-specific subclass of * the jk_ws_service class.  Think of the *s param as a "this" or "self" * pointer. */static int JK_METHOD ws_read(jk_ws_service_t *s,                             void *b,                             unsigned len,                             unsigned *actually_read){    if(s && s->ws_private && b && actually_read) {        apache_private_data_t *p = s->ws_private;        if(!p->read_body_started) {           if(ap_should_client_block(p->r)) {                p->read_body_started = JK_TRUE;            }        }        if(p->read_body_started) {#ifdef AS400    int long rv = OK;    if (rv = ap_change_request_body_xlate(p->r, 65535, 65535)) /* turn off request body translation*/    {		         ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,                      NULL, "mod_jk: Error on ap_change_request_body_xlate, rc=%d \n", rv);        return JK_FALSE;    }#else    long rv;#endif            if ((rv = ap_get_client_block(p->r, b, len)) < 0) {                *actually_read = 0;            } else {                *actually_read = (unsigned) rv;            }            return JK_TRUE;        }    }    return JK_FALSE;}/* * Write a chunk of response data back to the browser.  If the headers * haven't yet been sent over, send over default header values (Status = * 200, basically). * * Write len bytes from buffer b. * * Think of this function as a method of the apache1.3-specific subclass of * the jk_ws_service class.  Think of the *s param as a "this" or "self" * pointer. *//* Works with 4096, fails with 8192 */#ifndef CHUNK_SIZE#define CHUNK_SIZE 4096#endifstatic int JK_METHOD ws_write(jk_ws_service_t *s,                              const void *b,                              unsigned l){#ifdef AS400    int rc;#endif    if(s && s->ws_private && b) {        apache_private_data_t *p = s->ws_private;        if(l) {            /* BUFF *bf = p->r->connection->client; */            size_t w = (size_t)l;            size_t r = 0;            long ll=l;            char *bb=(char *)b;                        if(!p->response_started) {                jk_log(main_log, JK_LOG_DEBUG,                        "Write without start, starting with defaults\n");                if(!s->start_response(s, 200, NULL, NULL, NULL, 0)) {                    return JK_FALSE;                }            }            if (p->r->header_only) {#ifndef AS400                ap_rflush(p->r);#endif                return JK_TRUE;            }#ifdef AS400            rc = ap_change_response_body_xlate(p->r, 65535, 65535); /* turn off response body translation*/	    if(rc){                ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,                              NULL, "mod_jk: Error on ap_change_response_body_xlate, rc=%d \n", rc);                 return JK_FALSE;	                 }#endif                        /* Debug - try to get around rwrite */            while( ll > 0 ) {                size_t toSend=(ll>CHUNK_SIZE) ? CHUNK_SIZE : ll;                r = ap_rwrite((const char *)bb, toSend, p->r );                jk_log(main_log, JK_LOG_DEBUG,                        "writing %ld (%ld) out of %ld \n",toSend, r, ll );                ll-=CHUNK_SIZE;                bb+=CHUNK_SIZE;                                if(toSend != r) {                     return JK_FALSE;                 }                             }            /*             * To allow server push. After writing full buffers             */#ifndef AS400            if(ap_rflush(p->r) != APR_SUCCESS) {                ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,                              NULL, "mod_jk: Error flushing \n"  );                return JK_FALSE;            }#endif        }                return JK_TRUE;    }    return JK_FALSE;}/* ========================================================================= *//* Utility functions                                                         *//* ========================================================================= *//* ========================================================================= *//* Log something to Jk log file then exit */static void jk_error_exit(const char *file,                           int line,                           int level,                           const server_rec *s,                           apr_pool_t *p,                           const char *fmt, ...){    va_list ap;    char *res;    va_start(ap, fmt);    res = apr_pvsprintf(s->process->pool, fmt, ap);    va_end(ap);    ap_log_error(file, line, level, 0, s, res);    /* Exit process */    exit(1);}static int get_content_length(request_rec *r){    if(r->clength > 0) {        return r->clength;    } else {        char *lenp = (char *)apr_table_get(r->headers_in, "Content-Length");        if(lenp) {            int rc = atoi(lenp);            if(rc > 0) {                return rc;            }        }    }    return 0;}static int init_ws_service(apache_private_data_t *private_data,                           jk_ws_service_t *s,                           jk_server_conf_t *conf){    request_rec *r      = private_data->r;    apr_port_t port;    char *ssl_temp      = NULL;    s->jvm_route        = NULL;    /* Used for sticky session routing */    /* Copy in function pointers (which are really methods) */    s->start_response   = ws_start_response;    s->read             = ws_read;    s->write            = ws_write;    s->auth_type    = NULL_FOR_EMPTY(r->ap_auth_type);    s->remote_user  = NULL_FOR_EMPTY(r->user);    s->protocol     = r->protocol;    s->remote_host  = (char *)ap_get_remote_host(r->connection,                                                  r->per_dir_config,                                                  REMOTE_HOST, NULL);    s->remote_host  = NULL_FOR_EMPTY(s->remote_host);    s->remote_addr  = NULL_FOR_EMPTY(r->connection->remote_ip);    jk_log(main_log, JK_LOG_DEBUG,                  "agsp=%u agsn=%s hostn=%s shostn=%s cbsport=%d sport=%d \n",                ap_get_server_port( r ),                ap_get_server_name( r ),                r->hostname,                r->server->server_hostname,                r->connection->base_server->port,                r->server->port                );    /* get server name */    /* s->server_name= (char *)(r->hostname ? r->hostname : r->server->server_hostname); */    /* XXX : 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?