fixes dav startup without .dav dir

Tue, 05 Sep 2017 12:00:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 05 Sep 2017 12:00:49 +0200
changeset 294
dd5c0ebdf54f
parent 293
8f90dcfd0439
child 295
8ac7b8d56115
child 301
cbea102875a8

fixes dav startup without .dav dir

dav/config.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
docs/html/configuration.html file | annotate | diff | comparison | revisions
docs/html/sync-configuration.html file | annotate | diff | comparison | revisions
--- a/dav/config.c	Tue Sep 05 11:42:08 2017 +0200
+++ b/dav/config.c	Tue Sep 05 12:00:49 2017 +0200
@@ -100,7 +100,7 @@
         switch(errno) {
             case ENOENT: {
                 create_default_config(file);
-                break;
+                return 0;
             }
             default: {
                 perror("Cannot load config.xml");
--- a/dav/sync.c	Tue Sep 05 11:42:08 2017 +0200
+++ b/dav/sync.c	Tue Sep 05 12:00:49 2017 +0200
@@ -1593,6 +1593,12 @@
 }
 
 int cmd_add_directory(CmdArgs *args) {
+    if(!get_repositories()) {
+        fprintf(stderr, "No repositories available. Run 'dav add-repository' first.\n");
+        fprintf(stderr, "Abort\n");
+        return -1;
+    }
+    
     printf("Each sync directory must have an unique name.\n");
     char *name = assistant_getcfg("name");
     if(!name) {
--- a/docs/html/configuration.html	Tue Sep 05 11:42:08 2017 +0200
+++ b/docs/html/configuration.html	Tue Sep 05 12:00:49 2017 +0200
@@ -71,75 +71,104 @@
 <p>The <em>config.xml</em> file is an XML file with <code>&lt;configuration&gt;</code> as root element. The <code>&lt;configuration&gt;</code> element can have the following child elements: <code>&lt;repository&gt;</code>, <code>&lt;http-proxy&gt;</code>, <code>&lt;https-proxy&gt;</code>, <code>&lt;key&gt;</code></p>
 <h2 id="repository">repository</h2>
 <p>This element is used to configure a repository. A repository must have a unique name to identify the repository and a url pointing to the root collection for this repository.</p>
-<p>Required child elements: <code>&lt;name&gt;</code>, <code>&lt;url&gt;</code><br />Optional elements: <code>&lt;user&gt;</code>, <code>&lt;password&gt;</code>, <code>&lt;default-key&gt;</code>, <code>&lt;full-encryption&gt;</code>, <code>&lt;content-encryption&gt;</code>, <code>&lt;decrypt-content&gt;</code>, <code>&lt;decrypt-name&gt;</code>, <code>&lt;cert&gt;</code>, <code>&lt;verification&gt;</code>, <code>&lt;ssl-version&gt;</code>, <code>&lt;authmethods&gt;</code></p>
+<p>Required child elements: <code>&lt;name&gt;</code>, <code>&lt;url&gt;</code><br />
+Optional elements: <code>&lt;user&gt;</code>, <code>&lt;password&gt;</code>, <code>&lt;default-key&gt;</code>, <code>&lt;full-encryption&gt;</code>, <code>&lt;content-encryption&gt;</code>, <code>&lt;decrypt-content&gt;</code>, <code>&lt;decrypt-name&gt;</code>, <code>&lt;cert&gt;</code>, <code>&lt;verification&gt;</code>, <code>&lt;ssl-version&gt;</code>, <code>&lt;authmethods&gt;</code></p>
 <h3 id="name">name</h3>
 <p>Unique repository identifer.</p>
-<p>Type: string<br />Example: <code>&lt;name&gt;myrepo&lt;/name&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;name&gt;myrepo&lt;/name&gt;</code></p>
 <h3 id="url">url</h3>
 <p>The url must point to a valid WebDAV compilant collection.</p>
-<p>Type: url<br />Example: <code>&lt;url&gt;https://example.com/webdav/repo1/&lt;/url&gt;</code></p>
+<p>Type: url<br />
+Example: <code>&lt;url&gt;https://example.com/webdav/repo1/&lt;/url&gt;</code></p>
 <h3 id="user">user</h3>
 <p>User used for authentication</p>
-<p>Type: string<br />Example: <code>&lt;user&gt;alice&lt;/user&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;user&gt;alice&lt;/user&gt;</code></p>
 <h3 id="password">password</h3>
 <p>A base64 encoded password used for authentication.</p>
-<p>Type: base64 string<br />Example: <code>&lt;password&gt;MTIzNDU2Nzg=&lt;/password&gt;</code></p>
+<p>Type: base64 string<br />
+Example: <code>&lt;password&gt;MTIzNDU2Nzg=&lt;/password&gt;</code></p>
 <h3 id="default-key">default-key</h3>
 <p>Identifer of the key used by default for encryption. There must be a configured key with this name.</p>
-<p>Type: string<br />Example: <code>&lt;key&gt;mykey&lt;/key&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;key&gt;mykey&lt;/key&gt;</code></p>
 <h3 id="full-encryption">full-encryption</h3>
-<p>If this element has the value of true, content and resource name encryption/decryption is enabled. Because encryption and decryption is disabled by default, <code>false</code> has no effect for this element.</p>
-<p>Type: boolean<br />Default: false<br />Example: `<full-encryption>true</full-encryption></p>
+<p>If this element has the value of true, content and resource name encryption/decryption is enabled. Resources are only encrypted if the repository has a default-key or a key is specified via command line option. Because encryption and decryption is disabled by default, <code>false</code> has no effect for this element.</p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: `<full-encryption>true</full-encryption></p>
 <h3 id="content-encryption">content-encryption</h3>
 <p>This element enables only content encryption and decryption. A value of <code>false</code> disables content encryption, but it does not disables content decryption, if this is enabled with <code>&lt;decrypt-content&gt;</code>.</p>
-<p>Type: boolean<br />Default: false<br />Example: <code>&lt;content-encryption&gt;true&lt;/content-encryption&gt;</code></p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: <code>&lt;content-encryption&gt;true&lt;/content-encryption&gt;</code></p>
 <h3 id="decrypt-content">decrypt-content</h3>
 <p>Controls only the decryption of content. If <code>true</code> content is decrypted.</p>
-<p>Type: boolean<br />Default false<br />Example: <code>&lt;decrypt-content&gt;true&lt;/decrypt-content&gt;</code></p>
+<p>Type: boolean<br />
+Default false<br />
+Example: <code>&lt;decrypt-content&gt;true&lt;/decrypt-content&gt;</code></p>
 <h3 id="decrypt-name">decrypt-name</h3>
 <p>Controls only the decryption of resource names. If <code>true</code> resource names are decrypted. This effects path to url resolution.</p>
-<p>Type: boolean<br />Default: false<br />Example: <code>&lt;decrypt-name&gt;true&lt;/decrypt-name&gt;</code></p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: <code>&lt;decrypt-name&gt;true&lt;/decrypt-name&gt;</code></p>
 <h3 id="cert">cert</h3>
 <p>Path to a file containing certificates to verify the TLS connection to the server.</p>
-<p>Type: string<br />Example: <code>&lt;cert&gt;/etc/certs/cabundle.pem&lt;/cert&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;cert&gt;/etc/certs/cabundle.pem&lt;/cert&gt;</code></p>
 <p>Note: This element does the same as curl's <code>--cacert</code> option.</p>
 <h3 id="verification">verification</h3>
 <p>This element can disable TLS certificate verification.</p>
-<p>Type: boolean<br />Default: true<br />Example: <code>&lt;verification&gt;false&lt;/verification&gt;</code></p>
+<p>Type: boolean<br />
+Default: true<br />
+Example: <code>&lt;verification&gt;false&lt;/verification&gt;</code></p>
 <h3 id="ssl-version">ssl-version</h3>
 <p>Specifies the SSL version to attempt to use. The value must be one of this strings: TLSv1, TLSv1.0, TLSv1.1, TLSv1.2, SSLv2, SSLv3</p>
-<p>Type: ssl version enum<br />Example: <code>&lt;ssl-version&gt;TLSv1.2&lt;/ssl-version&gt;</code></p>
+<p>Type: ssl version enum<br />
+Example: <code>&lt;ssl-version&gt;TLSv1.2&lt;/ssl-version&gt;</code></p>
 <h3 id="authmethods">authmethods</h3>
 <p>Controls which http authentication methods are used. Multiple methods can be used. The value must be one or more authentication methods separated by space. Valid authentication methods are: basic, digest, negotiate, ntlm, any, none</p>
 <p>Type: list of authmethod</p>
-<p>Default: basic<br />Example: <code>&lt;authmethods&gt;basic digest&lt;/authmethods&gt;</code></p>
+<p>Default: basic<br />
+Example: <code>&lt;authmethods&gt;basic digest&lt;/authmethods&gt;</code></p>
 <h2 id="key">key</h2>
 <p>The <code>&lt;key&gt;</code> element configures a key used for encryption. A key must have a unique name, which is stored in the properties of encrypted resources. To decrypt resources, dav looks for configured keys with this name, therefore the name of the key should never changed and must be the same on all hosts accessing the same repository.</p>
-<p>Required child elements: <code>&lt;name&gt;</code>, <code>&lt;file&gt;</code><br />Optional elements: <code>&lt;type&gt;</code></p>
+<p>Required child elements: <code>&lt;name&gt;</code>, <code>&lt;file&gt;</code><br />
+Optional elements: <code>&lt;type&gt;</code></p>
 <h3 id="name-1">name</h3>
 <p>Unique key identifer.</p>
-<p>Type: string<br />Example: <code>&lt;name&gt;key1&lt;/name&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;name&gt;key1&lt;/name&gt;</code></p>
 <h3 id="file">file</h3>
 <p>Path to the content of the key. The file should contain 32 (aes256) or 16 (aes128) bytes. If value is not an absolut path, it must be relative to the dav config directory <em>$HOME/.dav/</em>.</p>
-<p>Type: string<br />Example: <code>&lt;path&gt;keys/key1.bin&lt;/path&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;path&gt;keys/key1.bin&lt;/path&gt;</code></p>
 <h3 id="type">type</h3>
 <p>Specifies the key type. Valid values are <code>aes128</code> or <code>aes256</code>.</p>
-<p>Type: aes type enum<br />Default: aes256<br />Example: <code>&lt;type&gt;aes128&lt;/type&gt;</code></p>
+<p>Type: aes type enum<br />
+Default: aes256<br />
+Example: <code>&lt;type&gt;aes128&lt;/type&gt;</code></p>
 <h2 id="http-proxy-https-proxy">http-proxy / https-proxy</h2>
 <p>Configuration for http and https proxies is the same. Both use the same elements, but https-proxy expects an https url.</p>
-<p>Required child elements: <code>&lt;url&gt;</code><br />Optional elements: <code>&lt;user&gt;</code>, <code>&lt;password&gt;</code>, <code>&lt;no&gt;</code></p>
+<p>Required child elements: <code>&lt;url&gt;</code><br />
+Optional elements: <code>&lt;user&gt;</code>, <code>&lt;password&gt;</code>, <code>&lt;no&gt;</code></p>
 <h3 id="url-1">url</h3>
 <p>Specifies the proxy url.</p>
-<p>Type: url<br />Example: <code>&lt;url&gt;http://myproxy/&lt;/url&gt;</code></p>
+<p>Type: url<br />
+Example: <code>&lt;url&gt;http://myproxy/&lt;/url&gt;</code></p>
 <h3 id="user-1">user</h3>
 <p>User used for authentication with the proxy.</p>
-<p>Type: string<br />Example: <code>&lt;user&gt;alice&lt;/user&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;user&gt;alice&lt;/user&gt;</code></p>
 <h3 id="password-1">password</h3>
 <p>A base64 encoded password used for authentication.</p>
-<p>Type: base64 string<br />Example: <code>&lt;password&gt;MTIzNDU2Nzg=&lt;/password&gt;</code></p>
+<p>Type: base64 string<br />
+Example: <code>&lt;password&gt;MTIzNDU2Nzg=&lt;/password&gt;</code></p>
 <h3 id="no">no</h3>
 <p>A comma separated list of all hosts that should not be accessed through the proxy.</p>
-<p>Type: string<br />Example: <code>&lt;no&gt;host1, host2, host3&lt;/no&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;no&gt;host1, host2, host3&lt;/no&gt;</code></p>
 <h2 id="example-1-minimal-repository-configuration">Example 1: minimal repository configuration</h2>
 <p>A minimal configuration for a repository. If no user and/or password are configured, dav prompts for authentication informations if required.</p>
 <pre><code>&lt;configuration&gt;
@@ -167,6 +196,7 @@
         &lt;user&gt;alice&lt;/user&gt;
         &lt;password&gt;MTIzNDU2Nzg=&lt;/password&gt;
         &lt;full-encryption&gt;true&lt;/full-encryption&gt;
+        &lt;default-key&gt;mykey1&lt;/default-key&gt;
     &lt;/repository&gt;
     
     &lt;key&gt;
--- a/docs/html/sync-configuration.html	Tue Sep 05 11:42:08 2017 +0200
+++ b/docs/html/sync-configuration.html	Tue Sep 05 12:00:49 2017 +0200
@@ -71,52 +71,71 @@
 <p>The <em>sync.xml</em> file is an XML file with <code>&lt;configuration&gt;</code> as root element. This element can only have <code>&lt;directory&gt;</code> elements as children.</p>
 <h2 id="directory">directory</h2>
 <p>This element configures a sync-directory. A sync-directory must have a unique name, a (local) path, repository and a database.</p>
-<p>Required elements: <code>&lt;name&gt;</code>, <code>&lt;repository&gt;</code>, <code>&lt;path&gt;</code>, <code>&lt;database&gt;</code><br />Optional elements: <code>&lt;collection&gt;</code>, <code>&lt;trash&gt;</code>, <code>&lt;max-retry&gt;</code>, <code>&lt;backup-on-pull&gt;</code>, <code>&lt;lock-pull&gt;</code>, <code>&lt;lock-push&gt;</code>, <code>&lt;filter&gt;</code></p>
+<p>Required elements: <code>&lt;name&gt;</code>, <code>&lt;repository&gt;</code>, <code>&lt;path&gt;</code>, <code>&lt;database&gt;</code><br />
+Optional elements: <code>&lt;collection&gt;</code>, <code>&lt;trash&gt;</code>, <code>&lt;max-retry&gt;</code>, <code>&lt;backup-on-pull&gt;</code>, <code>&lt;lock-pull&gt;</code>, <code>&lt;lock-push&gt;</code>, <code>&lt;filter&gt;</code></p>
 <h3 id="name">name</h3>
 <p>Unique sync-directory identifer. This identifer is used in combination with all <em>dav-sync</em> commands.</p>
-<p>Type: string<br />Example: <code>&lt;name&gt;mysyncdir&lt;/name&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;name&gt;mysyncdir&lt;/name&gt;</code></p>
 <h3 id="repository">repository</h3>
 <p>Name of the WebDAV-repository. A repository with the same name must be configured in [config.xml][1].</p>
-<p>Type: string<br />Example: <code>&lt;name&gt;myrepo&lt;/name&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;name&gt;myrepo&lt;/name&gt;</code></p>
 <h3 id="path">path</h3>
 <p>The path of the local directory that should be synchronized. The path must be an absolute path or start with an environment variable. A path with an environment variable must start with an <code>$</code> followed by the variable name optionally followed by a path. For example:</p>
 <pre><code>`&lt;path&gt;$HOME/Documents&lt;/path&gt;`</code></pre>
 <p>The part between <code>$</code> and <code>/</code> is the environment variable name.</p>
-<p>Type: string<br />Example: <code>&lt;path&gt;/absolute/path&lt;/path&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;path&gt;/absolute/path&lt;/path&gt;</code></p>
 <h3 id="database">database</h3>
 <p>Path to the database file used for this sync-directory. The path must be relative to the <em>$HOME/.dav/</em> directory.</p>
-<p>Type: string<br />Example: <code>&lt;database&gt;myrepo-db.xml&lt;/database&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;database&gt;myrepo-db.xml&lt;/database&gt;</code></p>
 <h3 id="collection">collection</h3>
 <p>Path of the collection relative to the repository root collection. For example if the repository url is <em>http://example.com/webdav/</em> and the collection value is <em>/myfiles/</em>, the directory is synchronized with <em>http://example.com/webdav/myfiles/</em></p>
-<p>Type: string<br />Default: /<br />Example: <code>&lt;collection&gt;/myfiles&lt;/collection&gt;</code></p>
+<p>Type: string<br />
+Default: /<br />
+Example: <code>&lt;collection&gt;/myfiles&lt;/collection&gt;</code></p>
 <h3 id="trash">trash</h3>
 <p>Path to the trash directory for this sync-directory. Files that should be deleted will be moved to this directory. The value must be an absolute path or relative to the sync-directory path.</p>
-<p>Type: string<br />Example: <code>&lt;trash&gt;.trash&lt;/trash&gt;</code></p>
+<p>Type: string<br />
+Example: <code>&lt;trash&gt;.trash&lt;/trash&gt;</code></p>
 <h3 id="max-retry">max-retry</h3>
 <p>This integer value controls how many attempts of downloading/uploading a file in case of an error are made.</p>
-<p>Type: integer<br />Default: 0<br />Example: <code>&lt;max-retry&gt;3&lt;/max-retry&gt;</code></p>
+<p>Type: integer<br />
+Default: 0<br />
+Example: <code>&lt;max-retry&gt;3&lt;/max-retry&gt;</code></p>
 <h3 id="backup-on-pull">backup-on-pull</h3>
 <p>If this element has the value of true, the <em>pull</em> command will move old local files to the trash directory before downloading the new version from the server.</p>
-<p>Type: boolean<br />Default: false<br />Example: <code>&lt;backup-on-pull&gt;true&lt;/backup-on-pull&gt;</code></p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: <code>&lt;backup-on-pull&gt;true&lt;/backup-on-pull&gt;</code></p>
 <h3 id="lock-pull">lock-pull</h3>
 <p>Enables locking for the <em>pull</em> command.</p>
-<p>Type: boolean<br />Default: false<br />Example: <code>&lt;lock-pull&gt;true&lt;/lock-pull&gt;</code></p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: <code>&lt;lock-pull&gt;true&lt;/lock-pull&gt;</code></p>
 <h3 id="lock-push">lock-push</h3>
 <p>Enables locking for the <em>push</em> command.</p>
-<p>Type: boolean<br />Default: false<br />Example: <code>&lt;lock-push&gt;true&lt;/lock-push&gt;</code></p>
+<p>Type: boolean<br />
+Default: false<br />
+Example: <code>&lt;lock-push&gt;true&lt;/lock-push&gt;</code></p>
 <h3 id="filter">filter</h3>
 <p>With the filter element, include and exclude filters can be specified, to control which files are synchronized. The <em>pull</em> and <em>push</em> command apply these filters to file paths. At first it is checked if a file is matching any include filter. If so only files matching not an exclude filter are further processed.</p>
 <p>Note: The file path is relative to the directory path (and WebDAV collection) but always starts with an path separator.</p>
 <p>Optional elements: <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code></p>
 <h3 id="include">include</h3>
 <p>Controls which files will be included by <em>pull</em> and <em>push</em>. If an include filter is specified, only files matching this filter are included.</p>
-<p>Type: regex string<br />Default: .*<br />Example:</p>
+<p>Type: regex string<br />
+Default: .*<br />
+Example:</p>
 <pre><code>&lt;filter&gt;
     &lt;include&gt;\.pdf$&lt;/include&gt;
 &lt;/filter&gt;</code></pre>
 <h3 id="exclude">exclude</h3>
 <p>Controls which files will be excluded by <em>pull</em> and <em>push</em>.</p>
-<p>Type: regex string<br />Example:</p>
+<p>Type: regex string<br />
+Example:</p>
 <pre><code>&lt;filter&gt;
     &lt;exclude&gt;^/secretdir&lt;/exclude&gt;
     &lt;exclude&gt;\.DS_Store$&lt;/exclude&gt;

mercurial