SUBST: add method to retrieve room preferences from a token
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 24 Aug 2012 13:31:41 +0000 (15:31 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 24 Aug 2012 13:31:41 +0000 (15:31 +0200)
  - when specifying a template string you now can use ."roompreference" similar to :"preference"

webcit/subst.c
webcit/subst.h

index 52f50f4489d3a4e9f4827c0bcbe8101b91688b91..7443515e7bbaec272e78ab9e83995cc85667c42e 100644 (file)
@@ -448,6 +448,7 @@ int HaveTemplateTokenString(StrBuf *Target,
        case TYPE_STR:
        case TYPE_BSTR:
        case TYPE_PREFSTR:
+       case TYPE_ROOMPREFSTR:
        case TYPE_GETTEXT:
        case TYPE_SUBTEMPLATE:
                return 1;
@@ -509,6 +510,19 @@ void GetTemplateTokenString(StrBuf *Target,
                *Value = ChrPtr(Buf);
                *len = StrLength(Buf);
                break;
+       case TYPE_ROOMPREFSTR:
+               if (TP->Tokens->Params[N]->len == 0) {
+                       LogTemplateError(Target, 
+                                        "TokenParameter", N, TP, 
+                                        "Requesting parameter %d; of type PREFSTR, empty lookup string not admitted.", N);
+                       *len = 0;
+                       *Value = EmptyStr;
+                       break;
+               }
+               Buf = get_ROOM_PREFS(TKEY(N));
+               *Value = ChrPtr(Buf);
+               *len = StrLength(Buf);
+               break;
        case TYPE_LONG:
                LogTemplateError(Target, 
                                 "TokenParameter", N, TP, 
@@ -588,6 +602,19 @@ long GetTemplateTokenNumber(StrBuf *Target, WCTemplputParams *TP, int N, long df
                if (get_PREF_LONG(TKEY(N), &Ret, dflt))
                        return Ret;
                return 0;
+       case TYPE_ROOMPREFSTR:
+               LogTemplateError(Target, 
+                                "TokenParameter", N, TP, 
+                                "requesting a prefstring in param %d want a number", N);
+               if (TP->Tokens->Params[N]->len == 0) {
+                       LogTemplateError(Target, 
+                                        "TokenParameter", N, TP, 
+                                        "Requesting parameter %d; of type PREFSTR, empty lookup string not admitted.", N);
+                       return 0;
+               }
+               if (get_ROOM_PREFS_LONG(TKEY(N), &Ret, dflt))
+                       return Ret;
+               return 0;
        case TYPE_INTDEFINE:
        case TYPE_LONG:
                return TP->Tokens->Params[N]->lvalue;
@@ -730,6 +757,14 @@ int GetNextParameter(StrBuf *Buf,
                        ParamBrace = 1;
                }
        }
+       else if (*pch == '.') {
+               Parm->Type = TYPE_ROOMPREFSTR;
+               pch ++;
+               if (*pch == '(') {
+                       pch ++;
+                       ParamBrace = 1;
+               }
+       }
        else if (*pch == ';') {
                Parm->Type = TYPE_PREFINT;
                pch ++;
index 75bbf3e33d7d4346f8f9b322f5238550e84820cd..56b5d19476d8b53706fe76061a2207b0f27ea14c 100644 (file)
@@ -14,11 +14,12 @@ extern HashList *LocalTemplateCache;
 #define TYPE_STR   1
 #define TYPE_LONG  2
 #define TYPE_PREFSTR 3
-#define TYPE_PREFINT 4
-#define TYPE_GETTEXT 5
-#define TYPE_BSTR 6
-#define TYPE_SUBTEMPLATE 7
-#define TYPE_INTDEFINE 8
+#define TYPE_ROOMPREFSTR 4
+#define TYPE_PREFINT 5
+#define TYPE_GETTEXT 6
+#define TYPE_BSTR 7
+#define TYPE_SUBTEMPLATE 8
+#define TYPE_INTDEFINE 9
 #define MAXPARAM  25
 
 #define IS_NUMBER(a) ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))