static json_object *ap_stlog_conn_rec_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "remote_ip", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->remote_ip))); json_object_object_add(my_object, "remote_host", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->remote_host))); json_object_object_add(my_object, "remote_logname", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->remote_logname))); json_object_object_add(my_object, "local_ip", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->local_ip))); json_object_object_add(my_object, "local_host", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->local_host))); json_object_object_add(my_object, "keepalives", json_object_new_int(r->connection->keepalives)); json_object_object_add(my_object, "data_in_input_filters", json_object_new_int(r->connection->data_in_input_filters)); json_object_object_add(my_object, "local_addr", ap_stlog_local_addr_to_json(r)); json_object_object_add(my_object, "remote_addr", ap_stlog_remote_addr_to_json(r)); return my_object; }
static json_object *ap_stlog_local_addr_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "hostname", json_object_new_string(ap_mrb_string_check(r->pool, r->connection->local_addr->hostname))); json_object_object_add(my_object, "port", json_object_new_int(r->connection->local_addr->port)); return my_object; }
static json_object *ap_stlog_process_rec_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "short_name", json_object_new_string(ap_mrb_string_check(r->pool, r->server->process->short_name))); //json_object_object_add(my_object, "argv", json_object_new_string(ap_mrb_string_check(r->pool, (char *)r->server->process->argv))); json_object_object_add(my_object, "argc", json_object_new_int(r->server->process->argc)); return my_object; }
static json_object *ap_stlog_server_rec_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "error_fname", json_object_new_string(ap_mrb_string_check(r->pool, r->server->error_fname))); json_object_object_add(my_object, "defn_name", json_object_new_string(ap_mrb_string_check(r->pool, r->server->defn_name))); json_object_object_add(my_object, "server_scheme", json_object_new_string(ap_mrb_string_check(r->pool, r->server->server_scheme))); json_object_object_add(my_object, "server_admin", json_object_new_string(ap_mrb_string_check(r->pool, r->server->server_admin))); json_object_object_add(my_object, "path", json_object_new_string(ap_mrb_string_check(r->pool, r->server->path))); json_object_object_add(my_object, "server_hostname", json_object_new_string(ap_mrb_string_check(r->pool, r->server->server_hostname))); json_object_object_add(my_object, "loglevel", json_object_new_int(r->server->loglevel)); json_object_object_add(my_object, "is_virtual", json_object_new_int(r->server->is_virtual)); json_object_object_add(my_object, "keep_alive_max", json_object_new_int(r->server->keep_alive_max)); json_object_object_add(my_object, "keep_alive", json_object_new_int(r->server->keep_alive)); json_object_object_add(my_object, "pathlen", json_object_new_int(r->server->pathlen)); json_object_object_add(my_object, "limit_req_line", json_object_new_int(r->server->limit_req_line)); json_object_object_add(my_object, "limit_req_fieldsize", json_object_new_int(r->server->limit_req_fieldsize)); json_object_object_add(my_object, "limit_req_fields", json_object_new_int(r->server->limit_req_fields)); json_object_object_add(my_object, "limit_req_fields", json_object_new_int(r->server->limit_req_fields)); json_object_object_add(my_object, "timeout", json_object_new_int((int)r->server->timeout)); json_object_object_add(my_object, "keep_alive_timeout", json_object_new_int((int)r->server->keep_alive_timeout)); json_object_object_add(my_object, "port", json_object_new_int((int)r->server->port)); json_object_object_add(my_object, "defn_line_number", json_object_new_int((int)r->server->defn_line_number)); json_object_object_add(my_object, "process", ap_stlog_process_rec_to_json(r)); json_object_object_add(my_object, "addrs", ap_stlog_server_addr_rec_to_json(r)); return my_object; }
static json_object *ap_stlog_server_addr_rec_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "virthost", json_object_new_string(ap_mrb_string_check(r->pool, r->server->addrs->virthost))); json_object_object_add(my_object, "host_port", json_object_new_int(r->server->addrs->host_port)); json_object_object_add(my_object, "host_addr", ap_stlog_host_addr_to_json(r)); return my_object; }
void mod_stlog_logging(json_object *json_obj, const char *func, apr_pool_t *p) { int len; time_t t; char *log_time, *val; char *mod_stlog_buf = NULL; time(&t); log_time = (char *)ctime(&t); len = strlen(log_time); log_time[len - 1] = '\0'; json_object_object_add(json_obj, "time", json_object_new_string(ap_mrb_string_check(p, log_time))); json_object_object_add(json_obj, "pid", json_object_new_int(getpid())); json_object_object_add(json_obj, "hook", json_object_new_string(ap_mrb_string_check(p, func))); val = (char *)json_object_to_json_string(json_obj); mod_stlog_buf = (char *)apr_psprintf(p, "%s\n", val); apr_file_puts(mod_stlog_buf, mod_stlog_fp); apr_file_flush(mod_stlog_fp); }
static json_object *ap_stlog_headers_in_to_json(request_rec *r) { json_object *my_object; int i; my_object = json_object_new_object(); const apr_array_header_t *arr = apr_table_elts(r->headers_in); apr_table_entry_t *elts = (apr_table_entry_t *)arr->elts; for (i = 0; i < arr->nelts; i++) { json_object_object_add(my_object, elts[i].key, json_object_new_string(ap_mrb_string_check(r->pool, elts[i].val))); } return my_object; }
static json_object *ap_stlog_request_rec_to_json(request_rec *r) { json_object *my_object; my_object = json_object_new_object(); json_object_object_add(my_object, "filename", json_object_new_string(ap_mrb_string_check(r->pool, r->filename))); json_object_object_add(my_object, "uri", json_object_new_string(ap_mrb_string_check(r->pool, r->uri))); json_object_object_add(my_object, "user", json_object_new_string(ap_mrb_string_check(r->pool, r->user))); json_object_object_add(my_object, "content_type", json_object_new_string(ap_mrb_string_check(r->pool, r->content_type))); json_object_object_add(my_object, "protocol", json_object_new_string(ap_mrb_string_check(r->pool, r->protocol))); json_object_object_add(my_object, "vlist_validator", json_object_new_string(ap_mrb_string_check(r->pool, r->vlist_validator))); json_object_object_add(my_object, "ap_auth_type", json_object_new_string(ap_mrb_string_check(r->pool, r->ap_auth_type))); json_object_object_add(my_object, "unparsed_uri", json_object_new_string(ap_mrb_string_check(r->pool, r->unparsed_uri))); json_object_object_add(my_object, "canonical_filename", json_object_new_string(ap_mrb_string_check(r->pool, r->canonical_filename))); json_object_object_add(my_object, "path_info", json_object_new_string(ap_mrb_string_check(r->pool, r->path_info))); json_object_object_add(my_object, "hostname", json_object_new_string(ap_mrb_string_check(r->pool, r->hostname))); json_object_object_add(my_object, "method", json_object_new_string(ap_mrb_string_check(r->pool, r->method))); json_object_object_add(my_object, "the_request", json_object_new_string(ap_mrb_string_check(r->pool, r->the_request))); json_object_object_add(my_object, "range", json_object_new_string(ap_mrb_string_check(r->pool, r->range))); json_object_object_add(my_object, "handler", json_object_new_string(ap_mrb_string_check(r->pool, r->handler))); json_object_object_add(my_object, "args", json_object_new_string(ap_mrb_string_check(r->pool, r->args))); json_object_object_add(my_object, "status_line", json_object_new_string(ap_mrb_string_check(r->pool, r->status_line))); json_object_object_add(my_object, "content_encoding", json_object_new_string(ap_mrb_string_check(r->pool, r->content_encoding))); json_object_object_add(my_object, "assbackwards", json_object_new_int(r->assbackwards)); json_object_object_add(my_object, "proxyreq", json_object_new_int(r->proxyreq)); json_object_object_add(my_object, "header_only", json_object_new_int(r->header_only)); json_object_object_add(my_object, "proto_num", json_object_new_int(r->proto_num)); json_object_object_add(my_object, "status", json_object_new_int(r->status)); json_object_object_add(my_object, "method_number", json_object_new_int(r->method_number)); json_object_object_add(my_object, "chunked", json_object_new_int(r->chunked)); json_object_object_add(my_object, "read_body", json_object_new_int(r->read_body)); json_object_object_add(my_object, "read_chunked", json_object_new_int(r->read_chunked)); json_object_object_add(my_object, "no_cache", json_object_new_int(r->no_cache)); json_object_object_add(my_object, "no_local_copy", json_object_new_int(r->no_local_copy)); json_object_object_add(my_object, "used_path_info", json_object_new_int(r->used_path_info)); json_object_object_add(my_object, "eos_sent", json_object_new_int(r->eos_sent)); json_object_object_add(my_object, "request_time", json_object_new_int(r->request_time)); json_object_object_add(my_object, "connection", ap_stlog_conn_rec_to_json(r)); json_object_object_add(my_object, "server", ap_stlog_server_rec_to_json(r)); json_object_object_add(my_object, "headers_in", ap_stlog_headers_in_to_json(r)); json_object_object_add(my_object, "headers_out", ap_stlog_headers_out_to_json(r)); //json_object_object_add(my_object, "htaccess", ap_stlog_htaccess_result_to_json(r)); return my_object; }
mrb_value ap_mrb_get_server_defn_name(mrb_state *mrb, mrb_value str) { request_rec *r = ap_mrb_get_request(); char *val = apr_pstrdup(r->pool, ap_mrb_string_check(r->pool, r->server->defn_name)); return mrb_str_new(mrb, val, strlen(val)); }