Example #1
0
/* al - NULL to use a "dumping" mode */
void template_apply(template_t *t, attrlist_t al, kore_buf_t *out) {
	struct entry *e;
	char buf[64]; /* TODO: max macro length */
	attr_t *tmp;

	/* TODO: we could cache the attrget lookup */
	// fflush(stdout); /* we'll be using posix i/o instead of iso c */
	for(e=t->entry_list;e;e=e->next) {
        // kore_log(LOG_DEBUG,"::%u:%u:%.*s",
        //          e->type, e->len, e->len, e->data);

		/* ignore macro type if the macro is too large */
		if(al && e->type && (e->len<(sizeof buf-1))) {
			memcpy(buf, e->data, e->len);
			buf[e->len]=0;
			tmp = attrget(al, buf);
            if(tmp) kore_buf_append(out, tmp->value, tmp->len);

		} else if(!al && e->type) { /* debug mode because al==NULL */
			kore_log(LOG_DEBUG,"%s (%u)", e->data, e->len);
		} else { /* raw data */
            if(e->data) kore_buf_append(out,e->data,e->len);
        }
	}
}
Example #2
0
/* gets an attribute as a numeric value */
int attrget_int(attrlist_t al, const char *name, long *i) {
	long ret;
	const char *tmp;
	char *endptr;

	assert(i!=NULL);
	assert(al!=NULL);
	assert(name!=NULL);
	tmp=(const char*)attrget(al, name);
	if(!tmp) {
		return 0; /* failure */
	}
	ret=strtoul(tmp, &endptr, 10);
	assert(endptr!=NULL);
	if(endptr==tmp || *endptr) {
		return 0; /* failure */
	}
	*i=ret;
	return 1; /* success */
}