/*lint -e{818} cli could be const */ void VCLI_Quote(struct cli *cli, const char *s) { CHECK_OBJ_NOTNULL(cli, CLI_MAGIC); VSB_quote(cli->sb, s, -1, 0); }
/*lint -e{818} cli could be const */ void VCLI_JSON_str(struct cli *cli, const char *s) { CHECK_OBJ_NOTNULL(cli, CLI_MAGIC); VSB_quote(cli->sb, s, -1, VSB_QUOTE_JSON); }
static int vlog_cb_func(struct VSL_data *vsl, struct VSL_transaction * const trans[], void *priv) { int i; struct vlog_req_priv *vrp = priv; struct VSL_transaction *t; for (i = 0; (t = trans[i]) != NULL && vrp->entries < vrp->limit; ++i) { while (VSL_Next(t->c) && vrp->entries < vrp->limit) { if (!VSL_Match(vsl, t->c)) { continue; } if (vrp->entries != 0) VSB_printf(vrp->answer,","); VSB_printf(vrp->answer,"\n"); VSB_printf(vrp->answer, "{ \"vxid\": \"%u\", " "\"tag\": \"%s\", \"type\": \"%s\", \"reason\": \"%s\", " "\"value\": ", t->vxid, VSL_tags[VSL_TAG(t->c->rec.ptr)], vsl_t_names[t->type], vsl_r_names[t->reason]); VSB_quote(vrp->answer, VSL_CDATA(t->c->rec.ptr), strlen(VSL_CDATA(t->c->rec.ptr)), 0); VSB_printf(vrp->answer,"}"); vrp->entries++; } } return (0); }
int tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg) { char **p = TRUST_ME(par->priv); AN(p); /* XXX should have tweak_generic_string */ if (arg == NULL) { VSB_quote(vsb, *p, -1, 0); } else { REPLACE(*p, arg); } return (0); }
static void mcf_askchild(struct cli *cli, const char * const *av, void *priv) { int i; char *q; unsigned u; struct vsb *vsb; (void)priv; /* * Command not recognized in master, try cacher if it is * running. */ if (cli_o <= 0) { if (!strcmp(av[1], "help")) { if (av[2] == NULL || strcmp(av[2], "-j")) VCLI_Out(cli, "No help from child, (not running).\n"); return; } VCLI_SetResult(cli, CLIS_UNKNOWN); VCLI_Out(cli, "Unknown request in manager process " "(child not running).\n" "Type 'help' for more info."); return; } vsb = VSB_new_auto(); for (i = 1; av[i] != NULL; i++) { VSB_quote(vsb, av[i], strlen(av[i]), 0); VSB_putc(vsb, ' '); } VSB_putc(vsb, '\n'); AZ(VSB_finish(vsb)); i = write(cli_o, VSB_data(vsb), VSB_len(vsb)); if (i != VSB_len(vsb)) { VSB_destroy(&vsb); VCLI_SetResult(cli, CLIS_COMMS); VCLI_Out(cli, "CLI communication error"); MGT_Child_Cli_Fail(); return; } VSB_destroy(&vsb); if (VCLI_ReadResult(cli_i, &u, &q, mgt_param.cli_timeout)) MGT_Child_Cli_Fail(); VCLI_SetResult(cli, u); VCLI_Out(cli, "%s", q); free(q); }
/* * Print a single line of varnishlog as json, possibly adding a comma. * * XXX: This concept is slightly flawed. It is global, which means that the * comma-logic can mess up. Assume that the first line /read/ is part of a * session, but that the first line output is not. If that happens, the * first entry output will have a comma prefixed. Plain wrong. */ static void print_entry(struct vlog_priv_t *vlog, int fd, enum VSL_tag_e tag, int type, const char *ptr, unsigned len) { if (vlog->entries > 0) VSB_printf(vlog->answer,","); VSB_printf(vlog->answer,"\n"); VSB_printf(vlog->answer, "{ \"fd\": \"%d\"," "\"tag\": \"%s\", \"type\":\"%c\"," "\"value\":", fd, VSL_tags[tag], type); VSB_quote(vlog->answer, ptr, len, 0); VSB_printf(vlog->answer,"}"); vlog->entries++; }
static void mgt_panic_record(pid_t r) { char time_str[30]; if (child_panic != NULL) VSB_delete(child_panic); child_panic = VSB_new_auto(); AN(child_panic); VTIM_format(VTIM_real(), time_str); VSB_printf(child_panic, "Last panic at: %s\n", time_str); VSB_quote(child_panic, heritage.panic_str, strnlen(heritage.panic_str, heritage.panic_str_len), VSB_QUOTE_NONL); AZ(VSB_finish(child_panic)); MGT_complain(C_ERR, "Child (%jd) %s", (intmax_t)r, VSB_data(child_panic)); }
void vcc_ParseImport(struct vcc *tl) { void *hdl; char fn[1024], *fnp, *fnpx; char buf[256]; struct token *mod, *t1; struct inifin *ifp; const char * const *spec; struct symbol *sym; struct symbol *msym; const struct symbol *osym; const char *p; // int *modlen; const struct vmod_data *vmd; t1 = tl->t; SkipToken(tl, ID); /* "import" */ ExpectErr(tl, ID); mod = tl->t; vcc_NextToken(tl); osym = VCC_SymbolTok(tl, NULL, mod, SYM_NONE, 0); if (osym != NULL && osym->kind != SYM_VMOD) { VSB_printf(tl->sb, "Module %.*s conflicts with other symbol.\n", PF(mod)); vcc_ErrWhere2(tl, t1, tl->t); return; } if (osym != NULL) { VSB_printf(tl->sb, "Module %.*s already imported.\n", PF(mod)); vcc_ErrWhere2(tl, t1, tl->t); VSB_printf(tl->sb, "Previous import was here:\n"); vcc_ErrWhere2(tl, osym->def_b, osym->def_e); return; } bprintf(fn, "%.*s", PF(mod)); msym = VCC_Symbol(tl, NULL, fn, NULL, SYM_VMOD, 1); ERRCHK(tl); AN(msym); msym->def_b = t1; msym->def_e = tl->t; if (tl->t->tok == ID) { if (!vcc_IdIs(tl->t, "from")) { VSB_printf(tl->sb, "Expected 'from path ...'\n"); vcc_ErrWhere(tl, tl->t); return; } vcc_NextToken(tl); if (!tl->unsafe_path && strchr(tl->t->dec, '/')) { VSB_printf(tl->sb, "'import ... from path ...' is unsafe.\nAt:"); vcc_ErrToken(tl, tl->t); vcc_ErrWhere(tl, tl->t); return; } ExpectErr(tl, CSTR); p = strrchr(tl->t->dec, '/'); if (p != NULL && p[1] == '\0') bprintf(fn, "%slibvmod_%.*s.so", tl->t->dec, PF(mod)); else bprintf(fn, "%s", tl->t->dec); vcc_NextToken(tl); } else { bprintf(fn, "libvmod_%.*s.so", PF(mod)); } SkipToken(tl, ';'); if (VFIL_searchpath(tl->vmod_path, vcc_path_dlopen, &hdl, fn, &fnpx)) { VSB_printf(tl->sb, "Could not load VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnpx != NULL ? fnpx : fn); VSB_printf(tl->sb, "\tdlerror: %s\n", dlerror()); vcc_ErrWhere(tl, mod); free(fnpx); return; } AN(fnpx); fnp = TlDup(tl, fnpx); free(fnpx); bprintf(buf, "Vmod_%.*s_Data", PF(mod)); vmd = dlsym(hdl, buf); if (vmd == NULL) { VSB_printf(tl->sb, "Malformed VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\t(no Vmod_Data symbol)\n"); vcc_ErrWhere(tl, mod); return; } if (strcmp(VCS_Branch, "master") == 0 && strcmp(vmd->abi, VMOD_ABI_Version) != 0) { VSB_printf(tl->sb, "Incompatible VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\tABI mismatch, expected <%s>, got <%s>\n", VMOD_ABI_Version, vmd->abi); vcc_ErrWhere(tl, mod); return; } if (vmd->vrt_major != VRT_MAJOR_VERSION || vmd->vrt_minor > VRT_MINOR_VERSION) { VSB_printf(tl->sb, "Incompatible VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\tVMOD version %u.%u\n", vmd->vrt_major, vmd->vrt_minor); VSB_printf(tl->sb, "\tvarnishd version %u.%u\n", VRT_MAJOR_VERSION, VRT_MINOR_VERSION); vcc_ErrWhere(tl, mod); return; } if (vmd->name == NULL || vmd->func == NULL || vmd->func_len <= 0 || vmd->proto == NULL || vmd->abi == NULL) { VSB_printf(tl->sb, "Mangled VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\tInconsistent metadata\n"); vcc_ErrWhere(tl, mod); return; } if (!vcc_IdIs(mod, vmd->name)) { VSB_printf(tl->sb, "Wrong VMOD file %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\tContains vmod \"%s\"\n", vmd->name); vcc_ErrWhere(tl, mod); return; } ifp = New_IniFin(tl); VSB_printf(ifp->ini, "\tif (VRT_Vmod_Init(&VGC_vmod_%.*s,\n", PF(mod)); VSB_printf(ifp->ini, "\t &Vmod_%.*s_Func,\n", PF(mod)); VSB_printf(ifp->ini, "\t sizeof(Vmod_%.*s_Func),\n", PF(mod)); VSB_printf(ifp->ini, "\t \"%.*s\",\n", PF(mod)); VSB_printf(ifp->ini, "\t "); VSB_quote(ifp->ini, fnp, -1, VSB_QUOTE_CSTR); VSB_printf(ifp->ini, ",\n"); AN(vmd); AN(vmd->file_id); VSB_printf(ifp->ini, "\t \"%s\",\n", vmd->file_id); VSB_printf(ifp->ini, "\t ctx))\n"); VSB_printf(ifp->ini, "\t\treturn(1);"); /* XXX: zero the function pointer structure ?*/ VSB_printf(ifp->fin, "\t\tVRT_priv_fini(&vmod_priv_%.*s);", PF(mod)); VSB_printf(ifp->fin, "\n\t\tVRT_Vmod_Fini(&VGC_vmod_%.*s);", PF(mod)); ifp = NULL; spec = vmd->spec; for (; *spec != NULL; spec++) { p = *spec; if (!strcmp(p, "$OBJ")) { p += strlen(p) + 1; sym = VCC_Symbol(tl, NULL, p, NULL, SYM_OBJECT, 1); XXXAN(sym); sym->extra = p; sym->vmod = msym->name; } else if (!strcmp(p, "$EVENT")) { p += strlen(p) + 1; if (ifp == NULL) ifp = New_IniFin(tl); VSB_printf(ifp->ini, "\tif (%s(ctx, &vmod_priv_%.*s, VCL_EVENT_LOAD))\n" "\t\treturn(1);", p, PF(mod)); VSB_printf(ifp->fin, "\t\t(void)%s(ctx, &vmod_priv_%.*s,\n" "\t\t VCL_EVENT_DISCARD);\n", p, PF(mod)); VSB_printf(ifp->event, "\t%s(ctx, &vmod_priv_%.*s, ev)", p, PF(mod)); } else if (!strcmp(p, "$FUNC")) { p += strlen(p) + 1; sym = VCC_Symbol(tl, NULL, p, NULL, SYM_FUNC, 1); ERRCHK(tl); AN(sym); sym->vmod = msym->name; sym->eval = vcc_Eval_SymFunc; p += strlen(p) + 1; sym->eval_priv = p; sym->fmt = VCC_Type(p); AN(sym->fmt); } else { VSB_printf(tl->sb, "Internal spec error (%s)\n", p); vcc_ErrWhere(tl, mod); return; } } Fh(tl, 0, "\n/* --- BEGIN VMOD %.*s --- */\n\n", PF(mod)); Fh(tl, 0, "static struct vmod *VGC_vmod_%.*s;\n", PF(mod)); Fh(tl, 0, "static struct vmod_priv vmod_priv_%.*s;\n", PF(mod)); Fh(tl, 0, "\n%s\n", vmd->proto); Fh(tl, 0, "\n/* --- END VMOD %.*s --- */\n\n", PF(mod)); }
/*lint -e{818} cli could be const */ void VCLI_Quote(struct cli *cli, const char *s) { VSB_quote(cli->sb, s, -1, 0); }