From f455c2f6077225d8b87a9a9e9d7e237c36a7ca13 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Sat, 20 Oct 2007 21:42:43 -0400 Subject: [PATCH] add C++ include guards and a new method to get pfe's by annotation --- polkit-dbus/polkit-dbus.h | 3 +++ polkit-grant/polkit-grant.h | 3 +++ polkit/polkit-action.h | 4 ++++ polkit/polkit-caller.h | 4 ++++ polkit/polkit-config.h | 5 +++++ polkit/polkit-context.h | 4 ++++ polkit/polkit-error.h | 6 ++++++ polkit/polkit-grant-database.h | 4 ++++ polkit/polkit-policy-cache.c | 42 +++++++++++++++++++++++++++++++++++++++ polkit/polkit-policy-cache.h | 10 ++++++++++ polkit/polkit-policy-default.h | 5 +++++ polkit/polkit-policy-file-entry.h | 4 ++++ polkit/polkit-policy-file.h | 5 +++++ polkit/polkit-result.h | 4 ++++ polkit/polkit-seat.h | 4 ++++ polkit/polkit-session.h | 4 ++++ polkit/polkit-types.h | 12 +++++++++++ polkit/polkit-utils.h | 4 ++++ polkit/polkit.h | 1 + 19 files changed, 128 insertions(+) diff --git a/polkit-dbus/polkit-dbus.h b/polkit-dbus/polkit-dbus.h index 10b5c90..95166a5 100644 --- a/polkit-dbus/polkit-dbus.h +++ b/polkit-dbus/polkit-dbus.h @@ -30,6 +30,8 @@ #include #include +POLKIT_BEGIN_DECLS + PolKitSession *polkit_session_new_from_objpath (DBusConnection *con, const char *objpath, uid_t uid, DBusError *error); PolKitSession *polkit_session_new_from_cookie (DBusConnection *con, const char *cookie, DBusError *error); @@ -54,6 +56,7 @@ PolKitCaller *polkit_tracker_get_caller_from_dbus_name (PolKitTracker *pk_trac PolKitCaller *polkit_tracker_get_caller_from_pid (PolKitTracker *pk_tracker, pid_t pid, DBusError *error); +POLKIT_END_DECLS #endif /* POLKIT_DBUS_H */ diff --git a/polkit-grant/polkit-grant.h b/polkit-grant/polkit-grant.h index 630d0ae..2fdf6a4 100644 --- a/polkit-grant/polkit-grant.h +++ b/polkit-grant/polkit-grant.h @@ -28,6 +28,8 @@ #include +POLKIT_BEGIN_DECLS + struct _PolKitGrant; typedef struct _PolKitGrant PolKitGrant; @@ -360,6 +362,7 @@ void polkit_grant_cancel_auth (PolKitGrant *polkit_grant); void polkit_grant_io_func (PolKitGrant *polkit_grant, int fd); void polkit_grant_child_func (PolKitGrant *polkit_grant, pid_t pid, int exit_code); +POLKIT_END_DECLS #endif /* POLKIT_GRANT_H */ diff --git a/polkit/polkit-action.h b/polkit/polkit-action.h index 19e911d..d062124 100644 --- a/polkit/polkit-action.h +++ b/polkit/polkit-action.h @@ -32,6 +32,8 @@ #include +POLKIT_BEGIN_DECLS + struct _PolKitAction; typedef struct _PolKitAction PolKitAction; @@ -46,6 +48,8 @@ polkit_bool_t polkit_action_validate (PolKitAction *action); polkit_bool_t polkit_action_validate_id (const char *action_id); +POLKIT_END_DECLS + #endif /* POLKIT_ACTION_H */ diff --git a/polkit/polkit-caller.h b/polkit/polkit-caller.h index b6b63eb..ad52102 100644 --- a/polkit/polkit-caller.h +++ b/polkit/polkit-caller.h @@ -34,6 +34,8 @@ #include #include +POLKIT_BEGIN_DECLS + struct _PolKitCaller; typedef struct _PolKitCaller PolKitCaller; @@ -54,4 +56,6 @@ polkit_bool_t polkit_caller_get_ck_session (PolKitCaller *caller, Pol void polkit_caller_debug (PolKitCaller *caller); polkit_bool_t polkit_caller_validate (PolKitCaller *caller); +POLKIT_END_DECLS + #endif /* POLKIT_H */ diff --git a/polkit/polkit-config.h b/polkit/polkit-config.h index 40f1590..aed5655 100644 --- a/polkit/polkit-config.h +++ b/polkit/polkit-config.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,8 @@ #include #include +POLKIT_BEGIN_DECLS + struct _PolKitConfig; typedef struct _PolKitConfig PolKitConfig; @@ -78,6 +81,8 @@ polkit_bool_t polkit_config_determine_admin_auth_type (PolKitConfig PolKitConfigAdminAuthType *out_admin_auth_type, const char **out_data); +POLKIT_END_DECLS + #endif /* POLKIT_CONFIG_H */ diff --git a/polkit/polkit-context.h b/polkit/polkit-context.h index 867265a..5c66514 100644 --- a/polkit/polkit-context.h +++ b/polkit/polkit-context.h @@ -41,6 +41,8 @@ #include #include +POLKIT_BEGIN_DECLS + struct _PolKitContext; typedef struct _PolKitContext PolKitContext; @@ -165,6 +167,8 @@ PolKitResult polkit_context_can_caller_do_action (PolKitContext *pk_contex PolKitConfig *polkit_context_get_config (PolKitContext *pk_context, PolKitError **error); +POLKIT_END_DECLS + #endif /* POLKIT_CONTEXT_H */ diff --git a/polkit/polkit-error.h b/polkit/polkit-error.h index cd5fc71..91d85cc 100644 --- a/polkit/polkit-error.h +++ b/polkit/polkit-error.h @@ -30,6 +30,10 @@ #ifndef POLKIT_ERROR_H #define POLKIT_ERROR_H +#include + +POLKIT_BEGIN_DECLS + /** * PolKitErrorCode: * @POLKIT_ERROR_OUT_OF_MEMORY: Out of memory @@ -51,4 +55,6 @@ const char *polkit_error_get_error_message (PolKitError *error); void polkit_error_free (PolKitError *error); void polkit_error_set_error (PolKitError **error, PolKitErrorCode error_code, const char *format, ...) __attribute__((__format__ (__printf__, 3, 4))); +POLKIT_END_DECLS + #endif /* POLKIT_ERROR_H */ diff --git a/polkit/polkit-grant-database.h b/polkit/polkit-grant-database.h index 33a6654..e04dac5 100644 --- a/polkit/polkit-grant-database.h +++ b/polkit/polkit-grant-database.h @@ -28,6 +28,8 @@ #include +POLKIT_BEGIN_DECLS + PolKitResult _polkit_grantdb_check_can_caller_do_action (PolKitContext *pk_context, PolKitAction *action, PolKitCaller *caller); @@ -78,4 +80,6 @@ void _polkit_grantdb_foreach (PolKitGrantDbForeachFunc callback, void *user_data polkit_bool_t _polkit_grantdb_delete_for_user (uid_t uid); +POLKIT_END_DECLS + #endif /* POLKIT_GRANT_DATABASE_H */ diff --git a/polkit/polkit-policy-cache.c b/polkit/polkit-policy-cache.c index d4e4a06..0fcd9c2 100644 --- a/polkit/polkit-policy-cache.c +++ b/polkit/polkit-policy-cache.c @@ -301,3 +301,45 @@ polkit_policy_cache_foreach (PolKitPolicyCache *policy_cache, callback (policy_cache, pfe, user_data); } } + +/** + * polkit_policy_cache_get_entry_by_annotation: + * @policy_cache: the policy cache + * @annotation_key: the key to check for + * @annotation_value: the value to check for + * + * Find the first policy file entry where a given annotation matches a + * given value. Note that there is nothing preventing the existence of + * multiple policy file entries matching this criteria; it would + * however be a packaging bug if this situation occured. + * + * Returns: The first #PolKitPolicyFileEntry matching the search + * criteria. The caller shall not unref this object. Returns #NULL if + * there are no policy file entries matching the search criteria. + */ +PolKitPolicyFileEntry* +polkit_policy_cache_get_entry_by_annotation (PolKitPolicyCache *policy_cache, + const char *annotation_key, + const char *annotation_value) +{ + GSList *i; + + g_return_val_if_fail (policy_cache != NULL, NULL); + g_return_val_if_fail (annotation_key != NULL, NULL); + g_return_val_if_fail (annotation_value != NULL, NULL); + + for (i = policy_cache->priv_entries; i != NULL; i = g_slist_next (i)) { + const char *value; + PolKitPolicyFileEntry *pfe = i->data; + + value = polkit_policy_file_entry_get_annotation (pfe, annotation_key); + if (value == NULL) + continue; + + if (strcmp (annotation_value, value) == 0) { + return pfe; + } + } + + return NULL; +} diff --git a/polkit/polkit-policy-cache.h b/polkit/polkit-policy-cache.h index 535f7e0..e7e5662 100644 --- a/polkit/polkit-policy-cache.h +++ b/polkit/polkit-policy-cache.h @@ -30,10 +30,13 @@ #ifndef POLKIT_POLICY_CACHE_H #define POLKIT_POLICY_CACHE_H +#include #include #include #include +POLKIT_BEGIN_DECLS + struct _PolKitPolicyCache; typedef struct _PolKitPolicyCache PolKitPolicyCache; @@ -56,10 +59,17 @@ PolKitPolicyFileEntry* polkit_policy_cache_get_entry (PolKitPolicyCache *policy_ PolKitAction *action); PolKitPolicyFileEntry* polkit_policy_cache_get_entry_by_id (PolKitPolicyCache *policy_cache, const char *action_id); + +PolKitPolicyFileEntry* polkit_policy_cache_get_entry_by_annotation (PolKitPolicyCache *policy_cache, + const char *annotation_key, + const char *annotation_value); + void polkit_policy_cache_foreach (PolKitPolicyCache *policy_cache, PolKitPolicyCacheForeachFunc callback, void *user_data); +POLKIT_END_DECLS + #endif /* POLKIT_POLICY_CACHE_H */ diff --git a/polkit/polkit-policy-default.h b/polkit/polkit-policy-default.h index b2dced8..a9f6146 100644 --- a/polkit/polkit-policy-default.h +++ b/polkit/polkit-policy-default.h @@ -30,12 +30,15 @@ #ifndef POLKIT_POLICY_DEFAULT_H #define POLKIT_POLICY_DEFAULT_H +#include #include #include #include #include #include +POLKIT_BEGIN_DECLS + struct _PolKitPolicyDefault; typedef struct _PolKitPolicyDefault PolKitPolicyDefault; @@ -57,6 +60,8 @@ PolKitResult polkit_policy_default_get_allow_active (PolKitPolicyDefault *policy /* TODO: export knobs for "default policy" */ +POLKIT_END_DECLS + #endif /* POLKIT_POLICY_DEFAULT_H */ diff --git a/polkit/polkit-policy-file-entry.h b/polkit/polkit-policy-file-entry.h index 2046330..8eb88a9 100644 --- a/polkit/polkit-policy-file-entry.h +++ b/polkit/polkit-policy-file-entry.h @@ -30,9 +30,12 @@ #ifndef POLKIT_POLICY_FILE_ENTRY_H #define POLKIT_POLICY_FILE_ENTRY_H +#include #include #include +POLKIT_BEGIN_DECLS + struct _PolKitPolicyFileEntry; typedef struct _PolKitPolicyFileEntry PolKitPolicyFileEntry; @@ -66,6 +69,7 @@ void polkit_policy_file_entry_annotations_foreach (PolKitPolic const char *polkit_policy_file_entry_get_annotation (PolKitPolicyFileEntry *policy_file_entry, const char *key); +POLKIT_END_DECLS #endif /* POLKIT_POLICY_FILE_ENTRY_H */ diff --git a/polkit/polkit-policy-file.h b/polkit/polkit-policy-file.h index 85e89b0..ac590c3 100644 --- a/polkit/polkit-policy-file.h +++ b/polkit/polkit-policy-file.h @@ -30,9 +30,12 @@ #ifndef POLKIT_POLICY_FILE_H #define POLKIT_POLICY_FILE_H +#include #include #include +POLKIT_BEGIN_DECLS + struct _PolKitPolicyFile; typedef struct _PolKitPolicyFile PolKitPolicyFile; @@ -57,6 +60,8 @@ void polkit_policy_file_entry_foreach (PolKitPolicyFile PolKitPolicyFileEntryForeachFunc cb, void *user_data); +POLKIT_END_DECLS + #endif /* POLKIT_POLICY_FILE_H */ diff --git a/polkit/polkit-result.h b/polkit/polkit-result.h index 92c6a8e..3ebd17d 100644 --- a/polkit/polkit-result.h +++ b/polkit/polkit-result.h @@ -32,6 +32,8 @@ #include +POLKIT_BEGIN_DECLS + /** * PolKitResult: * @POLKIT_RESULT_UNKNOWN: The result is unknown / cannot be @@ -88,4 +90,6 @@ polkit_result_to_string_representation (PolKitResult result); polkit_bool_t polkit_result_from_string_representation (const char *string, PolKitResult *out_result); +POLKIT_END_DECLS + #endif /* POLKIT_RESULT_H */ diff --git a/polkit/polkit-seat.h b/polkit/polkit-seat.h index 5f322a8..ecb9958 100644 --- a/polkit/polkit-seat.h +++ b/polkit/polkit-seat.h @@ -32,6 +32,8 @@ #include +POLKIT_BEGIN_DECLS + struct _PolKitSeat; typedef struct _PolKitSeat PolKitSeat; @@ -44,6 +46,8 @@ polkit_bool_t polkit_seat_get_ck_objref (PolKitSeat *seat, char **out_ck_o void polkit_seat_debug (PolKitSeat *seat); polkit_bool_t polkit_seat_validate (PolKitSeat *seat); +POLKIT_END_DECLS + #endif /* POLKIT_SEAT_H */ diff --git a/polkit/polkit-session.h b/polkit/polkit-session.h index 390666d..b1a2abe 100644 --- a/polkit/polkit-session.h +++ b/polkit/polkit-session.h @@ -35,6 +35,8 @@ #include +POLKIT_BEGIN_DECLS + struct _PolKitSession; typedef struct _PolKitSession PolKitSession; @@ -57,4 +59,6 @@ polkit_bool_t polkit_session_get_ck_remote_host (PolKitSession *session, char void polkit_session_debug (PolKitSession *session); polkit_bool_t polkit_session_validate (PolKitSession *session); +POLKIT_END_DECLS + #endif /* POLKIT_SESSION_H */ diff --git a/polkit/polkit-types.h b/polkit/polkit-types.h index 97a7ab2..529b18d 100644 --- a/polkit/polkit-types.h +++ b/polkit/polkit-types.h @@ -30,6 +30,16 @@ #ifndef POLKIT_TYPES_H #define POLKIT_TYPES_H +#ifdef __cplusplus +# define POLKIT_BEGIN_DECLS extern "C" { +# define POLKIT_END_DECLS } +#else +# define POLKIT_BEGIN_DECLS +# define POLKIT_END_DECLS +#endif + +POLKIT_BEGIN_DECLS + /** * SECTION:polkit-types * @title: Basic types @@ -59,6 +69,8 @@ typedef unsigned long long polkit_uint64_t; # define FALSE 0 #endif +POLKIT_END_DECLS + #endif /* POLKIT_TYPES_H */ diff --git a/polkit/polkit-utils.h b/polkit/polkit-utils.h index 5dee853..910033a 100644 --- a/polkit/polkit-utils.h +++ b/polkit/polkit-utils.h @@ -28,10 +28,14 @@ #include +POLKIT_BEGIN_DECLS + polkit_bool_t _pk_validate_identifier (const char *identifier); polkit_bool_t _pk_validate_unique_bus_name (const char *unique_bus_name); +POLKIT_END_DECLS + #endif /* POLKIT_UTILS_H */ diff --git a/polkit/polkit.h b/polkit/polkit.h index 581fbe3..096e72b 100644 --- a/polkit/polkit.h +++ b/polkit/polkit.h @@ -39,6 +39,7 @@ #include #include #include +#include #undef _POLKIT_INSIDE_POLKIT_H #endif /* POLKIT_H */ -- 2.7.4