예제 #1
0
isc_result_t dhcp_group_set_value  (omapi_object_t *h,
				    omapi_object_t *id,
				    omapi_data_string_t *name,
				    omapi_typed_data_t *value)
{
	struct group_object *group;
	isc_result_t status;
	int foo;

	if (h -> type != dhcp_type_group)
		return ISC_R_INVALIDARG;
	group = (struct group_object *)h;

	/* XXX For now, we can only set these values on new group objects. 
	   XXX Soon, we need to be able to update group objects. */
	if (!omapi_ds_strcmp (name, "name")) {
		if (group -> name)
			return ISC_R_EXISTS;
		if (value -> type == omapi_datatype_data ||
		    value -> type == omapi_datatype_string) {
			group -> name = dmalloc (value -> u.buffer.len + 1,
						 MDL);
			if (!group -> name)
				return ISC_R_NOMEMORY;
			memcpy (group -> name,
				value -> u.buffer.value,
				value -> u.buffer.len);
			group -> name [value -> u.buffer.len] = 0;
		} else
			return ISC_R_INVALIDARG;
		return ISC_R_SUCCESS;
	}

	if (!omapi_ds_strcmp (name, "statements")) {
		if (group -> group && group -> group -> statements)
			return ISC_R_EXISTS;
		if (!group -> group) {
			if (!clone_group (&group -> group, root_group, MDL))
				return ISC_R_NOMEMORY;
		}
		if (value -> type == omapi_datatype_data ||
		    value -> type == omapi_datatype_string) {
			struct parse *parse;
			int lose = 0;
			parse = (struct parse *)0;
			status = new_parse (&parse, -1,
					    (char *)value -> u.buffer.value,
					    value -> u.buffer.len,
					    "network client", 0);
			if (status != ISC_R_SUCCESS)
				return status;
			if (!(parse_executable_statements
			      (&group -> group -> statements, parse, &lose,
			       context_any))) {
				end_parse (&parse);
				return ISC_R_BADPARSE;
			}
			end_parse (&parse);
			return ISC_R_SUCCESS;
		} else
			return ISC_R_INVALIDARG;
	}

	/* Try to find some inner object that can take the value. */
	if (h -> inner && h -> inner -> type -> set_value) {
		status = ((*(h -> inner -> type -> set_value))
			  (h -> inner, id, name, value));
		if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)
			return status;
	}
			  
	return ISC_R_NOTFOUND;
}
예제 #2
0
파일: dbquery.c 프로젝트: VertiPub/mcelog
int main(int ac, char **av)
{
	struct database *db;
	struct group *group = NULL;
	char *line = NULL;
	size_t linesz = 0;
	if (!av[1]) {
		printf("%s database\n", av[0]);
		exit(1);
	}
	printf("dbtest\n");
	db = open_db(av[1], 1);
	while (printf("> "),
		fflush(stdout),
		getline(&line, &linesz, stdin) > 0) {
		char *p = line + strlen(line) - 1;
		while (p >= line && isspace(*p))
			*p-- = 0;
		switch (line[0]) {
		case 's':
			C(sync_db(db));
			break;
		case 'q':
			C(close_db(db));
			exit(0);
		case 'g':
			group = find_group(db, line + 1);
			if (group)
				printf("found\n");
			break;
		case 'G':
			NEEDGROUP;
			C(delete_group(db, group));
			group = NULL;
			break;
		case 'a': {
			int existed = 0;
			group = add_group(db, line + 1, &existed);
			if (existed)
				printf("existed\n");
			break;
		}
		case 'v':
			NEEDGROUP;
			printf("%s\n", entry_val(group, line + 1));
			break;
		case 'c': {
			p = line + 1;
			char *entry = strsep(&p, ",");
			NEEDGROUP;
			change_entry(db, group, entry, strsep(&p, ""));
			break;
		}
		case 'L':
			NEEDGROUP;
			clone_group(db, group, line + 1);
			break;
		case 'f': {
			struct group *g;
			p = line + 1;
			char *entry = strsep(&p, ",");
			char *val = strsep(&p, "");
			g = NULL;
			int nr = 0;
			while ((g = find_entry(db, g, entry, val)) != NULL) {
				if (nr == 0)
					group = g;
				nr++;
				dump_group(group, stdout);
			}
			if (nr == 0)
				printf("not found\n");
			break;
		}
		case 'C':
			NEEDGROUP;
			add_comment(db, group, line + 1);
			break;
		case 'd':
			NEEDGROUP;
			dump_group(group, stdout);
			break;
		case 'D':
			dump_database(db, stdout);
			break;
		default:
			usage();
			break;
		}
	}
	return 0;
}