예제 #1
0
파일: cmscalendar.c 프로젝트: juddy/edcde
static CSA_return_code
_GetSupportedVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
{
	attr->name.num = CSA_CAL_ATTR_VERSION_I;
	if (attr->name.name = strdup(CSA_CAL_ATTR_VERSION)) {
		return (_DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED,
			&attr->value, CSA_VALUE_STRING));
	} else {
		return (CSA_E_INSUFFICIENT_MEMORY);
	}
}
예제 #2
0
파일: cmscalendar.c 프로젝트: juddy/edcde
static CSA_return_code
_GetProductId(_DtCmsCalendar *cal, int index, cms_attribute *attr)
{
	attr->name.num = CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I;
	if (attr->name.name = strdup(CSA_CAL_ATTR_PRODUCT_IDENTIFIER)) {
		return (_DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER,
			&attr->value, CSA_VALUE_STRING));
	} else {
		return (CSA_E_INSUFFICIENT_MEMORY);
	}
}
예제 #3
0
파일: cmscalendar.c 프로젝트: juddy/edcde
static CSA_return_code
_GetCalendarName(_DtCmsCalendar *cal, int index, cms_attribute *attr)
{
	if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
		return (_DtCm_copy_cms_attribute(attr,
			&cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I], B_TRUE));
	} else {
		attr->name.num = CSA_CAL_ATTR_CALENDAR_NAME_I;
		if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_NAME)) {
			return (_DtCm_set_string_attrval(cal->calendar,
				&attr->value, CSA_VALUE_STRING));
		} else {
			return (CSA_E_INSUFFICIENT_MEMORY);
		}
	}
}
예제 #4
0
파일: cmscalendar.c 프로젝트: juddy/edcde
/*
 * Load calendar data into memory from callog file.
 */
extern CSA_return_code
_DtCmsLoadCalendar(char *target, _DtCmsCalendar **infoptr)
{
	CSA_return_code	stat;
	char		*calname;
	char		*log;
	_DtCmsCalendar	*cal = NULL;

	if (target == NULL || infoptr == NULL)
		return (CSA_E_FAILURE);

	*infoptr = NULL;

	if ((calname = get_calname(target)) == NULL)
		return(CSA_E_INSUFFICIENT_MEMORY);

	if ((log = _DtCmsGetLogFN(calname)) == NULL)
	{
		free(calname);
		return(CSA_E_INSUFFICIENT_MEMORY);
	}

	if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
	    == NULL) {
		stat = CSA_E_INSUFFICIENT_MEMORY;
		goto ERROR;
	}

	if (!(cal->calendar = (char *)strdup(calname))) {
		stat = CSA_E_INSUFFICIENT_MEMORY;
		goto ERROR;
	}

	/* load data from file */
	if ((stat = start_log(cal, log)) != CSA_SUCCESS) {
		goto ERROR;
	}

	/*
	 * get file owner after the file is loaded since file
	 * ownership might be fixed in start_log()
	 */
	if (cal->fversion == _DtCMS_VERSION1) {
		if ((stat = get_file_owner(calname, &cal->owner))
		    != CSA_SUCCESS)
			goto ERROR;

		cal->alist = _DtCmsCalendarAccessList(cal);
	} else {
		if (cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value)
			cal->owner = strdup(cal->\
					attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
					value->item.calendar_user_value);
		else {
			stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
	    		fprintf(stderr, "%s: %s\n", pgname,
				"calendar owner attribute is missing from callog file");
			goto ERROR;
		}

		if (cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value == NULL)
		{
			if ((stat = _DtCm_set_string_attrval(
			    _DtCM_PRODUCT_IDENTIFIER, &cal->\
			    attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value,
			    CSA_VALUE_STRING)) != CSA_SUCCESS) {
				goto ERROR;
			}
		}

		if (cal->attrs[CSA_CAL_ATTR_VERSION_I].value == NULL) {
			if ((stat = _DtCm_set_string_attrval(
			    _DtCM_SPEC_VERSION_SUPPORTED,
			    &cal->attrs[CSA_CAL_ATTR_VERSION_I].value,
			    CSA_VALUE_STRING)) != CSA_SUCCESS) {
				goto ERROR;
			}
		}

		cal->num_entry_attrs = cal->entry_tbl->size;
	}

	cal->getattrfuncs = _GetAttrFuncPtrs;

	/* link with other calendar structures */
	cal->next = calendar_list;
	calendar_list = cal;

	free(log);
	free(calname);

	*infoptr = cal;
	return (CSA_SUCCESS);
ERROR:
	free(calname);
	free(log);

	_DtCmsFreeCalendar(cal);
	return (stat);
}
예제 #5
0
파일: cmscalendar.c 프로젝트: juddy/edcde
extern _DtCmsCalendar *
_DtCmsMakeCalendar(char *owner, char *name)
{
	_DtCmsCalendar	*cal;

	if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
	    == NULL) {
		return (NULL);
	}

	cal->fversion = _DtCMS_VERSION4;

	if (init_cal_attrs(cal) != CSA_SUCCESS) {
		free(cal);
		return (NULL);
	}

	if (_DtCm_set_string_attrval(owner,
	    &cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value,
	    CSA_VALUE_CALENDAR_USER)) {
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}
	if ((cal->owner = strdup(cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
	    value->item.string_value)) == NULL) {
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}

	if (_DtCm_set_string_attrval(name,
	    &cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value, CSA_VALUE_STRING))
	{
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}
	if ((cal->calendar = get_calname(name)) == NULL) {
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}

	if ((cal->types = (int *)calloc(1, sizeof(int) *
	    (_DtCm_entry_name_tbl->size + 1))) == NULL) {
		_DtCmsFreeCalendar(cal);
		return (NULL);
	} else
		_DtCm_get_attribute_types(_DtCm_entry_name_tbl->size,
			cal->types);

	if (!(cal->tree = rb_create(_DtCmsGetEntryKey, _DtCmsCompareEntry))) {
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}

	if (!(cal->list = hc_create(_DtCmsGetEntryKey, _DtCmsCompareRptEntry)))
	{
		_DtCmsFreeCalendar(cal);
		return (NULL);
	}

	cal->cal_tbl = _DtCm_cal_name_tbl;
	cal->entry_tbl = _DtCm_entry_name_tbl;
	cal->num_entry_attrs = _DtCm_entry_name_tbl->size;
	cal->getattrfuncs = _GetAttrFuncPtrs;

	return (cal);
}
예제 #6
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);
}
예제 #7
0
static CSA_return_code
_DtCmsCreateCallog(char *user, cms_create_args *args, _DtCmsCalendar **newcal)
{
	CSA_return_code	stat;
	_DtCmsCalendar	*cal;
	int		i, index;
	char		datestr[80];
	char		*calname;
	char		*log;
	char		*username;
	cms_attribute_value val;
	cms_access_entry aentry;
	int		nidx = 0, oidx = 0;
	char		*name, *owner;

	/*
	 * if calendar name is a user name, make sure that
	 * it's the same as the sender.
	 */
	calname = _DtCmGetPrefix(args->cal, '@');
	username = _DtCmGetPrefix(user, '@');

	if (_DtCmIsUserName(calname) && strcmp(calname, username)) {
		free(calname);
		free(username);
		return (CSA_E_NO_AUTHORITY);
	}
	log = _DtCmsGetLogFN(calname);
	free(calname);
	free(username);

	/* create internal calendar data structure */
	if ((cal = _DtCmsMakeCalendar(user, args->cal)) == NULL) {
		free(log);
		return (CSA_E_INSUFFICIENT_MEMORY);
	}

	/* fill in information */
	_csa_tick_to_iso8601(time(0), datestr);

	if ((stat = _DtCm_set_string_attrval(datestr,
	    &cal->attrs[CSA_CAL_ATTR_DATE_CREATED_I].value,
	    CSA_VALUE_DATE_TIME)) != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	/* initialize access list to be "WORLD", VIEW_PUBLIC */
	aentry.user = WORLD;
	aentry.rights = CSA_VIEW_PUBLIC_ENTRIES;
	aentry.next = NULL;
	val.item.access_list_value = &aentry;
	val.type = CSA_VALUE_ACCESS_LIST;

	if ((stat = _DtCmUpdateAccessListAttrVal(&val,
	    &cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value)) != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	/* set product identifier */
	if ((stat = _DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER,
	    &cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value,
	    CSA_VALUE_STRING)) != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	/* set CSA version */
	if ((stat = _DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED,
	    &cal->attrs[CSA_CAL_ATTR_VERSION_I].value, CSA_VALUE_STRING))
	    != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	/* we dont use the values specified by client */
	for (i = 0; i < args->num_attrs; i++) {
		if (strcmp(args->attrs[i].name.name,
		    CSA_CAL_ATTR_CALENDAR_NAME) == 0) {
			nidx = i;
			name = args->attrs[i].name.name;
			args->attrs[i].name.name = NULL;
		} else if (strcmp(args->attrs[i].name.name,
		    CSA_CAL_ATTR_CALENDAR_OWNER) == 0) {
			oidx = i;
			owner = args->attrs[i].name.name;
			args->attrs[i].name.name = NULL;
		}
	}

	/* initialize calendar attribute with info provided by caller */
	if ((stat = _DtCmUpdateAttributes(args->num_attrs, args->attrs,
	    &cal->num_attrs, &cal->attrs, &cal->cal_tbl, B_TRUE,
	    NULL, B_FALSE)) != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	if (nidx) args->attrs[nidx].name.name = name;
	if (oidx) args->attrs[oidx].name.name = owner;

	/* use passed in char set if client does not supply one */
	if (cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value == NULL &&
	     args->char_set && *args->char_set != NULL) {
		if ((stat = _DtCm_set_string_attrval(args->char_set,
		    &cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value,
		    CSA_VALUE_STRING)) != CSA_SUCCESS) {
			_DtCmsFreeCalendar(cal);
			free(log);
			return (stat);
		}
	}

	/* create file */
	if ((stat = _DtCmsCreateLogV2(user, log)) != CSA_SUCCESS) {
		_DtCmsFreeCalendar(cal);
		free(log);
		return (stat);
	}

	/* dump file */
	if ((stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs, cal->attrs))
	    != CSA_SUCCESS) {
		free(log);
		unlink(log);
		_DtCmsFreeCalendar(cal);
		return (stat);
	}
	free(log);

	_DtCmsPutInCalList(cal);

	*newcal = cal;

	return (stat);
}