2003-03-19 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / bus / policy.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* policy.h  Policies for what a connection can do
3  *
4  * Copyright (C) 2003  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef BUS_POLICY_H
25 #define BUS_POLICY_H
26
27 #include <dbus/dbus.h>
28 #include "bus.h"
29
30 typedef struct BusPolicy     BusPolicy;
31 typedef struct BusPolicyRule BusPolicyRule;
32
33 typedef enum
34 {
35   DBUS_POLICY_RULE_SEND,
36   DBUS_POLICY_RULE_RECEIVE,
37   DBUS_POLICY_RULE_OWN
38 } BusPolicyRuleType;
39
40 struct BusPolicyRule
41 {
42   int refcount;
43   
44   BusPolicyRuleType type;
45
46   unsigned int allow : 1; /**< #TRUE if this allows, #FALSE if it denies */
47   
48   union
49   {
50     struct
51     {
52       /* either can be NULL meaning "any" */
53       char *message_name;
54       char *destination;
55     } send;
56
57     struct
58     {
59       /* either can be NULL meaning "any" */
60       char *message_name;
61       char *origin;
62     } receive;
63
64     struct
65     {
66       /* can be NULL meaning "any" */
67       char *service_name;
68     } own;
69
70   } d;
71 };
72
73 BusPolicyRule* bus_policy_rule_new   (BusPolicyRuleType type,
74                                       dbus_bool_t       allow);
75 void           bus_policy_rule_ref   (BusPolicyRule    *rule);
76 void           bus_policy_rule_unref (BusPolicyRule    *rule);
77
78 BusPolicy*  bus_policy_new               (void);
79 void        bus_policy_ref               (BusPolicy      *policy);
80 void        bus_policy_unref             (BusPolicy      *policy);
81 dbus_bool_t bus_policy_check_can_send    (BusPolicy      *policy,
82                                           DBusConnection *sender,
83                                           DBusMessage    *message);
84 dbus_bool_t bus_policy_check_can_receive (BusPolicy      *policy,
85                                           DBusConnection *receiver,
86                                           DBusMessage    *message);
87 dbus_bool_t bus_policy_check_can_own     (BusPolicy      *policy,
88                                           DBusConnection *connection,
89                                           const char     *service_name);
90
91
92
93 #endif /* BUS_POLICY_H */