Example #1
0
/* Create new context */
tcCtx tcNew(tcCallbacks *cb) {
    tcCtx g = cb->malloc(cb->ctx, sizeof(struct tcCtx_));
    tcprivCtx h;

    g->cb = *cb;

    h = MEM_NEW(g, sizeof(struct tcprivCtx_));

    tc_dna_memcb.ctx = g;
    tc_dna_memcb.manage = tc_manage;
    g->ctx.dnaCtx = dnaNew(&tc_dna_memcb, DNA_CHECK_ARGS);

    dnaINIT(g->ctx.dnaCtx, h->set, 4, 120);
    h->set.func = fontInit;

    initSet(g, h);

    /* Initialize other library modules */
    g->ctx.sindex = NULL;
    g->ctx.fdselect = NULL;
    g->ctx.subr = NULL;
    g->ctx.cs = NULL;
    g->ctx.encoding = NULL;
    g->ctx.charset = NULL;
    g->ctx.recode = NULL;
    g->ctx.parse = NULL;
    g->ctx.tcpriv = NULL;
    g->ctx.t13 = NULL;

    sindexNew(g);
    encodingNew(g);
    charsetNew(g);
    parseNew(g);
    csNew(g);
    recodeNew(g);
#if TC_SUBR_SUPPORT
    subrNew(g);
#endif /* TC_SUBR_SUPPORT */
    fdselectNew(g);
    t13New(g);

    /* Link contexts */
    h->g = g;
    g->ctx.tcpriv = h;

    return g;
}
void SyslogParser::parse(const std::string& msg)
{
	// <int> -> int: lower 3 bits severity, upper bits: facility
	std::size_t pos = 0;
	RemoteSyslogChannel::Severity severity;
	RemoteSyslogChannel::Facility fac;
	parsePrio(msg, pos, severity, fac);

	// the next field decide if we parse an old BSD message or a new syslog message
	// BSD: expects a month value in string form: Jan, Feb...
	// SYSLOG expects a version number: 1
	
	if (std::isdigit(msg[pos]))
	{
		parseNew(msg, severity, fac, pos);
	}
	else
	{
		parseBSD(msg, severity, fac, pos);
	}
	poco_assert (pos == msg.size());
}