Example #1
0
int plot_index_add_qidx_file(plotindex_t* args, const char* fn) {
	int i;
	qidxfile* qidx = qidxfile_open(fn);
	if (!qidx) {
		ERROR("Failed to open quad index file \"%s\"", fn);
		return -1;
	}
	pad_qidxes(args);
	i = pl_size(args->indexes) - 1;
	pl_set(args->qidxes, i, qidx);
	return 0;
}
Example #2
0
/**
 * @brief	Split a mime body into an array of children by a boundary string.
 * @param	body		a placer containing the body text to be parsed.
 * @param	boundary	a pointer to a managed string containing the boundary string to split the mime content.
 * @return	NULL on failure, or a pointer to an array of mime children on success.
 */
array_t * mail_mime_split(placer_t body, stringer_t *boundary) {

	array_t *result;
	uint32_t parts;
	stringer_t *item;

	// Figure out how many children this body part has.
	if (!(parts = mail_mime_count(body, boundary))) {
		return NULL;
	}

	// Allocate an array to hold all of the children.
	if (!(result = ar_alloc(parts))) {
		log_pedantic("Could not allocate an array of %i elements for the MIME parts.", parts);
		return NULL;
	}

	// Build an array that contains all of the children.
	for (uint32_t i = 1; i <= parts; i++) {

		if ((item = st_alloc_opts(PLACER_T | JOINTED | HEAP | FOREIGNDATA, 0))) {

			// Get the part and clean it up.
			*((placer_t *)item) = pl_set(*((placer_t *)item), mail_mime_child(body, boundary, i));

			/// TODO: This is ugly. Because the array gets a placer pointer we need to free it when done. But that means differentiating between
			/// these placers and what were usually passed which will likely stack allocated placers. We could probably just change it to a stringer
			/// now that its going to st_free(), but that would mean lots of updates all over the place.
			if (st_empty(item) || ar_append(&result, ARRAY_TYPE_STRINGER, item) != 1) {
				st_free(item);
			}

		}
	}

	return result;
}