Esempio n. 1
0
/**
 * Helper function to perform the equivalent of
 * msab_getStatus(&stats, x) but over the network.
 */
static char *
MEROgetStatus(sabdb **ret, char *database)
{
	sabdb *orig;
	sabdb *stats;
	sabdb *w = NULL;
	size_t swlen = 50;
	size_t swpos = 0;
	sabdb **sw;
	char *p;
	char *buf;
	char *e;
	
	if (database == NULL)
		database = "#all";

	e = control_send(&buf, mero_host, mero_port,
			database, "status", 1, mero_pass);
	if (e != NULL)
		return(e);

	sw = malloc(sizeof(sabdb *) * swlen);
	orig = NULL;
	if ((p = strtok(buf, "\n")) != NULL) {
		if (strcmp(p, "OK") != 0) {
			p = strdup(p);
			free(buf);
			free(sw);
			return(p);
		}
		for (swpos = 0; (p = strtok(NULL, "\n")) != NULL; swpos++) {
			e = msab_deserialise(&stats, p);
			if (e != NULL) {
				printf("WARNING: failed to parse response from "
						"monetdbd: %s\n", e);
				free(e);
				swpos--;
				continue;
			}
			if (swpos == swlen)
				sw = realloc(sw, sizeof(sabdb *) * (swlen = swlen * 2));
			sw[swpos] = stats;
		}
	}

	free(buf);

	if (swpos > 1) {
		qsort(sw, swpos, sizeof(sabdb *), cmpsabdb);
		orig = w = sw[0];
		for (swlen = 1; swlen < swpos; swlen++)
			w = w->next = sw[swlen];
	} else if (swpos == 1) {
		orig = sw[0];
		orig->next = NULL;
	}

	free(sw);

	*ret = orig;
	return(NULL);
}
Esempio n. 2
0
/**
 * Produces a sabdb struct out of a serialised string.
 */
str SABAOTHdeserialise(sabdb **ret, str *sdb) {
	str err = msab_deserialise(ret, *sdb);
	if (err != NULL)
		excFromMem(MAL, "sabaoth.deserialise", err);
	return(MAL_SUCCEED);
}