1
/* utils.c generated by valac 0.14.2, the Vala compiler
2
* generated from utils.vala, do not modify */
6
* Copyright © 2011 Collabora Ltd.
7
* By Seif Lotfy <seif@lotfy.com>
8
* By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
9
* Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
10
* Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
12
* This program is free software: you can redistribute it and/or modify
13
* it under the terms of the GNU Lesser General Public License as published by
14
* the Free Software Foundation, either version 2.1 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU Lesser General Public License
23
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28
#include <glib-object.h>
31
#include <glib/gstdio.h>
34
#define _g_free0(var) (var = (g_free (var), NULL))
35
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
36
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
37
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
40
ZEITGEIST_ENGINE_ERROR_BACKUP_FAILED,
41
ZEITGEIST_ENGINE_ERROR_DATABASE_BUSY,
42
ZEITGEIST_ENGINE_ERROR_DATABASE_CANTOPEN,
43
ZEITGEIST_ENGINE_ERROR_DATABASE_CORRUPT,
44
ZEITGEIST_ENGINE_ERROR_DATABASE_ERROR,
45
ZEITGEIST_ENGINE_ERROR_DATABASE_RETIRE_FAILED,
46
ZEITGEIST_ENGINE_ERROR_EXISTING_INSTANCE,
47
ZEITGEIST_ENGINE_ERROR_INVALID_ARGUMENT,
48
ZEITGEIST_ENGINE_ERROR_INVALID_KEY,
49
ZEITGEIST_ENGINE_ERROR_INVALID_SIGNATURE,
50
ZEITGEIST_ENGINE_ERROR_TOO_MANY_RESULTS
51
} ZeitgeistEngineError;
52
#define ZEITGEIST_ENGINE_ERROR zeitgeist_engine_error_quark ()
54
extern gchar* zeitgeist_utils_DATA_PATH;
55
gchar* zeitgeist_utils_DATA_PATH = NULL;
56
extern gchar* zeitgeist_utils_DATABASE_FILE_PATH;
57
gchar* zeitgeist_utils_DATABASE_FILE_PATH = NULL;
58
extern gchar* zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
59
gchar* zeitgeist_utils_DATABASE_FILE_BACKUP_PATH = NULL;
60
extern gchar* zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
61
gchar* zeitgeist_utils_LOCAL_EXTENSIONS_PATH = NULL;
63
#define ZEITGEIST_UTILS_DATA_FOLDER "zeitgeist"
64
#define ZEITGEIST_UTILS_DATABASE_BASENAME "activity.sqlite"
65
#define ZEITGEIST_UTILS_USER_EXTENSION_PATH ""
66
#define ZEITGEIST_UTILS_DBUS_INTERFACE ""
67
#define ZEITGEIST_UTILS_SIG_EVENT "asaasay"
68
#define ZEITGEIST_UTILS_MAX_DBUS_RESULT_SIZE ((gsize) ((4 * 1024) * 1024))
69
#define ZEITGEIST_UTILS_CACHE_SIZE ((guint) 0)
70
const gchar* zeitgeist_utils_get_data_path (void);
71
gchar* zeitgeist_utils_get_default_data_path (void);
72
const gchar* zeitgeist_utils_get_database_file_path (void);
73
const gchar* zeitgeist_utils_get_database_file_backup_path (void);
74
gchar* zeitgeist_utils_get_database_file_retire_name (void);
75
const gchar* zeitgeist_utils_get_local_extensions_path (void);
76
gboolean zeitgeist_utils_using_in_memory_database (void);
77
void zeitgeist_utils_backup_database (GError** error);
78
GQuark zeitgeist_engine_error_quark (void);
79
void zeitgeist_utils_retire_database (GError** error);
80
gboolean zeitgeist_utils_parse_negation (gchar** val);
81
gboolean zeitgeist_utils_parse_noexpand (gchar** val);
82
gboolean zeitgeist_utils_parse_wildcard (gchar** val);
83
gboolean zeitgeist_utils_is_empty_string (const gchar* s);
86
const gchar* zeitgeist_utils_get_data_path (void) {
87
const gchar* result = NULL;
89
const gchar* _tmp2_ = NULL;
96
gboolean _tmp10_ = FALSE;
99
_tmp0_ = zeitgeist_utils_DATA_PATH;
100
if (_tmp0_ != NULL) {
102
_tmp1_ = zeitgeist_utils_DATA_PATH;
106
_tmp2_ = g_getenv ("ZEITGEIST_DATA_PATH");
107
_tmp3_ = g_strdup (_tmp2_);
110
if (_tmp5_ == NULL) {
111
gchar* _tmp6_ = NULL;
112
_tmp6_ = zeitgeist_utils_get_default_data_path ();
117
_tmp8_ = g_strdup (_tmp7_);
118
_g_free0 (zeitgeist_utils_DATA_PATH);
119
zeitgeist_utils_DATA_PATH = _tmp8_;
120
_tmp9_ = zeitgeist_utils_DATA_PATH;
121
_tmp10_ = g_file_test (_tmp9_, G_FILE_TEST_IS_DIR);
123
const gchar* _tmp11_;
124
_tmp11_ = zeitgeist_utils_DATA_PATH;
125
g_mkdir_with_parents (_tmp11_, 0755);
127
_tmp12_ = zeitgeist_utils_DATA_PATH;
128
g_debug ("utils.vala:59: DATA_PATH = %s", _tmp12_);
129
_tmp13_ = zeitgeist_utils_DATA_PATH;
136
gchar* zeitgeist_utils_get_default_data_path (void) {
137
gchar* result = NULL;
138
const gchar* _tmp0_ = NULL;
139
gchar* _tmp1_ = NULL;
140
_tmp0_ = g_get_user_data_dir ();
141
_tmp1_ = g_build_filename (_tmp0_, ZEITGEIST_UTILS_DATA_FOLDER, NULL);
147
const gchar* zeitgeist_utils_get_database_file_path (void) {
148
const gchar* result = NULL;
150
const gchar* _tmp2_ = NULL;
156
const gchar* _tmp10_;
157
const gchar* _tmp11_;
158
_tmp0_ = zeitgeist_utils_DATABASE_FILE_PATH;
159
if (_tmp0_ != NULL) {
161
_tmp1_ = zeitgeist_utils_DATABASE_FILE_PATH;
165
_tmp2_ = g_getenv ("ZEITGEIST_DATABASE_PATH");
166
_tmp3_ = g_strdup (_tmp2_);
169
if (_tmp5_ == NULL) {
170
const gchar* _tmp6_ = NULL;
171
gchar* _tmp7_ = NULL;
172
_tmp6_ = zeitgeist_utils_get_data_path ();
173
_tmp7_ = g_build_filename (_tmp6_, ZEITGEIST_UTILS_DATABASE_BASENAME, NULL);
178
_tmp9_ = g_strdup (_tmp8_);
179
_g_free0 (zeitgeist_utils_DATABASE_FILE_PATH);
180
zeitgeist_utils_DATABASE_FILE_PATH = _tmp9_;
181
_tmp10_ = zeitgeist_utils_DATABASE_FILE_PATH;
182
g_debug ("utils.vala:78: DATABASE_FILE_PATH = %s", _tmp10_);
183
_tmp11_ = zeitgeist_utils_DATABASE_FILE_PATH;
190
const gchar* zeitgeist_utils_get_database_file_backup_path (void) {
191
const gchar* result = NULL;
193
const gchar* _tmp2_ = NULL;
199
const gchar* _tmp10_;
200
const gchar* _tmp11_;
201
_tmp0_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
202
if (_tmp0_ != NULL) {
204
_tmp1_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
208
_tmp2_ = g_getenv ("ZEITGEIST_DATABASE_BACKUP_PATH");
209
_tmp3_ = g_strdup (_tmp2_);
212
if (_tmp5_ == NULL) {
213
const gchar* _tmp6_ = NULL;
214
gchar* _tmp7_ = NULL;
215
_tmp6_ = zeitgeist_utils_get_data_path ();
216
_tmp7_ = g_build_filename (_tmp6_, ZEITGEIST_UTILS_DATABASE_BASENAME ".bck", NULL);
221
_tmp9_ = g_strdup (_tmp8_);
222
_g_free0 (zeitgeist_utils_DATABASE_FILE_BACKUP_PATH);
223
zeitgeist_utils_DATABASE_FILE_BACKUP_PATH = _tmp9_;
224
_tmp10_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
225
g_debug ("utils.vala:93: DATABASE_FILE_BACKUP_PATH = %s", _tmp10_);
226
_tmp11_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
233
gchar* zeitgeist_utils_get_database_file_retire_name (void) {
234
gchar* result = NULL;
237
gchar* _tmp2_ = NULL;
239
gchar* _tmp4_ = NULL;
243
_tmp0_ = g_date_time_new_now_local ();
245
_tmp2_ = g_date_time_format (_tmp1_, "%Y%m%d-%H%M%S");
247
_tmp4_ = g_strdup_printf (".%s.bck", _tmp3_);
249
_tmp6_ = g_strconcat (ZEITGEIST_UTILS_DATABASE_BASENAME, _tmp5_, NULL);
253
_g_date_time_unref0 (_tmp1_);
259
const gchar* zeitgeist_utils_get_local_extensions_path (void) {
260
const gchar* result = NULL;
262
const gchar* _tmp2_ = NULL;
263
gchar* _tmp3_ = NULL;
266
_tmp0_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
267
if (_tmp0_ != NULL) {
269
_tmp1_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
273
_tmp2_ = zeitgeist_utils_get_data_path ();
274
_tmp3_ = g_build_filename (_tmp2_, "extensions", NULL);
275
_g_free0 (zeitgeist_utils_LOCAL_EXTENSIONS_PATH);
276
zeitgeist_utils_LOCAL_EXTENSIONS_PATH = _tmp3_;
277
_tmp4_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
278
g_debug ("utils.vala:111: LOCAL_EXTENSIONS_PATH = %s", _tmp4_);
279
_tmp5_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
285
gboolean zeitgeist_utils_using_in_memory_database (void) {
286
gboolean result = FALSE;
287
const gchar* _tmp0_ = NULL;
288
_tmp0_ = zeitgeist_utils_get_database_file_path ();
289
result = g_strcmp0 (_tmp0_, ":memory:") == 0;
294
void zeitgeist_utils_backup_database (GError** error) {
295
GFile* original = NULL;
296
GFile* destination = NULL;
297
const gchar* _tmp0_ = NULL;
298
GFile* _tmp1_ = NULL;
299
const gchar* _tmp2_ = NULL;
300
GFile* _tmp3_ = NULL;
301
const gchar* _tmp4_ = NULL;
302
GError * _inner_error_ = NULL;
303
_tmp0_ = zeitgeist_utils_get_database_file_path ();
304
_tmp1_ = g_file_new_for_path (_tmp0_);
305
_g_object_unref0 (original);
307
_tmp2_ = zeitgeist_utils_get_database_file_backup_path ();
308
_tmp3_ = g_file_new_for_path (_tmp2_);
309
_g_object_unref0 (destination);
310
destination = _tmp3_;
311
_tmp4_ = zeitgeist_utils_get_database_file_backup_path ();
312
g_message ("utils.vala:128: Backing up database to \"%s\" for schema upgrade...", _tmp4_);
313
g_file_copy (original, destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &_inner_error_);
314
if (_inner_error_ != NULL) {
315
g_propagate_error (error, _inner_error_);
316
_g_object_unref0 (destination);
317
_g_object_unref0 (original);
320
_g_object_unref0 (destination);
321
_g_object_unref0 (original);
325
void zeitgeist_utils_retire_database (GError** error) {
326
GError * _inner_error_ = NULL;
328
const gchar* _tmp0_ = NULL;
329
GFile* _tmp1_ = NULL;
332
gchar* _tmp3_ = NULL;
334
_tmp0_ = zeitgeist_utils_get_database_file_path ();
335
_tmp1_ = g_file_new_for_path (_tmp0_);
338
_tmp3_ = zeitgeist_utils_get_database_file_retire_name ();
340
g_file_set_display_name (_tmp2_, _tmp4_, NULL, &_inner_error_);
342
if (_inner_error_ != NULL) {
343
_g_object_unref0 (dbfile);
344
goto __catch18_g_error;
346
_g_object_unref0 (dbfile);
354
gchar* _tmp7_ = NULL;
359
_inner_error_ = NULL;
361
_tmp6_ = _tmp5_->message;
362
_tmp7_ = g_strdup_printf ("Could not rename database: %s", _tmp6_);
365
_tmp9_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_DATABASE_RETIRE_FAILED, _tmp8_);
366
_inner_error_ = _tmp9_;
368
_g_error_free0 (err);
372
if (_inner_error_ != NULL) {
373
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
374
g_propagate_error (error, _inner_error_);
377
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
378
g_clear_error (&_inner_error_);
386
* Check if the value starts with the negation operator. If it does,
387
* remove the operator from the value and return true. Otherwise,
390
static glong string_strnlen (gchar* str, glong maxlen) {
394
gchar* _tmp2_ = NULL;
399
_tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
402
if (_tmp3_ == NULL) {
412
result = (glong) (_tmp5_ - _tmp6_);
418
static gchar* string_substring (const gchar* self, glong offset, glong len) {
419
gchar* result = NULL;
420
glong string_length = 0L;
421
gboolean _tmp0_ = FALSE;
431
gchar* _tmp23_ = NULL;
432
g_return_val_if_fail (self != NULL, NULL);
434
if (_tmp1_ >= ((glong) 0)) {
437
_tmp0_ = _tmp2_ >= ((glong) 0);
448
_tmp6_ = string_strnlen ((gchar*) self, _tmp4_ + _tmp5_);
449
string_length = _tmp6_;
453
_tmp7_ = strlen (self);
455
string_length = (glong) _tmp8_;
458
if (_tmp9_ < ((glong) 0)) {
462
_tmp10_ = string_length;
464
offset = _tmp10_ + _tmp11_;
466
g_return_val_if_fail (_tmp12_ >= ((glong) 0), NULL);
471
_tmp14_ = string_length;
472
g_return_val_if_fail (_tmp13_ <= _tmp14_, NULL);
475
if (_tmp15_ < ((glong) 0)) {
478
_tmp16_ = string_length;
480
len = _tmp16_ - _tmp17_;
484
_tmp20_ = string_length;
485
g_return_val_if_fail ((_tmp18_ + _tmp19_) <= _tmp20_, NULL);
488
_tmp23_ = g_strndup (((gchar*) self) + _tmp21_, (gsize) _tmp22_);
494
gboolean zeitgeist_utils_parse_negation (gchar** val) {
495
gboolean result = FALSE;
497
gboolean _tmp1_ = FALSE;
499
gchar* _tmp3_ = NULL;
500
g_return_val_if_fail (val != NULL, FALSE);
502
_tmp1_ = g_str_has_prefix (_tmp0_, "!");
508
_tmp3_ = string_substring (_tmp2_, (glong) 1, (glong) (-1));
517
* Check if the value starts with the noexpand operator. If it does,
518
* remove the operator from the value and return true. Otherwise,
521
* Check for the negation operator before calling this function.
523
gboolean zeitgeist_utils_parse_noexpand (gchar** val) {
524
gboolean result = FALSE;
526
gboolean _tmp1_ = FALSE;
528
gchar* _tmp3_ = NULL;
529
g_return_val_if_fail (val != NULL, FALSE);
531
_tmp1_ = g_str_has_prefix (_tmp0_, "+");
537
_tmp3_ = string_substring (_tmp2_, (glong) 1, (glong) (-1));
546
* Check if the value ends with the wildcard character. If it does,
547
* remove the wildcard character from the value and return true.
548
* Otherwise, return false.
550
static guint8* string_get_data (const gchar* self, int* result_length1) {
562
g_return_val_if_fail (self != NULL, NULL);
563
res = (guint8*) self;
565
_res_size_ = res_length1;
566
_tmp0_ = strlen (self);
568
res_length1 = (gint) _tmp1_;
569
_tmp2_ = res_length1;
571
_tmp3__length1 = res_length1;
573
_tmp4__length1 = _tmp3__length1;
574
if (result_length1) {
575
*result_length1 = _tmp4__length1;
582
gboolean zeitgeist_utils_parse_wildcard (gchar** val) {
583
gboolean result = FALSE;
585
gboolean _tmp1_ = FALSE;
592
gint val_data_length1;
593
gint _val_data_size_;
599
g_return_val_if_fail (val != NULL, FALSE);
601
_tmp1_ = g_str_has_suffix (_tmp0_, "*");
607
_tmp3_ = string_get_data (_tmp2_, &_tmp3__length1);
609
_tmp4__length1 = _tmp3__length1;
611
val_data_length1 = _tmp4__length1;
612
_val_data_size_ = val_data_length1;
614
_tmp5__length1 = val_data_length1;
616
_tmp6__length1 = val_data_length1;
617
_tmp5_[_tmp6__length1 - 1] = (guint8) '\0';
618
_tmp7_ = _tmp5_[_tmp6__length1 - 1];
625
* Return true if a string is empty (null or containing just a null
628
gboolean zeitgeist_utils_is_empty_string (const gchar* s) {
629
gboolean result = FALSE;
630
gboolean _tmp0_ = FALSE;
634
if (_tmp1_ == NULL) {
639
_tmp0_ = g_strcmp0 (_tmp2_, "") == 0;