<commit_before>#include "cache/cache.h"
#include "vapi/vsm.h"
#include "vcl.h"
#include "cache/cache_backend.h"
#include "vmod_rtstatus.h"

int
backend(struct iter_priv *iter)
{
	int i;

	VSB_cat(iter->vsb, "\t\"backend\": [");
	for (i = 1; i < iter->cpy_ctx->vcl->ndirector; ++i) {
		CHECK_OBJ_NOTNULL(iter->cpy_ctx->vcl->director[i], DIRECTOR_MAGIC);
		if (strcmp("simple", iter->cpy_ctx->vcl->director[i]->name) == 0) {
			char buf[1024];
			int j, healthy;
			healthy = VDI_Healthy(iter->cpy_ctx->vcl->director[i]);
			j = snprintf(buf, sizeof buf, "{\"director_name\" : \"%s\" , \"name\":\"%s\", \"value\": \"%s\"}",
					iter->cpy_ctx->vcl->director[i]->name,
					iter->cpy_ctx->vcl->director[i]->vcl_name,
					healthy ? "healthy" : "sick");
			assert(j >= 0);
			VSB_cat(iter->vsb, buf);
			if (i < (iter->cpy_ctx->vcl->ndirector - 1)) {
			    VSB_cat(iter->vsb, ",\n\t\t");
			}
		}
	}
	VSB_cat(iter->vsb, "],\n");
	return(0);
}

int
general_info(struct iter_priv *iter)
{
	VSB_cat(iter->vsb, "\t\"varnish_version\" : \"");
	VSB_cat(iter->vsb, VCS_version);
	VSB_cat(iter->vsb, "\",\n");
	VSB_cat(iter->vsb, "\t\"server_id\": \"");
	VSB_cat(iter->vsb, VRT_r_server_identity(iter->cpy_ctx));
	VSB_cat(iter->vsb, "\",\n");
	VSB_cat(iter->vsb, "\t\"client_id\": \"");
	VSB_cat(iter->vsb, VRT_r_client_identity(iter->cpy_ctx));
	VSB_cat(iter->vsb, "\",\n");
	return(0);
}

VCL_STRING
vmod_rtstatus(const struct vrt_ctx *ctx)
{
//	const struct VSC_C_main *VSC_C_main;
	struct iter_priv iter = { 0 };
	struct VSM_data *vd;

	vd = VSM_New();
	if (VSM_Open(vd)) {
	    VSLb(ctx->vsl, SLT_VCL_Error, "Can't open VSM");
	    VSM_Delete(vd);
	    return "{}";
	}
	iter.vsb = VSB_new(NULL, ctx->ws->f, WS_Reserve(ctx->ws, 0), VSB_AUTOEXTEND);
	iter.cpy_ctx = ctx;
       	iter.jp = 1;
	run_subroutine(&iter, vd);
	VSB_finish(iter.vsb);
	if (VSB_error(iter.vsb)) {
	    VSLb(ctx->vsl, SLT_VCL_Error, "VSB error");
	    VSM_Delete(vd);
	    WS_Release(ctx->ws, VSB_len(iter.vsb) + 1);
	    return "{}";
	}
	VSM_Delete(vd);
	WS_Release(ctx->ws, VSB_len(iter.vsb) + 1);
	return(iter.vsb->s_buf);
}
<commit_msg>Cosmetic changes to make the code more readable.<commit_after>#include "cache/cache.h"
#include "vapi/vsm.h"
#include "vcl.h"
#include "cache/cache_backend.h"
#include "vmod_rtstatus.h"

int
backend(struct iter_priv *iter)
{
	const struct vrt_ctx *ctx = iter->cpy_ctx;
	int i;

	VSB_cat(iter->vsb, "\t\"backend\": [");
	for (i = 1; i < iter->cpy_ctx->vcl->ndirector; ++i) {
		CHECK_OBJ_NOTNULL(ctx->vcl->director[i], DIRECTOR_MAGIC);
		if (strcmp("simple", ctx->vcl->director[i]->name) == 0) {
			char buf[1024];
			int j, healthy;
			healthy = VDI_Healthy(ctx->vcl->director[i]);
			j = snprintf(buf, sizeof buf, "{\"director_name\" :"
			    " \"%s\" , \"name\":\"%s\", \"value\": \"%s\"}",
			    ctx->vcl->director[i]->name,
			    ctx->vcl->director[i]->vcl_name,
			    healthy ? "healthy" : "sick");
			assert(j >= 0);
			VSB_cat(iter->vsb, buf);
			if (i < (ctx->vcl->ndirector - 1)) {
			    VSB_cat(iter->vsb, ",\n\t\t");
			}
		}
	}
	VSB_cat(iter->vsb, "],\n");
	return(0);
}

int
general_info(struct iter_priv *iter)
{
	VSB_cat(iter->vsb, "\t\"varnish_version\" : \"");
	VSB_cat(iter->vsb, VCS_version);
	VSB_cat(iter->vsb, "\",\n");
	VSB_cat(iter->vsb, "\t\"server_id\": \"");
	VSB_cat(iter->vsb, VRT_r_server_identity(iter->cpy_ctx));
	VSB_cat(iter->vsb, "\",\n");
	VSB_cat(iter->vsb, "\t\"client_id\": \"");
	VSB_cat(iter->vsb, VRT_r_client_identity(iter->cpy_ctx));
	VSB_cat(iter->vsb, "\",\n");
	return(0);
}

VCL_STRING
vmod_rtstatus(const struct vrt_ctx *ctx)
{
	struct iter_priv iter = { 0 };
	struct VSM_data *vd;
	unsigned u;

	vd = VSM_New();
	if (VSM_Open(vd)) {
	    VSLb(ctx->vsl, SLT_VCL_Error, "Can't open VSM");
	    VSM_Delete(vd);
	    return "{}";
	}
	u =  WS_Reserve(ctx->ws, 0);
	iter.vsb = VSB_new(NULL, ctx->ws->f, u, VSB_AUTOEXTEND);
	iter.cpy_ctx = ctx;
       	iter.jp = 1;
	run_subroutine(&iter, vd);
	VSB_finish(iter.vsb);
	if (VSB_error(iter.vsb)) {
	    VSLb(ctx->vsl, SLT_VCL_Error, "VSB error");
	    VSM_Delete(vd);
	    WS_Release(ctx->ws, VSB_len(iter.vsb) + 1);
	    return "{}";
	}
	VSM_Delete(vd);
	WS_Release(ctx->ws, VSB_len(iter.vsb) + 1);
	return(iter.vsb->s_buf);
}

{'fraction_non_alphanumeric': 0.2264017033356991, 'fraction_numerical': 0.007097232079488999, 'mean_word_length': 3.870967741935484, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2068863', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1917, 'n_words': 298}