~zeitgeist/zeitgeist/saucy-packaging-0-9-14

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Package Import Robot
  • Author(s): Siegfried-Angel Gevatter Pujals
  • Date: 2012-04-10 15:44:19 UTC
  • mfrom: (1.3.1) (6.2.6 experimental)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20120410154419-kswflpfbcllm5a8y
* New upstream release. Some of the changes are:
   - Updated MIME-type mappings.
   - Added a query result size limit.
   - Enhanced database/index corruption recovery.
   - Don't index events from Ubuntu One.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* utils.c generated by valac 0.14.2, the Vala compiler
 
2
 * generated from utils.vala, do not modify */
 
3
 
 
4
/* utils.vala
 
5
 *
 
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>
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 *
 
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/>.
 
24
 *
 
25
 */
 
26
 
 
27
#include <glib.h>
 
28
#include <glib-object.h>
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <glib/gstdio.h>
 
32
#include <gio/gio.h>
 
33
 
 
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)))
 
38
 
 
39
typedef enum  {
 
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 ()
 
53
 
 
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;
 
62
 
 
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);
 
84
 
 
85
 
 
86
const gchar* zeitgeist_utils_get_data_path (void) {
 
87
        const gchar* result = NULL;
 
88
        const gchar* _tmp0_;
 
89
        const gchar* _tmp2_ = NULL;
 
90
        gchar* _tmp3_;
 
91
        gchar* _tmp4_;
 
92
        const gchar* _tmp5_;
 
93
        const gchar* _tmp7_;
 
94
        gchar* _tmp8_;
 
95
        const gchar* _tmp9_;
 
96
        gboolean _tmp10_ = FALSE;
 
97
        const gchar* _tmp12_;
 
98
        const gchar* _tmp13_;
 
99
        _tmp0_ = zeitgeist_utils_DATA_PATH;
 
100
        if (_tmp0_ != NULL) {
 
101
                const gchar* _tmp1_;
 
102
                _tmp1_ = zeitgeist_utils_DATA_PATH;
 
103
                result = _tmp1_;
 
104
                return result;
 
105
        }
 
106
        _tmp2_ = g_getenv ("ZEITGEIST_DATA_PATH");
 
107
        _tmp3_ = g_strdup (_tmp2_);
 
108
        _tmp4_ = _tmp3_;
 
109
        _tmp5_ = _tmp4_;
 
110
        if (_tmp5_ == NULL) {
 
111
                gchar* _tmp6_ = NULL;
 
112
                _tmp6_ = zeitgeist_utils_get_default_data_path ();
 
113
                _g_free0 (_tmp4_);
 
114
                _tmp4_ = _tmp6_;
 
115
        }
 
116
        _tmp7_ = _tmp4_;
 
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);
 
122
        if (!_tmp10_) {
 
123
                const gchar* _tmp11_;
 
124
                _tmp11_ = zeitgeist_utils_DATA_PATH;
 
125
                g_mkdir_with_parents (_tmp11_, 0755);
 
126
        }
 
127
        _tmp12_ = zeitgeist_utils_DATA_PATH;
 
128
        g_debug ("utils.vala:59: DATA_PATH = %s", _tmp12_);
 
129
        _tmp13_ = zeitgeist_utils_DATA_PATH;
 
130
        result = _tmp13_;
 
131
        _g_free0 (_tmp4_);
 
132
        return result;
 
133
}
 
134
 
 
135
 
 
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);
 
142
        result = _tmp1_;
 
143
        return result;
 
144
}
 
145
 
 
146
 
 
147
const gchar* zeitgeist_utils_get_database_file_path (void) {
 
148
        const gchar* result = NULL;
 
149
        const gchar* _tmp0_;
 
150
        const gchar* _tmp2_ = NULL;
 
151
        gchar* _tmp3_;
 
152
        gchar* _tmp4_;
 
153
        const gchar* _tmp5_;
 
154
        const gchar* _tmp8_;
 
155
        gchar* _tmp9_;
 
156
        const gchar* _tmp10_;
 
157
        const gchar* _tmp11_;
 
158
        _tmp0_ = zeitgeist_utils_DATABASE_FILE_PATH;
 
159
        if (_tmp0_ != NULL) {
 
160
                const gchar* _tmp1_;
 
161
                _tmp1_ = zeitgeist_utils_DATABASE_FILE_PATH;
 
162
                result = _tmp1_;
 
163
                return result;
 
164
        }
 
165
        _tmp2_ = g_getenv ("ZEITGEIST_DATABASE_PATH");
 
166
        _tmp3_ = g_strdup (_tmp2_);
 
167
        _tmp4_ = _tmp3_;
 
168
        _tmp5_ = _tmp4_;
 
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);
 
174
                _g_free0 (_tmp4_);
 
175
                _tmp4_ = _tmp7_;
 
176
        }
 
177
        _tmp8_ = _tmp4_;
 
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;
 
184
        result = _tmp11_;
 
185
        _g_free0 (_tmp4_);
 
186
        return result;
 
187
}
 
188
 
 
189
 
 
190
const gchar* zeitgeist_utils_get_database_file_backup_path (void) {
 
191
        const gchar* result = NULL;
 
192
        const gchar* _tmp0_;
 
193
        const gchar* _tmp2_ = NULL;
 
194
        gchar* _tmp3_;
 
195
        gchar* _tmp4_;
 
196
        const gchar* _tmp5_;
 
197
        const gchar* _tmp8_;
 
198
        gchar* _tmp9_;
 
199
        const gchar* _tmp10_;
 
200
        const gchar* _tmp11_;
 
201
        _tmp0_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
 
202
        if (_tmp0_ != NULL) {
 
203
                const gchar* _tmp1_;
 
204
                _tmp1_ = zeitgeist_utils_DATABASE_FILE_BACKUP_PATH;
 
205
                result = _tmp1_;
 
206
                return result;
 
207
        }
 
208
        _tmp2_ = g_getenv ("ZEITGEIST_DATABASE_BACKUP_PATH");
 
209
        _tmp3_ = g_strdup (_tmp2_);
 
210
        _tmp4_ = _tmp3_;
 
211
        _tmp5_ = _tmp4_;
 
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);
 
217
                _g_free0 (_tmp4_);
 
218
                _tmp4_ = _tmp7_;
 
219
        }
 
220
        _tmp8_ = _tmp4_;
 
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;
 
227
        result = _tmp11_;
 
228
        _g_free0 (_tmp4_);
 
229
        return result;
 
230
}
 
231
 
 
232
 
 
233
gchar* zeitgeist_utils_get_database_file_retire_name (void) {
 
234
        gchar* result = NULL;
 
235
        GDateTime* _tmp0_;
 
236
        GDateTime* _tmp1_;
 
237
        gchar* _tmp2_ = NULL;
 
238
        gchar* _tmp3_;
 
239
        gchar* _tmp4_ = NULL;
 
240
        gchar* _tmp5_;
 
241
        gchar* _tmp6_;
 
242
        gchar* _tmp7_;
 
243
        _tmp0_ = g_date_time_new_now_local ();
 
244
        _tmp1_ = _tmp0_;
 
245
        _tmp2_ = g_date_time_format (_tmp1_, "%Y%m%d-%H%M%S");
 
246
        _tmp3_ = _tmp2_;
 
247
        _tmp4_ = g_strdup_printf (".%s.bck", _tmp3_);
 
248
        _tmp5_ = _tmp4_;
 
249
        _tmp6_ = g_strconcat (ZEITGEIST_UTILS_DATABASE_BASENAME, _tmp5_, NULL);
 
250
        _tmp7_ = _tmp6_;
 
251
        _g_free0 (_tmp5_);
 
252
        _g_free0 (_tmp3_);
 
253
        _g_date_time_unref0 (_tmp1_);
 
254
        result = _tmp7_;
 
255
        return result;
 
256
}
 
257
 
 
258
 
 
259
const gchar* zeitgeist_utils_get_local_extensions_path (void) {
 
260
        const gchar* result = NULL;
 
261
        const gchar* _tmp0_;
 
262
        const gchar* _tmp2_ = NULL;
 
263
        gchar* _tmp3_ = NULL;
 
264
        const gchar* _tmp4_;
 
265
        const gchar* _tmp5_;
 
266
        _tmp0_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
 
267
        if (_tmp0_ != NULL) {
 
268
                const gchar* _tmp1_;
 
269
                _tmp1_ = zeitgeist_utils_LOCAL_EXTENSIONS_PATH;
 
270
                result = _tmp1_;
 
271
                return result;
 
272
        }
 
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;
 
280
        result = _tmp5_;
 
281
        return result;
 
282
}
 
283
 
 
284
 
 
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;
 
290
        return result;
 
291
}
 
292
 
 
293
 
 
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);
 
306
        original = _tmp1_;
 
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);
 
318
                return;
 
319
        }
 
320
        _g_object_unref0 (destination);
 
321
        _g_object_unref0 (original);
 
322
}
 
323
 
 
324
 
 
325
void zeitgeist_utils_retire_database (GError** error) {
 
326
        GError * _inner_error_ = NULL;
 
327
        {
 
328
                const gchar* _tmp0_ = NULL;
 
329
                GFile* _tmp1_ = NULL;
 
330
                GFile* dbfile;
 
331
                GFile* _tmp2_;
 
332
                gchar* _tmp3_ = NULL;
 
333
                gchar* _tmp4_;
 
334
                _tmp0_ = zeitgeist_utils_get_database_file_path ();
 
335
                _tmp1_ = g_file_new_for_path (_tmp0_);
 
336
                dbfile = _tmp1_;
 
337
                _tmp2_ = dbfile;
 
338
                _tmp3_ = zeitgeist_utils_get_database_file_retire_name ();
 
339
                _tmp4_ = _tmp3_;
 
340
                g_file_set_display_name (_tmp2_, _tmp4_, NULL, &_inner_error_);
 
341
                _g_free0 (_tmp4_);
 
342
                if (_inner_error_ != NULL) {
 
343
                        _g_object_unref0 (dbfile);
 
344
                        goto __catch18_g_error;
 
345
                }
 
346
                _g_object_unref0 (dbfile);
 
347
        }
 
348
        goto __finally18;
 
349
        __catch18_g_error:
 
350
        {
 
351
                GError* err = NULL;
 
352
                GError* _tmp5_;
 
353
                const gchar* _tmp6_;
 
354
                gchar* _tmp7_ = NULL;
 
355
                gchar* message;
 
356
                const gchar* _tmp8_;
 
357
                GError* _tmp9_;
 
358
                err = _inner_error_;
 
359
                _inner_error_ = NULL;
 
360
                _tmp5_ = err;
 
361
                _tmp6_ = _tmp5_->message;
 
362
                _tmp7_ = g_strdup_printf ("Could not rename database: %s", _tmp6_);
 
363
                message = _tmp7_;
 
364
                _tmp8_ = message;
 
365
                _tmp9_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_DATABASE_RETIRE_FAILED, _tmp8_);
 
366
                _inner_error_ = _tmp9_;
 
367
                _g_free0 (message);
 
368
                _g_error_free0 (err);
 
369
                goto __finally18;
 
370
        }
 
371
        __finally18:
 
372
        if (_inner_error_ != NULL) {
 
373
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
374
                        g_propagate_error (error, _inner_error_);
 
375
                        return;
 
376
                } else {
 
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_);
 
379
                        return;
 
380
                }
 
381
        }
 
382
}
 
383
 
 
384
 
 
385
/**
 
386
         * Check if the value starts with the negation operator. If it does,
 
387
         * remove the operator from the value and return true. Otherwise,
 
388
         * return false.
 
389
         */
 
390
static glong string_strnlen (gchar* str, glong maxlen) {
 
391
        glong result = 0L;
 
392
        gchar* _tmp0_;
 
393
        glong _tmp1_;
 
394
        gchar* _tmp2_ = NULL;
 
395
        gchar* end;
 
396
        gchar* _tmp3_;
 
397
        _tmp0_ = str;
 
398
        _tmp1_ = maxlen;
 
399
        _tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
 
400
        end = _tmp2_;
 
401
        _tmp3_ = end;
 
402
        if (_tmp3_ == NULL) {
 
403
                glong _tmp4_;
 
404
                _tmp4_ = maxlen;
 
405
                result = _tmp4_;
 
406
                return result;
 
407
        } else {
 
408
                gchar* _tmp5_;
 
409
                gchar* _tmp6_;
 
410
                _tmp5_ = end;
 
411
                _tmp6_ = str;
 
412
                result = (glong) (_tmp5_ - _tmp6_);
 
413
                return result;
 
414
        }
 
415
}
 
416
 
 
417
 
 
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;
 
422
        glong _tmp1_;
 
423
        gboolean _tmp3_;
 
424
        glong _tmp9_;
 
425
        glong _tmp15_;
 
426
        glong _tmp18_;
 
427
        glong _tmp19_;
 
428
        glong _tmp20_;
 
429
        glong _tmp21_;
 
430
        glong _tmp22_;
 
431
        gchar* _tmp23_ = NULL;
 
432
        g_return_val_if_fail (self != NULL, NULL);
 
433
        _tmp1_ = offset;
 
434
        if (_tmp1_ >= ((glong) 0)) {
 
435
                glong _tmp2_;
 
436
                _tmp2_ = len;
 
437
                _tmp0_ = _tmp2_ >= ((glong) 0);
 
438
        } else {
 
439
                _tmp0_ = FALSE;
 
440
        }
 
441
        _tmp3_ = _tmp0_;
 
442
        if (_tmp3_) {
 
443
                glong _tmp4_;
 
444
                glong _tmp5_;
 
445
                glong _tmp6_ = 0L;
 
446
                _tmp4_ = offset;
 
447
                _tmp5_ = len;
 
448
                _tmp6_ = string_strnlen ((gchar*) self, _tmp4_ + _tmp5_);
 
449
                string_length = _tmp6_;
 
450
        } else {
 
451
                gint _tmp7_;
 
452
                gint _tmp8_;
 
453
                _tmp7_ = strlen (self);
 
454
                _tmp8_ = _tmp7_;
 
455
                string_length = (glong) _tmp8_;
 
456
        }
 
457
        _tmp9_ = offset;
 
458
        if (_tmp9_ < ((glong) 0)) {
 
459
                glong _tmp10_;
 
460
                glong _tmp11_;
 
461
                glong _tmp12_;
 
462
                _tmp10_ = string_length;
 
463
                _tmp11_ = offset;
 
464
                offset = _tmp10_ + _tmp11_;
 
465
                _tmp12_ = offset;
 
466
                g_return_val_if_fail (_tmp12_ >= ((glong) 0), NULL);
 
467
        } else {
 
468
                glong _tmp13_;
 
469
                glong _tmp14_;
 
470
                _tmp13_ = offset;
 
471
                _tmp14_ = string_length;
 
472
                g_return_val_if_fail (_tmp13_ <= _tmp14_, NULL);
 
473
        }
 
474
        _tmp15_ = len;
 
475
        if (_tmp15_ < ((glong) 0)) {
 
476
                glong _tmp16_;
 
477
                glong _tmp17_;
 
478
                _tmp16_ = string_length;
 
479
                _tmp17_ = offset;
 
480
                len = _tmp16_ - _tmp17_;
 
481
        }
 
482
        _tmp18_ = offset;
 
483
        _tmp19_ = len;
 
484
        _tmp20_ = string_length;
 
485
        g_return_val_if_fail ((_tmp18_ + _tmp19_) <= _tmp20_, NULL);
 
486
        _tmp21_ = offset;
 
487
        _tmp22_ = len;
 
488
        _tmp23_ = g_strndup (((gchar*) self) + _tmp21_, (gsize) _tmp22_);
 
489
        result = _tmp23_;
 
490
        return result;
 
491
}
 
492
 
 
493
 
 
494
gboolean zeitgeist_utils_parse_negation (gchar** val) {
 
495
        gboolean result = FALSE;
 
496
        const gchar* _tmp0_;
 
497
        gboolean _tmp1_ = FALSE;
 
498
        const gchar* _tmp2_;
 
499
        gchar* _tmp3_ = NULL;
 
500
        g_return_val_if_fail (val != NULL, FALSE);
 
501
        _tmp0_ = *val;
 
502
        _tmp1_ = g_str_has_prefix (_tmp0_, "!");
 
503
        if (!_tmp1_) {
 
504
                result = FALSE;
 
505
                return result;
 
506
        }
 
507
        _tmp2_ = *val;
 
508
        _tmp3_ = string_substring (_tmp2_, (glong) 1, (glong) (-1));
 
509
        _g_free0 (*val);
 
510
        *val = _tmp3_;
 
511
        result = TRUE;
 
512
        return result;
 
513
}
 
514
 
 
515
 
 
516
/**
 
517
         * Check if the value starts with the noexpand operator. If it does,
 
518
         * remove the operator from the value and return true. Otherwise,
 
519
         * return false.
 
520
         *
 
521
         * Check for the negation operator before calling this function.
 
522
         */
 
523
gboolean zeitgeist_utils_parse_noexpand (gchar** val) {
 
524
        gboolean result = FALSE;
 
525
        const gchar* _tmp0_;
 
526
        gboolean _tmp1_ = FALSE;
 
527
        const gchar* _tmp2_;
 
528
        gchar* _tmp3_ = NULL;
 
529
        g_return_val_if_fail (val != NULL, FALSE);
 
530
        _tmp0_ = *val;
 
531
        _tmp1_ = g_str_has_prefix (_tmp0_, "+");
 
532
        if (!_tmp1_) {
 
533
                result = FALSE;
 
534
                return result;
 
535
        }
 
536
        _tmp2_ = *val;
 
537
        _tmp3_ = string_substring (_tmp2_, (glong) 1, (glong) (-1));
 
538
        _g_free0 (*val);
 
539
        *val = _tmp3_;
 
540
        result = TRUE;
 
541
        return result;
 
542
}
 
543
 
 
544
 
 
545
/**
 
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.
 
549
         */
 
550
static guint8* string_get_data (const gchar* self, int* result_length1) {
 
551
        guint8* result;
 
552
        guint8* res;
 
553
        gint res_length1;
 
554
        gint _res_size_;
 
555
        gint _tmp0_;
 
556
        gint _tmp1_;
 
557
        gint _tmp2_;
 
558
        guint8* _tmp3_;
 
559
        gint _tmp3__length1;
 
560
        guint8* _tmp4_;
 
561
        gint _tmp4__length1;
 
562
        g_return_val_if_fail (self != NULL, NULL);
 
563
        res = (guint8*) self;
 
564
        res_length1 = -1;
 
565
        _res_size_ = res_length1;
 
566
        _tmp0_ = strlen (self);
 
567
        _tmp1_ = _tmp0_;
 
568
        res_length1 = (gint) _tmp1_;
 
569
        _tmp2_ = res_length1;
 
570
        _tmp3_ = res;
 
571
        _tmp3__length1 = res_length1;
 
572
        _tmp4_ = _tmp3_;
 
573
        _tmp4__length1 = _tmp3__length1;
 
574
        if (result_length1) {
 
575
                *result_length1 = _tmp4__length1;
 
576
        }
 
577
        result = _tmp4_;
 
578
        return result;
 
579
}
 
580
 
 
581
 
 
582
gboolean zeitgeist_utils_parse_wildcard (gchar** val) {
 
583
        gboolean result = FALSE;
 
584
        const gchar* _tmp0_;
 
585
        gboolean _tmp1_ = FALSE;
 
586
        const gchar* _tmp2_;
 
587
        guint8* _tmp3_;
 
588
        gint _tmp3__length1;
 
589
        guint8* _tmp4_;
 
590
        gint _tmp4__length1;
 
591
        guint8* val_data;
 
592
        gint val_data_length1;
 
593
        gint _val_data_size_;
 
594
        guint8* _tmp5_;
 
595
        gint _tmp5__length1;
 
596
        guint8* _tmp6_;
 
597
        gint _tmp6__length1;
 
598
        guint8 _tmp7_;
 
599
        g_return_val_if_fail (val != NULL, FALSE);
 
600
        _tmp0_ = *val;
 
601
        _tmp1_ = g_str_has_suffix (_tmp0_, "*");
 
602
        if (!_tmp1_) {
 
603
                result = FALSE;
 
604
                return result;
 
605
        }
 
606
        _tmp2_ = *val;
 
607
        _tmp3_ = string_get_data (_tmp2_, &_tmp3__length1);
 
608
        _tmp4_ = _tmp3_;
 
609
        _tmp4__length1 = _tmp3__length1;
 
610
        val_data = _tmp4_;
 
611
        val_data_length1 = _tmp4__length1;
 
612
        _val_data_size_ = val_data_length1;
 
613
        _tmp5_ = val_data;
 
614
        _tmp5__length1 = val_data_length1;
 
615
        _tmp6_ = val_data;
 
616
        _tmp6__length1 = val_data_length1;
 
617
        _tmp5_[_tmp6__length1 - 1] = (guint8) '\0';
 
618
        _tmp7_ = _tmp5_[_tmp6__length1 - 1];
 
619
        result = TRUE;
 
620
        return result;
 
621
}
 
622
 
 
623
 
 
624
/**
 
625
         * Return true if a string is empty (null or containing just a null
 
626
         * byte).
 
627
         */
 
628
gboolean zeitgeist_utils_is_empty_string (const gchar* s) {
 
629
        gboolean result = FALSE;
 
630
        gboolean _tmp0_ = FALSE;
 
631
        const gchar* _tmp1_;
 
632
        gboolean _tmp3_;
 
633
        _tmp1_ = s;
 
634
        if (_tmp1_ == NULL) {
 
635
                _tmp0_ = TRUE;
 
636
        } else {
 
637
                const gchar* _tmp2_;
 
638
                _tmp2_ = s;
 
639
                _tmp0_ = g_strcmp0 (_tmp2_, "") == 0;
 
640
        }
 
641
        _tmp3_ = _tmp0_;
 
642
        result = _tmp3_;
 
643
        return result;
 
644
}
 
645
 
 
646
 
 
647