jk_ajp14.c

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

C
647
字号
 * */int ajp14_marshal_unknown_packet_into_msgb(jk_msg_buf_t		*msg,                                           jk_msg_buf_t		*unk,                                           jk_logger_t  	*l){	jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_unknown_packet_into_msgb\n");	/* To be on the safe side */	jk_b_reset(msg);	/* 	 * UNKNOWN PACKET CMD	 */	if (jk_b_append_byte(msg, AJP14_UNKNOW_PACKET_CMD))		return JK_FALSE;	/*	 * UNHANDLED MESSAGE SIZE	 */	if (jk_b_append_int(msg, (unsigned short) jk_b_get_len(unk)))		return JK_FALSE;	/*	 * UNHANDLED MESSAGE (Question : Did we have to send all the message or only part of)	 *					 (           ie: only 1k max								    )	 */	if (jk_b_append_bytes(msg, jk_b_get_buff(unk), jk_b_get_len(unk))) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_unknown_packet_into_msgb - Error appending the UNHANDLED MESSAGE\n");        return JK_FALSE;    }    return JK_TRUE;}/* * Build the Context Query Cmd (autoconf) * * +--------------------------+---------------------------------+ * | CONTEXT QRY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | * +--------------------------+---------------------------------+ * */int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,										  char         *virtual,										  jk_logger_t  *l){	jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_query_into_msgb\n");	/* To be on the safe side */	jk_b_reset(msg);    /*     * CONTEXT QUERY CMD     */    if (jk_b_append_byte(msg, AJP14_CONTEXT_QRY_CMD))        return JK_FALSE;    /*     * VIRTUAL HOST CSTRING     */     if (jk_b_append_string(msg, virtual)) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_query_into_msgb - Error appending the virtual host string\n");        return JK_FALSE;    }	return JK_TRUE;}/* * Decode the Context Info Cmd (Autoconf) * * The Autoconf feature of AJP14, let us know which URL/URI could * be handled by the servlet-engine * * +---------------------------+---------------------------------+----------------------------+-------------------------------+-----------+ * | CONTEXT INFO CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | URL1 [\n] URL2 [\n] URL3 [\n] | NEXT CTX. | * +---------------------------+---------------------------------+----------------------------+-------------------------------+-----------+ */int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,								 jk_context_t *c,                                 jk_logger_t  *l){    char *vname;    char *cname;    char *uri;    vname  = (char *)jk_b_get_string(msg);    jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_info - get virtual %s for virtual %s\n", vname, c->virtual);    if (! vname) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get virtual hostname\n");        return JK_FALSE;    }    /* Check if we get the correct virtual host */    if (c->virtual != NULL && 	vname != NULL &&	strcmp(c->virtual, vname)) {        /* set the virtual name, better to add to a virtual list ? */                if (context_set_virtual(c, vname) == JK_FALSE) {            jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't malloc virtual hostname\n");            return JK_FALSE;        }    }    for (;;) {            cname  = (char *)jk_b_get_string(msg);         if (! cname) {            jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get context\n");            return JK_FALSE;        }           jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_info - get context %s for virtual %s\n", cname, vname);        /* grab all contexts up to empty one which indicate end of contexts */        if (! strlen(cname))             break;        /* create new context base (if needed) */        if (context_add_base(c, cname) == JK_FALSE) {            jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't add/set context %s\n", cname);            return JK_FALSE;        }	    for (;;) {            uri  = (char *)jk_b_get_string(msg);		    if (!uri) {                jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get URI\n");                return JK_FALSE;		    }		    if (! strlen(uri)) {			    jk_log(l, JK_LOG_DEBUG, "No more URI for context %s", cname);			    break;		    }		    jk_log(l, JK_LOG_INFO, "Got URI (%s) for virtualhost %s and context %s\n", uri, vname, cname);		    if (context_add_uri(c, cname, uri) == JK_FALSE) {                jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't add/set uri (%s) for context %s\n", uri, cname);                return JK_FALSE;            } 	    }	}    return JK_TRUE;}/* * Build the Context State Query Cmd * * We send the list of contexts where we want to know state, empty string end context list* * If cname is set, only ask about THIS context * * +----------------------------+----------------------------------+----------------------------+----+ * | CONTEXT STATE CMD (1 byte) |  VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | .. | * +----------------------------+----------------------------------+----------------------------+----+ * */int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,                                          jk_context_t *c,                                          char         *cname,                                          jk_logger_t  *l){    jk_context_item_t *ci;    int                i;    jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_state_into_msgb\n");    /* To be on the safe side */    jk_b_reset(msg);    /*     * CONTEXT STATE CMD     */    if (jk_b_append_byte(msg, AJP14_CONTEXT_STATE_CMD))        return JK_FALSE;    /*     * VIRTUAL HOST CSTRING     */     if (jk_b_append_string(msg, c->virtual)) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the virtual host string\n");        return JK_FALSE;    }        if (cname) {        ci = context_find_base(c, cname);        if (! ci) {            jk_log(l, JK_LOG_ERROR, "Warning ajp14_marshal_context_state_into_msgb - unknown context %s\n", cname);            return JK_FALSE;        }        /*         * CONTEXT CSTRING         */        if (jk_b_append_string(msg, cname )) {            jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the context string %s\n", cname);            return JK_FALSE;        }    }    else { /* Grab all contexts name */        for (i = 0; i < c->size; i++) {                    /*             * CONTEXT CSTRING             */            if (jk_b_append_string(msg, c->contexts[i]->cbase )) {                jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the context string\n");                return JK_FALSE;            }        }    }    /* End of context list, an empty string */     if (jk_b_append_string(msg, "")) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending end of contexts\n");        return JK_FALSE;    }    return JK_TRUE;}/* * Decode the Context State Reply Cmd * * We get update of contexts list, empty string end context list* * * +----------------------------------+---------------------------------+----------------------------+------------------+----+ * | CONTEXT STATE REPLY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) | .. | * +----------------------------------+---------------------------------+----------------------------+------------------+----+ * */int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,										jk_context_t *c,                           				jk_logger_t  *l){    char                *vname;    char                *cname;    jk_context_item_t   *ci;    /* get virtual name */	vname  = (char *)jk_b_get_string(msg);    if (! vname) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't get virtual hostname\n");        return JK_FALSE;    }    /* Check if we speak about the correct virtual */    if (strcmp(c->virtual, vname)) {        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - incorrect virtual %s instead of %s\n",               vname, c->virtual);        return JK_FALSE;    }     for (;;) {        /* get context name */	    cname  = (char *)jk_b_get_string(msg);	    if (! cname) {		    jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't get context\n");		    return JK_FALSE;	    }	        if (! strlen(cname))            break;        ci = context_find_base(c, cname);        if (! ci) {            jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - unknow context %s for virtual %s\n",                    cname, vname);            return JK_FALSE;        }	    ci->status = jk_b_get_int(msg);        jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_state_reply - updated context %s to state %d\n", cname, ci->status);    }    return JK_TRUE;}/* * Decode the Context Update Cmd *  * +-----------------------------+---------------------------------+----------------------------+------------------+ * | CONTEXT UPDATE CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) | * +-----------------------------+---------------------------------+----------------------------+------------------+ *  */int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,                                       jk_context_t *c,                                       jk_logger_t  *l){	return (ajp14_unmarshal_context_state_reply(msg, c, l));}

⌨️ 快捷键说明

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