Debian Codegraph @

libgupnp-av/gupnp-protocol-info.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2009 Nokia Corporation.
3 * Copyright (C) 2007, 2008 OpenedHand Ltd.
4 *
5 * Authors: Zeeshan Ali (Khattak) <[email protected]>
6 * <[email protected]>
7 * Jorn Baayen <[email protected]>
8 *
9 * SPDX-License-Identifier: LGPL-2.1-or-later
10 *
11 */
12
13 /**
14 * GUPnPProtocolInfo:
15 *
16 * UPnP AV ProtocolInfo
17 *
18 * #GUPnPProtocolInfo provides a convenient API to deal with ProtocolInfo
19 * strings used in UPnP AV specifications.
20 */
21
22 #include <config.h>
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include "gupnp-protocol-info.h"
27 #include "gupnp-av-error.h"
28
29 struct _GUPnPProtocolInfoPrivate {
30 char *protocol;
31 char *network;
32 char *mime_type;
33 char *dlna_profile;
34 char **play_speeds;
35
36 GUPnPDLNAConversion dlna_conversion;
37 GUPnPDLNAOperation dlna_operation;
38 GUPnPDLNAFlags dlna_flags;
39 };
40 typedef struct _GUPnPProtocolInfoPrivate GUPnPProtocolInfoPrivate;
41
42 G_DEFINE_TYPE_WITH_PRIVATE (GUPnPProtocolInfo,
43 gupnp_protocol_info,
44 G_TYPE_OBJECT)
45
46 enum {
47 PROP_0,
48 PROP_PROTOCOL,
49 PROP_NETWORK,
50 PROP_MIME_TYPE,
51 PROP_DLNA_PROFILE,
52 PROP_PLAY_SPEEDS,
53
54 PROP_DLNA_CONVERSION,
55 PROP_DLNA_OPERATION,
56 PROP_DLNA_FLAGS
57 };
58
59 static void
60 parse_additional_info (const char *additional_info,
61 GUPnPProtocolInfo *info)
62 {
63 char **tokens = NULL;
64 short i;
65
66 if (strcmp (additional_info, "*") == 0)
67 return;
68
69 tokens = g_strsplit (additional_info, ";", -1);
70 if (tokens == NULL) {
71 g_warning ("Invalid additional info in DIDL-Lite info: %s",
72 additional_info);
73
74 return;
75 }
76
77 for (i = 0; tokens[i]; i++) {
78 char *p;
79
80 p = g_strstr_len (tokens[i],
81 strlen (tokens[i]),
82 "DLNA.ORG_PN=");
83 if (p != NULL) {
84 p += 12; /* end of "DLNA.ORG_PN=" */
85 gupnp_protocol_info_set_dlna_profile (info, p);
86
87 continue;
88 }
89
90 p = g_strstr_len (tokens[i],
91 strlen (tokens[i]),
92 "DLNA.ORG_PS=");
93 if (p != NULL) {
94 char **play_speeds;
95
96 p += 12; /* end of "DLNA.ORG_PS=" */
97
98 play_speeds = g_strsplit (p, ",", -1);
99 gupnp_protocol_info_set_play_speeds
100 (info,
101 (const char **) play_speeds);
102 g_strfreev (play_speeds);
103
104 continue;
105 }
106
107 p = g_strstr_len (tokens[i],
108 strlen (tokens[i]),
109 "DLNA.ORG_CI=");
110 if (p != NULL) {
111 p += 12; /* end of "DLNA.ORG_CI=" */
112
113 gupnp_protocol_info_set_dlna_conversion (info,
114 atoi (p));
115
116 continue;
117 }
118
119 p = g_strstr_len (tokens[i],
120 strlen (tokens[i]),
121 "DLNA.ORG_OP=");
122 if (p != NULL) {
123 p += 12; /* end of "DLNA.ORG_OP=" */
124
125 gupnp_protocol_info_set_dlna_operation
126 (info,
127 strtoul (p, NULL, 16));
128
129 continue;
130 }
131
132 p = g_strstr_len (tokens[i],
133 strlen (tokens[i]),
134 "DLNA.ORG_FLAGS=");
135 if (p != NULL) {
136 p += 15; /* end of "DLNA.ORG_FLAGS=" */
137 if (strlen (p) > 8)
138 p[8] = '\0';
139 gupnp_protocol_info_set_dlna_flags
140 (info,
141 strtoul (p, NULL, 16));
142
143 continue;
144 }
145 }
146
147 g_strfreev (tokens);
148 }
149
150 static gboolean
151 is_transport_compat (GUPnPProtocolInfo *info1,
152 GUPnPProtocolInfo *info2)
153 {
154 const char *protocol1;
155 const char *protocol2;
156
157 protocol1 = gupnp_protocol_info_get_protocol (info1);
158 protocol2 = gupnp_protocol_info_get_protocol (info2);
159
160 if (protocol1[0] != '*' &&
161 protocol2[0] != '*' &&
162 g_ascii_strcasecmp (protocol1, protocol2) != 0)
163 return FALSE;
164 else if (g_ascii_strcasecmp ("internal", protocol1) == 0 &&
165 strcmp (gupnp_protocol_info_get_network (info1),
166 gupnp_protocol_info_get_network (info2)) != 0)
167 /* Host must be the same in case of INTERNAL protocol */
168 return FALSE;
169 else
170 return TRUE;
171 }
172
173 static gboolean
174 is_content_format_compat (GUPnPProtocolInfo *info1,
175 GUPnPProtocolInfo *info2)
176 {
177 const char *mime_type1;
178 const char *mime_type2;
179
180 mime_type1 = gupnp_protocol_info_get_mime_type (info1);
181 mime_type2 = gupnp_protocol_info_get_mime_type (info2);
182
183 if (mime_type1 [0] != '*' &&
184 mime_type2 [0] != '*' &&
185 g_ascii_strcasecmp (mime_type1, mime_type2) != 0 &&
186 /* Handle special case for LPCM: It is the only content type that
187 * make use of mime-type parameters that we know of.
188 *
189 * Example: audio/L16;rate=44100;channels=2
190 */
191 !((g_ascii_strcasecmp (mime_type1, "audio/L16") == 0 &&
192 g_ascii_strncasecmp (mime_type2, "audio/L16", 9) == 0) ||
193 (g_ascii_strcasecmp (mime_type2, "audio/L16") == 0 &&
194 g_ascii_strncasecmp (mime_type1, "audio/L16", 9) == 0)))
195 return FALSE;
196 else
197 return TRUE;
198 }
199
200 static gboolean
201 is_additional_info_compat (GUPnPProtocolInfo *info1,
202 GUPnPProtocolInfo *info2)
203 {
204 const char *profile1;
205 const char *profile2;
206
207 profile1 = gupnp_protocol_info_get_dlna_profile (info1);
208 profile2 = gupnp_protocol_info_get_dlna_profile (info2);
209
210 if (profile1 == NULL ||
211 profile2 == NULL ||
212 profile1 [0] == '*' ||
213 profile2 [0] == '*' ||
214 g_ascii_strcasecmp (profile1, profile2) == 0)
215 return TRUE;
216 else
217 return FALSE;
218 }
219
220 static void
221 add_dlna_info (GString *str,
222 GUPnPProtocolInfo *info)
223 {
224 const char *dlna_profile;
225 const char **speeds;
226 GUPnPDLNAConversion conversion;
227 GUPnPDLNAOperation operation;
228 GUPnPDLNAFlags flags;
229
230 dlna_profile = gupnp_protocol_info_get_dlna_profile (info);
231 if (dlna_profile == NULL) {
232 g_string_append_printf (str, ":");
233 } else {
234 g_string_append_printf (str, ":DLNA.ORG_PN=%s;", dlna_profile);
235 }
236
237 operation = gupnp_protocol_info_get_dlna_operation (info);
238 if (operation != GUPNP_DLNA_OPERATION_NONE &&
239 /* the OP parameter is only allowed for the "http-get"
240 * and "rtsp-rtp-udp" protocols
241 */
242 (strcmp (gupnp_protocol_info_get_protocol (info),
243 "http-get") == 0 ||
244 strcmp (gupnp_protocol_info_get_protocol (info),
245 "rtsp-rtp-udp") == 0))
246 g_string_append_printf (str, "DLNA.ORG_OP=%.2x;", operation);
247
248 /* Specify PS parameter if list of play speeds is provided */
249 speeds = gupnp_protocol_info_get_play_speeds (info);
250 if (speeds != NULL) {
251 int i;
252
253 g_string_append (str, "DLNA.ORG_PS=");
254
255 for (i = 0; speeds[i]; i++) {
256 g_string_append (str, speeds[i]);
257
258 if (speeds[i + 1])
259 g_string_append_c (str, ',');
260 }
261 g_string_append_c (str, ';');
262 }
263
264 conversion = gupnp_protocol_info_get_dlna_conversion (info);
265 /* omit the CI parameter for non-converted content */
266 if (conversion != GUPNP_DLNA_CONVERSION_NONE)
267 g_string_append_printf (str, "DLNA.ORG_CI=%d;", conversion);
268
269 flags = gupnp_protocol_info_get_dlna_flags (info);
270 /* Omit the FLAGS parameter if no or DLNA profile are set */
271 if (flags != GUPNP_DLNA_FLAGS_NONE && dlna_profile != NULL) {
272 g_string_append_printf (str, "DLNA.ORG_FLAGS=%.8x", flags);
273 /* append 24 reserved hex-digits */
274 g_string_append_printf (str,
275 "0000" "0000" "0000"
276 "0000" "0000" "0000");
277 }
278
279 /* if nothing of the above was set, use the "match all" rule */
280 switch (str->str[str->len - 1]) {
281 case ':':
282 g_string_append_c (str, '*');
283 break;
284 case ';':
285 g_string_erase (str, str->len - 1, 1);
286 break;
287 default:
288 break;
289 }
290 }
291
292 static void
293 gupnp_protocol_info_init (GUPnPProtocolInfo *info)
294 {
295 }
296
297 static void
298 gupnp_protocol_info_set_property (GObject *object,
299 guint property_id,
300 const GValue *value,
301 GParamSpec *pspec)
302 {
303 GUPnPProtocolInfo *info;
304
305 info = GUPNP_PROTOCOL_INFO (object);
306
307 switch (property_id) {
308 case PROP_PROTOCOL:
309 gupnp_protocol_info_set_protocol (info,
310 g_value_get_string (value));
311 break;
312 case PROP_NETWORK:
313 gupnp_protocol_info_set_network (info,
314 g_value_get_string (value));
315 break;
316 case PROP_MIME_TYPE:
317 gupnp_protocol_info_set_mime_type (info,
318 g_value_get_string (value));
319 break;
320 case PROP_DLNA_PROFILE:
321 gupnp_protocol_info_set_dlna_profile
322 (info,
323 g_value_get_string (value));
324 break;
325 case PROP_PLAY_SPEEDS:
326 gupnp_protocol_info_set_play_speeds (info,
327 g_value_get_boxed (value));
328 break;
329 case PROP_DLNA_CONVERSION:
330 gupnp_protocol_info_set_dlna_conversion
331 (info,
332 g_value_get_flags (value));
333 break;
334 case PROP_DLNA_OPERATION:
335 gupnp_protocol_info_set_dlna_operation
336 (info,
337 g_value_get_flags (value));
338 break;
339 case PROP_DLNA_FLAGS:
340 gupnp_protocol_info_set_dlna_flags
341 (info,
342 g_value_get_flags (value));
343 break;
344 default:
345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
346 break;
347 }
348 }
349
350 static void
351 gupnp_protocol_info_get_property (GObject *object,
352 guint property_id,
353 GValue *value,
354 GParamSpec *pspec)
355 {
356 GUPnPProtocolInfo *info;
357
358 info = GUPNP_PROTOCOL_INFO (object);
359
360 switch (property_id) {
361 case PROP_PROTOCOL:
362 g_value_set_string (value,
363 gupnp_protocol_info_get_protocol (info));
364 break;
365 case PROP_NETWORK:
366 g_value_set_string (value,
367 gupnp_protocol_info_get_network (info));
368 break;
369 case PROP_MIME_TYPE:
370 g_value_set_string (value,
371 gupnp_protocol_info_get_mime_type (info));
372 break;
373 case PROP_DLNA_PROFILE:
374 g_value_set_string
375 (value,
376 gupnp_protocol_info_get_dlna_profile (info));
377 break;
378 case PROP_PLAY_SPEEDS:
379 g_value_set_boxed (value,
380 gupnp_protocol_info_get_play_speeds (info));
381 break;
382 case PROP_DLNA_CONVERSION:
383 g_value_set_flags
384 (value,
385 gupnp_protocol_info_get_dlna_conversion
386 (info));
387 break;
388 case PROP_DLNA_OPERATION:
389 g_value_set_flags
390 (value,
391 gupnp_protocol_info_get_dlna_operation (info));
392 break;
393 case PROP_DLNA_FLAGS:
394 g_value_set_flags (value,
395 gupnp_protocol_info_get_dlna_flags (info));
396 break;
397 default:
398 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
399 break;
400 }
401 }
402
403 static void
404 gupnp_protocol_info_finalize (GObject *object)
405 {
406 GObjectClass *object_class;
407 GUPnPProtocolInfoPrivate *priv =
408 gupnp_protocol_info_get_instance_private (
409 GUPNP_PROTOCOL_INFO (object));
410
411 g_free (priv->protocol);
412 g_free (priv->network);
413 g_free (priv->mime_type);
414 g_free (priv->dlna_profile);
415 g_clear_pointer(&priv->play_speeds,g_strfreev);
416
417 object_class = G_OBJECT_CLASS (gupnp_protocol_info_parent_class);
418 object_class->finalize (object);
419 }
420
421 static void
422 gupnp_protocol_info_class_init (GUPnPProtocolInfoClass *klass)
423 {
424 GObjectClass *object_class;
425
426 object_class = G_OBJECT_CLASS (klass);
427
428 object_class->set_property = gupnp_protocol_info_set_property;
429 object_class->get_property = gupnp_protocol_info_get_property;
430 object_class->finalize = gupnp_protocol_info_finalize;
431
432 /**
433 * GUPnPProtocolInfo:protocol:
434 *
435 * The protocol of this info.
436 **/
437 g_object_class_install_property
438 (object_class,
439 PROP_PROTOCOL,
440 g_param_spec_string ("protocol",
441 "Protocol",
442 "The protocol of this info.",
443 NULL,
444 G_PARAM_READWRITE |
445 G_PARAM_STATIC_NAME |
446 G_PARAM_STATIC_NICK |
447 G_PARAM_STATIC_BLURB));
448
449 /**
450 * GUPnPProtocolInfo:network:
451 *
452 * The network this info is associated with.
453 **/
454 g_object_class_install_property
455 (object_class,
456 PROP_NETWORK,
457 g_param_spec_string ("network",
458 "Network",
459 "The network this info is associated"
460 " with.",
461 NULL,
462 G_PARAM_READWRITE |
463 G_PARAM_STATIC_NAME |
464 G_PARAM_STATIC_NICK |
465 G_PARAM_STATIC_BLURB));
466
467 /**
468 * GUPnPProtocolInfo:mime-type:
469 *
470 * The MIME-type of this info.
471 **/
472 g_object_class_install_property
473 (object_class,
474 PROP_MIME_TYPE,
475 g_param_spec_string ("mime-type",
476 "MIMEType",
477 "The MIME-type of this info.",
478 NULL,
479 G_PARAM_READWRITE |
480 G_PARAM_STATIC_NAME |
481 G_PARAM_STATIC_NICK |
482 G_PARAM_STATIC_BLURB));
483
484 /**
485 * GUPnPProtocolInfo:dlna-profile:
486 *
487 * The DLNA profile of this info.
488 **/
489 g_object_class_install_property
490 (object_class,
491 PROP_DLNA_PROFILE,
492 g_param_spec_string ("dlna-profile",
493 "DLNAProfile",
494 "The DLNA profile of this info.",
495 NULL,
496 G_PARAM_READWRITE |
497 G_PARAM_STATIC_NAME |
498 G_PARAM_STATIC_NICK |
499 G_PARAM_STATIC_BLURB));
500
501 /**
502 * GUPnPProtocolInfo:play-speeds:
503 *
504 * The allowed play speeds on this info in the form of array of
505 * strings.
506 **/
507 g_object_class_install_property
508 (object_class,
509 PROP_PLAY_SPEEDS,
510 g_param_spec_boxed ("play-speeds",
511 "PlaySpeeds",
512 "The allowed play speeds on this"
513 " info in the form of array of"
514 " strings.",
515 G_TYPE_STRV,
516 G_PARAM_READWRITE |
517 G_PARAM_STATIC_NAME |
518 G_PARAM_STATIC_NICK |
519 G_PARAM_STATIC_BLURB));
520
521 /**
522 * GUPnPProtocolInfo:dlna-conversion:
523 *
524 * The DLNA conversion flags.
525 **/
526 g_object_class_install_property (
527 object_class,
528 PROP_DLNA_CONVERSION,
529 g_param_spec_flags ("dlna-conversion",
530 "DLNAConversion",
531 "The DLNA conversion flags.",
532 GUPNP_TYPE_DLNA_CONVERSION,
533 GUPNP_DLNA_CONVERSION_NONE,
534 G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
535 G_PARAM_STATIC_STRINGS));
536
537 /**
538 * GUPnPProtocolInfo:dlna-operation:
539 *
540 * The DLNA operation flags.
541 **/
542 g_object_class_install_property (
543 object_class,
544 PROP_DLNA_OPERATION,
545 g_param_spec_flags ("dlna-operation",
546 "DLNAOperation",
547 "The DLNA operation flags.",
548 GUPNP_TYPE_DLNA_OPERATION,
549 GUPNP_DLNA_OPERATION_NONE,
550 G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
551 G_PARAM_STATIC_STRINGS));
552
553 /**
554 * GUPnPProtocolInfo:dlna-flags:
555 *
556 * Various generic DLNA flags.
557 **/
558 g_object_class_install_property (
559 object_class,
560 PROP_DLNA_FLAGS,
561 g_param_spec_flags ("dlna-flags",
562 "DLNAFlags",
563 "Various generic DLNA flags.",
564 GUPNP_TYPE_DLNA_FLAGS,
565 GUPNP_DLNA_FLAGS_NONE,
566 G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
567 G_PARAM_STATIC_STRINGS));
568 }
569
570 /**
571 * gupnp_protocol_info_new:
572 *
573 * Return value: A new #GUPnPProtocolInfo object. Unref after usage.
574 **/
575 GUPnPProtocolInfo *
576 gupnp_protocol_info_new (void)
577 {
578 return g_object_new (GUPNP_TYPE_PROTOCOL_INFO,
579 NULL);
580 }
581
582 /**
583 * gupnp_protocol_info_new_from_string:
584 * @protocol_info: The protocol info string
585 * @error: The location where to store any error, or NULL
586 *
587 * Parses the @protocol_info string and creates a new #GUPnPProtocolInfo object
588 * as a result.
589 *
590 * Return value: A new #GUPnPProtocolInfo object. Unref after usage.
591 **/
592 GUPnPProtocolInfo *
593 gupnp_protocol_info_new_from_string (const char *protocol_info,
594 GError **error)
595 {
596 // FIXME: make a property...
597 GUPnPProtocolInfo *info;
598 char **tokens;
599
600 g_return_val_if_fail (protocol_info != NULL, NULL);
601
602 tokens = g_strsplit (protocol_info, ":", 4);
603 if (tokens[0] == NULL ||
604 tokens[1] == NULL ||
605 tokens[2] == NULL ||
606 tokens[3] == NULL) {
607 g_set_error (error,
608 GUPNP_PROTOCOL_ERROR,
609 GUPNP_PROTOCOL_ERROR_INVALID_SYNTAX,
610 "Failed to parse protocolInfo string: \n%s",
611 protocol_info);
612
613 g_strfreev (tokens);
614
615 return NULL;
616 }
617
618 info = gupnp_protocol_info_new ();
619
620 gupnp_protocol_info_set_protocol (info, tokens[0]);
621 gupnp_protocol_info_set_network (info, tokens[1]);
622 gupnp_protocol_info_set_mime_type (info, tokens[2]);
623
624 parse_additional_info (tokens[3], info);
625
626 g_strfreev (tokens);
627
628 return info;
629 }
630
631 /**
632 * gupnp_protocol_info_to_string:
633 * @info: The #GUPnPProtocolInfo
634 *
635 * Provides the string representation of @info.
636 *
637 * Return value:(transfer full)(nullable): String representation of @info.
638 * #g_free after usage.
639 **/
640 char *
641 gupnp_protocol_info_to_string (GUPnPProtocolInfo *info)
642 {
643 GString *str;
644 const char *protocol;
645 const char *mime_type;
646 const char *network;
647
648 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
649
650 protocol = gupnp_protocol_info_get_protocol (info);
651 mime_type = gupnp_protocol_info_get_mime_type (info);
652 network = gupnp_protocol_info_get_network (info);
653
654 g_return_val_if_fail (protocol != NULL, NULL);
655 g_return_val_if_fail (mime_type != NULL, NULL);
656
657 str = g_string_new ("");
658
659 g_string_append (str, protocol);
660 g_string_append_c (str, ':');
661 if (network != NULL)
662 g_string_append (str, network);
663 else
664 g_string_append_c (str, '*');
665 g_string_append_c (str, ':');
666 g_string_append (str, mime_type);
667
668 add_dlna_info (str, info);
669
670 return g_string_free (str, FALSE);
671 }
672
673 /**
674 * gupnp_protocol_info_get_protocol:
675 * @info: A #GUPnPProtocolInfo
676 *
677 * Get the protocol of this info.
678 *
679 * Return value:(transfer none)(nullable): The protocol of this info or %NULL. This string should not
680 * be freed.
681 **/
682 const char *
683 gupnp_protocol_info_get_protocol (GUPnPProtocolInfo *info)
684 {
685 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
686 GUPnPProtocolInfoPrivate *priv =
687 gupnp_protocol_info_get_instance_private (info);
688
689 return priv->protocol;
690 }
691
692 /**
693 * gupnp_protocol_info_get_network:
694 * @info: A #GUPnPProtocolInfo
695 *
696 * Get the network this info is associated with.
697 *
698 * Return value:(transfer none)(nullable): The network string or %NULL. This string should not be freed.
699 **/
700 const char *
701 gupnp_protocol_info_get_network (GUPnPProtocolInfo *info)
702 {
703 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
704 GUPnPProtocolInfoPrivate *priv =
705 gupnp_protocol_info_get_instance_private (info);
706
707 return priv->network;
708 }
709
710 /**
711 * gupnp_protocol_info_get_mime_type:
712 * @info: A #GUPnPProtocolInfo
713 *
714 * Get the MIME-type of this info.
715 *
716 * Return value:(transfer none)(nullable): The MIME-type of this info or %NULL. This string should not
717 * be freed.
718 **/
719 const char *
720 gupnp_protocol_info_get_mime_type (GUPnPProtocolInfo *info)
721 {
722 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
723 GUPnPProtocolInfoPrivate *priv =
724 gupnp_protocol_info_get_instance_private (info);
725
726 return priv->mime_type;
727 }
728
729 /**
730 * gupnp_protocol_info_get_dlna_profile:
731 * @info: A #GUPnPProtocolInfo
732 *
733 * Get the DLNA profile of this info.
734 *
735 * Return value:(transfer none)(nullable): The DLNA profile of this info or %NULL. This string should
736 * not be freed.
737 **/
738 const char *
739 gupnp_protocol_info_get_dlna_profile (GUPnPProtocolInfo *info)
740 {
741 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
742 GUPnPProtocolInfoPrivate *priv =
743 gupnp_protocol_info_get_instance_private (info);
744
745 return priv->dlna_profile;
746 }
747
748 /**
749 * gupnp_protocol_info_get_play_speeds:
750 * @info: A #GUPnPProtocolInfo
751 *
752 * Get the allowed play speeds on this info in the form of array of strings.
753 *
754 * Returns: (transfer none)(nullable): The allowed play speeds as array of strings or %NULL. This
755 * return array and it's content must not be modified or freed.
756 **/
757 const char **
758 gupnp_protocol_info_get_play_speeds (GUPnPProtocolInfo *info)
759 {
760 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info), NULL);
761 GUPnPProtocolInfoPrivate *priv =
762 gupnp_protocol_info_get_instance_private (info);
763
764 return (const char **) priv->play_speeds;
765 }
766
767 /**
768 * gupnp_protocol_info_get_dlna_conversion:
769 * @info: A #GUPnPProtocolInfo
770 *
771 * Get the DLNA conversion flags.
772 *
773 * Return value: The DLNA conversion flags.
774 **/
775 GUPnPDLNAConversion
776 gupnp_protocol_info_get_dlna_conversion (GUPnPProtocolInfo *info)
777 {
778 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info),
779 GUPNP_DLNA_CONVERSION_NONE);
780 GUPnPProtocolInfoPrivate *priv =
781 gupnp_protocol_info_get_instance_private (info);
782
783 return priv->dlna_conversion;
784 }
785
786 /**
787 * gupnp_protocol_info_get_dlna_operation:
788 * @info: A #GUPnPProtocolInfo
789 *
790 * Get the DLNA operation flags.
791 *
792 * Return value: The DLNA operation flags.
793 **/
794 GUPnPDLNAOperation
795 gupnp_protocol_info_get_dlna_operation (GUPnPProtocolInfo *info)
796 {
797 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info),
798 GUPNP_DLNA_OPERATION_NONE);
799 GUPnPProtocolInfoPrivate *priv =
800 gupnp_protocol_info_get_instance_private (info);
801
802 return priv->dlna_operation;
803 }
804
805 /**
806 * gupnp_protocol_info_get_dlna_flags:
807 * @info: A #GUPnPProtocolInfo
808 *
809 * Get the gereric DLNA flags.
810 *
811 * Return value: The generic DLNA flags.
812 **/
813 GUPnPDLNAFlags
814 gupnp_protocol_info_get_dlna_flags (GUPnPProtocolInfo *info)
815 {
816 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info),
817 GUPNP_DLNA_FLAGS_NONE);
818 GUPnPProtocolInfoPrivate *priv =
819 gupnp_protocol_info_get_instance_private (info);
820
821 return priv->dlna_flags;
822 }
823
824 /**
825 * gupnp_protocol_info_set_protocol:
826 * @info: A #GUPnPProtocolInfo
827 * @protocol: The protocol string
828 *
829 * Set the protocol of this info.
830 **/
831 void
832 gupnp_protocol_info_set_protocol (GUPnPProtocolInfo *info,
833 const char *protocol)
834 {
835 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
836 GUPnPProtocolInfoPrivate *priv =
837 gupnp_protocol_info_get_instance_private (info);
838
839 g_free (priv->protocol);
840 priv->protocol = g_strdup (protocol);
841
842 g_object_notify (G_OBJECT (info), "protocol");
843 }
844
845 /**
846 * gupnp_protocol_info_set_network:
847 * @info: A #GUPnPProtocolInfo
848 * @network: The network string
849 *
850 * Set the network this info is associated with.
851 **/
852 void
853 gupnp_protocol_info_set_network (GUPnPProtocolInfo *info,
854 const char *network)
855 {
856 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
857 GUPnPProtocolInfoPrivate *priv =
858 gupnp_protocol_info_get_instance_private (info);
859
860 g_free (priv->network);
861 priv->network = g_strdup (network);
862
863 g_object_notify (G_OBJECT (info), "network");
864 }
865
866 /**
867 * gupnp_protocol_info_set_mime_type:
868 * @info: A #GUPnPProtocolInfo
869 * @mime_type: The MIME-type string
870 *
871 * Set the MIME-type of this info.
872 **/
873 void
874 gupnp_protocol_info_set_mime_type (GUPnPProtocolInfo *info,
875 const char *mime_type)
876 {
877 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
878 GUPnPProtocolInfoPrivate *priv =
879 gupnp_protocol_info_get_instance_private (info);
880
881 g_free (priv->mime_type);
882 priv->mime_type = g_strdup (mime_type);
883
884 g_object_notify (G_OBJECT (info), "mime-type");
885 }
886
887 /**
888 * gupnp_protocol_info_set_dlna_profile:
889 * @info: A #GUPnPProtocolInfo
890 * @profile: The DLNA profile string
891 *
892 * Set the DLNA profile of this info.
893 **/
894 void
895 gupnp_protocol_info_set_dlna_profile (GUPnPProtocolInfo *info,
896 const char *profile)
897 {
898 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
899 GUPnPProtocolInfoPrivate *priv =
900 gupnp_protocol_info_get_instance_private (info);
901
902 g_free (priv->dlna_profile);
903 priv->dlna_profile = g_strdup (profile);
904
905 g_object_notify (G_OBJECT (info), "dlna-profile");
906 }
907
908 /**
909 * gupnp_protocol_info_set_play_speeds:
910 * @info: A #GUPnPProtocolInfo
911 * @speeds: (array zero-terminated=1): The allowed play speeds
912 *
913 * Set the allowed play speeds on this info in the form of array of strings.
914 * The array must be %NULL-terminated.
915 **/
916 void
917 gupnp_protocol_info_set_play_speeds (GUPnPProtocolInfo *info,
918 const char **speeds)
919 {
920 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
921 GUPnPProtocolInfoPrivate *priv =
922 gupnp_protocol_info_get_instance_private (info);
923
924 if (priv->play_speeds)
925 g_strfreev (priv->play_speeds);
926 priv->play_speeds = (char **) g_boxed_copy (G_TYPE_STRV, speeds);
927
928 g_object_notify (G_OBJECT (info), "play-speeds");
929 }
930
931 /**
932 * gupnp_protocol_info_set_dlna_conversion:
933 * @info: A #GUPnPProtocolInfo
934 * @conversion: The bitwise OR of one or more DLNA conversion flags
935 *
936 * Set the DLNA conversion flags.
937 **/
938 void
939 gupnp_protocol_info_set_dlna_conversion (GUPnPProtocolInfo *info,
940 GUPnPDLNAConversion conversion)
941 {
942 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
943 GUPnPProtocolInfoPrivate *priv =
944 gupnp_protocol_info_get_instance_private (info);
945
946 priv->dlna_conversion = conversion;
947
948 g_object_notify (G_OBJECT (info), "dlna-conversion");
949 }
950
951 /**
952 * gupnp_protocol_info_set_dlna_operation:
953 * @info: A #GUPnPProtocolInfo
954 * @operation: The bitwise OR of one or more DLNA operation flags
955 *
956 * Set the DLNA operation flags.
957 **/
958 void
959 gupnp_protocol_info_set_dlna_operation (GUPnPProtocolInfo *info,
960 GUPnPDLNAOperation operation)
961 {
962 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
963 GUPnPProtocolInfoPrivate *priv =
964 gupnp_protocol_info_get_instance_private (info);
965
966 priv->dlna_operation = operation;
967
968 g_object_notify (G_OBJECT (info), "dlna-operation");
969 }
970
971 /**
972 * gupnp_protocol_info_set_dlna_flags:
973 * @info: A #GUPnPProtocolInfo
974 * @flags: The bitwise OR of one or more generic DLNA flags
975 *
976 * Set the gereric DLNA flags.
977 **/
978 void
979 gupnp_protocol_info_set_dlna_flags (GUPnPProtocolInfo *info,
980 GUPnPDLNAFlags flags)
981 {
982 g_return_if_fail (GUPNP_IS_PROTOCOL_INFO (info));
983 GUPnPProtocolInfoPrivate *priv =
984 gupnp_protocol_info_get_instance_private (info);
985
986 priv->dlna_flags = flags;
987
988 g_object_notify (G_OBJECT (info), "dlna-flags");
989 }
990
991 /**
992 * gupnp_protocol_info_is_compatible:
993 * @info1: The first #GUPnPProtocolInfo
994 * @info2: The second #GUPnPProtocolInfo
995 *
996 * Checks if the given protocolInfo string is compatible with @info.
997 *
998 * Return value: #TRUE if @protocol_info is compatible with @info, otherwise
999 * #FALSE.
1000 **/
1001 gboolean
1002 gupnp_protocol_info_is_compatible (GUPnPProtocolInfo *info1,
1003 GUPnPProtocolInfo *info2)
1004 {
1005 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info1), FALSE);
1006 g_return_val_if_fail (GUPNP_IS_PROTOCOL_INFO (info2), FALSE);
1007
1008 return is_transport_compat (info1, info2) &&
1009 is_content_format_compat (info1, info2) &&
1010 is_additional_info_compat (info1, info2);
1011 }
1012