MEDIUM: chunks: make the chunk struct's fields match the buffer struct

Chunks are only a subset of a buffer (a non-wrapping version with no head
offset). Despite this we still carry a lot of duplicated code between
buffers and chunks. Replacing chunks with buffers would significantly
reduce the maintenance efforts. This first patch renames the chunk's
fields to match the name and types used by struct buffers, with the goal
of isolating the code changes from the declaration changes.

Most of the changes were made with spatch using this coccinelle script :

  @rule_d1@
  typedef chunk;
  struct chunk chunk;
  @@
  - chunk.str
  + chunk.area

  @rule_d2@
  typedef chunk;
  struct chunk chunk;
  @@
  - chunk.len
  + chunk.data

  @rule_i1@
  typedef chunk;
  struct chunk *chunk;
  @@
  - chunk->str
  + chunk->area

  @rule_i2@
  typedef chunk;
  struct chunk *chunk;
  @@
  - chunk->len
  + chunk->data

Some minor updates to 3 http functions had to be performed to take size_t
ints instead of ints in order to match the unsigned length here.
diff --git a/src/51d.c b/src/51d.c
index a36333e..4ad82fe 100644
--- a/src/51d.c
+++ b/src/51d.c
@@ -160,7 +160,7 @@
 	if (!ptr)
 		return;
 
-	free(ptr->str);
+	free(ptr->area);
 	free(ptr);
 }
 
@@ -189,15 +189,15 @@
 	if (!cache_entry)
 		return;
 
-	cache_entry->str = _51d_malloc(smp->data.u.str.len + 1);
-	if (!cache_entry->str) {
+	cache_entry->area = _51d_malloc(smp->data.u.str.data + 1);
+	if (!cache_entry->area) {
 		free(cache_entry);
 		return;
 	}
 
-	memcpy(cache_entry->str, smp->data.u.str.str, smp->data.u.str.len);
-	cache_entry->str[smp->data.u.str.len] = 0;
-	cache_entry->len = smp->data.u.str.len;
+	memcpy(cache_entry->area, smp->data.u.str.area, smp->data.u.str.data);
+	cache_entry->area[smp->data.u.str.data] = 0;
+	cache_entry->data = smp->data.u.str.data;
 	lru64_commit(lru, cache_entry, domain, 0, _51d_lru_free);
 }
 
@@ -206,8 +206,8 @@
 static void _51d_retrieve_cache_entry(struct sample *smp, struct lru64 *lru)
 {
 	struct chunk *cache_entry = lru->data;
-	smp->data.u.str.str = cache_entry->str;
-	smp->data.u.str.len = cache_entry->len;
+	smp->data.u.str.area = cache_entry->area;
+	smp->data.u.str.data = cache_entry->data;
 }
 #endif
 
@@ -228,10 +228,9 @@
 
 	for (i = 0; i < global_51degrees.header_count; i++) {
 		ctx.idx = 0;
-		if (http_find_full_header2(
-			(global_51degrees.header_names + i)->str,
-			(global_51degrees.header_names + i)->len,
-			msg->chn->buf->p, idx, &ctx) == 1) {
+		if (http_find_full_header2((global_51degrees.header_names + i)->area,
+					   (global_51degrees.header_names + i)->data,
+					   msg->chn->buf->p, idx, &ctx) == 1) {
 			ws->importantHeaders[ws->importantHeadersCount].header = ws->dataSet->httpHeaders + i;
 			ws->importantHeaders[ws->importantHeadersCount].headerValue = ctx.line + ctx.val;
 			ws->importantHeaders[ws->importantHeadersCount].headerValueLength = ctx.vlen;
@@ -256,10 +255,9 @@
 
 	for (index = 0; index < global_51degrees.header_count; index++) {
 		ctx.idx = 0;
-		if (http_find_full_header2(
-			(global_51degrees.header_names + index)->str,
-			(global_51degrees.header_names + index)->len,
-			msg->chn->buf->p, idx, &ctx) == 1) {
+		if (http_find_full_header2((global_51degrees.header_names + index)->area,
+					   (global_51degrees.header_names + index)->data,
+					   msg->chn->buf->p, idx, &ctx) == 1) {
 			(offsets->firstOffset + offsets->size)->httpHeaderOffset = *(global_51degrees.header_offsets + index);
 			(offsets->firstOffset + offsets->size)->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set, ctx.line + ctx.val);
 			offsets->size++;
@@ -307,11 +305,11 @@
 	const char* property_name;
 
 	/* Loop through property names passed to the filter and fetch them from the dataset. */
-	while (args[i].data.str.str) {
+	while (args[i].data.str.area) {
 		/* Try to find request property in dataset. */
 		found = 0;
 #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
-		if (strcmp("Method", args[i].data.str.str) == 0) {
+		if (strcmp("Method", args[i].data.str.area) == 0) {
 			switch(ws->method) {
 				case EXACT: methodName = "Exact"; break;
 				case NUMERIC: methodName = "Numeric"; break;
@@ -323,18 +321,18 @@
 			chunk_appendf(temp, "%s", methodName);
 			found = 1;
 		}
-		else if (strcmp("Difference", args[i].data.str.str) == 0) {
+		else if (strcmp("Difference", args[i].data.str.area) == 0) {
 			chunk_appendf(temp, "%d", ws->difference);
 			found = 1;
 		}
-		else if (strcmp("Rank", args[i].data.str.str) == 0) {
+		else if (strcmp("Rank", args[i].data.str.area) == 0) {
 			chunk_appendf(temp, "%d", fiftyoneDegreesGetSignatureRank(ws));
 			found = 1;
 		}
 		else {
 			for (j = 0; j < ws->dataSet->requiredPropertyCount; j++) {
 				property_name = fiftyoneDegreesGetPropertyName(ws->dataSet, ws->dataSet->requiredProperties[j]);
-				if (strcmp(property_name, args[i].data.str.str) == 0) {
+				if (strcmp(property_name, args[i].data.str.area) == 0) {
 					found = 1;
 					fiftyoneDegreesSetValues(ws, j);
 					chunk_appendf(temp, "%s", fiftyoneDegreesGetValueName(ws->dataSet, *ws->values));
@@ -347,7 +345,7 @@
 		found = 0;
 		for (j = 0; j < requiredPropertiesCount; j++) {
 			property_name = requiredProperties[j];
-			if (strcmp(property_name, args[i].data.str.str) == 0 &&
+			if (strcmp(property_name, args[i].data.str.area) == 0 &&
 				fiftyoneDegreesGetValueFromOffsets(&global_51degrees.data_set, deviceOffsets, j, valuesBuffer, 1024) > 0) {
 				found = 1;
 				chunk_appendf(temp, "%s", valuesBuffer);
@@ -363,13 +361,13 @@
 		++i;
 	}
 
-	if (temp->len) {
-		--temp->len;
-		temp->str[temp->len] = '\0';
+	if (temp->data) {
+		--temp->data;
+		temp->area[temp->data] = '\0';
 	}
 
-	smp->data.u.str.str = temp->str;
-	smp->data.u.str.len = temp->len;
+	smp->data.u.str.area = temp->area;
+	smp->data.u.str.data = temp->data;
 }
 
 static int _51d_fetch(const struct arg *args, struct sample *smp, const char *kw, void *private)
@@ -457,7 +455,7 @@
 	if (_51d_lru_tree) {
 		unsigned long long seed = _51d_lru_seed ^ (long)args;
 
-		lru = lru64_get(XXH64(smp->data.u.str.str, smp->data.u.str.len, seed),
+		lru = lru64_get(XXH64(smp->data.u.str.area, smp->data.u.str.data, seed),
 		                _51d_lru_tree, (void*)args, 0);
 		if (lru && lru->domain) {
 			_51d_retrieve_cache_entry(smp, lru);
@@ -475,15 +473,16 @@
 	if (!smp_dup(smp))
 		return 0;
 
-	smp->data.u.str.str[smp->data.u.str.len] = '\0';
+	smp->data.u.str.area[smp->data.u.str.data] = '\0';
 
 	/* Perform detection. */
 #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
-	fiftyoneDegreesMatch(ws, smp->data.u.str.str);
+	fiftyoneDegreesMatch(ws, smp->data.u.str.area);
 	_51d_process_match(args, smp, ws);
 #endif
 #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED
-	global_51degrees.device_offsets.firstOffset->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set, smp->data.u.str.str);
+	global_51degrees.device_offsets.firstOffset->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set,
+												   smp->data.u.str.area);
 	global_51degrees.device_offsets.size = 1;
 	_51d_process_match(args, smp);
 #endif
@@ -507,9 +506,9 @@
 	global_51degrees.header_names = malloc(global_51degrees.header_count * sizeof(struct chunk));
 	for (index = 0; index < global_51degrees.header_count; index++) {
 		headerName = fiftyoneDegreesGetString(ds, ds->httpHeaders[index].headerNameOffset);
-		(global_51degrees.header_names + index)->str = (char*)&headerName->firstByte;
-		(global_51degrees.header_names + index)->len = headerName->length - 1;
-		(global_51degrees.header_names + index)->size = (global_51degrees.header_names + index)->len;
+		(global_51degrees.header_names + index)->area = (char*)&headerName->firstByte;
+		(global_51degrees.header_names + index)->data = headerName->length - 1;
+		(global_51degrees.header_names + index)->size = (global_51degrees.header_names + index)->data;
 	}
 }
 #endif
@@ -526,9 +525,9 @@
 	global_51degrees.header_offsets = malloc(global_51degrees.header_count * sizeof(int32_t));
 	for (index = 0; index < global_51degrees.header_count; index++) {
 		global_51degrees.header_offsets[index] = fiftyoneDegreesGetHttpHeaderNameOffset(ds, index);
-		global_51degrees.header_names[index].str = (char*)fiftyoneDegreesGetHttpHeaderNamePointer(ds, index);
-		global_51degrees.header_names[index].len = strlen(global_51degrees.header_names[index].str);
-		global_51degrees.header_names[index].size = global_51degrees.header_names[index].len;
+		global_51degrees.header_names->area = (char*)fiftyoneDegreesGetHttpHeaderNamePointer(ds, index);
+		global_51degrees.header_names->data = strlen(global_51degrees.header_names->area);
+		global_51degrees.header_names[index].size = global_51degrees.header_names->data;
 	}
 }
 #endif
@@ -615,8 +614,9 @@
 			break;
 	}
 	if (_51d_dataset_status != DATA_SET_INIT_STATUS_SUCCESS) {
-		if (temp->len)
-			ha_alert("51Degrees Setup - Error reading 51Degrees data file. %s\n", temp->str);
+		if (temp->data)
+			ha_alert("51Degrees Setup - Error reading 51Degrees data file. %s\n",
+				 temp->area);
 		else
 			ha_alert("51Degrees Setup - Error reading 51Degrees data file.\n");
 		return ERR_ALERT | ERR_FATAL;