示例#1
0
文件: cmscalendar.c 项目: juddy/edcde
/*
 * For parser only.
 */
extern CSA_return_code
_DtCmsInsertEntry4Parser(_DtCmsCalendar *cal, cms_entry *entry)
{
	cms_entry	*eptr;
	CSA_return_code stat;

	if ((stat = _DtCmsMakeHashedEntry(cal, entry->num_attrs,
	    entry->attrs, &eptr)) != CSA_SUCCESS)
		return (stat);

	eptr->key = entry->key;

	stat = _DtCmsInsertEntry(cal, eptr);

	_DtCm_free_cms_entry(eptr);

	return(stat);
}
示例#2
0
extern  cms_entry_res *
cms_insert_entry_5_svc(cms_insert_args *args, struct svc_req *svcrq)
{
	static cms_entry_res	res;
	_DtCmsCalendar		*cal;
	cms_entry		*entry;
	cms_key			key;
	char			*user;
	uint			access, needaccess;
	Appt_4			*appt;

	if (debug)
		fprintf(stderr, "cms_insert_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_INSERT_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->num_attrs == 0) {
		res.stat = CSA_E_INVALID_PARAMETER;
		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_ADDED, B_TRUE))
	    != CSA_SUCCESS)
		return (&res);

	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
		if ((res.stat = _DtCmsMakeHashedEntry(cal, args->num_attrs,
		    args->attrs, &entry)) != CSA_SUCCESS)
			return (&res);

		if ((res.stat = _DtCmsCheckInitialAttributes(entry))
		    != CSA_SUCCESS) {
			_DtCm_free_cms_entry(entry);
			return (&res);
		}

		/* check access rights */
		needaccess = _DtCmsClassToInsertAccess(entry);
		if ((access & (CSA_OWNER_RIGHTS | needaccess)) == 0) {
			_DtCm_free_cms_entry(entry);
			res.stat = CSA_E_NO_AUTHORITY;
			return (&res);
		}

		/* set organizer */
		if ((res.stat = _DtCm_set_string_attrval(user,
		    &entry->attrs[CSA_ENTRY_ATTR_ORGANIZER_I].value,
		    CSA_VALUE_CALENDAR_USER)) != CSA_SUCCESS) {
			_DtCm_free_cms_entry(entry);
			return (&res);
		}

		/* insert entry and log it */
		if ((res.stat = _DtCmsInsertEntryAndLog(cal, entry))
		    != CSA_SUCCESS) {
			_DtCm_free_cms_entry(entry);
			return (&res);
		}

		key = entry->key;
	} else {
		if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL) {
			res.stat = CSA_E_INSUFFICIENT_MEMORY;
			return (&res);
		}
 
		if ((res.stat = _DtCmsAttrsToAppt4(args->num_attrs,
		    args->attrs, appt, B_TRUE)) != CSA_SUCCESS) {
			_DtCm_free_appt4(appt);
			return (&res);
		}

		if (appt->author) free(appt->author);
		if ((appt->author = strdup(user)) == NULL) {
			_DtCm_free_appt4(appt);
			return (&res);
		}

		/*
		 * calculate the correct start day,
		 */
		_DtCms_adjust_appt_startdate(appt);

		if ((res.stat = _DtCmsInsertApptAndLog(cal, appt))
		    != CSA_SUCCESS) {
			_DtCm_free_appt4(appt);
			return (&res);
		}

		key.id = appt->appt_id.key;
		key.time = appt->appt_id.tick;
	}

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

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

	cal->rlist = _DtCmsDoInsertEntryCallback(cal->rlist, cal->calendar,
			user, key.id, args->pid);

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

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

		_DtCm_free_cms_entry(entry);
	}

	return (&res);
}