Esempio n. 1
0
static void add_suggestion(rb_tree *suggs, string word){
  if(!(rb_lookup(suggs, &word))){
    DEBUG_PRINTF("adding suggestion %.*s\n", (int)word.len, word.str);
    string *ptr = xmalloc(sizeof(string) + word.sz);
    ptr->sz = word.sz; ptr->mem = (((void*)ptr)+sizeof(string));
    memcpy(ptr->mem, word.mem, word.sz);
    rb_insert(suggs, ptr);
  }
}
Esempio n. 2
0
void * rblookup(const void *low,const void *high, struct rbtree *rbinfo) {
  struct rbnode *x;

  /* If we have a NULL root (empty tree) then just return NULL */
  if (rbinfo==NULL || rbinfo->rb_root==NULL)
    return(NULL);
  
  x=rb_lookup(low, high, rbinfo);
  
  return((x==RBNULL) ? NULL : x->object);
}
Esempio n. 3
0
struct pair rbfind(const void *low,const void *high, struct rbtree *rbinfo) {
  struct rbnode *x;
  struct pair p;
  /* If we have a NULL root (empty tree) then just return NULL */

  p.low=NULL;
  p.high=NULL;
  if (rbinfo==NULL || rbinfo->rb_root==NULL)
    return p;
  
  x=rb_lookup(low, high, rbinfo);
  if (x!=NULL) {
    p.low=x->key;
    p.high=x->high;
  }
  return p;
}
Esempio n. 4
0
void *rb_get(struct rb_tree *t, void *key)
{
  struct rb_tree_node *n = rb_lookup(t, key);
  if (n) return n->value;
  return NULL;
}
Esempio n. 5
0
int rb_contains(struct rb_tree *t, void *key)
{
  return rb_lookup(t, key) != NULL;
}
Esempio n. 6
0
extern  cms_entry_res *
cms_update_entry_5_svc(cms_update_args *args, struct svc_req *svcrq)
{
	static cms_entry_res	res;
	_DtCmsCalendar		*cal;
	cms_entry		*newentry;
	caddr_t			event;
	char			*user;
	uint			access, needaccess;
	Appt_4			*appt = NULL;

	if (debug)
		fprintf(stderr, "cms_update_entry_5_svc called\n");

	if (res.entry != NULL) {
		res.entry->num_attrs--;
		_DtCm_free_cms_entry(res.entry);
		res.entry = NULL;
	}

	if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
	    &access, &cal)) != CSA_SUCCESS)
		return (&res);

	if ((cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
	    !_DTCMS_HAS_CHANGE_ACCESS(access)) ||
	    (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
	    !_DTCMS_HAS_V4_WRITE_ACCESS(access))) {
		res.stat = CSA_E_NO_AUTHORITY;
		return (&res);
	}

	/* check argument */
	if (args->cal == NULL || args->entry.id <= 0 || args->num_attrs == 0) {
		res.stat = CSA_E_INVALID_PARAMETER;
		return (&res);
	}

	if (args->scope < CSA_SCOPE_ALL || args->scope > CSA_SCOPE_FORWARD) {
		res.stat = CSA_E_INVALID_ENUM;
		return (&res);
	}

	/* check validity of attribute values */
	if ((res.stat = _DtCm_check_entry_cms_attributes(
	    (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
	    cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1),
	    args->num_attrs, args->attrs, CSA_CB_ENTRY_UPDATED, B_TRUE))
	    != CSA_SUCCESS)
		return (&res);

	/* get event from one-time event tree */
	event = (caddr_t)rb_lookup(cal->tree, (caddr_t)&args->entry);

	/* update entry and log it */
	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
		if (event != NULL || args->scope == CSA_SCOPE_ALL) {
			res.stat = _DtCmsUpdateEntry(cal, user, access,
					&args->entry, args->num_attrs,
					args->attrs, NULL, &newentry);
		} else {
			res.stat = _DtCmsUpdateInstances(cal, user, access,
					&args->entry, args->scope,
					args->num_attrs, args->attrs, NULL,
					&newentry);
		}
	} else {
		Options_4	opt;

		if (event != NULL || args->scope == CSA_SCOPE_ALL)
			opt = do_all_4;
		else
			opt = (args->scope == CSA_SCOPE_ONE) ?
				do_one_4 : do_forward_4;

		if (event == NULL && (event = hc_lookup(cal->list,
		    (caddr_t)&args->entry)) == NULL) {

			res.stat = CSA_X_DT_E_ENTRY_NOT_FOUND;

		} else if ((appt = _DtCm_copy_one_appt4((Appt_4 *)event))
		    == NULL) {

			res.stat = CSA_E_INSUFFICIENT_MEMORY; 

		} else {
			/* get rid of exceptions */
			_DtCm_free_excpt4(appt->exception);
			appt->exception = NULL;

			if ((res.stat = _DtCmsAttrsToAppt4(args->num_attrs,
			    args->attrs, appt, B_TRUE)) == CSA_SUCCESS) {

				if (opt == do_all_4)
					res.stat = _DtCmsChangeAll(cal, user,
						access, (Id_4 *)&args->entry,
						appt, NULL);
				else
					res.stat = _DtCmsChangeSome(cal, user,
						access, (Id_4 *)&args->entry,
						appt, opt, NULL);

			}
		}
	}

	if (res.stat == CSA_SUCCESS)
		cal->modified = B_TRUE;
	else
		return (&res);

	/* do callback */
	cal->rlist = _DtCmsDoV1CbForV4Data(cal->rlist, user, args->pid,
			&args->entry,
			(appt ? (cms_key *)&appt->appt_id : &newentry->key));

	cal->rlist = _DtCmsDoUpdateEntryCallback(cal->rlist, cal->calendar,
			user, (appt ? appt->appt_id.key : newentry->key.id),
			args->entry.id, args->scope, args->entry.time,
			args->pid);

	/* reply */
	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ||
	    (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
	    (res.stat = _DtCmsAppt4ToCmsentriesForClient(cal->calendar, appt,
	    &newentry)) == CSA_SUCCESS)) {

		res.stat = _DtCmsGetCmsEntryForClient(newentry, &res.entry, B_FALSE);

		_DtCm_free_cms_entry(newentry);
	}

	return (&res);
}
Esempio n. 7
0
extern  CSA_return_code *
cms_delete_entry_5_svc(cms_delete_args *args, struct svc_req *svcrq)
{
	static CSA_return_code	res;
	_DtCmsCalendar		*cal;
	caddr_t			event;
	char			*user;
	uint			access, needaccess;

	if (debug)
		fprintf(stderr, "cms_delete_entry_5_svc called\n");

	if ((res = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
	    &access, &cal)) != CSA_SUCCESS)
		return (&res);

	/* for v3 data, authority check is done in the routines doing the
	 * deletion since we may need to check the organizer
	 */
	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
	    !_DTCMS_HAS_CHANGE_ACCESS(access)) {
		res = CSA_E_NO_AUTHORITY;
		return (&res);
	}

	/* check argument */
	if (args->cal == NULL || args->entry.id <= 0) {
		res = CSA_E_INVALID_PARAMETER;
		return (&res);
	}

	if (args->scope < CSA_SCOPE_ALL || args->scope > CSA_SCOPE_FORWARD) {
		res = CSA_E_INVALID_ENUM;
		return (&res);
	}


	/* get event from one-time event tree */
	event = (caddr_t)rb_lookup(cal->tree, (caddr_t)&args->entry);

	/* delete entry and log it */
	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
		if (event != NULL || args->scope == CSA_SCOPE_ALL) {
			res = _DtCmsDeleteEntryAndLog(cal, user, access,
				&args->entry, NULL);
		} else {
			res = _DtCmsDeleteInstancesAndLog(cal, user, access,
				&args->entry, args->scope, NULL, NULL);
		}
	} else {
		if (event != NULL || args->scope == CSA_SCOPE_ALL) {
			res = _DtCmsDeleteApptAndLog(cal, user, access,
				(Id_4 *)&args->entry, NULL);
		} else {
			res = _DtCmsDeleteApptInstancesAndLog(cal, user, access,
				(Id_4 *)&args->entry,
				((args->scope == CSA_SCOPE_ONE) ? do_one_4 :
				do_forward_4), NULL, NULL);
		}
	}

	if (res == CSA_SUCCESS)
		cal->modified = B_TRUE;
	else
		return (&res);

	/* do callback */
	cal->rlist = _DtCmsDoV1CbForV4Data(cal->rlist, user, args->pid,
			&args->entry, NULL);

	cal->rlist = _DtCmsDoDeleteEntryCallback(cal->rlist, cal->calendar,
			user, args->entry.id, args->scope, args->entry.time,
			args->pid);


	return (&res);
}