]> code.citadel.org Git - citadel.git/blobdiff - webcit/vcard_edit.c
found the bug! fixed it!
[citadel.git] / webcit / vcard_edit.c
index 09d63f81ca8ef3a55752aefbfcd68840e5834291..3a05145ba88b4e5732a8358ce3814ec35b87748d 100644 (file)
@@ -145,8 +145,7 @@ void RegisterVCardToken(vcField * vf, StrBuf * name, int inTokenCount)
        Put(vcNames, LKEY(vf->cval), NewStrBufPlain(CKEY(vf->Name)),
            HFreeStrBuf);
 
-       syslog(LOG_DEBUG, "Token: %s -> %ld, %d",
-              ChrPtr(name), vf->cval, inTokenCount);
+       syslog(LOG_DEBUG, "Token: %s -> %ld, %d", ChrPtr(name), vf->cval, inTokenCount);
 
 }
 
@@ -165,16 +164,14 @@ void autoRegisterTokens(long *enumCounter, vcField * vf, StrBuf * BaseStr,
                }
                StrBufAppendBufPlain(subStr, CKEY(vf[i].STR), 0);
                if (layer == 0) {
-                       Put(VCTokenToDefine, CKEY(vf[i].STR), &vf[i],
-                           reference_free_handler);
+                       Put(VCTokenToDefine, CKEY(vf[i].STR), &vf[i], reference_free_handler);
                }
                switch (vf[i].Type) {
                case FlatString:
                        break;
                case StringCluster:
                        {
-                               autoRegisterTokens(enumCounter, vf[i].Sub,
-                                                  subStr, 1, vf[i].cval);
+                               autoRegisterTokens(enumCounter, vf[i].Sub, subStr, 1, vf[i].cval);
                        }
                        break;
                case PhoneNumber:
@@ -218,8 +215,7 @@ int preeval_vcard_item(WCTemplateToken * Token)
        TP->Tokens = Token;
        searchFieldNo = GetTemplateTokenNumber(Target, TP, 0, 0);
        if (searchFieldNo >= VCEnumCounter) {
-               LogTemplateError(NULL, "VCardItem", ERR_PARM1, TP,
-                                "Invalid define");
+               LogTemplateError(NULL, "VCardItem", ERR_PARM1, TP, "Invalid define");
                return 0;
        }
        return 1;
@@ -230,8 +226,7 @@ void tmpl_vcard_item(StrBuf * Target, WCTemplputParams * TP)
        void *vItem;
        long searchFieldNo = GetTemplateTokenNumber(Target, TP, 0, 0);
        addrbookent *ab = (addrbookent *) CTX(CTX_VCARD);
-       if (GetHash(ab->VC, LKEY(searchFieldNo), &vItem)
-           && (vItem != NULL)) {
+       if (GetHash(ab->VC, LKEY(searchFieldNo), &vItem) && (vItem != NULL)) {
                StrBufAppendTemplate(Target, TP, (StrBuf *) vItem, 1);
        }
 }
@@ -243,16 +238,14 @@ void tmpl_vcard_context_item(StrBuf * Target, WCTemplputParams * TP)
        addrbookent *ab = (addrbookent *) CTX(CTX_VCARD);
 
        if (t == NULL) {
-               LogTemplateError(NULL, "VCard item", ERR_NAME, TP,
-                                "Missing context");
+               LogTemplateError(NULL, "VCard item", ERR_NAME, TP, "Missing context");
                return;
        }
 
        if (GetHash(ab->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?");
+               LogTemplateError(NULL, "VCard item", ERR_NAME, TP, "Doesn't have that key - did you miss to filter in advance?");
        }
 }
 
@@ -279,8 +272,7 @@ void tmpl_vcard_name_str(StrBuf * Target, WCTemplputParams * TP)
        void *vItem;
        long searchFieldNo = GetTemplateTokenNumber(Target, TP, 0, 0);
        /* todo: get descriptive string for this vcard type */
-       if (GetHash(vcNames, LKEY(searchFieldNo), &vItem)
-           && (vItem != NULL)) {
+       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.");
@@ -325,13 +317,13 @@ int filter_VC_ByType(const char *key, long len, void *Context, StrBuf * Target,
        vcField *vf = (vcField *) Context;
 
        memcpy(&type, key, sizeof(long));
-       searchType =
-           GetTemplateTokenNumber(Target, TP, IT_ADDT_PARAM(0), 0);
+       searchType = GetTemplateTokenNumber(Target, TP, IT_ADDT_PARAM(0), 0);
 
        if (vf->Type == searchType) {
                addrbookent *ab = (addrbookent *) CTX(CTX_VCARD);
-               if (GetHash(ab->VC, LKEY(vf->cval), &v) && v != NULL)
+               if (GetHash(ab->VC, LKEY(vf->cval), &v) && v != NULL) {
                        return 1;
+               }
        }
        return rc;
 }
@@ -343,7 +335,6 @@ HashList *getContextVcard(StrBuf * Target, WCTemplputParams * TP)
 
        if ((vf == NULL) || (ab == NULL)) {
                LogTemplateError(NULL, "VCard item type", ERR_NAME, TP, "Need VCard and Vcard type in context");
-
                return NULL;
        }
        return ab->VC;
@@ -372,8 +363,7 @@ int conditional_VC_Havetype(StrBuf * Target, WCTemplputParams * TP)
        const char *Key;
        long len;
        HashPos *it = GetNewHashPos(ab->VC, 0);
-       while (GetNextHashPos(ab->VC, it, &len, &Key, &vVCitem) &&
-              (vVCitem != NULL)) {
+       while (GetNextHashPos(ab->VC, it, &len, &Key, &vVCitem) && (vVCitem != NULL)) {
                void *vvcField;
                long type = 0;
                memcpy(&type, Key, sizeof(long));
@@ -426,17 +416,14 @@ void parse_vcard(StrBuf * Target, struct vCard *v, HashList * VC, wc_mime_attach
                FlushStrBuf(thisVCToken);
                is_qp = 0;
                is_b64 = 0;
-               syslog(LOG_DEBUG, "i: %d oneprop: %s - value: %s", i, v->prop[i].name, v->prop[i].value);
+               // syslog(LOG_DEBUG, "i: %d oneprop: %s - value: %s", i, v->prop[i].name, v->prop[i].value);
                StrBufPlain(thisname, v->prop[i].name, -1);
                StrBufLowerCase(thisname);
 
-               extract_token(firsttoken, ChrPtr(thisname), 0, ';',
-                             sizeof firsttoken);
+               extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
                ntokens = num_tokens(ChrPtr(thisname), ';');
                for (j = 0, k = 0; j < ntokens && k < 10; ++j) {
-                       len =
-                           extract_token(buf, ChrPtr(thisname), j, ';',
-                                         sizeof buf);
+                       len = extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
                        if (!strcasecmp(buf, "encoding=quoted-printable")) {
                                is_qp = 1;
                        } else if (!strcasecmp(buf, "encoding=base64")) {
@@ -455,7 +442,7 @@ void parse_vcard(StrBuf * Target, struct vCard *v, HashList * VC, wc_mime_attach
                    (vField != NULL)) {
                        vcField *thisField = (vcField *) vField;
                        StrBuf *ThisFieldStr = NULL;
-                       syslog(LOG_DEBUG, "got this token: %s, found: %s", ChrPtr(thisVCToken), thisField->STR.Key);
+                       // syslog(LOG_DEBUG, "got this token: %s, found: %s", ChrPtr(thisVCToken), thisField->STR.Key);
                        switch (thisField->Type) {
                        case StringCluster:{
                                        int j = 0;
@@ -606,10 +593,10 @@ wc_mime_attachment *load_vcard(message_summary * Msg)
  * to start with a blank card.
  */
 void do_edit_vcard(long msgnum, char *partnum,
-                  message_summary * VCMsg,
-                  wc_mime_attachment * VCAtt,
-                  const char *return_to, const char *force_room)
-{
+       message_summary * VCMsg,
+       wc_mime_attachment * VCAtt,
+       const char *return_to, const char *force_room
+{
        WCTemplputParams SubTP;
        wcsession *WCC = WC;
        message_summary *Msg = NULL;
@@ -711,19 +698,15 @@ void submit_vcard(void)
        if (havebstr("force_room")) {
                ForceRoom = sbstr("force_room");
                if (gotoroom(ForceRoom) != 200) {
-                       AppendImportantMessage(_
-                                              ("Unable to enter the room to save your message"),
-                                              -1);
+                       AppendImportantMessage(_ ("Unable to enter the room to save your message"), -1);
                        AppendImportantMessage(HKEY(": "));
                        AppendImportantMessage(SKEY(ForceRoom));
                        AppendImportantMessage(HKEY("; "));
                        AppendImportantMessage(_("Aborting."), -1);
 
-                       if (!strcmp
-                           (bstr("return_to"), "select_user_to_edit")) {
+                       if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
                                select_user_to_edit(NULL);
-                       } else
-                           if (!strcmp(bstr("return_to"), "do_welcome")) {
+                       } else if (!strcmp(bstr("return_to"), "do_welcome")) {
                                do_welcome();
                        } else if (!IsEmptyStr(bstr("return_to"))) {
                                http_redirect(bstr("return_to"));
@@ -749,9 +732,7 @@ void submit_vcard(void)
        }
 
        /* Make a vCard structure out of the data supplied in the form */
-       StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
-                    bstr("extrafields")
-           );
+       StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n", bstr("extrafields"));
        v = VCardLoad(Buf);     /* Start with the extra fields */
        if (v == NULL) {
                AppendImportantMessage(_("An error has occurred."), -1);
@@ -772,27 +753,17 @@ void submit_vcard(void)
                        vcField *Sub;
                        FlushStrBuf(SubStr);
                        itSub = GetNewHashPos(DefineToToken, 0);
-                       while (GetNextHashPos
-                              (DefineToToken, itSub, &len, &Key, &pv)
-                              && (pv != NULL)) {
+                       while (GetNextHashPos (DefineToToken, itSub, &len, &Key, &pv) && (pv != NULL)) {
                                Sub = (vcField *) pv;
                                if (Sub->parentCVal == t->cval) {
-                                       if (StrLength(SubStr) > 0)
-                                               StrBufAppendBufPlain
-                                                   (SubStr, HKEY(";"), 0);
-
-
-
-                                       blen =
-                                           snprintf(buf, sizeof(buf),
-                                                    "%ld", Sub->cval);
+                                       if (StrLength(SubStr) > 0) {
+                                               StrBufAppendBufPlain (SubStr, HKEY(";"), 0);
+                                       }
+                                       blen = snprintf(buf, sizeof(buf), "%ld", Sub->cval);
                                        s = SSubBstr(postVcard, buf, blen);
-
-                                       if ((s != NULL)
-                                           && (StrLength(s) > 0)) {
+                                       if ((s != NULL) && (StrLength(s) > 0)) {
                                                /// todo: utf8 qp
-                                               StrBufAppendBuf(SubStr, s,
-                                                               0);
+                                               StrBufAppendBuf(SubStr, s, 0);
                                        }
                                }
                        }
@@ -815,11 +786,9 @@ void submit_vcard(void)
        s = sbstr("other_inetemail");
        if (StrLength(s) > 0) {
                FlushStrBuf(SubStr);
-               while (StrBufSipLine(SubStr, s, &Pos),
-                      ((Pos != StrBufNOTNULL) && (Pos != NULL))) {
+               while (StrBufSipLine(SubStr, s, &Pos), ((Pos != StrBufNOTNULL) && (Pos != NULL))) {
                        if (StrLength(SubStr) > 0) {
-                               vcard_add_prop(v, "email;internet",
-                                              ChrPtr(SubStr));
+                               vcard_add_prop(v, "email;internet", ChrPtr(SubStr));
                        }
                }
        }
@@ -881,8 +850,7 @@ int vcard_GetParamsGetServerCall(SharedMessageStatus * Stat,
        if (VS->is_singlecard != 1) {
                VS->addrbook = NewHash(0, NULL);
                if (oper == do_search) {
-                       snprintf(cmd, len, "MSGS SEARCH|%s",
-                                bstr("query"));
+                       snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
                } else {
                        strcpy(cmd, "MSGS ALL");
                }
@@ -924,17 +892,15 @@ int vcard_LoadMsgFromServer(SharedMessageStatus * Stat,
 
        memset(&SubTP, 0, sizeof(WCTemplputParams));
        StackContext(TP, &SubTP, abEntry, CTX_VCARD, 0, NULL);
-
-       // No, don't display the name, it just shits all over the screen
-       // FIXME AJC WORKING IN HERE RIGHT NOW
-       // DoTemplate(HKEY("vcard_list_name"), WCC->WBuf, &SubTP);
-
+       DoTemplate(HKEY("vcard_list_name"), abEntry->name, &SubTP);             // this puts the indexable contact name in abEntry->name for later sorting/display
        UnStackContext(&SubTP);
 
        if (StrLength(abEntry->name) == 0) {
                StrBufPlain(abEntry->name, _("(no name)"), -1);
        }
 
+       syslog(LOG_DEBUG, "abEntry->name : %s", ChrPtr(abEntry->name));
+
        vcard_free(v);
 
        Put(VS->addrbook, SKEY(abEntry->name), abEntry, deleteAbEnt);
@@ -995,19 +961,14 @@ void do_addrbook_view(vcardview_struct * VS)
                if (tablast > (num_ab - 1))
                        tablast = (num_ab - 1);
 
-               headline =
-                   NewStrBufPlain(NULL,
-                                  StrLength(v1) + StrLength(v2) + 10);
+               headline = NewStrBufPlain(NULL, StrLength(v1) + StrLength(v2) + 10);
                if (GetHashAt(VS->addrbook, tabfirst, &hklen1, &c1, &v1)) {
                        a1 = (addrbookent *) v1;
                        StrBufAppendBuf(headline, a1->name, 0);
                        StrBuf_Utf8StrCut(headline, 3);
-                       if (GetHashAt
-                           (VS->addrbook, tablast, &hklen2, &c2, &v2)) {
-
+                       if (GetHashAt(VS->addrbook, tablast, &hklen2, &c2, &v2)) {
                                a2 = (addrbookent *) v2;
-                               StrBufAppendBufPlain(headline, HKEY(" - "),
-                                                    0);
+                               StrBufAppendBufPlain(headline, HKEY(" - "), 0);
                                StrBufAppendBuf(headline, a2->name, 0);
                                StrBuf_Utf8StrCut(headline, 9);
                        }
@@ -1026,19 +987,18 @@ void do_addrbook_view(vcardview_struct * VS)
 }
 
 
-
-int vcard_RenderView_or_Tail(SharedMessageStatus * Stat,
-                            void **ViewSpecific, long oper)
+int vcard_RenderView_or_Tail(SharedMessageStatus * Stat, void **ViewSpecific, long oper)
 {
        const StrBuf *Mime;
        vcardview_struct *VS;
 
        VS = (vcardview_struct *) * ViewSpecific;
-       if (VS->is_singlecard)
-               read_message(WC->WBuf, HKEY("view_message"),
-                            lbstr("startmsg"), NULL, &Mime, NULL);
-       else
+       if (VS->is_singlecard) {
+               read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime, NULL);
+       }
+       else {
                do_addrbook_view(VS);   /* Render the address book */
+       }
        return 0;
 }
 
@@ -1048,37 +1008,34 @@ int vcard_Cleanup(void **ViewSpecific)
 
        VS = (vcardview_struct *) * ViewSpecific;
        wDumpContent(1);
-       if ((VS != NULL) && (VS->addrbook != NULL))
+       if ((VS != NULL) && (VS->addrbook != NULL)) {
                DeleteHash(&VS->addrbook);
-       if (VS != NULL)
+       }
+       if (VS != NULL) {
                free(VS);
+       }
 
        return 0;
 }
 
-void render_MIME_VCard(StrBuf * Target, WCTemplputParams * TP,
-                      StrBuf * FoundCharset)
+void render_MIME_VCard(StrBuf * Target, WCTemplputParams * TP, StrBuf * FoundCharset)
 {
-       wc_mime_attachment *Mime =
-           (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        wcsession *WCC = WC;
-       if (StrLength(Mime->Data) == 0)
+       if (StrLength(Mime->Data) == 0) {
                MimeLoadData(Mime);
+       }
        if (StrLength(Mime->Data) > 0) {
                struct vCard *v;
                StrBuf *Buf;
 
                Buf = NewStrBuf();
                /* If it's my vCard I can edit it */
-               if ((!strcasecmp
-                    (ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
-                   || ((StrLength(WCC->CurRoom.name) > 11)
-                       &&
-                       (!strcasecmp
-                        (&(ChrPtr(WCC->CurRoom.name)[11]),
-                         USERCONFIGROOM)))
-                   || (WCC->CurRoom.view == VIEW_ADDRESSBOOK)
-                   ) {
+               if (    (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
+                       || ((StrLength(WCC->CurRoom.name) > 11)
+                       && (!strcasecmp (&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM)))
+                       || (WCC->CurRoom.view == VIEW_ADDRESSBOOK)
+               ) {
                        StrBufAppendPrintf(Buf,
                                           "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
                                           Mime->msgnum,
@@ -1104,8 +1061,7 @@ void render_MIME_VCard(StrBuf * Target, WCTemplputParams * TP,
                        memset(&SubTP, 0, sizeof(WCTemplputParams));
                        StackContext(TP, &SubTP, &ab, CTX_VCARD, 0, NULL);
 
-                       DoTemplate(HKEY("vcard_msg_display"), Target,
-                                  &SubTP);
+                       DoTemplate(HKEY("vcard_msg_display"), Target, &SubTP);
                        UnStackContext(&SubTP);
                        DeleteHash(&ab.VC);
                        vcard_free(v);