server: disable use of SO_LINGER
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-server.c
1 /* GStreamer
2  * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <sys/ioctl.h>
21
22 #include "rtsp-server.h"
23 #include "rtsp-client.h"
24
25 #define DEFAULT_ADDRESS         "0.0.0.0"
26 /* #define DEFAULT_ADDRESS         "::0" */
27 #define DEFAULT_SERVICE         "8554"
28 #define DEFAULT_BACKLOG         5
29
30 /* Define to use the SO_LINGER option so that the server sockets can be resused
31  * sooner. Disabled for now because it is not very well implemented by various
32  * OSes and it causes clients to fail to read the TEARDOWN response. */
33 #undef USE_SOLINGER
34
35 enum
36 {
37   PROP_0,
38   PROP_ADDRESS,
39   PROP_SERVICE,
40   PROP_BACKLOG,
41
42   PROP_SESSION_POOL,
43   PROP_MEDIA_MAPPING,
44   PROP_LAST
45 };
46
47 G_DEFINE_TYPE (GstRTSPServer, gst_rtsp_server, G_TYPE_OBJECT);
48
49 GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug);
50 #define GST_CAT_DEFAULT rtsp_server_debug
51
52 static void gst_rtsp_server_get_property (GObject *object, guint propid,
53     GValue *value, GParamSpec *pspec);
54 static void gst_rtsp_server_set_property (GObject *object, guint propid,
55     const GValue *value, GParamSpec *pspec);
56 static void gst_rtsp_server_finalize (GObject *object);
57
58 static GstRTSPClient * default_accept_client (GstRTSPServer *server,
59     GIOChannel *channel);
60
61 static void
62 gst_rtsp_server_class_init (GstRTSPServerClass * klass)
63 {
64   GObjectClass *gobject_class;
65
66   gobject_class = G_OBJECT_CLASS (klass);
67
68   gobject_class->get_property = gst_rtsp_server_get_property;
69   gobject_class->set_property = gst_rtsp_server_set_property;
70   gobject_class->finalize = gst_rtsp_server_finalize;
71
72   /**
73    * GstRTSPServer::address
74    *
75    * The address of the server. This is the address where the server will
76    * listen on.
77    */
78   g_object_class_install_property (gobject_class, PROP_ADDRESS,
79       g_param_spec_string ("address", "Address", "The address the server uses to listen on",
80           DEFAULT_ADDRESS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
81   /**
82    * GstRTSPServer::service
83    *
84    * The service of the server. This is either a string with the service name or
85    * a port number (as a string) the server will listen on.
86    */
87   g_object_class_install_property (gobject_class, PROP_SERVICE,
88       g_param_spec_string ("service", "Service", "The service or port number the server uses to listen on",
89           DEFAULT_SERVICE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
90   /**
91    * GstRTSPServer::backlog
92    *
93    * The backlog argument defines the maximum length to which the queue of
94    * pending connections for the server may grow. If a connection request arrives
95    * when the queue is full, the client may receive an error with an indication of
96    * ECONNREFUSED or, if the underlying protocol supports retransmission, the
97    * request may be ignored so that a later reattempt at  connection succeeds.
98    */
99   g_object_class_install_property (gobject_class, PROP_BACKLOG,
100       g_param_spec_int ("backlog", "Backlog", "The maximum length to which the queue "
101               "of pending connections may grow",
102           0, G_MAXINT, DEFAULT_BACKLOG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
103   /**
104    * GstRTSPServer::session-pool
105    *
106    * The session pool of the server. By default each server has a separate
107    * session pool but sessions can be shared between servers by setting the same
108    * session pool on multiple servers.
109    */
110   g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
111       g_param_spec_object ("session-pool", "Session Pool",
112           "The session pool to use for client session",
113           GST_TYPE_RTSP_SESSION_POOL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
114   /**
115    * GstRTSPServer::media-mapping
116    *
117    * The media mapping to use for this server. By default the server has no
118    * media mapping and thus cannot map urls to media streams.
119    */
120   g_object_class_install_property (gobject_class, PROP_MEDIA_MAPPING,
121       g_param_spec_object ("media-mapping", "Media Mapping",
122           "The media mapping to use for client session",
123           GST_TYPE_RTSP_MEDIA_MAPPING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
124
125   klass->accept_client = default_accept_client;
126
127   GST_DEBUG_CATEGORY_INIT (rtsp_server_debug, "rtspserver", 0, "GstRTSPServer");
128 }
129
130 static void
131 gst_rtsp_server_init (GstRTSPServer * server)
132 {
133   server->address = g_strdup (DEFAULT_ADDRESS);
134   server->service = g_strdup (DEFAULT_SERVICE);
135   server->backlog = DEFAULT_BACKLOG;
136   server->session_pool = gst_rtsp_session_pool_new ();
137   server->media_mapping = gst_rtsp_media_mapping_new ();
138 }
139
140 static void
141 gst_rtsp_server_finalize (GObject *object)
142 {
143   GstRTSPServer *server = GST_RTSP_SERVER (object);
144
145   g_free (server->address);
146   g_free (server->service);
147
148   g_object_unref (server->session_pool);
149   g_object_unref (server->media_mapping);
150 }
151
152 /**
153  * gst_rtsp_server_new:
154  *
155  * Create a new #GstRTSPServer instance.
156  */
157 GstRTSPServer *
158 gst_rtsp_server_new (void)
159 {
160   GstRTSPServer *result;
161
162   result = g_object_new (GST_TYPE_RTSP_SERVER, NULL);
163
164   return result;
165 }
166
167 /**
168  * gst_rtsp_server_set_address:
169  * @server: a #GstRTSPServer
170  * @address: the address
171  *
172  * Configure @server to accept connections on the given address.
173  *
174  * This function must be called before the server is bound.
175  */
176 void
177 gst_rtsp_server_set_address (GstRTSPServer *server, const gchar *address)
178 {
179   g_return_if_fail (GST_IS_RTSP_SERVER (server));
180   g_return_if_fail (address != NULL);
181
182   g_free (server->address);
183   server->address = g_strdup (address);
184 }
185
186 /**
187  * gst_rtsp_server_get_address:
188  * @server: a #GstRTSPServer
189  *
190  * Get the address on which the server will accept connections.
191  *
192  * Returns: the server address. g_free() after usage.
193  */
194 gchar *
195 gst_rtsp_server_get_address (GstRTSPServer *server)
196 {
197   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
198
199   return g_strdup (server->address);
200 }
201
202 /**
203  * gst_rtsp_server_set_service:
204  * @server: a #GstRTSPServer
205  * @service: the service
206  *
207  * Configure @server to accept connections on the given service.
208  * @service should be a string containing the service name (see services(5)) or
209  * a string containing a port number between 1 and 65535.
210  *
211  * This function must be called before the server is bound.
212  */
213 void
214 gst_rtsp_server_set_service (GstRTSPServer *server, const gchar *service)
215 {
216   g_return_if_fail (GST_IS_RTSP_SERVER (server));
217   g_return_if_fail (service != NULL);
218
219   g_free (server->service);
220   server->service = g_strdup (service);
221 }
222
223 /**
224  * gst_rtsp_server_get_service:
225  * @server: a #GstRTSPServer
226  *
227  * Get the service on which the server will accept connections.
228  *
229  * Returns: the service. use g_free() after usage.
230  */
231 gchar *
232 gst_rtsp_server_get_service (GstRTSPServer *server)
233 {
234   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
235
236   return g_strdup (server->service);
237 }
238
239 /**
240  * gst_rtsp_server_set_backlog:
241  * @server: a #GstRTSPServer
242  * @backlog: the backlog
243  *
244  * configure the maximum amount of requests that may be queued for the
245  * server.
246  *
247  * This function must be called before the server is bound.
248  */
249 void
250 gst_rtsp_server_set_backlog (GstRTSPServer *server, gint backlog)
251 {
252   g_return_if_fail (GST_IS_RTSP_SERVER (server));
253
254   server->backlog = backlog;
255 }
256
257 /**
258  * gst_rtsp_server_get_backlog:
259  * @server: a #GstRTSPServer
260  *
261  * The maximum amount of queued requests for the server.
262  *
263  * Returns: the server backlog.
264  */
265 gint
266 gst_rtsp_server_get_backlog (GstRTSPServer *server)
267 {
268   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), -1);
269
270   return server->backlog;
271 }
272
273 /**
274  * gst_rtsp_server_set_session_pool:
275  * @server: a #GstRTSPServer
276  * @pool: a #GstRTSPSessionPool
277  *
278  * configure @pool to be used as the session pool of @server.
279  */
280 void
281 gst_rtsp_server_set_session_pool (GstRTSPServer *server, GstRTSPSessionPool *pool)
282 {
283   GstRTSPSessionPool *old;
284
285   g_return_if_fail (GST_IS_RTSP_SERVER (server));
286
287   old = server->session_pool;
288
289   if (old != pool) {
290     if (pool)
291       g_object_ref (pool);
292     server->session_pool = pool;
293     if (old)
294       g_object_unref (old);
295   }
296 }
297
298 /**
299  * gst_rtsp_server_get_session_pool:
300  * @server: a #GstRTSPServer
301  *
302  * Get the #GstRTSPSessionPool used as the session pool of @server.
303  *
304  * Returns: the #GstRTSPSessionPool used for sessions. g_object_unref() after
305  * usage.
306  */
307 GstRTSPSessionPool *
308 gst_rtsp_server_get_session_pool (GstRTSPServer *server)
309 {
310   GstRTSPSessionPool *result;
311
312   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
313
314   if ((result = server->session_pool))
315     g_object_ref (result);
316
317   return result;
318 }
319
320 /**
321  * gst_rtsp_server_set_media_mapping:
322  * @server: a #GstRTSPServer
323  * @mapping: a #GstRTSPMediaMapping
324  *
325  * configure @mapping to be used as the media mapping of @server.
326  */
327 void
328 gst_rtsp_server_set_media_mapping (GstRTSPServer *server, GstRTSPMediaMapping *mapping)
329 {
330   GstRTSPMediaMapping *old;
331
332   g_return_if_fail (GST_IS_RTSP_SERVER (server));
333
334   old = server->media_mapping;
335
336   if (old != mapping) {
337     if (mapping)
338       g_object_ref (mapping);
339     server->media_mapping = mapping;
340     if (old)
341       g_object_unref (old);
342   }
343 }
344
345
346 /**
347  * gst_rtsp_server_get_media_mapping:
348  * @server: a #GstRTSPServer
349  *
350  * Get the #GstRTSPMediaMapping used as the media mapping of @server.
351  *
352  * Returns: the #GstRTSPMediaMapping of @server. g_object_unref() after
353  * usage.
354  */
355 GstRTSPMediaMapping *
356 gst_rtsp_server_get_media_mapping (GstRTSPServer *server)
357 {
358   GstRTSPMediaMapping *result;
359
360   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
361
362   if ((result = server->media_mapping))
363     g_object_ref (result);
364
365   return result;
366 }
367
368 static void
369 gst_rtsp_server_get_property (GObject *object, guint propid,
370     GValue *value, GParamSpec *pspec)
371 {
372   GstRTSPServer *server = GST_RTSP_SERVER (object);
373
374   switch (propid) {
375     case PROP_ADDRESS:
376       g_value_take_string (value, gst_rtsp_server_get_address (server));
377       break;
378     case PROP_SERVICE:
379       g_value_take_string (value, gst_rtsp_server_get_service (server));
380       break;
381     case PROP_BACKLOG:
382       g_value_set_int (value, gst_rtsp_server_get_backlog (server));
383       break;
384     case PROP_SESSION_POOL:
385       g_value_take_object (value, gst_rtsp_server_get_session_pool (server));
386       break;
387     case PROP_MEDIA_MAPPING:
388       g_value_take_object (value, gst_rtsp_server_get_media_mapping (server));
389       break;
390     default:
391       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
392   }
393 }
394
395 static void
396 gst_rtsp_server_set_property (GObject *object, guint propid,
397     const GValue *value, GParamSpec *pspec)
398 {
399   GstRTSPServer *server = GST_RTSP_SERVER (object);
400
401   switch (propid) {
402     case PROP_ADDRESS:
403       gst_rtsp_server_set_address (server, g_value_get_string (value));
404       break;
405     case PROP_SERVICE:
406       gst_rtsp_server_set_service (server, g_value_get_string (value));
407       break;
408     case PROP_BACKLOG:
409       gst_rtsp_server_set_backlog (server, g_value_get_int (value));
410       break;
411     case PROP_SESSION_POOL:
412       gst_rtsp_server_set_session_pool (server, g_value_get_object (value));
413       break;
414     case PROP_MEDIA_MAPPING:
415       gst_rtsp_server_set_media_mapping (server, g_value_get_object (value));
416       break;
417     default:
418       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
419   }
420 }
421
422 /* Prepare a server socket for @server and make it listen on the configured port */
423 static gboolean
424 gst_rtsp_server_sink_init_send (GstRTSPServer * server)
425 {
426   int ret, sockfd;
427   struct addrinfo hints;
428   struct addrinfo *result, *rp;
429 #ifdef USE_SOLINGER
430   struct linger linger;
431 #endif
432
433   memset(&hints, 0, sizeof(struct addrinfo));
434   hints.ai_family = AF_UNSPEC;     /* Allow IPv4 or IPv6 */
435   hints.ai_socktype = SOCK_STREAM; /* stream socket */
436   hints.ai_flags = AI_PASSIVE | AI_CANONNAME;     /* For wildcard IP address */
437   hints.ai_protocol = 0;           /* Any protocol */
438   hints.ai_canonname = NULL;
439   hints.ai_addr = NULL;
440   hints.ai_next = NULL;
441
442   GST_DEBUG_OBJECT (server, "getting address info of %s/%s", server->address, server->service);
443
444   /* resolve the server IP address */
445   if ((ret = getaddrinfo (server->address, server->service, &hints, &result)) != 0)
446     goto no_address;
447
448   /* create server socket, we loop through all the addresses until we manage to
449    * create a socket and bind. */
450   for (rp = result; rp; rp = rp->ai_next) {
451     sockfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
452     if (sockfd == -1) {
453       GST_DEBUG_OBJECT (server, "failed to make socket (%s), try next", g_strerror (errno));
454       continue;
455     }
456
457     if (bind (sockfd, rp->ai_addr, rp->ai_addrlen) == 0) {
458       GST_DEBUG_OBJECT (server, "bind on %s", rp->ai_canonname);
459       break;
460     }
461
462     GST_DEBUG_OBJECT (server, "failed to bind socket (%s), try next", g_strerror (errno));
463     close (sockfd);
464   }
465   freeaddrinfo (result);
466
467   if (rp == NULL)
468     goto no_socket;
469
470   server->server_sock.fd = sockfd;
471
472   GST_DEBUG_OBJECT (server, "opened sending server socket with fd %d",
473       server->server_sock.fd);
474
475   /* make address reusable */
476   ret = 1;
477   if (setsockopt (server->server_sock.fd, SOL_SOCKET, SO_REUSEADDR,
478           (void *) &ret, sizeof (ret)) < 0)
479     goto reuse_failed;
480
481   /* keep connection alive; avoids SIGPIPE during write */
482   ret = 1;
483   if (setsockopt (server->server_sock.fd, SOL_SOCKET, SO_KEEPALIVE,
484           (void *) &ret, sizeof (ret)) < 0)
485     goto keepalive_failed;
486
487 #ifdef USE_SOLINGER
488   /* make sure socket is reset 5 seconds after close. This ensure that we can
489    * reuse the socket quickly while still having a chance to send data to the
490    * client. */
491   linger.l_onoff = 1;
492   linger.l_linger = 5;
493   if (setsockopt (server->server_sock.fd, SOL_SOCKET, SO_LINGER,
494           (void *) &linger, sizeof (linger)) < 0)
495     goto linger_failed;
496 #endif
497
498   /* set the server socket to nonblocking */
499   fcntl (server->server_sock.fd, F_SETFL, O_NONBLOCK);
500
501   GST_DEBUG_OBJECT (server, "listening on server socket %d with queue of %d",
502       server->server_sock.fd, server->backlog);
503   if (listen (server->server_sock.fd, server->backlog) == -1)
504     goto listen_failed;
505
506   GST_DEBUG_OBJECT (server,
507       "listened on server socket %d, returning from connection setup",
508       server->server_sock.fd);
509
510   GST_INFO_OBJECT (server, "listening on service %s", server->service);
511
512   return TRUE;
513
514   /* ERRORS */
515 no_address:
516   {
517     GST_ERROR_OBJECT (server, "failed to resolve address: %s", gai_strerror(ret));
518     return FALSE;
519   }
520 no_socket:
521   {
522     GST_ERROR_OBJECT (server, "failed to create socket: %s", g_strerror (errno));
523     return FALSE;
524   }
525 reuse_failed:
526   {
527     GST_ERROR_OBJECT (server, "failed to reuse socket: %s", g_strerror (errno));
528     goto close_error;
529   }
530 keepalive_failed:
531   {
532     GST_ERROR_OBJECT (server, "failed to configure keepalive socket: %s", g_strerror (errno));
533     goto close_error;
534   }
535 #ifdef USE_SOLINGER
536 linger_failed:
537   {
538     GST_ERROR_OBJECT (server, "failed to no linger socket: %s", g_strerror (errno));
539     goto close_error;
540   }
541 #endif
542 listen_failed:
543   {
544     GST_ERROR_OBJECT (server, "failed to listen on socket: %s", g_strerror (errno));
545     goto close_error;
546   }
547 close_error:
548   {
549     if (server->server_sock.fd >= 0) {
550       close (server->server_sock.fd);
551       server->server_sock.fd = -1;
552     }
553     return FALSE;
554   }
555 }
556
557 /* default method for creating a new client object in the server to accept and
558  * handle a client connection on this server */
559 static GstRTSPClient *
560 default_accept_client (GstRTSPServer *server, GIOChannel *channel)
561 {
562   GstRTSPClient *client;
563
564   /* a new client connected, create a session to handle the client. */
565   client = gst_rtsp_client_new ();
566
567   /* set the session pool that this client should use */
568   gst_rtsp_client_set_session_pool (client, server->session_pool);
569   /* set the media mapping that this client should use */
570   gst_rtsp_client_set_media_mapping (client, server->media_mapping);
571
572   /* accept connections for that client, this function returns after accepting
573    * the connection and will run the remainder of the communication with the
574    * client asyncronously. */
575   if (!gst_rtsp_client_accept (client, channel))
576     goto accept_failed;
577
578   return client;
579
580   /* ERRORS */
581 accept_failed:
582   {
583     GST_ERROR_OBJECT (server, "Could not accept client on server socket %d: %s (%d)",
584             server->server_sock.fd, g_strerror (errno), errno);
585     gst_object_unref (client);
586     return NULL;
587   }
588 }
589
590 /**
591  * gst_rtsp_server_io_func:
592  * @channel: a #GIOChannel
593  * @condition: the condition on @source
594  *
595  * A default #GIOFunc that creates a new #GstRTSPClient to accept and handle a
596  * new connection on @channel or @server.
597  *
598  * Returns: TRUE if the source could be connected, FALSE if an error occured.
599  */
600 gboolean
601 gst_rtsp_server_io_func (GIOChannel *channel, GIOCondition condition, GstRTSPServer *server)
602 {
603   GstRTSPClient *client = NULL;
604   GstRTSPServerClass *klass;
605
606   if (condition & G_IO_IN) {
607     klass = GST_RTSP_SERVER_GET_CLASS (server);
608
609     /* a new client connected, create a client object to handle the client. */
610     if (klass->accept_client)
611       client = klass->accept_client (server, channel);
612     if (client == NULL)
613       goto client_failed;
614
615     /* can unref the client now, when the request is finished, it will be
616      * unreffed async. */
617     gst_object_unref (client);
618   }
619   else {
620     GST_WARNING_OBJECT (server, "received unknown event %08x", condition);
621   }
622   return TRUE;
623
624   /* ERRORS */
625 client_failed:
626   {
627     GST_ERROR_OBJECT (server, "failed to create a client");
628     return FALSE;
629   }
630 }
631
632 /**
633  * gst_rtsp_server_get_io_channel:
634  * @server: a #GstRTSPServer
635  *
636  * Create a #GIOChannel for @server.
637  *
638  * Returns: the GIOChannel for @server or NULL when an error occured.
639  */
640 GIOChannel *
641 gst_rtsp_server_get_io_channel (GstRTSPServer *server)
642 {
643   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
644
645   if (server->io_channel == NULL) {
646     if (!gst_rtsp_server_sink_init_send (server))
647       goto init_failed;
648
649     /* create IO channel for the socket */
650     server->io_channel = g_io_channel_unix_new (server->server_sock.fd);
651   }
652   return server->io_channel;
653
654 init_failed:
655   {
656     GST_ERROR_OBJECT (server, "failed to initialize server");
657     return NULL;
658   }
659 }
660
661 /**
662  * gst_rtsp_server_create_watch:
663  * @server: a #GstRTSPServer
664  *
665  * Create a #GSource for @server. The new source will have a default
666  * #GIOFunc of gst_rtsp_server_io_func().
667  *
668  * Returns: the #GSource for @server or NULL when an error occured.
669  */
670 GSource *
671 gst_rtsp_server_create_watch (GstRTSPServer *server)
672 {
673   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
674
675   if (server->io_watch == NULL) {
676     GIOChannel *channel;
677
678     channel = gst_rtsp_server_get_io_channel (server);
679     if (channel == NULL)
680       goto no_channel;
681
682     /* create a watch for reads (new connections) and possible errors */
683     server->io_watch = g_io_create_watch (channel, G_IO_IN |
684                   G_IO_ERR | G_IO_HUP | G_IO_NVAL);
685
686     /* configure the callback */
687     g_source_set_callback (server->io_watch, (GSourceFunc) gst_rtsp_server_io_func, server, NULL);
688   }
689   return server->io_watch;
690
691 no_channel:
692   {
693     GST_ERROR_OBJECT (server, "failed to create IO channel");
694     return NULL;
695   }
696 }
697
698 /**
699  * gst_rtsp_server_attach:
700  * @server: a #GstRTSPServer
701  * @context: a #GMainContext
702  *
703  * Attaches @server to @context. When the mainloop for @context is run, the
704  * server will be dispatched.
705  *
706  * This function should be called when the server properties and urls are fully
707  * configured and the server is ready to start.
708  *
709  * Returns: the ID (greater than 0) for the source within the GMainContext.
710  */
711 guint
712 gst_rtsp_server_attach (GstRTSPServer *server, GMainContext *context)
713 {
714   guint res;
715   GSource *source;
716
717   g_return_val_if_fail (GST_IS_RTSP_SERVER (server), 0);
718
719   source = gst_rtsp_server_create_watch (server);
720   if (source == NULL)
721     goto no_source;
722
723   res = g_source_attach (source, context);
724
725   return res;
726
727   /* ERRORS */
728 no_source:
729   {
730     GST_ERROR_OBJECT (server, "failed to create watch");
731     return 0;
732   }
733 }