modify.c
来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 1,375 行 · 第 1/3 页
C
1,375 行
#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/quipu/uips/doog/query/RCS/modify.c,v 9.0 1992/06/16 12:45:27 isode Rel $";#endif/* $Header: /xtel/isode/isode/others/quipu/uips/doog/query/RCS/modify.c,v 9.0 1992/06/16 12:45:27 isode Rel $ *//***************************************************************************** modify.c - Modify entry attributes.*****************************************************************************/#include "types.h"#include "util.h"#include "read.h"#include "modify.h"#include "request.h"#include "ds_tasks.h"#include "quipu/common.h"#include "quipu/entry.h"#include "quipu/modify.h"#include "quipu/name.h"#include "quipu/util.h"#include "quipu/dap2.h"#include "quipu/attrvalue.h"#include "quipu/photo.h"#define AS_SYNTAX(attrSeq) attrSeq->attr_type->oa_syntax#define AS_STROID(attrSeq) attrSeq->attr_type->oa_ot.ot_stroidextern int dsap_ad;extern int next_task_id;extern void get_read_attrs();#ifndef NO_STATSextern LLog *log_stat;#endifstatic errorList start_modify();static struct entrymod * ems_append();static void get_template_attrs();static modifyAttr remove_common_attrs(), remove_double_attrs();extern QE_error_code start_read();/* * Start of procedures for entry modification requests. * * *//* * - get_modify_result() - * * */modifyResult get_modify_result(request_id) QCardinal request_id;{ requestRec request = _get_request_of_id(request_id); modifyRec modrec; modifyResult result; if (request == NULLReqRec) return NULLModifyResult; modrec = request->MODIFY_REC; result = modrec->result; modrec->result = NULLModifyResult; _request_complete(request_id); return result;} /* get_modify_result *//* * - do_modify() - * * */errorList do_modify(baseobject, id_ptr, mod_attr_list) char *baseobject; QCardinal *id_ptr; modifyAttr mod_attr_list;{ modifyRec modify_request; requestRec this_request; (void) _request_invoked(MODIFY_ENTRY, id_ptr); this_request = _get_request_of_id(*id_ptr); modify_request = this_request->MODIFY_REC; modify_request->request_id = *id_ptr; modify_request->base_object = copy_string(baseobject); return start_modify(*id_ptr, baseobject, mod_attr_list, &modify_request->task_id);} /* do_modify *//* * - start_modify() - * * */static errorList start_modify(request_id, baseobject, mod_attr_list, task_id_ptr) QCardinal request_id; char *baseobject; modifyAttr mod_attr_list; int *task_id_ptr;{ int task_id; struct ds_modifyentry_arg mod_arg; struct DAPindication di; struct entrymod *curr_mod = (struct entrymod *) NULL, *entrymods = (struct entrymod *) NULL; char err_msg[LINESIZE]; errorList error; modifyAttr curr_attr = mod_attr_list; modifyValue curr_val; AttributeType curr_type = NULLAttrT; AttributeValue attr_val = (AttributeValue) NULL; AV_Sequence attrVal_seq = (AV_Sequence) NULL; /* Quipu procedures */ int avs_free(), as_free(); for (curr_attr = mod_attr_list; curr_attr != NULLModifyAttr; curr_attr = curr_attr->next) { if (curr_attr->to_modify) { QCardinal val_count = 0, /* Number of existing values */ delete_count = 0, /* Number of values to delete */ new_count = 0; /* Number of values that need adding */ curr_type = curr_attr->attr_type;/* * Check the modification status of this attribute. * */ for (curr_val = curr_attr->values; curr_val != NULLModifyValue; curr_val = curr_val->next) { switch (curr_val->status) { case updated: new_count++; delete_count++; val_count++; break; case deleted: delete_count++; val_count++; break; case new: new_count++; break; default: val_count++; } } curr_mod = em_alloc(); curr_mod->em_next = NULLMOD; curr_mod->em_what = NULL; curr_mod->em_type = 127;/* * If * i) There are NO values to add, and * ii) There are existing values, and * iii) All existing values are marked for deletion. * Then * Delete the attribute. */ if (new_count == 0 && val_count > 0 && val_count == delete_count) { curr_mod->em_type = EM_REMOVEATTRIBUTE; curr_mod->em_what = as_comp_new(curr_attr->attr_type, NULLAV, NULLACL_INFO); }/* * Else if * i) There are values to add, and * ii) There are no existing values. * Then * Add a new attribute with given values. */ else if (new_count > 0 && val_count == 0) { curr_mod->em_type = EM_ADDATTRIBUTE; for (curr_val = curr_attr->values; curr_val != NULLModifyValue; curr_val = curr_val->next) { attr_val = str2AttrV(curr_val->new_value, curr_type->oa_syntax); if (attr_val != NULLAttrV) { if (attrVal_seq != NULLAV) attrVal_seq = avs_merge(attrVal_seq, avs_comp_new(attr_val)); else attrVal_seq = avs_comp_new(attr_val); } else /* Attribute value has an inappropriate syntax! */ { if (entrymods) ems_free(entrymods); if (attrVal_seq != NULLAV) avs_free(attrVal_seq); (void) sprintf (err_msg, "*** Bad Value `%s' in Attribute `%s' ***", curr_val->new_value, attr2name(curr_attr->attr_type, OIDPART)); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_bad_value_syntax; error->ds_message = copy_string(err_msg); return error; } } /* Add value list to entrymods */ curr_mod->em_what = as_comp_new(curr_attr->attr_type, attrVal_seq, NULLACL_INFO); }/* * Else if * i) There are existing values to be deleted * Then * i) Remove marked values * ii) Check if any new values are given. */ else if (delete_count > 0) { curr_mod->em_type = EM_REMOVEVALUES; for (curr_val = curr_attr->values; curr_val != NULLModifyValue; curr_val = curr_val->next) { if (curr_val->status == updated || curr_val->status == deleted) { attr_val = str2AttrV(curr_val->value, curr_type->oa_syntax); if (attr_val != NULLAttrV) { if (attrVal_seq != NULLAV) attrVal_seq = avs_merge(attrVal_seq, avs_comp_new(attr_val)); else attrVal_seq = avs_comp_new(attr_val); } else /* Attribute value has an inappropriate syntax! */ { if (entrymods) ems_free(entrymods); if (attrVal_seq != NULLAV) avs_free(attrVal_seq); (void) sprintf (err_msg, "*** Bad Value `%s' in Attribute `%s' ***", curr_val->new_value, attr2name(curr_attr->attr_type, OIDPART)); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_bad_value_syntax; error->ds_message = copy_string(err_msg); return error; } } } curr_mod->em_what = as_comp_new(curr_attr->attr_type, attrVal_seq, NULLACL_INFO); attrVal_seq = NULLAV;/* * Check if there are any new values to replace the ones just deleted. */ if (new_count > 0) { entrymods = ems_append(entrymods, curr_mod); curr_mod = em_alloc(); curr_mod->em_next = NULLMOD; curr_mod->em_type = EM_ADDVALUES; for (curr_val = curr_attr->values; curr_val != NULLModifyValue; curr_val = curr_val->next) { if (curr_val->status == updated || curr_val->status == new) { attr_val = str2AttrV(curr_val->new_value, curr_type->oa_syntax); if (attr_val != NULLAttrV) { if (attrVal_seq != NULLAV) attrVal_seq = avs_merge(attrVal_seq, avs_comp_new(attr_val)); else attrVal_seq = avs_comp_new(attr_val); } else /* Value has an inappropriate syntax! */ { if (entrymods) ems_free(entrymods); ems_free(curr_mod); if (attrVal_seq != NULLAV) avs_free(attrVal_seq); (void) sprintf (err_msg, "*** Bad Value `%s' in Attribute `%s' ***", curr_val->new_value, attr2name(curr_attr->attr_type, OIDPART)); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_bad_value_syntax; error->ds_message = copy_string(err_msg); return error; } } } if (attrVal_seq == NULLAV) { if (entrymods) ems_free(entrymods); ems_free(curr_mod); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_internal; error->ds_message = NULLCP; return error; } else curr_mod->em_what = as_comp_new(curr_attr->attr_type, attrVal_seq, NULLACL_INFO); } } else if (new_count > 0) { curr_mod->em_type = EM_ADDVALUES; for (curr_val = curr_attr->values; curr_val != NULLModifyValue; curr_val = curr_val->next) { if (curr_val->status == new) { attr_val = str2AttrV(curr_val->new_value, curr_type->oa_syntax); if (attr_val != NULLAttrV) { if (attrVal_seq != NULLAV) attrVal_seq = avs_merge(attrVal_seq, avs_comp_new(attr_val)); else attrVal_seq = avs_comp_new(attr_val); } else /* Value has an inappropriate syntax! */ { if (entrymods) ems_free(entrymods); ems_free(curr_mod); if (attrVal_seq != NULLAV) avs_free(attrVal_seq); (void) sprintf (err_msg, "*** Bad Value `%s' in Attribute `%s' ***", curr_val->new_value, attr2name(curr_attr->attr_type, OIDPART)); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_bad_value_syntax; error->ds_message = copy_string(err_msg); return error; } } } if (attrVal_seq == NULLAV) { if (entrymods) ems_free(entrymods); ems_free(curr_mod); error = error_alloc(); error->next = NULLError; error->baseobject = NULLCP; error->error_type = QERR_internal; error->ds_message = NULLCP; return error; } else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?