40 #include <sys/types.h>
41 #include <sys/ioctl.h>
44 #include <libxml/tree.h>
45 #include <libxml/xpath.h>
55 #define INFO_BUFFER_SIZE 1024*1024
56 #define OCS_MGMT_MAX_NAME 128
69 printf(
"Mgmt values:\n");
73 obj = status_list->
head;
80 if (strstr(prop->
access,
"r")) {
118 while (node != NULL) {
138 if (list->
head == NULL) {
144 while (node->
next != NULL) {
177 if ((name == NULL) || (strlen(name) < 1)) {
184 if (strcmp(node->
head->name, name) == 0) {
188 if (previous == NULL) {
208 return (list->
head == NULL);
224 smallest_name = obj->
head->name;
227 if (strcmp(obj->
head->name, smallest_name) < 0) {
228 smallest_name = obj->
head->name;
246 new_list->
head = NULL;
261 ret->
name = strdup(name);
262 ret->
value = strdup(value);
263 ret->
access = strdup(access);
276 if (prop->
name != NULL) {
279 if (prop->
value != NULL) {
340 if (obj->
head == NULL) {
346 while (node->
next != NULL) {
361 xmlXPathContextPtr xpathCtx;
362 xmlXPathObjectPtr xpathObj;
367 req.
name = (uint8_t *)name;
368 req.
value = (uint8_t *) buf;
375 printf(
"Error: Device is busy in performing other operations. Please retry the command\n");
381 doc = xmlParseMemory(buf, strlen(buf));
387 xpathCtx = xmlXPathNewContext(doc);
388 if (xpathCtx == NULL) {
394 if (strchr(name,
'[')) {
412 while (*src !=
'\0') {
415 strcpy(dest,
"@instance='");
416 dest += strlen(
"@instance='");
417 while (*src !=
']') {
428 sprintf(xmlExpr,
"//%s", name);
431 xpathObj = xmlXPathEval((xmlChar *)xmlExpr, xpathCtx);
432 if (xpathObj == NULL) {
433 xmlXPathFreeContext(xpathCtx);
439 strncpy(result, (
char *)xmlXPathCastNodeSetToString(xpathObj->nodesetval) ,
sizeof(result) - 1);
441 xmlXPathFreeContext(xpathCtx);
452 req.
name = (uint8_t *) name;
453 req.
value = (uint8_t *) value;
459 printf(
"Device is busy in performing other operations. Please retry the command\n");
470 req.
name = (uint8_t *)name;
518 doc = xmlParseMemory(buf, strlen(buf));
523 cur = xmlDocGetRootElement(doc);
539 numChildren = xmlChildElementCount(node);
540 if (numChildren == 0) {
542 strncpy(long_name, (
char *)xmlGetNodePath(node) ,
sizeof(long_name) - 1);
544 access = (
char *)xmlGetProp(node, (xmlChar *)
"mode");
545 if (access == NULL) {
556 child = xmlFirstElementChild(node);
559 child = xmlNextElementSibling(child);
566 current_section[0] =
'\0';
578 p = strtok(buf,
"<");
581 if (strncmp(p,
"section", 7) == 0) {
584 char *p2 = strstr(p,
"name=");
586 char *p3 = strchr(p2,
'"');
590 strncpy(name, p2, len);
593 if (strlen(current_section) != 0) {
594 strcat(current_section,
".");
596 strcat(current_section, name);
598 }
else if (strncmp(p,
"/section", 8) == 0) {
600 char *p = strrchr(current_section,
'.');
604 current_section[0] =
'\0';
606 }
else if (strncmp(p,
"property", 8) == 0) {
609 char *p2 = strstr(p,
"name=");
611 char *p3 = strchr(p2,
'"');
615 strncpy(name, p2, len);
619 strcpy(long_name, current_section);
620 if (strlen(long_name) > 0) {
621 strcat(long_name,
".");
623 strcat(long_name, name);
632 p = strtok(NULL,
"<");
mgmt_property_t * mgmt_new_property(char *name, char *value, char *access)
mgmt_new_property: Create a new property with the given name and value
static void display_mgmt_list(elxu_device_t *device)
struct mgmt_object * head
void mgmt_delete_object(mgmt_object_t *obj)
mgmt_delete_object: Delete a mgmt object
mgmt_object_t * mgmt_new_object()
mgmt_new_object: Create a new mgmt object
struct mgmt_property * next
#define OCS_IOCTL_CMD_MGMT_SET
#define OCS_MGMT_MAX_NAME
#define OCS_IOCTL_CMD_MGMT_GET
int mgmt_exec(elxu_device_t *device, char *name, void *arg_in, int arg_in_len, void *arg_out, int arg_out_len)
static mgmt_list_t * parse_list(char *buf)
void elxu_mgmt_info(elxu_device_t *device)
static void parse_node(mgmt_list_t *list, xmlNodePtr node)
int elxu_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to a device.
void mgmt_delete_property(mgmt_property_t *prop)
mgmt_delete_property: delete a property, freeing the name and value
mgmt_object_t * mgmt_list_remove(mgmt_list_t *list, char *name)
Remove an object from a list.
struct mgmt_object * next
int mgmt_set_value(elxu_device_t *device, char *name, char *value)
#define OCS_IOCTL_CMD_MGMT_GET_ALL
#define OCS_IOCTL_CMD_MGMT_EXEC
void mgmt_delete_list(mgmt_list_t *list)
mgmt_delete_list Delete a linked list and free its contents
mgmt_list is a linked list of objects
void mgmt_object_add_property(mgmt_object_t *obj, char *name, char *value, char *access)
mgmt_object_add_property: Add a name/value pair to an object as a new property
mgmt_list_t * mgmt_get_all(elxu_device_t *device)
mgmt_object is a list of properties
mgmt_list_t * mgmt_new_list()
mgmt_new_list: Create a new empty linked list
OCS_CTL_CMD_GET_STATUS, OCS_CTL_CMD_GET_CONFIG.
void mgmt_list_sort(mgmt_list_t *list)
mgmt_property is a name / value pair
int mgmt_list_is_empty(mgmt_list_t *list)
struct mgmt_property * head
char * mgmt_get_value(elxu_device_t *device, char *name)
void mgmt_list_add(mgmt_list_t *list, mgmt_object_t *object)
mgmt_list_add: Add an object to the tail of a list