X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=067362a5f6559d428544981cf8c0f4521d9752b1;hb=f638dfd082af857e57f1d3d3fc1b923151fe0c33;hp=448d1ebcff8815e057723786fd560b1d77e67afa;hpb=5e23b16863fae5fd019f9d9d36be11baea256947;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 448d1ebcf..067362a5f 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -15,6 +15,7 @@ #include "calendar.h" CtxType CTX_VCARD = CTX_NONE; +CtxType CTX_VCARD_TYPE = CTX_NONE; long VCEnumCounter = 0; typedef enum _VCStrEnum { @@ -22,6 +23,7 @@ typedef enum _VCStrEnum { StringCluster, PhoneNumber, EmailAddr, + Address, Street, Number, AliasFor, @@ -34,47 +36,48 @@ struct vcField { VCStrEnum Type; vcField *Sub; long cval; + ConstStr Name; }; vcField VCStr_Ns [] = { - {{HKEY("last")}, FlatString, NULL, 0}, - {{HKEY("first")}, FlatString, NULL, 0}, - {{HKEY("middle")}, FlatString, NULL, 0}, - {{HKEY("prefix")}, FlatString, NULL, 0}, - {{HKEY("suffix")}, FlatString, NULL, 0}, - {{HKEY("")}, TerminateList, NULL, 0} + {{HKEY("last")}, FlatString, NULL, 0, {HKEY("Last Name")}}, + {{HKEY("first")}, FlatString, NULL, 0, {HKEY("First Name")}}, + {{HKEY("middle")}, FlatString, NULL, 0, {HKEY("Middle Name")}}, + {{HKEY("prefix")}, FlatString, NULL, 0, {HKEY("Prefix")}}, + {{HKEY("suffix")}, FlatString, NULL, 0, {HKEY("Suffix")}}, + {{HKEY("")}, TerminateList, NULL, 0, {HKEY("")}} }; vcField VCStr_Addrs [] = { - {{HKEY("POBox")}, FlatString, NULL, 0}, - {{HKEY("address")}, FlatString, NULL, 0}, - {{HKEY("address2")}, FlatString, NULL, 0}, - {{HKEY("city")}, FlatString, NULL, 0}, - {{HKEY("state")}, FlatString, NULL, 0}, - {{HKEY("zip")}, FlatString, NULL, 0}, - {{HKEY("country")}, FlatString, NULL, 0}, - {{HKEY("")}, TerminateList, NULL, 0} + {{HKEY("POBox")}, Address, NULL, 0, {HKEY("PO box")}}, + {{HKEY("address")}, Address, NULL, 0, {HKEY("Address")}}, + {{HKEY("address2")}, Address, NULL, 0, {HKEY("")}}, + {{HKEY("city")}, Address, NULL, 0, {HKEY("City")}}, + {{HKEY("state")}, Address, NULL, 0, {HKEY("State")}}, + {{HKEY("zip")}, Address, NULL, 0, {HKEY("ZIP code")}}, + {{HKEY("country")}, Address, NULL, 0, {HKEY("Country")}}, + {{HKEY("")}, TerminateList, NULL, 0, {HKEY("")}} }; vcField VCStrE [] = { - {{HKEY("n")}, StringCluster, VCStr_Ns, 0}, /* N is name, but only if there's no FN already there */ - {{HKEY("fn")}, FlatString, NULL, 0}, /* FN (full name) is a true 'display name' field */ - {{HKEY("title")}, FlatString, NULL, 0}, /* title */ - {{HKEY("org")}, FlatString, NULL, 0}, /* organization */ - {{HKEY("email")}, EmailAddr, NULL, 0}, - {{HKEY("tel")}, PhoneNumber, NULL, 0}, - {{HKEY("adr")}, StringCluster, VCStr_Addrs, 0}, - {{HKEY("photo")}, Base64BinaryAttachment, NULL, 0}, - {{HKEY("version")}, Number, NULL, 0}, - {{HKEY("rev")}, Number, NULL, 0}, - {{HKEY("label")}, FlatString, NULL, 0}, - {{HKEY("uid")}, FlatString, NULL, 0}, - {{HKEY("tel;home")}, PhoneNumber, NULL, 0}, - {{HKEY("tel;work")}, PhoneNumber, NULL, 0}, - {{HKEY("tel;fax")}, PhoneNumber, NULL, 0}, - {{HKEY("tel;cell")}, PhoneNumber, NULL, 0}, - {{HKEY("email;internet")}, EmailAddr, NULL, 0}, - {{HKEY("")}, TerminateList, NULL, 0} + {{HKEY("version")}, Number, NULL, 0, {HKEY("")}}, + {{HKEY("rev")}, Number, NULL, 0, {HKEY("")}}, + {{HKEY("label")}, FlatString, NULL, 0, {HKEY("")}}, + {{HKEY("uid")}, FlatString, NULL, 0, {HKEY("")}}, + {{HKEY("n")}, StringCluster, VCStr_Ns, 0, {HKEY("")}}, /* N is name, but only if there's no FN already there */ + {{HKEY("fn")}, FlatString, NULL, 0, {HKEY("")}}, /* FN (full name) is a true 'display name' field */ + {{HKEY("title")}, FlatString, NULL, 0, {HKEY("Title:")}}, + {{HKEY("org")}, FlatString, NULL, 0, {HKEY("Organization:")}},/* organization */ + {{HKEY("email")}, EmailAddr, NULL, 0, {HKEY("E-mail:")}}, + {{HKEY("tel")}, PhoneNumber, NULL, 0, {HKEY("Telephone:")}}, + {{HKEY("adr")}, StringCluster, VCStr_Addrs, 0, {HKEY("Address:")}}, + {{HKEY("photo")}, Base64BinaryAttachment, NULL, 0, {HKEY("Photo:")}}, + {{HKEY("tel;home")}, PhoneNumber, NULL, 0, {HKEY(" (home)")}}, + {{HKEY("tel;work")}, PhoneNumber, NULL, 0, {HKEY(" (work)")}}, + {{HKEY("tel;fax")}, PhoneNumber, NULL, 0, {HKEY(" (fax)")}}, + {{HKEY("tel;cell")}, PhoneNumber, NULL, 0, {HKEY(" (cell)")}}, + {{HKEY("email;internet")}, EmailAddr, NULL, 0, {HKEY("E-mail:")}}, + {{HKEY("")}, TerminateList, NULL, 0, {HKEY("")}} }; ConstStr VCStr [] = { @@ -100,11 +103,15 @@ ConstStr VCStr [] = { HashList *DefineToToken = NULL; HashList *VCTokenToDefine = NULL; HashList *vcNames = NULL; /* todo: fill with the name strings */ + + void RegisterVCardToken(vcField* vf, StrBuf *name, int inTokenCount) { RegisterTokenParamDefine(SKEY(name), vf->cval); Put(DefineToToken, LKEY(vf->cval), vf, reference_free_handler); - syslog(LOG_DEBUG, "Token: %s -> %d, %d", + Put(vcNames, LKEY(vf->cval), NewStrBufPlain(CKEY(vf->Name)), HFreeStrBuf); + + syslog(LOG_DEBUG, "Token: %s -> %ld, %d", ChrPtr(name), vf->cval, inTokenCount); @@ -114,8 +121,9 @@ void RegisterVCardToken(vcField* vf, StrBuf *name, int inTokenCount) void autoRegisterTokens(long *enumCounter, vcField* vf, StrBuf *BaseStr, int layer) { int i = 0; + StrBuf *subStr = NewStrBuf(); while (vf[i].STR.len > 0) { - StrBuf *subStr = NewStrBuf(); + FlushStrBuf(subStr); vf[i].cval = (*enumCounter) ++; StrBufAppendBuf(subStr, BaseStr, 0); if (StrLength(subStr) > 0) { @@ -149,10 +157,13 @@ void autoRegisterTokens(long *enumCounter, vcField* vf, StrBuf *BaseStr, int lay break; case TerminateList: break; + case Address: + break; } RegisterVCardToken(&vf[i], subStr, i); i++; } + FreeStrBuf(&subStr); } int preeval_vcard_item(WCTemplateToken *Token) @@ -184,6 +195,26 @@ void tmpl_vcard_item(StrBuf *Target, WCTemplputParams *TP) } } +void tmpl_vcard_context_item(StrBuf *Target, WCTemplputParams *TP) +{ + void *vItem; + vcField *t = (vcField*) CTX(CTX_VCARD_TYPE); + HashList *vc = (HashList*) CTX(CTX_VCARD); + + if (t == NULL) { + LogTemplateError(NULL, "VCard item", ERR_NAME, TP, + "Missing context"); + return; + } + + if (GetHash(vc, LKEY(t->cval), &vItem) && (vItem != NULL)) { + StrBufAppendTemplate(Target, TP, (StrBuf*) vItem, 0); + } + else { + LogTemplateError(NULL, "VCard item", ERR_NAME, TP, + "Doesn't have that key - did you miss to filter in advance?"); + } +} int preeval_vcard_name_str(WCTemplateToken *Token) { WCTemplputParams TPP; @@ -211,9 +242,115 @@ void tmpl_vcard_name_str(StrBuf *Target, WCTemplputParams *TP) if (GetHash(vcNames, LKEY(searchFieldNo), &vItem) && (vItem != NULL)) { StrBufAppendTemplate(Target, TP, (StrBuf*) vItem, 1); } + else { + LogTemplateError(NULL, "VCard item type", ERR_NAME, TP, + "No i18n string for this."); + return; + } +} + +void tmpl_vcard_context_name_str(StrBuf *Target, WCTemplputParams *TP) +{ + void *vItem; + vcField *t = (vcField*) CTX(CTX_VCARD_TYPE); + + if (t == NULL) { + LogTemplateError(NULL, "VCard item type", ERR_NAME, TP, + "Missing context"); + return; + } + + if (GetHash(vcNames, LKEY(t->cval), &vItem) && (vItem != NULL)) { + StrBufAppendTemplate(Target, TP, (StrBuf*) vItem, 1); + } + else { + LogTemplateError(NULL, "VCard item type", ERR_NAME, TP, + "No i18n string for this."); + return; + } +} + +int filter_VC_ByType(const char* key, long len, void *Context, StrBuf *Target, WCTemplputParams *TP) +{ + long searchType; + long type = 0; + void *v; + int rc = 0; + vcField *vf = (vcField*) Context; + + memcpy(&type, key, sizeof(long)); + searchType = GetTemplateTokenNumber(Target, TP, IT_ADDT_PARAM(0), 0); + + if (vf->Type == searchType) { + HashList *vc = (HashList*) CTX(CTX_VCARD); + if (GetHash(vc, LKEY(vf->cval), &v) && v != NULL) + return 1; + } + return rc; } + + +HashList *getContextVcard(StrBuf *Target, WCTemplputParams *TP) +{ + vcField *vf = (vcField*) CTX(CTX_VCARD_TYPE); + HashList *vc = (HashList*) CTX(CTX_VCARD); + + if ((vf == NULL) || (vc == NULL)) { + LogTemplateError(NULL, "VCard item type", ERR_NAME, TP, + "Need VCard and Vcard type in context"); + + return NULL; + } + return vc; +} + +int filter_VC_ByContextType(const char* key, long len, void *Context, StrBuf *Target, WCTemplputParams *TP) +{ + long searchType; + vcField *vf = (vcField*) CTX(CTX_VCARD_TYPE); + + memcpy(&searchType, key, sizeof(long)); + + if (vf->cval == searchType) { + return 1; + } + else { + return 0; + } +} + + +int conditional_VC_Havetype(StrBuf *Target, WCTemplputParams *TP) +{ + HashList *vc = (HashList*) CTX(CTX_VCARD); + long HaveFieldType = GetTemplateTokenNumber(Target, TP, 2, 0); + int rc = 0; + void *vVCitem; + const char *Key; + long len; + HashPos *it = GetNewHashPos(vc, 0); + while (GetNextHashPos(vc, it, &len, &Key, &vVCitem) && + (vVCitem != NULL)) + { + void *vvcField; + long type = 0; + memcpy(&type, Key, sizeof(long)); + if (GetHash(DefineToToken, LKEY(type), &vvcField) && + (vvcField != NULL)) + { + vcField *t = (vcField*) vvcField; + if (t && t->Type == HaveFieldType) { + rc = 1; + break; + } + } + } + DeleteHashPos(&it); + return rc; +} + /* * Record compare function for sorting address book indices */ @@ -436,265 +573,8 @@ void fetchname_parsed_vcard(struct vCard *v, char **storename) { -/* - * html print a vcard - * display_vcard() calls this after parsing the textual vCard into - * our 'struct vCard' data object. - * - * Set 'full' to nonzero to display the full card, otherwise it will only - * show a summary line. - * - * This code is a bit ugly, so perhaps an explanation is due: we do this - * in two passes through the vCard fields. On the first pass, we process - * fields we understand, and then render them in a pretty fashion at the - * end. Then we make a second pass, outputting all the fields we don't - * understand in a simple two-column name/value format. - * v the vCard to display - * full display all items of the vcard? - * msgnum Citadel message pointer - */ -void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime) -{ - int i, j; - char buf[SIZ]; - char *name; - int is_qp = 0; - int is_b64 = 0; - char *thisname, *thisvalue; - char firsttoken[SIZ]; - int pass; - - char fullname[SIZ]; - char title[SIZ]; - char org[SIZ]; - char phone[SIZ]; - char mailto[SIZ]; - - strcpy(fullname, ""); - strcpy(phone, ""); - strcpy(mailto, ""); - strcpy(title, ""); - strcpy(org, ""); - - if (!full) { - StrBufAppendPrintf(Target, "
"); - StrBufAppendPrintf(Target, _("Address:")); - StrBufAppendPrintf(Target, " | ");
- for (j=0; j | \n");
- }
- }
- /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
- // Only output on second pass
- StrBufAppendPrintf(Target, "
"); - StrBufAppendPrintf(Target, _("Photo:")); - StrBufAppendPrintf(Target, " | "); - StrBufAppendPrintf(Target, "",msgnum); - StrBufAppendPrintf(Target, " |
"); - StrEscAppend(Target, NULL, thisname, 0, 0); - StrBufAppendPrintf(Target, " | "); - StrEscAppend(Target, NULL, thisvalue, 0, 0); - StrBufAppendPrintf(Target, " |
"
- ""
- "");
- StrEscAppend(Target, NULL, fullname, 0, 0);
- StrBufAppendPrintf(Target, "");
- if (!IsEmptyStr(title)) {
- StrBufAppendPrintf(Target, " \"");
- StrEscAppend(Target, NULL, title, 0, 0);
- StrBufAppendPrintf(Target, " ");
- }
- if (!IsEmptyStr(org)) {
- StrBufAppendPrintf(Target, "");
- StrEscAppend(Target, NULL, org, 0, 0);
- StrBufAppendPrintf(Target, " ");
- }
- StrBufAppendPrintf(Target, " | |
"); - StrBufAppendPrintf(Target, _("Telephone:")); - StrBufAppendPrintf(Target, " | %s |
"); - StrBufAppendPrintf(Target, _("E-mail:")); - StrBufAppendPrintf(Target, " | %s |