2003-03-20 Havoc Pennington <hp@pobox.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 <dbus/dbus-string.h>
29 #include "bus.h"
30
31 typedef struct BusPolicy     BusPolicy;
32 typedef struct BusPolicyRule BusPolicyRule;
33
34 typedef enum
35 {
36   BUS_POLICY_RULE_SEND,
37   BUS_POLICY_RULE_RECEIVE,
38   BUS_POLICY_RULE_OWN
39 } BusPolicyRuleType;
40
41 struct BusPolicyRule
42 {
43   int refcount;
44   
45   BusPolicyRuleType type;
46
47   unsigned int allow : 1; /**< #TRUE if this allows, #FALSE if it denies */
48   
49   union
50   {
51     struct
52     {
53       /* either can be NULL meaning "any" */
54       char *message_name;
55       char *destination;
56     } send;
57
58     struct
59     {
60       /* either can be NULL meaning "any" */
61       char *message_name;
62       char *origin;
63     } receive;
64
65     struct
66     {
67       /* can be NULL meaning "any" */
68       char *service_name;
69     } own;
70
71   } d;
72 };
73
74 BusPolicyRule* bus_policy_rule_new   (BusPolicyRuleType type,
75                                       dbus_bool_t       allow);
76 void           bus_policy_rule_ref   (BusPolicyRule    *rule);
77 void           bus_policy_rule_unref (BusPolicyRule    *rule);
78
79 BusPolicy*  bus_policy_new               (void);
80 void        bus_policy_ref               (BusPolicy        *policy);
81 void        bus_policy_unref             (BusPolicy        *policy);
82 dbus_bool_t bus_policy_check_can_send    (BusPolicy        *policy,
83                                           BusRegistry      *registry,
84                                           DBusConnection   *receiver,
85                                           DBusMessage      *message);
86 dbus_bool_t bus_policy_check_can_receive (BusPolicy        *policy,
87                                           BusRegistry      *registry,
88                                           DBusConnection   *sender,
89                                           DBusMessage      *message);
90 dbus_bool_t bus_policy_check_can_own     (BusPolicy        *policy,
91                                           DBusConnection   *connection,
92                                           const DBusString *service_name);
93
94
95
96 #endif /* BUS_POLICY_H */