/* ------------------------------------------------------------------------- */ int Reg_Get(Reg_TRegistry* reg, const ezxml_t keys, ezxml_t items) { ezxml_t key; assert(reg); key = keys->child; if (key) { do { ezxml_t item; if ((item = ezxml_child(reg->m_root, ezxml_txt(key))) && ezxml_name(item)) { ezxml_t child = ezxml_add_child_d(items, ezxml_name(item), 0); ezxml_set_txt_d(child, ezxml_txt(item)); } } while((key = key->ordered)); } else { ezxml_t item = reg->m_root->child; while(item) { ezxml_t child = ezxml_add_child_d(items, ezxml_name(item), 0); ezxml_set_txt_d(child, ezxml_txt(item)); item = item->ordered; } } return -EXIT_SUCCESS; }
/* ------------------------------------------------------------------------- */ static ezxml_t CreateTestMessage() { ezxml_t message = ezxml_new("status"); { ezxml_t node = ezxml_add_child_d(message, "temperature", 0); ezxml_set_txt_d(node, "10"); } { ezxml_t node = ezxml_add_child_d(message, "humidity", 0); ezxml_set_txt_d(node, "13"); } return message; }
/* ------------------------------------------------------------------------- */ int Reg_Update(Reg_TRegistry* reg, const ezxml_t items) { ezxml_t new_item; assert(reg); /* sanity check */ if (!(new_item = items->child)) return -EXIT_SUCCESS; while(new_item) { if ('\0' == ezxml_txt(new_item)[0]) return -EXIT_FAILURE; new_item = new_item->ordered; } /* update */ new_item = items->child; while(new_item) { ezxml_t existing_item; if ((existing_item = ezxml_child(reg->m_root, ezxml_name(new_item)))) ezxml_set_txt_d(existing_item, ezxml_txt(new_item)); else { ezxml_t n = ezxml_add_child_d(reg->m_root, ezxml_name(new_item), 0); ezxml_set_txt_d(n, ezxml_txt(new_item)); } ezxml_remove(new_item); new_item = items->child; } if (reg->m_file_name) Reg_ExportToFile(reg, reg->m_file_name); return -EXIT_SUCCESS; }
static int user_list_xml(USRM_I_KNOW_U_t* i_m, ezxml_t xml_root, lpINI_PARSER ini_list) { int i = 0; int ret = 0; ezxml_t list_node = NULL; ezxml_t user_node = NULL; char str_val[32] = {""}; int const user_count = ini_list->read_int(ini_list, "OPTION", "user", 0); APP_ASSERT(user_count > 0, "Why there is no user"); // xml root node list_node = ezxml_add_child_d(xml_root, "user_list", 0); // user list node // attribute count sprintf(str_val, "%d", user_count); ezxml_set_attr_d(list_node, "count", str_val); // attribute backlog sprintf(str_val, "%d", USR_MANGER_USER_HOURSE_BACKLOG); ezxml_set_attr_d(list_node, "backlog", str_val); for(i = 0; NULL != i_m && i < user_count && i < USR_MANGER_USER_HOURSE_BACKLOG; ++i){ char user_section[32] = {""}; char user_node_name[32] = {""}; char his_name[32] = {""}; char *can_del_user, *can_edit_user, *can_set_pass; bool his_is_admin; char buf[1024] = {""}; sprintf(user_section, "USER%d", i); sprintf(user_node_name, "user%d", i); //APP_TRACE("Reading section [%s]", user_section); user_node = ezxml_add_child_d(list_node, user_node_name, i); // add user child to list strncpy(his_name, ini_list->read_text(ini_list, user_section, "name", "", buf, sizeof(buf)), ARRAY_ITEM(his_name)); his_is_admin = ini_list->read_bool(ini_list, user_section, "admin", false); ezxml_set_attr_d(user_node, "name", his_name); ezxml_set_attr_d(user_node, "admin", ini_list->read_bool(ini_list, user_section, "admin", false) ? "yes" : "no"); ezxml_set_attr_d(user_node, "permit_live", ini_list->read_bool(ini_list, user_section, "permit_live", false) ? "yes" : "no"); ezxml_set_attr_d(user_node, "permit_setting", ini_list->read_bool(ini_list, user_section, "permit_setting", false) ? "yes" : "no"); ezxml_set_attr_d(user_node, "permit_playback", ini_list->read_bool(ini_list, user_section, "permit_playback", false) ? "yes" : "no"); // 1. only admin and not user himself could be deleted can_del_user = "******"; if(i_m->is_admin && !STR_CASE_THE_SAME(i_m->username, his_name)){ can_del_user = "******"; } // 2. only admin to edit not admin, and not user himself can_edit_user = "******"; if(i_m->is_admin && !his_is_admin && !STR_CASE_THE_SAME(i_m->username, his_name)){ can_edit_user = "******"; } // 3. only user himself could set his own password can_set_pass = STR_CASE_THE_SAME(i_m->username, his_name) ? "yes" : "no"; // 4. add attributes ezxml_set_attr_d(user_node, "del_user", can_del_user); ezxml_set_attr_d(user_node, "edit_user", can_edit_user); ezxml_set_attr_d(user_node, "set_pass", can_set_pass); } return 0; }