jk_status.c
来自「以便Apache与其他服务进行整合 Mod_JK安装」· C语言 代码 · 共 1,753 行 · 第 1/5 页
C
1,753 行
}static int jk_printf(jk_ws_service_t *s, const char *fmt, ...){ int rc = 0; va_list args;#ifdef NETWARE/* On NetWare, this can get called on a thread that has a limited stack so *//* we will allocate and free the temporary buffer in this function */ char *buf;#else char buf[HUGE_BUFFER_SIZE];#endif if (!s || !fmt) { return -1; } va_start(args, fmt);#ifdef NETWARE buf = (char *)malloc(HUGE_BUFFER_SIZE); if (NULL == buf) return -1;#endif rc = vsnprintf(buf, HUGE_BUFFER_SIZE, fmt, args); va_end(args); if (rc > 0) s->write(s, buf, rc);#ifdef NETWARE free(buf);#endif return rc;}static void jk_print_xml_start_elt(jk_ws_service_t *s, status_worker_t *w, int indentation, int close_tag, const char *name){ if (close_tag) { jk_printf(s, "%*s<%s%s>\n", indentation, "", w->ns, name); } else { jk_printf(s, "%*s<%s%s\n", indentation, "", w->ns, name); }}static void jk_print_xml_close_elt(jk_ws_service_t *s, status_worker_t *w, int indentation, const char *name){ jk_printf(s, "%*s</%s%s>\n", indentation, "", w->ns, name);}static void jk_print_xml_stop_elt(jk_ws_service_t *s, int indentation, int close_tag){ if (close_tag) { jk_printf(s, "%*s/>\n", indentation, ""); } else { jk_printf(s, "%*s>\n", indentation, ""); }}static void jk_print_xml_att_string(jk_ws_service_t *s, int indentation, const char *key, const char *value){ jk_printf(s, "%*s%s=\"%s\"\n", indentation, "", key, value ? value : "");}static void jk_print_xml_att_int(jk_ws_service_t *s, int indentation, const char *key, int value){ jk_printf(s, "%*s%s=\"%d\"\n", indentation, "", key, value);}static void jk_print_xml_att_uint32(jk_ws_service_t *s, int indentation, const char *key, jk_uint32_t value){ jk_printf(s, "%*s%s=\"%" JK_UINT32_T_FMT "\"\n", indentation, "", key, value);}static void jk_print_xml_att_uint64(jk_ws_service_t *s, int indentation, const char *key, jk_uint64_t value){ jk_printf(s, "%*s%s=\"%" JK_UINT64_T_FMT "\"\n", indentation, "", key, value);}static void jk_print_prop_att_string(jk_ws_service_t *s, status_worker_t *w, const char *name, const char *key, const char *value){ if (name) { jk_printf(s, "%s.%s.%s=%s\n", w->prefix, name, key, value ? value : ""); } else { jk_printf(s, "%s.%s=%s\n", w->prefix, key, value ? value : ""); }}static void jk_print_prop_att_int(jk_ws_service_t *s, status_worker_t *w, const char *name, const char *key, int value){ if (name) { jk_printf(s, "%s.%s.%s=%d\n", w->prefix, name, key, value); } else { jk_printf(s, "%s.%s=%d\n", w->prefix, key, value); }}static void jk_print_prop_att_uint32(jk_ws_service_t *s, status_worker_t *w, const char *name, const char *key, jk_uint32_t value){ if (name) { jk_printf(s, "%s.%s.%s=%" JK_UINT32_T_FMT "\n", w->prefix, name, key, value); } else { jk_printf(s, "%s.%s=%" JK_UINT32_T_FMT "\n", w->prefix, key, value); }}static void jk_print_prop_att_uint64(jk_ws_service_t *s, status_worker_t *w, const char *name, const char *key, jk_uint64_t value){ if (name) { jk_printf(s, "%s.%s.%s=%" JK_UINT64_T_FMT "\n", w->prefix, name, key, value); } else { jk_printf(s, "%s.%s=%" JK_UINT64_T_FMT "\n", w->prefix, key, value); }}static void jk_print_prop_item_string(jk_ws_service_t *s, status_worker_t *w, const char *name, const char *list, int num, const char *key, const char *value){ if (name) { jk_printf(s, "%s.%s.%s.%d.%s=%s\n", w->prefix, name, list, num, key, value ? value : ""); } else { jk_printf(s, "%s.%s.%d.%s=%s\n", w->prefix, list, num, key, value ? value : ""); }}/* Actually APR's apr_strfsize */static char *status_strfsize(jk_uint64_t size, char *buf){ const char ord[] = "KMGTPE"; const char *o = ord; unsigned int remain, siz; if (size < 973) { if (sprintf(buf, "%3d ", (int) size) < 0) return strcpy(buf, "****"); return buf; } do { remain = (unsigned int)(size & 0x03FF); size >>= 10; if (size >= 973) { ++o; continue; } siz = (unsigned int)(size & 0xFFFF); if (siz < 9 || (siz == 9 && remain < 973)) { if ((remain = ((remain * 5) + 256) / 512) >= 10) ++siz, remain = 0; if (sprintf(buf, "%d.%d%c", siz, remain, *o) < 0) return strcpy(buf, "****"); return buf; } if (remain >= 512) ++siz; if (sprintf(buf, "%3d%c", siz, *o) < 0) return strcpy(buf, "****"); return buf; } while (1);}static int status_rate(worker_record_t *wr, status_worker_t *w, jk_logger_t *l){ jk_uint32_t mask = 0; int activation = wr->s->activation; int state = wr->s->state; jk_uint32_t good = w->good_mask; jk_uint32_t bad = w->bad_mask; int rv = 0; switch (activation) { case JK_LB_ACTIVATION_ACTIVE: mask = JK_STATUS_MASK_ACTIVE; break; case JK_LB_ACTIVATION_DISABLED: mask = JK_STATUS_MASK_DISABLED; break; case JK_LB_ACTIVATION_STOPPED: mask = JK_STATUS_MASK_STOPPED; break; default: jk_log(l, JK_LOG_WARNING, "Status worker '%s' unknown activation type '%d'", w->name, activation); } switch (state) { case JK_LB_STATE_OK: mask &= JK_STATUS_MASK_OK; break; case JK_LB_STATE_IDLE: mask &= JK_STATUS_MASK_IDLE; break; case JK_LB_STATE_BUSY: mask &= JK_STATUS_MASK_BUSY; break; case JK_LB_STATE_ERROR: mask &= JK_STATUS_MASK_ERROR; break; case JK_LB_STATE_RECOVER: mask &= JK_STATUS_MASK_RECOVER; break; case JK_LB_STATE_FORCE: mask &= JK_STATUS_MASK_RECOVER; break; case JK_LB_STATE_PROBE: mask &= JK_STATUS_MASK_RECOVER; break; default: jk_log(l, JK_LOG_WARNING, "Status worker '%s' unknown state type '%d'", w->name, state); } if (mask&bad) rv = -1; else if (mask&good) rv = 1; else rv = 0; if (JK_IS_DEBUG_LEVEL(l)) jk_log(l, JK_LOG_DEBUG, "Status worker '%s' rating of activation '%s' and state '%s' for good '%08" JK_UINT32_T_HEX_FMT "' and bad '%08" JK_UINT32_T_HEX_FMT "' is %d", w->name, jk_lb_get_activation(wr, l), jk_lb_get_state(wr, l), good, bad, rv); return rv;}static jk_uint32_t status_get_single_rating(const char rating, jk_logger_t *l){ if (JK_IS_DEBUG_LEVEL(l)) jk_log(l, JK_LOG_DEBUG, "rating retrieval for '%c'", rating); switch (rating) { case 'A': case 'a': return JK_STATUS_MASK_ACTIVE; case 'D': case 'd': return JK_STATUS_MASK_DISABLED; case 'S': case 's': return JK_STATUS_MASK_STOPPED; case 'O': case 'o': return JK_STATUS_MASK_OK; case 'I': case 'i': case 'N': case 'n': return JK_STATUS_MASK_IDLE; case 'B': case 'b': return JK_STATUS_MASK_BUSY; case 'R': case 'r': return JK_STATUS_MASK_RECOVER; case 'E': case 'e': return JK_STATUS_MASK_ERROR; default: jk_log(l, JK_LOG_WARNING, "Unknown rating type '%c'", rating); return 0; }}static jk_uint32_t status_get_rating(const char *rating, jk_logger_t *l){ int off = 0; jk_uint32_t mask = 0; while (rating[off] == ' ' || rating[off] == '\t' || rating[off] == '.') { off++; } mask = status_get_single_rating(rating[off], l); while (rating[off] != '\0' && rating[off] != '.') { off++; } if (rating[off] == '.') { off++; } if (rating[off] != '\0') { mask &= status_get_single_rating(rating[off], l); } if (JK_IS_DEBUG_LEVEL(l)) jk_log(l, JK_LOG_DEBUG, "rating for '%s' is '%08" JK_UINT32_T_HEX_FMT "'", rating, mask); return mask;}static const char *status_worker_type(int t){ if (t < 0 || t > 6) t = 0; return worker_type[t];}static int status_get_string(status_endpoint_t *p, const char *param, const char *def, const char **result, jk_logger_t *l){ int rv; *result = jk_map_get_string(p->req_params, param, NULL); if (*result) { rv = JK_TRUE; } else { *result = def; rv = JK_FALSE; } if (JK_IS_DEBUG_LEVEL(l)) jk_log(l, JK_LOG_DEBUG,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?