Skip to content

Commit cd670f6

Browse files
committed
core: add dynamic password infrastructure
Some media sources (e.g., DAAP) support notifying a client that a password is required at connection time. Since such sources are commonly detected with protocols like DNS-SD, Grilo needs a mechanism to support handling such password requests. This work adds a new "grl_source_notify_authenticate" function which a plugin can call when a password is needed. The function, in turn, emits an "authenticate" signal which the application should respond to by obtaining a password. The application then provides the password back to the plugin by calling the new "grl_daap_source_continue_with_password" function. Signed-off-by: W. Michael Petullo <[email protected]>
1 parent a520247 commit cd670f6

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

src/grl-marshal.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
VOID:BOXED,ENUM,BOOLEAN
2+
VOID:POINTER

src/grl-source.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enum {
7474

7575
enum {
7676
SIG_CONTENT_CHANGED,
77+
SIG_AUTHENTICATE,
7778
SIG_LAST
7879
};
7980

@@ -513,6 +514,26 @@ grl_source_class_init (GrlSourceClass *source_class)
513514
GRL_TYPE_SOURCE_CHANGE_TYPE,
514515
G_TYPE_BOOLEAN);
515516

517+
/**
518+
* GrlSource::authenticate:
519+
* @source: source that requires authentication to continue.
520+
*
521+
* Signals that the source requires authentication to continue.
522+
*
523+
* Since: 0.3.5
524+
*/
525+
source_signals[SIG_AUTHENTICATE] =
526+
g_signal_new("authenticate",
527+
G_TYPE_FROM_CLASS (gobject_class),
528+
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
529+
0,
530+
NULL,
531+
NULL,
532+
grl_marshal_VOID__POINTER,
533+
G_TYPE_NONE,
534+
1,
535+
G_TYPE_POINTER);
536+
516537
g_type_class_add_private (source_class,
517538
sizeof (GrlSourcePrivate));
518539
}
@@ -3984,6 +4005,27 @@ grl_source_search_sync (GrlSource *source,
39844005
return result;
39854006
}
39864007

4008+
/**
4009+
* grl_source_continue_with_password:
4010+
* @source: a source
4011+
* @opaque: opaque data from the plugin which bears the information necessary
4012+
* for the plugin to continue the browse or search operation once the password
4013+
* is known
4014+
* @password: the password needed to complete browse or search operation
4015+
*
4016+
* Complete a browse or search operation by providing the plugin the needed
4017+
* password.
4018+
*
4019+
* Since: 0.3.5
4020+
*/
4021+
void
4022+
grl_source_continue_with_password (GrlSource *source,
4023+
gpointer opaque,
4024+
gchar *password)
4025+
{
4026+
GRL_SOURCE_GET_CLASS (source)->continue_with_password (source, opaque, password);
4027+
}
4028+
39874029
/**
39884030
* grl_source_query:
39894031
* @source: a source
@@ -4579,6 +4621,36 @@ void grl_source_notify_change_list (GrlSource *source,
45794621
g_ptr_array_unref (changed_medias);
45804622
}
45814623

4624+
/**
4625+
* grl_source_notify_authenticate:
4626+
* @source: a source
4627+
* @opaque: opaque data from the plugin which bears the information necessary
4628+
* for the plugin to continue the browse or search operation once the password
4629+
* is known
4630+
*
4631+
* Complete a browse or search operation by providing the plugin the requisite
4632+
* password.
4633+
*
4634+
* Emits "authenticate" signal to notify subscribers that authentication is
4635+
* needed for @source to proceed.
4636+
*
4637+
* See GrlSource::authenticate signal.
4638+
*
4639+
* <note>
4640+
* <para>
4641+
* This function is intended to be used only by plugins.
4642+
* </para>
4643+
* </note>
4644+
*
4645+
* Since: 0.3.5
4646+
*/
4647+
void grl_source_notify_authenticate (GrlSource *source, gpointer opaque)
4648+
{
4649+
g_return_if_fail (GRL_IS_SOURCE (source));
4650+
4651+
g_signal_emit (source, source_signals[SIG_AUTHENTICATE], 0, opaque);
4652+
}
4653+
45824654
/**
45834655
* grl_source_notify_change:
45844656
* @source: a source

src/grl-source.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ typedef struct _GrlSourceClass GrlSourceClass;
413413
* exposed by a certain URI.
414414
* @browse: browse through a list of media
415415
* @search: search for media
416+
* @continue_with_password: continue search or browse with password
416417
* @query: query for a specific media
417418
* @remove: remove a media from a container
418419
* @store: store a media in a container
@@ -454,6 +455,10 @@ struct _GrlSourceClass {
454455

455456
void (*search) (GrlSource *source, GrlSourceSearchSpec *ss);
456457

458+
void (*continue_with_password) (GrlSource *source,
459+
gpointer opaque,
460+
gchar *password);
461+
457462
void (*query) (GrlSource *source, GrlSourceQuerySpec *qs);
458463

459464
void (*remove) (GrlSource *source, GrlSourceRemoveSpec *rs);
@@ -555,6 +560,10 @@ GList *grl_source_search_sync (GrlSource *source,
555560
GrlOperationOptions *options,
556561
GError **error);
557562

563+
void grl_source_continue_with_password (GrlSource *source,
564+
gpointer opaque,
565+
gchar *password);
566+
558567
guint grl_source_query (GrlSource *source,
559568
const gchar *query,
560569
const GList *keys,
@@ -619,6 +628,8 @@ void grl_source_notify_change (GrlSource *source,
619628
GrlSourceChangeType change_type,
620629
gboolean location_unknown);
621630

631+
void grl_source_notify_authenticate (GrlSource *source, gpointer opaque);
632+
622633
const gchar *grl_source_get_id (GrlSource *source);
623634

624635
const gchar *grl_source_get_name (GrlSource *source);

tools/grilo-test-ui/main.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,27 @@ query_btn_clicked_cb (GtkButton *btn, gpointer user_data)
13981398
}
13991399
}
14001400

1401+
typedef struct {
1402+
GrlSource *source;
1403+
GtkWindow *window;
1404+
GtkEntry *entry;
1405+
gpointer opaque;
1406+
} AuthCbArgs;
1407+
1408+
static void
1409+
auth_btn_clicked_cb (GtkButton *btn, gpointer user_data)
1410+
{
1411+
gchar *password;
1412+
AuthCbArgs *args = user_data;
1413+
1414+
password = g_strdup(gtk_entry_get_text (args->entry));
1415+
gtk_widget_destroy (args->window);
1416+
grl_source_continue_with_password (args->source, args->opaque, password);
1417+
1418+
g_free(password);
1419+
g_free(args);
1420+
}
1421+
14011422
static void
14021423
query_combo_setup (void)
14031424
{
@@ -2249,6 +2270,41 @@ metadata_key_added_cb (GrlRegistry *registry,
22492270
g_free (message);
22502271
}
22512272

2273+
static void
2274+
authenticate_cb (GrlSource *source, gpointer opaque, gpointer user_data)
2275+
{
2276+
GtkWidget *window;
2277+
GtkWidget *vbox;
2278+
GtkWidget *entry;
2279+
GtkWidget *button;
2280+
AuthCbArgs *args;
2281+
2282+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2283+
gtk_window_set_title (GTK_WINDOW (view->window), "Enter password");
2284+
gtk_window_resize (GTK_WINDOW (view->window), 200, 100);
2285+
2286+
vbox = gtk_vbox_new (FALSE, 0);
2287+
gtk_container_add (GTK_CONTAINER (window), vbox);
2288+
2289+
entry = gtk_entry_new ();
2290+
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);
2291+
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
2292+
2293+
button = gtk_button_new_from_stock (GTK_STOCK_OK);
2294+
args = g_new(AuthCbArgs, 1);
2295+
args->source = source;
2296+
args->window = window;
2297+
args->entry = entry;
2298+
args->opaque = opaque;
2299+
g_signal_connect (button, "clicked", G_CALLBACK (auth_btn_clicked_cb), args);
2300+
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
2301+
2302+
gtk_widget_show (button);
2303+
gtk_widget_show (entry);
2304+
gtk_widget_show (vbox);
2305+
gtk_widget_show (window);
2306+
}
2307+
22522308
static void
22532309
source_added_cb (GrlRegistry *registry,
22542310
GrlSource *source,
@@ -2269,6 +2325,9 @@ source_added_cb (GrlRegistry *registry,
22692325
search_combo_setup ();
22702326
query_combo_setup ();
22712327

2328+
/* Handle authentication requests. */
2329+
g_signal_connect (GRL_SOURCE (source), "authenticate", G_CALLBACK (authenticate_cb), NULL);
2330+
22722331
/* Check for changes in source (if supported) */
22732332
if (ui_state->changes_notification &&
22742333
(grl_source_supported_operations (source) &

0 commit comments

Comments
 (0)