X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fical_subst.c;h=adb923882994665fdf53883134a02ebc672ccf77;hb=HEAD;hp=1690b4b262658994fdd7dbf77dc7273d42740577;hpb=2439b9cc9db4404cc04400ef337a9b37c7aae581;p=citadel.git diff --git a/webcit/ical_subst.c b/webcit/ical_subst.c index 1690b4b26..adb923882 100644 --- a/webcit/ical_subst.c +++ b/webcit/ical_subst.c @@ -20,64 +20,8 @@ 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; - void *vCal; - const char *Key; - long KLen; - IcalEnumMap *SortMap[10]; - IcalEnumMap *Map; - void *vSort; - const char *Next = NULL; - const StrBuf *SortVector; - StrBuf *SortBy; - int i = 0; - HashPos *It; - - SortVector = SBSTR("ICALSortVec"); - if (SortVector == NULL) - return; - - for (i = 0; i < 10; i++) SortMap[i] = NULL; - SortBy = NewStrBuf(); - while (StrBufExtract_NextToken(SortBy, SortVector, &Next, ':') > 0) { - GetHash(IcalComponentMap, SKEY(SortBy), &vSort); - Map = (IcalEnumMap*) vSort; - SortMap[i] = Map; - i++; - if (i > 9) - break; - } - - if (i == 0) - return; - - switch (SortMap[i - 1]->map) { - /* case */ - - default: - break; - } - - It = GetNewHashPos(Cals, 0); - while (GetNextHashPos(Cals, It, &KLen, &Key, &vCal)) { - i = 0; - Cal = (disp_cal*) vCal; - Cal->Status = icalcomponent_get_status(Cal->cal); - Cal->SortBy = Cal->cal; - - - while ((SortMap[i] != NULL) && - (Cal->SortBy != NULL)) - { - /****Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map); */ - } - } -} -#endif - +CtxType CTX_ICALATTENDEE = CTX_NONE; +CtxType CTX_ICALCONFLICT = CTX_NONE; void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP) { @@ -157,34 +101,31 @@ int cond_ICalHaveTimeItem(StrBuf *Target, WCTemplputParams *TP) icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); icalproperty *p; icalproperty_kind Kind; - struct icaltimetype tt; Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY); - - p = icalcomponent_get_first_property(cal, Kind); if (p != NULL) { struct icaltimetype *t; - time_t ttt; + struct icaltimetype tt; WCTemplputParams *DynamicTP; DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams) + sizeof(struct icaltimetype)); - t = (struct icaltimetype *) ((char*)DynamicTP) + sizeof(WCTemplputParams); + t = (struct icaltimetype *) &DynamicTP[1]; + memset(&tt, 0, sizeof(struct icaltimetype)); switch (Kind) { case ICAL_DTSTART_PROPERTY: - *t = icalproperty_get_dtstart(p); + tt = icalproperty_get_dtstart(p); break; case ICAL_DTEND_PROPERTY: tt = icalproperty_get_dtend(p); - ttt = icaltime_as_timet(tt); break; default: - memset(t, 0, sizeof(struct icaltimetype)); break; } - + memcpy(t, &tt, sizeof(struct icaltimetype)); + StackDynamicContext (TP, DynamicTP, t, @@ -268,14 +209,17 @@ void tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP) -void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset) +void render_MIME_ICS_TPL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset) { + wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH); icalproperty_method the_method = ICAL_METHOD_NONE; icalproperty *method = NULL; - icalcomponent *cal; - icalcomponent *c; + icalcomponent *cal = NULL; + icalcomponent *c = NULL; WCTemplputParams SubTP; - WCTemplputParams SubSubTP; + WCTemplputParams SuperTP; + + static int divcount = 0; if (StrLength(Mime->Data) == 0) { MimeLoadData(Mime); @@ -289,31 +233,42 @@ void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun return; } + putlbstr("divname", ++divcount); + + + putbstr("cal_partnum", NewStrBufDup(Mime->PartNum)); + putlbstr("msgnum", Mime->msgnum); + memset(&SubTP, 0, sizeof(WCTemplputParams)); - memset(&SubSubTP, 0, sizeof(WCTemplputParams)); - SubTP.Filter.ContextType = CTX_ICAL; + 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; - SubTP.Context = c; - method = icalcomponent_get_first_property(c, ICAL_METHOD_PROPERTY); + method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY); if (method != NULL) { the_method = icalproperty_get_method(method); } - StackContext (&SubTP, - &SubSubTP, + StackContext (TP, + &SuperTP, &the_method, CTX_ICALMETHOD, 0, - SubTP.Tokens); + TP->Tokens); + + StackContext (&SuperTP, + &SubTP, + c, + CTX_ICAL, + 0, + SuperTP.Tokens); FlushStrBuf(Mime->Data); - DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP); +/// DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP); + DoTemplate(HKEY("ical_edit"), Mime->Data, &SubTP); /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */ @@ -325,7 +280,8 @@ void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun "EnableOrDisableCheckButton(); \n" ); - UnStackContext(&SubSubTP); + UnStackContext(&SuperTP); + UnStackContext(&SubTP); icalcomponent_free(cal); } void CreateIcalComponendKindLookup(void) @@ -360,18 +316,174 @@ 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, 3, ICAL_METHOD_X); + which_method = GetTemplateTokenNumber(Target, TP, 2, ICAL_METHOD_X); return *the_method == which_method; } +typedef struct CalendarConflict +{ + long is_update; + long existing_msgnum; + StrBuf *conflict_event_uid; + StrBuf *conflict_event_summary; +}CalendarConflict; +void DeleteConflict(void *vConflict) +{ + CalendarConflict *c = (CalendarConflict *) vConflict; + FreeStrBuf(&c->conflict_event_uid); + FreeStrBuf(&c->conflict_event_summary); + free(c); +} +HashList *iterate_FindConflict(StrBuf *Target, WCTemplputParams *TP) +{ + StrBuf *Line; + HashList *Conflicts = NULL; + CalendarConflict *Conflict; + wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH); + + serv_printf("ICAL conflicts|%ld|%s|", Mime->msgnum, ChrPtr(Mime->PartNum)); + + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + if (GetServerStatus(Line, NULL) == 1) + { + const char *Pos = NULL; + int Done = 0; + int n = 0; + Conflicts = NewHash(1, Flathash); + while(!Done && (StrBuf_ServGetln(Line) >= 0) ) + if ( (StrLength(Line)==3) && + !strcmp(ChrPtr(Line), "000")) + { + Done = 1; + } + else { + Conflict = (CalendarConflict *) malloc(sizeof(CalendarConflict)); + Conflict->conflict_event_uid = NewStrBufPlain(NULL, StrLength(Line)); + Conflict->conflict_event_summary = NewStrBufPlain(NULL, StrLength(Line)); + + Conflict->existing_msgnum = StrBufExtractNext_long(Line, &Pos, '|'); + StrBufSkip_NTokenS(Line, &Pos, '|', 1); + StrBufExtract_NextToken(Conflict->conflict_event_uid, Line, &Pos, '|'); + StrBufExtract_NextToken(Conflict->conflict_event_summary, Line, &Pos, '|'); + Conflict->is_update = StrBufExtractNext_long(Line, &Pos, '|'); + + Put(Conflicts, IKEY(n), Conflict, DeleteConflict); + n++; + Pos = NULL; + } + } + FreeStrBuf(&Line); + syslog(LOG_DEBUG, "...done.\n"); + return Conflicts; +} +void tmplput_ConflictEventMsgID(StrBuf *Target, WCTemplputParams *TP) +{ + CalendarConflict *C = (CalendarConflict *) CTX(CTX_ICALCONFLICT); + char buf[sizeof(long) * 16]; + + snprintf(buf, sizeof(buf), "%ld", C->existing_msgnum); + StrBufAppendTemplateStr(Target, TP, buf, 0); +} +void tmplput_ConflictEUID(StrBuf *Target, WCTemplputParams *TP) +{ + CalendarConflict *C = (CalendarConflict *) CTX(CTX_ICALCONFLICT); + + StrBufAppendTemplate(Target, TP, C->conflict_event_uid, 0); +} +void tmplput_ConflictSummary(StrBuf *Target, WCTemplputParams *TP) +{ + CalendarConflict *C = (CalendarConflict *) CTX(CTX_ICALCONFLICT); + + StrBufAppendTemplate(Target, TP, C->conflict_event_summary, 0); +} +int cond_ConflictIsUpdate(StrBuf *Target, WCTemplputParams *TP) +{ + CalendarConflict *C = (CalendarConflict *) CTX(CTX_ICALCONFLICT); + return C->is_update; +} +typedef struct CalAttendee +{ + StrBuf *AttendeeStr; + icalparameter_partstat partstat; +} CalAttendee; + +void DeleteAtt(void *vAtt) +{ + CalAttendee *att = (CalAttendee*) vAtt; + FreeStrBuf(&att->AttendeeStr); + free(vAtt); +} + +HashList *iterate_get_ical_attendees(StrBuf *Target, WCTemplputParams *TP) +{ + icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); + icalparameter *partstat_param; + icalproperty *p; + CalAttendee *Att; + HashList *Attendees = NULL; + const char *ch; + int n = 0; + + /* 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)) { + ch = icalproperty_get_attendee(p); + if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) { + Att = (CalAttendee*) malloc(sizeof(CalAttendee)); + + /** screen name or email address */ + Att->AttendeeStr = NewStrBufPlain(ch + 7, -1); + StrBufTrim(Att->AttendeeStr); + + /** participant status */ + partstat_param = icalproperty_get_first_parameter( + p, + ICAL_PARTSTAT_PARAMETER + ); + if (partstat_param == NULL) { + Att->partstat = ICAL_PARTSTAT_X; + } + else { + Att->partstat = icalparameter_get_partstat(partstat_param); + } + if (Attendees == NULL) + Attendees = NewHash(1, Flathash); + Put(Attendees, IKEY(n), Att, DeleteAtt); + n++; + } + } + return Attendees; +} +void tmplput_ICalAttendee(StrBuf *Target, WCTemplputParams *TP) +{ + CalAttendee *Att = (CalAttendee*) CTX(CTX_ICALATTENDEE); + StrBufAppendTemplate(Target, TP, Att->AttendeeStr, 0); +} +int cond_ICalAttendeeState(StrBuf *Target, WCTemplputParams *TP) +{ + CalAttendee *Att = (CalAttendee*) CTX(CTX_ICALATTENDEE); + icalparameter_partstat which_partstat; + which_partstat = GetTemplateTokenNumber(Target, TP, 2, ICAL_PARTSTAT_X); + return Att->partstat == which_partstat; +} + /* If the component has subcomponents, recurse through them. * / + for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); + (c != 0); + c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) { + // Recursively process subcomponent + cal_process_object(Target, c, recursion_level+1, msgnum, cal_partnum); + } + */ void @@ -379,15 +491,30 @@ InitModule_ICAL_SUBST (void) { RegisterCTX(CTX_ICAL); -//* +/* RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS_TPL, 1, 501); RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS_TPL, 1, 500); -//*/ +*/ CreateIcalComponendKindLookup (); RegisterConditional("COND:ICAL:PROPERTY", 1, cond_ICalHaveItem, CTX_ICAL); RegisterConditional("COND:ICAL:IS:A", 1, cond_ICalIsA, CTX_ICAL); + + RegisterIterator("ICAL:CONFLICT", 0, NULL, iterate_FindConflict, + NULL, DeleteHash, CTX_MIME_ATACH, CTX_ICALCONFLICT, IT_NOFLAG); + RegisterNamespace("ICAL:CONFLICT:MSGID", 0, 1, tmplput_ConflictEventMsgID, NULL, CTX_ICALCONFLICT); + RegisterNamespace("ICAL:CONFLICT:EUID", 0, 1, tmplput_ConflictEUID, NULL, CTX_ICALCONFLICT); + RegisterNamespace("ICAL:CONFLICT:SUMMARY", 0, 1, tmplput_ConflictSummary, NULL, CTX_ICALCONFLICT); + RegisterConditional("ICAL:CONFLICT:IS:UPDATE", 0, cond_ConflictIsUpdate, CTX_ICALCONFLICT); + + + RegisterCTX(CTX_ICALATTENDEE); + RegisterIterator("ICAL:ATTENDEES", 0, NULL, iterate_get_ical_attendees, + NULL, DeleteHash, CTX_ICALATTENDEE, CTX_ICAL, IT_NOFLAG); + RegisterNamespace("ICAL:ATTENDEE", 1, 2, tmplput_ICalAttendee, NULL, CTX_ICALATTENDEE); + RegisterConditional("COND:ICAL:ATTENDEE", 1, cond_ICalAttendeeState, CTX_ICALATTENDEE); + RegisterCTX(CTX_ICALPROPERTY); RegisterNamespace("ICAL:ITEM", 1, 2, tmplput_ICalItem, NULL, CTX_ICAL); RegisterNamespace("ICAL:PROPERTY:STR", 0, 1, tmplput_CtxICalProperty, NULL, CTX_ICALPROPERTY); @@ -410,7 +537,3 @@ ServerShutdownModule_ICAL { DeleteHash(&IcalComponentMap); } - - - -