doc
csync_statedb.h
Go to the documentation of this file.
1 /*
2  * libcsync -- a library to sync a directory with another
3  *
4  * Copyright (c) 2008 by Andreas Schneider <mail@cynapses.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * @file csync_private.h
23  *
24  * @brief Private interface of csync
25  *
26  * @defgroup csyncstatedbInternals csync statedb internals
27  * @ingroup csyncInternalAPI
28  *
29  * @{
30  */
31 
32 #ifndef _CSYNC_STATEDB_H
33 #define _CSYNC_STATEDB_H
34 
35 #include "c_lib.h"
36 #include "csync_private.h"
37 
38 void csync_set_statedb_exists(CSYNC *ctx, int val);
39 
41 
42 /**
43  * @brief Load the statedb.
44  *
45  * This function tries to load the statedb. If it doesn't exists it creates
46  * the sqlite3 database, but doesn't create the tables. This will be done when
47  * csync gets destroyed.
48  *
49  * @param ctx The csync context.
50  * @param statedb Path to the statedb file (sqlite3 db).
51  *
52  * @return 0 on success, less than 0 if an error occured with errno set.
53  */
54 int csync_statedb_load(CSYNC *ctx, const char *statedb);
55 
56 int csync_statedb_write(CSYNC *ctx);
57 
58 int csync_statedb_close(CSYNC *ctx, const char *statedb, int jwritten);
59 
61 
63 
64 char *csync_statedb_get_uniqId(CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t *buf);
65 
66 /**
67  * @brief Query all files metadata inside and below a path.
68  * @param ctx The csync context.
69  * @param path The path.
70  *
71  * This function queries all metadata of all files inside or below the
72  * given path. The result is a linear string list with a multiple of 9
73  * entries. For each result file there are 9 strings which are phash,
74  * path, inode, uid, gid, mode, modtime, type and md5 (unique id).
75  *
76  * Note that not only the files in the given path are part of the result
77  * but also the files in directories below the given path. Ie. if the
78  * parameter path is /home/kf/test, we have /home/kf/test/file.txt in
79  * the result but also /home/kf/test/homework/another_file.txt
80  *
81  * @return A stringlist containing a multiple of 9 entries.
82  */
84 
85 /**
86  * @brief A generic statedb query.
87  *
88  * @param ctx The csync context.
89  * @param statement The SQL statement to execute
90  *
91  * @return A stringlist of the entries of a column. An emtpy stringlist if
92  * nothing has been found. NULL on error.
93  */
94 c_strlist_t *csync_statedb_query(CSYNC *ctx, const char *statement);
95 
96 /**
97  * @brief Insert function for the statedb.
98  *
99  * @param ctx The csync context.
100  * @param statement The SQL statement to insert into the statedb.
101  *
102  * @return The rowid of the most recent INSERT on success, 0 if the query
103  * wasn't successful.
104  */
105 int csync_statedb_insert(CSYNC *ctx, const char *statement);
106 
108 
110 
112 
113 typedef struct csync_progressinfo_s {
115  uint64_t phash;
116  uint64_t modtime;
117  char *md5;
118  int error;
119  int chunk;
121  char *tmpfile;
124 
125 csync_progressinfo_t *csync_statedb_get_progressinfo(CSYNC *ctx, uint64_t phash, uint64_t modtime, const char *md5);
128 
129 
130 /**
131  * }@
132  */
133 #endif /* _CSYNC_STATEDB_H */
134 /* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */
int csync_statedb_write_progressinfo(CSYNC *ctx, csync_progressinfo_t *pi)
int csync_statedb_create_tables(CSYNC *ctx)
char * csync_statedb_get_uniqId(CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t *buf)
csync_file_stat_t * csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode)
Private interface of csync.
int csync_statedb_close(CSYNC *ctx, const char *statedb, int jwritten)
const char * md5
Definition: csync_private.h:77
struct csync_progressinfo_s * next
csync_progressinfo_t * csync_statedb_get_progressinfo(CSYNC *ctx, uint64_t phash, uint64_t modtime, const char *md5)
int csync_statedb_load(CSYNC *ctx, const char *statedb)
Load the statedb.
Structure for a stringlist.
Definition: c_string.h:54
csync public structure
Definition: csync_private.h:88
time_t modtime
Definition: csync_private.h:64
csync_file_stat_t * csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash)
struct csync_progressinfo_s csync_progressinfo_t
int csync_statedb_insert(CSYNC *ctx, const char *statement)
Insert function for the statedb.
uint64_t inode
Definition: csync_private.h:67
uint64_t phash
Definition: csync_private.h:63
void csync_set_statedb_exists(CSYNC *ctx, int val)
char path[1]
Definition: csync_private.h:81
int csync_statedb_drop_tables(CSYNC *ctx)
int csync_statedb_insert_metadata(CSYNC *ctx)
void csync_statedb_free_progressinfo(csync_progressinfo_t *pi)
c_strlist_t * csync_statedb_get_below_path(CSYNC *ctx, const char *path)
Query all files metadata inside and below a path.
int csync_statedb_write(CSYNC *ctx)
int csync_get_statedb_exists(CSYNC *ctx)
c_strlist_t * csync_statedb_query(CSYNC *ctx, const char *statement)
A generic statedb query.