~shnatsel/+junk/pkg-kde-tools-backport

« back to all changes in this revision

Viewing changes to dlrestrictions/dlrestrictions.h

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2016-04-18 20:56:33 UTC
  • Revision ID: shnatsel@gmail.com-20160418205633-i7sh6o3o6yzm410a
Initial import of version 0.15.16ubuntu2 from vivid

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2011  Modestas Vainius <modax@debian.org>
 
3
 
 
4
    This file is part of DLRestrictions.
 
5
 
 
6
    This program is free software: you can redistribute it and/or modify it
 
7
    under the terms of the GNU Lesser General Public License as published by
 
8
    the Free Software Foundation, either version 2.1 of the License, or (at your
 
9
    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 Lesser General Public License
 
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#ifndef _LIBRUNTIMERESTRICTIONS_H_
 
21
#define _LIBRUNTIMERESTRICTIONS_H_
 
22
 
 
23
#include <sys/types.h>
 
24
 
 
25
#ifndef DLR_LIBRARY_NAME
 
26
#define DLR_LIBRARY_NAME            "DLRestrictions"
 
27
#endif
 
28
 
 
29
#define DLR_STRINGIFY(s)            #s
 
30
#define DLR_STRINGIFY2(s)           DLR_STRINGIFY(s)
 
31
 
 
32
#define DLR_SYMBOL                  dlrestrictions_data
 
33
#define DLR_SYMBOL_NAME             DLR_STRINGIFY2(DLR_SYMBOL)
 
34
#define DLR_SYMBOL_MAGIC             "DLR_SYMBOL_V1:"
 
35
#define MAX_DLR_EXPRESSION_LENGTH    4096
 
36
 
 
37
typedef struct {
 
38
    char magic[sizeof(DLR_SYMBOL_MAGIC)];
 
39
    unsigned int expression_length;
 
40
    const char *expression;
 
41
} dlr_symbol_t;
 
42
 
 
43
/* FIXME: proper visibility stuff */
 
44
#define DLR_EXPORT_SYMBOL(expression) \
 
45
    __attribute__((visibility("default"))) \
 
46
    const dlr_symbol_t DLR_SYMBOL = { \
 
47
        DLR_SYMBOL_MAGIC, \
 
48
        (unsigned int) sizeof(expression), \
 
49
        expression \
 
50
    }
 
51
 
 
52
/* Get or set the name of the DLRestrictions symbol */
 
53
void dlr_set_symbol_name(const char *name);
 
54
const char* dlr_get_symbol_name(void);
 
55
 
 
56
/* Error functions */
 
57
const char* dlr_error(void);
 
58
int dlr_snprintf_pretty_error(char *str, size_t n, const char *context);
 
59
void dlr_print_pretty_error(const char *context);
 
60
 
 
61
/* Library compatibility checking functions */
 
62
 
 
63
/*
 
64
   Public function for verification of the given library file against global
 
65
   symbol object.
 
66
 
 
67
   * file - if present, the file to dlopen(); if omitted, the handle parameter
 
68
            will be used.
 
69
   * handle - if not NULL, the handle of the dlopen()'ed file will be stored here
 
70
              (and the object won't be dlclose()'ed). If file is NULL, handle must
 
71
              be non-NULL and point to the already open shared object.
 
72
   * Return value:
 
73
      < 0 - error occured while checking compatibility:
 
74
          * -ENOENT - unable to open file;
 
75
          * -ENOTDIR - unable to dlopen() global symbol object;
 
76
          * -EPROTO - syntax or other fatal error while checking compatibility;
 
77
     == 0 - library and its dependencies are NOT compatible with global object;
 
78
      > 0 - library and its dependencies are compatible with global object;
 
79
*/
 
80
int dlr_check_file_compatibility(const char *file, void **handle);
 
81
 
 
82
/*
 
83
   An extended wrapper around dlopen() with integrated file compatibility checking.
 
84
 
 
85
   * file - same as to dlopen();
 
86
   * mode - same as to dlopen();
 
87
   * printerror - if enabled, a pretty DLRestrctions error will be printed to stderr
 
88
     when one occurs or if the file is NOT compatible.
 
89
   * fail_on_error - if enabled, NULL will be returned if DLRestrictions specific
 
90
     error occurs. Please note that successful compatibility checking regardless
 
91
     of the outcome is NOT an error.
 
92
   * Return value - a valid dlopen() handle if successful, NULL otherwise.
 
93
*/
 
94
void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_on_error);
 
95
 
 
96
#endif