json_t *get_json_listener(listener_dest_info_t *header) { json_t *result = NULL; json_t *jitem = NULL; json_t *evt_type_item = NULL; int32 i = 0; int8 evt_type[128]; listener_dest_info_t *tmp; result = json_array(); if (result == NULL) { HTTPD_ERR("result json object request fail\n"); return NULL; } while (header) { jitem = json_object(); json_object_add(jitem, RMM_JSON_RF_LINKS, json_string(header->dest)); evt_type_item = json_array(); for (i = 0; i < header->evt_index; i++) { memset(evt_type, 0, 128); get_event_type_by_nodeid(header->event_types[i], evt_type, sizeof(evt_type)); json_array_add(evt_type_item, json_string(evt_type)); } json_object_add(jitem, RMM_JSON_RF_EVT_TYPES, evt_type_item); json_array_add(result, jitem); tmp = header->pnext; free(header); header = tmp; } return result; }
void pack_rf_evt_links(json_t *result, rf_link_t *link) { int32 i = 0; json_t *array = NULL; json_t *listener = NULL; array = json_array(); if (array == NULL) { HTTPD_ERR("json array request fail\n"); return; } for (i = 0; i < RF_EVENT_MAX_LISTENER_NUM; i++) { listener = NULL; listener = json_object(); if (listener != NULL) { if (strlen(link->subscription[i]) != 0) { add_json_string(listener, RMM_JSON_RF_LISTENER, (uint8 *)(link->subscription[i])); json_array_add(array, listener); } } } json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, array); add_json_string(result, RMM_JSON_RF_SELF, (uint8 *)link->self); }
static json_t *tzone_coll_get(struct rest_uri_param *param) { collections_t *tzone_collections = NULL; uint32 tzone_num = 0; result_t rs = RESULT_OK; json_t *result = NULL; json_t *tzone = NULL; json_t *array = NULL; int32 i; int32 zone_num = 0; zone_num = libwrap_get_asset_num(MC_TYPE_TZONE); if (zone_num == 0) { HTTPD_ERR("get thermal zone num fail\n"); return NULL; } tzone_collections = (collections_t *)malloc(zone_num * sizeof(collections_t)); if (tzone_collections == NULL) return NULL; memset(tzone_collections, 0, zone_num * sizeof(collections_t)); rs = libwrap_get_tzone_coll(tzone_collections, &tzone_num); if (rs != RESULT_OK) { HTTPD_ERR("get cooling zone collection fail, result is %d\n", rs); return NULL; } result = json_object(); if (result == NULL) { HTTPD_ERR("result json object request error\n"); return NULL; } array = json_array(); if (array == NULL) { HTTPD_ERR("json array request error\n"); return NULL; } for (i = 0; i < tzone_num; i++) { tzone = NULL; tzone = json_object(); if (tzone != NULL) { add_json_integer(tzone, RMM_JSON_ID, tzone_collections[i].id); add_json_string(tzone, RMM_JSON_UUID, tzone_collections[i].uuid); add_json_string(tzone, RMM_JSON_NAME, tzone_collections[i].name); update_href_host(tzone_collections[i].href, HREF_URL_LEN, param->host); add_json_string(tzone, RMM_JSON_HREF, tzone_collections[i].href); json_array_add(array, tzone); } } json_object_add(result, RMM_JSON_THERMAL_ZONES, array); if (tzone_collections) free(tzone_collections); return result; }
int32 evt_listeners_pack_json(json_t *result, evt_listeners_t *listeners) { json_t *listener_array = NULL; json_t * listener = NULL; int32 i = 0; json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(listeners->odata_context)); json_object_add(result, RMM_JSON_ODATA_TYPE, json_string(listeners->odata_type)); json_object_add(result, RMM_JSON_NAME, json_string(listeners->name)); json_object_add(result, RMM_JSON_MEMBERS_ODATA_COUNT, json_integer(listeners->num)); listener_array = json_array(); if (listener_array == NULL) { HTTPD_ERR("json array request fail\n"); return -1; } for (i = 0; i < listeners->num; i++) { listener = json_object(); if (listener == NULL) { HTTPD_ERR("json object request fail\n"); return -1; } json_object_add(listener, RMM_JSON_ODATA_ID, json_string(listeners->url[i])); json_array_add(listener_array, listener); } json_object_add(result, RMM_JSON_MEMBERS, listener_array); return 0; }
static void table_print_json__(const struct table *table, const struct table_style *style) { struct json *json, *headings, *data; size_t x, y; char *s; json = json_object_create(); if (table->caption) { json_object_put_string(json, "caption", table->caption); } if (table->timestamp) { char *s = table_format_timestamp__(); json_object_put_string(json, "time", s); free(s); } headings = json_array_create_empty(); for (x = 0; x < table->n_columns; x++) { const struct column *column = &table->columns[x]; json_array_add(headings, json_string_create(column->heading)); } json_object_put(json, "headings", headings); data = json_array_create_empty(); for (y = 0; y < table->n_rows; y++) { struct json *row = json_array_create_empty(); for (x = 0; x < table->n_columns; x++) { const struct cell *cell = table_cell__(table, y, x); if (cell->text) { json_array_add(row, json_string_create(cell->text)); } else if (cell->json) { json_array_add(row, json_clone(cell->json)); } else { json_array_add(row, json_null_create()); } } json_array_add(data, row); } json_object_put(json, "data", data); s = json_to_string(json, style->json_flags); json_destroy(json); puts(s); free(s); }
static int32 fan_add_property(json_t *threshold, json_t *property, int32 value, const int8 *name) { property = NULL; property = json_object(); if (property != NULL) { add_json_integer(property, name, value); json_array_add(threshold, property); } return 0; }
int32 rf_evt_pack_json(json_t *result, const int32 *evt_types, rf_evt_svc_t *service) { int32 i = 0; json_t *types_array = NULL; json_t *listener = NULL; json_t *status = NULL; json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(service->links.odata_context)); json_object_add(result, RMM_JSON_ODATA_ID, json_string(service->links.odata_id)); add_json_string(result, RMM_JSON_ODATA_TYPE, service->fixed.odata_type); add_json_string(result, RMM_JSON_RF_ID, service->fixed.id); add_json_string(result, RMM_JSON_RF_NAME, service->fixed.name); status = json_object(); if (status != NULL) { add_json_string(status, RMM_JSON_RF_STATUS_STATE, service->fixed.status.state); add_json_string(status, RMM_JSON_RF_STATUS_HEALTH, service->fixed.status.health); } json_object_add(result, RMM_JSON_RF_STATUS, status); if (service->fixed.service_enabled) json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_true()); else json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_false()); add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY, service->fixed.retry); add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY_INTERVAL, service->fixed.retry_interval); types_array = json_array(); if (types_array == NULL) return -1; for (i = 0; i < MAX_EVT_ACTION_NUM; i++) { if (evt_types[i] == 0) continue; json_array_add(types_array, json_string((int8 *)rf_evt_msg[i].type_name)); } json_object_add(result, RMM_JSON_RF_SUPPORTED_EVT_TYPES, types_array); listener = json_object(); if (listener == NULL) return -1; add_json_string(listener, RMM_JSON_ODATA_ID, service->links.subscriptions); json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, listener); return 0; }
int32 evt_listener_pack_json(json_t *result, evt_listener_t *listener) { int8 evt_type[128] = {}; int32 i = 0; json_t *evt_type_item = NULL; if (strnlen_s(listener->url, sizeof(listener->url)-1) == 0) { HTTPD_ERR("invalid subscribe destination\n"); return -1; } json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(listener->odata_context)); json_object_add(result, RMM_JSON_ODATA_ID, json_string(listener->odata_id)); json_object_add(result, RMM_JSON_ODATA_TYPE, json_string(listener->odata_type)); json_object_add(result, RMM_JSON_RF_ID, json_string(listener->id)); json_object_add(result, RMM_JSON_RF_NAME, json_string(listener->name)); json_object_add(result, RMM_JSON_RF_DESC, json_string(listener->description)); json_object_add(result, RMM_JSON_RF_DEST_URL, json_string(listener->url)); evt_type_item = json_array(); if (evt_type_item == NULL) { HTTPD_ERR("json array request fail\n"); return -1; } for (i = 0; i < listener->evt_index; i++) { memset(evt_type, 0, sizeof(evt_type)); get_event_type_by_node_type(listener->event_types[i], evt_type, sizeof(evt_type)); if (strnlen_s(evt_type, sizeof(evt_type)-1) != 0) json_array_add(evt_type_item, json_string(evt_type)); } json_object_add(result, RMM_JSON_RF_EVT_TYPES, evt_type_item); json_object_add(result, RMM_JSON_RF_CONTEXT, json_string(listener->context)); json_object_add(result, RMM_JSON_RF_PROTOCOL, json_string(listener->protocol)); return 0; }
struct json * ovsdb_execute(struct ovsdb *db, const struct ovsdb_session *session, const struct json *params, long long int elapsed_msec, long long int *timeout_msec) { struct ovsdb_execution x; struct ovsdb_error *error; struct json *results; size_t n_operations; size_t i; if (params->type != JSON_ARRAY || !params->u.array.n || params->u.array.elems[0]->type != JSON_STRING || strcmp(params->u.array.elems[0]->u.string, db->schema->name)) { if (params->type != JSON_ARRAY) { error = ovsdb_syntax_error(params, NULL, "array expected"); } else { error = ovsdb_syntax_error(params, NULL, "database name expected " "as first parameter"); } results = ovsdb_error_to_json(error); ovsdb_error_destroy(error); return results; } x.db = db; x.session = session; x.txn = ovsdb_txn_create(db); x.symtab = ovsdb_symbol_table_create(); x.durable = false; x.elapsed_msec = elapsed_msec; x.timeout_msec = LLONG_MAX; results = NULL; results = json_array_create_empty(); n_operations = params->u.array.n - 1; error = NULL; for (i = 1; i <= n_operations; i++) { struct json *operation = params->u.array.elems[i]; struct ovsdb_error *parse_error; struct ovsdb_parser parser; struct json *result; const struct json *op; /* Parse and execute operation. */ ovsdb_parser_init(&parser, operation, "ovsdb operation %"PRIuSIZE" of %"PRIuSIZE, i, n_operations); op = ovsdb_parser_member(&parser, "op", OP_ID); result = json_object_create(); if (op) { const char *op_name = json_string(op); ovsdb_operation_executor *executor = lookup_executor(op_name); if (executor) { error = executor(&x, &parser, result); } else { ovsdb_parser_raise_error(&parser, "No operation \"%s\"", op_name); } } else { ovs_assert(ovsdb_parser_has_error(&parser)); } /* A parse error overrides any other error. * An error overrides any other result. */ parse_error = ovsdb_parser_finish(&parser); if (parse_error) { ovsdb_error_destroy(error); error = parse_error; } if (error) { json_destroy(result); result = ovsdb_error_to_json(error); } if (error && !strcmp(ovsdb_error_get_tag(error), "not supported") && timeout_msec) { ovsdb_txn_abort(x.txn); *timeout_msec = x.timeout_msec; json_destroy(result); json_destroy(results); results = NULL; goto exit; } /* Add result to array. */ json_array_add(results, result); if (error) { break; } } if (!error) { error = ovsdb_txn_commit(x.txn, x.durable); if (error) { json_array_add(results, ovsdb_error_to_json(error)); } } else { ovsdb_txn_abort(x.txn); } while (json_array(results)->n < n_operations) { json_array_add(results, json_null_create()); } exit: ovsdb_error_destroy(error); ovsdb_symbol_table_destroy(x.symtab); return results; }
static json_t *mbp_get(struct rest_uri_param *param) { int32 idx = 0; result_t rs = RESULT_OK; json_t *result = NULL; json_t *fru = NULL; json_t *av_action = NULL; json_t *rs_json = NULL; json_t *cap = NULL; mbp_member_t mbp_member = { {0} }; json_t *loc = NULL; idx = get_asset_idx(param, "mbp_id", MC_TYPE_CM); if (idx == -1) { HTTPD_ERR("get mbp index fail\n"); return NULL; } rs = libwrap_get_mbp_by_idx(idx, &mbp_member); if (rs != RESULT_OK) { HTTPD_ERR("get mbp info fail, result is %d\n", rs); return NULL; } result = json_object(); if (result == NULL) { HTTPD_ERR("result json object request fail\n"); return NULL; } pack_mbp_basic_info(&mbp_member, result); loc = json_object(); if (loc == NULL) { HTTPD_ERR("loc json object request fail\n"); return NULL; } add_loc_info(loc, (int32)mbp_member.loc.units, RMM_JSON_RACK_UNITS); add_loc_info(loc, mbp_member.loc.u_location, RMM_JSON_ULOC); add_loc_info(loc, mbp_member.loc.u_height, RMM_JSON_UHEIGHT); add_loc_info(loc, mbp_member.loc.x_location, RMM_JSON_XLOC); json_object_add(result, RMM_JSON_RACK_LOC, loc); add_json_string(result, RMM_JSON_ASSET_TAG, mbp_member.asset.asset_tag); fru = json_object(); if (fru != NULL) { pack_fru_info(&(mbp_member.asset.fru), fru); json_object_add(result, RMM_JSON_FRU_INFO, fru); } av_action = json_array(); if (av_action == NULL) { HTTPD_ERR("available action array request fail\n"); return NULL; } /* action reset */ json_t *action = NULL; action = json_object(); if (0 != prepare_get_action(mbp_member.av_action, action, 0)) { HTTPD_ERR("action prepare fail\n"); return NULL; } cap = json_array(); if (cap != NULL) { json_t *property = NULL; json_t *allow_values = NULL; allow_values = json_array(); /* soft reset */ property = json_object(); if ((property != NULL) && (allow_values != NULL)) { if (0 != strcmp((int8 *)(mbp_member.av_action[0].cap[0].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[0].cap[0].property))); json_array_add(allow_values, json_string((int8 *)(mbp_member.av_action[0].cap[0].av))); } json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values); json_array_add(cap, property); } json_object_add(action, RMM_JSON_CAPABILITIES, cap); } json_array_add(av_action, action); /* action SetUartTarget */ action = NULL; action = json_object(); if (0 != prepare_get_action(mbp_member.av_action, action, 1)) { HTTPD_ERR("action prepare fail\n"); return NULL; } cap = NULL; cap = json_array(); if (cap != NULL) { json_t *property = NULL; /* targetIndex */ property = json_object(); if (property != NULL) { if (0 != strcmp((int8 *)(mbp_member.av_action[1].cap[0].property), "")) json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[1].cap[0].property))); json_array_add(cap, property); } json_object_add(action, RMM_JSON_CAPABILITIES, cap); } json_array_add(av_action, action); /* action Update */ action = NULL; action = json_object(); if (prepare_get_action(mbp_member.av_action, action, 2)) { HTTPD_ERR("action prepare fail\n"); return NULL; } cap = NULL; cap = json_array(); if (cap != NULL) { json_t *property = NULL; property = json_object(); if (property != NULL) { if (0 != strcmp((int8 *)(mbp_member.av_action[2].cap[0].property), "")) json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[2].cap[0].property))); json_array_add(cap, property); } json_object_add(action, RMM_JSON_CAPABILITIES, cap); } json_array_add(av_action, action); json_object_add(result, RMM_JSON_AVALIBLE_ACTIONS, av_action); return result; }
static json_t *mbp_coll_get(struct rest_uri_param *param) { collections_t *mbp_collections = NULL; uint32 mbp_num = 0; int32 i; int32 cm_num = 0; result_t rs = RESULT_OK; json_t *result = NULL; json_t *array = NULL; json_t *sub_mbp = NULL; cm_num = libwrap_get_asset_num(MC_TYPE_CM); if (cm_num == 0) { HTTPD_ERR("get mbp num fail\n"); return NULL; } mbp_collections = (collections_t *)malloc(cm_num * sizeof(collections_t)); if (mbp_collections == NULL) return NULL; memset(mbp_collections, 0, cm_num * sizeof(collections_t)); rs = libwrap_get_mbp_coll(mbp_collections, &mbp_num); if (rs != RESULT_OK) { HTTPD_ERR("get mbp coll info fail, result is %d\n", rs); return NULL; } result = json_object(); if (result == NULL) { HTTPD_ERR("result json object request fail\n"); return NULL; } array = json_array(); if (array == NULL) { HTTPD_ERR("json array request fail\n"); return NULL; } for (i = 0; i < mbp_num; i++) { sub_mbp = NULL; sub_mbp = json_object(); if (sub_mbp == NULL) { HTTPD_ERR("sub mbp json object request fail\n"); return NULL; } add_json_integer(sub_mbp, RMM_JSON_ID, mbp_collections[i].id); add_json_string(sub_mbp, RMM_JSON_UUID, mbp_collections[i].uuid); add_json_string(sub_mbp, RMM_JSON_NAME, mbp_collections[i].name); update_href_host(mbp_collections[i].href, HREF_URL_LEN, param->host); add_json_string(sub_mbp, RMM_JSON_HREF, mbp_collections[i].href); json_array_add(array, sub_mbp); } json_object_add(result, RMM_JSON_MBPS, array); if (mbp_collections) free(mbp_collections); return result; }
int gami_register_req(gami_reg_t *reg_info) { jrpc_req_pkg_t req_pkg = {}; json_t *cap_array = NULL; json_t *cap = NULL; int i = 0; int rc; int64 ip = reg_info->ip_addr; int64 port = reg_info->port; printf("gami_register, name %s, ip %d, port %d.\n", reg_info->name, reg_info->ip_addr, reg_info->port); fill_param(&req_pkg, JRPC_GAMI_REG_NAME, reg_info->name, JSON_STRING); fill_param(&req_pkg, JRPC_GAMI_REG_IP, &ip, JSON_INTEGER); fill_param(&req_pkg, JRPC_GAMI_REG_PORT, &port, JSON_INTEGER); /*mbp*/ cap_array = json_array(); if (cap_array == NULL) { return -1; } for (i = 0; i < GAMI_MAX_CAP_NUM; i++) { if (strlen((char *)reg_info->capability.cap_mbp[i]) != 0) { cap = NULL; cap = json_object(); if (cap == NULL) { return -1; } add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_mbp[i]); json_array_add(cap_array, cap); } } fill_param(&req_pkg, JRPC_GAMI_REG_CAP_MBP, cap_array, JSON_ARRAY); /*psu*/ cap_array = json_array(); if (cap_array == NULL) { return -1; } for (i = 0; i < GAMI_MAX_CAP_NUM; i++) { if (strlen((char *)reg_info->capability.cap_psu[i]) != 0) { cap = NULL; cap = json_object(); if (cap == NULL) { return -1; } add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_psu[i]); json_array_add(cap_array, cap); } } fill_param(&req_pkg, JRPC_GAMI_REG_CAP_PSU, cap_array, JSON_ARRAY); /*fan*/ cap_array = json_array(); if (cap_array == NULL) { return -1; } for (i = 0; i < GAMI_MAX_CAP_NUM; i++) { if (strlen((char *)reg_info->capability.cap_fan[i]) != 0) { cap = NULL; cap = json_object(); if (cap == NULL) { return -1; } add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_fan[i]); json_array_add(cap_array, cap); } } fill_param(&req_pkg, JRPC_GAMI_REG_CAP_FAN, cap_array, JSON_ARRAY); /*drawer*/ cap_array = json_array(); if (cap_array == NULL) { return -1; } for (i = 0; i < GAMI_MAX_CAP_NUM; i++) { if (strlen((char *)reg_info->capability.cap_drawer[i]) != 0) { cap = NULL; cap = json_object(); if (cap == NULL) { return -1; } add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_drawer[i]); json_array_add(cap_array, cap); } } fill_param(&req_pkg, JRPC_GAMI_REG_CAP_DRAWER, cap_array, JSON_ARRAY); rc = send_msg_to_registerd(&req_pkg, REG_APP); return rc; }
static json_t *fan_get(struct rest_uri_param *param) { fan_member_t fan_member = { {0} }; result_t rs = RESULT_OK; json_t *result = NULL; json_t *threshold = NULL; json_t *av_action = NULL; json_t *fru = NULL; json_t *property = NULL; json_t *action = NULL; json_t *cap = NULL; int32 tzone_idx = 0, fan_idx = 0; json_t *loc = NULL; tzone_idx = get_asset_idx(param, "zone_id", MC_TYPE_TZONE); if (tzone_idx == -1) { HTTPD_ERR("get cooling zone index fail\n"); return NULL; } fan_idx = get_asset_idx(param, "fan_id", MC_TYPE_FAN); if (fan_idx == -1) { HTTPD_ERR("get fan index fail\n"); return NULL; } rs = libwrap_get_tzone_fan_by_idx(tzone_idx, fan_idx, &fan_member); if (rs != RESULT_OK) { HTTPD_ERR("get fan fail, result is %d\n", rs); return NULL; } result = json_object(); if (result == NULL) { HTTPD_ERR("result json object request fail\n"); return NULL; } pack_fan_basic_info(&fan_member, result); loc = json_object(); if (loc != NULL) { add_loc_info(loc, (int32)fan_member.fan_loc.units, RMM_JSON_RACK_UNITS); add_loc_info(loc, fan_member.fan_loc.u_location, RMM_JSON_ULOC); add_loc_info(loc, fan_member.fan_loc.u_height, RMM_JSON_UHEIGHT); add_loc_info(loc, fan_member.fan_loc.x_location, RMM_JSON_XLOC); } json_object_add(result, RMM_JSON_RACK_LOC, loc); threshold = NULL; threshold = json_array(); if (threshold == NULL) { HTTPD_ERR("threshold array request error\n"); return NULL; } fan_add_property(threshold, property, fan_member.tachometer.threshold.lower_non_critical, RMM_JSON_LOWER_NON_CRITICAL); fan_add_property(threshold, property, fan_member.tachometer.threshold.upper_non_critical, RMM_JSON_UPPER_NON_CRITICAL); fan_add_property(threshold, property, fan_member.tachometer.threshold.lower_critical, RMM_JSON_LOWER_CRITICAL); fan_add_property(threshold, property, fan_member.tachometer.threshold.upper_critical, RMM_JSON_UPPER_CRITICAL); json_object_add(result, RMM_JSON_THRESHOLD, threshold); add_json_string(result, RMM_JSON_PRESENCE, fan_member.presence); add_json_string(result, RMM_JSON_ASSET_TAG, fan_member.asset.asset_tag); add_json_integer(result, RMM_JSON_SPEED_UNIT, fan_member.speed_unit);// 0--PWM, 1---RPM fru = json_object(); if (fru != NULL) { pack_fru_info(&(fan_member.asset.fru), fru); json_object_add(result, RMM_JSON_FRU_INFO, fru); } av_action = json_array(); if (av_action == NULL) { HTTPD_ERR("available action array request fail\n"); return NULL; } /* requestStateChange */ action = json_object(); if (0 != prepare_get_action(fan_member.av_action, action, 0)) { HTTPD_ERR("action prepare fail\n"); return NULL; } cap = json_array(); if (cap != NULL) { json_t *property = NULL; json_t *allow_values = NULL; allow_values = json_array(); property = json_object(); if ((property != NULL) && (allow_values != NULL)) { if (0 != strcmp((int8 *)(fan_member.av_action[0].cap[0].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[0].cap[0].property))); json_array_add(allow_values, json_integer(str2int((int8 *)fan_member.av_action[0].cap[0].av))); } } property = NULL; property = json_object(); if ((property != NULL) && (allow_values != NULL)) { if (0 != strcmp((int8 *)(fan_member.av_action[0].cap[1].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[0].cap[1].property))); json_array_add(allow_values, json_integer(str2int((int8 *)fan_member.av_action[0].cap[1].av))); } } json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values); json_array_add(cap, property); json_object_add(action, RMM_JSON_CAPABILITIES, cap); } json_array_add(av_action, action); /* SetDesiredSpeed */ action = NULL; action = json_object(); if (0 != prepare_get_action(fan_member.av_action, action, 1)) { HTTPD_ERR("action prepare fail\n"); return NULL; } cap = NULL; cap = json_array(); if (cap != NULL) { json_t *property = NULL; json_t *allow_values = NULL; allow_values = json_array(); property = json_object(); if ((property != NULL) && (allow_values != NULL)) { if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[0].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[0].property))); json_array_add(allow_values, json_string((int8 *)(fan_member.av_action[1].cap[0].av))); } if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[1].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[1].property))); json_array_add(allow_values, json_string((int8 *)(fan_member.av_action[1].cap[1].av))); } json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values); json_array_add(cap, property); } property = NULL; property = json_object(); if (property != NULL) { if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[2].property), "")) { json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[2].property))); json_array_add(cap, property); } } json_object_add(action, RMM_JSON_CAPABILITIES, cap); } json_array_add(av_action, action); json_object_add(result, RMM_JSON_AVALIBLE_ACTIONS, av_action); return result; }
static json_t *fan_coll_get(struct rest_uri_param *param) { collections_t *tzone_fan_coll = NULL; uint32 fan_num = 0; int8 *p_tzone_id = NULL; result_t rs = RESULT_OK; json_t *result = NULL; json_t *fan = NULL; json_t *array = NULL; int32 tzone_idx = 0; int32 i; tzone_fan_coll = (collections_t *)malloc(MAX_PWM_NUM * sizeof(collections_t)); if (tzone_fan_coll == NULL) return NULL; memset(tzone_fan_coll, 0, MAX_PWM_NUM * sizeof(collections_t)); tzone_idx = get_asset_idx(param, "zone_id", MC_TYPE_TZONE); if (tzone_idx == -1) { HTTPD_ERR("get cooling zone index fail\n"); return NULL; } rs = libwrap_get_tzone_fan_coll(tzone_idx, tzone_fan_coll, &fan_num); if (rs != RESULT_OK) { HTTPD_ERR("get fan collection fail, result is %d\n", rs); return NULL; } result = json_object(); if (result == NULL) { HTTPD_ERR("result json object request fail\n"); return NULL; } array = json_array(); if (array == NULL) { HTTPD_ERR("json array request fail\n"); return NULL; } for (i = 0; i < fan_num; i++) { fan = NULL; fan = json_object(); if (NULL != fan) { add_json_integer(fan, RMM_JSON_ID, tzone_fan_coll[i].id); add_json_string(fan, RMM_JSON_UUID, tzone_fan_coll[i].uuid); add_json_string(fan, RMM_JSON_NAME, tzone_fan_coll[i].name); update_href_host(tzone_fan_coll[i].href, HREF_URL_LEN, param->host); add_json_string(fan, RMM_JSON_HREF, tzone_fan_coll[i].href); json_array_add(array, fan); } } json_object_add(result, RMM_JSON_FANS, array); if (tzone_fan_coll) free(tzone_fan_coll); return result; }