On Thu, 2010-09-02 at 11:48 +0200, Patrick Ohly wrote:
> Now I would go one step further and suppress generating this parameter
> for a peer, after identifying the peer. I thought that this should be
> possible with the remoterule config option, but <parameter> doesn't
> support that according to the documentation. BTW, the config parser
> doesn't complain when it is specified, it just doesn't do anything.
> 
> Is adding support for it a good idea? The semantic would be "during
> parsing and generating, ignore parameter unless no remoterule set or
> rule is active". I'm a bit uncertain whether this should apply during
> parsing *and* generating, because parsing something that was sent to us
> shouldn't do any harm. But it wouldn't be consistent.

I've implemented this and verified that it does what we need by adapting
SyncEvolution.

Attached are the patches, also pushed to meego.gitorious.org in the
parameter-rule branch. Does that look acceptable? I'd prefer to use them
in SyncEvolution 1.1 only after a review by Synthesis.

> MAKETEXTWITHPROFILE(... "EVOLUTION")
> 
> Except that the last step doesn't work yet either. Would it make sense
> to extend TMimeDirProfileHandler::setRemoteRule() such that setting a
> rule also sets all included rules?

This is what I implemented. It has the advantage that the choice about
full recursion can be made differently in different situations.

-- 
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.

>From 79e379ca56c1efbcf10db5e16a7a869d45c95a97 Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.o...@intel.com>
Date: Fri, 3 Sep 2010 17:52:46 +0200
Subject: [PATCH 1/4] MIME Profile: added <parameter rule="something">

The "rule" parameter is currently only stored. It is not yet used
for anything.
---
 src/sysync/mimedirprofile.cpp |   32 ++++++++++++++++++++++++++++++++
 src/sysync/mimedirprofile.h   |    8 ++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/sysync/mimedirprofile.cpp b/src/sysync/mimedirprofile.cpp
index c351ca0..fd7b790 100644
--- a/src/sysync/mimedirprofile.cpp
+++ b/src/sysync/mimedirprofile.cpp
@@ -485,6 +485,10 @@ bool TMIMEProfileConfig::localStartElement(const char *aElementName, const char
         return fail("bad boolean value");
       // - add parameter
       fOpenParameter = fOpenProperty->addParam(nam,defparam,positional,shownonempty,showinctcap,modeDep);
+#ifndef NO_REMOTE_RULES
+      const char *depRuleName = getAttr(aAttributes,"rule");
+      TCFG_ASSIGN(fOpenParameter->dependencyRuleName,depRuleName); // save name for later resolving
+#endif
       startNestedParsing();
     }
     else if (strucmp(aElementName,"position")==0) {
@@ -705,6 +709,30 @@ static void resolveRemoteRuleDeps(TProfileDefinition *aProfileP, TAgentConfig *a
           }
         } // rule specified
       }
+
+      // also fix rule-dependent parameters
+      TParameterDefinition *paramP = propP->parameterDefs;
+      while (paramP) {
+        if (!TCFG_ISEMPTY(paramP->dependencyRuleName)) {
+          TRemoteRulesList::iterator pos;
+          for(pos=aSessionConfigP->fRemoteRulesList.begin();pos!=aSessionConfigP->fRemoteRulesList.end();pos++) {
+            if (strucmp(TCFG_CSTR(paramP->dependencyRuleName),(*pos)->getName())==0) {
+              paramP->ruleDependency=(*pos);
+              break;
+            }
+          }
+          if (paramP->ruleDependency==NULL) {
+            string s;
+            StringObjPrintf(s,"parameter '%s' in property '%s' depends on unknown rule '%s'",
+                            TCFG_CSTR(paramP->paramname),
+                            TCFG_CSTR(propP->propname),
+                            TCFG_CSTR(propP->dependencyRuleName));
+            SYSYNC_THROW(TConfigParseException(s.c_str()));
+          }
+        }
+        paramP = paramP->next;
+      }
+
       // next
       propP=propP->next;
     }
@@ -885,6 +913,10 @@ TParameterDefinition::TParameterDefinition(
   shownonempty=aShowNonEmpty;
   showInCTCap=aShowInCTCap;
   modeDependency=aModeDep;
+#ifndef NO_REMOTE_RULES
+  ruleDependency=NULL;
+  TCFG_CLEAR(dependencyRuleName);
+#endif
 } // TParameterDefinition::TParameterDefinition
 
 
diff --git a/src/sysync/mimedirprofile.h b/src/sysync/mimedirprofile.h
index c3be59a..02d6a13 100755
--- a/src/sysync/mimedirprofile.h
+++ b/src/sysync/mimedirprofile.h
@@ -171,6 +171,14 @@ public:
   bool showInCTCap;
   // conversion information
   TConversionDef convdef;
+#ifndef NO_REMOTE_RULES
+  // rule processing is simpler than with properties:
+  // a parameter is expanded or parsed if no rule was set or the given
+  // rule is active
+  TRemoteRuleConfig *ruleDependency;
+  // name of remote rule dependency (will be resolved to set ruleDependency)
+  TCFG_STRING dependencyRuleName;
+#endif
 }; // TParameterDefinition
 
 
-- 
1.7.0

>From a8d1e9b0e7ac7e0aa20f7d74610a2e3786fd0bc4 Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.o...@intel.com>
Date: Fri, 3 Sep 2010 17:54:08 +0200
Subject: [PATCH 2/4] MIME Profile: check <parameter rule="something"> when generating

This patch adds new semantic: a parameter definition is ignored
during generation of an item unless no rule was specified or that
rule is active.

This semantic is simpler than the one for properties, which also
has the concept of a set of alternative properties of which only
one is selected.
---
 src/sysync/mimedirprofile.cpp |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/sysync/mimedirprofile.cpp b/src/sysync/mimedirprofile.cpp
index fd7b790..0726d79 100644
--- a/src/sysync/mimedirprofile.cpp
+++ b/src/sysync/mimedirprofile.cpp
@@ -2448,8 +2448,12 @@ bool TMimeDirProfileHandler::generateParams(
   while (paramP) {
     // parameter not started yet
     paramstarted=false;
-    // process param only if matching mode
-    if (mimeModeMatch(paramP->modeDependency)) {
+    // process param only if matching mode and active rules
+    if (mimeModeMatch(paramP->modeDependency)
+#ifndef NO_REMOTE_RULES
+        && (!paramP->ruleDependency || isActiveRule(paramP->ruleDependency))
+#endif
+        ) {
       // first append extendsname param values
       if (paramP->extendsname && aPropNameExt) {
         const TEnumerationDef *enumP = paramP->convdef.enumdefs;
-- 
1.7.0

>From dab9870496d998173e01b05c7ad52f730c0f57d6 Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.o...@intel.com>
Date: Fri, 3 Sep 2010 17:56:37 +0200
Subject: [PATCH 3/4] MIME Profile: check <parameter rule="something"> when parsing

This patch adds new semantic: a parameter definition is ignored
while parsing an item unless no rule was specified or that
rule is active.

This semantic is simpler than the one for properties, which also
has the concept of a set of alternative properties of which only
one is selected.

The original use case for <parameter rule> only requires suppressing
the generation of parameters not understood by a peer. This patch here
was merely added to keep the functionality symmetric.
---
 src/sysync/mimedirprofile.cpp |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/sysync/mimedirprofile.cpp b/src/sysync/mimedirprofile.cpp
index 0726d79..df385d0 100644
--- a/src/sysync/mimedirprofile.cpp
+++ b/src/sysync/mimedirprofile.cpp
@@ -3763,6 +3763,9 @@ bool TMimeDirProfileHandler::parseProperty(
         // check for match
         if (
           mimeModeMatch(paramP->modeDependency) &&
+#ifndef NO_REMOTE_RULES
+          (!paramP->ruleDependency || isActiveRule(paramP->ruleDependency)) &&
+#endif
           ((defaultparam && paramP->defaultparam) || strucmp(pname.c_str(),TCFG_CSTR(paramP->paramname))==0)
         ) {
           // param name found
-- 
1.7.0

>From ec41e2742679f58dbfa2303ed7427440aadd3340 Mon Sep 17 00:00:00 2001
From: Patrick Ohly <patrick.o...@intel.com>
Date: Fri, 3 Sep 2010 17:59:14 +0200
Subject: [PATCH 4/4] MIME Profile: setting one rule also activates all included rules

The MAKE/PARSETEXTWITHPROFILE() macro calls can only active one
rule. Allowing that rule to have <include> elements for other
rules *and* activating them together with the main rule allows
the macros to enables multiple rules.

Note that this activation is not recursive: subrules included by
subrules are not activated - perhaps they should be? This patch
follows the code in TSyncSession::checkRemoteSpecifics() which also
only activates the <remoterule> and the rules included in it,
without recursing.
---
 src/sysync/mimedirprofile.cpp |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/sysync/mimedirprofile.cpp b/src/sysync/mimedirprofile.cpp
index df385d0..2cbce65 100644
--- a/src/sysync/mimedirprofile.cpp
+++ b/src/sysync/mimedirprofile.cpp
@@ -5155,9 +5155,13 @@ void TMimeDirProfileHandler::setRemoteRule(const string &aRemoteRuleName)
   TRemoteRulesList::iterator pos;
   for(pos=scP->fRemoteRulesList.begin();pos!=scP->fRemoteRulesList.end();pos++) {
     if((*pos)->fElementName == aRemoteRuleName) {
-    	// only this rule must be active
+      // only this rule and all rules included by it rule must be active
       fActiveRemoteRules.clear();
       fActiveRemoteRules.push_back(*pos);
+      TRemoteRulesList::iterator spos;
+      for(spos=(*pos)->fSubRulesList.begin();spos!=(*pos)->fSubRulesList.end();spos++) {
+        fActiveRemoteRules.push_back(*spos);
+      }
       break;
     }
   }
-- 
1.7.0

_______________________________________________
os-libsynthesis mailing list
os-libsynthesis@synthesis.ch
http://lists.synthesis.ch/mailman/listinfo/os-libsynthesis

Reply via email to