Beispiel #1
0
static esl_event_header_t *new_header(const char *header_name)
{
	esl_event_header_t *header;

#ifdef ESL_EVENT_RECYCLE
		void *pop;
		if (esl_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == ESL_SUCCESS) {
			header = (esl_event_header_t *) pop;
		} else {
#endif
			header = ALLOC(sizeof(*header));
			esl_assert(header);
#ifdef ESL_EVENT_RECYCLE
		}
#endif	

		memset(header, 0, sizeof(*header));
		header->name = DUP(header_name);

		return header;

}
Beispiel #2
0
static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
{
	esl_event_header_t *header = NULL;
	esl_ssize_t hlen = -1;
	int exists = 0;
	
	if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT) || esl_test_flag(event, ESL_EF_CONTAINS_ARRAYS)) {

		if ((header = esl_event_get_header_ptr(event, header_name))) {
			
			if (!(stack & ESL_STACK_PUSH) && !(stack & ESL_STACK_UNSHIFT) && header->idx) {
				stack |= ESL_STACK_PUSH;
			}

			if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
				exists++;
				stack &= ~(ESL_STACK_TOP | ESL_STACK_BOTTOM);
			} else {
				header = NULL;
			}
		}
	}

	if (!header) {

#ifdef ESL_EVENT_RECYCLE
		void *pop;
		if (esl_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == ESL_SUCCESS) {
			header = (esl_event_header_t *) pop;
		} else {
#endif
			header = ALLOC(sizeof(*header));
			esl_assert(header);
#ifdef ESL_EVENT_RECYCLE
		}
#endif
	

		if (esl_test_flag(event, ESL_EF_UNIQ_HEADERS)) {
			esl_event_del_header(event, header_name);
		}

		memset(header, 0, sizeof(*header));

		header->name = DUP(header_name);
	}
	
	if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
		char **m = NULL;
		esl_size_t len = 0;
		char *hv;
		int i = 0, j = 0;

		esl_set_flag(event, ESL_EF_CONTAINS_ARRAYS);

		if (header->value && !header->idx) {
			m = malloc(sizeof(char *));
			esl_assert(m);
			m[0] = header->value;
			header->value = NULL;
			header->array = m;
			header->idx++;
			m = NULL;
		}

		i = header->idx + 1;
		m = realloc(header->array, sizeof(char *) * i); 
		esl_assert(m);

		if ((stack & ESL_STACK_PUSH)) {
			m[header->idx] = data;
		} else if ((stack & ESL_STACK_UNSHIFT)) {
			for (j = header->idx; j > 0; j--) {
				m[j] = m[j-1];
			}
			m[0] = data;
		}

		header->idx++;		
		header->array = m;

		for(j = 0; j < header->idx; j++) {
			len += strlen(header->array[j]) + 2;
		}

		if (len) {
			len += 8;
			hv = realloc(header->value, len);
			esl_assert(hv);
			header->value = hv;
			esl_snprintf(header->value, len, "ARRAY::");
			for(j = 0; j < header->idx; j++) {
				esl_snprintf(header->value + strlen(header->value), len - strlen(header->value), "%s%s", j == 0 ? "" : "::", header->array[j]);
			}
		}

	} else {
		header->value = data;
	}

	if (!exists) {
		header->hash = esl_ci_hashfunc_default(header->name, &hlen);

		if ((stack & ESL_STACK_TOP)) {
			header->next = event->headers;
			event->headers = header;
			if (!event->last_header) {
				event->last_header = header;
			}
		} else {
			if (event->last_header) {
				event->last_header->next = header;
			} else {
				event->headers = header;
				header->next = NULL;
			}
			event->last_header = header;
		}
	}

	return ESL_SUCCESS;
}