Lines Matching refs:ctx

239 	vs_scan_ctx_t ctx;
258 (void) memset(&ctx, 0, sizeof (vs_scan_ctx_t));
259 ctx.vsc_idx = eng->vse_eidx;
260 (void) strlcpy(ctx.vsc_host, eng->vse_host, sizeof (ctx.vsc_host));
261 ctx.vsc_port = eng->vse_port;
262 ctx.vsc_sockfd = eng->vse_sockfd;
263 ctx.vsc_fd = fd;
264 ctx.vsc_fname = fname;
265 ctx.vsc_fsize = fsize;
266 ctx.vsc_flags = flags;
267 ctx.vsc_result = result;
270 ctx.vsc_flags |= VS_NO_REPAIR;
271 ctx.vsc_repair = 0;
272 ctx.vsc_repair_fname = NULL;
273 ctx.vsc_repair_fd = -1;
277 if (vs_icap_compare_se(ctx.vsc_idx, ctx.vsc_host, ctx.vsc_port) == 0) {
278 vs_icap_copy_options(&ctx.vsc_options,
279 &vs_options[ctx.vsc_idx]);
291 if (vs_icap_option_request(&ctx) == 0)
292 (void) vs_icap_respmod_request(&ctx);
295 vs_icap_free_options(&ctx.vsc_options);
319 vs_icap_option_request(vs_scan_ctx_t *ctx)
321 if (ctx->vsc_options.vso_req_time != -1 &&
322 ((time(0) - ctx->vsc_options.vso_req_time) >
323 ctx->vsc_options.vso_ttl)) {
325 if (vs_icap_send_option_req(ctx) < 0)
328 if (vs_icap_read_option_resp(ctx) < 0)
331 vs_icap_update_options(ctx);
349 vs_icap_send_option_req(vs_scan_ctx_t *ctx)
353 char *buf0 = ctx->vsc_info.vsi_send_buf;
359 ctx->vsc_result->vsr_rc = VS_RESULT_ERROR;
363 (void) memset(ctx->vsc_info.vsi_send_buf, 0,
364 sizeof (ctx->vsc_info.vsi_send_buf));
367 ctx->vsc_host, ctx->vsc_port, VS_SERVICE_NAME, VS_ICAP_VER);
374 if (vs_icap_write(ctx->vsc_sockfd, buf0, (bufp - buf0)) < 0)
388 vs_icap_read_option_resp(vs_scan_ctx_t *ctx)
390 if (vs_icap_read_resp_code(ctx) < 0)
393 if (ctx->vsc_info.vsi_icap_rc != VS_RESP_OK) {
396 vs_icap_resp_str(ctx->vsc_info.vsi_icap_rc));
400 if (vs_icap_read_hdr(ctx, option_hdrs, VS_OPT_HDR_MAX) != 0)
403 if ((ctx->vsc_options.vso_scanstamp[0] == 0) ||
404 (ctx->vsc_options.vso_respmod == 0) ||
405 (ctx->vsc_options.vso_req_time == 0)) {
436 vs_icap_respmod_request(vs_scan_ctx_t *ctx)
440 uint64_t resid = ctx->vsc_fsize;
442 if (vs_icap_may_preview(ctx)) {
444 if ((rv = vs_icap_send_preview(ctx)) < 0)
447 if (vs_icap_read_respmod_resp(ctx) < 0)
450 if (ctx->vsc_info.vsi_icap_rc != VS_RESP_CONTINUE)
456 if ((ctx->vsc_fsize - (uint64_t)bytes_sent) > VS_BUF_SZ) {
458 if ((rv = vs_icap_send_chunk(ctx, send_len)) < 0)
467 if (vs_icap_send_respmod_hdr(ctx, 0) < 0)
475 if ((rv = vs_icap_send_chunk(ctx, send_len)) < 0)
484 if (vs_icap_send_termination(ctx) < 0)
488 if (vs_icap_read_respmod_resp(ctx) < 0)
502 vs_icap_may_preview(vs_scan_ctx_t *ctx)
506 vs_options_t *opts = &ctx->vsc_options;
512 if (ctx->vsc_fsize < (uint64_t)ctx->vsc_options.vso_preview_len)
520 if ((ext = vs_icap_find_ext(ctx->vsc_fname)) != 0)
526 if ((ext = vs_icap_find_ext(ctx->vsc_fname)) != 0)
571 vs_icap_send_preview(vs_scan_ctx_t *ctx)
573 int preview_len = ctx->vsc_options.vso_preview_len;
577 if (vs_icap_send_respmod_hdr(ctx, 'P') < 0)
580 if ((bytes_sent = vs_icap_send_chunk(ctx, preview_len)) < 0)
586 if (vs_icap_send_termination(ctx) < 0)
602 vs_icap_send_respmod_hdr(vs_scan_ctx_t *ctx, int ispreview)
606 if ((len = vs_icap_create_respmod_hdr(ctx, ispreview)) == -1) {
608 ctx->vsc_result->vsr_rc = VS_RESULT_ERROR;
613 if (vs_icap_write(ctx->vsc_sockfd,
614 ctx->vsc_info.vsi_send_buf, len) < 0) {
638 vs_icap_create_respmod_hdr(vs_scan_ctx_t *ctx, int ispreview)
642 char *hbuf0 = ctx->vsc_info.vsi_send_buf;
645 int preview_len = ctx->vsc_options.vso_preview_len;
650 ctx->vsc_result->vsr_rc = VS_RESULT_ERROR;
658 ctx->vsc_host, ctx->vsc_port, VS_SERVICE_NAME, VS_ICAP_VER);
698 tlen = vs_icap_uri_encode(hbufp, hbufsp, ctx->vsc_fname);
741 vs_icap_read_respmod_resp(vs_scan_ctx_t *ctx)
743 if (vs_icap_read_resp_code(ctx) < 0)
746 if (vs_icap_read_hdr(ctx, resp_hdrs, VS_RESP_HDR_MAX) < 0)
749 if (ctx->vsc_info.vsi_icap_rc == VS_RESP_CONTINUE) {
751 if ((ctx->vsc_info.vsi_res_hdr) ||
752 (ctx->vsc_info.vsi_res_body)) {
758 if (vs_icap_set_scan_result(ctx) < 0)
761 if (ctx->vsc_info.vsi_res_hdr) {
762 if (vs_icap_read_encap_hdr(ctx) < 0)
766 if (ctx->vsc_info.vsi_res_body)
767 vs_icap_read_encap_data(ctx);
768 else if (ctx->vsc_result->vsr_rc == VS_RESULT_CLEANED)
769 ctx->vsc_result->vsr_rc = VS_RESULT_FORBIDDEN;
782 vs_icap_read_resp_code(vs_scan_ctx_t *ctx)
784 char *buf = ctx->vsc_info.vsi_recv_buf;
791 if ((retval = vs_icap_readline(ctx, buf, VS_BUF_SZ)) < 0)
797 &ctx->vsc_info.vsi_icap_rc);
820 vs_icap_read_hdr(vs_scan_ctx_t *ctx, vs_hdr_t hdrs[], int num_hdrs)
822 char *buf = ctx->vsc_info.vsi_recv_buf;
830 if ((retval = vs_icap_readline(ctx, buf, VS_BUF_SZ)) < 0)
841 hdrs[i].vsh_func(ctx, hdrs[i].vsh_id, val);
861 vs_icap_set_scan_result(vs_scan_ctx_t *ctx)
864 vs_result_t *result = ctx->vsc_result;
868 ctx->vsc_options.vso_scanstamp, sizeof (vs_scanstamp_t));
870 switch (ctx->vsc_info.vsi_icap_rc) {
906 vs_icap_resp_str(ctx->vsc_info.vsi_icap_rc));
938 vs_icap_read_encap_hdr(vs_scan_ctx_t *ctx)
940 char *buf = ctx->vsc_info.vsi_recv_buf;
946 if ((retval = vs_icap_readline(ctx, buf, VS_BUF_SZ)) < 0)
955 &ctx->vsc_info.vsi_http_rc);
956 ctx->vsc_info.vsi_html_content = B_TRUE;
959 if (ctx->vsc_result->vsr_rc == VS_RESULT_CLEAN) {
960 if ((ctx->vsc_info.vsi_icap_rc == VS_RESP_OK) &&
961 (ctx->vsc_info.vsi_http_rc == VS_RESP_OK)) {
962 ctx->vsc_result->vsr_rc =
965 ctx->vsc_result->vsr_rc =
973 &ctx->vsc_info.vsi_content_len);
1000 * in ctx == 0).
1003 vs_icap_read_encap_data(vs_scan_ctx_t *ctx)
1005 if (ctx->vsc_result->vsr_rc == VS_RESULT_CLEANED) {
1006 ctx->vsc_result->vsr_rc = VS_RESULT_FORBIDDEN;
1008 if (!(ctx->vsc_flags & VS_NO_REPAIR)) {
1009 if (vs_icap_create_repair_file(ctx) == 0)
1010 ctx->vsc_repair = B_TRUE;
1016 * resets ctx->vsc_repair
1018 (void) vs_icap_read_resp_body(ctx);
1020 if (ctx->vsc_repair_fd != -1) {
1021 (void) close(ctx->vsc_repair_fd);
1023 if (ctx->vsc_repair) {
1025 ctx->vsc_result->vsr_rc = VS_RESULT_CLEANED;
1028 (void) unlink(ctx->vsc_repair_fname);
1040 vs_icap_create_repair_file(vs_scan_ctx_t *ctx)
1042 if (ctx->vsc_repair_fname == NULL)
1045 if ((ctx->vsc_repair_fd = open(ctx->vsc_repair_fname,
1059 * -1 indicating a read error -> reset ctx->vsc_repair 0
1065 vs_icap_read_resp_body(vs_scan_ctx_t *ctx)
1069 while ((retval = vs_icap_read_body_chunk(ctx)) > 0)
1073 ctx->vsc_repair = B_FALSE;
1085 * flag in ctx to 0, and discard all subsequent data.
1091 vs_icap_read_body_chunk(vs_scan_ctx_t *ctx)
1093 char *lbuf = ctx->vsc_info.vsi_recv_buf;
1098 if ((vs_icap_readline(ctx, lbuf, VS_BUF_SZ) < 0) ||
1108 if ((rsize = vs_icap_read(ctx->vsc_sockfd, lbuf, rsize)) <= 0)
1111 if (ctx->vsc_repair) {
1112 if (vs_icap_write(ctx->vsc_repair_fd, lbuf, rsize) < 0)
1113 ctx->vsc_repair = B_FALSE;
1120 if (vs_icap_readline(ctx, lbuf, VS_BUF_SZ) < 0)
1208 vs_icap_send_chunk(vs_scan_ctx_t *ctx, int chunk_len)
1210 char *hdr = ctx->vsc_info.vsi_send_hdr;
1211 char *dbuf = ctx->vsc_info.vsi_send_buf;
1220 if ((nread = vs_icap_read(ctx->vsc_fd, dbuf, chunk_len)) < 0)
1232 if (vs_icap_write(ctx->vsc_sockfd, hdr,
1251 vs_icap_send_termination(vs_scan_ctx_t *ctx)
1253 if (vs_icap_write(ctx->vsc_sockfd, VS_TERMINATION,
1271 vs_icap_readline(vs_scan_ctx_t *ctx, char *buf, int buflen)
1279 retval = recv(ctx->vsc_sockfd, &c, 1, 0);
1354 vs_icap_resp_violations(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1360 ctx->vsc_result->vsr_nviolations =
1363 ctx->vsc_info.vsi_threat_hdr = VS_RESP_X_VIOLATIONS;
1366 if ((rv = vs_icap_resp_violation_rec(ctx, i)) < 0)
1384 vs_icap_resp_violation_rec(vs_scan_ctx_t *ctx, int vr_idx)
1388 char *buf = ctx->vsc_info.vsi_recv_buf;
1392 vr = &ctx->vsc_result->vsr_vrec[vr_idx];
1398 if ((retval = vs_icap_readline(ctx, buf, VS_BUF_SZ)) < 0)
1432 vs_icap_opt_value(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1445 ctx->vsc_options.vso_preview_len = x;
1450 ctx->vsc_options.vso_req_time = -1;
1458 ctx->vsc_options.vso_ttl = val;
1459 ctx->vsc_options.vso_req_time = time(0);
1463 (void) sscanf(line, "%d", &ctx->vsc_options.vso_allow);
1467 (void) strlcpy(ctx->vsc_options.vso_service, line,
1472 (void) strlcpy(ctx->vsc_options.vso_defninfo, line,
1478 ctx->vsc_options.vso_respmod = 1;
1483 ctx->vsc_options.vso_scanstamp);
1504 vs_icap_resp_istag(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1506 vs_icap_istag_to_scanstamp(line, ctx->vsc_result->vsr_scanstamp);
1510 if (vs_icap_compare_se(ctx->vsc_idx,
1511 ctx->vsc_host, ctx->vsc_port) == 0) {
1512 if (strcmp(vs_options[ctx->vsc_idx].vso_scanstamp,
1513 ctx->vsc_result->vsr_scanstamp) != 0) {
1514 (void) strlcpy(vs_options[ctx->vsc_idx].vso_scanstamp,
1515 ctx->vsc_result->vsr_scanstamp,
1562 vs_icap_opt_ext(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1564 vs_options_t *opt = &ctx->vsc_options;
1606 * reported violation and save in ctx->vsc_result
1610 vs_icap_resp_infection(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1655 if ((ctx->vsc_result->vsr_nviolations == 0) ||
1656 (ctx->vsc_info.vsi_threat_hdr < VS_RESP_X_INFECTION)) {
1657 vr = &ctx->vsc_result->vsr_vrec[0];
1661 ctx->vsc_result->vsr_nviolations = 1;
1663 ctx->vsc_info.vsi_threat_hdr = VS_RESP_X_INFECTION;
1680 vs_icap_resp_virus_id(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1684 if (ctx->vsc_result->vsr_nviolations == 0) {
1685 vr = &ctx->vsc_result->vsr_vrec[0];
1689 ctx->vsc_result->vsr_nviolations = 1;
1691 ctx->vsc_info.vsi_threat_hdr = VS_RESP_X_VIRUS_ID;
1705 vs_icap_resp_encap(vs_scan_ctx_t *ctx, int hdr_id, char *line)
1708 ctx->vsc_info.vsi_res_hdr = B_TRUE;
1711 ctx->vsc_info.vsi_res_body = B_TRUE;
1804 vs_icap_update_options(vs_scan_ctx_t *ctx)
1806 int idx = ctx->vsc_idx;
1810 if (vs_icap_compare_se(idx, ctx->vsc_host, ctx->vsc_port) == 0) {
1812 vs_icap_copy_options(&vs_options[idx], &ctx->vsc_options);
1834 char *tmp, *ctx;
1848 for (tmp = strtok_r(vec->iov_base, sep, &ctx); tmp;
1849 tmp = strtok_r(0, sep, &ctx)) {