60
60
#define gnome_keyring_memory_free gnome_keyring_free_password
61
61
#define gnome_keyring_memory_strdup g_strdup
62
62
63
- static const char * gnome_keyring_result_to_message (GnomeKeyringResult result )
63
+ static const char * gnome_keyring_result_to_message (GnomeKeyringResult result )
64
64
{
65
65
switch (result ) {
66
66
case GNOME_KEYRING_RESULT_OK :
@@ -95,9 +95,9 @@ static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)
95
95
96
96
static void gnome_keyring_done_cb (GnomeKeyringResult result , gpointer user_data )
97
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
101
102
102
* r = result ;
103
103
* done = 1 ;
@@ -130,34 +130,30 @@ static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, gu
130
130
/*
131
131
* This credential struct and API is simplified from git's credential.{h,c}
132
132
*/
133
- struct credential
134
- {
135
- char * protocol ;
136
- char * host ;
133
+ struct credential {
134
+ char * protocol ;
135
+ char * host ;
137
136
unsigned short port ;
138
- char * path ;
139
- char * username ;
140
- char * password ;
137
+ char * path ;
138
+ char * username ;
139
+ char * password ;
141
140
};
142
141
143
- #define CREDENTIAL_INIT \
144
- { NULL,NULL,0,NULL,NULL,NULL }
142
+ #define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
145
143
146
- typedef int (* credential_op_cb )(struct credential * );
144
+ typedef int (* credential_op_cb )(struct credential * );
147
145
148
- struct credential_operation
149
- {
150
- char * name ;
146
+ struct credential_operation {
147
+ char * name ;
151
148
credential_op_cb op ;
152
149
};
153
150
154
- #define CREDENTIAL_OP_END \
155
- { NULL,NULL }
151
+ #define CREDENTIAL_OP_END { NULL, NULL }
156
152
157
153
/* ----------------- GNOME Keyring functions ----------------- */
158
154
159
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 )
161
157
{
162
158
if (!c -> path )
163
159
return NULL ;
@@ -170,7 +166,7 @@ static char* keyring_object(struct credential *c)
170
166
171
167
static int keyring_get (struct credential * c )
172
168
{
173
- char * object = NULL ;
169
+ char * object = NULL ;
174
170
GList * entries ;
175
171
GnomeKeyringNetworkPasswordData * password_data ;
176
172
GnomeKeyringResult result ;
@@ -204,7 +200,7 @@ static int keyring_get(struct credential *c)
204
200
}
205
201
206
202
/* pick the first one from the list */
207
- password_data = (GnomeKeyringNetworkPasswordData * ) entries -> data ;
203
+ password_data = (GnomeKeyringNetworkPasswordData * )entries -> data ;
208
204
209
205
gnome_keyring_memory_free (c -> password );
210
206
c -> password = gnome_keyring_memory_strdup (password_data -> password );
@@ -221,7 +217,7 @@ static int keyring_get(struct credential *c)
221
217
static int keyring_store (struct credential * c )
222
218
{
223
219
guint32 item_id ;
224
- char * object = NULL ;
220
+ char * object = NULL ;
225
221
GnomeKeyringResult result ;
226
222
227
223
/*
@@ -262,7 +258,7 @@ static int keyring_store(struct credential *c)
262
258
263
259
static int keyring_erase (struct credential * c )
264
260
{
265
- char * object = NULL ;
261
+ char * object = NULL ;
266
262
GList * entries ;
267
263
GnomeKeyringNetworkPasswordData * password_data ;
268
264
GnomeKeyringResult result ;
@@ -298,22 +294,20 @@ static int keyring_erase(struct credential *c)
298
294
if (result == GNOME_KEYRING_RESULT_CANCELLED )
299
295
return EXIT_SUCCESS ;
300
296
301
- if (result != GNOME_KEYRING_RESULT_OK )
302
- {
297
+ if (result != GNOME_KEYRING_RESULT_OK ) {
303
298
g_critical ("%s" , gnome_keyring_result_to_message (result ));
304
299
return EXIT_FAILURE ;
305
300
}
306
301
307
302
/* pick the first one from the list (delete all matches?) */
308
- password_data = (GnomeKeyringNetworkPasswordData * ) entries -> data ;
303
+ password_data = (GnomeKeyringNetworkPasswordData * )entries -> data ;
309
304
310
305
result = gnome_keyring_item_delete_sync (
311
306
password_data -> keyring , password_data -> item_id );
312
307
313
308
gnome_keyring_network_password_list_free (entries );
314
309
315
- if (result != GNOME_KEYRING_RESULT_OK )
316
- {
310
+ if (result != GNOME_KEYRING_RESULT_OK ) {
317
311
g_critical ("%s" , gnome_keyring_result_to_message (result ));
318
312
return EXIT_FAILURE ;
319
313
}
@@ -325,9 +319,8 @@ static int keyring_erase(struct credential *c)
325
319
* Table with helper operation callbacks, used by generic
326
320
* credential helper main function.
327
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 },
331
324
{ "store" , keyring_store },
332
325
{ "erase" , keyring_erase },
333
326
CREDENTIAL_OP_END
@@ -353,24 +346,23 @@ static void credential_clear(struct credential *c)
353
346
354
347
static int credential_read (struct credential * c )
355
348
{
356
- char * buf ;
349
+ char * buf ;
357
350
size_t line_len ;
358
- char * key ;
359
- char * value ;
351
+ char * key ;
352
+ char * value ;
360
353
361
354
key = buf = gnome_keyring_memory_alloc (1024 );
362
355
363
- while (fgets (buf , 1024 , stdin ))
364
- {
356
+ while (fgets (buf , 1024 , stdin )) {
365
357
line_len = strlen (buf );
366
358
367
359
if (line_len && buf [line_len - 1 ] == '\n' )
368
- buf [-- line_len ]= '\0' ;
360
+ buf [-- line_len ] = '\0' ;
369
361
370
362
if (!line_len )
371
363
break ;
372
364
373
- value = strchr (buf ,'=' );
365
+ value = strchr (buf , '=' );
374
366
if (!value ) {
375
367
g_warning ("invalid credential line: %s" , key );
376
368
gnome_keyring_memory_free (buf );
@@ -384,7 +376,7 @@ static int credential_read(struct credential *c)
384
376
} else if (!strcmp (key , "host" )) {
385
377
g_free (c -> host );
386
378
c -> host = g_strdup (value );
387
- value = strrchr (c -> host ,':' );
379
+ value = strrchr (c -> host , ':' );
388
380
if (value ) {
389
381
* value ++ = '\0' ;
390
382
c -> port = atoi (value );
@@ -398,7 +390,8 @@ static int credential_read(struct credential *c)
398
390
} else if (!strcmp (key , "password" )) {
399
391
gnome_keyring_memory_free (c -> password );
400
392
c -> password = gnome_keyring_memory_strdup (value );
401
- while (* value ) * value ++ = '\0' ;
393
+ while (* value )
394
+ * value ++ = '\0' ;
402
395
}
403
396
/*
404
397
* Ignore other lines; we don't know what they mean, but
@@ -429,24 +422,24 @@ static void credential_write(const struct credential *c)
429
422
static void usage (const char * name )
430
423
{
431
424
struct credential_operation const * try_op = credential_helper_ops ;
432
- const char * basename = strrchr (name ,'/' );
425
+ const char * basename = strrchr (name , '/' );
433
426
434
427
basename = (basename ) ? basename + 1 : name ;
435
428
fprintf (stderr , "usage: %s <" , basename );
436
429
while (try_op -> name ) {
437
- fprintf (stderr ,"%s" ,(try_op ++ )-> name );
430
+ fprintf (stderr , "%s" , (try_op ++ )-> name );
438
431
if (try_op -> name )
439
- fprintf (stderr ,"%s" ,"|" );
432
+ fprintf (stderr , "%s" , "|" );
440
433
}
441
- fprintf (stderr ,"%s" ,">\n" );
434
+ fprintf (stderr , "%s" , ">\n" );
442
435
}
443
436
444
437
int main (int argc , char * argv [])
445
438
{
446
439
int ret = EXIT_SUCCESS ;
447
440
448
441
struct credential_operation const * try_op = credential_helper_ops ;
449
- struct credential cred = CREDENTIAL_INIT ;
442
+ struct credential cred = CREDENTIAL_INIT ;
450
443
451
444
if (!argv [1 ]) {
452
445
usage (argv [0 ]);
0 commit comments