Define the escaping behaviour of ical properties, to make sure we do the right thing with escaped values in ical calendars.

bug 307948, r=dmose
This commit is contained in:
mvl%exedo.nl 2005-11-18 18:05:37 +00:00
Родитель da608b74fc
Коммит fa7e36310f
4 изменённых файлов: 80 добавлений и 12 удалений

Просмотреть файл

@ -168,7 +168,19 @@ interface calIIcalComponent : nsISupports
[scriptable,uuid(17349a10-5d80-47fa-9bea-f22957357675)] [scriptable,uuid(17349a10-5d80-47fa-9bea-f22957357675)]
interface calIIcalProperty : nsISupports interface calIIcalProperty : nsISupports
{ {
attribute AUTF8String stringValue; /**
* The value of the property as string.
* The exception for properties of TEXT or X- type, those will be unescaped
* when getting, and also expects an unescaped string when setting.
* Datetime, numeric and other non-text types are represented as ical string
*/
attribute AUTF8String value;
/**
* The value of the property in (escaped) ical format.
*/
attribute AUTF8String valueAsIcalString;
// XXX attribute AUTF8String stringValueWithParams; ? // XXX attribute AUTF8String stringValueWithParams; ?
readonly attribute AUTF8String propertyName; readonly attribute AUTF8String propertyName;

Просмотреть файл

@ -181,7 +181,7 @@ calEvent.prototype = {
try { try {
if (!this.eventPromotedProps[iprop.name]) { if (!this.eventPromotedProps[iprop.name]) {
var icalprop = icssvc.createIcalProperty(iprop.name); var icalprop = icssvc.createIcalProperty(iprop.name);
icalprop.stringValue = iprop.value; icalprop.value = iprop.value;
icalcomp.addProperty(icalprop); icalcomp.addProperty(icalprop);
} }
} catch (e) { } catch (e) {

Просмотреть файл

@ -67,12 +67,26 @@ calIcalProperty::GetIcalProperty()
} }
NS_IMETHODIMP NS_IMETHODIMP
calIcalProperty::GetStringValue(nsACString &str) calIcalProperty::GetValue(nsACString &str)
{ {
const char *icalstr = icalproperty_get_value_as_string(mProperty); icalvalue_kind kind = icalproperty_kind_to_value_kind(icalproperty_isa(mProperty));
const char *icalstr;
if (kind == ICAL_TEXT_VALUE) {
icalvalue *v = icalproperty_get_value(mProperty);
icalstr = icalvalue_get_text(v);
} else if (kind == ICAL_X_VALUE) {
icalvalue *v = icalproperty_get_value(mProperty);
icalstr = icalvalue_get_x(v);
} else {
icalstr = icalproperty_get_value_as_string(mProperty);
}
if (!icalstr) { if (!icalstr) {
if (icalerrno == ICAL_BADARG_ERROR) { if (icalerrno == ICAL_BADARG_ERROR) {
str.Truncate(); str.Truncate();
// Set string to null, because we don't have a value
// (which is something different then an empty value)
str.SetIsVoid(PR_TRUE); str.SetIsVoid(PR_TRUE);
return NS_OK; return NS_OK;
} }
@ -89,7 +103,49 @@ calIcalProperty::GetStringValue(nsACString &str)
} }
NS_IMETHODIMP NS_IMETHODIMP
calIcalProperty::SetStringValue(const nsACString &str) calIcalProperty::SetValue(const nsACString &str)
{
icalvalue_kind kind = icalproperty_kind_to_value_kind(icalproperty_isa(mProperty));
if (kind == ICAL_TEXT_VALUE) {
icalvalue *v = icalvalue_new_text(PromiseFlatCString(str).get());
icalproperty_set_value(mProperty, v);
} else if (kind == ICAL_X_VALUE) {
icalvalue *v = icalvalue_new_x(PromiseFlatCString(str).get());
icalproperty_set_value(mProperty, v);
} else {
icalproperty_set_value_from_string(mProperty,
PromiseFlatCString(str).get(),
icalvalue_kind_to_string(kind));
}
return NS_OK;
}
NS_IMETHODIMP
calIcalProperty::GetValueAsIcalString(nsACString &str)
{
const char *icalstr = icalproperty_get_value_as_string(mProperty);
if (!icalstr) {
if (icalerrno == ICAL_BADARG_ERROR) {
str.Truncate();
// Set string to null, because we don't have a value
// (which is something different then an empty value)
str.SetIsVoid(PR_TRUE);
return NS_OK;
}
#ifdef DEBUG
fprintf(stderr, "Error getting string value: %d (%s)\n",
icalerrno, icalerror_strerror(icalerrno));
#endif
return NS_ERROR_FAILURE;
}
str.Assign(icalstr);
return NS_OK;
}
NS_IMETHODIMP
calIcalProperty::SetValueAsIcalString(const nsACString &str)
{ {
const char *kindstr = const char *kindstr =
icalvalue_kind_to_string(icalproperty_kind_to_value_kind(icalproperty_isa(mProperty))); icalvalue_kind_to_string(icalproperty_kind_to_value_kind(icalproperty_isa(mProperty)));
@ -380,7 +436,7 @@ calIcalComponent::AddTimezoneReference(calIIcalComponent *aTimezone)
} }
nsCAutoString tzid; nsCAutoString tzid;
rv = tzidProp->GetStringValue(tzid); rv = tzidProp->GetValue(tzid);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// figure out if we already have this tzid // figure out if we already have this tzid

Просмотреть файл

@ -484,7 +484,7 @@ calItemBase.prototype = {
var gen = icalcomp.getFirstProperty("X-MOZILLA-GENERATION"); var gen = icalcomp.getFirstProperty("X-MOZILLA-GENERATION");
if (gen) if (gen)
this.mGeneration = parseInt(gen.stringValue); this.mGeneration = parseInt(gen.value);
// find recurrence properties // find recurrence properties
var rec = null; var rec = null;
@ -521,7 +521,7 @@ calItemBase.prototype = {
var triggerProp = alarmComp.getFirstProperty("TRIGGER"); var triggerProp = alarmComp.getFirstProperty("TRIGGER");
var duration = Components.classes["@mozilla.org/calendar/duration;1"] var duration = Components.classes["@mozilla.org/calendar/duration;1"]
.createInstance(Components.interfaces.calIDuration); .createInstance(Components.interfaces.calIDuration);
duration.icalString = triggerProp.stringValue; duration.icalString = triggerProp.valueAsIcalString;
if (duration.minutes) { if (duration.minutes) {
this.setProperty("alarmLength", duration.minutes); this.setProperty("alarmLength", duration.minutes);
@ -552,7 +552,7 @@ calItemBase.prototype = {
prop = icalcomp.getNextProperty("ANY")) { prop = icalcomp.getNextProperty("ANY")) {
if (!promoted[prop.propertyName]) { if (!promoted[prop.propertyName]) {
// XXX keep parameters around, sigh // XXX keep parameters around, sigh
this.setProperty(prop.propertyName, prop.stringValue); this.setProperty(prop.propertyName, prop.value);
} }
} }
}, },
@ -579,7 +579,7 @@ calItemBase.prototype = {
if (this.mGeneration) { if (this.mGeneration) {
var genprop = icalProp("X-MOZILLA-GENERATION"); var genprop = icalProp("X-MOZILLA-GENERATION");
genprop.stringValue = String(this.mGeneration); genprop.value = String(this.mGeneration);
icalcomp.addProperty(genprop); icalcomp.addProperty(genprop);
} }
@ -601,7 +601,7 @@ calItemBase.prototype = {
duration[this.getProperty("alarmUnits")] = this.getProperty("alarmLength"); duration[this.getProperty("alarmUnits")] = this.getProperty("alarmLength");
var triggerProp = icssvc.createIcalProperty("TRIGGER"); var triggerProp = icssvc.createIcalProperty("TRIGGER");
triggerProp.stringValue = duration.icalString; triggerProp.valueAsIcalString = duration.icalString;
if (this.getProperty("alarmRelated") == "END") if (this.getProperty("alarmRelated") == "END")
triggerProp.setParameter("RELATED", "END"); triggerProp.setParameter("RELATED", "END");
@ -610,7 +610,7 @@ calItemBase.prototype = {
if (this.getProperty("alarmEmailAddress")) { if (this.getProperty("alarmEmailAddress")) {
var emailProp = icssvc.createIcalProperty("X-EMAILADDRESS"); var emailProp = icssvc.createIcalProperty("X-EMAILADDRESS");
emailProp.stringValue = this.getProperty("alarmEmailAddress"); emailProp.value = this.getProperty("alarmEmailAddress");
alarmComp.addProperty(emailProp); alarmComp.addProperty(emailProp);
} }