]>
Commit | Line | Data |
---|---|---|
bde1652c | 1 | package mit.moira; |
2 | ||
3 | public class MoiraConnect { | |
4 | boolean connected = false; | |
5 | boolean isauth = false; | |
6 | Object LOCK; | |
7 | ||
8 | String server = ""; | |
9 | MoiraConnect() { | |
10 | } | |
11 | ||
12 | public MoiraConnect(String server, Object lock) { | |
13 | this.server = server; | |
14 | this.LOCK = lock; | |
15 | } | |
16 | ||
17 | public void connect() throws MoiraException { | |
18 | if (!connected) { | |
19 | MoiraConnectInternal.connect(server); | |
20 | connected = true; | |
21 | } | |
22 | } | |
23 | ||
24 | public void auth() throws MoiraException { | |
25 | if (!isauth) { | |
26 | synchronized(LOCK) { | |
27 | MoiraConnectInternal.auth(); | |
28 | } | |
29 | isauth = true; | |
30 | } | |
31 | } | |
32 | ||
33 | public void proxy(String user) throws MoiraException { | |
34 | MoiraConnectInternal.proxy(user); | |
35 | } | |
36 | ||
37 | public void disconnect() { | |
38 | if (connected) { | |
39 | MoiraConnectInternal.disconnect(); | |
40 | connected = false; | |
41 | isauth = false; | |
42 | } | |
43 | } | |
44 | ||
45 | public ListInfo get_list_info(String list) throws MoiraException { | |
46 | if (!connected) throw new MoiraException("Not Connected"); | |
47 | String [] args = new String[1]; | |
48 | args[0] = list; | |
49 | Object [] retinternal = MoiraConnectInternal.mr_query("get_list_info", args); | |
50 | if (retinternal == null) return (null); | |
51 | if (retinternal.length == 0) return (null); | |
52 | if (retinternal.length != 1) throw new MoiraException("get_list_info returned more then one list!"); | |
53 | String [] entry = (String []) retinternal[0]; | |
54 | return (new ListInfo(entry[0], entry[1], entry[2], entry[3], entry[4], entry[5], entry[6], entry[7], entry[8], entry[9], entry[10], entry[11], entry[12])); | |
55 | } | |
56 | ||
57 | void update_list_info(String list, ListInfo info) throws MoiraException { | |
58 | if (!connected) throw new MoiraException("Not Connected"); | |
59 | String [] args = new String[11]; | |
60 | args[0] = list; | |
61 | args[1] = info.name; | |
62 | args[2] = info.active ? "1" : "0"; | |
63 | args[3] = info.bpublic ? "1" : "0"; | |
64 | args[4] = info.hidden ? "1" : "0"; | |
65 | args[5] = info.maillist ? "1" : "0"; | |
66 | args[6] = info.grouplist ? "1" : "0"; | |
67 | args[7] = info.gid_original; | |
68 | args[8] = info.ace_type; | |
69 | args[9] = info.ace_name; | |
70 | args[10] = info.description; | |
71 | Object [] retinternal = MoiraConnectInternal.mr_query("update_list", args); | |
72 | return; | |
73 | } | |
74 | ||
75 | void delete_member_from_list(String list, String type, String member) throws MoiraException { | |
76 | if (!connected) throw new MoiraException("Not Connected"); | |
77 | String [] args = new String[3]; | |
78 | args[0] = list; | |
79 | args[1] = type; | |
80 | args[2] = member; | |
81 | Object [] retinternal = MoiraConnectInternal.mr_query("delete_member_from_list", args); | |
82 | return; | |
83 | } | |
84 | ||
85 | void add_member_to_list(String list, String type, String member) throws MoiraException { | |
86 | if (!connected) throw new MoiraException("Not Connected"); | |
87 | String [] args = new String[3]; | |
88 | args[0] = list; | |
89 | args[1] = type; | |
90 | args[2] = member; | |
91 | Object [] retinternal = MoiraConnectInternal.mr_query("add_member_to_list", args); | |
92 | return; | |
93 | } | |
94 | ||
95 | public Member [] get_members_of_list(String list) throws MoiraException { | |
96 | if (!connected) throw new MoiraException("Not Connected"); | |
97 | String [] args = new String[1]; | |
98 | args[0] = list; | |
99 | Object [] retinternal = MoiraConnectInternal.mr_query("get_members_of_list", args); | |
100 | if (retinternal == null) return (null); | |
101 | Member [] retval = new Member[retinternal.length]; | |
102 | for (int i = 0; i < retinternal.length; i++) { | |
103 | String [] entry = (String []) retinternal[i]; | |
104 | retval[i] = new Member(entry[0], entry[1]); | |
105 | } | |
106 | return (retval); | |
107 | } | |
108 | } | |
109 | ||
110 | class MoiraConnectInternal { | |
111 | static native void connect(String server) throws MoiraException; | |
112 | static native void auth() throws MoiraException; | |
113 | static native void proxy(String user) throws MoiraException; | |
114 | static native void disconnect(); | |
115 | static native Object [] mr_query(String command, String [] args) throws MoiraException; | |
116 | static { | |
117 | System.loadLibrary("moirajava"); | |
118 | } | |
119 | } |