contrib/git-credential-gnome-keyring.c: support ancient gnome-keyring

The gnome-keyring lib distributed with RHEL 5.X is ancient and does not provide a few of the functions/defines that more recent versions do, but mostly the API is the same. Let's provide the missing bits via macro definitions and function implementation. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Sep 23, 2013 at 11:49 UTC 5a3db110533b3b58002a03da837aa38fdc4bfc56
1 file changed +58
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+58
@@ -28,8 +28,66 @@
28 #include <stdlib.h>
29 #include <glib.h>
30 #include <gnome-keyring.h>
31 +
32 +#ifdef GNOME_KEYRING_DEFAULT
33 +
34 + /* Modern gnome-keyring */
35 +
36 #include <gnome-keyring-memory.h>
37
38 +#else
39 +
40 + /*
41 + * Support ancient gnome-keyring, circ. RHEL 5.X.
42 + * GNOME_KEYRING_DEFAULT seems to have been introduced with Gnome 2.22,
43 + * and the other features roughly around Gnome 2.20, 6 months before.
44 + * Ubuntu 8.04 used Gnome 2.22 (I think). Not sure any distro used 2.20.
45 + * So the existence/non-existence of GNOME_KEYRING_DEFAULT seems like
46 + * a decent thing to use as an indicator.
47 + */
48 +
49 +#define GNOME_KEYRING_DEFAULT NULL
50 +
51 +/*
52 + * ancient gnome-keyring returns DENIED when an entry is not found.
53 + * Setting NO_MATCH to DENIED will prevent us from reporting DENIED
54 + * errors during get and erase operations, but we will still report
55 + * DENIED errors during a store.
56 + */
57 +#define GNOME_KEYRING_RESULT_NO_MATCH GNOME_KEYRING_RESULT_DENIED
58 +
59 +#define gnome_keyring_memory_alloc g_malloc
60 +#define gnome_keyring_memory_free gnome_keyring_free_password
61 +#define gnome_keyring_memory_strdup g_strdup
62 +
63 +static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)
64 +{
65 + switch (result) {
66 + case GNOME_KEYRING_RESULT_OK:
67 + return "OK";
68 + case GNOME_KEYRING_RESULT_DENIED:
69 + return "Denied";
70 + case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
71 + return "No Keyring Daemon";
72 + case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
73 + return "Already UnLocked";
74 + case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
75 + return "No Such Keyring";
76 + case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
77 + return "Bad Arguments";
78 + case GNOME_KEYRING_RESULT_IO_ERROR:
79 + return "IO Error";
80 + case GNOME_KEYRING_RESULT_CANCELLED:
81 + return "Cancelled";
82 + case GNOME_KEYRING_RESULT_ALREADY_EXISTS:
83 + return "Already Exists";
84 + default:
85 + return "Unknown Error";
86 + }
87 +}
88 +
89 +#endif
90 +
91 /*
92 * This credential struct and API is simplified from git's credential.{h,c}
93 */