ClamAV-Clamd
view release on metacpan or search on metacpan
include/clamav/clamd_abi_impl.h view on Meta::CPAN
g->t.reply_max = 1024 * 1024;
g->t.frame = CC_FRAME_Z;
return g;
}
static void cca_target_timeouts(pTHX_ void *target, double ct, double rt) {
cca_target *g = (cca_target *)target;
PERL_UNUSED_CONTEXT;
if (!g) return;
if (ct > 0) g->t.connect_timeout = ct;
if (rt > 0) g->t.reply_timeout = rt;
}
static void cca_target_limits(pTHX_ void *target, size_t reply_max,
size_t chunk, size_t max_size) {
cca_target *g = (cca_target *)target;
PERL_UNUSED_CONTEXT;
if (!g) return;
if (reply_max) g->t.reply_max = reply_max;
g->t.chunk = chunk;
g->t.max_size = max_size;
}
static void cca_target_free(pTHX_ void *target) {
cca_target *g = (cca_target *)target;
PERL_UNUSED_CONTEXT;
if (!g) return;
free(g->path); free(g->host); free(g);
}
/* A handle is always returned, even for a refusal, so verdict_state is
* always answerable - the same rule the Perl side follows, for the same
* reason: the safe reading has to be the short one. */
static cc_scan *cca_scan_new(void) {
cc_scan *s = (cc_scan *)malloc(sizeof *s);
if (!s) return NULL;
memset(s, 0, sizeof *s);
s->sock = CC_INVALID_SOCK;
s->scan_fd = -1;
s->phase = CC_PH_DONE;
return s;
}
static int cca_pick_mode(const cc_target *t) {
return (CC_HAVE_FD_PASSING && t->path) ? CC_TRANSPORT_FILDES
: CC_TRANSPORT_INSTREAM;
}
static void *cca_start_fd(pTHX_ void *target, int fd, int blocking) {
cca_target *g = (cca_target *)target;
cc_scan *s;
int mode;
PERL_UNUSED_CONTEXT;
if (!g) return NULL;
s = cca_scan_new();
if (!s) return NULL;
{
struct stat st;
if (fstat(fd, &st) < 0) {
cc_err_set(&s->err, CC_ERR_IO, "fstat", strerror(errno));
s->rc = CC_ERR_IO; return s;
}
if (!S_ISREG(st.st_mode)) {
cc_err_set(&s->err, CC_ERR_NOTREG, "not a regular file", NULL);
s->rc = CC_ERR_NOTREG; return s;
}
if (g->t.max_size && (size_t)st.st_size > g->t.max_size) {
cc_err_set(&s->err, CC_ERR_TOOBIGLOC,
"larger than max_size; refused without scanning", NULL);
s->rc = CC_ERR_TOOBIGLOC; return s;
}
}
mode = cca_pick_mode(&g->t);
if (mode == CC_TRANSPORT_FILDES)
(void)cc_scan_start(s, &g->t, mode, fd, 0, NULL, 0, -1);
else
(void)cc_scan_start(s, &g->t, mode, -1, 0, NULL, 0, fd);
if (blocking) {
char *out = NULL;
size_t n = 0;
cc_err e;
(void)cc_scan_run(s, &out, &n, &e);
/* cc_scan_run hands ownership out; put it straight back, because
* the verdict is read from the handle. */
s->reply = out; s->replylen = n;
}
return s;
}
static void *cca_start_mem(pTHX_ void *target, const char *buf, size_t len,
int blocking) {
cca_target *g = (cca_target *)target;
cc_scan *s;
PERL_UNUSED_CONTEXT;
if (!g) return NULL;
s = cca_scan_new();
if (!s) return NULL;
if (g->t.max_size && len > g->t.max_size) {
cc_err_set(&s->err, CC_ERR_TOOBIGLOC,
"larger than max_size; refused without scanning", NULL);
s->rc = CC_ERR_TOOBIGLOC;
return s;
}
(void)cc_scan_start(s, &g->t, CC_TRANSPORT_INSTREAM, -1, 0,
buf ? buf : "", len, -1);
if (blocking) {
char *out = NULL;
size_t n = 0;
cc_err e;
(void)cc_scan_run(s, &out, &n, &e);
s->reply = out; s->replylen = n;
}
return s;
( run in 4.471 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )