void extensiongroups_remove_save(void) { int size,ret_value=0,iserror=0; char name[STRING_LENGTH]={"bb1"}; //与之关联的结构定义 struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL; cgiFormString("name",name,STRING_LENGTH); /******************************参数检查*****************************/ if(strlen(name) < STRING_LITTLE_LENGTH){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size); if ( NULL == httpdirpolicys){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //HTTPS_DIR策略检查 ret_value = httpdir_policy_name_check(httpdirpolicys, name, name, 1); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } /*************************释放内存,调用保存函数*************************/ ret_value = groups_remove_save(MGTCGI_TYPE_EXTENSION_GROUP,name); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&httpdirpolicys); return; }
void extensions_list_show(void) { int size=0,index=0,index_end=0; char page_str[DIGITAL_LENGTH]; char pagesize_str[DIGITAL_LENGTH]; int total=0,iserror=0,result=0; struct mgtcgi_xml_extensions *extensions = NULL; cgiFormString("page",page_str,STRING_LENGTH); cgiFormString("pagesize",pagesize_str,STRING_LENGTH); get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&extensions,&size); if ( NULL == extensions){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } total = extensions->num; result = get_page_turn_index(page_str, pagesize_str, total, &index, &index_end); if (result != 0){ iserror = result; goto ERROR_EXIT; } printf("{\"data\":["); for (; index < index_end ;){ printf("{\"name\":\"%s\",\"value\":\"%s\",\"comment\":\"%s\"}",\ extensions->pinfo[index].name,extensions->pinfo[index].value,extensions->pinfo[index].comment); index++; if (index < index_end) printf(","); else break; } printf("],\"total\":%d,\"iserror\":0,\"msg\":\"\"}",total); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&extensions); return; }
void extensions_edit_show(void) { int size=0,index=0,iserror=0; char name[STRING_LENGTH]; struct mgtcgi_xml_extensions *extensions = NULL; cgiFormString("name",name,STRING_LENGTH); if (strlen(name) < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&extensions,&size); if ( NULL == extensions){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } printf("{\"data\":["); for (index = 0; index < extensions->num ; index++){ if (strcmp(name,extensions->pinfo[index].name) == 0){ printf("{\"name\":\"%s\",\"comment\":\"%s\"}",\ extensions->pinfo[index].name,extensions->pinfo[index].comment); break; } } printf("],\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&extensions); return; }
void extensiongroups_edit_save(void) { int size,index=0,ret_value=0,add_includ_num=0; int diff_name=0,iserror=0; char old_name[STRING_LENGTH]={"bb"}; char name[STRING_LENGTH]={"bb1"}; //char value[STRING_LIST_LENGTH]={"exe,txt"}; char * value=NULL; char *dot=","; //char str[STRING_LIST_LENGTH]; char *str = NULL; char *ptr; struct mgtcgi_xml_extensions *obj_nodes = NULL; //与之关联的结构定义 struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL; value = (char *) malloc(STRING_LIST_LENGTH*sizeof(char)); if(!value) goto ERROR_EXIT; cgiFormString("old_name",old_name,STRING_LENGTH); cgiFormString("name",name,STRING_LENGTH); cgiFormString("value",value,STRING_LIST_LENGTH*sizeof(char)); /******************************参数检查*****************************/ if((strlen(name) < STRING_LITTLE_LENGTH) || (strlen(old_name) < STRING_LITTLE_LENGTH) || (strlen(value) < STRING_LITTLE_LENGTH)){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } add_includ_num = check_list_string_dot(value, dot); if (add_includ_num < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } /******************************重复性检查*****************************/ get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&obj_nodes,&size); if ( NULL == obj_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } str = (char *) malloc(STRING_LIST_LENGTH*sizeof(char)); if(!str) goto ERROR_EXIT; //value检查,必须是对象存在的名称。 strcpy(str, value); ptr=strtok(str,dot); if (NULL != ptr){ for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, ptr)) break; } if (index == obj_nodes->num){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } while((ptr=strtok(NULL,dot))){ if (NULL != ptr){ for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, ptr)) break; } if (index == obj_nodes->num){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } } if (strcmp(name, old_name) == 0){ diff_name = 0;//名称没有被修改 } else { diff_name = 1; //名称修改了,检测是否重复 //不能与对象名重名 for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } } if (1 == diff_name){ get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size); if ( NULL == httpdirpolicys){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //HTTPS_DIR策略检查 ret_value = httpdir_policy_name_check(httpdirpolicys, name, old_name, 1); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } }//end if(1 == diff_name) free(str); str = NULL; /*************************释放内存,调用保存函数*************************/ ret_value = groups_edit_save(MGTCGI_TYPE_EXTENSION_GROUP, add_includ_num, diff_name, name, old_name, value, ""); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&obj_nodes); free_xml_node((void*)&httpdirpolicys); if(value) free(value); if(str) free(str); return; }
void extensiongroups_add_save(void) { int size,index=0,add_includ_num=0,iserror=0; char name[STRING_LENGTH]={"test"}; //char value[STRING_LIST_LENGTH]={"aa,bb,cc"}; char * value = NULL; char *dot=","; //char str[STRING_LIST_LENGTH]; char *str = NULL; char *ptr; struct mgtcgi_xml_extensions *obj_nodes = NULL; value = (char *)malloc(STRING_LIST_LENGTH*sizeof(char)); if(!value) goto ERROR_EXIT; cgiFormString("name",name,STRING_LENGTH); cgiFormString("value",value,STRING_LIST_LENGTH*sizeof(char)); /******************************参数检查*****************************/ if((strlen(name) < STRING_LITTLE_LENGTH) || (strlen(value) < STRING_LITTLE_LENGTH)){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } add_includ_num = check_list_string_dot(value, dot); if (add_includ_num < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } /******************************重复性检查*****************************/ get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&obj_nodes,&size); if ( NULL == obj_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //不能与对象名重名 for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } str = (char *) malloc(STRING_LIST_LENGTH*sizeof(char)); if(!str) goto ERROR_EXIT; //value检查,必须是对象存在的名称。 strcpy(str, value); ptr=strtok(str,dot); if (NULL != ptr){ for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, ptr)) break; } if (index == obj_nodes->num){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } while((ptr=strtok(NULL,dot))){ if (NULL != ptr){ for (index=0; index < obj_nodes->num; index++){ if (0 == strcmp(obj_nodes->pinfo[index].name, ptr)) break; } if (index == obj_nodes->num){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } } free(str); str = NULL; /************************释放内存,调用修改xml文件函数*************************/ groups_add_save(MGTCGI_TYPE_EXTENSION_GROUP, add_includ_num, name, value, ""); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&obj_nodes); if(value) free(value); if(str) free(str); return; }
void extensiongroups_edit_show(void) { int size=0,index=0,left=0,i=0; int flag,use_flag=0,iserror=0; char name[STRING_LENGTH]; struct mgtcgi_xml_extensions * extensions = NULL; struct mgtcgi_xml_group_array * group = NULL; cgiFormString("name",name,STRING_LENGTH); if (strlen(name) < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&extensions,&size); if ( NULL == extensions){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } flag = 0; printf("{\"data\":[{\"name\":\"%s\"}],\"left_list\":[",name); for (left=0; left < extensions->num; left++){ use_flag = 0; for (index=0; index < group->num; index++){ for (i=0; i < group->pinfo[index].num; i++){ if (strcmp(group->pinfo[index].pinfo[i].name, extensions->pinfo[left].name) == 0){ use_flag = 1; break; } } if (use_flag == 1) break; } if (use_flag == 0){ if (flag == 0){ printf("\"%s\"",extensions->pinfo[left].name); flag = 1; } else { printf(",\"%s\"",extensions->pinfo[left].name); } } } printf("],"); printf("\"right_list\":["); for (index=0; index < group->num; index++){ flag = 0; if (strcmp(group->pinfo[index].group_name, name) == 0){ for(i=0; i < group->pinfo[index].num; i++){ if (flag == 0) { printf("\"%s\"",group->pinfo[index].pinfo[i].name); flag = 1; } else { printf(",\"%s\"",group->pinfo[index].pinfo[i].name); } } break; } } printf("],\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&extensions); free_xml_node((void*)&group); return; }
void extensions_remove_save(void) { int old_size,size,index=0,result=0; int ret_value=0,iserror=0; int remove_num,old_num,new_num,new_size,new_index; char name[STRING_LENGTH]={"aa1"}; struct mgtcgi_xml_extensions *old_nodes = NULL; struct mgtcgi_xml_extensions *new_nodes = NULL; //与对象关联的结构定义 struct mgtcgi_xml_group_array *group = NULL; //对象组 struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL; cgiFormString("name",name,STRING_LENGTH); /******************************参数检查*****************************/ if(strlen(name) < STRING_LITTLE_LENGTH){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&old_nodes,&old_size); if ( NULL == old_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } if (old_nodes->num < 1){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } remove_num = -1; for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, name)){ remove_num = index; break; } } if (!((-1 != remove_num) && (remove_num < old_nodes->num))){//没有找到要删除的条目 iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } //如果名称修改了,检查是否重复和检查是否正在使用 get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size); if ( NULL == httpdirpolicys){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //对象组检查 ret_value = group_name_check(group, name, name); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else if (2 == ret_value){ ; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } //HTTPS_DIR策略检查 ret_value = httpdir_policy_name_check(httpdirpolicys, name, name, 1); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } /***********************可以删除,构建新结构***************************************/ old_num = old_nodes->num; new_num = old_num - 1; if (new_num < 0) new_num = 0; old_size = sizeof(struct mgtcgi_xml_extensions) + old_num * sizeof(struct mgtcgi_xml_extension_info); new_size = sizeof(struct mgtcgi_xml_extensions) + new_num * sizeof(struct mgtcgi_xml_extension_info); new_nodes = (struct mgtcgi_xml_extensions *)malloc_buf(new_size); if (NULL == new_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } new_nodes->num = new_num; for (index=0,new_index=0; index < old_nodes->num; index++){ if ((remove_num != index) && (new_index < new_nodes->num)){ strcpy(new_nodes->pinfo[new_index].name, old_nodes->pinfo[index].name); strcpy(new_nodes->pinfo[new_index].value, old_nodes->pinfo[index].value); strcpy(new_nodes->pinfo[new_index].comment, old_nodes->pinfo[index].comment); new_index++; } } if (new_index == new_nodes->num){ result = save_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSIONS,(void*)new_nodes, new_size); if (result < 0){ iserror = MGTCGI_WRITE_FILE_ERR; goto ERROR_EXIT; } } else { iserror = MGTCGI_NO_TARGET_ERR; goto ERROR_EXIT; } #if _MGTCGI_DEBUG_GET_ for (index=0; index < new_nodes->num; index++){ printf("new_nodes->pinfo[%d].name:%s\n",index,old_nodes->pinfo[index].name); printf("new_nodes->pinfo[%d].value:%s\n",index,old_nodes->pinfo[index].value); printf("new_nodes->pinfo[%d].comment:%s\n",index,old_nodes->pinfo[index].comment); } #endif /**************************成功,释放内存***************************/ printf("{\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&old_nodes); free_malloc_buf((void*)&new_nodes); free_xml_node((void*)&group); free_xml_node((void*)&httpdirpolicys); return; }
void extensions_edit_save(void) { int old_size,size,index=0,result=0; int diff_name=0,ret_value=0,iserror=0; char old_name[STRING_LENGTH]={"aa"}; char name[STRING_LENGTH]={"aa1"}; char value[STRING_LENGTH]={"rar"}; char comment[STRING_LENGTH]={"tt"}; struct mgtcgi_xml_extensions *old_nodes = NULL; //与对象关联的结构定义 struct mgtcgi_xml_group_array *group = NULL; //对象组 struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL; cgiFormString("old_name",old_name,STRING_LENGTH); cgiFormString("name",name,STRING_LENGTH); cgiFormString("value",value,DIGITAL_LENGTH); cgiFormString("comment",comment,DIGITAL_LENGTH); /******************************参数检查*****************************/ if((strlen(name) < STRING_LITTLE_LENGTH) || (strlen(old_name) < STRING_LITTLE_LENGTH) || (strlen(value) < STRING_LITTLE_LENGTH)){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&old_nodes,&old_size); if ( NULL == old_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } if (strcmp(name, old_name) == 0){ diff_name = 0; //名称没有被修改 } else { //名称修改了,检测是否重复 diff_name = 1; for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } } if (1 == diff_name){//如果名称修改了,检查是否重复和检查是否正在使用 get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size); if ( NULL == httpdirpolicys){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } //对象组检查 ret_value = group_name_check(group, name, old_name); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else if (2 == ret_value){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } //HTTPS_DIR策略检查 ret_value = httpdir_policy_name_check(httpdirpolicys, name, old_name, 1); if (0 != ret_value){ if (1 == ret_value){ iserror = MGTCGI_USED_ERR; goto ERROR_EXIT; } else{ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } } }//end if(1 == diff_name) /*********************************修改数据***********************************/ iserror = -1; for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, old_name)){ strcpy(old_nodes->pinfo[index].name, name); strcpy(old_nodes->pinfo[index].value, value); strcpy(old_nodes->pinfo[index].comment, comment); result = save_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSIONS,(void*)old_nodes, old_size); if (result < 0){ iserror = MGTCGI_WRITE_FILE_ERR; goto ERROR_EXIT; } iserror = 0; break; } } if (iserror != 0){ iserror = MGTCGI_NO_TARGET_ERR; goto ERROR_EXIT; } #if _MGTCGI_DEBUG_GET_ for (index=0; index < new_nodes->num; index++){ printf("new_nodes->pinfo[%d].name:%s\n",index,old_nodes->pinfo[index].name); printf("new_nodes->pinfo[%d].value:%s\n",index,old_nodes->pinfo[index].value); printf("new_nodes->pinfo[%d].comment:%s\n",index,old_nodes->pinfo[index].comment); } #endif /**************************成功,释放内存***************************/ printf("{\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&old_nodes); free_xml_node((void*)&group); free_xml_node((void*)&httpdirpolicys); return; }
void extensions_add_save(void) { int old_size,new_size,index=0,size,iserror=0,result=0; char name[STRING_LENGTH]={"1"}; char value[STRING_LENGTH]={"10000"}; char comment[STRING_LENGTH]; struct mgtcgi_xml_extensions *old_nodes = NULL; struct mgtcgi_xml_extensions *new_nodes = NULL; struct mgtcgi_xml_group_array * group = NULL; cgiFormString("name",name,STRING_LENGTH); cgiFormString("value",value,DIGITAL_LENGTH); cgiFormString("comment",comment,DIGITAL_LENGTH); /******************************参数检查*****************************/ if((strlen(name) < STRING_LITTLE_LENGTH) || (strlen(value) < STRING_LITTLE_LENGTH)){ iserror = MGTCGI_PARAM_ERR; goto ERROR_EXIT; } /******************************重复性检查*****************************/ get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&old_nodes,&old_size); if ( NULL == old_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSION_GROUP,(void**)&group,&size); if ( NULL == group){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } for (index=0; index < old_nodes->num; index++){ if (0 == strcmp(old_nodes->pinfo[index].name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } for (index=0; index < group->num; index++){ if (0 == strcmp(group->pinfo[index].group_name, name)){ iserror = MGTCGI_DUPLICATE_ERR; goto ERROR_EXIT; } } /****************************重新构建新结构***************************/ old_size = sizeof(struct mgtcgi_xml_extensions) + old_nodes->num * sizeof(struct mgtcgi_xml_extension_info); new_size = sizeof(struct mgtcgi_xml_extensions) + (old_nodes->num + 1) * sizeof(struct mgtcgi_xml_extension_info); new_nodes = (struct mgtcgi_xml_extensions *)malloc_buf(new_size); if (NULL == new_nodes){ iserror = MGTCGI_READ_FILE_ERR; goto ERROR_EXIT; } memcpy(new_nodes, old_nodes, old_size); new_nodes->num = old_nodes->num + 1; strcpy(new_nodes->pinfo[old_nodes->num].name, name); strcpy(new_nodes->pinfo[old_nodes->num].value, value); strcpy(new_nodes->pinfo[old_nodes->num].comment, comment); #if _MGTCGI_DEBUG_GET_ for (index=0; index < new_nodes->num; index++){ printf("new_nodes->pinfo[%d].name:%s\n",index,new_nodes->pinfo[index].name); printf("new_nodes->pinfo[%d].value:%s\n",index,new_nodes->pinfo[index].value); printf("new_nodes->pinfo[%d].comment:%s\n",index,new_nodes->pinfo[index].comment); } #endif result = save_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_EXTENSIONS,(void*)new_nodes, new_size); if (result < 0){ iserror = MGTCGI_WRITE_FILE_ERR; goto ERROR_EXIT; } /**************************成功,释放内存***************************/ printf("{\"iserror\":0,\"msg\":\"\"}"); goto FREE_EXIT; ERROR_EXIT: printf("{\"iserror\":%d,\"msg\":\"\"}",iserror); goto FREE_EXIT; FREE_EXIT: free_xml_node((void*)&group); free_xml_node((void*)&old_nodes); free_malloc_buf((void*)&new_nodes); return; }
bool xml_istream::process() { stack<string> tag_stack; stack< map<string, string> > attribute_stack; bool ok = true; while (ok != false && good() != false) { string tag, cdata, doctype, s; map<string, string> attributes; xml_t t = get_xml_node(s, tag, attributes); switch (t) { case OPEN_TAG: tag_stack.push(tag); attribute_stack.push(attributes); break; case EMPTY_TAG: { callback pFunc = _callback_map[tag]; if (pFunc != NULL) { pFunc(s, attributes); } } break; case CLOSE_TAG: if (tag_stack.size() > 0 && tag_stack.top() == tag) /* Ensure opening tag matches the closing tag. */ { tag_stack.pop(); attribute_stack.pop(); } else { ok = false; } break; case TEXT: if (s.empty() == false && tag_stack.size() > 0) { callback pFunc = _callback_map[tag_stack.top()]; if (pFunc != NULL) { if (_entity_translation != false) { string ts; entity_translation(s, ts); s = ts; } if (_collapse_whitespace != false) { string ts; collapse_whitespace(s, ts); s = ts; } pFunc(s, attribute_stack.top()); } } else { ok = false; } break; case CDATA: ok = parse_cdata(s, cdata); if (cdata.empty() == false && tag_stack.size() > 0) { callback pFunc = _callback_map[tag_stack.top()]; if (pFunc != NULL) { pFunc(cdata, attribute_stack.top()); } } else { ok = false; } break; case UNKNOWN: ok = false; break; } } if (tag_stack.size() != 0 || attribute_stack.size() != 0) { ok = false; } return ok; }