syncevolution/src/syncevo/configs/update-samples.pl
Patrick Ohly a3574c27e2 XML config: use configuration composed from fragments (MB #7712)
This patch replaces src/syncclient_sample_config.xml with a
combination of src/syncevo/configs/syncevolution.xml and the
config fragments that are shared with Synthesis upstream.

These fragments are installed in /usr/share/syncevolution/xml (or
the corresponding data path). From there they are read at runtime
to compose the final XML configuration. Users can copy individual files
into the corresponding directory hierarchy rooted at
$XDG_CONFIG_HOME/syncevolution-xml to replace individual fragments.
New fragments can be added there or in /usr/share.

For testing, these two directories can be overridden with the
SYNCEVOLUTION_XML_CONFIG_DIR env variable. No tests have been added
for this yet. There's also no documentation about it except this
commit message - add something to the HACKING guide once this
new concept stabilizes.

Developers can add new fragments in the source tree, invoke make and run the
resulting binary in client mode. As before, a complete config is included
in the binary. However, it is only sufficient for SyncML client mode.
For server mode, the files are expected to be installed (no need to maintain
a list of files in a Makefile for that) or SYNCEVOLUTION_XML_CONFIG_DIR
must be set.

At the moment, the following sub-directories are scanned for .xml files:
- the root directory to find syncevolution.xml
- datatypes, datatypes/client, datatypes/server
- scripting, scripting/client, scripting/server
- remoterules, remoterules/client, remoterules/server

Files inside "client" or "server" sub-directories are only used
when assembling a config for the corresponding mode of operation.

The goal of this patch is to simplify config sharing with Synthesis
(individual files are easier to manage than the monolitithic one), to
share files between client and server with the possibility to add
mode-specific files, and to allow users to extend the XML
configuration. The most likely use case for the latter is support for
more devices.

Previously, remote rules for the different devices listed in
syncserv_sample_config.xml were not used by SyncEvolution.

This patch moves the ZYB remote rule into a client-specific remote rule,
thus removing a complaint from libsynthesis about the unknown <client>
element when running as server.

Because we are using the unified upstream config, some parts of the config
have changed:
- There is a SYNCLVL field in all field list. This is currently unused
  by SyncEvolution, but doesn't hurt either.
- A new iCalendar 2.0 all-day sanity check was added (for older Oracle servers?).
- The CATEGORIES defition in vBookmark was extended.
- some comment and white space changes

Because this is such fundamental change, extra care was taken to
minimize and verify the config changes. Here's the command which compares
old and new config for clients plus its output:

$ update-samples.pl syncevolution.xml client | diff -c -b syncclient_sample_config.xml -

***************
*** 31,42 ****
    <scripting>
      <looptimeout>5</looptimeout>

-     <function><![CDATA[
-       // create a UID
-       string newuid() {
-         return "syuid" + NUMFORMAT(RANDOM(1000000),6,"0") + "." + (string)MILLISECONDS(NOW());
-       }
-     ]]></function>
      <macro name="VCARD_BEFOREWRITE_SCRIPT_EVOLUTION"><![CDATA[
        // a wordaround for cellphone in evolution. for incoming contacts, if there is only one CELL,
        // strip the HOME or WORK flag from it. Evolution then should show it. */
--- 30,35 ----
***************
*** 118,123 ****
--- 111,124 ----
        }
      ]]></macro>

+     <function><![CDATA[
+       // create a UID
+       string newuid() {
+         return "syuid" + NUMFORMAT(RANDOM(1000000),6,"0") + "." + (string)MILLISECONDS(NOW());
+       }
+     ]]></function>
+
+
      <!-- define script macros for scripts that are used by both vCalendar 1.0 and iCalendar 2.0 -->

      <macro name="VCALENDAR_INCOMING_SCRIPT"><![CDATA[
***************
*** 145,150 ****
--- 146,158 ----
            DTSTART = CONVERTTOUSERZONE(DTSTART);
            MAKEALLDAY(DTSTART,DTEND,i);
          }
+         else {
+           // iCalendar 2.0 - only if DTSTART is a date-only value this really is an allday
+           if (ISDATEONLY(DTSTART)) {
+             // reshape to make sure we don't have invalid zero-duration alldays (old OCS 9 servers)
+             MAKEALLDAY(DTSTART,DTEND,i);
+           }
+         }

          // Make sure that all EXDATE times are in the same timezone as the start
          // time. Some servers send them as UTC, which is all fine and well, but
***************
*** 265,275 ****

    </scripting>

-
    <datatypes>
-
      <!-- list of internal fields representing vCard data -->
      <fieldlist name="contacts">
        <field name="REV" type="timestamp" compare="never" age="yes"/>

        <!-- Name elements -->
--- 274,283 ----

    </scripting>

    <datatypes>
      <!-- list of internal fields representing vCard data -->
      <fieldlist name="contacts">
+       <field name="SYNCLVL" type="integer" compare="never"/>
        <field name="REV" type="timestamp" compare="never" age="yes"/>

        <!-- Name elements -->
***************
*** 680,689 ****
          $VCARD_INCOMING_NAMECHANGE_SCRIPT
        ]]></incomingscript>
      </datatype>
-
-
      <!-- common field list for events and todos (both represented by vCalendar/iCalendar) -->
      <fieldlist name="calendar">
        <field name="ISEVENT" type="integer" compare="always"/>

        <field name="DMODIFIED" type="timestamp" compare="never" age="yes"/>
--- 688,696 ----
          $VCARD_INCOMING_NAMECHANGE_SCRIPT
        ]]></incomingscript>
      </datatype>
      <!-- common field list for events and todos (both represented by vCalendar/iCalendar) -->
      <fieldlist name="calendar">
+       <field name="SYNCLVL" type="integer" compare="never"/>
        <field name="ISEVENT" type="integer" compare="always"/>

        <field name="DMODIFIED" type="timestamp" compare="never" age="yes"/>
***************
*** 787,793 ****

          <subprofile onlyformode="standard" name="VTIMEZONE" mode="vtimezones"/>

!         <!-- sub-profile for todoz -->
          <subprofile name="VTODO" nummandatory="1" showifselectedonly="yes" field="ISEVENT" value="0">

            <property name="LAST-MODIFIED" suppressempty="yes">
--- 792,798 ----

          <subprofile onlyformode="standard" name="VTIMEZONE" mode="vtimezones"/>

!         <!-- sub-profile for tasks -->
          <subprofile name="VTODO" nummandatory="1" showifselectedonly="yes" field="ISEVENT" value="0">

            <property name="LAST-MODIFIED" suppressempty="yes">
***************
*** 1394,1401 ****

          <!-- non-standard properties -->

!         <property name="CATEGORIES">
!           <value field="CATEGORIES"/>
          </property>

          <property name="CLASS" suppressempty="yes">
--- 1394,1402 ----

          <!-- non-standard properties -->

!         <!-- inherit CATEGORIES from vCard 3.0, i.e. comma separated -->
!         <property name="CATEGORIES" values="list" valueseparator="," altvalueseparator=";">
!           <value field="CATEGORIES" combine=","/>
          </property>

          <property name="CLASS" suppressempty="yes">
***************
*** 1416,1435 ****
        <use profile="vBookmark"/>
      </datatype>

!     <fieldlists/>
!     <profiles/>
!     <datatypes/>
    </datatypes>

    <clientorserver/>
-
-   <client type="plugin">
-       <remoterule name="ZYB">
-           <manufacturer>ZYB</manufacturer>
-           <model>ZYB</model>
-           <!-- information to disable anchors checking -->
-           <lenientmode>yes</lenientmode>
-       </remoterule>
-   </client>
-
  </sysync_config>
--- 1417,1424 ----
        <use profile="vBookmark"/>
      </datatype>

!
    </datatypes>

    <clientorserver/>
  </sysync_config>
2010-02-02 21:53:28 +01:00

77 lines
2.3 KiB
Perl
Executable file

#! /usr/bin/env perl
sub basename {
$_ = shift;
s;.*/;;;
return $_;
}
# Concatenate all files ending in .xml in the given directory
# plus those in a specific subdirectory for client or server.
# Order lexicographic ascending of the base filename.
sub readfragments {
my $dir = shift;
my $subdir = shift;
my @res = ();
my @files = ();
if (opendir(my $dh, $dir)) {
foreach (grep (/.*\.xml$/, readdir($dh))) {
push @files, "$dir/$_";
}
closedir($dh);
if (opendir(my $dh, "$dir/$subdir")) {
foreach (grep (/.*\.xml$/, readdir($dh))) {
push @files, "$dir/$subdir/$_";
}
closedir($dh);
}
}
@files = sort { basename($a) <=> basename($b) } @files;
foreach (@files) {
open(IN, "<$_") || die "cannot read $_: $!";
push @res, <IN>;
close(IN);
}
return join("", @res);
}
# replace content of <debug>, <scripting>, <datatypes> and all <remoterule>s
# with the corresponding shared and/or client/server .xml fragments
sub update {
my $file = shift;
my $subdir = shift;
my $write = shift;
open(IN, "<$file") || die "cannot read $file: $!";
$_ = join("", <IN>);
close(IN) || die "closing $file: $!";
s;(<debug>\n).*(\n *</debug>);$1 . readfragments("debug", $subdir) . $2;se;
s;(<scripting>\n).*(\n *</scripting>);$1 . readfragments("scripting", $subdir) . $2;se ||
s;(\n *)<scripting/>;$1 . "<scripting>\n" . readfragments("scripting", $subdir) . $1 . "</scripting>";se;
s;(<datatypes>\n).*(\n *</datatypes>);$1 . readfragments("datatypes", $subdir) . $2;se ||
s;(\n *)<datatypes/>;$1 . "<datatypes>\n" . readfragments("datatypes", $subdir) . $1 . "</datatypes>";se;
s;(\n *)<remoterule>.*</remoterule>;$1 . readfragments("remoterules", $subdir);se ||
s;(\n *)<remoterules/>;readfragments("remoterules", $subdir);se;
if ($write) {
open(OUT, ">$file") || die "cannot write $file: $!";
print OUT;
close(OUT) || die "closing $file: $!";
} else {
print;
}
}
if ($#ARGV == -1) {
update("syncclient_sample_config.xml", "client", 1);
update("syncserv_sample_config.xml", "server", 1);
} else {
update($ARGV[0], $ARGV[1], 0);
}