contrib/git-credential-gnome-keyring.c: small stylistic cleanups
Signed-off-by: John Szakmeister <john@szakmeister.net> Signed-off-by: Junio C Hamano <gitster@pobox.com> Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com>
John Szakmeister committed
Dec 14, 2013 at 06:21 UTC
0162b3c43063ad8886a6e2f5bd52110f1e7ebfaf
1 file changed
+39
-46
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+39
-46
@@ -60,7 +60,7 @@
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)
63
+static const char *gnome_keyring_result_to_message(GnomeKeyringResult result)
64
{
65
switch (result) {
66
case GNOME_KEYRING_RESULT_OK:
@@ -95,9 +95,9 @@ static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)
95
96
static void gnome_keyring_done_cb(GnomeKeyringResult result, gpointer user_data)
97
{
98
- gpointer *data = (gpointer*) user_data;
99
- int *done = (int*) data[0];
100
- GnomeKeyringResult *r = (GnomeKeyringResult*) data[1];
98
+ gpointer *data = (gpointer *)user_data;
99
+ int *done = (int *)data[0];
100
+ GnomeKeyringResult *r = (GnomeKeyringResult *)data[1];
101
102
*r = result;
103
*done = 1;
@@ -130,34 +130,30 @@ static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, gu
130
/*
131
* This credential struct and API is simplified from git's credential.{h,c}
132
*/
133
-struct credential
134
-{
135
- char *protocol;
136
- char *host;
133
+struct credential {
134
+ char *protocol;
135
+ char *host;
136
unsigned short port;
138
- char *path;
139
- char *username;
140
- char *password;
137
+ char *path;
138
+ char *username;
139
+ char *password;
140
};
141
143
-#define CREDENTIAL_INIT \
144
- { NULL,NULL,0,NULL,NULL,NULL }
142
+#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
143
146
-typedef int (*credential_op_cb)(struct credential*);
144
+typedef int (*credential_op_cb)(struct credential *);
145
148
-struct credential_operation
149
-{
150
- char *name;
146
+struct credential_operation {
147
+ char *name;
148
credential_op_cb op;
149
};
150
154
-#define CREDENTIAL_OP_END \
155
- { NULL,NULL }
151
+#define CREDENTIAL_OP_END { NULL, NULL }
152
153
/* ----------------- GNOME Keyring functions ----------------- */
154
155
/* create a special keyring option string, if path is given */
160
-static char* keyring_object(struct credential *c)
156
+static char *keyring_object(struct credential *c)
157
{
158
if (!c->path)
159
return NULL;
@@ -170,7 +166,7 @@ static char* keyring_object(struct credential *c)
166
167
static int keyring_get(struct credential *c)
168
{
173
- char* object = NULL;
169
+ char *object = NULL;
170
GList *entries;
171
GnomeKeyringNetworkPasswordData *password_data;
172
GnomeKeyringResult result;
@@ -204,7 +200,7 @@ static int keyring_get(struct credential *c)
200
}
201
202
/* pick the first one from the list */
207
- password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
203
+ password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
204
205
gnome_keyring_memory_free(c->password);
206
c->password = gnome_keyring_memory_strdup(password_data->password);
@@ -221,7 +217,7 @@ static int keyring_get(struct credential *c)
217
static int keyring_store(struct credential *c)
218
{
219
guint32 item_id;
224
- char *object = NULL;
220
+ char *object = NULL;
221
GnomeKeyringResult result;
222
223
/*
@@ -262,7 +258,7 @@ static int keyring_store(struct credential *c)
258
259
static int keyring_erase(struct credential *c)
260
{
265
- char *object = NULL;
261
+ char *object = NULL;
262
GList *entries;
263
GnomeKeyringNetworkPasswordData *password_data;
264
GnomeKeyringResult result;
@@ -298,22 +294,20 @@ static int keyring_erase(struct credential *c)
294
if (result == GNOME_KEYRING_RESULT_CANCELLED)
295
return EXIT_SUCCESS;
296
301
- if (result != GNOME_KEYRING_RESULT_OK)
302
- {
297
+ if (result != GNOME_KEYRING_RESULT_OK) {
298
g_critical("%s", gnome_keyring_result_to_message(result));
299
return EXIT_FAILURE;
300
}
301
302
/* pick the first one from the list (delete all matches?) */
308
- password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
303
+ password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
304
305
result = gnome_keyring_item_delete_sync(
306
password_data->keyring, password_data->item_id);
307
308
gnome_keyring_network_password_list_free(entries);
309
315
- if (result != GNOME_KEYRING_RESULT_OK)
316
- {
310
+ if (result != GNOME_KEYRING_RESULT_OK) {
311
g_critical("%s", gnome_keyring_result_to_message(result));
312
return EXIT_FAILURE;
313
}
@@ -325,9 +319,8 @@ static int keyring_erase(struct credential *c)
319
* Table with helper operation callbacks, used by generic
320
* credential helper main function.
321
*/
328
-static struct credential_operation const credential_helper_ops[] =
329
-{
330
- { "get", keyring_get },
322
+static struct credential_operation const credential_helper_ops[] = {
323
+ { "get", keyring_get },
324
{ "store", keyring_store },
325
{ "erase", keyring_erase },
326
CREDENTIAL_OP_END
@@ -353,24 +346,23 @@ static void credential_clear(struct credential *c)
346
347
static int credential_read(struct credential *c)
348
{
356
- char *buf;
349
+ char *buf;
350
size_t line_len;
358
- char *key;
359
- char *value;
351
+ char *key;
352
+ char *value;
353
354
key = buf = gnome_keyring_memory_alloc(1024);
355
363
- while (fgets(buf, 1024, stdin))
364
- {
356
+ while (fgets(buf, 1024, stdin)) {
357
line_len = strlen(buf);
358
359
if (line_len && buf[line_len-1] == '\n')
368
- buf[--line_len]='\0';
360
+ buf[--line_len] = '\0';
361
362
if (!line_len)
363
break;
364
373
- value = strchr(buf,'=');
365
+ value = strchr(buf, '=');
366
if (!value) {
367
g_warning("invalid credential line: %s", key);
368
gnome_keyring_memory_free(buf);
@@ -384,7 +376,7 @@ static int credential_read(struct credential *c)
376
} else if (!strcmp(key, "host")) {
377
g_free(c->host);
378
c->host = g_strdup(value);
387
- value = strrchr(c->host,':');
379
+ value = strrchr(c->host, ':');
380
if (value) {
381
*value++ = '\0';
382
c->port = atoi(value);
@@ -398,7 +390,8 @@ static int credential_read(struct credential *c)
390
} else if (!strcmp(key, "password")) {
391
gnome_keyring_memory_free(c->password);
392
c->password = gnome_keyring_memory_strdup(value);
401
- while (*value) *value++ = '\0';
393
+ while (*value)
394
+ *value++ = '\0';
395
}
396
/*
397
* Ignore other lines; we don't know what they mean, but
@@ -429,16 +422,16 @@ static void credential_write(const struct credential *c)
422
static void usage(const char *name)
423
{
424
struct credential_operation const *try_op = credential_helper_ops;
432
- const char *basename = strrchr(name,'/');
425
+ const char *basename = strrchr(name, '/');
426
427
basename = (basename) ? basename + 1 : name;
428
fprintf(stderr, "usage: %s <", basename);
429
while (try_op->name) {
437
- fprintf(stderr,"%s",(try_op++)->name);
430
+ fprintf(stderr, "%s", (try_op++)->name);
431
if (try_op->name)
439
- fprintf(stderr,"%s","|");
432
+ fprintf(stderr, "%s", "|");
433
}
441
- fprintf(stderr,"%s",">\n");
434
+ fprintf(stderr, "%s", ">\n");
435
}
436
437
int main(int argc, char *argv[])
@@ -446,7 +439,7 @@ int main(int argc, char *argv[])
439
int ret = EXIT_SUCCESS;
440
441
struct credential_operation const *try_op = credential_helper_ops;
449
- struct credential cred = CREDENTIAL_INIT;
442
+ struct credential cred = CREDENTIAL_INIT;
443
444
if (!argv[1]) {
445
usage(argv[0]);