示例#1
0
static void set_features(const char* name, PyObject *PyFeatures)
{
	Py_ssize_t l, i;
	PyObject *PyStr;

	if (!PyFeatures) {
		/* not specified -> enable all */
		ncds_features_enableall(name);
	} else if ((l = PyList_Size(PyFeatures)) == 0) {
		/* empty list -> disable all */
		ncds_features_disableall(name);
	} else {
		/* enable specified */
		for (i = 0; i < l; i++) {
			PyObject *PyUni = PyList_GetItem(PyFeatures, i);
			Py_INCREF(PyUni);
			if (!PyUnicode_Check(PyUni)) {
				Py_DECREF(PyUni);
				continue;
			}
			PyStr = PyUnicode_AsEncodedString(PyUni, "UTF-8", NULL);
			Py_DECREF(PyUni);
			if (PyStr == NULL) {
				continue;
			}
			ncds_feature_enable(name, PyBytes_AsString(PyStr));
			Py_DECREF(PyStr);
		}
	}
}
示例#2
0
int cmd_add_model(const char* arg) {
	char* argv, *ptr, *ptr2, *model;
	struct data_model* mdl;

	argv = strdupa(arg + strlen("add-model "));

	if ((ptr = strtok(argv, " ")) == NULL) {
		cmd_add_model_help();
		return 1;
	}

	/* add .yin if not specified */
	ptr2 = strstr(ptr, ".yin");
	if (ptr2 == NULL) {
		asprintf(&ptr2, "%s.yin", ptr);
		model = ptr2;
	} else {
		ptr2 = NULL;
		model = ptr;
	}

	mdl = read_model(model);
	free(ptr2);
	if (mdl == NULL) {
		return 1;
	}

	add_hint(mdl->name);

	ptr = strtok(NULL, " ");
	if (ptr != NULL) {
		if (strcmp(ptr, "*") == 0) {
			ncds_features_enableall(mdl->name);
			return 0;
		} else {
			ncds_feature_enable(mdl->name, ptr);
		}
	}
	while ((ptr = strtok(NULL, " ")) != NULL) {
		ncds_feature_enable(mdl->name, ptr);
	}

	return 0;
}
示例#3
0
int cmd_add_datastore(const char* arg) {
	char* argv, *ptr, *ptr2;
	struct ncds_ds* new_ds;

	argv = strdupa(arg + strlen("add-datastore "));

	if ((ptr = strtok(argv, " ")) == NULL) {
		cmd_add_datastore_help();
		return 1;
	}

	/* remove .yin if specified */
	ptr2 = strstr(ptr, ".yin");
	if (ptr2 != NULL) {
		*ptr2 = '\0';
	}

	if ((new_ds = ncds_new_internal(NCDS_TYPE_EMPTY, ptr)) == NULL) {
		return 1;
	}

	ncds_init(new_ds);

	add_hint(new_ds->data_model->name);

	ptr = strtok(NULL, " ");
	if (ptr != NULL) {
		if (strcmp(ptr, "*") == 0) {
			ncds_features_enableall(new_ds->data_model->name);
			return 0;
		} else {
			ncds_feature_enable(new_ds->data_model->name, ptr);
		}
	}
	while ((ptr = strtok(NULL, " ")) != NULL) {
		ncds_feature_enable(new_ds->data_model->name, ptr);
	}

	return 0;
}
/*
 * if repo_type is -1, then we are working with augment models specifications
 */
static int parse_model_cfg(struct np_module* module, xmlNodePtr node, NCDS_TYPE repo_type) {
	char *transapi_path = NULL, *model_path = NULL, *feature, *name, *aux;
	struct transapi *st = NULL;
	xmlNodePtr aux_node;

	if (strcmp(module->name, NETOPEER_MODULE_NAME) == 0) {
		st = &netopeer_transapi;
	} else if (strcmp(module->name, NCSERVER_MODULE_NAME) == 0) {
		st = &server_transapi;
	}

	for (aux_node = node->children; aux_node != NULL; aux_node = aux_node->next) {
		if (xmlStrcmp(aux_node->name, BAD_CAST "path") == 0) {
			model_path = (char*)xmlNodeGetContent(aux_node);
		}
		if (xmlStrcmp(aux_node->name, BAD_CAST "transapi") == 0) {
			transapi_path = (char*)xmlNodeGetContent(aux_node);
		}
		if (model_path && transapi_path) {
			break;
		}
	}
	/* Netopeer module is something extra */
	if (st != NULL && model_path) {
		/* internal static server (Netopeer) module */
		if (repo_type == -1 && transapi_path) {
			/* augment transapi module */
			nc_verb_verbose("Adding augment transapi \"%s\"", model_path);
			ncds_add_augment_transapi(model_path, transapi_path);
		} else if (repo_type == -1) {
			/* augment model */
			nc_verb_verbose("Adding augment model \"%s\"", model_path);
			ncds_add_model(model_path);
		} else {
			nc_verb_verbose("Adding static transapi \"%s\"", model_path);
			if ((module->ds = ncds_new_transapi_static(repo_type, model_path, st)) == NULL) {
				free(model_path);
				free(transapi_path);
				return (EXIT_FAILURE);
			}
		}
	} else if (model_path && transapi_path) {
		if (repo_type == -1) {
			/* augment transapi module */
			nc_verb_verbose("Adding augment transapi \"%s\"", model_path);
			ncds_add_augment_transapi(model_path, transapi_path);
		} else {
			/* base transapi module for datastore */
			nc_verb_verbose("Adding transapi \"%s\"", model_path);
			if ((module->ds = ncds_new_transapi(repo_type, model_path, transapi_path)) == NULL) {
				free(model_path);
				free(transapi_path);
				return (EXIT_FAILURE);
			}
		}
	} else if (model_path) {
		if (repo_type == -1) {
			/* augment model */
			nc_verb_verbose("Adding augment model \"%s\"", model_path);
			ncds_add_model(model_path);
		} else {
			/* base model for datastore */
			nc_verb_verbose("Adding base model \"%s\"", model_path);
			if ((module->ds = ncds_new2(repo_type, model_path, NULL)) == NULL) {
				free(model_path);
				return (EXIT_FAILURE);
			}
		}
	} else {
		nc_verb_error("Configuration mismatch: missing model path in %s config.", module->name);
	}
	name = strdup(basename(model_path));
	/* cut off the .yin suffix */
	aux = strrchr(name, '.');
	if (aux) { *aux = '\0';}

	free(model_path);
	free(transapi_path);

	/* set features */
	for (aux_node = node->children; aux_node != NULL; aux_node = aux_node->next) {
		if (xmlStrcmp(aux_node->name, BAD_CAST "feature") == 0) {
			feature = (char*)xmlNodeGetContent(aux_node);
			if (strcmp(feature, "*") == 0) {
				ncds_features_enableall(name);
			} else {
				ncds_feature_enable(name, feature);
			}
			free(feature);
		}
	}
	free(name);

	return (EXIT_SUCCESS);
}