summaryrefslogtreecommitdiffstats
path: root/libsefs/swig/sefs.i
blob: adc5d7e2c1716a057eb874d9e20701f9a61227c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * @file
 * SWIG declarations for libsefs.
 *
 * @author Jeremy A. Mowery jmowery@tresys.com
 * @author Jason Tang  jtang@tresys.com
 *
 * Copyright (C) 2006-2007 Tresys Technology, LLC
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

%module sefs

%{
#include <sefs/db.hh>
#include <sefs/entry.hh>
#include <sefs/fcfile.hh>
#include <sefs/fclist.hh>
#include <sefs/filesystem.hh>
#include <sefs/query.hh>
#include <sefs/util.h>
%}

%import apol.i

%exception;

%include std_except.i

%{
#undef BEGIN_EXCEPTION
#undef END_EXCEPTION
%}

%inline %{
	typedef struct apol_string_vector apol_string_vector_t;
%}

#ifdef SWIGPYTHON

%typemap(out) time_t {
	$result = PyInt_FromLong((long) $1);
}

#endif  // end of python specific code

#ifdef SWIGJAVA

/* handle size_t correctly in java as architecture independent */
%typemap(jni) size_t "jlong"
%typemap(jtype) size_t "long"
%typemap(jstype) size_t "long"
%typemap("javaimports") SWIGTYPE, FILE* %{
import com.tresys.setools.qpol.*;
import com.tresys.setools.apol.*;
%}
/* the following handles the dependencies on qpol and apol */
%pragma(java) jniclassimports=%{
import com.tresys.setools.qpol.*;
import com.tresys.setools.apol.*;
%}
%pragma(java) jniclasscode=%{
	static {
		try
		{
			libsefs_get_version ();
		}
		catch (UnsatisfiedLinkError ule)
		{
			System.loadLibrary("jsefs");
		}
	}
%}
%pragma(java) moduleimports=%{
import com.tresys.setools.qpol.*;
import com.tresys.setools.apol.*;
%}

%apply long { time_t }

%javaconst(1);

#else
/* not in java so handle size_t as architecture dependent */
#ifdef SWIGWORDSIZE64
typedef uint64_t size_t;
#else
typedef uint32_t size_t;
#endif

#endif  // end of Java specific code

#ifdef SWIGTCL

%wrapper %{
/* Tcl module's initialization routine is expected to be named
 * Sefs_Init(), but the output file will be called libtsefs.so instead
 * of libsefs.so.  Therefore add an alias from Tsefs_Init() to the
 * real Sefs_Init().
 */
SWIGEXPORT int Tsefs_Init(Tcl_Interp *interp) {
	return SWIG_init(interp);
}
%}

%typemap(out) time_t {
	Tcl_SetObjResult(interp, Tcl_NewLongObj((long) $1));
}

#endif  // end of Tcl specific code


%nodefaultctor;

#define __attribute__(x)

%ignore sefs_fcfile::fileList() const;

// don't wrap private friend functions
#define SWIG_FRIENDS

%newobject sefs_fclist::runQuery(sefs_query * query);
%newobject sefs_entry::toString();
%newobject sefs_default_file_contexts_get_path();

%include <sefs/fclist.hh>
%include <sefs/db.hh>
%include <sefs/entry.hh>
%include <sefs/fcfile.hh>
%include <sefs/filesystem.hh>
%include <sefs/query.hh>

const char *libsefs_get_version (void);
char *sefs_default_file_contexts_get_path(void);

%inline %{
	// needed to convert from the results of runQuery() to the entry
	sefs_entry *sefs_entry_from_void(void *v) {
		return static_cast<sefs_entry *>(v);
	}
%}

%extend sefs_fcfile {
	const apol_string_vector_t *fileListStrs() const
	{
		const apol_vector_t *v = self->fileList();
		return reinterpret_cast<const apol_string_vector_t*>(v);
	}
}