X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fical_subst.c;h=e48b2f9902b0c9aa5a55d7435f1ab0b21fe2e136;hb=716dc48890328a0d892ae02e1ff1b65917d76f54;hp=8d44830fea2aececc8dac3b87d48887b73b5bd8f;hpb=6c69c17330a725e46868931521dac203a9beb7f3;p=citadel.git
diff --git a/webcit/ical_subst.c b/webcit/ical_subst.c
index 8d44830fe..e48b2f990 100644
--- a/webcit/ical_subst.c
+++ b/webcit/ical_subst.c
@@ -1,11 +1,26 @@
-#include "webcit.h"
-
+/*
+ * Copyright (c) 1996-2012 by the citadel.org team
+ *
+ * This program is open source software. You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
-extern IcalEnumMap icalproperty_kind_map[];
+#include "webcit.h"
+extern IcalKindEnumMap icalproperty_kind_map[];
+extern IcalMethodEnumMap icalproperty_method_map[];
HashList *IcalComponentMap = NULL;
-
+CtxType CTX_ICAL = CTX_NONE;
+CtxType CTX_ICALPROPERTY = CTX_NONE;
+CtxType CTX_ICALMETHOD = CTX_NONE;
+CtxType CTX_ICALTIME = CTX_NONE;
+#if 0
void SortPregetMatter(HashList *Cals)
{
disp_cal *Cal;
@@ -40,13 +55,12 @@ void SortPregetMatter(HashList *Cals)
return;
switch (SortMap[i - 1]->map) {
- /// case
+ /* case */
default:
break;
}
-
It = GetNewHashPos(Cals, 0);
while (GetNextHashPos(Cals, It, &KLen, &Key, &vCal)) {
i = 0;
@@ -58,19 +72,264 @@ void SortPregetMatter(HashList *Cals)
while ((SortMap[i] != NULL) &&
(Cal->SortBy != NULL))
{
- Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map);
+ /****Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map); */
}
}
-
-
}
+#endif
void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP)
{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+ const char *str;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ str = icalproperty_get_comment (p);
+ StrBufAppendTemplateStr(Target, TP, str, 1);
+ }
+}
+
+void tmplput_CtxICalProperty(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
+ const char *str;
+
+ str = icalproperty_get_comment (p);
+ StrBufAppendTemplateStr(Target, TP, str, 0);
+}
+
+int ReleaseIcalSubCtx(StrBuf *Target, WCTemplputParams *TP)
+{
+ WCTemplputParams *TPP = TP;
+ UnStackContext(TP);
+ free(TPP);
+ return 0;
+}
+int cond_ICalIsA(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalcomponent_kind c = GetTemplateTokenNumber(Target, TP, 2, ICAL_NO_COMPONENT);
+ return icalcomponent_isa(cal) == c;
+}
+
+int cond_ICalHaveItem(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ WCTemplputParams *DynamicTP;
+
+ DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams));
+ StackDynamicContext (TP,
+ DynamicTP,
+ p,
+ CTX_ICALPROPERTY,
+ 0,
+ TP->Tokens,
+ ReleaseIcalSubCtx,
+ TP->Tokens->Params[1]->lvalue);
+
+ return 1;
+ }
+ return 0;
+}
+
+int ReleaseIcalTimeCtx(StrBuf *Target, WCTemplputParams *TP)
+{
+ WCTemplputParams *TPP = TP;
+
+ UnStackContext(TP);
+ free(TPP);
+ return 0;
+}
+
+int cond_ICalHaveTimeItem(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ struct icaltimetype *t;
+ struct icaltimetype tt;
+ WCTemplputParams *DynamicTP;
+
+ DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams) +
+ sizeof(struct icaltimetype));
+ t = (struct icaltimetype *) ((char*)DynamicTP) + sizeof(WCTemplputParams);
+ memset(&tt, 0, sizeof(struct icaltimetype));
+ switch (Kind)
+ {
+ case ICAL_DTSTART_PROPERTY:
+ tt = icalproperty_get_dtstart(p);
+ break;
+ case ICAL_DTEND_PROPERTY:
+ tt = icalproperty_get_dtend(p);
+ break;
+ default:
+ break;
+ }
+ memcpy(t, &tt, sizeof(struct icaltimetype));
+
+ StackDynamicContext (TP,
+ DynamicTP,
+ t,
+ CTX_ICALTIME,
+ 0,
+ TP->Tokens,
+ ReleaseIcalTimeCtx,
+ TP->Tokens->Params[1]->lvalue);
+
+ return 1;
+ }
+ return 0;
+}
+
+
+int cond_ICalTimeIsDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+ return t->is_date;
+}
+
+void tmplput_ICalTime_Date(StrBuf *Target, WCTemplputParams *TP)
+{
+ struct tm d_tm;
+ long len;
+ char buf[256];
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+
+ memset(&d_tm, 0, sizeof d_tm);
+ d_tm.tm_year = t->year - 1900;
+ d_tm.tm_mon = t->month - 1;
+ d_tm.tm_mday = t->day;
+ len = wc_strftime(buf, sizeof(buf), "%x", &d_tm);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}
+void tmplput_ICalTime_Time(StrBuf *Target, WCTemplputParams *TP)
+{
+ long len;
+ char buf[256];
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+ time_t tt;
+
+ tt = icaltime_as_timet(*t);
+ len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}
+void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+ struct icaltimetype t;
+ time_t tt;
+ char buf[256];
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ long len;
+ t = icalproperty_get_dtend(p);
+ tt = icaltime_as_timet(t);
+ len = webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+ }
}
+void tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
+ struct icaltimetype t;
+ time_t tt;
+ char buf[256];
+
+ long len;
+ t = icalproperty_get_dtend(p);
+ tt = icaltime_as_timet(t);
+ len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}
+
+
+
+void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+{
+ icalproperty_method the_method = ICAL_METHOD_NONE;
+ icalproperty *method = NULL;
+ icalcomponent *cal;
+ icalcomponent *c;
+ WCTemplputParams SubTP;
+ WCTemplputParams SuperTP;
+ static int divcount = 0;
+
+ if (StrLength(Mime->Data) == 0) {
+ MimeLoadData(Mime);
+ }
+ if (StrLength(Mime->Data) > 0) {
+ cal = icalcomponent_new_from_string(ChrPtr(Mime->Data));
+ }
+ if (cal == NULL) {
+ StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item."));
+ StrBufAppendPrintf(Mime->Data, "
\n");
+ return;
+ }
+
+ putlbstr("divname", ++divcount);
+ putbstr("cal_partnum", NewStrBufDup(Mime->PartNum));
+ putlbstr("msgnum", Mime->msgnum);
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ memset(&SuperTP, 0, sizeof(WCTemplputParams));
+
+ /*//ical_dezonify(cal); */
+
+ /* If the component has subcomponents, recurse through them. */
+ c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
+ c = (c != NULL) ? c : cal;
+
+ method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
+ if (method != NULL) {
+ the_method = icalproperty_get_method(method);
+ }
+
+ SuperTP.Context = &the_method;
+ SuperTP.Filter.ContextType = CTX_ICALMETHOD,
+
+ StackContext (&SuperTP,
+ &SubTP,
+ c,
+ CTX_ICAL,
+ 0,
+ SuperTP.Tokens);
+ FlushStrBuf(Mime->Data);
+ DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP);
+
+ /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */
+
+ /* Free the memory we obtained from libical's constructor */
+ StrBufPlain(Mime->ContentType, HKEY("text/html"));
+ StrBufAppendPrintf(WC->trailing_javascript,
+ "eventEditAllDay(); \n"
+ "RecurrenceShowHide(); \n"
+ "EnableOrDisableCheckButton(); \n"
+ );
+
+ UnStackContext(&SubTP);
+ icalcomponent_free(cal);
+}
void CreateIcalComponendKindLookup(void)
{
int i = 0;
@@ -82,6 +341,7 @@ void CreateIcalComponendKindLookup(void)
0,
10,
tmplput_ICalItem,
+ NULL,
CTX_ICAL);
Put(IcalComponentMap,
icalproperty_kind_map[i].Name,
@@ -97,7 +357,14 @@ void CreateIcalComponendKindLookup(void)
+int cond_ICalIsMethod(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalproperty_method *the_method = (icalproperty_method *) CTX(CTX_ICALMETHOD);
+ icalproperty_method which_method;
+ which_method = GetTemplateTokenNumber(Target, TP, 2, ICAL_METHOD_X);
+ return *the_method == which_method;
+}
@@ -105,7 +372,45 @@ void CreateIcalComponendKindLookup(void)
+void tmplput_Conflict(StrBuf *Target, WCTemplputParams *TP)
+{}
+HashList* IterateGetAttendees()
+{
+/*
+ /* If the component has attendees, iterate through them. * /
+ for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY);
+ (p != NULL);
+ p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) {
+ StrBufAppendPrintf(Target, "