/******************************************************************** * FUNCTION y_toaster_toaster_toasterStatus_get * * Get database object callback * Path: /toaster/toasterStatus * Fill in 'dstval' contents * * INPUTS: * see ncx/getcb.h for details * * RETURNS: * error status ********************************************************************/ static status_t y_toaster_toaster_toasterStatus_get ( ses_cb_t *scb, getcb_mode_t cbmode, const val_value_t *virval, val_value_t *dstval) { status_t res; const xmlChar *toasterStatus; res = NO_ERR; /* remove the next line if scb is used */ (void)scb; /* remove the next line if virval is used */ (void)virval; if (cbmode != GETCB_GET_VALUE) { return ERR_NCX_OPERATION_NOT_SUPPORTED; } if (toaster_toasting) { toasterStatus = (const xmlChar *)"down"; } else { toasterStatus = (const xmlChar *)"up"; } res = val_set_simval_obj( dstval, dstval->obj, toasterStatus); return res; } /* y_toaster_toaster_toasterStatus_get */
/******************************************************************** * FUNCTION y_toaster_toaster_toasterModelNumber_get * * Get database object callback * Path: /toaster/toasterModelNumber * Fill in 'dstval' contents * * INPUTS: * see ncx/getcb.h for details * * RETURNS: * error status ********************************************************************/ static status_t y_toaster_toaster_toasterModelNumber_get ( ses_cb_t *scb, getcb_mode_t cbmode, const val_value_t *virval, val_value_t *dstval) { status_t res; const xmlChar *toasterModelNumber; res = NO_ERR; /* remove the next line if scb is used */ (void)scb; /* remove the next line if virval is used */ (void)virval; if (cbmode != GETCB_GET_VALUE) { return ERR_NCX_OPERATION_NOT_SUPPORTED; } /* set the toasterModelNumber var here, change EMPTY_STRING */ toasterModelNumber = (const xmlChar *)"Super Toastamatic 2000"; res = val_set_simval_obj( dstval, dstval->obj, toasterModelNumber); return res; } /* y_toaster_toaster_toasterModelNumber_get */
static status_t add_interfaces_state_entry(char* buf, val_value_t* interfaces_state_val) { /*objs*/ obj_template_t* interface_obj; obj_template_t* name_obj; obj_template_t* statistics_obj; obj_template_t* obj; /*vals*/ val_value_t* interface_val; val_value_t* name_val; val_value_t* statistics_val; val_value_t* val; status_t res=NO_ERR; boolean done; char* name; char* str; char* endptr; unsigned int i; uint64_t counter; int ret; char* counter_names_array[] = { "in-octets", "in-unicast-pkts", "in-errors", "in-discards", NULL/*"in-fifo"*/, NULL/*"in-frames"*/, NULL/*in-compressed*/, "in-multicast-pkts", "out-octets", "out-unicast-pkts", "out-errors", "out-discards", NULL/*"out-fifo"*/, NULL/*out-collisions*/, NULL/*out-carrier*/, NULL/*out-compressed*/ }; /* get the start of the interface name */ str = buf; while (*str && isspace(*str)) { str++; } if (*str == '\0') { /* not expecting a line with just whitespace on it */ return ERR_NCX_SKIPPED; } else { name = str++; } /* get the end of the interface name */ while (*str && *str != ':') { str++; } if (*str != ':') { /* expected e.g. eth0: ...*/ return ERR_NCX_SKIPPED; } else { *str=0; str++; } /* /interfaces-state/interface */ interface_obj = obj_find_child(interfaces_state_val->obj, "ietf-interfaces", "interface"); assert(interface_obj != NULL); interface_val = val_new_value(); if (interface_val == NULL) { return ERR_INTERNAL_MEM; } val_init_from_template(interface_val, interface_obj); val_add_child(interface_val, interfaces_state_val); /* /interfaces-state/interface/name */ name_obj = obj_find_child(interface_obj, "ietf-interfaces", "name"); assert(name_obj != NULL); name_val = val_new_value(); if (name_val == NULL) { return ERR_INTERNAL_MEM; } val_init_from_template(name_val, name_obj); res = val_set_simval_obj(name_val, name_obj, name); val_add_child(name_val, interface_val); res = val_gen_index_chain(interface_obj, interface_val); assert(res == NO_ERR); /* /interfaces-state/interface/statistics */ statistics_obj = obj_find_child(interface_obj, "ietf-interfaces", "statistics"); assert(statistics_obj != NULL); statistics_val = val_new_value(); if (statistics_val == NULL) { return ERR_INTERNAL_MEM; } val_init_from_template(statistics_val, statistics_obj); val_add_child(statistics_val, interface_val); done = FALSE; for(i=0;i<(sizeof(counter_names_array)/sizeof(char*));i++) { endptr = NULL; counter = strtoull((const char *)str, &endptr, 10); if (counter == 0 && str == endptr) { /* number conversion failed */ log_error("Error: /proc/net/dev number conversion failed."); return ERR_NCX_OPERATION_FAILED; } if(counter_names_array[i]!=NULL) { obj = obj_find_child(statistics_obj, "ietf-interfaces", counter_names_array[i]); assert(obj != NULL); val = val_new_value(); if (val == NULL) { return ERR_INTERNAL_MEM; } val_init_from_template(val, obj); VAL_UINT64(val) = counter; val_add_child(val, statistics_val); } str = (xmlChar *)endptr; if (*str == '\0' || *str == '\n') { break; } } return res; }