ufsearch.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 1,325 行 · 第 1/3 页

C
1,325
字号
#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/quipu/uips/doog/query/RCS/ufsearch.c,v 9.0 1992/06/16 12:45:27 isode Rel $";#endif/* $Header: /xtel/isode/isode/others/quipu/uips/doog/query/RCS/ufsearch.c,v 9.0 1992/06/16 12:45:27 isode Rel $ *//*****************************************************************************    ufsearch.c -*****************************************************************************/#include "types.h"#include "util.h"#include "ufsearch.h"#include "ditmodel.h"#include "ds_tasks.h"#include "request.h"#include "ds_util.h"#include "read.h"#include "quipu/ds_search.h"#include "quipu/dap2.h"#include "quipu/name.h"extern int dsap_ad;extern int next_task_id;extern ufsPath ufs_paths;#ifndef NO_STATSextern LLog    *log_stat;#endifstatic QE_error_code process_ufsearch();static QE_error_code do_directory_search();static QE_error_code follow_up();char *TidyString();/* * - do_ufsearch() - * Start a user friendly search. The 'search_data' list is taken (not copied) * by the proc. * */QE_error_code do_ufsearch(target_data, search_data, baselist, id_ptr)     searchPair target_data;     searchPair search_data;     entryList baselist;     QCardinal *id_ptr;{  requestRec request;  ufsearchRec ufsrec;  searchPair curr_srch_data;  QBool have_co = FALSE,        have_org = FALSE,        have_loc = FALSE;  AttributeType co_type, org_type, ou_type, loc_type, curr_type, per_type;  /* Record request invocation */  (void) _request_invoked(UFSEARCH, id_ptr);  request = _get_request_of_id(*id_ptr);  ufsrec = request->UFSEARCH_REC;  ufsrec->target_data = target_data;  ufsrec->search_data = search_data;  /* ### Ignore given base path for the moment ### */  co_type = AttrT_new("2.5.6.2");  org_type = AttrT_new("2.5.6.4");  ou_type = AttrT_new("2.5.6.5");  loc_type = AttrT_new("2.5.6.3");  per_type = AttrT_new("2.5.6.6");  /* Check for country attribute */  for (curr_srch_data = search_data;       curr_srch_data != NULLSearchPair;       curr_srch_data = curr_srch_data->next)    {      curr_type = curr_srch_data->type;            if (curr_type == co_type)	{	  have_co = TRUE;	  continue;	}      if (curr_type == loc_type)	{	  have_loc = TRUE;	  continue;	}        if (curr_type == org_type)	{	  have_org = TRUE;	  continue;	}      if (curr_type == ou_type)	continue;    }  if (target_data->type == per_type || target_data->type == ou_type)    {      if (have_co == FALSE)	{	  if (have_org == FALSE && have_loc == FALSE)	    {	      dn_list_copy(get_default_path(org_type), &ufsrec->path);	    }	  else	    {	      dn_list_copy(get_default_path(co_type), &ufsrec->path);	    }	  	  if (ufsrec->path != NULLEntryList)	    {	      ufsrec->to_follow = ufsrec->path;	      ufsrec->path = ufsrec->path->next;	      	      ufsrec->to_follow->next = NULLEntryList;	    }	  else	    ufsrec->to_follow = baselist;	}      else	{	  if (have_org == FALSE && have_loc == FALSE)	    return QERR_request_failed;	  	  ufsrec->to_follow = baselist;	}    }  else if (target_data->type == org_type)    {      if (have_co == FALSE)	dn_list_copy(get_default_path(co_type), &ufsrec->path);            if (ufsrec->path != NULLEntryList)	{	  ufsrec->to_follow = ufsrec->path;	  ufsrec->path = ufsrec->path->next;	  	  ufsrec->to_follow->next = NULLEntryList;	}      else	ufsrec->to_follow = baselist;    }  return process_ufsearch(ufsrec);} /* do_ufsearch *//* * - process_ufsearch() - * * */static QE_error_code process_ufsearch(ufsrec)     ufsearchRec ufsrec;{  entryList to_follow;  register objectTypeList curr_type, child_types;  QCardinal succeeded = 0;  /* If ds searches outstanding, then do nothing. */  if (ufsrec->exact_task_count > 0 || ufsrec->approx_task_count > 0)    return QERR_ok;  if (ufsrec->trying_target_search == TRUE)    {      ufsrec->tried_target_search = TRUE;      ufsrec->trying_target_search = FALSE;            ufsrec->to_follow = ufsrec->followed;      ufsrec->followed = NULLEntryList;    }  /* Check if attempt to search for target is valid */  if (ufsrec->tried_target_search == FALSE)    {      for (to_follow = ufsrec->to_follow;	   to_follow != NULLEntryList;	   to_follow = to_follow->next)	{	  child_types = get_child_list(to_follow->object_class);	  for (curr_type = child_types;	       curr_type != NULLObjectType;	       curr_type = curr_type->next)	    if (qy_in_hierarchy		(name2oc(ufsrec->target_data->type->oa_ot.ot_stroid),		 name2oc(curr_type->object_type->oa_ot.ot_stroid)))	      {		ufsrec->trying_target_search = TRUE;		if (follow_up(to_follow, ufsrec) == QERR_ok) succeeded++;				break;	      }	}            if (ufsrec->trying_target_search == TRUE)	{	  if (succeeded == 0)	    return QERR_bad_value_syntax;	  else	    {	      ufsrec->followed = ufsrec->to_follow;	      ufsrec->to_follow = NULLEntryList;	    }	  	  return QERR_ok;	}    }  else    ufsrec->tried_target_search = FALSE;  /* Doing an intermediate search */  /* For each that needs to be followed up */  for (to_follow = ufsrec->to_follow;       to_follow != NULLEntryList;       to_follow = to_follow->next)    if (follow_up(to_follow, ufsrec) == QERR_ok) succeeded++;  /* If trying a search for the target then don't remove list in case     search fails to hit and further intermediate searches are required */  dn_list_free(&ufsrec->to_follow);  if (succeeded == 0)     return QERR_bad_value_syntax;  ufsrec->followed = ufsrec->to_follow = NULLEntryList;  return QERR_ok;} /* process_ufsearch *//* * - follow_up() - * * */static QE_error_code follow_up(baseinfo, ufsrec)     entryList baseinfo;     ufsearchRec ufsrec;{  AttributeType base_type;  objectTypeList search_types, child_types, curr_type;  searchPair search_vals = NULLSearchPair,                 curr_val = NULLSearchPair,                 search_on = NULLSearchPair;  stringCell curr_str_val;  QCardinal search_val_count = 0;  QE_error_code return_status;  char *objectname;  objectname = baseinfo->string_dn;  for (search_vals = ufsrec->search_data;       search_vals != NULLSearchPair;       search_vals = search_vals->next)    {      search_vals->checked = FALSE;      search_val_count++;    }  if (ufsrec->trying_target_search == TRUE)    { /* Searching for target */      for (search_types = get_search_attrs(ufsrec->target_data->type);	   search_types != NULLObjectType;	   search_types = search_types->next)	{	  search_on = search_pair_alloc();	  search_on->type = search_types->object_type;	  search_on->values = NULLStrCell;	  search_on->next = NULLSearchPair;	  	  for (curr_str_val = ufsrec->target_data->values;	       curr_str_val != NULLStrCell;	       curr_str_val = curr_str_val->next)	    add_string_to_seq(curr_str_val->string, &search_on->values);	}      return_status = do_directory_search(objectname, search_on, ufsrec);    }  else /* Searching for intermediate entry */    {      base_type = baseinfo->object_class;      child_types = get_child_list(base_type);            for (curr_type = child_types;	   curr_type != NULLObjectType && search_val_count > 0;	   curr_type = curr_type->next)	{	  for (search_vals = ufsrec->search_data;	       search_vals != NULLSearchPair && search_val_count > 0;	       search_vals = search_vals->next)	    if (search_vals->checked == FALSE &&		search_vals->type == curr_type->object_type)	      {		search_vals->checked = TRUE;		search_val_count--;	      }	}            for (search_vals = ufsrec->search_data, search_on = NULLSearchPair;	   search_vals != NULLSearchPair;	   search_vals = search_vals->next)	if (search_vals->checked == TRUE)	  {	    for (search_types = get_search_attrs(search_vals->type);		 search_types != NULLObjectType;		 search_types = search_types->next)	      {		curr_val = search_pair_alloc();		curr_val->next = search_on;		search_on = curr_val;				search_on->type = search_types->object_type;		search_on->values = NULLStrCell;				for (curr_str_val = search_vals->values;		     curr_str_val != NULLStrCell;		     curr_str_val = curr_str_val->next)		  add_string_to_seq(curr_str_val->string, &curr_val->values);				search_on->use_subtree = TRUE;	      }	  }            if (search_on != NULLSearchPair)	return_status = do_directory_search(objectname, search_on, ufsrec);      else 	return_status = QERR_request_failed;    }    while (search_on != NULLSearchPair)    {      curr_val = search_on->next;      free_string_seq(&search_on->values);      free((char *) search_on);      search_on = curr_val;    }  return return_status;} /* follow_up *//* * - do_directory_search() - * * */static QE_error_code do_directory_search(baseobject, search_vals, ufsrec)     char *baseobject;     searchPair search_vals;     ufsearchRec ufsrec;{  struct ds_search_arg search_arg;  struct DAPindication di;  DN base_dn;  char *start, *end;  QCardinal level_count;  Filter exact_filter, *exfilt_ptr, tmp_ex_filt,         approx_filter, *apfilt_ptr, tmp_ap_filt;  Attr_Sequence get_attrs = NULLATTR;  searchPair curr_val_list;  stringCell curr_val;  int task_id, count;  char valbuf[1024];  valbuf[0] = '\0';  /* Make a DN struct from given string object name.     If not valid then return an error. */  if (baseobject == NULLCP || isnull(*baseobject)) base_dn = NULLDN;  else if ((base_dn = str2dn(baseobject)) == NULLDN) return QERR_bad_name;  /* `Analyse' the string dn. */  start = baseobject;  level_count = 0;  if (base_dn != NULLDN)    while ((end = index(start, '=')) != NULLCP)      {	level_count++;	start = ++end;      }  (void) get_default_service(&search_arg.sra_common);  search_arg.sra_common.ca_servicecontrol.svc_options =    search_arg.sra_common.ca_servicecontrol.svc_options | SVC_OPT_PREFERCHAIN;  search_arg.sra_common.ca_servicecontrol.svc_timelimit = SVC_NOTIMELIMIT;  search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 10;  search_arg.sra_baseobject = base_dn;  /* Don't want any attributes back. */  search_arg.sra_eis.eis_allattributes = FALSE;  /* Approx search will ask for some attributes back */  search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;  search_arg.sra_searchaliases = TRUE;  /* Want objectClasss back */  get_attrs = as_comp_new(AttrT_new("2.5.4.0"), NULLAV, NULLACL_INFO);  exact_filter = filter_alloc();  approx_filter = filter_alloc();  if (search_vals->next != NULLSearchPair ||      search_vals->values->next != NULLStrCell)    {      approx_filter->flt_next = exact_filter->flt_next = NULLFILTER;      exact_filter->flt_type = approx_filter->flt_type = FILTER_OR;            for (curr_val_list = search_vals,	   apfilt_ptr = &approx_filter->FUFILT,	   exfilt_ptr = &exact_filter->FUFILT;	   curr_val_list != NULLSearchPair;	   curr_val_list = curr_val_list->next)	{	  if (curr_val_list != search_vals)	    {	      tmp_ap_filt = *apfilt_ptr;	      apfilt_ptr = &tmp_ap_filt->flt_next;	      	      tmp_ex_filt = *exfilt_ptr;	      exfilt_ptr = &tmp_ex_filt->flt_next;	    }	  	  for (curr_val = curr_val_list->values;	       curr_val != NULLStrCell;	       curr_val = curr_val->next)	    {	      if (curr_val != curr_val_list->values)		{		  tmp_ap_filt = *apfilt_ptr;		  apfilt_ptr = &tmp_ap_filt->flt_next;		  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?