Initial Commit
[Projects.git] / pkgbuilds / tagsistant-svn / src / tagsistant-build / tagsistant / src / tagsistant.h
blob1ec97b0318ac67106fbd8d7b20b32735e96bf959
1 /*
2 Tagsistant (tagfs) -- tagsistant.h
3 Copyright (C) 2006-2007 Tx0 <tx0@strumentiresistenti.org>
5 Tagsistant (tagfs) mount binary written using FUSE userspace library.
6 Header file
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* for developing purposes only */
24 #define VERBOSE_DEBUG 0
25 /* #define DEBUG_STRDUP */
27 #define TAGSISTANT_PLUGIN_PREFIX "libtagsistant_"
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
33 /* used to import mempcpy */
34 #ifndef _GNU_SOURCE
35 #define _GNU_SOURCE
36 #endif
38 #ifdef linux
39 /* For pread()/pwrite() */
40 #ifdef _XOPEN_SOURCE
41 #undef _XOPEN_SOURCE
42 #endif
43 #define _XOPEN_SOURCE 500
44 #endif
46 #ifndef FUSE_USE_VERSION
47 #define FUSE_USE_VERSION 26
48 #endif
50 #define _REENTRANT
51 #define _POSIX_PTHREAD_SEMANTICS
53 #include <pthread.h>
54 #ifndef TAGMAN
55 #include <debug.h>
56 #else
57 #include "../../debug.h"
58 #endif
59 #include <stdio.h>
60 #include <string.h>
61 #include <unistd.h>
62 #include <fcntl.h>
63 #include <dirent.h>
64 #include <errno.h>
65 #include <stdlib.h>
66 #include <sys/types.h>
67 #include <sys/socket.h>
68 #include <sys/stat.h>
69 #if FUSE_USE_VERSION == 25
70 # if HAVE_SYS_STATVFS_H
71 # include <sys/statvfs.h>
72 # endif
73 #else
74 # if HAVE_SYS_STATFS_H
75 # include <sys/statfs.h>
76 # endif
77 #endif
78 #include <stddef.h>
79 #include <netinet/in.h>
80 #include <utime.h>
81 #include <signal.h>
82 #include <dlfcn.h> /* for dlopen() and friends */
83 #include <glib.h>
84 #include <glib/gstrfuncs.h>
86 #ifdef HAVE_SETXATTR
87 #include <sys/xattr.h>
88 #endif
90 #ifndef _FILE_OFFSET_BITS
91 #define _FILE_OFFSET_BITS 64
92 #endif
94 #include <sqlite3.h>
95 #ifndef TAGMAN
96 #include <fuse.h>
97 #include <compat/fuse_opt.h>
98 #endif
100 #include "sql.h"
102 #define MAX_TAG_LENGTH 255
104 #define dyn_strcat(original, newstring) original = _dyn_strcat(original, newstring)
105 extern gchar *_dyn_strcat(gchar *original, const gchar *newstring);
108 * defines an AND token in a query path
110 typedef struct ptree_and_node {
111 /** the name of this token */
112 char *tag;
114 /** list of all related tags **/
115 struct ptree_and_node *related;
117 /** next AND token */
118 struct ptree_and_node *next;
119 } ptree_and_node_t;
122 * define an OR section in a query path
124 typedef struct ptree_or_node {
125 /** the next OR section */
126 struct ptree_or_node *next;
128 /** the list of AND tokens */
129 struct ptree_and_node *and_set;
130 } ptree_or_node_t;
133 * used in linked list of returned results
135 typedef struct file_handle {
136 /** filename pointed by this structure */
137 char *name;
139 /** next element in results */
140 struct file_handle *next;
141 } file_handle_t;
143 /* codes used in plugin chain processing */
145 #define TP_ERROR 0 /**< an error occurred while processing with this plugin */
146 #define TP_OK 1 /**< ok, but further tagging can be done by other plugins */
147 #define TP_STOP 2 /**< this plugin is authoritative for mimetype, stop chaining */
148 #define TP_NULL 3 /**< no tagging has been done, but that's not an error */
151 * holds a pointer to a processing funtion
152 * exported by a plugin
154 typedef struct tagsistant_plugin {
155 /** MIME type managed by this plugins */
156 char *mime_type;
158 /** file name of this plugin */
159 char *filename;
161 /** handle to plugin returned by dlopen() */
162 void *handle;
165 * hook to processing function
167 * \param filename the file to be processed
168 * \return 0 on failure (the plugin wasn't unable to process the file), 1 on
169 * partial success (the plugin did processed the file, but later processing
170 * by other plugins is allowed) or 2 on successful processing (no further
171 * processing required).
173 int (*processor)(const char *filename);
176 * hook to g_free allocated resources
178 void (*free)();
180 /** next plugin in linked list */
181 struct tagsistant_plugin *next;
182 } tagsistant_plugin_t;
185 * defines command line options for tagsistant mount tool
187 struct tagsistant {
188 int debug; /**< enable debug */
189 int foreground; /**< run in foreground */
190 int singlethread; /**< single thread? */
191 int readonly; /**< mount filesystem readonly */
192 int verbose; /**< do verbose logging on syslog (stderr is always verbose) */
193 int quiet; /**< don't log anything */
195 char *progname; /**< tagsistant */
196 char *mountpoint; /**< no clue? */
197 char *repository; /**< it's where files and tags are archived, no? */
198 char *archive; /**< a directory holding all the files */
199 char *tags; /**< a SQLite database on file */
201 sqlite3 *dbh; /**< database handle to operate on SQLite thingy, but no longer used? */
204 extern struct tagsistant tagsistant;
206 extern int debug;
207 extern int log_enabled;
209 extern char *get_tag_name(const char *path);
210 extern char *get_tag_path(const char *tag);
211 extern char *get_file_path(const char *tag);
212 extern char *get_tmp_file_path(const char *tag);
214 extern int is_tagged(char *filename, char *tagname);
215 extern int tag_file(const char *filename, char *tagname);
216 extern int untag_file(char *filename, char *tagname);
218 extern ptree_or_node_t *build_querytree(const char *path);
219 extern file_handle_t *build_filetree(ptree_or_node_t *query, const char *path);
221 extern void destroy_querytree(ptree_or_node_t *pt);
222 extern void destroy_filetree(file_handle_t *fh);
224 extern FILE *debugfd;
226 #ifdef DEBUG_STRDUP
227 # ifndef DEBUG_TO_LOGFILE
228 # define DEBUG_TO_LOGFILE
229 # endif
230 # ifdef strdup
231 # undef strdup
232 # define strdup(string) real_strdup(string, __FILE__, __LINE__)
233 # endif
234 char *real_strdup(const char *orig, char *file, int line);
235 #endif
237 #define freenull(symbol) {\
238 if (symbol != NULL) {\
239 if (debugfd != NULL) {\
240 fprintf(debugfd, "0x%.8x: g_free()\n", (unsigned int) symbol);\
242 g_free(symbol);\
243 symbol = NULL;\
244 } else {\
245 dbg(LOG_ERR, "FREE ERROR: symbol %s is NULL!", __STRING(symbol));\
249 // vim:ts=4:nocindent:nowrap