Example #1
0
File: attr.c Project: bgraves/dowse
// TODO: split this in two functions: one to retrieve attr and one to
// strcat contents into it.
void attrcatn(attrlist_t al, const char *name, const _char *value, size_t len) {
    attr_t *at;
    size_t oldlen;
    _char *newvalue;
    at = setup_access(al, name);

    /* a null value would delete the attribute */
    if(value==NULL) {
        if(at) attrdel(al, at); /* delete if there is no value */
        return;
    }

    /* append the string */
    oldlen = at->len;

    // kore_log(LOG_DEBUG,"attr realloc from %u to %u for value: %s",
    //          oldlen, oldlen+len+1, value);

    newvalue = kore_realloc(at->value, oldlen+len+1);
    if(!newvalue) {
        kore_log(LOG_ERR,"attrcatn realloc to size %u",
                 oldlen+len+1);
        return; }

    at->len = oldlen+len+1;
    strncat(newvalue,value,len);
    at->value=newvalue;
}
Example #2
0
/*** EXPORTED STUFF ***/
void attrcatn(attrlist_t al, const char *name, const _char *value, size_t len) {
	attr_t *at;
	size_t oldlen;
	_char *newvalue;
	at=setup_access(al, name);
	/* a null value would delete the attribute */
	if(value==NULL) {
		if(at) attrdel(al, at); /* delete if there is no value */
		return;
	}
	/* append the string */
	oldlen=at->len;
	newvalue=realloc(at->value, oldlen+len+1);
	if(!newvalue) return;
	memcpy(newvalue+oldlen, value, len);
	at->value=newvalue;
}
Example #3
0
/* set an attribute */
static void attrsetn_internal(attrlist_t al, const char *name, int safe_fl, const _char *value, size_t len)
{
	attr_t *at;
	at=setup_access(al, name);
	/* a null value would delete the attribute */
	if(value==NULL) {
		if(at) attrdel(al, at); /* delete if there is no value */
		return;
	}
	/* discard the old attribute values */
	free(at->value);
	at->value=NULL;
	/* set the attribute */
	if(safe_fl) {
		at->len=html_escape_len(value, len);
		at->value=malloc(at->len+1);
		html_escape(at->value, at->len, value);
	} else {
		at->len=len;
		at->value=malloc(len+1);
		memcpy(at->value, value, at->len+1);
	}
}