Calendar-CSA
view release on metacpan or search on metacpan
return 0;
if (!buffer)
buffer = alloc_temp(64);
if (SvIOKp(value) || SvNOKp(value)) {
_csa_tick_to_iso8601(SvIV(value), buffer);
} else {
strncpy(buffer, SvPV(value, na), 63);
buffer[63] = '\0';
if (strlen(buffer)==0)
return 0;
}
return buffer;
}
char * SvISO_date_time_range(SV * value, char *buffer)
{
if (!value || !SvOK(value))
return 0;
if (!buffer)
buffer = alloc_temp(64);
if (SvRV(value)) {
time_t t1,t2;
AV * a = (AV*)SvRV(value);
t1 = SvIV(*av_fetch(a,0,0));
t2 = SvIV(*av_fetch(a,1,0));
_csa_range_to_iso8601(t1, t2, buffer);
} else {
strncpy(buffer, SvPV(value, na), 63);
buffer[63] = '\0';
if (strlen(buffer)==0)
return 0;
}
return buffer;
}
char * SvISO_time_duration(SV * value, char * buffer)
{
if (!value || !SvOK(value))
return 0;
if (!buffer)
buffer = alloc_temp(64);
if (SvIOKp(value) || SvNOKp(value)) {
_csa_duration_to_iso8601(SvIV(value), buffer);
} else {
strncpy(buffer, SvPV(value, na), 63);
buffer[63] = '\0';
if (strlen(buffer)==0)
return 0;
}
return buffer;
}
SV * newSVCSA_calendar_user(CSA_calendar_user * user)
{
HV * u;
SV * r;
if (!user)
return newSVsv(&sv_undef);
u = newHV();
if (user->user_name)
hv_store(u, "user_name", 9, newSVpv(user->user_name,0), 0);
if (user->calendar_address)
hv_store(u, "calendar_address", 16, newSVpv(user->calendar_address,0), 0);
if (user->calendar_address ||
user->user_name ||
user->user_type)
hv_store(u, "user_type", 9, newSVCSA_USER_TYPE(user->user_type), 0);
r = newRV((SV*)u);
SvREFCNT_dec(u);
return r;
}
CSA_calendar_user * SvCSA_calendar_user(SV * user, CSA_calendar_user * target)
{
HV * u = (HV*)SvRV(user);
SV ** s;
if (!user || !SvOK(user))
return 0;
if (!target)
target = alloc_temp(sizeof(CSA_calendar_user));
if ((s=hv_fetch(u, "user_name", 9, 0)) && SvOK(*s))
target->user_name = SvPV(*s, na);
else
target->user_name = 0;
if ((s=hv_fetch(u, "calendar_address", 16, 0)) && SvOK(*s))
target->calendar_address = SvPV(*s, na);
else
target->calendar_address = 0;
if ((s=hv_fetch(u, "user_type", 9, 0)) && SvOK(*s))
target->user_type = SvCSA_USER_TYPE(*s);
else
target->user_type = 0;
return target;
}
static struct opts rights[] = {
{CSA_FREE_TIME_SEARCH, "FREE TIME SEARCH"},
{CSA_VIEW_PUBLIC_ENTRIES, "VIEW PUBLIC ENTRIES"},
{CSA_INSERT_PUBLIC_ENTRIES, "INSERT PUBLIC ENTRIES"},
{CSA_INSERT_CONFIDENTIAL_ENTRIES, "INSERT CONFIDENTIAL ENTRIES"},
{CSA_INSERT_PRIVATE_ENTRIES, "INSERT PRIVATE ENTRIES"},
{CSA_CHANGE_PUBLIC_ENTRIES, "CHANGE PUBLIC ENTRIES"},
{CSA_CHANGE_CONFIDENTIAL_ENTRIES, "CHANGE CONFIDENTIAL ENTRIES"},
{CSA_CHANGE_PRIVATE_ENTRIES, "CHANGE PRIVATE ENTRIES"},
{CSA_VIEW_CALENDAR_ATTRIBUTES, "VIEW CALENDAR ATTRIBUTES"},
{CSA_INSERT_CALENDAR_ATTRIBUTES, "INSERT CALENDAR ATTRIBUTES"},
{CSA_CHANGE_CALENDAR_ATTRIBUTES, "CHANGE CALENDAR ATTRIBUTES"},
{CSA_ORGANIZER_RIGHTS, "ORGANIZER RIGHTS"},
{CSA_OWNER_RIGHTS, "OWNER RIGHTS"},
{0, 0}
};
SV * newSVCSA_access_rights(CSA_access_rights * right)
{
HV * u;
SV * r;
int i;
if (!right)
return newSVsv(&sv_undef);
u = newHV();
hv_store(u, "user", 4, newSVCSA_calendar_user(right->user), 0);
hv_store(u, "rights", 6, newSVOptFlags(right->rights, "rights", rights, 1), 0);
r = newRV((SV*)u);
SvREFCNT_dec(u);
return r;
}
CSA_access_rights * SvCSA_access_rights(SV * data, CSA_access_rights * target)
{
HV * h;
SV ** s;
int i;
if (!data || !SvOK(data))
return 0;
if (!target)
target = alloc_temp(sizeof(CSA_access_rights));
h = (HV*)SvRV(data);
if ((s = hv_fetch(h, "user", 4, 0)) && SvOK(*s))
target->user = SvCSA_calendar_user(*s, 0);
else
target->user = 0;
target->rights = 0;
if ((s = hv_fetch(h, "rights", 6, 0)) && SvOK(*s))
target->rights = SvOptFlags(*s, "rights", rights);
return target;
}
SV * newSVCSA_access_list(CSA_access_list list)
{
AV * l;
SV * r;
CSA_access_rights * right;
if (!list)
return newSVsv(&sv_undef);
l = newAV();
for(right = list; right; right=right->next)
av_push(l, newSVCSA_access_rights(right));
r = newRV((SV*)l);
SvREFCNT_dec(l);
return r;
}
CSA_access_list SvCSA_access_list(SV * data, CSA_access_list list)
{
AV * l;
int i;
if (!data || !SvOK(data))
return 0;
l = (AV*)SvRV(data);
if (av_len(l)==-1)
return 0;
if (!list)
list = alloc_temp(sizeof(CSA_access_rights)* (av_len(l)+1));
for(i=0;i<=av_len(l);i++) {
SvCSA_access_rights(*av_fetch(l, i, 0), list);
list->next = list+i+1;
}
if (i)
(list+i-1)->next = 0;
return list;
}
static struct opts statuses[] = {
{CSA_STATUS_ACCEPTED, "ACCEPTED"},
{CSA_STATUS_NEEDS_ACTION, "NEEDS ACTION"},
{CSA_STATUS_SENT, "SENT"},
{CSA_STATUS_TENTATIVE, "TENTATIVE"},
{CSA_STATUS_CONFIRMED, "CONFIRMED"},
{CSA_STATUS_REJECTED, "REJECTED"},
{CSA_STATUS_COMPLETED, "COMPLETED"},
{CSA_STATUS_DELEGATED, "DELEGATED"},
#ifdef CSA_X_DT_STATUS_ACTIVE
{CSA_X_DT_STATUS_ACTIVE, "X-DT ACTIVE"},
#endif
#ifdef CSA_X_DT_STATUS_DELETE_PENDING
{CSA_X_DT_STATUS_DELETE_PENDING, "X-DT DELETE PENDING"},
#endif
#ifdef CSA_X_DT_STATUS_ADD_PENDING
{CSA_X_DT_STATUS_ADD_PENDING, "X-DT ADD PENDING"},
#endif
#ifdef CSA_X_DT_STATUS_COMMITTED
{CSA_X_DT_STATUS_COMMITTED, "X-DT COMMITTED"},
#endif
#ifdef CSA_X_DT_STATUS_CANCELLED
{CSA_X_DT_STATUS_CANCELLED, "X-DT CANCELLED"},
#endif
{0, 0}
};
static struct opts priorities[] = {
{CSA_FOR_YOUR_INFORMATION, "FOR YOUR INFORMATION"},
{CSA_ATTENDANCE_REQUESTED, "ATTENDANCE REQUESTED"},
{CSA_ATTENDANCE_REQUIRED, "ATTENDANCE REQUIRED"},
{CSA_IMMEDIATE_RESPONSE, "IMMEDIATE RESPONSE"},
{0, 0}
};
SV * newSVCSA_attendee(CSA_attendee * attendee)
{
HV * u;
HV * flags;
SV * r;
int i;
if (!attendee)
return newSVsv(&sv_undef);
u = newHV();
flags = newHV();
hv_store(u, "attendee", 8, newSVCSA_calendar_user(&attendee->attendee), 0);
hv_store(u, "rsvp_requested", 14, newSViv(attendee->rsvp_requested),0);
hv_store(u, "status", 6, newSVOpt(attendee->status, "status", statuses), 0);
hv_store(u, "priority", 8, newSVOpt(attendee->status, "priority", priorities), 0);
r = newRV((SV*)u);
SvREFCNT_dec(u);
return r;
}
SV * newSVCSA_attendee_list(CSA_attendee_list list)
{
AV * l;
SV * r;
CSA_attendee * attendee;
if (!list)
return newSVsv(&sv_undef);
l = newAV();
for(attendee = list; attendee; attendee = attendee->next)
av_push(l, newSVCSA_attendee(attendee));
r = newRV((SV*)l);
SvREFCNT_dec(l);
return r;
}
SV * newSVCSA_date_time_list(CSA_date_time_list list, int doiso_times)
{
AV * l;
SV * r;
CSA_date_time_entry * dt;
if (!list)
return newSVsv(&sv_undef);
l = newAV();
for(dt = list; dt; dt = dt->next)
av_push(l, newSVISO_date_time(dt->date_time, doiso_times));
r = newRV((SV*)l);
SvREFCNT_dec(l);
return r;
}
CSA_date_time_list SvCSA_date_time_list(SV * data, CSA_date_time_list target)
{
AV * l;
int i;
if (!data || !SvOK(data))
return 0;
l = (AV*)SvRV(data);
if (av_len(l)<0)
return 0;
if (!target)
target = alloc_temp(sizeof(CSA_date_time_entry)*(av_len(l)+1));
for(i=0;i<=av_len(l);i++) {
(target+i)->date_time = SvISO_date_time(*av_fetch(l, i, 0), 0);
(target+i)->next = target+i+1;
}
if (i)
(target+i-1)->next = 0;
HV * h = (HV*)SvRV(data);
SV ** s;
int i;
if (!data || !SvOK(data))
return 0;
if (!target)
target = alloc_temp(sizeof(CSA_reminder));
memset(target, 0, sizeof(CSA_reminder));
if ((s=hv_fetch(h, "lead_time", 9, 0)) && SvOK(*s))
target->lead_time = SvISO_time_duration(*s,0);
else
target->lead_time = 0;
if ((s=hv_fetch(h, "snooze_time", 11, 0)) && SvOK(*s))
target->snooze_time = SvISO_time_duration(*s,0);
else
target->snooze_time = 0;
if ((s=hv_fetch(h, "repeat_count", 12, 0)) && SvOK(*s))
target->repeat_count = SvIV(*s);
else
target->repeat_count = 0;
if ((s=hv_fetch(h, "data", 4, 0)) && SvOK(*s))
SvCSA_opaque_data(*s, &target->reminder_data);
return target;
}
SV * newSVCSA_attribute_value(CSA_attribute_value * attr, int doshorten, int doiso_times)
{
HV * h;
SV * r;
SV * type = 0;
SV * value = 0;
if (!attr)
return newSVsv(&sv_undef);
h = newHV();
type = newSVOpt(attr->type, "attribute type", attributes);
switch (attr->type) {
case CSA_VALUE_BOOLEAN:
value = newSViv(attr->item.boolean_value);
break;
case CSA_VALUE_ENUMERATED:
value = newSViv(attr->item.enumerated_value);
break;
case CSA_VALUE_FLAGS:
value = newSViv(attr->item.flags_value);
break;
case CSA_VALUE_SINT32:
value = newSViv(attr->item.sint32_value);
break;
case CSA_VALUE_UINT32:
value = newSViv(attr->item.uint32_value);
break;
case CSA_VALUE_STRING:
value = newSVpv(shorten(attr->item.string_value, doshorten), 0);
break;
case CSA_VALUE_CALENDAR_USER:
value = newSVCSA_calendar_user(attr->item.calendar_user_value);
break;
case CSA_VALUE_DATE_TIME:
value = newSVISO_date_time(attr->item.date_time_value, doiso_times);
break;
case CSA_VALUE_DATE_TIME_RANGE:
value = newSVISO_date_time_range(attr->item.date_time_range_value, doiso_times);
break;
case CSA_VALUE_TIME_DURATION:
value = newSVISO_time_duration(attr->item.time_duration_value, doiso_times);
break;
case CSA_VALUE_ACCESS_LIST:
value = newSVCSA_access_list(attr->item.access_list_value);
break;
case CSA_VALUE_DATE_TIME_LIST:
value = newSVCSA_date_time_list(attr->item.date_time_list_value, doiso_times);
break;
case CSA_VALUE_REMINDER:
value = newSVCSA_reminder(attr->item.reminder_value, doiso_times);
break;
case CSA_VALUE_OPAQUE_DATA:
value = newSVCSA_opaque_data(attr->item.opaque_data_value);
break;
default:
value = newSVsv(&sv_undef); /* unknown type */
}
hv_store(h, "type", 4, type, 0);
hv_store(h, "value", 5, value, 0);
r = newRV((SV*)h);
SvREFCNT_dec(h);
return r;
}
SV * newSVCSA_attribute(CSA_attribute * attr, int doshorten, int doiso_times)
{
HV * h;
SV * r;
char * type = 0;
SV * value = 0;
if (!attr)
return newSVsv(&sv_undef);
h = newHV();
hv_store(h, "name", 4, newSVpv(attr->name,0), 0);
hv_store(h, "value", 5, newSVCSA_attribute_value(attr->value, doshorten, doiso_times), 0);
r = newRV((SV*)h);
SvREFCNT_dec(h);
return r;
}
CSA_attribute_value * SvCSA_attribute_value(SV * attr, CSA_attribute_value * target)
{
HV * h;
SV * r;
SV ** s;
int type = 0;
SV * value = 0;
if (!attr || !SvOK(attr))
return 0;
if (SvTYPE(SvRV(attr)) != SVt_PVHV)
croak("an attribute value must be a hash containing type and value keys");
h = (HV*)SvRV(attr);
if (!(s=hv_fetch(h, "type", 4, 0)) || !SvOK(*s))
croak("an attribute value must be a hash containing type and value keys");
type = SvOpt(*s, "attribute type", attributes);
if (!(s=hv_fetch(h, "value", 5, 0)))
croak("an attribute value must be a hash containing type and value keys");
if (!target)
target = alloc_temp(sizeof(CSA_attribute_value));
target->type = type;
switch (type) {
case CSA_VALUE_BOOLEAN:
target->item.boolean_value = SvIV(*s);
break;
case CSA_VALUE_ENUMERATED:
target->item.enumerated_value = SvIV(*s);
break;
case CSA_VALUE_FLAGS:
target->item.flags_value = SvIV(*s);
break;
case CSA_VALUE_SINT32:
target->item.sint32_value = SvIV(*s);
break;
case CSA_VALUE_UINT32:
target->item.uint32_value = SvIV(*s);
break;
case CSA_VALUE_STRING:
target->item.string_value = lengthen(SvPV(*s, na));
break;
case CSA_VALUE_CALENDAR_USER:
target->item.calendar_user_value = SvCSA_calendar_user(*s, 0);
break;
case CSA_VALUE_DATE_TIME:
target->item.date_time_value = SvISO_date_time(*s, 0);
break;
case CSA_VALUE_DATE_TIME_RANGE:
target->item.date_time_range_value = SvISO_date_time_range(*s, 0);
break;
case CSA_VALUE_TIME_DURATION:
target->item.time_duration_value = SvISO_time_duration(*s, 0);
break;
case CSA_VALUE_ACCESS_LIST:
target->item.access_list_value = SvCSA_access_list(*s, 0);
break;
case CSA_VALUE_DATE_TIME_LIST:
target->item.date_time_list_value = SvCSA_date_time_list(*s, 0);
break;
case CSA_VALUE_REMINDER:
target->item.reminder_value = SvCSA_reminder(*s, 0);
break;
case CSA_VALUE_OPAQUE_DATA:
target->item.opaque_data_value = SvCSA_opaque_data(*s, 0);
break;
defaut:
croak("unhandled attribute type");
}
return target;
}
CSA_attribute * SvCSA_attribute(SV * attr, CSA_attribute * target)
{
HV * h;
SV * r;
SV ** s;
char * type = 0;
SV * value = 0;
if (!attr || !SvOK(attr))
return 0;
if (!target)
target = alloc_temp(sizeof(CSA_attribute));
h = (HV*)SvRV(attr);
if ((s=hv_fetch(h, "name", 4, 0)) && SvOK(*s))
target->name = SvPV(*s, na);
else
croak("attribute must have name");
if ((s=hv_fetch(h, "value", 5, 0)) && SvOK(*s))
target->value = SvCSA_attribute_value(*s, 0);
else
croak("attribute must have value");
return target;
}
static struct opts cb_modes[] = {
{CSA_CB_CALENDAR_LOGON, "CALENDAR LOGON"},
{CSA_CB_CALENDAR_DELETED, "CALENDAR DELETED"},
{CSA_CB_CALENDAR_ATTRIBUTE_UPDATED, "CALENDAR ATTRIBUTE UPDATED"},
{CSA_CB_ENTRY_ADDED, "ENTRY ADDED"},
( run in 2.088 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )