if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
[citadel.git] / webcit / useredit.c
index 09d10898743c82e5840e893d558252b5662868aa..c76188b4e1e0930bcb39fc44bd46b4040f14583b 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * $Id$
- */
 
 #include "webcit.h"
 #include "webserver.h"
@@ -14,7 +11,7 @@
 void select_user_to_edit(const char *preselect)
 {
        output_headers(1, 0, 0, 0, 1, 0);
-       do_template("edituser_select", NULL);
+       do_template("aide_edituser_select", NULL);
         end_burst();
 }
 
@@ -255,7 +252,7 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP)
 {
        int Done = 0;
        CompareFunc SortIt;
-       HashList *Hash;
+       HashList *Hash = NULL;
        StrBuf *Buf;
        UserListEntry* ul;
        char nnn[64];
@@ -272,8 +269,10 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP)
 
                while (!Done) {
                        len = StrBuf_ServGetln(Buf);
-                       if ((len == 3) &&
-                           (strcmp(ChrPtr(Buf), "000")==0)) {
+                       if ((len <0) || 
+                           ((len == 3) &&
+                            strcmp(ChrPtr(Buf), "000")))
+                       {
                                Done = 1;
                                break;
                        }
@@ -290,10 +289,9 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP)
                        SortByPayload(Hash, SortIt);
                else 
                        SortByPayload(Hash, CompareUID);
-               return Hash;
         }
        FreeStrBuf(&Buf);
-       return NULL;
+       return Hash;
 }
 
 
@@ -392,11 +390,16 @@ int ConditionalFlagINetEmail(StrBuf *Target, WCTemplputParams *TP)
 int ConditionalUserAccess(StrBuf *Target, WCTemplputParams *TP)
 {
        UserListEntry *ul = (UserListEntry*) CTX;
-
-       if (TP->Tokens->Params[3]->Type == TYPE_LONG)
-               return (TP->Tokens->Params[3]->lvalue == ul->AccessLevel);
-       else
+       
+       if (ul == NULL)
                return 0;
+
+       return GetTemplateTokenNumber(Target, 
+                                     TP, 
+                                     3, 
+                                     AxNewU)
+               ==
+               ul->AccessLevel;
 }
 
 /*
@@ -430,7 +433,7 @@ TRYAGAIN:
        Stat.highest_found = (-1);
        Done = 0;
        /* Search for the user's vCard */
-       if (load_msg_ptrs("MSGS ALL||||1", &Stat) > 0) {
+       if (load_msg_ptrs("MSGS ALL||||1", &Stat, NULL) > 0) {
                at = GetNewHashPos(WCC->summ, 0);
                while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
                        Msg = (message_summary*) vMsg;          
@@ -442,7 +445,8 @@ TRYAGAIN:
                        
                        if (Msg->AllAttach != NULL) {
                                att = GetNewHashPos(Msg->AllAttach, 0);
-                               while (GetNextHashPos(Msg->AllAttach, att, &HKLen, &HashKey, &vMsg)) {
+                               while (GetNextHashPos(Msg->AllAttach, att, &HKLen, &HashKey, &vMsg) && 
+                                      (vcard_msgnum == -1)) {
                                        Att = (wc_mime_attachment*) vMsg;
                                        if (
                                                (strcasecmp(ChrPtr(Att->ContentType), "text/x-vcard") == 0)
@@ -450,9 +454,9 @@ TRYAGAIN:
                                        ) {
                                                *VCAtt = Att;
                                                *VCMsg = Msg;
+                                               vcard_msgnum = Msg->msgnum;
                                                if (Att->Data == NULL) {
                                                        MimeLoadData(Att);
-                                                       vcard_msgnum = Msg->msgnum;
                                                }
                                        }
                                }
@@ -466,16 +470,19 @@ TRYAGAIN:
 
        /* If there's no vcard, create one */
        if ((*VCMsg == NULL) && (already_tried_creating_one == 0)) {
+               FlushStrBuf(Buf);
                already_tried_creating_one = 1;
                serv_puts("ENT0 1|||4");
                StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) != 4) {
+               if (GetServerStatus(Buf, NULL) == 4) {
                        serv_puts("Content-type: text/x-vcard");
                        serv_puts("");
                        serv_puts("begin:vcard");
                        serv_puts("end:vcard");
                        serv_puts("000");
                }
+               else 
+                       syslog(1, "Error while creating user vcard: %s\n", ChrPtr(Buf));
                goto TRYAGAIN;
        }
        FreeStrBuf(&Buf);
@@ -580,7 +587,7 @@ void display_edituser(const char *supplied_username, int is_new) {
                        SubTP.Filter.ContextType = CTX_USERLIST;
                        SubTP.Context = UL;
                        output_headers(1, 0, 0, 0, 1, 0);
-                       DoTemplate(HKEY("userlist_detailview"), NULL, &SubTP);
+                       DoTemplate(HKEY("aide_edituser_detailview"), NULL, &SubTP);
                        end_burst();
                }
                DeleteUserListEntry(UL);
@@ -792,4 +799,12 @@ InitModule_USEREDIT
                         GroupchangenPosts,
                         CTX_USERLIST);
 
+       REGISTERTokenParamDefine(AxDeleted);
+       REGISTERTokenParamDefine(AxNewU);
+       REGISTERTokenParamDefine(AxProbU);
+       REGISTERTokenParamDefine(AxLocU);
+       REGISTERTokenParamDefine(AxNetU);
+       REGISTERTokenParamDefine(AxPrefU);
+       REGISTERTokenParamDefine(AxAideU);
 }
+